diff --git a/docs/API b/docs/API index dfa6690260..a61408e6aa 100644 --- a/docs/API +++ b/docs/API @@ -227,7 +227,8 @@ Various int set_irq_level(int level) Sets the interrupt level (0 = lowest, 15 = highest) and returns the - previous level. + previous level. Note that you must shift the argument 4 bits to the left: + set_irq_level(level << 4); void queue_init(struct event_queue *q) diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 66c7e978fb..cbb6d58f7b 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -30,6 +30,7 @@ #include "adc.h" #include "serial.h" #include "power.h" +#include "system.h" struct event_queue button_queue; @@ -256,10 +257,10 @@ static int button_flip(int button) */ void button_set_flip(bool flip) { - if (flip != flipped) /* not the curent setting */ + if (flip != flipped) /* not the current setting */ { /* avoid race condition with the button_tick() */ - int oldlevel = set_irq_level(15); + int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); lastbtn = button_flip(lastbtn); flipped = flip; set_irq_level(oldlevel); diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index 563ff3e25c..621f53e11e 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c @@ -118,7 +118,7 @@ bool ide_powered(void) void power_off(void) { - set_irq_level(15); + set_irq_level(HIGHEST_IRQ_LEVEL); #ifdef HAVE_POWEROFF_ON_PBDR and_b(~0x10, &PBDRL); or_b(0x10, &PBIORL); diff --git a/firmware/drivers/serial.c b/firmware/drivers/serial.c index 5aae38e58c..2badf2e39f 100644 --- a/firmware/drivers/serial.c +++ b/firmware/drivers/serial.c @@ -172,7 +172,7 @@ static void screen_dump(void) serial_enable_tx(); - level = set_irq_level(15); + level = set_irq_level(HIGHEST_IRQ_LEVEL); for(y = 0;y < LCD_HEIGHT/8;y++) { for(x = 0;x < LCD_WIDTH;x++) diff --git a/firmware/export/system.h b/firmware/export/system.h index 5886145d7b..038d9567e0 100644 --- a/firmware/export/system.h +++ b/firmware/export/system.h @@ -25,7 +25,6 @@ extern void system_reboot (void); extern void system_init(void); -extern int set_irq_level(int level); #define FREQ CPU_FREQ #define BAUDRATE 9600 @@ -73,6 +72,20 @@ extern int set_irq_level(int level); #ifndef SIMULATOR +/**************************************************************************** + * Interrupt level setting + * The level is left shifted 4 bits + ****************************************************************************/ +#define HIGHEST_IRQ_LEVEL (15<<4) +static inline int set_irq_level(int level) +{ + int i; + /* Read the old level and set the new one */ + asm volatile ("stc sr, %0" : "=r" (i)); + asm volatile ("ldc %0, sr" : : "r" (level)); + return i; +} + static inline short SWAB16(short value) /* result[15..8] = value[ 7..0]; diff --git a/firmware/kernel.c b/firmware/kernel.c index 1c37f004a4..84fb438b49 100644 --- a/firmware/kernel.c +++ b/firmware/kernel.c @@ -118,7 +118,7 @@ void queue_post(struct event_queue *q, int id, void *data) int wr; int oldlevel; - oldlevel = set_irq_level(15); + oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); wr = (q->write++) & QUEUE_LENGTH_MASK; q->events[wr].id = id; @@ -201,7 +201,7 @@ void IMIA0(void) int tick_add_task(void (*f)(void)) { int i; - int oldlevel = set_irq_level(15); + int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); /* Add a task if there is room */ for(i = 0;i < MAX_NUM_TICK_TASKS;i++) @@ -221,7 +221,7 @@ int tick_add_task(void (*f)(void)) int tick_remove_task(void (*f)(void)) { int i; - int oldlevel = set_irq_level(15); + int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); /* Remove a task if it is there */ for(i = 0;i < MAX_NUM_TICK_TASKS;i++) diff --git a/firmware/mp3_playback.c b/firmware/mp3_playback.c index 422a0e6822..a775ba4ff5 100644 --- a/firmware/mp3_playback.c +++ b/firmware/mp3_playback.c @@ -338,7 +338,7 @@ static void postpone_dma_tick(void) #ifdef HAVE_MAS3587F void demand_irq_enable(bool on) { - int oldlevel = set_irq_level(15); + int oldlevel = set_irq_level(HIGHEST_IRQ_LEVEL); if(on) { diff --git a/firmware/system.c b/firmware/system.c index 3ec56f7c15..cb0cb29778 100644 --- a/firmware/system.c +++ b/firmware/system.c @@ -318,18 +318,6 @@ void system_reboot (void) "r"(*(int*)0),"r"(4)); } -/**************************************************************************** - * Interrupt level setting - ****************************************************************************/ -int set_irq_level(int level) -{ - int i; - /* Read the old level and set the new one */ - asm volatile ("stc sr, %0" : "=r" (i)); - asm volatile ("ldc %0, sr" : : "r" (level << 4)); - return (i >> 4) & 0x0f; -} - void UIE (unsigned int pc) /* Unexpected Interrupt or Exception */ { bool state = true;