00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef __AVR_CPP_TIMER_H__
00029 #define __AVR_CPP_TIMER_H__
00030
00031 #include "IO.h"
00032
00033
00034 namespace AVRCpp
00035 {
00036 namespace Timer
00037 {
00038 enum ClockA
00039 {
00040 NoClockA = 0x00,
00041 NoPrescaleA = 0x01,
00042 Prescale8A = 0x02,
00043 Prescale32A = 0x03,
00044 Prescale64A = 0x04,
00045 Prescale128A = 0x05,
00046 Prescale256A = 0x06,
00047 Prescale1024A = 0x07
00048
00049 };
00050
00051 enum ClockB
00052 {
00053 NoClockB = 0x00,
00054 NoPrescaleB = 0x01,
00055 Prescale8B = 0x02,
00056 Prescale64B = 0x03,
00057 Prescale256B = 0x04,
00058 Prescale1024B = 0x05,
00059 ExternalFall = 0x06,
00060 ExternalRise = 0x07
00061
00062 };
00063
00064 enum CompareOutputMode
00065 {
00066 NormalPortOperation = 0x00,
00067 Toggle = 0x10,
00068 Clear = 0x20,
00069 Set = 0x30
00070
00071 };
00072
00073 enum CompareOutputModeA
00074 {
00075 NormalPortOperationA = 0x00,
00076 ToggleA = 0x40,
00077 ClearA = 0x80,
00078 SetA = 0xC0
00079
00080 };
00081
00082 enum CompareOutputModeB
00083 {
00084 NormalPortOperationB = 0x00,
00085 ToggleB = 0x10,
00086 ClearB = 0x20,
00087 SetB = 0x30
00088
00089 };
00090
00091 enum CompareOutputModeC
00092 {
00093 NormalPortOperationC = 0x00,
00094 ToggleC = 0x04,
00095 ClearC = 0x08,
00096 SetC = 0x0C
00097
00098 };
00099
00100 enum InputNoiseCanceler
00101 {
00102 On = 0x80,
00103 Off = 0x00
00104
00105 };
00106
00107 enum InputCaptureEdge
00108 {
00109 Rise = 0x40,
00110 Fall = 0x00
00111
00112 };
00113
00114 enum Mode
00115 {
00116 Normal = 0x00,
00117 ClearTimerOnCompareMatch = 0x08,
00118 PhaseCorrectPWM = 0x40,
00119 FastPWM = 0x48
00120
00121 };
00122
00123 enum FixedTop16
00124 {
00125 Normal16 = 0x00,
00126 FastPWM16BitsCount8 = 0x09,
00127 FastPWM16BitsCount9 = 0x0A,
00128 FastPWM16BitsCount10 = 0x0B,
00129 PhaseCorrectPWM16BitsCount8 = 0x01,
00130 PhaseCorrectPWM16BitsCount9 = 0x02,
00131 PhaseCorrectPWM16BitsCount10 = 0x03
00132
00133 };
00134
00135 enum TopFromInputCapture16
00136 {
00137 ClearTimerOnCompareMatch16TopFromInputCapture = 0x18,
00138 FastPWM16TopFromInputCapture = 0x1A,
00139 PhaseCorrectPWM16TopFromInputCapture = 0x12,
00140 PhaseAndFrequencyCorrectPWM16TopFromInputCapture = 0x10
00141
00142 };
00143
00144 enum TopFromOutputCompareA16
00145 {
00146 ClearTimerOnCompareMatch16TopFromOutputCompareA = 0x08,
00147 FastPWM16TopFromOutputCompareA = 0x1B,
00148 PhaseCorrectPWM16TopFromOutputCompareA = 0x13,
00149 PhaseAndFrequencyCorrectPWM16TopFromOutputCompareA = 0x11
00150
00151 };
00152
00153 enum FixedTop8
00154 {
00155 Normal8 = 0x00,
00156 FastPWM8 = 0x03,
00157 PhaseCorrectPWM8 = 0x01
00158
00159 };
00160
00161 enum TopFromOutputCompareA8
00162 {
00163 ClearTimerOnCompareMatch8TopFromOutputCompareA = 0x02,
00164 FastPWM8TopFromOutputCompareA = 0x0B,
00165 PhaseCorrectPWM8TopFromOutputCompareA = 0x09
00166
00167 };
00168
00169
00170 namespace Internal
00171 {
00172 enum CommonConstants
00173 {
00174 ClockMask = 0x03,
00175 Force = 0x80,
00176 ForceA = 0x80,
00177 ForceB = 0x40,
00178 ForceC = 0x20,
00179 OldForceA = 0x08,
00180 OldForceB = 0x04,
00181 TopMaskA8 = 0x03,
00182 TopMaskA16 = 0x03,
00183 TopMaskB8 = 0x08,
00184 TopMaskB16 = 0x18
00185
00186 };
00187
00188 enum BitFlags
00189 {
00190 AsynchronousFlagA = 0x08,
00191 CounterUpdateFlagA = 0x04,
00192 OutputCompareUpdateFlagA = 0x02,
00193 ControlUpdateFlagA = 0x01,
00194 ExternalClockEnableFlagB = 0x40,
00195 AsynchronousFlagB = 0x20,
00196 CounterUpdateFlagB = 0x10,
00197 OutputCompareAUpdateFlagB = 0x08,
00198 OutputCompareBUpdateFlagB = 0x04,
00199 ControlAUpdateFlagB = 0x02,
00200 ControlBUpdateFlagB = 0x01
00201
00202 };
00203
00204
00205 template <class Register, class UpdateBit> struct AsyncRegister : Register
00206 {
00207 static inline void Set(typename Register::Type)
00208 {
00209 while (UpdateBit::IsSet() );
00210 Register::Set();
00211
00212 }
00213
00214 static inline void SleepSafeSet(typename Register::Type value)
00215 {
00216 Set(value);
00217 while (UpdateBit::IsSet() );
00218
00219 }
00220
00221 };
00222
00223
00224 template <
00225 class CounterRegister,
00226 class ClockRegister,
00227 class ClockEnum >
00228
00229 struct SimpleTimer
00230 {
00231 typedef CounterRegister Counter;
00232
00233 static inline void SelectClock(ClockEnum clock) { ChangeBits<ClockRegister>(ClockMask, clock); }
00234 static inline uint8_t GetSelectedClock() { return SelectBits<ClockRegister>(ClockMask); }
00235
00236 };
00237
00238
00239 template <
00240 class CounterRegister,
00241 class OutputCompareRegister,
00242 class ControlRegister,
00243 class ClockEnum,
00244 class ChannelOutputPin >
00245
00246 struct OneChannel8BitTimer : SimpleTimer<CounterRegister, ControlRegister, ClockEnum>
00247 {
00248 typedef OutputCompareRegister OutputCompare;
00249 typedef ChannelOutputPin ChannelPin;
00250
00251 static inline void ForceOutputCompare() { SetBits<ControlRegister>(Force); }
00252
00253 static inline void SetUp (
00254 ClockEnum clock,
00255 Mode mode,
00256 CompareOutputMode compareOutputMode )
00257 {
00258 ControlRegister::Set(compareOutputMode | mode | clock);
00259
00260 }
00261
00262 };
00263
00264
00265 template <
00266 class CounterRegister,
00267 class OutputCompareRegister,
00268 class ControlRegister,
00269 class AsyncStatusRegister,
00270 class InterruptEnableBits,
00271 class InterruptFlagBits,
00272 class ChannelOutputPin >
00273
00274 class AsyncOneChannel8BitTimer : OneChannel8BitTimer <
00275 AsyncRegister<CounterRegister, Bits<AsyncStatusRegister, CounterUpdateFlagA> >,
00276 AsyncRegister<OutputCompareRegister, Bits<AsyncStatusRegister, OutputCompareUpdateFlagA> >,
00277 AsyncRegister<ControlRegister, Bits<AsyncStatusRegister, ControlUpdateFlagA> >,
00278 ClockA,
00279 ChannelOutputPin >
00280 {
00281 private:
00282
00283 typedef Bits<AsyncStatusRegister, AsynchronousFlagA> AsynchronousBit;
00284 typedef Bits<AsyncStatusRegister, CounterUpdateFlagA> CounterUpdateBit;
00285 typedef Bits<AsyncStatusRegister, OutputCompareUpdateFlagA> OutputCompareUpdateBit;
00286 typedef Bits<AsyncStatusRegister, ControlUpdateFlagA> ControlUpdateBit;
00287
00288 typedef AsyncRegister<CounterRegister, CounterUpdateBit> AsyncCounterRegister;
00289 typedef AsyncRegister<OutputCompareRegister, OutputCompareUpdateBit> AsyncOutputCompareRegister;
00290 typedef AsyncRegister<ControlRegister, ControlUpdateBit> AsyncControlRegister;
00291
00292 public:
00293
00294 static inline bool IsSafeForSleepMode()
00295 {
00296 return !(CounterUpdateBit::IsSet()
00297 || OutputCompareUpdateBit::IsSet()
00298 || ControlUpdateBit::IsSet() );
00299
00300 }
00301
00302 static inline void WaitUntilSafeForSleepMode() { while (!IsSafeForSleepMode() ); }
00303
00304 static void WaitMinimumTimeForReEnteringSleepMode()
00305 {
00306 AsyncControlRegister::Set(ControlRegister::Get() );
00307 WaitUntilSafeForSleepMode();
00308
00309 }
00310
00311 static inline uint8_t GetSafeCounterValue()
00312 {
00313 WaitMinimumTimeForReEnteringSleepMode();
00314
00315 return CounterRegister::Get();
00316
00317 }
00318
00319 static void AsynchronousOperation(bool enable)
00320 {
00321 uint8_t counter = CounterRegister::Get();
00322 uint8_t outputCompare = OutputCompareRegister::Get();
00323 uint8_t control = ControlRegister::Get();
00324 uint8_t interruptEnableBits = InterruptEnableBits::Select();
00325
00326 InterruptEnableBits::Clear();
00327
00328 AsynchronousBit::SetTo(enable);
00329
00330 AsyncCounterRegister::Set(counter);
00331 AsyncOutputCompareRegister::Set(outputCompare);
00332 AsyncControlRegister::Set(control);
00333
00334 WaitUntilSafeForSleepMode();
00335
00336 InterruptFlagBits::Clear();
00337 InterruptEnableBits::Change(interruptEnableBits);
00338
00339 }
00340
00341 };
00342
00343
00344 template <
00345 class CounterRegister,
00346 class OutputCompareRegister,
00347 class ControlRegister,
00348 class AsyncStatusRegister,
00349 class InterruptEnableBits,
00350 class InterruptFlagBits,
00351 class ChannelOutputPin >
00352
00353 struct OneChannel8BitTimerWithAsynchronousOperation
00354 {
00355 typedef OneChannel8BitTimer <
00356 CounterRegister,
00357 OutputCompareRegister,
00358 ControlRegister,
00359 ClockA,
00360 ChannelOutputPin > Synchronous;
00361
00362 typedef AsyncOneChannel8BitTimer <
00363 CounterRegister,
00364 OutputCompareRegister,
00365 ControlRegister,
00366 AsyncStatusRegister,
00367 InterruptEnableBits,
00368 InterruptFlagBits,
00369 ChannelOutputPin > Asynchronous;
00370
00371 };
00372
00373
00374 template <
00375 class CounterRegister,
00376 class OutputCompareRegisterA,
00377 class OutputCompareRegisterB,
00378 class ControlRegisterA,
00379 class ControlRegisterB,
00380 class ClockEnum,
00381 class ChannelAOutputPin,
00382 class ChannelBOutputPin >
00383
00384 struct TwoChannel8BitTimer : SimpleTimer<CounterRegister, ControlRegisterB, ClockEnum>
00385 {
00386 typedef OutputCompareRegisterA OutputCompareA;
00387 typedef OutputCompareRegisterB OutputCompareB;
00388
00389 typedef ChannelAOutputPin ChannelAPin;
00390 typedef ChannelBOutputPin ChannelBPin;
00391
00392 static inline void ForceOutputCompareA() { SetBits<ControlRegisterB>(ForceA); }
00393 static inline void ForceOutputCompareB() { SetBits<ControlRegisterB>(ForceB); }
00394
00395 static inline void SetUp (
00396 ClockEnum clock,
00397 FixedTop8 fixedTop8,
00398 CompareOutputModeA compareOutputModeA,
00399 CompareOutputModeB compareOutputModeB )
00400 {
00401 ControlRegisterA::Set(compareOutputModeA | compareOutputModeB | (fixedTop8 & TopMaskA8) );
00402 ControlRegisterB::Set(clock | (fixedTop8 & TopMaskB8) );
00403
00404 }
00405
00406 static inline void SetUp (
00407 ClockEnum clock,
00408 TopFromOutputCompareA8 topFromOutputCompareA8,
00409 CompareOutputModeB compareOutputModeB )
00410 {
00411 ControlRegisterA::Set(compareOutputModeB | (topFromOutputCompareA8 & TopMaskA8) );
00412 ControlRegisterB::Set(clock | (topFromOutputCompareA8 & TopMaskB8) );
00413
00414 }
00415
00416 };
00417
00418
00419 template <
00420 class CounterRegister,
00421 class OutputCompareRegisterA,
00422 class OutputCompareRegisterB,
00423 class ControlRegisterA,
00424 class ControlRegisterB,
00425 class InterruptMaskRegister,
00426 class InterruptFlagRegister,
00427 class AsyncStatusRegister,
00428 class ChannelAOutputPin,
00429 class ChannelBOutputPin >
00430
00431 class AsyncTwoChannel8BitTimer : TwoChannel8BitTimer <
00432 AsyncRegister<CounterRegister, Bits<AsyncStatusRegister, CounterUpdateFlagB> >,
00433 AsyncRegister<OutputCompareRegisterA, Bits<AsyncStatusRegister, OutputCompareAUpdateFlagB> >,
00434 AsyncRegister<OutputCompareRegisterB, Bits<AsyncStatusRegister, OutputCompareBUpdateFlagB> >,
00435 AsyncRegister<ControlRegisterA, Bits<AsyncStatusRegister, ControlAUpdateFlagB> >,
00436 AsyncRegister<ControlRegisterB, Bits<AsyncStatusRegister, ControlBUpdateFlagB> >,
00437 ClockA,
00438 ChannelAOutputPin,
00439 ChannelBOutputPin >
00440 {
00441
00442 private:
00443
00444 typedef Bits<AsyncStatusRegister, ExternalClockEnableFlagB> ExternalClockEnableBit;
00445 typedef Bits<AsyncStatusRegister, AsynchronousFlagB> AsynchronousBit;
00446 typedef Bits<AsyncStatusRegister, CounterUpdateFlagB> CounterUpdateBit;
00447 typedef Bits<AsyncStatusRegister, OutputCompareAUpdateFlagB> OutputCompareAUpdateBit;
00448 typedef Bits<AsyncStatusRegister, OutputCompareBUpdateFlagB> OutputCompareBUpdateBit;
00449 typedef Bits<AsyncStatusRegister, ControlAUpdateFlagB> ControlAUpdateBit;
00450 typedef Bits<AsyncStatusRegister, ControlBUpdateFlagB> ControlBUpdateBit;
00451
00452 typedef AsyncRegister<CounterRegister, CounterUpdateBit> AsyncCounterRegister;
00453 typedef AsyncRegister<OutputCompareRegisterA, OutputCompareAUpdateBit> AsyncOutputCompareRegisterA;
00454 typedef AsyncRegister<OutputCompareRegisterB, OutputCompareBUpdateBit> AsyncOutputCompareRegisterB;
00455 typedef AsyncRegister<ControlRegisterA, ControlAUpdateBit> AsyncControlRegisterA;
00456 typedef AsyncRegister<ControlRegisterB, ControlBUpdateBit> AsyncControlRegisterB;
00457
00458 public:
00459
00460 static inline void EnableExternalClock() { ExternalClockEnableBit::Set(); }
00461 static inline void DisableExternalClock() { ExternalClockEnableBit::Clear(); }
00462 static inline bool IsExternalClockEnabled() { return ExternalClockEnableBit::IsSet(); }
00463
00464 static inline bool IsSafeForSleepMode()
00465 {
00466 return !(CounterUpdateBit::IsSet()
00467 || OutputCompareAUpdateBit::IsSet()
00468 || OutputCompareBUpdateBit::IsSet()
00469 || ControlAUpdateBit::IsSet()
00470 || ControlBUpdateBit::IsSet() );
00471
00472 }
00473
00474 static inline void WaitUntilSafeForSleepMode() { while (!IsSafeForSleepMode() ); }
00475
00476 static void WaitMinimumTimeForReEnteringSleepMode()
00477 {
00478 AsyncControlRegisterA::Set(ControlRegisterA::Get() );
00479 WaitUntilSafeForSleepMode();
00480
00481 }
00482
00483 static inline uint8_t GetSafeCounterValue()
00484 {
00485 WaitMinimumTimeForReEnteringSleepMode();
00486
00487 return CounterRegister::Get();
00488
00489 }
00490
00491 static void AsynchronousOperation(bool enable)
00492 {
00493 uint8_t counter = CounterRegister::Get();
00494 uint8_t outputCompareA = OutputCompareRegisterA::Get();
00495 uint8_t outputCompareB = OutputCompareRegisterB::Get();
00496 uint8_t controlA = ControlRegisterA::Get();
00497 uint8_t controlB = ControlRegisterB::Get();
00498 uint8_t interruptMask = InterruptMaskRegister::Get();
00499
00500 InterruptMaskRegister::Set(0);
00501
00502 AsynchronousBit::SetTo(enable);
00503
00504 AsyncCounterRegister::Set(counter);
00505 AsyncOutputCompareRegisterA::Set(outputCompareA);
00506 AsyncOutputCompareRegisterB::Set(outputCompareB);
00507 AsyncControlRegisterA::Set(controlA);
00508 AsyncControlRegisterB::Set(controlB);
00509
00510 WaitUntilSafeForSleepMode();
00511
00512 InterruptFlagRegister::Set(0);
00513 InterruptMaskRegister::Set(interruptMask);
00514
00515 }
00516
00517 };
00518
00519
00520 template <
00521 class CounterRegister,
00522 class OutputCompareRegisterA,
00523 class OutputCompareRegisterB,
00524 class ControlRegisterA,
00525 class ControlRegisterB,
00526 class InterruptMaskRegister,
00527 class InterruptFlagRegister,
00528 class AsyncStatusRegister,
00529 class ChannelAOutputPin,
00530 class ChannelBOutputPin >
00531
00532 struct TwoChannel8BitTimerWithAsynchronousOperation
00533 {
00534 typedef TwoChannel8BitTimer <
00535 CounterRegister,
00536 OutputCompareRegisterA,
00537 OutputCompareRegisterB,
00538 ControlRegisterA,
00539 ControlRegisterB,
00540 ClockA,
00541 ChannelAOutputPin,
00542 ChannelBOutputPin > Synchronous;
00543
00544 typedef AsyncTwoChannel8BitTimer <
00545 CounterRegister,
00546 OutputCompareRegisterA,
00547 OutputCompareRegisterB,
00548 ControlRegisterA,
00549 ControlRegisterB,
00550 InterruptMaskRegister,
00551 InterruptFlagRegister,
00552 AsyncStatusRegister,
00553 ChannelAOutputPin,
00554 ChannelBOutputPin > Asynchronous;
00555
00556 };
00557
00558
00559 template <
00560 class CounterRegister,
00561 class OutputCompareRegisterA,
00562 class OutputCompareRegisterB,
00563 class InputCaptureRegister,
00564 class ControlRegisterA,
00565 class ControlRegisterB,
00566 class ClockEnum,
00567 class ChannelAOutputPin,
00568 class ChannelBOutputPin,
00569 class InputCaptureInputPin >
00570
00571 struct TwoChannel16BitTimerBase : SimpleTimer<CounterRegister, ControlRegisterB, ClockEnum>
00572 {
00573 typedef OutputCompareRegisterA OutputCompareA;
00574 typedef OutputCompareRegisterB OutputCompareB;
00575 typedef InputCaptureRegister InputCapture;
00576
00577 typedef ChannelAOutputPin ChannelAPin;
00578 typedef ChannelBOutputPin ChannelBPin;
00579 typedef InputCaptureInputPin InputCapturePin;
00580
00581 static inline void SetUp (
00582 ClockEnum clock,
00583 FixedTop16 fixedTop16,
00584 CompareOutputModeA compareOutputModeA,
00585 CompareOutputModeB compareOutputModeB,
00586 InputNoiseCanceler inputNoiseCanceler,
00587 InputCaptureEdge inputCaptureEdge )
00588 {
00589 ControlRegisterA::Set(compareOutputModeA | compareOutputModeB | (fixedTop16 & TopMaskA16) );
00590 ControlRegisterB::Set(inputNoiseCanceler | inputCaptureEdge | clock | (fixedTop16 & TopMaskB16) );
00591
00592 }
00593
00594 static inline void SetUp (
00595 ClockEnum clock,
00596 TopFromInputCapture16 topFromInputCapture16,
00597 CompareOutputModeA compareOutputModeA,
00598 CompareOutputModeB compareOutputModeB )
00599 {
00600 ControlRegisterA::Set(compareOutputModeA | compareOutputModeB | (topFromInputCapture16 & TopMaskA16) );
00601 ControlRegisterB::Set(clock | (topFromInputCapture16 & TopMaskB16) );
00602
00603 }
00604
00605 static inline void SetUp (
00606 ClockEnum clock,
00607 TopFromOutputCompareA16 topFromOutputCompareA16,
00608 CompareOutputModeB compareOutputModeB,
00609 InputNoiseCanceler inputNoiseCanceler,
00610 InputCaptureEdge inputCaptureEdge )
00611 {
00612 ControlRegisterA::Set(compareOutputModeB | (topFromOutputCompareA16 & TopMaskA16) );
00613 ControlRegisterB::Set(inputNoiseCanceler | inputCaptureEdge | clock | (topFromOutputCompareA16 & TopMaskB16) );
00614
00615 }
00616
00617 };
00618
00619
00620 template <
00621 class CounterRegister,
00622 class OutputCompareRegisterA,
00623 class OutputCompareRegisterB,
00624 class InputCaptureRegister,
00625 class ControlRegisterA,
00626 class ControlRegisterB,
00627 class ClockEnum,
00628 class ChannelAOutputPin,
00629 class ChannelBOutputPin,
00630 class InputCaptureInputPin >
00631
00632 struct OldTwoChannel16BitTimer : TwoChannel16BitTimerBase < CounterRegister,
00633 OutputCompareRegisterA,
00634 OutputCompareRegisterB,
00635 InputCaptureRegister,
00636 ControlRegisterA,
00637 ControlRegisterB,
00638 ClockEnum,
00639 ChannelAOutputPin,
00640 ChannelBOutputPin,
00641 InputCaptureInputPin >
00642 {
00643 static inline void ForceOutputCompareA() { SetBits<ControlRegisterA>(OldForceA); }
00644 static inline void ForceOutputCompareB() { SetBits<ControlRegisterA>(OldForceB); }
00645
00646 };
00647
00648
00649 template <
00650 class CounterRegister,
00651 class OutputCompareRegisterA,
00652 class OutputCompareRegisterB,
00653 class InputCaptureRegister,
00654 class ControlRegisterA,
00655 class ControlRegisterB,
00656 class ControlRegisterC,
00657 class ClockEnum,
00658 class ChannelAOutputPin,
00659 class ChannelBOutputPin,
00660 class InputCaptureInputPin >
00661
00662 struct NewTwoChannel16BitTimer : TwoChannel16BitTimerBase < CounterRegister,
00663 OutputCompareRegisterA,
00664 OutputCompareRegisterB,
00665 InputCaptureRegister,
00666 ControlRegisterA,
00667 ControlRegisterB,
00668 ClockEnum,
00669 ChannelAOutputPin,
00670 ChannelBOutputPin,
00671 InputCaptureInputPin >
00672 {
00673 static inline void ForceOutputCompareA() { SetBits<ControlRegisterC>(ForceA); }
00674 static inline void ForceOutputCompareB() { SetBits<ControlRegisterC>(ForceB); }
00675
00676 };
00677
00678
00679 template <
00680 class CounterRegister,
00681 class OutputCompareRegisterA,
00682 class OutputCompareRegisterB,
00683 class OutputCompareRegisterC,
00684 class InputCaptureRegister,
00685 class ControlRegisterA,
00686 class ControlRegisterB,
00687 class ControlRegisterC,
00688 class ClockEnum,
00689 class ChannelAOutputPin,
00690 class ChannelBOutputPin,
00691 class ChannelCOutputPin,
00692 class InputCaptureInputPin >
00693
00694 struct ThreeChannel16BitTimer : SimpleTimer<CounterRegister, ControlRegisterB, ClockEnum>
00695 {
00696 typedef OutputCompareRegisterA OutputCompareA;
00697 typedef OutputCompareRegisterB OutputCompareB;
00698 typedef OutputCompareRegisterC OutputCompareC;
00699 typedef InputCaptureRegister InputCapture;
00700
00701 typedef ChannelAOutputPin ChannelAPin;
00702 typedef ChannelBOutputPin ChannelBPin;
00703 typedef ChannelCOutputPin ChannelCPin;
00704 typedef InputCaptureInputPin InputCapturePin;
00705
00706 static inline void ForceOutputCompareA() { SetBits<ControlRegisterC>(ForceA); }
00707 static inline void ForceOutputCompareB() { SetBits<ControlRegisterC>(ForceB); }
00708 static inline void ForceOutputCompareC() { SetBits<ControlRegisterC>(ForceC); }
00709
00710 static inline void SetUp (
00711 ClockEnum clock,
00712 FixedTop16 fixedTop16,
00713 CompareOutputModeA compareOutputModeA,
00714 CompareOutputModeB compareOutputModeB,
00715 CompareOutputModeC compareOutputModeC,
00716 InputNoiseCanceler inputNoiseCanceler,
00717 InputCaptureEdge inputCaptureEdge )
00718 {
00719 ControlRegisterA::Set(compareOutputModeA | compareOutputModeB | compareOutputModeC | (fixedTop16 & TopMaskA16) );
00720 ControlRegisterB::Set(inputNoiseCanceler | inputCaptureEdge | clock | (fixedTop16 & TopMaskB16) );
00721
00722 }
00723
00724 static inline void SetUp (
00725 ClockEnum clock,
00726 TopFromInputCapture16 topFromInputCapture16,
00727 CompareOutputModeA compareOutputModeA,
00728 CompareOutputModeB compareOutputModeB,
00729 CompareOutputModeC compareOutputModeC )
00730 {
00731 ControlRegisterA::Set(compareOutputModeA | compareOutputModeB | compareOutputModeC | (topFromInputCapture16 & TopMaskA16) );
00732 ControlRegisterB::Set(clock | (topFromInputCapture16 & TopMaskB16) );
00733
00734 }
00735
00736 static inline void SetUp (
00737 ClockEnum clock,
00738 TopFromOutputCompareA16 topFromOutputCompareA16,
00739 CompareOutputModeB compareOutputModeB,
00740 CompareOutputModeC compareOutputModeC,
00741 InputNoiseCanceler inputNoiseCanceler,
00742 InputCaptureEdge inputCaptureEdge )
00743 {
00744 ControlRegisterA::Set(compareOutputModeB | compareOutputModeC | (topFromOutputCompareA16 & TopMaskA16) );
00745 ControlRegisterB::Set(inputNoiseCanceler | inputCaptureEdge | clock | (topFromOutputCompareA16 & TopMaskB16) );
00746
00747 }
00748
00749 };
00750
00751 }
00752
00753 }
00754
00755 }
00756
00757
00758 #if defined(__AVR_AT90USB1287__)
00759 #include "at90usb1287/Timer.h"
00760 #elif defined(__AVR_ATmega128__)
00761 #include "atmega128/Timer.h"
00762 #elif defined(__AVR_ATmega64__)
00763 #include "atmega64/Timer.h"
00764 #elif defined(__AVR_ATmega8__)
00765 #include "atmega8/Timer.h"
00766 #elif defined(__AVR_ATmega8515__)
00767 #include "atmega8515/Timer.h"
00768 #elif defined(__AVR_ATmega88__)
00769 #include "atmega88/Timer.h"
00770 #elif defined(__AVR_ATmega48__)
00771 #include "atmega48/Timer.h"
00772 #elif defined(__AVR_ATmega168__)
00773 #include "atmega168/Timer.h"
00774 #elif defined(__AVR_ATmega164P__)
00775 #include "atmega164p/Timer.h"
00776 #elif defined(__AVR_ATmega324P__)
00777 #include "atmega324p/Timer.h"
00778 #elif defined(__AVR_ATmega644P__)
00779 #include "atmega644p/Timer.h"
00780 #elif defined(__AVR_ATmega644__)
00781 #include "atmega644/Timer.h"
00782 #else
00783 #error "Device is not selected or selected device is not supported."
00784 #endif
00785
00786 #endif // ifndef __AVR_CPP_TIMER_H__