2 * FreeRTOS Kernel V10.0.0
\r
3 * Copyright (C) 2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
\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
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
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
23 * http://www.FreeRTOS.org
\r
24 * http://aws.amazon.com/freertos
\r
26 * 1 tab == 4 spaces!
\r
29 /* FreeRTOS includes. */
\r
30 #include "FreeRTOS.h"
\r
33 /* Xilinx includes. */
\r
34 #include "platform.h"
\r
36 #include "xscugic.h"
\r
38 /* Timer used to generate the tick interrupt. */
\r
39 static XTtcPs xRTOSTickTimerInstance;
\r
41 /*-----------------------------------------------------------*/
\r
43 void vConfigureTickInterrupt( void )
\r
46 XTtcPs_Config *pxTimerConfiguration;
\r
47 XInterval usInterval;
\r
49 const uint8_t ucLevelSensitive = 1;
\r
50 extern XScuGic xInterruptController;
\r
52 pxTimerConfiguration = XTtcPs_LookupConfig( XPAR_XTTCPS_3_DEVICE_ID );
\r
54 /* Initialise the device. */
\r
55 xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );
\r
57 if( xStatus != XST_SUCCESS )
\r
59 /* Not sure how to do this before XTtcPs_CfgInitialize is called as
\r
60 *xRTOSTickTimerInstance is set within XTtcPs_CfgInitialize(). */
\r
61 XTtcPs_Stop( &xRTOSTickTimerInstance );
\r
62 xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );
\r
63 configASSERT( xStatus == XST_SUCCESS );
\r
66 /* Set the options. */
\r
67 XTtcPs_SetOptions( &xRTOSTickTimerInstance, ( XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE ) );
\r
69 /* Derive values from the tick rate. */
\r
70 XTtcPs_CalcIntervalFromFreq( &xRTOSTickTimerInstance, configTICK_RATE_HZ, &( usInterval ), &( ucPrescale ) );
\r
72 /* Set the interval and prescale. */
\r
73 XTtcPs_SetInterval( &xRTOSTickTimerInstance, usInterval );
\r
74 XTtcPs_SetPrescaler( &xRTOSTickTimerInstance, ucPrescale );
\r
76 /* The priority must be the lowest possible. */
\r
77 XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_XTTCPS_3_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucLevelSensitive );
\r
79 /* Connect to the interrupt controller. */
\r
80 xStatus = XScuGic_Connect( &xInterruptController, XPAR_XTTCPS_3_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xRTOSTickTimerInstance );
\r
81 configASSERT( xStatus == XST_SUCCESS);
\r
83 /* Enable the interrupt in the GIC. */
\r
84 XScuGic_Enable( &xInterruptController, XPAR_XTTCPS_3_INTR );
\r
86 /* Enable the interrupts in the timer. */
\r
87 XTtcPs_EnableInterrupts( &xRTOSTickTimerInstance, XTTCPS_IXR_INTERVAL_MASK );
\r
89 /* Start the timer. */
\r
90 XTtcPs_Start( &xRTOSTickTimerInstance );
\r
92 /*-----------------------------------------------------------*/
\r
94 void vClearTickInterrupt( void )
\r
96 volatile uint32_t ulInterruptStatus;
\r
98 /* Read the interrupt status, then write it back to clear the interrupt. */
\r
99 ulInterruptStatus = XTtcPs_GetInterruptStatus( &xRTOSTickTimerInstance );
\r
100 XTtcPs_ClearInterruptStatus( &xRTOSTickTimerInstance, ulInterruptStatus );
\r
101 __asm volatile( "DSB SY" );
\r
102 __asm volatile( "ISB SY" );
\r
104 /*-----------------------------------------------------------*/
\r
106 void vApplicationIRQHandler( uint32_t ulICCIAR )
\r
108 extern const XScuGic_Config XScuGic_ConfigTable[];
\r
109 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;
\r
110 uint32_t ulInterruptID;
\r
111 const XScuGic_VectorTableEntry *pxVectorEntry;
\r
113 /* Interrupts cannot be re-enabled until the source of the interrupt is
\r
114 cleared. The ID of the interrupt is obtained by bitwise ANDing the ICCIAR
\r
115 value with 0x3FF. */
\r
116 ulInterruptID = ulICCIAR & 0x3FFUL;
\r
117 if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )
\r
119 /* Call the function installed in the array of installed handler
\r
121 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );
\r
122 configASSERT( pxVectorEntry );
\r
123 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );
\r