/*---------------------------------------------------------------------------- * DBG *---------------------------------------------------------------------------*/ #include "stm32f7xx_hal.h" #include "RTE_Components.h" #include CMSIS_device_header #include "cmsis_os2.h" #include #ifdef RTE_Compiler_EventRecorder #include "EventRecorder.h" #endif osThreadId_t thread1,thread2,thread3,thread4; void Thread_1 (void *argument); void Thread_2 (void *argument); void Thread_3 (void *argument); void Thread_4 (void *argument); const osThreadAttr_t thread1_attr = { .stack_size = 1024, .priority = osPriorityNormal, // 24 .name = "FACT" }; const osThreadAttr_t thread2_attr = { .stack_size = 1024, .priority = osPriorityBelowNormal4, // 20 .name = "RESUMER" }; const osThreadAttr_t thread3_attr = { .stack_size = 1024, .priority = osPriorityBelowNormal, // 16 .name = "BLOCKER" }; const osThreadAttr_t thread4_attr = { .stack_size = 256, .priority = osPriorityLow, // 8 .name = "FLAG" }; //------------------------------------------------------------------------------ // Setup system clock to 216MHz //------------------------------------------------------------------------------ void SystemClock_Config (void) { RCC_ClkInitTypeDef RCC_ClkInitStruct; RCC_OscInitTypeDef RCC_OscInitStruct; /* Enable HSE Oscillator and activate PLL with HSE as source */ RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE; RCC_OscInitStruct.HSEState = RCC_HSE_ON; RCC_OscInitStruct.HSIState = RCC_HSI_OFF; RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE; RCC_OscInitStruct.PLL.PLLM = 25; RCC_OscInitStruct.PLL.PLLN = 432; RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2; RCC_OscInitStruct.PLL.PLLQ = 9; HAL_RCC_OscConfig(&RCC_OscInitStruct); /* Activate the OverDrive to reach the 216 MHz Frequency */ HAL_PWREx_EnableOverDrive(); /* Select PLL as system clock source and configure the HCLK, PCLK1 and PCLK2 clocks dividers */ RCC_ClkInitStruct.ClockType = (RCC_CLOCKTYPE_SYSCLK | RCC_CLOCKTYPE_HCLK | RCC_CLOCKTYPE_PCLK1 | RCC_CLOCKTYPE_PCLK2); RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV4; RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2; HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_7); } /*---------------------------------------------------------------------------- * Factorial function calculation *---------------------------------------------------------------------------*/ double Fact(double number) { if(number <= 1) return 1; return (number * Fact(number-1)); } /*---------------------------------------------------------------------------- * Thread 1 - FACT. *---------------------------------------------------------------------------*/ void Thread_1 (void *argument) { uint32_t x = 1; double result; for (;;) { result = 1; for(int i = 1; i<=x;i++) { result *= i; } //result = Fact(x); printf("Fact of %d is %a\r\n",x, result); x++; //if(x > 100) x = 1; osDelay(200); } } /*---------------------------------------------------------------------------- * Thread 2 - RESUMER *---------------------------------------------------------------------------*/ void Thread_2 (void *argument) { osThreadState_t state; for (;;) { osDelay(20); state = osThreadGetState(thread4); if(state == osThreadBlocked) { osThreadResume(thread4); } } } /*---------------------------------------------------------------------------- * Thread 3 - BLOCKER *---------------------------------------------------------------------------*/ void Thread_3 (void *argument) { osThreadState_t state; for (;;) { osDelay(50); state = osThreadGetState(thread4); if(state != osThreadBlocked) { osThreadSuspend(thread4); } } } /*---------------------------------------------------------------------------- * Thread 4 - FLAG *---------------------------------------------------------------------------*/ void Thread_4 (void *argument) { char str[10] = "Flag is:0"; uint8_t flag = '0'; for (;;) { if(flag == '0') { flag = '1'; } else { flag = '0'; } str[8]= flag; puts(str); EventRecordData(0x0000, str, 10); osDelay(100); } } int main (void) { // System Initialization SystemClock_Config(); SystemCoreClockUpdate(); #ifdef RTE_Compiler_EventRecorder // Initialize and start Event Recorder EventRecorderInitialize(EventRecordAll, 1U); #endif osKernelInitialize(); thread1 = osThreadNew(Thread_1, NULL, &thread1_attr); thread2 = osThreadNew(Thread_2, NULL, &thread2_attr); thread3 = osThreadNew(Thread_3, NULL, &thread3_attr); thread4 = osThreadNew(Thread_4, NULL, &thread4_attr); osKernelStart(); for (;;) {} }