2022-05-19 04:19:21 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "arch.h"
|
|
|
|
#include "net.h"
|
|
|
|
|
|
|
|
struct mip_driver {
|
2022-09-02 19:58:43 +08:00
|
|
|
bool (*init)(uint8_t *mac, void *data); // Initialise driver
|
2022-05-19 04:19:21 +08:00
|
|
|
size_t (*tx)(const void *, size_t, void *data); // Transmit frame
|
|
|
|
size_t (*rx)(void *buf, size_t len, void *data); // Receive frame (polling)
|
2022-08-31 15:34:38 +08:00
|
|
|
bool (*up)(void *data); // Up/down status
|
2022-05-19 04:19:21 +08:00
|
|
|
// Set receive callback for interrupt-driven drivers
|
2022-08-31 15:34:38 +08:00
|
|
|
void (*setrx)(void (*fn)(void *buf, size_t len, void *rxdata), void *rxdata);
|
2022-05-19 04:19:21 +08:00
|
|
|
};
|
|
|
|
|
2022-08-31 15:41:16 +08:00
|
|
|
struct mip_cfg {
|
2022-05-19 04:19:21 +08:00
|
|
|
uint8_t mac[6]; // MAC address. Must not be 0
|
|
|
|
uint32_t ip, mask, gw; // IP, netmask, GW. If IP is 0, DHCP is used
|
|
|
|
};
|
|
|
|
|
2022-08-31 15:41:16 +08:00
|
|
|
void mip_init(struct mg_mgr *, struct mip_cfg *, struct mip_driver *, void *);
|
2022-06-12 00:29:45 +08:00
|
|
|
|
|
|
|
extern struct mip_driver mip_driver_stm32;
|
2022-08-31 15:34:38 +08:00
|
|
|
extern struct mip_driver mip_driver_enc28j60;
|
2022-09-02 19:58:43 +08:00
|
|
|
extern struct mip_driver mip_driver_w5500;
|
2022-08-31 15:34:38 +08:00
|
|
|
|
|
|
|
// Drivers that require SPI, can use this SPI abstraction
|
|
|
|
struct mip_spi {
|
|
|
|
void *spi; // Opaque SPI bus descriptor
|
|
|
|
void (*begin)(void *); // SPI begin: slave select low
|
|
|
|
void (*end)(void *); // SPI end: slave select high
|
2022-09-02 19:58:43 +08:00
|
|
|
uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
|
2022-08-31 15:34:38 +08:00
|
|
|
};
|