freertos.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  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. #include "spi.h"
  63. /* USER CODE END Includes */
  64. /* Private typedef -----------------------------------------------------------*/
  65. /* USER CODE BEGIN PTD */
  66. /* USER CODE END PTD */
  67. /* Private define ------------------------------------------------------------*/
  68. /* USER CODE BEGIN PD */
  69. /* USER CODE END PD */
  70. /* Private macro -------------------------------------------------------------*/
  71. /* USER CODE BEGIN PM */
  72. /* USER CODE END PM */
  73. /* Private variables ---------------------------------------------------------*/
  74. /* USER CODE BEGIN Variables */
  75. uint8_t t_SPIReceived[MAXRECEIVESPI];
  76. /* USER CODE END Variables */
  77. osThreadId TimerHandle;
  78. /* Private function prototypes -----------------------------------------------*/
  79. /* USER CODE BEGIN FunctionPrototypes */
  80. void init();
  81. /* USER CODE END FunctionPrototypes */
  82. void TimerTask(void const * argument);
  83. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  84. /**
  85. * @brief FreeRTOS initialization
  86. * @param None
  87. * @retval None
  88. */
  89. void MX_FREERTOS_Init(void) {
  90. /* USER CODE BEGIN Init */
  91. init();
  92. HAL_SPI_Receive_IT(&hspi1,t_SPIReceived,1); // On demare la réception du spi.
  93. /* USER CODE END Init */
  94. /* USER CODE BEGIN RTOS_MUTEX */
  95. /* add mutexes, ... */
  96. /* USER CODE END RTOS_MUTEX */
  97. /* USER CODE BEGIN RTOS_SEMAPHORES */
  98. /* add semaphores, ... */
  99. /* USER CODE END RTOS_SEMAPHORES */
  100. /* USER CODE BEGIN RTOS_TIMERS */
  101. /* start timers, add new ones, ... */
  102. /* USER CODE END RTOS_TIMERS */
  103. /* USER CODE BEGIN RTOS_QUEUES */
  104. /* add queues, ... */
  105. /* USER CODE END RTOS_QUEUES */
  106. /* Create the thread(s) */
  107. /* definition and creation of Timer */
  108. osThreadDef(Timer, TimerTask, osPriorityNormal, 0, 128);
  109. TimerHandle = osThreadCreate(osThread(Timer), NULL);
  110. /* USER CODE BEGIN RTOS_THREADS */
  111. /* add threads, ... */
  112. /* USER CODE END RTOS_THREADS */
  113. }
  114. /* USER CODE BEGIN Header_TimerTask */
  115. /**
  116. * @brief Function implementing the Timer thread.
  117. * @param argument: Not used
  118. * @retval None
  119. */
  120. /* USER CODE END Header_TimerTask */
  121. void TimerTask(void const * argument)
  122. {
  123. /* USER CODE BEGIN TimerTask */
  124. /* Infinite loop */
  125. Heure heu;
  126. for (;;) {
  127. readHeure(&heu);
  128. for (int i=0; i<10;i++){
  129. if (tabSortie[i].Fonctionement==0){//fonctionnement en mode tableau
  130. PWMSetDutyCycle(i,PWMPourcentage(&heu,&tabSortie[i]));
  131. PWMStart(i);
  132. }
  133. }
  134. osDelay(DELAYTIMER);
  135. }
  136. /* USER CODE END TimerTask */
  137. }
  138. /* Private application code --------------------------------------------------*/
  139. /* USER CODE BEGIN Application */
  140. /*
  141. * On vient dans la fonction Init uniquement au d�marage. L
  142. * L'application ne doit pas avoir de d�marage sauf coupure de courant.
  143. * La fonction init sert donc de gestion au coupure de courant.
  144. *
  145. * Quand il y a une coupure d'electricit� la RTC fige la date les registre de date a l'heure de la coupure.
  146. * Il suffit ensuite de venir ecrire un bit de configuration pour que les registres de date ce mette a jour avec la date actuels.
  147. */
  148. void init(){
  149. initTab(); //Initialisation du tableau des heures
  150. Date ancienDate;
  151. Date newDate;
  152. readDate(&ancienDate);//Lecture de l'heure fige
  153. redemareRTC();//Redemarage des Mise a jours des registres RTC
  154. readDate(&newDate);// Lecture de la nouvelle heure*/
  155. //TODO (RAMPES LED Amélioration) Faire un programme pour une reprise en douceur
  156. }
  157. /* USER CODE END Application */
  158. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/