Interrupting coded loop

Discussion to talk about software related topics only.
Post Reply
jokes304
Posts: 23
Joined: Wed Jun 02, 2010 12:13 pm

Interrupting coded loop

Post by jokes304 »

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.
User avatar
lgitlitz
Posts: 331
Joined: Wed Apr 23, 2008 11:43 am
Location: San Diego, CA
Contact:

Re: Interrupting coded loop

Post by lgitlitz »

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
jokes304
Posts: 23
Joined: Wed Jun 02, 2010 12:13 pm

Re: Interrupting coded loop

Post by jokes304 »

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
The code is from a different task not UserMain. I am trying to stop the loop via Ethernet.
v8dave
Posts: 333
Joined: Thu Dec 31, 2009 8:31 pm

Re: Interrupting coded loop

Post by v8dave »

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();
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Interrupting coded loop

Post by rnixon »

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.
Post Reply