stm32l1xx_it.c 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. /**
  2. ******************************************************************************
  3. * @file stm32l1xx_it.c
  4. * @date 03/01/2015 16:46:03
  5. * @brief Interrupt Service Routines.
  6. ******************************************************************************
  7. *
  8. * COPYRIGHT(c) 2015 STMicroelectronics
  9. *
  10. * Redistribution and use in source and binary forms, with or without modification,
  11. * are permitted provided that the following conditions are met:
  12. * 1. Redistributions of source code must retain the above copyright notice,
  13. * this list of conditions and the following disclaimer.
  14. * 2. Redistributions in binary form must reproduce the above copyright notice,
  15. * this list of conditions and the following disclaimer in the documentation
  16. * and/or other materials provided with the distribution.
  17. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  22. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  24. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  27. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  28. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  29. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32l1xx_hal.h"
  36. #include "stm32l1xx.h"
  37. #include "stm32l1xx_it.h"
  38. /* USER CODE BEGIN 0 */
  39. #include "app.h"
  40. #include "led_blink.h"
  41. #include "queue.h"
  42. #include "main.h"
  43. #include "nexa.h"
  44. #include "sw_fifo.h"
  45. //#define TC_DEBUG
  46. /* USER CODE END 0 */
  47. /* External variables --------------------------------------------------------*/
  48. extern TIM_HandleTypeDef htim2;
  49. extern TIM_HandleTypeDef htim3;
  50. extern UART_HandleTypeDef huart1;
  51. /******************************************************************************/
  52. /* Cortex-M3 Processor Interruption and Exception Handlers */
  53. /******************************************************************************/
  54. /**
  55. * @brief This function handles TIM2 global interrupt.
  56. */
  57. void TIM2_IRQHandler_notworking(void)
  58. {
  59. /* USER CODE BEGIN TIM2_IRQn 0 */
  60. //--------------------------------------------------------------------------------------
  61. // This function is called once every 10uS
  62. //--------------------------------------------------------------------------------------
  63. static unsigned char currValue = 0;
  64. static unsigned short samples = 0;
  65. static unsigned short sendSamples = 0;
  66. static int ladder=4;
  67. const int L_MAX = 8;
  68. const int L_MIN = 0;
  69. const int L_UP_THR = 6;
  70. const int L_DW_THR = 2;
  71. // Sample the pin value
  72. unsigned char value = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_3);
  73. samples++;
  74. if( value ) {
  75. ladder++;
  76. if( currValue == 0 && ladder == L_UP_THR ) {
  77. currValue = 1;
  78. sendSamples = samples;
  79. samples=0;
  80. }
  81. }
  82. else {
  83. ladder--;
  84. if( currValue == 1 && ladder == L_DW_THR ) {
  85. currValue = 0;
  86. sendSamples = samples;
  87. samples=0;
  88. }
  89. }
  90. if( ladder > L_MAX ) ladder=L_MAX;
  91. if( ladder < L_MIN ) ladder=L_MIN;
  92. if( sendSamples ) {
  93. rcvEnQueue(sendSamples * 10);
  94. sendSamples = 0;
  95. }
  96. //--------------------------------------------------------------------------------------
  97. //--------------------------------------------------------------------------------------
  98. /* USER CODE END TIM2_IRQn 0 */
  99. HAL_TIM_IRQHandler(&htim2);
  100. /* USER CODE BEGIN TIM2_IRQn 1 */
  101. /* USER CODE END TIM2_IRQn 1 */
  102. }
  103. void TIM2_IRQHandler(void)
  104. {
  105. /* USER CODE BEGIN TIM2_IRQn 0 */
  106. //--------------------------------------------------------------------------------------
  107. // This function is called once every 10uS
  108. //--------------------------------------------------------------------------------------
  109. static unsigned char currValue = 0;
  110. static unsigned short samples = 0;
  111. static unsigned short newSamples = 0;
  112. // Sample the pin value
  113. unsigned char value = HAL_GPIO_ReadPin(GPIOB,GPIO_PIN_3);
  114. #ifdef TC_DEBUG
  115. if( logCounter < (LOG_SIZE-1) ) {
  116. //nexaData[logCounter++] = value;
  117. }
  118. #endif
  119. if( value == currValue ) {
  120. samples++;
  121. samples+=newSamples;
  122. newSamples=0;
  123. }
  124. else {
  125. newSamples++;
  126. }
  127. if( newSamples == 6 ) {
  128. #ifdef TC_DEBUG
  129. if( logCounter < (LOG_SIZE-1) ) {
  130. nexaData[logCounter++] = samples * 10;
  131. }
  132. else {
  133. //logCounter--;
  134. }
  135. #else
  136. rcvEnQueue(samples * 10);
  137. #endif
  138. samples = newSamples;
  139. newSamples = 0;
  140. currValue = value;
  141. }
  142. //--------------------------------------------------------------------------------------
  143. //--------------------------------------------------------------------------------------
  144. /* USER CODE END TIM2_IRQn 0 */
  145. HAL_TIM_IRQHandler(&htim2);
  146. /* USER CODE BEGIN TIM2_IRQn 1 */
  147. /* USER CODE END TIM2_IRQn 1 */
  148. }
  149. /**
  150. * @brief This function handles System tick timer.
  151. */
  152. void SysTick_Handler(void)
  153. {
  154. /* USER CODE BEGIN SysTick_IRQn 0 */
  155. const int LED_BLINK_START_VALUE = 200;
  156. static int i=200;
  157. if( (--i) == 0 ) {
  158. i= LED_BLINK_START_VALUE;
  159. led_interrupt();
  160. }
  161. /* USER CODE END SysTick_IRQn 0 */
  162. HAL_IncTick();
  163. HAL_SYSTICK_IRQHandler();
  164. /* USER CODE BEGIN SysTick_IRQn 1 */
  165. /* USER CODE END SysTick_IRQn 1 */
  166. }
  167. /**
  168. * @brief This function handles USART1 global interrupt.
  169. */
  170. void USART1_IRQHandler(void)
  171. {
  172. /* USER CODE BEGIN USART1_IRQn 0 */
  173. usartInterrupt();
  174. return;
  175. #pragma diag_suppress=Pe111
  176. /* USER CODE END USART1_IRQn 0 */
  177. HAL_UART_IRQHandler(&huart1);
  178. /* USER CODE BEGIN USART1_IRQn 1 */
  179. #pragma diag_default=Pe111
  180. /* USER CODE END USART1_IRQn 1 */
  181. }
  182. /**
  183. * @brief This function handles TIM3 global interrupt.
  184. */
  185. void TIM3_IRQHandler(void)
  186. {
  187. /* USER CODE BEGIN TIM3_IRQn 0 */
  188. tim3mSTick++;
  189. /* USER CODE END TIM3_IRQn 0 */
  190. HAL_TIM_IRQHandler(&htim3);
  191. /* USER CODE BEGIN TIM3_IRQn 1 */
  192. /* USER CODE END TIM3_IRQn 1 */
  193. }
  194. /* USER CODE BEGIN 1 */
  195. /* USER CODE END 1 */
  196. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/