Difference between revisions of "GOS"

From uGFX Wiki
Jump to: navigation, search
(Threading)
(Threading)
Line 9: Line 9:
 
== Threading ==
 
== Threading ==
 
It is highly recommended to use the uGFX API to create and manage threads. This way the application is fully portable. In most cases these are just 1:1 wrappers to the calls from the underlying operating systems so there is no  additional overhead.
 
It is highly recommended to use the uGFX API to create and manage threads. This way the application is fully portable. In most cases these are just 1:1 wrappers to the calls from the underlying operating systems so there is no  additional overhead.
 +
 +
The following demos which can be found in the uGFX repository show how to properly use the threading API:
 +
* ''/demos/modules/gos/threads''
 +
* ''/demos/modules/gos/threads_advanced''
  
 
== Memory management ==
 
== Memory management ==

Revision as of 18:03, 28 November 2014

GOS is the module which builds the abstraction layer between µGFX and the underlying system. The underlying system can be an RTOS such as ChibiOS or FreeRTOS, or also just a stand-alone library like the STDperiph library from STmicroelectronics. The GOS module allows to write completely platform independent application code.

API reference

The API reference of the GOS module can be found here.

Initialization

For code portability reasons the underlying system will be automatically initialized when gosInit() is called unless GFX_NO_OS_INIT is set to TRUE in the configuration file.

Threading

It is highly recommended to use the uGFX API to create and manage threads. This way the application is fully portable. In most cases these are just 1:1 wrappers to the calls from the underlying operating systems so there is no additional overhead.

The following demos which can be found in the uGFX repository show how to properly use the threading API:

  • /demos/modules/gos/threads
  • /demos/modules/gos/threads_advanced

Memory management

It is highly recommended to use the uGFX API for memory management. This way the application is fully portable. In most cases these calls are just 1:1 wrappers to the calls from the underlying operating system so there is no additional overhead.

Existing ports

The following ports already exist and are part of the official repository:

  • ChibiOS/RT
  • FreeRTOS
  • eCos
  • rawrtos
  • BareMetal (no OS at all)
  • Linux
  • Mac OS X
  • Windows

BareMetal

It's possible to run µGFX directly on a bare-metal system like the stdperipheral library for the STM controller without any underlying OS. Start with the RAW32 implementation. This supports a simple non-preemptive scheduler. You still need to provide some basic routines such as a routine to get the system tick count.

Porting

Porting uGFX to a new underlying system is fairly easy. Only a couple of functions and data types have to be implemented and declared.

Functions

ToDo

void            gfxHalt(const char *msg);
void            gfxExit(void);
void*           gfxAlloc(size_t sz);
void*           gfxRealloc(void *p, size_t oldsz, size_t newsz);
void            gfxFree(void *ptr);
void            gfxYield(void);
void            gfxSleepMilliseconds(delaytime_t ms);
void            gfxSleepMicroseconds(delaytime_t ms);
systemticks_t   gfxSystemTicks(void);
systemticks_t   gfxMillisecondsToTicks(delaytime_t ms);
void            gfxSystemLock(void);
void            gfxSystemUnlock(void);
void            gfxMutexInit(gfxMutex *pmutex);
void            gfxMutexDestroy(gfxMutex *pmutex);
void            gfxMutexEnter(gfxMutex *pmutex);
void            gfxMutexExit(gfxMutex *pmutex);
void            gfxSemInit(gfxSem *psem, semcount_t val, semcount_t limit);
void            gfxSemDestroy(gfxSem *psem);
bool_t          gfxSemWait(gfxSem *psem, delaytime_t ms);
void            gfxSemSignal(gfxSem *psem);
void            gfxSemSignalI(gfxSem *psem);
semcount_t      gfxSemCounter(gfxSem *pSem);
semcount_t      gfxSemCounterI(gfxSem *pSem);
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio,
                                DECLARE_THREAD_FUNCTION((*fn),p), void *param);
threadreturn_t  gfxThreadWait(gfxThreadHandle thread);
gfxThreadHandle gfxThreadMe(void)
void            gfxThreadClose(gfxThreadHandle thread);

Data types

ToDo

Examples

When creating a new port, taking a look at existing ones can help a lot. The existing ports can be found under /src/gos/'