Forum Discussion
Altera_Forum
Honored Contributor
19 years agoThanks hippo
I lost the "-" in D__KERNEL__ firster. so I make fail. http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/biggrin.gif every one: If you do not want to write driver for some simple device. You can use macro outl , inl to control the device directly. frist add "-D__KERNEL__ " to CFLAGS += in your makefile second copy "nios2_system.h" from ~/linux2.6.x/include to your include dir follow is my simple code: # ifndef __LED_H__# define __LED_H__ # include <asm/io.h> # include "board.h" // define constants for LED status# define LED_ALL_OFF 0x00# define LED_ALL_ON 0xFF # define MAJ_LED_OFF (inl(LED_CTRL) & 0xFE)# define MAJ_LED_ON (inl(LED_CTRL) | 0x01) # define MIN_LED_OFF (inl(LED_CTRL) & 0xFD)# define MIN_LED_ON (inl(LED_CTRL) | 0x02) # define ACO_LED_OFF (inl(LED_CTRL) & 0xFB)# define ACO_LED_ON (inl(LED_CTRL) | 0x04) void init_led(void); # endif # ifndef __BOARD_H__# define __BOARD_H__ // Main clck frequency.# define MCLK 50000000 // SDRAM area definition.# define SDRAM_BASE 0x01000000# define SDRAM_SIZE 0x01000000 // 16MBytes //FALSH area definition# define FLASH_BASE 0x00000000# define FLASH_SIZE 0x00800000 // 8MBytes // led Configuration Registers# define LED_CTRL 0x00810850 # endif # include "led.h"# include "board.h" void init_led(void) { outl(LED_ALL_ON, LED_CTRL); } int main(void) { //init_msgQ(); init_led(); while(1) { outl(LED_ALL_OFF, LED_CTRL); outl(MAJ_LED_ON, LED_CTRL); sleep(1); outl(MAJ_LED_OFF, LED_CTRL); sleep(1); outl(MIN_LED_ON, LED_CTRL); sleep(1); outl(MIN_LED_OFF, LED_CTRL); sleep(1); outl(ACO_LED_ON, LED_CTRL); sleep(1); outl(ACO_LED_OFF, LED_CTRL); sleep(1); } }