]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_A9_Zynq_ZC702/RTOSDemo/src/FreeRTOS_tick_config.c
Update to MIT licensed FreeRTOS V10.0.0 - see https://www.freertos.org/History.txt
[freertos] / FreeRTOS / Demo / CORTEX_A9_Zynq_ZC702 / RTOSDemo / src / FreeRTOS_tick_config.c
1 /*\r
2  * FreeRTOS Kernel V10.0.0\r
3  * Copyright (C) 2017 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software. If you wish to use our Amazon\r
14  * FreeRTOS name, please do so in a fair use way that does not cause confusion.\r
15  *\r
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
17  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
18  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
19  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
20  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
22  *\r
23  * http://www.FreeRTOS.org\r
24  * http://aws.amazon.com/freertos\r
25  *\r
26  * 1 tab == 4 spaces!\r
27  */\r
28 \r
29 /* FreeRTOS includes. */\r
30 #include "FreeRTOS.h"\r
31 #include "task.h"\r
32 \r
33 /* Xilinx includes. */\r
34 #include "xscutimer.h"\r
35 #include "xscugic.h"\r
36 \r
37 #define XSCUTIMER_CLOCK_HZ ( XPAR_CPU_CORTEXA9_0_CPU_CLK_FREQ_HZ / 2UL )\r
38 \r
39 static XScuTimer xTimer;\r
40 XScuGic xInterruptController;   /* Interrupt controller instance */\r
41 \r
42 /*\r
43  * The application must provide a function that configures a peripheral to\r
44  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()\r
45  * in FreeRTOSConfig.h to call the function.  This file contains a function\r
46  * that is suitable for use on the Zynq SoC.\r
47  */\r
48 void vConfigureTickInterrupt( void )\r
49 {\r
50 BaseType_t xStatus;\r
51 extern void FreeRTOS_Tick_Handler( void );\r
52 XScuTimer_Config *pxTimerConfig;\r
53 XScuGic_Config *pxGICConfig;\r
54 const uint8_t ucRisingEdge = 3;\r
55 \r
56         /* This function is called with the IRQ interrupt disabled, and the IRQ\r
57         interrupt should be left disabled.  It is enabled automatically when the\r
58         scheduler is started. */\r
59 \r
60         /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has\r
61         already been called from prvSetupHardware() in main(). */\r
62         pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );\r
63         xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );\r
64         configASSERT( xStatus == XST_SUCCESS );\r
65         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
66 \r
67         /* The priority must be the lowest possible. */\r
68         XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );\r
69 \r
70         /* Install the FreeRTOS tick handler. */\r
71         xStatus = XScuGic_Connect( &xInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer );\r
72         configASSERT( xStatus == XST_SUCCESS );\r
73         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
74 \r
75         /* Initialise the timer. */\r
76         pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID );\r
77         xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr );\r
78         configASSERT( xStatus == XST_SUCCESS );\r
79         ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */\r
80 \r
81         /* Enable Auto reload mode. */\r
82         XScuTimer_EnableAutoReload( &xTimer );\r
83 \r
84         /* Ensure there is no prescale. */\r
85         XScuTimer_SetPrescaler( &xTimer, 0 );\r
86 \r
87         /* Load the timer counter register. */\r
88         XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );\r
89 \r
90         /* Start the timer counter and then wait for it to timeout a number of\r
91         times. */\r
92         XScuTimer_Start( &xTimer );\r
93 \r
94         /* Enable the interrupt for the xTimer in the interrupt controller. */\r
95         XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );\r
96 \r
97         /* Enable the interrupt in the xTimer itself. */\r
98         vClearTickInterrupt();\r
99         XScuTimer_EnableInterrupt( &xTimer );\r
100 }\r
101 /*-----------------------------------------------------------*/\r
102 \r
103 void vClearTickInterrupt( void )\r
104 {\r
105         XScuTimer_ClearInterruptStatus( &xTimer );\r
106 }\r
107 /*-----------------------------------------------------------*/\r
108 \r
109 /* This is the callback function which is called by the FreeRTOS Cortex-A port\r
110 layer in response to an interrupt.  If the function is called\r
111 vApplicationFPUSafeIRQHandler() then it is called after the floating point\r
112 registers have been saved.  If the function is called vApplicationIRQHandler()\r
113 then it will be called without first having saved the FPU registers.  See\r
114 http://www.freertos.org/Using-FreeRTOS-on-Cortex-A-Embedded-Processors.html for\r
115 more information */\r
116 void vApplicationFPUSafeIRQHandler( uint32_t ulICCIAR )\r
117 {\r
118 extern const XScuGic_Config XScuGic_ConfigTable[];\r
119 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;\r
120 uint32_t ulInterruptID;\r
121 const XScuGic_VectorTableEntry *pxVectorEntry;\r
122 \r
123         /* Re-enable interrupts. */\r
124         __asm ( "cpsie i" );\r
125 \r
126         /* The ID of the interrupt is obtained by bitwise anding the ICCIAR value\r
127         with 0x3FF. */\r
128         ulInterruptID = ulICCIAR & 0x3FFUL;\r
129         if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )\r
130         {\r
131                 /* Call the function installed in the array of installed handler functions. */\r
132                 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );\r
133                 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );\r
134         }\r
135 }\r
136 \r
137 \r
138 \r