⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bsp.c

📁 IAR编译环境下的AT91SAM7S64芯片的ucosii系统移植和演示代码。
💻 C
📖 第 1 页 / 共 2 页
字号:
             break;

        case 1:
             AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
             break;

        case 2:
             AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
             break;

        case 3:
             AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
             break;

        case 4:
             AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
             break;
    }
}

/*
*********************************************************************************************************
*                                             LED TOGGLE
*
* Description : This function is used to toggle any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to toggle
*                      0    indicates that you want ALL the LEDs to be toggle
*                      1    toggles LED1 on the board
*                      .
*                      .
*                      4    toggles LED4 on the board
*********************************************************************************************************
*/

void  LED_Toggle (INT8U led)
{
    switch (led) {
        case 0:
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
             }
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED2) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
             }
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED3) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
             }
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED4) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED4;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
             }
             break;

        case 1:
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED1) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED1;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED1;
             }
             break;

        case 2:
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED2) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED2;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED2;
             }
             break;

        case 3:
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED3) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED3;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED3;
             }
             break;

        case 4:
             if (AT91C_BASE_PIOA->PIO_ODSR & BSP_LED4) {
                 AT91C_BASE_PIOA->PIO_CODR = BSP_LED4;
             } else {
                 AT91C_BASE_PIOA->PIO_SODR = BSP_LED4;
             }
             break;
    }
}

/*
*********************************************************************************************************
*                                           IRQ ISR HANDLER
*
* Description : This function is called by OS_CPU_IRQ_ISR() to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OS_CPU_IRQ_ISR_Handler (void)
{
    BSP_PFNCT  pfnct;


#if 1
    pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR;     /* Read the interrupt vector from the VIC          */
    if (pfnct != (BSP_PFNCT)0) {                    /* Make sure we don't have a NULL pointer          */
        (*pfnct)();                                 /* Execute the ISR for the interrupting device     */
    }
#else
    pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR;     /* Read the interrupt vector from the VIC          */
    while (pfnct != (BSP_PFNCT)0) {                 /* Make sure we don't have a NULL pointer          */
      (*pfnct)();                                   /* Execute the ISR for the interrupting device     */
        pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_IVR; /* Read the interrupt vector from the VIC          */
    }
#endif
}

/*
*********************************************************************************************************
*                                           FIQ ISR HANDLER
*
* Description : This function is called by OS_CPU_FIQ_ISR() to determine the source of the interrupt
*               and process it accordingly.
*
* Arguments   : none
*********************************************************************************************************
*/

void  OS_CPU_FIQ_ISR_Handler (void)
{
    BSP_PFNCT  pfnct;


#if 1
    pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR;     /* Read the interrupt vector from the VIC               */
    if (pfnct != (BSP_PFNCT)0) {                    /* Make sure we don't have a NULL pointer               */
        (*pfnct)();                                 /* Execute the ISR for the interrupting device          */
    }
#else
    pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR;     /* Read the interrupt vector from the VIC               */
    while (pfnct != (BSP_PFNCT)0) {                 /* Make sure we don't have a NULL pointer               */
      (*pfnct)();                                   /* Execute the ISR for the interrupting device          */
        pfnct = (BSP_PFNCT)AT91C_BASE_AIC->AIC_FVR; /* Read the interrupt vector from the VIC               */
    }
#endif
}

/*
*********************************************************************************************************
*                                         TICKER INITIALIZATION
*
* Description : This function is called to initialize uC/OS-II's tick source which uses the PIT
*               (typically a timer generating interrupts every 1 to 100 mS).
*
* Arguments   : none
*
* Note(s)     : 1) PIT Interrupt frequency:
*
*                         MCLK        1
*               Freq =    ---- * -----------
*                          16     (PIV + 1)
*
*
*                         MCLK      1
*               PIV  =  ( ---- * ------ ) - 1
*                          16     Freq
*
*               Where:
*                    MCLK = 48 MHz (i.e 48,000,000)
*                    Freq = Desired frequency (i.e. OS_TICKS_PER_SEC)
*********************************************************************************************************
*/

static  void  Tmr_TickInit (void)
{
    INT32U  counts;

                                                /* Set the vector address for PIT                      */
    AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (INT32U)Tmr_TickISR_Handler;
    AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_LEVEL_SENSITIVE
                                          | AT91C_AIC_PRIOR_LOWEST;
    AT91C_BASE_AIC->AIC_ICCR              = 1 << AT91C_ID_SYS;
    AT91C_BASE_AIC->AIC_IECR              = 1 << AT91C_ID_SYS;

    counts                                = (48000000 / 16 / OS_TICKS_PER_SEC) - 1;
    AT91C_BASE_PITC->PITC_PIMR            = AT91C_PITC_PITEN | AT91C_PITC_PITIEN | counts;
}


/*
*********************************************************************************************************
*                                           PIT IRQ HANDLER
*
* Description : This function handles the PIT interrupt that is used to generate TICKs for uC/OS-II.
*
* Arguments   : none
*********************************************************************************************************
*/

static  void  Tmr_TickISR_Handler (void)
{
    volatile  INT32U  status;


    status                    = AT91C_BASE_PITC->PITC_PIVR;
    AT91C_BASE_AIC->AIC_IVR   = 0;            /* Debug variant of vector read (protect mode is used)   */

    AT91C_BASE_AIC->AIC_ICCR  = AT91C_ID_SYS; /* Clear  timer #0 interrupt                             */
    AT91C_BASE_AIC->AIC_EOICR = 0;            /* Signal end of interrupt                               */
    OSTimeTick();                             /* Tell uC/OS-II about clock tick                        */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -