Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Altera_Forum
Honored Contributor I
1,145 Views

Multithreading with NIOS II CORE

Hi, 

 

I want to know if it is possible to have one NIOS II CORE which can work in a multithreading mode. I want this because I have build up a system with several components and now I need two threads. One thread should monitor my system and the second thread should read some values over the console. If I give in a value the other thread should read it and adjust my system again with the new value. And If no value will appear from me the first thread should just monitor th system. 

 

Thanks in advance for the help
0 Kudos
3 Replies
Altera_Forum
Honored Contributor I
222 Views

The Hello MicroC/OS-II example in the Eclipse NIOS tool has a pretty straight forward example of multi-threading with the MicroC OS.

Altera_Forum
Honored Contributor I
222 Views

Thanks!  

I just try the example and it works. Now i just try to monitor my system and also I want to typ in new values but the problem is that it reacts very strange. If I typ in the start parameter it works fine but after that if I want to change a parameter I always need to tyo it in twice till the system change the value. Why is it so strange? 

 

 

 

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){ printf("Der Chris hat keine Ahnung und der Sämann erst recht!\n"); 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); zahl=0; befehl=0; } //write the amplitude to the FAD if(strcmp(befehl,"w2")==0){ send_16bit_Data_To_SPI_Slave(SPI_MASTER_BASE,0x1,zahl); zahl=0; befehl=0; } //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 zahl=0; befehl=0; } //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; zahl=0; befehl=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); zahl=0; befehl=0; } //read the threshold from the PSD which was give in before if(strcmp(befehl,"r3")==0){ printf("Der Schr2wellwert vom PSD beträgt momentan: %ld\n", thresholdForThePSD); zahl=0; befehl=0; } controlTheSystem=1; } } 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); } OSTimeDlyHMSM(0, 0, 2, 0); } } void task2(void* pdata) { while (1) { zahl_Eingabe(); OSTimeDlyHMSM(0, 0, 1, 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; } 

 

Thanks in advance for the help!
Altera_Forum
Honored Contributor I
222 Views

When sharing variables between two tasks there are two important things to do[list][*]define them as volatile so that the compiler doesn't make assumptions about how the variables are used and makes optimizations that prevent you from correctly transferring the value from one task to the other[*]protect access to the shared variables with a mutex, to be sure a task doesn't read the variables while you are right into the middle of editing them. You could end up in strange cases with mix ups of old and new values[/list] 

I'm not sure this is the reason why you have this problem, but it won't hurt ;) Except that you should use a bit more printfs to see if your variables are modified as expected.
Reply