今天学习了ok6410的串口,用轮寻的方式查找串口的发送和中断。
共有4个文件head.S,uart.h,uart.c和Makefile:
head.S:
- .global _start
- _start:
- bl main
uart.h:
- #define ULCON0 (*(volatile unsigned int *)0x7F005000)
- #define UCON0 (*(volatile unsigned int *)0x7F005004)
- #define UFCON0 (*(volatile unsigned int *)0x7F005008)
- #define UMCON0 (*(volatile unsigned int *)0x7F00500C)
- #define UTRSTAT0 (*(volatile unsigned int *)0x7F005010)
- #define UERSTAT0 (*(volatile unsigned int *)0x7F005014)
- #define UFSTAT0 (*(volatile unsigned int *)0x7F005018)
- #define UMSTAT0 (*(volatile unsigned int *)0x7F00501C)
- #define UTXH0 (*(volatile unsigned int *)0x7F005020)
- #define URXH0 (*(volatile unsigned int *)0x7F005024)
- #define UBRDIV0 (*(volatile unsigned int *)0x7F005028)
- #define UDIVSLOT0 (*(volatile unsigned int *)0x7F00502C)
- #define UINTP0 (*(volatile unsigned int *)0x7F005030)
- #define UINTSP0 (*(volatile unsigned int *)0x7F005034)
- #define UINTM0 (*(volatile unsigned int *)0x7F005038)
- #define GPACON (*(volatile unsigned int *)0x7F008000)
uart.c:
- #include "uart.h"
- void init_gpm(void)
- {
- GPACON = 0x2222; //uart mode
- }
- void init_uart(void)
- {
- ULCON0 = 0x3; //8bit
- UCON0 = (3 << 10); //EXT_UCLK1
- UCON0 &= ~(1 << 10); //change EXT_UCLK1 to PCLK
- UCON0 |= (1 << 2); //Tx mode poll
- UCON0 |= (1 << 0); //Rx mode poll
- UFCON0 = 0; //non fifo
- UMCON0 = 0; //non modem
-
- UBRDIV0 = 34;
- UDIVSLOT0 = 0x1fff; //115200bps/s
- UINTM0 = 0xf; //mask interrupt
- }
- int uart_rx(void)
- {
- while(!(UTRSTAT0 & 1));
- return URXH0;
- }
- void uart_tx(unsigned int ch)
- {
- while (!(UTRSTAT0 & 0x2));
- UTXH0 = ch;
- }
- int main(void)
- {
- unsigned int temp;
- init_gpm();
- init_uart();
- while(1)
- {
- temp = uart_rx();
- uart_tx(temp);
- }
- return 0;
- }
Makefile:
- all:
- arm-linux-gcc -c head.S uart.c
- arm-linux-ld -Ttext=0x54000000 -o uart.elf head.o uart.o
- arm-linux-objcopy -O binary uart.elf uart.bin
- clean:
- rm -rf *.o *.elf *.bin
阅读(1968) | 评论(0) | 转发(0) |