📄 44blib.c
字号:
/************************************************
* NAME : 44BLIB.C *
* Version : 17.APR.00 *
************************************************/
#include "44b.h"
#include "44blib.h"
#include "def.h"
#include "option.h"
#include <stdarg.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#define STACKSIZE 0xa00
//SVC satck size(do not use user stack)
#define HEAPEND (_ISR_STARTADDRESS-STACKSIZE-0x500) // = 0xc7ff000
//SVC Stack Area:0xc(e)7ff000-0xc(e)7ffaff
U32 UART_BAUD = 115200 ; //串口波特率设定
//U32 UART_BAUD = 57600 ; //串口波特率设定
U32 MCLK = 64000000; //系统主频设定
extern char Image$$RW$$Limit[];//使用在外部文件定义的字符变量型数组Image$$RW$$Limit[]
void *mallocPt=Image$$RW$$Limit;//把数组首地址赋给指针变量
/******************************************/
static int delayLoopCount=400;//静态全局变量
/************************************************************
*函数名:Delay
*功能:延时指定时间,单位为100us即0.1ms
*入口参数:time---延时数量
*出口参数:无
************************************************************/
void Delay(int time)
// time=0: adjust the Delay function by WatchDog timer.
// time>0: the number of loop time,100us resolution.
{
int i,adjust=0;
if(time==0)
{
time=200;
adjust=1;
delayLoopCount=400;
rWTCON=((MCLK/1000000-1)<<8)|(2<<3); //MCLK/1M,Watch-dog disable,1/64,interrupt disable,reset disable
rWTDAT=0xffff;//for first update
rWTCNT=0xffff;//resolution=64us @any MCLK
rWTCON=((MCLK/1000000-1)<<8)|(2<<3)|(1<<5); //Watch-dog timer start
}
for(;time>0;time--)
{
for(i=0;i<delayLoopCount;i++)
{
;
}
}
if(adjust==1)
{
rWTCON=((MCLK/1000000-1)<<8)|(2<<3);//Watch-dog timer stop
i=0xffff-rWTCNT; //1count->64us, 200*400 cycle runtime = 64*i us
delayLoopCount=8000000/(i*64); //200*400:64*i=1*x:100 -> x=80000*100/(64*i)
}
}
/************************************************************
*函数名:Port_Init
*功能:所有IO口初始化
*入口参数:无
*出口参数:无
************************************************************/
void Port_Init(void)
{
//SMDK41100 B/D Status
//LED D5 D6
// PB9 PB10
//S/W S4 S5
// PG5 PG4
//CAUTION:Follow the configuration order for setting the ports.
// 1) setting value
// 2) setting control register
// 3) configure pull-up resistor.
//16bit data bus configuration
//PORT A GROUP
//ADDR24 ADDR23 ADDR22 ADDR21 ADDR20 ADDR19 ADDR18 ADDR17 ADDR16 ADDR0
// 1, 1, 1, 1, 1, 1, 1, 1, 1, 1
rPCONA=0x3ff;
//PORT B GROUP
//OUT OUT nGCS3 nGCS2 nGCS1 nWBE3 nWBE2 nSRAS nSCAS SCLK SCKE
// 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1
rPDATB=0x600;
rPCONB=0x1cf;
//PORT C GROUP
#if (BUSWIDTH==32)
//D31 D30 D29 D28 D27 D26 D25 D24 D23 D22 D21 D20 D19 D18 D17 D16
// 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10
rPCONC=0xaaaaaaaa;
rPUPC=0xffff;
#else //BUSWIDTH=16
//PORT C GROUP
//Input or Output
rPDATC=0x0001;
rPCONC=0x5f555554;
rPUPC=0x3000;
#endif
//PORT D GROUP
//VFRAME VM VLINE VCLK VD3 VD2 VD1 VD0
// 10,10, 10, 10, 10, 10, 10, 10
rPCOND=0xaaaa;
rPUPD=0xff;
//PORT E GROUP
/* Bit 8 7 6 5 4 3 2 1 0 */
/* ENDLAN LED3 LED2 LED1 LED0 BEEP RXD0 TXD0 CLKOUT */
/* 00 01 01 01 01 01 10 10 01 */
rPDATE = 0x357;
rPCONE = 0x556b;
rPUPE = 0x6;
//PORT F GROUP
//All input
// 0x0
rPDATF=0x0;
rPCONF=0x0;
rPUPF=0x3;
//PORT G GROUP
//All input
// 0x0
rPCONG=0xf00;
rPUPG=0x30;
rSPUCR=0x3; //pull-up disable
rEXTINT=0x22222222; //All EINT[7:0] will be falling edge triggered.
}
static int whichUart=0;
/************************************************************
*函数名:Uart_Init
*功能:UART初始化
*入口参数
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -