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

#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-5
volatile 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 interrupts
ALMOST_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
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值