Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
PAL

This module acts as a wrapper layer between the Wireless stack and the ASF drivers All hardwar level acess to the ASF drivers from the stack happens through this module.

Modules

 Common SW Timer
 Implements the software Algorithm for Timer Handling in the Stack.
 

Macros

#define DISABLE_GLOBAL_IRQ()   Disable_global_interrupt()
 
#define ENABLE_GLOBAL_IRQ()   Enable_global_interrupt()
 
#define ENTER_CRITICAL_REGION()   {uint8_t flags = cpu_irq_save();
 
#define LEAVE_CRITICAL_REGION()   cpu_irq_restore(flags); }
 
#define MIN_TIMEOUT   (0x80)
 
#define pal_timer_delay(delay)   delay_us(delay)
 Generates blocking delay. 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_tstamp()   CLEAR_TRX_IRQ_TSTAMP()
 Clears the transceiver timestamp interrupt. More...
 
#define PAL_WAIT_1_US()   delay_us(1);
 
#define PAL_WAIT_65_NS()   {nop(); nop(); }
 
#define STACK_FLASH_SIZE   (1024)
 
#define TIMER_SRC_DURING_TRX_AWAKE()
 Timer clock source while radio is awake. More...
 
#define TIMER_SRC_DURING_TRX_SLEEP()
 Timer clock source while radio is sleeping. More...
 
#define U16_TO_TARGET(x)   (x)
 This macro is used for handling endianness among the different CPUs. More...
 

Typedefs

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 source_type_tag source_type_t
 Timer clock source type. More...
 
typedef enum timeout_type_tag timeout_type_t
 Timeout type. More...
 

Enumerations

enum  ps_id_tag {
  PS_IEEE_ADDR,
  PS_XTAL_TRIM
}
 IDs for persistence storage access. More...
 
enum  ps_type_tag {
  INTERN_EEPROM,
  EXTERN_EEPROM
}
 IDs for persistence storage type. More...
 
enum  pwr_mode_tag { SYSTEM_SLEEP }
 Power modes. More...
 
