mirror of
https://github.com/cesanta/mongoose.git
synced 2026-12-04 21:58:22 +00:00
Rename mg_tcpip_spi to mg_spi and move it to flash.h
This commit is contained in:
1 parent
1d8c55c892
commit
e7bfbf99fa
23 files changed
+104
-106
No files matched your search
+11
-11
@@ -2,7 +2,7 @@
|
||||
|
||||
#if MG_ENABLE_TCPIP && defined(MG_ENABLE_DRIVER_W5100) && MG_ENABLE_DRIVER_W5100
|
||||
|
||||
static void w5100_txn(struct mg_tcpip_spi *s, uint16_t addr, bool wr, void *buf,
|
||||
static void w5100_txn(struct mg_spi *s, uint16_t addr, bool wr, void *buf,
|
||||
size_t len) {
|
||||
uint8_t control = wr ? 0xF0 : 0x0F;
|
||||
uint8_t cmd[] = {control, (uint8_t) (addr >> 8), (uint8_t) (addr & 255)};
|
||||
@@ -14,16 +14,16 @@ static void w5100_txn(struct mg_tcpip_spi *s, uint16_t addr, bool wr, void *buf,
|
||||
}
|
||||
|
||||
// clang-format off
|
||||
static void w5100_wn(struct mg_tcpip_spi *s, uint16_t addr, void *buf, size_t len) { w5100_txn(s, addr, true, buf, len); }
|
||||
static void w5100_w1(struct mg_tcpip_spi *s, uint16_t addr, uint8_t val) { w5100_wn(s, addr, &val, 1); }
|
||||
static void w5100_w2(struct mg_tcpip_spi *s, uint16_t addr, uint16_t val) { uint8_t buf[2] = {(uint8_t) (val >> 8), (uint8_t) (val & 255)}; w5100_wn(s, addr, buf, sizeof(buf)); }
|
||||
static void w5100_rn(struct mg_tcpip_spi *s, uint16_t addr, void *buf, size_t len) { w5100_txn(s, addr, false, buf, len); }
|
||||
static uint8_t w5100_r1(struct mg_tcpip_spi *s, uint16_t addr) { uint8_t r = 0; w5100_rn(s, addr, &r, 1); return r; }
|
||||
static uint16_t w5100_r2(struct mg_tcpip_spi *s, uint16_t addr) { uint8_t buf[2] = {0, 0}; w5100_rn(s, addr, buf, sizeof(buf)); return (uint16_t) ((buf[0] << 8) | buf[1]); }
|
||||
static void w5100_wn(struct mg_spi *s, uint16_t addr, void *buf, size_t len) { w5100_txn(s, addr, true, buf, len); }
|
||||
static void w5100_w1(struct mg_spi *s, uint16_t addr, uint8_t val) { w5100_wn(s, addr, &val, 1); }
|
||||
static void w5100_w2(struct mg_spi *s, uint16_t addr, uint16_t val) { uint8_t buf[2] = {(uint8_t) (val >> 8), (uint8_t) (val & 255)}; w5100_wn(s, addr, buf, sizeof(buf)); }
|
||||
static void w5100_rn(struct mg_spi *s, uint16_t addr, void *buf, size_t len) { w5100_txn(s, addr, false, buf, len); }
|
||||
static uint8_t w5100_r1(struct mg_spi *s, uint16_t addr) { uint8_t r = 0; w5100_rn(s, addr, &r, 1); return r; }
|
||||
static uint16_t w5100_r2(struct mg_spi *s, uint16_t addr) { uint8_t buf[2] = {0, 0}; w5100_rn(s, addr, buf, sizeof(buf)); return (uint16_t) ((buf[0] << 8) | buf[1]); }
|
||||
// clang-format on
|
||||
|
||||
static size_t w5100_rx(void *buf, size_t buflen, struct mg_tcpip_if *ifp) {
|
||||
struct mg_tcpip_spi *s = (struct mg_tcpip_spi *) ifp->driver_data;
|
||||
struct mg_spi *s = (struct mg_spi *) ifp->driver_data;
|
||||
uint16_t r = 0, n = 0, len = (uint16_t) buflen, n2; // Read recv len
|
||||
while ((n2 = w5100_r2(s, 0x426)) > n) n = n2; // Until it is stable
|
||||
if (n > 0) {
|
||||
@@ -49,7 +49,7 @@ static size_t w5100_rx(void *buf, size_t buflen, struct mg_tcpip_if *ifp) {
|
||||
|
||||
static size_t w5100_tx(const void *buf, size_t buflen,
|
||||
struct mg_tcpip_if *ifp) {
|
||||
struct mg_tcpip_spi *s = (struct mg_tcpip_spi *) ifp->driver_data;
|
||||
struct mg_spi *s = (struct mg_spi *) ifp->driver_data;
|
||||
uint16_t i, n = 0, ptr = 0, len = (uint16_t) buflen;
|
||||
while (n < len) n = w5100_r2(s, 0x420); // Wait for space
|
||||
ptr = w5100_r2(s, 0x424); // Get write pointer
|
||||
@@ -77,7 +77,7 @@ static size_t w5100_tx(const void *buf, size_t buflen,
|
||||
}
|
||||
|
||||
static bool w5100_init(struct mg_tcpip_if *ifp) {
|
||||
struct mg_tcpip_spi *s = (struct mg_tcpip_spi *) ifp->driver_data;
|
||||
struct mg_spi *s = (struct mg_spi *) ifp->driver_data;
|
||||
s->end(s->spi);
|
||||
w5100_w1(s, 0, 0x80); // Reset chip: CR -> 0x80
|
||||
w5100_w1(s, 0x72, 0x53); // CR PHYLCKR -> unlock PHY
|
||||
@@ -93,7 +93,7 @@ static bool w5100_init(struct mg_tcpip_if *ifp) {
|
||||
}
|
||||
|
||||
static bool w5100_poll(struct mg_tcpip_if *ifp, bool s1) {
|
||||
struct mg_tcpip_spi *spi = (struct mg_tcpip_spi *) ifp->driver_data;
|
||||
struct mg_spi *spi = (struct mg_spi *) ifp->driver_data;
|
||||
return s1 ? w5100_r1(spi, 0x3c /* PHYSR */) & 1
|
||||
: false; // Bit 0 of PHYSR is LNK (0 - down, 1 - up)
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user