📄 44b_lib.c.bak
字号:
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()
{
#if 0
/*
*
*/
rWTDAT = ;
/*
*
*/
rWTCNT = ;
/* 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;
#endif
}
/******************************************************************************
Function : void enable_watchdog(void)
Params : N/A
:
:
:
Return : N/A
Description : enable the 44b0x cpu's watchdog unit.
:
******************************************************************************/
void enable_watchdog()
{
}
/******************************************************************************
Function : void disable_watchdog(void)
Params : N/A
:
:
:
Return : N/A
Description : disable the 44b0x cpu's watchdog unit.
:
******************************************************************************/
void disable_watchdog()
{
}
/******************************************************************************
Function : void clear_watchdog()
Params : N/A
:
:
:
Return : N/A
Description : clear the 44b0x cpu's watchdog.
:
******************************************************************************/
void clear_watchdog()
{
}
/******************************************************************************
Function : void flash_led()
Params : N/A
:
:
:
Return : N/A
Description : Flash the running LED.
:
******************************************************************************/
void flash_led()
{
static int counter=0;
static int ledState=LED_OFF;
counter++;
if (counter >= TICK_INT_FREQ)
{
counter = 0;
if (ledState == LED_OFF)
{
ledState = LED_ON;
}
else
{
ledState = LED_OFF;
}
light_led(LED1, ledState);
}
}
/******************************************************************************
Function : void OS_printf (const char * format, ...)
Params : format - the format for informations.
:
:
:
Return : N/A
Description : the alternative function for printf() for RockOS.
:
******************************************************************************/
void OS_printf (const char * format, ...)
{
va_list arglist;
char buffer[1024];
va_start(arglist, format);
vsprintf(&buffer[0], format, arglist);
va_end(arglist);
UART_sendString(UART_CH0, &buffer[0]);
}
/******************************************************************************
Function : void OS_error (const char * format, ...)
Params : format - the format for informations.
:
:
:
Return : N/A
Description : same as OS_printf(), but use a well-marked color to mark that
: this information is an error.
******************************************************************************/
void OS_error (const char * format, ...)
{
va_list arglist;
char buffer[1024];
SET_COLOR_YELLOW();
va_start(arglist, format);
vsprintf(&buffer[0], format, arglist);
va_end(arglist);
UART_sendString(UART_CH0, &buffer[0]);
SET_COLOR_DEFAULT();
}
/******************************************************************************
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);
}
/******************************************************************************
Function : void fatalError(void)
Params : N/A
:
:
:
Return : N/A
Description : enter fatal error, reboot the system by watchdog.
:
******************************************************************************/
void fatalError()
{
enable_watchdog();
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -