Altera_Forum
Honored Contributor
13 years agoRead problem by using MicroC/OS-II
Hi,
I'm a new in using mutitasking tasks. I have the following code:
int startTheSystem=0;
int systemWasBooted=0;
int controlTheSystem=0;
char befehl;
long int zahl=0;
void system_Monitoring(alt_u32 pe_address,alt_u32 mme_address, alt_u32 spdm_address){...}
void zahl_Eingabe(){
if(startTheSystem==0){
printf("Das System wird gestartet.\n");
printf("Bitte geben Sie die Frequenz für das FAD ein.\n");
scanf("%ld", &zahl);
frequencyFromFAD=zahl;
printf("Bitte geben Sie die Amplitude für das FAD ein.\n");
scanf("%ld", &zahl);
amplitudeFromFAD=zahl;
printf("Bitte geben Sie den Schwellwert für das PSD ein.\n");
scanf("%ld",&zahl);
thresholdForThePSD=zahl;
startTheSystem=1;
}
if(controlTheSystem==0){
scanf("%s %ld",befehl,&zahl);
//write the frequency to FAD
if(strcmp(befehl,"w1")==0){
send_16bit_Data_To_SPI_Slave(SPI_MASTER_BASE,0x1,zahl);
frequencyFromFAD=zahl;
printf("Neue Fequenz: %ld\n",zahl);
}
//write the amplitude to the FAD
if(strcmp(befehl,"w2")==0){
send_16bit_Data_To_SPI_Slave(SPI_MASTER_BASE,0x1,zahl);
printf("Neue Amplitude: %ld\n", zahl);
amplitudeFromFAD=zahl;
}
//write the threshold to the PSD
if(strcmp(befehl,"w3")==0){
send_16bit_Data_To_SPI_Slave(SPI_MASTER_BASE,0x2,zahl); //take care about the slave_select_address
printf("Neuer Schwellwert: %ld\n", zahl);
thresholdForThePSD=zahl;
}
//read the frequency from the FAD which is generated now
if(strcmp(befehl,"r1")==0){
double countedFreq=0;
countedFreq =count_The_Frequency_Of_The_FAD();
printf("Die Frequenz vom FAD ist momentan auf: %e Hz\n", countedFreq);
countedFreq=0;
}
//read the amplitude from the FAD which was give in before
if(strcmp(befehl,"r2")==0){
printf("Die Amplitude vom FAD beträgt momentan: %ld °\n", amplitudeFromFAD);
}
//read the threshold from the PSD which was give in before
if(strcmp(befehl,"r3")==0){
printf("Der Schwellwert vom PSD beträgt momentan: %ld\n", thresholdForThePSD);
}
zahl=0;
befehl=0;
controlTheSystem=1;
}
}
/* Definition of Task Stacks */# define TASK_STACKSIZE 2048
OS_STK task1_stk;
OS_STK task2_stk;
/* Definition of Task Priorities */
# define TASK1_PRIORITY 1# define TASK2_PRIORITY 2
void task1(void* pdata)
{
while (1)
{
if((startTheSystem==1) & (systemWasBooted==0)){
printf("Das System wird nun gebootet!\n");
systemWasBooted=1;
}
if(((controlTheSystem==0) & (systemWasBooted==1)) | ((controlTheSystem==1) & (systemWasBooted==1))){
controlTheSystem=0;
printf("Controlflag: %d\n", controlTheSystem);
system_Monitoring(PE_PIO_BASE,MME_PIO_BASE,SPDM_PIO_BASE);
}
// printf("Task 1 nochmal.\n");
// if(startTheSystem==1){
// printf("Die Zahl war: %ld\n",zahl);
// zahl=0;
// startTheSystem=0;
// }
OSTimeDlyHMSM(0, 0, 2, 0);
}
}
void task2(void* pdata)
{
while (1)
{
zahl_Eingabe();
// printf("Zahl eingeben!\n");
// scanf("%ld", &zahl);
// if(zahl!=0){
// printf("Frequenz:%ld\n", zahl);
// startTheSystem=1;
// }
OSTimeDlyHMSM(0, 0, 2, 0);
}
}
/* The main function creates two task and starts multi-tasking */
int main(void)
{
OSTaskCreateExt(task1,
NULL,
(void *)&task1_stk,
TASK1_PRIORITY,
TASK1_PRIORITY,
task1_stk,
TASK_STACKSIZE,
NULL,
0);
OSTaskCreateExt(task2,
NULL,
(void *)&task2_stk,
TASK2_PRIORITY,
TASK2_PRIORITY,
task2_stk,
TASK_STACKSIZE,
NULL,
0);
OSStart();
return 0;
}
My Probelm is now: I need type in the instruction to read and then I need to typ in something else to read out the value I want to have by using the second task? You can see it in the console: --- Quote Start --- Controlflag: 0 Systemüberwachung gestartet! r2 Controlflag: 0 Systemüberwachung gestartet! s Die Amplitude vom FAD beträgt momentan: 10 ° --- Quote End --- Why it doesn't work by the first time because if I use the write instruction it works well. Thanks for the help in advance!