Click here to Skip to main content
14,207,205 members

C / C++ / MFC

 
QuestionRe: create_task function in PPL Pin
David Crow11-Jun-18 9:54
memberDavid Crow11-Jun-18 9:54 
AnswerRe: create_task function in PPL Pin
Daniel Ramnath11-Jun-18 20:36
memberDaniel Ramnath11-Jun-18 20:36 
AnswerRe: create_task function in PPL Pin
Daniel Ramnath11-Jun-18 20:30
memberDaniel Ramnath11-Jun-18 20:30 
QuestionDynamic programming fill 3D array Pin
pro grimi10-Jun-18 23:12
memberpro grimi10-Jun-18 23:12 
QuestionInitInstance() implimentation. Pin
Member 1271142610-Jun-18 20:17
memberMember 1271142610-Jun-18 20:17 
AnswerRe: InitInstance() implimentation. Pin
Jochen Arndt10-Jun-18 21:24
mveJochen Arndt10-Jun-18 21:24 
QuestionAdvice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
arnold_w9-Jun-18 10:37
memberarnold_w9-Jun-18 10:37 
AnswerRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
leon de boer10-Jun-18 17:27
memberleon de boer10-Jun-18 17:27 
All of your code you have done is a co-operative system for the situation of longer tasks you need to do pre-emptive context switches and for the asynchronous order problem you need semaphores,mutex or spinlock implementation.

For pre-emptive context switching you usually have a timer interrupt it triggers 10-1000 times a second. When the interrupt triggers it looks to see what task should run next in a scheduler scheme, it then forcibly saves every cpu register and every fpu register to a context stack so the program can resume from that point. Next it loads the cpu registers and fpu registers for the next task to run from a context stack and then it proceeds to run that task until a subsequent timer tick stops it passing control to another task. You will require critical section process which is small areas of code when it enters the task switcher can not interrupt and often that is as simple as switching off interrupts so the timer interrupt doesn't fire.

Semaphores or spinlocks are the usual way of dealing with sharing the I/O functionality. So in your DMA example the use of the DMA would have an aquire and release process. So any function wanting to do a DMA transfer would first ask for ownership of the DMA, if the DMA is in use it will already be aquired and the caller must wait for whoever has it to release. So anyone that has the DMA then releases and the act of doing so then allows waiting callers to then execute so it looks like.
void DMA_Write ( /.* some variables */)
{
	SpinLock_Acquire ();
    ActualDMAFunction(/.* some variables */);   
	SpinLock_Release ();
}

For the processor you are on if you search for "ARM Synchronization Primitives" and ARM will have a whitepaper on typical setups and minimum requirements. It will usually involve the use of the special opcodes LDREX/STREX (as well as WFE/WFI on multicore systems if you want to sleep the core while waiting).

You will also find the code for the context switch by a simple search of "ARM Context switch" with the processor name and you will get an ARM white paper describing it. They will all generally work on entering the call with one register pointing to the where to save all the current registers and another to where to load the registers from.

There are some really simple AVR task switcher projects which would be easy to adapt .. you simply need to change the context_switch assembler and replace the ATOMIC_BLOCK store and release with the interrupt enable/disable (it is all it generally does on smaller AVR processors) it is a basic CRITICAL SECTION control so it doesn't get interruptted with the code inside the curly brackets.
GitHub - kcuzner/kos-avr: Kevin's RTOS for AVR microcontrollers[^]
That is basically one file kos.c and 1 header kos.h

That uses a simple round robin scheduler (every task has same priority) if you want advanced priority based scheduler you can simply replace the scheduler code but I would suggest get the most simple running first then add the advanced scheduler. All you will end up doing is replacing the scheduler function with a more advanced one and your task creation call will have a priority you assign.

Final note if you are on a multicore system you will need to change the semaphore to the proper arm code the presented one generally won't work with multicores. It should be fine on a single core.

If you need further help we really need what ARM processor.
In vino veritas


modified 11-Jun-18 0:54am.

GeneralRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
arnold_w10-Jun-18 20:16
memberarnold_w10-Jun-18 20:16 
GeneralRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
leon de boer11-Jun-18 2:52
memberleon de boer11-Jun-18 2:52 
GeneralRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
arnold_w11-Jun-18 3:13
memberarnold_w11-Jun-18 3:13 
GeneralRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
leon de boer11-Jun-18 4:04
memberleon de boer11-Jun-18 4:04 
GeneralRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
arnold_w11-Jun-18 9:38
memberarnold_w11-Jun-18 9:38 
AnswerRe: Advice on designing a simple task scheduler in embedded C, that can handle asynchronuous tasks? Pin
supercat920-Jun-18 12:22
membersupercat920-Jun-18 12:22 
QuestionC# combo box text color change Pin
czaar9998-Jun-18 7:18
memberczaar9998-Jun-18 7:18 
AnswerRe: C# combo box text color change Pin
Richard Andrew x648-Jun-18 10:54
professionalRichard Andrew x648-Jun-18 10:54 
Questionusing dynamic_cast with template classes. Pin
Tarun Jha5-Jun-18 1:48
memberTarun Jha5-Jun-18 1:48 
AnswerRe: using dynamic_cast with template classes. Pin
Richard MacCutchan5-Jun-18 3:20
protectorRichard MacCutchan5-Jun-18 3:20 
GeneralRe: using dynamic_cast with template classes. Pin
Tarun Jha5-Jun-18 8:31
memberTarun Jha5-Jun-18 8:31 
GeneralRe: using dynamic_cast with template classes. Pin
Richard MacCutchan5-Jun-18 21:00
protectorRichard MacCutchan5-Jun-18 21:00 
AnswerRe: using dynamic_cast with template classes. Pin
CPallini5-Jun-18 11:03
mveCPallini5-Jun-18 11:03 
GeneralRe: using dynamic_cast with template classes. Pin
Tarun Jha5-Jun-18 18:45
memberTarun Jha5-Jun-18 18:45 
GeneralRe: using dynamic_cast with template classes. Pin
CPallini5-Jun-18 21:22
mveCPallini5-Jun-18 21:22 
GeneralRe: using dynamic_cast with template classes. Pin
Tarun Jha6-Jun-18 3:11
memberTarun Jha6-Jun-18 3:11 
GeneralRe: using dynamic_cast with template classes. Pin
CPallini6-Jun-18 22:26
mveCPallini6-Jun-18 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.


Advertise | Privacy | Cookies | Terms of Service
Web05 | 2.8.190612.1 | Last Updated 15 Jun 2019
Copyright © CodeProject, 1999-2019
All Rights Reserved.
Layout: fixed | fluid