]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/RISC-V_IGLOO2_Creative_SoftConsole/Microsemi_Code/drivers/CoreTimer/core_timer.c
3f6720b16d8931e578d44b04d73f759e9526dec0
[freertos] / FreeRTOS / Demo / RISC-V_IGLOO2_Creative_SoftConsole / Microsemi_Code / drivers / CoreTimer / core_timer.c
1 /*******************************************************************************\r
2  * (c) Copyright 2007-2015 Microsemi SoC Products Group. All rights reserved.\r
3  * \r
4  * CoreTimer driver implementation.\r
5  * \r
6  * SVN $Revision: 7967 $\r
7  * SVN $Date: 2015-10-09 18:48:26 +0530 (Fri, 09 Oct 2015) $\r
8  */\r
9 \r
10 #include "core_timer.h"\r
11 #include "coretimer_regs.h"\r
12 #include "hal.h"\r
13 #include "hal_assert.h"\r
14 \r
15 #ifndef NDEBUG\r
16 static timer_instance_t* NULL_timer_instance;\r
17 #endif\r
18 \r
19 /***************************************************************************//**\r
20  * TMR_init()\r
21  * See "core_timer.h" for details of how to use this function.\r
22  */\r
23 void \r
24 TMR_init\r
25 (\r
26         timer_instance_t * this_timer,\r
27         addr_t address,\r
28         uint8_t mode,\r
29         uint32_t prescale,\r
30         uint32_t load_value\r
31 )\r
32 {\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
36     \r
37     this_timer->base_address = address;\r
38 \r
39     /* Disable interrupts. */\r
40     HAL_set_32bit_reg_field( address, InterruptEnable,0 );\r
41 \r
42     /* Disable timer. */\r
43     HAL_set_32bit_reg_field( address, TimerEnable, 0 );\r
44 \r
45     /* Clear pending interrupt. */\r
46     HAL_set_32bit_reg( address, TimerIntClr, 1 );\r
47 \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
51 \r
52     /* Set the interrupt mode. */\r
53     if ( mode == TMR_CONTINUOUS_MODE )\r
54     {\r
55         HAL_set_32bit_reg_field( address, TimerMode, 0 );\r
56     }\r
57     else\r
58     {\r
59         /* TMR_ONE_SHOT_MODE */\r
60         HAL_set_32bit_reg_field( address, TimerMode, 1 );\r
61     }\r
62 }\r
63 \r
64 /***************************************************************************//**\r
65  * TMR_start()\r
66  * See "core_timer.h" for details of how to use this function.\r
67  */\r
68 void\r
69 TMR_start\r
70 (\r
71     timer_instance_t * this_timer\r
72 )\r
73 {\r
74         HAL_ASSERT( this_timer != NULL_timer_instance )\r
75     \r
76     HAL_set_32bit_reg_field( this_timer->base_address, TimerEnable, 1 );\r
77 }\r
78 \r
79 /***************************************************************************//**\r
80  * TMR_stop()\r
81  * See "core_timer.h" for details of how to use this function.\r
82  */\r
83 void\r
84 TMR_stop\r
85 (\r
86     timer_instance_t * this_timer\r
87 )\r
88 {\r
89         HAL_ASSERT( this_timer != NULL_timer_instance )\r
90     \r
91     HAL_set_32bit_reg_field( this_timer->base_address, TimerEnable, 0 );\r
92 }\r
93 \r
94 \r
95 /***************************************************************************//**\r
96  * TMR_enable_int()\r
97  * See "core_timer.h" for details of how to use this function.\r
98  */\r
99 void\r
100 TMR_enable_int\r
101 (\r
102     timer_instance_t * this_timer\r
103 )\r
104 {\r
105         HAL_ASSERT( this_timer != NULL_timer_instance )\r
106     \r
107     HAL_set_32bit_reg_field( this_timer->base_address, InterruptEnable, 1 );\r
108 }\r
109 \r
110 /***************************************************************************//**\r
111  * TMR_clear_int()\r
112  * See "core_timer.h" for details of how to use this function.\r
113  */\r
114 void\r
115 TMR_clear_int\r
116 (\r
117     timer_instance_t * this_timer\r
118 )\r
119 {\r
120         HAL_ASSERT( this_timer != NULL_timer_instance )\r
121     \r
122     HAL_set_32bit_reg( this_timer->base_address, TimerIntClr, 0x01 );\r
123 }\r
124 \r
125 /***************************************************************************//**\r
126  * TMR_current_value()\r
127  * See "core_timer.h" for details of how to use this function.\r
128  */\r
129 uint32_t\r
130 TMR_current_value\r
131 (\r
132     timer_instance_t * this_timer\r
133 )\r
134 {\r
135         uint32_t value = 0;\r
136         HAL_ASSERT( this_timer != NULL_timer_instance )\r
137     \r
138     value = HAL_get_32bit_reg( this_timer->base_address, TimerValue );\r
139     \r
140         return value;\r
141 }\r
142 \r
143 /***************************************************************************//**\r
144  * TMR_reload()\r
145  * See "core_timer.h" for details of how to use this function.\r
146  */\r
147 void TMR_reload\r
148 (\r
149         timer_instance_t * this_timer,\r
150         uint32_t load_value\r
151 )\r
152 {\r
153         HAL_ASSERT( this_timer != NULL_timer_instance )\r
154         HAL_ASSERT( load_value != 0 )\r
155         \r
156         HAL_set_32bit_reg(this_timer->base_address, TimerLoad, load_value );\r
157 }\r
158 \r