Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FuriHal: interrupt priorities and documentation #3366

Merged
merged 6 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/signal_reader/signal_reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,10 @@ void signal_reader_start(SignalReader* instance, SignalReaderCallback callback,

// Start DMA irq, higher priority than normal
furi_hal_interrupt_set_isr_ex(
SIGNAL_READER_DMA_GPIO_IRQ, 14, furi_hal_sw_digital_pin_dma_rx_isr, instance);
SIGNAL_READER_DMA_GPIO_IRQ,
FuriHalInterruptPriorityVeryHigh,
furi_hal_sw_digital_pin_dma_rx_isr,
instance);

// Start DMA Sync timer
LL_DMA_EnableChannel(SIGNAL_READER_DMA_CNT_SYNC_DEF);
Expand Down
4 changes: 2 additions & 2 deletions targets/f18/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,50.1,,
Version,+,51.0,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Header,+,applications/services/cli/cli_vcp.h,,
Expand Down Expand Up @@ -1156,7 +1156,7 @@ Function,-,furi_hal_init,void,
Function,-,furi_hal_init_early,void,
Function,-,furi_hal_interrupt_init,void,
Function,+,furi_hal_interrupt_set_isr,void,"FuriHalInterruptId, FuriHalInterruptISR, void*"
Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, uint16_t, FuriHalInterruptISR, void*"
Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, FuriHalInterruptPriority, FuriHalInterruptISR, void*"
Function,+,furi_hal_light_blink_set_color,void,Light
Function,+,furi_hal_light_blink_start,void,"Light, uint8_t, uint16_t, uint16_t"
Function,+,furi_hal_light_blink_stop,void,
Expand Down
4 changes: 2 additions & 2 deletions targets/f7/api_symbols.csv
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
entry,status,name,type,params
Version,+,50.1,,
Version,+,51.0,,
Header,+,applications/drivers/subghz/cc1101_ext/cc1101_ext_interconnect.h,,
Header,+,applications/services/bt/bt_service/bt.h,,
Header,+,applications/services/cli/cli.h,,
Expand Down Expand Up @@ -1263,7 +1263,7 @@ Function,-,furi_hal_init,void,
Function,-,furi_hal_init_early,void,
Function,-,furi_hal_interrupt_init,void,
Function,+,furi_hal_interrupt_set_isr,void,"FuriHalInterruptId, FuriHalInterruptISR, void*"
Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, uint16_t, FuriHalInterruptISR, void*"
Function,+,furi_hal_interrupt_set_isr_ex,void,"FuriHalInterruptId, FuriHalInterruptPriority, FuriHalInterruptISR, void*"
Function,+,furi_hal_light_blink_set_color,void,Light
Function,+,furi_hal_light_blink_start,void,"Light, uint8_t, uint16_t, uint16_t"
Function,+,furi_hal_light_blink_stop,void,
Expand Down
7 changes: 5 additions & 2 deletions targets/f7/furi_hal/furi_hal_infrared.c
Original file line number Diff line number Diff line change
Expand Up @@ -406,7 +406,10 @@ static void furi_hal_infrared_configure_tim_cmgr2_dma_tx(void) {
LL_DMA_EnableIT_TC(INFRARED_DMA_CH1_DEF);

furi_hal_interrupt_set_isr_ex(
INFRARED_DMA_CH1_IRQ, 4, furi_hal_infrared_tx_dma_polarity_isr, NULL);
INFRARED_DMA_CH1_IRQ,
FuriHalInterruptPriorityKamiSama,
furi_hal_infrared_tx_dma_polarity_isr,
NULL);
}

