Last active
June 16, 2016 02:56
-
-
Save matthewphilyaw/ff43c955c9fcecd29206154199bd500e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// common.h | |
// fifo | |
// | |
// Created by Matthew Philyaw on 6/15/16. | |
// Copyright © 2016 Matthew Philyaw. All rights reserved. | |
// | |
#ifndef common_h | |
#define common_h | |
// define the types that you want a fifo for | |
// and macros generate a set of functions for that type | |
#define FIFO_UINT8_T | |
#define FIFO_UINT32_T | |
#endif /* common_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "FIFO.h" | |
#include "common.h" | |
#define AccessBuffer(buffer, index, index_width) ((char *)(buffer))+((index) * (index_width)) | |
int FIFO_Init(FIFOBuffer_TypeDef *buf, uint32_t maxSize, uint32_t bufferWidth, void *buffer) { | |
if (!buffer) { | |
return -1; | |
} | |
buf->MaxSize = maxSize; | |
buf->CurrentSize = 0; | |
buf->WritePos = 0; | |
buf->ReadPos = 0; | |
buf->BufferWidth = bufferWidth; | |
buf->Buffer = buffer; | |
return 0; | |
} | |
int FIFO_Write(FIFOBuffer_TypeDef *buf, void(* setFun)(void*, void*), void *val) { | |
if (buf->CurrentSize >= buf->MaxSize) { | |
return -1; | |
} | |
void *addr = AccessBuffer(buf->Buffer, buf->WritePos, buf->BufferWidth); | |
setFun(addr, val); | |
buf->CurrentSize++; | |
buf->WritePos++; | |
if (buf->WritePos >= buf->MaxSize) { | |
buf->WritePos = 0; | |
} | |
return 0; | |
} | |
int FIFO_Read(FIFOBuffer_TypeDef *buf, void(* getFun)(void*, void*), void *ret) { | |
if (buf->CurrentSize <= 0) { | |
return -1; | |
} | |
void *addr = AccessBuffer(buf->Buffer, buf->ReadPos, buf->BufferWidth); | |
getFun(addr, ret); | |
buf->CurrentSize--; | |
buf->ReadPos++; | |
if (buf->ReadPos >= buf->MaxSize) { | |
buf->ReadPos = 0; | |
} | |
return 0; | |
} | |
#ifdef FIFO_INT8_T | |
CREATE_FIFO_SETTER_PAIR(int8_t); | |
#endif | |
#ifdef FIFO_INT16_T | |
CREATE_FIFO_SETTER_PAIR(int16_t); | |
#endif | |
#ifdef FIFO_INT32_T | |
CREATE_FIFO_SETTER_PAIR(int32_t); | |
#endif | |
#ifdef FIFO_INT64_T | |
CREATE_FIFO_SETTER_PAIR(int64_t); | |
#endif | |
#ifdef FIFO_UINT8_T | |
CREATE_FIFO_SETTER_PAIR(uint8_t); | |
#endif | |
#ifdef FIFO_UINT16_T | |
CREATE_FIFO_SETTER_PAIR(uint16_t); | |
#endif | |
#ifdef FIFO_UINT32_T | |
CREATE_FIFO_SETTER_PAIR(uint32_t); | |
#endif | |
#ifdef FIFO_UINT64_T | |
CREATE_FIFO_SETTER_PAIR(uint64_t); | |
#endif | |
#ifdef FIFO_INT_LEAST8_T | |
CREATE_FIFO_SETTER_PAIR(int_least8_t); | |
#endif | |
#ifdef FIFO_INT_LEAST16_T | |
CREATE_FIFO_SETTER_PAIR(int_least16_t); | |
#endif | |
#ifdef FIFO_INT_LEAST32_T | |
CREATE_FIFO_SETTER_PAIR(int_least32_t); | |
#endif | |
#ifdef FIFO_INT_LEAST64_T | |
CREATE_FIFO_SETTER_PAIR(int_least64_t); | |
#endif | |
#ifdef FIFO_UINT_LEAST8_T | |
CREATE_FIFO_SETTER_PAIR(uint_least8_t); | |
#endif | |
#ifdef FIFO_UINT_LEAST16_T | |
CREATE_FIFO_SETTER_PAIR(uint_least16_t); | |
#endif | |
#ifdef FIFO_UINT_LEAST32_T | |
CREATE_FIFO_SETTER_PAIR(uint_least32_t); | |
#endif | |
#ifdef FIFO_UINT_LEAST64_T | |
CREATE_FIFO_SETTER_PAIR(uint_least64_t); | |
#endif | |
#ifdef FIFO_INT_FAST8_T | |
CREATE_FIFO_SETTER_PAIR(int_fast8_t); | |
#endif | |
#ifdef FIFO_INT_FAST16_T | |
CREATE_FIFO_SETTER_PAIR(int_fast16_t); | |
#endif | |
#ifdef FIFO_INT_FAST32_T | |
CREATE_FIFO_SETTER_PAIR(int_fast32_t); | |
#endif | |
#ifdef FIFO_INT_FAST64_T | |
CREATE_FIFO_SETTER_PAIR(int_fast64_t); | |
#endif | |
#ifdef FIFO_UINT_FAST8_T | |
CREATE_FIFO_SETTER_PAIR(uint_fast8_t); | |
#endif | |
#ifdef FIFO_UINT_FAST16_T | |
CREATE_FIFO_SETTER_PAIR(uint_fast16_t); | |
#endif | |
#ifdef FIFO_UINT_FAST32_T | |
CREATE_FIFO_SETTER_PAIR(uint_fast32_t); | |
#endif | |
#ifdef FIFO_UINT_FAST64_T | |
CREATE_FIFO_SETTER_PAIR(uint_fast64_t); | |
#endif | |
#ifdef FIFO_INTPTR_T | |
CREATE_FIFO_SETTER_PAIR(intptr_t); | |
#endif | |
#ifdef FIFO_UINTPTR_T | |
CREATE_FIFO_SETTER_PAIR(uintptr_t); | |
#endif | |
#ifdef FIFO_INTMAX_T | |
CREATE_FIFO_SETTER_PAIR(intmax_t); | |
#endif | |
#ifdef FIFO_UINTMAX_T | |
CREATE_FIFO_SETTER_PAIR(uintmax_t); | |
#endif | |
#ifdef FIFO_ | |
CREATE_FIFO_SETTER_PAIR(); | |
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#ifndef __FIFO_h__ | |
#define __FIFO_h__ | |
#include "common.h" | |
#include <stdint.h> | |
typedef struct { | |
uint32_t MaxSize; | |
uint32_t CurrentSize; | |
uint32_t WritePos; | |
uint32_t ReadPos; | |
uint32_t BufferWidth; | |
void *Buffer; | |
} FIFOBuffer_TypeDef; | |
int FIFO_Init(FIFOBuffer_TypeDef *buf, uint32_t maxSize, uint32_t bufferWidth, void *buffer); | |
int FIFO_Write(FIFOBuffer_TypeDef *buf, void(* setFun)(void*, void*), void *val); | |
int FIFO_Read(FIFOBuffer_TypeDef *buf, void(* retFun)(void*, void*), void *ret); | |
/*********************************** Macros for generating FIFO Functions *******************/ | |
#define TOKENPASTE(x, y) x ## y | |
#define TOKENPASTE2(x, y) TOKENPASTE(x, y) | |
#define CREATE_FIFO_SETTER_PAIR(type) \ | |
void TOKENPASTE2(FIFO_Set_, type)(void *addr, void *val) { *((type *)addr) = *((type *)val); }\ | |
void TOKENPASTE2(FIFO_Get_, type)(void *addr, void *val) { *((type *)val) = *((type *)addr); } | |
#define CREATE_FIFO_SETTER_PROTO(type) \ | |
void TOKENPASTE2(FIFO_Set_, type)(void *addr, void *val); \ | |
void TOKENPASTE2(FIFO_Get_, type)(void *addr, void *val) | |
/*********************************** ifdefs to include fifo function type *******************/ | |
#ifdef FIFO_INT8_T | |
CREATE_FIFO_SETTER_PROTO(int8_t); | |
#define FIFO_Init_int8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int8_t), &(buffer)) | |
#define FIFO_Write_int8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int8_t, &(val)) | |
#define FIFO_Read_int8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int8_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT16_T | |
CREATE_FIFO_SETTER_PROTO(int16_t); | |
#define FIFO_Init_int16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int16_t), &(buffer)) | |
#define FIFO_Write_int16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int16_t, &(val)) | |
#define FIFO_Read_int16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int16_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT32_T | |
CREATE_FIFO_SETTER_PROTO(int32_t); | |
#define FIFO_Init_int32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int32_t), &(buffer)) | |
#define FIFO_Write_int32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int32_t, &(val)) | |
#define FIFO_Read_int32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int32_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT64_T | |
CREATE_FIFO_SETTER_PROTO(int64_t); | |
#define FIFO_Init_int64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int64_t), &(buffer)) | |
#define FIFO_Write_int64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int64_t, &(val)) | |
#define FIFO_Read_int64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int64_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT8_T | |
CREATE_FIFO_SETTER_PROTO(uint8_t); | |
#define FIFO_Init_uint8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint8_t), &(buffer)) | |
#define FIFO_Write_uint8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint8_t, &(val)) | |
#define FIFO_Read_uint8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint8_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT16_T | |
CREATE_FIFO_SETTER_PROTO(uint16_t); | |
#define FIFO_Init_uint16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint16_t), &(buffer)) | |
#define FIFO_Write_uint16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint16_t, &(val)) | |
#define FIFO_Read_uint16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint16_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT32_T | |
CREATE_FIFO_SETTER_PROTO(uint32_t); | |
#define FIFO_Init_uint32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint32_t), &(buffer)) | |
#define FIFO_Write_uint32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint32_t, &(val)) | |
#define FIFO_Read_uint32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint32_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT64_T | |
CREATE_FIFO_SETTER_PROTO(uint64_t); | |
#define FIFO_Init_uint64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint64_t), &(buffer)) | |
#define FIFO_Write_uint64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint64_t, &(val)) | |
#define FIFO_Read_uint64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint64_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_LEAST8_T | |
CREATE_FIFO_SETTER_PROTO(int_least8_t); | |
#define FIFO_Init_int_least8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_least8_t), &(buffer)) | |
#define FIFO_Write_int_least8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_least8_t, &(val)) | |
#define FIFO_Read_int_least8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_least8_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_LEAST16_T | |
CREATE_FIFO_SETTER_PROTO(int_least16_t); | |
#define FIFO_Init_int_least16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_least16_t), &(buffer)) | |
#define FIFO_Write_int_least16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_least16_t, &(val)) | |
#define FIFO_Read_int_least16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_least16_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_LEAST32_T | |
CREATE_FIFO_SETTER_PROTO(int_least32_t); | |
#define FIFO_Init_int_least32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_least32_t), &(buffer)) | |
#define FIFO_Write_int_least32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_least32_t, &(val)) | |
#define FIFO_Read_int_least32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_least32_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_LEAST64_T | |
CREATE_FIFO_SETTER_PROTO(int_least64_t); | |
#define FIFO_Init_int_least64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_least64_t), &(buffer)) | |
#define FIFO_Write_int_least64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_least64_t, &(val)) | |
#define FIFO_Read_int_least64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_least64_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_LEAST8_T | |
CREATE_FIFO_SETTER_PROTO(uint_least8_t); | |
#define FIFO_Init_uint_least8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_least8_t), &(buffer)) | |
#define FIFO_Write_uint_least8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_least8_t, &(val)) | |
#define FIFO_Read_uint_least8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_least8_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_LEAST16_T | |
CREATE_FIFO_SETTER_PROTO(uint_least16_t); | |
#define FIFO_Init_uint_least16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_least16_t), &(buffer)) | |
#define FIFO_Write_uint_least16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_least16_t, &(val)) | |
#define FIFO_Read_uint_least16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_least16_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_LEAST32_T | |
CREATE_FIFO_SETTER_PROTO(uint_least32_t); | |
#define FIFO_Init_uint_least32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_least32_t), &(buffer)) | |
#define FIFO_Write_uint_least32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_least32_t, &(val)) | |
#define FIFO_Read_uint_least32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_least32_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_LEAST64_T | |
CREATE_FIFO_SETTER_PROTO(uint_least64_t); | |
#define FIFO_Init_uint_least64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_least64_t), &(buffer)) | |
#define FIFO_Write_uint_least64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_least64_t, &(val)) | |
#define FIFO_Read_uint_least64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_least64_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_FAST8_T | |
CREATE_FIFO_SETTER_PROTO(int_fast8_t); | |
#define FIFO_Init_int_fast8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_fast8_t), &(buffer)) | |
#define FIFO_Write_int_fast8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_fast8_t, &(val)) | |
#define FIFO_Read_int_fast8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_fast8_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_FAST16_T | |
CREATE_FIFO_SETTER_PROTO(int_fast16_t); | |
#define FIFO_Init_int_fast16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_fast16_t), &(buffer)) | |
#define FIFO_Write_int_fast16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_fast16_t, &(val)) | |
#define FIFO_Read_int_fast16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_fast16_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_FAST32_T | |
CREATE_FIFO_SETTER_PROTO(int_fast32_t); | |
#define FIFO_Init_int_fast32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_fast32_t), &(buffer)) | |
#define FIFO_Write_int_fast32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_fast32_t, &(val)) | |
#define FIFO_Read_int_fast32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_fast32_t, &(ret)) | |
#endif | |
#ifdef FIFO_INT_FAST64_T | |
CREATE_FIFO_SETTER_PROTO(int_fast64_t); | |
#define FIFO_Init_int_fast64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(int_fast64_t), &(buffer)) | |
#define FIFO_Write_int_fast64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_int_fast64_t, &(val)) | |
#define FIFO_Read_int_fast64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_int_fast64_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_FAST8_T | |
CREATE_FIFO_SETTER_PROTO(uint_fast8_t); | |
#define FIFO_Init_uint_fast8_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_fast8_t), &(buffer)) | |
#define FIFO_Write_uint_fast8_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_fast8_t, &(val)) | |
#define FIFO_Read_uint_fast8_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_fast8_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_FAST16_T | |
CREATE_FIFO_SETTER_PROTO(uint_fast16_t); | |
#define FIFO_Init_uint_fast16_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_fast16_t), &(buffer)) | |
#define FIFO_Write_uint_fast16_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_fast16_t, &(val)) | |
#define FIFO_Read_uint_fast16_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_fast16_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_FAST32_T | |
CREATE_FIFO_SETTER_PROTO(uint_fast32_t); | |
#define FIFO_Init_uint_fast32_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_fast32_t), &(buffer)) | |
#define FIFO_Write_uint_fast32_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_fast32_t, &(val)) | |
#define FIFO_Read_uint_fast32_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_fast32_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINT_FAST64_T | |
CREATE_FIFO_SETTER_PROTO(uint_fast64_t); | |
#define FIFO_Init_uint_fast64_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uint_fast64_t), &(buffer)) | |
#define FIFO_Write_uint_fast64_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uint_fast64_t, &(val)) | |
#define FIFO_Read_uint_fast64_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uint_fast64_t, &(ret)) | |
#endif | |
#ifdef FIFO_INTPTR_T | |
CREATE_FIFO_SETTER_PROTO(intptr_t); | |
#define FIFO_Init_intptr_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(intptr_t), &(buffer)) | |
#define FIFO_Write_intptr_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_intptr_t, &(val)) | |
#define FIFO_Read_intptr_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_intptr_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINTPTR_T | |
CREATE_FIFO_SETTER_PROTO(uintptr_t); | |
#define FIFO_Init_uintptr_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uintptr_t), &(buffer)) | |
#define FIFO_Write_uintptr_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uintptr_t, &(val)) | |
#define FIFO_Read_uintptr_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uintptr_t, &(ret)) | |
#endif | |
#ifdef FIFO_INTMAX_T | |
CREATE_FIFO_SETTER_PROTO(intmax_t); | |
#define FIFO_Init_intmax_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(intmax_t), &(buffer)) | |
#define FIFO_Write_intmax_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_intmax_t, &(val)) | |
#define FIFO_Read_intmax_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_intmax_t, &(ret)) | |
#endif | |
#ifdef FIFO_UINTMAX_T | |
CREATE_FIFO_SETTER_PROTO(uintmax_t); | |
#define FIFO_Init_uintmax_t(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(uintmax_t), &(buffer)) | |
#define FIFO_Write_uintmax_t(fifo, val) FIFO_Write(&(fifo), FIFO_Set_uintmax_t, &(val)) | |
#define FIFO_Read_uintmax_t(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_uintmax_t, &(ret)) | |
#endif | |
#ifdef FIFO_ | |
CREATE_FIFO_SETTER_PROTO(); | |
#define FIFO_Init_(fifo, maxSize, buffer) FIFO_Init(&(fifo), (maxSize), sizeof(), &(buffer)) | |
#define FIFO_Write_(fifo, val) FIFO_Write(&(fifo), FIFO_Set_, &(val)) | |
#define FIFO_Read_(fifo, ret) FIFO_Read(&(fifo), FIFO_Get_, &(ret)) | |
#endif | |
#endif /* __FIFO_h__ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdint.h> | |
#include "common.h" | |
#include "FIFO.h" | |
#define BUF_SIZE 20 | |
uint8_t buffer_8[BUF_SIZE]; | |
FIFOBuffer_TypeDef fifo_8; | |
uint32_t buffer_32[BUF_SIZE]; | |
FIFOBuffer_TypeDef fifo_32; | |
int main() { | |
if (FIFO_Init_uint8_t(fifo_8, BUF_SIZE, buffer_8)) { | |
printf("error!\n"); | |
} | |
if (FIFO_Init_uint32_t(fifo_32, BUF_SIZE, buffer_32)) { | |
printf("error!\n"); | |
} | |
printf("writing values to uint8_t fifo\n"); | |
for (uint8_t i = 0; i < BUF_SIZE; i++) { | |
FIFO_Write_uint8_t(fifo_8, i); | |
} | |
printf("reading values from fifo\n"); | |
uint8_t r8; | |
for (int i = 0; i < BUF_SIZE; i++) { | |
FIFO_Read_uint8_t(fifo_8, r8); | |
printf("%d\n", r8); | |
} | |
printf("writing values to uint32_t fifo\n"); | |
for (uint32_t i = 0; i < BUF_SIZE; i++) { | |
FIFO_Write_uint32_t(fifo_32, i); | |
} | |
printf("reading values from fifo\n"); | |
uint32_t r32; | |
for (int j = 0; j < BUF_SIZE; j++) { | |
FIFO_Read_uint32_t(fifo_32, r32); | |
printf("%d\n", r32); | |
} | |
printf("done"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment