Fri, 13 Aug 2010 10:49:23 +0100
Initial import, Timer v3.0
1 /****************************************************************************
2 **
3 ** Name: MicoTimer.h
4 **
5 ** Description:
6 ** Implements functions for manipulating LatticeMico32 Timer and
7 ** defines timer register map
8 **
9 ** $Revision: $
10 **
11 ** Disclaimer:
12 **
13 ** This source code is intended as a design reference which
14 ** illustrates how these types of functions can be implemented. It
15 ** is the user's responsibility to verify their design for
16 ** consistency and functionality through the use of formal
17 ** verification methods. Lattice Semiconductor provides no warranty
18 ** regarding the use or functionality of this code.
19 **
20 ** --------------------------------------------------------------------
21 **
22 ** Lattice Semiconductor Corporation
23 ** 5555 NE Moore Court
24 ** Hillsboro, OR 97214
25 ** U.S.A
26 **
27 ** TEL: 1-800-Lattice (USA and Canada)
28 ** (503)268-8001 (other locations)
29 **
30 ** web: http://www.latticesemi.com
31 ** email: techsupport@latticesemi.com
32 **
33 ** --------------------------------------------------------------------------
34 **
35 ** Change History (Latest changes on top)
36 **
37 ** Ver Date Description
38 ** --------------------------------------------------------------------------
39 **
40 ** 3.0 Mar-25-2008 Added Header
41 **
42 **---------------------------------------------------------------------------
43 *****************************************************************************/
45 #ifndef MICO32_MICOTIMER_HEADER_FILE
46 #define MICO32_MICOTIMER_HEADER_FILE
48 #include "MicoTypes.h"
49 #include "DDStructs.h"
51 /****************************************************************************
52 * Mico-timer driver provides the ability to use a Mico-32 timer in either *
53 * a single-shot mode or a periodic mode. *
54 *--------------------------------------------------------------------------*
55 * Mico Timers must be located in a non-cached region to use this driver *
56 ****************************************************************************/
59 #ifdef __cplusplus
60 extern "C"
61 {
62 #endif /* __cplusplus */
65 /******************************************************************************
66 * Data Structures: *
67 ******************************************************************************/
68 /* timer callback function type */
69 typedef void(*TimerCallback_t)(void *);
72 /* mico-timer register structure */
73 typedef struct st_MicoTimer{
74 volatile unsigned int Status;
75 volatile unsigned int Control;
76 volatile unsigned int Period;
77 volatile unsigned int Snapshot;
78 }MicoTimer_t;
81 /**************************************************************************
82 * MICO32 TIMER REGISTER DEFINITIONS *
83 * (NOTE: OFFSETS REPRESENT BYTES) *
84 **************************************************************************/
85 #define MICO32_TIMER_STATUS_REG_OFFSET (0x00)
86 #define MICO32_TIMER_CONTROL_REG_OFFSET (0x04)
87 #define MICO32_TIMER_PERIOD_REG_OFFSET (0x08)
88 #define MICO32_TIMER_SNAPSHOT_REG_OFFSET (0x0c)
91 /* status-register bits: */
92 #define MICO32_TIMER_STATUS_TO_BIT_MASK (0x1)
95 /* control-register bits */
96 #define MICO32_TIMER_CONTROL_INT_BIT_MASK (0x1)
97 #define MICO32_TIMER_CONTROL_CONT_BIT_MASK (0x2)
98 #define MICO32_TIMER_CONTROL_START_BIT_MASK (0x4)
99 #define MICO32_TIMER_CONTROL_STOP_BIT_MASK (0x8)
102 /******************************************************************************
103 * functions *
104 ******************************************************************************/
106 /* initializes Mico32 timer */
107 void MicoTimerInit( MicoTimerCtx_t *ctx );
110 /*
111 ******************************************************************************
112 * Starts a Mico32 timer *
113 *----------------------------------------------------------------------------*
114 * Inputs: *
115 * MicoTimerCtx_t *ctx: pointer to valid ctx *
116 * *
117 * TimerCallback_t callback: User-provided callback function, called *
118 * in interrupt-context. *
119 * typedef void(*TimerCallback_t)(void *) *
120 * *
121 * void *priv: user-provided data that will be called in the callback *
122 * *
123 * unsigned int timercount: ticks to load counter with *
124 * *
125 * int periodic: if 1, the timer is programmed to auto-load, else *
126 * timer is programmed not to reload on reaching terminal value *
127 * *
128 * Note: user MUST supply a valid ctx. *
129 * user MUST make sure timerCount is non-zero *
130 ******************************************************************************
131 */
132 mico_status MicoTimerStart( MicoTimerCtx_t *ctx, TimerCallback_t callback,
133 void *priv, unsigned int timerCount, int periodic );
136 /* stops a mico-32 timer */
137 mico_status MicoTimerStop(MicoTimerCtx_t *ctx);
140 /*
141 * Reads timer-count snapshot; snapshot value is returned
142 * as function return value
143 */
144 unsigned int MicoTimerSnapshot(MicoTimerCtx_t *ctx);
147 #ifdef __cplusplus
148 };
149 #endif /* __cplusplus */
152 #endif /*MICO32_MICOTIMER_HEADER_FILE */