Microcontroller Wireless Solutions


pal.h File Reference

PAL related APIs. More...

Go to the source code of this file.

Defines

#define ADD_TIME(a, b)   ((a) + (b))
#define PAL_RST_HIGH()   RST_HIGH()
#define PAL_RST_LOW()   RST_LOW()
#define PAL_SLP_TR_HIGH()   SLP_TR_HIGH()
#define PAL_SLP_TR_LOW()   SLP_TR_LOW()
#define pal_trx_irq_flag_clr()   CLEAR_TRX_IRQ()
#define pal_trx_irq_flag_clr_awake()   (CLEAR_TRX_IRQ_AWAKE())
#define pal_trx_irq_flag_clr_cca_ed()   (CLEAR_TRX_IRQ_CCA_ED())
#define pal_trx_irq_flag_clr_rx_end()   (CLEAR_TRX_IRQ_RX_END())
#define pal_trx_irq_flag_clr_tstamp()   CLEAR_TRX_IRQ_TSTAMP()
#define pal_trx_irq_flag_clr_tx_end()   (CLEAR_TRX_IRQ_TX_END())
#define PAL_TRX_IRQ_HIGH()   IRQ_PINGET()
#define SUB_TIME(a, b)   ((a) - (b))
#define U16_TO_TARGET(x)   ((((x) << 8) & 0xFF00) | (((x) >> 8) & 0x00FF))

Typedefs

typedef enum button_state_tag button_state_t
typedef void(* irq_handler_t )(void)
typedef enum led_action_tag led_action_t
typedef enum pin_state_tag pin_state_t
typedef enum ps_id_tag ps_id_t
typedef enum ps_type_tag ps_type_t
typedef enum pwr_mode_tag pwr_mode_t
typedef enum sio_serial_tag sio_serial_t
typedef enum source_type_tag source_type_t
typedef enum timeout_type_tag timeout_type_t

Enumerations

enum  button_state_tag { BUTTON_PRESSED, BUTTON_OFF }
enum  led_action_tag { LED_ON, LED_OFF, LED_TOGGLE }
enum  pin_state_tag { LOW, HIGH }
enum  ps_id_tag { PS_IEEE_ADDR, PS_XTAL_TRIM }
enum  ps_type_tag { INTERN_EEPROM, EXTERN_EEPROM }
enum  pwr_mode_tag { SYSTEM_SLEEP }
enum  sio_serial_tag {
  SIO_0, SIO_1, SIO_2, SIO_3,
  SIO_4
}
enum  source_type_tag { TMR_CLK_SRC_DURING_TRX_SLEEP, TMR_CLK_SRC_DURING_TRX_AWAKE }
enum  timeout_type_tag { TIMEOUT_RELATIVE, TIMEOUT_ABSOLUTE }

Functions

