版主
主题
回帖0
积分10609
阅读权限200
注册时间2008-11-22
最后登录1970-1-1
在线时间 小时
|
NiosII处理器的启动可采用两种方式: 自动初始化和用户自定义初始化,nios中alt_main 和main的区别也在这里。8 T# ^/ P8 b$ j( ~
如果NiosII处理器自动初始化,ANSI C标准定义应用程序可以通过调用main()来开始执行。在调用main()之前,应用程序假定运行环境和所有的服务系统都被初始化并准备运行。初始化可以被硬件抽象层(HAL)系统库自动执行。程序员不需要考虑系统的输出设备以及如何初始化每一个外设,HAL会自动初始化整个系统。, o' |6 N9 S$ p$ G, [7 G
如果用户要避免自动初始化。ANSI C标准将提供了一个可变的入口点程序,定义程序员能手动初始化任何所用的硬件。alt_main()函数提供了一个独立式的编程环境,能够完全控制系统的初始化。例如用alt_irq_init (ALT_IRQ_BASE)函数初始化中断控制器。具体方法在例程hello_alt_main中能找到。( X9 E/ K \: ? m2 L, N
另外,能使用main函数作为开头开头时cpu可能需要更大的ram( on chip memory )空间。最简单的例子(ram都设为4k的条件下):/ d: `. {* F9 q% H! A4 }( ~1 K% j
程序1:4 b9 g) a7 ?; Z
#include <stdio.h>
9 f, y5 ]( h* M#include <stdlib.h>: O9 M; v& h. ^0 d
#include <string.h>
; @( l7 Z( U- A x#include "system.h"
7 O$ K0 T% G, ^) b' i) a#include "sys/alt_sys_init.h"
1 D5 C' D4 E0 \$ ? ?( B#include "sys/alt_irq.h", Y. g% A, j. d
#include "priv/alt_file.h"
0 e2 S: a* _ A4 ]) W" ?/ fint main (void) __attribute__ ((weak, alias ("alt_main")));
8 z& c7 H* ? k H6 q3 `7 oint alt_main(void)9 r" U' \- |4 \ q: [! F; Z) y
{$ _! Y- Q' T P8 b- l
alt_irq_init (ALT_IRQ_BASE);, C3 ~4 C: u) y% }% E
alt_sys_init();+ {' N3 _" x5 t# y0 G! O0 m
alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);6 @. h, Y) l6 Y6 |6 e7 h
int i;1 K5 G& s1 n/ n. o4 a
i=1;4 k% }; z+ L0 _3 G) q& ]/ H
return 0;% D9 H# A) D' b
}
" C5 K. W' ]# o5 [- K--------这样就没问题,编译能通过!!!!!
3 S- E4 W, C* T" {& O3 ?如果改成这样:
) P& O/ ^. x/ S3 h4 A1 H0 S) r程序2
; R* a3 b+ ~$ D: m2 Z#include <stdio.h>% x! o5 D/ P0 V0 w& R' L
#include <stdlib.h>. @) N8 Z( y3 \% I* K+ P3 h- @5 _
#include <string.h>7 O5 g" t1 P* d
#include "system.h"
; D! Y; i1 a8 H#include "sys/alt_sys_init.h"
4 S) A: U4 b4 E#include "sys/alt_irq.h"# [) I) e' k; A7 C3 {/ N
#include "priv/alt_file.h"
$ o: S4 ]# q% [: Iint main(void)8 {- g4 |; }- p; m, D
{
% Q% ~ E/ |1 m& o9 P K9 v! Z int i;/ h& u( T3 \5 E B1 {4 J
i=1;/ } t5 U: |/ F2 P5 U7 P
return 0;# c( F/ S& R4 W# ]+ g
}! z Y2 Y7 H7 W) F% ^3 z. c
----------编译就不能通过了,提示如下
- m9 N6 g* B6 z- N3 `6 dConsole中的提示——————————————————
! n8 e! j& e2 E# ^. t/ X. `**** 00000047] overlaps section .exceptions [00000020 -> 00000ab7] overlaps section .exceptions [00000020 -> 00000ccb] overlaps section .text [000001c8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
( [7 o1 W/ {7 N; Z( G) @/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]( T$ n o8 s. T
/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]6 ]$ Y7 C m [6 i! C
region onchip_memory_0 is full 这就是提示ram不够,根据程序适当改大一点后就能编译了。' T) q. f* P( k
0 ~: u5 o$ T! w
[ 本帖最后由 kenson 于 2008-12-12 22:04 编辑 ] |
|