CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug Reports on this forum. Send them to support@ccsinfo.com

Best way to multitasking
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
guy



Joined: 21 Oct 2005
Posts: 270

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 24, 2017 10:17 am     Reply with quote

It's not too complicated. You might want to learn the general concept (DMA, pingpong buffers etc) in wikipedia. Also be prepared that it might not work and then either turn to the forum or check the hardware registers carefully. My quick attempt at DMA with the PIC I mentioned wasn't successful, not sure why yet.
jeremiah



Joined: 20 Jul 2010
Posts: 994

View user's profile Send private message

Re: Best way to multitasking
PostPosted: Tue Oct 24, 2017 11:58 am     Reply with quote

ccsfred wrote:

I tried using the CCS RTOS this morning, but can't get it to sample enough due to serial Max time, whilst allowing the serial tasks enough Max time.


Curiosity: What do you mean by this? A serial task in an RTOS would typically place data on a buffer and let the serial transmit ISR handle putting bytes out on the wire. It should be able to do that and then quickly yield to other tasks. Were you trying to use blocking serial?

An alternative to RTOS is coroutines or protothreads. They are cooperative just like the CCS RTOS but tend to mimic threads a bit more closely. I did an early port of protothreads a couple years ago (in the code library forum here) if you are interested. I haven't tried it on the recent versions of the compiler though. They take a bit more care as they don't context save. Here is a link to the originators website if you want more information / discussion on how they are used:
http://dunkels.com/adam/pt/

That said, I tend to go the route of DMA and/or interrupts depending on what my needs are.
newguy



Joined: 24 Jun 2004
Posts: 1516
Location: Edmonton, Alberta

View user's profile Send private message

PostPosted: Tue Oct 24, 2017 12:01 pm     Reply with quote

DMA isn't too tough to figure out, but do yourself a favour and download (and read) all the DMA documentation that microchip has available. Look for application notes, if your processor has a FRM (family reference manual), etc.

The only thing that ever "got" me was that the dsPIC33 I was using wouldn't support/work with byte DMA transfers between the UART and memory. Couldn't figure it out so I just switched my arrays to int16 and configured the DMA for word transfers. Inefficient, but it worked given the timeframe I found myself in.
Ttelmah



Joined: 11 Mar 2010
Posts: 13523

View user's profile Send private message

Re: Best way to multitasking
PostPosted: Tue Oct 24, 2017 1:14 pm     Reply with quote

jeremiah wrote:
ccsfred wrote:

I tried using the CCS RTOS this morning, but can't get it to sample enough due to serial Max time, whilst allowing the serial tasks enough Max time.


Curiosity: What do you mean by this? A serial task in an RTOS would typically place data on a buffer and let the serial transmit ISR handle putting bytes out on the wire. It should be able to do that and then quickly yield to other tasks. Were you trying to use blocking serial?

An alternative to RTOS is coroutines or protothreads. They are cooperative just like the CCS RTOS but tend to mimic threads a bit more closely. I did an early port of protothreads a couple years ago (in the code library forum here) if you are interested. I haven't tried it on the recent versions of the compiler though. They take a bit more care as they don't context save. Here is a link to the originators website if you want more information / discussion on how they are used:
http://dunkels.com/adam/pt/

That said, I tend to go the route of DMA and/or interrupts depending on what my needs are.


Yes.
It is very important to understand that all multi-tasking that is really practical on the PIC, is co-operative multi tasking. As such it becomes your responsibility as author, to ensure that every 'task' terminates in less time than the time slot you want to work with. It's an attitude thing in terms of how code is written. So (for instance), I currently have multiple jobs being done on a system using two serials, USB, SPI, etc.., and each of the serial routines has to simply arrive, see if a character is waiting in it's buffer (handled by the hardware ISR), and if it is handle this with a state machine. So it 'walks' through keywords it is looking for, with a received character just resulting in the state machine moving to a new position depending what it is, and exiting. Timed events (timeout on the serial), is similarly handled by a hardware tick. The total time involved in receiving any character is never more than a few hundred machine cycles, allowing other tasks a fair chance to operate. This is totally down to thinking this way in designing the code.
guy



Joined: 21 Oct 2005
Posts: 270

View user's profile Send private message Visit poster's website

PostPosted: Tue Oct 24, 2017 3:15 pm     Reply with quote

newguy wrote:
The only thing that ever "got" me was that the dsPIC33 I was using wouldn't support/work with byte DMA transfers between the UART and memory. Couldn't figure it out so I just switched my arrays to int16 and configured the DMA for word transfers. Inefficient, but it worked given the timeframe I found myself in.

Probably what I was experiencing! Thanks! Cool
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group