#include <stdbool.h>
#include <stdint.h>
#include "pal_types.h"
#include "pal_config.h"
#include "pal_mcu_generic.h"
#include "app_config.h"
Macros | |
#define | ADD_TIME(a, b) ((a) + (b)) |
Adds two time values. More... | |
#define | PAL_RST_HIGH() RST_HIGH() |
Macro to set Reset pin to high. More... | |
#define | PAL_RST_LOW() RST_LOW() |
Macro to set Reset pin to low. More... | |
#define | PAL_SLP_TR_HIGH() SLP_TR_HIGH() |
Macro to set SLP_TR pin to high. More... | |
#define | PAL_SLP_TR_LOW() SLP_TR_LOW() |
Macro to set SLP_TR pin to low. More... | |
#define | pal_trx_irq_dis() DISABLE_TRX_IRQ() |
Disables the transceiver main interrupt. More... | |
#define | pal_trx_irq_dis_tstamp() DISABLE_TRX_IRQ_TSTAMP() |
Disables the transceiver timestamp interrupt. More... | |
#define | pal_trx_irq_en() ENABLE_TRX_IRQ() |
Enables the transceiver main interrupt. More... | |
#define | pal_trx_irq_en_tstamp() ENABLE_TRX_IRQ_TSTAMP() |
Enables the transceiver timestamp interrupt. More... | |
#define | pal_trx_irq_flag_clr() CLEAR_TRX_IRQ() |
Clears the transceiver main interrupt. More... | |
#define | pal_trx_irq_flag_clr_awake() (CLEAR_TRX_IRQ_AWAKE()) |
Clears the transceiver AWAKE interrupt. More... | |
#define | pal_trx_irq_flag_clr_cca_ed() (CLEAR_TRX_IRQ_CCA_ED()) |
Clears the transceiver CCA_ED_END interrupt. More... | |
#define | pal_trx_irq_flag_clr_rx_end() (CLEAR_TRX_IRQ_RX_END()) |
Clears the transceiver RX_END interrupt. More... | |
#define | pal_trx_irq_flag_clr_tstamp() CLEAR_TRX_IRQ_TSTAMP() |
Clears the transceiver timestamp interrupt. More... | |
#define | pal_trx_irq_flag_clr_tx_end() (CLEAR_TRX_IRQ_TX_END()) |
Clears the transceiver TX_END interrupt. More... | |
#define | PAL_TRX_IRQ_HIGH() IRQ_PINGET() |
Macro to get the transceiver's main IRQ status. More... | |
#define | SUB_TIME(a, b) ((a) - (b)) |
Subtracts two time values. More... | |
#define | U16_TO_TARGET(x) (x) |
This macro is used for handling endianness among the different CPUs. More... | |
Typedefs | |
typedef enum button_state_tag | button_state_t |
Button action. More... | |
typedef enum led_action_tag | led_action_t |
LED action. More... | |
typedef enum pin_state_tag | pin_state_t |
Pin State. More... | |
typedef enum ps_id_tag | ps_id_t |
IDs for persistence storage access. More... | |
typedef enum ps_type_tag | ps_type_t |
IDs for persistence storage type. More... | |
typedef enum pwr_mode_tag | pwr_mode_t |
Power modes. More... | |
typedef enum sio_serial_tag | sio_serial_t |
Stream I/O to serial mapping enumeration. More... | |
typedef enum source_type_tag | source_type_t |
Timer clock source type. More... | |
typedef enum timeout_type_tag | timeout_type_t |
Timeout type. More... | |
Enumerations | |
enum | button_state_tag { BUTTON_PRESSED, BUTTON_OFF } |
Button action. More... | |
enum | led_action_tag { LED_ON, LED_OFF, LED_TOGGLE } |
LED action. More... | |
enum | pin_state_tag { LOW, HIGH, LOW, HIGH, LOW, HIGH } |
Pin State. More... | |
enum | ps_id_tag { PS_IEEE_ADDR, PS_XTAL_TRIM, PS_IEEE_ADDR, PS_XTAL_TRIM } |
IDs for persistence storage access. More... | |
enum | ps_type_tag { INTERN_EEPROM, EXTERN_EEPROM, INTERN_EEPROM, EXTERN_EEPROM } |
IDs for persistence storage type. More... | |
enum | pwr_mode_tag { SYSTEM_SLEEP, SYSTEM_SLEEP } |
Power modes. More... | |
enum | sio_serial_tag { SIO_0, SIO_1, SIO_2, SIO_3, SIO_4 } |
Stream I/O to serial mapping enumeration. More... | |
enum | source_type_tag { TMR_CLK_SRC_DURING_TRX_SLEEP, TMR_CLK_SRC_DURING_TRX_AWAKE, TMR_CLK_SRC_DURING_TRX_SLEEP, TMR_CLK_SRC_DURING_TRX_AWAKE } |
Timer clock source type. More... | |
enum | timeout_type_tag { TIMEOUT_RELATIVE, TIMEOUT_ABSOLUTE, TIMEOUT_RELATIVE, TIMEOUT_ABSOLUTE } |
Timeout type. More... | |
Functions | |
static uint32_t | pal_add_time_us (uint32_t a, uint32_t b) |
Adds two time values. More... | |
void | pal_alert (void) |
Alert indication. More... | |
void | pal_button_init (void) |
Button initialization. More... | |
button_state_t | pal_button_read (button_id_t button_no) |
Button handling. More... | |
bool | pal_calibrate_rc_osc (void) |
Calibrates the internal RC oscillator. More... | |
uint16_t | pal_generate_rand_seed (void) |
Generation of random seed for function srand() in case this is not supported by the transceiver (e.g. More... | |
void | pal_get_current_time (uint32_t *current_time) |
Gets current time. More... | |
static void | pal_global_irq_disable (void) |
Disables the global interrupt. More... | |
static void | pal_global_irq_enable (void) |
Enables the global interrupt. More... | |
retval_t | pal_init (void) |
Initialization of PAL. More... | |
void | pal_led (led_id_t led_no, led_action_t led_setting) |
LED handling. More... | |
void | pal_led_init (void) |
LED initialization. More... | |
retval_t | pal_ps_get (ps_type_t ps_type, uint16_t start_addr, uint16_t length, void *value) |
Get data from persistence storage. More... | |
retval_t | pal_ps_set (uint16_t start_addr, uint16_t length, void *value) |
Write data to persistence storage. More... | |
retval_t | pal_sio_init (uint8_t sio_unit) |
Initializes the requested SIO unit. More... | |
uint8_t | pal_sio_rx (uint8_t sio_unit, uint8_t *data, uint8_t max_length) |
Receives data from selected SIO unit. More... | |
uint8_t | pal_sio_tx (uint8_t sio_unit, uint8_t *data, uint8_t length) |
Transmits data through selected SIO unit. More... | |
void | pal_sleep_mode (uint8_t sleep_mode) |
Sleep/Power handling. More... | |
static uint32_t | pal_sub_time_us (uint32_t a, uint32_t b) |
Subtracts two time values. More... | |
void | pal_task (void) |
Services timer and sio handler. More... | |
void | pal_timer_delay (uint16_t delay) |
Generates blocking delay. More... | |
void | pal_timer_source_select (source_type_t source) |
Selects timer clock source. More... | |
void | pal_trx_irq_init (FUNC_PTR trx_irq_cb) |
Initializes the transceiver main interrupt. More... | |
void | pal_trx_irq_init_awake (FUNC_PTR trx_irq_cb) |
Initializes the transceiver AWAKE interrupt. More... | |
void | pal_trx_irq_init_cca_ed (FUNC_PTR trx_irq_cb) |
Initializes the transceiver CCA ED END interrupt. More... | |
void | pal_trx_irq_init_rx_end (FUNC_PTR trx_irq_cb) |
Initializes the transceiver RX END interrupt. More... | |
void | pal_trx_irq_init_tstamp (FUNC_PTR trx_irq_cb) |
Initializes the transceiver timestamp interrupt. More... | |
void | pal_trx_irq_init_tx_end (FUNC_PTR trx_irq_cb) |
Initializes the transceiver TX END interrupt. More... | |
void | pal_trx_read_timestamp (uint32_t *timestamp) |
Provides timestamp of the last received frame. More... | |
#define ADD_TIME | ( | a, | |
b | |||
) | ((a) + (b)) |
Adds two time values.
Referenced by pal_add_time_us().
#define PAL_RST_HIGH | ( | ) | RST_HIGH() |
Macro to set Reset pin to high.
#define PAL_RST_LOW | ( | ) | RST_LOW() |
Macro to set Reset pin to low.
#define PAL_SLP_TR_HIGH | ( | ) | SLP_TR_HIGH() |
Macro to set SLP_TR pin to high.
#define PAL_SLP_TR_LOW | ( | ) | SLP_TR_LOW() |
Macro to set SLP_TR pin to low.
#define pal_trx_irq_dis | ( | ) | DISABLE_TRX_IRQ() |
Disables the transceiver main interrupt.
This macro is only available for non-single chip transceivers, since in single chip transceivers there is no separation between disabling transceiver interrupts at the transceiver, and clearing the IRQ mask at the MCU. Therefore the transceiver interrupts in single chips are disabled by clearing the MCU IRQ mask.
#define pal_trx_irq_dis_tstamp | ( | ) | DISABLE_TRX_IRQ_TSTAMP() |
Disables the transceiver timestamp interrupt.
This macro is only available for non-single chip transceivers, since in single chip transceivers there is no separation between disabling transceiver interrupts at the transceiver, and clearing the IRQ mask at the MCU. Therefore the transceiver interrupts in single chips are disabled by clearing the MCU IRQ mask.
#define pal_trx_irq_en | ( | ) | ENABLE_TRX_IRQ() |
Enables the transceiver main interrupt.
This macro is only available for non-single chip transceivers, since in single chip transceivers there is no separation between enabling transceiver interrupts at the transceiver, and setting the IRQ mask at the MCU. Therefore the transceiver interrupts in single chips are enabled by setting the MCU IRQ mask.
#define pal_trx_irq_en_tstamp | ( | ) | ENABLE_TRX_IRQ_TSTAMP() |
Enables the transceiver timestamp interrupt.
This macro is only available for non-single chip transceivers, since in single chip transceivers there is no separation between enabling transceiver interrupts at the transceiver, and setting the IRQ mask at the MCU. Therefore the transceiver interrupts in single chips are enabled by setting the MCU IRQ mask.
#define pal_trx_irq_flag_clr | ( | ) | CLEAR_TRX_IRQ() |
Clears the transceiver main interrupt.
#define pal_trx_irq_flag_clr_awake | ( | ) | (CLEAR_TRX_IRQ_AWAKE()) |
Clears the transceiver AWAKE interrupt.
#define pal_trx_irq_flag_clr_cca_ed | ( | ) | (CLEAR_TRX_IRQ_CCA_ED()) |
Clears the transceiver CCA_ED_END interrupt.
#define pal_trx_irq_flag_clr_rx_end | ( | ) | (CLEAR_TRX_IRQ_RX_END()) |
Clears the transceiver RX_END interrupt.
#define pal_trx_irq_flag_clr_tstamp | ( | ) | CLEAR_TRX_IRQ_TSTAMP() |
Clears the transceiver timestamp interrupt.
#define pal_trx_irq_flag_clr_tx_end | ( | ) | (CLEAR_TRX_IRQ_TX_END()) |
Clears the transceiver TX_END interrupt.
#define PAL_TRX_IRQ_HIGH | ( | ) | IRQ_PINGET() |
Macro to get the transceiver's main IRQ status.
#define SUB_TIME | ( | a, | |
b | |||
) | ((a) - (b)) |
Subtracts two time values.
Referenced by calculate_time_duration(), and pal_sub_time_us().
#define U16_TO_TARGET | ( | x | ) | (x) |
This macro is used for handling endianness among the different CPUs.
typedef enum button_state_tag button_state_t |
Button action.
typedef enum led_action_tag led_action_t |
LED action.
typedef enum pin_state_tag pin_state_t |
Pin State.
typedef enum ps_type_tag ps_type_t |
IDs for persistence storage type.
typedef enum pwr_mode_tag pwr_mode_t |
Power modes.
typedef enum sio_serial_tag sio_serial_t |
Stream I/O to serial mapping enumeration.
typedef enum source_type_tag source_type_t |
Timer clock source type.
typedef enum timeout_type_tag timeout_type_t |
Timeout type.
enum button_state_tag |
enum led_action_tag |
enum pin_state_tag |
enum ps_id_tag |
enum ps_type_tag |
enum pwr_mode_tag |
enum sio_serial_tag |
enum source_type_tag |
Timer clock source type.
enum timeout_type_tag |
|
inlinestatic |
Adds two time values.
a | Time value 1 |
b | Time value 2 |
References ADD_TIME.
void pal_alert | ( | void | ) |
Alert indication.
This Function can be used by any application to indicate an error condition. The function is blocking and does never return.
Referenced by main().
void pal_button_init | ( | void | ) |
Button initialization.
button_state_t pal_button_read | ( | button_id_t | button_no | ) |
Button handling.
button_no | Button id |
uint16_t pal_generate_rand_seed | ( | void | ) |
Generation of random seed for function srand() in case this is not supported by the transceiver (e.g.
AT86RF230)
void pal_get_current_time | ( | uint32_t * | current_time | ) |
Gets current time.
This function returns the current time.
[out] | current_time | Returns current system time |
|
inlinestatic |
Disables the global interrupt.
References DISABLE_GLOBAL_IRQ.
|
inlinestatic |
Enables the global interrupt.
References ENABLE_GLOBAL_IRQ.
void pal_led | ( | led_id_t | led_no, |
led_action_t | led_setting | ||
) |
LED handling.
led_no | LED id |
led_setting | LED action |
Referenced by led_handling(), main(), nlme_set_confirm(), pbp_pair_confirm(), Receive_Message(), and zrc_cmd_indication().
void pal_led_init | ( | void | ) |
LED initialization.
Referenced by main().
Get data from persistence storage.
[in] | ps_type | Persistence storage type |
[in] | start_addr | Start offset within EEPROM |
[in] | length | Number of bytes to read from EEPROM |
[out] | value | Data from persistence storage |
retval_t pal_ps_set | ( | uint16_t | start_addr, |
uint16_t | length, | ||
void * | value | ||
) |
Write data to persistence storage.
[in] | start_addr | Start address offset within EEPROM |
[in] | length | Number of bytes to be written to EEPROM |
[in] | value | Data to persistence storage |
retval_t pal_sio_init | ( | uint8_t | sio_unit | ) |
Initializes the requested SIO unit.
This function initializes the requested SIO unit.
sio_unit | Specifies the SIO uint to be initialized |
uint8_t pal_sio_rx | ( | uint8_t | sio_unit, |
uint8_t * | data, | ||
uint8_t | max_length | ||
) |
Receives data from selected SIO unit.
This function receives data from the selected SIO unit.
sio_unit | Specifies SIO unit | |
[out] | data | Pointer to the buffer to store received data |
[in] | max_length | Maximum number of bytes to be received |
uint8_t pal_sio_tx | ( | uint8_t | sio_unit, |
uint8_t * | data, | ||
uint8_t | length | ||
) |
Transmits data through selected SIO unit.
This function transmits data through the selected SIO unit.
sio_unit | Specifies the SIO unit |
data | Pointer to the data to be transmitted is present |
length | Number of bytes to be transmitted |
void pal_sleep_mode | ( | uint8_t | sleep_mode | ) |
Sleep/Power handling.
Handles sleep/power modes for entire system
sleep_mode | desired sleep/power mode, see sleep.h |
Referenced by app_task().
|
inlinestatic |
Subtracts two time values.
a | Time value 1 |
b | Time value 2 |
References SUB_TIME.
void pal_task | ( | void | ) |
Services timer and sio handler.
This function calls sio & timer handling functions.
void pal_timer_delay | ( | uint16_t | delay | ) |
Generates blocking delay.
This functions generates a blocking delay of specified time.
delay | in microseconds |
Referenced by accelero_init(), extended_delay_ms(), handle_received_frame_irq(), perform_cca_twice(), send_frame(), set_trx_state(), switch_pll_on(), tal_task(), tfa_cca_perform(), tfa_ed_sample(), tfa_get_batmon_voltage(), trx_init(), and trx_reset().
void pal_trx_irq_init | ( | FUNC_PTR | trx_irq_cb | ) |
Initializes the transceiver main interrupt.
This function sets the microcontroller specific registers responsible for handling the transceiver main interrupt
trx_irq_cb | Callback function for the transceiver main interrupt |
void pal_trx_irq_init_awake | ( | FUNC_PTR | trx_irq_cb | ) |
Initializes the transceiver AWAKE interrupt.
This function sets the microcontroller specific registers responsible for handling the transceiver AWAKE interrupt
trx_irq_cb | Callback function for the transceiver AWAKE interrupt |
This function sets the microcontroller specific registers responsible for handling the transceiver AWAKE interrupt
trx_irq_cb | Callback function for the transceiver AWAKE interrupt |
References irq_hdl_trx_awake.
Referenced by set_trx_state(), and tal_init().
void pal_trx_irq_init_cca_ed | ( | FUNC_PTR | trx_irq_cb | ) |
Initializes the transceiver CCA ED END interrupt.
This function sets the microcontroller specific registers responsible for handling the transceiver CCA ED END interrupt
trx_irq_cb | Callback function for the transceiver CCA ED END interrupt |
This function sets the microcontroller specific registers responsible for handling the transceiver CCA ED END interrupt
trx_irq_cb | Callback function for the transceiver CCA ED END interrupt |
References irq_hdl_trx_cca_ed.
void pal_trx_irq_init_rx_end | ( | FUNC_PTR | trx_irq_cb | ) |
Initializes the transceiver RX END interrupt.
This function sets the microcontroller specific registers responsible for handling the transceiver RX END interrupt
trx_irq_cb | Callback function for the transceiver RX END interrupt |
This function sets the microcontroller specific registers responsible for handling the transceiver RX END interrupt
trx_irq_cb | Callback function for the transceiver RX END interrupt |
References irq_hdl_trx_rx_end.
Referenced by tal_init().
void pal_trx_irq_init_tx_end | ( | FUNC_PTR | trx_irq_cb | ) |
Initializes the transceiver TX END interrupt.
This function sets the microcontroller specific registers responsible for handling the transceiver TX END interrupt
trx_irq_cb | Callback function for the transceiver TX END interrupt |
This function sets the microcontroller specific registers responsible for handling the transceiver TX END interrupt
trx_irq_cb | Callback function for the transceiver TX END interrupt |
References irq_hdl_trx_tx_end.
Referenced by tal_init().