]> git.sur5r.net Git - freertos/blobdiff - FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/FreeRTOS_tick_config.c
Update some more standard demos for use on 64-bit architectures.
[freertos] / FreeRTOS / Demo / CORTEX_R5_UltraScale_MPSoC / RTOSDemo_R5 / src / FreeRTOS_tick_config.c
diff --git a/FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/FreeRTOS_tick_config.c b/FreeRTOS/Demo/CORTEX_R5_UltraScale_MPSoC/RTOSDemo_R5/src/FreeRTOS_tick_config.c
new file mode 100644 (file)
index 0000000..e55323f
--- /dev/null
@@ -0,0 +1,177 @@
+/*\r
+    FreeRTOS V9.0.0rc2 - 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
+/* FreeRTOS includes. */\r
+#include "FreeRTOS.h"\r
+#include "Task.h"\r
+\r
+/* Xilinx includes. */\r
+#include "xscugic.h"\r
+#include "xttcps.h"\r
+\r
+/* Settings to generate the tick from channel 0 of TTC 0. */\r
+#define tickTTC_ID                     XPAR_PSU_TTC_0_DEVICE_ID\r
+#define tickINTERRUPT_ID       XPAR_XTTCPS_0_INTR\r
+\r
+/* The timer used to generate the tick interrupt. */\r
+static XTtcPs xTimerInstance;\r
+\r
+/*\r
+ * The application must provide a function that configures a peripheral to\r
+ * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
+ * in FreeRTOSConfig.h to call the function.  This file contains a function\r
+ * that is suitable for use on the Zynq SoC.\r
+ */\r
+void vConfigureTickInterrupt( void )\r
+{\r
+XTtcPs_Config *pxTimerConfig;\r
+BaseType_t xStatus;\r
+XScuGic_Config *pxGICConfig;\r
+static XScuGic xInterruptController;   /* Interrupt controller instance */\r
+uint16_t usInterval;\r
+uint8_t ucPrescale = 0;\r
+const uint8_t ucRisingEdge = 3;\r
+\r
+       /* This function is called with the IRQ interrupt disabled, and the IRQ\r
+       interrupt should be left disabled.  It is enabled automatically when the\r
+       scheduler is started. */\r
+\r
+       /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has\r
+       already been called from prvSetupHardware() in main(). */\r
+       pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
+       xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
+       configASSERT( xStatus == XST_SUCCESS );\r
+       ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
+\r
+       /* The interrupt priority must be the lowest possible. */\r
+       XScuGic_SetPriorityTriggerType( &xInterruptController, tickINTERRUPT_ID, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );\r
+\r
+       /* Install the FreeRTOS tick handler. */\r
+       xStatus = XScuGic_Connect( &xInterruptController, tickINTERRUPT_ID, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, NULL );\r
+       configASSERT( xStatus == XST_SUCCESS );\r
+       ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
+\r
+       /* Initialise the Triple Timer Counter (TTC) that is going to be used to\r
+       generate the tick interrupt. */\r
+       pxTimerConfig = XTtcPs_LookupConfig( tickTTC_ID );\r
+       xStatus = XTtcPs_CfgInitialize( &xTimerInstance, pxTimerConfig, pxTimerConfig->BaseAddress );\r
+       configASSERT( xStatus == XST_SUCCESS );\r
+       ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
+\r
+       /* Configure the interval to be the require tick rate. */\r
+       XTtcPs_CalcIntervalFromFreq( &xTimerInstance, configTICK_RATE_HZ, &usInterval, &ucPrescale );\r
+       XTtcPs_SetInterval( &xTimerInstance, usInterval );\r
+       XTtcPs_SetPrescaler( &xTimerInstance, ucPrescale );\r
+\r
+       /* Interval mode used. */\r
+       XTtcPs_SetOptions( &xTimerInstance, XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE );\r
+\r
+       /* Start the timer. */\r
+       XTtcPs_Start( &xTimerInstance );\r
+\r
+       /* Enable the interrupt in the interrupt controller. */\r
+       XScuGic_Enable( &xInterruptController, tickINTERRUPT_ID );\r
+\r
+       /* Enable the interrupt in the timer itself. */\r
+       XTtcPs_EnableInterrupts( &xTimerInstance, XTTCPS_IXR_INTERVAL_MASK );\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vClearTickInterrupt( void )\r
+{\r
+volatile uint32_t ulStatus;\r
+\r
+       ulStatus = XTtcPs_GetInterruptStatus( &xTimerInstance );\r
+       ( void ) ulStatus;\r
+}\r
+/*-----------------------------------------------------------*/\r
+\r
+void vApplicationIRQHandler( uint32_t ulICCIAR )\r
+{\r
+extern const XScuGic_Config XScuGic_ConfigTable[];\r
+static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
+uint32_t ulInterruptID;\r
+const XScuGic_VectorTableEntry *pxVectorEntry;\r
+\r
+       /* Re-enable interrupts. */\r
+    __asm ( "cpsie i" );\r
+\r
+       /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
+       with 0x3FF. */\r
+       ulInterruptID = ulICCIAR & 0x3FFUL;\r
+       if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
+       {\r
+               /* Call the function installed in the array of installed handler\r
+               functions. */\r
+               pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
+               pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
+       }\r
+}\r
+\r
+\r