2 * FreeRTOS Kernel V10.0.1
\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.
\r
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
\r
17 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
\r
18 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
\r
19 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
\r
20 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
\r
22 * http://www.FreeRTOS.org
\r
23 * http://aws.amazon.com/freertos
\r
25 * 1 tab == 4 spaces!
\r
28 /* FreeRTOS includes. */
\r
29 #include "FreeRTOS.h"
\r
32 /* Xilinx includes. */
\r
33 #include "platform.h"
\r
35 #include "xscugic.h"
\r
37 /* Timer used to generate the tick interrupt. */
\r
38 static XTtcPs xRTOSTickTimerInstance;
\r
40 /*-----------------------------------------------------------*/
\r
42 void vConfigureTickInterrupt( void )
\r
45 XTtcPs_Config *pxTimerConfiguration;
\r
46 XInterval usInterval;
\r
48 const uint8_t ucLevelSensitive = 1;
\r
49 extern XScuGic xInterruptController;
\r
51 pxTimerConfiguration = XTtcPs_LookupConfig( XPAR_XTTCPS_3_DEVICE_ID );
\r
53 /* Initialise the device. */
\r
54 xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );
\r
56 if( xStatus != XST_SUCCESS )
\r
58 /* Not sure how to do this before XTtcPs_CfgInitialize is called as
\r
59 *xRTOSTickTimerInstance is set within XTtcPs_CfgInitialize(). */
\r
60 XTtcPs_Stop( &xRTOSTickTimerInstance );
\r
61 xStatus = XTtcPs_CfgInitialize( &xRTOSTickTimerInstance, pxTimerConfiguration, pxTimerConfiguration->BaseAddress );
\r
62 configASSERT( xStatus == XST_SUCCESS );
\r
65 /* Set the options. */
\r
66 XTtcPs_SetOptions( &xRTOSTickTimerInstance, ( XTTCPS_OPTION_INTERVAL_MODE | XTTCPS_OPTION_WAVE_DISABLE ) );
\r
68 /* Derive values from the tick rate. */
\r
69 XTtcPs_CalcIntervalFromFreq( &xRTOSTickTimerInstance, configTICK_RATE_HZ, &( usInterval ), &( ucPrescale ) );
\r
71 /* Set the interval and prescale. */
\r
72 XTtcPs_SetInterval( &xRTOSTickTimerInstance, usInterval );
\r
73 XTtcPs_SetPrescaler( &xRTOSTickTimerInstance, ucPrescale );
\r
75 /* The priority must be the lowest possible. */
\r
76 XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_XTTCPS_3_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucLevelSensitive );
\r
78 /* Connect to the interrupt controller. */
\r
79 xStatus = XScuGic_Connect( &xInterruptController, XPAR_XTTCPS_3_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xRTOSTickTimerInstance );
\r
80 configASSERT( xStatus == XST_SUCCESS);
\r
82 /* Enable the interrupt in the GIC. */
\r
83 XScuGic_Enable( &xInterruptController, XPAR_XTTCPS_3_INTR );
\r
85 /* Enable the interrupts in the timer. */
\r
86 XTtcPs_EnableInterrupts( &xRTOSTickTimerInstance, XTTCPS_IXR_INTERVAL_MASK );
\r
88 /* Start the timer. */
\r
89 XTtcPs_Start( &xRTOSTickTimerInstance );
\r
91 /*-----------------------------------------------------------*/
\r
93 void vClearTickInterrupt( void )
\r
95 volatile uint32_t ulInterruptStatus;
\r
97 /* Read the interrupt status, then write it back to clear the interrupt. */
\r
98 ulInterruptStatus = XTtcPs_GetInterruptStatus( &xRTOSTickTimerInstance );
\r
99 XTtcPs_ClearInterruptStatus( &xRTOSTickTimerInstance, ulInterruptStatus );
\r
100 __asm volatile( "DSB SY" );
\r
101 __asm volatile( "ISB SY" );
\r
103 /*-----------------------------------------------------------*/
\r
105 void vApplicationIRQHandler( uint32_t ulICCIAR )
\r
107 extern const XScuGic_Config XScuGic_ConfigTable[];
\r
108 static const XScuGic_VectorTableEntry *pxVectorTable = XScuGic_ConfigTable[ XPAR_SCUGIC_SINGLE_DEVICE_ID ].HandlerTable;
\r
109 uint32_t ulInterruptID;
\r
110 const XScuGic_VectorTableEntry *pxVectorEntry;
\r
112 /* Interrupts cannot be re-enabled until the source of the interrupt is
\r
113 cleared. The ID of the interrupt is obtained by bitwise ANDing the ICCIAR
\r
114 value with 0x3FF. */
\r
115 ulInterruptID = ulICCIAR & 0x3FFUL;
\r
116 if( ulInterruptID < XSCUGIC_MAX_NUM_INTR_INPUTS )
\r
118 /* Call the function installed in the array of installed handler
\r
120 pxVectorEntry = &( pxVectorTable[ ulInterruptID ] );
\r
121 configASSERT( pxVectorEntry );
\r
122 pxVectorEntry->Handler( pxVectorEntry->CallBackRef );
\r