]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_A9_Cyclone_V_SoC_DK/main.c
Update version number ready for version 9 release candidate 1.
[freertos] / FreeRTOS / Demo / CORTEX_A9_Cyclone_V_SoC_DK / main.c
index e7000fcab11ed33c4b138d1cf5d2c5b025519efc..406ab82572c5cb55480a53537805c3ef8245ff24 100644 (file)
+/*\r
+    FreeRTOS V9.0.0rc1 - Copyright (C) 2016 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
+    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
+    ***************************************************************************\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
+\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 on the following\r
+    link: http://www.freertos.org/a00114.html\r
+\r
+    ***************************************************************************\r
+     *                                                                       *\r
+     *    FreeRTOS provides completely free yet professionally developed,    *\r
+     *    robust, strictly quality controlled, supported, and cross          *\r
+     *    platform software that is more than just the market leader, it     *\r
+     *    is the industry's de facto standard.                               *\r
+     *                                                                       *\r
+     *    Help yourself get started quickly while simultaneously helping     *\r
+     *    to support the FreeRTOS project by purchasing a FreeRTOS           *\r
+     *    tutorial book, reference manual, or both:                          *\r
+     *    http://www.FreeRTOS.org/Documentation                              *\r
+     *                                                                       *\r
+    ***************************************************************************\r
+\r
+    http://www.FreeRTOS.org/FAQHelp.html - Having a problem?  Start by reading\r
+    the FAQ page "My application does not run, what could be wrong?".  Have you\r
+    defined configASSERT()?\r
+\r
+    http://www.FreeRTOS.org/support - In return for receiving this top quality\r
+    embedded software for free we request you assist our global community by\r
+    participating in the support forum.\r
+\r
+    http://www.FreeRTOS.org/training - Investing in training allows your team to\r
+    be as productive as possible as early as possible.  Now you can receive\r
+    FreeRTOS training directly from Richard Barry, CEO of Real Time Engineers\r
+    Ltd, and the world's leading authority on the world's leading RTOS.\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.FreeRTOS.org/labs - Where new FreeRTOS products go to incubate.\r
+    Come and try FreeRTOS+TCP, our new open source TCP/IP stack for FreeRTOS.\r
+\r
+    http://www.OpenRTOS.com - Real Time Engineers ltd. license FreeRTOS to High\r
+    Integrity Systems ltd. to sell under the OpenRTOS brand.  Low cost OpenRTOS\r
+    licenses offer ticketed support, indemnification and commercial 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 and FreeRTOS hook functions.\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
 /* Standard includes. */\r
-#include <stdint.h>\r
+#include <stdio.h>\r
+#include <limits.h>\r
 \r
-/* FreeRTOS includes. */\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
+#include "IntSemTest.h"\r
+\r
+/* Altera library includes. */\r
+#include "alt_timers.h"\r
+#include "alt_clock_manager.h"\r
+#include "alt_interrupt.h"\r
+#include "alt_globaltmr.h"\r
+#include "alt_address_space.h"\r
+#include "mmu_support.h"\r
+#include "cache_support.h"\r
+\r
+/* mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is used to select between two demo\r
+ * applications, as described at the top of this file.\r
+ *\r
+ * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 1 the simple blinky example\r
+ * will be run.\r
+ *\r
+ * When mainCREATE_SIMPLE_BLINKY_DEMO_ONLY is set to 0 the comprehensive test\r
+ * and demo application will be run.\r
+ */\r
+#define mainCREATE_SIMPLE_BLINKY_DEMO_ONLY     1\r
 \r
 /*-----------------------------------------------------------*/\r
 \r
-/* Perform any hardware initialisation necessary. */\r
+/*\r
+ * Configure the hardware as necessary to run this demo.\r
+ */\r
 static void prvSetupHardware( void );\r
 \r
+/*\r
+ * See the comments at the top of this file and above the\r
+ * mainSELECTED_APPLICATION definition.\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
@@ -19,10 +146,39 @@ void vApplicationTickHook( void );
 \r
 /*-----------------------------------------------------------*/\r
 \r
