void W5500Initialze(void)
{
	unsigned char temp;
	unsigned char W5500FifoSize[2][8] = {{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2}};

	W5500DeSelect();

	/* spi function register */
	reg_wizchip_spi_cbfunc(W5500ReadByte, W5500WriteByte);

	/* CS function register */
	reg_wizchip_cs_cbfunc(W5500Select,W5500DeSelect);

	if(ctlwizchip(CW_INIT_WIZCHIP,(void*)W5500FifoSize) == -1)
	{
		printf("W5500 initialized fail.\r\n");
	}

	do{//check phy status.
		if(ctlwizchip(CW_GET_PHYLINK,(void*)&temp) == -1){
			printf("Unknown PHY link status.\r\n");
		}
	}while(temp == PHY_LINK_OFF);

}
Exemplo n.º 2
0
void W5500_Init()
{
	uint8_t memsize[2][8] = { { 2, 2, 2, 2, 2, 2, 2, 2 }, { 2, 2, 2, 2, 2, 2, 2, 2 } };

	Chip_GPIO_SetPinState(LPC_GPIO, 0, 2, true);	// SSEL(CS)

	Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, false);	// N_RESET
	delay_cnt(1000);
	Chip_GPIO_SetPinState(LPC_GPIO, 0, 22, true);	// N_RESET

	reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
	reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);
	reg_wizchip_spiburst_cbfunc(wizchip_readburst, wizchip_writeburst);

	/* wizchip initialize*/
	if (ctlwizchip(CW_INIT_WIZCHIP, (void*) memsize) == -1) {
		//printf("WIZCHIP Initialized fail.\r\n");
		while (1);
	}

	/* For Delay */
	delay_cnt(10000);

	setRCR(3);
}
Exemplo n.º 3
0
void ip_init(void){
	wiz_NetInfo netInfo;
	uint8_t  bufSize[] = {2, 2, 2, 2};
	reg_wizchip_cs_cbfunc(cs_sel, cs_desel);
	reg_wizchip_spi_cbfunc(spi_rb, spi_wb);
	wizphy_reset();
	wizchip_init(bufSize, bufSize);
	memcpy_P(&netInfo, &network_info, sizeof(wiz_NetInfo));
	wizchip_setnetinfo(&netInfo);
	sock_state=IP_STATE_NO_SOCKET;
}
Exemplo n.º 4
0
/*---------------------------------------------------------------------------*/
bool HALW5500_Init(uint8_t *mac)
{
    DEBUG("HALW5500: MAC ");
    for (uint8_t i = 0; i <= 5; i++)
        DEBUG("%02X",  mac[i]);
    DEBUG("\n");
    memset(&netInfo, 0, sizeof(netInfo));
    memcpy(netInfo.mac, mac, 6);
    HAL_EthReset();
    reg_wizchip_cs_cbfunc(HAL_EthCS0, HAL_EthCS1);
    reg_wizchip_spi_cbfunc(HALW5500_Read, HALW5500_Write);
    uint8_t memsize[2][8] = {{2, 2, 2, 2, 2, 2, 2, 2}, {2, 2, 2, 2, 2, 2, 2, 2}};
    return ctlwizchip(CW_INIT_WIZCHIP, (void*) memsize) >= 0;
}
Exemplo n.º 5
0
/*JSON{ "type":"staticmethod", 
         "class" : "WIZnet", "name" : "connect",
         "generate" : "jswrap_wiznet_connect",
         "description" : "Initialise the WIZnet module and return an Ethernet object",
         "params" : [ ],
         "return" : ["JsVar", "An Ethernet Object"], "return_object":"Ethernet"
}*/
JsVar *jswrap_wiznet_connect() {
  JsVar *ethObj = jspNewObject(0, "Ethernet");

  // SPI config
  JshSPIInfo inf;
  jshSPIInitInfo(&inf);
  inf.pinSCK =  ETH_CLK_PIN;
  inf.pinMISO = ETH_MISO_PIN;
  inf.pinMOSI = ETH_MOSI_PIN;
  inf.baudRate = 1000000;
  inf.spiMode = SPIF_SPI_MODE_0;
  jshSPISetup(ETH_SPI, &inf);

  // CS Configuration
  jshSetPinStateIsManual(ETH_CS_PIN, false);
  jshPinOutput(ETH_CS_PIN, 1); // de-assert CS

  // Wiznet
  reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
  reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);

  /* wizchip initialize*/
  uint8_t tmp;
  uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};

  if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1)
  {
    jsiConsolePrint("WIZCHIP Initialized fail.\r\n");
    return 0;
  }

  /* PHY link status check */
  do {
    if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1) {
      jsiConsolePrint("Unknown PHY Link status.\r\n");
      return 0;
    }
  } while (tmp == PHY_LINK_OFF);

  JsNetwork net;
  networkCreate(&net, JSNETWORKTYPE_W5500);
  networkFree(&net);

  networkState = NETWORKSTATE_ONLINE;

  return ethObj;
}
Exemplo n.º 6
0
STATIC void wiznet5k_init(void) {
    // SPI configuration
    SPI_InitTypeDef *init = &wiznet5k_obj.spi->spi->Init;
    init->Mode = SPI_MODE_MASTER;
    init->Direction = SPI_DIRECTION_2LINES;
    init->DataSize = SPI_DATASIZE_8BIT;
    init->CLKPolarity = SPI_POLARITY_LOW; // clock is low when idle
    init->CLKPhase = SPI_PHASE_1EDGE; // data latched on first edge, which is rising edge for low-idle
    init->NSS = SPI_NSS_SOFT;
    init->BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2; // clock freq = f_PCLK / this_prescale_value; Wiz820i can do up to 80MHz
    init->FirstBit = SPI_FIRSTBIT_MSB;
    init->TIMode = SPI_TIMODE_DISABLED;
    init->CRCCalculation = SPI_CRCCALCULATION_DISABLED;
    init->CRCPolynomial = 7; // unused
    spi_init(wiznet5k_obj.spi, false);

    mp_hal_pin_output(wiznet5k_obj.cs);
    mp_hal_pin_output(wiznet5k_obj.rst);

    // Reset the chip
    mp_hal_pin_low(wiznet5k_obj.rst);
    mp_hal_delay_ms(1); // datasheet says 2us
    mp_hal_pin_high(wiznet5k_obj.rst);
    mp_hal_delay_ms(150); // datasheet says 150ms

    // Set physical interface callbacks
    reg_wizchip_cris_cbfunc(wiz_cris_enter, wiz_cris_exit);
    reg_wizchip_cs_cbfunc(wiz_cs_select, wiz_cs_deselect);
    reg_wizchip_spi_cbfunc(wiz_spi_read, wiz_spi_write);

    // Configure 16k buffers for fast MACRAW
    uint8_t sn_size[16] = {16, 0, 0, 0, 0, 0, 0, 0, 16, 0, 0, 0, 0, 0, 0, 0};
    ctlwizchip(CW_INIT_WIZCHIP, sn_size);

    // Seems we need a small delay after init
    mp_hal_delay_ms(250);

    // Hook the Wiznet into lwIP
    wiznet5k_lwip_init(&wiznet5k_obj);
}
Exemplo n.º 7
0
/*
 *System initialize
 */
