?? test_s3c44b0_uart.c
字號(hào):
/*======================================================
* File Name: test_s3c44b0_uart.c
*
* Author:gong
*
* Email:gongyanlei@msn.com
*
* QQ & MSN:6213599, gongyanlei@msn.com
* Modification History: 2008-05 gong, created.
*
* Debug History: 2008-05
*
======================================================*/
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
/*44b0 sfr base address*/
#define REGBASE 0x01c00000
/*Memory Controller Registers*/
#define BWSCON *(volatile unsigned int *)(REGBASE+0x080000)
/*I/O Ports Registers */
#define PCONA *(volatile unsigned int *)(REGBASE+0x120000)
#define PDATA *(volatile unsigned int *)(REGBASE+0x120004)
#define PCONB *(volatile unsigned int *)(REGBASE+0x120008)
#define PDATB *(volatile unsigned int *)(REGBASE+0x12000c)
#define PCONC *(volatile unsigned int *)(REGBASE+0x120010)
#define PDATC *(volatile unsigned int *)(REGBASE+0x120014)
#define PUPC *(volatile unsigned int *)(REGBASE+0x120018)
#define PCOND *(volatile unsigned int *)(REGBASE+0x12001c)
#define PDATD *(volatile unsigned int *)(REGBASE+0x120020)
#define PUPD *(volatile unsigned int *)(REGBASE+0x120024)
#define PCONE *(volatile unsigned int *)(REGBASE+0x120028)
#define PDATE *(volatile unsigned int *)(REGBASE+0x12002c)
#define PUPE *(volatile unsigned int *)(REGBASE+0x120030)
#define PCONF *(volatile unsigned int *)(REGBASE+0x120034)
#define PDATF *(volatile unsigned int *)(REGBASE+0x120038)
#define PUPF *(volatile unsigned int *)(REGBASE+0x12003c)
#define PCONG *(volatile unsigned int *)(REGBASE+0x120040)
#define PDATG *(volatile unsigned int *)(REGBASE+0x120044)
#define PUPG *(volatile unsigned int *)(REGBASE+0x120048)
#define SPUCR *(volatile unsigned int *)(REGBASE+0x12004c)
#define EXTINT *(volatile unsigned int *)(REGBASE+0x120050)
#define EXTINPND *(volatile unsigned int *)(REGBASE+0x120054)
/*Interrupt Controller Registers */
#define INTCON *(volatile unsigned int *)(REGBASE+0x200000)
#define INTPND *(volatile unsigned int *)(REGBASE+0x200004)
#define INTMOD *(volatile unsigned int *)(REGBASE+0x200008)
#define INTMSK *(volatile unsigned int *)(REGBASE+0x20000c)
#define I_PSLV *(volatile unsigned int *)(REGBASE+0x200010)
#define I_PMST *(volatile unsigned int *)(REGBASE+0x200014)
#define I_CSLV *(volatile unsigned int *)(REGBASE+0x200018)
#define I_CMST *(volatile unsigned int *)(REGBASE+0x20001c)
#define I_ISPR *(volatile unsigned int *)(REGBASE+0x200020)
#define I_ISPC *(volatile unsigned int *)(REGBASE+0x200024)
#define F_ISPR *(volatile unsigned int *)(REGBASE+0x200038)
#define F_ISPC *(volatile unsigned int *)(REGBASE+0x20003c)
#define BUFSIZE 100
static void config_bwscon_and_port_and_extint (void)
{
long temp;
/*bus width config for fpga and s3c44b0_uart*/
temp = BWSCON ;
BWSCON = ( temp & ( ~0xFF00 ) ) | 0x4400 ; /*nGCS3: s3c44b0_uart. 8bit mode*/
/*nGCS2: FPGA. 8bit mode*/
/* Configuration Port Control Register*/
/* Port A */
PCONA = 0x3FF;
/* Port B */
PCONB = 0x7FF;
/* Port C */
PCONC = 0XFF000000;
/* Port D */
PCOND = 0x5000;
PDATD = 0xC0;
/* Port E */
PCONE = 0x00000028;
/* Port F */
PCONF = 0x00124b2a;
/* Port G */
PCONG = 0x00000030; /* PG2--INT750--EINT2*/
/*INTMSK*/
temp = INTMSK ;
INTMSK = temp | 0x800064; /*open UTXD1,URXD1,EXTINT2,I2C*/
/* Configure s3c44b0_uart interupt*/
temp = EXTINT;
EXTINT = ( temp & ( ~0x700 ) ) | 0x100 ;
}
int main(void)
{
int fd = 0 ;
int i = 0 ;
int count = 0 ;
int j;
unsigned char buf[BUFSIZE];
PDATD = 0xc0;
printf("start to test the driver for s3c44b0_uart.\n\n");
printf("configure arm......");
config_bwscon_and_port_and_extint();
printf("done!\n\n");
printf("open s3c44b0_uart......");
fd = open("/dev/s3c44b0_uart", O_RDWR | O_NOCTTY | O_NDELAY);
if ( fd < 0)
{
printf("Error in open s3c44b0_uart\n");
exit(-1);
}
printf("done\n\n");
PDATD = 0x00;
while(1)
{
PDATD = 0x80;
count= read( fd , buf, sizeof(buf) );
//count = 0;
if( count != 0 )
{
PDATD |= 0x40;
printf("The test program read %d character via s3c44b0_uart, they are:.\n", count );
for ( i = 0 ; i < count ; i ++ )
{
printf( "0x%x" , buf[i] );
printf("%d\n", i);
for (j = 0; j < 1000; j++);
}
printf("\n\n");
for(i = 0 ; i < 1000 ; i ++)
{
i++;
}
printf("The test program is sending back to host via s3c44b0_uart......", count );
i=write( fd , buf , count );
printf("done\n");
printf("%d character send via s3c44b0_uart, Please check.\n\n", count );
PDATD &= (~0x40);
}
printf("shat!\n");
PDATD = 0x00;
}
close(fd);
return 0;
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -