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