version 2.8
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.org/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 TRUE 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(delaytime_t ms)
49 {
50  systemticks_t ticks = ms*RAW_TICKS_PER_SECOND/1000;
51  if(!ticks)ticks = 1;
52  raw_sleep(ticks);
53 }
54 
55 void gfxSleepMicroseconds(delaytime_t us)
56 {
57  systemticks_t ticks = (us/1000)*RAW_TICKS_PER_SECOND/1000;
58  if(!ticks)ticks = 1;
59  raw_sleep(ticks);
60 }
61 
62 bool_t gfxSemWait(gfxSem* psem, delaytime_t ms)
63 {
64  systemticks_t ticks = ms*RAW_TICKS_PER_SECOND/1000;
65  if(!ticks)ticks=1;
66  if(raw_semaphore_get((psem), ticks)==RAW_SUCCESS)
67  return TRUE;
68  return FALSE;
69 }
70 
71 bool_t gfxSemWaitI(gfxSem* psem)
72 {
73  if(raw_semaphore_get((psem), TIME_IMMEDIATE)==RAW_SUCCESS)
74  return TRUE;
75  return FALSE;
76 }
77 
78 gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn),p), void *param)
79 {
80  RAW_U16 ret;
81  gfxThreadHandle 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 * gfxThreadHandle
A thread handle.
Definition: gos.h:117
#define FALSE
Generic &#39;false&#39; boolean constant.
Definition: gfx.h:31
void * gfxAlloc(size_t sz)
Allocate memory.
bool_t gfxSemWait(gfxSem *psem, delaytime_t ms)
Wait on a semaphore.
A semaphore.
Definition: gos.h:105
#define DECLARE_THREAD_FUNCTION(fnName, param)
Declare a thread function.
Definition: gos.h:62
void gfxSleepMicroseconds(delaytime_t us)
Put the current thread to sleep for the specified period in microseconds.
gfxThreadHandle gfxThreadCreate(void *stackarea, size_t stacksz, threadpriority_t prio, DECLARE_THREAD_FUNCTION((*fn), p), void *param)
Start a new thread.
#define TRUE
Generic &#39;true&#39; boolean constant.
Definition: gfx.h:38
void gfxSleepMilliseconds(delaytime_t ms)
Put the current thread to sleep for the specified period in milliseconds.
bool_t gfxSemWaitI(gfxSem *psem)
Test if a wait on a semaphore can be satisfied immediately.