Example of background calling the user functions?

Discussion to talk about software related topics only.
Post Reply
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Example of background calling the user functions?

Post by yevgenit »

Can somebody recommend a good code and documentation for template (or example) of background recognition of some events and calling the user-filled functions?
The library Telnet/Serial Command Processor is seem too complex for such a template.
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Example of background calling the user functions?

Post by Ridgeglider »

Yevgenit: are the events from a single source, say a com port? If so, a switch() on the input and a case statemet is pretty easy. If the inputs come from things that can be set up as fds (com ports, buffers, etc), then using select() makes sense for triggering reads or writes, also perhaps through a case statement. If the events are from disparate hardware sources, the OSFLAGS is a great way to consolidate or pool the inputs into a place where they can be acted on together in various flexible combinations. What sort of events are you trying to handle?
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Example of background calling the user functions?

Post by rnixon »

The type of events makes all the difference. What type of events?
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Inpus for generating events by backgound processing

Post by yevgenit »

rnixon,
I intend to generate most of the events by some background processing of analog and digital inputs. The other events will be generated by some background processing of UART input.
The system deadline is 10 ms to 100 ms.
My primary interest is a good arrangement of the event flow from the low-level background processing layer to the middle-level of the advanced processing.
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Re: Example of background calling the user functions?

Post by yevgenit »

Ridgeglider,

Some events will be generated by certain background processing of UART and Telnet input.
The library's Command Processor is proven to be suitable for this subsystem during my previous project.

Is exist proven way to arrange as FDs (virtual serial ports?) those event sources, which implement some background processing of analog and digital inputs?

"If the events are from disparate hardware sources, the OSFLAGS is a great way to consolidate or pool the inputs into a place where they can be acted on together in various flexible combinations."
Where can I, please, see the tested example of this arrangement?
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Example of background calling the user functions?

Post by Ridgeglider »

Yevgenit: See: C:\nburn\examples\RTOS\OSFlags. I think this may be the same example as the one discussed in the NNDK Programmer's Guide on Page 111 in section 15.1.6. See also the discusson of the related functions [OSFlagCreate, OSFlagSet, OSFlagState, OSFlagClear, OSFlagPendAll,OSFlagPendAllNoWait, OSFlagPendAny, OSFlagPendAnyNoWait] in C:\nburn\docs\NetBurnerRuntimeLibrary\uCOSLibrary.pdf.

OS_FLAGS give one task the ability to simultaneously monitor up to 32 other processes in parallel. In contrast, if a task PENDed on a mailbox, queue or fifo alone, it would be blind to events from any other source. Flags give tasks the ability to monitor many sources at once. Typically, an IRQ for your AD or IO will set flags when new data is ready. Similarly, in addition to a hardware source, one task can set or clear a flag to send a message to another task to report some conditon, say that some processing is done. Ideal for the event driven handler you mention.

See also the discussion of setting up your own fd with the IoExpandStruct in the NNDK manual. That example builds a circular buffer. If you set up an fd, you can wait on events from multiple fds using select() that is similar to the way flags allow you to look at flag multiple sources.
rnixon
Posts: 833
Joined: Thu Apr 24, 2008 3:59 pm

Re: Example of background calling the user functions?

Post by rnixon »

Ridgeglider has an excellent answer. On a general note, one method to consider would be grouping items with flow control and items without. For example, in interrupt and high priority task that continually updates A/D and digital inputs, so you just read the most recent values. The other task handles all your tcp related background tasks and is of one lesser priority level than the A/D. The mechanism of the tcp and serial is a select() with multiple fd's, or use OSFlags as mentioned earlier.
User avatar
yevgenit
Posts: 84
Joined: Fri Apr 25, 2008 12:47 am
Contact:

Re: Example of background calling the user functions?

Post by yevgenit »

rnixon and Ridgeglider,

thanks for excellent introduction to the (new for me) method of event-driven communication between the low level and the middle level using QS flags.

The method with select(), as I understand, is implemented in the library "Command Processor", which was successfuly used in my previous project.
Yevgeni Tunik
Embedded/RealTime software engineer
https://www.linkedin.com/in/yevgenitunik/
________________________
Ridgeglider
Posts: 513
Joined: Sat Apr 26, 2008 7:14 am

Re: Example of background calling the user functions?

Post by Ridgeglider »

Yevgenit:

Thanks... we all learn a lot here! For several other examples on the use of select() see C:\nburn\examples\serial.
Post Reply