AppNearMe µNFC stack for the NXP PN532 chip License: You can use the stack free of charge to prototype with mbed; if you want to use the stack with your commercial product, get in touch!

Dependents:   IOT_sensor_nfc AppNearMe_MuNFC_PN532_Test p2p_nfc_test NFCMoodLamp ... more

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers buffer.h Source File

buffer.h

00001 /*
00002   buffer.h
00003   Copyright (c) Donatien Garnier 2012
00004   donatien.garnier@appnearme.com
00005   http://www.appnearme.com/
00006 */
00007 
00008 #ifndef BUFFER_H_
00009 #define BUFFER_H_
00010 
00011 #ifdef __cplusplus
00012 extern "C" {
00013 #endif
00014 
00015 #include "core/fwk.h"
00016 
00017 typedef struct __buffer
00018 {
00019   uint8_t* bufdata;
00020   size_t size;
00021 
00022   uint8_t* start;
00023   size_t first_byte_length; //In bits
00024 
00025   uint8_t* end;
00026   size_t last_byte_length; //In bits
00027 
00028   struct __buffer* next;
00029 
00030 } buffer;
00031 
00032 void buffer_init(buffer* pBuf, uint8_t* bufdata, size_t size);
00033 
00034 void buffer_byref(buffer* pBuf, uint8_t* bufdata, size_t length); //New buffer by ref on a size_t array, no malloc (useful on PIC for instance)
00035 
00036 buffer* buffer_new(size_t size); //malloc
00037 
00038 uint8_t* buffer_data(buffer* pBuf);
00039 
00040 void buffer_reset(buffer* pBuf);
00041 
00042 size_t buffer_size(buffer* pBuf);
00043 
00044 size_t buffer_length(buffer* pBuf);
00045 
00046 bool buffer_empty(buffer* pBuf);
00047 
00048 void buffer_set_length(buffer* pBuf, size_t length);
00049 
00050 size_t buffer_last_byte_length(buffer* pBuf);
00051 
00052 void buffer_set_last_byte_length(buffer* pBuf, size_t length);
00053 
00054 size_t buffer_bits_count(buffer* pBuf);
00055 
00056 void buffer_write_byte(buffer* pBuf, uint8_t b);
00057 
00058 void buffer_write_bit(buffer* pBuf, uint8_t b);
00059 
00060 #if 0
00061 size_t buffer_read_byte(buffer* pBuf, uint8_t b);
00062 
00063 size_t buffer_read_bit(buffer* pBuf, uint8_t b);
00064 #endif
00065 
00066 buffer* buffer_next(buffer* pBuf);
00067 
00068 void buffer_set_next(buffer* pBuf, buffer* pNextBuf);
00069 
00070 void buffer_append(buffer* pBuf, buffer* pAppBuf);
00071 
00072 void buffer_unlink(buffer* pBuf, buffer* pLinkedBuf);
00073 
00074 size_t buffer_total_size(buffer* pBuf);
00075 
00076 size_t buffer_total_length(buffer* pBuf);
00077 
00078 void buffer_set_total_length(buffer* pBuf, size_t length);
00079 
00080 void buffer_free(buffer* pBuf);
00081 
00082 #ifdef __cplusplus
00083 }
00084 #endif
00085 
00086 #endif /* BUFFER_H_ */