fraisedevice.h 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /*********************************************************************
  2. *
  3. * Fraise device firmware v2.1
  4. *
  5. *********************************************************************
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10. This program is distributed in the hope that it will be useful,
  11. but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. GNU General Public License for more details.
  14. You should have received a copy of the GNU General Public License
  15. along with this program; if not, write to the Free Software Foundation,
  16. Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  17. *********************************************************************
  18. * Copyright (c) Antoine Rousseau 2009 - 2015
  19. ********************************************************************/
  20. #ifndef FRAISEDEV_H
  21. #define FRAISEDEV_H
  22. /** @file */
  23. #include <core.h>
  24. /** @defgroup fraisedevice Fraise device module
  25. * Implements Fraise device protocol on the serial device.
  26. * @{
  27. */
  28. //-------------- SYSTEM -------------
  29. /** @name Initialization */
  30. /** @{ */
  31. /** @brief Init fraise device stack. Normally automatically called by fruitInit().*/
  32. /** Configure serial port as a fraise device. */
  33. void fraiseInit(void);
  34. /** @} */
  35. /** @name Service */
  36. /** @{ */
  37. /** @brief Fraise device service routine. */
  38. /** Check for input data from Fraise.
  39. This function calls input functions when the device receives a message from master.
  40. Normal users shouldn't call fraiseService() directly, but use fruitService() instead. */
  41. void fraiseService(void); // to be called by the main loop.
  42. /** @} */
  43. void fraiseSetID(unsigned char id); // normally you don't have to use this.
  44. void fraiseISR(); //to be called by low priority interrupt.
  45. void fraiseSetInterruptEnable(char enable); //fraiseInit automatically enables interrupt.
  46. char fraiseGetInterruptEnable(void);
  47. //-------------- OUT ----------------
  48. /** @name Fraise output to master */
  49. /** @{ */
  50. /** @brief Put a message into the Fraise TX queue
  51. @param buf Address of the bytes buffer
  52. @param len Number of bytes in the buffer
  53. @return 0 : success
  54. @return -1 : TX queue overload
  55. @return -2 : TX buffer format error
  56. */
  57. char fraiseSend(const unsigned char *buf,unsigned char len);
  58. /** @} */
  59. //-------------- IN ----------------
  60. /** \name Input Functions prototypes
  61. User may define any of these four functions, that are called when the device receives a message. Each input function is for a specific type of message. These functions then parse the received message using one of the Input Routines or Input Macros.
  62. */
  63. //@{
  64. void fraiseReceiveCharBroadcast(); /**< @brief String message to every device. */
  65. void fraiseReceiveBroadcast(); /**< @brief Raw message to every device. */
  66. void fraiseReceiveChar(); /**< @brief String message to this device. */
  67. void fraiseReceive(); /**< @brief Raw message to this device. */
  68. //@}
  69. /** \name Input routines
  70. Use these functions when parsing the current message in Input Functions.
  71. */
  72. //@{
  73. unsigned char fraiseGetChar(); ///< Get next char from receive buffer.
  74. unsigned char fraisePeekChar(); ///< See next char (but keep it in the buffer).
  75. unsigned char fraiseGetIndex(); ///< Get read index in RXbuffer.
  76. unsigned char fraiseGetAt(unsigned char i); ///< Get RXbuffer content at a given place.
  77. unsigned char fraiseGetLen(); ///< Get total length of current receive packet.
  78. void fraiseSendCopy(); ///< Copy the RX buffer to TX buffer, in char mode, from first RX byte to the one before current index (don't add last fraiseGetChar). Used to return queried parameter setting.
  79. #define fraiseGetInt() ((unsigned int)(fraiseGetChar()<<8) + (unsigned int)fraiseGetChar()) ///< @brief Get next 16 bit integer from receive buffer.
  80. #define fraiseGetLong() (((unsigned long)( \
  81. (((unsigned int)fraiseGetChar()) << 8) + fraiseGetChar()) ) << 16 | \
  82. (((unsigned int)fraiseGetChar()) << 8) + fraiseGetChar()) ///< @brief Get next 32 bit long integer from receive buffer.
  83. //@}
  84. /** \name Input macros (parameters set/get)
  85. To be used in a switch() block.
  86. */
  87. //@{
  88. /// in case **n**, assign next byte in the message to **p**
  89. #define PARAM_CHAR(n,p) case n: p = fraiseGetChar();
  90. /// in case **n**, assign next 16 bit integer in the message to **p**
  91. #define PARAM_INT(n,p) case n: p = fraiseGetChar() << 8; p += fraiseGetChar();
  92. /// in case **n**, assign next 32 bit integer in the message to **p**
  93. #define PARAM_LONG(n,p) case n: p = ((unsigned long)( \
  94. (((unsigned int)fraiseGetChar()) << 8) + fraiseGetChar()) ) << 16 | \
  95. (((unsigned int)fraiseGetChar()) << 8) + fraiseGetChar();
  96. /// in case **n**, set **i** to the value of parameter **p**
  97. #define GETPARAM(n, p, i) case n: i = p; break
  98. //@}
  99. /** @}
  100. */
  101. #endif //FRAISEDEV_H