+/* configAPPLICATION_ALLOCATED_HEAP is set to 1 in FreeRTOSConfig.h so the\r
+application can define the array used as the FreeRTOS heap.  This is done so the\r
+heap can be forced into fast internal RAM - useful because the stacks used by\r
+the tasks come from this space. */\r
+uint8_t ucHeap[ configTOTAL_HEAP_SIZE ] __attribute__ ( ( section( ".oc_ram" ) ) );\r
+\r
+/* FreeRTOS uses its own interrupt handler code.  This code cannot use the array\r
+of handlers defined by the Altera drivers because the array is declared static,\r
+and so not accessible outside of the dirver's source file.  Instead declare an\r
+array for use by the FreeRTOS handler.  See:\r
+http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html. */\r
+static INT_DISPATCH_t xISRHandlers[ ALT_INT_PROVISION_INT_COUNT ];\r
+\r
+/*-----------------------------------------------------------*/\r
+\r
 int main( void )\r
 {\r
+       /* Configure the hardware ready to run the demo. */\r
        prvSetupHardware();\r
-       vTaskStartScheduler();\r
+\r
+       /* The mainSELECTED_APPLICATION 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
+       /* Don't expect to reach here. */\r
        return 0;\r
 }\r
 /*-----------------------------------------------------------*/\r
@@ -34,6 +190,7 @@ uint32_t ulSCTLR, ulVectorTable = ( uint32_t ) &__cs3_interrupt_vector;
 const uint32_t ulVBit = 13U;\r
 \r
        alt_int_global_init();\r
+       alt_int_cpu_binary_point_set( 0 );\r
 \r
        /* Clear SCTLR.V for low vectors and map the vector table to the beginning\r
        of the code. */\r
@@ -44,47 +201,10 @@ const uint32_t ulVBit = 13U;
 \r
        cache_init();\r
        mmu_init();\r
-}\r
-/*-----------------------------------------------------------*/\r
-\r
-void vConfigureTickInterrupt( void )\r
-{\r
-alt_freq_t ulTempFrequency;\r
-const alt_freq_t ulMicroSecondsPerSecond = 1000000UL;\r
-void FreeRTOS_Tick_Handler( void );\r
-\r
-       /* Interrupts are disabled when this function is called. */\r
-\r
-       /* Initialise the general purpose timer modules. */\r
-       alt_gpt_all_tmr_init();\r
-\r
-       /* ALT_CLK_MPU_PERIPH = mpu_periph_clk */\r
-       alt_clk_freq_get( ALT_CLK_MPU_PERIPH, &ulTempFrequency );\r
-\r
-       /* Use the local private timer. */\r
-       alt_gpt_counter_set( ALT_GPT_CPU_PRIVATE_TMR, ulTempFrequency / configTICK_RATE_HZ );\r
-\r
-       /* Sanity check. */\r
-       configASSERT( alt_gpt_time_microsecs_get( ALT_GPT_CPU_PRIVATE_TMR ) == ( ulMicroSecondsPerSecond / configTICK_RATE_HZ ) );\r
-\r
-       /* Set to periodic mode. */\r
-       alt_gpt_mode_set( ALT_GPT_CPU_PRIVATE_TMR, ALT_GPT_RESTART_MODE_PERIODIC );\r
-\r
-       /* The timer can be started here as interrupts are disabled. */\r
-       alt_gpt_tmr_start( ALT_GPT_CPU_PRIVATE_TMR );\r
-\r
-       /* Register the standard FreeRTOS Cortex-A tick handler as the timer's\r
-       interrupt handler.  The handler clears the interrupt using the\r
-       configCLEAR_TICK_INTERRUPT() macro, which is defined in FreeRTOSConfig.h. */\r
-       vRegisterIRQHandler( ALT_INT_INTERRUPT_PPI_TIMER_PRIVATE, ( alt_int_callback_t ) FreeRTOS_Tick_Handler, NULL );\r
-\r
-       /* Ensure the interrupt is forwarded to the CPU. */\r
-    alt_int_dist_enable( ALT_INT_INTERRUPT_PPI_TIMER_PRIVATE );\r
-\r
-    /* Finally, enable the interrupt. */\r
-       alt_gpt_int_clear_pending( ALT_GPT_CPU_PRIVATE_TMR );\r
-       alt_gpt_int_enable( ALT_GPT_CPU_PRIVATE_TMR );\r
 \r
+       /* GPIO for LEDs.  ParTest is a historic name which used to stand for\r
+       parallel port test. */\r
+       vParTestInitialise();\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
@@ -153,7 +273,7 @@ volatile unsigned long ul = 0;
 \r
 void vApplicationTickHook( void )\r
 {\r
-       #if( mainSELECTED_APPLICATION == 1 )\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
@@ -164,14 +284,57 @@ void vApplicationTickHook( void )
 \r
                /* Call the periodic event group from ISR demo. */\r
                vPeriodicEventGroupsProcessing();\r
+\r
+               /* Call the periodic test that uses mutexes form an interrupt. */\r
+               vInterruptSemaphorePeriodicTest();\r
        }\r
        #endif\r
 }\r
 /*-----------------------------------------------------------*/\r
 \r
