diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-23 15:21:09 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-10-23 15:21:09 -0600 |
commit | e7378b9f9b122e05baebce387fe9c3844c0736b6 (patch) | |
tree | ce921a21811cb4ded792f61f2d933cf4e8f87a96 /cmd/sbc_harness/main.c | |
parent | 9940877f4bb44bc69fecf7fb5afcf3cbab90f088 (diff) |
wip
Diffstat (limited to 'cmd/sbc_harness/main.c')
-rw-r--r-- | cmd/sbc_harness/main.c | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c index c6df8f5..8ecc56c 100644 --- a/cmd/sbc_harness/main.c +++ b/cmd/sbc_harness/main.c @@ -7,9 +7,11 @@ #include <string.h> /* for strlen() */ #include <stdio.h> /* for printf() */ #include "pico/stdlib.h" +#include "hardware/flash.h" #include <libcr/coroutine.h> #include <libusb/usb_common.h> +#include <libmisc/hash.h> #include "hw/rp2040_hwspi.h" #include "hw/w5500.h" @@ -32,9 +34,23 @@ COROUTINE hello_world_cr(void *_chan) { } int main() { - /* initialization */ + /* initialization *****************************************************/ stdio_uart_init(); + /* NOR flash chips have a (bog-?)standard "RUID" "Read Unique + * ID" instruction; use our flash chip's unique ID as the + * basis for our serial numbers. */ + uint64_t flash_id64; + static_assert(sizeof(flash_id64) == FLASH_UNIQUE_ID_SIZE_BYTES); + flash_get_unique_id((uint8_t *)&flash_id64); + uint32_t flash_id32 = hash(&flash_id64, sizeof(flash_id64)); + static_assert(sizeof(flash_id32) == sizeof(hash(NULL, 0))); + uint8_t flash_id24[3] = { + (uint8_t)((flash_id32 >> 16) & 0xFF), + (uint8_t)((flash_id32 >> 8) & 0xFF), + (uint8_t)((flash_id32 >> 0) & 0xFF), + }; + struct rp2040_hwspi dev_spi; struct w5500 dev_w5500; rp2040_hwspi_init(&dev_spi, "W5500", RP2040_HWSPI_0, @@ -47,18 +63,24 @@ int main() { w5500_init(&dev_w5500, "W5500", &dev_spi, 21, /* PIN_INTR */ 20, /* PIN_RESET */ - ((struct net_eth_addr){{0xDE,0xAD,0xBE,0xEF,0x01,0x02}})); + ((struct net_eth_addr){{ + /* vendor ID: "Wiznet" */ + 0x00, 0x08, 0xDC, + /* serial number */ + flash_id24[0], flash_id24[1], flash_id24[2], + }})); usb_common_earlyinit(); usb_keyboard_init(); usb_common_lateinit(); - /* set up coroutines */ + /* set up coroutines **************************************************/ coroutine_add(usb_common_cr, NULL); usb_keyboard_rpc_t keyboard_chan = {0}; coroutine_add(usb_keyboard_cr, &keyboard_chan); //coroutine_add(hello_world_cr, &keyboard_chan); + //coroutine_add(dhcp_client_cr, NULL); - /* Event loop. */ + /* event loop *********************************************************/ coroutine_main(); } |