Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .github/workflows/pr-build-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ jobs:
axera_test hal_hisi_test novatek_test sstar_test \
report_test http_test mtd_alias_test \
nand_layout_test upgrade_env_test \
jffs2_test raw_image_test
jffs2_test raw_image_test decoders_test
./build/cYAML_test
./build/decoders_test
./build/report_test
./build/http_test
./build/mtd_alias_test
Expand Down
13 changes: 12 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ set(IPCHW_PADMUX_BACKENDS_ALL src/hal/sstar_padmux.c src/hal/ingenic_padmux.c
# Same shape and vocabulary as IPCHW_PADMUX above, and "none" is meaningful
# here too: a SigmaStar or Ingenic consumer drops the HiSilicon HAL entirely.
# The ipctool executable always carries every generation.
set(IPCHW_HISI_GENERATIONS v1 v2 v2a v3 v3a v4 v4a v5 3536c 3536d goke7206)
set(IPCHW_HISI_GENERATIONS v1 v2 v2a v3 v3a v4 v4a v5 3536c 3536d 3520d goke7206)

# The default follows IPCHW_VENDORS, because a consumer that has named its
# silicon has already answered this question and should not have to answer it
Expand Down Expand Up @@ -336,6 +336,10 @@ message(STATUS "libipchw vendor HALs: hisi ${_ipchw_selected}")
set(IPCTOOL_SRC
src/backup.c
src/backup.h
src/bitbang_i2c.c
src/bitbang_i2c.h
src/decoders.c
src/decoders.h
src/jffs2.c
src/jffs2.h
src/upgrade_env.c
Expand Down Expand Up @@ -574,6 +578,13 @@ if(NOT ONLY_LIBRARY)
add_executable(report_test src/report_test.c src/report.c src/cjson/cJSON.c)
target_include_directories(report_test PRIVATE include src)

# decoders.c is included, as sensors.c is in sensors_test: the probes and
# the bus seam are file-statics. mem_reg() is the test's own model of the
# Hi3520DV200's GPIO1 with an I2C slave on the lines.
add_executable(decoders_test src/decoders_test.c src/bitbang_i2c.c
src/cjson/cJSON.c src/cjson/cYAML.c)
target_include_directories(decoders_test PRIVATE include src)

# How the upload meets a server: a redirect on the headers, an interim
# 100, a body taken whole, and a connection that stops draining -- against
# servers forked on the loopback.
Expand Down
95 changes: 95 additions & 0 deletions src/bitbang_i2c.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
#include "bitbang_i2c.h"

static void d(const bb_i2c_t *b) { b->delay(b->ctx); }

static void start(const bb_i2c_t *b) {
b->sda(b->ctx, 1);
b->scl(b->ctx, 1);
d(b);
b->sda(b->ctx, 0);
d(b);
b->scl(b->ctx, 0);
d(b);
}

static void stop(const bb_i2c_t *b) {
b->sda(b->ctx, 0);
d(b);
b->scl(b->ctx, 1);
d(b);
b->sda(b->ctx, 1);
d(b);
}

static void put_bit(const bb_i2c_t *b, int bit) {
b->sda(b->ctx, bit);
d(b);
b->scl(b->ctx, 1);
d(b);
d(b);
b->scl(b->ctx, 0);
d(b);
}

static int get_bit(const bb_i2c_t *b) {
b->sda_release(b->ctx);
d(b);
b->scl(b->ctx, 1);
d(b);
int bit = b->sda_get(b->ctx) ? 1 : 0;
d(b);
b->scl(b->ctx, 0);
d(b);
return bit;
}

/* 0 when the slave acknowledged. */
static int put_byte(const bb_i2c_t *b, uint8_t v) {
for (int i = 7; i >= 0; i--)
put_bit(b, (v >> i) & 1);
return get_bit(b);
}

static uint8_t get_byte(const bb_i2c_t *b, int ack) {
uint8_t v = 0;
for (int i = 0; i < 8; i++)
v = (uint8_t)(v << 1 | get_bit(b));
put_bit(b, ack ? 0 : 1);
return v;
}

static int put_reg(const bb_i2c_t *b, uint8_t addr, const uint8_t *reg,
int reglen) {
start(b);
if (put_byte(b, addr & 0xfe))
return -1;
for (int i = 0; i < reglen; i++)
if (put_byte(b, reg[i]))
return -1;
return 0;
}

int bb_i2c_read(const bb_i2c_t *b, uint8_t addr, const uint8_t *reg,
int reglen, uint8_t *val) {
if (put_reg(b, addr, reg, reglen)) {
stop(b);
return -1;
}
start(b); /* repeated start */
if (put_byte(b, addr | 1)) {
stop(b);
return -1;
}
*val = get_byte(b, 0);
stop(b);
return 0;
}

int bb_i2c_write(const bb_i2c_t *b, uint8_t addr, const uint8_t *reg,
int reglen, uint8_t val) {
int rc = put_reg(b, addr, reg, reglen);
if (!rc && put_byte(b, val))
rc = -1;
stop(b);
return rc;
}
33 changes: 33 additions & 0 deletions src/bitbang_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#ifndef BITBANG_I2C_H
#define BITBANG_I2C_H

#include <stdint.h>

/* An I2C master on two GPIO lines. The line operations are the caller's,
* so the same protocol runs on a SoC's GPIO registers and on a test's model
* of a slave. sda()/scl() set a line's level: open-drain (high = released to
* a pull-up) or, as the vendors' gpio_i2c drivers do on boards with no
* pull-ups, push-pull. Either way SDA is let go with sda_release() before
* the slave's acknowledge or data are read: driven, it would read back the
* master's own level. Addresses are 8-bit (7-bit << 1), as the rest of
* ipctool writes them. */
typedef struct {
void *ctx;
void (*sda)(void *ctx, int high);
void (*scl)(void *ctx, int high);
void (*sda_release)(void *ctx);
int (*sda_get)(void *ctx);
void (*delay)(void *ctx); /* a quarter of a bit */
} bb_i2c_t;

/* One register read: reglen register-address bytes (1 or 2, most
* significant first), a repeated start, one data byte. 0 with *val set, or
* -1 when the device did not acknowledge. */
int bb_i2c_read(const bb_i2c_t *b, uint8_t addr, const uint8_t *reg,
int reglen, uint8_t *val);

/* One register write. 0, or -1 on a missing acknowledge. */
int bb_i2c_write(const bb_i2c_t *b, uint8_t addr, const uint8_t *reg,
int reglen, uint8_t val);

#endif /* BITBANG_I2C_H */
Loading
Loading