diff --git a/trunk/bootrom/build/libraries/os/ARM11/Makefile b/trunk/bootrom/build/libraries/os/ARM11/Makefile index 7f72995..9a91a9c 100644 --- a/trunk/bootrom/build/libraries/os/ARM11/Makefile +++ b/trunk/bootrom/build/libraries/os/ARM11/Makefile @@ -45,6 +45,7 @@ SRCS = \ os_cache.c \ os_printf.c \ os_boot.c \ + os_event.c \ os_mmu.c \ TARGET_LIB = libos$(BROM_LIBSUFFIX).a diff --git a/trunk/bootrom/build/libraries/os/ARM9/Makefile b/trunk/bootrom/build/libraries/os/ARM9/Makefile index 0d3cbc3..4962578 100644 --- a/trunk/bootrom/build/libraries/os/ARM9/Makefile +++ b/trunk/bootrom/build/libraries/os/ARM9/Makefile @@ -48,6 +48,7 @@ SRCS = \ os_cache.c \ os_printf.c \ os_boot.c \ + os_event.c \ os_protectionUnit.c \ TARGET_LIB = libos_sp$(BROM_LIBSUFFIX).a diff --git a/trunk/bootrom/build/libraries/os/common/os_event.c b/trunk/bootrom/build/libraries/os/common/os_event.c new file mode 100644 index 0000000..8b85a0f --- /dev/null +++ b/trunk/bootrom/build/libraries/os/common/os_event.c @@ -0,0 +1,244 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS + File: os_event.c + + Copyright 2007-2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ +/* +#ifdef SDK_TWL +#include +#else +#include +#endif*/ + +#include + + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif + +/*---------------------------------------------------------------------------* + Name: OS_InitEvent + + Description: initialize event struct + + Arguments: event : pointer to event struct + + Returns: none + *---------------------------------------------------------------------------*/ +void osInitEvent( OSEvent *event ) +{ + osInitThreadQueue( &event->queue ); + event->flag = 0; +} + +/*---------------------------------------------------------------------------* + Name: osWaitEvent + + Description: sleep thread and wait event + if event is NULL, just sleep. + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + + Returns: none + *---------------------------------------------------------------------------*/ +u32 osWaitEvent(OSEvent* event, u32 pattern, OSEventMode mode ) +{ + return osWaitEventEx(event, pattern, mode, 0); +} + +/*---------------------------------------------------------------------------* + Name: osWaitEventEx + + Description: sleep thread and wait event + if event is NULL, just sleep. + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + clearBit : clear bits (in case of the end of waiting) + + Returns: none + *---------------------------------------------------------------------------*/ +u32 osWaitEventEx(OSEvent* event, u32 pattern, OSEventMode mode, u32 clearBit ) +{ + u32 retval = 0; + OSIntrMode enable = osDisableInterrupts(); + + SDK_ASSERT( event ); + + switch( mode ) + { + case OS_EVENT_MODE_AND: + while( (event->flag & pattern) != pattern ) + { + osSleepThread(&event->queue); + } + retval = event->flag; + break; + case OS_EVENT_MODE_OR: + while( (event->flag & pattern) == 0 ) + { + osSleepThread(&event->queue); + } + retval = event->flag; + break; + } + + //---- clear flag + if ( retval ) + { + event->flag &= ~clearBit; + } + + (void)osRestoreInterrupts(enable); + return retval; +} + +/*---------------------------------------------------------------------------* + Name: osSignalEvent + + Description: set event bit and wakeup thread. + if setPattern == 0, do nothing + + Arguments: event : pointer to event struct + setPattern : bit pattern to set + + Returns: none + *---------------------------------------------------------------------------*/ +void osSignalEvent(OSEvent* event, u32 setPattern) +{ + OSIntrMode enable = osDisableInterrupts(); + SDK_ASSERT( event ); + + if ( setPattern ) + { + event->flag |= setPattern; + osWakeupThread( &event->queue ); + } + + (void)osRestoreInterrupts(enable); +} + +/*---------------------------------------------------------------------------* + Name: osClearAllEvent + + Description: clear all event bits + + Arguments: event : pointer to event struct + + Returns: none + *---------------------------------------------------------------------------*/ +void osClearAllEvent(OSEvent* event) +{ + SDK_ASSERT( event ); + event->flag = 0; +} + +/*---------------------------------------------------------------------------* + Name: osClearEvent + + Description: clear specified event bits + + Arguments: event : pointer to event struct + clearBit : clear bits + + Returns: none + *---------------------------------------------------------------------------*/ +void osClearEvent(OSEvent* event, u32 clearBit) +{ + OSIntrMode enable = osDisableInterrupts(); + SDK_ASSERT( event ); + + event->flag &= ~clearBit; + + (void)osRestoreInterrupts(enable); +} + +/*---------------------------------------------------------------------------* + Name: osPollEvent + + Description: poll event struct if condition matches + + Arguments: event : waiting condition + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + + Returns: not 0 ... matched. return the event flag. + 0 ... not match. + *---------------------------------------------------------------------------*/ +u32 osPollEvent(OSEvent* event, u32 pattern, OSEventMode mode ) +{ + return osPollEventEx( event, pattern, mode, 0 ); +} + +/*---------------------------------------------------------------------------* + Name: osPollEventEx + + Description: poll event struct if condition matches + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + clearBit : clear bits (in case of matching) + + Returns: not 0 ... matched. return the event flag. + 0 ... not match. + *---------------------------------------------------------------------------*/ +u32 osPollEventEx(OSEvent* event, u32 pattern, OSEventMode mode, u32 clearBit ) +{ + u32 retval = 0; + OSIntrMode enable = osDisableInterrupts(); + + SDK_ASSERT( event ); + + switch( mode ) + { + case OS_EVENT_MODE_AND: + if ( (event->flag & pattern) == pattern ) + { + retval = event->flag; + } + break; + case OS_EVENT_MODE_OR: + if ( event->flag & pattern ) + { + retval = event->flag; + } + break; + } + + //---- clear flag + if ( retval ) + { + event->flag &= ~clearBit; + } + + (void)osRestoreInterrupts(enable); + return retval; +} + +#if defined(SDK_TCM_APPLY) && defined(SDK_ARM9) +#include +#endif diff --git a/trunk/bootrom/include/brom/os.h b/trunk/bootrom/include/brom/os.h index 40359d0..49b3019 100644 --- a/trunk/bootrom/include/brom/os.h +++ b/trunk/bootrom/include/brom/os.h @@ -43,6 +43,7 @@ extern "C" { #include #include #include +#include #ifdef SDK_ARM11 #include diff --git a/trunk/bootrom/include/brom/os/common/event.h b/trunk/bootrom/include/brom/os/common/event.h new file mode 100644 index 0000000..eaa8d9d --- /dev/null +++ b/trunk/bootrom/include/brom/os/common/event.h @@ -0,0 +1,200 @@ +/*---------------------------------------------------------------------------* + Project: TwlSDK - OS - include + File: event.h + + Copyright 2003-2008 Nintendo. All rights reserved. + + These coded instructions, statements, and computer programs contain + proprietary information of Nintendo of America Inc. and/or Nintendo + Company Ltd., and are protected by Federal copyright law. They may + not be disclosed to third parties or copied or duplicated in any form, + in whole or in part, without the prior written consent of Nintendo. + + $Date:: $ + $Rev$ + $Author$ + *---------------------------------------------------------------------------*/ + +#ifndef NITRO_OS_EVENT_H_ +#define NITRO_OS_EVENT_H_ + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +//---------------- event mode +typedef enum +{ + OS_EVENT_MODE_AND = 0, + OS_EVENT_MODE_OR = 1 +} +OSEventMode; + + +//---------------- event parameter +typedef struct +{ + vu32 flag; + OSThreadQueue queue; +} +OSEvent; + + +/*---------------------------------------------------------------------------* + Name: osInitEvent + + Description: initialize event struct + + Arguments: event : pointer to event struct + + Returns: none + *---------------------------------------------------------------------------*/ +void osInitEvent( OSEvent *event ); + +/*---------------------------------------------------------------------------* + Name: osWaitEvent + + Description: sleep thread and wait event + if event is NULL, just sleep. + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + + Returns: none + *---------------------------------------------------------------------------*/ +u32 osWaitEvent(OSEvent* event, u32 pattern, OSEventMode mode ); + +/*---------------------------------------------------------------------------* + Name: osWaitEventEx + + Description: sleep thread and wait event + if event is NULL, just sleep. + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + clearBit : clear bits (in case of the end of waiting) + + Returns: none + *---------------------------------------------------------------------------*/ +u32 osWaitEventEx(OSEvent* event, u32 pattern, OSEventMode mode, u32 clearBit ); + + +//---- inline access +static inline u32 osWaitEvent_And( OSEvent* event, u32 pattern ) +{ + return osWaitEventEx( event, pattern, OS_EVENT_MODE_AND, 0 ); +} +static inline u32 osWaitEvent_Or(OSEvent* event, u32 pattern ) +{ + return osWaitEventEx( event, pattern, OS_EVENT_MODE_OR, 0 ); +} +static inline u32 osWaitEventEx_And( OSEvent* event, u32 pattern, u32 clearBit ) +{ + return osWaitEventEx( event, pattern, OS_EVENT_MODE_AND, clearBit ); +} +static inline u32 osWaitEventEx_Or(OSEvent* event, u32 pattern, u32 clearBit ) +{ + return osWaitEventEx( event, pattern, OS_EVENT_MODE_OR, clearBit ); +} + +/*---------------------------------------------------------------------------* + Name: osSignalEvent + + Description: set event bit and wakeup thread. + if setPattern == 0, do nothing + + Arguments: event : pointer to event struct + setPattern : bit pattern to set + + Returns: none + *---------------------------------------------------------------------------*/ +void osSignalEvent(OSEvent* event, u32 setPattern); + +/*---------------------------------------------------------------------------* + Name: osClearEvent + + Description: clear specified event bits + + Arguments: event : pointer to event struct + clearBit : clear bits + + Returns: none + *---------------------------------------------------------------------------*/ +void osClearEvent(OSEvent* event, u32 clearBit); + +/*---------------------------------------------------------------------------* + Name: osClearAllEvent + + Description: clear all event bits + + Arguments: event : pointer to event struct + + Returns: none + *---------------------------------------------------------------------------*/ +void osClearAllEvent(OSEvent* event); + +/*---------------------------------------------------------------------------* + Name: osPollEvent + + Description: poll event struct if condition matches + + Arguments: event : waiting condition + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + + Returns: not 0 ... matched. returnd the event flag. + 0 ... not match. + *---------------------------------------------------------------------------*/ +u32 osPollEvent(OSEvent* event, u32 pattern, OSEventMode mode ); + +/*---------------------------------------------------------------------------* + Name: osPollEventEx + + Description: poll event struct if condition matches + + Arguments: event : pointer to event struct + pattern : event pattern + mode : event mode + OS_EVENT_MODE_AND ... wait for all event bit + OS_EVENT_MODE_OR ... wait for any event bit + clearBit : clear bits (in case of matching) + + Returns: not 0 ... matched. returnd the event flag. + 0 ... not match. + *---------------------------------------------------------------------------*/ +u32 osPollEventEx(OSEvent* event, u32 pattern, OSEventMode mode, u32 clearBit ); + +//---- inline access +static inline u32 osPollEvent_And( OSEvent* event, u32 pattern ) +{ + return osPollEventEx( event, pattern, OS_EVENT_MODE_AND, 0 ); +} +static inline u32 osPollEvent_Or(OSEvent* event, u32 pattern ) +{ + return osPollEventEx( event, pattern, OS_EVENT_MODE_OR, 0 ); +} +static inline u32 osPollEventEx_And( OSEvent* event, u32 pattern, u32 clearBit ) +{ + return osPollEventEx( event, pattern, OS_EVENT_MODE_AND, clearBit ); +} +static inline u32 osPollEventEx_Or(OSEvent* event, u32 pattern, u32 clearBit ) +{ + return osPollEventEx( event, pattern, OS_EVENT_MODE_OR, clearBit ); +} + +#ifdef __cplusplus +} /* extern "C" */ +#endif + +/* NITRO_OS_EVENT_H_ */ +#endif diff --git a/trunk/firmware/build/libraries/os/ARM11/Makefile b/trunk/firmware/build/libraries/os/ARM11/Makefile index b2124f9..8aa06e1 100644 --- a/trunk/firmware/build/libraries/os/ARM11/Makefile +++ b/trunk/firmware/build/libraries/os/ARM11/Makefile @@ -46,6 +46,7 @@ SRCS = \ os_cache.c \ os_printf.c \ os_boot.c \ + os_event.c \ os_mmu.c \ TARGET_LIB = libos$(FIRM_LIBSUFFIX).a diff --git a/trunk/firmware/build/libraries/os/ARM9/Makefile b/trunk/firmware/build/libraries/os/ARM9/Makefile index 91d38bf..d74293e 100644 --- a/trunk/firmware/build/libraries/os/ARM9/Makefile +++ b/trunk/firmware/build/libraries/os/ARM9/Makefile @@ -50,6 +50,7 @@ SRCS = \ os_printf.c \ os_boot.c \ os_protectionUnit.c \ + os_event.c \ TARGET_LIB = libos_sp$(FIRM_LIBSUFFIX).a