总结:niosii中pio口的设定及端口操作的补充说明_第1页
总结:niosii中pio口的设定及端口操作的补充说明_第2页
总结:niosii中pio口的设定及端口操作的补充说明_第3页
总结:niosii中pio口的设定及端口操作的补充说明_第4页
总结:niosii中pio口的设定及端口操作的补充说明_第5页
已阅读5页,还剩11页未读 继续免费阅读

付费下载

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、总结: nios ii 中 pio口的设定及端口操作的补充说明3 种:输入、输出、双向(三态)。在输入 函数操作,或者直接对其地址操作, 如: 有NIOS II 中 PIO 口的设定常用的有 或输出模式下直接对使用 iord/iowr 一 PIO 口(名称设定为“ LED ,1BIT. o) define LED *(unsigned int *)LED_BASEIOWR_ALTERA_AVALON_PIO_DATA(LCD_RESET_BASE,OX使);P/O LED输出为 0 或者 IOWR(LED_BASE,O,O); / 使 PIO LED输出为 0在双向( bidirectiona

2、l 系统复位後其默认状态下为输 对其进行读取。或者LED=0x0 / 使PIO LED输出为0,此种方法在有数据 CACHED会失效)模式下,要对 pio 先设定输入输出方向,但是 nios若需要使 PIO LED 输出,则需要先设定其为输出 一直到方向寄存器再次被改变为止 。方向寄存器入的状态,此寸不需要设定方向寄存器就可以直接 例如:有一双向口 PIO LED , 状态,且这种状态会一直保持, 位于 PIO 地址 偏移量 1 的位置,对其地址偏移量为 1 的寄存器写入 1,(偏移 量决定写入的数据对应何种 目的/所起作用 ,偏移量“ 1 ”对应方向寄存器, 此 寸写入的数据“ 1”决定端口

3、方向为输出;“ 0”则对应着输入) 例如: define LED *(unsigned int *)LED_BASEIOWR(LED_BASE,1,0); / 设定 PIO 方向为输入IORD(LED_BASE,0) ; / 读取 PIO LED 值 或者 IORD_ALTERA_AVALON_PIO_DATA(LED)读取 PIO LED值又或者: x= LED; “ / 读取 PIO LED 值至 寄存器“ x” 。同样地,此种方法 在有数据CACHE寸会失效 注意:上面所列PIO皆为1位。多位的情况:举例 8 位 pio LEDIOWR(LED_BASE,1,0xF0); /PIO 高

4、4位为输出,低 4位为输入Tabts U-2. Rsgtslst M即 hrth PtO CarsOfisetRegister MaineR/W(n-1)21a0dataread acc*s&RmiQ value currently on PIO jnpuUwite aajs55WNew value to drive on; PEO outputs1direct Lon if I;R/WIndiMduai direction oortrol lor ?ach iro poH A vak)& of o Gt9 the direction to input i m他 the drection to

5、 output.2intexrkip-tmask UjRAVITO erabledisable tor each input port. S日ttinq a bit to 1 pnflblos jniprrupts tnr ttio coirpsporulirtg port3edge ciptur & ,fJ i;岛FVWkdgo dotocton for oacti input portXWts ta Ytfbh 11 2id) This icg|Qt?j itijy not exist, dqxxidinx on the hLiiJvbflrv connLiEatiiMi. If ivLt

