--- /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
+/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+\r
+/* BSP includes. */\r
+#include "xemaclite.h"\r
+\r
+/* lwIP includes. */\r
+#include "lwip/opt.h"\r
+#include "lwip/def.h"\r
+#include "lwip/mem.h"\r
+#include "lwip/pbuf.h"\r
+#include "lwip/sys.h"\r
+#include <lwip/stats.h>\r
+#include <lwip/snmp.h>\r
+#include "netif/etharp.h"\r
+\r
+/* Define those to better describe your network interface. */\r
+#define IFNAME0 'e'\r
+#define IFNAME1 'l'\r
+\r
+#define netifMAX_MTU 1500\r
+\r
+struct xEthernetIf\r
+{\r
+ struct eth_addr *ethaddr;\r
+ /* Add whatever per-interface state that is needed here. */\r
+};\r
+\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( struct netif *pxNetIf, 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
+\r
+/**\r
+ * In this function, the hardware should be initialized.\r
+ * Called from ethernetif_init().\r
+ *\r
+ * @param pxNetIf the already initialized lwip network interface structure\r
+ * for this etherpxNetIf\r
+ */\r
+static void prvLowLevelInit( struct netif *pxNetIf )\r
+{\r
+ /* set MAC hardware address length */\r
+ pxNetIf->hwaddr_len = ETHARP_HWADDR_LEN;\r
+\r
+ /* set MAC hardware address */\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 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
+#if 0\r
+_RB_\r
+\r
+ /* Query the computer the simulation is being executed on to find the\r
+ network interfaces it has installed. */\r
+ pxAllNetworkInterfaces = prvPrintAvailableNetworkInterfaces();\r
+\r
+ /* Open the network interface. The number of the interface to be opened is\r
+ set by the configNETWORK_INTERFACE_TO_USE constant in FreeRTOSConfig.h.\r
+ Calling this function will set the pxOpenedInterfaceHandle variable. If,\r
+ after calling this function, pxOpenedInterfaceHandle is equal to NULL, then\r
+ the interface could not be opened. */\r
+ if( pxAllNetworkInterfaces != NULL )\r
+ {\r
+ prvOpenSelectedNetworkInterface( pxAllNetworkInterfaces );\r
+ }\r
+\r
+ /* Remember which interface was opened as it is used in the interrupt\r
+ simulator task. */\r
+ pxlwIPNetIf = pxNetIf;\r
+#endif\r
+}\r
+\r
+/**\r
+ * This function should do the actual transmission of the packet. The packet is\r
+ * contained in the pbuf that is passed to the function. This pbuf\r
+ * might be chained.\r
+ *\r
+ * @param pxNetIf the lwip network interface structure for this etherpxNetIf\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
+ *\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
+ */\r
+\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 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
+ #endif\r
+\r
+ /* Initiate transfer. */\r
+ if( p->len == p->tot_len ) \r
+ {\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 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( pxNetIf );\r
+ xReturn = ERR_BUF;\r
+ }\r
+ else\r
+ {\r
+ pucChar = ucBuffer;\r
+\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
+ if( xReturn == ERR_OK )\r
+ {\r
+#if 0\r
+_RB_\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
+ 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
+ /* broadcast or multicast packet*/\r
+ snmp_inc_ifoutnucastpkts( pxNetIf );\r
+ } \r
+ else \r
+ {\r
+ /* unicast packet */\r
+ snmp_inc_ifoutucastpkts( pxNetIf );\r
+ }\r
+ }\r
+#endif\r
+ }\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 pxNetIf the lwip network interface structure for this etherpxNetIf\r
+ * @return a pbuf filled with the received packet (including MAC header)\r
+ * NULL on memory error\r
+ */\r
+static struct pbuf *prvLowLevelInput( const unsigned char * const pucInputData, long lDataLength )\r
+{\r
+struct pbuf *p = NULL, *q;\r
+\r
+ if( lDataLength > 0 )\r
+ {\r
+ #if ETH_PAD_SIZE\r
+ len += ETH_PAD_SIZE; /* allow room for Ethernet padding */\r
+ #endif\r
+\r
+ /* We allocate a pbuf chain of pbufs from the pool. */\r
+ p = pbuf_alloc( PBUF_RAW, lDataLength, PBUF_POOL );\r
+ \r
+ if( p != NULL ) \r
+ {\r
+ #if ETH_PAD_SIZE\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
+ * packet into the pbuf. */\r
+ lDataLength = 0;\r
+ for( q = p; q != NULL; q = q->next ) \r
+ {\r
+ /* Read enough bytes to fill this pbuf in the chain. The\r
+ * available data in the pbuf is given by the q->len\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 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
+ lDataLength += q->len;\r
+ }\r
+\r
+ #if ETH_PAD_SIZE\r
+ pbuf_header( p, ETH_PAD_SIZE ); /* reclaim the padding word */\r
+ #endif\r
+\r
+ LINK_STATS_INC(link.recv);\r
+ }\r
+ }\r
+\r
+ return p; \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 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 pxNetIf the lwip network interface structure for this etherpxNetIf\r
+ */\r
+static void prvEthernetInput( struct netif *pxNetIf, 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 *pxHeader;\r
+struct pbuf *p;\r
+\r
+ /* move received packet into a new pbuf */\r
+ p = prvLowLevelInput( pucInputData, lInputLength );\r
+\r
+ /* no packet could be read, silently ignore this */\r
+ if( p != NULL )\r
+ {\r
+ /* points to packet payload, which starts with an Ethernet header */\r
+ pxHeader = p->payload;\r
+\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( pxNetIf->input( p, pxNetIf ) != 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
+ 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 prvLowLevelInit() to do the\r
+ * actual setup of the hardware.\r
+ *\r
+ * This function should be passed as a parameter to pxNetIf_add().\r
+ *\r
+ * @param pxNetIf the lwip network interface structure for this etherpxNetIf\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
+ */\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 xEthernetIf *pxEthernetIf;\r
+\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
+ xReturn = ERR_MEM;\r
+ }\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
+ prvLowLevelInit( pxNetIf );\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+/*-----------------------------------------------------------*/\r
--- /dev/null
+#pragma pack(push,1)
--- /dev/null
+/*
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without modification,
+ * are permitted provided that the following conditions are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright notice,
+ * this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
+ * OF SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ */
+#ifndef __ARCH_CC_H__
+#define __ARCH_CC_H__
+
+/* Include some files for defining library routines */
+#include <stdio.h> /* printf, fflush, FILE */
+#include <stdlib.h> /* abort */
+
+
+
+/** @todo fix some warnings: don't use #pragma if compiling with cygwin gcc */
+#ifndef __GNUC__
+ #include <limits.h>
+ #pragma warning (disable: 4244) /* disable conversion warning (implicit integer promotion!) */
+ #pragma warning (disable: 4127) /* conditional expression is constant */
+ #pragma warning (disable: 4996) /* 'strncpy' was declared deprecated */
+ #pragma warning (disable: 4103) /* structure packing changed by including file */
+#endif
+
+#define LWIP_PROVIDE_ERRNO
+
+/* Define generic types used in lwIP */
+typedef unsigned char u8_t;
+typedef signed char s8_t;
+typedef unsigned short u16_t;
+typedef signed short s16_t;
+typedef unsigned long u32_t;
+typedef signed long s32_t;
+
+typedef size_t mem_ptr_t;
+typedef u32_t sys_prot_t;
+
+/* Define (sn)printf formatters for these lwIP types */
+#define X8_F "02x"
+#define U16_F "hu"
+#define S16_F "hd"
+#define X16_F "hx"
+#define U32_F "lu"
+#define S32_F "ld"
+#define X32_F "lx"
+#define SZT_F U32_F
+
+/* Compiler hints for packing structures */
+#define PACK_STRUCT_STRUCT __attribute__( (packed) )
+
+/* Plaform specific diagnostic output */
+#define LWIP_PLATFORM_DIAG(x) do { printf x; } while(0)
+
+#define LWIP_PLATFORM_ASSERT(x) do { printf("Assertion \"%s\" failed at line %d in %s\n", \
+ x, __LINE__, __FILE__); fflush(NULL); abort(); } while(0)
+
+#define LWIP_ERROR(message, expression, handler) do { if (!(expression)) { \
+ printf("Assertion \"%s\" failed at line %d in %s\n", message, __LINE__, __FILE__); \
+ fflush(NULL);handler;} } while(0)
+
+/* C runtime functions redefined */
+#define snprintf _snprintf
+
+u32_t dns_lookup_external_hosts_file(const char *name);
+
+#define LWIP_RAND() ((u32_t)rand())
+
+#endif /* __ARCH_CC_H__ */
--- /dev/null
+#pragma pack(pop)
--- /dev/null
+/*
+ * Copyright (c) 2001, Swedish Institute of Computer Science.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. Neither the name of the Institute nor the names of its contributors
+ * may be used to endorse or promote products derived from this software
+ * without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * This file is part of the lwIP TCP/IP stack.
+ *
+ * Author: Adam Dunkels <adam@sics.se>
+ *
+ */
+#ifndef __PERF_H__
+#define __PERF_H__
+
+#define PERF_START /* null definition */
+#define PERF_STOP(x) /* null definition */
+
+#endif /* __PERF_H__ */
--- /dev/null
+/*\r
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.\r
+ * All rights reserved. \r
+ * \r
+ * Redistribution and use in source and binary forms, with or without modification, \r
+ * are permitted provided that the following conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright notice,\r
+ * this list of conditions and the following disclaimer in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ * derived from this software without specific prior written permission. \r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED \r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF \r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT \r
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, \r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT \r
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS \r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN \r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING \r
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY \r
+ * OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the lwIP TCP/IP stack.\r
+ * \r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+#ifndef __ARCH_SYS_ARCH_H__\r
+#define __ARCH_SYS_ARCH_H__\r
+\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "queue.h"\r
+#include "semphr.h"\r
+\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 xSemaphoreHandle sys_mutex_t;\r
+typedef xQueueHandle sys_mbox_t;\r
+typedef xTaskHandle sys_thread_t;\r
+\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
+\r
--- /dev/null
+/**
+ * Additional settings for the win32 port.
+ * Copy this to lwipcfg_msvc.h and make the config changes you need.
+ */
+
+/* configuration for this port */
+#define PPP_USERNAME "Admin"
+#define PPP_PASSWORD "pass"
+
+/** Define this to the index of the windows network adapter to use */
+#define PACKET_LIB_ADAPTER_NR 2
+/** Define this to the GUID of the windows network adapter to use
+ * or NOT define this if you want PACKET_LIB_ADAPTER_NR to be used */
+/*#define PACKET_LIB_ADAPTER_GUID "00000000-0000-0000-0000-000000000000"*/
+/*#define PACKET_LIB_GET_ADAPTER_NETADDRESS(addr) IP4_ADDR((addr), 192,168,1,0)*/
+/*#define PACKET_LIB_QUIET*/
+
+#define LWIP_PORT_INIT_IPADDR(addr) IP4_ADDR((addr), 192,168,0,200)
+#define LWIP_PORT_INIT_GW(addr) IP4_ADDR((addr), 192,168,0,3)
+#define LWIP_PORT_INIT_NETMASK(addr) IP4_ADDR((addr), 255,255,255,0)
+
+/* remember to change this MAC address to suit your needs!
+ the last octet will be increased by netif->num for each netif */
+#define LWIP_MAC_ADDR_BASE {0x00,0x01,0x02,0x03,0x04,0x05}
+
+/* configuration for applications */
+
+#define LWIP_CHARGEN_APP 0
+#define LWIP_DNS_APP 0
+#define LWIP_HTTPD_APP 1
+/* Set this to 1 to use the netconn http server,
+ * otherwise the raw api server will be used. */
+/*#define LWIP_HTTPD_APP_NETCONN */
+#define LWIP_NETBIOS_APP 0
+#define LWIP_NETIO_APP 0
+#define LWIP_PING_APP 0
+#define LWIP_RTP_APP 0
+#define LWIP_SHELL_APP 0
+#define LWIP_SNTP_APP 0
+#define LWIP_SOCKET_EXAMPLES_APP 0
+#define LWIP_TCPECHO_APP 0
+/* Set this to 1 to use the netconn tcpecho server,
+ * otherwise the raw api server will be used. */
+/*#define LWIP_TCPECHO_APP_NETCONN */
+#define LWIP_UDPECHO_APP 0
--- /dev/null
+/*\r
+ * Copyright (c) 2001-2003 Swedish Institute of Computer Science.\r
+ * All rights reserved.\r
+ *\r
+ * Redistribution and use in source and binary forms, with or without modification,\r
+ * are permitted provided that the following conditions are met:\r
+ *\r
+ * 1. Redistributions of source code must retain the above copyright notice,\r
+ * this list of conditions and the following disclaimer.\r
+ * 2. Redistributions in binary form must reproduce the above copyright notice,\r
+ * this list of conditions and the following disclaimer in the documentation\r
+ * and/or other materials provided with the distribution.\r
+ * 3. The name of the author may not be used to endorse or promote products\r
+ * derived from this software without specific prior written permission.\r
+ *\r
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED\r
+ * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF\r
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT\r
+ * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,\r
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT\r
+ * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\r
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\r
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING\r
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY\r
+ * OF SUCH DAMAGE.\r
+ *\r
+ * This file is part of the lwIP TCP/IP stack.\r
+ *\r
+ * Author: Adam Dunkels <adam@sics.se>\r
+ *\r
+ */\r
+\r
+//*****************************************************************************\r
+//\r
+// Include OS functionality.\r
+//\r
+//*****************************************************************************\r
+\r
+/* ------------------------ System architecture includes ----------------------------- */\r
+#include "arch/sys_arch.h"\r
+\r
+/* ------------------------ lwIP includes --------------------------------- */\r
+#include "lwip/opt.h"\r
+\r
+#include "lwip/debug.h"\r
+#include "lwip/def.h"\r
+#include "lwip/sys.h"\r
+#include "lwip/mem.h"\r
+#include "lwip/stats.h"\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_mbox_new\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Creates a new mailbox\r
+ * Inputs:\r
+ * int size -- Size of elements in the mailbox\r
+ * Outputs:\r
+ * sys_mbox_t -- Handle to new mailbox\r
+ *---------------------------------------------------------------------------*/\r
+err_t sys_mbox_new( sys_mbox_t *pxMailBox, int iSize )\r
+{\r
+err_t xReturn = ERR_MEM;\r
+\r
+ *pxMailBox = xQueueCreate( iSize, sizeof( void * ) );\r
+\r
+ if( *pxMailBox != NULL )\r
+ {\r
+ xReturn = ERR_OK;\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( mbox.used );\r
+ }\r
+ #endif /* SYS_STATS */\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_mbox_free\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Deallocates a mailbox. If there are messages still present in the\r
+ * mailbox when the mailbox is deallocated, it is an indication of a\r
+ * programming error in lwIP and the developer should be notified.\r
+ * Inputs:\r
+ * sys_mbox_t mbox -- Handle of mailbox\r
+ * Outputs:\r
+ * sys_mbox_t -- Handle to new mailbox\r
+ *---------------------------------------------------------------------------*/\r
+void sys_mbox_free( sys_mbox_t *pxMailBox )\r
+{\r
+unsigned long ulMessagesWaiting;\r
+\r
+ ulMessagesWaiting = uxQueueMessagesWaiting( *pxMailBox );\r
+ configASSERT( ( ulMessagesWaiting == 0 ) );\r
+\r
+ #if SYS_STATS\r
+ {\r
+ if( ulMessagesWaiting != 0UL )\r
+ {\r
+ SYS_STATS_INC( mbox.err );\r
+ }\r
+\r
+ SYS_STATS_DEC( mbox.used );\r
+ }\r
+ #endif /* SYS_STATS */\r
+\r
+ vQueueDelete( *pxMailBox );\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_mbox_post\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Post the "msg" to the mailbox.\r
+ * Inputs:\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 *pxMailBox, void *pxMessageToPost )\r
+{\r
+ while( xQueueSendToBack( *pxMailBox, &pxMessageToPost, portMAX_DELAY ) != pdTRUE );\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_mbox_trypost\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Try to post the "msg" to the mailbox. Returns immediately with\r
+ * error if cannot.\r
+ * Inputs:\r
+ * sys_mbox_t mbox -- Handle of mailbox\r
+ * void *msg -- Pointer to data to post\r
+ * Outputs:\r
+ * err_t -- ERR_OK if message posted, else ERR_MEM\r
+ * if not.\r
+ *---------------------------------------------------------------------------*/\r
+err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )\r
+{\r
+err_t xReturn;\r
+\r
+ if( xQueueSend( *pxMailBox, &pxMessageToPost, 0UL ) == pdPASS )\r
+ {\r
+ xReturn = ERR_OK;\r
+ }\r
+ else\r
+ {\r
+ /* The queue was already full. */\r
+ xReturn = ERR_MEM;\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( mbox.err );\r
+ }\r
+ #endif /* SYS_STATS */\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_arch_mbox_fetch\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Blocks the thread until a message arrives in the mailbox, but does\r
+ * not block the thread longer than "timeout" milliseconds (similar to\r
+ * the sys_arch_sem_wait() function). The "msg" argument is a result\r
+ * parameter that is set by the function (i.e., by doing "*msg =\r
+ * ptr"). The "msg" parameter maybe NULL to indicate that the message\r
+ * should be dropped.\r
+ *\r
+ * The return values are the same as for the sys_arch_sem_wait() function:\r
+ * Number of milliseconds spent waiting or SYS_ARCH_TIMEOUT if there was a\r
+ * timeout.\r
+ *\r
+ * Note that a function with a similar name, sys_mbox_fetch(), is\r
+ * implemented by lwIP.\r
+ * Inputs:\r
+ * sys_mbox_t mbox -- Handle of mailbox\r
+ * void **msg -- Pointer to pointer to msg received\r
+ * u32_t timeout -- Number of milliseconds until timeout\r
+ * Outputs:\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 *pxMailBox, void **ppvBuffer, u32_t ulTimeOut )\r
+{\r
+void *pvDummy;\r
+portTickType xStartTime, xEndTime, xElapsed;\r
+unsigned long ulReturn;\r
+\r
+ xStartTime = xTaskGetTickCount();\r
+\r
+ if( NULL == ppvBuffer )\r
+ {\r
+ ppvBuffer = &pvDummy;\r
+ }\r
+\r
+ if( ulTimeOut != 0UL )\r
+ {\r
+ if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_RATE_MS ) )\r
+ {\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
+\r
+ ulReturn = xElapsed;\r
+ }\r
+ else\r
+ {\r
+ /* Timed out. */\r
+ *ppvBuffer = NULL;\r
+ ulReturn = SYS_ARCH_TIMEOUT;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ while( pdTRUE != xQueueReceive( pxMailBox, &( *ppvBuffer ), portMAX_DELAY ) );\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
+\r
+ if( xElapsed == 0UL )\r
+ {\r
+ xElapsed = 1UL;\r
+ }\r
+\r
+ ulReturn = xElapsed;\r
+ }\r
+\r
+ return ulReturn;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_arch_mbox_tryfetch\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Similar to sys_arch_mbox_fetch, but if message is not ready\r
+ * immediately, we'll return with SYS_MBOX_EMPTY. On success, 0 is\r
+ * returned.\r
+ * Inputs:\r
+ * sys_mbox_t mbox -- Handle of mailbox\r
+ * void **msg -- Pointer to pointer to msg received\r
+ * Outputs:\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 *pxMailBox, void **ppvBuffer )\r
+{\r
+void *pvDummy;\r
+unsigned long ulReturn;\r
+\r
+ if( ppvBuffer== NULL )\r
+ {\r
+ ppvBuffer = &pvDummy;\r
+ }\r
+\r
+ if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), 0UL ) )\r
+ {\r
+ ulReturn = ERR_OK;\r
+ }\r
+ else\r
+ {\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 "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 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 *pxSemaphore, u8_t ucCount )\r
+{\r
+err_t xReturn = ERR_MEM;\r
+\r
+ vSemaphoreCreateBinary( ( *pxSemaphore ) );\r
+\r
+ if( *pxSemaphore != NULL )\r
+ {\r
+ if( ucCount == 0U )\r
+ {\r
+ xSemaphoreTake( *pxSemaphore, 1UL );\r
+ }\r
+\r
+ xReturn = ERR_OK;\r
+\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( sem.used );\r
+ }\r
+ #endif\r
+ }\r
+ else\r
+ {\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( sem.err );\r
+ }\r
+ #endif\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_arch_sem_wait\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Blocks the thread while waiting for the semaphore to be\r
+ * signaled. If the "timeout" argument is non-zero, the thread should\r
+ * only be blocked for the specified time (measured in\r
+ * milliseconds).\r
+ *\r
+ * If the timeout argument is non-zero, the return value is the number of\r
+ * milliseconds spent waiting for the semaphore to be signaled. If the\r
+ * semaphore wasn't signaled within the specified time, the return value is\r
+ * SYS_ARCH_TIMEOUT. If the thread didn't have to wait for the semaphore\r
+ * (i.e., it was already signaled), the function may return zero.\r
+ *\r
+ * Notice that lwIP implements a function with a similar name,\r
+ * sys_sem_wait(), that uses the sys_arch_sem_wait() function.\r
+ * Inputs:\r
+ * sys_sem_t sem -- Semaphore to wait on\r
+ * u32_t timeout -- Number of milliseconds until timeout\r
+ * Outputs:\r
+ * u32_t -- Time elapsed or SYS_ARCH_TIMEOUT.\r
+ *---------------------------------------------------------------------------*/\r
+u32_t sys_arch_sem_wait( sys_sem_t *pxSemaphore, u32_t ulTimeout )\r
+{\r
+portTickType xStartTime, xEndTime, xElapsed;\r
+unsigned long ulReturn;\r
+\r
+ xStartTime = xTaskGetTickCount();\r
+\r
+ if( ulTimeout != 0UL )\r
+ {\r
+ if( xSemaphoreTake( *pxSemaphore, ulTimeout / portTICK_RATE_MS ) == pdTRUE )\r
+ {\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = (xEndTime - xStartTime) * portTICK_RATE_MS;\r
+ ulReturn = xElapsed;\r
+ }\r
+ else\r
+ {\r
+ ulReturn = SYS_ARCH_TIMEOUT;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ while( xSemaphoreTake( pxSemaphore, portMAX_DELAY ) != pdTRUE );\r
+ xEndTime = xTaskGetTickCount();\r
+ xElapsed = ( xEndTime - xStartTime ) * portTICK_RATE_MS;\r
+\r
+ if( xElapsed == 0UL )\r
+ {\r
+ xElapsed = 1UL;\r
+ }\r
+\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 *pxMutex )\r
+{\r
+err_t xReturn = ERR_MEM;\r
+\r
+ *pxMutex = xQueueCreateMutex();\r
+\r
+ if( *pxMutex != NULL )\r
+ {\r
+ xReturn = ERR_OK;\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( mutex.used );\r
+ }\r
+ #endif\r
+ } \r
+ else \r
+ {\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_INC( mutex.err );\r
+ }\r
+ #endif\r
+ }\r
+ \r
+ return xReturn;\r
+}\r
+\r
+/** Lock a mutex\r
+ * @param mutex the mutex to lock */\r
+void sys_mutex_lock( sys_mutex_t *pxMutex )\r
+{\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 *pxMutex )\r
+{\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 *pxMutex )\r
+{\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_DEC( mutex.used );\r
+ }\r
+ #endif /* SYS_STATS */\r
+ vQueueDelete( *pxMutex );\r
+}\r
+\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_sem_signal\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Signals (releases) a semaphore\r
+ * Inputs:\r
+ * sys_sem_t sem -- Semaphore to signal\r
+ *---------------------------------------------------------------------------*/\r
+void sys_sem_signal( sys_sem_t *pxSemaphore )\r
+{\r
+ xSemaphoreGive( *pxSemaphore );\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_sem_free\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Deallocates a semaphore\r
+ * Inputs:\r
+ * sys_sem_t sem -- Semaphore to free\r
+ *---------------------------------------------------------------------------*/\r
+void sys_sem_free( sys_sem_t *pxSemaphore )\r
+{\r
+ #if SYS_STATS\r
+ {\r
+ SYS_STATS_DEC(sem.used);\r
+ }\r
+ #endif\r
+\r
+ vQueueDelete( *pxSemaphore );\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_init\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Initialize sys arch\r
+ *---------------------------------------------------------------------------*/\r
+void sys_init(void)\r
+{\r
+}\r
+\r
+u32_t sys_now(void)\r
+{\r
+ return xTaskGetTickCount();\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_thread_new\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * Starts a new thread with priority "prio" that will begin its\r
+ * execution in the function "thread()". The "arg" argument will be\r
+ * passed as an argument to the thread() function. The id of the new\r
+ * thread is returned. Both the id and the priority are system\r
+ * dependent.\r
+ * Inputs:\r
+ * char *name -- Name of thread\r
+ * void (* thread)(void *arg) -- Pointer to function to run.\r
+ * void *arg -- Argument passed into function\r
+ * int stacksize -- Required stack amount in bytes\r
+ * int prio -- Thread priority\r
+ * Outputs:\r
+ * sys_thread_t -- Pointer to per-thread timeouts.\r
+ *---------------------------------------------------------------------------*/\r
+sys_thread_t sys_thread_new( const char *pcName, void( *pxThread )( void *pvParameters ), void *pvArg, int iStackSize, int iPriority )\r
+{\r
+xTaskHandle xCreatedTask;\r
+portBASE_TYPE xResult;\r
+sys_thread_t xReturn;\r
+\r
+ xResult = xTaskCreate( pxThread, ( signed char * ) pcName, iStackSize, pvArg, iPriority, &xCreatedTask );\r
+\r
+ if( xResult == pdPASS )\r
+ {\r
+ xReturn = xCreatedTask;\r
+ }\r
+ else\r
+ {\r
+ xReturn = NULL;\r
+ }\r
+\r
+ return xReturn;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_arch_protect\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * This optional function does a "fast" critical region protection and\r
+ * returns the previous protection level. This function is only called\r
+ * during very short critical regions. An embedded system which supports\r
+ * ISR-based drivers might want to implement this function by disabling\r
+ * interrupts. Task-based systems might want to implement this by using\r
+ * a mutex or disabling tasking. This function should support recursive\r
+ * calls from the same task or interrupt. In other words,\r
+ * sys_arch_protect() could be called while already protected. In\r
+ * that case the return value indicates that it is already protected.\r
+ *\r
+ * sys_arch_protect() is only required if your port is supporting an\r
+ * operating system.\r
+ * Outputs:\r
+ * sys_prot_t -- Previous protection level (not used here)\r
+ *---------------------------------------------------------------------------*/\r
+sys_prot_t sys_arch_protect( void )\r
+{\r
+ taskENTER_CRITICAL();\r
+ return ( sys_prot_t ) 1;\r
+}\r
+\r
+/*---------------------------------------------------------------------------*\r
+ * Routine: sys_arch_unprotect\r
+ *---------------------------------------------------------------------------*\r
+ * Description:\r
+ * This optional function does a "fast" set of critical region\r
+ * protection to the value specified by pval. See the documentation for\r
+ * sys_arch_protect() for more information. This function is only\r
+ * required if your port is supporting an operating system.\r
+ * Inputs:\r
+ * sys_prot_t -- Previous protection level (not used here)\r
+ *---------------------------------------------------------------------------*/\r
+void sys_arch_unprotect( sys_prot_t xValue )\r
+{\r
+ (void) xValue;\r
+ taskEXIT_CRITICAL();\r
+}\r
+\r
+/*\r
+ * Prints an assertion messages and aborts execution.\r
+ */\r
+void sys_assert( const char *pcMessage )\r
+{\r
+ (void) pcMessage;\r
+\r
+ for (;;)\r
+ {\r
+ }\r
+}\r
+/*-------------------------------------------------------------------------*\r
+ * End of File: sys_arch.c\r
+ *-------------------------------------------------------------------------*/\r
+\r