MHVLib
20111011
An efficiency oriented runtime library for AVR microcontrollers
|
00001 /* 00002 * Copyright (c) 2011, Make, Hack, Void Inc 00003 * All rights reserved. 00004 * 00005 * Redistribution and use in source and binary forms, with or without 00006 * modification, are permitted provided that the following conditions are met: 00007 * * Redistributions of source code must retain the above copyright 00008 * notice, this list of conditions and the following disclaimer. 00009 * * Redistributions in binary form must reproduce the above copyright 00010 * notice, this list of conditions and the following disclaimer in the 00011 * documentation and/or other materials provided with the distribution. 00012 * * Neither the name of the Make, Hack, Void nor the 00013 * names of its contributors may be used to endorse or promote products 00014 * derived from this software without specific prior written permission. 00015 * 00016 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 00017 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00018 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00019 * DISCLAIMED. IN NO EVENT SHALL MAKE, HACK, VOID BE LIABLE FOR ANY 00020 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00021 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00022 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00023 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00024 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00025 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00026 */ 00027 00028 00029 #ifndef MHV_TIMER16_H_ 00030 #define MHV_TIMER16_H_ 00031 00032 #include <MHV_Timer8.h> 00033 00034 #ifdef MHV_TIMER16_1 00035 00036 00037 #define MHV_TIMER_ASSIGN_3INTERRUPTS(mhvTimer, mhvTimerVectors) \ 00038 _MHV_TIMER_ASSIGN_3INTERRUPTS(mhvTimer, mhvTimerVectors) 00039 #define _MHV_TIMER_ASSIGN_3INTERRUPTS(mhvTimer, mhvTimerVect1, mhvTimerVect2, mhvTimerVect3) \ 00040 ISR(mhvTimerVect1) { \ 00041 mhvTimer.trigger1(); \ 00042 } \ 00043 ISR(mhvTimerVect2) { \ 00044 mhvTimer.trigger2(); \ 00045 } \ 00046 ISR(mhvTimerVect3) { \ 00047 mhvTimer.trigger3(); \ 00048 } 00049 00050 class MHV_Timer16 : public MHV_Timer8 { 00051 protected: 00052 volatile uint8_t *_controlRegC; 00053 volatile uint16_t *_outputCompare1; 00054 volatile uint16_t *_outputCompare2; 00055 volatile uint16_t *_outputCompare3; 00056 volatile uint16_t *_counter; 00057 bool _haveTime3; 00058 volatile uint16_t *_inputCapture1; 00059 00060 void (*_triggerFunction3)(void *data); 00061 void *_triggerData3; 00062 00063 void setGenerationMode(); 00064 00065 public: 00066 MHV_Timer16(volatile uint8_t *controlRegA, volatile uint8_t *controlRegB, volatile uint8_t *controlRegC, 00067 volatile uint16_t *outputCompare1, volatile uint16_t *outputCompare2, volatile uint16_t *outputCompare3, 00068 volatile uint16_t *counter, volatile uint8_t *interrupt, volatile uint16_t *inputCapture1); 00069 void setPeriods(uint32_t usec1, uint32_t usec2, uint32_t usec3); 00070 void setPeriods(MHV_TIMER_PRESCALER prescaler, uint16_t time1, uint16_t time2, uint16_t time3); 00071 uint16_t getTop(); 00072 void setTop(uint16_t value); 00073 void setOutput(uint8_t channel, uint16_t value); 00074 void setOutput1(uint16_t value); 00075 void setOutput2(uint16_t value); 00076 void setOutput3(uint16_t value); 00077 uint16_t getOutput(uint8_t channel); 00078 uint16_t getOutput1(); 00079 uint16_t getOutput2(); 00080 uint16_t getOutput3(); 00081 void connectOutput(uint8_t channel, MHV_TIMER_CONNECT_TYPE type); 00082 void connectOutput1(MHV_TIMER_CONNECT_TYPE type); 00083 void connectOutput2(MHV_TIMER_CONNECT_TYPE type); 00084 void connectOutput3(MHV_TIMER_CONNECT_TYPE type); 00085 void enable(); 00086 void disable(); 00087 void trigger3(); 00088 void setTriggers(void (*triggerFunction1)(void *triggerData), void *triggerData1, 00089 void (*triggerFunction2)(void *triggerData), void *triggerData2, 00090 void (*triggerFunction3)(void *triggerData), void *triggerData3); 00091 uint16_t current(); 00092 }; 00093 00094 #endif // MHV_TIMER16_1 00095 00096 #endif /* MHV_TIMER16_H_ */