freertos.c 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. /**
  2. ******************************************************************************
  3. * File Name : freertos.c
  4. * Description : Code for freertos applications
  5. ******************************************************************************
  6. *
  7. * Copyright (c) 2017 STMicroelectronics International N.V.
  8. * All rights reserved.
  9. *
  10. * Redistribution and use in source and binary forms, with or without
  11. * modification, are permitted, provided that the following conditions are met:
  12. *
  13. * 1. Redistribution of source code must retain the above copyright notice,
  14. * this list of conditions and the following disclaimer.
  15. * 2. Redistributions in binary form must reproduce the above copyright notice,
  16. * this list of conditions and the following disclaimer in the documentation
  17. * and/or other materials provided with the distribution.
  18. * 3. Neither the name of STMicroelectronics nor the names of other
  19. * contributors to this software may be used to endorse or promote products
  20. * derived from this software without specific written permission.
  21. * 4. This software, including modifications and/or derivative works of this
  22. * software, must execute solely and exclusively on microcontroller or
  23. * microprocessor devices manufactured by or for STMicroelectronics.
  24. * 5. Redistribution and use of this software other than as permitted under
  25. * this license is void and will automatically terminate your rights under
  26. * this license.
  27. *
  28. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  29. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  30. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  31. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  32. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  33. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  34. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  35. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  36. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  37. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  38. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  39. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  40. *
  41. ******************************************************************************
  42. */
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "FreeRTOS.h"
  45. #include "task.h"
  46. #include "cmsis_os.h"
  47. /* USER CODE BEGIN Includes */
  48. #include "gpio.h"
  49. #include "RTC.h"
  50. #include "Eprom.h"
  51. /* USER CODE END Includes */
  52. /* Variables -----------------------------------------------------------------*/
  53. osThreadId defaultTaskHandle;
  54. osMutexId m_tableHandle;
  55. osMutexId m_changeHandle;
  56. /* USER CODE BEGIN Variables */
  57. int8_t g_change; // variable globale savoir si il y a du changement
  58. uint8_t table[12]; //tableau des changement au cours de cette heure;
  59. uint8_t Xms; // temps
  60. uint32_t heure;
  61. uint32_t ancienheure;
  62. /* USER CODE END Variables */
  63. /* Function prototypes -------------------------------------------------------*/
  64. void StartDefaultTask(void const * argument);
  65. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  66. /* USER CODE BEGIN FunctionPrototypes */
  67. void eteint(int i, int Etat);
  68. void allume(int i, int Etat);
  69. void PollHeure();
  70. /* USER CODE END FunctionPrototypes */
  71. /* Hook prototypes */
  72. /* Init FreeRTOS */
  73. void MX_FREERTOS_Init(void) {
  74. /* USER CODE BEGIN Init */
  75. /* USER CODE END Init */
  76. /* Create the mutex(es) */
  77. /* definition and creation of m_table */
  78. osMutexDef(m_table);
  79. m_tableHandle = osMutexCreate(osMutex(m_table));
  80. /* definition and creation of m_change */
  81. osMutexDef(m_change);
  82. m_changeHandle = osMutexCreate(osMutex(m_change));
  83. /* USER CODE BEGIN RTOS_MUTEX */
  84. /* add mutexes, ... */
  85. /* USER CODE END RTOS_MUTEX */
  86. /* USER CODE BEGIN RTOS_SEMAPHORES */
  87. /* add semaphores, ... */
  88. /* USER CODE END RTOS_SEMAPHORES */
  89. /* USER CODE BEGIN RTOS_TIMERS */
  90. /* start timers, add new ones, ... */
  91. /* USER CODE END RTOS_TIMERS */
  92. /* Create the thread(s) */
  93. /* definition and creation of defaultTask */
  94. osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 128);
  95. defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL);
  96. /* USER CODE BEGIN RTOS_THREADS */
  97. /* add threads, ... */
  98. /* USER CODE END RTOS_THREADS */
  99. /* USER CODE BEGIN RTOS_QUEUES */
  100. /* add queues, ... */
  101. /* USER CODE END RTOS_QUEUES */
  102. }
  103. /* StartDefaultTask function */
  104. void StartDefaultTask(void const * argument)
  105. {
  106. /* USER CODE BEGIN StartDefaultTask */
  107. /* Infinite loop */
  108. for(;;)
  109. {
  110. osDelay(1);
  111. }
  112. /* USER CODE END StartDefaultTask */
  113. }
  114. /* USER CODE BEGIN Application */
  115. void allume(int i, int Etat) {
  116. if (Etat == 1) {
  117. if (table[0] == Etat)
  118. HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_SET);
  119. if (table[1] == Etat)
  120. HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_SET);
  121. if (table[2] == Etat)
  122. HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_SET);
  123. if (table[3] == Etat)
  124. HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_SET);
  125. if (table[4] == Etat)
  126. HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_SET);
  127. if (table[5] == Etat)
  128. HAL_GPIO_WritePin(S6_GPIO_Port, S6_Pin, GPIO_PIN_SET);
  129. if (table[6] == Etat)
  130. HAL_GPIO_WritePin(S7_GPIO_Port, S7_Pin, GPIO_PIN_SET);
  131. if (table[7] == Etat)
  132. HAL_GPIO_WritePin(S8_GPIO_Port, S8_Pin, GPIO_PIN_SET);
  133. if (table[8] == Etat)
  134. HAL_GPIO_WritePin(S9_GPIO_Port, S9_Pin, GPIO_PIN_SET);
  135. if (table[9] == Etat)
  136. HAL_GPIO_WritePin(S10_GPIO_Port, S10_Pin, GPIO_PIN_SET);
  137. if (table[10] == Etat)
  138. HAL_GPIO_WritePin(S11_GPIO_Port, S11_Pin, GPIO_PIN_SET);
  139. if (table[11] == Etat)
  140. HAL_GPIO_WritePin(S12_GPIO_Port, S12_Pin, GPIO_PIN_SET);
  141. }
  142. }
  143. void eteint(int i, int Etat) {
  144. if (Etat == 1) {
  145. if (table[0] == Etat)
  146. HAL_GPIO_WritePin(S1_GPIO_Port, S1_Pin, GPIO_PIN_RESET);
  147. if (table[1] == Etat)
  148. HAL_GPIO_WritePin(S2_GPIO_Port, S2_Pin, GPIO_PIN_RESET);
  149. if (table[2] == Etat)
  150. HAL_GPIO_WritePin(S3_GPIO_Port, S3_Pin, GPIO_PIN_RESET);
  151. if (table[3] == Etat)
  152. HAL_GPIO_WritePin(S4_GPIO_Port, S4_Pin, GPIO_PIN_RESET);
  153. if (table[4] == Etat)
  154. HAL_GPIO_WritePin(S5_GPIO_Port, S5_Pin, GPIO_PIN_RESET);
  155. if (table[5] == Etat)
  156. HAL_GPIO_WritePin(S6_GPIO_Port, S6_Pin, GPIO_PIN_RESET);
  157. if (table[6] == Etat)
  158. HAL_GPIO_WritePin(S7_GPIO_Port, S7_Pin, GPIO_PIN_RESET);
  159. if (table[7] == Etat)
  160. HAL_GPIO_WritePin(S8_GPIO_Port, S8_Pin, GPIO_PIN_RESET);
  161. if (table[8] == Etat)
  162. HAL_GPIO_WritePin(S9_GPIO_Port, S9_Pin, GPIO_PIN_RESET);
  163. if (table[9] == Etat)
  164. HAL_GPIO_WritePin(S10_GPIO_Port, S10_Pin, GPIO_PIN_RESET);
  165. if (table[10] == Etat)
  166. HAL_GPIO_WritePin(S11_GPIO_Port, S11_Pin, GPIO_PIN_RESET);
  167. if (table[11] == Etat)
  168. HAL_GPIO_WritePin(S12_GPIO_Port, S12_Pin, GPIO_PIN_RESET);
  169. }
  170. }
  171. /* USER CODE END Application */
  172. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/