Skip to content

Commit 870cf6a

Browse files
committed
- added a routine called in the main routine to initialise peripherals.
1 parent dca251c commit 870cf6a

File tree

1 file changed

+40
-35
lines changed

1 file changed

+40
-35
lines changed

src/main_dist_freertos.c

Lines changed: 40 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
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)
156156
vTaskDelay(150);
157157
xSemaphoreGive(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*/
265271
xBinarySemaphore_InpCap = xSemaphoreCreateBinary();
@@ -286,16 +292,12 @@ int main(void)
286292
if (xQueueDispDistBuff == NULL)
287293
USART_TX_string("Queue Creation xQueueDispDistBuff Failed!\r\n");
288294

289-
290295
if (xQueueTimeBuff == NULL)
291296
USART_TX_string("Queue Creation xQueueTimeBuff Failed!\r\n");
292297

293298
if (xQueueTimeDispBuff == NULL)
294299
USART_TX_string("Queue Creation xQueueTimeDispBuff Failed!\r\n");
295300

296-
297-
298-
299301
/*Make sure Semaphore creation was successful*/
300302
if ((xBinarySemaphore_InpCap != NULL) && (xBinarySemaphore_DMA != NULL)
301303
&& (xBinarySemaphore_InpCapDone != NULL)
@@ -310,7 +312,6 @@ int main(void)
310312
NULL,
311313
TASK1_PRIO, Task1_Stack, &Task1Buff);
312314

313-
314315
xTaskCreateStatic(vTask_HandlerInpCapture, "tsk_IC_Hndlr",
315316
TASK2_STACK_SIZE,
316317
NULL,
@@ -378,6 +379,8 @@ void TIM1_CC_IRQHandler(void)
378379
{
379380
static timestamp_t pulse;
380381

382+
383+
381384
static BaseType_t xHigherPriorityTaskWoken;
382385
xHigherPriorityTaskWoken = pdFALSE;
383386

@@ -432,6 +435,8 @@ void TIM1_CC_IRQHandler(void)
432435
//portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
433436

434437
}
438+
439+
435440
}
436441

437442
void vApplicationTickHook(void)

0 commit comments

Comments
 (0)