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

📄 44b_lib.c

📁 RockOS是在ARM上开发的
💻 C
📖 第 1 页 / 共 3 页
字号:
        rULCON0 = ulcon;
        rUBRDIV0 = ubrdiv;
        break;
    case UART_CH1:
        ulcon = rULCON1;
        ubrdiv = rUBRDIV1;
        ulcon |= parity<<3;
        ubrdiv = (MCLK + 8 * baud)/(16 * baud) - 1;
        rULCON1 = ulcon;
        rUBRDIV1 = ubrdiv;
        break;
    default:
        break;
    }
}

/******************************************************************************
Function    : void UART_sendChar(int which, char ch)
Params      : which - UART0 or UART1
            : ch    - send this char to UART [which].
            : 
            : 
Return      : N/A
Description : output char to a special UART channel. This feature can be used
            : for output print information or send answer frame to host.
******************************************************************************/
void UART_sendChar(int which, char ch)
{
    if ((which != UART_CH0)&&(which != UART_CH1))
    {
        return;
    }
    switch (which)
    {
    case UART_CH0:
        if(ch=='\n')
        {
            while(!(rUTRSTAT0 & 0x2));
            WrUTXH0('\r');
        }
        while(!(rUTRSTAT0 & 0x2)); /* Wait until THR is empty. */
        WrUTXH0(ch);
        break;
    case UART_CH1:
        if(ch=='\n')
        {
            while(!(rUTRSTAT1 & 0x2));
            WrUTXH1('\r');
        }
        while(!(rUTRSTAT1 & 0x2)); /* Wait until THR is empty. */
        WrUTXH1(ch);
        break;
    default:
        break;
    }
}

/******************************************************************************
Function    : void UART_sendString(int which, const char * pszstring)
Params      : which     - UART0 or UART1
            : pszstring - send this string to UART [which](end by '\0').
            : 
            : 
Return      : N/A
Description : send a string to UART0 or UART1.
            :
******************************************************************************/
void UART_sendString(int which, const char * pszstring)
{
    int i;

    for (i = 0; i < strlen(pszstring); i++)
    {
        UART_sendChar(which, pszstring[i]);
    }
}

/******************************************************************************
Function    : void init_irq()
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : This function is used to config interrupt controller, and open
            : all interrupts which are accepted.
******************************************************************************/
void init_irq()
{
    /* Bit2 = 1, non-vectored interrupt mode.
     * Bit1 = 0, IRQ interrupt enable.
     * Bit0 = 0, FIQ interrupt enable.
     */
    rINTCON = 0x4;

    /*
     * INTMSK: All interrupts are inhibited, but global mask(Bit 26) bit is cleared.
     */
    rINTMSK = 0x03ffffff;

    /*
     * INTMOD: All interrupts are in IRQ mode.
     */
    rINTMOD = 0x0;
}
/******************************************************************************
Function    : void enable_irq()
Params      : N/A
            :
Return      : N/A
Description : Enable IRQ by clear the CPSR's I bit.
            :
******************************************************************************/
void enable_irq()
{
    __asm
    {
        mrs r0, CPSR
        bic r0, r0, #0x80
        msr CPSR_c, r0
    }
}

/******************************************************************************
Function    : void disable_irq()
Params      : N/A
            :
Return      : N/A
Description : Disable IRQ by set the CPSR's I bit.
            :
******************************************************************************/
void disable_irq()
{
    __asm
    {
        mrs r0, CPSR
        orr r0, r0, #0x80
        msr CPSR_c, r0
    }
}

/******************************************************************************
Function    : void add_irq(int irq)
Params      : irq - the interrupt source to be added
            : 
            : 
            : 
Return      : N/A
Description : This function is used to add a special interrupt source thouth
            : set INTMSK and INTMOD with appropriate value.
******************************************************************************/
void add_irq(int irq)
{
    unsigned msk;

    if (irq >= IRQ_GLOBAL)
    {
        return;
    }
    msk = rINTMSK;
    msk &= ~(1<<irq);
    rINTMSK = msk;
}

/******************************************************************************
Function    : void del_irq(int irq)
Params      : irq - the interrupt source to be deleted.
            : 
            : 
            : 
Return      : N/A
Description : This function is used to remove a special interrupt source thouth
            : set INTMSK and INTMOD with appropriate value.
******************************************************************************/
void del_irq(int irq)
{
    unsigned msk;

    if (irq >= IRQ_GLOBAL)
    {
        return;
    }
    msk = rINTMSK;
    msk |= 1<<irq;
    rINTMSK = msk;
}

/******************************************************************************
Function    : void init_watchdog(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : init the 44b0x cpu's watchdog unit.
            : 
******************************************************************************/
void init_watchdog()
{
    /*
     * Bit15..Bit0 = 20000, Watchdog timer count value for reload.
     */
    rWTDAT = 20000;

    /* 
     * Bit15..Bit0 = 20000, Watchdog timer count Register
     */
    rWTCNT = 20000;

    /* Bit15..Bit8 = 0x63(Dec 99), Prescale is 99
     * Bit7..Bit6 = 0, reserved
     * Bit5 = 0, disable watchdog timer
     * Bit4..Bit3 = 11, clock division factor is 1/128
     * Bit2 = 0, disable watchdog interrupt
     * Bit1 = 0, reserved
     * Bit0 = 1, reset cpu if watchdog timer timeout
     * 
     * frequance of watchdog timer = MCLK / (prescale+1) * clock division factor
     * in this system, the watch dog timer frequance is 2500Hz
     */
    rWTCON = 0x63<<8 + 0x3<<3 + 1<<0;
}

/******************************************************************************
Function    : void enable_watchdog(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : enable the 44b0x cpu's watchdog unit.
            : 
******************************************************************************/
void enable_watchdog()
{
    unsigned int wtcon;

    /* 
     * Bit15..Bit0 = 20000, Watchdog timer count Register
     */
    rWTCNT = 20000;

    wtcon = rWTCON;
    wtcon |= 1<<2;  /* bit2 = 1, enable watchdog. */
    rWTCON = wtcon;
}

/******************************************************************************
Function    : void disable_watchdog(void)
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : disable the 44b0x cpu's watchdog unit.
            : 
******************************************************************************/
void disable_watchdog()
{
    unsigned int wtcon;

    wtcon = rWTCON;
    wtcon &= ~(1<<2);

    rWTCON = wtcon;
}

/******************************************************************************
Function    : void clear_watchdog()
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : clear the 44b0x cpu's watchdog.
            : 
******************************************************************************/
void clear_watchdog()
{
    /* 
     * Bit15..Bit0 = 20000, Watchdog timer count Register
     */
    rWTCNT = 20000;
}

/******************************************************************************
Function    : void flash_led()
Params      : N/A
            : 
            : 
            : 
Return      : N/A
Description : Flash the running LED.
            : 
******************************************************************************/
void flash_led()
{
    static int ledState=LED_OFF;

    if (ledState == LED_OFF)
    {
        ledState = LED_ON;
    }
    else
    {
        ledState = LED_OFF;
    }

        light_led(LED1, ledState);
}

/******************************************************************************
Function    : void delay(unsigned n)
Params      : n - delay time, it is not an accurate time.
            : 
Return      : N/A
Description : This function is used to config the RTC registers and should be
            : called only once, when the system is power on.
******************************************************************************/
void delay(unsigned n)
{
    while(n--!=0);
}

⌨️ 快捷键说明

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