Beispiel #1
0
static inline void w5100_set_buffer(uint16_t _reg, volatile uint8_t *_buf, uint16_t _len)
{
  for (int i = 0; i < _len; i++) {
    w5100_set(_reg, _buf[ i ]);
    _reg++;
  }
}
Beispiel #2
0
static inline void w5100_sock_set(uint8_t _sock, uint16_t _reg, uint8_t _val)
{
  w5100_set(CH_BASE + _sock * CH_SIZE + _reg, _val);
}
Beispiel #3
0
void w5100_init( void ) {

  // configure the SPI bus.
  w5100_spi.slave_idx = W5100_SLAVE_IDX;
  w5100_spi.output_length = 4;
  w5100_spi.input_length = 4;
  w5100_spi.select = SPISelectUnselect;
  w5100_spi.cpol = SPICpolIdleLow;
  w5100_spi.cpha = SPICphaEdge1;
  w5100_spi.dss = SPIDss8bit;
  w5100_spi.bitorder = SPIMSBFirst;
  w5100_spi.cdiv = SPIDiv64;

  chip0.status = W5100StatusUninit;
  chip0.curbuf = 0;
  w5100_spi.input_buf = &chip0.work_rx[0];
  w5100_spi.output_buf = &chip0.work_tx[0];

  // wait one second for proper initialization (chip getting powered up).
  sys_time_usleep(1000000);

  // set DRDY pin
  gpio_setup_output(W5100_DRDY_GPIO, W5100_DRDY_GPIO_PIN);
  gpio_clear(W5100_DRDY_GPIO, W5100_DRDY_GPIO_PIN);
  sys_time_usleep(200);
  gpio_set(W5100_DRDY_GPIO, W5100_DRDY_GPIO_PIN);

  // allow some time for the chip to wake up.
  sys_time_usleep(20000);

  // write reset bit into mode register
  w5100_set( REG_MR, 1<<RST );

  // allow some time to wake up...
  sys_time_usleep(20000);

  // receive memory size
  w5100_set( REG_RX_MEM, 0x55 );

  // transmit memory size
  w5100_set( REG_TX_MEM, 0x55 );

  // Setting the required socket base addresses for reads and writes to/from sockets
  for (int i=0; i<SOCKETS; i++) {
    SBASE[i] = TXBUF_BASE + SSIZE * i;
    RBASE[i] = RXBUF_BASE + RSIZE * i;
  }

  uint8_t gateway[4];
  gateway[0] = ip[0];
  gateway[1] = ip[1];
  gateway[2] = ip[2];
  gateway[3] = 1;

  // configure gateway, subnet, mac and ip on "NIC".
  w5100_set_buffer( REG_GAR, gateway, 4 );
  w5100_set_buffer( REG_SUBR, subnet, 4 );
  w5100_set_buffer( REG_SHAR, mac, 6 );
  w5100_set_buffer( REG_SIPR, ip, 4 );

  // create a socket to send telemetry through.
  configure_socket( TELEM_SOCKET, SNMR_MULTI, 1, dport, dest );

  // make dest zero and configure socket to receive data
  dest[ 0 ] = 0x00;
  configure_socket( CMD_SOCKET, 0, dport, dport, dest );
}