Microprocessor and peripheral 2 assignments for AUTH
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

195 lines
6.1 KiB

  1. /*!
  2. * \file onewire_uart.h
  3. * \brief
  4. * A target independent 1-wire implementation using a microprocessor's uart
  5. * for bit timing
  6. * \note
  7. * This 1-wire implementation is based on MCU UART io functionality. In order
  8. * to work it needs:
  9. * 1) A Open drain tx and floating(or pull-up) rx UART pin configuration with both pins
  10. * connected to the 1-wire bus wire
  11. * 2) A Transmit function even in blocking/polling mode
  12. * 3) A receive function even in blocking/polling mode
  13. * 4) A baudrate set function
  14. *
  15. * Author: Christos Choutouridis AEM: 8997
  16. * email : <cchoutou@ece.auth.gr>
  17. *
  18. */
  19. #ifndef __onewire_uart_h__
  20. #define __onewire_uart_h__
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24. #include "driver_types.h"
  25. #include <string.h>
  26. /* ================ General Defines ====================*/
  27. typedef uint16_t (*ow_uart_rw_ft) (uint8_t); /*!< UART read-write function pointer */
  28. typedef drv_status_en (*ow_uart_br_ft) (uint32_t); /*!< UART baudrate modify function pointer */
  29. /*!
  30. * 1-Wire operational state
  31. */
  32. typedef enum {
  33. OWS_RESET = 0, /*!< 1-Wire bus is during in Reset state */
  34. OWS_OPER /*!< 1-Wire bus is during normal operation */
  35. }ow_uart_state_en;
  36. /*!
  37. * 1-Wire UART baudrate table
  38. */
  39. typedef struct {
  40. uint32_t reset; /*!< Baudrate during reset */
  41. uint32_t oper; /*!< Baudrate during normal operation */
  42. uint32_t current; /*!< The current baudrate to use as flag */
  43. }ow_uart_br_t;
  44. /*!
  45. * 1-Wire driver function callback pointers
  46. * \note
  47. * The function in this structure provided from the low level driver (usually).
  48. */
  49. typedef struct {
  50. ow_uart_rw_ft rw; /*!< Pointer UART read-write function */
  51. ow_uart_br_ft br; /*!< Pointer to UART baudrate function */
  52. }ow_uart_io_t;
  53. /*!
  54. * 1-Wire Data type
  55. */
  56. typedef struct {
  57. ow_uart_io_t io; /*!< Callback pointers and direction state */
  58. uint32_t timing; /*!< The selected timing mode */
  59. ow_uart_br_t baudrate; /*!< The current baudrate configuration */
  60. drv_status_en status; /*!< Toolbox driver status */
  61. }ow_uart_t;
  62. /*
  63. * ============ Helper Macros =============
  64. */
  65. /*!
  66. * 1-Wire speed
  67. */
  68. #define OW_UART_T_STANDARD (0)
  69. #define OW_UART_T_OVERDRIVE (1)
  70. /*!
  71. * Check if the timing is a valid \ref ow_uart_timing_en value
  72. */
  73. #define _ow_uart_is_timings(_t_) ( ((_t_) == OW_UART_T_STANDARD) || ((_t_) == OW_UART_T_OVERDRIVE) )
  74. /*
  75. * Timing Diagram
  76. * --------------------------------------------------
  77. * Based on Application Note 214 (www.maxim-ic.com)
  78. *
  79. * --- ---- - - - -------
  80. * Reset \ / \ X X X /
  81. * -------------------- - - - -
  82. * RS: | | | | | | | | | | |
  83. * bit: st 0 1 2 3 4 5 6 7 st
  84. * < ---------- 1024/174 usec ------------->
  85. *
  86. * 8 bits, no parity, 1 stop
  87. * Standard: Overdrive :
  88. * BR: 9600, BR: 57600
  89. * TX: 0xF0, TX: 0xF8
  90. * RX: 0xF0 not present RX: 0xF8 not present
  91. * less if present less if present
  92. *
  93. *
  94. * --- --------------------------------------
  95. * Write 1 \ /
  96. * ----
  97. * RS: | | | | | | | | | | |
  98. * bit: st 0 1 2 3 4 5 6 7 st
  99. * < ------------- 87/11 usec ------------->
  100. * 8 bits, no parity, 1 stop
  101. * standard: BR: 115200 Overdrive: BR: 921600
  102. * TX: 0xFF
  103. * RX: 0xFF
  104. *
  105. * --- ------
  106. * Write 0 \ /
  107. * -------------------------------------
  108. * RS: | | | | | | | | | | |
  109. * bit: st 0 1 2 3 4 5 6 7 st
  110. * < ------------- 87/11 usec ------------->
  111. * 8 bits, no parity, 1 stop
  112. * standard: BR: 115200 Overdrive: BR: 921600
  113. * TX: 0x00
  114. * RX: 0x00
  115. *
  116. * --- - - - - - - - - - - - ------
  117. * Read \ / X X X X X X X X X X X X X X X /
  118. * ---- - - - - - - - - - - -
  119. * RS: | | | | | | | | | | |
  120. * bit: st 0 1 2 3 4 5 6 7 st
  121. * < ------------- 87/11 usec ------------->
  122. * ^
  123. * |
  124. * Master sample
  125. *
  126. * 8 bits, no parity, 1 stop
  127. * standard: BR: 115200 Overdrive: BR: 921600
  128. * TX: 0xFF
  129. * RX: {1 - 0xFF, 0 - [0x00 - 0xFE] }
  130. *
  131. */
  132. #define _ow_baudrate_standard(_br_) \
  133. do { \
  134. _br_.reset = 9600; \
  135. _br_.oper = 115200; \
  136. _br_.current = 9600; \
  137. } while (0)
  138. #define _ow_baudrate_overdrive(_br_) \
  139. do { \
  140. _br_.reset = 115200; \
  141. _br_.oper = 921600; \
  142. _br_.current = 115200; \
  143. } while (0)
  144. /*
  145. * ============= PUBLIC ALCD API =============
  146. */
  147. /*
  148. * Link and Glue functions
  149. */
  150. void ow_uart_link_rw (ow_uart_t *ow, ow_uart_rw_ft tx); /*!< link driver's read-write function */
  151. void ow_uart_link_br (ow_uart_t *ow, ow_uart_br_ft br); /*!< link driver's baudrate function*/
  152. /*
  153. * Set functions
  154. */
  155. void ow_uart_set_timing (ow_uart_t *ow, uint32_t owt); /*!< set 1-wire timing mode */
  156. /*
  157. * User Functions
  158. */
  159. void ow_uart_deinit (ow_uart_t *ow); /*!< for compatibility */
  160. drv_status_en ow_uart_init (ow_uart_t *ow); /*!< for compatibility */
  161. drv_status_en
  162. ow_uart_reset (ow_uart_t *ow);
  163. uint8_t ow_uart_rx (ow_uart_t *ow);
  164. void ow_uart_tx (ow_uart_t *ow, byte_t byte);
  165. uint8_t ow_uart_rw (ow_uart_t *ow, byte_t byte);
  166. drv_status_en
  167. ow_uart_search (ow_uart_t *ow, uint8_t *romid);
  168. #ifdef __cplusplus
  169. }
  170. #endif
  171. #endif /* #ifndef __onewire_uart_h__ */