SOPC的FIFO核 - NIOS中FIFO的控制函数

来源:互联网 发布:剪辑一分钟多少钱 知乎 编辑:程序博客网 时间:2024/04/27 16:29

#include "altera_avalon_fifo_regs.h"#include "altera_avalon_fifo_util.h"#include "system.h"#include "sys/alt_irq.h"#include <stdio.h>#include <stdlib.h>#define ALMOST_EMPTY 2#define ALMOST_FULL FIFO_MEM_IN_FIFO_DEPTH-5volatile int input_fifo_wrclk_irq_event;void main(){ int i,j;int return_code;long int data[200];int level;//初始化FIFO数据return_code = altera_avalon_fifo_init(FIFO_MEM_IN_CSR_BASE,0, // Disabled interruptsALMOST_EMPTY,ALMOST_FULL); //写入FIFO数据for(i=1;i<128;i++)altera_avalon_fifo_write_fifo(FIFO_MEM_IN_BASE,FIFO_MEM_IN_CSR_BASE,i);//读取FIFO数据for(i=0;i<=200;i++)data[i] = altera_avalon_fifo_read_fifo(FIFO_MEM_OUT_BASE,FIFO_MEM_OUT_CSR_BASE);for(i=0;i<=100;i++)printf("data_%d=%lu\t",i,data[i]);//Gets the fill level of the FIFO:输出FIFO中还存有多少个数据level=altera_avalon_fifo_read_level(FIFO_MEM_OUT_CSR_BASE);printf("\nlevel=%u\n",level);//这两个函数只返回了最大地址和最小个数printf("full=%d", altera_avalon_fifo_read_almostfull(FIFO_MEM_OUT_CSR_BASE));printf("empty=%d",altera_avalon_fifo_read_almostempty(FIFO_MEM_OUT_CSR_BASE));}



FIFO函数说明

On-Chip FIFO Memory API
This section describes the application programming interface (API) for the on-chip
FIFO memory core.

1. altera_avalon_fifo_init()
Prototype: int altera_avalon_fifo_init(alt_u32 address, alt_u32 ienable,
alt_u32 emptymark, alt_u32 fullmark)

Include: <altera_avalon_fifo_regs.h>, <altera_avalon_fifo_utils.h>

Parameters: address—the base address of the FIFO control slave
ienable—the value to write to the interruptenable register
emptymark—the value for the almost empty threshold level
fullmark—the value for the almost full threshold level

Returns: Returns 0 (ALTERA_AVALON_FIFO_OK) if successful,
ALTERA_AVALON_FIFO_EVENT_CLEAR_ERROR for clear errors,
ALTERA_AVALON_FIFO_IENABLE_WRITE_ERROR for interrupt enable write errors,
ALTERA_AVALON_FIFO_THRESHOLD_WRITE_ERROR for errors writing the almostfull
and almostempty registers.

Description: Clears the event register, writes the interruptenable register, and sets the almostfull register and almostempty registers.

2.altera_avalon_fifo_read_level()
3. altera_avalon_fifo_clear_event()

Prototype: int altera_avalon_fifo_read_level(alt_u32 address)
Parameters: address—the base address of the FIFO control slave
Returns: Returns the fill level of the FIFO.
Description: Gets the fill level of the FIFO.

Prototype: int altera_avalon_fifo_clear_event(alt_u32 address, alt_u32 mask)

mask—the mask to use for bit-clearing (1 means clear this bit, 0 means do not clear)
Returns: Returns 0 (ALTERA_AVALON_FIFO_OK) if successful,
ALTERA_AVALON_FIFO_EVENT_CLEAR_ERROR if unsuccessful.
Description: Clears the specified bits of the event register.

4.altera_avalon_write_fifo()
Prototype: int altera_avalon_write_fifo(alt_u32 write_address, alt_u32
ctrl_address, alt_u32 data)
Include: <altera_avalon_fifo_regs.h>, <altera_avalon_fifo_utils.h>
Parameters: write_address—the base address of the FIFO write slave
ctrl_address—the base address of the FIFO control slave
data—the value to write to address offset 0 for Avalon-MM to Avalon-ST transfers, the value to write to the single address available for Avalon-MM to Avalon-MM transfers. See the AvalonInterfaceSpecifications for the data ordering.

Returns: Returns 0 (ALTERA_AVALON_FIFO_OK) if successful, ALTERA_AVALON_FIFO_FULL if
unsuccessful.
Description: Writes data to the specified address if the FIFO is not full.

5. altera_avalon_fifo_read_fifo()
Prototype: int altera_avalon_fifo_read_fifo(alt_u32 read_address, alt_u32
ctrl_address)
Thread-safe: No.
Available from ISR: No.
Include: <altera_avalon_fifo_regs.h>, <altera_avalon_fifo_utils.h>
Parameters: read_address—the base address of the FIFO read slave
ctrl_address—the base address of the FIFO control slave
Returns: Returns the data from address offset 0, or 0 if the FIFO is empty.
Description: Gets the data addressed by read_address.
更多的参考《Embedded Peripherals IP User Guide》

0 0
原创粉丝点击