static uint32_t pal_add_time_us (uint32_t a, uint32_t b)
void pal_alert (void)
void pal_button_init (void)
button_state_t pal_button_read (button_id_t button_no)
bool pal_calibrate_rc_osc (void)
uint16_t pal_generate_rand_seed (void)
void pal_get_current_time (uint32_t *current_time)
static void pal_global_irq_disable (void)
static void pal_global_irq_enable (void)
retval_t pal_init (void)
bool pal_is_timer_running (uint8_t timer_id)
void pal_led (led_id_t led_no, led_action_t led_setting)
void pal_led_init (void)
retval_t pal_ps_get (ps_type_t ps_type, uint16_t start_addr, uint16_t length, void *value)
retval_t pal_ps_set (uint16_t start_addr, uint16_t length, void *value)
retval_t pal_sio_init (uint8_t sio_unit)
uint8_t pal_sio_rx (uint8_t sio_unit, uint8_t *data, uint8_t max_length)
uint8_t pal_sio_tx (uint8_t sio_unit, uint8_t *data, uint8_t length)
void pal_sleep_mode (uint8_t sleep_mode)
void pal_spi_done_cb_init (void *spi_done_cb)
retval_t pal_start_high_priority_timer (uint8_t timer_id, uint16_t timer_count, FUNC_PTR timer_cb, void *param_cb)
retval_t pal_stop_high_priority_timer (uint8_t timer_id)
static uint32_t pal_sub_time_us (uint32_t a, uint32_t b)
void pal_task (void)
void pal_timer_delay (uint16_t delay)
void pal_timer_source_select (source_type_t source)
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)
retval_t pal_timer_stop (uint8_t timer_id)
void pal_trx_aes_wrrd (uint8_t addr, uint8_t *idata, uint8_t length)
uint8_t pal_trx_bit_read (uint8_t addr, uint8_t mask, uint8_t pos)
void pal_trx_bit_write (uint8_t reg_addr, uint8_t mask, uint8_t pos, uint8_t new_value)
void pal_trx_frame_read (uint8_t *data, uint8_t length)
void pal_trx_frame_write (uint8_t *data, uint8_t length)
void pal_trx_irq_init_awake (FUNC_PTR trx_irq_cb)
void pal_trx_irq_init_cca_ed (FUNC_PTR trx_irq_cb)
void pal_trx_irq_init_rx_end (FUNC_PTR trx_irq_cb)
void pal_trx_irq_init_tstamp (FUNC_PTR trx_irq_cb)
void pal_trx_irq_init_tx_end (FUNC_PTR trx_irq_cb)
void pal_trx_read_timestamp (uint32_t *timestamp)
uint8_t pal_trx_reg_read (uint8_t addr)
void pal_trx_reg_write (uint8_t addr, uint8_t data)
void pal_trx_sram_read (uint8_t addr, uint8_t *data, uint8_t length)
void pal_trx_sram_write (uint8_t addr, uint8_t *data, uint8_t length)
void pal_wdt_enable (WDT_PER_t period)
void RTC_Initialize (uint16_t period, uint16_t count, uint16_t compareValue, RTC_PRESCALER_t prescaler)
void RTC_SetIntLevels (RTC_OVFINTLVL_t ovfIntLevel, RTC_COMPINTLVL_t compIntLevel)
void sleeping_timer_init (void)
void sleeping_timer_with_wdt (void)
void sleeping_timer_without_wdt (void)
void wdt_clear (void)
void wdt_init (void)
void wdt_parallel_timer_init (void)

Detailed Description

PAL related APIs.

This header file declares prototypes of PAL APIs, enumerations used by TAL and MAC.

Id:
pal.h 29538 2011-11-25 14:54:44Z sschneid
Author:
Atmel Corporation: http://www.atmel.com
Support email: avr@atmel.com

Definition in file pal.h.


Define Documentation

#define ADD_TIME (   a,
 
)    ((a) + (b))

Adds two time values

Definition at line 45 of file pal.h.

Referenced by pal_add_time_us().

#define PAL_RST_HIGH ( )    RST_HIGH()

Macro to set Reset pin to high

Definition at line 727 of file pal.h.

#define PAL_RST_LOW ( )    RST_LOW()

Macro to set Reset pin to low

Definition at line 729 of file pal.h.

#define PAL_SLP_TR_HIGH ( )    SLP_TR_HIGH()

Macro to set SLP_TR pin to high

Definition at line 731 of file pal.h.

#define PAL_SLP_TR_LOW ( )    SLP_TR_LOW()

Macro to set SLP_TR pin to low

Definition at line 733 of file pal.h.

Referenced by ISR().

#define PAL_TRX_IRQ_HIGH ( )    IRQ_PINGET()

Macro to get the transceiver's main IRQ status

Definition at line 735 of file pal.h.

#define SUB_TIME (   a,
 
)    ((a) - (b))

Subtracts two time values

Definition at line 50 of file pal.h.

Referenced by pal_sub_time_us().

#define U16_TO_TARGET (   x)    ((((x) << 8) & 0xFF00) | (((x) >> 8) & 0x00FF))

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

