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.
targets/hal/TARGET_Atmel/TARGET_SAM21/pinmap_function.c@592:a274ee790e56, 2015-07-17 (annotated)
- Committer:
- mbed_official
- Date:
- Fri Jul 17 09:15:10 2015 +0100
- Revision:
- 592:a274ee790e56
Synchronized with git revision e7144f83a8d75df80c4877936b6ffe552b0be9e6
Full URL: https://github.com/mbedmicro/mbed/commit/e7144f83a8d75df80c4877936b6ffe552b0be9e6/
More API implementation for SAMR21
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 592:a274ee790e56 | 1 | /* mbed Microcontroller Library |
mbed_official | 592:a274ee790e56 | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 592:a274ee790e56 | 3 | * |
mbed_official | 592:a274ee790e56 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 592:a274ee790e56 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 592:a274ee790e56 | 6 | * You may obtain a copy of the License at |
mbed_official | 592:a274ee790e56 | 7 | * |
mbed_official | 592:a274ee790e56 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 592:a274ee790e56 | 9 | * |
mbed_official | 592:a274ee790e56 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 592:a274ee790e56 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 592:a274ee790e56 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 592:a274ee790e56 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 592:a274ee790e56 | 14 | * limitations under the License. |
mbed_official | 592:a274ee790e56 | 15 | */ |
mbed_official | 592:a274ee790e56 | 16 | #include <stddef.h> |
mbed_official | 592:a274ee790e56 | 17 | #include "us_ticker_api.h" |
mbed_official | 592:a274ee790e56 | 18 | #include "cmsis.h" |
mbed_official | 592:a274ee790e56 | 19 | #include "mbed_assert.h" |
mbed_official | 592:a274ee790e56 | 20 | #include "ins_gclk.h" |
mbed_official | 592:a274ee790e56 | 21 | #include "compiler.h" |
mbed_official | 592:a274ee790e56 | 22 | #include "system.h" |
mbed_official | 592:a274ee790e56 | 23 | |
mbed_official | 592:a274ee790e56 | 24 | #include "pinmap_function.h" |
mbed_official | 592:a274ee790e56 | 25 | |
mbed_official | 592:a274ee790e56 | 26 | static uint32_t pinmap_merge_pins(uint32_t a, uint32_t b) |
mbed_official | 592:a274ee790e56 | 27 | { |
mbed_official | 592:a274ee790e56 | 28 | // both are the same (inc both NC) |
mbed_official | 592:a274ee790e56 | 29 | if (a == b) |
mbed_official | 592:a274ee790e56 | 30 | return a; |
mbed_official | 592:a274ee790e56 | 31 | |
mbed_official | 592:a274ee790e56 | 32 | // one (or both) is not connected |
mbed_official | 592:a274ee790e56 | 33 | if (a == (uint32_t)NC) |
mbed_official | 592:a274ee790e56 | 34 | return b; |
mbed_official | 592:a274ee790e56 | 35 | if (b == (uint32_t)NC) |
mbed_official | 592:a274ee790e56 | 36 | return a; |
mbed_official | 592:a274ee790e56 | 37 | |
mbed_official | 592:a274ee790e56 | 38 | return (uint32_t)NC; |
mbed_official | 592:a274ee790e56 | 39 | } |
mbed_official | 592:a274ee790e56 | 40 | |
mbed_official | 592:a274ee790e56 | 41 | /** Find the common SERCOM shared by two pins |
mbed_official | 592:a274ee790e56 | 42 | * |
mbed_official | 592:a274ee790e56 | 43 | * Finds the common SERCOM index of two input pins. |
mbed_official | 592:a274ee790e56 | 44 | * If swapping the input argument gives different result, it means, two SERCOMs share both pins |
mbed_official | 592:a274ee790e56 | 45 | * @param[in] pin1 First pin |
mbed_official | 592:a274ee790e56 | 46 | * @param[in] pin2 Second pin |
mbed_official | 592:a274ee790e56 | 47 | * @return SERCOM index if found, else, NC |
mbed_official | 592:a274ee790e56 | 48 | */ |
mbed_official | 592:a274ee790e56 | 49 | uint32_t pinmap_merge_sercom(PinName pin1, PinName pin2) |
mbed_official | 592:a274ee790e56 | 50 | { |
mbed_official | 592:a274ee790e56 | 51 | int i, j; |
mbed_official | 592:a274ee790e56 | 52 | uint32_t pin1_sercom[2]; |
mbed_official | 592:a274ee790e56 | 53 | uint32_t pin2_sercom[2]; |
mbed_official | 592:a274ee790e56 | 54 | uint32_t sercom_index[4]; |
mbed_official | 592:a274ee790e56 | 55 | |
mbed_official | 592:a274ee790e56 | 56 | uint32_t pin_com = NC; |
mbed_official | 592:a274ee790e56 | 57 | uint32_t pin_alt = NC; |
mbed_official | 592:a274ee790e56 | 58 | uint32_t count_com = 0; |
mbed_official | 592:a274ee790e56 | 59 | uint32_t count_alt = 0; |
mbed_official | 592:a274ee790e56 | 60 | |
mbed_official | 592:a274ee790e56 | 61 | /* Adding a condition check just in case we need a different result when swapping arguments */ |
mbed_official | 592:a274ee790e56 | 62 | if (pin1 >= pin2) { |
mbed_official | 592:a274ee790e56 | 63 | pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 64 | pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 65 | } else { |
mbed_official | 592:a274ee790e56 | 66 | pin1_sercom[0] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 67 | pin1_sercom[1] = pinmap_find_peripheral(pin1, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 68 | } |
mbed_official | 592:a274ee790e56 | 69 | |
mbed_official | 592:a274ee790e56 | 70 | pin2_sercom[0] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 71 | pin2_sercom[1] = pinmap_find_peripheral(pin2, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 72 | |
mbed_official | 592:a274ee790e56 | 73 | for (i=0; i<2; i++) { |
mbed_official | 592:a274ee790e56 | 74 | if (pin1_sercom[i] != NC) { |
mbed_official | 592:a274ee790e56 | 75 | pin1_sercom[i] &= 0x0F; |
mbed_official | 592:a274ee790e56 | 76 | } |
mbed_official | 592:a274ee790e56 | 77 | for (j=0; j<2; j++) { |
mbed_official | 592:a274ee790e56 | 78 | if (pin2_sercom[i] != NC) { |
mbed_official | 592:a274ee790e56 | 79 | pin2_sercom[i] &= 0x0F; |
mbed_official | 592:a274ee790e56 | 80 | } |
mbed_official | 592:a274ee790e56 | 81 | sercom_index[(i*2) + j] = pinmap_merge_pins(pin1_sercom[i], pin2_sercom[j]); |
mbed_official | 592:a274ee790e56 | 82 | } |
mbed_official | 592:a274ee790e56 | 83 | } |
mbed_official | 592:a274ee790e56 | 84 | |
mbed_official | 592:a274ee790e56 | 85 | for (i=0; i<4; i++) { |
mbed_official | 592:a274ee790e56 | 86 | if (sercom_index[i] != NC) { |
mbed_official | 592:a274ee790e56 | 87 | if (pin_com == NC) { |
mbed_official | 592:a274ee790e56 | 88 | pin_com = sercom_index[i]; |
mbed_official | 592:a274ee790e56 | 89 | count_com++; |
mbed_official | 592:a274ee790e56 | 90 | } else if (pin_com == sercom_index[i]) { |
mbed_official | 592:a274ee790e56 | 91 | count_com++; |
mbed_official | 592:a274ee790e56 | 92 | } else if (pin_alt == NC) { |
mbed_official | 592:a274ee790e56 | 93 | pin_alt = sercom_index[i]; |
mbed_official | 592:a274ee790e56 | 94 | count_alt++; |
mbed_official | 592:a274ee790e56 | 95 | } else if (pin_alt == sercom_index[i]) { |
mbed_official | 592:a274ee790e56 | 96 | count_alt++; |
mbed_official | 592:a274ee790e56 | 97 | } else {} |
mbed_official | 592:a274ee790e56 | 98 | } |
mbed_official | 592:a274ee790e56 | 99 | } |
mbed_official | 592:a274ee790e56 | 100 | return ((count_com >= count_alt) ? pin_com : pin_alt); |
mbed_official | 592:a274ee790e56 | 101 | } |
mbed_official | 592:a274ee790e56 | 102 | |
mbed_official | 592:a274ee790e56 | 103 | /** Find the common SERCOM shared by four pins |
mbed_official | 592:a274ee790e56 | 104 | * |
mbed_official | 592:a274ee790e56 | 105 | * Finds the common SERCOM index shared by four input pins. |
mbed_official | 592:a274ee790e56 | 106 | * If reversing the input argument order gives different result, it means, two SERCOMs share the pins |
mbed_official | 592:a274ee790e56 | 107 | * @param[in] pin1 First pin |
mbed_official | 592:a274ee790e56 | 108 | * @param[in] pin2 Second pin |
mbed_official | 592:a274ee790e56 | 109 | * @param[in] pin3 Third pin |
mbed_official | 592:a274ee790e56 | 110 | * @param[in] pin4 Fourth pin |
mbed_official | 592:a274ee790e56 | 111 | * @return SERCOM index if found, else, NC |
mbed_official | 592:a274ee790e56 | 112 | */ |
mbed_official | 592:a274ee790e56 | 113 | uint32_t pinmap_find_sercom(PinName pin1, PinName pin2, PinName pin3, PinName pin4) |
mbed_official | 592:a274ee790e56 | 114 | { |
mbed_official | 592:a274ee790e56 | 115 | int i; |
mbed_official | 592:a274ee790e56 | 116 | uint32_t sercom_index[4]; |
mbed_official | 592:a274ee790e56 | 117 | uint32_t pin_com = NC; |
mbed_official | 592:a274ee790e56 | 118 | uint32_t pin_alt = NC; |
mbed_official | 592:a274ee790e56 | 119 | uint32_t count_com = 0; |
mbed_official | 592:a274ee790e56 | 120 | uint32_t count_alt = 0; |
mbed_official | 592:a274ee790e56 | 121 | |
mbed_official | 592:a274ee790e56 | 122 | sercom_index[0] = pinmap_merge_sercom(pin1, pin2); |
mbed_official | 592:a274ee790e56 | 123 | sercom_index[1] = pinmap_merge_sercom(pin3, pin3); |
mbed_official | 592:a274ee790e56 | 124 | sercom_index[2] = pinmap_merge_sercom(pin1, pin3); |
mbed_official | 592:a274ee790e56 | 125 | sercom_index[3] = pinmap_merge_sercom(pin2, pin4); |
mbed_official | 592:a274ee790e56 | 126 | |
mbed_official | 592:a274ee790e56 | 127 | |
mbed_official | 592:a274ee790e56 | 128 | for (i=0; i<4; i++) { |
mbed_official | 592:a274ee790e56 | 129 | if (sercom_index[i] != NC) { |
mbed_official | 592:a274ee790e56 | 130 | if (pin_com == NC) { |
mbed_official | 592:a274ee790e56 | 131 | pin_com = sercom_index[i]; |
mbed_official | 592:a274ee790e56 | 132 | count_com++; |
mbed_official | 592:a274ee790e56 | 133 | } else if (pin_com == sercom_index[i]) { |
mbed_official | 592:a274ee790e56 | 134 | count_com++; |
mbed_official | 592:a274ee790e56 | 135 | } else if (pin_alt == NC) { |
mbed_official | 592:a274ee790e56 | 136 | pin_alt = sercom_index[i]; |
mbed_official | 592:a274ee790e56 | 137 | count_alt++; |
mbed_official | 592:a274ee790e56 | 138 | } else if (pin_alt == sercom_index[i]) { |
mbed_official | 592:a274ee790e56 | 139 | count_alt++; |
mbed_official | 592:a274ee790e56 | 140 | } else {} |
mbed_official | 592:a274ee790e56 | 141 | } |
mbed_official | 592:a274ee790e56 | 142 | } |
mbed_official | 592:a274ee790e56 | 143 | return ((count_com >= count_alt) ? pin_com : pin_alt); |
mbed_official | 592:a274ee790e56 | 144 | } |
mbed_official | 592:a274ee790e56 | 145 | |
mbed_official | 592:a274ee790e56 | 146 | /** Find the MUX function of input pin specific to given SERCOM index |
mbed_official | 592:a274ee790e56 | 147 | * |
mbed_official | 592:a274ee790e56 | 148 | * @param[in] pin Pin whose function is to be found out |
mbed_official | 592:a274ee790e56 | 149 | * @param[in] sercom_index SERCOM index |
mbed_official | 592:a274ee790e56 | 150 | * @return MUX function if found, else, NC |
mbed_official | 592:a274ee790e56 | 151 | */ |
mbed_official | 592:a274ee790e56 | 152 | uint32_t pinmap_function_sercom(PinName pin, uint32_t sercom_index) |
mbed_official | 592:a274ee790e56 | 153 | { |
mbed_official | 592:a274ee790e56 | 154 | uint32_t func = NC; |
mbed_official | 592:a274ee790e56 | 155 | uint32_t index; |
mbed_official | 592:a274ee790e56 | 156 | sercom_index &= 0x0F; |
mbed_official | 592:a274ee790e56 | 157 | |
mbed_official | 592:a274ee790e56 | 158 | if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) { |
mbed_official | 592:a274ee790e56 | 159 | return NC; |
mbed_official | 592:a274ee790e56 | 160 | } |
mbed_official | 592:a274ee790e56 | 161 | index = pinmap_peripheral(pin, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 162 | if ((index & 0x0F) == sercom_index) { |
mbed_official | 592:a274ee790e56 | 163 | func = pinmap_function(pin, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 164 | return func; |
mbed_official | 592:a274ee790e56 | 165 | } |
mbed_official | 592:a274ee790e56 | 166 | index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 167 | if ((index & 0x0F) == sercom_index) { |
mbed_official | 592:a274ee790e56 | 168 | func = pinmap_function(pin, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 169 | return func; |
mbed_official | 592:a274ee790e56 | 170 | } |
mbed_official | 592:a274ee790e56 | 171 | return NC; |
mbed_official | 592:a274ee790e56 | 172 | } |
mbed_official | 592:a274ee790e56 | 173 | |
mbed_official | 592:a274ee790e56 | 174 | /** Find the MUX pad of input pin specific to given SERCOM index |
mbed_official | 592:a274ee790e56 | 175 | * |
mbed_official | 592:a274ee790e56 | 176 | * @param[in] pin Pin whose function is to be found out |
mbed_official | 592:a274ee790e56 | 177 | * @param[in] sercom_index SERCOM index |
mbed_official | 592:a274ee790e56 | 178 | * @return MUX pad if found, else, NC |
mbed_official | 592:a274ee790e56 | 179 | */ |
mbed_official | 592:a274ee790e56 | 180 | uint32_t pinmap_pad_sercom(PinName pin, uint32_t sercom_index) |
mbed_official | 592:a274ee790e56 | 181 | { |
mbed_official | 592:a274ee790e56 | 182 | uint32_t index; |
mbed_official | 592:a274ee790e56 | 183 | sercom_index &= 0x0F; |
mbed_official | 592:a274ee790e56 | 184 | |
mbed_official | 592:a274ee790e56 | 185 | if ((pin == NC) || (sercom_index >= SERCOM_INST_NUM)) { |
mbed_official | 592:a274ee790e56 | 186 | return NC; |
mbed_official | 592:a274ee790e56 | 187 | } |
mbed_official | 592:a274ee790e56 | 188 | index = pinmap_peripheral(pin, PinMap_SERCOM_PAD); |
mbed_official | 592:a274ee790e56 | 189 | if ((index & 0x0F) == sercom_index) { |
mbed_official | 592:a274ee790e56 | 190 | return ((index >> 4) & 0x0F); |
mbed_official | 592:a274ee790e56 | 191 | } |
mbed_official | 592:a274ee790e56 | 192 | index = pinmap_peripheral(pin, PinMap_SERCOM_PADEx); |
mbed_official | 592:a274ee790e56 | 193 | if ((index & 0x0F) == sercom_index) { |
mbed_official | 592:a274ee790e56 | 194 | return ((index >> 4) & 0x0F); |
mbed_official | 592:a274ee790e56 | 195 | } |
mbed_official | 592:a274ee790e56 | 196 | return NC; |
mbed_official | 592:a274ee790e56 | 197 | } |
mbed_official | 592:a274ee790e56 | 198 | |
mbed_official | 592:a274ee790e56 | 199 | /** Find the MUX function of input pin specific to given SERCOM index |
mbed_official | 592:a274ee790e56 | 200 | * |
mbed_official | 592:a274ee790e56 | 201 | * @param[in] pin unused |
mbed_official | 592:a274ee790e56 | 202 | * @param[in] sercom_index SERCOM index |
mbed_official | 592:a274ee790e56 | 203 | * @return base address to SERCOM if found, else NC |
mbed_official | 592:a274ee790e56 | 204 | */ |
mbed_official | 592:a274ee790e56 | 205 | uint32_t pinmap_peripheral_sercom(PinName pin, uint32_t sercom_index) |
mbed_official | 592:a274ee790e56 | 206 | { |
mbed_official | 592:a274ee790e56 | 207 | uint32_t sercom_address[6] = { |
mbed_official | 592:a274ee790e56 | 208 | 0x42000800UL, // Base address of SERCOM0 |
mbed_official | 592:a274ee790e56 | 209 | 0x42000C00UL, // Base address of SERCOM1 |
mbed_official | 592:a274ee790e56 | 210 | 0x42001000UL, // Base address of SERCOM2 |
mbed_official | 592:a274ee790e56 | 211 | 0x42001400UL, // Base address of SERCOM3 |
mbed_official | 592:a274ee790e56 | 212 | 0x42001800UL, // Base address of SERCOM4 |
mbed_official | 592:a274ee790e56 | 213 | 0x42001C00UL // Base address of SERCOM5 |
mbed_official | 592:a274ee790e56 | 214 | }; |
mbed_official | 592:a274ee790e56 | 215 | uint32_t index = sercom_index & 0x0F; |
mbed_official | 592:a274ee790e56 | 216 | |
mbed_official | 592:a274ee790e56 | 217 | if (index >= SERCOM_INST_NUM) { |
mbed_official | 592:a274ee790e56 | 218 | return NC; |
mbed_official | 592:a274ee790e56 | 219 | } |
mbed_official | 592:a274ee790e56 | 220 | return sercom_address[(sercom_index&0x0F)]; |
mbed_official | 592:a274ee790e56 | 221 | } |