一乐电子

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

微信扫码登录

搜索
查看: 9874|回复: 0

nios中alt_main 和main的区别

[复制链接]
发表于 2008-12-12 22:03 | 显示全部楼层 |阅读模式
NiosII处理器的启动可采用两种方式: 自动初始化和用户自定义初始化,nios中alt_main 和main的区别也在这里。" t* I% y6 Q) `
如果NiosII处理器自动初始化,ANSI C标准定义应用程序可以通过调用main()来开始执行。在调用main()之前,应用程序假定运行环境和所有的服务系统都被初始化并准备运行。初始化可以被硬件抽象层(HAL)系统库自动执行。程序员不需要考虑系统的输出设备以及如何初始化每一个外设,HAL会自动初始化整个系统。
5 r& n7 Q" K2 t+ }& Z 如果用户要避免自动初始化。ANSI C标准将提供了一个可变的入口点程序,定义程序员能手动初始化任何所用的硬件。alt_main()函数提供了一个独立式的编程环境,能够完全控制系统的初始化。例如用alt_irq_init (ALT_IRQ_BASE)函数初始化中断控制器。具体方法在例程hello_alt_main中能找到。
/ j, h+ V( f$ O) I4 z另外,能使用main函数作为开头开头时cpu可能需要更大的ram( on chip memory )空间。最简单的例子(ram都设为4k的条件下):
0 f: t$ s6 P" W2 r' G3 D& c程序1:
: J8 N6 a( ]0 o; c! O  |- |% z#include <stdio.h>/ ]9 A' T6 l' [
#include <stdlib.h>6 [% G* _% m& u' m# N# K) \0 O
#include <string.h>
7 s1 `' N# j: U1 d6 a#include "system.h"; D3 i, h% ^1 |7 v7 {6 A! c( g. x
#include "sys/alt_sys_init.h"
+ J0 p$ L" b( w  L( c7 M9 U#include "sys/alt_irq.h"
# m3 o- R+ f$ R; M0 O#include "priv/alt_file.h"
7 V! p# @6 i, ^6 [+ j1 X! q% _int main (void) __attribute__ ((weak, alias ("alt_main")));
* ~8 `3 b" o4 F7 G1 k! z: C2 Nint alt_main(void)
& e9 L' J9 a( ~* {{
, k  C0 p' F6 d9 h. x  alt_irq_init (ALT_IRQ_BASE);, J* U( `0 ]3 N4 o
  alt_sys_init();
' D1 \" Z0 z  V+ ~/ M  T8 G' y+ ^9 t  alt_io_redirect (ALT_STDOUT, ALT_STDIN, ALT_STDERR);
0 t9 I* S' c, A: ~  int i;
- s% a+ p) r7 u2 M# L: X4 W/ {  i=1;0 G6 F% Y0 X3 e9 h9 l# ?' V; @
  return 0;1 v6 b" T8 Y3 f8 O% ~
}7 H9 V% ^$ z1 n* |
--------这样就没问题,编译能通过!!!!!9 V- ~' b( T9 I
如果改成这样:
8 T& k% o* s( i& b# ]6 [程序2 * D# s# z, L; h2 x! g6 O% n+ b2 O2 t
#include <stdio.h>- R8 |% U% o# S; V( R3 m: n
#include <stdlib.h>
; S6 c/ R, F4 u/ {% z#include <string.h>
  V) j3 D1 G! e2 M5 C#include "system.h"6 Q1 R5 B' l; R, H( p' j; C4 P: A
#include "sys/alt_sys_init.h"3 E9 P& a. s8 A$ f
#include "sys/alt_irq.h"" S( \( |) w3 m, O' w
#include "priv/alt_file.h"
) Y: @8 e$ ?: v) [4 W5 c' s' @. f0 {int main(void)6 H3 M; ~( o& Z2 `4 E0 p5 W
{2 d' H! A/ G: |3 @, L2 G. T1 [' D
  int i;
9 V7 R0 M9 r4 l! c7 `  i=1;! b2 G( h3 t9 e7 G# \
return 0;
0 g0 H% |/ k9 K. h}$ O1 B1 d) k# |8 P
----------编译就不能通过了,提示如下  8 t0 k. J  C) E& m* K
Console中的提示——————————————————
3 V  G1 t( K8 s**** 00000047] overlaps section .exceptions [00000020 -> 00000ab7] overlaps section .exceptions [00000020 -> 00000ccb] overlaps section .text [000001c8 -> 00000ccb] overlaps section .text [000001c8 -> 0000261b]
  j2 D6 R! N( @# K6 ?/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]
% Q- h- W) f! A/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]& v$ I% T# }1 I5 M) z
region onchip_memory_0 is full 这就是提示ram不够,根据程序适当改大一点后就能编译了。) G9 c( \* w1 A0 X+ a4 ~3 r" Y
/ b- ?& \' \' q  T% I9 |8 v& k9 c. o1 J
[ 本帖最后由 kenson 于 2008-12-12 22:04 编辑 ]

本版积分规则

QQ|一淘宝店|手机版|商店|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2025-8-20 12:04 , Processed in 0.030083 second(s), 18 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表