freertos.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. /* USER CODE BEGIN Header */
  2. /**
  3. ******************************************************************************
  4. * File Name : freertos.c
  5. * Description : Code for freertos applications
  6. ******************************************************************************
  7. * This notice applies to any and all portions of this file
  8. * that are not between comment pairs USER CODE BEGIN and
  9. * USER CODE END. Other portions of this file, whether
  10. * inserted by the user or by software development tools
  11. * are owned by their respective copyright owners.
  12. *
  13. * Copyright (c) 2019 STMicroelectronics International N.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted, provided that the following conditions are met:
  18. *
  19. * 1. Redistribution of source code must retain the above copyright notice,
  20. * this list of conditions and the following disclaimer.
  21. * 2. Redistributions in binary form must reproduce the above copyright notice,
  22. * this list of conditions and the following disclaimer in the documentation
  23. * and/or other materials provided with the distribution.
  24. * 3. Neither the name of STMicroelectronics nor the names of other
  25. * contributors to this software may be used to endorse or promote products
  26. * derived from this software without specific written permission.
  27. * 4. This software, including modifications and/or derivative works of this
  28. * software, must execute solely and exclusively on microcontroller or
  29. * microprocessor devices manufactured by or for STMicroelectronics.
  30. * 5. Redistribution and use of this software other than as permitted under
  31. * this license is void and will automatically terminate your rights under
  32. * this license.
  33. *
  34. * THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
  35. * AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
  36. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  37. * PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
  38. * RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
  39. * SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  40. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  41. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
  42. * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
  43. * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
  44. * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
  45. * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  46. *
  47. ******************************************************************************
  48. */
  49. /* USER CODE END Header */
  50. /* Includes ------------------------------------------------------------------*/
  51. #include "FreeRTOS.h"
  52. #include "task.h"
  53. #include "main.h"
  54. #include "cmsis_os.h"
  55. /* Private includes ----------------------------------------------------------*/
  56. /* USER CODE BEGIN Includes */
  57. #include <stdint.h>
  58. #include "PWM.h"
  59. #include "RTC.h"
  60. #include "Tab.h"
  61. #include "Heure.h"
  62. /* USER CODE END Includes */
  63. /* Private typedef -----------------------------------------------------------*/
  64. /* USER CODE BEGIN PTD */
  65. /* USER CODE END PTD */
  66. /* Private define ------------------------------------------------------------*/
  67. /* USER CODE BEGIN PD */
  68. /* USER CODE END PD */
  69. /* Private macro -------------------------------------------------------------*/
  70. /* USER CODE BEGIN PM */
  71. /* USER CODE END PM */
  72. /* Private variables ---------------------------------------------------------*/
  73. /* USER CODE BEGIN Variables */
  74. uint8_t Arret = 0;
  75. /* USER CODE END Variables */
  76. osThreadId TimerHandle;
  77. /* Private function prototypes -----------------------------------------------*/
  78. /* USER CODE BEGIN FunctionPrototypes */
  79. void init();
  80. /* USER CODE END FunctionPrototypes */
  81. void TimerTask(void const * argument);
  82. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  83. /**
  84. * @brief FreeRTOS initialization
  85. * @param None
  86. * @retval None
  87. */
  88. void MX_FREERTOS_Init(void) {
  89. /* USER CODE BEGIN Init */
  90. init();
  91. /* USER CODE END Init */
  92. /* USER CODE BEGIN RTOS_MUTEX */
  93. /* add mutexes, ... */
  94. /* USER CODE END RTOS_MUTEX */
  95. /* USER CODE BEGIN RTOS_SEMAPHORES */
  96. /* add semaphores, ... */
  97. /* USER CODE END RTOS_SEMAPHORES */
  98. /* USER CODE BEGIN RTOS_TIMERS */
  99. /* start timers, add new ones, ... */
  100. /* USER CODE END RTOS_TIMERS */
  101. /* USER CODE BEGIN RTOS_QUEUES */
  102. /* add queues, ... */
  103. /* USER CODE END RTOS_QUEUES */
  104. /* Create the thread(s) */
  105. /* definition and creation of Timer */
  106. osThreadDef(Timer, TimerTask, osPriorityNormal, 0, 128);
  107. TimerHandle = osThreadCreate(osThread(Timer), NULL);
  108. /* USER CODE BEGIN RTOS_THREADS */
  109. /* add threads, ... */
  110. /* USER CODE END RTOS_THREADS */
  111. }
  112. /* USER CODE BEGIN Header_TimerTask */
  113. /**
  114. * @brief Function implementing the Timer thread.
  115. * @param argument: Not used
  116. * @retval None
  117. */
  118. /* USER CODE END Header_TimerTask */
  119. void TimerTask(void const * argument)
  120. {
  121. /* USER CODE BEGIN TimerTask */
  122. /* Infinite loop */
  123. Heure heu;
  124. for (;;) {
  125. readHeure(&heu);
  126. for (int i=0; i<10;i++){
  127. if (tabSortie[i].Fonctionement==0){//fonctionnement en mode tableau
  128. uint8_t t = PWMPourcentage(&heu,&tabSortie[i]);
  129. PWMSetDutyCycle(i,t);
  130. PWMStart(i);
  131. }
  132. }
  133. osDelay(DELAYTIMER);
  134. }
  135. /* USER CODE END TimerTask */
  136. }
  137. /* Private application code --------------------------------------------------*/
  138. /* USER CODE BEGIN Application */
  139. /*
  140. * On vient dans la fonction Init uniquement au d�marage. L
  141. * L'application ne doit pas avoir de d�marage sauf coupure de courant.
  142. * La fonction init sert donc de gestion au coupure de courant.
  143. *
  144. * Quand il y a une coupure d'electricit� la RTC fige la date les registre de date a l'heure de la coupure.
  145. * Il suffit ensuite de venir ecrire un bit de configuration pour que les registres de date ce mette a jour avec la date actuels.
  146. */
  147. void init(){
  148. initTab(); //Initialisation du tableau des heures
  149. Date ancienDate;
  150. Date newDate;
  151. readDate(&ancienDate);//Lecture de l'heure fige
  152. redemareRTC();//Redemarage des Mise a jours des registres RTC
  153. readDate(&newDate);// Lecture de la nouvelle heure*/
  154. //TODO Faire un programme pour une reprise en douceur
  155. }
  156. /* USER CODE END Application */
  157. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/