Microchip® Advanced Software Framework

tc_megarf.h File Reference

AVR MEGA Timer Counter (TC) driver.

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

Macros

#define TCCRB_OFFSET   1
 
#define TCNT_OFFSET   4
 

Typedefs

typedef void(* tc_callback_t )(void)
 Interrupt event callback function type. More...
 
typedef enum TC_CLKSEL_enum TC_CLKSEL_t
 
typedef enum TC_MODE_enum TC_MODE_t
 

Enumerations

enum  tc_cc_channel_t {
  TC_COMPA = 0X08,
  TC_COMPB = 0X0A,
  TC_COMPC = 0X0C
}
 
enum  TC_CLKSEL_enum {
  TC_CLKSEL_OFF_gc = (0x00),
  TC_CLKSEL_DIV1_gc = (0x01),
  TC_CLKSEL_DIV8_gc = (0x02),
  TC_CLKSEL_DIV64_gc = (0x03),
  TC_CLKSEL_DIV256_gc = (0x04),
  TC_CLKSEL_DIV1024_gc = (0x05),
  TC_EXT_CLK_FALLING_gc = (0x06),
  TC_EXT_CLK_RISING_gc = (0x07)
}
 
enum  TC_MODE_enum {
  NORMAL = 0X00,
  PWM_Mode1 = 0X01,
  PWM_Mode2 = 0X02,
  PWM_Mode3 = 0X03,
  CTC_Mode1 = 0X04,
  PWM_Mode4 = 0X05,
  PWM_Mode5 = 0X06,
  PWM_Mode6 = 0X07,
  PWM_Mode7 = 0X08,
  PWM_Mode8 = 0X09,
  PWM_Mode9 = 0X0A,
  PWM_Mode10 = 0X0B,
  CTC_Mode2 = 0X0C,
  PWM_Mode11 = 0X0E,
  PWM_Mode12 = 0X0F
}
 

Functions

static void clear_compa_flag (volatile void *tc)
 Clears Compare Match Flag in channel A. More...
 
static void clear_compb_flag (volatile void *tc)
 Clears Compare Match Flag in channel B. More...
 
static void clear_compc_flag (volatile void *tc)
 Clears Compare Match Flag in channel C. More...
 
static void clear_ovf_flag (volatile void *tc)
 Clears Overflow Flag. More...
 
void tc_disable (volatile void *tc)
 Disable Timer. More...
 
static void tc_disable_compa_int (volatile void *tc)
 Disable Compare Interrupt in channel A. More...
 
static void tc_disable_compb_int (volatile void *tc)
 Disable Compare Interrupt in channel B. More...
 
static void tc_disable_compc_int (volatile void *tc)
 Disable Compare Interrupt in channel C. More...
 
static void tc_disable_ovf_int (volatile void *tc)
 Disable Overflow Interrupt. More...
 
void tc_enable (volatile void *tc)
 Enable Timer. More...
 
static void tc_enable_compa_int (volatile void *tc)
 Enable Compare Interrupt in channel A. More...
 
static void tc_enable_compb_int (volatile void *tc)
 Enable Compare Interrupt in channel B. More...
 
static void tc_enable_compc_int (volatile void *tc)
 Enable Compare Interrupt in channel C. More...
 
static void tc_enable_ovf_int (volatile void *tc)
 Enable Overflow Interrupt. More...
 
static bool tc_is_compa_match (volatile void *tc)
 Checks whether a Compare Match has occured in Channel A. More...
 
static bool tc_is_compb_match (volatile void *tc)
 Checks whether a Compare Match has occured in Channel B. More...
 
static bool tc_is_compc_match (volatile void *tc)
 Checks whether a Compare Match has occured in Channel C. More...
 
static bool tc_is_overflow (volatile void *tc)
 Checks whether a timer has overflowed. More...
 
static uint16_t tc_read_count (volatile void *tc)
 Reads the count value in the Timer Counter Register. More...
 
void tc_set_compa_interrupt_callback (volatile void *tc, tc_callback_t callback)
 Register a Compare interrupt callback. More...
 
void tc_set_compb_interrupt_callback (volatile void *tc, tc_callback_t callback)
 Register a Compare interrupt callback. More...
 
