PicoWAN SDK Documentation
os.h
Go to the documentation of this file.
1 
31 #ifndef _OS_H_
32 #define _OS_H_
33 
34 #include <stdlib.h>
35 #include <stdint.h>
36 #include <string.h>
37 #include <tick.h>
38 
39 typedef int64_t os_time_t;
40 
41 #ifndef TICK_FREQ
42 #error "TICK_FREQ has not been defined for the current MCU !"
43 #elif ((TICK_FREQ % 64) != 0)
44 #error "TICK_FREQ must be a multiple of 64 !"
45 #elif (TICK_FREQ < 8192)
46 #error "TICK_FREQ too low (should be >= 8192) !"
47 #endif
48 
49 #define s2ostime(s) ((os_time_t) ((int64_t) s * TICK_FREQ))
50 #define ms2ostime(ms) ((os_time_t) (((int64_t) ms * TICK_FREQ) / 1000))
51 #define us2ostime(us) ((os_time_t) (((int64_t) us * (TICK_FREQ / 64)) / 15625))
52 
53 #define ostime2s(t) ((int64_t) (t / TICK_FREQ))
54 #define ostime2ms(t) ((int64_t) ((t * (int64_t) 1000) / TICK_FREQ))
55 #define ostime2us(t) ((int64_t) ((t * (int64_t) 15625) / (TICK_FREQ / 64)))
56 
57 struct os_job {
58  void (*callback)(struct os_job *);
59  os_time_t time;
60  struct os_job *next;
61 };
62 
63 typedef struct os_job os_job_t;
64 
65 
71 void os_init(void);
72 
80 os_time_t os_get_time(void);
81 
89 void os_wait_until(os_time_t time);
90 
98 void os_delay(os_time_t time);
99 
109 os_time_t os_get_elapsed_time(os_time_t time);
110 
120 uint8_t os_cancel_job(os_job_t *job);
121 
130 void os_post_job(os_job_t *job, void (*cb)(os_job_t *));
131 
141 void os_post_delayed_job(os_job_t *job, os_time_t time, void (*cb)(os_job_t *));
142 
149 void os_unblock_powersave(void);
150 
158 void os_block_powersave(void);
159 
165 void os_mainloop(void);
166 
167 #endif /* _OS_H_ */
void os_post_job(os_job_t *job, void(*cb)(os_job_t *))
Posts a job to be executed as soon as possible.
Definition: os.c:102
Tick driver.
void os_delay(os_time_t time)
Waits for a given time.
Definition: os.c:61
void os_unblock_powersave(void)
Allows the system to go to sleep mode.
Definition: os.c:148
void os_post_delayed_job(os_job_t *job, os_time_t time, void(*cb)(os_job_t *))
Posts a job to be executed at a given time.
Definition: os.c:122
uint8_t os_cancel_job(os_job_t *job)
Cancels a scheduled job.
Definition: os.c:89
void os_block_powersave(void)
Prevents the system from going to sleep mode.
Definition: os.c:161
os_time_t os_get_elapsed_time(os_time_t time)
Returns how much time passed since a given timestamp.
Definition: os.c:66
Definition: os.h:57
void os_mainloop(void)
The Operating System mainloop.
Definition: os.c:174
void os_init(void)
Initializes the Operating System.
Definition: os.c:45
os_time_t os_get_time(void)
Gets the current time.
Definition: os.c:51
void os_wait_until(os_time_t time)
Waits until a given time.
Definition: os.c:56