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

📄 44b_lib.c

📁 RockOS是在ARM上开发的
💻 C
📖 第 1 页 / 共 3 页
字号:
        break;
    case PWM_TIMER1:
        /* Write the initial value into TCNTB1 and TCMPB1 */
        rTCNTB1 = tout;
        rTCMPB1 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<8);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<8;    /* auto reload off,
                            * inverter off,
                            * manual update,
                            * timer stop.
                            */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<8);
        if (periodly != 0)
        {
            ctrl |= (0xd<<8);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x5<<8);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;
    case PWM_TIMER2:
        /* Write the initial value into TCNTB2 and TCMPB2 */
        rTCNTB2 = tout;
        rTCMPB2 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<12);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<12;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<12);
        if (periodly != 0)
        {
            ctrl |= (0xd<<12);   /* auto-reload on(Interval mode)
                                  * Timer output inverter on
                                  * No operation (for manual update off)
                                  * Timer start
                                  */

        }
        else
        {
            ctrl |= (0x5<<12);   /* auto-reload off (one shot mode)
                                  * Timer output inverter on
                                  * No operation (for manual update off)
                                  * Timer start
                                  */
        }
        rTCON = ctrl;
        break;
    case PWM_TIMER3:
        /* Write the initial value into TCNTB3 and TCMPB3 */
        rTCNTB3 = tout;
        rTCMPB3 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<16);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<16;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<16);
        if (periodly != 0)
        {
            ctrl |= (0xd<<16);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x5<<16);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;
    case PWM_TIMER4:
        /* Write the initial value into TCNTB4 and TCMPB4 */
        rTCNTB4 = tout;
        rTCMPB4 = tout>>1;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0xf<<20);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<20;    /* auto reload off,
                             * inverter off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0xf<<20);
        if (periodly != 0)
        {
            ctrl |= (0xd<<20);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x5<<20);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;

    case PWM_TIMER5:
        /* Write the initial value into TCNTB5 */
        rTCNTB5 = tout;

        /* Set the manual update bit of the corresponding timer. */
        ctrlMsk = ~(0x7<<24);
        ctrl = rTCON & ctrlMsk;
        ctrl |= 0x2<<24;    /* auto reload off,
                             * manual update,
                             * timer stop.
                             */
        rTCON = ctrl;

        /* Set the start bit of the corresponding timer to start the timer,
           At the same time, clear the manual update bit.*/
        ctrl &= ~(0x7<<24);
        if (periodly != 0)
        {
            ctrl |= (0x5<<24);   /* auto-reload on(Interval mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */

        }
        else
        {
            ctrl |= (0x1<<24);   /* auto-reload off (one shot mode)
                                 * Timer output inverter on
                                 * No operation (for manual update off)
                                 * Timer start
                                 */
        }
        rTCON = ctrl;
        break;

    default:
        break;
    }
}

/******************************************************************************
Function    : void pwm_stop(int which)
Params      : which - the PWM Timer channel(0~5)
            : 
            : 
            : 
Return      : N/A
Description : stop the special PWM timer channel.
            : 
******************************************************************************/
void pwm_stop(int which)
{
    unsigned ctrl;

    /* for detail information about rTCON, pls reference pwm_start(). */
    ctrl = rTCON;

    switch(which)
    {
    case PWM_TIMER0:
        ctrl &= ~(1<<0);    /* clear Bit0. */
        break;
    case PWM_TIMER1:
        ctrl &= ~(1<<8);    /* clear Bit8. */
        break;
    case PWM_TIMER2:
        ctrl &= ~(1<<12);    /* clear Bit12. */
        break;
    case PWM_TIMER3:
        ctrl &= ~(1<<16);    /* clear Bit16. */
        break;
    case PWM_TIMER4:
        ctrl &= ~(1<<20);    /* clear Bit20. */
        break;
    case PWM_TIMER5:
        ctrl &= ~(1<<24);    /* clear Bit24. */
        break;

    default:
        break;
    }

    rTCON = ctrl;
}

