1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/drivers/device/MicoTimer.h Fri Aug 13 10:49:23 2010 +0100 1.3 @@ -0,0 +1,153 @@ 1.4 +/**************************************************************************** 1.5 +** 1.6 +** Name: MicoTimer.h 1.7 +** 1.8 +** Description: 1.9 +** Implements functions for manipulating LatticeMico32 Timer and 1.10 +** defines timer register map 1.11 +** 1.12 +** $Revision: $ 1.13 +** 1.14 +** Disclaimer: 1.15 +** 1.16 +** This source code is intended as a design reference which 1.17 +** illustrates how these types of functions can be implemented. It 1.18 +** is the user's responsibility to verify their design for 1.19 +** consistency and functionality through the use of formal 1.20 +** verification methods. Lattice Semiconductor provides no warranty 1.21 +** regarding the use or functionality of this code. 1.22 +** 1.23 +** -------------------------------------------------------------------- 1.24 +** 1.25 +** Lattice Semiconductor Corporation 1.26 +** 5555 NE Moore Court 1.27 +** Hillsboro, OR 97214 1.28 +** U.S.A 1.29 +** 1.30 +** TEL: 1-800-Lattice (USA and Canada) 1.31 +** (503)268-8001 (other locations) 1.32 +** 1.33 +** web: http://www.latticesemi.com 1.34 +** email: techsupport@latticesemi.com 1.35 +** 1.36 +** -------------------------------------------------------------------------- 1.37 +** 1.38 +** Change History (Latest changes on top) 1.39 +** 1.40 +** Ver Date Description 1.41 +** -------------------------------------------------------------------------- 1.42 +** 1.43 +** 3.0 Mar-25-2008 Added Header 1.44 +** 1.45 +**--------------------------------------------------------------------------- 1.46 +*****************************************************************************/ 1.47 + 1.48 +#ifndef MICO32_MICOTIMER_HEADER_FILE 1.49 +#define MICO32_MICOTIMER_HEADER_FILE 1.50 + 1.51 +#include "MicoTypes.h" 1.52 +#include "DDStructs.h" 1.53 + 1.54 +/**************************************************************************** 1.55 + * Mico-timer driver provides the ability to use a Mico-32 timer in either * 1.56 + * a single-shot mode or a periodic mode. * 1.57 + *--------------------------------------------------------------------------* 1.58 + * Mico Timers must be located in a non-cached region to use this driver * 1.59 + ****************************************************************************/ 1.60 + 1.61 + 1.62 +#ifdef __cplusplus 1.63 +extern "C" 1.64 +{ 1.65 +#endif /* __cplusplus */ 1.66 + 1.67 + 1.68 +/****************************************************************************** 1.69 + * Data Structures: * 1.70 + ******************************************************************************/ 1.71 + /* timer callback function type */ 1.72 + typedef void(*TimerCallback_t)(void *); 1.73 + 1.74 + 1.75 + /* mico-timer register structure */ 1.76 + typedef struct st_MicoTimer{ 1.77 + volatile unsigned int Status; 1.78 + volatile unsigned int Control; 1.79 + volatile unsigned int Period; 1.80 + volatile unsigned int Snapshot; 1.81 + }MicoTimer_t; 1.82 + 1.83 + 1.84 + /************************************************************************** 1.85 + * MICO32 TIMER REGISTER DEFINITIONS * 1.86 + * (NOTE: OFFSETS REPRESENT BYTES) * 1.87 + **************************************************************************/ 1.88 + #define MICO32_TIMER_STATUS_REG_OFFSET (0x00) 1.89 + #define MICO32_TIMER_CONTROL_REG_OFFSET (0x04) 1.90 + #define MICO32_TIMER_PERIOD_REG_OFFSET (0x08) 1.91 + #define MICO32_TIMER_SNAPSHOT_REG_OFFSET (0x0c) 1.92 + 1.93 + 1.94 + /* status-register bits: */ 1.95 + #define MICO32_TIMER_STATUS_TO_BIT_MASK (0x1) 1.96 + 1.97 + 1.98 + /* control-register bits */ 1.99 + #define MICO32_TIMER_CONTROL_INT_BIT_MASK (0x1) 1.100 + #define MICO32_TIMER_CONTROL_CONT_BIT_MASK (0x2) 1.101 + #define MICO32_TIMER_CONTROL_START_BIT_MASK (0x4) 1.102 + #define MICO32_TIMER_CONTROL_STOP_BIT_MASK (0x8) 1.103 + 1.104 + 1.105 +/****************************************************************************** 1.106 + * functions * 1.107 + ******************************************************************************/ 1.108 + 1.109 +/* initializes Mico32 timer */ 1.110 +void MicoTimerInit( MicoTimerCtx_t *ctx ); 1.111 + 1.112 + 1.113 +/* 1.114 + ****************************************************************************** 1.115 + * Starts a Mico32 timer * 1.116 + *----------------------------------------------------------------------------* 1.117 + * Inputs: * 1.118 + * MicoTimerCtx_t *ctx: pointer to valid ctx * 1.119 + * * 1.120 + * TimerCallback_t callback: User-provided callback function, called * 1.121 + * in interrupt-context. * 1.122 + * typedef void(*TimerCallback_t)(void *) * 1.123 + * * 1.124 + * void *priv: user-provided data that will be called in the callback * 1.125 + * * 1.126 + * unsigned int timercount: ticks to load counter with * 1.127 + * * 1.128 + * int periodic: if 1, the timer is programmed to auto-load, else * 1.129 + * timer is programmed not to reload on reaching terminal value * 1.130 + * * 1.131 + * Note: user MUST supply a valid ctx. * 1.132 + * user MUST make sure timerCount is non-zero * 1.133 + ****************************************************************************** 1.134 + */ 1.135 +mico_status MicoTimerStart( MicoTimerCtx_t *ctx, TimerCallback_t callback, 1.136 + void *priv, unsigned int timerCount, int periodic ); 1.137 + 1.138 + 1.139 +/* stops a mico-32 timer */ 1.140 +mico_status MicoTimerStop(MicoTimerCtx_t *ctx); 1.141 + 1.142 + 1.143 +/* 1.144 + * Reads timer-count snapshot; snapshot value is returned 1.145 + * as function return value 1.146 + */ 1.147 +unsigned int MicoTimerSnapshot(MicoTimerCtx_t *ctx); 1.148 + 1.149 + 1.150 +#ifdef __cplusplus 1.151 +}; 1.152 +#endif /* __cplusplus */ 1.153 + 1.154 + 1.155 +#endif /*MICO32_MICOTIMER_HEADER_FILE */ 1.156 +