|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
public interface IAT91_TC
Interface to an AT91 Timer Counter.
The AT91 Timer Counter includes three identical 16-bit Timer Counter channels.
Each channel can be independently programmed to perform a wide range of functions including frequency measurement, event counting, interval measurement, pulse generation, delay timing and pulse width modulation.
Each channel has three external clock inputs, five internal clock inputs and two multi-purpose input/output signals which can be configured by the user. Each channel drives an internal interrupt signal which can be programmed to generate processor interrupts.
For a full description of the AT91 Timer Counter please refer to the Atmel documentation.
Here we will provide a few basics to allow using the Timer to generate a periodic interrupt.
For Timer Counter bit definitions please see TimerCounterBits
.
Several signals are provided on the SPOT processor board via the top connector, though the initial eDemo sensor board does not make them available. The available signals are the three external clock inputs (TCLK0, TCLK1, TCLK2) and the general purpose input/output pins for channel 0 (TIOA0, TIOB0).
The Timer Counter can operate in two distinct modes: Capture & Waveform generation. In either mode the rate at which the Timer counts is determined by which internal clock is used. The available clock speeds are:
TimerCounterBits.TC_CLKS_MCK2
)
TimerCounterBits.TC_CLKS_MCK8
)
TimerCounterBits.TC_CLKS_MCK32
)
TimerCounterBits.TC_CLKS_MCK128
)
TimerCounterBits.TC_CLKS_SLCK
)
To use the Timer to measure an interval use Capture Mode, enable the clock to start it counting,
and at the end of the interval just read the counter value:
To generate periodic interrupts modify the above code to set the RC Register to the number of counts
that will span the desired period, and enable interrupts on RC Compare:
IAT91_TC timer = Spot.getInstance().getAT91_TC(0);
timer.configure(TC_CAPT | TC_CLKS_MCK32);
timer.enableAndReset();
... interval to measure ...
int cntr = timer.counter();
double interval = cntr * 0.5342; // time in microseconds
A Java thread detects an interrupt by calling
IAT91_TC timer = Spot.getInstance().getAT91_TC(0);
int cnt = (int)(25000 / 0.5342); // number of clock counts for 25 milliseconds
timer.configure(TC_CAPT | TC_CPCTRG | TC_CLKS_MCK32);
timer.setRegC(cnt);
timer.enableAndReset();
while(true) {
timer.enableIrq(TC_CPCS); // Enable RC Compare interrupt
timer.waitForIrq();
timer.status(); // Clear interrupt pending flag
doTask(); // method will be called every 25 milliseconds
}
waitForIrq()
.
This method performs a Channel IO request. If the Timer Counter interrupt bit
is set the request returns immediately. If not the calling thread is blocked
until the interrupt occurs. To clear the interrupt bit call status()
.
To handle an interrupt in Java you must:
configure(int)
to configure the timer so that it will generate an interrupt request.
enableAndReset()
to start the timer counting
enableIrq(int)
to enable one or more of the interrupt sources associated with this TC channel.
waitForIrq()
to wait for the interrupt.
status()
to clear the interrupt.
enableIrq(int)
to allow another interrupt.
If you don't want more interrupts then don't call enableIrq(int)
.
Method Summary | |
---|---|
void |
blockSync()
Perform a block sync command, which causes a reset of all three counters |
void |
claimTCLK()
Enable PIO use of shared TCLK line |
void |
claimTIOA()
Disable PIO use of shared TIOA line |
void |
claimTIOB()
Disable PIO use of shared TIOB line |
void |
configure(int mask)
Configure the Timer-Counter |
void |
configureXC(int xcMask)
Configure the block mode inputs appropriate to this TC channel |
int |
counter()
Read current counter value |
void |
disable()
Disable the counter |
void |
disableIrq(int mask)
Disable one or more of the interrupt sources associated with this TC channel. |
void |
enable()
Enable counter |
void |
enableAndReset()
Enable counter and cause software trigger which forces a reset on next clock edge |
void |
enableIrq(int mask)
Enable one or more of the interrupt sources associated with this TC channel. |
int |
regA()
Read current Reg A value |
int |
regB()
Read current Reg B value |
void |
setRegA(int i)
Set the value of the A Compare Register |
void |
setRegC(int i)
Set the value of the C Compare Register |
int |
status()
Read current status |
void |
unclaimTIOA()
Enable PIO use of shared TIOA line |
void |
waitForIrq()
Suspend this thread until this TC generates an interrupt. |
Methods inherited from interface com.sun.spot.peripheral.IDriver |
---|
getDriverName, setUp, shutDown, tearDown |
Method Detail |
---|
void configure(int mask)
mask
- bits to set in TC_CMRvoid enableAndReset()
void enable()
int counter()
int status()
void claimTIOA()
void unclaimTIOA()
void claimTIOB()
void claimTCLK()
int regA()
int regB()
void setRegC(int i)
i
- Value to be setvoid setRegA(int i)
i
- Value to be setvoid disable()
void configureXC(int xcMask)
xcMask
- Bits to be set in TC_BMRvoid blockSync()
void enableIrq(int mask)
mask
- Bit mask identifying the required interrupt source(s)void waitForIrq()
enableIrq(int)
prior to this, and again if you want a subsequent interrupt.
void disableIrq(int mask)
mask
- Bit mask identifying the required interrupt source(s)
|
SunSPOT API V3.0 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |