drivers/device/MicoTimer.h

Fri, 13 Aug 2010 10:49:23 +0100

author
Philip Pemberton <philpem@philpem.me.uk>
date
Fri, 13 Aug 2010 10:49:23 +0100
changeset 0
396b0bd970d3
permissions
-rw-r--r--

Initial import, Timer v3.0

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