This repository has been archived by the owner on Oct 24, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libseven 0.11.0: split IRQ module for LTO, API rework
- removed CriticalSection functions - rewrote IRQ API functions in C, for readability/LTO - renamed IRQ function types, Callback -> Handler - renamed ISR related macros and types
- Loading branch information
1 parent
1add6e6
commit 062b7b8
Showing
10 changed files
with
346 additions
and
430 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
#include <seven/base.h> | ||
#include <seven/hw/irq.h> | ||
|
||
extern IsrFn isrDefault; | ||
extern IsrFn isrSimple; | ||
extern IsrFn isrStub; | ||
|
||
extern IrqHandlerFn* ISR_SIMPLE_HANDLER; | ||
extern IrqHandlerFn* ISR_DEFAULT_HANDLERS[16]; | ||
|
||
extern void irqInit(IsrFn *isr) | ||
{ | ||
REG_IME = 0; | ||
REG_IE = 0; | ||
REG_IF = 0xFFFF; | ||
|
||
MEM_ISR = isr; | ||
|
||
REG_IME = 1; | ||
return; | ||
} | ||
|
||
extern void irqInitDefault(void) | ||
{ | ||
REG_IME = 0; | ||
|
||
for (usize i = 0; i < 16; i++) | ||
{ | ||
ISR_DEFAULT_HANDLERS[i] = NULL; | ||
} | ||
|
||
irqInit(isrDefault); | ||
} | ||
|
||
extern void irqInitSimple(IrqHandlerFn *handler) | ||
{ | ||
REG_IME = 0; | ||
|
||
ISR_SIMPLE_HANDLER = handler; | ||
|
||
irqInit(isrSimple); | ||
} | ||
|
||
extern void irqInitStub(void) | ||
{ | ||
irqInit(isrStub); | ||
} | ||
|
||
extern bool irqHandlerSet(u16 irq, IrqHandlerFn *fn) | ||
{ | ||
if (!irq || (irq & (irq - 1))) | ||
{ | ||
return false; | ||
} | ||
|
||
ISR_DEFAULT_HANDLERS[(0x09AF0000 * irq) >> 28] = fn; | ||
|
||
return true; | ||
} | ||
|
||
extern bool irqHandlerGet(u16 irq, IrqHandlerFn **fn) | ||
{ | ||
if (!irq || (irq & (irq - 1))) | ||
{ | ||
return false; | ||
} | ||
|
||
*fn = ISR_DEFAULT_HANDLERS[(0x09AF0000 * irq) >> 28]; | ||
|
||
return true; | ||
} | ||
|
||
extern bool irqHandlerSwap(u16 irq, IrqHandlerFn **fn) | ||
{ | ||
if (!irq || (irq & (irq - 1))) | ||
{ | ||
return false; | ||
} | ||
|
||
u32 idx = (0x09AF0000 * irq) >> 28; | ||
|
||
IrqHandlerFn *p = ISR_DEFAULT_HANDLERS[idx]; | ||
ISR_DEFAULT_HANDLERS[idx] = *fn; | ||
*fn = p; | ||
|
||
return true; | ||
} | ||
|
||
extern u16 irqEnable(u16 irqs) | ||
{ | ||
u32 ime = REG_IME; | ||
REG_IME = 0; | ||
|
||
u16 old = REG_IE; | ||
REG_IE = old | irqs; | ||
|
||
REG_IME = ime; | ||
|
||
return old; | ||
} | ||
|
||
extern u16 irqDisable(u16 irqs) | ||
{ | ||
u32 ime = REG_IME; | ||
REG_IME = 0; | ||
|
||
u16 old = REG_IE; | ||
REG_IE = old & ~irqs; | ||
|
||
REG_IME = ime; | ||
|
||
return old; | ||
} | ||
|
||
extern void irqFree(void (*f)(void*), void *arg) | ||
{ | ||
u32 ime = REG_IME; | ||
REG_IME = 0; | ||
|
||
f(arg); | ||
|
||
REG_IME = ime; | ||
|
||
return; | ||
} |
Oops, something went wrong.