Definition at line 56 of file pal.h.


Typedef Documentation

typedef enum pin_state_tag pin_state_t

Pin State

Stream I/O to serial mapping enumeration

Timer clock source type

Timeout type


Enumeration Type Documentation

Button action.

Enumerator:
BUTTON_PRESSED 

Button is pressed.

BUTTON_OFF 

Button is released.

Definition at line 160 of file pal.h.

LED action.

Enumerator:
LED_ON 

Switch LED on.

LED_OFF 

Switch LED off.

LED_TOGGLE 

Toggle LED.

Definition at line 146 of file pal.h.

Pin State

Enumerator:
LOW 

Pin state low

HIGH 

Pin state high

Definition at line 67 of file pal.h.

IDs for persistence storage type.

Enumerator:
INTERN_EEPROM 

MCU Internal EEPROM

EXTERN_EEPROM 

External EEPROM

Definition at line 134 of file pal.h.

Stream I/O to serial mapping enumeration

Enumerator:
SIO_0 

UART 0

SIO_1 

UART 1

SIO_2 

USB 0

SIO_3 

UART 2

SIO_4 

UART 3

Definition at line 80 of file pal.h.

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

Definition at line 113 of file pal.h.

Timeout type

Enumerator:
TIMEOUT_RELATIVE 

The timeout is relative to the current time.

TIMEOUT_ABSOLUTE 

The timeout is an absolute value.

Definition at line 100 of file pal.h.


Function Documentation

static uint32_t pal_add_time_us ( uint32_t  a,
uint32_t  b 
) [inline, static]

Adds two time values.

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

Definition at line 702 of file pal.h.

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.

Definition at line 191 of file pal.c.

References ALERT_INDICATE, ALERT_INIT, and pal_timer_delay().

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

This function returns the current time.

Parameters:
[out]current_timeCurrent system time

Definition at line 697 of file pal_timer.c.

Referenced by ISR().

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

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

Returns:
MAC_SUCCESS if PAL initialization is successful, FAILURE otherwise

Definition at line 50 of file pal.c.

References gpio_init(), MAC_SUCCESS, mcu_init(), timer_init(), and wdt_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.

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.

Definition at line 834 of file pal_timer.c.

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

Definition at line 110 of file pal.c.

References EXTERN_EEPROM, extern_eeprom_get(), FAILURE, INTERN_EEPROM, MAC_INVALID_PARAMETER, and MAC_SUCCESS.

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

Definition at line 157 of file pal.c.

References FAILURE, and MAC_SUCCESS.

retval_t pal_sio_init ( uint8_t  sio_unit)

Initializes the requested SIO unit.

This function initializes the requested SIO unit.

Parameters:
sio_unitSpecifies the SIO uint to be initialized
Returns:
MAC_SUCCESS if SIO unit is initialized successfully, FAILURE otherwise
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.

Parameters:
sio_unitSpecifies SIO unit
[out]dataPointer to the buffer to store received data
[in]max_lengthMaximum number of bytes to be received
Returns:
Actual number of received bytes
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.

Parameters:
sio_unitSpecifies the SIO unit
dataPointer to the data to be transmitted is present
lengthNumber of bytes to be transmitted
Returns:
Actual number of transmitted bytes
void pal_spi_done_cb_init ( void *  spi_done_cb)

SPI done callback initialization.

Parameters:
spi_done_cbPointer to SPI done callback function
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:

Definition at line 315 of file pal_timer.c.

References ENTER_CRITICAL_REGION, LEAVE_CRITICAL_REGION, MAC_INVALID_PARAMETER, MAC_SUCCESS, PAL_TMR_ALREADY_RUNNING, and PAL_TMR_INVALID_ID.

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:

Definition at line 560 of file pal_timer.c.

References ENTER_CRITICAL_REGION, LEAVE_CRITICAL_REGION, MAC_SUCCESS, and PAL_TMR_NOT_RUNNING.