6、tvi is no I p icsciiLtheRylbtut ittur b ui uiidliiitd v(iJut Jiu 迸hKtPIO core LiArdwAio is cciiiijvivd in output-unJy tuodc, icadiiig from data 11 unJefineiJ 謝叱Wtitiiig to da t a sfoiiss: tJiQ3 rgistr tha 14riv& th? oitpiit ports11-7If th? pro cocv hrdwaie is configured in inpiit-oaly incde writing

7、to dati has ni effect If the PC coo? hardware is in bidirectioiul mcndc; the it?ghtprfd w】wppvdrsuiwnnu(puTpL)TMniy 找 lu*n rht? tn! rehporiL.h!iy bit; in the direct ion retei is wet to 1 (output).Altera Cotporotion May 200e端口操作的补充说明 若:#define LED *(unsigned int *) LED_BASE那么:IOWR_ALTERA_AVALO N_P IO

8、_DATA(LED_BASE,OxOO); 和LCD_RESET=0x(有啥区别?哪个效率高些?edacn的luyeallen ”网友的解答: 编译后是不一样的。lOWR的操作编译后的汇编指令 STWIO是直接10操作,不经过数据CACHE而指 针操作编译后是STVy经过数据CACHE我自己用的情况是用指针对I0操作在有 数据CACHE勺情况下会失效,我用的版本比较老,5.1的,不知道后面的版本是 否这样。经测试发现 6.0+sp2 版本问题同上,现在看来在使用数据 cache 的情况下LED=OxO这种写法是行不通的!(offset lJ lU F M 申M / 20 诊 2directio

9、n RegisterThe direct ion register controls the data direction for each PIO port assuming the port is bidirectional. When bit it in direction is set to 1, port n drives out the value in the corresponding bit of the data register.orThe? direction register only exists when the PIO core hardware is conf

10、igured in bidirectional mode. Tlie mode (input, output bidirectional) is specified at system generation tim巳 and cannot be changed at runtime. In input-only or output-only mode, the direction register does not exist In this case, reading direction returns an undefined value,writing direction has no

11、effect.After reset, all bits of directioai are 0, so that all bidirectionall/O ports are configured as inputs, f those PIO ports are connected to device piiis, the pins are held in a high-itnpeddnee erruptmask RegisterSetting a bit in the interruptmask register to 1 enables biterrupts for t

12、he corresponding PIO input port. Interrupt behavior depends on the hardware configuration of the PIO core. See Internipt Behavioron page 11一9The interruptmask register only exists when the hardware is configured to generate IRQs. If the core cannot generate IRQs, read big interr up tniask returns an

13、 undefined value, and writing to interruptmask has no effectAfter reseC all bits of interruptmask arc zero, so that interrupts are disabled for all PIQ ports.edgecapture RegisterBit w in the edgecapture register is set to 1 whenever an edge is detected on input port il An Avalon master peripheral ca

14、n read the edgecapture register to determine if an edge has occurred on any of the PIO input ports. Writing any value to edge capture clears all bits in the registerThe type of edgefs) to detect is ftxed in hardware at system generation time. The edgecapture register only exists when the hardware is

15、 vonfigxired toa pture edges. If the core is not configured to capture edges reading from edgecapture returns an undefined value,日nd writing to edgecapture has no effect./NIOS II 常用函数整理 感谢 slam 原创 偏移量决定写入的数据对应何种(目的 / 所起作用)IO 操作函数函数原型: IORD(BASE, REGNUM)输入参数:base为寄存器的基地址,REGNU为寄存器的偏移量函数说明:从基地址为base的设

16、备中读取寄存器中偏移量为 REGNUM单元里面 的值。寄存器的值在地址总线的范围之内。返回值: 函数原型: IOWR(BASE, REGNUM, DATA)输入参数:base为寄存器的基地址,REGNUM寄存器的偏移量,data为要写入 的数据函数说明:往偏移量为REGNU寄存器中写入数据。寄存器的值在地址总线的范 围之内。返回值: 转帖注)base为寄存器的基地址,offsets寄存器的的偏移量 从地址位置为 BASE+OFFSEJJ寄存器中直接读取32Bit的数据函数原型:IORD_32DIRECT(BASE, OFFSET注意:类似 IOxx_xDIRECT 的这几 函数好像现在并不被支

17、持,请了解的兄弟留言告知 输入参数: 函数说明:返回值:IORD_16DIRECT(BASE, OFFSET)base为寄存器的基地址,offsets寄存器的的偏移量函数原型:输入参数:函数原型 输入参数 函数说明 返回值:函数原型: 输入参数: 的数据 函数说明: 返回值:函数说明:从地址位置为BASE+OFFSE的寄存器中直接读取16Bit的数据 返回值: IORD_8DIRECT(BASE, OFFSET)base为寄存器的基地址,offsets寄存器的的偏移量从地址位置为BASE+OFFSETJ寄存器中直接读取8Bit的数据IOWR_32DIRECT(BASE, OFFSET, DAT

18、A)base为寄存器的基地址,REGNUM寄存器的偏移量,data为要写入往地址位置为BASE+OFFSET寄存器中直接写入32Bit的数据函数原型: 输入参数: 的数据 函数说明: 返回值:IOWR_16DIRECT(BASE, OFFSET, DATA)base为寄存器的基地址,REGNUM寄存器的偏移量,DATA为要写入往地址位置为BASE+OFFSET寄存器中直接写入16Bit的数据 函数原型:输入参数:的数据函数说明:往地址位置为BASE+OFFSE的寄存器中直接写入8Bit的数据 返回值: IOWR_8DIRECT(BASE, OFFSET, DATA)base为寄存器的基地址,R

19、EGNUM寄存器的偏移量,DATA为要写入Dma:函数原型 输入参数 函数说明 接收信道 返回值:intalt_dma_rxchan_close (alt_dma_rxchanrxchan)rxchan 为接收信道函数 alt_dma_rxchan_close () 通知系统:应用程序已经完成 DMArxchan ,目前执行是成功的成功返回为 0,反之为 1函数原型:输入参数:函数说明: 度)的接收请求alt_dma_rxchan_depth(alt_dma_rxchandma) dma函数 alt_dma_rxchan_depth () 返回传送到特别 返回值:DMA的最大数量函数原型: 输

20、入参数: 函数说明: 返回值: 请求类型 请求类型intalt_dma_rxchan_ioctl (alt_dma_rxchandma, dma直接存储器名,req为请求操作的列举,arg 通过DMA接收信道执行设备的具体I/O操作 成功返回请求具体值,反之返回为负数DMA勺最大数量(深intreq, void* arg) 由请求决定请求类型说明ALT_DMA_SET_MODE传输以8Bit为单位的数据,arg值忽略ALT_DMA_SET_MODE传输以16Bit为单位的数据,arg值忽略 ALT_DMA_SET_MODE_传输以32Bit为单位的数据,arg值忽略 ALT_DMA_SET_M

21、ODE传输以64Bit为单位的数据,arg值忽略 ALT_DMA_SET_MODEJ传输以128Bit为单位的数据,arg值忽略 ALT_DMA_TX_ONLY_ON (软1 )件控制下只能发送ALT_DMA_TX_ONLY_OFF (1自) 定义模式,软件控制下可以接收,发送 ALT_DMA_RX_ONLY_ON (软1)件控制下只能接收ALT_DMA_RX_ONLY_OFF (自1)定义模式,软件控制下可以接收,发送函数原型: alt_dma_rxchanalt_dma_rxchan_open (const char* name)输入参数:name为常数字符指针,如/dev/dma_0函数

22、说明:为DMA接收信道获得一个alt_dma_rxchan描述符 返回值: 成功返回非 0,反之返回为 0发送一个接收请求到 DMA接收信道,成功返回 0,反之返回为负数函数原型: intalt_dma_rxchan_prepare (alt_dma_rxchandma, void* data, alt_u32 length, alt_rxchan_done * done, void* handle) 输入参数:dma使用的信道;data接收数据位置的指针;length最大的接收数 据长度;done 旦数据被接收,调用返回函数;handle,非透明值传到done 函数说明: 返回值:函数原型

23、输入参数 函数说明 返回值:函数原型: 输入参数: 函数说明: 返回值:intalt_dma_rxchan_reg (alt_dma_rxchan_dev * dev) dev 接收信道设备名给系统寄存DMA接收信道成功返回 0,反之返回为负数 intalt_dma_txchan_close (alt_dma_txchantxchan)txchan 发送信道名通知系统:应用程序已经完成DMA发送信道txchan成功返回0,反之返回为负数函数原型: 输入参数: 由请求决定 函数说明: 返回值:intalt_dma_txchan_ioctl (alt_dma_txchandma, intreq,

24、void* arg) dma直接存储器名;req为请求操作的列举;arg请求的额外参数,通过DMA发送信道执行设备的具体I/O操作成功返回请求具体值,反之返回为负数alt_dma_txchanalt_dma_txchan_open (const char* name)name为常数字符指针,如/dev/dma_O函数原型:输入参数:成功返回非 0,反之返回为 0函数说明:为DMA发送信道获得一个alt_dma_rxchan描述符 返回值:函数原型 输入参数 函数说明 返回值:intalt_dma_txchan_reg (alt_dma_txchan_dev* dev) dev 接收信道设备名给

25、系统寄存DMA发送信道成功返回 0,反之返回为负数intalt_dma_txchan_send (alt_dma_txchandma, const void* from,函数原型:alt_u32 length, alt_txchan_done* done, void* handle)发送一个发送请求到 DMA发送信道,发送成功返回 0,反之返回为负数输入参数:dma使用的信道;data接收数据位置的指针;length最大的接收数 据长度;done 旦数据被接收,调用返回函数;handle,非透明值传到done 函数说明: 返回值:函数原型:输入参数:ntalt_dma_txchan_space

26、 (alt_dma_txchandma) dma 直接存储器名函数说明:返回值:Flash函数原型:length)输入参数:擦除的 flash 模块的长度 函数说明:擦除单独的一个 flash 模块 返回值:intalt_erase_flash_block(alt_flash_fd* fd, int offset, intfd为具体的flash设备;offset擦除的flash 模块的偏移量;length发送成功返回 0,反之返回为负数函数原型 输入参数 函数说明 返回值:void alt_flash_close_dev(alt_flash_fd * fd) fd 为具体的 flash 设备关

27、闭 flash 设备函数原型 输入参数 函数说明 数 alt_read_flash() 用来读取数据,或者使用函数 alt_erase_flash_block(), alt_write_flash_block(), 返回值: 失败返回 0,成功其他值alt_flash_fd * alt_flash_open_dev(const char* name)打开 flash 设备。一旦打开,函数 alt_write_flash() 用来写入,函alt_get_flash_info(), 控制单个模块函数原型: intalt_get_flash_info(alt_flash_fd* int* numbe

28、r_of_regions) 输入参数: fd flash 设备; number_of_regions 函数说明:得到擦除 flash 返回值: 发送成功返回 0,fd, flash_region * info,info 指向 flash_region区域的细节 反之返回为负数结构体的指针;返回被传送到具体DMA发送信道的发送请求数目 返回发送请求数目函数原型: intalt_read_flash(alt_flash_fd* fd, int offset, void* dest_addr, int length)输入参数: dest_addr 目标地址指针成功返回 0,反之为非 0intalt_

29、write_flash(alt_flash_fd* fd, int offset, const void*函数说明:从 flash 偏移量为 offset 字节开始读取数据,写入到目标地址 dest_addr 中 返回值:函数原型: src_addr, int length)src_addr 源地址; fd ,flash 设备; offset 偏移量; length 字节长输入参数: 度写数据到 flsah 中,要写的数据在源地址 src_addr 中成功返回 0,反之为非 0函数说明: 返回值:函数原型: intalt_write_flash_block(alt_flash_fd* fd,

30、intblock_offset, intdata_offset,const void *data, int length)输入参数: fd ; data_offset 起始写数据的偏移量; length 为要写数据的长度 函数说明:写入到一个已擦除的 flash 模块 返回值:成功返回 0,反之为非 0Irq 函数原型 输入参数 函数说明 返回值:alt_irq_contextalt_irq_disable_all (void)void禁止所有中断传递的值作为随后的函数调用的输入参数函数原型:输入参数: 函数说明:启动所有中断 返回值: void alt_irq_enable_all (alt

31、_irq_context context) 先前调用函数 alt_irq_disable_all (void) 的返回值,函数原型: intalt_irq_enabled (void) 输入参数: void 函数说明:启动中断返回值: 禁止中断返回 0,反之为非 0函数原型: intalt_irq_register (alt_u32 id, void* context, void (*isr)(void*, alt_u32)输入参数:id,32位无符号数,中断使能;con text和id是isr的两个输入参数; 中断激活时调用 isr寄存一个 isr成功返回 0,反之为非 0函数原型: src

32、_addr, int length) 输入参数: 度函数说明: 返回值:intalt_write_flash(alt_flash_fd* fd, int offset, const void*src_addr 源地址; fd ,flash 设备; offset 偏移量; length 字节长写数据到 flsah 中,要写的数据在源地址 src_addr 中成功返回 0,反之为非 0函数说明: 返回值:intalt_write_flash_block(alt_flash_fd* fd, intblock_offset,函数原型: intdata_offset, const void *data,

33、 int length)输入参数: fd ; data_offset 起始写数据的偏移量; length 为要写数据的长度成功返回 0,反之为非 0函数说明:写入到一个已擦除的 flash 模块 返回值:函数原型: 输入参数: 函数说明: 返回值:int close (intfiledes) filedes ,描述符int open (const char* pathname, int flags, mode_t mode)path name,路径名;flags,O_RDONLY或 O_WRONLS O_RDW分别对 只写,或读写操作;mode 用许可说明标准的UNIX函数closeO,关闭文

34、件描述符filedes 成功返回 0,反之为 1成功返回文件描述符,反之返回 1函数原型: 输入参数: 位为字节 函数说明:从文件或设备中读取数据块 返回值:函数原型: 输入参数: 应着只读, 函数说明:打开文件或设备,返回一个文件描述符(读写中使用的非负整数) 返回值:int read(int file, void *ptr, size_tlen)成功返回读取的字节数,反之返回 1file 文件描述符; ptr 为读数据的位置指针, len 读数据的长度,单clock_t times (structtms *buf)buf 结构体指针兼容 newlib ,tms 的结构体指针如下:函数原型:

35、输入参数:函数说明:type structclock_ttms_utime; clock_ttms_stime;clock_ttms_cutime;clock_ttms_sutime;tms_utime : CPU索取用户指令的执行时间 tms_stime : CPU索取由系统表示的过程的执行时间返回时钟数,没有时钟则返回 0函数原型: 输入参数: 函数说明: 返回值:函数原型 输入参数 函数说明 返回tms_cutime :所有子进程 tms_utime 和 tms_cutime 的时间之和 tms_sutime :所有子进程 tms_stime 和 tms_sutime 的时间之和 返回值

36、:intusleep (int us)us, 单位为微秒直到us微秒后才解除阻塞,即其功能相当于延时 us微秒 成功返回 0,反之为 1,有错误发生显示错误发生原因int wait(int *status) status 进程状态指针功能是等候所有子进程退出,由于HAL不支持分散子进程,函数立即返回值:status内容清0,表明没有子进程;返回值为一1且errno置为ECHILD 表明没有子进程等候 函数原型: int write(int file, const void *ptr, size_tlen)输入参数: file 文件描述符; ptr 为读数据的位置指针, len 读数据的长度,单

37、 位为字节函数说明:往文件或设备写入数据块,返回值: 成功返回写入的字节数,也可能少于请求的长度;反之返回1,万一有错误发生, errno 被设置为发生的原因号 8 位整数 无符号 8 位整数 符号 16 位整数无符号 16 位整数 符号 32 位整数无符号 32 位整数数据的标准类型 类型 说明 alt_8 符alt_u8alt_16 alt_u16alt_32alt_u32下面为自己整理 函数原型: intfopen (char * file_name, way_use);打不开则出错,返回一个空指针 NULL输入参数:file_name文件名,way_use使用文件方式,比如r ,w分别

38、对应着读 写 函数说明:打开文件,对其进行某种文件操作 返回值:函数原型 输入参数 函数说明 返回值:intfclose (fp)fp 的定义为: FILE *fp 关闭文件 fp函数原型:输入参数:字节数地数目; fp 文件型指针 函数说明:从一个流中读取数据 返回值:成功返回 0,反之为 1(EOF) intfread(void *ptr, int size, int count, FILE * fp);成功返回值为 count函数原型:输入参数:字节数地数目; fp 文件型指针, 函数说明:写内容到流中 返回值: 成功返回值为 countbuffer 为指针;是读入数据地存放地址; si

39、ze 读字节数; count 读intfwrite(void *ptr, int size, int count, FILE *fp)buffer 为指针;是读入数据地存放地址; size 读字节数; count 读intfprintf(FILE *fp, char *format, argument,.); fp 文件型指针; format 格式字符串; , argument,.函数原型: 输入参数: 如: fprint f(fp, 函数说明:传送格式化输出到一个流中 返回值: %d,%f”,i,t)函数原型: 输入参数: 如: fscanf(fp, 函数说明:从一个流中执行格式化输入 返回

40、值: intfscanf(FILE * fp, char *format,argument.) fp 文件型指针; format 格式字符串; , argument,.%d,%f”,i,t)输出列表 ,输入列表,函数原型: 输入参数: 函数说明: 返回值:intfputc(intch, FILE *fp)ch字符;fp :文件型指针送一个字符到一个流中 成功返回字符,反之返回 1(EOF)函数原型:输入参数: 函数说明:从流中读取字符 返回值:intfgetc(FILE *fp); fp :文件型指针遇到文件结束返回 1(EOF)函数原型 输入参数 函数说明 返回值:intputw(int w

41、, FILE *fp) w: 字符或字 ; fp :文件型指针 把一字符或字送到流中函数原型 输入参数 函数说明 返回值:intgetw(FILE *fp) fp :文件型指针 从流中取一整数函数原型: 输入参数: 函数说明:将文件指针重新指向一个流的开头 返回值: int rewind(FILE *fp) fp :文件型指针函数原型: intfseek(FILE *fp, long offset, intfromwhere);输入参数:fp :文件型指针;offset : long型偏移量;fromwhere:起始点起始点为 0,1,2 分别代表文件开始,当前位置,文件末尾 函数说明:重定位

42、流上的文件指针返回值: 函数原型: intferror(FILE *fp) 输入参数: fp :文件型指针 函数说明:检测流上的错误 返回值:未出错返回值为 0,反之为非 0函数原型 输入参数 函数说明 返回值:long ftell(FILE *fp)fp :文件型指针 返回当前文件指针,得到当前位置 返回值为 1 表示出错,反之为非 0函数原型 输入参数 函数说明 返回值:void clearerr(FILE *fp) fp :文件型指针 复位错误标志 出错为非 0,反之为 0函数原型: 输入参数: 函数说明:从流中读取一字符串, 但只从文件输入 n1 个字符,后一个为 0 结束标志位 返回值: char *fgets(char *string, int n, FILE *fp) string :字符串指针; fp :文件型指针函数原型 输入参数 函数说明 返回值:ntfputs(char *string, FILE *fp) string :字符串指针; fp :文件型指针 送一个字符串到一个流中函数原型 输入

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论