void tc_set_compc_interrupt_callback (volatile void *tc, tc_callback_t callback)
 Register a Compare interrupt callback. More...
 
static void tc_set_mode (volatile void *tc, TC_MODE_t mode)
 Sets a timer in a particular mode of operation. More...
 
void tc_set_overflow_interrupt_callback (volatile void *tc, tc_callback_t callback)
 Register a Overflow interrupt callback. More...
 
static void tc_write_cc (volatile void *tc, enum tc_cc_channel_t channel_index, uint16_t value)
 Write Compare register with timer Value. More...
 
static void tc_write_clock_source (volatile void *tc, TC_CLKSEL_t TC_CLKSEL_enum)
 Select a source for a timer. More...
 
static void tc_write_count (volatile void *tc, uint16_t value)
 Writes a count value to the Timer Counter Register. More...
 

#define TCCRB_OFFSET   1
#define TCNT_OFFSET   4

typedef void(* tc_callback_t)(void)

Interrupt event callback function type.

The interrupt handler can be configured to do a function callback, the callback function must match the tc_callback_t type.

typedef enum TC_MODE_enum TC_MODE_t

Enumerator
TC_COMPA 
TC_COMPB 
TC_COMPC 
Enumerator
TC_CLKSEL_OFF_gc 
TC_CLKSEL_DIV1_gc 
TC_CLKSEL_DIV8_gc 
TC_CLKSEL_DIV64_gc 
TC_CLKSEL_DIV256_gc 
TC_CLKSEL_DIV1024_gc 
TC_EXT_CLK_FALLING_gc 
TC_EXT_CLK_RISING_gc 
Enumerator
NORMAL 
PWM_Mode1 
PWM_Mode2 
PWM_Mode3 
CTC_Mode1 
PWM_Mode4 
PWM_Mode5 
PWM_Mode6 
PWM_Mode7 
PWM_Mode8 
PWM_Mode9 
PWM_Mode10 
CTC_Mode2 
PWM_Mode11 
PWM_Mode12 

static void clear_compa_flag ( volatile void *  tc)
inlinestatic

Clears Compare Match Flag in channel A.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int(), tmr_disable_cc_interrupt(), and tmr_enable_cc_interrupt().

static void clear_compb_flag ( volatile void *  tc)
inlinestatic

Clears Compare Match Flag in channel B.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int().

static void clear_compc_flag ( volatile void *  tc)
inlinestatic

Clears Compare Match Flag in channel C.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int().

static void clear_ovf_flag ( volatile void *  tc)
inlinestatic

Clears Overflow Flag.

Parameters
tcTimer Address

Referenced by tc_disable_overflow_int(), and tmr_disable_ovf_interrupt().

void tc_disable ( volatile void *  tc)

Disable Timer.

Parameters
tcTimer Address

References cpu_irq_restore(), cpu_irq_save(), and sysclk_disable_peripheral_clock().

Referenced by tc_stop(), and tmr_stop().

static void tc_disable_compa_int ( volatile void *  tc)
inlinestatic

Disable Compare Interrupt in channel A.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int(), tmr_disable_cc_interrupt(), and tmr_init().

static void tc_disable_compb_int ( volatile void *  tc)
inlinestatic

Disable Compare Interrupt in channel B.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int().

static void tc_disable_compc_int ( volatile void *  tc)
inlinestatic

Disable Compare Interrupt in channel C.

Parameters
tcTimer Address

Referenced by tc_disable_compare_int().

static void tc_disable_ovf_int ( volatile void *  tc)
inlinestatic

Disable Overflow Interrupt.

Parameters
tcTimer Address

Referenced by tc_disable_overflow_int(), and tc_stop().

void tc_enable ( volatile void *  tc)

Enable Timer.

Parameters
tcTimer Address

References cpu_irq_restore(), cpu_irq_save(), and sysclk_enable_peripheral_clock().

Referenced by init_timer_isr(), and tmr_init().

static void tc_enable_compa_int ( volatile void *  tc)
inlinestatic

Enable Compare Interrupt in channel A.

Parameters
tcTimer Address

Referenced by initialize_EPD_timer(), and tmr_enable_cc_interrupt().

static void tc_enable_compb_int ( volatile void *  tc)
inlinestatic

