<projectStorage><?xml version="1.0" encoding="UTF-8"?> \r
<TargetConfig> \r
<Properties property_0="" property_1="" property_2="" property_3="NXP" property_4="LPC1766ENG" property_count="5" version="1"/> \r
-<infoList vendor="NXP"> \r
-<info chip="LPC1766ENG" match_id="0x00033f33" name="LPC1766ENG"> \r
-<chip> \r
-<name>LPC1766ENG</name> \r
+<infoList vendor="NXP"><info chip="LPC1766ENG" match_id="0x00033f33" name="LPC1766ENG"><chip><name>LPC1766ENG</name> \r
<family>LPC17xx</family> \r
<vendor>NXP (formerly Philips)</vendor> \r
<reset board="None" core="Real" sys="Real"/> \r
<peripheralInstance derived_from="MPU" determined="infoFile" id="MPU" location="0xE000ED90"/> \r
<peripheralInstance derived_from="LPC1x_WDT" determined="infoFile" id="WDT" location="0x40000000"/> \r
</chip> \r
-<processor> \r
-<name gcc_name="cortex-m3">Cortex-M3</name> \r
+<processor><name gcc_name="cortex-m3">Cortex-M3</name> \r
<family>Cortex-M</family> \r
</processor> \r
<link href="nxp_lpcxxxx_peripheral.xme" show="embed" type="simple"/> \r
/*\r
- FreeRTOS.org V5.0.3 - Copyright (C) 2003-2008 Richard Barry.\r
+ FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
\r
This file is part of the FreeRTOS.org distribution.\r
\r
- FreeRTOS.org is free software; you can redistribute it and/or modify\r
- it under the terms of the GNU General Public License as published by\r
- the Free Software Foundation; either version 2 of the License, or\r
- (at your option) any later version.\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it \r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
\r
- FreeRTOS.org is distributed in the hope that it will be useful,\r
- but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\r
- GNU General Public License for more details.\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for \r
+ more details.\r
\r
- You should have received a copy of the GNU General Public License\r
- along with FreeRTOS.org; if not, write to the Free Software\r
- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
+ You should have received a copy of the GNU General Public License along \r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
\r
- A special exception to the GPL can be applied should you wish to distribute\r
- a combined work that includes FreeRTOS.org, without being obliged to provide\r
+ A special exception to the GPL is included to allow you to distribute a \r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
the source code for any proprietary components. See the licensing section\r
- of http://www.FreeRTOS.org for full details of how and when the exception\r
- can be applied.\r
-\r
- ***************************************************************************\r
- ***************************************************************************\r
- * *\r
- * SAVE TIME AND MONEY! We can port FreeRTOS.org to your own hardware, *\r
- * and even write all or part of your application on your behalf. *\r
- * See http://www.OpenRTOS.com for details of the services we provide to *\r
- * expedite your project. *\r
- * *\r
- ***************************************************************************\r
- ***************************************************************************\r
+ of http://www.FreeRTOS.org for full details.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
\r
Please ensure to read the configuration and relevant port sections of the\r
online documentation.\r
\r
- http://www.FreeRTOS.org - Documentation, latest information, license and \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
+ 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
+ http://www.OpenRTOS.com - Commercial support, development, porting,\r
licensing and training services.\r
*/\r
\r
#ifndef FREERTOS_CONFIG_H\r
#define FREERTOS_CONFIG_H\r
\r
+#include "LPC17xx.h"\r
+#include "LPC17xx_defs.h"\r
+\r
/*-----------------------------------------------------------\r
* Application specific definitions.\r
*\r
\r
#define configUSE_PREEMPTION 1\r
#define configUSE_IDLE_HOOK 0\r
-#define configUSE_TICK_HOOK 0\r
+#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )\r
+#define configUSE_TICK_HOOK 1\r
#define configCPU_CLOCK_HZ ( ( unsigned portLONG ) 72000000 )\r
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )\r
-#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 70 )\r
+#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 80 )\r
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 19 * 1024 ) )\r
#define configMAX_TASK_NAME_LEN ( 12 )\r
#define configUSE_TRACE_FACILITY 1\r
#define configUSE_CO_ROUTINES 0\r
#define configUSE_MUTEXES 1\r
\r
+#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )\r
+\r
#define configUSE_COUNTING_SEMAPHORES 0\r
#define configUSE_ALTERNATIVE_API 0\r
#define configCHECK_FOR_STACK_OVERFLOW 2\r
#define configQUEUE_REGISTRY_SIZE 10\r
#define configGENERATE_RUN_TIME_STATS 1\r
\r
-#define configMAX_PRIORITIES ( ( unsigned portBASE_TYPE ) 5 )\r
-#define configMAX_CO_ROUTINE_PRIORITIES ( 2 )\r
-\r
/* Set the following definitions to 1 to include the API function, or zero\r
to exclude the API function. */\r
\r
#define INCLUDE_vTaskDelay 1\r
#define INCLUDE_uxTaskGetStackHighWaterMark 1\r
\r
+/*-----------------------------------------------------------\r
+ * Ethernet configuration.\r
+ *-----------------------------------------------------------*/\r
\r
/* MAC address configuration. */\r
#define configMAC_ADDR0 0x00\r
#define configMAX_SYSCALL_INTERRUPT_PRIORITY ( 5 << (8 - configPRIO_BITS) )\r
\r
\r
-#define TMR0_BASE_ADDR 0x40004000\r
-#define T0TCR (*(volatile unsigned long *)(TMR0_BASE_ADDR + 0x04))\r
-#define T0CTCR (*(volatile unsigned long *)(TMR0_BASE_ADDR + 0x70))\r
-#define T0PR (*(volatile unsigned long *)(TMR0_BASE_ADDR + 0x0C))\r
-#define T0TC (*(volatile unsigned long *)(TMR0_BASE_ADDR + 0x08))\r
-#define TCR_COUNT_RESET ( 0x02 )\r
-#define TCR_COUNT_ENABLE ( 0x01 )\r
-#define CTCR_CTM_TIMER ( 0x00 )\r
\r
-#define _PCLKSEL0 (*(volatile unsigned long *)(SCB_BASE_ADDR + 0x1A8))\r
\r
+\r
+/*-----------------------------------------------------------\r
+ * Macros required to setup the timer for the run time stats.\r
+ *-----------------------------------------------------------*/\r
extern void vConfigureTimerForRunTimeStats( void );\r
#define portCONFIGURE_TIMER_FOR_RUN_TIME_STATS() vConfigureTimerForRunTimeStats()\r
#define portGET_RUN_TIME_COUNTER_VALUE() T0TC\r
\r
+\r
+/* The structure that is passed on the xLCDQueue. Put here for convenience. */\r
typedef struct\r
{\r
- long xColumn;\r
char *pcMessage;\r
} xLCDMessage;\r
\r
-\r
-\r
#endif /* FREERTOS_CONFIG_H */\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it \r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for \r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along \r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+ A special exception to the GPL is included to allow you to distribute a \r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. See the licensing section\r
+ of http://www.FreeRTOS.org for full details.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\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
+\r
+void vToggleLED( unsigned long ulLED )\r
+{\r
+ /* ulLED is a bit mask for the LED. */\r
+ \r
+ taskENTER_CRITICAL();\r
+ {\r
+ if( FIO2PIN & ulLED )\r
+ {\r
+ FIO2CLR = ulLED;\r
+ }\r
+ else\r
+ {\r
+ FIO2SET = ulLED;\r
+ }\r
+ }\r
+ taskEXIT_CRITICAL();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vSetLEDState( unsigned long ulLED, long lState )\r
+{\r
+ /* ulLED is a bit mask for the LED. */\r
+ if( lState == 0 )\r
+ {\r
+ FIO2CLR = ulLED;\r
+ }\r
+ else\r
+ {\r
+ FIO2SET = ulLED;\r
+ }\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+long lGetLEDState( unsigned long ulLED )\r
+{\r
+ /* ulLED is a bit mask for the LED. */\r
+ return FIO2PIN & ulLED;\r
+}\r
+/*-----------------------------------------------------------*/\r
--- /dev/null
+/*\r
+ FreeRTOS.org V5.2.0 - Copyright (C) 2003-2009 Richard Barry.\r
+\r
+ This file is part of the FreeRTOS.org distribution.\r
+\r
+ FreeRTOS.org is free software; you can redistribute it and/or modify it \r
+ under the terms of the GNU General Public License (version 2) as published\r
+ by the Free Software Foundation and modified by the FreeRTOS exception.\r
+\r
+ FreeRTOS.org is distributed in the hope that it will be useful, but WITHOUT\r
+ ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or \r
+ FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for \r
+ more details.\r
+\r
+ You should have received a copy of the GNU General Public License along \r
+ with FreeRTOS.org; if not, write to the Free Software Foundation, Inc., 59 \r
+ Temple Place, Suite 330, Boston, MA 02111-1307 USA.\r
+\r
+ A special exception to the GPL is included to allow you to distribute a \r
+ combined work that includes FreeRTOS.org without being obliged to provide\r
+ the source code for any proprietary components. See the licensing section\r
+ of http://www.FreeRTOS.org for full details.\r
+\r
+\r
+ ***************************************************************************\r
+ * *\r
+ * Get the FreeRTOS eBook! See http://www.FreeRTOS.org/Documentation *\r
+ * *\r
+ * This is a concise, step by step, 'hands on' guide that describes both *\r
+ * general multitasking concepts and FreeRTOS specifics. It presents and *\r
+ * explains numerous examples that are written using the FreeRTOS API. *\r
+ * Full source code for all the examples is provided in an accompanying *\r
+ * .zip file. *\r
+ * *\r
+ ***************************************************************************\r
+\r
+ 1 tab == 4 spaces!\r
+\r
+ Please ensure to read the configuration and relevant port sections of the\r
+ online documentation.\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 LED_HH\r
+#define LED_HH\r
+\r
+void vToggleLED( unsigned long ulLED );\r
+void vSetLEDState( unsigned long ulLED, long lState );\r
+long lGetLEDState( unsigned long ulLED );\r
+\r
+#endif\r
#define SRAM_BASE_AHB ((unsigned long)0x20000000) // 32 Kb\r
\r
/* System Control Space memory map */\r
-#define SCS_BASE ((unsigned long)0xE000E000)\r
+#ifndef SCS_BASE\r
+ #define SCS_BASE ((unsigned long)0xE000E000)\r
+#endif\r
\r
#define SysTick_BASE (SCS_BASE + 0x0010)\r
#define NVIC_BASE (SCS_BASE + 0x0100)\r
RM := rm -rf\r
\r
# Set the optimisation level - this should be set to 0, 1, 2, 3 or s (s for size).\r
-OPTIM=0\r
+OPTIM=1\r
\r
# Set the debug level\r
DEBUG=-g3\r
$(OUTPUT_DIR)/blocktim.o \\r
$(OUTPUT_DIR)/printf-stdarg.o \\r
$(OUTPUT_DIR)/cr_startup_nxp_cm3.o \\r
+ $(OUTPUT_DIR)/LED.o \\r
$(OUTPUT_DIR)/syscalls.o # This is just a dummy.\r
\r
# The TCP/IP and WEB server files.\r
*/\r
\r
\r
-\r
+/*\r
+ * Creates all the demo application tasks, then starts the scheduler. The WEB\r
+ * documentation provides more details of the standard demo application tasks\r
+ * (which just exist to test the kernel port and provide an example of how to use\r
+ * each FreeRTOS API function).\r
+ * \r
+ * In addition to the standard demo tasks, the following tasks and tests are\r
+ * defined and/or created within this file:\r
+ *\r
+ * "LCD" task - the LCD task is a 'gatekeeper' task. It is the only task that\r
+ * is permitted to access the display directly. Other tasks wishing to write a\r
+ * message to the LCD send the message on a queue to the LCD task instead of\r
+ * accessing the LCD themselves. The LCD task just blocks on the queue waiting\r
+ * for messages - waking and displaying the messages as they arrive. The use\r
+ * of a gatekeeper in this manner permits both tasks and interrupts to write to \r
+ * the LCD without worrying about mutual exclusion. This is demonstrated by the \r
+ * check hook (see below) which sends messages to the display even though it \r
+ * executes from an interrupt context.\r
+ *\r
+ * "Check" hook - This only executes fully every five seconds from the tick \r
+ * hook. Its main function is to check that all the standard demo tasks are \r
+ * still operational. Should any unexpected behaviour be discovered within a \r
+ * demo task then the tick hook will write an error to the LCD (via the LCD task). \r
+ * If all the demo tasks are executing with their expected behaviour then the \r
+ * check task writes PASS to the LCD (again via the LCD task), as described above.\r
+ *\r
+ * LED tasks - These just demonstrate how multiple instances of a single task\r
+ * definition can be created. Each LED task simply toggles an LED. The task\r
+ * parameter is used to pass the number of the LED to be toggled into the task.\r
+ * \r
+ * "uIP" task - This is the task that handles the uIP stack. All TCP/IP\r
+ * processing is performed in this task.\r
+ */\r
\r
/* Standard includes. */\r
#include <stdio.h>\r
/* Hardware library includes. */\r
#include "LPC17xx_defs.h"\r
\r
-\r
-#define NUM_LEDS 8\r
-\r
/* Demo app includes. */\r
#include "BlockQ.h"\r
#include "integer.h"\r
#include "QPeek.h"\r
#include "recmutex.h"\r
#include "lcd/portlcd.h"\r
+#include "LED.h"\r
\r
/*-----------------------------------------------------------*/\r
\r
+/* The number of LED tasks that will be created. */\r
+#define mainNUM_LED_TASKS ( 6 )\r
+\r
/* The time between cycles of the 'check' functionality (defined within the\r
tick hook. */\r
#define mainCHECK_DELAY ( ( portTickType ) 5000 / portTICK_RATE_MS )\r
\r
/* Task priorities. */\r
#define mainQUEUE_POLL_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainCHECK_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
#define mainSEM_TEST_PRIORITY ( tskIDLE_PRIORITY + 1 )\r
#define mainBLOCK_Q_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
-#define mainCREATOR_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainUIP_TASK_PRIORITY ( tskIDLE_PRIORITY + 3 )\r
+#define mainLCD_TASK_PRIORITY ( tskIDLE_PRIORITY + 2 )\r
#define mainINTEGER_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
#define mainGEN_QUEUE_TASK_PRIORITY ( tskIDLE_PRIORITY )\r
\r
-/* The period of the system clock in nano seconds. This is used to calculate\r
-the jitter time in nano seconds. */\r
-#define mainNS_PER_CLOCK ( ( unsigned portLONG ) ( ( 1.0 / ( double ) configCPU_CLOCK_HZ ) * 1000000000.0 ) )\r
-\r
+/* The WEB server has a larger stack as it utilises stack hungry string\r
+handling library calls. */\r
#define mainBASIC_WEB_STACK_SIZE ( configMINIMAL_STACK_SIZE * 4 )\r
+\r
+/* The length of the queue used to send messages to the LCD task. */\r
#define mainQUEUE_SIZE ( 3 )\r
+\r
/*-----------------------------------------------------------*/\r
\r
/*\r
*/\r
static void prvSetupHardware( void );\r
\r
-/*\r
- * Simply toggles the indicated LED.\r
- */\r
-static void vToggleLED( unsigned portBASE_TYPE uxLED );\r
-\r
/*\r
* Very simple task that toggles an LED.\r
*/\r
*/\r
extern void vuIP_Task( void *pvParameters );\r
\r
+/*\r
+ * The LCD gatekeeper task as described in the comments at the top of this file. \r
+ * */\r
static void vLCDTask( void *pvParameters );\r
\r
+/*-----------------------------------------------------------*/\r
+\r
/* The queue used to send messages to the LCD task. */\r
xQueueHandle xLCDQueue;\r
\r
+\r
+\r
/*-----------------------------------------------------------*/\r
\r
int main( void )\r
{\r
long l;\r
\r
+ /* Configure the hardware for use by this demo. */\r
prvSetupHardware();\r
\r
- /* Start the standard demo tasks. */\r
+ /* Start the standard demo tasks. These are just here to exercise the\r
+ kernel port and provide examples of how the FreeRTOS API can be used. */\r
vStartBlockingQueueTasks( mainBLOCK_Q_PRIORITY );\r
vCreateBlockTimeTasks();\r
vStartSemaphoreTasks( mainSEM_TEST_PRIORITY );\r
vStartQueuePeekTasks();\r
vStartRecursiveMutexTasks();\r
\r
- /* Start 8 tasks, each of which toggles a different LED at a different rate. */\r
- for( l = 0; l < NUM_LEDS; l++ )\r
+ /* Start the tasks that toggle LEDs - the LED to toggle is passed in as the\r
+ task parameter. */\r
+ for( l = 0; l < mainNUM_LED_TASKS; l++ )\r
{\r
- xTaskCreate( vLEDTask, (signed char *) "LED", configMINIMAL_STACK_SIZE, ( void * ) l, tskIDLE_PRIORITY+1, NULL );\r
+ xTaskCreate( vLEDTask, (signed char *) "LED", configMINIMAL_STACK_SIZE, ( void * ) l, tskIDLE_PRIORITY, NULL );\r
}\r
\r
- /* Create the uIP task. This uses the lwIP RTOS abstraction layer.*/\r
- xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
+ /* Create the uIP task. The WEB server runs in this task. */\r
+ xTaskCreate( vuIP_Task, ( signed char * ) "uIP", mainBASIC_WEB_STACK_SIZE, ( void * ) NULL, mainUIP_TASK_PRIORITY, NULL );\r
\r
/* Create the queue used by the LCD task. Messages for display on the LCD\r
are received via this queue. */\r
xLCDQueue = xQueueCreate( mainQUEUE_SIZE, sizeof( xLCDMessage ) );\r
\r
- /* Start the tasks defined within this file/specific to this demo. */\r
- xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE * 2, NULL, mainCHECK_TASK_PRIORITY - 1, NULL );\r
+ /* Start the LCD gatekeeper task - as described in the comments at the top\r
+ of this file. */\r
+ xTaskCreate( vLCDTask, ( signed portCHAR * ) "LCD", configMINIMAL_STACK_SIZE * 2, NULL, mainLCD_TASK_PRIORITY, NULL );\r
\r
/* Start the scheduler. */\r
vTaskStartScheduler();\r
\r
/* Will only get here if there was insufficient memory to create the idle\r
- task. */\r
+ task. The idle task is created within vTaskStartScheduler(). */\r
for( ;; );\r
}\r
/*-----------------------------------------------------------*/\r
\r
static void vLEDTask( void *pvParameters ) \r
{\r
-/* The LED to toggle is passed in as the task paramter. */\r
+/* The LED to toggle is passed in as the task parameter. */\r
long lLED = ( long ) pvParameters;\r
unsigned long ulLEDToToggle = 1 << lLED;\r
\r
\r
for( ;; )\r
{\r
+ /* Delay for the calculated time. */\r
vTaskDelay( ulDelayPeriod );\r
+ \r
+ /* Toggle the LED before going back to delay again. */\r
vToggleLED( ulLEDToToggle );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
-static void vToggleLED( unsigned portBASE_TYPE uxLED )\r
+void vLCDTask( void *pvParameters )\r
{\r
- if( FIO2PIN & uxLED )\r
+xLCDMessage xMessage;\r
+unsigned long ulRow = 0;\r
+char cIPAddr[ 17 ]; /* To fit max IP address length of xxx.xxx.xxx.xxx\0 */\r
+\r
+ ( void ) pvParameters;\r
+\r
+ /* The LCD gatekeeper task as described in the comments at the top of this\r
+ file. */\r
+ \r
+ /* Initialise the LCD and display a startup message that includes the\r
+ configured IP address. */\r
+ LCD_init();\r
+ LCD_cur_off();\r
+ LCD_cls(); \r
+ LCD_gotoxy( 1, 1 );\r
+ LCD_puts( "www.FreeRTOS.org" );\r
+ LCD_gotoxy( 1, 2 );\r
+ sprintf( cIPAddr, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
+ LCD_puts( cIPAddr );\r
+\r
+ for( ;; )\r
{\r
- FIO2CLR = uxLED;\r
+ /* Wait for a message to arrive to be displayed. */\r
+ while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
+ \r
+ /* Clear the old message. */\r
+ LCD_cls();\r
+ \r
+ /* Switch LCD rows, jut to make it obvious that messages are arriving. */\r
+ ulRow++; \r
+ LCD_gotoxy( 1, ( ulRow & 0x01 ) + 1 );\r
+ \r
+ /* Display the received text. */\r
+ LCD_puts( xMessage.pcMessage );\r
}\r
- else\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationTickHook( void )\r
+{\r
+static xLCDMessage xMessage = { "PASS" };\r
+static unsigned portLONG ulTicksSinceLastDisplay = 0;\r
+portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+\r
+ /* Called from every tick interrupt as described in the comments at the top\r
+ of this file. \r
+ \r
+ Have enough ticks passed to make it time to perform our health status \r
+ check again? */\r
+ ulTicksSinceLastDisplay++;\r
+ if( ulTicksSinceLastDisplay >= mainCHECK_DELAY )\r
{\r
- FIO2SET = uxLED;\r
+ /* Reset the counter so these checks run again in mainCHECK_DELAY\r
+ ticks time. */\r
+ ulTicksSinceLastDisplay = 0;\r
+\r
+ /* Has an error been found in any task? */\r
+ if( xAreGenericQueueTasksStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: GEN Q";\r
+ }\r
+ else if( xAreQueuePeekTasksStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: PEEK Q";\r
+ }\r
+ else if( xAreBlockingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: BLOCK Q";\r
+ }\r
+ else if( xAreBlockTimeTestTasksStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: BLOCK TIME";\r
+ }\r
+ else if( xAreSemaphoreTasksStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: SEMAPHR";\r
+ }\r
+ else if( xArePollingQueuesStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: POLL Q";\r
+ }\r
+ else if( xAreIntegerMathsTaskStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: INT MATH";\r
+ }\r
+ else if( xAreRecursiveMutexTasksStillRunning() != pdTRUE )\r
+ {\r
+ xMessage.pcMessage = "ERROR: REC MUTEX";\r
+ }\r
+\r
+ /* Send the message to the OLED gatekeeper for display. The\r
+ xHigherPriorityTaskWoken parameter is not actually used here\r
+ as this function is running in the tick interrupt anyway - but\r
+ it must still be supplied. */\r
+ xHigherPriorityTaskWoken = pdFALSE;\r
+ xQueueSendFromISR( xLCDQueue, &xMessage, &xHigherPriorityTaskWoken );\r
}\r
}\r
/*-----------------------------------------------------------*/\r
\r
void prvSetupHardware( void )\r
{\r
- PCONP = 0; /* Disable peripherals power. */\r
- PCONP = PCONP_PCGPIO; /* Enable GPIO power. */\r
- PINSEL10 = 0; /* Disable TPIU. */\r
+ /* Disable peripherals power. */\r
+ PCONP = 0; \r
+ \r
+ /* Enable GPIO power. */\r
+ PCONP = PCONP_PCGPIO; \r
\r
- PLL0CON &= ~PLLCON_PLLC; /* Disconnect the main PLL. */\r
+ /* Disable TPIU. */\r
+ PINSEL10 = 0; \r
+ \r
+ /* Disconnect the main PLL. */\r
+ PLL0CON &= ~PLLCON_PLLC; \r
PLL0FEED = PLLFEED_FEED1;\r
PLL0FEED = PLLFEED_FEED2;\r
while ((PLL0STAT & PLLSTAT_PLLC) != 0); \r
\r
- PLL0CON &= ~PLLCON_PLLE; /* Turn off the main PLL. */\r
+ /* Turn off the main PLL. */\r
+ PLL0CON &= ~PLLCON_PLLE; \r
PLL0FEED = PLLFEED_FEED1;\r
PLL0FEED = PLLFEED_FEED2;\r
while ((PLL0STAT & PLLSTAT_PLLE) != 0); \r
\r
- CCLKCFG = 0; /* No CPU clock divider. */\r
- SCS = 0x20; /* OSCEN. */\r
+ /* No CPU clock divider. */\r
+ CCLKCFG = 0;\r
+ \r
+ /* OSCEN. */\r
+ SCS = 0x20; \r
while ((SCS & 0x40) == 0);\r
\r
- CLKSRCSEL = 1; /* Use main oscillator. */\r
+ /* Use main oscillator. */\r
+ CLKSRCSEL = 1; \r
PLL0CFG = (PLLCFG_MUL16 | PLLCFG_DIV1);\r
\r
PLL0FEED = PLLFEED_FEED1;\r
PLL0FEED = PLLFEED_FEED1;\r
PLL0FEED = PLLFEED_FEED2;\r
\r
- CCLKCFG = 5; /* 6x CPU clock divider (72 MHz) */\r
+ /* 6x CPU clock divider (72 MHz) */\r
+ CCLKCFG = 5; \r
\r
/* Wait for the PLL to lock. */\r
while ((PLL0STAT & PLLSTAT_PLOCK) == 0);\r
\r
void vApplicationStackOverflowHook( xTaskHandle *pxTask, signed portCHAR *pcTaskName )\r
{\r
+ /* This function will get called if a task overflows its stack. */\r
+ \r
( void ) pxTask;\r
( void ) pcTaskName;\r
\r
\r
void vConfigureTimerForRunTimeStats( void )\r
{\r
+const unsigned long TCR_COUNT_RESET = 2, CTCR_CTM_TIMER = 0x00, TCR_COUNT_ENABLE = 0x01;\r
+\r
+ /* This function configures a timer that is used as the time base when\r
+ collecting run time statistical information - basically the percentage\r
+ of CPU time that each task is utilising. It is called automatically when\r
+ the scheduler is started (assuming configGENERATE_RUN_TIME_STATS is set\r
+ to 1. */\r
+ \r
+ /* Power up and feed the timer. */\r
PCONP |= 0x02UL;\r
- _PCLKSEL0 = (_PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
+ PCLKSEL0 = (PCLKSEL0 & (~(0x3<<2))) | (0x01 << 2);\r
\r
/* Reset Timer 0 */\r
T0TCR = TCR_COUNT_RESET;\r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vLCDTask( void *pvParameters )\r
-{\r
-xLCDMessage xMessage;\r
-char cIPAddr[ 17 ]; /* To fit max IP address length of xxx.xxx.xxx.xxx\0 */\r
-\r
- ( void ) pvParameters;\r
-\r
- /* Initialise the LCD and display a startup message. */\r
- LCD_init();\r
- LCD_cur_off();\r
- LCD_cls(); \r
- LCD_gotoxy( 1, 1 );\r
- LCD_puts( "www.FreeRTOS.org" );\r
- LCD_gotoxy( 1, 2 );\r
- sprintf( cIPAddr, "%d.%d.%d.%d", configIP_ADDR0, configIP_ADDR1, configIP_ADDR2, configIP_ADDR3 );\r
- LCD_puts( cIPAddr );\r
-\r
- for( ;; )\r
- {\r
- /* Wait for a message to arrive that requires displaying. */\r
- while( xQueueReceive( xLCDQueue, &xMessage, portMAX_DELAY ) != pdPASS );\r
- \r
- /* Display the message. Print each message to a different position. */\r
- LCD_cls();\r
- LCD_gotoxy( ( xMessage.xColumn & 0x07 ) + 1, ( xMessage.xColumn & 0x01 ) + 1 );\r
- LCD_puts( xMessage.pcMessage );\r
- }\r
-}\r
-/*-----------------------------------------------------------*/\r
/******************************************************************\r
***** *****\r
- ***** Name: cs8900.c *****\r
***** Ver.: 1.0 *****\r
***** Date: 07/05/2001 *****\r
***** Auth: Andreas Dannenberg *****\r
******************************************************************/\r
\r
/* Adapted from file originally written by Andreas Dannenberg. Supplied with permission. */\r
-\r
#include "FreeRTOS.h"\r
-#include "semphr.h" \r
+#include "semphr.h"\r
#include "task.h"\r
#include "emac.h"\r
#include "LPC17xx_defs.h"\r
\r
-#define configPINSEL2_VALUE 0x50150105\r
+#define configPINSEL2_VALUE 0x50150105\r
\r
/* The semaphore used to wake the uIP task when data arives. */\r
-xSemaphoreHandle xEMACSemaphore = NULL;\r
-\r
-static unsigned short *rptr;\r
-static unsigned short *tptr;\r
+xSemaphoreHandle xEMACSemaphore = NULL;\r
\r
-// easyWEB internal function\r
-// help function to swap the byte order of a WORD\r
+static unsigned short *rptr;\r
+static unsigned short *tptr;\r
\r
-static unsigned short SwapBytes(unsigned short Data)\r
+static unsigned short SwapBytes( unsigned short Data )\r
{\r
- return (Data >> 8) | (Data << 8);\r
+ return( Data >> 8 ) | ( Data << 8 );\r
}\r
\r
// Keil: function added to write PHY\r
-void write_PHY (int PhyReg, int Value)\r
+int write_PHY( int PhyReg, int Value )\r
{\r
- unsigned int tout;\r
- const unsigned int uiMaxTime = 10;\r
-\r
- MAC_MADR = DP83848C_DEF_ADR | PhyReg;\r
- MAC_MWTD = Value;\r
-\r
- /* Wait utill operation completed */\r
- tout = 0;\r
- for (tout = 0; tout < uiMaxTime; tout++) {\r
- if ((MAC_MIND & MIND_BUSY) == 0) {\r
- break;\r
- }\r
- vTaskDelay( 2 );\r
- }\r
+ unsigned int tout;\r
+ const unsigned int uiMaxTime = 10;\r
+\r
+ MAC_MADR = DP83848C_DEF_ADR | PhyReg;\r
+ MAC_MWTD = Value;\r
+\r
+ /* Wait utill operation completed */\r
+ tout = 0;\r
+ for( tout = 0; tout < uiMaxTime; tout++ )\r
+ {\r
+ if( (MAC_MIND & MIND_BUSY) == 0 )\r
+ {\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( 2 );\r
+ }\r
+\r
+ if( tout < uiMaxTime )\r
+ {\r
+ return pdPASS;\r
+ }\r
+ else\r
+ {\r
+ return pdFAIL;\r
+ }\r
}\r
\r
-\r
// Keil: function added to read PHY\r
-unsigned short read_PHY (unsigned char PhyReg) \r
+unsigned short read_PHY( unsigned char PhyReg, portBASE_TYPE *pxStatus )\r
{\r
- unsigned int tout;\r
- const unsigned int uiMaxTime = 10;\r
-\r
- MAC_MADR = DP83848C_DEF_ADR | PhyReg;\r
- MAC_MCMD = MCMD_READ;\r
-\r
- /* Wait until operation completed */\r
- tout = 0;\r
- for (tout = 0; tout < uiMaxTime; tout++) {\r
- if ((MAC_MIND & MIND_BUSY) == 0) {\r
- break;\r
- }\r
- vTaskDelay( 2 );\r
- }\r
- MAC_MCMD = 0;\r
- return (MAC_MRDD);\r
-}\r
+ unsigned int tout;\r
+ const unsigned int uiMaxTime = 10;\r
+\r
+ MAC_MADR = DP83848C_DEF_ADR | PhyReg;\r
+ MAC_MCMD = MCMD_READ;\r
+\r
+ /* Wait until operation completed */\r
+ tout = 0;\r
+ for( tout = 0; tout < uiMaxTime; tout++ )\r
+ {\r
+ if( (MAC_MIND & MIND_BUSY) == 0 )\r
+ {\r
+ break;\r
+ }\r
+\r
+ vTaskDelay( 2 );\r
+ }\r
+\r
+ MAC_MCMD = 0;\r
\r
+ if( tout >= uiMaxTime )\r
+ {\r
+ *pxStatus = pdFAIL;\r
+ }\r
+\r
+ return( MAC_MRDD );\r
+}\r
\r
// Keil: function added to initialize Rx Descriptors\r
-void rx_descr_init (void)\r
+void rx_descr_init( void )\r
{\r
- unsigned int i;\r
-\r
- for (i = 0; i < NUM_RX_FRAG; i++) {\r
- RX_DESC_PACKET(i) = RX_BUF(i);\r
- RX_DESC_CTRL(i) = RCTRL_INT | (ETH_FRAG_SIZE-1);\r
- RX_STAT_INFO(i) = 0;\r
- RX_STAT_HASHCRC(i) = 0;\r
- }\r
-\r
- /* Set EMAC Receive Descriptor Registers. */\r
- MAC_RXDESCRIPTOR = RX_DESC_BASE;\r
- MAC_RXSTATUS = RX_STAT_BASE;\r
- MAC_RXDESCRIPTORNUM = NUM_RX_FRAG-1;\r
-\r
- /* Rx Descriptors Point to 0 */\r
- MAC_RXCONSUMEINDEX = 0;\r
+ unsigned int i;\r
+\r
+ for( i = 0; i < NUM_RX_FRAG; i++ )\r
+ {\r
+ RX_DESC_PACKET( i ) = RX_BUF( i );\r
+ RX_DESC_CTRL( i ) = RCTRL_INT | ( ETH_FRAG_SIZE - 1 );\r
+ RX_STAT_INFO( i ) = 0;\r
+ RX_STAT_HASHCRC( i ) = 0;\r
+ }\r
+\r
+ /* Set EMAC Receive Descriptor Registers. */\r
+ MAC_RXDESCRIPTOR = RX_DESC_BASE;\r
+ MAC_RXSTATUS = RX_STAT_BASE;\r
+ MAC_RXDESCRIPTORNUM = NUM_RX_FRAG - 1;\r
+\r
+ /* Rx Descriptors Point to 0 */\r
+ MAC_RXCONSUMEINDEX = 0;\r
}\r
\r
-\r
// Keil: function added to initialize Tx Descriptors\r
-void tx_descr_init (void) {\r
- unsigned int i;\r
-\r
- for (i = 0; i < NUM_TX_FRAG; i++) {\r
- TX_DESC_PACKET(i) = TX_BUF(i);\r
- TX_DESC_CTRL(i) = 0;\r
- TX_STAT_INFO(i) = 0;\r
- }\r
-\r
- /* Set EMAC Transmit Descriptor Registers. */\r
- MAC_TXDESCRIPTOR = TX_DESC_BASE;\r
- MAC_TXSTATUS = TX_STAT_BASE;\r
- MAC_TXDESCRIPTORNUM = NUM_TX_FRAG-1;\r
-\r
- /* Tx Descriptors Point to 0 */\r
- MAC_TXPRODUCEINDEX = 0;\r
+void tx_descr_init( void )\r
+{\r
+ unsigned int i;\r
+\r
+ for( i = 0; i < NUM_TX_FRAG; i++ )\r
+ {\r
+ TX_DESC_PACKET( i ) = TX_BUF( i );\r
+ TX_DESC_CTRL( i ) = 0;\r
+ TX_STAT_INFO( i ) = 0;\r
+ }\r
+\r
+ /* Set EMAC Transmit Descriptor Registers. */\r
+ MAC_TXDESCRIPTOR = TX_DESC_BASE;\r
+ MAC_TXSTATUS = TX_STAT_BASE;\r
+ MAC_TXDESCRIPTORNUM = NUM_TX_FRAG - 1;\r
+\r
+ /* Tx Descriptors Point to 0 */\r
+ MAC_TXPRODUCEINDEX = 0;\r
}\r
\r
-\r
// configure port-pins for use with LAN-controller,\r
// reset it and send the configuration-sequence\r
-\r
-portBASE_TYPE Init_EMAC(void)\r
+portBASE_TYPE Init_EMAC( void )\r
{\r
-portBASE_TYPE xReturn = pdPASS;\r
-\r
-// Keil: function modified to access the EMAC\r
-// Initializes the EMAC ethernet controller\r
- volatile unsigned int regv,tout,id1,id2;\r
-\r
- /* Enable P1 Ethernet Pins. */\r
- PINSEL2 = configPINSEL2_VALUE;\r
- PINSEL3 = (PINSEL3 & ~0x0000000F) | 0x00000005;\r
-\r
- /* Power Up the EMAC controller. */\r
- PCONP |= PCONP_PCENET;\r
- vTaskDelay( 2 );\r
-\r
- /* Reset all EMAC internal modules. */\r
- MAC_MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | MAC1_SIM_RES | MAC1_SOFT_RES;\r
- MAC_COMMAND = CR_REG_RES | CR_TX_RES | CR_RX_RES | CR_PASS_RUNT_FRM;\r
-\r
- /* A short delay after reset. */\r
- vTaskDelay( 2 );\r
-\r
- /* Initialize MAC control registers. */\r
- MAC_MAC1 = MAC1_PASS_ALL;\r
- MAC_MAC2 = MAC2_CRC_EN | MAC2_PAD_EN;\r
- MAC_MAXF = ETH_MAX_FLEN;\r
- MAC_CLRT = CLRT_DEF;\r
- MAC_IPGR = IPGR_DEF;\r
-\r
- /* Enable Reduced MII interface. */\r
- MAC_COMMAND = CR_RMII | CR_PASS_RUNT_FRM;\r
-\r
- /* Reset Reduced MII Logic. */\r
- MAC_SUPP = SUPP_RES_RMII;\r
- vTaskDelay( 2 );\r
- MAC_SUPP = 0;\r
-\r
- /* Put the PHY in reset mode */\r
- write_PHY (PHY_REG_BMCR, 0x8000);\r
- write_PHY (PHY_REG_BMCR, 0x8000);\r
-\r
- /* Wait for hardware reset to end. */\r
- for (tout = 0; tout < 100; tout++) {\r
- vTaskDelay( 10 );\r
- regv = read_PHY (PHY_REG_BMCR);\r
- if (!(regv & 0x8000)) {\r
- /* Reset complete */\r
- break;\r
- }\r
- }\r
-\r
- /* Set the Ethernet MAC Address registers */\r
- MAC_SA0 = (emacETHADDR0 << 8) | emacETHADDR1;\r
- MAC_SA1 = (emacETHADDR2 << 8) | emacETHADDR3;\r
- MAC_SA2 = (emacETHADDR4 << 8) | emacETHADDR5;\r
-\r
- /* Initialize Tx and Rx DMA Descriptors */\r
- rx_descr_init ();\r
- tx_descr_init ();\r
-\r
- /* Receive Broadcast and Perfect Match Packets */\r
- MAC_RXFILTERCTRL = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;\r
-\r
- /* Create the semaphore used ot wake the uIP task. */\r
- vSemaphoreCreateBinary( xEMACSemaphore ); \r
- \r
- /* Check if this is a DP83848C PHY. */\r
- id1 = read_PHY (PHY_REG_IDR1);\r
- id2 = read_PHY (PHY_REG_IDR2);\r
- if (((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID) {\r
- /* Configure the PHY device */\r
-\r
- /* Use autonegotiation about the link speed. */\r
- write_PHY (PHY_REG_BMCR, PHY_AUTO_NEG);\r
- /* Wait to complete Auto_Negotiation. */\r
- for (tout = 0; tout < 10; tout++) {\r
- vTaskDelay( 100 );\r
- regv = read_PHY (PHY_REG_BMSR);\r
- if (regv & 0x0020) {\r
- /* Autonegotiation Complete. */\r
- break;\r
- }\r
- }\r
- }\r
- else\r
- {\r
- xReturn = pdFAIL;\r
- }\r
-\r
- /* Check the link status. */\r
- if( xReturn == pdPASS )\r
- {\r
- xReturn = pdFAIL;\r
- for (tout = 0; tout < 10; tout++) {\r
- vTaskDelay( 100 );\r
- regv = read_PHY (PHY_REG_STS);\r
- if (regv & 0x0001) {\r
- /* Link is on. */\r
- xReturn = pdPASS;\r
- break;\r
- }\r
- }\r
- }\r
-\r
- if( xReturn == pdPASS )\r
- {\r
- /* Configure Full/Half Duplex mode. */\r
- if (regv & 0x0004) {\r
- /* Full duplex is enabled. */\r
- MAC_MAC2 |= MAC2_FULL_DUP;\r
- MAC_COMMAND |= CR_FULL_DUP;\r
- MAC_IPGT = IPGT_FULL_DUP;\r
- }\r
- else {\r
- /* Half duplex mode. */\r
- MAC_IPGT = IPGT_HALF_DUP;\r
- }\r
-\r
- /* Configure 100MBit/10MBit mode. */\r
- if (regv & 0x0002) {\r
- /* 10MBit mode. */\r
- MAC_SUPP = 0;\r
- }\r
- else {\r
- /* 100MBit mode. */\r
- MAC_SUPP = SUPP_SPEED;\r
- }\r
-\r
- /* Reset all interrupts */\r
- MAC_INTCLEAR = 0xFFFF;\r
-\r
- /* Enable receive and transmit mode of MAC Ethernet core */\r
- MAC_COMMAND |= (CR_RX_EN | CR_TX_EN);\r
- MAC_MAC1 |= MAC1_REC_EN;\r
- }\r
-\r
- return xReturn;\r
+ portBASE_TYPE xReturn = pdPASS;\r
+\r
+ // Keil: function modified to access the EMAC\r
+ // Initializes the EMAC ethernet controller\r
+ volatile unsigned int regv, tout, id1, id2;\r
+\r
+ /* Enable P1 Ethernet Pins. */\r
+ PINSEL2 = configPINSEL2_VALUE;\r
+ PINSEL3 = ( PINSEL3 &~0x0000000F ) | 0x00000005;\r
+\r
+ /* Power Up the EMAC controller. */\r
+ PCONP |= PCONP_PCENET;\r
+ vTaskDelay( 2 );\r
+\r
+ /* Reset all EMAC internal modules. */\r
+ MAC_MAC1 = MAC1_RES_TX | MAC1_RES_MCS_TX | MAC1_RES_RX | MAC1_RES_MCS_RX | MAC1_SIM_RES | MAC1_SOFT_RES;\r
+ MAC_COMMAND = CR_REG_RES | CR_TX_RES | CR_RX_RES | CR_PASS_RUNT_FRM;\r
+\r
+ /* A short delay after reset. */\r
+ vTaskDelay( 2 );\r
+\r
+ /* Initialize MAC control registers. */\r
+ MAC_MAC1 = MAC1_PASS_ALL;\r
+ MAC_MAC2 = MAC2_CRC_EN | MAC2_PAD_EN;\r
+ MAC_MAXF = ETH_MAX_FLEN;\r
+ MAC_CLRT = CLRT_DEF;\r
+ MAC_IPGR = IPGR_DEF;\r
+\r
+ /* Enable Reduced MII interface. */\r
+ MAC_COMMAND = CR_RMII | CR_PASS_RUNT_FRM;\r
+\r
+ /* Reset Reduced MII Logic. */\r
+ MAC_SUPP = SUPP_RES_RMII;\r
+ vTaskDelay( 2 );\r
+ MAC_SUPP = 0;\r
+\r
+ /* Put the PHY in reset mode */\r
+ write_PHY( PHY_REG_BMCR, 0x8000 );\r
+ xReturn = write_PHY( PHY_REG_BMCR, 0x8000 );\r
+\r
+ /* Wait for hardware reset to end. */\r
+ for( tout = 0; tout < 100; tout++ )\r
+ {\r
+ vTaskDelay( 10 );\r
+ regv = read_PHY( PHY_REG_BMCR, &xReturn );\r
+ if( !(regv & 0x8000) )\r
+ {\r
+ /* Reset complete */\r
+ break;\r
+ }\r
+ }\r
+\r
+ /* Check if this is a DP83848C PHY. */\r
+ id1 = read_PHY( PHY_REG_IDR1, &xReturn );\r
+ id2 = read_PHY( PHY_REG_IDR2, &xReturn );\r
+ if( ((id1 << 16) | (id2 & 0xFFF0)) == DP83848C_ID )\r
+ {\r
+ /* Set the Ethernet MAC Address registers */\r
+ MAC_SA0 = ( emacETHADDR0 << 8 ) | emacETHADDR1;\r
+ MAC_SA1 = ( emacETHADDR2 << 8 ) | emacETHADDR3;\r
+ MAC_SA2 = ( emacETHADDR4 << 8 ) | emacETHADDR5;\r
+\r
+ /* Initialize Tx and Rx DMA Descriptors */\r
+ rx_descr_init();\r
+ tx_descr_init();\r
+\r
+ /* Receive Broadcast and Perfect Match Packets */\r
+ MAC_RXFILTERCTRL = RFC_UCAST_EN | RFC_BCAST_EN | RFC_PERFECT_EN;\r
+\r
+ /* Create the semaphore used ot wake the uIP task. */\r
+ vSemaphoreCreateBinary( xEMACSemaphore );\r
+\r
+ /* Configure the PHY device */\r
+\r
+ /* Use autonegotiation about the link speed. */\r
+ if( write_PHY(PHY_REG_BMCR, PHY_AUTO_NEG) )\r
+ {\r
+ /* Wait to complete Auto_Negotiation. */\r
+ for( tout = 0; tout < 10; tout++ )\r
+ {\r
+ vTaskDelay( 100 );\r
+ regv = read_PHY( PHY_REG_BMSR, &xReturn );\r
+ if( regv & 0x0020 )\r
+ {\r
+ /* Autonegotiation Complete. */\r
+ break;\r
+ }\r
+ }\r
+ }\r
+ }\r
+ else\r
+ {\r
+ xReturn = pdFAIL;\r
+ }\r
+\r
+ /* Check the link status. */\r
+ if( xReturn == pdPASS )\r
+ {\r
+ xReturn = pdFAIL;\r
+ for( tout = 0; tout < 10; tout++ )\r
+ {\r
+ vTaskDelay( 100 );\r
+ regv = read_PHY( PHY_REG_STS, &xReturn );\r
+ if( regv & 0x0001 )\r
+ {\r
+ /* Link is on. */\r
+ xReturn = pdPASS;\r
+ break;\r
+ }\r
+ }\r
+ }\r
+\r
+ if( xReturn == pdPASS )\r
+ {\r
+ /* Configure Full/Half Duplex mode. */\r
+ if( regv & 0x0004 )\r
+ {\r
+ /* Full duplex is enabled. */\r
+ MAC_MAC2 |= MAC2_FULL_DUP;\r
+ MAC_COMMAND |= CR_FULL_DUP;\r
+ MAC_IPGT = IPGT_FULL_DUP;\r
+ }\r
+ else\r
+ {\r
+ /* Half duplex mode. */\r
+ MAC_IPGT = IPGT_HALF_DUP;\r
+ }\r
+\r
+ /* Configure 100MBit/10MBit mode. */\r
+ if( regv & 0x0002 )\r
+ {\r
+ /* 10MBit mode. */\r
+ MAC_SUPP = 0;\r
+ }\r
+ else\r
+ {\r
+ /* 100MBit mode. */\r
+ MAC_SUPP = SUPP_SPEED;\r
+ }\r
+\r
+ /* Reset all interrupts */\r
+ MAC_INTCLEAR = 0xFFFF;\r
+\r
+ /* Enable receive and transmit mode of MAC Ethernet core */\r
+ MAC_COMMAND |= ( CR_RX_EN | CR_TX_EN );\r
+ MAC_MAC1 |= MAC1_REC_EN;\r
+ }\r
+\r
+ return xReturn;\r
}\r
\r
-\r
// reads a word in little-endian byte order from RX_BUFFER\r
-\r
-unsigned short ReadFrame_EMAC(void)\r
+unsigned short ReadFrame_EMAC( void )\r
{\r
- return (*rptr++);\r
+ return( *rptr++ );\r
}\r
\r
// reads a word in big-endian byte order from RX_FRAME_PORT\r
// (useful to avoid permanent byte-swapping while reading\r
// TCP/IP-data)\r
-\r
-unsigned short ReadFrameBE_EMAC(void)\r
+unsigned short ReadFrameBE_EMAC( void )\r
{\r
- unsigned short ReturnValue;\r
+ unsigned short ReturnValue;\r
\r
- ReturnValue = SwapBytes (*rptr++);\r
- return (ReturnValue);\r
+ ReturnValue = SwapBytes( *rptr++ );\r
+ return( ReturnValue );\r
}\r
\r
-\r
// copies bytes from frame port to MCU-memory\r
// NOTES: * an odd number of byte may only be transfered\r
// if the frame is read to the end!\r
// * MCU-memory MUST start at word-boundary\r
-\r
-void CopyFromFrame_EMAC(void *Dest, unsigned short Size)\r
+void CopyFromFrame_EMAC( void *Dest, unsigned short Size )\r
{\r
- unsigned short * piDest; // Keil: Pointer added to correct expression\r
-\r
- piDest = Dest; // Keil: Line added\r
- while (Size > 1) {\r
- *piDest++ = ReadFrame_EMAC();\r
- Size -= 2;\r
- }\r
- \r
- if (Size) { // check for leftover byte...\r
- *(unsigned char *)piDest = (char)ReadFrame_EMAC();// the LAN-Controller will return 0\r
- } // for the highbyte\r
+ unsigned short *piDest; // Keil: Pointer added to correct expression\r
+ piDest = Dest; // Keil: Line added\r
+ while( Size > 1 )\r
+ {\r
+ *piDest++ = ReadFrame_EMAC();\r
+ Size -= 2;\r
+ }\r
+\r
+ if( Size )\r
+ { // check for leftover byte...\r
+ *( unsigned char * ) piDest = ( char ) ReadFrame_EMAC(); // the LAN-Controller will return 0\r
+ } // for the highbyte\r
}\r
\r
// does a dummy read on frame-I/O-port\r
// NOTE: only an even number of bytes is read!\r
-\r
-void DummyReadFrame_EMAC(unsigned short Size) // discards an EVEN number of bytes\r
-{ // from RX-fifo\r
- while (Size > 1) {\r
- ReadFrame_EMAC();\r
- Size -= 2;\r
- }\r
+void DummyReadFrame_EMAC( unsigned short Size ) // discards an EVEN number of bytes\r
+{ // from RX-fifo\r
+ while( Size > 1 )\r
+ {\r
+ ReadFrame_EMAC();\r
+ Size -= 2;\r
+ }\r
}\r
\r
-// Reads the length of the received ethernet frame and checks if the \r
+// Reads the length of the received ethernet frame and checks if the\r
// destination address is a broadcast message or not\r
// returns the frame length\r
-unsigned short StartReadFrame(void) {\r
- unsigned short RxLen;\r
- unsigned int idx;\r
-\r
- idx = MAC_RXCONSUMEINDEX;\r
- RxLen = (RX_STAT_INFO(idx) & RINFO_SIZE) - 3;\r
- rptr = (unsigned short *)RX_DESC_PACKET(idx);\r
- return(RxLen);\r
+unsigned short StartReadFrame( void )\r
+{\r
+ unsigned short RxLen;\r
+ unsigned int idx;\r
+\r
+ idx = MAC_RXCONSUMEINDEX;\r
+ RxLen = ( RX_STAT_INFO(idx) & RINFO_SIZE ) - 3;\r
+ rptr = ( unsigned short * ) RX_DESC_PACKET( idx );\r
+ return( RxLen );\r
}\r
\r
-void EndReadFrame(void) {\r
- unsigned int idx;\r
+void EndReadFrame( void )\r
+{\r
+ unsigned int idx;\r
\r
- /* DMA free packet. */\r
- idx = MAC_RXCONSUMEINDEX;\r
+ /* DMA free packet. */\r
+ idx = MAC_RXCONSUMEINDEX;\r
\r
- if (++idx == NUM_RX_FRAG)\r
- idx = 0;\r
+ if( ++idx == NUM_RX_FRAG )\r
+ {\r
+ idx = 0;\r
+ }\r
\r
- MAC_RXCONSUMEINDEX = idx;\r
+ MAC_RXCONSUMEINDEX = idx;\r
}\r
\r
-unsigned int CheckFrameReceived(void) { // Packet received ?\r
-\r
- if (MAC_RXPRODUCEINDEX != MAC_RXCONSUMEINDEX) // more packets received ?\r
- return(1);\r
- else \r
- return(0);\r
+unsigned int CheckFrameReceived( void )\r
+{ \r
+ // Packet received ?\r
+ if( MAC_RXPRODUCEINDEX != MAC_RXCONSUMEINDEX )\r
+ { // more packets received ?\r
+ return( 1 );\r
+ }\r
+ else\r
+ {\r
+ return( 0 );\r
+ }\r
}\r
\r
unsigned int uiGetEMACRxData( unsigned char *ucBuffer )\r
{\r
-unsigned int uiLen = 0;\r
+ unsigned int uiLen = 0;\r
\r
- if( MAC_RXPRODUCEINDEX != MAC_RXCONSUMEINDEX )\r
- {\r
- uiLen = StartReadFrame();\r
- CopyFromFrame_EMAC( ucBuffer, uiLen );\r
- EndReadFrame();\r
- }\r
+ if( MAC_RXPRODUCEINDEX != MAC_RXCONSUMEINDEX )\r
+ {\r
+ uiLen = StartReadFrame();\r
+ CopyFromFrame_EMAC( ucBuffer, uiLen );\r
+ EndReadFrame();\r
+ }\r
\r
- return uiLen;\r
+ return uiLen;\r
}\r
\r
// requests space in EMAC memory for storing an outgoing frame\r
-\r
-void RequestSend(void)\r
+void RequestSend( void )\r
{\r
- unsigned int idx;\r
+ unsigned int idx;\r
\r
- idx = MAC_TXPRODUCEINDEX;\r
- tptr = (unsigned short *)TX_DESC_PACKET(idx);\r
+ idx = MAC_TXPRODUCEINDEX;\r
+ tptr = ( unsigned short * ) TX_DESC_PACKET( idx );\r
}\r
\r
// check if ethernet controller is ready to accept the\r
// frame we want to send\r
-\r
-unsigned int Rdy4Tx(void)\r
+unsigned int Rdy4Tx( void )\r
{\r
- return (1); // the ethernet controller transmits much faster\r
-} // than the CPU can load its buffers\r
-\r
+ return( 1 ); // the ethernet controller transmits much faster\r
+} // than the CPU can load its buffers\r
\r
// writes a word in little-endian byte order to TX_BUFFER\r
-void WriteFrame_EMAC(unsigned short Data)\r
+void WriteFrame_EMAC( unsigned short Data )\r
{\r
- *tptr++ = Data;\r
+ *tptr++ = Data;\r
}\r
\r
// copies bytes from MCU-memory to frame port\r
// NOTES: * an odd number of byte may only be transfered\r
// if the frame is written to the end!\r
// * MCU-memory MUST start at word-boundary\r
-\r
-void CopyToFrame_EMAC(void *Source, unsigned int Size)\r
+void CopyToFrame_EMAC( void *Source, unsigned int Size )\r
{\r
- unsigned short * piSource;\r
-\r
- piSource = Source;\r
- Size = (Size + 1) & 0xFFFE; // round Size up to next even number\r
- while (Size > 0) {\r
- WriteFrame_EMAC(*piSource++);\r
- Size -= 2;\r
- }\r
+ unsigned short *piSource;\r
+\r
+ piSource = Source;\r
+ Size = ( Size + 1 ) & 0xFFFE; // round Size up to next even number\r
+ while( Size > 0 )\r
+ {\r
+ WriteFrame_EMAC( *piSource++ );\r
+ Size -= 2;\r
+ }\r
}\r
\r
-void DoSend_EMAC(unsigned short FrameSize)\r
+void DoSend_EMAC( unsigned short FrameSize )\r
{\r
- unsigned int idx;\r
+ unsigned int idx;\r
+\r
+ idx = MAC_TXPRODUCEINDEX;\r
+ TX_DESC_CTRL( idx ) = FrameSize | TCTRL_LAST;\r
+ if( ++idx == NUM_TX_FRAG )\r
+ {\r
+ idx = 0;\r
+ }\r
\r
- idx = MAC_TXPRODUCEINDEX;\r
- TX_DESC_CTRL(idx) = FrameSize | TCTRL_LAST;\r
- if (++idx == NUM_TX_FRAG) idx = 0;\r
- MAC_TXPRODUCEINDEX = idx;\r
+ MAC_TXPRODUCEINDEX = idx;\r
}\r
\r
void vEMAC_ISR( void )\r
{\r
-portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
+ portBASE_TYPE xHigherPriorityTaskWoken = pdFALSE;\r
\r
- /* Clear the interrupt. */\r
- MAC_INTCLEAR = 0xffff;\r
+ /* Clear the interrupt. */\r
+ MAC_INTCLEAR = 0xffff;\r
\r
- /* Ensure the uIP task is not blocked as data has arrived. */\r
- xSemaphoreGiveFromISR( xEMACSemaphore, &xHigherPriorityTaskWoken );\r
+ /* Ensure the uIP task is not blocked as data has arrived. */\r
+ xSemaphoreGiveFromISR( xEMACSemaphore, &xHigherPriorityTaskWoken );\r
\r
- portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
+ portEND_SWITCHING_ISR( xHigherPriorityTaskWoken );\r
}\r
#include <stdio.h>\r
#include <string.h>\r
\r
+#include "LED.h"\r
+\r
HTTPD_CGI_CALL(file, "file-stats", file_stats);\r
HTTPD_CGI_CALL(tcp, "tcp-connections", tcp_stats);\r
HTTPD_CGI_CALL(net, "net-stats", net_stats);\r
}\r
/*---------------------------------------------------------------------------*/\r
\r
-char *pcStatus[ 3 ];\r
+char *pcStatus;\r
unsigned long ulString;\r
-extern unsigned long uxParTextGetLED( unsigned long uxLED );\r
\r
static unsigned short generate_io_state( void *arg )\r
{\r
( void ) arg;\r
- \r
-// for( ulString = 0; ulString < 3; ulString++ )\r
-// {\r
-// if( uxParTextGetLED( ulString + 5 ) )\r
-// {\r
-// pcStatus[ ulString ] = "checked";\r
-// }\r
-// else\r
-// {\r
-// pcStatus[ ulString ] = "";\r
-// }\r
-// }\r
+\r
+ if( lGetLEDState( 1 << 7 ) == 0 )\r
+ {\r
+ pcStatus = "";\r
+ }\r
+ else\r
+ {\r
+ pcStatus = "checked";\r
+ }\r
\r
sprintf( uip_appdata,\r
- "<input type=\"checkbox\" name=\"LED0\" value=\"1\" %s>LED 2.5,"\\r
- "<input type=\"checkbox\" name=\"LED1\" value=\"1\" %s>LED 2.6,"\\r
- "<input type=\"checkbox\" name=\"LED2\" value=\"1\" %s>LED 2.7"\\r
+ "<input type=\"checkbox\" name=\"LED0\" value=\"1\" %s>LED 7"\\r
"<p>"\\r
"<input type=\"text\" name=\"LCD\" value=\"Enter LCD text\" size=\"16\">",\r
- pcStatus[ 0 ], \r
- pcStatus[ 1 ], \r
- pcStatus[ 2 ] );\r
+ pcStatus );\r
\r
return strlen( uip_appdata );\r
}\r
\r
/* Process any form input being sent to the server. */\r
{\r
- extern void vApplicationProcessFormInput( char *pcInputString, long xInputLength );\r
- vApplicationProcessFormInput( s->inputbuf, PSOCK_DATALEN(&s->sin) );\r
+ extern void vApplicationProcessFormInput( char *pcInputString );\r
+ vApplicationProcessFormInput( s->inputbuf );\r
}\r
\r
strncpy(s->filename, &s->inputbuf[0], sizeof(s->filename));\r
http://www.OpenRTOS.com - Commercial support, development, porting,\r
licensing and training services.\r
*/\r
+\r
/* Standard includes. */\r
#include <string.h>\r
\r
\r
/* Demo includes. */\r
#include "emac.h"\r
-//#include "partest.h"\r
+#include "LED.h"\r
\r
-//#include "LPC17xx_defs.h"\r
#include "LPC17xx.h"\r
#include "core_cm3.h"\r
/*-----------------------------------------------------------*/\r
#define uipTOTAL_FRAME_HEADER_SIZE 54\r
\r
\r
-#define MAC_INTENABLE (*(volatile unsigned long *)(EMAC_BASE + 0xFE4)) /* Interrupt enable reg */\r
/*-----------------------------------------------------------*/\r
\r
/* \r
}\r
/*-----------------------------------------------------------*/\r
\r
-void vApplicationProcessFormInput( portCHAR *pcInputString, portBASE_TYPE xInputLength )\r
+void vApplicationProcessFormInput( portCHAR *pcInputString )\r
{\r
char *c, *pcText;\r
static portCHAR cMessageForDisplay[ 32 ];\r
extern xQueueHandle xLCDQueue;\r
-//xLCDMessage xLCDMessage;\r
+xLCDMessage xLCDMessage;\r
\r
/* Process the form input sent by the IO page of the served HTML. */\r
\r
/* Turn LED's on or off in accordance with the check box status. */\r
if( strstr( c, "LED0=1" ) != NULL )\r
{\r
-// vParTestSetLED( 5, 0 );\r
+ /* Set LED7. */\r
+ vSetLEDState( 1 << 7, 1 );\r
}\r
else\r
{\r
-// vParTestSetLED( 5, 1 );\r
+ /* Clear LED7. */\r
+ vSetLEDState( 1 << 7, 0 );\r
} \r
\r
- if( strstr( c, "LED1=1" ) != NULL )\r
- {\r
-// vParTestSetLED( 6, 0 );\r
- }\r
- else\r
- {\r
-// vParTestSetLED( 6, 1 );\r
- } \r
-\r
- if( strstr( c, "LED2=1" ) != NULL )\r
- {\r
-// vParTestSetLED( 7, 0 );\r
- }\r
- else\r
- {\r
-// vParTestSetLED( 7, 1 );\r
- }\r
-\r
/* Find the start of the text to be displayed on the LCD. */\r
pcText = strstr( c, "LCD=" );\r
pcText += strlen( "LCD=" );\r
}\r
\r
/* Write the message to the LCD. */\r
-// strcpy( cMessageForDisplay, pcText );\r
-// xLCDMessage.xColumn = 0;\r
-// xLCDMessage.pcMessage = cMessageForDisplay;\r
-// xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );\r
+ strcpy( cMessageForDisplay, pcText );\r
+ xLCDMessage.pcMessage = cMessageForDisplay;\r
+ xQueueSend( xLCDQueue, &xLCDMessage, portMAX_DELAY );\r
}\r
}\r
\r