Microchip® Advanced Software Framework

macsc_megarf.h File Reference

AVR MEGARF MAC Symbol Counter Driver Definitions.

Copyright (c) 2014-2018 Microchip Technology Inc. and its subsidiaries.

#include <compiler.h>
#include <parts.h>
#include "status_codes.h"

Macros

#define CONCAT(a, b)   a ## b
 String concatenation by preprocessor used to create proper register names. More...
 
#define MACSC_ABSOLUTE_CMP   0
 
#define MACSC_READ32(reg)
 Creates proper subregister names and reads the corresponding values. More...
 
#define MACSC_RELATIVE_CMP   1
 
#define MACSC_WRITE32(reg, val)
 

Typedefs

typedef void(* macsc_callback_t )(void)
 Interrupt event callback function type. More...
 

Enumerations

enum  macsc_cc_channel {
  MACSC_CC1 = 1,
  MACSC_CC2 = 2,
  MACSC_CC3 = 3
}
 
enum  macsc_xtal {
  MACSC_16MHz = 0,
  MACSC_32KHz = 1
}
 MAC SC clock source select. More...
 

Functions

bool is_macsc_backoff_enable (void)
 Check if back-off slot counter is enabled. More...
 
bool is_macsc_enable (void)
 Check if MACSC is enabled. More...
 
static void macsc_backoff_slot_cnt_disable (void)
 Disable back-off slot counter. More...
 
static bool macsc_backoff_slot_cnt_enable (void)
 enable back-off slot counter More...
 
static void macsc_clear_cmp_interrupt_flag (enum macsc_cc_channel channel)
 Clears Compare interrupt. More...
 
static void macsc_clear_overflow_flag (void)
 Clears the Overflow flag. More...
 
static void macsc_clear_slot_cntr_interrupt_flag (void)
 Clears the Backoff Slot cntr interrupt flag. More...
 
void macsc_disable (void)
 Disable MAC SC. More...
 
void macsc_enable (void)
 Enable MAC SC. More...
 
static void macsc_enable_auto_ts (void)
 Enable the Auto SFD and Beacon Timestamping feature If this bit is zero,only manual beacon timestamping can be used. More...
 
void macsc_enable_cmp_int (enum macsc_cc_channel channel)
 Enables compare interrupts of the MACSC. More...
 
static void macsc_enable_manual_bts (void)
 Write the Beacon Timestamp register of the MAC Symbol counter The manual beacon timestamping can be used in conjunction with the relative compare mode of the three compare units to generate compare match interrupts without having a beacon frame received. More...
 
static void macsc_enable_overflow_interrupt (void)
 Enable the MACSC Overflow interrupt. More...
 
static bool macsc_is_cmp_interrupt_flag_set (enum macsc_cc_channel channel)
 Reports if Compare interrupt has occurred. More...
 
static bool macsc_is_overflow_flag_set (void)
 Tests if the Overflow flag is set. More...
 
static bool macsc_is_slot_cntr_interrupt_flag_set (void)
 Tests if the Backoff slot cntr interrupt flag is set. More...
 
static uint32_t macsc_read32 (volatile uint8_t *hh, volatile uint8_t *hl, volatile uint8_t *lh, volatile uint8_t *ll)
 Reads the 32-bit timer register in the required order of bytes. More...
 
static uint32_t macsc_read_bts (void)
 Reads the Beacon Timestamp register. More...
 
static enum macsc_xtal macsc_read_clock_source (void)
 Read MAC SC Clock Source. More...
 
static uint32_t macsc_read_count (void)
 Reads the Counter value of the MAC Symbol counter. More...
 
static bool macsc_read_status (void)
 Read the MACSC status register This bit is set if a write operation to the symbol counter register is pending. More...
 
static uint32_t macsc_read_ts (void)
 Reads the SFD Timestamp register. More...
 
void macsc_set_backoff_slot_cntr_int_cb (macsc_callback_t callback)
 Set MACSC backoff slot counter interrupt callback function. More...
 
void macsc_set_cmp1_int_cb (macsc_callback_t callback)
 Set MACSC Compare Channel 1 interrupt callback function. More...
 
void macsc_set_cmp2_int_cb (macsc_callback_t callback)
 Set MACSC Compare Channel 2 interrupt callback function. More...
 
void macsc_set_cmp3_int_cb (macsc_callback_t callback)
 Set MACSC Compare Channel 3 interrupt callback function. More...
 
void macsc_set_ovf_int_cb (macsc_callback_t callback)
 Set MACSC overflow interrupt callback function. More...
 
static void macsc_sleep_clk_disable (void)
 Disable 32.768KHz clk using timer 2 async register. More...
 
static void macsc_sleep_clk_enable (void)
 Enable 32.768KHz clk using timer 2 async register. More...
 
static bool macsc_sync (void)
 Symbol Counter sync. More...
 
void macsc_use_cmp (bool abs_rel, uint32_t cmp, enum macsc_cc_channel channel)
 Usage of Absolute compare mode of the MACSC. More...
 
