|
|
View previous topic :: View next topic |
Author |
Message |
kgng97ccs
Joined: 02 Apr 2022 Posts: 97
|
Using RTOS for scheduling tasks |
Posted: Mon May 16, 2022 3:10 am |
|
|
I am using the PIC18LF46K22 as a secondary processor, CCS C compiler v5.078, and MBLAB IDE v8.92.
My application involves a master processor sending data to the secondary processor (PIC) through UART1. The PIC is required to perform two tasks each at regular intervals, and the values for these intervals are provided by the master processor. At any time, the master processor may send a signal to change the regular intervals, and upon receipt of this signal, the PIC will then change the intervals in the main program accordingly.
I am exploring whether I could use the RTOS method (instead of Timer1 and Timer3 interrupts with preloads) to schedule the tasks, and change the "rate" in the #task directive if instructed so by the master processor.
I am thinking the code would go something like this:
Code: | #include "18LF46K22.h"
#fuses NOMCLR, HSH, FCMEN, IESO
#use delay(xtal=16MHz, clock=16MHz)
#use rs232(UART, baud=9600, errors)
#use RTOS(timer=0, minor_cycle=100ms)
unsigned int16 rate1_ms, rate2_ms;
#task(rate=rate1_ms, max=50ms)
void first_RTOS_task()
{
printf("1"); /* example */
}
#task(rate=rate2_ms, max=50ms)
void second_RTOS_task()
{
printf("2"); /* example */
}
#int_rda()
{
...
/* rate1_ms and rate2_ms settings */
rate1_ms = ...;
rate2_ms = ...;
}
void main()
{
...
enable_interrupts(int_rda);
enable_interrupts(global);
rate1_ms = 100;
rate2_ms = 200;
rtos_run();
... /* if new rate1_ms or rate2_ms setting is received,
update rate in corresponding #task directive above */
} |
I tested a separate simple program with the same structure, and for the #task directive, the compiler said “USE parameter value is out of range Not a number: RATE1_” for rate1_ms and similarly for rate2_ms.
Is there any way to make the "rate" in the #task directive a variable, such that it can be changed in the main program if desired?
Is there a preferred way of managing such scheduling (in which the task intervals are subject to change)?
I will appreciate any comments or suggestions. Thank you. |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19477
|
|
Posted: Mon May 16, 2022 3:20 am |
|
|
Basic answer, no.
The point is that the directive changes the code actually being used to setup
the timers and schedule things. Done at compile time, not run time.
Honestly 'KISS'. Don't change times, change counts. Have a basic
1mSec 'tick' interrupt, and have counters in this for your services. Change
the values for these counters to change the intervals. Just have this set a
flag to say 'do_this' when the count expires. |
|
|
kgng97ccs
Joined: 02 Apr 2022 Posts: 97
|
|
Posted: Wed May 18, 2022 10:13 pm |
|
|
Thank you, Ttelmah, for your explanation and suggestion. |
|
|
|
|
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
|