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