Hello,I have a problem using Micro C in Nios EDS. I do not have a wide experience working with Nios EDS and I am sorry if my problem is basic but I have not been able to find the solution. I download the .sof in Quartus II and then I create a new BSP with Hello world Micro C template in Nios EDS. The design compile with no problems but when I click in Run As --> Nios II Hardware, it does not work as I expected. It would have to display every three seconds "Hello from task1" and "Hello from task2" and I only get Hello from task1 once... It is quite strange, it seems as if the program stops and does not resume any more without create task2 and I am not able to understand why. If I work without Micro C (a single threaded design) everything works well. I attached the code but it is the example from Altera (I only added a printf("Hello") in the int main). I will be very grateful if anyone can help me with this problem. Any help will be welcome;) Many thanks!
Is the printf("Hello") in main displayed?Try one of the following: - set a PIO or a LED in the very beginning of main in order to see if program starts. - place a OSTimeSet(0) call in main, before creating tasks - use TK_SLEEP(3000) instead of OSTimeDlyHMSM(0, 0, 3, 0) - place a TK_SLEEP(1000) after the print in main, too
First of all, many thanks for your reply Cris72 :)I attach a new file with several screenshots which I think they can be useful to understand my problem. Let me explain a little more.. I have put usleep() instead the OS function because TK_SLEEP was a problem for the compiler. On the other hand, the program is executed until OSStart() at least, so tasks are created but none of them is working. I tried other example with LEDs and switches and it did not work (only the first created task worked, which is very strange). However, everything works well in single threaded mode so the hardware design cannot be the problem. I have checked my design over and over again but I do not know what I am doing wrongly... I would be very grateful if you could help me. Many thanks ;)
A few ideas. I any of these can help you.1. You selected small C library in sys lib properties. I'm not sure, but if I remember correctly the reduced library uses an implementation of printf which is not thread safe. So this could explain your problem. Use the complete C library. If you can't, because of SRAM size, remove the printf in tasks and replace them with PIO/LED signaling. 2. Please check the usleep function. In some cases this is implemented as a rough blocking for() cycle. This would prevent a higher priority task to release control and your app would get stuck. 3. Is the timer period correctly set to 1ms or whatever? Regards Cris
Many thanks for your fast reply Cris, I am grateful for your attention:)However, I am afraid my problem is not solved. I debugged the program to check if the tasks are created well and the returned value was zero, so the problem is not here. Therefore, I resumed debugging the program and it stopped in the command OSStart(), it is to say, the code never reach tasks. I suppose I must have defined something badly about the micro c but I have no idea which the problem can be. By the way, the timer is set to 1ms. If I am not wrong, this timer is used to control the delays and so 1ms is a proper value. I hope this information is useful. If any tip comes into your head, let me know. Many thanks! ;)
I have been working a little more and I have information which I hope it is useful to solve the problem.I was analyzing the micro c code and I found out the reason for which my program does not execute any taks: the code is suspended in an infinite loop in the command OSStart. To be more precise, the infinite loop is in the OSTimeTick function (I attach the code). The infinite loop is emphasized in grey. OS_IDLE_PRIO is defined with the same value as OS_LOWEST_PRIO in the micro c files. Therefore, it seems as if the idle task is not created. In my case the tasks have 10 and 11 priority, the lowest priority is 20 and both tasks are created well (the returned value is zero). In the previos reply I attached a .pdf with screenshots of my design. Does anybody know what I am doing wrongly or whatever? Any help will be welcome ;) Many thanks!
That's actually correct: OS_IDLE_PRIO must always be defined the same as OS_LOWEST_PRIO.The while loop goes through all the other (higher priority) tasks, in order to schedule those ready for execution. Since you debug into OSTimeTick, you should also find out which of the condition inside the loop is not fulfilled for your tasks. But, first of all, did you make sure your application tasks are included in the OSTCBList chain?
Cris72, many thanks for your help :)I have new information... I debugged again and I created a variable called "prova" with the value of OSTCBList before the infinte loop. I attach a pdf with the values of this variable. As can be seen, OSTCBPrio is never the same as OS_IDLE_PRIO (or OS_TASK_IDLE_PRIO depending on the version of Quartus II) and so it is the reason for which there is an infinite loop. The reason is clear, but I dont understand why. I hope this information is useful to solve the problem. Any help is welcome ;) Many thanks!
These's definitely a problem with OS or with tasks creation.Did you try removing the OSInit() call? I never used it and actually it is not in the hello_ucosii template project I have here (version 9.0sp2).
Hello Cris72,I solved the problem, I did two modifications and now it is working well! Let me explain the modifications.. Firstly, I assigned the global reset to the CPU reset of the board instead of to Vcc. Secondly, I downloaded the .pof in Quartus II using the active serial programming instead of the .sof with JTAG mode. Thus, the hardware design is downloaded permanently. I am very grateful to you for your help;) Many thanks, Best regards