Professional Documents
Culture Documents
Module
ReloadIRCaptureModule.c
Description
Listens for IR events
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
#include "ReloadIRCaptureModule.h"
// Hardware
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "inc/hw_sysctl.h"
#include "inc/hw_pwm.h"
#include "inc/hw_nvic.h"
#include "inc/hw_timer.h"
void InitReloadIRCapture(void)
{
// enable wide timer 1, timer B
HWREG(SYSCTL_RCGCWTIMER) |= SYSCTL_RCGCWTIMER_R1;
// this will output/listen to pin pc4 (the first available pin)
HWREG(SYSCTL_RCGCGPIO) |= SYSCTL_RCGCGPIO_R2;
// disable timer
HWREG(WTIMER1_BASE + TIMER_O_CTL) &= ~TIMER_CTL_TBEN;
// make sure it's in 32bit long mode, this concatenates two 16bit timers.
HWREG(WTIMER1_BASE + TIMER_O_CFG) = TIMER_CFG_16_BIT;
//make roll-over of timer equal to the roll-over or 32bit int for simplicity/time
subtraction
HWREG(WTIMER1_BASE + TIMER_O_TBILR) = 0xffffffff;
// Set wide timer A to capture mode (TAMR=3, TAAMS = 0),
// store the edge time in the value register (TACMR = 1) and make it count up(TACDIR
= 1)
HWREG(WTIMER1_BASE + TIMER_O_TBMR) = (HWREG(WTIMER1_BASE + TIMER_O_TBMR) &
~TIMER_TBMR_TBAMS) | (TIMER_TBMR_TBCDIR | TIMER_TBMR_TBCMR | TIMER_TBMR_TBMR_CAP);
// To listen to rising edges, set TAEVENT bits in CTL register to clear
HWREG(WTIMER1_BASE + TIMER_O_CTL) &= ~TIMER_CTL_TBEVENT_M;
void DisableReloadIR()
{
CurrentPeriod_US = 0;
HWREG(WTIMER1_BASE + TIMER_O_IMR) &= (~TIMER_IMR_CBEIM);
}
void EnableReloadIR()
{
HWREG(WTIMER1_BASE + TIMER_O_IMR) |= TIMER_IMR_CBEIM;
}