static void furi_hal_infrared_configure_tim_rcr_dma_tx(void) {
Expand Down Expand Up @@ -436,7 +439,7 @@ static void furi_hal_infrared_configure_tim_rcr_dma_tx(void) {
LL_DMA_EnableIT_HT(INFRARED_DMA_CH2_DEF);
LL_DMA_EnableIT_TE(INFRARED_DMA_CH2_DEF);

furi_hal_interrupt_set_isr_ex(INFRARED_DMA_CH2_IRQ, 5, furi_hal_infrared_tx_dma_isr, NULL);
furi_hal_interrupt_set_isr(INFRARED_DMA_CH2_IRQ, furi_hal_infrared_tx_dma_isr, NULL);
}

static void furi_hal_infrared_tx_fill_buffer_last(uint8_t buf_num) {
Expand Down
12 changes: 7 additions & 5 deletions targets/f7/furi_hal/furi_hal_interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#define TAG "FuriHalInterrupt"

#define FURI_HAL_INTERRUPT_DEFAULT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY)
#define FURI_HAL_INTERRUPT_DEFAULT_PRIORITY (configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY + 2)
skotopes marked this conversation as resolved.
Show resolved Hide resolved

typedef struct {
FuriHalInterruptISR isr;
Expand Down Expand Up @@ -120,16 +120,18 @@ void furi_hal_interrupt_init() {
}

void furi_hal_interrupt_set_isr(FuriHalInterruptId index, FuriHalInterruptISR isr, void* context) {
furi_hal_interrupt_set_isr_ex(index, FURI_HAL_INTERRUPT_DEFAULT_PRIORITY, isr, context);
furi_hal_interrupt_set_isr_ex(index, FuriHalInterruptPriorityNormal, isr, context);
}

void furi_hal_interrupt_set_isr_ex(
FuriHalInterruptId index,
uint16_t priority,
FuriHalInterruptPriority priority,
FuriHalInterruptISR isr,
void* context) {
furi_check(index < FuriHalInterruptIdMax);
furi_check(priority <= 15);
furi_check(priority >= -2 && priority <= 3);

uint16_t real_priority = FURI_HAL_INTERRUPT_DEFAULT_PRIORITY - priority;

if(isr) {
// Pre ISR set
Expand All @@ -147,7 +149,7 @@ void furi_hal_interrupt_set_isr_ex(
if(isr) {
// Post ISR set
furi_hal_interrupt_clear_pending(index);
furi_hal_interrupt_enable(index, priority);
furi_hal_interrupt_enable(index, real_priority);
} else {
// Post ISR clear
}
Expand Down
43 changes: 31 additions & 12 deletions targets/f7/furi_hal/furi_hal_interrupt.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,46 @@ typedef enum {
FuriHalInterruptIdMax,
} FuriHalInterruptId;

typedef enum {
FuriHalInterruptPriorityVeryLow =
-2, /**< Lowest priority level, you can use ISR-safe OS primitives */
FuriHalInterruptPriorityLow =
-1, /**< Lower than normal priority level, you can use ISR-safe OS primitives */
FuriHalInterruptPriorityNormal =
0, /**< Normal(default) priority level, you can use ISR-safe OS primitives */
FuriHalInterruptPriorityHigh =
1, /**< Higher than normal priority level, you can use ISR-safe OS primitives */
FuriHalInterruptPriorityVeryHigh =
2, /**< Highest priority level, you can use ISR-safe OS primitives */

/* Special group, read docs first(ALL OF THEM: especially FreeRTOS configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY) */
FuriHalInterruptPriorityKamiSama =
3, /**< Forget about thread safety, you are god now, no one can prevent you from fucking up OS critical section, you are not allowed to use any OS primitives, but who can stop you? Use this priority only for direct hardware interaction with LL HAL. */
skotopes marked this conversation as resolved.
Show resolved Hide resolved
} FuriHalInterruptPriority;

/** Initialize interrupt subsystem */
void furi_hal_interrupt_init();

/** Set ISR and enable interrupt with default priority
* We don't clear interrupt flags for you, do it by your self.
* @param index - interrupt ID
* @param isr - your interrupt service routine or use NULL to clear
* @param context - isr context
/** Set ISR and enable interrupt with default priority We don't clear interrupt
skotopes marked this conversation as resolved.
Show resolved Hide resolved
* flags for you, do it by your self.
*
* @param index - interrupt ID
* @param isr - your interrupt service routine or use NULL to clear
* @param context - isr context
*/
void furi_hal_interrupt_set_isr(FuriHalInterruptId index, FuriHalInterruptISR isr, void* context);

/** Set ISR and enable interrupt with custom priority
* We don't clear interrupt flags for you, do it by your self.
* @param index - interrupt ID
* @param priority - 0 to 15, 0 highest
* @param isr - your interrupt service routine or use NULL to clear
* @param context - isr context
/** Set ISR and enable interrupt with custom priority We don't clear interrupt
* flags for you, do it by your self.
*
* @param index - interrupt ID
* @param priority - One of FuriHalInterruptPriority
* @param isr - your interrupt service routine or use NULL to clear
* @param context - isr context
*/
void furi_hal_interrupt_set_isr_ex(
FuriHalInterruptId index,
uint16_t priority,
FuriHalInterruptPriority priority,
FuriHalInterruptISR isr,
void* context);

Expand Down