Академический Документы
Профессиональный Документы
Культура Документы
Module
Beacon.c
Revision
1.0.1
Description
This is a template file for implementing a simple service under the
Gen2 Events and Services Framework.
Notes
History
When Who
--------------------
****************************************************************************/
/*----------------------------- Include Files -----------------------------*/
/* include header files for this state machine as well as any machines at the
next lower level in the hierarchy that are sub-machines to this machine
*/
#include <stdio.h>
#include "ES_Configure.h"
#include "ES_Framework.h"
#include "ES_Port.h"
#include "ES_DeferRecall.h"
#include "ES_Timers.h"
#include "termio.h"
#include "BITDEFS.h" // standard bit definitions to make things more readable
//Time define
#define TicksPerMS 40000 //use system clock
#define USperMS 1000
#define OneShotTimeout 100*TicksPerMS // 100 ms
#define PeriodMinTicks 0.25*TicksPerMS
#define PeriodMaxTicks 1.25*TicksPerMS
uint32_t ThisEdgeTime;
uint32_t SignalPeriod;
//grab ThisEdgeTime from timer register
ThisEdgeTime = HWREG(WTIMER0_BASE+TIMER_O_TAR);
//calculate SignalPeriod using ThisEdgeTime and LastEdgeTime
SignalPeriod = ThisEdgeTime - LastEdgeTime;
//increase EdgeCounter
EdgeCounter ++;
//calculate AvgSignalPeriod by calculating the average period during the
EdgeCounter time
AvgSignalPeriod = (AvgSignalPeriod * (EdgeCounter - 1) + SignalPeriod) /
EdgeCounter;
PostGameMasterSM(ThisEvent);
/*******************************************************************************
******************************/
void InitBeaconOneShot( void ){
// start by enabling the clock to the timer (Wide Timer 0)
HWREG(SYSCTL_RCGCWTIMER) |= SYSCTL_RCGCWTIMER_R0;
// kill a few cycles to let the clock get going
while((HWREG(SYSCTL_PRWTIMER) & SYSCTL_PRWTIMER_R0) != SYSCTL_PRWTIMER_R0);
// make sure that timer (Timer B) is disabled before configuring
HWREG(WTIMER0_BASE+TIMER_O_CTL) &= ~TIMER_CTL_TBEN; //TBEN = Bit0
// set it up in 32bit wide (individual, not concatenated) mode
// the constant name derives from the 16/32 bit timer, but this is a 32/64
// bit timer so we are setting the 32bit mode
HWREG(WTIMER0_BASE+TIMER_O_CFG) = TIMER_CFG_16_BIT; //bits 0-2 = 0x04
// set up timer B in 1-shot mode so that it disables timer on timeouts
// first mask off the TBMR field (bits 0:1) then set the value for
// 1-shot mode = 0x01
HWREG(WTIMER0_BASE+TIMER_O_TBMR) =
(HWREG(WTIMER0_BASE+TIMER_O_TBMR)& ~TIMER_TBMR_TBMR_M)|
TIMER_TBMR_TBMR_1_SHOT;
// set up timer B DOWN-counting (TBCDIR = 0)
// so that rewrting the OneShotTimeout will restart timerB
HWREG(WTIMER0_BASE+TIMER_O_TBMR) &= ~TIMER_TBMR_TBCDIR;
// set timeout
HWREG(WTIMER0_BASE+TIMER_O_TBILR) = OneShotTimeout;
// enable a local timeout interrupt. TBTOIM = bit 0
HWREG(WTIMER0_BASE+TIMER_O_IMR) |= TIMER_IMR_TBTOIM; // bit0
// enable the Timer B in Wide Timer 0 interrupt in the NVIC
// it is interrupt number 95 so appears in EN2 at bit 31
HWREG(NVIC_EN2) |= BIT31HI;
// make sure interrupts are enabled globally
__enable_irq();
// Start the one shot timer later when needed (when command ==AlignWithBeacon)
}