Enable Compare Interrupt in channel B.

Parameters
tcTimer Address
static void tc_enable_compc_int ( volatile void *  tc)
inlinestatic

Enable Compare Interrupt in channel C.

Parameters
tcTimer Address
static void tc_enable_ovf_int ( volatile void *  tc)
inlinestatic

Enable Overflow Interrupt.

Parameters
tcTimer Address

Referenced by tmr_disable_ovf_interrupt(), and tmr_init().

static bool tc_is_compa_match ( volatile void *  tc)
inlinestatic

Checks whether a Compare Match has occured in Channel A.

Parameters
tcTimer Address
static bool tc_is_compb_match ( volatile void *  tc)
inlinestatic

Checks whether a Compare Match has occured in Channel B.

Parameters
tcTimer Address
static bool tc_is_compc_match ( volatile void *  tc)
inlinestatic

Checks whether a Compare Match has occured in Channel C.

Parameters
tcTimer Address
static bool tc_is_overflow ( volatile void *  tc)
inlinestatic

Checks whether a timer has overflowed.

Parameters
tcTimer Address
static uint16_t tc_read_count ( volatile void *  tc)
inlinestatic

Reads the count value in the Timer Counter Register.

Parameters
tcTimer Address
Returns
count in the register

Referenced by tmr_read_count().

void tc_set_compa_interrupt_callback ( volatile void *  tc,
tc_callback_t  callback 
)

Register a Compare interrupt callback.

Parameters
tcTimer Address
callbackCallback called once Compare interrupt occurs in channel A

References tc_tccr1_compa_callback, tc_tccr3_compa_callback, tc_tccr4_compa_callback, and tc_tccr5_compa_callback.

Referenced by configure_tc_callback(), and initialize_EPD_timer().

void tc_set_compb_interrupt_callback ( volatile void *  tc,
tc_callback_t  callback 
)

Register a Compare interrupt callback.

Parameters
tcTimer Address
callbackCallback called once Compare interrupt occurs in channel B

References tc_tccr1_compb_callback, tc_tccr3_compb_callback, tc_tccr4_compb_callback, and tc_tccr5_compb_callback.

Referenced by configure_tc_callback().

void tc_set_compc_interrupt_callback ( volatile void *  tc,
tc_callback_t  callback 
)

Register a Compare interrupt callback.

Parameters
tcTimer Address
callbackCallback called once Compare interrupt occurs in channel C

References tc_tccr1_compc_callback, tc_tccr3_compc_callback, tc_tccr4_compc_callback, and tc_tccr5_compc_callback.

Referenced by configure_tc_callback().

static void tc_set_mode ( volatile void *  tc,
TC_MODE_t  mode 
)
inlinestatic

Sets a timer in a particular mode of operation.

Parameters
tcTimer Address
modeEnum value of the selected mode

References CTC_Mode1, NORMAL, and TCCRB_OFFSET.

Referenced by tmr_init().

void tc_set_overflow_interrupt_callback ( volatile void *  tc,
tc_callback_t  callback 
)

Register a Overflow interrupt callback.

Parameters
tcTimer Address
callbackCallback called once Overflow interrupt occurs

References tc_tccr1_ovf_callback, tc_tccr3_ovf_callback, tc_tccr4_ovf_callback, and tc_tccr5_ovf_callback.

Referenced by tmr_init().

static void tc_write_cc ( volatile void *  tc,
enum tc_cc_channel_t  channel_index,
uint16_t  value 
)
inlinestatic

Write Compare register with timer Value.

Parameters
tcTimer Address
channel_indexCompare Channel to be used
valueCompare value to be written

Referenced by initialize_EPD_timer(), PWM_start_toggle(), and tmr_write_cmpreg().

static void tc_write_clock_source ( volatile void *  tc,
TC_CLKSEL_t  TC_CLKSEL_enum 
)
inlinestatic

Select a source for a timer.

Parameters
tcTimer Address
TC_CLKSEL_enumSelect a source from enum type

Referenced by tmr_init().

static void tc_write_count ( volatile void *  tc,
uint16_t  value 
)
inlinestatic

Writes a count value to the Timer Counter Register.

Parameters
tcTimer Address
valuecount to be written in the register