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

📄 bsp.c

📁 ucos-ii 的完整代码
💻 C
📖 第 1 页 / 共 2 页
字号:
*                                       LED_Toggle()** Description : Toggle an LED Pin** Arguments   : led   0 = Toggle ALL LEDs*                     1 = Toggle LED 1*                     2 = Toggle LED 2*                     ...*                     8 = Toggle LED 8** Returns     : None.** Notes       : None.**********************************************************************************************************/void  LED_Toggle (CPU_INT08U led){    if (led > 8) {        return;                                                         /* Argument checking, return if led > 8                     */        }        if (led == 0) {        PTCTOG  =   PTC_LED_MASK;                                       /* Toggle all Port C LEDs                                   */        PTETOG  =   PTE_LED_MASK;                                       /* Toggle all Port E LEDs                                   */    }        if ((led > 0) && led <= 6) {                                        /* Toggle On Port C LED                                     */        PTCTOG  =  (1 << (led - 1));    } else {        PTETOG  =  (1 << (led - 1));                                    /* Toggle On Port E LED                                     */    }}     /***********************************************************************************************************                                       LED_On()** DescriptiOn : Turn On an LED** Arguments   : led   0 = Turn On ALL LEDs*                     1 = Turn On LED 1*                     2 = Turn On LED 2*                     ...*                     8 = Turn On LED 8** Returns     : NOne.** Notes       : NOne.**********************************************************************************************************/void  LED_On (CPU_INT08U led){    if (led > 8) {        return;                                                         /* Argument checking, return if led > 8                     */        }        if (led == 0) {        PTCCLR  =   PTC_LED_MASK;                                       /* Turn On all Port C LEDs                                  */        PTECLR  =   PTE_LED_MASK;                                       /* Turn On all Port E LEDs                                  */    }        if ((led > 0) && led <= 6) {                                        /* Turn On One Port C LED                                   */        PTCCLR  =  (1 << (led - 1));    } else {        PTECLR  =  (1 << (led - 1));                                    /* Turn On One Port E LED                                   */    }}/***********************************************************************************************************                                       LED_Off()** Description : Turn Off an LED** Arguments   : led   0 = Turn Off ALL LEDs*                     1 = Turn Off LED 1*                     2 = Turn Off LED 2*                     ...*                     8 = Turn Off LED 8** Returns     : None.** Notes       : None.**********************************************************************************************************/void  LED_Off (CPU_INT08U led){    if (led > 8) {        return;                                                         /* Argument checking, return if led > 8                     */        }        if (led == 0) {        PTCSET  =   PTC_LED_MASK;                                       /* Turn Off all Port C LEDs                                 */        PTESET  =   PTE_LED_MASK;                                       /* Turn Off all Port E LEDs                                 */    }        if ((led > 0) && led <= 6) {                                        /* Turn Off Port C LED                                      */        PTCSET  =  (1 << (led - 1));    } else {        PTESET  =  (1 << (led - 1));                                    /* Turn Off Port E LED                                      */    }}/***********************************************************************************************************                                   OSProbe_TmrInit()** Description : This function is called to by uC/Probe Plug-In for uC/OS-II to initialize the*               free running timer that is used to make time measurements.** Arguments   : none** Returns     : none** Note(s)     : 1) This timer is shared with the uC/OS-II time tick and is initialized *                  from OSTickISR_Init().**********************************************************************************************************/#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)void  OSProbe_TmrInit (void){}#endif/***********************************************************************************************************                                   OSProbe_TmrRd()** Description : This function is called to read the current counts of a 16 bit free running timer.** Arguments   : none** Returns     ; The 16 bit count (in a 32 bit variable) of the timer assuming the timer is an UP counter.**********************************************************************************************************/#if (uC_PROBE_OS_PLUGIN > 0) && (OS_PROBE_HOOKS_EN == 1)CPU_INT32U  OSProbe_TmrRd (void){    return (TPM1CNT);                                                   /* Return the current TPM1 timer value                      */}#endif/***********************************************************************************************************                                     uC/OS-II TICK ISR INITIALIZATION** Description : This function is used to initialize one of three possible TPM0 channels for use*               as the periodic OS Tick Source. The ticker period is controlled by the macro*               OS_TICKS_PER_SEC defined in os_cfg.h.* *                   OS_TICK_TPM1_OC set to 0 chooses TPM1 output compare #0 as the ticker source*                   OS_TICK_TPM1_OC set to 1 chooses TPM1 output compare #1 as the ticker source*                   OS_TICK_TPM1_OC set to 2 chooses TPM1 output compare #2 as the ticker source** Arguments   : None.** Returns     : None.** Note(s)     : 1) vectors.c has been plugged with the address of 'OSTickISR' for vectors 66, 67 and 68*                  each of which correspond to TPM0 channels 1, 2, 3 respectively.**********************************************************************************************************/static void  OSTickISR_Init (void){    CPU_INT32U  bus_freq;    bus_freq    =   BSP_CPU_ClkFreq();                                  /* Get the current CPU frequency                            */    bus_freq   /=   2;                                                  /* Divide by 2 to generate the BUS clock frequency          */        OSTickCnts  =  (CPU_INT16U)(bus_freq / (8 * OS_TICKS_PER_SEC));     /* Calculate the nbr of ticks for the interrupt period      */                                                                         /* Assume TPM input clock prescaler of 8                    */        SCGC1      |=   SCGC1_TPM1_MASK;                                    /* Enable the TPM module clock                              */    TPM1SC      =   0;                                                  /* Stop and reset the TPM counter                           */    TPM1MOD     =   0;                                                  /* Set the modulus count to 0x00 allowing freerun           */#if OS_TICK_TPM1_CH == 0    TPM1C0SC    =   TPM1C0SC_MS0A_MASK          |                       /* Configure the channel for output compare mode            */                    TPM1C0SC_CH0IE_MASK;                                /* Enable TPM1 Channel 0 interrupts                         */    TPM1C0V     =   TPM1CNT + OSTickCnts;                               /* Set the match value to the present time + OSTickCnts     */#endif#if OS_TICK_TPM1_CH == 1    TPM1C1SC    =   TPM1C1SC_MS1A_MASK          |                       /* Configure the channel for output compare mode            */                    TPM1C1SC_CH1IE_MASK;                                /* Enable TPM1 Channel 0 interrupts                         */    TPM1C1V     =   TPM1CNT + OSTickCnts;                               /* Set the match value to the present time + OSTickCnts     */#endif#if OS_TICK_TPM1_CH == 2    TPM1C2SC    =   TPM1C2SC_MS2A_MASK          |                       /* Configure the channel for output compare mode            */                    TPM1C2SC_CH2IE_MASK;                                /* Enable TPM1 Channel 0 interrupts                         */    TPM1C2V     =   TPM1CNT + OSTickCnts;                               /* Set the match value to the present time + OSTickCnts     */#endif    TPM1SC     |=  (1 << TPM1SC_CLKSx_BITNUM)   |                       /* Configure reference clock to BUS clock, set prescaler to */                   (3 << TPM1SC_PS_BITNUM);                             /* 8, enable the TPM                                        */}/***********************************************************************************************************                                      uC/OS-II TICK ISR HANDLER** Description : This function is called by OSTickISR() when a tick interrupt occurs.*               See file bsp_a.asm for more information about the OS time tick ISR.** Arguments   : None.** Returns     : None.**********************************************************************************************************/void  OSTickISR_Handler (void){#if OS_TICK_TPM1_CH == 0    TPM1C0SC   &=  ~TPM1C0SC_CH0F_MASK;                                 /* Clear the interrupt source                               */    TPM1C0V    +=   OSTickCnts;                                         /* Set the next match value                                 */#endif#if OS_TICK_TPM1_CH == 1    TPM1C0SC   &=  ~TPM1C1SC_CH1F_MASK;                                 /* Clear the interrupt source                               */    TPM1C0V    +=   OSTickCnts;                                         /* Set the next match value                                 */#endif#if OS_TICK_TPM1_CH == 2    TPM1C0SC   &=  ~TPM1C2SC_CH2F_MASK;                                 /* Clear the interrupt source                               */    TPM1C0V    +=   OSTickCnts;                                         /* Set the next match value                                 */#endif    OSTimeTick();                                                       /* Notify uC/OS-II that a tick has occurred                 */}

⌨️ 快捷键说明

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