📄 uhal.c
字号:
/* ARM board targetting source file.
file name: uhal.c
date: 2001. 2. 14
made by cho dong-seok
homepage: www.pusanssm.com/~cthr36/
*/
#include <stdarg.h>
#include <string.h>
#include "uHAL.h"
#include "44B.h"
//MCLK= 50000000
//50000000hz/256/32= 6103.51hz
#define _TICK 1000 // 1/_TICK 秒 (为 1000 则表明为 1/1000 秒)
#define _CLOCK (66000/(_TICK/10))
//#define _CLOCK 61035 // 1 sec
#define MAX_TBUF 10000
static char tbuf[MAX_TBUF]= {0, };
int delayLoopCount= 400;
int whichUart= 0;
//------------------------------------------------------------------------------------
// 通过串口输出数据进行调试
//------------------------------------------------------------------------------------
int uHALr_printf(const char *format, ...)
{
va_list v_list;
char *ptr;
int i= 0;
// 根据格式字符串和参数形成固定字符串
va_start(v_list, format);
vsprintf(tbuf, format, v_list );
va_end(v_list);
ptr= tbuf;
while( (*ptr) && i<MAX_TBUF)
{
Uart_SendByte(*ptr);
ptr++; i++;
}
return 1;
}
//------------------------------------------------------------------------------------
// 断点处理,用于调试
//------------------------------------------------------------------------------------
void BreakPoint(void)
{
uHALr_printf("!!!Enter break point.");
while(1)
{
Led_Display(0xf);
Delay(1000);
Led_Display(0x0);
Delay(1000);
}
}
//----------------------------------------------------------------------------------------------
// 复位内存管理单元 (由 ARMTargetInit 调用)
//----------------------------------------------------------------------------------------------
void uHALr_ResetMMU(void)
{
}
//Define pre & post-process routines for Interrupt.
void uHALir_DefineIRQ(void *is, void *iq, void *n)
{
}
//----------------------------------------------------------------------------------------------
// 初始化中断
//----------------------------------------------------------------------------------------------
void uHALr_InitInterrupts(void)
{
rINTCON = 0x0; // 非向量,禁止 IRQ,禁止 FIQ
rINTMOD = 0x0; // 所有中断源工作在 IRQ 模式
rINTMSK = BIT_GLOBAL; // 禁止所有中断
}
//----------------------------------------------------------------------------------------------
// 初始化操作系统所需的定时器
//----------------------------------------------------------------------------------------------
void uHALr_InitTimers(void)
{
rTCFG0 = 0x00000004; // prescaler0 = 4
rTCFG1 = 0x00000003; // mux0 = 1/16
rTCNTB0 = 1000;//_CLOCK;
rTCMPB0 = 0x0;
rTCON = 0x2; //update mode for TCNTB0 and TCMPB0.
rTCON = 0x9; //timer0 = auto reload, start
}
int I_COUNT=0;
void DebugUNDEF(void)
{
uHALr_printf("\r\n!!!Enter UNDEFINED. %d\r\n", I_COUNT);
while(1) {
Led_Display(0xf);
Delay(1000);
Led_Display(0x0);
Delay(1000);
}
}
void DebugSWI(void)
{
uHALr_printf("\r\n!!!Enter SWI. %d\r\n", I_COUNT);
while(1)
{
Led_Display(0xf);
Delay(1000);
Led_Display(0x0);
Delay(1000);
}
}
void DebugABORT(void)
{
uHALr_printf("\r\n!!!Enter ABORT %d\r\n", I_COUNT);
while(1)
{
Led_Display(0xf);
Delay(1000);
Led_Display(0x0);
Delay(1000);
}
}
void DebugFIQ(void)
{
uHALr_printf("\r\n!!!Enter FIQ. %d\r\n", I_COUNT);
while(1)
{
Led_Display(0xf);
Delay(1000);
Led_Display(0x0);
Delay(1000);
}
}
extern void __Tick(void);
//----------------------------------------------------------------------------------------------
// 请求系统定时器(由 ARMTargetStart 调用),成功返回 1,否则返回 0
//----------------------------------------------------------------------------------------------
int uHALr_RequestSystemTimer(void *tick, const unsigned char *str)
{
pISR_TIMER0 = (unsigned)__Tick; // 操作系统使用 Timer0 进行时间片调度
pISR_UNDEF = (unsigned) DebugUNDEF;
pISR_SWI = (unsigned) DebugSWI;
pISR_PABORT = (unsigned) DebugABORT;
pISR_DABORT = (unsigned) DebugABORT;
// pISR_RESERVED
// pISR_IRQ = (unsigned) 0;
pISR_FIQ = (unsigned) DebugFIQ;
pISR_RTC = (unsigned) BreakPoint;
pISR_SIO = (unsigned) BreakPoint;
pISR_IIC = (unsigned) BreakPoint;
pISR_EINT4567 = (unsigned) BreakPoint;
pISR_WDT = (unsigned) BreakPoint;
pISR_UERR01 = (unsigned) BreakPoint;
pISR_BDMA1 = (unsigned) BreakPoint;
pISR_BDMA0 = (unsigned) BreakPoint;
pISR_ZDMA1 = (unsigned) BreakPoint;
pISR_ZDMA0 = (unsigned) BreakPoint;
pISR_EINT3 = (unsigned) BreakPoint;
pISR_EINT2 = (unsigned) BreakPoint;
pISR_EINT1 = (unsigned) BreakPoint;
pISR_EINT0 = (unsigned) BreakPoint;
pISR_ADC = (unsigned) BreakPoint; // AD 转换成功中断
pISR_URXD0 = (unsigned) BreakPoint; // 串口 0 接收中断
pISR_UTXD0 = (unsigned) BreakPoint; // 串口 0 发送中断
pISR_URXD1 = (unsigned) BreakPoint; // 串口 1 接收中断
pISR_UTXD1 = (unsigned) BreakPoint; // 串口 1 发送中断
pISR_TIMER1 = (unsigned) BreakPoint; // 定时器 1 中断
pISR_TIMER2 = (unsigned) BreakPoint; // 定时器 2 中断
pISR_TIMER3 = (unsigned) BreakPoint; // 定时器 3 中断
return 1;
}
//----------------------------------------------------------------------------------------------
// 开始系统定时器并允许中断
//----------------------------------------------------------------------------------------------
void uHALr_InstallSystemTimer(void)
{
rINTCON = 0x5; // 非向量、允许IRQ,禁止FIQ
// 允许 TIMER0 中断、(缺省值为 0x7FFFFFFF)
rINTMSK = ~(BIT_GLOBAL | BIT_TIMER0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -