裸机移植yaffs2文件系统(3)

/*  armboot_start is defined in the board-specific linker script */
 
    mem_malloc_init (TEXT_BASE - CONFIG_SYS_MALLOC_LEN, CONFIG_SYS_MALLOC_LEN);
 
   
 
    ptr = (char *)malloc(MALLOC_SIZE);                         
 
    strncpy(ptr, "Hello World!\n", MALLOC_SIZE);
 
    printf("Malloc address: %p, string: %s\n", ptr, ptr);     
 
    free(ptr);
 
   
 
    yaffs_test(YAFFSFS_MNT_POINT);
 

hang:
 
    while(1)
 
        ;
 

return 0;
 
}
 
首先是初始化串口,console_serial_init()函数如下:
 
位置:yaffs2/bsp/s3c_board.h
 
#define CONSOLE_BAUDRATE        115200
 
#define CONSOLE_SERIAL          S3C2440_UART0
 
其中S3C2440_UART0在文件yaffs2/bsp/s3c2440.h中定义:
 
enum s3c2440_uarts_nr {
 
    S3C2440_UART0 = 0,
 
    S3C2440_UART1 = 1,
 
    S3C2440_UART2 = 2
 
};
 

#define console_serial_init()      s3c2440_serial_init(CONSOLE_BAUDRATE, CONSOLE_SERIAL)
 
即--> console_serial_init()-->s3c2440_serial_init()如下:
 
int s3c2440_serial_init(unsigned int baudrate, int index)
 
{
 
    struct s3c2440_uart *uart = s3c2440_get_base_uart(index);
 

/* FIFO enable, Tx/Rx FIFO clear */
 
    uart->UFCON = 0x07;
 
    uart->UMCON = 0x0;
 

/* Normal,No parity,1 stop,8 bit */
 
    uart->ULCON = 0x3;
 
    /*
 
    * tx=level,rx=edge,disable timeout int.,enable rx error int.,
 
    * normal,interrupt or polling
 
    */
 
    uart->UCON = (1<<8) | (1<<2) | (1<<0);
 

//  uart->UMCON = 0x1; /* RTS up */
 

s3c2440_set_baudrate(baudrate, index);
 

return (0);
 
}
 
设置波特率函数s3c2440_set_baudrate()
 
void s3c2440_set_baudrate(unsigned int baudrate, int index)
 
{
 
    struct s3c2440_uart *uart = s3c2440_get_base_uart(index);
 
    unsigned int reg = 0;
 
    int i;
 
    reg = s3c2440_get_pclk() / (16 * baudrate) - 1;
 

uart->UBRDIV = reg;
 
    for (i = 0; i < 100; i++);
 
}
 
返回到bootstrap_main()函数中去,看下printf()函数如何将打印信息通过串口显示出来。
 
#define CFG_PBSIZE                  1024 /*  Print Buffer Size */
 
void printf(const char *fmt, ...)
 
{
 
    va_list args;
 
    uint i;
 
    char printbuffer[CFG_PBSIZE];
 

va_start(args, fmt);
 

/* For this to work, printbuffer must be larger than
 
    * anything we ever want to print.
 
    */
 
    i = vsprintf(printbuffer, fmt, args);
 
    va_end(args);
 

console_serial_puts(printbuffer);
 
}
 
调用函数console_serial_puts()函数,如下:
 
#define console_serial_puts(s)    s3c2440_serial_puts(s, CONSOLE_SERIAL)
 
void s3c2440_serial_puts(const char *s, int index)
 
{
 
    while (*s)
 
    {
 
        if (*s == '\n')              /*  If \n, also do \r */
 
            s3c2440_serial_putc('\r', index);
 
        s3c2440_serial_putc (*s++, index);
 
    }
 
}
 
调用函数s3c2440_serial_putc()函数,如下:
 
/*
 
 * Output a single byte to the serial port.
 
 */
 
void s3c2440_serial_putc (char c, int index)
 
{
 
    struct s3c2440_uart *uart = s3c2440_get_base_uart(index);
 

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/4be9678c1495a1085cea27b68226880c.html