Skip to content

Commit

Permalink
Merge pull request #14 from vkottler/dev/networking
Browse files Browse the repository at this point in the history
Initial comm to W5500 working
  • Loading branch information
vkottler authored Oct 31, 2023
2 parents 11deab2 + a862cf9 commit 973df3d
Show file tree
Hide file tree
Showing 18 changed files with 834 additions and 2 deletions.
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,9 @@
[submodule "pico-sdk"]
path = pico-sdk
url = https://github.com/raspberrypi/pico-sdk.git
[submodule "pico-extras"]
path = pico-extras
url = https://github.com/raspberrypi/pico-extras.git
[submodule "ioLibrary_Driver"]
path = ioLibrary_Driver
url = https://github.com/Wiznet/ioLibrary_Driver.git
27 changes: 27 additions & 0 deletions RP2040-HAT-C/port/ioLibrary_Driver/inc/w5x00_gpio_irq.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#define PIN_INT 21

#include <stdint.h>

/*! \brief Initialize w5x00 gpio interrupt callback function
* \ingroup w5x00_gpio_irq
*
* Add a w5x00 interrupt callback.
*
* \param socket socket number
* \param callback the gpio interrupt callback function
*/
void wizchip_gpio_interrupt_initialize(uint8_t socket, void (*callback)(void));

/*! \brief Assign gpio interrupt callback function
* \ingroup w5x00_gpio_irq
*
* GPIO interrupt callback function.
*
* \param gpio Which GPIO caused this interrupt
* \param events Which events caused this interrupt. See \ref
* gpio_set_irq_enabled for details.
*/
static void wizchip_gpio_interrupt_callback(unsigned int gpio,
uint32_t events);
171 changes: 171 additions & 0 deletions RP2040-HAT-C/port/ioLibrary_Driver/inc/w5x00_spi.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
#pragma once

/* SPI */
#define SPI_PORT spi0

#define PIN_SCK 18
#define PIN_MOSI 19
#define PIN_MISO 16
#define PIN_CS 17
#define PIN_RST 20

/* Use SPI DMA */
// #define USE_SPI_DMA // if you want to use SPI DMA, uncomment.

#include "wizchip_conf.h"

/* W5x00 */
/*! \brief Set CS pin
* \ingroup w5x00_spi
*
* Set chip select pin of spi0 to low(Active low).
*
* \param none
*/
static inline void wizchip_select(void);

/*! \brief Set CS pin
* \ingroup w5x00_spi
*
* Set chip select pin of spi0 to high(Inactive high).
*
* \param none
*/
static inline void wizchip_deselect(void);

/*! \brief Read from an SPI device, blocking
* \ingroup w5x00_spi
*
* Set spi_read_blocking function.
* Read byte from SPI to rx_data buffer.
* Blocks until all data is transferred. No timeout, as SPI hardware always
* transfers at a known data rate.
*
* \param none
*/
static uint8_t wizchip_read(void);

/*! \brief Write to an SPI device, blocking
* \ingroup w5x00_spi
*
* Set spi_write_blocking function.
* Write byte from tx_data buffer to SPI device.
* Blocks until all data is transferred. No timeout, as SPI hardware always
* transfers at a known data rate.
*
* \param tx_data Buffer of data to write
*/
static void wizchip_write(uint8_t tx_data);

#ifdef USE_SPI_DMA
/*! \brief Configure all DMA parameters and optionally start transfer
* \ingroup w5x00_spi
*
* Configure all DMA parameters and read from DMA
*
* \param pBuf Buffer of data to read
* \param len element count (each element is of size transfer_data_size)
*/
static void wizchip_read_burst(uint8_t *pBuf, uint16_t len);

/*! \brief Configure all DMA parameters and optionally start transfer
* \ingroup w5x00_spi
*
* Configure all DMA parameters and write to DMA
*
* \param pBuf Buffer of data to write
* \param len element count (each element is of size transfer_data_size)
*/
static void wizchip_write_burst(uint8_t *pBuf, uint16_t len);
#endif

/*! \brief Enter a critical section
* \ingroup w5x00_spi
*
* Set ciritical section enter blocking function.
* If the spin lock associated with this critical section is in use, then this
* method will block until it is released.
*
* \param none
*/
static void wizchip_critical_section_lock(void);

/*! \brief Release a critical section
* \ingroup w5x00_spi
*
* Set ciritical section exit function.
* Release a critical section.
*
* \param none
*/
static void wizchip_critical_section_unlock(void);

/*! \brief Initialize SPI instances and Set DMA channel
* \ingroup w5x00_spi
*
* Set GPIO to spi0.
* Puts the SPI into a known state, and enable it.
* Set DMA channel completion channel.
*
* \param none
*/
void wizchip_spi_initialize(void);

/*! \brief Initialize a critical section structure
* \ingroup w5x00_spi
*
* The critical section is initialized ready for use.
* Registers callback function for critical section for WIZchip.
*
* \param none
*/
void wizchip_cris_initialize(void);

/*! \brief W5x00 chip reset
* \ingroup w5x00_spi
*
* Set a reset pin and reset.
*
* \param none
*/
void wizchip_reset(void);

/*! \brief Initialize WIZchip
* \ingroup w5x00_spi
*
* Set callback function to read/write byte using SPI.
* Set callback function for WIZchip select/deselect.
* Set memory size of W5x00 chip and monitor PHY link status.
*
* \param none
*/
void wizchip_initialize(bool wait_link_up);

/*! \brief Check chip version
* \ingroup w5x00_spi
*
* Get version information.
*
* \param none
*/
void wizchip_check(void);

/* Network */
/*! \brief Initialize network
* \ingroup w5x00_spi
*
* Set network information.
*
* \param net_info network information.
*/
void network_initialize(wiz_NetInfo net_info);

/*! \brief Print network information
* \ingroup w5x00_spi
*
* Print network information about MAC address, IP address, Subnet mask,
* Gateway, DHCP and DNS address.
*
* \param net_info network information.
*/
void print_network_information(wiz_NetInfo net_info);
40 changes: 40 additions & 0 deletions RP2040-HAT-C/port/ioLibrary_Driver/src/w5x00_gpio_irq.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>

#include "hardware/gpio.h"
#include "pico/stdlib.h"

#include "socket.h"
#include "w5x00_gpio_irq.h"
#include "wizchip_conf.h"

static void (*callback_ptr)(void);

/* GPIO */
void wizchip_gpio_interrupt_initialize(uint8_t socket, void (*callback)(void))
{
uint16_t reg_val;
int ret_val;

reg_val = (SIK_CONNECTED | SIK_DISCONNECTED | SIK_RECEIVED |
SIK_TIMEOUT); // except SendOK
ret_val = ctlsocket(socket, CS_SET_INTMASK, (void *)&reg_val);

#if (_WIZCHIP_ == W5100S)
reg_val = (1 << socket);
#elif (_WIZCHIP_ == W5500)
reg_val = ((1 << socket) << 8);
#endif
ret_val = ctlwizchip(CW_SET_INTRMASK, (void *)&reg_val);

callback_ptr = callback;
gpio_set_irq_enabled_with_callback(PIN_INT, GPIO_IRQ_EDGE_FALL, true,
&wizchip_gpio_interrupt_callback);
}

static void wizchip_gpio_interrupt_callback(uint gpio, uint32_t events)
{
if (callback_ptr != NULL)
{
callback_ptr();
}
}
Loading

0 comments on commit 973df3d

Please sign in to comment.