]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/main.c
Core kernel files:
[freertos] / FreeRTOS / Demo / CORTEX_A5_SAMA5D4x_EK_IAR / main.c
diff --git a/FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/main.c b/FreeRTOS/Demo/CORTEX_A5_SAMA5D4x_EK_IAR/main.c
new file mode 100644 (file)
index 0000000..20ff22c
--- /dev/null
@@ -0,0 +1,280 @@
+/*\r
+    FreeRTOS V8.1.2 - 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
+ * This project provides two demo applications.  A simple blinky style project,\r
+ * and a more comprehensive test and demo application.  The\r
+ * mainCREATE_SIMPLE_BLINKY_DEMO_ONLY setting (defined in this file) is used to\r
+ * select between the two.  The simply blinky demo is implemented and described\r
+ * in main_blinky.c.  The more comprehensive test and demo application is\r
+ * implemented and described in main_full.c.\r
+ *\r
+ * This file implements the code that is not demo specific, including the\r
+ * hardware setup, standard FreeRTOS hook functions, and the ISR hander called\r
+ * by the RTOS after interrupt entry (including nesting) has been taken care of.\r
+ *\r
+ * ENSURE TO READ THE DOCUMENTATION PAGE FOR THIS PORT AND DEMO APPLICATION ON\r
+ * THE http://www.FreeRTOS.org WEB SITE FOR FULL INFORMATION ON USING THIS DEMO\r
+ * APPLICATION, AND ITS ASSOCIATE FreeRTOS ARCHITECTURE PORT!\r
+ *\r
+ */\r
+\r
+/* Scheduler include files. */\r
+#include "FreeRTOS.h"\r
+#include "task.h"\r
+#include "semphr.h"\r
+\r
+/* Standard demo includes. */\r
+#include "partest.h"\r
+#include "TimerDemo.h"\r
+#include "QueueOverwrite.h"\r
+#include "EventGroupsDemo.h"\r
+\r
+/* Library includes. */\r
+#include "chip.h"\r
+\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     1\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+/*\r
+ * Configure the hardware as necessary to run this demo.\r
+ */\r
+static void prvSetupHardware( void );\r
+\r
+/*\r
+ * main_blinky() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1.\r
+ * main_full() is used when mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0.\r
+ */\r
+#if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1\r
+       extern void main_blinky( void );\r
+#else\r
+       extern void main_full( void );\r
+#endif /* #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 1 */\r
+\r
+/* Prototypes for the standard FreeRTOS callback/hook functions implemented\r
+within this file. */\r
+void vApplicationMallocFailedHook( void );\r
+void vApplicationIdleHook( void );\r
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName );\r
+void vApplicationTickHook( void );\r
+\r
+/* Prototype for the IRQ handler called by the generic Cortex-A5 RTOS port\r
+layer.  The address of the ISR is passed into this function as a parameter.\r
+Note this level of indirection could be removed by creating a SAMA5 specific\r
+port layer that calls the IRQ directly from the port layer rather than via this\r
+application callback. */\r
+void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress );\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
+int main( void )\r
+{\r
+//extern int atmel_main( void );\r
+//atmel_main();\r
+\r
+       /* Configure the hardware ready to run the demo. */\r
+       prvSetupHardware();\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
+       {\r
+               main_blinky();\r
+       }\r
+       #else\r
+       {\r
+               main_full();\r
+       }\r
+       #endif\r
+\r
+       return 0;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+static void prvSetupHardware( void )\r
+{\r
+    /* Disable watchdog */\r
+    WDT_Disable( WDT );\r
+\r
+       /* Set protect mode in the AIC for easier debugging. */\r
+//     AIC->AIC_DCR |= AIC_DCR_PROT;\r
+\r
+       /* Configure ports used by LEDs. */\r
+       vParTestInitialise();\r
+\r
+//_RB_ CP15_EnableIcache();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationMallocFailedHook( void )\r
+{\r
+       /* Called if a call to pvPortMalloc() fails because there is insufficient\r
+       free memory available in the FreeRTOS heap.  pvPortMalloc() is called\r
+       internally by FreeRTOS API functions that create tasks, queues, software\r
+       timers, and semaphores.  The size of the FreeRTOS heap is set by the\r
+       configTOTAL_HEAP_SIZE configuration constant in FreeRTOSConfig.h. */\r
+       taskDISABLE_INTERRUPTS();\r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )\r
+{\r
+       ( void ) pcTaskName;\r
+       ( void ) pxTask;\r
+\r
+       /* Run time stack overflow checking is performed if\r
+       configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2.  This hook\r
+       function is called if a stack overflow is detected. */\r
+       taskDISABLE_INTERRUPTS();\r
+       for( ;; );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationIdleHook( void )\r
+{\r
+volatile size_t xFreeHeapSpace;\r
+\r
+       /* This is just a trivial example of an idle hook.  It is called on each\r
+       cycle of the idle task.  It must *NOT* attempt to block.  In this case the\r
+       idle task just queries the amount of FreeRTOS heap that remains.  See the\r
+       memory management section on the http://www.FreeRTOS.org web site for memory\r
+       management options.  If there is a lot of heap memory free then the\r
+       configTOTAL_HEAP_SIZE value in FreeRTOSConfig.h can be reduced to free up\r
+       RAM. */\r
+       xFreeHeapSpace = xPortGetFreeHeapSize();\r
+\r
+       /* Remove compiler warning about xFreeHeapSpace being set but never used. */\r
+       ( void ) xFreeHeapSpace;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vAssertCalled( const char * pcFile, unsigned long ulLine )\r
+{\r
+volatile unsigned long ul = 0;\r
+\r
+       ( void ) pcFile;\r
+       ( void ) ulLine;\r
+\r
+       taskENTER_CRITICAL();\r
+       {\r
+               /* Set ul to a non-zero value using the debugger to step out of this\r
+               function. */\r
+               while( ul == 0 )\r
+               {\r
+                       portNOP();\r
+               }\r
+       }\r
+       taskEXIT_CRITICAL();\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationTickHook( void )\r
+{\r
+       #if mainCREATE_SIMPLE_BLINKY_DEMO_ONLY == 0\r
+       {\r
+               /* The full demo includes a software timer demo/test that requires\r
+               prodding periodically from the tick interrupt. */\r
+               vTimerPeriodicISRTests();\r
+\r
+               /* Call the periodic queue overwrite from ISR demo. */\r
+               vQueueOverwritePeriodicISRDemo();\r
+\r
+               /* Call the periodic event group from ISR demo. */\r
+               vPeriodicEventGroupsProcessing();\r
+       }\r
+       #endif\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+/* The function called by the RTOS port layer after it has managed interrupt\r
+entry. */\r
+void vApplicationIRQHandler( uint32_t ulInterruptVectorAddress )\r
+{\r
+typedef void (*ISRFunction_t)( void );\r
+ISRFunction_t pxISRFunction;\r
+volatile uint32_t * pulAIC_IVR = ( uint32_t * ) configINTERRUPT_VECTOR_ADDRESS;\r
+\r
+       /* On the SAMA5 the parameter is a pointer to the ISR handling function. */\r
+       pxISRFunction = ( ISRFunction_t ) ulInterruptVectorAddress;\r
+\r
+       /* Write back to the SAMA5's interrupt controller's IVR register in case the\r
+       CPU is in protect mode.  If the interrupt controller is not in protect mode\r
+       then this write is not necessary. */\r
+       *pulAIC_IVR = 0;\r
+\r
+       /* Ensure the write takes before re-enabling interrupts. */\r
+       __DSB();\r
+       __ISB();\r
+    __enable_irq();\r
+\r
+       /* Call the installed ISR. */\r
+       pxISRFunction();\r
+}\r
+\r
+\r