hello_world_small.c


01: /* 
02:  * "Small Hello World" example. 
03:  * 
04:  * This example prints 'Hello from Nios II' to the STDOUT stream. It runs on
05:  * the Nios II 'standard', 'full_featured', 'fast', and 'low_cost' example 
06:  * designs. It requires a STDOUT  device in your system's hardware. 
07:  *
08:  * The purpose of this example is to demonstrate the smallest possible Hello 
09:  * World application, using the Nios II HAL library.  The memory footprint
10:  * of this hosted application is ~332 bytes by default using the standard 
11:  * reference design.  For a more fully featured Hello World application
12:  * example, see the example titled "Hello World".
13:  *
14:  * The memory footprint of this example has been reduced by making the
15:  * following changes to the normal "Hello World" example.
16:  * Check in the Nios II Software Developers Manual for a more complete 
17:  * description.
18:  * 
19:  * In the SW Application project (small_hello_world):
20:  *
21:  *  - In the C/C++ Build page
22:  * 
23:  *    - Set the Optimization Level to -Os
24:  * 
25:  * In System Library project (small_hello_world_syslib):
26:  *  - In the C/C++ Build page
27:  * 
28:  *    - Set the Optimization Level to -Os
29:  * 
30:  *    - Define the preprocessor option ALT_NO_INSTRUCTION_EMULATION 
31:  *      This removes software exception handling, which means that you cannot 
32:  *      run code compiled for Nios II cpu with a hardware multiplier on a core 
33:  *      without a the multiply unit. Check the Nios II Software Developers 
34:  *      Manual for more details.
35:  *
36:  *  - In the System Library page:
37:  *    - Set Periodic system timer and Timestamp timer to none
38:  *      This prevents the automatic inclusion of the timer driver.
39:  *
40:  *    - Set Max file descriptors to 4
41:  *      This reduces the size of the file handle pool.
42:  *
43:  *    - Check Main function does not exit
44:  *    - Uncheck Clean exit (flush buffers)
45:  *      This removes the unneeded call to exit when main returns, since it
46:  *      won't.
47:  *
48:  *    - Check Don't use C++
49:  *      This builds without the C++ support code.
50:  *
51:  *    - Check Small C library
52:  *      This uses a reduced functionality C library, which lacks  
53:  *      support for buffering, file IO, floating point and getch(), etc. 
54:  *      Check the Nios II Software Developers Manual for a complete list.
55:  *
56:  *    - Check Reduced device drivers
57:  *      This uses reduced functionality drivers if they're available. For the
58:  *      standard design this means you get polled UART and JTAG UART drivers,
59:  *      no support for the LCD driver and you lose the ability to program 
60:  *      CFI compliant flash devices.
61:  *
62:  *    - Check Access device drivers directly
63:  *      This bypasses the device file system to access device drivers directly.
64:  *      This eliminates the space required for the device file system services.
65:  *      It also provides a HAL version of libc services that access the drivers
66:  *      directly, further reducing space. Only a limited number of libc
67:  *      functions are available in this configuration.
68:  *
69:  *    - Use ALT versions of stdio routines:
70:  *
71:  *           Function                  Description
72:  *        ===============  =====================================
73:  *        alt_printf       Only supports %s, %x, and %c ( < 1 Kbyte)
74:  *        alt_putstr       Smaller overhead than puts with direct drivers
75:  *                         Note this function doesn't add a newline.
76:  *        alt_putchar      Smaller overhead than putchar with direct drivers
77:  *        alt_getchar      Smaller overhead than getchar with direct drivers
78:  *
79:  */
80: 
81: #include "sys/alt_stdio.h"
82: 
83: int main()
84: { 
85:   alt_putstr("Hello from Nios II!\n");
86: 
87:   /* Event loop never exits. */
88:   while (1);
89: 
90:   return 0;
91: }


Maintained by John Loomis, updated Tue Sep 02 21:04:15 2008