Advertisement
Guest User

FreeRTOS tick config for Zynq

a guest
Jun 10th, 2015
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.52 KB | None | 0 0
  1. /*
  2.  * The application must provide a function that configures a peripheral to
  3.  * create the FreeRTOS tick interrupt, then define configSETUP_TICK_INTERRUPT()
  4.  * in FreeRTOSConfig.h to call the function.  This file contains a function
  5.  * that is suitable for use on the Zynq SoC.
  6.  */
  7. void vConfigureTickInterrupt( void )
  8. {
  9. static XScuGic xInterruptController;    /* Interrupt controller instance */
  10. BaseType_t xStatus;
  11. extern void FreeRTOS_Tick_Handler( void );
  12. XScuTimer_Config *pxTimerConfig;
  13. XScuGic_Config *pxGICConfig;
  14. const uint8_t ucRisingEdge = 3;
  15.  
  16.     /* This function is called with the IRQ interrupt disabled, and the IRQ
  17.     interrupt should be left disabled.  It is enabled automatically when the
  18.     scheduler is started. */
  19.  
  20.     /* Ensure XScuGic_CfgInitialize() has been called.  In this demo it has
  21.     already been called from prvSetupHardware() in main(). */
  22.     pxGICConfig = XScuGic_LookupConfig( XPAR_SCUGIC_SINGLE_DEVICE_ID );
  23.     xStatus = XScuGic_CfgInitialize( &xInterruptController, pxGICConfig, pxGICConfig->CpuBaseAddress );
  24.     configASSERT( xStatus == XST_SUCCESS );
  25.     ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
  26.  
  27.     /* The priority must be the lowest possible. */
  28.     XScuGic_SetPriorityTriggerType( &xInterruptController, XPAR_SCUTIMER_INTR, portLOWEST_USABLE_INTERRUPT_PRIORITY << portPRIORITY_SHIFT, ucRisingEdge );
  29.  
  30.     /* Install the FreeRTOS tick handler. */
  31.     xStatus = XScuGic_Connect( &xInterruptController, XPAR_SCUTIMER_INTR, (Xil_ExceptionHandler) FreeRTOS_Tick_Handler, ( void * ) &xTimer );
  32.     configASSERT( xStatus == XST_SUCCESS );
  33.     ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
  34.  
  35.     /* Initialise the timer. */
  36.     pxTimerConfig = XScuTimer_LookupConfig( XPAR_SCUTIMER_DEVICE_ID );
  37.     xStatus = XScuTimer_CfgInitialize( &xTimer, pxTimerConfig, pxTimerConfig->BaseAddr );
  38.     configASSERT( xStatus == XST_SUCCESS );
  39.     ( void ) xStatus; /* Remove compiler warning if configASSERT() is not defined. */
  40.  
  41.     /* Enable Auto reload mode. */
  42.     XScuTimer_EnableAutoReload( &xTimer );
  43.  
  44.     /* Load the timer counter register. */
  45.     XScuTimer_LoadTimer( &xTimer, XSCUTIMER_CLOCK_HZ / configTICK_RATE_HZ );
  46.  
  47.     /* Start the timer counter and then wait for it to timeout a number of
  48.     times. */
  49.     XScuTimer_Start( &xTimer );
  50.  
  51.     /* Enable the interrupt for the xTimer in the interrupt controller. */
  52.     XScuGic_Enable( &xInterruptController, XPAR_SCUTIMER_INTR );
  53.  
  54.     /* Enable the interrupt in the xTimer itself. */
  55.     vClearTickInterrupt();
  56.     XScuTimer_EnableInterrupt( &xTimer );
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement