\section{aversive\_\-10-03-12/modules/hardware/timer/timer\_\-definitions.h File Reference}
\label{timer__definitions_8h}\index{aversive\_\-10-03-12/modules/hardware/timer/timer\_\-definitions.h@{aversive\_\-10-03-12/modules/hardware/timer/timer\_\-definitions.h}}
{\tt \#include $<$aversive/parts.h$>$}\par
\subsection*{Defines}
\begin{CompactItemize}
\item 
\#define {\bf DEFINE\_\-TIMER\_\-START\_\-STOP}(x)
\item 
\#define {\bf DEFINE\_\-TIMER\_\-GET\_\-SET}(x)
\item 
\#define {\bf DEFINE\_\-OV\_\-INTR}(x)
\item 
\#define {\bf DEFINE\_\-OC\_\-INTR}(x)
\item 
\#define {\bf DEFINE\_\-REGISTER\_\-OV\_\-INTR}(x)
\item 
\#define {\bf DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS}(x)
\item 
\#define {\bf DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US}(x, y)
\item 
\#define {\bf DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS}(x)
\item 
\#define {\bf DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS}(x)
\item 
\#define {\bf DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS}(x)
\end{CompactItemize}


\subsection{Define Documentation}
\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS@{DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS}}
\index{DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS@{DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-DYNAMIC\_\-PRESCALER\_\-FUNCS(x)}\label{timer__definitions_8h_09001827bc5fd4e63c3e94e993baaf5a}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
int16_t timer##x##_div_to_reg(uint16_t div)                         \
{                                                                   \
        return __timer##x##_div_to_reg(div);                        \
}                                                                   \
                                                                    \
int16_t timer##x##_reg_to_div(uint8_t reg)                          \
{                                                                   \
        return __timer##x##_reg_to_div(reg);                        \
}                                                                   \
                                                                    \
uint16_t timer##x##_get_prescaler_div(void)                         \
{                                                                   \
        return __timer##x##_reg_to_div(CS##x##0_REG >> CS##x##0);   \
}                                                                   \
                                                                    \
void timer##x##_set_prescaler_div(uint16_t div)                     \
{                                                                   \
        CS##x##0_REG = __timer##x##_div_to_reg(div) << CS##x##0 ;   \
}
\end{verbatim}
\end{Code}


Definition at line 141 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-OC\_\-INTR@{DEFINE\_\-OC\_\-INTR}}
\index{DEFINE\_\-OC\_\-INTR@{DEFINE\_\-OC\_\-INTR}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-OC\_\-INTR]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-OC\_\-INTR(x)}\label{timer__definitions_8h_a80acdc1164695c3a3d8005442b564ff}


\textbf{Value:}

