PicoWAN SDK Documentation
Data Structures | Macros | Typedefs | Functions
os.h File Reference

Implementation of a Low-Power scheduler. More...

#include <stdlib.h>
#include <stdint.h>
#include <string.h>
#include <tick.h>

Go to the source code of this file.

Data Structures

struct  os_job_t
 

Macros

#define s2ostime(s)   ((os_time_t) ((int64_t) s * TICK_FREQ))
 
#define ms2ostime(ms)   ((os_time_t) (((int64_t) ms * TICK_FREQ) / 1000))
 
#define us2ostime(us)   ((os_time_t) (((int64_t) us * (TICK_FREQ / 64)) / 15625))
 
#define ostime2s(t)   ((int64_t) (t / TICK_FREQ))
 
#define ostime2ms(t)   ((int64_t) ((t * (int64_t) 1000) / TICK_FREQ))
 
#define ostime2us(t)   ((int64_t) ((t * (int64_t) 15625) / (TICK_FREQ / 64)))
 

Typedefs

typedef int64_t os_time_t
 

Functions

void os_init (void)
 Initializes the Operating System. More...
 
os_time_t os_get_time (void)
 Gets the current time. More...
 
void os_wait_until (os_time_t time)
 Waits until a given time. More...
 
void os_delay (os_time_t time)
 Waits for a given time. More...
 
os_time_t os_get_elapsed_time (os_time_t time)
 Returns how much time passed since a given timestamp. More...
 
uint8_t os_cancel_job (os_job_t *job)
 Cancels a scheduled job. More...
 
void os_post_job (os_job_t *job, void(*cb)(os_job_t *))
 Posts a job to be executed as soon as possible. More...
 
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. More...
 
void os_unblock_powersave (void)
 Allows the system to go to sleep mode. More...
 
void os_block_powersave (void)
 Prevents the system from going to sleep mode. More...
 
void os_mainloop (void)
 The Operating System mainloop. More...
 

Detailed Description

Implementation of a Low-Power scheduler.

Copyright (c) 2018, Archos S.A. All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' AND AND EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARCHOS S.A. BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Function Documentation

void os_block_powersave ( void  )

Prevents the system from going to sleep mode.

This function prevents the system from going to sleep, thus allowing to get the lowest possible latency. It uses a reference counter, so as many calls to os_unblock_powersave() as calls to os_block_powersave() will be needed to re-enable the sleep mode.

uint8_t os_cancel_job ( os_job_t *  job)

Cancels a scheduled job.

This function cancels a job that has been previously scheduled (delayed or not).

Parameters
jobThe job to cancel.
Return values
uint8_t1 if the job has been canceled, 0 otherwise.
void os_delay ( os_time_t  time)

Waits for a given time.

This function waits for a given time.

Parameters
timeHow much time to wait.
os_time_t os_get_elapsed_time ( os_time_t  time)

Returns how much time passed since a given timestamp.

This function returns how much time passed since a given timestamp.

Parameters
timeThe timestamp used as origin.
Return values
os_time_t
os_time_t os_get_time ( void  )

Gets the current time.

This function returns the current time in ticks.

Return values
os_time_t
void os_init ( void  )

Initializes the Operating System.

This function initializes the Low-Level system dependencies.

void os_mainloop ( void  )

The Operating System mainloop.

This is the Operating System mainloop. It must be called only once, as soon as basic system initialization has been performed.

void os_post_delayed_job ( os_job_t *  job,
os_time_t  time,
void(*)(os_job_t *)  cb 
)

Posts a job to be executed at a given time.

This function posts a job that will be executed at a given time. If the job is already scheduled, it will be canceled first.

Parameters
jobThe job handle.
timeThe timestamp at which the job needs to be executed.
cbThe callback that will be executed.
void os_post_job ( os_job_t *  job,
void(*)(os_job_t *)  cb 
)

Posts a job to be executed as soon as possible.

This function posts a job that will be executed as soon as possible. If the job is already scheduled, it will be canceled first.

Parameters
jobThe job handle.
cbThe callback that will be executed.
void os_unblock_powersave ( void  )

Allows the system to go to sleep mode.

This function allows the system to go to sleep mode. Any calls to os_block_powersave() must be released at a point by a call to os_unblock_powersave().

void os_wait_until ( os_time_t  time)

Waits until a given time.

This function blocks until the given time is reached.

Parameters
timeThe timestamp to reach.