新聞中心

EEPW首頁 > 嵌入式系統(tǒng) > 設計應用 > ARM-Linux s3c2440 之UART分析(五)

ARM-Linux s3c2440 之UART分析(五)

作者: 時間:2016-11-19 來源:網(wǎng)絡 收藏
從上面四篇介紹文章中,已經(jīng)清楚了串口設備與串口驅(qū)動實現(xiàn)的各層次關系流程。是一種從上而下的關系,從第二篇的層次流程圖中可以看出。之前說過串口設備是一種platform device,下面看看串口作為platform device的實現(xiàn)細節(jié)。

串口的硬件平臺實現(xiàn)smdk2440_map_io()初始化入口:

本文引用地址:http://2s4d.com/article/201611/318135.htm


  1. staticvoid__initsmdk2440_map_io(void)
  2. {
  3. s3c24xx_init_io(smdk2440_iodesc,ARRAY_SIZE(smdk2440_iodesc));
  4. s3c24xx_init_clocks(12000000);
  5. s3c24xx_init_uarts(smdk2440_uartcfgs,ARRAY_SIZE(smdk2440_uartcfgs));//串口初始化
  6. }

s3c24xx_init_uarts()初始化串口, 主要完成platform device結構相關參數(shù)的賦值,如IO,中斷,以及platform device私有數(shù)據(jù)賦值等。

串口platform_device結構:

  1. staticstructplatform_devices3c24xx_uart_device0={
  2. .id=0,//ID號
  3. };
  4. staticstructplatform_devices3c24xx_uart_device1={
  5. .id=1,
  6. };
  7. staticstructplatform_devices3c24xx_uart_device2={
  8. .id=2,
  9. };

要完成platform_device參數(shù)初始化,主要涉及到一下數(shù)據(jù)結構:

串口配置數(shù)據(jù)結構:

  1. staticstructs3c2410_uartcfgtq2440_uartcfgs[]__initdata={
  2. [0]={
  3. .hwport=0,
  4. .flags=0,
  5. .ucon=0x3c5,//rx,tx采用中斷方式
  6. .ulcon=0x03,//數(shù)據(jù)長度設置為8-bits
  7. .ufcon=0x51,//開啟FIFO,并設置rx,tx觸發(fā)字節(jié)數(shù)
  8. },
  9. [1]={
  10. .hwport=1,
  11. .flags=0,
  12. .ucon=0x3c5,
  13. .ulcon=0x03,
  14. .ufcon=0x51,
  15. },
  16. [2]={
  17. .hwport=2,
  18. .flags=0,
  19. .ucon=0x3c5,
  20. .ulcon=0x03,
  21. .ufcon=0x51,
  22. }
  23. };

串口資源:

  1. staticstructresources3c2410_uart0_resource[]={
  2. [0]={
  3. .start=S3C2410_PA_UART0,
  4. .end=S3C2410_PA_UART0+0x3fff,
  5. .flags=IORESOURCE_MEM,
  6. },
  7. [1]={
  8. .start=IRQ_S3CUART_RX0,
  9. .end=IRQ_S3CUART_ERR0,
  10. .flags=IORESOURCE_IRQ,
  11. }
  12. };
  13. structs3c24xx_uart_resourcess3c2410_uart_resources[]__initdata={
  14. [0]={
  15. .resources=s3c2410_uart0_resource,
  16. .nr_resources=ARRAY_SIZE(s3c2410_uart0_resource),
  17. },
  18. [1]={
  19. .resources=s3c2410_uart1_resource,
  20. .nr_resources=ARRAY_SIZE(s3c2410_uart1_resource),
  21. },
  22. [2]={
  23. .resources=s3c2410_uart2_resource,
  24. .nr_resources=ARRAY_SIZE(s3c2410_uart2_resource),
  25. },
  26. [3]={
  27. .resources=s3c2410_uart3_resource,
  28. .nr_resources=ARRAY_SIZE(s3c2410_uart3_resource),
  29. },
  30. };

最后通過函數(shù)s3c24xx_init_uartdevs()完成 串口platform_device的初始化:

  1. void__inits3c24xx_init_uartdevs(char*name,
  2. structs3c24xx_uart_resources*res,
  3. structs3c2410_uartcfg*cfg,intno)
  4. {//name=s3c2440-uart,res=s3c2410_uart_resources[],cfg=tq2440_uartcfgs,no=3
  5. structplatform_device*platdev;
  6. structs3c2410_uartcfg*cfgptr=uart_cfgs;
  7. structs3c24xx_uart_resources*resp;
  8. intuart;
  9. memcpy(cfgptr,cfg,sizeof(structs3c2410_uartcfg)*no);
  10. for(uart=0;uart
  11. platdev=s3c24xx_uart_src[cfgptr->hwport];//platdev=s3c24xx_uart_device0
  12. resp=res+cfgptr->hwport;//resp=s3c2410_uart_resources[]+tq2440_uartcfgs.hwport
  13. s3c24xx_uart_devs[uart]=platdev;//
  14. platdev->name=name;
  15. platdev->resource=resp->resources;
  16. platdev->num_resources=resp->nr_resources;
  17. platdev->dev.platform_data=cfgptr;//plat_form_data=cfgptr=tq2440_uartcfgs
  18. }
  19. nr_uarts=no;
  20. }

最終在platform_add_device()中完成注冊

  1. platform_add_devices(s3c24xx_uart_devs,nr_uarts);
  2. intplatform_add_devices(structplatform_device**devs,intnum)
  3. {
  4. inti,ret=0;
  5. for(i=0;i
  6. ret=platform_device_register(devs[i]);
  7. if(ret){
  8. while(--i>=0)
  9. platform_device_unregister(devs[i]);
  10. break;
  11. }
  12. }
  13. returnret;
  14. }



關鍵詞: ARMLinuxs3c2440UAR

評論


技術專區(qū)

關閉