AvrIO  1.4.5
Bibliothèque C modulaire pour ATMEL AVR
device.h
1 
21 #ifndef _AVRIO_WUSB_DEVICE_H_
22 #define _AVRIO_WUSB_DEVICE_H_
23 
24 #include <avrio/defs.h>
25 
26 __BEGIN_C_DECLS
27 /* ========================================================================== */
37 /* macros =================================================================== */
41 #define WDEV_REGTABLE_SIZEOF(r) (sizeof(r)/sizeof(xWDevRegister))
42 
43 /* constants ================================================================ */
44 #define WDEV_MID_SIZEOF 4
45 #define WDEV_RXSTAT 0
46 #define WDEV_RXDATA 1
47 #define WDEV_RXVALID 2
48 
49 /* enum ===================================================================== */
53 typedef enum {
54  WDEV_RATE_EEPROM = 0,
55  WDEV_RATE_16KBPS = 1,
56  WDEV_RATE_64KBPS = 2
58 
62 typedef enum {
63  WDEV_IDLE = 0x00,
64  WDEV_TX = 0x01,
65  WDEV_RX = 0x02,
66  WDEV_BUSY = 0x04,
68 } eWDevStatus;
69 
70 /* structures =============================================================== */
74 typedef struct xWDevRegister {
75 
76  uint8_t Address;
77  uint8_t Value;
79 
83 typedef struct xWDevRegisterTable {
84 
85  const struct xWDevRegister * Regs;
86  uint8_t Size;
88 
92 typedef struct xWDevConfig {
93 
95  int8_t pXtalAdjust;
96 } xWDevConfig;
97 
98 /* == <API> == public application interface ================================ */
106 void vWDevInit (eWDevDataRate DataRate);
107 
113 void vWDevTransmit (const uint8_t * Data, uint8_t Length);
114 
126 int iWDevReceive (uint8_t * ucUserPacket, uint8_t * ucUserValid,
127  int iUserBufferSize, int usTimeout);
134 void vWDevRxCB (uint8_t * Data);
135 
140 void vWDevEnable (uint8_t Tx);
141 
145 void vWDevDisable (void);
146 
152 void vWDevSleep (bool Sleep);
153 
159 void vWDevSetup (const xWDevRegister * Regs, uint8_t Size);
160 
166 void vWDevSetup_P (const xWDevRegister * Regs, uint8_t Size);
167 
173 void vWDevSetupFromTable_P(const xWDevRegisterTable * SetupTable, uint8_t Index);
174 
186 int8_t iWDevRssi (void);
187 
202 void vWDevSetCrystal (uint8_t Capacitance);
203 
210 void vWDevSetX13Out (uint8_t flag);
211 
217 void vWDevSaveConfigToEEPROM (void);
218 
222 const uint8_t * pucWDevGetPnCode (void);
223 
224 #if defined(__DOXYGEN__)
225 
229 inline void vWDevSetPnCode (const uint8_t * PnCode);
230 
235 inline void vWDevSetPnCode_P (const uint8_t * PnCode);
236 
240 inline const uint8_t * pucWDevMid (void);
241 
251 inline void vWDevSetMid (const uint8_t * Mid);
252 
256 inline uint8_t ucWDevRevId (void);
257 
261 inline eWDevDataRate eWDevGetDataRate (void);
262 
267 inline void vWDevSetDataRate (eWDevDataRate DataRate);
268 
272 inline void vWDevSetChannel (uint8_t Value);
273 
277 inline uint8_t ucWDevGetChannel (void);
278 
282 inline void vWDevSetPaBias (uint8_t Value);
283 
287 inline uint8_t ucWDevGetPaBias (void);
288 
292 inline void vWDevSetThresholdLow (uint8_t Value);
293 
297 inline uint8_t ucWDevGetThresholdLow (void);
298 
302 inline void vWDevSetThresholdHigh (uint8_t Value);
303 
307 inline uint8_t ucWDevGetThresholdHigh (void);
308 
312 inline void vWDevSetSynthLockCount (uint8_t Value);
313 
317 inline uint8_t ucWDevGetSynthLockCount (void);
318 
322 inline eWDevStatus eWDevGetStatus (void);
323 
327 inline void vWDevWaitStatus (eWDevStatus eStatus);
328 
333 inline uint8_t ucWDevGetCrystal (void);
334 
339 inline uint8_t ucWDevGetX13Out (void);
340 
346 inline void vWDevSetReg (uint8_t Address, uint8_t Value);
347 
353 inline uint8_t ucWDevGetReg (uint8_t Address);
354 
355 /* == <API-END> == public application interface ============================ */
361 #else /* ! defined(__DOXYGEN__) */
362 #include <avrio/state.h>
363 #include <avrio/wusb/net/device/iface.h>
364 
365 #ifdef AVRIO_WUSB_ENABLE
366 /* ========================================================================== */
367 /* Implémentation inline (non documentée) */
368 /* ========================================================================== */
369 #include <string.h>
370 #include <avr/eeprom.h>
371 
372 /* structures =============================================================== */
373 typedef struct xWDevice {
374 
375 /* private: */
376  xState pState; /*< état du module */
377  const uint8_t * pTxData; /*< pointeur sur les octets à envoyer */
378  uint8_t pTxLength; /*< nombre d'octets pointés par \c pTxData */
379  xWDevConfig xConfig; /*< config actuelle du module */
380  uint8_t pMid[4]; /*< copie en ram du Mid du module */
381 } xWDevice;
382 
383 /* internal public functions ================================================ */
384 extern void vWDevIdle (void);
385 
386 /* public variables ========================================================= */
387 extern xWDevice dDevice;
388 
389 /* inline public functions ================================================== */
390 
391 // -----------------------------------------------------------------------------
392 __STATIC_ALWAYS_INLINE (void
393 vWDevSetReg (uint8_t Reg, uint8_t Value)) {
394 
395  vWIfcWrite (Reg, Value);
396 }
397 
398 // -----------------------------------------------------------------------------
399 __STATIC_ALWAYS_INLINE (uint8_t
400 ucWDevGetReg (uint8_t Reg)) {
401 
402  return ucWIfcRead (Reg);
403 }
404 
405 // -----------------------------------------------------------------------------
406 __STATIC_ALWAYS_INLINE (eWDevStatus
407 eWDevGetStatus (void)) {
408 
409  return (eWDevStatus) xStateGet (&dDevice.pState);
410 }
411 
412 // -----------------------------------------------------------------------------
413 __STATIC_ALWAYS_INLINE (void
414 vWDevWaitStatus (eWDevStatus Status)) {
415 
416  vStateWait (&dDevice.pState, Status);
417 }
418 
419 // -----------------------------------------------------------------------------
420 __STATIC_ALWAYS_INLINE (const uint8_t *
421 pucWDevMid (void)) {
422 
423  return dDevice.pMid;
424 }
425 
426 // -----------------------------------------------------------------------------
427 __STATIC_ALWAYS_INLINE (eWDevDataRate
428 eWDevGetDataRate (void)) {
429 
430  return dDevice.xConfig.pDataRate;
431 }
432 
433 // -----------------------------------------------------------------------------
434 __STATIC_ALWAYS_INLINE (void
435 vWDevSetDataRate (eWDevDataRate DataRate)) {
436 
437  vWDevInit (DataRate);
438 }
439 
440 // -----------------------------------------------------------------------------
441 __STATIC_ALWAYS_INLINE (uint8_t
442 ucWDevGetCrystal (void)) {
443 
444  return ucWDevGetReg (REG_CRYSTAL_ADJ) & mCRYSTAL_ADJ;
445 }
446 
447 // -----------------------------------------------------------------------------
448 __STATIC_ALWAYS_INLINE (uint8_t
449 ucWDevGetX13Out (void)) {
450 
451  return ucWDevGetReg (REG_CRYSTAL_ADJ) & bCLOCK_DISABLE;
452 }
453 
454 // -----------------------------------------------------------------------------
455 __STATIC_ALWAYS_INLINE (void
456 vWDevSetPnCode_P (const uint8_t * PnCode)) {
457 
458  vWIfcBurstWrite_P (REG_PN_CODE, PnCode, 8);
459 }
460 
461 // -----------------------------------------------------------------------------
462 __STATIC_ALWAYS_INLINE (void
463 vWDevSetPnCode (const uint8_t * PnCode)) {
464 
465  vWIfcBurstWrite (REG_PN_CODE, PnCode, 8);
466 }
467 
468 // -----------------------------------------------------------------------------
469 __STATIC_ALWAYS_INLINE (uint8_t
470 ucWDevRevId (void)) {
471 
472  return ucWDevGetReg (REG_ID);
473 }
474 
475 // -----------------------------------------------------------------------------
476 __STATIC_ALWAYS_INLINE (uint8_t
477 ucWDevGetThresholdLow (void)) {
478 
479  return ucWDevGetReg (REG_THRESHOLD_L) & mTHRESHOLD_L;
480 }
481 
482 // -----------------------------------------------------------------------------
483 __STATIC_ALWAYS_INLINE (uint8_t
484 ucWDevGetThresholdHigh (void)) {
485 
486  return ucWDevGetReg (REG_THRESHOLD_H) & mTHRESHOLD_H;
487 }
488 
489 // -----------------------------------------------------------------------------
490 __STATIC_ALWAYS_INLINE (uint8_t
491 ucWDevGetChannel (void)) {
492 
493  return ucWDevGetReg (REG_CHANNEL) & mCHANNEL;
494 }
495 
496 // -----------------------------------------------------------------------------
497 __STATIC_ALWAYS_INLINE (uint8_t
498 ucWDevGetPaBias (void)) {
499 
500  return ucWDevGetReg (REG_PA) & mPA_BIAS;
501 }
502 
503 // -----------------------------------------------------------------------------
504 __STATIC_ALWAYS_INLINE (uint8_t
505 ucWDevGetSynthLockCount (void)) {
506 
507  return ucWDevGetReg (REG_SYN_LOCK_CNT);
508 }
509 
510 // -----------------------------------------------------------------------------
511 __STATIC_ALWAYS_INLINE (void
512 vWDevSetThresholdLow (uint8_t Value)) {
513 
514  vWDevSetReg (REG_THRESHOLD_L, Value & mTHRESHOLD_L);
515 }
516 
517 // -----------------------------------------------------------------------------
518 __STATIC_ALWAYS_INLINE (void
519 vWDevSetThresholdHigh (uint8_t Value)) {
520 
521  vWDevSetReg (REG_THRESHOLD_H, Value & mTHRESHOLD_H);
522 }
523 
524 // -----------------------------------------------------------------------------
525 __STATIC_ALWAYS_INLINE (void
526 vWDevSetChannel (uint8_t Value)) {
527 
528  vWDevIdle ();
529  vWDevSetReg (REG_CHANNEL, Value & mCHANNEL);
530 }
531 
532 // -----------------------------------------------------------------------------
533 __STATIC_ALWAYS_INLINE (void
534 vWDevSetPaBias (uint8_t Value)) {
535 
536  vWDevSetReg (REG_PA, Value & mPA_BIAS);
537 }
538 
539 // -----------------------------------------------------------------------------
540 __STATIC_ALWAYS_INLINE (void
541 vWDevSetSynthLockCount (uint8_t Value)) {
542 
543  vWDevSetReg (REG_SYN_LOCK_CNT, Value);
544 }
545 
546 // -----------------------------------------------------------------------------
547 __STATIC_ALWAYS_INLINE (void
548 vWDevSetMid (const uint8_t * Mid)) {
549 
550  memcpy (&dDevice.pMid, Mid, WDEV_MID_SIZEOF);
551 }
552 #endif /* AVRIO_WUSB_ENABLE defined */
553 #endif /* __DOXYGEN__ not defined */
554 
555 /* ========================================================================== */
556 __END_C_DECLS
557 #endif /* _AVRIO_WUSB_DEVICE_H_ */
void vWDevSetChannel(uint8_t Value)
Modification du canal de réception (REG_CHANNEL)
eWDevDataRate pDataRate
Definition: device.h:94
struct xWDevConfig xWDevConfig
Structure de stockage de la configuration du module.
eWDevStatus
Différents états du module.
Definition: device.h:62
uint8_t Value
Definition: device.h:77
uint8_t ucWDevGetChannel(void)
Lecture du canal de réception (REG_CHANNEL)
uint8_t ucWDevGetSynthLockCount(void)
Lecture du délai de verrouillage du synthetiseur par pas de 2 us(REG_SYN_LOCK_CNT) ...
void vWDevEnable(uint8_t Tx)
Passe le module en attente de réception ou de transmission.
int8_t pXtalAdjust
Definition: device.h:95
const uint8_t * pucWDevGetPnCode(void)
Lecture du PN Code courant.
void vWDevInit(eWDevDataRate DataRate)
Initialise le module radio L&#39;initialisation se fait avec les valeurs par défaut correspondants à la v...
uint8_t ucWDevGetX13Out(void)
Lecture de l&#39;activation de la broche X13OUT (REG_PA)
void vWDevSetupFromTable_P(const xWDevRegisterTable *SetupTable, uint8_t Index)
Charge les registres du module radio à partir d&#39;un tableau de configuration en FLASH.
uint8_t xStateGet(xState *pxState)
Lit la valeur d&#39;une machine d&#39;état de façon atomique.
void vWDevSetPnCode(const uint8_t *PnCode)
Modification du PN Code.
void vWDevSetPaBias(uint8_t Value)
Modification du niveau d&#39;amplification à l&#39;emission (REG_PA)
int iWDevReceive(uint8_t *ucUserPacket, uint8_t *ucUserValid, int iUserBufferSize, int usTimeout)
Réception d&#39;un message.
eWDevStatus eWDevGetStatus(void)
Renvoie l&#39;état du module.
uint8_t ucWDevGetThresholdHigh(void)
Lecture du seuil de réception du niveau haut (REG_THRESHOLD_H)
void vWDevSetCrystal(uint8_t Capacitance)
Ajustement de la fréquence du quartz (REG_CRYSTAL_ADJ) Permet d&#39;ajuster la capacité parallèle du quar...
void vWDevSetThresholdLow(uint8_t Value)
Modification du seuil de réception du niveau bas (REG_THRESHOLD_L)
uint8_t ucWDevRevId(void)
Lecture de l&#39;identifiant de revision (REG_ID)
void vStateWait(xState *pxState, uint8_t ucValue)
vStateWait suspend le thread appelant jusqu&#39;à ce que le compteur de la machine d&#39;état pointée par pxS...
void vWDevSaveConfigToEEPROM(void)
Sauvegarde la configuration courante en EEPROM.
const struct xWDevRegister * Regs
Definition: device.h:85
volatile uint8_t xState
Le type xState est une variable atomique qui peut évoluer entre 0 et 255.
Definition: state.h:46
uint8_t ucWDevGetThresholdLow(void)
Lecture du seuil de réception du niveau bas (REG_THRESHOLD_L)
uint8_t Address
Definition: device.h:76
Structure de stockage de la configuration du module.
Definition: device.h:92
const uint8_t * pucWDevMid(void)
Lecture des 4 octets de l&#39;identifiant de fabrication (REG_MID)
void vWDevWaitStatus(eWDevStatus eStatus)
Attends que le module passe à l&#39;état Status.
uint8_t ucWDevGetCrystal(void)
Lecture de la capacité d&#39;ajustement de la fréquence du quartz (REG_CRYSTAL_ADJ)
eWDevDataRate
Différentes vitesse de transmission.
Definition: device.h:53
void vWDevSetPnCode_P(const uint8_t *PnCode)
Modification du PN Code.
Definition: device.h:65
void vWDevSetMid(const uint8_t *Mid)
Modifie les 4 octets de l&#39;identifiant de fabrication La modificiation se fait en RAM. Elle est perdue lors d&#39;un RESET. Attention, normalement le MID est fourni par le fabricant du module et n&#39;est pas accessible en écriture. La modification du MID risque de provoquer des conflits sur le réseau (si un autre node a le même MID)
void vWDevRxCB(uint8_t *Data)
Gestionnaire de réception radio Renvoie l&#39;information reçue à la couche supérieure.
void vWDevSetup(const xWDevRegister *Regs, uint8_t Size)
Charge les registres du module radio à partir d&#39;un tableau en RAM.
void vWDevSetDataRate(eWDevDataRate DataRate)
Réinitialise le module radio avec une nouvelle vitesse de transmission.
void vWDevDisable(void)
Arrête la transmission ou la réception.
void vWDevTransmit(const uint8_t *Data, uint8_t Length)
Transmission d&#39;un message.
void vWDevSetSynthLockCount(uint8_t Value)
Modification du délai de verrouillage du synthetiseur par pas de 2 us(REG_SYN_LOCK_CNT) ...
void vWDevSetThresholdHigh(uint8_t Value)
Modification du seuil de réception du niveau haut (REG_THRESHOLD_H)
struct xWDevRegisterTable xWDevRegisterTable
Structure de stockage d&#39;un tableau de registres du module.
Definition: device.h:64
void vWDevSetX13Out(uint8_t flag)
Active ou désactive la broche X13OUT du module radio.
Structure de stockage d&#39;un tableau de registres du module.
Definition: device.h:83
uint8_t ucWDevGetReg(uint8_t Address)
Lecture d&#39;un registre octet du module radio.
void vWDevSleep(bool Sleep)
Endort ou réveille le module afin d&#39;économiser de l&#39;énergie Le module est à l&#39;état statique...
uint8_t ucWDevGetPaBias(void)
Lecture du niveau d&#39;amplification à l&#39;emission (REG_PA)
int8_t iWDevRssi(void)
Evaluation de la qualité de la transmission La valeur renvoyée, entre 0 et 31 permet d&#39;évaluer le bru...
Structure de stockage d&#39;un registre du module.
Definition: device.h:74
uint8_t Size
Definition: device.h:86
eWDevDataRate eWDevGetDataRate(void)
Renvoie la vitesse de transmission.
void vWDevSetup_P(const xWDevRegister *Regs, uint8_t Size)
Charge les registres du module radio à partir d&#39;un tableau en FLASH.
struct xWDevRegister xWDevRegister
Structure de stockage d&#39;un registre du module.
void vWDevSetReg(uint8_t Address, uint8_t Value)
Ecriture dans un registre octet du module radio.