\begin{Code}\begin{verbatim}SIGNAL(x)                                               \
{                                                       \
        if(timer_OC_callback_table[x##_NUM])            \
                timer_OC_callback_table[x##_NUM]();     \
}
\end{verbatim}
\end{Code}


Definition at line 67 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-OV\_\-INTR@{DEFINE\_\-OV\_\-INTR}}
\index{DEFINE\_\-OV\_\-INTR@{DEFINE\_\-OV\_\-INTR}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-OV\_\-INTR]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-OV\_\-INTR(x)}\label{timer__definitions_8h_6496fd92130668b62dc317989dabc7c9}


\textbf{Value:}

\begin{Code}\begin{verbatim}SIGNAL(x)                                               \
{                                                       \
        if(timer_OV_callback_table[x##_NUM])            \
                timer_OV_callback_table[x##_NUM]();     \
}
\end{verbatim}
\end{Code}


Definition at line 59 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS@{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS}}
\index{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS@{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-AT\_\-TICS(x)}\label{timer__definitions_8h_65741984b62566b70f5b91d937de59b5}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
void timer##x##_register_OC_intr_at_tics(void (*func)(void), uint16_t t)        \
{                                                                               \
        uint8_t flags;                                                          \
                                                                                \
        IRQ_LOCK(flags);                                                        \
        timer_OC_callback_table[SIG_OUTPUT_COMPARE##x##_NUM] = func;            \
        if (func) {                                                             \
                OCIE##x##_REG |= (1<<OCIE##x);                                  \
                OCR##x = t;                                                     \
        }                                                                       \
        else {                                                                  \
                OCIE##x##_REG &= (uint8_t)(~(1<<OCIE##x));                      \
        }                                                                       \
        IRQ_UNLOCK(flags);                                                      \
}
\end{verbatim}
\end{Code}


Definition at line 93 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US@{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US}}
\index{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US@{DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-REGISTER\_\-OC\_\-INTR\_\-IN\_\-US(x, \/  y)}\label{timer__definitions_8h_5b46e317bb3cf4a84aafb528d67fe87f}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
int8_t timer##y##_register_OC_intr_in_us(void (*func)(void), uint16_t t)        \
{                                                                               \
        uint8_t flags;                                                          \
        float tics;                                                             \
                                                                                \
        IRQ_LOCK(flags);                                                        \
        if (! func) {                                                           \
                timer_OC_callback_table[SIG_OUTPUT_COMPARE##y##_NUM] = func;    \
                OCIE##y##_REG &= (uint8_t)(~(1<<OCIE##y));                      \
                IRQ_UNLOCK(flags);                                              \
                return 0;                                                       \
        }                                                                       \
                                                                                \
        tics = timer##x##_us_to_tics(t);                                        \
        if ( tics > 0xFFFF ) {  /* XXX use MAX_TIMER */                         \
                IRQ_UNLOCK(flags);                                              \
                return -1;                                                      \
        }                                                                       \
                                                                                \
        OCR##y = TCNT##x + tics;                                                \
        timer_OC_callback_table[SIG_OUTPUT_COMPARE##y##_NUM] = func;            \
        OCIE##y##_REG |= (1<<OCIE##y);                                          \
        IRQ_UNLOCK(flags);                                                      \
        return 0;                                                               \
}
\end{verbatim}
\end{Code}


Definition at line 112 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-REGISTER\_\-OV\_\-INTR@{DEFINE\_\-REGISTER\_\-OV\_\-INTR}}
\index{DEFINE\_\-REGISTER\_\-OV\_\-INTR@{DEFINE\_\-REGISTER\_\-OV\_\-INTR}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-REGISTER\_\-OV\_\-INTR]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-REGISTER\_\-OV\_\-INTR(x)}\label{timer__definitions_8h_893f57eb9c18672243113ccde74cadc9}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
void timer##x##_register_OV_intr(void (*func)(void))                \
{                                                                   \
        uint8_t flags;                                              \
                                                                    \
        IRQ_LOCK(flags);                                            \
        timer_OV_callback_table[SIG_OVERFLOW##x##_NUM] = func;      \
        if (func) {                                                 \
                TOIE##x##_REG |= (1<<TOIE##x);                      \
        }                                                           \
        else {                                                      \
                TOIE##x##_REG &= (uint8_t)(~(1<<TOIE##x));          \
        }                                                           \
        IRQ_UNLOCK(flags);                                          \
}
\end{verbatim}
\end{Code}


Definition at line 75 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS@{DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS}}
\index{DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS@{DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-STATIC\_\-PRESCALER\_\-FUNCS(x)}\label{timer__definitions_8h_e07ae6ac081e0a39162aea25179b6960}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
int16_t timer##x##_div_to_reg(uint16_t div)                         \
{                                                                   \
        return __timer##x##_div_to_reg(TIMER##x##_PRESCALER_DIV);   \
}                                                                   \
                                                                    \
uint16_t timer##x##_get_prescaler_div(void)                         \
{                                                                   \
        return TIMER##x##_PRESCALER_DIV;                            \
}
\end{verbatim}
\end{Code}


Definition at line 164 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-TIMER\_\-GET\_\-SET@{DEFINE\_\-TIMER\_\-GET\_\-SET}}
\index{DEFINE\_\-TIMER\_\-GET\_\-SET@{DEFINE\_\-TIMER\_\-GET\_\-SET}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-TIMER\_\-GET\_\-SET]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-TIMER\_\-GET\_\-SET(x)}\label{timer__definitions_8h_773db332b9b088bc0c1b1b88aef415d4}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
uint16_t timer##x##_get(void)                                                            \
{                                                                                        \
        return TCNT##x ;                                                                 \
}                                                                                        \
                                                                                         \
void timer##x##_set(uint16_t t)                                                          \
{                                                                                        \
        TCNT##x = t;                                                                     \
}
\end{verbatim}
\end{Code}


Definition at line 46 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-TIMER\_\-START\_\-STOP@{DEFINE\_\-TIMER\_\-START\_\-STOP}}
\index{DEFINE\_\-TIMER\_\-START\_\-STOP@{DEFINE\_\-TIMER\_\-START\_\-STOP}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-TIMER\_\-START\_\-STOP]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-TIMER\_\-START\_\-STOP(x)}\label{timer__definitions_8h_181991fd959da43ffd54f5291475b43f}


\textbf{Value:}

\begin{Code}\begin{verbatim}\                                                                        \
void timer##x##_start(void)                                                              \
{                                                                                        \
        TCNT##x = 0;                                                                     \
        CS##x##0_REG = __timer##x##_div_to_reg(TIMER##x##_PRESCALER_DIV) << CS##x##0 ;   \
}                                                                                        \
                                                                                         \                                                                       \
void timer##x##_stop(void)                                                               \
{                                                                                        \
        CS##x##0_REG = 0;                                                                \
        TCNT##x = 0;                                                                     \
}
\end{verbatim}
\end{Code}


Definition at line 28 of file timer\_\-definitions.h.\index{timer\_\-definitions.h@{timer\_\-definitions.h}!DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS@{DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS}}
\index{DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS@{DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS}!timer_definitions.h@{timer\_\-definitions.h}}
\subsubsection[DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS]{\setlength{\rightskip}{0pt plus 5cm}\#define DEFINE\_\-TIMER\_\-US\_\-CONVERSIONS(x)}\label{timer__definitions_8h_891423addd19324ea890b4d0f25425cd}


\textbf{Value:}

\begin{Code}\begin{verbatim}\
static inline float timer##x##_us_to_tics(float us)                      \
{                                                                        \
        return ((float)CONFIG_QUARTZ /                                   \
                ((float)MHz * timer##x##_get_prescaler_div()) ) * us;    \
}                                                                        \
                                                                         \
static inline float timer##x##_tics_to_us(float t)                       \
{                                                                        \
        return t / ((float)CONFIG_QUARTZ /                               \
                ((float)MHz * timer##x##_get_prescaler_div()) );         \
}
\end{verbatim}
\end{Code}


Definition at line 176 of file timer\_\-definitions.h.