+void vConfigureTickInterrupt( void )\r
+{\r
+alt_freq_t ulTempFrequency;\r
+const alt_freq_t ulMicroSecondsPerSecond = 1000000UL;\r
+void FreeRTOS_Tick_Handler( void );\r
 \r
-#warning A separate array of handlers is maintained as the drivers array is static so cannot be reached and the handler is incompatible.\r
-static INT_DISPATCH_t xISRHandlers[ ALT_INT_PROVISION_INT_COUNT ];\r
+       /* Interrupts are disabled when this function is called. */\r
+\r
+       /* Initialise the general purpose timer modules. */\r
+       alt_gpt_all_tmr_init();\r
+\r
+       /* ALT_CLK_MPU_PERIPH = mpu_periph_clk */\r
+       alt_clk_freq_get( ALT_CLK_MPU_PERIPH, &ulTempFrequency );\r
+\r
+       /* Use the local private timer. */\r
+       alt_gpt_counter_set( ALT_GPT_CPU_PRIVATE_TMR, ulTempFrequency / configTICK_RATE_HZ );\r
+\r
+       /* Sanity check. */\r
+       configASSERT( alt_gpt_time_microsecs_get( ALT_GPT_CPU_PRIVATE_TMR ) == ( ulMicroSecondsPerSecond / configTICK_RATE_HZ ) );\r
+\r
+       /* Set to periodic mode. */\r
+       alt_gpt_mode_set( ALT_GPT_CPU_PRIVATE_TMR, ALT_GPT_RESTART_MODE_PERIODIC );\r
+\r
+       /* The timer can be started here as interrupts are disabled. */\r
+       alt_gpt_tmr_start( ALT_GPT_CPU_PRIVATE_TMR );\r
+\r
+       /* Register the standard FreeRTOS Cortex-A tick handler as the timer's\r
+       interrupt handler.  The handler clears the interrupt using the\r
+       configCLEAR_TICK_INTERRUPT() macro, which is defined in FreeRTOSConfig.h. */\r
+       vRegisterIRQHandler( ALT_INT_INTERRUPT_PPI_TIMER_PRIVATE, ( alt_int_callback_t ) FreeRTOS_Tick_Handler, NULL );\r
+\r
+       /* This tick interrupt must run at the lowest priority. */\r
+       alt_int_dist_priority_set( ALT_INT_INTERRUPT_PPI_TIMER_PRIVATE, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT );\r
+\r
+       /* Ensure the interrupt is forwarded to the CPU. */\r
+    alt_int_dist_enable( ALT_INT_INTERRUPT_PPI_TIMER_PRIVATE );\r
+\r
+    /* Finally, enable the interrupt. */\r
+       alt_gpt_int_clear_pending( ALT_GPT_CPU_PRIVATE_TMR );\r
+       alt_gpt_int_enable( ALT_GPT_CPU_PRIVATE_TMR );\r
+\r
+}\r
+/*-----------------------------------------------------------*/\r
 \r
 void vRegisterIRQHandler( uint32_t ulID, alt_int_callback_t pxHandlerFunction, void *pvContext )\r
 {\r