@@ -62,7 +62,7 @@ int BTaskSwitcher::get_next_task() {
6262 unsigned weights[] = { 50 , 33 , 17 };
6363 const unsigned priCount = sizeof (weights) / sizeof (weights[0 ]);
6464 auto total = 0 ;
65- for (auto i = 0 ; i < priCount; ++i) {
65+ for (unsigned i = 0 ; i < priCount; ++i) {
6666 if (!_pri[i].count || (_pri[i].count == 1 && _pri[i].current == _yielded_task)) {
6767 weights[i] = 0 ;
6868 }
@@ -99,7 +99,7 @@ int BTaskSwitcher::get_next_task() {
9999
100100void BTaskSwitcher::pause_task (int id) {
101101 BDisableInterrupts cli;
102- if (id >=0 && id < _tasks.Length () && _tasks[id] && !_tasks[id]->paused ()) {
102+ if (id >= 0 && id < ( int ) _tasks.Length () && _tasks[id] && !_tasks[id]->paused ()) {
103103 --_pri[_tasks[id]->priority ()].count ;
104104 _tasks[id]->pause ();
105105 if (id == _current_task) {
@@ -110,7 +110,7 @@ void BTaskSwitcher::pause_task(int id) {
110110
111111void BTaskSwitcher::resume_task (int id) {
112112 BDisableInterrupts cli;
113- if (id >=0 && id < _tasks.Length () && _tasks[id] && _tasks[id]->paused ()) {
113+ if (id >= 0 && id < ( int ) _tasks.Length () && _tasks[id] && _tasks[id]->paused ()) {
114114 ++_pri[_tasks[id]->priority ()].count ;
115115 _tasks[id]->resume ();
116116 }
@@ -159,16 +159,16 @@ void BTaskSwitcher::yield_task() {
159159 }
160160}
161161
162- void BTaskSwitcher::initialize (int tasks, int slice) {
162+ void BTaskSwitcher::initialize (int tasks, int slice, uint8_t loop_pri ) {
163163 BDisableInterrupts cli;
164- if (!_initialized && tasks > 0 && slice > 0 ) {
164+ if (!_initialized && tasks > 0 && slice > 0 && loop_pri <= TaskPriority::Low ) {
165165 _slice = slice;
166166 _tasks.Resize (tasks + 1 ); // 1 for main loop()
167167
168168 // add the initial loop() task
169169 _tasks.Add (new BTaskInfoBase ()); // loop() already has a stack
170170 _tasks[0 ]->id = 0 ;
171- _tasks[0 ]->priority (TaskPriority::Medium );
171+ _tasks[0 ]->priority (loop_pri );
172172 _pri[_tasks[0 ]->priority ()].count = 1 ;
173173
174174 init_arch ();
@@ -197,8 +197,8 @@ int currentTask() {
197197 return BTaskSwitcher::current_task_id ();
198198}
199199
200- void setupTasks (int numTasks, int msSlice) {
201- BTaskSwitcher::initialize (numTasks, msSlice);
200+ void setupTasks (int numTasks, int msSlice, uint8_t loopPriority ) {
201+ BTaskSwitcher::initialize (numTasks, msSlice, loopPriority );
202202}
203203
204204// used by arduino's delay()
0 commit comments