Professional Documents
Culture Documents
Module
BeaconIRCaptureModule.c
Description
Listens for IR events
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
#include "BeaconIRInputCaptureModule.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 InitBeaconIRInputCaptureModule(void)
{
// enable wide timer 1 subtimer A which corresponds to PC6.
// enable wide timer 1 subtimer A which corresponds to PC6.
// enable wide timer 1 subtimer A which corresponds to PC6.
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_TAEN;
// 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_TAILR) = 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_TAMR) = (HWREG(WTIMER1_BASE + TIMER_O_TAMR) &
~TIMER_TAMR_TAAMS) | (TIMER_TAMR_TACDIR | TIMER_TAMR_TACMR | TIMER_TAMR_TAMR_CAP);
// To listen to rising edges, set TAEVENT bits in CTL register to clear
HWREG(WTIMER1_BASE + TIMER_O_CTL) &= ~TIMER_CTL_TAEVENT_M;
void DisableBeaconIR()
{
HWREG(WTIMER1_BASE + TIMER_O_IMR) &= ~TIMER_IMR_CAEIM;
}