AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
blyss.h
1 
18 #ifndef _AVRIO_BLYSS_H_
19 #define _AVRIO_BLYSS_H_
20 
21 #include <avrio/defs.h>
22 __BEGIN_C_DECLS
23 /* ========================================================================== */
24 #include <stdio.h>
25 #include <avr/interrupt.h>
26 
75 /* constants ================================================================ */
76 #define BLYSS_BROADCAST 0 /***< Canal d'appel général */
77 
78 /* macros =================================================================== */
84 #define vBlyssPrintFrame(f) vBlyssPrintFrameToFile (f, stdout)
85 
86 /* structures =============================================================== */
87 
105 struct xBlyssFrame {
106 
107  uint8_t raw[7];
108 };
109 
110 
111 /* types ==================================================================== */
115 typedef struct xBlyss xBlyss;
116 
120 typedef struct xBlyssFrame xBlyssFrame;
121 
122 /* internal public functions ================================================ */
129 void vBlyssInit (void);
130 
140 void vBlyssSend (xBlyssFrame * frame, uint8_t repeat);
141 
158 bool bBlyssReceive (xBlyssFrame * frame);
159 
167 void vBlyssFrameInit (xBlyssFrame * frame, const uint8_t * tx_id);
168 
177 void vBlyssFrameSetChannel (xBlyssFrame * frame, uint8_t channel);
178 
187 uint8_t ucBlyssFrameChannel (const xBlyssFrame * frame);
188 
195 bool bBlyssIsValidFrame (const void * buffer);
196 
203 bool bBlyssIsValidChannel (uint8_t channel);
204 
222 void vBlyssPrintFrameToFile (const xBlyssFrame * frame, FILE * out);
223 
224 
225 #if defined(__DOXYGEN__)
226 /*
227  * __DOXYGEN__ defined
228  * Partie documentation ne devant pas être compilée.
229  * ===========================================================================*/
236 static inline void vBlyssFrameSetState (xBlyssFrame * frame, bool state);
237 
244 static inline bool bBlyssFrameState (const xBlyssFrame * frame);
245 
252 static inline uint8_t ucBlyssFrameGlobalChannel (const xBlyssFrame * frame);
253 
260 static inline uint16_t usBlyssFrameAddress (const xBlyssFrame * frame);
261 
269 static inline bool bBlyssFrameMatch (const xBlyssFrame * f1, const xBlyssFrame * f2);
270 
277 static inline void vBlyssFrameCopy (xBlyssFrame * dest, const xBlyssFrame * src);
278 
284 /* ========================================================================== */
285 #else
286 /*
287  * __DOXYGEN__ not defined
288  * Partie ne devant pas être documentée.
289  * =============================================================================
290  */
291 #include <string.h>
292 
293 /* constants ================================================================ */
294 #define BLYSS_IDX_FLAG 0
295 #define BLYSS_IDX_GCHAN 8
296 #define BLYSS_IDX_ADDR 12
297 #define BLYSS_IDX_CHAN 28
298 #define BLYSS_IDX_STATE 32
299 #define BLYSS_IDX_ROLL 36
300 #define BLYSS_IDX_TOKEN 44
301 
302 /* internal private functions ================================================ */
303 void vBlyssFrameSetBits (xBlyssFrame * f, uint8_t index, uint8_t len, uint16_t value);
304 uint16_t vBlyssFrameGetBits (const xBlyssFrame * f, uint8_t index, uint8_t len);
305 
306 /* internal inline functions ================================================ */
307 // -----------------------------------------------------------------------------
308 INLINE void
309 vBlyssFrameSetState (xBlyssFrame * f, bool state) {
310 
311  vBlyssFrameSetBits (f, BLYSS_IDX_STATE, 4, ! state);
312 }
313 
314 // -----------------------------------------------------------------------------
315 INLINE uint8_t
317 
318  return vBlyssFrameGetBits (f, BLYSS_IDX_GCHAN, 4);
319 }
320 
321 // -----------------------------------------------------------------------------
322 INLINE uint16_t
323 usBlyssFrameAddress (const xBlyssFrame * f) {
324 
325  return vBlyssFrameGetBits (f, BLYSS_IDX_ADDR, 16);
326 }
327 
328 // -----------------------------------------------------------------------------
329 INLINE bool
330 bBlyssFrameState (const xBlyssFrame * f) {
331 
332  return ! vBlyssFrameGetBits (f, BLYSS_IDX_STATE, 4);
333 }
334 
335 // -----------------------------------------------------------------------------
336 INLINE bool
337 bBlyssFrameMatch (const xBlyssFrame * f1, const xBlyssFrame * f2) {
338 
339  return memcmp (f1, f2, sizeof(xBlyssFrame)) == 0;
340 }
341 
342 // -----------------------------------------------------------------------------
343 INLINE void
344 vBlyssFrameCopy (xBlyssFrame * dest, const xBlyssFrame * src) {
345 
346  memcpy (dest, src, sizeof(xBlyssFrame));
347 }
348 
349 /* ========================================================================== */
350 #endif /* __DOXYGEN__ not defined */
351 
352 /* ========================================================================== */
353 __END_C_DECLS
354 #endif /*_AVRIO_BLYSS_H_ defined */
struct xBlyss xBlyss
xBlyss
Definition: blyss.h:115
void vBlyssFrameSetChannel(xBlyssFrame *frame, uint8_t channel)
Modification du canal destinataire d&#39;une trame.
void vBlyssPrintFrameToFile(const xBlyssFrame *frame, FILE *out)
Imprime le contenu d&#39;une trame dans un fichier.
void vBlyssFrameInit(xBlyssFrame *frame, const uint8_t *tx_id)
Initialisation d&#39;une trame LiveEz.
bool bBlyssReceive(xBlyssFrame *frame)
Réception d&#39;une trame.
bool bBlyssIsValidChannel(uint8_t channel)
Test si un canal est valide.
uint8_t ucBlyssFrameChannel(const xBlyssFrame *frame)
Canal destinataire de la trame.
static bool bBlyssFrameMatch(const xBlyssFrame *f1, const xBlyssFrame *f2)
Compare deux trames.
bool bBlyssIsValidFrame(const void *buffer)
Test si un buffer contient une trame LiveEz valide.
Trame LiveEz.
Definition: blyss.h:105
static void vBlyssFrameCopy(xBlyssFrame *dest, const xBlyssFrame *src)
Copie d&#39;une trame.
static void vBlyssFrameSetState(xBlyssFrame *frame, bool state)
Modification de l&#39;état du destinataire.
static bool bBlyssFrameState(const xBlyssFrame *frame)
Etat du destinataire de la trame.
static uint16_t usBlyssFrameAddress(const xBlyssFrame *frame)
Adresse source d&#39;une trame.
static uint8_t ucBlyssFrameGlobalChannel(const xBlyssFrame *frame)
Canal global d&#39;une trame.
void vBlyssInit(void)
Initialisation du module Blyss.
void vBlyssSend(xBlyssFrame *frame, uint8_t repeat)
Envoi d&#39;une trame.