Добрый день!
Я решил использовать RTOS от Keil RTX-166 Tiny для Infineon, потому что эта ОСь халявная и очень простая(на мой взгляд).
Но в ней есть документированная проблема следующего характера:
Используется переключение стэка при смене задач, и вследствии проблемы с автоматическими переменными внутри функции самой задачи.
Дается 2 варианта решения проблемы:
1 - не использовать автоматичесие переменные.
2 - работать с ними в критической секции(заморозка планировщика).
У меня такой вопрос - эта система ПОЛНОЕ говно или я чего-то не понимаю?
Ведь для того, чтобы вызвать любую функцию, в теле задачи мне придется помещать её в крит. секцию или делать все переменные внутри функции статическими. И так для каждой ф-ции с нестатическими переменными. Как мне кажется, одинаково как пичканье программы повсюду крит. секциями, так и ф-ций статическими переменными является дурным тоном(и не только).
Что посоветуете в данном случае?
Текст нотации от Keil:
Цитата
1. Problems with pointers to stack based variables
==================================================
The RTX166 Tiny uses a stack swapping method to reduce the required stack
space of the whole system. However, due to the stack swapping, the addresses
of automatic variables change during program execution. This can cause
problems with the program execution when you use a pointer to an automatic
variable in your program.
There are a couple of ways arround that problem as explained in the follwoing
sample program.
#pragma MOD167
#include <string.h>
#include <reg167.h>
#include <intrins.h>
#define TIM_INT_ENABLE T0IE /* same configuration as in CPUTIMER.INC */
/*****************************/
/* RTX166 Tiny Task Function */
/*****************************/
void job (void) _task_ 0 {
char a[16]; /* stack based variable */
static char b[16]; /* static variable */
strcpy (a, "Hello World"); /* this can fail since the address of the
variable 'a' can change due to stack
swapping during a task switch */
/* as a work-around you can disable the RTX166 Tiny Timer Interrupt */
TIM_INT_ENABLE = 0; /* disable RTX166 Tiny Timer */
_nop_ (); /* two NOP's to make sure that 166/167 */
_nop_ (); /* hardware has disabled the interrupt */
strcpy (a, "Hello World"); /* now it works, since there can be not
RTX166 Tiny task switch */
TIM_INT_ENABLE = 1; /* enable RTX166 Tiny Timer */
/* another solution is to use static variables instead of stack based
variables as in the following example */
strcpy (b, "Hello World"); /* this will always work. The variable 'b'
is a static variable which has a fixed
memory location */
}