Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1694459
  • 博文数量: 511
  • 博客积分: 967
  • 博客等级: 准尉
  • 技术积分: 2560
  • 用 户 组: 普通用户
  • 注册时间: 2012-07-06 14:19
文章分类

全部博文(511)

文章存档

2016年(11)

2015年(61)

2014年(257)

2013年(63)

2012年(119)

分类: LINUX

2013-01-04 12:56:50

u-boot 串口初始化                                                
    printf()                                                     
==================================================================
board_init_r (gd_t *id, ulong dest_addr)                         
        -------->serial_initialize()                             
               {                                                 
                #if defined(CONFIG_AML_MESON)                    
                serial_aml_register();---------->下面.           
                #endif                                           
             serial_assign (default_serial_console ()->name); 
             }                                                
                                                                 
\uboot\arch\arm\cpu\aml_meson):void serial_aml_register(void)    
void serial_aml_register(void)                                   
{                                                                
    serial_register(&device_UART_PORT_0);---------->下面         
    serial_register(&device_UART_PORT_1);//参数在哪里呢? ------>
#ifdef UART_PORT_AO                                          |   
    serial_register(&device_UART_PORT_AO);                   |   
#endif                                                       |   
}                                                            |   
int serial_register (struct serial_device *dev)  
{                                                
#ifdef CONFIG_NEEDS_MANUAL_RELOC                 
 dev->init += gd->reloc_off;                  
 dev->setbrg += gd->reloc_off;                
 dev->getc += gd->reloc_off;                  
 dev->tstc += gd->reloc_off;                  
 dev->putc += gd->reloc_off;                  
 dev->puts += gd->reloc_off;                  
#endif                                           
 dev->next = serial_devices;                  
 serial_devices = dev;                        
 return 0;                                    
--------------------------参数--------------------------------

                                                          
 #define INIT_UART_STRUCTURE(port,name,bus)               
  static struct serial_device device_##port={\  name,\   
    bus,\                                                
    uart_##port##_init,\                                 
    NULL,\                                               
    uart_##port##_setbrg,\                               
    uart_##port##_getc,\                                 
    uart_##port##_tstc,\                                 
    uart_##port##_putc,\                                 
    uart_##port##_puts, }                                
                                                          
    DECLARE_UART_FUNCTIONS(UART_PORT_0);                  
    INIT_UART_STRUCTURE(UART_PORT_0,"uart0","UART0");     
    DECLARE_UART_FUNCTIONS(UART_PORT_1);                  
    INIT_UART_STRUCTURE(UART_PORT_1,"uart1","UART1");     
    #ifdef UART_PORT_AO                                   
    DECLARE_UART_FUNCTIONS(UART_PORT_AO);                 
    INIT_UART_STRUCTURE(UART_PORT_AO,"uart_ao","UART_AO");
    #endif                                                
             INIT_UART_STRUCTURE(UART_PORT_0,"uart0","UART0");                 
             ---->  static struct serial_device device_UART_PORT_0={           
                 ....                                                          
                    uart_UART_PORT_0_getc,------| 这些函数在下面:              
                 ....                           |                              
                 }                              |                              
                        #define DECLARE_UART_FUNCTIONS(port) \                 
                            static int  uart_##port##_init (void) {\           
                         serial_init_port(port); return(0);}\               
                            static void uart_##port##_setbrg (void) {\         
                         serial_setbrg_port(port);}\                        
 uart_UART_PORT_0_getc ---->static int  uart_##port##_getc (void) {\           
                         return serial_getc_port(port);}\                   
                            static int  uart_##port##_tstc (void) {\           
                         return serial_tstc_port(port);}\                   
                            static void uart_##port##_putc (const char c) {\   
                         serial_putc_port(port, c);}\                       
                            static void uart_##port##_puts (const char *s) {\  
                         serial_puts_port(port, s);}                        
int serial_assign (char *name) -->参数中的结构?
{                                             
 struct serial_device *s;                   
 for (s = serial_devices; s; s = s->next) { 
  if (strcmp (s->name, name) == 0) {     
   serial_current = s;                
   return 0;                          
  }                                      
 }                                          
 return 1;                                  
}                                             
  struct serial_device * default_serial_console (void)
{                                                   
#if (UART_PORT_CONS==UART_PORT_0)                   
    return &device_UART_PORT_0;                     
#elif (UART_PORT_CONS==UART_PORT_1)                 
    return &device_UART_PORT_1;                     
#else                                               
#ifdef UART_PORT_AO                                 
#if (UART_PORT_CONS==UART_PORT_AO)                  
   return &device_UART_PORT_AO;                     
#else                                               
 #error "invalid uart port index defined"         
#endif                                              
#endif                                              
#endif                                              
  

int printf(const char *fmt, ...)  \uboot\com
{                                          
 va_list args;                          
 uint i;                                
 char printbuffer[CONFIG_SYS_PBSIZE];   
                                           
 va_start(args, fmt);                   
                                           
 /* For this to work, printbuffer must be
  * anything we ever want to print.     
  */                                    
 i = vsprintf(printbuffer, fmt, args);  
 va_end(args);                          
                                           
 /* Print the string */                 
 puts(printbuffer);  -------------------->
 return i;                              
}                                          
 void puts(const char *s)                                     
 {                                                            
 #ifdef CONFIG_SILENT_CONSOLE                                 
  if (gd->flags & GD_FLG_SILENT)                             
   return;                                                
 #endif                                                       
                                                              
 #ifdef CONFIG_DISABLE_CONSOLE                                
  if (gd->flags & GD_FLG_DISABLE_CONSOLE)                    
   return;                                                
 #endif                                                       
                                                              
  if (gd->flags & GD_FLG_DEVINIT) {                          
   /* Send to the standard output */                      
   fputs(stdout, s);                                      
  } else {                                                   
   /* Send directly to the handler */                     
   serial_puts(s);   ----->这里才是调用我们的SOC级的驱动  
  }                                                          
 }                                                            
-------------------------------------------------------------------------------->
 void serial_putc(const char c){     \uboot\arch\arm\cpu\aml_meson\serial.c      
  serial_putc_port(UART_PORT_CONS,c);                                          
 }                                                                               
                                                                                 
 int serial_tstc(void){                                                          
  return serial_tstc_port(UART_PORT_CONS);                                     
 }                                                                               
                                                                                 
 int serial_getc(void){                                                          
  return serial_getc_port(UART_PORT_CONS);                                     
 }                                                                               
                                                                                 
 void serial_puts(const char * s){                                               
  serial_puts_port(UART_PORT_CONS,s);                                          
 }                                                                               
                                                                                 
 void serial_setbrg(void){                                                       
  serial_setbrg_port(UART_PORT_CONS);                                          
 }                                                                               
  

阅读(2054) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~