📄 xmain.c
字号:
//====================================================================
// File Name : xmain.c
//====================================================================
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h"
#include "mmu.h"
#if USE_MAIN
#include <stdio.h>
#endif
/**************** User test program header file ********************/
#include "lcd.h"
#include "Glib.h"
#include "LCDlib.h"
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Clk0_Enable(int clock_sel);
void Clk1_Enable(int clock_sel);
void Clk0_Disable(void);
void Clk1_Disable(void);
extern void Calc_Clock(int print_msg);
extern U32 Mdiv, Pdiv, Sdiv, Fclk, Hclk, Pclk, Hdivn, Pdivn, Hclk_Ratio, Pclk_Ratio, Ref_Cnt;
extern void Test_16c554(void);
extern void Test_Lcd_carling(void);
extern void Test_Lcd_Tft_16Bit_800600(void);
void* function[][2]=
{
(void *)Lcd_Test, "Lcd test ",
0,0
};
// Clock select argument.
#define UCLK_SEL (1)
#define HCLK_SEL (3)
#define PCLK_SEL (4)
#define DCLK_SEL (5)
// Hidden
#define MPLL_SEL (0)
#define FCLK_SEL (2)
/*********************************************************************************************************
** 函数名称: GpioSet
** 功能描述: 控制GPIO的输出类型
** 输 入: PortType 端口类型
** PortBit PORT中的具体位
** PortState GPIO的输出状态
** 输 出:TRUE :成功
** FALSE:失败
** 全局变量: 无
** 调用模块: 无
**
** 注意:
********************************************************************************************************/
U8 GpioSet(U8 PortType, U8 PortBit,U8 PortState)
{
switch(PortType)
{
case 'A':
rGPADAT &= ~(1 << PortBit);
rGPADAT |= (PortState << PortBit);
break;
case 'B':
rGPBDAT &= ~(1 << PortBit);
rGPBDAT |= (PortState << PortBit);
break;
case 'C':
rGPCDAT &= ~(1 << PortBit);
rGPCDAT |= (PortState << PortBit);
break;
case 'D':
rGPDDAT &= ~(1 << PortBit);
rGPDDAT |= (PortState << PortBit);
break;
case 'E':
rGPEDAT &= ~(1 << PortBit);
rGPEDAT |= (PortState << PortBit);
break;
case 'F':
rGPFDAT &= ~(1 << PortBit);
rGPFDAT |= (PortState << PortBit);
break;
case 'G':
rGPGDAT &= ~(1 << PortBit);
rGPGDAT |= (PortState << PortBit);
break;
case 'H':
rGPHDAT &= ~(1 << PortBit);
rGPHDAT |= (PortState << PortBit);
break;
default:
return 99;
break;
}
return 1;
}
void xmain(void)
{
int i, voltage=120;
unsigned int mpll_val;
// GPIO port init.
Port_Init();
GpioSet('A', 12, 0); //pull-down
GpioSet('A', 12, 1); //pull-up
GpioSet('A', 13, 0); //pull-down
GpioSet('A', 13, 1); //pull-up
GpioSet('B', 6, 0); //pull-down
GpioSet('B', 6, 1); //pull-up
GpioSet('B', 5, 0); //pull-down
GpioSet('B', 5, 1); //pull-up
GpioSet('B', 8, 0); //pull-up
GpioSet('B', 10, 1); //pull-up
// MMU init. I/D cache on.
MMU_Init();
// ISR init
Isr_Init(); //中断服务程序初始化
Uart_Init(0, 115200);
Uart_Select(1); //uart1
Uart_TxEmpty(1); //清空发送缓冲
// timer setting for delay 100us unit.
// Check whether or not the POWER_OFF wake-up.
Delay(0);
while(1){
Test_Lcd_carling();
}
}
//===================================================================
void Isr_Init(void)
{
pISR_UNDEF = (unsigned)HaltUndef;
pISR_SWI = (unsigned)HaltSwi;
pISR_PABORT = (unsigned)HaltPabort;
pISR_DABORT = (unsigned)HaltDabort;
rINTMOD = 0x0; //All=IRQ mode
// rINTCON = 0x5; //Non-vectored,IRQ enable,FIQ disable
rINTMSK = BIT_ALLMSK; //All interrupt is masked.
rINTSUBMSK = BIT_SUB_ALLMSK; //All sub-interrupt is masked. <- April 01, 2002 SOP
// rINTSUBMSK = ~(BIT_SUB_RXD0); //Enable Rx0 Default value=0x7ff
// rINTMSK = ~(BIT_UART0); //Enable UART0 Default value=0xffffffff
// pISR_UART0=(unsigned)RxInt; //pISR_FIQ,pISR_IRQ must be initialized
}
//===================================================================
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception.\n");
while(1);
}
//===================================================================
void HaltSwi(void)
{
#if !SEMIHOSTING
Uart_Printf("SWI exception!!!\n");
while(1);
#endif
}
//===================================================================
void HaltPabort(void)
{
Uart_Printf("Pabort exception.\n");
while(1);
}
//===================================================================
void HaltDabort(void)
{
Uart_Printf("Dabort exception.\n");
while(1);
}
void Clk0_Enable(int clock_sel)
{
// 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
rMISCCR = rMISCCR&~(7<<4) | (clock_sel<<4);
rGPHCON = rGPHCON&~(3<<18) | (2<<18);
}
void Clk1_Enable(int clock_sel)
{
// 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
rMISCCR = rMISCCR&~(7<<8) | (clock_sel<<8);
rGPHCON = rGPHCON&~(3<<20) | (2<<20);
}
void Clk0_Disable(void)
{
rGPHCON = rGPHCON&~(3<<18); // GPH9 Input
}
void Clk1_Disable(void)
{
rGPHCON = rGPHCON&~(3<<20); // GPH10 Input
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -