新建项目
This commit is contained in:
1 parent
5e2e890cfc
commit
633d9b872b
1351 files changed
+730564
No files matched your search
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* @Author: zhangpeng
|
||||
* @Date: 2020-03-05 18:28:21
|
||||
* @LastEditTime: 2020-03-05 20:02:45
|
||||
* @LastEditors: zhangpeng
|
||||
* @Description: New File
|
||||
* @FilePath: \Firmware\user\fifo.c
|
||||
* @Copyright (c) 2019-2021 ZhangYeJinZhi.Co.Ltd. All rights reserved.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @function: Fifo_Read
|
||||
* @description: 从数据队列里面读取一帧数据
|
||||
* @param {type}
|
||||
* @return:
|
||||
* @Author: zhangpeng
|
||||
* @LastEditTime: Do not edit
|
||||
*/
|
||||
#include "fifo-board.h"
|
||||
|
||||
/**
|
||||
* @function: Fifo_Read
|
||||
* @description: 从数据队列里面读取一帧数据
|
||||
* @param fifo: 队列指针
|
||||
* @param buf: 读取数据的缓存
|
||||
* @return:
|
||||
* @Author: zhangpeng
|
||||
*/
|
||||
int FifoRead(Fifo_p fifo, char *buf, int length)
|
||||
{
|
||||
if (fifo->count == 0)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
fifo->count--;
|
||||
// *length = fifo->data[fifo->read].length;
|
||||
memcpy(buf, fifo->data + fifo->read * length, length);
|
||||
fifo->read++;
|
||||
if (fifo->read >= fifo->max_count)
|
||||
fifo->read = 0;
|
||||
return 0; //数据读取成功
|
||||
}
|
||||
|
||||
/**
|
||||
* @function: Fifo_Read
|
||||
* @description: 从数据队列里面读取一帧数据
|
||||
* @param fifo: 队列指针
|
||||
* @param buf: 读取数据的缓存
|
||||
* @return:
|
||||
* @Author: zhangpeng
|
||||
*/
|
||||
int FifoWrite(Fifo_p fifo, char *buf, int length) //
|
||||
{
|
||||
if (fifo->data == NULL)
|
||||
return -1;
|
||||
if (fifo->count == fifo->max_count)
|
||||
{ // 满
|
||||
return -1;
|
||||
}
|
||||
fifo->count++;
|
||||
// fifo->data[fifo->write].length = length;
|
||||
memcpy(fifo->data + fifo->write * length, buf, length);
|
||||
fifo->write++;
|
||||
if (fifo->write >= fifo->max_count)
|
||||
fifo->write = 0;
|
||||
return 0; //数据读取成功
|
||||
}
|
||||
/*清空缓冲区*/
|
||||
void FifoInit(Fifo_p fifo, char *data, int max)
|
||||
{
|
||||
fifo->read = 0;
|
||||
fifo->write = 0;
|
||||
fifo->count = 0;
|
||||
fifo->data = data;
|
||||
fifo->max_count = max;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user