finish lab
This commit is contained in:
@@ -20,19 +20,23 @@ void Thread_4 (void *argument);
|
||||
|
||||
const osThreadAttr_t thread1_attr = {
|
||||
.stack_size = 1024,
|
||||
.priority = osPriorityNormal,
|
||||
.priority = osPriorityNormal, // 24
|
||||
.name = "FACT"
|
||||
};
|
||||
const osThreadAttr_t thread2_attr = {
|
||||
.stack_size = 1024,
|
||||
.priority = osPriorityBelowNormal4,
|
||||
.priority = osPriorityBelowNormal4, // 20
|
||||
.name = "RESUMER"
|
||||
};
|
||||
const osThreadAttr_t thread3_attr = {
|
||||
.stack_size = 4096,
|
||||
.priority = osPriorityBelowNormal,
|
||||
.stack_size = 1024,
|
||||
.priority = osPriorityBelowNormal, // 16
|
||||
.name = "BLOCKER"
|
||||
};
|
||||
const osThreadAttr_t thread4_attr = {
|
||||
.stack_size = 256,
|
||||
.priority = osPriorityLow,
|
||||
.priority = osPriorityLow, // 8
|
||||
.name = "FLAG"
|
||||
};
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
@@ -77,57 +81,62 @@ double Fact(double number)
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread 1
|
||||
* Thread 1 - FACT.
|
||||
*---------------------------------------------------------------------------*/
|
||||
void Thread_1 (void *argument) {
|
||||
uint32_t x = 1;
|
||||
double result;
|
||||
for (;;)
|
||||
{
|
||||
result = Fact(x);
|
||||
printf("Fact of %d is %f\r\n",x,result);
|
||||
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
|
||||
* Thread 2 - RESUMER
|
||||
*---------------------------------------------------------------------------*/
|
||||
void Thread_2 (void *argument) {
|
||||
osThreadState_t state;
|
||||
for (;;)
|
||||
{
|
||||
osDelay(20);
|
||||
state = osThreadGetState(Thread_4);
|
||||
state = osThreadGetState(thread4);
|
||||
if(state == osThreadBlocked)
|
||||
{
|
||||
osThreadResume(Thread_4);
|
||||
osThreadResume(thread4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread 3
|
||||
* Thread 3 - BLOCKER
|
||||
*---------------------------------------------------------------------------*/
|
||||
void Thread_3 (void *argument) {
|
||||
osThreadState_t state;
|
||||
for (;;)
|
||||
{
|
||||
osDelay(50);
|
||||
state = osThreadGetState(Thread_4);
|
||||
state = osThreadGetState(thread4);
|
||||
if(state != osThreadBlocked)
|
||||
{
|
||||
osThreadSuspend(Thread_4);
|
||||
osThreadSuspend(thread4);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*----------------------------------------------------------------------------
|
||||
* Thread 4
|
||||
* Thread 4 - FLAG
|
||||
*---------------------------------------------------------------------------*/
|
||||
void Thread_4 (void *argument) {
|
||||
char * str = "Flag is:0";
|
||||
char str[10] = "Flag is:0";
|
||||
uint8_t flag = '0';
|
||||
for (;;)
|
||||
{
|
||||
@@ -141,6 +150,7 @@ void Thread_4 (void *argument) {
|
||||
}
|
||||
str[8]= flag;
|
||||
puts(str);
|
||||
EventRecordData(0x0000, str, 10);
|
||||
osDelay(100);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user