>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);
/* wait for room in the tx FIFO */
//while ((!(uart->UTRSTAT & 0x2)));
while (uart->UFSTAT & (1<<14));
uart->UTXH = c;
}
返回bootstrap_main()函数,调用mem_mallloc_init()函数初始化动态分配的存储区,为我们调用malloc()函数做好准备工作,如下:
void mem_malloc_init(ulong start, ulong size)
{
mem_malloc_start = start;
mem_malloc_end = start + size;
mem_malloc_brk = start;
memset((void *)mem_malloc_start, 0, size);
printf("malloc memory space: 0x%lx~0x%lx\n", start, start+size);
}
函数返回,调用函数
ptr = (char *)malloc(MALLOC_SIZE);
其中MALLOC_SIZE定义在makefile函数,MALLOC_SIZE=0x100000。我们深入到malloc函数中去,如下
声明位置:yaffs2/common/malloc.h
#define mALLOc malloc
Void_t* mALLOc(size_t);
定义位置:yaffs2/common/dlmalloc.c
代码量很大,不拷贝了。
返回bootstrap_main()函数,调用如下函数目的是测试动态分配到存储区域是否成功:
strncpy(ptr, "Hello World!\n", MALLOC_SIZE);
printf("Malloc address: %p, string: %s\n", ptr, ptr);
free(ptr);
接着就到了测试yaffs2文件系统的阶段了。
#define YAFFSFS_MNT_POINT "/nand"
yaffs_test(YAFFSFS_MNT_POINT);
hang:
while(1)
;
return 0;
}
其中yaffs_test()函数主要是通过创建文件或目录,并删除一些文件的功能来达到测试yaffs2文件系统是否移植成功,代码如下:
位置:与bootstrap_main()函数同处于一个位置。
void yaffs_test(const char *mountpt)
{
yaffs_start_up();
yaffs_format(mountpt,0,0,0);
yaffs_mount(mountpt);
printf("'%s' mounted\n", mountpt);
mkdir(mountpt, "foo");
mkfile(mountpt, "foo/f1");
mkfile(mountpt, "foo/f2");
mkfile(mountpt, "foo/f3");
mkfile(mountpt, "foo/f4");
mkdir(mountpt, "bar");
mkfile(mountpt, "bar/f1");
ls(mountpt, NULL);
rm(mountpt, "foo/f4");
rm(mountpt, "bar");
ls(mountpt, NULL);
printf("unmount and remount\n\n");
/* Unmount/remount yaffs_trace_mask */
yaffs_unmount(mountpt);
yaffs_mount(mountpt);
ls(mountpt, NULL);
}
其中yaffs_start_up()函数用来配置将要用到的设备,如下:
位置:yaffs2/yaffs2/yaffscfg2k.c
/* Configure the devices that will be used */