📄 main.c
字号:
//====================================================================
// File Name : 2410test.c
// Function : S3C2410 Test Main Menu
// Program : Shin, On Pil (SOP)
// Date : May 30, 2002
// Version : 0.0
// History
// 0.0 : Programming start (February 20,2002) -> SOP
// 1.0 (20020530) : First release for customer
// 1.1 (20020801) : Strata NOR Flash Added and etc. -> SOP
//====================================================================
#include <stdlib.h>
#include <string.h>
#include "def.h"
#include "option.h"
#include "2410addr.h"
#include "2410lib.h"
#include "2410slib.h"
#include "mmu.h"
void Isr_Init(void);
void HaltUndef(void);
void HaltSwi(void);
void HaltPabort(void);
void HaltDabort(void);
void Led_Display(int data);
void InitUart2(int baud)
{
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : CLKOUT1 CLKOUT0 UCLK RXD2 TXD2 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10 , 10 10 , 10 10 , 10 10 , 10 10 , 10 10
rGPHCON = 0x2aaaaa;
rGPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
rULCON2 = 0x3; //Line control register : Normal,No parity,1 stop,8 bits
// [10] [9] [8] [7] [6] [5] [4] [3:2] [1:0]
// Clock Sel, Tx Int, Rx Int, Rx Time Out, Rx err, Loop-back, Send break, Transmit Mode, Receive Mode
// 0 1 0 , 0 1 0 0 , 01 01
// PCLK Level Pulse Disable Generate Normal Normal Interrupt or Polling
rUCON2 = 0x245; // Control register
rUBRDIV2=( (int)(PCLK/16./baud) -1 ); //Baud rate divisior register 0
//rUBRDIV2=( (int)(pclk/16./baud+0.5) -1 ); //Baud rate divisior register 0
rUFCON2 = 0x0; //UART channel 2 FIFO control register, FIFO disable
}
void InitUart1(int baud)
{
//=== PORT H GROUP
//Ports : GPH10 GPH9 GPH8 GPH7 GPH6 GPH5 GPH4 GPH3 GPH2 GPH1 GPH0
//Signal : CLKOUT1 CLKOUT0 UCLK nCTS1 nRTS1 RXD1 TXD1 RXD0 TXD0 nRTS0 nCTS0
//Binary : 10 , 10 10 , 11 11 , 10 10 , 10 10 , 10 10
rGPHCON = 0x2afaaa;
rGPHUP = 0x7ff; // The pull up function is disabled GPH[10:0]
rUMCON1 = 0x11; //UART chaneel 1 MODEM control register, AFC disable
rULCON1 = 0x3;
rUCON1 = 0x245;
rUBRDIV1=( (int)(PCLK/16./baud) -1 );
}
void RunGPRSTest()
{
char key=0;
InitUart1(9600);
while (1)
{
// if(rUMSTAT0 & 0x04)
rUMCON1 |= rUMSTAT0 & 0x01;
if((rUTRSTAT0 & 0x1))
{
key = RdURXH0();
if(key == 0x1b)
break;
if(rUMSTAT1 & 0x01)
{
while(!(rUTRSTAT1 & 0x2));
WrUTXH1(RdURXH0());
}
}
// if(rUMSTAT1 & 0x04)
rUMCON0 |= rUMSTAT1 & 0x01;
if((rUTRSTAT1 & 0x1))
{
while(!(rUTRSTAT0 & 0x2));
WrUTXH0(RdURXH1());
}
}
}
void RunGPSTest()
{
char key=0;
InitUart2(9600);
while (1)
{
if((rUTRSTAT0 & 0x1))
{
key = RdURXH0();
if(key == 0x1b)
return;
while(!(rUTRSTAT2 & 0x2));
WrUTXH2(key);
}
if((rUTRSTAT2 & 0x1))
{
while(!(rUTRSTAT0 & 0x2));
WrUTXH0(RdURXH2());
}
}
}
//===================================================================
void Main(void)
{
char key=0;
Led_Display(0x0f);
Led_Display(0x00);
MMU_Init();
ChangeClockDivider(1,1); // 1:2:4
ChangeMPllValue(0xa1,0x3,0x1); // FCLK=202.8MHz
Port_Init();
Isr_Init();
Uart_Init(0,115200);
rUMCON0 = 0x11;
Uart_Select(0);
Uart_Printf("\n GPRS/GPS TEST\n");
Uart_Printf("\n Press any key to continue...\n");
while(!Uart_GetKey());
while(1)
{
Uart_Printf("======== Menu ========");
Uart_Printf("\n[1] Run GPRS test");
Uart_Printf("\n[2] Run GPS test");
Uart_Printf("\nSelect:");
key = Uart_Getch();
Uart_Printf("%c\n", key);
switch(key)
{
case '1':
RunGPRSTest();
break;
case '2':
RunGPSTest();
break;
default:
Uart_Printf("\n\n");
break;
}
}
}
//===================================================================
//Active is low.(LED On)
// GPF7 GPF6 GPF5 GPF4
//nLED_1 nLED2 nLED_4 nLED_3
void Led_Display(int data)
{
// rGPFDAT = (rGPFDAT & 0xf) | !((data & 0xf)<<4);
rGPFDAT = (rGPFDAT & ~(0xf<<4)) | ((~data & 0xf)<<4);
}
//===================================================================
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
rINTMSK = BIT_ALLMSK; //All interrupt is masked.
rINTSUBMSK = BIT_SUB_ALLMSK; //All sub-interrupt is masked. <- April 01, 2002 SOP
}
//===================================================================
void HaltUndef(void)
{
Uart_Printf("Undefined instruction exception.\n");
while(1);
}
//===================================================================
void HaltSwi(void)
{
Uart_Printf("SWI exception.\n");
while(1);
}
//===================================================================
void HaltPabort(void)
{
Uart_Printf("Pabort exception.\n");
while(1);
}
//===================================================================
void HaltDabort(void)
{
Uart_Printf("Dabort exception.\n");
while(1);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -