版主
主题
回帖0
积分10609
阅读权限200
注册时间2008-11-22
最后登录1970-1-1
在线时间 小时
|
NiosII处理器的启动可采用两种方式: 自动初始化和用户自定义初始化,nios中alt_main 和main的区别也在这里。
3 w, J" C9 Y8 J u/ n如果NiosII处理器自动初始化,ANSI C标准定义应用程序可以通过调用main()来开始执行。在调用main()之前,应用程序假定运行环境和所有的服务系统都被初始化并准备运行。初始化可以被硬件抽象层(HAL)系统库自动执行。程序员不需要考虑系统的输出设备以及如何初始化每一个外设,HAL会自动初始化整个系统。
* u. e% y i, }5 ]9 O3 W A 如果用户要避免自动初始化。ANSI C标准将提供了一个可变的入口点程序,定义程序员能手动初始化任何所用的硬件。alt_main()函数提供了一个独立式的编程环境,能够完全控制系统的初始化。例如用alt_irq_init (ALT_IRQ_BASE)函数初始化中断控制器。具体方法在例程hello_alt_main中能找到。
+ n8 C6 b+ A$ _7 J6 Q" Z另外,能使用main函数作为开头开头时cpu可能需要更大的ram( on chip memory )空间。最简单的例子(ram都设为4k的条件下): n! r: D% R6 v, g# W0 `* d' q
程序1:
0 N- R; e7 M& L! ~9 q" N#include <stdio.h>
c0 L2 E ^8 K4 J: e5 z#include <stdlib.h>- @3 p( z% I5 V& k
#include <string.h>
8 X9 `" }1 A- p# ]7 [#include "system.h"
0 O! U: G# z: S# m; M#include "sys/alt_sys_init.h"" C& c! K: U5 \) }' m
#include "sys/alt_irq.h"
]' W! V$ p2 m#include "priv/alt_file.h"
# X& }2 T9 i) T7 B2 P! K) eint main (void) __attribute__ ((weak, alias ("alt_main")));+ Q7 B9 I0 w m8 W
int alt_main(void)+ ]9 h) p! U3 h ~
{) w! Y7 N$ U5 m) Z
alt_irq_init (ALT_IRQ_BASE);% i0 K1 h% Q, Y' E$ s0 J5 M; z
alt_sys_init();% s+ \# ? V. n- L7 u6 X
alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);+ [% f7 C$ u$ @- g: r, q
int i;$ Y& `% u1 o' M; u8 K
i=1;2 l) X; e/ u! o9 _; q% F
return 0;( M$ i! h/ `2 @) Z8 r2 u
}
9 Q3 q) q; D- k/ {( @, k+ O--------这样就没问题,编译能通过!!!!!* ]" G/ g* S% W/ Y- s( @* H
如果改成这样:
: A) b7 S" {/ a# M w程序2
% z- T5 t8 f5 @2 t f6 h8 d! _& u( O#include <stdio.h>; S3 p, H s: R' }' d$ D: F
#include <stdlib.h>( T. e6 t; l4 ]3 s* _7 t
#include <string.h>. ]- b" ~7 q% G+ K! Q$ {" c& n
#include "system.h"
! Y, q1 I$ x& @#include "sys/alt_sys_init.h"
0 Z3 x8 I- u/ z4 p% [#include "sys/alt_irq.h"! X7 P5 W4 l; M- _
#include "priv/alt_file.h"
- c4 H h5 f) a, E T- X, vint main(void)
$ U& b& A6 h! X' e. ?{3 a" F/ p, _' U7 P: T
int i;
* Z8 \' W2 Z8 Z$ D( v, ]( l i=1;
0 `$ s1 \3 w, S& ~ ]* h3 q' zreturn 0;7 @ x- B/ V0 a6 y$ R2 N
}2 u$ s! z9 u, ^% }6 u b7 _
----------编译就不能通过了,提示如下
3 J& E! k9 I6 m( r( @1 ^4 @Console中的提示——————————————————* q( [5 c: b; f! S9 f% b
**** 00000047] overlaps section .exceptions [00000020 -> 00000ab7] overlaps section .exceptions [00000020 -> 00000ccb] overlaps section .text [000001c8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
4 c5 D) d( E- C, \1 o% f" y7 U& b3 Q4 m/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld section .rodata [00000020 -> 00000047] overlaps section .exceptions [00000020 -> 000001c7]
8 d8 [. G. s Q! P4 Y5 o/cygdrive/d/MyProgram/altera/kits/nios2_60/bin/nios2-gnutools/H-i686-pc-cygwin/bin/../lib/gcc/nios2-elf/3.4.1/../../../../nios2-elf/bin/ld section .rwdata [00000048 -> 00000ab7] overlaps section .exceptions [00000020 -> 000001c7]
9 N A6 I6 ?6 z; i: @+ qregion onchip_memory_0 is full 这就是提示ram不够,根据程序适当改大一点后就能编译了。/ Z. @' B3 H. c- H; s, C s
- m2 a5 D$ z6 {3 ^- F( }2 F[ 本帖最后由 kenson 于 2008-12-12 22:04 编辑 ] |
|