2017-03-28 07:18 PM
Everybody,
I want to switch between thread on RTOS, how can I do that ?
I've written down below, but it seems that it's staying on the first thread only,
Thanks
/* StartDefaultTask function */
void StartDefaultTask(void const * argument){
/* init code for FATFS */MX_FATFS_Init();
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init();/* USER CODE BEGIN StartDefaultTask */
/* Infinite loop */ test_fatfs(); reading_file_test(); /* Suspend Thread 1 */ osThreadSuspend(NULL); /* Resume Thread 2*/ osThreadResume(secondTaskHandle); /* for(;;) { osDelay(1); } */ /* USER CODE END StartDefaultTask */}void StartSecondTask(void const * argument)
{ reading_file_test(); /* Resume Thread 1 */ osThreadResume(defaultTaskHandle);/* Suspend Thread 2 */
osThreadSuspend(NULL);}#switch #rtos #thread2017-03-31 12:47 AM
,
,
I increse heap size :
♯ define configTOTAL_HEAP_SIZE ((size_t)8192)
It's running now but not flipping yet ?
Code :
==============
void MX_FREERTOS_Init(void) {
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* USER CODE BEGIN RTOS_MUTEX */
/* add mutexes, ... */
/* USER CODE END RTOS_MUTEX */
/* USER CODE BEGIN RTOS_SEMAPHORES */
/* add semaphores, ... */
/* USER CODE END RTOS_SEMAPHORES */
/* USER CODE BEGIN RTOS_TIMERS */
/* start timers, add new ones, ... */
/* USER CODE END RTOS_TIMERS */
/* Create the thread(s) */
/* definition and creation of defaultTask */
osThreadDef(defaultTask, StartDefaultTask, osPriorityNormal, 0, 512),
defaultTaskHandle = osThreadCreate(osThread(defaultTask), NULL),
/* USER CODE BEGIN RTOS_THREADS */
/* add threads, ... */
/* definition and creation of defaultTask */
osThreadDef(secondTask, StartSecondTask, osPriorityNormal, 0, 512),
secondTaskHandle = osThreadCreate(osThread(secondTask), NULL),
/* USER CODE END RTOS_THREADS */
/* USER CODE BEGIN RTOS_QUEUES */
/* add queues, ... */
/* USER CODE END RTOS_QUEUES */
}
/* StartDefaultTask function */
static void StartDefaultTask(void const * argument)
{
uint32_t count = 0,
(void) argument,
/* init code for FATFS */
MX_FATFS_Init(),
/* init code for USB_DEVICE */
MX_USB_DEVICE_Init(),
/* USER CODE BEGIN StartDefaultTask */
/* Infinite loop */
printf('Start Default Task! \n'),*
for (,,)**
{//thread1 endless loop begin**
printf('Task 1, DefaultTask running! \n'),*
//test_fatfs(), //task thread_2 1
//reading_file_test(), //task thread_2 2
printf('Line 242 <,<,== \n'),
/* Suspend Thread 1 */
osThreadSuspend(NULL),
osDelay(1000),
/* Resume Thread 2*/
osThreadResume(secondTaskHandle),
}//thread1 endless loop end
/*
for(,,)
{
osDelay(1),
}
*/
/* USER CODE END StartDefaultTask */
}
static void StartSecondTask(void const * argument)
{
printf('Start Second Task! \n'),*
for (,,)**
{//thread2 endless loop begin**
printf('Task 2, SecondTask running! \n'),*
//reading_file_test(), //task on thread 2
/* Resume Thread 1 */
osThreadResume(defaultTaskHandle),
osDelay(1000),
/* Suspend Thread 2 */
osThreadSuspend(NULL),
}//thread2 endless loop end
}
======
Output :
*Start Second Task! **
**Task 2, SecondTask running! **
**Task 1, DefaultTask running! **
**Line 242 <,<,== *
2017-03-31 12:55 AM
I found the answer of my puzzle :
I commented out one of :
/*//osThreadSuspend(NULL); ==> in this case, it's on the first task, */
now it's flipping from task one to task two
thanks a lot guys...:)
2017-04-02 05:42 PM
Where can I find the example for those in :
\FreeRTOS Example\FreeRTOSv9.0.0\FreeRTOS\Demo\Common\Full
mutex example ?
thanks
2017-04-02 05:44 PM
Is it this one you're talking about to solve this puzzle ?
7.3 Mutexes (and Binary Semaphores)
2018-07-07 12:31 AM
Hey there!
Is your code stacked at the printf??
2018-11-03 10:20 PM
What RTOS is being used? Is it FreeRTOS or something else?