[352] | 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 | ******************************************************************************/
|
---|
[374] | 33 | #include "cmsis.h"
|
---|
[352] | 34 | #include "wdt_iodefine.h"
|
---|
| 35 | #include "nvic_wrapper.h"
|
---|
| 36 |
|
---|
| 37 | /******************************************************************************
|
---|
| 38 | Typedef definitions
|
---|
| 39 | ******************************************************************************/
|
---|
| 40 |
|
---|
| 41 | /******************************************************************************
|
---|
| 42 | Macro definitions
|
---|
| 43 | ******************************************************************************/
|
---|
| 44 | #define PRIO_BITS (7) /* Set binary point to 0 in gic.c */
|
---|
| 45 | #define WDT_WTCNT_WRITE (0x5A00)
|
---|
| 46 | #define WDT_WTCSR_WRITE (0xA500)
|
---|
| 47 | #define WDT_WRCSR_WOVF_WRITE (0xA500)
|
---|
| 48 | #define WDT_WRCSR_RSTE_WRITE (0x5A00)
|
---|
| 49 |
|
---|
| 50 | /******************************************************************************
|
---|
| 51 | Imported global variables and functions (from other files)
|
---|
| 52 | ******************************************************************************/
|
---|
| 53 |
|
---|
| 54 | /******************************************************************************
|
---|
| 55 | Exported global variables and functions (to be accessed by other files)
|
---|
| 56 | ******************************************************************************/
|
---|
| 57 |
|
---|
| 58 | /******************************************************************************
|
---|
| 59 | Private global variables and functions
|
---|
| 60 | ******************************************************************************/
|
---|
| 61 |
|
---|
| 62 |
|
---|
| 63 |
|
---|
| 64 | /* ########################## NVIC functions #################################### */
|
---|
| 65 | void NVIC_SetPriorityGrouping(uint32_t PriorityGroup)
|
---|
| 66 | {
|
---|
| 67 | GIC_SetBinaryPoint(PriorityGroup);
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 | uint32_t NVIC_GetPriorityGrouping(void)
|
---|
| 72 | {
|
---|
[374] | 73 | return GIC_GetBinaryPoint();
|
---|
[352] | 74 | }
|
---|
| 75 |
|
---|
| 76 |
|
---|
| 77 | void NVIC_EnableIRQ(IRQn_Type IRQn)
|
---|
| 78 | {
|
---|
| 79 | GIC_EnableIRQ(IRQn);
|
---|
| 80 | }
|
---|
| 81 |
|
---|
| 82 |
|
---|
| 83 | void NVIC_DisableIRQ(IRQn_Type IRQn)
|
---|
| 84 | {
|
---|
| 85 | GIC_DisableIRQ(IRQn);
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 |
|
---|
| 89 | uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn)
|
---|
| 90 | {
|
---|
| 91 | uint32_t pending;
|
---|
| 92 |
|
---|
| 93 | pending = GIC_GetIRQStatus(IRQn);
|
---|
| 94 | pending = (pending & 0x00000001);
|
---|
| 95 |
|
---|
| 96 | return pending;
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 |
|
---|
| 100 | void NVIC_SetPendingIRQ(IRQn_Type IRQn)
|
---|
| 101 | {
|
---|
| 102 | GIC_SetPendingIRQ(IRQn);
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 |
|
---|
| 106 | void NVIC_ClearPendingIRQ(IRQn_Type IRQn)
|
---|
| 107 | {
|
---|
| 108 | GIC_ClearPendingIRQ(IRQn);
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | uint32_t NVIC_GetActive(IRQn_Type IRQn)
|
---|
| 113 | {
|
---|
| 114 | uint32_t active;
|
---|
| 115 |
|
---|
| 116 | active = GIC_GetIRQStatus(IRQn);
|
---|
| 117 | active = ((active >> 1) & 0x00000001);
|
---|
| 118 |
|
---|
| 119 | return active;
|
---|
| 120 | }
|
---|
| 121 |
|
---|
| 122 |
|
---|
| 123 | void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority)
|
---|
| 124 | {
|
---|
| 125 | GIC_SetPriority(IRQn, (priority << 3));
|
---|
| 126 | }
|
---|
| 127 |
|
---|
| 128 |
|
---|
| 129 | uint32_t NVIC_GetPriority(IRQn_Type IRQn)
|
---|
| 130 | {
|
---|
| 131 | uint32_t priority_field;
|
---|
| 132 |
|
---|
| 133 | priority_field = GIC_GetPriority(IRQn);
|
---|
| 134 | priority_field = (priority_field >> 3);
|
---|
| 135 | return priority_field;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 |
|
---|
| 139 | uint32_t NVIC_EncodePriority (uint32_t PriorityGroup, uint32_t PreemptPriority, uint32_t SubPriority)
|
---|
| 140 | {
|
---|
| 141 | uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
|
---|
| 142 | uint32_t PreemptPriorityBits;
|
---|
| 143 | uint32_t SubPriorityBits;
|
---|
| 144 |
|
---|
| 145 | PreemptPriorityBits = ((7 - PriorityGroupTmp) > PRIO_BITS) ? PRIO_BITS : 7 - PriorityGroupTmp;
|
---|
| 146 | SubPriorityBits = ((PriorityGroupTmp + PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + PRIO_BITS;
|
---|
| 147 |
|
---|
| 148 | return (
|
---|
| 149 | ((PreemptPriority & ((1 << (PreemptPriorityBits)) - 1)) << SubPriorityBits) |
|
---|
| 150 | ((SubPriority & ((1 << (SubPriorityBits )) - 1)))
|
---|
| 151 | );
|
---|
| 152 | }
|
---|
| 153 |
|
---|
| 154 |
|
---|
| 155 | void NVIC_DecodePriority (uint32_t Priority, uint32_t PriorityGroup, uint32_t* pPreemptPriority, uint32_t* pSubPriority)
|
---|
| 156 | {
|
---|
| 157 | uint32_t PriorityGroupTmp = (PriorityGroup & 0x07); /* only values 0..7 are used */
|
---|
| 158 | uint32_t PreemptPriorityBits;
|
---|
| 159 | uint32_t SubPriorityBits;
|
---|
| 160 |
|
---|
| 161 | PreemptPriorityBits = ((7 - PriorityGroupTmp) > PRIO_BITS) ? PRIO_BITS : 7 - PriorityGroupTmp;
|
---|
| 162 | SubPriorityBits = ((PriorityGroupTmp + PRIO_BITS) < 7) ? 0 : PriorityGroupTmp - 7 + PRIO_BITS;
|
---|
| 163 |
|
---|
| 164 | *pPreemptPriority = (Priority >> SubPriorityBits) & ((1 << (PreemptPriorityBits)) - 1);
|
---|
| 165 | *pSubPriority = (Priority ) & ((1 << (SubPriorityBits )) - 1);
|
---|
| 166 | }
|
---|
| 167 |
|
---|
| 168 | void NVIC_SystemReset(void)
|
---|
| 169 | {
|
---|
| 170 | uint16_t reg;
|
---|
| 171 | uint8_t dummy_read;
|
---|
| 172 | /* Use Watch Dog Timer to system reset */
|
---|
| 173 |
|
---|
| 174 | /* Set WT/IT bit of WTCSR to 1 = Watch Dog */
|
---|
| 175 | /* CLK = 000, 1xP0phi(=33.3333MHz) = 7.7us */
|
---|
| 176 | reg = (WDT_WTCSR_WRITE | 0x0058);
|
---|
| 177 | WDTWTCSR = reg;
|
---|
| 178 |
|
---|
| 179 | /* Clear Count reg */
|
---|
| 180 | reg = (WDT_WTCNT_WRITE | 0x0000);
|
---|
| 181 | WDTWTCNT = reg;
|
---|
| 182 |
|
---|
| 183 | /* Clear WOVF flag */
|
---|
| 184 | dummy_read = WDTWRCSR;
|
---|
| 185 | reg = (WDT_WRCSR_WOVF_WRITE | (dummy_read & 0x0000));
|
---|
| 186 | WDTWRCSR = reg;
|
---|
| 187 | /* Enable Internal Reset */
|
---|
| 188 | reg = (WDT_WRCSR_RSTE_WRITE | 0x005F);
|
---|
| 189 | WDTWRCSR = reg;
|
---|
| 190 |
|
---|
| 191 | /* Watch Dog start */
|
---|
| 192 | reg = (WDT_WTCSR_WRITE | 0x0078);
|
---|
| 193 | WDTWTCSR = reg;
|
---|
| 194 |
|
---|
| 195 | while(1); /* wait Internal Reset */
|
---|
| 196 | }
|
---|
| 197 |
|
---|
| 198 | /* ################################## SysTick function ############################################ */
|
---|
| 199 | uint32_t SysTick_Config(uint32_t ticks)
|
---|
| 200 | {
|
---|
| 201 | /* Not support this function */
|
---|
| 202 | /* Use mbed Ticker */
|
---|
| 203 | return (1); /* impossible */
|
---|
| 204 | }
|
---|
| 205 |
|
---|
| 206 |
|
---|
| 207 | /* ##################################### Debug In/Output function ########################################### */
|
---|
| 208 | uint32_t ITM_SendChar (uint32_t ch)
|
---|
| 209 | {
|
---|
| 210 | /* Not support this function */
|
---|
| 211 | /* Use mbed Serial */
|
---|
| 212 | return (ch);
|
---|
| 213 | }
|
---|
| 214 |
|
---|
| 215 |
|
---|
[374] | 216 | int32_t ITM_ReceiveChar (void)
|
---|
| 217 | {
|
---|
[352] | 218 | /* Not support this function */
|
---|
| 219 | /* Use mbed Serial */
|
---|
| 220 | return (-1); /* no character available */
|
---|
| 221 | }
|
---|
| 222 |
|
---|
| 223 |
|
---|
[374] | 224 | int32_t ITM_CheckChar (void)
|
---|
| 225 | {
|
---|
[352] | 226 | /* Not support this function */
|
---|
| 227 | /* Use mbed Serial */
|
---|
| 228 | return (0); /* no character available */
|
---|
| 229 | }
|
---|
| 230 |
|
---|