hal_pal_lld.h 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451
  1. /*
  2. ChibiOS - Copyright (C) 2006..2018 Giovanni Di Sirio
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. /**
  14. * @file hal_pal_lld.h
  15. * @brief PLATFORM PAL subsystem low level driver header.
  16. *
  17. * @addtogroup PAL
  18. * @{
  19. */
  20. #ifndef HAL_PAL_LLD_H
  21. #define HAL_PAL_LLD_H
  22. #if (HAL_USE_PAL == TRUE) || defined(__DOXYGEN__)
  23. /*===========================================================================*/
  24. /* Unsupported modes and specific modes */
  25. /*===========================================================================*/
  26. /* Specifies palInit() without parameter, required until all platforms will
  27. be updated to the new style.*/
  28. #define PAL_NEW_INIT
  29. /*===========================================================================*/
  30. /* I/O Ports Types and constants. */
  31. /*===========================================================================*/
  32. /**
  33. * @name Port related definitions
  34. * @{
  35. */
  36. /**
  37. * @brief Width, in bits, of an I/O port.
  38. */
  39. #define PAL_IOPORTS_WIDTH 16U
  40. /**
  41. * @brief Whole port mask.
  42. * @details This macro specifies all the valid bits into a port.
  43. */
  44. #define PAL_WHOLE_PORT ((ioportmask_t)0xFFFFU)
  45. /** @} */
  46. /**
  47. * @name Line handling macros
  48. * @{
  49. */
  50. /**
  51. * @brief Forms a line identifier.
  52. * @details A port/pad pair are encoded into an @p ioline_t type. The encoding
  53. * of this type is platform-dependent.
  54. */
  55. #define PAL_LINE(port, pad) \
  56. ((ioline_t)((uint32_t)(port)) | ((uint32_t)(pad)))
  57. /**
  58. * @brief Decodes a port identifier from a line identifier.
  59. */
  60. #define PAL_PORT(line) \
  61. ((stm32_gpio_t *)(((uint32_t)(line)) & 0xFFFFFFF0U))
  62. /**
  63. * @brief Decodes a pad identifier from a line identifier.
  64. */
  65. #define PAL_PAD(line) \
  66. ((uint32_t)((uint32_t)(line) & 0x0000000FU))
  67. /**
  68. * @brief Value identifying an invalid line.
  69. */
  70. #define PAL_NOLINE 0U
  71. /** @} */
  72. /**
  73. * @brief Generic I/O ports static initializer.
  74. * @details An instance of this structure must be passed to @p palInit() at
  75. * system startup time in order to initialized the digital I/O
  76. * subsystem. This represents only the initial setup, specific pads
  77. * or whole ports can be reprogrammed at later time.
  78. * @note Implementations may extend this structure to contain more,
  79. * architecture dependent, fields.
  80. */
  81. typedef struct {
  82. } PALConfig;
  83. /**
  84. * @brief Digital I/O port sized unsigned type.
  85. */
  86. typedef uint32_t ioportmask_t;
  87. /**
  88. * @brief Digital I/O modes.
  89. */
  90. typedef uint32_t iomode_t;
  91. /**
  92. * @brief Type of an I/O line.
  93. */
  94. typedef uint32_t ioline_t;
  95. /**
  96. * @brief Port Identifier.
  97. * @details This type can be a scalar or some kind of pointer, do not make
  98. * any assumption about it, use the provided macros when populating
  99. * variables of this type.
  100. */
  101. typedef uint32_t ioportid_t;
  102. /**
  103. * @brief Type of an pad identifier.
  104. */
  105. typedef uint32_t iopadid_t;
  106. /*===========================================================================*/
  107. /* I/O Ports Identifiers. */
  108. /*===========================================================================*/
  109. /**
  110. * @brief First I/O port identifier.
  111. * @details Low level drivers can define multiple ports, it is suggested to
  112. * use this naming convention.
  113. */
  114. #define IOPORT1 0
  115. /*===========================================================================*/
  116. /* Implementation, some of the following macros could be implemented as */
  117. /* functions, if so please put them in pal_lld.c. */
  118. /*===========================================================================*/
  119. /**
  120. * @brief Low level PAL subsystem initialization.
  121. *
  122. * @notapi
  123. */
  124. #define pal_lld_init() _pal_lld_init()
  125. /**
  126. * @brief Reads the physical I/O port states.
  127. *
  128. * @param[in] port port identifier
  129. * @return The port bits.
  130. *
  131. * @notapi
  132. */
  133. #define pal_lld_readport(port) 0U
  134. /**
  135. * @brief Reads the output latch.
  136. * @details The purpose of this function is to read back the latched output
  137. * value.
  138. *
  139. * @param[in] port port identifier
  140. * @return The latched logical states.
  141. *
  142. * @notapi
  143. */
  144. #define pal_lld_readlatch(port) 0U
  145. /**
  146. * @brief Writes a bits mask on a I/O port.
  147. *
  148. * @param[in] port port identifier
  149. * @param[in] bits bits to be written on the specified port
  150. *
  151. * @notapi
  152. */
  153. #define pal_lld_writeport(port, bits) \
  154. do { \
  155. (void)port; \
  156. (void)bits; \
  157. } while (false)
  158. /**
  159. * @brief Sets a bits mask on a I/O port.
  160. * @note The @ref PAL provides a default software implementation of this
  161. * functionality, implement this function if can optimize it by using
  162. * special hardware functionalities or special coding.
  163. *
  164. * @param[in] port port identifier
  165. * @param[in] bits bits to be ORed on the specified port
  166. *
  167. * @notapi
  168. */
  169. #define pal_lld_setport(port, bits) \
  170. do { \
  171. (void)port; \
  172. (void)bits; \
  173. } while (false)
  174. /**
  175. * @brief Clears a bits mask on a I/O port.
  176. * @note The @ref PAL provides a default software implementation of this
  177. * functionality, implement this function if can optimize it by using
  178. * special hardware functionalities or special coding.
  179. *
  180. * @param[in] port port identifier
  181. * @param[in] bits bits to be cleared on the specified port
  182. *
  183. * @notapi
  184. */
  185. #define pal_lld_clearport(port, bits) \
  186. do { \
  187. (void)port; \
  188. (void)bits; \
  189. } while (false)
  190. /**
  191. * @brief Toggles a bits mask on a I/O port.
  192. * @note The @ref PAL provides a default software implementation of this
  193. * functionality, implement this function if can optimize it by using
  194. * special hardware functionalities or special coding.
  195. *
  196. * @param[in] port port identifier
  197. * @param[in] bits bits to be XORed on the specified port
  198. *
  199. * @notapi
  200. */
  201. #define pal_lld_toggleport(port, bits) \
  202. do { \
  203. (void)port; \
  204. (void)bits; \
  205. } while (false)
  206. /**
  207. * @brief Reads a group of bits.
  208. * @note The @ref PAL provides a default software implementation of this
  209. * functionality, implement this function if can optimize it by using
  210. * special hardware functionalities or special coding.
  211. *
  212. * @param[in] port port identifier
  213. * @param[in] mask group mask
  214. * @param[in] offset group bit offset within the port
  215. * @return The group logical states.
  216. *
  217. * @notapi
  218. */
  219. #define pal_lld_readgroup(port, mask, offset) 0U
  220. /**
  221. * @brief Writes a group of bits.
  222. * @note The @ref PAL provides a default software implementation of this
  223. * functionality, implement this function if can optimize it by using
  224. * special hardware functionalities or special coding.
  225. *
  226. * @param[in] port port identifier
  227. * @param[in] mask group mask
  228. * @param[in] offset group bit offset within the port
  229. * @param[in] bits bits to be written. Values exceeding the group width
  230. * are masked.
  231. *
  232. * @notapi
  233. */
  234. #define pal_lld_writegroup(port, mask, offset, bits) \
  235. do { \
  236. (void)port; \
  237. (void)mask; \
  238. (void)offset; \
  239. (void)bits; \
  240. } while (false)
  241. /**
  242. * @brief Pads group mode setup.
  243. * @details This function programs a pads group belonging to the same port
  244. * with the specified mode.
  245. * @note Programming an unknown or unsupported mode is silently ignored.
  246. *
  247. * @param[in] port port identifier
  248. * @param[in] mask group mask
  249. * @param[in] offset group bit offset within the port
  250. * @param[in] mode group mode
  251. *
  252. * @notapi
  253. */
  254. #define pal_lld_setgroupmode(port, mask, offset, mode) \
  255. _pal_lld_setgroupmode(port, mask << offset, mode)
  256. /**
  257. * @brief Reads a logical state from an I/O pad.
  258. * @note The @ref PAL provides a default software implementation of this
  259. * functionality, implement this function if can optimize it by using
  260. * special hardware functionalities or special coding.
  261. *
  262. * @param[in] port port identifier
  263. * @param[in] pad pad number within the port
  264. * @return The logical state.
  265. * @retval PAL_LOW low logical state.
  266. * @retval PAL_HIGH high logical state.
  267. *
  268. * @notapi
  269. */
  270. #define pal_lld_readpad(port, pad) PAL_LOW
  271. /**
  272. * @brief Writes a logical state on an output pad.
  273. * @note This function is not meant to be invoked directly by the
  274. * application code.
  275. * @note The @ref PAL provides a default software implementation of this
  276. * functionality, implement this function if can optimize it by using
  277. * special hardware functionalities or special coding.
  278. *
  279. * @param[in] port port identifier
  280. * @param[in] pad pad number within the port
  281. * @param[in] bit logical value, the value must be @p PAL_LOW or
  282. * @p PAL_HIGH
  283. *
  284. * @notapi
  285. */
  286. #define pal_lld_writepad(port, pad, bit) \
  287. do { \
  288. (void)port; \
  289. (void)pad; \
  290. (void)bit; \
  291. } while (false)
  292. /**
  293. * @brief Sets a pad logical state to @p PAL_HIGH.
  294. * @note The @ref PAL provides a default software implementation of this
  295. * functionality, implement this function if can optimize it by using
  296. * special hardware functionalities or special coding.
  297. *
  298. * @param[in] port port identifier
  299. * @param[in] pad pad number within the port
  300. *
  301. * @notapi
  302. */
  303. #define pal_lld_setpad(port, pad) \
  304. do { \
  305. (void)port; \
  306. (void)pad; \
  307. } while (false)
  308. /**
  309. * @brief Clears a pad logical state to @p PAL_LOW.
  310. * @note The @ref PAL provides a default software implementation of this
  311. * functionality, implement this function if can optimize it by using
  312. * special hardware functionalities or special coding.
  313. *
  314. * @param[in] port port identifier
  315. * @param[in] pad pad number within the port
  316. *
  317. * @notapi
  318. */
  319. #define pal_lld_clearpad(port, pad) \
  320. do { \
  321. (void)port; \
  322. (void)pad; \
  323. } while (false)
  324. /**
  325. * @brief Toggles a pad logical state.
  326. * @note The @ref PAL provides a default software implementation of this
  327. * functionality, implement this function if can optimize it by using
  328. * special hardware functionalities or special coding.
  329. *
  330. * @param[in] port port identifier
  331. * @param[in] pad pad number within the port
  332. *
  333. * @notapi
  334. */
  335. #define pal_lld_togglepad(port, pad) \
  336. do { \
  337. (void)port; \
  338. (void)pad; \
  339. } while (false)
  340. /**
  341. * @brief Pad mode setup.
  342. * @details This function programs a pad with the specified mode.
  343. * @note The @ref PAL provides a default software implementation of this
  344. * functionality, implement this function if can optimize it by using
  345. * special hardware functionalities or special coding.
  346. * @note Programming an unknown or unsupported mode is silently ignored.
  347. *
  348. * @param[in] port port identifier
  349. * @param[in] pad pad number within the port
  350. * @param[in] mode pad mode
  351. *
  352. * @notapi
  353. */
  354. #define pal_lld_setpadmode(port, pad, mode) \
  355. do { \
  356. (void)port; \
  357. (void)pad; \
  358. (void)mode; \
  359. } while (false)
  360. /**
  361. * @brief Returns a PAL event structure associated to a pad.
  362. *
  363. * @param[in] port port identifier
  364. * @param[in] pad pad number within the port
  365. *
  366. * @notapi
  367. */
  368. #define pal_lld_get_pad_event(port, pad) \
  369. &_pal_events[0]; (void)(port); (void)pad
  370. /**
  371. * @brief Returns a PAL event structure associated to a line.
  372. *
  373. * @param[in] line line identifier
  374. *
  375. * @notapi
  376. */
  377. #define pal_lld_get_line_event(line) \
  378. &_pal_events[0]; (void)line
  379. #if !defined(__DOXYGEN__)
  380. #if (PAL_USE_WAIT == TRUE) || (PAL_USE_CALLBACKS == TRUE)
  381. extern palevent_t _pal_events[1];
  382. #endif
  383. #endif
  384. #ifdef __cplusplus
  385. extern "C" {
  386. #endif
  387. void _pal_lld_init(void);
  388. void _pal_lld_setgroupmode(ioportid_t port,
  389. ioportmask_t mask,
  390. iomode_t mode);
  391. #ifdef __cplusplus
  392. }
  393. #endif
  394. #endif /* HAL_USE_PAL == TRUE */
  395. #endif /* HAL_PAL_LLD_H */
  396. /** @} */