新建项目

This commit is contained in:
gitea committed 2023-04-29 09:09:12 +08:00
1 parent 5e2e890cfc
commit 633d9b872b
1351 files changed
+730564

No files matched your search

+40
View File
@@ -0,0 +1,40 @@
#pragma once
/*
* @Author: zhangpeng
* @Date: 2020-03-05 18:28:46
* @LastEditTime: 2020-03-05 20:11:27
* @LastEditors: zhangpeng
* @Description: New File
* @FilePath: \Firmware\user\fifo.h
* @Copyright (c) 2019-2021 ZhangYeJinZhi.Co.Ltd. All rights reserved.
*/
#ifndef _FIFO_H
#define _FIFO_H
#include <stdlib.h>
#include <string.h>
#define RECERIVRSIZE 6
typedef struct {
int length;
char data[256];
char type;
}data_t;
typedef struct {
int read;
int write;
int count;
char * data;
int max_count;// 最大多少个队列
}Fifo_t, *Fifo_p;
int FifoRead(Fifo_p fifo, char * buf, int length);
int FifoWrite(Fifo_p fifo, char *buf, int length);
void FifoInit(Fifo_p fifo, char * data, int max);
#endif/*_USARTBUF_H*/
+77
View File
@@ -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;
}