µGFX  2.9
version 2.9
gos_rawrtos.c
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.io/license.html
6  */
7 
8 #include "../../gfx.h"
9 
10 #if GFX_USE_OS_RAWRTOS
11 
12 #include <string.h>
13 #include "raw_api.h"
14 #include "raw_config.h"
15 
16 #if CONFIG_RAW_MUTEX != 1
17  #error "GOS: CONFIG_RAW_MUTEX must be defined in raw_config.h"
18 #endif
19 
20 #if CONFIG_RAW_SEMAPHORE != 1
21  #error "GOS: CONFIG_RAW_SEMAPHORE must be defined in raw_config.h"
22 #endif
23 
24 
25 void _gosInit(void)
26 {
27  #if !GFX_OS_NO_INIT
28  #error "GOS: Operating System initialization for RawRTOS is not yet implemented in uGFX. Please set GFX_OS_NO_INIT to GFXON in your gfxconf.h"
29  #endif
30  #if !GFX_OS_INIT_NO_WARNING
31  #if GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_DIRECT
32  #warning "GOS: Operating System initialization has been turned off. Make sure you call raw_os_start() before gfxInit() in your application!"
33  #elif GFX_COMPILER_WARNING_TYPE == GFX_COMPILER_WARNING_MACRO
34  COMPILER_WARNING("GOS: Operating System initialization has been turned off. Make sure you call raw_os_start() before gfxInit() in your application!")
35  #endif
36  #endif
37 }
38 
39 void _gosPostInit(void)
40 {
41 }
42 
43 void _gosDeinit(void)
44 {
45 }
46 
47 
48 void gfxSleepMilliseconds(gDelay ms)
49 {
50  gTicks ticks = ms*RAW_TICKS_PER_SECOND/1000;
51  if(!ticks)ticks = 1;
52  raw_sleep(ticks);
53 }
54 
55 void gfxSleepMicroseconds(gDelay us)
56 {
57  gTicks ticks = (us/1000)*RAW_TICKS_PER_SECOND/1000;
58  if(!ticks)ticks = 1;
59  raw_sleep(ticks);
60 }
61 
62 gBool gfxSemWait(gSem* psem, gDelay ms)
63 {
64  gTicks ticks = ms*RAW_TICKS_PER_SECOND/1000;
65  if(!ticks)ticks=1;
66  if(raw_semaphore_get((psem), ticks)==RAW_SUCCESS)
67  return gTrue;
68  return gFalse;
69 }
70 
71 gBool gfxSemWaitI(gSem* psem)
72 {
73  if(raw_semaphore_get((psem), RAW_NO_WAIT)==RAW_SUCCESS)
74  return gTrue;
75  return gFalse;
76 }
77 
78 gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn),p), void *param)
79 {
80  RAW_U16 ret;
81  gThread taskobj;
82 
83  taskobj = gfxAlloc(sizeof(RAW_TASK_OBJ));
84  ret = raw_task_create(taskobj, (RAW_U8 *)"uGFX_TASK", param,
85  prio, 0, stackarea,
86  stacksz/sizeof(PORT_STACK) , fn, 1);
87 
88  if (ret != RAW_SUCCESS) {
89  for (;;);
90  }
91 
92  return (taskobj);
93 }
94 
95 
96 #endif
97 
98 
99 
void * gThread
A thread handle.
Definition: gos.h:116
#define GFX_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:73
gBool gfxSemWait(gSem *psem, gDelay ms)
Wait on a semaphore.
void gfxSleepMicroseconds(gDelay us)
Put the current thread to sleep for the specified period in microseconds.
void * gfxAlloc(gMemSize sz)
Allocate memory.
gThread gfxThreadCreate(void *stackarea, gMemSize stacksz, gThreadpriority prio, GFX_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
gBool gfxSemWaitI(gSem *psem)
Test if a wait on a semaphore can be satisfied immediately.
void gfxSleepMilliseconds(gDelay ms)
Put the current thread to sleep for the specified period in milliseconds.
A semaphore.
Definition: gos.h:104