static void prvQueueReceiveTask( void *pvParameters );\r
static void prvQueueSendTask( void *pvParameters );\r
\r
-/*\r
- * Called by main() to create the simply blinky style application if\r
- * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
- */\r
-void main_blinky( void );\r
-\r
/*-----------------------------------------------------------*/\r
\r
/* The queue used by both tasks. */\r
\r
/****** Network configuration settings. ***************************************/\r
\r
-#define configLWIP_TASK_PRIORITY ( 5 )\r
+#define configMAC_INPUT_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )\r
+#define configLWIP_TASK_PRIORITY ( configMAX_PRIORITIES - 2 )\r
\r
/* MAC address configuration. */\r
#define configMAC_ADDR0 0x00\r
use of the lwIP raw API. */\r
httpd_init();\r
\r
- sys_thread_new( "lwIP Input", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE * 6, tskIDLE_PRIORITY );\r
+ sys_thread_new( "lwIP Input", xemacif_input_thread, &xNetIf, configMINIMAL_STACK_SIZE, configMAC_INPUT_TASK_PRIORITY );\r
\r
/* Create the FreeRTOS defined basic command server. This demonstrates use\r
of the lwIP sockets API. */\r
extern u8 _end;
#ifdef OS_IS_FREERTOS
-long xInsideISR = 0;
+extern BaseType_t xInsideISR;
#endif
#define XEMACPS_BD_TO_INDEX(ringptr, bdptr) \
#include "lwip/mem.h"\r
#include "lwip/stats.h"\r
\r
+/* Very crude mechanism used to determine if the critical section handling\r
+functions are being called from an interrupt context or not. This relies on\r
+the interrupt handler setting this variable manually. */\r
+BaseType_t xInsideISR = pdFALSE;\r
+\r
/*---------------------------------------------------------------------------*\r
* Routine: sys_mbox_new\r
*---------------------------------------------------------------------------*\r
err_t sys_mbox_trypost( sys_mbox_t *pxMailBox, void *pxMessageToPost )\r
{\r
err_t xReturn;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
\r
- if( xQueueSend( *pxMailBox, &pxMessageToPost, 0UL ) == pdPASS )\r
+ if( xInsideISR != pdFALSE )\r
+ {\r
+ xReturn = xQueueSendFromISR( *pxMailBox, &pxMessageToPost, &xHigherPriorityTaskWoken );\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+ }\r
+ else\r
+ {\r
+ xReturn = xQueueSend( *pxMailBox, &pxMessageToPost, ( TickType_t ) 0 );\r
+ }\r
+\r
+ if( xReturn == pdPASS )\r
{\r
xReturn = ERR_OK;\r
}\r
\r
if( ulTimeOut != 0UL )\r
{\r
+ configASSERT( xInsideISR == ( portBASE_TYPE ) 0 );\r
+\r
if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), ulTimeOut/ portTICK_PERIOD_MS ) )\r
{\r
xEndTime = xTaskGetTickCount();\r
{\r
void *pvDummy;\r
unsigned long ulReturn;\r
+long lResult;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
\r
if( ppvBuffer== NULL )\r
{\r
ppvBuffer = &pvDummy;\r
}\r
\r
- if( pdTRUE == xQueueReceive( *pxMailBox, &( *ppvBuffer ), 0UL ) )\r
+ if( xInsideISR != pdFALSE )\r
+ {\r
+ lResult = xQueueReceiveFromISR( *pxMailBox, &( *ppvBuffer ), &xHigherPriorityTaskWoken );\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+ }\r
+ else\r
+ {\r
+ lResult = xQueueReceive( *pxMailBox, &( *ppvBuffer ), 0UL );\r
+ }\r
+\r
+ if( lResult == pdPASS )\r
{\r
ulReturn = ERR_OK;\r
}\r
{\r
err_t xReturn = ERR_MEM;\r
\r
+ //vSemaphoreCreateBinary( ( *pxSemaphore ) );\r
*pxSemaphore = xSemaphoreCreateCounting( 0xffff, ( unsigned long ) ucCount );\r
\r
if( *pxSemaphore != NULL )\r
{\r
+ if( ucCount == 0U )\r
+ {\r
+// xSemaphoreTake( *pxSemaphore, 1UL );\r
+ }\r
+\r
xReturn = ERR_OK;\r
SYS_STATS_INC_USED( sem );\r
}\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
+BaseType_t xGotSemaphore;\r
+BaseType_t xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ if( xInsideISR == 0 )\r
+ {\r
+ while( xSemaphoreTake( *pxMutex, portMAX_DELAY ) != pdPASS );\r
+ }\r
+ else\r
+ {\r
+#warning What happens if the mutex cannot be taken from an ISR in the code below\r
+ xGotSemaphore = xSemaphoreTakeFromISR( *pxMutex, &xHigherPriorityTaskWoken );\r
+ configASSERT( xGotSemaphore );\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+ }\r
}\r
\r
/** Unlock a mutex\r
*---------------------------------------------------------------------------*/\r
void sys_sem_signal( sys_sem_t *pxSemaphore )\r
{\r
- xSemaphoreGive( *pxSemaphore );\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ if( xInsideISR != pdFALSE )\r
+ {\r
+ xSemaphoreGiveFromISR( *pxSemaphore, &xHigherPriorityTaskWoken );\r
+ portYIELD_FROM_ISR( xHigherPriorityTaskWoken );\r
+ }\r
+ else\r
+ {\r
+ xSemaphoreGive( *pxSemaphore );\r
+ }\r
}\r
\r
/*---------------------------------------------------------------------------*\r
*---------------------------------------------------------------------------*/\r
sys_prot_t sys_arch_protect( void )\r
{\r
- taskENTER_CRITICAL();\r
+ if( xInsideISR == pdFALSE )\r
+ {\r
+ taskENTER_CRITICAL();\r
+ }\r
return ( sys_prot_t ) 1;\r
}\r
\r
void sys_arch_unprotect( sys_prot_t xValue )\r
{\r
(void) xValue;\r
- taskEXIT_CRITICAL();\r
+ if( xInsideISR == pdFALSE )\r
+ {\r
+ taskEXIT_CRITICAL();\r
+ }\r
}\r
\r
/*\r
#include "IntQueue.h"\r
#include "EventGroupsDemo.h"\r
\r
-/* lwIP includes. */\r
-#include "lwip/tcpip.h"\r
-\r
/* Priorities for the demo application tasks. */\r
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1UL )\r
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2UL )\r
*/\r
static void prvPseudoRandomiser( void *pvParameters );\r
\r
-/*\r
- * Defined in lwIPApps.c.\r
- */\r
-extern void lwIPAppsInit( void *pvArguments );\r
-\r
/*-----------------------------------------------------------*/\r
\r
/* The following two variables are used to communicate the status of the\r
\r
void main_full( void )\r
{\r
- /* Init lwIP and start lwIP tasks. */\r
- tcpip_init( lwIPAppsInit, NULL );\r
-\r
/* Start all the other standard demo/test tasks. They have not particular\r
functionality, but do demonstrate how to use the FreeRTOS API and test the\r
kernel port. */\r
--- /dev/null
+/*\r
+ FreeRTOS V8.0.1 - Copyright (C) 2014 Real Time Engineers Ltd.\r
+ All rights reserved\r
+\r
+ VISIT http://www.FreeRTOS.org TO ENSURE YOU ARE USING THE LATEST VERSION.\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * FreeRTOS provides completely free yet professionally developed, *\r
+ * robust, strictly quality controlled, supported, and cross *\r
+ * platform software that has become a de facto standard. *\r
+ * *\r
+ * Help yourself get started quickly and support the FreeRTOS *\r
+ * project by purchasing a FreeRTOS tutorial book, reference *\r
+ * manual, or both from: http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * Thank you! *\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
+\r
+ >>! NOTE: The modification to the GPL is included to allow you to !<<\r
+ >>! distribute a combined work that includes FreeRTOS without being !<<\r
+ >>! obliged to provide the source code for proprietary components !<<\r
+ >>! outside of the FreeRTOS kernel. !<<\r
+\r
+ FreeRTOS is distributed in the hope that it will be useful, but WITHOUT ANY\r
+ WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS\r
+ FOR A PARTICULAR PURPOSE. Full license text is available from the following\r
+ link: http://www.freertos.org/a00114.html\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Having a problem? Start by reading the FAQ "My application does *\r
+ * not run, what could be wrong?" *\r
+ * *\r
+ * http://www.FreeRTOS.org/FAQHelp.html *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ http://www.FreeRTOS.org - Documentation, books, training, latest versions,\r
+ license and Real Time Engineers Ltd. contact details.\r
+\r
+ http://www.FreeRTOS.org/plus - A selection of FreeRTOS ecosystem products,\r
+ including FreeRTOS+Trace - an indispensable productivity tool, a DOS\r
+ compatible FAT file system, and our tiny thread aware UDP/IP stack.\r
+\r
+ http://www.OpenRTOS.com - Real Time Engineers ltd license FreeRTOS to High\r
+ Integrity Systems to sell under the OpenRTOS brand. Low cost OpenRTOS\r
+ licenses offer ticketed support, indemnification and middleware.\r
+\r
+ http://www.SafeRTOS.com - High Integrity Systems also provide a safety\r
+ engineered and independently SIL3 certified version for use in safety and\r
+ mission critical applications that require provable dependability.\r
+\r
+ 1 tab == 4 spaces!\r
+*/\r
+\r
+/******************************************************************************\r
+ * NOTE 1: This project provides two demo applications. A simple blinky style\r
+ * project, and a more comprehensive test and demo application. The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting in main.c is used to select\r
+ * between the two. See the notes on using mainCREATE_SIMPLE_BLINKY_DEMO_ONLY\r
+ * in main.c. This file implements the simply blinky style version.\r
+ *\r
+ * NOTE 2: This file only contains the source code that is specific to the\r
+ * basic demo. Generic functions, such FreeRTOS hook functions, and functions\r
+ * required to configure the hardware are defined in main.c.\r
+ ******************************************************************************\r
+ *\r
+ * main_blinky() creates one queue, and two tasks. It then starts the\r
+ * scheduler.\r
+ *\r
+ * The Queue Send Task:\r
+ * The queue send task is implemented by the prvQueueSendTask() function in\r
+ * this file. prvQueueSendTask() sits in a loop that causes it to repeatedly\r
+ * block for 200 milliseconds, before sending the value 100 to the queue that\r
+ * was created within main_blinky(). Once the value is sent, the task loops\r
+ * back around to block for another 200 milliseconds...and so on.\r
+ *\r
+ * The Queue Receive Task:\r
+ * The queue receive task is implemented by the prvQueueReceiveTask() function\r
+ * in this file. prvQueueReceiveTask() sits in a loop where it repeatedly\r
+ * blocks on attempts to read data from the queue that was created within\r
+ * main_blinky(). When data is received, the task checks the value of the\r
+ * data, and if the value equals the expected 100, toggles an LED. The 'block\r
+ * time' parameter passed to the queue receive function specifies that the\r
+ * task should be held in the Blocked state indefinitely to wait for data to\r
+ * be available on the queue. The queue receive task will only leave the\r
+ * Blocked state when the queue send task writes to the queue. As the queue\r
+ * send task writes to the queue every 200 milliseconds, the queue receive\r
+ * task leaves the Blocked state every 200 milliseconds, and therefore toggles\r
+ * the LED every 200 milliseconds.\r
+ */\r
+#warning Need to update the comment above.\r
+#warning Move lwIP code into the lwIP_Demo directory.\r
+\r
+/* Kernel includes. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "timers.h"\r
+\r
+/* Standard demo includes. */\r
+#include "partest.h"\r
+\r
+/* lwIP includes. */\r
+#include "lwip/tcpip.h"\r
+\r
+/* The rate at which data is sent to the queue. The 200ms value is converted\r
+to ticks using the portTICK_PERIOD_MS constant. */\r
+#define mainTIMER_PERIOD_MS ( 200 / portTICK_PERIOD_MS )\r
+\r
+/* The LED toggled by the Rx task. */\r
+#define mainTIMER_LED ( 0 )\r
+\r
+/* A block time of zero just means "don't block". */\r
+#define mainDONT_BLOCK ( 0 )\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * The callback for the timer that just toggles an LED to show the system is\r
+ * running.\r
+ */\r
+static void prvLEDToggleTimer( TimerHandle_t pxTimer );\r
+\r
+/*\r
+ * Defined in lwIPApps.c.\r
+ */\r
+extern void lwIPAppsInit( void *pvArguments );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+void main_lwIP( void )\r
+{\r
+TimerHandle_t xTimer;\r
+\r
+ /* Init lwIP and start lwIP tasks. */\r
+ tcpip_init( lwIPAppsInit, NULL );\r
+\r
+ /* A timer is used to toggle an LED just to show the application is\r
+ executing. */\r
+ xTimer = xTimerCreate( "LED", /* Text name to make debugging easier. */\r
+ mainTIMER_PERIOD_MS, /* The timer's period. */\r
+ pdTRUE, /* This is an auto reload timer. */\r
+ NULL, /* ID is not used. */\r
+ prvLEDToggleTimer ); /* The callback function. */\r
+\r
+ /* Start the timer. */\r
+ configASSERT( xTimer );\r
+ xTimerStart( xTimer, mainDONT_BLOCK );\r
+\r
+ /* Start the tasks and timer running. */\r
+ vTaskStartScheduler();\r
+\r
+ /* If all is well, the scheduler will now be running, and the following\r
+ line will never be reached. If the following line does execute, then\r
+ there was either insufficient FreeRTOS heap memory available for the idle\r
+ and/or timer tasks to be created, or vTaskStartScheduler() was called from\r
+ User mode. See the memory management section on the FreeRTOS web site for\r
+ more details on the FreeRTOS heap http://www.freertos.org/a00111.html. The\r
+ mode from which main() is called is set in the C start up code and must be\r
+ a privileged mode (not user mode). */\r
+ for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvLEDToggleTimer( TimerHandle_t pxTimer )\r
+{\r
+ /* Prevent compiler warnings. */\r
+ ( void ) pxTimer;\r
+\r
+ /* Just toggle an LED to show the application is running. */\r
+ vParTestToggleLED( mainTIMER_LED );\r
+}\r
+\r
+\r
void vLwipAppsReleaseTxBuffer( void );
#define CONFIG_LINKSPEED_AUTODETECT 1
+#define OS_IS_FREERTOS
/* SSI options. */
#define TCPIP_THREAD_NAME "tcpip"
/* The following four are used only with the sequential API and can be
set to 0 if the application only will use the raw API. */
/* MEMP_NUM_NETBUF: the number of struct netbufs. */
-#define MEMP_NUM_NETBUF 8
+#define MEMP_NUM_NETBUF 0
/* MEMP_NUM_NETCONN: the number of struct netconns. */
-#define MEMP_NUM_NETCONN 16
+#define MEMP_NUM_NETCONN 10
/* MEMP_NUM_TCPIP_MSG_*: the number of struct tcpip_msg, which is used
for sequential API communication and incoming packets. Used in
TCP_SND_BUF/TCP_MSS for things to work. */
#define TCP_SND_QUEUELEN (16 * TCP_SND_BUF/TCP_MSS)
-#define CHECKSUM_GEN_TCP 0
-#define CHECKSUM_GEN_UDP 0
-#define CHECKSUM_GEN_IP 0
-#define CHECKSUM_CHECK_TCP 0
-#define CHECKSUM_CHECK_UDP 0
-#define CHECKSUM_CHECK_IP 0
-
/* TCP writable space (bytes). This must be less than or equal
to TCP_SND_BUF. It is the amount of space which must be
available in the tcp snd_buf for select to return writable */
#define ARP_TABLE_SIZE 10
#define ARP_QUEUEING 1
+#define ICMP_TTL 255
+
+#define IP_OPTIONS 0
/* ---------- IP options ---------- */
/* Define IP_FORWARD to 1 if you wish to have the ability to forward
/* IP reassembly and segmentation.These are orthogonal even
* if they both deal with IP fragments */
-#define IP_REASSEMBLY 1
-#define IP_REASS_MAX_PBUFS 128
+#define IP_REASSEMBLY 0
+#define IP_REASS_MAX_PBUFS 10
#define MEMP_NUM_REASSDATA 10
-#define IP_FRAG 1
-
-#define IP_OPTIONS 0
-#define IP_FRAG_MAX_MTU 1500
-#define IP_DEFAULT_TTL 255
-#define LWIP_CHKSUM_ALGORITHM 3
+#define IP_FRAG 0
/* ---------- ICMP options ---------- */
#endif /* LWIP_STATS */
-#define NO_SYS_NO_TIMERS 1
-#define MEMP_SEPARATE_POOLS 1
-#define MEMP_NUM_FRAG_PBUF 256
-#define IP_OPTIONS_ALLOWED 0
-#define TCP_OVERSIZE TCP_MSS
-#define LWIP_COMPAT_MUTEX 0
-#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
-
-
/* ---------- PPP options ---------- */
#define PPP_SUPPORT 0 /* Set > 0 for PPP */
\r
/* Set mainCREATE_SIMPLE_BLINKY_DEMO_ONLY to one to run the simple blinky demo,\r
or 0 to run the more comprehensive test and demo application. */\r
-#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 0\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY 1\r
\r
/*-----------------------------------------------------------*/\r
\r
\r
int main( void )\r
{\r
+extern void main_lwIP( void );\r
+\r
/* Configure the hardware ready to run the demo. */\r
prvSetupHardware();\r
\r
+main_lwIP();\r
+\r
/* The mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting is described at the top\r
of this file. */\r
#if( mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 )\r