770be70688
* Added required linux Ethernet library for ethernet build * Added .obj to gitignore * Fixed BACnet port for APPLE to use BSD in CMake * Changed format in CMake to enable cleaner SC merge * Added create-object and delete-object recipes in GCC Makefile * Added datalink timer to all example OS apps * Changed most microcontroller ports to use BACAPP_MINIMAL to specify which datatypes can be written. * Fixed zephyr OS for BACnet/IP warning * Fixed zephyr OS log to not require log_strdup * Added writefile API to file object example * Added API to device-client to make it more robust. * Added API in network-port object for getting the ASCII object-name * Added debug print with a timestamp option * Added debug print with hex dump print * Added API to network port object for activate and discard * Added default define for debug with timestamp * Added prototype in header for disabled debug printf. * Added fifo peek ahead function to peek at more than one byte. * Added get-mac value for network port that uses buffer rather than octetstring
122 lines
2.3 KiB
C
122 lines
2.3 KiB
C
/**
|
|
* @file
|
|
* @author Steve Karg
|
|
* @date 2004
|
|
*/
|
|
#ifndef FIFO_H
|
|
#define FIFO_H
|
|
|
|
#include <stdint.h>
|
|
#include <stdbool.h>
|
|
/* BACnet Stack defines - first */
|
|
#include "bacnet/bacdef.h"
|
|
|
|
/**
|
|
* FIFO buffer power of two alignment macro
|
|
*
|
|
* @{
|
|
*/
|
|
#ifndef NEXT_POWER_OF_2
|
|
#define B2(x) ( (x) | ( (x) >> 1) )
|
|
#define B4(x) ( B2(x) | ( B2(x) >> 2) )
|
|
#define B8(x) ( B4(x) | ( B4(x) >> 4) )
|
|
#define B16(x) ( B8(x) | ( B8(x) >> 8) )
|
|
#define B32(x) (B16(x) | (B16(x) >>16) )
|
|
#define NEXT_POWER_OF_2(x) (B32((x)-1) + 1)
|
|
#endif
|
|
/** @} */
|
|
|
|
/**
|
|
* FIFO data store structure
|
|
*
|
|
* @{
|
|
*/
|
|
#define FIFO_DATA_STORE(b,c) uint8_t b[NEXT_POWER_OF_2(c)]
|
|
/** @} */
|
|
|
|
/**
|
|
* FIFO data structure
|
|
*
|
|
* @{
|
|
*/
|
|
struct fifo_buffer_t {
|
|
/** first byte of data */
|
|
volatile unsigned head;
|
|
/** last byte of data */
|
|
volatile unsigned tail;
|
|
/** block of memory or array of data */
|
|
volatile uint8_t *buffer;
|
|
/** length of the data */
|
|
unsigned buffer_len;
|
|
};
|
|
typedef struct fifo_buffer_t FIFO_BUFFER;
|
|
/** @} */
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif /* __cplusplus */
|
|
|
|
BACNET_STACK_EXPORT
|
|
unsigned FIFO_Count(
|
|
FIFO_BUFFER const *b);
|
|
|
|
BACNET_STACK_EXPORT
|
|
bool FIFO_Full(
|
|
FIFO_BUFFER const *b);
|
|
|
|
BACNET_STACK_EXPORT
|
|
bool FIFO_Available(
|
|
FIFO_BUFFER const *b,
|
|
unsigned count);
|
|
|
|
BACNET_STACK_EXPORT
|
|
bool FIFO_Empty(
|
|
FIFO_BUFFER const *b);
|
|
|
|
BACNET_STACK_EXPORT
|
|
uint8_t FIFO_Peek(
|
|
FIFO_BUFFER const *b);
|
|
|
|
BACNET_STACK_EXPORT
|
|
unsigned FIFO_Peek_Ahead(
|
|
FIFO_BUFFER const *b,
|
|
uint8_t* data_bytes,
|
|
unsigned length);
|
|
|
|
BACNET_STACK_EXPORT
|
|
uint8_t FIFO_Get(
|
|
FIFO_BUFFER * b);
|
|
|
|
BACNET_STACK_EXPORT
|
|
unsigned FIFO_Pull(
|
|
FIFO_BUFFER * b,
|
|
uint8_t * data_bytes,
|
|
unsigned length);
|
|
|
|
BACNET_STACK_EXPORT
|
|
bool FIFO_Put(
|
|
FIFO_BUFFER * b,
|
|
uint8_t data_byte);
|
|
|
|
BACNET_STACK_EXPORT
|
|
bool FIFO_Add(
|
|
FIFO_BUFFER * b,
|
|
uint8_t * data_bytes,
|
|
unsigned count);
|
|
|
|
BACNET_STACK_EXPORT
|
|
void FIFO_Flush(
|
|
FIFO_BUFFER * b);
|
|
|
|
/* note: buffer_len must be a power of two */
|
|
BACNET_STACK_EXPORT
|
|
void FIFO_Init(
|
|
FIFO_BUFFER * b,
|
|
volatile uint8_t * buffer,
|
|
unsigned buffer_len);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif /* __cplusplus */
|
|
#endif
|