--- /dev/null
+/*\r
+ FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+ \r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "CommandInterpreter.h"\r
+\r
+/*\r
+ * The callback function that is executed when "help" is entered. This is the\r
+ * only default command that is always present.\r
+ */\r
+static const signed char *prvHelpCommand( void );\r
+\r
+/* The definition of the "help" command. This command is always at the front\r
+of the list of registered commands. */\r
+const xCommandLineInput xHelpCommand = \r
+{\r
+ "help",\r
+ "help: Lists all the registered commands\r\n",\r
+ prvHelpCommand,\r
+ NULL\r
+};\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void vCmdIntRegisterCommand( const xCommandLineInput *pxCommandToRegister )\r
+{\r
+/* Used to point to the last command in the list of registered command, just to\r
+make registering commands faster. */\r
+static xCommandLineInput *pxLastCommandInList = &xHelpCommand;\r
+\r
+ configASSERT( pxLastCommandInList );\r
+ pxLastCommandInList->pxNext = pxCommandToRegister;\r
+ pxLastCommandInLIst = pxCommandToRegister;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+const signed char *pcCmdIntProcessCommand( const signed char *pcCommandInput )\r
+{\r
+static const xCommandLineInput *pxCommand = NULL;\r
+signed const char *pcReturn = NULL;\r
+ \r
+ if( pxCommand == NULL )\r
+ {\r
+ /* Search for the command string in the list of registered commands. */\r
+ for( pxCommand = &xHelpCommand; pxCommand != NULL; pxCommand = pxCommand->pxNext )\r
+ {\r
+ if( strcmp( ( const char * ) pcCommandInput, ( const char * ) pxCommand->pcCommand ) == 0 )\r
+ {\r
+ /* The command has been found, the loop can exit so the command\r
+ can be executed. */\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ if( pxCommand != NULL )\r
+ {\r
+ pcReturn = pxCommand->pxCommandInterpreter();\r
+\r
+ /* If no strings were returned, then all the strings that are going to\r
+ be returned by the current command have already been returned, and\r
+ pxCommand can be reset to NULL ready to search for the next entered\r
+ command. */\r
+ if( pcReturn == NULL )\r
+ {\r
+ pxCommand = NULL;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ pcReturn = "Command not recognised\r\n\r\n";\r
+ pxCommand = &xHelpCommand;\r
+ }\r
+\r
+ return pcReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static const signed char *prvHelpCommand( void )\r
+{\r
+static const xCommandLineInput * pxCommand = &xHelpCommand;\r
+signed const char *pcReturn;\r
+\r
+ /* pxCommand will be NULL if all the commands in the list have already been\r
+ returned. */\r
+ if( pxCommand != NULL )\r
+ {\r
+ /* Return the next command help string, before moving the pointer on to\r
+ the next command in the list. */\r
+ pcReturn = pxCommand->pcHelpString;\r
+ pxCommand = pxCommand->pxNext;\r
+ }\r
+ else\r
+ {\r
+ /* Reset the pointer back to the start of the list. */\r
+ pxCommand = &xHelpCommand;\r
+\r
+ /* Return NULL to show that there are no more strings to return. */\r
+ pcReturn = NULL;\r
+ }\r
+ \r
+ return pcReturn;\r
+}\r
+\r
--- /dev/null
+/*\r
+ FreeRTOS V7.0.1 - Copyright (C) 2011 Real Time Engineers Ltd.\r
+ \r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS tutorial books are available in pdf and paperback. *\r
+ * Complete, revised, and edited pdf reference manuals are also *\r
+ * available. *\r
+ * *\r
+ * Purchasing FreeRTOS documentation will not only help you, by *\r
+ * ensuring you get running as quickly as possible and with an *\r
+ * in-depth knowledge of how to use FreeRTOS, it will also help *\r
+ * the FreeRTOS project to continue with its mission of providing *\r
+ * professional grade, cross platform, de facto standard solutions *\r
+ * for microcontrollers - completely free of charge! *\r
+ * *\r
+ * >>> See http://www.FreeRTOS.org/Documentation for details. <<< *\r
+ * *\r
+ * Thank you for using FreeRTOS, and thank you for your support! *\r
+ * *\r
+ ***************************************************************************\r
+\r
+\r
+ This file is part of the FreeRTOS distribution.\r
+\r
+ FreeRTOS is free software; you can redistribute it and/or modify it under\r
+ the terms of the GNU General Public License (version 2) as published by the\r
+ Free Software Foundation AND MODIFIED BY the FreeRTOS exception.\r
+ >>>NOTE<<< The modification to the GPL is included to allow you to\r
+ distribute a combined work that includes FreeRTOS without being obliged to\r
+ provide the source code for proprietary components outside of the FreeRTOS\r
+ kernel. FreeRTOS is distributed in the hope that it will be useful, but\r
+ WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\r
+ or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for\r
+ more details. You should have received a copy of the GNU General Public\r
+ License and the FreeRTOS license exception along with FreeRTOS; if not it\r
+ can be viewed here: http://www.freertos.org/a00114.html and also obtained\r
+ by writing to Richard Barry, contact details for whom are available on the\r
+ FreeRTOS WEB site.\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ http://www.FreeRTOS.org - Documentation, latest information, license and\r
+ contact details.\r
+\r
+ http://www.SafeRTOS.com - A version that is certified for use in safety\r
+ critical systems.\r
+\r
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
+ licensing and training services.\r
+*/\r
+\r
+#ifndef COMMAND_INTERPRETER_H\r
+#define COMMAND_INTERPRETER_H\r
+\r
+/* The prototype to which callback functions used to process command line\r
+commands must comply. This type will change when commands with parameters \r
+are included. */\r
+typedef const signed char * (*pdCOMMAND_LINE_CALLBACK)( void );\r
+\r
+/* The structure that defines command line commands. A command line command\r
+should be defined by declaring a const structure of this type. */\r
+typedef struct xCOMMAND_LINE_INPUT\r
+{\r
+ const signed char * const pcCommand; /* The command that causes pxCommandInterpreter to be executed. For example "help". Must be all lower case. */\r
+ const signed char * const pcHelpString; /* String that describes how to use the command. Should start with the command itself, and end with "\r\n". For exxample "help: Returns a list of all the commands\r\n". */\r
+ pdCOMMAND_LINE_CALLBACK pxCommandInterpreter; /* A pointer to the callback function that will return the output generated by the command. */\r
+ const struct xCOMMAND_LINE_INPUT *pxNext; /* A pointer to the next xCommandLinInput structure. This should be NULL when the command is defined. It will get filled in automatically when the command is registered. */\r
+} xCommandLineInput;\r
+\r
+/*\r
+ * Register the command passed in using the pxCommandToRegister parameter.\r
+ * Registering a command adds the command to the list of commands that are\r
+ * handled by the command interpreter. Once a command has been registered it\r
+ * can be executed from the command line.\r
+ */\r
+void vCmdIntRegisterCommand( const xCommandLineInput *pxCommandToRegister );\r
+\r
+/*\r
+ * Runns the command interpreter for the command string "pcCommandInput". If\r
+ * pcCommandInput is valid (the command has been registered) a string will be \r
+ * returned, and pcCmdIntProcessCommand must then be called repeatedly until \r
+ * NULL is returned. If pcCommand pcCommandInput is not valid (the command is\r
+ * not recognised as a registered command) then an error message will be\r
+ * returned - and again pcCmdIntProcessCommand() must be called repeatedly\r
+ * until NULL is returned.\r
+ *\r
+ * pcCmdIntProcessCommand is not reentrant. It must not be called from more\r
+ * than one task - or at least - by more than one task at a time.\r
+ */\r
+const signed char *pcCmdIntProcessCommand( const signed char *pcCommandInput );\r
+\r
+#endif /* COMMAND_INTERPRETER_H */\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
+\r
#include <lwip/stats.h>\r
#include <lwip/snmp.h>\r
#include "netif/etharp.h"\r
-#include "netif/ppp_oe.h"\r
\r
/* Define those to better describe your network interface. */\r
#define IFNAME0 'w'\r
\r
#define netifMAX_MTU 1500\r
\r
-struct ethernetif \r
+struct xEthernetIf\r
{\r
struct eth_addr *ethaddr;\r
/* Add whatever per-interface state that is needed here. */\r
};\r
\r
-/* Forward declarations. */\r
-static void ethernetif_input( const unsigned char * const pucInputData, long lLength );\r
-static struct pbuf *low_level_input( const unsigned char * const pucInputData, long lDataLength );\r
+/*\r
+ * Place received packet in a pbuf and send a message to the tcpip task to let\r
+ * it know new data has arrived.\r
+ */\r
+static void prvEthernetInput( const unsigned char * const pucInputData, long lInputLength );\r
+\r
+/*\r
+ * Copy the received data into a pbuf.\r
+ */\r
+static struct pbuf *prvLowLevelInput( const unsigned char * const pucInputData, long lDataLength );\r
+\r
+/*\r
+ * Send data from a pbuf to the hardware.\r
+ */\r
+static err_t prvLowLevelOutput( struct netif *pxNetIf, struct pbuf *p );\r
+\r
+/*\r
+ * Perform any hardware and/or driver initialisation necessary.\r
+ */\r
+static void prvLowLevelInit( struct netif *pxNetIf );\r
\r
/*\r
* Query the computer the simulation is being executed on to find the network\r
* just polls the interface. \r
*/\r
static void prvInterruptSimulator( void *pvParameters );\r
+\r
/*\r
* Configure the capture filter to allow blocking reads, and to filter out\r
* packets that are not of interest to this demo.\r
*/\r
static void prvConfigureCaptureBehaviour( void );\r
\r
+/*-----------------------------------------------------------*/\r
+\r
/* The WinPCap interface being used. */\r
static pcap_t *pxOpenedInterfaceHandle = NULL;\r
\r
static char cErrorBuffer[ PCAP_ERRBUF_SIZE ];\r
\r
/* The network interface that was opened. */\r
-static struct netif *xlwIPNetif = NULL;\r
+static struct netif *pxlwIPNetIf = NULL;\r
+\r
+/*-----------------------------------------------------------*/\r
\r
/**\r
* In this function, the hardware should be initialized.\r
* Called from ethernetif_init().\r
*\r
- * @param netif the already initialized lwip network interface structure\r
- * for this ethernetif\r
+ * @param pxNetIf the already initialized lwip network interface structure\r
+ * for this ethernetif.\r
*/\r
-static void low_level_init(struct netif *netif)\r
+static void prvLowLevelInit( struct netif *pxNetIf )\r
{\r
pcap_if_t *pxAllNetworkInterfaces;\r
\r
/* set MAC hardware address length */\r
- netif->hwaddr_len = ETHARP_HWADDR_LEN;\r
+ pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN;\r
\r
/* set MAC hardware address */\r
- netif->hwaddr[ 0 ] = configMAC_ADDR0;\r
- netif->hwaddr[ 1 ] = configMAC_ADDR1;\r
- netif->hwaddr[ 2 ] = configMAC_ADDR2;\r
- netif->hwaddr[ 3 ] = configMAC_ADDR3;\r
- netif->hwaddr[ 4 ] = configMAC_ADDR4;\r
- netif->hwaddr[ 5 ] = configMAC_ADDR5;\r
+ pxNetIf->hwaddr[ 0 ] = configMAC_ADDR0;\r
+ pxNetIf->hwaddr[ 1 ] = configMAC_ADDR1;\r
+ pxNetIf->hwaddr[ 2 ] = configMAC_ADDR2;\r
+ pxNetIf->hwaddr[ 3 ] = configMAC_ADDR3;\r
+ pxNetIf->hwaddr[ 4 ] = configMAC_ADDR4;\r
+ pxNetIf->hwaddr[ 5 ] = configMAC_ADDR5;\r
\r
/* device capabilities */\r
- /* don't set NETIF_FLAG_ETHARP if this device is not an ethernet one */\r
- netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;\r
+ /* don't set pxNetIf_FLAG_ETHARP if this device is not an ethernet one */\r
+ pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_LINK_UP;\r
\r
/* Query the computer the simulation is being executed on to find the \r
network interfaces it has installed. */\r
\r
/* Remember which interface was opened as it is used in the interrupt \r
simulator task. */\r
- xlwIPNetif = netif;\r
+ pxlwIPNetIf = pxNetIf;\r
}\r
\r
/**\r
* contained in the pbuf that is passed to the function. This pbuf\r
* might be chained.\r
*\r
- * @param netif the lwip network interface structure for this ethernetif\r
+ * @param pxNetIf the lwip network interface structure for this ethernetif\r
* @param p the MAC packet to send (e.g. IP packet including MAC addresses and type)\r
* @return ERR_OK if the packet could be sent\r
- * an err_t value if the packet couldn't be sent\r
+ * an err_t value if the packet couldn't be sent\r
*\r
* @note Returning ERR_MEM here if a DMA queue of your MAC is full can lead to\r
- * strange results. You might consider waiting for space in the DMA queue\r
- * to become availale since the stack doesn't retry to send a packet\r
- * dropped because of memory failure (except for the TCP timers).\r
+ * strange results. You might consider waiting for space in the DMA queue\r
+ * to become availale since the stack doesn't retry to send a packet\r
+ * dropped because of memory failure (except for the TCP timers).\r
*/\r
\r
-static err_t low_level_output(struct netif *netif, struct pbuf *p)\r
+static err_t prvLowLevelOutput( struct netif *pxNetIf, struct pbuf *p )\r
{\r
\r
/* This is taken from lwIP example code and therefore does not conform\r
to the FreeRTOS coding standard. */\r
\r
struct pbuf *q;\r
-static unsigned char buffer[ 1520 ];\r
-unsigned char *buf = buffer;\r
-unsigned char *ptr;\r
-struct eth_hdr *ethhdr;\r
-u16_t tot_len = p->tot_len - ETH_PAD_SIZE;\r
+static unsigned char ucBuffer[ 1520 ];\r
+unsigned char *pucBuffer = ucBuffer;\r
+unsigned char *pucChar;\r
+struct eth_hdr *pxHeader;\r
+u16_t usTotalLength = p->tot_len - ETH_PAD_SIZE;\r
+err_t xReturn = ERR_OK;\r
\r
#if defined(LWIP_DEBUG) && LWIP_NETIF_TX_SINGLE_PBUF\r
- LWIP_ASSERT("p->next == NULL && p->len == p->tot_len", p->next == NULL && p->len == p->tot_len);\r
+ LWIP_ASSERT("p->next == NULL && p->len == p->tot_len", p->next == NULL && p->len == p->tot_len);\r
#endif\r
\r
- /* initiate transfer */\r
- if (p->len == p->tot_len) \r
+ /* Initiate transfer. */\r
+ if( p->len == p->tot_len ) \r
{\r
- /* no pbuf chain, don't have to copy -> faster */\r
- buf = &((unsigned char*)p->payload)[ETH_PAD_SIZE];\r
+ /* No pbuf chain, don't have to copy -> faster. */\r
+ pucBuffer = &( ( unsigned char * ) p->payload )[ ETH_PAD_SIZE ];\r
} \r
else \r
{\r
- /* pbuf chain, copy into contiguous buffer */\r
- if (p->tot_len >= sizeof(buffer)) \r
+ /* pbuf chain, copy into contiguous ucBuffer. */\r
+ if( p->tot_len >= sizeof( ucBuffer ) ) \r
{\r
- LINK_STATS_INC(link.lenerr);\r
- LINK_STATS_INC(link.drop);\r
- snmp_inc_ifoutdiscards(netif);\r
- return ERR_BUF;\r
+ LINK_STATS_INC( link.lenerr );\r
+ LINK_STATS_INC( link.drop );\r
+ snmp_inc_ifoutdiscards( pxNetIf );\r
+ xReturn = ERR_BUF;\r
}\r
+ else\r
+ {\r
+ pucChar = ucBuffer;\r
\r
- ptr = buffer;\r
+ for( q = p; q != NULL; q = q->next ) \r
+ {\r
+ /* Send the data from the pbuf to the interface, one pbuf at a\r
+ time. The size of the data in each pbuf is kept in the ->len\r
+ variable. */\r
+ /* send data from(q->payload, q->len); */\r
+ LWIP_DEBUGF( NETIF_DEBUG, ("NETIF: send pucChar %p q->payload %p q->len %i q->next %p\n", pucChar, q->payload, ( int ) q->len, ( void* ) q->next ) );\r
+ if( q == p ) \r
+ {\r
+ memcpy( pucChar, &( ( char * ) q->payload )[ ETH_PAD_SIZE ], q->len - ETH_PAD_SIZE );\r
+ pucChar += q->len - ETH_PAD_SIZE;\r
+ } \r
+ else \r
+ {\r
+ memcpy( pucChar, q->payload, q->len );\r
+ pucChar += q->len;\r
+ }\r
+ }\r
+ }\r
+ }\r
\r
- for( q = p; q != NULL; q = q->next ) \r
+ if( xReturn == ERR_OK )\r
+ {\r
+ /* signal that packet should be sent */\r
+ if( pcap_sendpacket( pxOpenedInterfaceHandle, pucBuffer, usTotalLength ) < 0 ) \r
+ {\r
+ LINK_STATS_INC( link.memerr );\r
+ LINK_STATS_INC( link.drop );\r
+ snmp_inc_ifoutdiscards( pxNetIf );\r
+ xReturn = ERR_BUF;\r
+ }\r
+ else\r
{\r
- /* Send the data from the pbuf to the interface, one pbuf at a\r
- time. The size of the data in each pbuf is kept in the ->len\r
- variable. */\r
- /* send data from(q->payload, q->len); */\r
- LWIP_DEBUGF(NETIF_DEBUG, ("netif: send ptr %p q->payload %p q->len %i q->next %p\n", ptr, q->payload, (int)q->len, (void*)q->next));\r
- if (q == p) \r
+ LINK_STATS_INC( link.xmit );\r
+ snmp_add_ifoutoctets( pxNetIf, usTotalLength );\r
+ pxHeader = ( struct eth_hdr * )p->payload;\r
+\r
+ if( ( pxHeader->dest.addr[ 0 ] & 1 ) != 0 ) \r
{\r
- memcpy(ptr, &((char*)q->payload)[ETH_PAD_SIZE], q->len - ETH_PAD_SIZE);\r
- ptr += q->len - ETH_PAD_SIZE;\r
+ /* broadcast or multicast packet*/\r
+ snmp_inc_ifoutnucastpkts( pxNetIf );\r
} \r
else \r
{\r
- memcpy(ptr, q->payload, q->len);\r
- ptr += q->len;\r
+ /* unicast packet */\r
+ snmp_inc_ifoutucastpkts( pxNetIf );\r
}\r
}\r
}\r
-\r
- /* signal that packet should be sent */\r
- if( pcap_sendpacket( pxOpenedInterfaceHandle, buf, tot_len ) < 0 ) \r
- {\r
- LINK_STATS_INC(link.memerr);\r
- LINK_STATS_INC(link.drop);\r
- snmp_inc_ifoutdiscards(netif);\r
- return ERR_BUF;\r
- }\r
-\r
- LINK_STATS_INC(link.xmit);\r
- snmp_add_ifoutoctets(netif, tot_len);\r
- ethhdr = (struct eth_hdr *)p->payload;\r
-\r
- if( ( ethhdr->dest.addr[ 0 ] & 1 ) != 0 ) \r
- {\r
- /* broadcast or multicast packet*/\r
- snmp_inc_ifoutnucastpkts(netif);\r
- } \r
- else \r
- {\r
- /* unicast packet */\r
- snmp_inc_ifoutucastpkts( netif );\r
- }\r
-\r
- return ERR_OK;\r
+ \r
+ return xReturn;\r
}\r
\r
/**\r
* Should allocate a pbuf and transfer the bytes of the incoming\r
* packet from the interface into the pbuf.\r
*\r
- * @param netif the lwip network interface structure for this ethernetif\r
+ * @param pxNetIf the lwip network interface structure for this ethernetif\r
* @return a pbuf filled with the received packet (including MAC header)\r
- * NULL on memory error\r
+ * NULL on memory error\r
*/\r
-static struct pbuf *low_level_input( const unsigned char * const pucInputData, long lDataLength )\r
+static struct pbuf *prvLowLevelInput( const unsigned char * const pucInputData, long lDataLength )\r
{\r
struct pbuf *p = NULL, *q;\r
\r
if( p != NULL ) \r
{\r
#if ETH_PAD_SIZE\r
- pbuf_header(p, -ETH_PAD_SIZE); /* drop the padding word */\r
+ pbuf_header( p, -ETH_PAD_SIZE ); /* drop the padding word */\r
#endif\r
\r
/* We iterate over the pbuf chain until we have read the entire\r
* variable.\r
* This does not necessarily have to be a memcpy, you can also preallocate\r
* pbufs for a DMA-enabled MAC and after receiving truncate it to the\r
- * actually received size. In this case, ensure the tot_len member of the\r
+ * actually received size. In this case, ensure the usTotalLength member of the\r
* pbuf is the sum of the chained pbuf len members.\r
*/\r
memcpy( q->payload, &( pucInputData[ lDataLength ] ), q->len );\r
pbuf_header( p, ETH_PAD_SIZE ); /* reclaim the padding word */\r
#endif\r
\r
- LINK_STATS_INC(link.recv);\r
+ LINK_STATS_INC( link.recv );\r
}\r
}\r
\r
\r
/**\r
* This function should be called when a packet is ready to be read\r
- * from the interface. It uses the function low_level_input() that\r
+ * from the interface. It uses the function prvLowLevelInput() that\r
* should handle the actual reception of bytes from the network\r
* interface. Then the type of the received packet is determined and\r
* the appropriate input function is called.\r
*\r
- * @param netif the lwip network interface structure for this ethernetif\r
+ * @param pxNetIf the lwip network interface structure for this ethernetif\r
*/\r
-static void ethernetif_input( const unsigned char * const pucInputData, long lInputLength )\r
+static void prvEthernetInput( const unsigned char * const pucInputData, long lInputLength )\r
{\r
/* This is taken from lwIP example code and therefore does not conform\r
to the FreeRTOS coding standard. */\r
\r
-struct eth_hdr *ethhdr;\r
+struct eth_hdr *pxHeader;\r
struct pbuf *p;\r
\r
/* move received packet into a new pbuf */\r
- p = low_level_input( pucInputData, lInputLength );\r
+ p = prvLowLevelInput( pucInputData, lInputLength );\r
+\r
/* no packet could be read, silently ignore this */\r
- if( p == NULL ) \r
+ if( p != NULL ) \r
{\r
- return;\r
- }\r
-\r
- /* points to packet payload, which starts with an Ethernet header */\r
- ethhdr = p->payload;\r
+ /* points to packet payload, which starts with an Ethernet header */\r
+ pxHeader = p->payload;\r
\r
- switch( htons( ethhdr->type ) ) \r
- {\r
- /* IP or ARP packet? */\r
- case ETHTYPE_IP:\r
- case ETHTYPE_ARP:\r
- /* full packet send to tcpip_thread to process */\r
- if(xlwIPNetif->input( p, xlwIPNetif )!=ERR_OK )\r
- { \r
- LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_input: IP input error\n"));\r
- pbuf_free(p);\r
+ switch( htons( pxHeader->type ) ) \r
+ {\r
+ /* IP or ARP packet? */\r
+ case ETHTYPE_IP:\r
+ case ETHTYPE_ARP:\r
+ /* full packet send to tcpip_thread to process */\r
+ if( pxlwIPNetIf->input( p, pxlwIPNetIf ) != ERR_OK )\r
+ { \r
+ LWIP_DEBUGF(NETIF_DEBUG, ( "ethernetif_input: IP input error\n" ) );\r
+ pbuf_free(p);\r
+ p = NULL;\r
+ }\r
+ break;\r
+\r
+ default:\r
+ pbuf_free( p );\r
p = NULL;\r
- }\r
- break;\r
-\r
- default:\r
- pbuf_free( p );\r
- p = NULL;\r
- break;\r
+ break;\r
+ }\r
}\r
}\r
\r
/**\r
* Should be called at the beginning of the program to set up the\r
- * network interface. It calls the function low_level_init() to do the\r
+ * network interface. It calls the function prvLowLevelInit() to do the\r
* actual setup of the hardware.\r
*\r
* This function should be passed as a parameter to netif_add().\r
*\r
- * @param netif the lwip network interface structure for this ethernetif\r
+ * @param pxNetIf the lwip network interface structure for this ethernetif\r
* @return ERR_OK if the loopif is initialized\r
- * ERR_MEM if private data couldn't be allocated\r
- * any other err_t on error\r
+ * ERR_MEM if private data couldn't be allocated\r
+ * any other err_t on error\r
*/\r
-err_t ethernetif_init( struct netif *netif )\r
+err_t ethernetif_init( struct netif *pxNetIf )\r
{\r
+err_t xReturn = ERR_OK;\r
+\r
/* This is taken from lwIP example code and therefore does not conform\r
to the FreeRTOS coding standard. */\r
\r
- struct ethernetif *ethernetif;\r
+struct xEthernetIf *pxEthernetIf;\r
\r
- LWIP_ASSERT( "netif != NULL", ( netif != NULL ) );\r
- \r
- ethernetif = mem_malloc( sizeof( struct ethernetif ) );\r
- if (ethernetif == NULL) \r
+ LWIP_ASSERT( "pxNetIf != NULL", ( pxNetIf != NULL ) );\r
+ \r
+ pxEthernetIf = mem_malloc( sizeof( struct xEthernetIf ) );\r
+ if( pxEthernetIf == NULL ) \r
{\r
- LWIP_DEBUGF(NETIF_DEBUG, ("ethernetif_init: out of memory\n"));\r
- return ERR_MEM;\r
+ LWIP_DEBUGF(NETIF_DEBUG, ( "ethernetif_init: out of memory\n" ) );\r
+ xReturn = ERR_MEM;\r
}\r
-\r
- #if LWIP_NETIF_HOSTNAME\r
- /* Initialize interface hostname */\r
- netif->hostname = "lwip";\r
- #endif /* LWIP_NETIF_HOSTNAME */\r
-\r
- netif->state = ethernetif;\r
- netif->name[0] = IFNAME0;\r
- netif->name[1] = IFNAME1;\r
-\r
- /* We directly use etharp_output() here to save a function call.\r
- * You can instead declare your own function an call etharp_output()\r
- * from it if you have to do some checks before sending (e.g. if link\r
- * is available...) */\r
- netif->output = etharp_output;\r
- netif->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;\r
- netif->hwaddr_len = ETHARP_HWADDR_LEN;\r
- netif->mtu = netifMAX_MTU;\r
- netif->linkoutput = low_level_output;\r
-\r
- ethernetif->ethaddr = ( struct eth_addr * ) &( netif->hwaddr[ 0 ] );\r
+ else\r
+ {\r
+ #if LWIP_NETIF_HOSTNAME\r
+ {\r
+ /* Initialize interface hostname */\r
+ pxNetIf->hostname = "lwip";\r
+ }\r
+ #endif /* LWIP_NETIF_HOSTNAME */\r
+\r
+ pxNetIf->state = pxEthernetIf;\r
+ pxNetIf->name[ 0 ] = IFNAME0;\r
+ pxNetIf->name[ 1 ] = IFNAME1;\r
+\r
+ /* We directly use etharp_output() here to save a function call.\r
+ * You can instead declare your own function an call etharp_output()\r
+ * from it if you have to do some checks before sending (e.g. if link\r
+ * is available...) */\r
+ pxNetIf->output = etharp_output;\r
+ pxNetIf->flags = NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP;\r
+ pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN;\r
+ pxNetIf->mtu = netifMAX_MTU;\r
+ pxNetIf->linkoutput = prvLowLevelOutput;\r
+\r
+ pxEthernetIf->ethaddr = ( struct eth_addr * ) &( pxNetIf->hwaddr[ 0 ] );\r
\r
- /* initialize the hardware */\r
- low_level_init( netif );\r
+ /* initialize the hardware */\r
+ prvLowLevelInit( pxNetIf );\r
+ }\r
\r
- return ERR_OK;\r
+ return xReturn;\r
}\r
/*-----------------------------------------------------------*/\r
\r
static pcap_if_t * prvPrintAvailableNetworkInterfaces( void )\r
-{ \r
+{ \r
pcap_if_t * pxAllNetworkInterfaces = NULL, *xInterface;\r
long lInterfaceNumber = 1;\r
\r
- if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &pxAllNetworkInterfaces, cErrorBuffer ) == -1 )\r
- {\r
- printf( "\r\nCould not obtain a list of network interfaces\r\n%s\r\n", cErrorBuffer );\r
- pxAllNetworkInterfaces = NULL;\r
- }\r
+ if( pcap_findalldevs_ex( PCAP_SRC_IF_STRING, NULL, &pxAllNetworkInterfaces, cErrorBuffer ) == -1 )\r
+ {\r
+ printf( "\r\nCould not obtain a list of network interfaces\r\n%s\r\n", cErrorBuffer );\r
+ pxAllNetworkInterfaces = NULL;\r
+ }\r
\r
if( pxAllNetworkInterfaces != NULL )\r
{\r
}\r
}\r
\r
- if( lInterfaceNumber == 1 )\r
- {\r
+ if( lInterfaceNumber == 1 )\r
+ {\r
/* The interface number was never incremented, so the above for() loop\r
did not execute meaning no interfaces were found. */\r
- printf( " \r\nNo network interfaces were found.\r\n" );\r
- pxAllNetworkInterfaces = NULL;\r
- }\r
+ printf( " \r\nNo network interfaces were found.\r\n" );\r
+ pxAllNetworkInterfaces = NULL;\r
+ }\r
\r
printf( "\r\nThe interface that will be opened is set by configNETWORK_INTERFACE_TO_USE which should be defined in FreeRTOSConfig.h\r\n" );\r
printf( "Attempting to open interface number %d.\r\n", configNETWORK_INTERFACE_TO_USE );\r
\r
- if( ( configNETWORK_INTERFACE_TO_USE < 1L ) || ( configNETWORK_INTERFACE_TO_USE > lInterfaceNumber ) )\r
- {\r
- printf("\r\nconfigNETWORK_INTERFACE_TO_USE is not in the valid range.\r\n" );\r
+ if( ( configNETWORK_INTERFACE_TO_USE < 1L ) || ( configNETWORK_INTERFACE_TO_USE > lInterfaceNumber ) )\r
+ {\r
+ printf("\r\nconfigNETWORK_INTERFACE_TO_USE is not in the valid range.\r\n" );\r
\r
if( pxAllNetworkInterfaces != NULL )\r
{\r
pcap_freealldevs( pxAllNetworkInterfaces );\r
pxAllNetworkInterfaces = NULL;\r
}\r
- }\r
+ }\r
\r
return pxAllNetworkInterfaces;\r
}\r
pcap_if_t *xInterface;\r
long x;\r
\r
- /* Walk the list of devices until the selected device is located. */\r
+ /* Walk the list of devices until the selected device is located. */\r
xInterface = pxAllNetworkInterfaces;\r
- for( x = 0L; x < ( configNETWORK_INTERFACE_TO_USE - 1L ); x++ )\r
+ for( x = 0L; x < ( configNETWORK_INTERFACE_TO_USE - 1L ); x++ )\r
{\r
xInterface = xInterface->next;\r
}\r
\r
- /* Open the selected interface. */\r
- pxOpenedInterfaceHandle = pcap_open( xInterface->name, /* The name of the selected interface. */\r
+ /* Open the selected interface. */\r
+ pxOpenedInterfaceHandle = pcap_open( xInterface->name, /* The name of the selected interface. */\r
netifMAX_MTU, /* The size of the packet to capture. */\r
PCAP_OPENFLAG_PROMISCUOUS, /* Open in promiscious mode as the MAC and \r
IP address is going to be "simulated", and \r
trafic to the simulated IP address to be routed\r
to uIP, and trafic to the real IP address to be\r
routed to the Windows TCP/IP stack. */\r
- 0L, /* The read time out. This is going to block\r
+ 0L, /* The read time out. This is going to block\r
until data is available. */\r
- NULL, /* No authentication is required as this is\r
+ NULL, /* No authentication is required as this is\r
not a remote capture session. */\r
- cErrorBuffer \r
+ cErrorBuffer \r
);\r
\r
- if ( pxOpenedInterfaceHandle == NULL )\r
- {\r
- printf( "\r\n%s is not supported by WinPcap and cannot be opened\r\n", xInterface->name );\r
- }\r
+ if ( pxOpenedInterfaceHandle == NULL )\r
+ {\r
+ printf( "\r\n%s is not supported by WinPcap and cannot be opened\r\n", xInterface->name );\r
+ }\r
else\r
{\r
/* Configure the capture filter to allow blocking reads, and to filter \r
lResult = pcap_next_ex( pxOpenedInterfaceHandle, &pxHeader, &pucPacketData );\r
if( lResult == 1 )\r
{\r
- if( xlwIPNetif != NULL )\r
+ if( pxlwIPNetIf != NULL )\r
{\r
- ethernetif_input( pucPacketData, pxHeader->len );\r
+ prvEthernetInput( pucPacketData, pxHeader->len );\r
}\r
}\r
else\r
ulNetMask = ( configNET_MASK3 << 24UL ) | ( configNET_MASK2 << 16UL ) | ( configNET_MASK1 << 8L ) | configNET_MASK0;\r
\r
if( pcap_compile(pxOpenedInterfaceHandle, &xFilterCode, cErrorBuffer, 1, ulNetMask ) < 0 )\r
- {\r
- printf("\r\nThe packet filter string is invalid\r\n" );\r
- }\r
+ {\r
+ printf( "\r\nThe packet filter string is invalid\r\n" );\r
+ }\r
else\r
- { \r
+ { \r
if( pcap_setfilter( pxOpenedInterfaceHandle, &xFilterCode ) < 0 )\r
{\r
printf( "\r\nAn error occurred setting the packet filter.\r\n" );\r
#include "queue.h"\r
#include "semphr.h"\r
\r
-#define SYS_MBOX_NULL (xQueueHandle)0\r
-#define SYS_SEM_NULL (xSemaphoreHandle)0\r
+#define SYS_MBOX_NULL ( ( xQueueHandle ) NULL )\r
+#define SYS_SEM_NULL ( ( xSemaphoreHandle ) NULL )\r
#define SYS_DEFAULT_THREAD_STACK_DEPTH configMINIMAL_STACK_SIZE\r
\r
typedef xSemaphoreHandle sys_sem_t;\r
typedef xQueueHandle sys_mbox_t;\r
typedef xTaskHandle sys_thread_t;\r
\r
-typedef struct _sys_arch_state_t\r
-{\r
- // Task creation data.\r
- char cTaskName[configMAX_TASK_NAME_LEN];\r
- unsigned short nStackDepth;\r
- unsigned short nTaskCount;\r
-} sys_arch_state_t;\r
-\r
-#define sys_mbox_valid( x ) ( (*x == NULL) ? 0 : 1 )\r
-#define sys_mbox_set_invalid( x ) ( *x = NULL )\r
-#define sys_sem_valid( x ) ( (*x == NULL) ? 0 : 1 )\r
-#define sys_sem_set_invalid( x ) ( *x = NULL )\r
+#define sys_mbox_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )\r
+#define sys_mbox_set_invalid( x ) ( ( *x ) = NULL )\r
+#define sys_sem_valid( x ) ( ( ( *x ) == NULL) ? pdFALSE : pdTRUE )\r
+#define sys_sem_set_invalid( x ) ( ( *x ) = NULL )\r
\r
\r
#endif /* __ARCH_SYS_ARCH_H__ */\r
#include "lwip/mem.h"\r
#include "lwip/stats.h"\r
\r
-/*---------------------------------------------------------------------------*\r
- * Globals:\r
- *---------------------------------------------------------------------------*/\r
-\r
-#if 0\r
-_RB_\r
-struct timeoutlist\r
-{\r
- struct sys_timeouts timeouts;\r
- xTaskHandle pid;\r
-};\r
-\r
-/* This is the number of threads that can be started with sys_thread_new() */\r
-#define SYS_THREAD_MAX 4\r
-\r
-static u16_t s_nextthread = 0;\r
-\r
-static struct timeoutlist s_timeoutlist[SYS_THREAD_MAX];\r
-#endif\r
-\r
-/*-----------------------------------------------------------------------------------*/\r
-\r
/*---------------------------------------------------------------------------*\r
* Routine: sys_mbox_new\r
*---------------------------------------------------------------------------*\r
* Outputs:\r
* sys_mbox_t -- Handle to new mailbox\r
*---------------------------------------------------------------------------*/\r
-err_t sys_mbox_new(sys_mbox_t *mbox, int size)\r
+err_t sys_mbox_new( sys_mbox_t *pxMailBox, int iSize )\r
{\r
-err_t lwip_err= ERR_MEM;\r
+err_t xReturn = ERR_MEM;\r
\r
- *mbox = xQueueCreate( size, sizeof( void * ) );\r
+ *pxMailBox = xQueueCreate( iSize, sizeof( void * ) );\r
\r
- // Created succesfully?\r
- if(*mbox != NULL)\r
+ if( *pxMailBox != NULL )\r
{\r
- lwip_err = ERR_OK;\r
-#if SYS_STATS\r
- SYS_STATS_INC(mbox.used);\r
-#endif /* SYS_STATS */\r
+ xReturn = ERR_OK;\r
+ SYS_STATS_INC_USED( mbox );\r
}\r
\r
- return lwip_err;\r
+ return xReturn;\r
}\r
\r
\r
* Outputs:\r
* sys_mbox_t -- Handle to new mailbox\r
*---------------------------------------------------------------------------*/\r
-void sys_mbox_free(sys_mbox_t *mbox)\r
+void sys_mbox_free( sys_mbox_t *pxMailBox )\r
{\r
-unsigned portBASE_TYPE uxMessagesWaiting;\r
+unsigned long ulMessagesWaiting;\r
\r
- uxMessagesWaiting = uxQueueMessagesWaiting( *mbox );\r
- configASSERT( ( uxMessagesWaiting == 0 ) );\r
+ ulMessagesWaiting = uxQueueMessagesWaiting( *pxMailBox );\r
+ configASSERT( ( ulMessagesWaiting == 0 ) );\r
\r
-#if SYS_STATS\r
- if (uxMessagesWaiting != 0U)\r
+ #if SYS_STATS\r
{\r
- SYS_STATS_INC(mbox.err);\r
- }\r
+ if( ulMessagesWaiting != 0UL )\r
+ {\r
+ SYS_STATS_INC( mbox.err );\r
+ }\r
\r
- SYS_STATS_DEC(mbox.used);\r
-#endif /* SYS_STATS */\r
+ SYS_STATS_DEC( mbox.used );\r
+ }\r
+ #endif /* SYS_STATS */\r
\r
- vQueueDelete( *mbox );\r
+ vQueueDelete( *pxMailBox );\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* sys_mbox_t mbox -- Handle of mailbox\r
* void *data -- Pointer to data to post\r
*---------------------------------------------------------------------------*/\r
-void sys_mbox_post(sys_mbox_t *mbox, void *msg)\r
+void sys_mbox_post( sys_mbox_t *pxMailBox, void *pxMessageToPost )\r
{\r
- while( xQueueSendToBack( *mbox, &msg, portMAX_DELAY ) != pdTRUE );\r
+ while( xQueueSendToBack( *pxMailBox, &pxMessageToPost, portMAX_DELAY ) != pdTRUE );\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* err_t -- ERR_OK if message posted, else ERR_MEM\r
* if not.\r
*---------------------------------------------------------------------------*/\r
-err_t sys_mbox_trypost(sys_mbox_t *mbox, void *msg)\r
+err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )\r
{\r
-err_t result;\r
+err_t xReturn;\r
\r
- if ( xQueueSend( *mbox, &msg, 0 ) == pdPASS )\r
+ if( xQueueSend( *pxMailBox, &pxMessageToPost, 0UL ) == pdPASS )\r
{\r
- result = ERR_OK;\r
+ xReturn = ERR_OK;\r
}\r
else\r
- {\r
- // could not post, queue must be full\r
- result = ERR_MEM;\r
-#if SYS_STATS\r
- SYS_STATS_INC(mbox.err);\r
-#endif /* SYS_STATS */\r
+ { \r
+ /* The queue was already full. */\r
+ xReturn = ERR_MEM;\r
+ SYS_STATS_INC( mbox.err );\r
}\r
- return result;\r
+\r
+ return xReturn;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* u32_t -- SYS_ARCH_TIMEOUT if timeout, else number\r
* of milliseconds until received.\r
*---------------------------------------------------------------------------*/\r
-u32_t sys_arch_mbox_fetch(sys_mbox_t *mbox, void **msg, u32_t timeout)\r
+u32_t sys_arch_mbox_fetch( sys_mbox_t *pxMailBox, void **ppvBuffer, u32_t ulTimeOut )\r
{\r
-void *dummyptr;\r
-portTickType StartTime, EndTime, Elapsed;\r
+void *pvDummy;\r
+portTickType xStartTime, xEndTime, xElapsed;\r
+unsigned long ulReturn;\r
\r
- StartTime = xTaskGetTickCount();\r
+ xStartTime = xTaskGetTickCount();\r
\r
- if (NULL == msg)\r
+ if( NULL == ppvBuffer )\r
{\r
- msg = &dummyptr;\r
+ ppvBuffer = &pvDummy;\r
}\r
\r
- if (timeout != 0)\r
+ if( ulTimeOut != 0UL )\r
{\r
- if ( pdTRUE == xQueueReceive( *mbox, &(*msg), timeout / portTICK_RATE_MS ) )\r
+ if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_RATE_MS ) )\r
{\r
- EndTime = xTaskGetTickCount();\r
- Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
\r
- return ( Elapsed );\r
+ ulReturn = xElapsed;\r
}\r
- else // timed out blocking for message\r
+ else \r
{\r
- *msg = NULL;\r
-\r
- return SYS_ARCH_TIMEOUT;\r
+ /* Timed out. */\r
+ *ppvBuffer = NULL;\r
+ ulReturn = SYS_ARCH_TIMEOUT;\r
}\r
}\r
else\r
{\r
- while( pdTRUE != xQueueReceive( mbox, &(*msg), portMAX_DELAY ) ); // time is arbitrary\r
- EndTime = xTaskGetTickCount();\r
- Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;\r
+ while( pdTRUE != xQueueReceive( *pxMailBox, &( *ppvBuffer ), portMAX_DELAY ) );\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
\r
- if (Elapsed == 0)\r
+ if( xElapsed == 0UL )\r
{\r
- Elapsed = 1;\r
+ xElapsed = 1UL;\r
}\r
\r
- // return time blocked TBD test\r
- return (Elapsed);\r
+ ulReturn = xElapsed;\r
}\r
+\r
+ return ulReturn;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* u32_t -- SYS_MBOX_EMPTY if no messages. Otherwise,\r
* return ERR_OK.\r
*---------------------------------------------------------------------------*/\r
-u32_t sys_arch_mbox_tryfetch(sys_mbox_t *mbox, void **msg)\r
+u32_t sys_arch_mbox_tryfetch( sys_mbox_t *pxMailBox, void **ppvBuffer )\r
{\r
- void *dummyptr;\r
+void *pvDummy;\r
+unsigned long ulReturn;\r
\r
- if (msg == NULL)\r
+ if( ppvBuffer== NULL )\r
{\r
- msg = &dummyptr;\r
+ ppvBuffer = &pvDummy;\r
}\r
\r
- if ( pdTRUE == xQueueReceive( *mbox, &(*msg), 0 ) )\r
+ if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), 0UL ) )\r
{\r
- return ERR_OK;\r
+ ulReturn = ERR_OK;\r
}\r
else\r
{\r
- return SYS_MBOX_EMPTY;\r
+ ulReturn = SYS_MBOX_EMPTY;\r
}\r
+\r
+ return ulReturn;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* Routine: sys_sem_new\r
*---------------------------------------------------------------------------*\r
* Description:\r
- * Creates and returns a new semaphore. The "count" argument specifies\r
+ * Creates and returns a new semaphore. The "ucCount" argument specifies\r
* the initial state of the semaphore.\r
* NOTE: Currently this routine only creates counts of 1 or 0\r
* Inputs:\r
* sys_mbox_t mbox -- Handle of mailbox\r
- * u8_t count -- Initial count of semaphore (1 or 0)\r
+ * u8_t ucCount -- Initial ucCount of semaphore (1 or 0)\r
* Outputs:\r
* sys_sem_t -- Created semaphore or 0 if could not create.\r
*---------------------------------------------------------------------------*/\r
-err_t sys_sem_new(sys_sem_t *sem, u8_t count)\r
+err_t sys_sem_new( sys_sem_t *pxSemaphore, u8_t ucCount )\r
{\r
- err_t lwip_err = ERR_MEM;\r
+err_t xReturn = ERR_MEM;\r
\r
- vSemaphoreCreateBinary( (*sem) );\r
+ vSemaphoreCreateBinary( ( *pxSemaphore ) );\r
\r
- if( *sem != NULL )\r
+ if( *pxSemaphore != NULL )\r
{\r
- // Means it can't be taken\r
- if (count == 0)\r
+ if( ucCount == 0U )\r
{\r
- xSemaphoreTake(*sem, 1);\r
+ xSemaphoreTake( *pxSemaphore, 1UL );\r
}\r
\r
- lwip_err = ERR_OK;\r
-\r
-#if SYS_STATS\r
- SYS_STATS_INC(sem.used);\r
-#endif\r
+ xReturn = ERR_OK;\r
+ SYS_STATS_INC_USED( sem );\r
}\r
else\r
{\r
-#if SYS_STATS\r
- SYS_STATS_INC(sem.err);\r
-#endif\r
+ SYS_STATS_INC( sem.err );\r
}\r
\r
- return lwip_err;\r
+ return xReturn;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* Outputs:\r
* u32_t -- Time elapsed or SYS_ARCH_TIMEOUT.\r
*---------------------------------------------------------------------------*/\r
-u32_t sys_arch_sem_wait(sys_sem_t *sem, u32_t timeout)\r
+u32_t sys_arch_sem_wait( sys_sem_t *pxSemaphore, u32_t ulTimeout )\r
{\r
-portTickType StartTime, EndTime, Elapsed;\r
+portTickType xStartTime, xEndTime, xElapsed;\r
+unsigned long ulReturn;\r
\r
- StartTime = xTaskGetTickCount();\r
+ xStartTime = xTaskGetTickCount();\r
\r
- if (timeout != 0)\r
+ if( ulTimeout != 0UL )\r
{\r
- if( xSemaphoreTake( *sem, timeout / portTICK_RATE_MS ) == pdTRUE )\r
+ if( xSemaphoreTake( *pxSemaphore, ulTimeout / portTICK_RATE_MS ) == pdTRUE )\r
{\r
- EndTime = xTaskGetTickCount();\r
- Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;\r
-\r
- return (Elapsed); // return time blocked TODO test\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = (xEndTime - xStartTime) * portTICK_RATE_MS;\r
+ ulReturn = xElapsed;\r
}\r
else\r
{\r
- return SYS_ARCH_TIMEOUT;\r
+ ulReturn = SYS_ARCH_TIMEOUT;\r
}\r
-\r
}\r
else\r
{\r
- while( xSemaphoreTake( sem, portMAX_DELAY ) != pdTRUE );\r
- EndTime = xTaskGetTickCount();\r
- Elapsed = (EndTime - StartTime) * portTICK_RATE_MS;\r
+ while( xSemaphoreTake( *pxSemaphore, portMAX_DELAY ) != pdTRUE );\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
\r
- if (Elapsed == 0)\r
+ if( xElapsed == 0UL )\r
{\r
- Elapsed = 1;\r
+ xElapsed = 1UL;\r
}\r
\r
- // return time blocked\r
- return (Elapsed);\r
+ ulReturn = xElapsed;\r
}\r
+\r
+ return ulReturn;\r
}\r
\r
/** Create a new mutex\r
* @param mutex pointer to the mutex to create\r
* @return a new mutex */\r
-err_t sys_mutex_new(sys_mutex_t *mutex) \r
+err_t sys_mutex_new( sys_mutex_t *pxMutex ) \r
{\r
-err_t lwip_err = ERR_MEM;\r
+err_t xReturn = ERR_MEM;\r
\r
- *mutex = xQueueCreateMutex();\r
+ *pxMutex = xQueueCreateMutex();\r
\r
- if( *mutex != NULL ) \r
+ if( *pxMutex != NULL ) \r
{\r
- lwip_err = ERR_OK;\r
-#if SYS_STATS\r
- SYS_STATS_INC(mutex.used);\r
-#endif\r
+ xReturn = ERR_OK;\r
+ SYS_STATS_INC_USED( mutex );\r
} \r
else \r
{\r
-#if SYS_STATS\r
- SYS_STATS_INC(mutex.err);\r
-#endif\r
+ SYS_STATS_INC( mutex.err );\r
}\r
\r
- return lwip_err;\r
+ return xReturn;\r
}\r
\r
/** Lock a mutex\r
* @param mutex the mutex to lock */\r
-void sys_mutex_lock(sys_mutex_t *mutex)\r
+void sys_mutex_lock( sys_mutex_t *pxMutex )\r
{\r
- while( xSemaphoreTake( *mutex, portMAX_DELAY ) != pdPASS );\r
+ while( xSemaphoreTake( *pxMutex, portMAX_DELAY ) != pdPASS );\r
}\r
\r
/** Unlock a mutex\r
* @param mutex the mutex to unlock */\r
-void sys_mutex_unlock(sys_mutex_t *mutex)\r
+void sys_mutex_unlock(sys_mutex_t *pxMutex )\r
{\r
- xSemaphoreGive(*mutex);\r
+ xSemaphoreGive( *pxMutex );\r
}\r
\r
\r
/** Delete a semaphore\r
* @param mutex the mutex to delete */\r
-void sys_mutex_free(sys_mutex_t *mutex)\r
+void sys_mutex_free( sys_mutex_t *pxMutex )\r
{\r
-#if SYS_STATS\r
- SYS_STATS_DEC(mutex.used);\r
-#endif /* SYS_STATS */\r
- vQueueDelete(*mutex);\r
+ SYS_STATS_DEC( mutex.used );\r
+ vQueueDelete( *pxMutex );\r
}\r
\r
\r
* Inputs:\r
* sys_sem_t sem -- Semaphore to signal\r
*---------------------------------------------------------------------------*/\r
-void sys_sem_signal(sys_sem_t * sem)\r
+void sys_sem_signal( sys_sem_t *pxSemaphore )\r
{\r
- //LWIP_ASSERT( "sys_sem_signal: sem != SYS_SEM_NULL", sem != SYS_SEM_NULL );\r
- xSemaphoreGive(*sem);\r
+ xSemaphoreGive( *pxSemaphore );\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* Inputs:\r
* sys_sem_t sem -- Semaphore to free\r
*---------------------------------------------------------------------------*/\r
-void sys_sem_free(sys_sem_t * sem)\r
+void sys_sem_free( sys_sem_t *pxSemaphore )\r
{\r
- //LWIP_ASSERT( "sys_sem_free: sem != SYS_SEM_NULL", sem != SYS_SEM_NULL );\r
-\r
-#if SYS_STATS\r
SYS_STATS_DEC(sem.used);\r
-#endif /* SYS_STATS */\r
-\r
- vQueueDelete(*sem);\r
+ vQueueDelete( *pxSemaphore );\r
}\r
\r
/*---------------------------------------------------------------------------*\r
*---------------------------------------------------------------------------*/\r
void sys_init(void)\r
{\r
-#if 0\r
- int i;\r
-\r
- // Initialize the the per-thread sys_timeouts structures\r
- // make sure there are no valid pids in the list\r
- for (i = 0; i < SYS_THREAD_MAX; i++)\r
- {\r
- s_timeoutlist[i].pid = SYS_THREAD_NULL;\r
- // s_timeoutlist[i].timeouts.next = NULL;\r
- }\r
-\r
- // keep track of how many threads have been created\r
- s_nextthread = 0;\r
-#endif\r
}\r
\r
u32_t sys_now(void)\r
return xTaskGetTickCount();\r
}\r
\r
-#if 0\r
-_RB_\r
-u32_t sys_jiffies(void)\r
-{\r
- return UEZTickCounterGet();\r
-}\r
-#endif\r
-\r
-/*---------------------------------------------------------------------------*\r
- * Routine: sys_arch_timeouts\r
- *---------------------------------------------------------------------------*\r
- * Description:\r
- * Returns a pointer to the per-thread sys_timeouts structure. In lwIP,\r
- * each thread has a list of timeouts which is represented as a linked\r
- * list of sys_timeout structures. The sys_timeouts structure holds a\r
- * pointer to a linked list of timeouts. This function is called by\r
- * the lwIP timeout scheduler and must not return a NULL value.\r
- *\r
- * In a single threaded sys_arch implementation, this function will\r
- * simply return a pointer to a global sys_timeouts variable stored in\r
- * the sys_arch module.\r
- * Outputs:\r
- * sys_timeouts * -- Pointer to per-thread timeouts.\r
- *---------------------------------------------------------------------------*/\r
-#if 0\r
-struct sys_timeouts *sys_arch_timeouts(void)\r
-{\r
- int i;\r
- T_uezTask pid;\r
- struct timeoutlist *tl;\r
-\r
- pid = UEZTaskGetCurrent();\r
-\r
- for (i = 0; i < s_nextthread; i++)\r
- {\r
- tl = &(s_timeoutlist[i]);\r
- if (tl->pid == pid)\r
- {\r
- // return &(tl->timeouts);\r
- }\r
- }\r
-\r
- // Error\r
- return NULL;\r
-}\r
-#endif\r
/*---------------------------------------------------------------------------*\r
* Routine: sys_thread_new\r
*---------------------------------------------------------------------------*\r
* Outputs:\r
* sys_thread_t -- Pointer to per-thread timeouts.\r
*---------------------------------------------------------------------------*/\r
-sys_thread_t sys_thread_new(const char *name, void(* thread)(void *arg), void *arg, int stacksize, int prio)\r
+sys_thread_t sys_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority )\r
{\r
-xTaskHandle CreatedTask;\r
-int result;\r
+xTaskHandle xCreatedTask;\r
+portBASE_TYPE xResult;\r
+sys_thread_t xReturn;\r
\r
- result = xTaskCreate( thread, ( signed portCHAR * ) name, stacksize, arg, prio, &CreatedTask );\r
+ xResult = xTaskCreate( pxThread, ( signed char * ) pcName, iStackSize, pvArg, iPriority, &xCreatedTask );\r
\r
- if(result == pdPASS)\r
+ if( xResult == pdPASS )\r
{\r
- return CreatedTask;\r
+ xReturn = xCreatedTask;\r
}\r
else\r
{\r
- return NULL;\r
+ xReturn = NULL;\r
}\r
+\r
+ return xReturn;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* Outputs:\r
* sys_prot_t -- Previous protection level (not used here)\r
*---------------------------------------------------------------------------*/\r
-sys_prot_t sys_arch_protect(void)\r
+sys_prot_t sys_arch_protect( void )\r
{\r
vPortEnterCritical();\r
- return 1;\r
+ return ( sys_prot_t ) 1;\r
}\r
\r
/*---------------------------------------------------------------------------*\r
* Inputs:\r
* sys_prot_t -- Previous protection level (not used here)\r
*---------------------------------------------------------------------------*/\r
-void sys_arch_unprotect(sys_prot_t pval)\r
+void sys_arch_unprotect( sys_prot_t xValue )\r
{\r
- (void) pval;\r
+ (void) xValue;\r
taskEXIT_CRITICAL();\r
}\r
\r
/*\r
* Prints an assertion messages and aborts execution.\r
*/\r
-void sys_assert(const char *msg)\r
+void sys_assert( const char *pcMessage )\r
{\r
- (void) msg;\r
+ (void) pcMessage;\r
\r
for (;;)\r
{\r