This module provides a USB Host Communications Device Class (HCDC-ECM) driver. It implements the USB HCDC_ECM (r_usb_hcdc_ecm).
The r_usb_hcdc_ecm module, when used in combination with the r_usb_basic and r_usb_hcdc modules, operates as a USB Host Communications Device Class (HCDC-ECM) driver. The HCDC-ECM conforms to subclass ethernet control model of the USB Communications Device Class (CDC) specification and enables communication with a CDC peripheral device.
This driver uses the following class request.
This driver has the following constrains.
#define USR_TEST_DOMAIN_NAME "www.freertos.org"
#define USR_TEST_PING_IP "172.217.160.174"
#define USR_PING_COUNT 100
#define USR_APP_DELAY_TICKS 100
#define USR_PING_WAIT_MS 100
#define USR_PING_DATA_SIZE 8
#define MAC_ADDRESS_BYTES 6
#define SUCCESS 0
#define PRINT_UP_MSG_DISABLE 0x01
#define PRINT_DOWN_MSG_DISABLE 0x02
#define PRINT_NWK_USR_MSG_DISABLE 0x04
#define ETHERNET_LINK_DOWN 0x01
#define ETHERNET_LINK_UP 0x00
#define IP_LINK_DOWN 0x02
#define IP_LINK_UP 0x00
char * domain_name = USR_TEST_DOMAIN_NAME;
#if (ipconfigUSE_DHCP != 0)
char ip_address_buffer[16] = {RESET_VALUE};
char * remote_ip_address = ip_address_buffer;
#else
char * remote_ip_address = "192.168.10.1";
#endif
#if (ipconfigSUPPORT_OUTGOING_PINGS == 1)
#define PING_INTERVAL_TICKS 200
uint32_t usrPingCount = RESET_VALUE;
typedef struct st_ping_data
{
uint32_t sent;
uint32_t received;
uint32_t lost;
} ping_data_t;
ping_data_t ping_data = {RESET_VALUE, RESET_VALUE, RESET_VALUE};
#endif
BaseType_t xRet;
BaseType_t xEndPointCount = 0;
static NetworkInterface_t xInterfaces[1];
static NetworkEndPoint_t xEndPoints[4];
extern NetworkInterface_t * pxFSP_Eth_FillInterfaceDescriptor(BaseType_t xEMACIndex, NetworkInterface_t * pxInterface);
#if (ipconfigUSE_DHCP != 0)
static uint8_t ucMACAddress[6] = {RESET_VALUE};
static uint8_t ucIPAddress[4] = {RESET_VALUE};
static uint8_t ucNetMask[4] = {RESET_VALUE};
static uint8_t ucGatewayAddress[4] = {RESET_VALUE};
static uint8_t ucDNSServerAddress[4] = {RESET_VALUE};
#else
static uint8_t ucMACAddress[6] = {RESET_VALUE};
static uint8_t ucIPAddress[4] = {192, 168, 10, 2};
static uint8_t ucNetMask[4] = {255, 255, 255, 0};
static uint8_t ucGatewayAddress[4] = {192, 168, 10, 0};
static uint8_t ucDNSServerAddress[4] = {RESET_VALUE};
#endif
#if (ipconfigUSE_DHCP != 0)
NetworkAddressingParameters_t xNetworkAddressing = {0, 0, 0, 0, 0};
NetworkAddressingParameters_t xNd = {RESET_VALUE, RESET_VALUE, RESET_VALUE, RESET_VALUE, RESET_VALUE};
#endif
#if (ipconfigUSE_DHCP != 0)
void updateDhcpResponseToUsr(void);
eDHCPCallbackAnswer_t xApplicationDHCPHook(eDHCPCallbackPhase_t eDHCPPhase, uint32_t ulIPAddress);
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi(eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress);
#endif
static uint32_t usr_print_ability = RESET_VALUE;
uint32_t dhcp_in_use = RESET_VALUE;
uint32_t isNetworkUp(void);
BaseType_t vSendPing(const char * pcIPAddress);
void pingSendFunc(void);
void print_ipconfig(void);
void print_pingResult(void);
void dnsQuerryFunc(char * domain_name);
BaseType_t vSendPing (const char * pcIPAddress)
{
uint32_t ulIPAddress = RESET_VALUE;
ulIPAddress = FreeRTOS_inet_addr(pcIPAddress);
return FreeRTOS_SendPingRequest(ulIPAddress, USR_PING_DATA_SIZE, USR_PING_WAIT_MS / portTICK_PERIOD_MS);
}
#if (ipconfigSUPPORT_OUTGOING_PINGS == 1)
void vApplicationPingReplyHook (ePingReplyStatus_t eStatus, uint16_t usIdentifier)
{
(void) usIdentifier;
switch (eStatus)
{
case eSuccess:
ping_data.received++;
break;
case eInvalidData:
default:
ping_data.lost++;
break;
}
}
#endif
uint32_t isNetworkUp (void)
{
BaseType_t networkUp = pdFALSE;
uint32_t status;
networkUp = FreeRTOS_IsNetworkUp();
if (pdTRUE == networkUp)
{
status = SUCCESS;
}
else
{
status = IP_LINK_DOWN;
}
return status;
}
void new_thread0_entry (void * pvParameters)
{
APP_PRINT(BANNER_INFO,
EP_VERSION,
version.version_id_b.
major,
version.version_id_b.
minor,
version.version_id_b.
patch);
APP_PRINT(ETH_PREINIT);
print_ipconfig();
pxFSP_Eth_FillInterfaceDescriptor(0, &xInterfaces[0]);
#if (ipconfigUSE_IPv4 != 0)
FreeRTOS_FillEndPoint(&(xInterfaces[0]),
&(xEndPoints[xEndPointCount]),
ucIPAddress,
ucNetMask,
ucGatewayAddress,
ucDNSServerAddress,
ucMACAddress);
#if (ipconfigUSE_DHCP != 0)
{
xEndPoints[xEndPointCount].bits.bWantDHCP = pdTRUE;
}
#endif
xEndPointCount += 1;
#endif
FreeRTOS_IPInit_Multi();
APP_PRINT(ETH_POSTINIT);
while (true)
{
if (SUCCESS == isNetworkUp())
{
if (!(PRINT_UP_MSG_DISABLE & usr_print_ability))
{
APP_PRINT("\r\nNetwork is Up");
usr_print_ability |= PRINT_UP_MSG_DISABLE;
}
if (!(PRINT_NWK_USR_MSG_DISABLE & usr_print_ability))
{
#if (ipconfigUSE_DHCP != 0)
if (dhcp_in_use)
{
updateDhcpResponseToUsr();
FreeRTOS_GetEndPointConfiguration(NULL,
&xNd.ulNetMask,
&xNd.ulGatewayAddress,
&xNd.ulDNSServerAddress,
&xEndPoints[0]);
print_ipconfig();
dnsQuerryFunc(domain_name);
pingSendFunc();
print_pingResult();
usr_print_ability |= PRINT_NWK_USR_MSG_DISABLE;
}
#else
print_ipconfig();
pingSendFunc();
print_pingResult();
usr_print_ability |= PRINT_NWK_USR_MSG_DISABLE;
#endif
}
}
else
{
if (!(PRINT_DOWN_MSG_DISABLE & usr_print_ability))
{
APP_PRINT("\r\nNetwork is Down");
usr_print_ability |= PRINT_DOWN_MSG_DISABLE;
}
else
{
APP_PRINT(".");
}
}
vTaskDelay(USR_APP_DELAY_TICKS);
}
}
#if (ipconfigUSE_DHCP != 0)
eDHCPCallbackAnswer_t xApplicationDHCPHook (eDHCPCallbackPhase_t eDHCPPhase, uint32_t ulIPAddress)
{
eDHCPCallbackAnswer_t eReturn = eDHCPContinue;
switch (eDHCPPhase)
{
case eDHCPPhasePreDiscover:
break;
case eDHCPPhasePreRequest:
xNetworkAddressing.ulDefaultIPAddress = ulIPAddress;
dhcp_in_use = 1;
break;
default:
break;
}
return eReturn;
}
eDHCPCallbackAnswer_t xApplicationDHCPHook_Multi (eDHCPCallbackPhase_t eDHCPPhase,
struct xNetworkEndPoint * pxEndPoint,
IP_Address_t * pxIPAddress)
{
eDHCPCallbackAnswer_t eReturn = eDHCPContinue;
switch (eDHCPPhase)
{
case eDHCPPhasePreDiscover:
break;
case eDHCPPhasePreRequest:
xNetworkAddressing.ulDefaultIPAddress = pxIPAddress->ulIP_IPv4;
dhcp_in_use = 1;
break;
default:
break;
}
return eReturn;
}
#endif
void pingSendFunc (void)
{
#if (ipconfigSUPPORT_OUTGOING_PINGS == 1)
BaseType_t status = pdFALSE;
APP_PRINT("\r\n");
while (usrPingCount < USR_PING_COUNT)
{
status = vSendPing((char *) remote_ip_address);
if (status != pdFALSE)
{
ping_data.sent++;
APP_PRINT("!");
}
else
{
ping_data.lost++;
APP_PRINT(".");
}
usrPingCount++;
vTaskDelay(PING_INTERVAL_TICKS);
}
#endif
}
void print_pingResult (void)
{
#if (ipconfigSUPPORT_OUTGOING_PINGS == 1)
APP_PRINT("\r\n \r\nPing Statistics for %s :\r\n", (char *) remote_ip_address);
APP_PRINT("\r\nPackets: Sent = %02d, Received = %02d, Lost = %02d \r\n",
ping_data.sent,
ping_data.received,
ping_data.lost);
#endif
}
void print_ipconfig (void)
{
#if (ipconfigUSE_DHCP != 0)
if (dhcp_in_use)
{
ucNetMask[3] = (uint8_t) ((xNd.ulNetMask & 0xFF000000) >> 24);
ucNetMask[2] = (uint8_t) ((xNd.ulNetMask & 0x00FF0000) >> 16);
ucNetMask[1] = (uint8_t) ((xNd.ulNetMask & 0x0000FF00) >> 8);
ucNetMask[0] = (uint8_t) (xNd.ulNetMask & 0x000000FF);
ucGatewayAddress[3] = (uint8_t) ((xNd.ulGatewayAddress & 0xFF000000) >> 24);;
ucGatewayAddress[2] = (uint8_t) ((xNd.ulGatewayAddress & 0x00FF0000) >> 16);
ucGatewayAddress[1] = (uint8_t) ((xNd.ulGatewayAddress & 0x0000FF00) >> 8);
ucGatewayAddress[0] = (uint8_t) (xNd.ulGatewayAddress & 0x000000FF);
ucDNSServerAddress[3] = (uint8_t) ((xNd.ulDNSServerAddress & 0xFF000000) >> 24);
ucDNSServerAddress[2] = (uint8_t) ((xNd.ulDNSServerAddress & 0x00FF0000) >> 16);
ucDNSServerAddress[1] = (uint8_t) ((xNd.ulDNSServerAddress & 0x0000FF00) >> 8);
ucDNSServerAddress[0] = (uint8_t) (xNd.ulDNSServerAddress & 0x000000FF);
ucIPAddress[3] = (uint8_t) ((xNd.ulDefaultIPAddress & 0xFF000000) >> 24);
ucIPAddress[2] = (uint8_t) ((xNd.ulDefaultIPAddress & 0x00FF0000) >> 16);
ucIPAddress[1] = (uint8_t) ((xNd.ulDefaultIPAddress & 0x0000FF00) >> 8);
ucIPAddress[0] = (uint8_t) (xNd.ulDefaultIPAddress & 0x000000FF);
}
#endif
APP_PRINT("\r\nEthernet adapter for Renesas "KIT_NAME ":\r\n")
APP_PRINT("\tDescription . . . . . . . . . . . : Renesas "KIT_NAME " Ethernet\r\n");
APP_PRINT("\tPhysical Address. . . . . . . . . : %02x-%02x-%02x-%02x-%02x-%02x\r\n",
ucMACAddress[0],
ucMACAddress[1],
ucMACAddress[2],
ucMACAddress[3],
ucMACAddress[4],
ucMACAddress[5]);
APP_PRINT("\tDHCP Enabled. . . . . . . . . . . : %s\r\n", dhcp_in_use ? "Yes" : "No")
APP_PRINT("\tIPv4 Address. . . . . . . . . . . : %d.%d.%d.%d\r\n",
ucIPAddress[0],
ucIPAddress[1],
ucIPAddress[2],
ucIPAddress[3]);
APP_PRINT("\tSubnet Mask . . . . . . . . . . . : %d.%d.%d.%d\r\n",
ucNetMask[0],
ucNetMask[1],
ucNetMask[2],
ucNetMask[3]);
APP_PRINT("\tDefault Gateway . . . . . . . . . : %d.%d.%d.%d\r\n",
ucGatewayAddress[0],
ucGatewayAddress[1],
ucGatewayAddress[2],
ucGatewayAddress[3]);
APP_PRINT("\tDNS Servers . . . . . . . . . . . : %d.%d.%d.%d\r\n",
ucDNSServerAddress[0],
ucDNSServerAddress[1],
ucDNSServerAddress[2],
ucDNSServerAddress[3]);
}
void dnsQuerryFunc (char * domain)
{
uint32_t ulIPAddress = RESET_VALUE;
int8_t cBuffer[16] = {RESET_VALUE};
ulIPAddress = FreeRTOS_gethostbyname((char *) domain);
if (ulIPAddress != 0)
{
FreeRTOS_inet_ntoa(ulIPAddress, (char *) cBuffer);
APP_PRINT("\r\nDNS Lookup for \"www.freertos.org\" is : %s \r\n", cBuffer);
memcpy((void *) remote_ip_address, (const void *) cBuffer, strlen((const char *) cBuffer) + 1);
}
else
{
APP_PRINT("\r\nDNS Lookup failed for \"www.freertos.org\" \r\n");
remote_ip_address = USR_TEST_PING_IP;
}
}
#if (ipconfigUSE_DHCP != 0)
void updateDhcpResponseToUsr (void)
{
if (dhcp_in_use)
{
memcpy(&xNd, &xNetworkAddressing, sizeof(xNd));
}
}
#endif
#if (ipconfigDHCP_REGISTER_HOSTNAME == 1)
const char * pcApplicationHostnameHook (void)
{
return KIT_NAME;
}
#endif
{
uint8_t * mac_address;
FreeRTOS_UpdateMACAddress(mac_address);
memcpy(ucMACAddress, mac_address, MAC_ADDRESS_BYTES);
}