]> Gitweb @ Texas Instruments - Open Source Git Repositories - git.TI.com/gitweb - keystone-rtos/ibl.git/blob - src/hw/timer/timer64/t64.c
Bug fix for automatic file format detection
[keystone-rtos/ibl.git] / src / hw / timer / timer64 / t64.c
1 /*************************************************************************
2  * FILE PURPOSE: Timer64 configuration
3  *************************************************************************
4  * FILE NAME: t64.c
5  *
6  * DESCRIPTION: The low level timer 64 driver
7  *
8  * @file t64.c
9  *
10  * @brief
11  *  This file is used to control timer64s at the device level. Only timer 0
12  *  is supported, and only in single shot mode.
13  *
14  **************************************************************************/
15 #include "types.h"
16 #include "iblcfg.h"
17 #include "ibl.h"
18 #include "iblloc.h"
19 #include "devtimer.h"
20 #include "t64hw.h"
23 /**
24  * @brief
25  *  A global variable is used to track the timer enable/disable status
26  */
27 Int32 timer_created = 0;
30 /**
31  *  @b Description
32  *  @n
33  *
34  *  A timer is disabled
35  *
36  *  @retval
37  *      0 - Timer deleted
38  *     -1 - Timer was not active 
39  */
40 Int32 dev_delete_timer (void) 
41
42     Int32 retval;
43     
44     /* Go ahead and disable the timer, even if it is not tracked as active */
45     t64_tcr   = TIMER64_TCR_DISABLE;
46     t64_tgcr  = TIMER64_TGCR_DISABLE;
48     /* Set the counters to 0 */
49     t64_tim12 = 0;
50     t64_tim34 = 0;
52     /* Set the timer period to 0 */
53     t64_prd12 = 0;
54     t64_prd34 = 0;
56     if (timer_created == 0)
57         retval = -1;
58     else
59         retval = 0;
61     timer_created = 0;
63     return (retval);
65 }
67 /**
68  * @b  Description
69  * @n
70  * 
71  *  Starts the timer in one shot mode
72  */
73 void timer_go (void)
74 {
75     long long timdiv;
77     /* Remove reset, leave timer disabled */
78     t64_tgcr = TIMER64_TGCR_64;
80     /* Write the timer period. 
81      * The desired period is 100mus. One cycle is 1us per MHz of the device */
82     timdiv = (long long)ibl.pllConfig[ibl_MAIN_PLL].pllOutFreqMhz / TIMER_INPUT_DIVIDER;
83     timdiv = timdiv * 100 * 1000;
84     t64_prd34 = (timdiv >> 32);
85     t64_prd12 = (timdiv & 0xffffffff);
87     /* Start the timer in 1 shot mode */
88     t64_tcr = TIMER64_TCR_ONE_SHOT;
90 }
93 /**
94  *  @b Description
95  *  @n
96  *
97  *  A very simple hardware driver to configure the timer as a one shot 100ms timer.
98  *
99  *  @retval
100  *      0  - Timer setup
101  *     -1  - Timer setup failed, timer already enabled
102  *
103  */
104 Int32 dev_create_timer (void)
105
106     volatile Int32 i;
107     
108     if (timer_created != 0)
109         return (-1);
111     /* Close out the timer, just to be safe */
112     dev_delete_timer ();
114     /* Need some delay before reprogramming the timer */
115     for (i = 0; i < 500; i++);
118     timer_go();
120     timer_created = 1;
122     return (0);
127 /**
128  *  @b  Description
129  *  @n
130  *  
131  *   The status of the timer is returned
132  *
133  *  @retval
134  *     TRUE - The timer has expired
135  *     FALSE - The timer is active
136  *
137  */
138 Bool dev_check_timer (void)
139
140     volatile unsigned int i;
142     if (timer_created == 0)
143         return (FALSE);
145     if ((t64_tim12 != 0) || (t64_tim34 != 0))
146         return (FALSE);
148     /* The timer has expired. Restart the timer */
149     dev_delete_timer ();
151     /* Need some delay before reprogramming the timer */
152     for (i = 0; i < 500; i++);
154     timer_go ();
156     timer_created = 1;
158     return (TRUE);