1/* @TAG(CUSTOM) *//**
2 *  \file   dmtimer.h
3 *
4 *  \brief  DMTimer API prototypes and macros.
5 *
6 *   This file contains the driver API prototypes and macro definitions.
7 */
8
9/*
10* Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/
11*/
12/*
13*  Redistribution and use in source and binary forms, with or without
14*  modification, are permitted provided that the following conditions
15*  are met:
16*
17*    Redistributions of source code must retain the above copyright
18*    notice, this list of conditions and the following disclaimer.
19*
20*    Redistributions in binary form must reproduce the above copyright
21*    notice, this list of conditions and the following disclaimer in the
22*    documentation and/or other materials provided with the
23*    distribution.
24*
25*    Neither the name of Texas Instruments Incorporated nor the names of
26*    its contributors may be used to endorse or promote products derived
27*    from this software without specific prior written permission.
28*
29*  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
30*  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
31*  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
32*  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
33*  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
34*  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
35*  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
36*  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
37*  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
38*  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39*  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40*
41*/
42
43#pragma once
44
45#include "hw/hw_dmtimer.h"
46#include "hw/hw_types.h"
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
52    /*****************************************************************************/
53    /*
54    ** Values that can be passed to DMTimerPreScalerClkEnable as ptv so as to derive
55    ** Pre-Scalar clock from timer clock.
56    */
57    /* Value used to divide timer clock by 2 */
58#define DMTIMER_PRESCALER_CLK_DIV_BY_2      ((0 << DMTIMER_TCLR_PTV_SHIFT) | \
59                                              DMTIMER_TCLR_PRE)
60
61    /* Value used to divide timer clock by 4 */
62#define DMTIMER_PRESCALER_CLK_DIV_BY_4	    ((BIT(DMTIMER_TCLR_PTV_SHIFT)) | \
63                                              DMTIMER_TCLR_PRE)
64
65    /* Value used to divide timer clock by 8 */
66#define DMTIMER_PRESCALER_CLK_DIV_BY_8	    ((2 << DMTIMER_TCLR_PTV_SHIFT) | \
67                                              DMTIMER_TCLR_PRE)
68
69    /* Value used to divide timer clock by 16 */
70#define DMTIMER_PRESCALER_CLK_DIV_BY_16	    ((3 << DMTIMER_TCLR_PTV_SHIFT) | \
71                                              DMTIMER_TCLR_PRE)
72
73    /* Value used to divide timer clock by 32 */
74#define DMTIMER_PRESCALER_CLK_DIV_BY_32	    ((4 << DMTIMER_TCLR_PTV_SHIFT) | \
75                                              DMTIMER_TCLR_PRE)
76
77    /* Value used to divide timer clock by 64 */
78#define DMTIMER_PRESCALER_CLK_DIV_BY_64	    ((5 << DMTIMER_TCLR_PTV_SHIFT) | \
79                                              DMTIMER_TCLR_PRE)
80
81    /* Value used to divide timer clock by 128 */
82#define DMTIMER_PRESCALER_CLK_DIV_BY_128    ((6 << DMTIMER_TCLR_PTV_SHIFT) | \
83                                              DMTIMER_TCLR_PRE)
84
85    /* Value used to divide timer clock by 256 */
86#define DMTIMER_PRESCALER_CLK_DIV_BY_256    ((7 << DMTIMER_TCLR_PTV_SHIFT) | \
87                                              DMTIMER_TCLR_PRE)
88
89    /******************************************************************************/
90    /*
91    ** Values that can be passed to DMTimerModeConfigure as timerMode.
92    */
93    /* Value used to enable the timer in one-shot and compare mode */
94#define DMTIMER_ONESHOT_CMP_ENABLE          (DMTIMER_TCLR_CE)
95
96    /* Value used to enable the timer only in one-shot mode */
97#define DMTIMER_ONESHOT_NOCMP_ENABLE        (0x0000000)
98
99    /* Value used to enable the timer in auto-reload and compare mode */
100#define DMTIMER_AUTORLD_CMP_ENABLE          (DMTIMER_TCLR_AR | DMTIMER_TCLR_CE)
101
102    /* Value used to enable the timer only in auto-reload mode */
103#define DMTIMER_AUTORLD_NOCMP_ENABLE        (DMTIMER_TCLR_AR)
104
105    /******************************************************************************/
106    /*
107    ** Values that can be passed to DMTimerGPOConfigure as gpoCfg.
108    */
109    /* Value used to drive 0 on PORGPOCFG pin */
110#define DMTIMER_GPO_CFG_0		    (DMTIMER_TCLR_GPO_CFG_DRIVE0)
111
112    /* Value used to drive 1 on PORGPOCFG pin */
113#define DMTIMER_GPO_CFG_1		    (DMTIMER_TCLR_GPO_CFG_DRIVE1 << \
114					     DMTIMER_TCLR_GPO_CFG_SHIFT)
115
116    /******************************************************************************/
117    /*
118    ** Values that can be passed to DMTimerIntStatusClear/DMTimerIntRawStatusSet/
119    ** as intFlags. Also these values can be used while checking the status got from
120    ** DMTimerIntRawStatusGet/DMTimerIntStatusGet.
121    ** Any combination is also followed.
122    ** Example- (DMTIMER_INT_TCAR_IT_FLAG | DMTIMER_INT_OVF_IT_FLAG)
123    */
124    /* Value used for capture event of DMTimer */
125#define DMTIMER_INT_TCAR_IT_FLAG             (DMTIMER_IRQSTATUS_RAW_TCAR_IT_FLAG)
126
127    /* Value used for overflow event of DMTimer */
128#define DMTIMER_INT_OVF_IT_FLAG              (DMTIMER_IRQSTATUS_RAW_OVF_IT_FLAG)
129
130    /* Value used for Match event of DMTimer */
131#define DMTIMER_INT_MAT_IT_FLAG              (DMTIMER_IRQSTATUS_RAW_MAT_IT_FLAG)
132
133    /******************************************************************************/
134    /*
135    ** Values that can be passed to DMTimerIntEnable/DMTimerIntDisable as intFlags.
136    ** Also these values can be used while checking the status got from
137    ** DMTimerIntEnableGet.
138    ** Any combination is also followed.
139    ** Example- (DMTIMER_INT_TCAR_EN_FLAG | DMTIMER_INT_OVF_EN_FLAG)
140    */
141    /* Value used for capture event of DMTimer */
142#define DMTIMER_INT_TCAR_EN_FLAG             (DMTIMER_IRQENABLE_SET_TCAR_EN_FLAG)
143
144    /* Value used for overflow event of DMTimer */
145#define DMTIMER_INT_OVF_EN_FLAG              (DMTIMER_IRQENABLE_SET_OVF_EN_FLAG)
146
147    /* Value used for Match event of DMTimer */
148#define DMTIMER_INT_MAT_EN_FLAG              (DMTIMER_IRQENABLE_SET_MAT_EN_FLAG)
149
150    /******************************************************************************/
151    /*
152    ** Values that can be passed to DMTimerResetConfigure as rstOption.
153    */
154    /* Value used to enable software reset for DMTimer */
155#define DMTIMER_SFT_RESET_ENABLE             (DMTIMER_TSICR_SFT_RESETENABLE)
156
157    /* Value used to disable software reset for DMTimer */
158#define DMTIMER_SFT_RESET_DISABLE            (DMTIMER_TSICR_SFT)
159
160    /******************************************************************************/
161    /*
162    ** Values that can be used while checking the status received from
163    ** DMTimerIsResetDone.
164    */
165    /* Value used to check whether reset is done */
166#define DMTIMER_IS_RESET_DONE                (DMTIMER_TIOCP_CFG_SOFTRESET_DONE)
167
168    /* Value used to check whether reset is ongoing */
169#define DMTIMER_IS_RESET_ONGOING             (DMTIMER_TIOCP_CFG_SOFTRESET_ONGOING)
170
171    /******************************************************************************/
172    /*
173    ** Structure to store the DM timer context
174    */
175    typedef struct dmtimerContext {
176        unsigned int tldr;
177        unsigned int tmar;
178        unsigned int irqenableset;
179        unsigned int tcrr;
180        unsigned int tclr;
181    } DMTIMERCONTEXT;
182
183    /*
184    ** Prototype of the APIs
185    */
186    extern void DMTimerEnable(unsigned int baseAdd);
187    extern void DMTimerDisable(unsigned int baseAdd);
188    extern void DMTimerModeConfigure(unsigned int baseAdd, unsigned int timerMode);
189    extern void DMTimerPreScalerClkEnable(unsigned int baseAdd, unsigned int ptv);
190    extern void DMTimerPreScalerClkDisable(unsigned int baseAdd);
191    extern void DMTimerCounterSet(unsigned int baseAdd, unsigned int counter);
192    extern unsigned int DMTimerCounterGet(unsigned int baseAdd);
193    extern void DMTimerReloadSet(unsigned int baseAdd, unsigned int reload);
194    extern unsigned int DMTimerReloadGet(unsigned int baseAdd);
195    extern void DMTimerGPOConfigure(unsigned int baseAdd, unsigned int gpoCfg);
196    extern void DMTimerCompareSet(unsigned int baseAdd, unsigned int compareVal);
197    extern unsigned int DMTimerCompareGet(unsigned int baseAdd);
198    extern void DMTimerEmulationModeConfigure(unsigned int baseAdd, unsigned int emuMode);
199    extern void DMTimerIntRawStatusSet(unsigned int baseAdd, unsigned int intFlags);
200    extern unsigned int DMTimerIntRawStatusGet(unsigned int baseAdd);
201    extern unsigned int DMTimerIntStatusGet(unsigned int baseAdd);
202    extern void DMTimerIntStatusClear(unsigned int baseAdd, unsigned int intFlags);
203    extern void DMTimerIntEnable(unsigned int baseAdd, unsigned int intFlags);
204    extern void DMTimerIntDisable(unsigned int baseAdd, unsigned int intFlags);
205    extern void DMTimerTriggerSet(unsigned int baseAdd);
206    extern unsigned int DMTimerIntEnableGet(unsigned int baseAdd);
207    extern void DMTimerResetConfigure(unsigned int baseAdd, unsigned int rstOption);
208    extern void DMTimerReset(unsigned int baseAdd);
209    extern void DMTimerContextSave(unsigned int baseAdd, DMTIMERCONTEXT *contextPtr);
210    extern void DMTimerContextRestore(unsigned int baseAdd, DMTIMERCONTEXT *contextPtr);
211
212#ifdef __cplusplus
213}
214#endif
215
216
217/******************************** END OF FILE *********************************/
218