5. HAL NII52005-1.1 HAL Hardware Abstraction Layer HAL API Application Programming Interface Nios II 2 HAL HAL API API HAL API HAL API DMA HAL HAL API HAL API ASCII LCD printf() LCD Altera Corporation 5 1 2004 12 Preliminary
API HAL API HAL API HAL API HAL API HAL C API HAL API 5 17 HAL HAL API API C++ HAL HAL C++ C C HAL C 4 1 HAL HAL 1. 2. 3. main () 4. HAL 5. HAL 5 2 Altera Corporation Nios II 2004 12
HAL SOPC Builder SOPC Builder Nios II SOPC Builder system.h SOPC Builder system.h Nios II system.h Nios II SOPC Builder SOPC Builder Nios II system.h SOPC Builder system.h 4 1 HAL SOPC Builder system.h SOPC Builder system.h SOPC Builder SOPC Builder Nios II SOPC Builder SOPC Builder Altera Corporation 5 3 2004 12 Nios II
SOPC Builder Nios II <Nios II >/components < >_regs.h inc JTAG UART <Nios II >/components/altera_avalon_jtag_uart/ inc/altera_avalon_jtag_uart_regs.h _regs.h IORD_< >_< > IOWR_< >_< > 7 1 < >_ < >_< >_MSK < >_< >_< >_OFST PE ALTERA_AVALON_UART_STATUS_PE_MSK ALTERA_AVALON_UART_STATUS_PE_OFST _regs.h _regs.h 5 4 Altera Corporation Nios II 2004 12
HAL 7 1 _regs.h SOPC Builder HAL HAL 3 1 HAL HAL HAL API DMA HAL alt_dev alt_dev typedef struct { alt_llist llist; /* */ const char* name; int (*open) (alt_fd* fd, const char* name, int flags, int mode); int (*close) (alt_fd* fd); int (*read) (alt_fd* fd, char* ptr, int len); int (*write) (alt_fd* fd, const char* ptr, int len); Altera Corporation 5 5 2004 12 Nios II
HAL int (*lseek) (alt_fd* fd, int ptr, int dir); int (*fstat) (alt_fd* fd, struct stat* buf); int (*ioctl) (alt_fd* fd, int req, void* arg); } alt_dev; HAL open() open() open() close() read() write() lseek() fstat() ioctl() 10 1 HAL API errno errno.h ioctl() errno ENOTTY ENOTTY errno HAL int alt_fd* alt_fd open() alt_fd typedef struct { alt_dev* dev; void* priv; int fd_flags; } alt_fd; dev fd_flags open() flags priv HAL 5 6 Altera Corporation Nios II 2004 12
HAL priv alt_dev NULL 5 1 5 1. alt_dev open close read write lseek fstat ioctl TIOCEXCL ioctl() open() close() read() write() lseek() ioctl() alt_dev llist name 2 llist ALT_LLIST_ENTRY name HAL system.h alt_dev HAL int alt_dev_reg (alt_dev* dev) Altera Corporation 5 7 2004 12 Nios II
HAL HAL API ANSI C (4 1 HAL )alt_dev HAL alt_dev 5 5 name read() write() fstat() int alt_fs_reg (alt_dev* dev) HAL HAL API ANSI C (4 1 HAL )alt_dev name 5 8 Altera Corporation Nios II 2004 12
HAL 4 1 HAL 1 1 ISR void alt_tick (void) alt_tick() int alt_sysclk_init (alt_u32 nticks) nticks 1 6 1 alt_timestamp_start() alt_timestamp() alt_timestamp_freq() 3 1 4 1 HAL 10 1 HAL API Altera Corporation 5 9 2004 12 Nios II
HAL sys/alt_flash_dev.h alt_flash_dev struct alt_flash_dev { alt_llist llist; // const char* name; alt_flash_open open; alt_flash_close close; alt_flash_write write; alt_flash_read read; alt_flash_get_flash_info get_info; alt_flash_erase_block erase_block; alt_flash_write_block write_block; void* base_addr; int length; int number_of_regions; flash_region region_info[alt_max_number_of_flash_regions]; }; llist ALT_LLIST_ENTRY name HAL system.h open write_block 8 API alt_flash_open_dev() alt_flash_close_dev() alt_flash_write() alt_write_flash() alt_read_flash() alt_get_flash_info() alt_erase_flash_block() alt_write_flash_block() 5 10 Altera Corporation Nios II 2004 12
HAL base_addr length number_of_regions region_info flash_region 4 14 CFI 2 alt_flash_dev HAL int alt_flash_device_register( alt_flash_fd* fd) DMA HAL DMA 2 DMA HAL DMA 4 20 DMA DMA sys/alt_dma_dev.h Altera Corporation 5 11 2004 12 Nios II
HAL DMA DMA alt_dma_txchan typedef struct alt_dma_txchan_dev_s alt_dma_txchan_dev; struct alt_dma_txchan_dev_s { alt_llist llist; const char* name; int (*space) (alt_dma_txchan dma); int (*send) (alt_dma_txchan dma, const void* from, alt_u32 len, alt_txchan_done* done, void* handle); int (*ioctl) (alt_dma_txchan dma, int req, void* arg); }; 5 2 5 2. alt_dma_txchan llist name space send ioctl ALT_LLIST_ENTRY alt_dma_txchan_open() name system.h alt_dma_txchan_dev API alt_dma_txchan_send() DMA alt_txchan_send() send() 10 20 alt_dma_txchan_send() I/O sys/alt_dma_dev.h space send ioctl null alt_dma_txchan_ioctl() ENOTTY alt_dma_txchan HAL int alt_dma_txchan_reg (alt_dma_txchan_dev* dev) dev 5 12 Altera Corporation Nios II 2004 12
HAL DMA DMA alt_dma_rxchan typedef alt_dma_rxchan_dev_s alt_dma_rxchan; struct alt_dma_rxchan_dev_s { alt_llist list; const char* name; alt_u32 depth; int (*prepare) (alt_dma_rxchan dma, void* data, alt_u32 len, alt_rxchan_done* done, void* handle); int (*ioctl) (alt_dma_rxchan dma, int req, void* arg); }; 5 3 5 3. alt_dma_rxchan llist name depth prepare ioctl ALT_LLIST_ENTRY alt_dma_rxchan_open() name system.h API alt_dma_rxchan_prepare() DMA alt_dma_rxchan_prepare() prepare() 10 14 alt_dma_rxchan_prepare() I/O sys/alt_dma_dev.h prepare() ioctl null alt_dma_rxchan_ioctl() ENOTTY Altera Corporation 5 13 2004 12 Nios II
HAL alt_dma_rxchan HAL int alt_dma_rxchan_reg (alt_dma_rxchan_dev* dev) dev HAL MicroC/OS-II IP lwip TCP/IP lwip 9 1 Lightweight IP SMSC lan91c111 MAC lwip lwip lwip www.sics.se/~adam/lwip/doc/lwip.pdf lan91c111 src inc <Nios II >/components/altera_avalon_lan91c111/ucosii/ Nios II <lwip >/UCOSII/inc/alt_lwip_dev.h 5 14 Altera Corporation Nios II 2004 12
HAL alt_lwip_dev_list alt_lwip_dev_list typedef struct { alt_llist llist; /* */ alt_lwip_dev dev; } alt_lwip_dev_list; struct alt_lwip_dev { /* netif */ struct netif* netif; const char* name; err_t (*init_routine)(struct netif*); void (*rx_routine)(); }; name system.h lwip netif netif <lwip >/UCOSII/src/downloads/lwip-0.7.2/src/include/lwip netif.h netif MAC IP MAC init_routine() alt_lwip_dev init_routine netif err_t init_routine(struct netif* netif) Altera Corporation 5 15 2004 12 Nios II
HAL init_routine() get_mac_addr() get_ip_addr() MAC IP netif 9 1 Lightweight IP init_routine() output() linkoutput() init_routine() output() link_output() 2 netif link_output() link_output() link_output(struct netif *netif, struct pbuf *p) link_output() IP IP MAC ARP link_output() link_output() output(struct netif *netif, struct pbuf *p, struct ip_addr *ipaddr) rx_routine() alt_lwip_dev rx_routine TCP/IP IRQ ISR rx_mbox <lwip >/UCOSII/src/alt_lwip_dev.c rx_thread rx_mbox rx_routine() rx_routine() TCP/IP 5 16 Altera Corporation Nios II 2004 12
HAL void rx_func() HAL HAL HAL HAL HAL HAL SOPC Builder 5 3 JTAG UART 5-1 JTAG UART <Nios II >/components 5-1. HAL altera_avalon_jtag_uart HAL HAL HAL inc src inc HAL HAL Altera Corporation 5 17 2004 12 Nios II
HAL HAL alt_sys_init.c HAL alt_sys_init.c alt_sys_init.c HAL alt_sys_init() main() alt_sys_init.c alt_sys_init.c #include "system.h" #include "sys/alt_sys_init.h" /* * */ #include "altera_avalon_timer.h" #include "altera_avalon_uart.h" /* * */ ALTERA_AVALON_UART_INSTANCE( UART1, uart1 ); ALTERA_AVALON_TIMER_INSTANCE( SYSCLK, sysclk ); /* * */ void alt_sys_init( void ) { ALTERA_AVALON_UART_INIT( UART1, uart1 ); ALTERA_AVALON_TIMER_INIT( SYSCLK, sysclk ); } Nios II IDE SOPC Builder alt_sys_init.c Nios II IDE gtf-generate alt_sys_init.c gtf-generate HAL gtf-generate 5 18 Altera Corporation Nios II 2004 12
HAL HAL/inc SOPC Builder JATG UART altera_avalon_jtag_uart/hal/inc/altera_avalon_jtag_uart.h alt_sys_init.c 5 18 alt_sys_init.c /* */ < >_INSTANCE 5 18 alt_sys_init.c /* */ alt_sys_init() < >_INIT 5 18 alt_sys_init.c /* */ *_INSTANCE *_INIT altera_avalon_jtag_uart.h ALTERA_AVALON_JTAG_UART_INSTANCE ALTERA_AVALON_JGAT_UART_INIT *_INSTANCE *_INIT 2 2 SOPC Builder system.h system.h alt_sys_init.c Altera Corporation 5 19 2004 12 Nios II
HAL SOPC Builder HAL/inc/<component_name>.h <COMPONENT_NAME>_INSTANCE <COMPONENT_NAME>_INIT HAL main() 5 18 HAL alt_sys_init.c HAL/src makefile component.mk component.mk JTAG UART makefile component.mk makefile C_LIB_SRCS += altera_avalon_uart.c ASM_LIB_SRCS += INCLUDE_PATH += 5 20 Altera Corporation Nios II 2004 12
HAL Nios II IDE component.mk makefilecomponent.mk make C_LIB_SRCS ASM_LIB_SRCS INCLUDE_PATH 5 4 5 4. component.mk make make C_LIB_SRCS ASM_LIB_SRCS INCLUDE_PATH C C <component>/hal/inc component.mk make 5 22 HAL *_INSTANCE *_INIT HAL/inc HAL/src makefile component.mk HAL/src Altera Corporation 5 21 2004 12 Nios II
HAL ALT_USE_SMALL_DRIVERS C Nios II IDE ALT_USE_SMALL_DRIVERS ALT_USE_SMALL_DRIVERS ALT_USE_SMALL_DRIVERS SOPC Builder SOPC Builder alt_ altera_avalon_jtag_uart altera_avalon_jtag_uart_init() alt_jtag_uart_init() avalon_jtag_uart_init() jtag_uart_init() 5 22 Altera Corporation Nios II 2004 12
HAL SOPC Builder HAL 5 17 HAL Nios II IDE Nios II IDE alt_my_component.h alt_my_component.h C Altera Corporation 5 23 2004 12 Nios II
5 24 Altera Corporation Nios II 2004 12