Difference between revisions of "GOS"
(→Existing ports) |
(→CPU) |
||
Line 22: | Line 22: | ||
=== CPU === | === CPU === | ||
− | The '''GFX_CPU''' configuration setting allows enabling CPU specific optimization code | + | The '''GFX_CPU''' configuration setting allows enabling CPU specific optimization code. |
Available settings: | Available settings: | ||
{| class="wikitable" | {| class="wikitable" |
Revision as of 17:09, 4 November 2015
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.
Contents
API reference
The API reference of the GOS module can be found here.
Configuration
There are several configuration options for the GOS module inside the configuration file. Note that none of these configuration settings need to be specified in 99% of the cases as everything comes with a reasonable default implementation/setting.
Compiler
The GFX_COMPILER configuration setting allows enabling compiler specific optimization code. Currently only used by the µGFX generic thread handling (GOS_USE_OS_RAW32 and GOS_USE_OS_ARDUINO). Available settings:
Option | Description |
---|---|
GFX_COMPILER_UNKNOWN | Unknown compiler. This is the default setting. |
GFX_COMPILER_MINGW32 | MinGW32 (x86) compiler for Windows. |
CPU
The GFX_CPU configuration setting allows enabling CPU specific optimization code. Available settings:
Option | Description |
---|---|
GFX_CPU_UNKNOWN | Unknown CPU. This is the default setting. |
GFX_CPU_CORTEX_M0 | Cortex M0. |
GFX_CPU_CORTEX_M1 | Cortex M1. |
GFX_CPU_CORTEX_M2 | Cortex M2. |
GFX_CPU_CORTEX_M3 | Cortex M3. |
GFX_CPU_CORTEX_M4 | Cortex M4. |
GFX_CPU_CORTEX_M4_FP | Cortex M4 with hardware floating point unit. |
GFX_CPU_CORTEX_M7 | Cortex M7. |
GFX_CPU_CORTEX_M7_FP | Cortex M7 with hardware floating point unit. |
Initialization
For code portability reasons the underlying system will be automatically initialized when gosInit()
is called unless GFX_OS_NO_INIT is set to TRUE in the configuration file.
Warnings
By default the GOS module will print out a warning during compile time to notify the user that he needs to make sure that his OS has been initialized before calling gfxInit(). Setting GFX_OS_INIT_NO_WARNING to TRUE will suppress this warning. Note that this warning is only printed out when the GOS module cannot initialize the operating system automatically. This is the case when eg. the RAW32 port is used (see BareBone).
Extra functions
It is possible to submit code that is executed when µGFX is being initialized and deinitialized through GFX_OS_EXTRA_INIT_FUNCTION and GFX_OS_EXTRA_DEINIT_FUNCTION.
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.
Please take a look at the API reference of the GOS module to learn about all the available functions.
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
Thread priority
The number of different thread priorities is not clearly defined as every underlying operating system implements this feature differently. However, the GOS module ensures that the following three priority levels are defined:
LOW_PRIORITY NORMAL_PRIORITY HIGH_PRIORITY
As thread priorities are usually implemented in form of integer variables, you can increment and decrement these defines in order to further split the thread priorities. For example:
/* Normal priority thread */ NORMAL_PRIORITY /* High priority thread */ HIGH_PRIORITY /* A thread that has a slightly higher priority than the normal priority but with a still smaller priority than the high priroty thread */ NORMAL_PRIORITY + 1
Terminating a thread
The uGFX API does not provide any function to terminate a running thread. This is due to the fact that only very few operating systems provide the feature to terminate a running thread from within another thread. However, it's still possible to tell a thread to terminate itself. This can for example be accomplished by implementing a 'falling over the edge' algorithm where a variable is passed to the custom parameter of the thread function. The thread will frequently check this variable which tells whether the thread should return or not. As the variable is only passed as a pointer it can be modified out of another thread.
The /demos/modules/gos/threads_advanced demo shows how to implement such an algorithm. Basically it looks like this:
threadreturn_t threadFunction(void* param) { /* Cast the paramter into a bool pointer so we can use it */ bool_t* doExit = (bool_t*)param; /* Execute this until we shall be terminated */ while (*doExit == FALSE) { /* Do the actual work... */ } /* Don't return anything (or return something) */ return (threadreturn_t)0; } int main(void) { bool_t exitThread = FALSE; /* Start the thread and pass the variable as a parameter to tell the thread to terminate later */ gfxThreadCreate(NULL, 128, NORMAL_PRIORITY, threadFunction, (void*)&exitThread); /* Tell the thread to return */ exitThread = TRUE; }
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.
Please take a look at the API reference of the GOS module to learn about all the available functions.
Existing ports
The following ports already exist and are part of the official repository:
- ChibiOS/RT
- FreeRTOS
- CMSIS RTOS
- Keil RTX
- eCos
- rawrtos
- BareMetal (no OS at all)
- Arduino
- 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/