static uint32_t pal_sub_time_us ( uint32_t  a,
uint32_t  b 
) [inline, static]

Subtracts two time values.

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

Definition at line 717 of file pal.h.

References SUB_TIME.

void pal_task ( void  )

Services timer and sio handler.

This function calls sio & timer handling functions.

Definition at line 79 of file pal.c.

References timer_service().

void pal_timer_delay ( uint16_t  delay)

Generates blocking delay.

This functions generates a blocking delay of specified time.

Parameters:
delayin microseconds

Generates blocking delay.

This functions performs a blocking delay of the specified time.

Parameters:
delayin microseconds

Definition at line 730 of file pal_timer.c.

References DELAY_WITHOUT_IRQS_US.

Referenced by pal_alert(), and timer_init().

void pal_timer_source_select ( source_type_t  source)

Selects timer clock source.

This function selects the clock source of the timer.

Parameters:
source

This function selects the clock source of the timer.

Unused for the ATmega128RFA1 because the MAC symbol counter automatically switches from XTAL1 to RTC when the transceiver module is put to sleep.

Parameters:
source

Definition at line 682 of file pal_timer.c.

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:

Start regular timer.

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

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

Definition at line 229 of file pal_timer.c.

References MAC_INVALID_PARAMETER, MAC_SUCCESS, MAX_TIMEOUT, MIN_TIMEOUT, PAL_TMR_ALREADY_RUNNING, PAL_TMR_INVALID_ID, PAL_TMR_INVALID_TIMEOUT, start_absolute_timer(), TIMEOUT_ABSOLUTE, and TIMEOUT_RELATIVE.

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:

This function stops a running timer with the specified timer_id.

Parameters:
timer_idTimer identifier
Returns:

Definition at line 398 of file pal_timer.c.

References ENTER_CRITICAL_REGION, internal_timer_handler(), LEAVE_CRITICAL_REGION, MAC_SUCCESS, PAL_TMR_INVALID_ID, PAL_TMR_NOT_RUNNING, and prog_ocr().

void pal_trx_aes_wrrd ( uint8_t  addr,
uint8_t *  idata,
uint8_t  length 
)

Writes and reads data into/from SRAM of the transceiver.

This function writes data into the SRAM of the transceiver and simultaneously reads the bytes.

Parameters:
addrStart address in the SRAM for the write operation
idataPointer to the data written/read into/from SRAM
lengthNumber of bytes written/read into/from SRAM
uint8_t pal_trx_bit_read ( uint8_t  addr,
uint8_t  mask,
uint8_t  pos 
)

Subregister read.

Parameters:
addroffset of the register
maskbit mask of the subregister
posbit position of the subregister
Returns:
value of the read bit(s)

Referenced by ISR().

void pal_trx_bit_write ( uint8_t  reg_addr,
uint8_t  mask,
uint8_t  pos,
uint8_t  new_value 
)

Subregister write.

Parameters:
[in]reg_addrOffset of the register
[in]maskBit mask of the subregister
[in]posBit position of the subregister
[out]new_valueData, which is muxed into the register
void pal_trx_frame_read ( uint8_t *  data,
uint8_t  length 
)

Reads frame buffer of the transceiver.

This function reads the frame buffer of the transceiver.

Parameters:
[out]dataPointer to the location to store frame
[in]lengthNumber of bytes to be read from the frame buffer.
void pal_trx_frame_write ( uint8_t *  data,
uint8_t  length 
)

Writes data into frame buffer of the transceiver.

This function writes data into the frame buffer of the transceiver

Parameters:
[in]dataPointer to data to be written into frame buffer
[in]lengthNumber of bytes to be written into frame buffer
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

Parameters:
trx_irq_cbCallback function for the transceiver AWAKE interrupt

Definition at line 146 of file pal_irq.c.

References irq_hdl_trx_awake.

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

