React to events without polling, and stay asleep until one arrives. Reaccionar a eventos sin sondear, y dormir hasta que llegue uno.
Santi Scagliusi, PhD
The same button press, handled two different ways.La misma pulsación de botón, atendida de dos formas distintas.
The CPU loops, asking the flag over and over if the event happened.La CPU itera, preguntando al flag una y otra vez si ocurrió el evento.
Burns cycles and energy while nothing happens.Quema ciclos y energía mientras no pasa nada.
The hardware watches the flag. The event calls the CPU, not the other way around.El hardware vigila el flag. El evento llama a la CPU, no al revés.
Sleeps at near-zero current, wakes only when needed.Duerme con corriente casi nula, despierta solo cuando hace falta.
How does the CPU learn which device asked, and which routine to run?¿Cómo sabe la CPU qué dispositivo pidió, y qué rutina ejecutar?
Inside the chip the lines are free, so the MSP430 gives every source its own vector.Dentro del chip las líneas son gratis, así que el MSP430 da a cada fuente su propio vector.
All three must hold at the same time, or the request just waits.Las tres deben cumplirse a la vez, o la petición espera.
Miss any one input and the request just waits. The vector must already point at a real ISR.Si falta una entrada, la petición espera. El vector ya debe apuntar a una ISR real.
From the event to the first ISR instruction: six fixed steps, about 6 cycles.Del evento a la primera instrucción de la ISR: seis pasos fijos, unos 6 ciclos.
128 bytes at 0xFF80–0xFFFE. Higher address means higher priority.128 bytes en 0xFF80–0xFFFE. Dirección más alta significa mayor prioridad.
You never read these addresses by hand. .intvec NAME, ISR installs the pointer for you.Nunca lees estas direcciones a mano. .intvec NAME, ISR instala el puntero por ti.
When several requests are pending at once, the address decides who goes first.Cuando varias peticiones están pendientes a la vez, la dirección decide quién va primero.
An ISR is not interrupted unless it sets GIE again, at the cost of more stack.Una ISR no se interrumpe salvo que vuelva a poner GIE, a costa de más pila.
The same SR holds the condition flags, the global enable, and the sleep bits.El mismo SR guarda los flags de condición, el permiso global y los bits de reposo.
GIE (bit 3) is the global switch. EINT sets it, DINT clears it.GIE (bit 3) es el interruptor global. EINT lo activa, DINT lo limpia.
Bits 4–7 select the low-power mode. Setting them is how you go to sleep.Bits 4–7 seleccionan el modo de bajo consumo. Activarlos es cómo te duermes.
Hardware calls it, you do not. A few constraints follow from that.La llama el hardware, no tú. De ahí salen unas pocas restricciones.
End with RETI, not RET. It pops SR then PC, restoring flags and sleep mode.Termina con RETI, no RET. Desapila SR y luego PC, restaurando flags y modo de reposo.
Save what you touch. PUSH and POP any working register the ISR uses.Guarda lo que toques. Apila y desapila cualquier registro de trabajo que uses.
Clear the flag. Single-source vectors auto-clear; shared flags like P1IFG you clear yourself.Limpia el flag. Los de fuente única se autoborran; los compartidos como P1IFG los limpias tú.
Stay short. Do the minimum and return. No long loops inside the ISR.Sé breve. Haz lo mínimo y vuelve. Sin bucles largos dentro de la ISR.
Configure the source, install the vector, then let the ISR do one thing.Configura la fuente, instala el vector, y deja que la ISR haga una sola cosa.
main: bic.b #BIT1, &P1DIR ; P1.1 input bis.b #BIT1, &P1REN ; resistor on bis.b #BIT1, &P1OUT ; pull-up bis.b #BIT1, &P1IES ; falling edge bic.b #BIT1, &P1IFG ; clear flag bis.b #BIT1, &P1IE ; enable eint ; GIE = 1
P1ISR: xor.b #BIT0, &P1OUT ; toggle LED1 bic.b #BIT1, &P1IFG ; clear P1.1 flag reti .intvec PORT1_VECTOR, P1ISR
P1 is a shared vector, so the flag is cleared by hand.P1 es un vector compartido, así que el flag se limpia a mano.
All eight P1 pins share vector 0xFFDA. Which pin fired?Los ocho pines de P1 comparten el vector 0xFFDA. ¿Qué pin disparó?
bit.b #BIT0, &P1IFG jz next bic.b #BIT0, &P1IFG ; ... one test per bit ...
Long, and you set the priority order yourself.Largo, y tú fijas el orden de prioridad.
add.w &P1IV, PC reti ; 0 = none jmp P1_0 ; 2 = P1.0 jmp P1_1 ; 4 = P1.1
Reading P1IV returns (pin+1)×2 and auto-clears that flag.Leer P1IV devuelve (pin+1)×2 y autoborra ese flag.
Value = (pin + 1) × 2. P1IV reports the highest-priority pending pin and auto-clears it.Valor = (pin + 1) × 2. P1IV informa del pin pendiente de mayor prioridad y lo autoborra.
Each mode shuts down more clocks. What stays on decides what can still wake you.Cada modo apaga más relojes. Lo que queda activo decide qué puede despertarte.
LPM3 is the common choice: lowest current that still keeps a time base.LPM3 es la elección habitual: la menor corriente que aún mantiene una base de tiempo.
Pick a mode and watch which clocks survive.Elige un modo y observa qué relojes sobreviven.
The default state is asleep. Each interrupt is a short burst of work, then back to sleep.El estado por defecto es dormir. Cada interrupción es una breve ráfaga de trabajo, y a dormir.
bis.w #GIE+LPM3, sr ; sleep
bic.w #LPM3, 0(sp) ; in stacked SR
Timer_A0 counts up to CCR0, fires its own vector, and toggles an output, no CPU polling.Timer_A0 cuenta hasta CCR0, dispara su vector y conmuta una salida, sin sondeo de CPU.
main: mov.w #20, &TA0CCR0 ; period = CCR0+1 mov.w #OUTMOD_4|CCIE, &TA0CCTL0 mov.w #TASSEL_1|MC_1|TACLR, &TA0CTL eint ; GIE = 1 loop: nop ; timer drives the ISR jmp loop TA00ISR: reti ; CCR0 flag auto-clears .intvec TIMER0_A0_VECTOR, TA00ISR
Open /msp430simulator and pick M9 · Timer: square wave + IRQ.Abre /msp430simulator y elige M9 · Timer: square wave + IRQ.
Watch the Timer_A panel: TA0R ramps 0 to CCR0, CCIFG sets, the CCR0 ISR runs each period.Observa el panel Timer_A: TA0R sube de 0 a CCR0, CCIFG se activa, la ISR de CCR0 corre cada periodo.
▶ Try it in the simulatorProbalo en el simuladorInterrupts and sleep, in three ideas.Interrupciones y reposo, en tres ideas.
A flag, its enable, and the global enable. All three, or the request waits.Un flag, su habilitación y el permiso global. Las tres, o la petición espera.
Entry pushes PC and SR, clears GIE, loads the vector. RETI undoes it.La entrada apila PC y SR, limpia GIE, carga el vector. RETI lo deshace.
Sleep in main, work in the ISR, clear LPM in the stacked SR to stay awake.Duerme en main, trabaja en la ISR, limpia LPM en el SR apilado para seguir activo.