Many tasks, one CPU, no operating system. Each task does a little and steps aside. Muchas tareas, una CPU, sin sistema operativo. Cada tarea hace un poco y cede el paso.
Santi Scagliusi, PhD
No OS. Just one loop in main that calls each task in turn, forever.Sin SO. Un solo bucle en main que llama a cada tarea por turno, para siempre.
The whole module is about honoring that one contract. Todo el módulo trata de honrar ese único contrato.
One task spins in a wait loop. The CPU is busy, so no other task runs.Una tarea gira en un bucle de espera. La CPU está ocupada, así que ninguna otra tarea corre.
B and C wait the whole delay before they get a turn. B y C esperan todo el retardo antes de tener turno.
Instead of waiting inside the task, the task remembers a state and returns.En vez de esperar dentro de la tarea, la tarea recuerda un estado y retorna.
Each call checks the trigger, maybe changes state, then returns. No spinning. Cada llamada comprueba el disparo, quizás cambia de estado, y retorna. Sin girar.
The state lives in a variable. A jump table picks the code for the current state.El estado vive en una variable. Una tabla de saltos elige el código del estado actual.
br tabEst(r14) jumps to the code for that state.br tabEst(r14) salta al código de ese estado.Do not burn cycles counting down. Compare the clock against a deadline.No quemes ciclos contando hacia atrás. Compara el reloj contra un plazo.
CPU held the whole wait. B and C never get a turn.CPU retenida toda la espera. B y C no tienen turno.
A checks the clock and returns. B and C run every pass; A acts only when the deadline arrives.A mira el reloj y retorna. B y C corren en cada vuelta; A actúa solo cuando llega el plazo.
A wait becomes a question asked each pass, not a loop that holds the CPU. Una espera pasa a ser una pregunta en cada vuelta, no un bucle que retiene la CPU.
A periodic CCR0 interrupt increments one shared 32-bit time counter.Una interrupción periódica de CCR0 incrementa un contador de tiempo de 32 bits compartido.
TA0 CCR0 sits at vector 0xFFE8. This example uses TA2 (0xFFD8).CCR0 de TA0 está en 0xFFE8. Este ejemplo usa TA2 (0xFFD8).
Keep the interrupt short. The real work happens in the cooperative loop.Mantén la interrupción breve. El trabajo real ocurre en el bucle cooperativo.
The ISR never waits for main, and main never blocks the ISR. La ISR nunca espera a main, y main nunca bloquea a la ISR.
Round-robin: call each task once, in order, every pass of the loop.Round-robin: llama a cada tarea una vez, en orden, en cada vuelta del bucle.
No priorities, no preemption. Order in the list is the whole policy. Sin prioridades, sin expropiación. El orden en la lista es toda la política.
After one pass, the loop sleeps in LPM3. The tick interrupt wakes it.Tras una vuelta, el bucle duerme en LPM3. La interrupción del tick lo despierta.
bis.w #LPM3+GIE, sr.Bucle: ejecuta cada tarea, luego bis.w #LPM3+GIE, sr.bic.w #LPM4, 0(sp).ISR: borra los bits LPM en el SR apilado con bic.w #LPM4, 0(sp).The amber line is the tick. Between ticks the CPU draws almost nothing.La línea ámbar es el tick. Entre ticks la CPU consume casi nada.
blinkLed toggles the LED every ledPeriod ticks, scheduled by the SystemTimer.blinkLed conmuta el LED cada ledPeriod ticks, planificado por el SystemTimer.
One task that refuses to return on time blocks every other task.Una tarea que se niega a retornar a tiempo bloquea a todas las demás.
Short slices. Each task waits one quick lap for its turn.Rebanadas cortas. Cada tarea espera una vuelta rápida su turno.
For those 10 ms nothing else runs, no matter how urgent.Durante esos 10 ms nada más corre, por urgente que sea.
There is no kernel to step in. Timing is a shared responsibility of every task. No hay un kernel que intervenga. El tiempo es una responsabilidad compartida de cada tarea.
When tasks cannot be trusted to yield, a kernel takes the CPU by force.Cuando no se confía en que las tareas cedan, un kernel toma la CPU por la fuerza.
Switches land at task boundaries. No kernel, tiny RAM, but one bad task freezes the rest.Los cambios caen en los bordes de tarea. Sin kernel, poca RAM, pero una mala tarea congela al resto.
Amber lines are the timer tick: it cuts a task mid-run. A scheduler and a stack per task cost RAM, but a runaway task cannot starve the others.Las líneas ámbar son el tick del timer: corta una tarea a mitad. Un planificador y una pila por tarea cuestan RAM, pero una tarea descontrolada no deja sin CPU a las demás.
Structuring firmware without an operating system.Estructurar firmware sin sistema operativo.
Model each task as an FSM. Check, maybe change state, return.Modela cada tarea como una FSM. Comprueba, quizás cambia de estado, retorna.
Compare against a deadline. ISRs set flags, the loop consumes them.Compara contra un plazo. Las ISR activan flags, el bucle los consume.
LPM3 between passes. Cooperation only works if every task yields.LPM3 entre vueltas. La cooperación solo funciona si toda tarea cede.