Chinaunix首页 | 论坛 | 博客
  • 博客访问: 360149
  • 博文数量: 135
  • 博客积分: 425
  • 博客等级: 下士
  • 技术积分: 599
  • 用 户 组: 普通用户
  • 注册时间: 2012-10-19 21:10
文章分类
文章存档

2014年(3)

2013年(79)

2012年(53)

分类: LINUX

2012-10-20 22:37:31

 
      今天学习了ok6410的串口,用轮寻的方式查找串口的发送和中断。
共有4个文件head.S,uart.h,uart.c和Makefile:
head.S:

点击(此处)折叠或打开

  1. .global _start
  2. _start:
  3. bl main
 
uart.h:

点击(此处)折叠或打开

  1. #define    ULCON0        (*(volatile unsigned int *)0x7F005000)
  2. #define    UCON0        (*(volatile unsigned int *)0x7F005004)
  3. #define    UFCON0        (*(volatile unsigned int *)0x7F005008)
  4. #define    UMCON0        (*(volatile unsigned int *)0x7F00500C)
  5. #define    UTRSTAT0    (*(volatile unsigned int *)0x7F005010)
  6. #define    UERSTAT0    (*(volatile unsigned int *)0x7F005014)
  7. #define    UFSTAT0        (*(volatile unsigned int *)0x7F005018)
  8. #define    UMSTAT0        (*(volatile unsigned int *)0x7F00501C)
  9. #define    UTXH0        (*(volatile unsigned int *)0x7F005020)
  10. #define    URXH0        (*(volatile unsigned int *)0x7F005024)
  11. #define    UBRDIV0        (*(volatile unsigned int *)0x7F005028)
  12. #define    UDIVSLOT0    (*(volatile unsigned int *)0x7F00502C)
  13. #define    UINTP0        (*(volatile unsigned int *)0x7F005030)
  14. #define    UINTSP0        (*(volatile unsigned int *)0x7F005034)
  15. #define    UINTM0        (*(volatile unsigned int *)0x7F005038)

  16. #define    GPACON        (*(volatile unsigned int *)0x7F008000)
uart.c:

点击(此处)折叠或打开

  1. #include "uart.h"

  2. void init_gpm(void)
  3. {
  4.     GPACON = 0x2222; //uart mode
  5. }

  6. void init_uart(void)
  7. {
  8.     ULCON0 = 0x3; //8bit
  9.     UCON0 = (3 << 10); //EXT_UCLK1
  10.     UCON0 &= ~(1 << 10); //change EXT_UCLK1 to PCLK
  11.     UCON0 |= (1 << 2); //Tx mode poll
  12.     UCON0 |= (1 << 0); //Rx mode poll

  13.     UFCON0 = 0; //non fifo
  14.     UMCON0 = 0; //non modem
  15.     
  16.     UBRDIV0 = 34;
  17.     UDIVSLOT0 = 0x1fff; //115200bps/s

  18.     UINTM0 = 0xf; //mask interrupt
  19. }

  20. int uart_rx(void)
  21. {
  22.     while(!(UTRSTAT0 & 1));
  23.     return URXH0;

  24. }

  25. void uart_tx(unsigned int ch)
  26. {
  27.     while (!(UTRSTAT0 & 0x2));
  28.     UTXH0 = ch;
  29. }


  30. int main(void)
  31. {
  32.     unsigned int temp;
  33.     init_gpm();
  34.     init_uart();
  35.     while(1)
  36.     {
  37.         temp = uart_rx();
  38.         uart_tx(temp);
  39.     }

  40.     return 0;
  41. }
 
Makefile:

点击(此处)折叠或打开

  1. all:    
  2.     arm-linux-gcc -c head.S    uart.c
  3.     arm-linux-ld -Ttext=0x54000000 -o uart.elf head.o uart.o
  4.     arm-linux-objcopy -O binary uart.elf uart.bin

  5. clean:
  6.     rm -rf *.o *.elf *.bin




阅读(1928) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:ok6410开发板_利用u-boot的printf打印数据

给主人留下些什么吧!~~