enum  source_type_tag {
  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 type. More...
 

Functions

static uint32_t pal_add_time_us (uint32_t a, uint32_t b)
 Adds two time values. 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...
 
bool pal_is_timer_running (uint8_t timer_id)
 Checks if the timer of requested timer identifier is running. 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_start_high_priority_timer (uint8_t timer_id, uint16_t timer_count, FUNC_PTR timer_cb, void *param_cb)
 Starts high priority timer. More...
 
retval_t pal_stop_high_priority_timer (uint8_t timer_id)
 Stops a high priority timer. 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...
 
retval_t pal_timer_get_id (uint8_t *timer_id)
 
void pal_timer_source_select (source_type_t source)
 Selects timer clock source. More...
 
retval_t pal_timer_start (uint8_t timer_id, uint32_t timer_count, timeout_type_t timeout_type, FUNC_PTR timer_cb, void *param_cb)
 Start regular timer. More...
 
retval_t pal_timer_stop (uint8_t timer_id)
 Stops a running timer. More...
 
void pal_trx_irq_init (FUNC_PTR trx_irq_cb)
 Initializes the transceiver main interrupt. More...
 
void pal_trx_irq_init_tstamp (FUNC_PTR trx_irq_cb)
 Initializes the transceiver timestamp interrupt. More...
 
void pal_trx_read_timestamp (uint32_t *timestamp)
 Provides timestamp of the last received frame. More...
 

#define DISABLE_GLOBAL_IRQ ( )    Disable_global_interrupt()

Referenced by pal_global_irq_disable().

#define ENABLE_GLOBAL_IRQ ( )    Enable_global_interrupt()
#define ENTER_CRITICAL_REGION ( )    {uint8_t flags = cpu_irq_save();
#define LEAVE_CRITICAL_REGION ( )    cpu_irq_restore(flags); }
#define MIN_TIMEOUT   (0x80)
#define pal_timer_delay (   delay)    delay_us(delay)

Generates blocking delay.

This functions generates a blocking delay of specified time.

Parameters
delayin microseconds

Referenced by send_frame(), set_trx_state(), trx_init(), and trx_reset().

#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.

Referenced by send_frame(), and tal_ed_start().

#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.

Referenced by ed_scan_done(), send_frame(), set_trx_state(), tal_ed_start(), tal_init(), and tal_reset().

#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.

Referenced by tal_init().

#define pal_trx_irq_flag_clr ( )    CLEAR_TRX_IRQ()

Clears the transceiver main interrupt.

Referenced by set_trx_state(), switch_pll_on(), tal_generate_rand_seed(), and tal_reset().

#define pal_trx_irq_flag_clr_tstamp ( )    CLEAR_TRX_IRQ_TSTAMP()

Clears the transceiver timestamp interrupt.

#define PAL_WAIT_1_US ( )    delay_us(1);
#define PAL_WAIT_65_NS ( )    {nop(); nop(); }

Referenced by handle_tx_end_irq(), and send_frame().

#define STACK_FLASH_SIZE   (1024)
#define TIMER_SRC_DURING_TRX_AWAKE ( )

Timer clock source while radio is awake.

T0 & T1 of PORTC clk source is event channel 2 triggered by transceiver clock (CLKM, 1MHz)

#define TIMER_SRC_DURING_TRX_SLEEP ( )

Timer clock source while radio is sleeping.

T0 & T1 of PORTC clk source is event channel 0 triggered by system clock with corresponding event system prescaler (see function event_system_init()).

#define U16_TO_TARGET (   x)    (x)

This macro is used for handling endianness among the different CPUs.

typedef enum ps_id_tag ps_id_t

IDs for persistence storage access.

typedef enum ps_type_tag ps_type_t

IDs for persistence storage type.

typedef enum pwr_mode_tag pwr_mode_t

Power modes.

Timer clock source type.

Timeout type.

enum ps_id_tag

IDs for persistence storage access.

Enumerator
PS_IEEE_ADDR 
PS_XTAL_TRIM 

IDs for persistence storage type.

Enumerator
INTERN_EEPROM 

MCU Internal EEPROM.

EXTERN_EEPROM 

External EEPROM.

Power modes.

Enumerator
SYSTEM_SLEEP 

Timer clock source type.

Enumerator
TMR_CLK_SRC_DURING_TRX_SLEEP 

Identifier for timer clock source during sleep.

TMR_CLK_SRC_DURING_TRX_AWAKE 

Identifier for timer clock source while being awake.

Timeout type.

Enumerator
TIMEOUT_RELATIVE 

The timeout is relative to the current time.

TIMEOUT_ABSOLUTE 

The timeout is an absolute value.

static uint32_t pal_add_time_us ( uint32_t  a,
uint32_t  b 
)
inlinestatic

Adds two time values.

Parameters
aTime value 1
bTime value 2
Returns
Addition of a and b

References ADD_TIME.

bool pal_calibrate_rc_osc ( void  )

Calibrates the internal RC oscillator.

Returns
True if calibration is successful, false otherwise.

Referenced by mac_init().

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)

Returns
uint16_t Random number to be used as seed for function srand()
void pal_get_current_time ( uint32_t *  current_time)

Gets current time.

This function returns the current time.

Parameters
[out]current_timeReturns current system time

References MEMCPY_ENDIAN, and sw_timer_get_time().

Referenced by mlme_rx_enable_request(), switch_pll_on(), and tal_tx_frame().

static void pal_global_irq_disable ( void  )
inlinestatic

Disables the global interrupt.

References DISABLE_GLOBAL_IRQ.

static void pal_global_irq_enable ( void  )
inlinestatic

Enables the global interrupt.

References ENABLE_GLOBAL_IRQ.

retval_t pal_init ( void  )

Initialization of PAL.

This function initializes the PAL. The RC Oscillator is calibrated.

Returns
MAC_SUCCESS if PAL initialization is successful, FAILURE otherwise

References MAC_SUCCESS, and trx_spi_init().

Referenced by tal_init().

bool pal_is_timer_running ( uint8_t  timer_id)

Checks if the timer of requested timer identifier is running.

This function checks if the timer of requested timer identifier is running.

Parameters
timer_idTimer identifier
Returns
  • true if timer with requested timer id is running,
  • false otherwise.

References sw_timer_is_running().

Referenced by handle_rx_on(), mac_check_persistence_timer(), mac_process_data_response(), mac_process_tal_data_ind(), mac_sleep_trans(), and process_data_ind_not_transient().

retval_t pal_ps_get ( ps_type_t  ps_type,
uint16_t  start_addr,
uint16_t  length,
void *  value 
)

Get data from persistence storage.

Parameters
[in]ps_typePersistence storage type
[in]start_addrStart offset within EEPROM
[in]lengthNumber of bytes to read from EEPROM
[out]valueData from persistence storage
Returns
MAC_SUCCESS if everything went OK else FAILURE

