freertos.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. /**
  2. ******************************************************************************
  3. * File Name : freertos.c
  4. * Description : Code for freertos applications
  5. ******************************************************************************
  6. *
  7. * COPYRIGHT(c) 2016 STMicroelectronics
  8. *
  9. * Redistribution and use in source and binary forms, with or without modification,
  10. * are permitted provided that the following conditions are met:
  11. * 1. Redistributions of source code must retain the above copyright notice,
  12. * this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright notice,
  14. * this list of conditions and the following disclaimer in the documentation
  15. * and/or other materials provided with the distribution.
  16. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  17. * may be used to endorse or promote products derived from this software
  18. * without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  21. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  22. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  23. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  24. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  25. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  26. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  27. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  29. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  30. *
  31. ******************************************************************************
  32. */
  33. /* Includes ------------------------------------------------------------------*/
  34. #include "FreeRTOS.h"
  35. #include "task.h"
  36. #include "cmsis_os.h"
  37. /* USER CODE BEGIN Includes */
  38. /* USER CODE END Includes */
  39. /* Variables -----------------------------------------------------------------*/
  40. osThreadId allumageHandle;
  41. osThreadId pilotageHandle;
  42. /* USER CODE BEGIN Variables */
  43. char S1=0,S2=0,S3=0,S4=0,S5=0,S6=0,S7=0,S8=0,S9=0,S10=0,S11=0,S12=0;
  44. char encours[12];
  45. int temps; // nombre de milisecond a attendre entre 2 mise a jour des sortie max 100
  46. char pause;//si pause du midi ou de la nuit
  47. char EEPROM; // variable pour l'ecriture de EEPROM 1 fois sur 2
  48. /* USER CODE END Variables */
  49. /* Function prototypes -------------------------------------------------------*/
  50. void allumageTask(void const * argument);
  51. void pilotageTask(void const * argument);
  52. void MX_FREERTOS_Init(void); /* (MISRA C 2004 rule 8.1) */
  53. /* USER CODE BEGIN FunctionPrototypes */
  54. /* USER CODE END FunctionPrototypes */
  55. /* Hook prototypes */
  56. /* Init FreeRTOS */
  57. void MX_FREERTOS_Init(void) {
  58. /* USER CODE BEGIN Init */
  59. /* USER CODE END Init */
  60. /* USER CODE BEGIN RTOS_MUTEX */
  61. /* add mutexes, ... */
  62. /* USER CODE END RTOS_MUTEX */
  63. /* USER CODE BEGIN RTOS_SEMAPHORES */
  64. /* add semaphores, ... */
  65. /* USER CODE END RTOS_SEMAPHORES */
  66. /* USER CODE BEGIN RTOS_TIMERS */
  67. /* start timers, add new ones, ... */
  68. /* USER CODE END RTOS_TIMERS */
  69. /* Create the thread(s) */
  70. /* definition and creation of allumage */
  71. osThreadDef(allumage, allumageTask, osPriorityNormal, 0, 128);
  72. allumageHandle = osThreadCreate(osThread(allumage), NULL);
  73. /* definition and creation of pilotage */
  74. osThreadDef(pilotage, pilotageTask, osPriorityNormal, 0, 128);
  75. pilotageHandle = osThreadCreate(osThread(pilotage), NULL);
  76. /* USER CODE BEGIN RTOS_THREADS */
  77. /* add threads, ... */
  78. /* USER CODE END RTOS_THREADS */
  79. /* USER CODE BEGIN RTOS_QUEUES */
  80. /* add queues, ... */
  81. /* USER CODE END RTOS_QUEUES */
  82. }
  83. /* allumageTask function */
  84. void allumageTask(void const * argument)
  85. {
  86. /* USER CODE BEGIN allumageTask */
  87. /* Infinite loop */
  88. int i;
  89. for (;;) {
  90. for(i=0;i<12;i++){
  91. if (encours[i])
  92. HAL_GPIO_WritePin(&listPort[i],listPin[i],GPIO_PIN_SET);
  93. }
  94. osDelay(temps);//TODO changer osDElay en quelleque chose de beaucoup beaucoup plus rapide
  95. for(i=0;i<12;i++){
  96. if (encours[i])
  97. HAL_GPIO_WritePin(&listPort[i],listPin[i],GPIO_PIN_RESET);
  98. }
  99. osDelay(100-temps);//TODO changer osDElay en quelleque chose de beaucoup beaucoup plus rapide
  100. }
  101. /* USER CODE END allumageTask */
  102. }
  103. /* pilotageTask function */
  104. void pilotageTask(void const * argument)
  105. {
  106. /* USER CODE BEGIN pilotageTask */
  107. /* Infinite loop */
  108. for (;;) {
  109. if (pause){
  110. ReveilRTC(6);
  111. osWait();
  112. }
  113. else{
  114. int time=lireRTC();
  115. sortie(encours,time,temps,pause);
  116. if(EEPROM){
  117. ecrireEEPROME();
  118. EEPROM=0;
  119. }
  120. else
  121. EEPROM=1;
  122. osDelay(36000);
  123. }
  124. }
  125. /* USER CODE END pilotageTask */
  126. }
  127. /* USER CODE BEGIN Application */
  128. /* USER CODE END Application */
  129. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/