mip.h 1.2 KB

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include "arch.h"
  3. #include "net.h"
  4. struct mip_driver {
  5. bool (*init)(uint8_t *mac, void *data); // Initialise driver
  6. size_t (*tx)(const void *, size_t, void *data); // Transmit frame
  7. size_t (*rx)(void *buf, size_t len, void *data); // Receive frame (polling)
  8. bool (*up)(void *data); // Up/down status
  9. // Set receive callback for interrupt-driven drivers
  10. void (*setrx)(void (*fn)(void *buf, size_t len, void *rxdata), void *rxdata);
  11. };
  12. struct mip_cfg {
  13. uint8_t mac[6]; // MAC address. Must not be 0
  14. uint32_t ip, mask, gw; // IP, netmask, GW. If IP is 0, DHCP is used
  15. };
  16. void mip_init(struct mg_mgr *, struct mip_cfg *, struct mip_driver *, void *);
  17. extern struct mip_driver mip_driver_stm32;
  18. extern struct mip_driver mip_driver_enc28j60;
  19. extern struct mip_driver mip_driver_w5500;
  20. // Drivers that require SPI, can use this SPI abstraction
  21. struct mip_spi {
  22. void *spi; // Opaque SPI bus descriptor
  23. void (*begin)(void *); // SPI begin: slave select low
  24. void (*end)(void *); // SPI end: slave select high
  25. uint8_t (*txn)(void *, uint8_t); // SPI transaction: write 1 byte, read reply
  26. };