1 /*******************************************************************************
\r
2 * (c) Copyright 2007-2015 Microsemi SoC Products Group. All rights reserved.
\r
4 * CoreTimer driver implementation.
\r
6 * SVN $Revision: 7967 $
\r
7 * SVN $Date: 2015-10-09 18:48:26 +0530 (Fri, 09 Oct 2015) $
\r
10 #include "core_timer.h"
\r
11 #include "coretimer_regs.h"
\r
13 #include "hal_assert.h"
\r
16 static timer_instance_t* NULL_timer_instance;
\r
19 /***************************************************************************//**
\r
21 * See "core_timer.h" for details of how to use this function.
\r
26 timer_instance_t * this_timer,
\r
33 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
34 HAL_ASSERT( prescale <= PRESCALER_DIV_1024 )
\r
35 HAL_ASSERT( load_value != 0 )
\r
37 this_timer->base_address = address;
\r
39 /* Disable interrupts. */
\r
40 HAL_set_32bit_reg_field( address, InterruptEnable,0 );
\r
42 /* Disable timer. */
\r
43 HAL_set_32bit_reg_field( address, TimerEnable, 0 );
\r
45 /* Clear pending interrupt. */
\r
46 HAL_set_32bit_reg( address, TimerIntClr, 1 );
\r
48 /* Configure prescaler and load value. */
\r
49 HAL_set_32bit_reg( address, TimerPrescale, prescale );
\r
50 HAL_set_32bit_reg( address, TimerLoad, load_value );
\r
52 /* Set the interrupt mode. */
\r
53 if ( mode == TMR_CONTINUOUS_MODE )
\r
55 HAL_set_32bit_reg_field( address, TimerMode, 0 );
\r
59 /* TMR_ONE_SHOT_MODE */
\r
60 HAL_set_32bit_reg_field( address, TimerMode, 1 );
\r
64 /***************************************************************************//**
\r
66 * See "core_timer.h" for details of how to use this function.
\r
71 timer_instance_t * this_timer
\r
74 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
76 HAL_set_32bit_reg_field( this_timer->base_address, TimerEnable, 1 );
\r
79 /***************************************************************************//**
\r
81 * See "core_timer.h" for details of how to use this function.
\r
86 timer_instance_t * this_timer
\r
89 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
91 HAL_set_32bit_reg_field( this_timer->base_address, TimerEnable, 0 );
\r
95 /***************************************************************************//**
\r
97 * See "core_timer.h" for details of how to use this function.
\r
102 timer_instance_t * this_timer
\r
105 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
107 HAL_set_32bit_reg_field( this_timer->base_address, InterruptEnable, 1 );
\r
110 /***************************************************************************//**
\r
112 * See "core_timer.h" for details of how to use this function.
\r
117 timer_instance_t * this_timer
\r
120 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
122 HAL_set_32bit_reg( this_timer->base_address, TimerIntClr, 0x01 );
\r
125 /***************************************************************************//**
\r
126 * TMR_current_value()
\r
127 * See "core_timer.h" for details of how to use this function.
\r
132 timer_instance_t * this_timer
\r
135 uint32_t value = 0;
\r
136 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
138 value = HAL_get_32bit_reg( this_timer->base_address, TimerValue );
\r
143 /***************************************************************************//**
\r
145 * See "core_timer.h" for details of how to use this function.
\r
149 timer_instance_t * this_timer,
\r
150 uint32_t load_value
\r
153 HAL_ASSERT( this_timer != NULL_timer_instance )
\r
154 HAL_ASSERT( load_value != 0 )
\r
156 HAL_set_32bit_reg(this_timer->base_address, TimerLoad, load_value );
\r