]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/hw/timer/timer64/t64.c
Merge branch 'tmp-mike2'
[keystone-rtos/ibl.git] / src / hw / timer / timer64 / t64.c
1 /*
2  *
3  * Copyright (C) 2010 Texas Instruments Incorporated - http://www.ti.com/ 
4  * 
5  * 
6  *  Redistribution and use in source and binary forms, with or without 
7  *  modification, are permitted provided that the following conditions 
8  *  are met:
9  *
10  *    Redistributions of source code must retain the above copyright 
11  *    notice, this list of conditions and the following disclaimer.
12  *
13  *    Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the 
15  *    documentation and/or other materials provided with the   
16  *    distribution.
17  *
18  *    Neither the name of Texas Instruments Incorporated nor the names of
19  *    its contributors may be used to endorse or promote products derived
20  *    from this software without specific prior written permission.
21  *
22  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 
23  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 
24  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
25  *  A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 
26  *  OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 
27  *  SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 
28  *  LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  *  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  *  THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 
31  *  (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
32  *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34 */
38 /*************************************************************************
39  * FILE PURPOSE: Timer64 configuration
40  *************************************************************************
41  * FILE NAME: t64.c
42  *
43  * DESCRIPTION: The low level timer 64 driver
44  *
45  * @file t64.c
46  *
47  * @brief
48  *  This file is used to control timer64s at the device level. Only timer 0
49  *  is supported, and only in single shot mode.
50  *
51  **************************************************************************/
52 #include "types.h"
53 #include "iblcfg.h"
54 #include "ibl.h"
55 #include "iblloc.h"
56 #include "devtimer.h"
57 #include "t64hw.h"
60 /**
61  * @brief
62  *  A global variable is used to track the timer enable/disable status
63  */
64 Int32 timer_created = 0;
67 /**
68  *  @b Description
69  *  @n
70  *
71  *  A timer is disabled
72  *
73  *  @retval
74  *      0 - Timer deleted
75  *     -1 - Timer was not active 
76  */
77 Int32 dev_delete_timer (void) 
78
79     Int32 retval;
80     
81     /* Go ahead and disable the timer, even if it is not tracked as active */
82     t64_tcr   = TIMER64_TCR_DISABLE;
83     t64_tgcr  = TIMER64_TGCR_DISABLE;
85     /* Set the counters to 0 */
86     t64_tim12 = 0;
87     t64_tim34 = 0;
89     /* Set the timer period to 0 */
90     t64_prd12 = 0;
91     t64_prd34 = 0;
93     if (timer_created == 0)
94         retval = -1;
95     else
96         retval = 0;
98     timer_created = 0;
100     return (retval);
104 /**
105  * @b  Description
106  * @n
107  * 
108  *  Starts the timer in one shot mode
109  */
110 void timer_go (void)
112     long long timdiv;
114     /* Remove reset, leave timer disabled */
115     t64_tgcr = TIMER64_TGCR_64;
117     /* Write the timer period. 
118      * The desired period is 100mus. One cycle is 1us per MHz of the device */
119     timdiv = (long long)ibl.pllConfig[ibl_MAIN_PLL].pllOutFreqMhz / TIMER_INPUT_DIVIDER;
120     timdiv = timdiv * 100 * 1000;
121     t64_prd34 = (timdiv >> 32);
122     t64_prd12 = (timdiv & 0xffffffff);
124     /* Start the timer in 1 shot mode */
125     t64_tcr = TIMER64_TCR_ONE_SHOT;
130 /**
131  *  @b Description
132  *  @n
133  *
134  *  A very simple hardware driver to configure the timer as a one shot 100ms timer.
135  *
136  *  @retval
137  *      0  - Timer setup
138  *     -1  - Timer setup failed, timer already enabled
139  *
140  */
141 Int32 dev_create_timer (void)
142
143     volatile Int32 i;
144     
145     if (timer_created != 0)
146         return (-1);
148     /* Close out the timer, just to be safe */
149     dev_delete_timer ();
151     /* Need some delay before reprogramming the timer */
152     for (i = 0; i < 500; i++);
155     timer_go();
157     timer_created = 1;
159     return (0);
164 /**
165  *  @b  Description
166  *  @n
167  *  
168  *   The status of the timer is returned
169  *
170  *  @retval
171  *     TRUE - The timer has expired
172  *     FALSE - The timer is active
173  *
174  */
175 Bool dev_check_timer (void)
176
177     volatile unsigned int i;
179     if (timer_created == 0)
180         return (FALSE);
182     if ((t64_tim12 != 0) || (t64_tim34 != 0))
183         return (FALSE);
185     /* The timer has expired. Restart the timer */
186     dev_delete_timer ();
188     /* Need some delay before reprogramming the timer */
189     for (i = 0; i < 500; i++);
191     timer_go ();
193     timer_created = 1;
195     return (TRUE);