Parameters:
trx_irq_cbCallback function for the transceiver CCA ED END interrupt

Definition at line 114 of file pal_irq.c.

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

Parameters:
trx_irq_cbCallback function for the transceiver RX END interrupt

Definition at line 100 of file pal_irq.c.

References irq_hdl_trx_rx_end.

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

Initializes the transceiver timestamp interrupt.

This function sets the microcontroller specific registers responsible for handling the transceiver timestamp interrupt (RX START interrupt)

Parameters:
trx_irq_cbCallback function for the transceiver timestamp interrupt (RX START interrupt)

Definition at line 130 of file pal_irq.c.

References irq_hdl_trx_tstamp.

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

Parameters:
trx_irq_cbCallback function for the transceiver TX END interrupt

Definition at line 86 of file pal_irq.c.

References irq_hdl_trx_tx_end.

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

Definition at line 716 of file pal_timer.c.

uint8_t pal_trx_reg_read ( uint8_t  addr)

Reads current value from a transceiver register.

This function reads the current value from a transceiver register.

Parameters:
addrSpecifies the address of the trx register from which the data shall be read
Returns:
value of the register read
void pal_trx_reg_write ( uint8_t  addr,
uint8_t  data 
)

Writes data into a transceiver register.

This function writes a value into transceiver register.

Parameters:
addrAddress of the trx register
dataData to be written to trx register
void pal_trx_sram_read ( uint8_t  addr,
uint8_t *  data,
uint8_t  length 
)

Reads data from SRAM of the transceiver.

This function reads from the SRAM of the transceiver

Parameters:
[in]addrStart address in SRAM for read operation
[out]dataPointer to the location where data stored
[in]lengthNumber of bytes to be read from SRAM
void pal_trx_sram_write ( uint8_t  addr,
uint8_t *  data,
uint8_t  length 
)

Writes data into SRAM of the transceiver.

This function writes data into the SRAM of the transceiver

Parameters:
addrStart address in the SRAM for the write operation
dataPointer to the data to be written into SRAM
lengthNumber of bytes to be written into SRAM
void pal_wdt_enable ( WDT_PER_t  period)

Enable Watchdog and set prescaler.

This function enables the Watchdog and applies prescaler settings. The Watchdog will be reset automatically.

The function writes the correct signature to the Configuration Change Protection register before writing the CTRL register. Interrupts are automatically ignored during the change enable period. The function will wait for the watchdog to be synchronized to the other clock domains before proceeding

Parameters:
periodWatchdog Timer timeout period
void RTC_Initialize ( uint16_t  period,
uint16_t  count,
uint16_t  compareValue,
RTC_PRESCALER_t  prescaler 
)

This function initializes the RTC with period, initial count, compare value and clock prescaler.

All the synchronized registers are written at the same time to save time. The program code need to check if the RTC is busy before calling this function. The RTC_Busy() function can be used to do this.

Parameters:
periodRTC period. Topvalue = Period - 1.
countInitial RTC count.
compareValueCompare value.
prescalerClock prescaler setting.
Note:
It is required that the period of the Sleeping Timer (RTC) is less than the Time-out period of Watchdog Timer (If enabled) to avoid the unintentional reset of the device.
void RTC_SetIntLevels ( RTC_OVFINTLVL_t  ovfIntLevel,
RTC_COMPINTLVL_t  compIntLevel 
)

This function sets both compare and overflow interrupt levels in one go.

Parameters:
ovfIntLevelThe overflow interrupt level.
compIntLevelThe compare interrupt level.
void sleeping_timer_with_wdt ( void  )

Initialization of Sleeping timer (RTC) of the Atxmega1281 when Watchdog Timer is enabled. The period for the Sleeping timer should be given by the user in this case and the period of the sleeping timer should be less than the time-out period of the watchdog timer.

Note:
It is required that the period of the Sleeping Timer (RTC) is less than the Time-out period of Watchdog Timer (If enabled) to avoid the unintentional reset of the device.