Referenced by tal_init().

retval_t pal_ps_set ( uint16_t  start_addr,
uint16_t  length,
void *  value 
)

Write data to persistence storage.

Parameters
[in]start_addrStart address offset within EEPROM
[in]lengthNumber of bytes to be written to EEPROM
[in]valueData to persistence storage
Returns
MAC_SUCCESS if everything went OK else FAILURE

Referenced by tal_init().

retval_t pal_start_high_priority_timer ( uint8_t  timer_id,
uint16_t  timer_count,
FUNC_PTR  timer_cb,
void *  param_cb 
)

Starts high priority timer.

This function starts a high priority timer for the specified timeout.

Parameters
timer_idTimer identifier
timer_countTimeout in microseconds
timer_cbCallback handler invoked upon timer expiry
param_cbArgument for the callback handler
Returns
retval_t pal_stop_high_priority_timer ( uint8_t  timer_id)

Stops a high priority timer.

This function stops a high priority timer.

Parameters
timer_idTimer identifier
Returns
static uint32_t pal_sub_time_us ( uint32_t  a,
uint32_t  b 
)
inlinestatic

Subtracts two time values.

Parameters
aTime value 1
bTime value 2
Returns
Difference between a and b

References SUB_TIME.

Referenced by switch_pll_on().

void pal_task ( void  )

Services timer and sio handler.

This function calls sio & timer handling functions.

References sw_timer_service().

Referenced by wpan_task().

retval_t pal_timer_get_id ( uint8_t *  timer_id)
void pal_timer_source_select ( source_type_t  source)

Selects timer clock source.

This function selects the clock source of the timer.

Parameters
source

Referenced by mac_reset(), mac_trx_init_sleep(), mac_trx_wakeup(), tal_trx_sleep(), and tal_trx_wakeup().

retval_t pal_timer_start ( uint8_t  timer_id,
uint32_t  timer_count,
timeout_type_t  timeout_type,
FUNC_PTR  timer_cb,
void *  param_cb 
)

Start regular timer.

This function starts a regular timer and installs the corresponding callback function handle the timeout event.

Parameters
timer_idTimer identifier
timer_countTimeout in microseconds
timeout_typeTIMEOUT_RELATIVE or TIMEOUT_ABSOLUTE
timer_cbCallback handler invoked upon timer expiry
param_cbArgument for the callback handler
Returns

References ERR_TIMER_ALREADY_RUNNING, MAC_INVALID_PARAMETER, MAC_SUCCESS, PAL_TMR_ALREADY_RUNNING, STATUS_OK, and sw_timer_start().

Referenced by handle_rx_on(), mac_process_beacon_frame(), mac_process_tal_tx_status(), mac_scan_send_complete(), mac_start_persistence_timer(), mac_t_response_wait_cb(), mac_t_rx_off_cb(), mlme_rx_enable_request(), process_data_ind_not_transient(), scan_set_complete(), tal_reset(), and tal_trx_wakeup().

retval_t pal_timer_stop ( uint8_t  timer_id)

Stops a running timer.

This function stops a running timer with specified timer_id

Parameters
timer_idTimer identifier
Returns

References ERR_TIMER_NOT_RUNNING, MAC_SUCCESS, PAL_TMR_INVALID_ID, PAL_TMR_NOT_RUNNING, STATUS_OK, and sw_timer_stop().

Referenced by handle_rx_on(), mac_process_data_response(), mac_process_tal_data_ind(), mac_timers_stop(), mlme_rx_enable_request(), process_data_ind_not_transient(), process_data_ind_scanning(), tal_timers_stop(), and tal_trx_sleep().

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

Parameters
trx_irq_cbCallback function for the transceiver main interrupt
void pal_trx_irq_init_tstamp ( FUNC_PTR  trx_irq_cb)

Initializes the transceiver timestamp interrupt.

This function sets the microcontroller specific registers responsible for handling the transceiver timestamp interrupt

Parameters
trx_irq_cbCallback function for the transceiver timestamp interrupt

Referenced by tal_init().

void pal_trx_read_timestamp ( uint32_t *  timestamp)

Provides timestamp of the last received frame.

This function provides the timestamp (in microseconds) of the last received frame.

Parameters
[out]timestampin microseconds

References sw_timer_get_time().

Referenced by handle_tx_end_irq(), and trx_irq_handler_cb().