BOOL ENC28J60_LWIP_Driver::Close( ENC28J60_LWIP_DRIVER_CONFIG* config, int index ) { NATIVE_PROFILE_HAL_DRIVERS_ETHERNET(); if(config == NULL) return FALSE; LwipUpTimeCompletion.Abort(); netif_set_link_down( &g_ENC28J60_NetIF ); netif_set_down( &g_ENC28J60_NetIF ); netif_remove( &g_ENC28J60_NetIF ); /* Disable the INTERRUPT pin */ CPU_GPIO_EnableInputPin2(config->INT_Pin, FALSE, /* Glitch filter enable */ NULL, /* ISR */ 0, /* minor number */ GPIO_INT_NONE, /* Interrupt edge */ RESISTOR_PULLUP); /* Resistor State */ InterruptTaskContinuation.Abort(); LwipNetworkStatus = FALSE; enc28j60_lwip_close( &g_ENC28J60_NetIF ); memset(&g_ENC28J60_NetIF, 0, sizeof(g_ENC28J60_NetIF)); return TRUE; }
int ENC28J60_Driver::Open( ENC28J60_DRIVER_CONFIG* config, int index ) { NATIVE_PROFILE_HAL_DRIVERS_ETHERNET(); int use_default_multicast = 1; if(config == NULL) return -1; memset(&g_ENC28J60_Driver.m_currentDhcpSession, 0, sizeof(g_ENC28J60_Driver.m_currentDhcpSession)); /* Enable the CHIP SELECT pin */ if (CPU_GPIO_EnableInputPin (config->SPI_Config.DeviceCS, FALSE, NULL, GPIO_INT_NONE, RESISTOR_PULLUP) == FALSE) { return -1; } /* Open the interface first */ g_ENC28J60_Driver.m_interfaceNumber = xn_interface_open_config(ENC28J60_DEVICE, index, /* minor_number */ 0, /* ioaddress */ 0, /* irq value */ 0 /* mem_address) */ ); if (g_ENC28J60_Driver.m_interfaceNumber == -1) { return -1; } if(index == 0) // default debugger port is index 0 { if (xn_interface_opt(g_ENC28J60_Driver.m_interfaceNumber, IO_DEFAULT_MCAST, (RTP_PFCCHAR)&use_default_multicast, sizeof(int)) == -1) { /* Failed to set the default multicast interface */ } } /* Enable the INTERRUPT pin */ if (CPU_GPIO_EnableInputPin2(config->INT_Pin, FALSE, /* Glitch filter enable */ (GPIO_INTERRUPT_SERVICE_ROUTINE) &enc28j60_pre_interrupt, /* ISR */ 0, /* minor number */ GPIO_INT_EDGE_LOW , /* Interrupt edge */ RESISTOR_PULLUP) == FALSE) /* Resistor State */ { return -1; } return g_ENC28J60_Driver.m_interfaceNumber; }
BOOL ENC28J60_Driver::Close( ENC28J60_DRIVER_CONFIG* config, int index ) { NATIVE_PROFILE_HAL_DRIVERS_ETHERNET(); int retVal = -1; if(config == NULL) return FALSE; /* Disable the INTERRUPT pin */ CPU_GPIO_EnableInputPin2(config->INT_Pin, FALSE, /* Glitch filter enable */ NULL, /* ISR */ 0, /* minor number */ GPIO_INT_NONE, /* Interrupt edge */ RESISTOR_PULLUP); /* Resistor State */ /* JRT - Wait not necessary since doing a HARD_CLOSE below xn_wait_pkts_output(RTP_TRUE, 10); */ { int option_value; option_value = 1; if (xn_interface_opt(g_ENC28J60_Driver.m_interfaceNumber, IO_HARD_CLOSE, (RTP_PFCHAR)&option_value, sizeof(int)) < 0) { RTP_DEBUG_ERROR("ifrtip.c: restart test: xn_interface_opt: HARD_CLOSE failed", NOVAR, 0, 0); } } /* JRT - changed interface number from 0 */ retVal = xn_interface_close(g_ENC28J60_Driver.m_interfaceNumber); if (retVal == 0) { /* JRT - Wait not necessary since just did a HARD_CLOSE above xn_wait_pkts_output(RTP_TRUE, 60); */ return TRUE; } else { return FALSE; } }
int ENC28J60_LWIP_Driver::Open( ENC28J60_LWIP_DRIVER_CONFIG* config, int index ) { NATIVE_PROFILE_HAL_DRIVERS_ETHERNET(); /* Network interface variables */ struct ip_addr ipaddr, netmask, gw; struct netif *pNetIF; int len; const SOCK_NetworkConfiguration *iface; if(config == NULL) return -1; iface = &g_NetworkConfig.NetworkInterfaces[index]; if(0 == (iface->flags & SOCK_NETWORKCONFIGURATION_FLAGS_DHCP)) { ipaddr.addr = iface->ipaddr; gw.addr = iface->gateway; netmask.addr = iface->subnetmask; } else { /* Set network address variables - this will be set by either DHCP or when the configuration is applied */ IP4_ADDR(&gw , 0, 0, 0, 0); IP4_ADDR(&ipaddr , 0, 0, 0, 0); IP4_ADDR(&netmask, 255, 255, 255, 0); } len = g_ENC28J60_NetIF.hwaddr_len; if(len == 0 || iface->macAddressLen < len) { len = iface->macAddressLen; g_ENC28J60_NetIF.hwaddr_len = len; } memcpy(g_ENC28J60_NetIF.hwaddr, iface->macAddressBuffer, len); pNetIF = netif_add( &g_ENC28J60_NetIF, &ipaddr, &netmask, &gw, NULL, enc28j60_ethhw_init, ethernet_input ); netif_set_default( pNetIF ); LwipNetworkStatus = enc28j60_get_link_status(&config->SPI_Config); /* Initialize the continuation routine for the driver interrupt and receive */ InitContinuations( pNetIF ); /* Enable the INTERRUPT pin */ if (CPU_GPIO_EnableInputPin2(config->INT_Pin, FALSE, /* Glitch filter enable */ (GPIO_INTERRUPT_SERVICE_ROUTINE) &enc28j60_lwip_pre_interrupt, /* ISR */ &g_ENC28J60_NetIF, /* minor number */ GPIO_INT_EDGE_LOW , /* Interrupt edge */ RESISTOR_PULLUP) == FALSE) /* Resistor State */ { return -1; } /* Enable the CHIP SELECT pin */ if (CPU_GPIO_EnableInputPin (config->SPI_Config.DeviceCS, FALSE, NULL, GPIO_INT_NONE, RESISTOR_PULLUP) == FALSE) { return -1; } return g_ENC28J60_NetIF.num; }
// --------------------------------------------------------------------------- BOOL CPU_GPIO_EnableInputPin(GPIO_PIN Pin, BOOL GlitchFilterEnable, GPIO_INTERRUPT_SERVICE_ROUTINE ISR, GPIO_INT_EDGE IntEdge, GPIO_RESISTOR ResistorState) { return CPU_GPIO_EnableInputPin2(Pin, GlitchFilterEnable, ISR, 0, IntEdge, ResistorState); }