ruuvi.drivers.c  ${PROJECT_VERSION}
Drivers for external sensors and peripherals on embedded systems.
ruuvi_interface_yield.h File Reference
#include "ruuvi_driver_enabled_modules.h"
#include "ruuvi_driver_error.h"
#include <stdbool.h>

Go to the source code of this file.

Typedefs

typedef void(* ri_yield_state_ind_fp_t) (const bool active)
 Enable implementation selected by application. More...
 

Functions

void ri_yield_indication_set (const ri_yield_state_ind_fp_t indication)
 
rd_status_t ri_yield_init (void)
 Initializes yielding functions. More...
 
rd_status_t ri_yield_uninit (void)
 Uninitializes yielding functions. More...
 
rd_status_t ri_yield_low_power_enable (const bool enable)
 Initializes yielding functions. More...
 
rd_status_t ri_yield (void)
 Function which will release execution. More...
 
rd_status_t ri_delay_ms (uint32_t time)
 Delay a given number of milliseconds. More...
 
rd_status_t ri_delay_us (uint32_t time)
 Delay a given number of microseconds. More...
 
bool ri_yield_is_interrupt_context (void)
 Check if current execution is in interrupt context. More...
 

Detailed Description

Author
Otso Jousimaa otso@.nosp@m.ojou.nosp@m.sima..nosp@m.net
Date
2019-07-26

Interface for yielding execution or delaying for a given time. Underlying implememntation may enter low-power mode or block the execution during delay.

Definition in file ruuvi_interface_yield.h.

Typedef Documentation

◆ ri_yield_state_ind_fp_t

typedef void(* ri_yield_state_ind_fp_t) (const bool active)

Enable implementation selected by application.

Function which gets called when entering / exiting sleep, configured by application.

Parameters
[in]activetrue if device is going to be active, false otherwise.

Definition at line 35 of file ruuvi_interface_yield.h.

Function Documentation

◆ ri_delay_ms()

rd_status_t ri_delay_ms ( uint32_t  time)

Delay a given number of milliseconds.

This function is meant for rough timing and is not quaranteed to be exact in any manner If you need exact timing use timers or for example PWM peripheral. This function is affected by low-power delay enable, which uses sleep mode and timer to return out of sleep.

Parameters
timenumber of milliseconds to delay.
Returns
RD_SUCCESS on success, error code from stack on error.
Warning
Underlying implementation may block execution and keep CPU active leading to high power consumption
The timing is indicative only and should not be relied for precise timing.

◆ ri_delay_us()

rd_status_t ri_delay_us ( uint32_t  time)

Delay a given number of microseconds.

This function is meant for rough timing and is not quaranteed to be exact in any manner If you need exact timing use timers or for example PWM peripheral. This function does not use low-power mode to maintain better precision on timing.

Parameters
timenumber of microseconds to delay.
Returns
RD_SUCCESS on success, error code from stack on error.
Warning
Underlying implementation may block execution and keep CPU active leading to high power consumption
The timing is indicative only and should not be relied for precise timing.

◆ ri_yield()

rd_status_t ri_yield ( void  )

Function which will release execution.

The program execution will not continue until some external event continues the program.

Returns
RD_SUCCESS on success, error code from stack on error.
Warning
This function will never return unless external event occurs.

◆ ri_yield_indication_set()

void ri_yield_indication_set ( const ri_yield_state_ind_fp_t  indication)

Configure sleep indication function.

Parameters
[in]indicationfunction to call when entering/exiting sleep, NULL to disable

◆ ri_yield_init()

rd_status_t ri_yield_init ( void  )

Initializes yielding functions.

Initializes necessary data stuctures and peripherals (if any) for yielding. May for example allocate a timer to wake the device up after delay is over.

Returns
RD_SUCCESS on success, error code from stack on error.

◆ ri_yield_is_interrupt_context()

bool ri_yield_is_interrupt_context ( void  )

Check if current execution is in interrupt context.

This function reads Interrupt Control and State Register (ICSR) to determine the interrupt status. The register is masked with VECTACTIVE mask.

Returns
true if execution is currently in interrupt context, false otherwise.

◆ ri_yield_low_power_enable()

rd_status_t ri_yield_low_power_enable ( const bool  enable)

Initializes yielding functions.

Enables using timer + RTC to shutdown the device for millisecond-sleeps.

Parameters
[in]enabletrue to enable low-power mode, false to disable.
Returns
RD_SUCCESS on success, error code from stack on error.

◆ ri_yield_uninit()

rd_status_t ri_yield_uninit ( void  )

Uninitializes yielding functions.

Clears state from previous initializations. This should be called before uninitializing timers if timer-based low-power delay is in use.

Returns
RD_SUCCESS.