mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Wed Jul 01 09:45:11 2015 +0100
Revision:
579:53297373a894
Parent:
500:04797f1feae2
Synchronized with git revision d5b4d2ab9c47edb4dc5776e7177b0c2263459081

Full URL: https://github.com/mbedmicro/mbed/commit/d5b4d2ab9c47edb4dc5776e7177b0c2263459081/

Initial version of drivers for SAMR21

Who changed what in which revision?

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