2121#define TASK1_STACK_SIZE 128
2222#define TASK2_STACK_SIZE 256
2323#define TASK3_STACK_SIZE 256
24- #define TASK4_STACK_SIZE 1024
25- #define TASK5_STACK_SIZE 1024
24+ #define TASK4_STACK_SIZE 512
25+ #define TASK5_STACK_SIZE 512
2626
2727#define TASK1_PRIO 1
2828#define TASK2_PRIO 3
@@ -156,9 +156,7 @@ void vTask_DisplayDistance(void *p)
156156vTaskDelay (150 );
157157xSemaphoreGive (xBinarySem_LCD );
158158}
159-
160159}
161-
162160}
163161
164162/* TASK 4
@@ -226,40 +224,48 @@ void vTask_DispTimeandDist(void *p)
226224
227225}
228226
229- int main (void )
230- {
231- SystemInit ();
232227
228+ static void init_HW_peripherals (void )
229+ {
233230/*Initialize USART2 peripheral */
234- init_USART2 ();
235- init_led_gpios ();
236- //init_debug_pin(); /* Initialize Debug pin LogicAnalyzer*/
231+ init_USART2 ();
232+ init_led_gpios ();
233+ //init_debug_pin(); /* Initialize Debug pin LogicAnalyzer*/
237234
238- /* Initialize I2C1 peripheral*/
239- init_i2c_bus_config ();
240- init_i2c_gpio ();
235+ /* Initialize I2C1 peripheral*/
236+ init_i2c_bus_config ();
237+ init_i2c_gpio ();
241238
242- /* Initialize the LCD using initialization commands */
243- LCD_Init ();
244- LCD_Clear ();
239+ /* Initialize the LCD using initialization commands */
240+ LCD_Init ();
241+ LCD_Clear ();
245242
246- /* Initialize Timer2 to trigger the Ultrasound HC04 module*/
247- init_timer2 ();
248- enable_alt_func_gpio ();
243+ /* Initialize Timer2 to trigger the Ultrasound HC04 module*/
244+ init_timer2 ();
245+ enable_alt_func_gpio ();
249246
250- /* Initialize Timer1 to initialize the input capture to receive echo from
251- * the Ultrasound HC04 module*/
252- init_capture_gpio ();
253- init_inp_capture_module ();
254- enable_inp_capture_irq ();
247+ /* Initialize Timer1 to initialize the input capture to receive echo from
248+ * the Ultrasound HC04 module*/
249+ init_capture_gpio ();
250+ init_inp_capture_module ();
251+ enable_inp_capture_irq ();
255252
256- /* initialize DMA module for receiving GPS data */
257- init_dma2 ();
258- enable_dma2_irq ();
253+ /* initialize DMA module for receiving GPS data */
254+ init_dma2 ();
255+ enable_dma2_irq ();
256+
257+ /* Initialize USART module to receive GPS data*/
258+ init_usart6_comm_module ();
259+ init_usart6_gpio ();
260+
261+ }
262+
263+ int main (void )
264+ {
265+ SystemInit ();
259266
260- /* Initialize USART module to receive GPS data*/
261- init_usart6_comm_module ();
262- init_usart6_gpio ();
267+ /* Initialise all the relevant peripherals*/
268+ init_HW_peripherals ();
263269
264270/*Create a semaphore for synchronizing Input capture interrupt and Distance calculation*/
265271xBinarySemaphore_InpCap = xSemaphoreCreateBinary ();
@@ -286,16 +292,12 @@ int main(void)
286292if (xQueueDispDistBuff == NULL )
287293USART_TX_string ("Queue Creation xQueueDispDistBuff Failed!\r\n" );
288294
289-
290295if (xQueueTimeBuff == NULL )
291296USART_TX_string ("Queue Creation xQueueTimeBuff Failed!\r\n" );
292297
293298if (xQueueTimeDispBuff == NULL )
294299USART_TX_string ("Queue Creation xQueueTimeDispBuff Failed!\r\n" );
295300
296-
297-
298-
299301/*Make sure Semaphore creation was successful*/
300302if ((xBinarySemaphore_InpCap != NULL ) && (xBinarySemaphore_DMA != NULL )
301303&& (xBinarySemaphore_InpCapDone != NULL )
@@ -310,7 +312,6 @@ int main(void)
310312NULL ,
311313TASK1_PRIO , Task1_Stack , & Task1Buff );
312314
313-
314315xTaskCreateStatic (vTask_HandlerInpCapture , "tsk_IC_Hndlr" ,
315316TASK2_STACK_SIZE ,
316317NULL ,
@@ -378,6 +379,8 @@ void TIM1_CC_IRQHandler(void)
378379{
379380static timestamp_t pulse ;
380381
382+
383+
381384static BaseType_t xHigherPriorityTaskWoken ;
382385xHigherPriorityTaskWoken = pdFALSE ;
383386
@@ -432,6 +435,8 @@ void TIM1_CC_IRQHandler(void)
432435//portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
433436
434437}
438+
439+
435440}
436441
437442void vApplicationTickHook (void )
0 commit comments