详解U-Boot中printf函数的实现


一、printf函数调用关系

U-Boot源代码下载地址


1.1fputc和srial_putc的关系

  1. /*  
  2.  * Output a single byte to the serial port.  
  3.  */  
  4. void serial_putc (const char c)//发送数据  
  5. {  
  6.     S3C24X0_UART * const uart = S3C24X0_GetBase_UART(UART_NR);  
  7. #ifdef CONFIG_MODEM_SUPPORT  
  8.     if (be_quiet)  
  9.         return;  
  10. #endif  
  11.   
  12.     /* wait for room in the tx FIFO */  
  13.     while (!(uart->UTRSTAT & 0x2));  
  14.   
  15. #ifdef CONFIG_HWFLOW  
  16.     /* Wait for CTS up */  
  17.     while(hwflow && !(uart->UMSTAT & 0x1))  
  18.         ;  
  19. #endif  
  20.   
  21.     uart->UTXH = c;  
  22.   
  23.     /* If \n, also do \r */  
  24.     if (c == '\n')  
  25.         serial_putc ('\r');  
  26. }  
serial_putc函数是直接和控制相关的,通过UTXH寄存器发送数据。
  1. void fputc (int file, const char c)  
  2. {  
  3.     if (file < MAX_FILES)  
  4.         stdio_devices[file]->putc (c);  
  5. }  

这是在console_init_r中设置stdio_devices[]后才有的,其他的是类似的。

1.2putc和fputc的关系

  1. void putc (const char c)  
  2. {  
  3. #ifdef CONFIG_SILENT_CONSOLE  
  4.     if (gd->flags & GD_FLG_SILENT)  
  5.         return;  
  6. #endif  
  7.   
  8.     if (gd->flags & GD_FLG_DEVINIT) {  
  9.         /* Send to the standard output */  
  10.         fputc (stdout, c);  
  11.     } else {  
  12.         /* Send directly to the handler */  
  13.         serial_putc (c);  
  14.     }  
  15. }  

这是console_init_r中设置gd->flags & GD_FLG_DEVINIT,也就是串口设备完全初始化之后才有这种关系,其他的函数是类似的。

  • 1
  • 2
  • 3
  • 下一页

相关内容