版主
  
主题
帖子
积分10609
阅读权限200
注册时间2008-11-22
最后登录1970-1-1
在线时间 小时
|
NiosII处理器的启动可采用两种方式: 自动初始化和用户自定义初始化,nios中alt_main 和main的区别也在这里。
. X/ k0 m# b' y. u& [8 w8 h如果NiosII处理器自动初始化,ANSI C标准定义应用程序可以通过调用main()来开始执行。在调用main()之前,应用程序假定运行环境和所有的服务系统都被初始化并准备运行。初始化可以被硬件抽象层(HAL)系统库自动执行。程序员不需要考虑系统的输出设备以及如何初始化每一个外设,HAL会自动初始化整个系统。4 l: X* U5 A$ @: f% V
如果用户要避免自动初始化。ANSI C标准将提供了一个可变的入口点程序,定义程序员能手动初始化任何所用的硬件。alt_main()函数提供了一个独立式的编程环境,能够完全控制系统的初始化。例如用alt_irq_init (ALT_IRQ_BASE)函数初始化中断控制器。具体方法在例程hello_alt_main中能找到。
# O4 S0 @5 Z/ ~* E) x: j# {& k9 l另外,能使用main函数作为开头开头时cpu可能需要更大的ram( on chip memory )空间。最简单的例子(ram都设为4k的条件下):$ P* p9 Q, i1 Y. O0 Q6 h! e
程序1:9 @9 [3 y; l/ x6 c. T/ g. U
#include <stdio.h>
% H, n+ G7 D5 }4 T+ ]( B2 J( W#include <stdlib.h>
; I$ x: t6 D6 a* \% s( ~7 j8 U#include <string.h>
3 k' [7 m) Q8 {0 t! \: C- I#include "system.h". S$ [- r1 c* N7 c( K
#include "sys/alt_sys_init.h"* r+ `1 x4 k1 ~" u* U7 Y4 Z& l
#include "sys/alt_irq.h"! ~$ C/ o6 L5 R
#include "priv/alt_file.h"
3 a) i* T6 p5 T( j5 R# f1 Lint main (void) __attribute__ ((weak, alias ("alt_main")));, I/ h7 i! W, f/ ^% P" x: w) O ~* {
int alt_main(void)
6 o3 d: _2 I) w2 x' C{& w& ~+ e3 k3 m0 U! n
alt_irq_init (ALT_IRQ_BASE);
1 f7 Z8 K( G& Q5 i' t alt_sys_init();. E) \/ z; o5 W$ {/ k9 P! y
alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);- n2 d* I4 X: s9 @4 C
int i;$ b. v* b- l6 d$ W y$ P
i=1;# X# X2 t* h( n9 C% o( W; e4 I- Y
return 0;
! e# r5 L0 j& Z& ~4 K8 C}
9 d' s! y+ K; Z--------这样就没问题,编译能通过!!!!!
' c. q5 { }4 J) e1 \* j) r/ G如果改成这样:
! \9 W- S# ?$ n$ p程序2 ( `, p1 J8 | {0 i1 p
#include <stdio.h>
. ~, s+ F/ D. i7 y7 Z$ c. `4 C#include <stdlib.h>
4 i- X/ k+ ]( k; _#include <string.h>7 }6 o B9 G h5 s
#include "system.h"! a1 h- G- B6 _: n
#include "sys/alt_sys_init.h"0 ?0 E7 ~1 R# F
#include "sys/alt_irq.h"
2 m4 A8 V# T0 e5 \ C @' U1 v#include "priv/alt_file.h"
$ b- u% R1 z1 ~( s7 y( `int main(void)2 U" S% j9 k5 R8 S8 V+ q
{% s& d% T& R4 U2 b
int i;
8 W7 K1 _7 Q2 E i=1;
+ |" J _3 y" vreturn 0;
4 N/ f+ T. T/ N7 i4 W& J9 X! Q}8 u! S# K$ m4 A( ?' \" O0 K
----------编译就不能通过了,提示如下 : f& V+ B9 [- k2 w
Console中的提示——————————————————, F, ~: Z) V* ^3 x
**** 00000047] overlaps section .exceptions [00000020 -> 00000ab7] overlaps section .exceptions [00000020 -> 00000ccb] overlaps section .text [000001c8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]7 y+ g3 V* w; e; h' i+ q6 m8 ^) s2 e1 ^
/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]
/ E! o' f9 ?" s# i. L: p9 ]' P/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]
8 Y1 T3 x, {1 M( _& m4 u9 Lregion onchip_memory_0 is full 这就是提示ram不够,根据程序适当改大一点后就能编译了。
) H" m% G& Q# u
$ d! L1 T g+ Q( J; l& R- q; _[ 本帖最后由 kenson 于 2008-12-12 22:04 编辑 ] |
|