-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAK_Interrupts.c
More file actions
42 lines (37 loc) · 1.5 KB
/
Copy pathAK_Interrupts.c
File metadata and controls
42 lines (37 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
// ----------------------------------
// | AK_Interrupts.c |
// | ArduinoKit (User Project Side) |
// | |
// | Last Update: 2026-07-20 |
// ----------------------------------
//
// Place this file in your S4A project directory and list it in the project's
// .swift4p `files:` section (e.g. `- AK_Interrupts.c`).
//
// WHY C, NOT Swift @interruptHandler?
// S4A's @interruptHandler currently lowers like avr-libc ISR_NOBLOCK: it
// emits `sei` at the start of the vector. USART_UDRE / USART_RX do not clear
// their condition on entry, so early `sei` re-enters the same ISR until the
// stack overflows (Serial often prints ~2 characters then halts).
//
// avr-libc's ISR() defaults to "block" / `signal` semantics (no early `sei`),
// which matches ArduinoCore and is safe for UDRE/RX. See:
// https://www.nongnu.org/avr-libc/user-manual/group__avr__interrupts.html#ga44569cb914d2aaf8fbb436f8f7c4ca68
//
// Library code cannot own these vectors (they must live in the final linked
// image). ArduinoKit exports the C-callable handlers below; this file only
// registers the AVR vectors and forwards into Swift.
#include <avr/interrupt.h>
/* Implemented in ArduinoKit (InterruptHook.swift) via @_cdecl. */
void AK_timer0Overflow(void);
void AK_usartRxComplete(void);
void AK_usartDataRegisterEmpty(void);
ISR(TIMER0_OVF_vect) {
AK_timer0Overflow();
}
ISR(USART_RX_vect) {
AK_usartRxComplete();
}
ISR(USART_UDRE_vect) {
AK_usartDataRegisterEmpty();
}