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

📄 bsp.c

📁 AT91SAM7X256微处理器
💻 C
📖 第 1 页 / 共 3 页
字号:
    LED_Off(BSP_LED_ALL);                                                  /* Turn OFF all the LEDs                                 */
}


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

void  LED_On (CPU_INT08U led)
{
    switch (led) {
        case 0:
             AT91C_BASE_PIOB->PIO_CODR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
             break;

        case 1:
             AT91C_BASE_PIOB->PIO_CODR = BSP_LED1;
             break;

        case 2:
             AT91C_BASE_PIOB->PIO_CODR = BSP_LED2;
             break;

        case 3:
             AT91C_BASE_PIOB->PIO_CODR = BSP_LED3;
             break;

        case 4:
             AT91C_BASE_PIOB->PIO_CODR = BSP_LED4;
             break;
    }
}

void  LED_On_number (CPU_INT08U led){
   int j ;
   j = led & 0xf;
   j = j << 19;
   AT91C_BASE_PIOB->PIO_CODR = j;
}
/*
*********************************************************************************************************
*                                             LED OFF
*
* Description : This function is used to control any or all the LEDs on the board.
*
* Arguments   : led    is the number of the LED to turn OFF
*                      0    indicates that you want ALL the LEDs to be OFF
*                      1    turns OFF LED1 on the board
*                      .
*                      .
*                      4    turns OFF LED4 on the board
*********************************************************************************************************
*/

void  LED_Off (CPU_INT08U led)
{
    switch (led) {
        case 0:
             AT91C_BASE_PIOB->PIO_SODR = BSP_LED4 | BSP_LED3 | BSP_LED2 | BSP_LED1;
             break;

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

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

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

        case 4:
             AT91C_BASE_PIOB->PIO_SODR = BSP_LED4;
             break;
    }
}
 
void  LED_Off_number (CPU_INT08U led){
   int j ;
   j = led & 0xf;
   j = j << 19;
   AT91C_BASE_PIOB->PIO_SODR = j;
}

/*
*********************************************************************************************************
*                                             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 (CPU_INT08U led)
{
    switch (led) {
        case 0:
             if (AT91C_BASE_PIOB->PIO_ODSR & BSP_LED1) {
                 AT91C_BASE_PIOB->PIO_CODR = BSP_LED1;
             } else {
                 AT91C_BASE_PIOB->PIO_SODR = BSP_LED1;
             }
             if (AT91C_BASE_PIOB->PIO_ODSR & BSP_LED2) {
                 AT91C_BASE_PIOB->PIO_CODR = BSP_LED2;
             } else {
                 AT91C_BASE_PIOB->PIO_SODR = BSP_LED2;
             }
             if (AT91C_BASE_PIOB->PIO_ODSR & BSP_LED3) {
                 AT91C_BASE_PIOB->PIO_CODR = BSP_LED3;
             } else {
                 AT91C_BASE_PIOB->PIO_SODR = BSP_LED3;
             }
             if (AT91C_BASE_PIOB->PIO_ODSR & BSP_LED4) {
                 AT91C_BASE_PIOB->PIO_CODR = BSP_LED4;
             } else {
                 AT91C_BASE_PIOB->PIO_SODR = BSP_LED4;
             }
             break;

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

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

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

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


/*
*********************************************************************************************************
*                                         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)
{
    CPU_INT32U      counts;
    CPU_INT32U      cpu_frq;

                                                                        /* Determine the number of counts per tick                  */
    cpu_frq                               = BSP_CPU_ClkFreq();

    counts                                = ((cpu_frq * 1000) / 16 / OS_TICKS_PER_SEC) - 1;

                                                                        /* Set the vector address for PIT                           */
    AT91C_BASE_AIC->AIC_SVR[AT91C_ID_SYS] = (CPU_INT32U)Tmr_TickISR_Handler;
    AT91C_BASE_AIC->AIC_SMR[AT91C_ID_SYS] = AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL
                                          | AT91C_AIC_PRIOR_LOWEST;

    AT91C_BASE_AIC->AIC_ICCR              = 1 << AT91C_ID_SYS;
    AT91C_BASE_AIC->AIC_IECR              = 1 << AT91C_ID_SYS;

                                                                        /* Enable the PIT with the correct compare value            */
    AT91C_BASE_PITC->PITC_PIMR            = AT91C_PITC_PITEN | AT91C_PITC_PITIEN | counts;
}


/*
*********************************************************************************************************
*                                           OSView Timer Initialization
*
* Description : This function selects and initializes a timer for use with OSView and the Statistics Task
*
* Arguments   : none
*********************************************************************************************************
*/

#if OS_VIEW_MODULE > 0
void  OSView_TmrInit (void)
{
#if OS_VIEW_TIMER_SEL == 0
    AT91C_BASE_PMC->PMC_PCER             =  (1 << 12);                  /* Enable the peripheral clk                                */
    AT91C_BASE_TCB->TCB_TC0.TC_CCR       =  (1 <<  1);                  /* TC0 timer disabled                                       */
    AT91C_BASE_TCB->TCB_TC0.TC_CMR      &= ~(7 <<  0);                  /* TIMER_CLOCK1 is input clk                                */
    AT91C_BASE_TCB->TCB_TC0.TC_CCR       =  (1 <<  0);                  /* TC0 timer enabled                                        */
    AT91C_BASE_TCB->TCB_TC0.TC_CCR       =  (1 <<  2);                  /* SWTRG to reset and start                                 */
#endif

#if OS_VIEW_TIMER_SEL == 1
    AT91C_BASE_PMC->PMC_PCER             =  (1 << 13);                  /* Enable the peripheral clk                                */
    AT91C_BASE_TCB->TCB_TC1.TC_CCR       =  (1 <<  1);                  /* TC1 timer disabled                                       */
    AT91C_BASE_TCB->TCB_TC1.TC_CMR      &= ~(7 <<  0);                  /* TIMER_CLOCK1 is input clk                                */
    AT91C_BASE_TCB->TCB_TC1.TC_CCR       =  (1 <<  0);                  /* TC1 timer enabled                                        */
    AT91C_BASE_TCB->TCB_TC1.TC_CCR       =  (1 <<  2);                  /* SWTRG to reset and start                                 */
#endif

#if OS_VIEW_TIMER_SEL == 2

⌨️ 快捷键说明

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