]> git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H/nvic_wrapper.c
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[tmk_keyboard.git] / tool / mbed / mbed-sdk / libraries / mbed / targets / cmsis / TARGET_RENESAS / TARGET_RZ_A1H / nvic_wrapper.c
1 /*******************************************************************************
2 * DISCLAIMER
3 * This software is supplied by Renesas Electronics Corporation and is only
4 * intended for use with Renesas products. No other uses are authorized. This
5 * software is owned by Renesas Electronics Corporation and is protected under
6 * all applicable laws, including copyright laws.
7 * THIS SOFTWARE IS PROVIDED "AS IS" AND RENESAS MAKES NO WARRANTIES REGARDING
8 * THIS SOFTWARE, WHETHER EXPRESS, IMPLIED OR STATUTORY, INCLUDING BUT NOT
9 * LIMITED TO WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
10 * AND NON-INFRINGEMENT. ALL SUCH WARRANTIES ARE EXPRESSLY DISCLAIMED.
11 * TO THE MAXIMUM EXTENT PERMITTED NOT PROHIBITED BY LAW, NEITHER RENESAS
12 * ELECTRONICS CORPORATION NOR ANY OF ITS AFFILIATED COMPANIES SHALL BE LIABLE
13 * FOR ANY DIRECT, INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR
14 * ANY REASON RELATED TO THIS SOFTWARE, EVEN IF RENESAS OR ITS AFFILIATES HAVE
15 * BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
16 * Renesas reserves the right, without notice, to make changes to this software
17 * and to discontinue the availability of this software. By using this software,
18 * you agree to the additional terms and conditions found by accessing the
19 * following link:
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /**************************************************************************//**
24 * @file nvic_wrapper.c
25 * $Rev: $
26 * $Date:: $
27 * @brief Wrapper between NVIC(for Cortex-M) and GIC(for Cortex-A9)
28 ******************************************************************************/
29
30 /******************************************************************************
31 Includes <System Includes> , "Project Includes"
32 ******************************************************************************/
33 #include "MBRZA1H.h"
34 #include "wdt_iodefine.h"
35 #include "nvic_wrapper.h"
36 #include "gic.h"
37
38 /******************************************************************************
39 Typedef definitions
40 ******************************************************************************/
41
42 /******************************************************************************
43 Macro definitions
44 ******************************************************************************/
45 #define PRIO_BITS (7) /* Set binary point to 0 in gic.c */
46 #define WDT_WTCNT_WRITE (0x5A00)
47 #define WDT_WTCSR_WRITE (0xA500)
48 #define WDT_WRCSR_WOVF_WRITE (0xA500)
49 #define WDT_WRCSR_RSTE_WRITE (0x5A00)
50
51 /******************************************************************************
52 Imported global variables and functions (from other files)
53 ******************************************************************************/
54
55 /******************************************************************************
56 Exported global variables and functions (to be accessed by other files)
57 ******************************************************************************/
58
59 /******************************************************************************
60 Private global variables and functions
61 ******************************************************************************/
62
63
64
65 /* ########################## NVIC functions #################################### */
66 void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
67 {
68 GIC_SetBinaryPoint(PriorityGroup);
69 }
70
71
72 uint32_t NVIC_GetPriorityGrouping(void)
73 {
74 return GIC_GetBinaryPoint(0);
75 }
76
77
78 void NVIC_EnableIRQ(IRQn_Type IRQn)
79 {
80 GIC_EnableIRQ(IRQn);
81 }
82
83
84 void NVIC_DisableIRQ(IRQn_Type IRQn)
85 {
86 GIC_DisableIRQ(IRQn);
87 }
88
89
90 uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
91 {
92 uint32_t pending;
93
94 pending = GIC_GetIRQStatus(IRQn);
95 pending = (pending & 0x00000001);
96
97 return pending;
98 }
99
100
101 void NVIC_SetPendingIRQ(IRQn_Type IRQn)
102 {
103 GIC_SetPendingIRQ(IRQn);
104 }
105
106
107 void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
108 {
109 GIC_ClearPendingIRQ(IRQn);
110 }
111
112
113 uint32_t NVIC_GetActive(IRQn_Type IRQn)
114 {
115 uint32_t active;
116
117 active = GIC_GetIRQStatus(IRQn);
118 active = ((active >> 1) & 0x00000001);
119
120 return active;
121 }
122
123
124 void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
125 {
126 GIC_SetPriority(IRQn, (priority << 3));
127 }
128
129
130 uint32_t NVIC_GetPriority(IRQn_Type IRQn)
131 {
132 uint32_t priority_field;
133
134 priority_field = GIC_GetPriority(IRQn);
135 priority_field = (priority_field >> 3);
136 return priority_field;
137 }
138
139
140 uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
141 {
142 uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
143 uint32_t PreemptPriorityBits;
144 uint32_t SubPriorityBits;
145
146 PreemptPriorityBits = ((7 - PriorityGroupTmp) > PRIO_BITS) ? PRIO_BITS : 7 - PriorityGroupTmp;
147 SubPriorityBits = ((PriorityGroupTmp + PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + PRIO_BITS;
148
149 return (
150 ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
151 ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
152 );
153 }
154
155
156 void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
157 {
158 uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
159 uint32_t PreemptPriorityBits;
160 uint32_t SubPriorityBits;
161
162 PreemptPriorityBits = ((7 - PriorityGroupTmp) > PRIO_BITS) ? PRIO_BITS : 7 - PriorityGroupTmp;
163 SubPriorityBits = ((PriorityGroupTmp + PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + PRIO_BITS;
164
165 *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
166 *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
167 }
168
169 void NVIC_SystemReset(void)
170 {
171 uint16_t reg;
172 uint8_t dummy_read;
173 /* Use Watch Dog Timer to system reset */
174
175 /* Set WT/IT bit of WTCSR to 1 = Watch Dog */
176 /* CLK = 000, 1xP0phi(=33.3333MHz) = 7.7us */
177 reg = (WDT_WTCSR_WRITE | 0x0058);
178 WDTWTCSR = reg;
179
180 /* Clear Count reg */
181 reg = (WDT_WTCNT_WRITE | 0x0000);
182 WDTWTCNT = reg;
183
184 /* Clear WOVF flag */
185 dummy_read = WDTWRCSR;
186 reg = (WDT_WRCSR_WOVF_WRITE | (dummy_read & 0x0000));
187 WDTWRCSR = reg;
188 /* Enable Internal Reset */
189 reg = (WDT_WRCSR_RSTE_WRITE | 0x005F);
190 WDTWRCSR = reg;
191
192 /* Watch Dog start */
193 reg = (WDT_WTCSR_WRITE | 0x0078);
194 WDTWTCSR = reg;
195
196 while(1); /* wait Internal Reset */
197 }
198
199 /* ################################## SysTick function ############################################ */
200 uint32_t SysTick_Config(uint32_t ticks)
201 {
202 /* Not support this function */
203 /* Use mbed Ticker */
204 return (1); /* impossible */
205 }
206
207
208 /* ##################################### Debug In/Output function ########################################### */
209 uint32_t ITM_SendChar (uint32_t ch)
210 {
211 /* Not support this function */
212 /* Use mbed Serial */
213 return (ch);
214 }
215
216
217 int32_t ITM_ReceiveChar (void) {
218 /* Not support this function */
219 /* Use mbed Serial */
220 return (-1); /* no character available */
221 }
222
223
224 int32_t ITM_CheckChar (void) {
225 /* Not support this function */
226 /* Use mbed Serial */
227 return (0); /* no character available */
228 }
229
Imprint / Impressum