]>
git.gir.st - tmk_keyboard.git/blob - tool/mbed/mbed-sdk/libraries/mbed/targets/cmsis/TARGET_RENESAS/TARGET_RZ_A1H/nvic_wrapper.c
1 /*******************************************************************************
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
20 * http://www.renesas.com/disclaimer
21 * Copyright (C) 2012 - 2015 Renesas Electronics Corporation. All rights reserved.
22 *******************************************************************************/
23 /**************************************************************************//**
24 * @file nvic_wrapper.c
27 * @brief Wrapper between NVIC(for Cortex-M) and GIC(for Cortex-A9)
28 ******************************************************************************/
30 /******************************************************************************
31 Includes <System Includes> , "Project Includes"
32 ******************************************************************************/
34 #include "wdt_iodefine.h"
35 #include "nvic_wrapper.h"
38 /******************************************************************************
40 ******************************************************************************/
42 /******************************************************************************
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)
51 /******************************************************************************
52 Imported global variables and functions (from other files)
53 ******************************************************************************/
55 /******************************************************************************
56 Exported global variables and functions (to be accessed by other files)
57 ******************************************************************************/
59 /******************************************************************************
60 Private global variables and functions
61 ******************************************************************************/
65 /* ########################## NVIC functions #################################### */
66 void NVIC_SetPriorityGrouping(uint32_t PriorityGroup
)
68 GIC_SetBinaryPoint(PriorityGroup
);
72 uint32_t NVIC_GetPriorityGrouping(void)
74 return GIC_GetBinaryPoint(0);
78 void NVIC_EnableIRQ(IRQn_Type IRQn
)
84 void NVIC_DisableIRQ(IRQn_Type IRQn
)
90 uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn
)
94 pending
= GIC_GetIRQStatus(IRQn
);
95 pending
= (pending
& 0x00000001);
101 void NVIC_SetPendingIRQ(IRQn_Type IRQn
)
103 GIC_SetPendingIRQ(IRQn
);
107 void NVIC_ClearPendingIRQ(IRQn_Type IRQn
)
109 GIC_ClearPendingIRQ(IRQn
);
113 uint32_t NVIC_GetActive(IRQn_Type IRQn
)
117 active
= GIC_GetIRQStatus(IRQn
);
118 active
= ((active
>> 1) & 0x00000001);
124 void NVIC_SetPriority(IRQn_Type IRQn
, uint32_t priority
)
126 GIC_SetPriority(IRQn
, (priority
<< 3));
130 uint32_t NVIC_GetPriority(IRQn_Type IRQn
)
132 uint32_t priority_field
;
134 priority_field
= GIC_GetPriority(IRQn
);
135 priority_field
= (priority_field
>> 3);
136 return priority_field
;
140 uint32_t NVIC_EncodePriority (uint32_t PriorityGroup
, uint32_t PreemptPriority
, uint32_t SubPriority
)
142 uint32_t PriorityGroupTmp
= (PriorityGroup
& 0x07); /* only values 0..7 are used */
143 uint32_t PreemptPriorityBits
;
144 uint32_t SubPriorityBits
;
146 PreemptPriorityBits
= ((7 - PriorityGroupTmp
) > PRIO_BITS
) ? PRIO_BITS
: 7 - PriorityGroupTmp
;
147 SubPriorityBits
= ((PriorityGroupTmp
+ PRIO_BITS
) < 7) ? 0 : PriorityGroupTmp
- 7 + PRIO_BITS
;
150 ((PreemptPriority
& ((1 << (PreemptPriorityBits
)) - 1)) << SubPriorityBits
) |
151 ((SubPriority
& ((1 << (SubPriorityBits
)) - 1)))
156 void NVIC_DecodePriority (uint32_t Priority
, uint32_t PriorityGroup
, uint32_t* pPreemptPriority
, uint32_t* pSubPriority
)
158 uint32_t PriorityGroupTmp
= (PriorityGroup
& 0x07); /* only values 0..7 are used */
159 uint32_t PreemptPriorityBits
;
160 uint32_t SubPriorityBits
;
162 PreemptPriorityBits
= ((7 - PriorityGroupTmp
) > PRIO_BITS
) ? PRIO_BITS
: 7 - PriorityGroupTmp
;
163 SubPriorityBits
= ((PriorityGroupTmp
+ PRIO_BITS
) < 7) ? 0 : PriorityGroupTmp
- 7 + PRIO_BITS
;
165 *pPreemptPriority
= (Priority
>> SubPriorityBits
) & ((1 << (PreemptPriorityBits
)) - 1);
166 *pSubPriority
= (Priority
) & ((1 << (SubPriorityBits
)) - 1);
169 void NVIC_SystemReset(void)
173 /* Use Watch Dog Timer to system reset */
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);
180 /* Clear Count reg */
181 reg
= (WDT_WTCNT_WRITE
| 0x0000);
184 /* Clear WOVF flag */
185 dummy_read
= WDTWRCSR
;
186 reg
= (WDT_WRCSR_WOVF_WRITE
| (dummy_read
& 0x0000));
188 /* Enable Internal Reset */
189 reg
= (WDT_WRCSR_RSTE_WRITE
| 0x005F);
192 /* Watch Dog start */
193 reg
= (WDT_WTCSR_WRITE
| 0x0078);
196 while(1); /* wait Internal Reset */
199 /* ################################## SysTick function ############################################ */
200 uint32_t SysTick_Config(uint32_t ticks
)
202 /* Not support this function */
203 /* Use mbed Ticker */
204 return (1); /* impossible */
208 /* ##################################### Debug In/Output function ########################################### */
209 uint32_t ITM_SendChar (uint32_t ch
)
211 /* Not support this function */
212 /* Use mbed Serial */
217 int32_t ITM_ReceiveChar (void) {
218 /* Not support this function */
219 /* Use mbed Serial */
220 return (-1); /* no character available */
224 int32_t ITM_CheckChar (void) {
225 /* Not support this function */
226 /* Use mbed Serial */
227 return (0); /* no character available */