2015-10-19 20:22:13 +00:00
/*
* This file is subject to the terms of the GFX License . If a copy of
* the license was not distributed with this file , you can obtain one at :
*
* http : //ugfx.org/license.html
*/
2015-11-21 09:27:08 +00:00
# include "../../gfx.h"
2015-10-19 20:22:13 +00:00
# include <string.h>
# if GFX_USE_OS_CMSIS
void _gosHeapInit ( void ) ;
void _gosInit ( void )
{
# if !GFX_OS_NO_INIT
osKernelInitialize ( ) ;
if ( ! osKernelRunning ( ) )
osKernelStart ( ) ;
# elif !GFX_OS_INIT_NO_WARNING
# warning "GOS: Operating System initialization has been turned off. Make sure you call osKernelInitialize() and osKernelStart() before gfxInit() in your application!"
# endif
// Set up the heap allocator
_gosHeapInit ( ) ;
}
void _gosDeinit ( void )
{
}
void gfxMutexInit ( gfxMutex * pmutex )
{
2015-10-25 21:10:00 +00:00
osMutexDef_t def ;
def . mutex = pmutex - > mutex ;
pmutex - > id = osMutexCreate ( & def ) ;
2015-10-19 20:22:13 +00:00
}
void gfxSemInit ( gfxSem * psem , semcount_t val , semcount_t limit )
{
2015-10-25 21:10:00 +00:00
osSemaphoreDef_t def ;
def . semaphore = psem - > semaphore ;
2015-10-26 13:04:51 +00:00
if ( val > limit ) val = limit ;
psem - > available = limit - val ;
psem - > id = osSemaphoreCreate ( & def , val ) ;
2015-10-19 20:22:13 +00:00
}
void gfxSemDestroy ( gfxSem * psem )
{
osSemaphoreDelete ( psem - > id ) ;
}
bool_t gfxSemWait ( gfxSem * psem , delaytime_t ms )
{
2015-10-26 13:08:38 +00:00
if ( osSemaphoreWait ( psem - > id , ms ) > 0 ) {
2015-10-26 13:04:51 +00:00
psem - > available + + ;
return TRUE ;
}
return FALSE ;
2015-10-19 20:22:13 +00:00
}
bool_t gfxSemWaitI ( gfxSem * psem )
{
2015-10-26 13:04:51 +00:00
return gfxSemWait ( psem , 0 ) ;
2015-10-19 20:22:13 +00:00
}
void gfxSemSignal ( gfxSem * psem )
{
2015-10-26 13:04:51 +00:00
gfxSemSignalI ( psem ) ;
2015-10-19 20:22:13 +00:00
}
void gfxSemSignalI ( gfxSem * psem )
{
2015-10-26 13:04:51 +00:00
if ( psem - > available ) {
psem - > available - - ;
osSemaphoreRelease ( psem - > id ) ;
}
2015-10-19 20:22:13 +00:00
}
gfxThreadHandle gfxThreadCreate ( void * stackarea , size_t stacksz , threadpriority_t prio , DECLARE_THREAD_FUNCTION ( ( * fn ) , p ) , void * param )
{
osThreadDef_t def ;
( void ) stackarea ;
def . pthread = ( os_pthread ) fn ;
def . tpriority = prio ;
def . instances = 1 ;
def . stacksize = stacksz ;
return osThreadCreate ( & def , param ) ;
}
threadreturn_t gfxThreadWait ( gfxThreadHandle thread ) {
while ( osThreadGetPriority ( thread ) = = osPriorityError )
gfxYield ( ) ;
}
# endif /* GFX_USE_OS_CMSIS */