Implement a secure ICS protocol targeting LoRa Node151 microcontroller for controlling irrigation.
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.
 
 
 
 
 
 

245 lines
7.3 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f1xx_hal_pcd_ex.c
  4. * @author MCD Application Team
  5. * @brief PCD Extended HAL module driver.
  6. * This file provides firmware functions to manage the following
  7. * functionalities of the USB Peripheral Controller:
  8. * + Extended features functions
  9. *
  10. ******************************************************************************
  11. * @attention
  12. *
  13. * <h2><center>&copy; Copyright (c) 2016 STMicroelectronics.
  14. * All rights reserved.</center></h2>
  15. *
  16. * This software component is licensed by ST under BSD 3-Clause license,
  17. * the "License"; You may not use this file except in compliance with the
  18. * License. You may obtain a copy of the License at:
  19. * opensource.org/licenses/BSD-3-Clause
  20. *
  21. ******************************************************************************
  22. */
  23. /* Includes ------------------------------------------------------------------*/
  24. #include "stm32f1xx_hal.h"
  25. /** @addtogroup STM32F1xx_HAL_Driver
  26. * @{
  27. */
  28. /** @defgroup PCDEx PCDEx
  29. * @brief PCD Extended HAL module driver
  30. * @{
  31. */
  32. #ifdef HAL_PCD_MODULE_ENABLED
  33. #if defined (USB) || defined (USB_OTG_FS)
  34. /* Private types -------------------------------------------------------------*/
  35. /* Private variables ---------------------------------------------------------*/
  36. /* Private constants ---------------------------------------------------------*/
  37. /* Private macros ------------------------------------------------------------*/
  38. /* Private functions ---------------------------------------------------------*/
  39. /* Exported functions --------------------------------------------------------*/
  40. /** @defgroup PCDEx_Exported_Functions PCDEx Exported Functions
  41. * @{
  42. */
  43. /** @defgroup PCDEx_Exported_Functions_Group1 Peripheral Control functions
  44. * @brief PCDEx control functions
  45. *
  46. @verbatim
  47. ===============================================================================
  48. ##### Extended features functions #####
  49. ===============================================================================
  50. [..] This section provides functions allowing to:
  51. (+) Update FIFO configuration
  52. @endverbatim
  53. * @{
  54. */
  55. #if defined (USB_OTG_FS)
  56. /**
  57. * @brief Set Tx FIFO
  58. * @param hpcd PCD handle
  59. * @param fifo The number of Tx fifo
  60. * @param size Fifo size
  61. * @retval HAL status
  62. */
  63. HAL_StatusTypeDef HAL_PCDEx_SetTxFiFo(PCD_HandleTypeDef *hpcd, uint8_t fifo, uint16_t size)
  64. {
  65. uint8_t i;
  66. uint32_t Tx_Offset;
  67. /* TXn min size = 16 words. (n : Transmit FIFO index)
  68. When a TxFIFO is not used, the Configuration should be as follows:
  69. case 1 : n > m and Txn is not used (n,m : Transmit FIFO indexes)
  70. --> Txm can use the space allocated for Txn.
  71. case2 : n < m and Txn is not used (n,m : Transmit FIFO indexes)
  72. --> Txn should be configured with the minimum space of 16 words
  73. The FIFO is used optimally when used TxFIFOs are allocated in the top
  74. of the FIFO.Ex: use EP1 and EP2 as IN instead of EP1 and EP3 as IN ones.
  75. When DMA is used 3n * FIFO locations should be reserved for internal DMA registers */
  76. Tx_Offset = hpcd->Instance->GRXFSIZ;
  77. if (fifo == 0U)
  78. {
  79. hpcd->Instance->DIEPTXF0_HNPTXFSIZ = ((uint32_t)size << 16) | Tx_Offset;
  80. }
  81. else
  82. {
  83. Tx_Offset += (hpcd->Instance->DIEPTXF0_HNPTXFSIZ) >> 16;
  84. for (i = 0U; i < (fifo - 1U); i++)
  85. {
  86. Tx_Offset += (hpcd->Instance->DIEPTXF[i] >> 16);
  87. }
  88. /* Multiply Tx_Size by 2 to get higher performance */
  89. hpcd->Instance->DIEPTXF[fifo - 1U] = ((uint32_t)size << 16) | Tx_Offset;
  90. }
  91. return HAL_OK;
  92. }
  93. /**
  94. * @brief Set Rx FIFO
  95. * @param hpcd PCD handle
  96. * @param size Size of Rx fifo
  97. * @retval HAL status
  98. */
  99. HAL_StatusTypeDef HAL_PCDEx_SetRxFiFo(PCD_HandleTypeDef *hpcd, uint16_t size)
  100. {
  101. hpcd->Instance->GRXFSIZ = size;
  102. return HAL_OK;
  103. }
  104. #endif /* defined (USB_OTG_FS) */
  105. #if defined (USB)
  106. /**
  107. * @brief Configure PMA for EP
  108. * @param hpcd Device instance
  109. * @param ep_addr endpoint address
  110. * @param ep_kind endpoint Kind
  111. * USB_SNG_BUF: Single Buffer used
  112. * USB_DBL_BUF: Double Buffer used
  113. * @param pmaadress: EP address in The PMA: In case of single buffer endpoint
  114. * this parameter is 16-bit value providing the address
  115. * in PMA allocated to endpoint.
  116. * In case of double buffer endpoint this parameter
  117. * is a 32-bit value providing the endpoint buffer 0 address
  118. * in the LSB part of 32-bit value and endpoint buffer 1 address
  119. * in the MSB part of 32-bit value.
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_PCDEx_PMAConfig(PCD_HandleTypeDef *hpcd, uint16_t ep_addr,
  123. uint16_t ep_kind, uint32_t pmaadress)
  124. {
  125. PCD_EPTypeDef *ep;
  126. /* initialize ep structure*/
  127. if ((0x80U & ep_addr) == 0x80U)
  128. {
  129. ep = &hpcd->IN_ep[ep_addr & EP_ADDR_MSK];
  130. }
  131. else
  132. {
  133. ep = &hpcd->OUT_ep[ep_addr];
  134. }
  135. /* Here we check if the endpoint is single or double Buffer*/
  136. if (ep_kind == PCD_SNG_BUF)
  137. {
  138. /* Single Buffer */
  139. ep->doublebuffer = 0U;
  140. /* Configure the PMA */
  141. ep->pmaadress = (uint16_t)pmaadress;
  142. }
  143. else /* USB_DBL_BUF */
  144. {
  145. /* Double Buffer Endpoint */
  146. ep->doublebuffer = 1U;
  147. /* Configure the PMA */
  148. ep->pmaaddr0 = (uint16_t)(pmaadress & 0xFFFFU);
  149. ep->pmaaddr1 = (uint16_t)((pmaadress & 0xFFFF0000U) >> 16);
  150. }
  151. return HAL_OK;
  152. }
  153. /**
  154. * @brief Software Device Connection,
  155. * this function is not required by USB OTG FS peripheral, it is used
  156. * only by USB Device FS peripheral.
  157. * @param hpcd PCD handle
  158. * @param state connection state (0 : disconnected / 1: connected)
  159. * @retval None
  160. */
  161. __weak void HAL_PCDEx_SetConnectionState(PCD_HandleTypeDef *hpcd, uint8_t state)
  162. {
  163. /* Prevent unused argument(s) compilation warning */
  164. UNUSED(hpcd);
  165. UNUSED(state);
  166. /* NOTE : This function Should not be modified, when the callback is needed,
  167. the HAL_PCDEx_SetConnectionState could be implemented in the user file
  168. */
  169. }
  170. #endif /* defined (USB) */
  171. /**
  172. * @brief Send LPM message to user layer callback.
  173. * @param hpcd PCD handle
  174. * @param msg LPM message
  175. * @retval HAL status
  176. */
  177. __weak void HAL_PCDEx_LPM_Callback(PCD_HandleTypeDef *hpcd, PCD_LPM_MsgTypeDef msg)
  178. {
  179. /* Prevent unused argument(s) compilation warning */
  180. UNUSED(hpcd);
  181. UNUSED(msg);
  182. /* NOTE : This function should not be modified, when the callback is needed,
  183. the HAL_PCDEx_LPM_Callback could be implemented in the user file
  184. */
  185. }
  186. /**
  187. * @brief Send BatteryCharging message to user layer callback.
  188. * @param hpcd PCD handle
  189. * @param msg LPM message
  190. * @retval HAL status
  191. */
  192. __weak void HAL_PCDEx_BCD_Callback(PCD_HandleTypeDef *hpcd, PCD_BCD_MsgTypeDef msg)
  193. {
  194. /* Prevent unused argument(s) compilation warning */
  195. UNUSED(hpcd);
  196. UNUSED(msg);
  197. /* NOTE : This function should not be modified, when the callback is needed,
  198. the HAL_PCDEx_BCD_Callback could be implemented in the user file
  199. */
  200. }
  201. /**
  202. * @}
  203. */
  204. /**
  205. * @}
  206. */
  207. #endif /* defined (USB) || defined (USB_OTG_FS) */
  208. #endif /* HAL_PCD_MODULE_ENABLED */
  209. /**
  210. * @}
  211. */
  212. /**
  213. * @}
  214. */
  215. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/