static void macsc_write_clock_source (enum macsc_xtal source)
 Configure MAC Symbol Counter Clock Source. More...
 
static void macsc_write_count (uint32_t cnt_value)
 Write the Counter value of the MAC Symbol counter. More...
 

static void macsc_backoff_slot_cnt_disable ( void  )
inlinestatic

Disable back-off slot counter.

Parameters
none
Note
Disables interrupt as well .
This counter works only if transceiver clock is running.So check Trx state in app before using this function in IEEE802.15.4 applications.

Referenced by test_macsc_backoff().

static bool macsc_backoff_slot_cnt_enable ( void  )
inlinestatic

enable back-off slot counter

Parameters
none
Note
Enables interrupt as well .
This counter works only if transceiver clock is running.So check Trx state in app before using this function in IEEE802.15.4 applications.

Referenced by main(), and test_macsc_backoff().

static void macsc_clear_cmp_interrupt_flag ( enum macsc_cc_channel  channel)
inlinestatic

Clears Compare interrupt.

Parameters
channelCompare Channel

References MACSC_CC1, MACSC_CC2, and MACSC_CC3.

static void macsc_clear_overflow_flag ( void  )
inlinestatic

Clears the Overflow flag.

Note
IRQSOF is cleared
static void macsc_clear_slot_cntr_interrupt_flag ( void  )
inlinestatic

Clears the Backoff Slot cntr interrupt flag.

Note
IRQSBO is cleared
static void macsc_enable_auto_ts ( void  )
inlinestatic

Enable the Auto SFD and Beacon Timestamping feature If this bit is zero,only manual beacon timestamping can be used.

static void macsc_enable_manual_bts ( void  )
inlinestatic

Write the Beacon Timestamp register of the MAC Symbol counter The manual beacon timestamping can be used in conjunction with the relative compare mode of the three compare units to generate compare match interrupts without having a beacon frame received.

If set to 1, the current symbol counter value is stored into the beacon timestamp register. The bit is cleared afterwards.

Referenced by example_cmp3_int_cb(), main(), and sm_sleep().

static void macsc_enable_overflow_interrupt ( void  )
inlinestatic

Enable the MACSC Overflow interrupt.

Note
IRQMOF is set;Before enabling an interrupt, the corresponding interrupt status bit should be cleared by writing a 1. If the status bit is set and the IRQ gets enabled, the IRQ handler is called immediately

Referenced by main().

static bool macsc_is_cmp_interrupt_flag_set ( enum macsc_cc_channel  channel)
inlinestatic

Reports if Compare interrupt has occurred.

Parameters
channelCompare Channel
Returns
CCx Interrupt or not

References MACSC_CC1, MACSC_CC2, and MACSC_CC3.

static bool macsc_is_overflow_flag_set ( void  )
inlinestatic

Tests if the Overflow flag is set.

Returns
overflow has occurred or not : IRQSOF
static bool macsc_is_slot_cntr_interrupt_flag_set ( void  )
inlinestatic

Tests if the Backoff slot cntr interrupt flag is set.

Returns
backoff slot cntr interrupt has occurred or not : IRQSBO
static uint32_t macsc_read_bts ( void  )
inlinestatic

Reads the Beacon Timestamp register.

Returns
Timestamp of last received beacon frame :SCBTSR

References MACSC_READ32.

static enum macsc_xtal macsc_read_clock_source ( void  )
inlinestatic

Read MAC SC Clock Source.

Parameters
none
Returns
macsc_xtal enum Clock source selection
static uint32_t macsc_read_count ( void  )
inlinestatic

Reads the Counter value of the MAC Symbol counter.

Note
Output the Counter value

References MACSC_READ32.

Referenced by example_cmp1_int_cb(), example_cmp2_int_cb(), and example_cmp3_int_cb().

static bool macsc_read_status ( void  )
inlinestatic

Read the MACSC status register This bit is set if a write operation to the symbol counter register is pending.

This bit is set after writing the counter low byte (SCCNTLL) until the symbol counter is updated with the new value. This update process can take up to 16 µs and during this time, no read or write access to the 32 bit counter register should occur.

static uint32_t macsc_read_ts ( void  )
inlinestatic

Reads the SFD Timestamp register.

Returns
Timestamp of last received frame :SCTSR(read-only register)

References MACSC_READ32.

static bool macsc_sync ( void  )
inlinestatic

Symbol Counter sync.

Note
to align macsc to within one symbol period
static void macsc_write_clock_source ( enum macsc_xtal  source)
inlinestatic

Configure MAC Symbol Counter Clock Source.

Parameters
macscmacsc clk src

References MACSC_16MHz, and MACSC_32KHz.

Referenced by main(), and sm_init().

static void macsc_write_count ( uint32_t  cnt_value)
inlinestatic

Write the Counter value of the MAC Symbol counter.

Parameters
cnt_valueCounter value

References MACSC_WRITE32.

Referenced by example_cmp1_int_cb(), example_cmp2_int_cb(), and example_cmp3_int_cb().