/******************************************************************************
Function    : void init_uart(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function config all of UART registers as app default:
            : No parity, 1 stop bit, 8 data bits, 57600bps baud.
******************************************************************************/
void init_uart()
{
    /* Bit6    : infra-Red mode or not, 1 for infra-Red mode.
     * bit5..3 : parity mode, 0xx for no parity.
     * Bit2    : number of stop bit, 0 one stop bit, 1 two stop bit per frame.
     * Bit1..0 : data bits per frame, 11 for 8 bits.
     */
    rULCON0 = 0x3;     /*No parity, 1 stop bit, 8 data bits*/
    rULCON1 = 0x3;

    /* Bit7..6 : Tx FIFO Trigger Level
     * Bit5..4 : Rx FIFO Trigger Level
     * Bit3    : Reserved and not used.
     * Bit2    : Tx FIFO Reset
     * Bit1    : Rx FIFO Reset
     * Bit0    : FIFO enable or not, 0 for disable, 1 for enable.
     */
    rUFCON0 = 0x0;     /* FIFO disabled. */
    rUFCON1 = 0x0;

    /* Bit4    : Auto Flow Control(AFC) enable or not, 1 for enable, 0 for disable.
     * Bit3..1 : Reserved and must be 0.
     * Bit0    : nRTS, only used when AFC is disabled.
     */
    rUMCON0 = 0x0;     /* AFC disabled. */
    rUMCON1 = 0x0;

    /* Bit9    : Tx interrupt type, 0 for pulse, 1 for level
     * Bit8    : Rx interrupt type, 0 for pulse, 1 for level
     * Bit7    : Rx timeout enable, 0 for disable, 1 for enable
     * Bit6    : Rx error status interrupt enable, 0 for disable, 1 for enable
     * Bit5    : Loop-back mode, 0 for normal option, 1 for Loop-back mode
     * Bit4    : Send Break Signal, 0 for normal transmit, 1 for send break signal
     * Bit3..2 : Transmit Mode, 00 for disable, 01 for interrupt request or polling mode
     * Bit1..0 : Receive Mode, 00 for disable, 01 for interrupt request or polling mode
     */
    rUCON0 = 0x45;     /* Tx is using polling mode.
                        * Rx is using pulse interrupt type.
                        * Rx timeout is disabled.
                        * Don't send break signal.
                        */
    rUCON1 = 0x45;

    /* default baud rate is 57600bps. */
    rUBRDIV0 = (MCLK + 8 * BAUD_DEFAULT)/(16 * BAUD_DEFAULT) - 1;
    rUBRDIV1 = (MCLK + 8 * BAUD_DEFAULT)/(16 * BAUD_DEFAULT) - 1;
}

/******************************************************************************
Function    : void set_uart_mode (int which, unsigned baud, unsigned parity)
Params      : which  - indicate UART channel 0 or UART channel 1.
            : baud   - baud rate for this UART channel.
            : parity - parity mode (even, odd or none).
            :
Return      : N/A
Description : Use this function to change the default UART config after system
            : starts up if you want a new one.
******************************************************************************/
void set_uart_mode(int which, unsigned baud, unsigned parity)
{
    unsigned ulcon;
    unsigned ubrdiv;

    if ((which > UART_CH1)
        ||((baud != 4800)&&(baud != 9600)&&(baud != 14400)&&(baud != 19200)
           &&(baud != 38400)&&(baud != 57600)&&(baud != 115200))
        ||((parity != PARITY_NONE)&&(parity != PARITY_ODD)&&(parity != PARITY_EVEN)
           &&(parity != PARITY_MARK)&&(parity != PARITY_CLR)))
    {
        OS_printf("set_uart_mode(): invalid params: which = [%d], baud = [%d],parity = [%d].\n",
                    which, baud, parity);
        return;
    }
    switch(which)
    {
    case UART_CH0:
        ulcon = rULCON0;
        ubrdiv = rUBRDIV0;
        ulcon |= parity<<3;
        ubrdiv = (MCLK + 8 * baud)/(16 * baud) - 1;

⌨️ 快捷键说明

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