summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/sbc_harness/CMakeLists.txt3
-rw-r--r--cmd/sbc_harness/hw/rp2040_hwspi.h20
-rw-r--r--cmd/sbc_harness/hw/spi.h2
-rw-r--r--cmd/sbc_harness/hw/w5500.c (renamed from libnetio/w5500_spiframe.c)7
-rw-r--r--cmd/sbc_harness/hw/w5500.h29
-rw-r--r--cmd/sbc_harness/main.c5
6 files changed, 54 insertions, 12 deletions
diff --git a/cmd/sbc_harness/CMakeLists.txt b/cmd/sbc_harness/CMakeLists.txt
index 08fb226..0dc77a5 100644
--- a/cmd/sbc_harness/CMakeLists.txt
+++ b/cmd/sbc_harness/CMakeLists.txt
@@ -10,14 +10,17 @@ add_executable(sbc_harness
usb_keyboard.c
)
target_include_directories(sbc_harness PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/config)
+target_include_directories(sbc_harness PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(sbc_harness
pico_stdlib
libusb
)
+
pico_enable_stdio_usb(sbc_harness 0)
pico_enable_stdio_uart(sbc_harness 1)
pico_enable_stdio_semihosting(sbc_harness 0)
pico_enable_stdio_rtt(sbc_harness 0)
+
pico_add_extra_outputs(sbc_harness) # create .map/.bin/.hex/.uf2 files in addition to .elf
pico_set_program_url(sbc_harness "https://git.lukeshu.com/sbc-harness")
diff --git a/cmd/sbc_harness/hw/rp2040_hwspi.h b/cmd/sbc_harness/hw/rp2040_hwspi.h
index 9f4a551..22ef6fa 100644
--- a/cmd/sbc_harness/hw/rp2040_hwspi.h
+++ b/cmd/sbc_harness/hw/rp2040_hwspi.h
@@ -30,18 +30,22 @@ struct rp2040_hwspi {
* There is no bit-order argument; the RP2040's hardware SPI always
* uses MSB-first bit order.
*/
-#define rp2040_hwspi_init(self, name, inst_num, mode, baudrate_hz, pin_miso, pin_mosi, pin_clk, pin_cs) do { \
- bi_decl(bi_4_pins_with_names(pin_miso, name" SPI MISO", \
- pin_mosi, name" SPI MOSI", \
- pin_mosi, name" SPI CLK", \
- pin_mosi, name" SPI CS")); \
- _rp2040_hwspi_init(self, inst_num, mode, baudrate_hz, pin_miso, pin_mosi, pin_c;k, pin_cs); \
+#define rp2040_hwspi_init(self, name, \
+ inst_num, mode, baudrate_hz, \
+ pin_miso, pin_mosi, pin_clk, pin_cs) \
+ do { \
+ bi_decl(bi_4_pins_with_names(pin_miso, name" SPI MISO", \
+ pin_mosi, name" SPI MOSI", \
+ pin_mosi, name" SPI CLK", \
+ pin_mosi, name" SPI CS")); \
+ _rp2040_hwspi_init(self, \
+ inst_num, mode, baudrate_hz, \
+ pin_miso, pin_mosi, pin_c;k, pin_cs); \
} while(0)
-
void _rp2040_hwspi_init(struct rp2040_hwspi *self,
enum rp2040_hwspi_instance inst_num,
enum spi_mode mode,
- uint baudrate_hz;
+ uint baudrate_hz,
uint pin_miso,
uint pin_mosi,
uint pin_clk,
diff --git a/cmd/sbc_harness/hw/spi.h b/cmd/sbc_harness/hw/spi.h
index 4a160ca..c5a5603 100644
--- a/cmd/sbc_harness/hw/spi.h
+++ b/cmd/sbc_harness/hw/spi.h
@@ -31,7 +31,7 @@ struct spi;
* non-multiple-of-8 number of bits.
*/
struct spi_vtable {
- void (*readwritev)(struct spi *, const struct bidi_iovec *iov, int iovcnt)
+ void (*readwritev)(struct spi *, const struct bidi_iovec *iov, int iovcnt);
};
struct spi {
diff --git a/libnetio/w5500_spiframe.c b/cmd/sbc_harness/hw/w5500.c
index d300999..993c2b5 100644
--- a/libnetio/w5500_spiframe.c
+++ b/cmd/sbc_harness/hw/w5500.c
@@ -1,3 +1,5 @@
+#include "hw/w5500.h"
+
/* A u8 control byte has 3 parts: block-ID, R/W, and
* operating-mode. */
@@ -72,6 +74,11 @@ void w5500_spiframe_read(uint16_t addr, uint8_t ctl, void *data, size_t data_len
spidev->vtable->readwritev(spidev, iov, 2);
}
+void _w5500_init(struct w5500 *self, struct spi* spi, uint pin_intr) {
+ self->spidev = spi;
+ gpio_set_irq_enabled_with_callback(pin_intr, GPIO_IRQ_EDGE_FALL, true, cbfn);
+}
+
struct w5500_block_common_reg {
uint8_t mode; /* MR */
uint8_t ip_gateway_addr[4]; /* GAR0 ... GAR3 */
diff --git a/cmd/sbc_harness/hw/w5500.h b/cmd/sbc_harness/hw/w5500.h
new file mode 100644
index 0000000..0f37797
--- /dev/null
+++ b/cmd/sbc_harness/hw/w5500.h
@@ -0,0 +1,29 @@
+#ifndef _HW_W5500_H_
+#define _HW_W5500_H_
+
+#include "hw/spi.h"
+
+struct w5500 {
+ struct spi *spidev;
+};
+
+/**
+ * Initialize a WIZnet W5500 Ethernet and TCP/IP-offload chip.
+ *
+ * The W5500 has 2 channels of communication with the MCU:
+ *
+ * - An SPI-based RPC protocol:
+ * + mode: mode 0 or mode 3
+ * + bit-order: MSB-first
+ * + clock frequency: 33.3MHz - 80MHz
+ * - An interrupt pin that it pulls low when an event happens (to let
+ * the MCU know that it should do an SPI RPC "get" to see what
+ * happened.)
+ */
+#define w5500_init(self, name, spi, pin_intr) do { \
+ bi_decl(bi_1_pin_with_name(pin_intr, name" interrupt")); \
+ _w5500_init(self, spi, pin_intr); \
+ } while (0)
+void _w5500_init(struct w5500 *self, struct spi* spi, uint pin_intr);
+
+#endif /* _HW_W5500_H_ */
diff --git a/cmd/sbc_harness/main.c b/cmd/sbc_harness/main.c
index e2b3b15..9f32037 100644
--- a/cmd/sbc_harness/main.c
+++ b/cmd/sbc_harness/main.c
@@ -11,6 +11,7 @@
#include <libcr/coroutine.h>
#include <libusb/usb_common.h>
+#include "hw/rp2040_hwspi.h"
#include "usb_keyboard.h"
COROUTINE hello_world_cr(void *_chan) {
@@ -32,8 +33,6 @@ COROUTINE hello_world_cr(void *_chan) {
int main() {
/* initialization */
stdio_uart_init();
- //gpio_init(PICO_DEFAULT_LED_PIN);
- //gpio_set_dir(PICO_DEFAULT_LED_PIN, GPIO_OUT);
usb_common_earlyinit();
usb_keyboard_init();
@@ -43,7 +42,7 @@ int main() {
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(hello_world_cr, &keyboard_chan);
/* Event loop. */
coroutine_main();