drivers/device/MicoTimer.h

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