[原创].HAL的不同方式访问字符器件的空间开销简单比较.[C][Nios II]
0赞
发表于 2010/6/8 21:32:43
阅读(1864)
注:本文所述皆为查询方式的比对,中断方式下请读者自习研究比对。
范例:/dev/jtag_uart
Unix类型
图1 系统库属性设置
源代码:
01 |
#include "system.h" |
02 |
#include "fcntl.h" |
03 |
#include "unistd.h" |
04 |
|
05 |
int main( void ) |
06 |
{ |
07 |
int fd; // file descriptor |
08 |
char msg[] = "Hello Nios!" ; |
09 |
|
10 |
fd = open( "/dev/jtag_uart" , O_WRONLY); |
11 |
write(fd, msg, sizeof (msg)-1); |
12 |
close(fd); |
13 |
|
14 |
return 0; |
15 |
} |
编译结果:
Info: (hello_nios.elf) 2608 Bytes program size (code + initialized data).
Info: 8189 KBytes free for stack + heap.
ANSI C
图2 系统库属性设置
源代码:
01 |
#include "system.h" |
02 |
#include <stdio.h> |
03 |
|
04 |
int main ( void ) |
05 |
{ |
06 |
FILE *fp; // file pointer |
07 |
char msg[] = "Hello Nios!" ; |
08 |
|
09 |
fp = fopen ( "/dev/jtag_uart" , "w" ); |
10 |
fprintf (fp, msg); |
11 |
fclose (fp); |
12 |
|
13 |
return 0; |
14 |
} |
编译结果:
Info: (hello_nios.elf) 43 KBytes program size (code + initialized data).
Info: 8148 KBytes free for stack + heap.
C++流
(略)
参考
1. Altera, HAL API Reference, 200905
2. 李兰英等, NiosII嵌入式软核SOPC设计原理及应用, 200611, 北京航空航天大学出版社