Interrupting coded loop
Interrupting coded loop
I am looking for a way to interrupt a program that is running on a loop. Right now after I have called the program, I cannot access anything else until the loops are done. I wanted a way to hard stop the loop without reseting my instrument. Please let me know of any ideas.
Re: Interrupting coded loop
What is your input to stop the loop? Serial Port, Ethernet, GPIO input ext.. Is this code running in UserMain or a different task? If you cant access anything when the loop is running you probably have the task priorities set incorrectly. The network tasks are pretty low level and should be able to run over a user task. They are interrupt driven, unless you are blocking interrupts you should have network connectivity.
-Larry
-Larry
Re: Interrupting coded loop
The code is from a different task not UserMain. I am trying to stop the loop via Ethernet.lgitlitz wrote:What is your input to stop the loop? Serial Port, Ethernet, GPIO input ext.. Is this code running in UserMain or a different task? If you cant access anything when the loop is running you probably have the task priorities set incorrectly. The network tasks are pretty low level and should be able to run over a user task. They are interrupt driven, unless you are blocking interrupts you should have network connectivity.
-Larry
Re: Interrupting coded loop
It's always a good idea to yield at some point in a loop if you want other tasks to run, unless the task is the lowest priority, whereby it will always be given priority to higher priority tasks. Use OSTimeDly(1); to yield at least 1 tick (assuming your loop is not required to run as fast as possible, in which case, set it as the lowest priority and don't worry about yielding)
To break out of the loop from another task is going to need some cooperation in your loop to check for an exit state. The ideal way to do this is to query a flag with OSFlagState and if the flag is set, you exit the loop. You set the flag in your other task.
What is the priority of each of your tasks? Maybe we can assist if we know what you have used.
Dave...
EDIT: You could also use the following function call OSFlagPendAllNoWait();
To break out of the loop from another task is going to need some cooperation in your loop to check for an exit state. The ideal way to do this is to query a flag with OSFlagState and if the flag is set, you exit the loop. You set the flag in your other task.
What is the priority of each of your tasks? Maybe we can assist if we know what you have used.
Dave...
EDIT: You could also use the following function call OSFlagPendAllNoWait();
Re: Interrupting coded loop
I agree with v8dave as a way to force the architecture you have to work. However, if I understand what you are trying to do (and I'm not actually sure I do) it sounds like you are trying to create a cooperative os out of a preemptive os. A better solution for a preemptive os would be to look at the architecture of your code as a whole, and design your tasks so that the functions they perform block and let other tasks run. The OSTimeDly function is a blocking function, but you don't really want to add latency. For example, a read() function on a tcp socket is a blocking function, and there is no timer latency like OSTimeDly. The docs describe which os functions are blocking functions. You can't code a preemtive os like a windows or linux os, the price you pay for real time and deterministic behavior is that you cant just code up a bunch of tasks/threads.