📄 xmain.c
字号:
//====================================================================
// File Name : xmain.c
// Function : S3C2440 Test Main Menu
// Program : Junon
// Date : Nov 29, 2003
// Version : 0.0
// History
// 0.0 : Programming start (February 20,2002) ->
//====================================================================
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2440addr.h"
#include "2440lib.h" // 03.11.27 junon
#if USE_MAIN
#include <stdio.h>
#endif
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);
int SST39VF160_CheckId(void);
extern void Calc_Clock(int print_msg);
extern U32 Mdiv, Pdiv, Sdiv, Fclk, Hclk, Pclk, Hdivn, Pdivn, Hclk_Ratio, Pclk_Ratio, Ref_Cnt;
unsigned char const LED_TAB[] = { 0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71 };
// 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)
//===================================================================
void xmain(void)
{
int i, voltage=120;
unsigned int mpll_val;
// GPIO port init.
Port_Init();
//Led_Display(0xf);
// MMU init. I/D cache on.
// MMU_Init();
//Led_Display(0x1);
//////// user can set clock again. /////////
#if 0
Delay(0);
voltage=110;
Max1718_Set(voltage); // set proper voltage after clock changed.
Delay(1);
#if FIN==12000000 //When 12MHz.
ChangeUPllValue(56,2,2); // 48MHz
for(i=0; i<7; i++);
ChangeClockDivider(13,12);
ChangeMPllValue(68,1,1); //2440x
#else // else xtal_in=16.9344MHz.
ChangeUPllValue(60,4,2); // 48MHz
for(i=0; i<7; i++);
ChangeClockDivider(13,12);
//ChangeMPllValue(118,2,2); //265Mhz
ChangeMPllValue(97,1,2); //295Mhz
//ChangeMPllValue(110,3,1); //398Mhz
//ChangeMPllValue(120,2,1); //531Mhz
#endif
#endif
/////////////////////////////////////////
//Led_Display(0x2);
Calc_Clock(0);
UPDATE_REFRESH(Hclk);
//Led_Display(0x3);
// ISR init
Isr_Init();
Uart_Init(Pclk, 115200);
Uart_Select(0);
Uart_TxEmpty(0);
// Led_Display(0x7);
// timer setting for delay 100us unit.
//Check whether or not the POWER_OFF wake-up.
Delay(0); //calibrate Delay()
//rIISPSR=(2<<5)|(2<<0); //IIS_LRCK=44.1Khz @384fs,PCLK=50Mhz.
// Set I/O strength control.
rDSC0 = (0<<31)|(0x3<<8)|(0xff<<0);
// rDSC0 = (0<<31)|(0x0<<8)|(0x00<<0);
// nEN_DSC [31] : 0:I/O drive strength enable, 1:Disable
// DSC_ADR [9:8] : Addr drive strength, 0:10mA, 1:8mA, 2:6mA, 3:4mA
// DSC_DATA [7:0] : DATA drive strength, 0:12mA, 1:10mA, 2:8mA, 3:6mA
rDSC1 = (0x3<<28)|(0x3<<26)|(0xfffff<<0);
// CLKOUT0/1 select.
Uart_Printf("CLKOUT0:MPLL in, CLKOUT1:RTC clock.\n");
Clk0_Enable(2); // 0:MPLLin, 1:UPLL, 2:FCLK, 3:HCLK, 4:PCLK, 5:DCLK0
Clk1_Enable(3); // 0:MPLLout, 1:UPLL, 2:RTC, 3:HCLK, 4:PCLK, 5:DCLK1
//Test_Iic2();
while(1);
} // end of xmain().
//===================================================================
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 + -