uint8_t wizSystemInit(void)
{
	uint8_t W5500SockBufSize[2][8] = {{2,2,2,2,2,2,2,2,},{2,2,2,2,2,2,2,2}};
	uint32_t tickStart;

	/* spi function register */
	reg_wizchip_spi_cbfunc(W5500ReadByte, W5500WriteByte);

	/* CS function register */
	reg_wizchip_cs_cbfunc(W5500Select, W5500DeSelect);

	/* Critical section */
	reg_wizchip_cris_cbfunc(spiMutexEnter,spiMutexExit);

	//W5500Select();

	if(ctlwizchip(CW_INIT_WIZCHIP,(void*)W5500SockBufSize) == -1)
	{
#if WIZSYSTEM_DEBUG == 1
		printf("W5500 initialized fail.\r\n");
#endif
		return -1;
	}
	/*Set network information by default*/
	wizchip_setnetinfo(&NetInfo);
	tickStart = HAL_GetTick();
	do{//check phy status.
		randomKey++;
		if((HAL_GetTick() - tickStart) > NETINFO_LINK_TIMEOUT)
		{
#if WIZSYSTEM_DEBUG == 1
			printf("Ethernet Link timeout.\r\n");
#endif
			return -1;
		}
	}while(!isLinked());
	return 1;
}
Exemplo n.º 8
0
int main(void)
{
   uint8_t tmp=0;
   int32_t ret = 0;
   uint8_t memsize[2][8] = {{2,2,2,2,2,2,2,2},{2,2,2,2,2,2,2,2}};
   uint8_t txsize[8] = {2,2,2,2,2,2,2,2};
   uint8_t rxsize[8] = {2,2,2,2,2,2,2,2};
   uint8_t pDestaddr[4] = {192,168,0,200};
   int8_t num;

   uint8_t ping_reply_received = 0;

   ///////////////////////////////////////////
   // Host dependent peripheral initialized //
   ///////////////////////////////////////////
   platform_init();


   //////////
   // TODO //
   ////////////////////////////////////////////////////////////////////////////////////////////////////
   // First of all, Should register SPI callback functions implemented by user for accessing WIZCHIP //
   ////////////////////////////////////////////////////////////////////////////////////////////////////
   /* Critical section callback - No use in this example */
   //reg_wizchip_cris_cbfunc(0, 0);
   /* Chip selection call back */
#if   _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_VDM_
    reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
#elif _WIZCHIP_IO_MODE_ == _WIZCHIP_IO_MODE_SPI_FDM_
    reg_wizchip_cs_cbfunc(wizchip_select, wizchip_select);  // CS must be tried with LOW.
#else
   #if (_WIZCHIP_IO_MODE_ & _WIZCHIP_IO_MODE_SIP_) != _WIZCHIP_IO_MODE_SIP_
      #error "Unknown _WIZCHIP_IO_MODE_"
   #else
      reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
   #endif
#endif
    /* SPI Read & Write callback function */
    reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);
    ////////////////////////////////////////////////////////////////////////

    /* WIZCHIP SOCKET Buffer initialize */

    wizchip_init(txsize,rxsize);

    /* Network initialization */
    network_init();


	/*******************************/
	/* WIZnet W5500 Code Examples  */
	/* TCPS/UDPS IPRAW test     */
	/*******************************/
    printf("------------PING_TEST_START-----------------------\r\n");
    tmp = ping_auto(0,pDestaddr);
    //tmp = ping_count(0,3,pDestaddr);
    if(tmp == SUCCESS)
    	printf("-----------PING TEST OK----------\r\n");
    else
        printf("----------ERROR  = %d----------\r\n",tmp);

} // end of main()
Exemplo n.º 9
0
/*JSON{
  "type" : "staticmethod",
  "class" : "WIZnet",
  "name" : "connect",
  "generate" : "jswrap_wiznet_connect",
  "params" : [
    ["spi", "JsVar", "Device to use for SPI (or undefined to use the default)"],
    ["cs", "pin", "The pin to use for Chip Select"]
  ],
  "return" : ["JsVar","An Ethernet Object"],
  "return_object" : "Ethernet"
}
Initialise the WIZnet module and return an Ethernet object
*/
JsVar *jswrap_wiznet_connect(JsVar *spi, Pin cs) {

  IOEventFlags spiDevice;
  if (spi) {
    spiDevice = jsiGetDeviceFromClass(spi);
    if (!DEVICE_IS_SPI(spiDevice)) {
      jsExceptionHere(JSET_ERROR, "Expecting SPI device, got %q", spi);
      return 0;
    }
  } else {
    // SPI config
    JshSPIInfo inf;
    jshSPIInitInfo(&inf);
    inf.pinSCK =  ETH_CLK_PIN;
    inf.pinMISO = ETH_MISO_PIN;
    inf.pinMOSI = ETH_MOSI_PIN;
    inf.baudRate = 1000000;
    inf.spiMode = SPIF_SPI_MODE_0;
    jshSPISetup(ETH_SPI, &inf);
    spiDevice = ETH_SPI;
  }
  if (!jshIsPinValid(cs))
    cs = ETH_CS_PIN;

  JsNetwork net;
  networkCreate(&net, JSNETWORKTYPE_W5500);
  net.data.device = spiDevice;
  net.data.pinCS = cs;
  networkSet(&net);

  JsVar *ethObj = jspNewObject(0, "Ethernet");

  // CS Configuration
  jshSetPinStateIsManual(net.data.pinCS, false);
  jshPinOutput(net.data.pinCS, 1); // de-assert CS

  // Initialise WIZnet functions
  reg_wizchip_cs_cbfunc(wizchip_select, wizchip_deselect);
  reg_wizchip_spi_cbfunc(wizchip_read, wizchip_write);

  /* wizchip initialize*/
  uint8_t tmp;
  uint8_t memsize[2][8] = { {2,2,2,2,2,2,2,2}, {2,2,2,2,2,2,2,2}};

  if(ctlwizchip(CW_INIT_WIZCHIP,(void*)memsize) == -1)
  {
    jsiConsolePrint("WIZnet Initialize failed.\r\n");
    networkFree(&net);
    return 0;
  }

#if _WIZCHIP_ == 5500
  /* PHY link status check - W5100 doesn't have this */
  do {
    if(ctlwizchip(CW_GET_PHYLINK, (void*)&tmp) == -1) {
      jsiConsolePrint("Unknown PHY Link status.\r\n");
      networkFree(&net);
      return 0;
    }
  } while (tmp == PHY_LINK_OFF);
#endif

  networkFree(&net);

  networkState = NETWORKSTATE_ONLINE;

  return ethObj;
}