Vybhav Kadaba
/
EV-PRO-MW1001_Development_MWARE2390
sensor result structure modified
src/mbed/admw_gpio.cpp@71:7b5ebd969aa7, 2020-04-23 (annotated)
- Committer:
- Vkadaba
- Date:
- Thu Apr 23 08:34:45 2020 +0000
- Revision:
- 71:7b5ebd969aa7
- Parent:
- 32:52445bef314d
Adding extra log for FIFI error
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ADIJake | 0:85855ecd3257 | 1 | /****************************************************************************** |
Vkadaba | 32:52445bef314d | 2 | Copyright 2019 (c) Analog Devices, Inc. |
ADIJake | 0:85855ecd3257 | 3 | |
ADIJake | 0:85855ecd3257 | 4 | All rights reserved. |
ADIJake | 0:85855ecd3257 | 5 | |
ADIJake | 0:85855ecd3257 | 6 | Redistribution and use in source and binary forms, with or without |
ADIJake | 0:85855ecd3257 | 7 | modification, are permitted provided that the following conditions are met: |
ADIJake | 0:85855ecd3257 | 8 | - Redistributions of source code must retain the above copyright |
ADIJake | 0:85855ecd3257 | 9 | notice, this list of conditions and the following disclaimer. |
ADIJake | 0:85855ecd3257 | 10 | - Redistributions in binary form must reproduce the above copyright |
ADIJake | 0:85855ecd3257 | 11 | notice, this list of conditions and the following disclaimer in |
ADIJake | 0:85855ecd3257 | 12 | the documentation and/or other materials provided with the |
ADIJake | 0:85855ecd3257 | 13 | distribution. |
ADIJake | 0:85855ecd3257 | 14 | - Neither the name of Analog Devices, Inc. nor the names of its |
ADIJake | 0:85855ecd3257 | 15 | contributors may be used to endorse or promote products derived |
ADIJake | 0:85855ecd3257 | 16 | from this software without specific prior written permission. |
ADIJake | 0:85855ecd3257 | 17 | - The use of this software may or may not infringe the patent rights |
ADIJake | 0:85855ecd3257 | 18 | of one or more patent holders. This license does not release you |
ADIJake | 0:85855ecd3257 | 19 | from the requirement that you obtain separate licenses from these |
ADIJake | 0:85855ecd3257 | 20 | patent holders to use this software. |
ADIJake | 0:85855ecd3257 | 21 | - Use of the software either in source or binary form, must be run |
ADIJake | 0:85855ecd3257 | 22 | on or directly connected to an Analog Devices Inc. component. |
ADIJake | 0:85855ecd3257 | 23 | |
ADIJake | 0:85855ecd3257 | 24 | THIS SOFTWARE IS PROVIDED BY ANALOG DEVICES "AS IS" AND ANY EXPRESS OR |
ADIJake | 0:85855ecd3257 | 25 | IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, NON-INFRINGEMENT, |
ADIJake | 0:85855ecd3257 | 26 | MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
ADIJake | 0:85855ecd3257 | 27 | IN NO EVENT SHALL ANALOG DEVICES BE LIABLE FOR ANY DIRECT, INDIRECT, |
ADIJake | 0:85855ecd3257 | 28 | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
ADIJake | 0:85855ecd3257 | 29 | LIMITED TO, INTELLECTUAL PROPERTY RIGHTS, PROCUREMENT OF SUBSTITUTE GOODS OR |
ADIJake | 0:85855ecd3257 | 30 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
ADIJake | 0:85855ecd3257 | 31 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
ADIJake | 0:85855ecd3257 | 32 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
ADIJake | 0:85855ecd3257 | 33 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
ADIJake | 0:85855ecd3257 | 34 | * |
ADIJake | 0:85855ecd3257 | 35 | *****************************************************************************/ |
ADIJake | 0:85855ecd3257 | 36 | |
ADIJake | 0:85855ecd3257 | 37 | /*! |
ADIJake | 0:85855ecd3257 | 38 | ****************************************************************************** |
ADIJake | 0:85855ecd3257 | 39 | * @file: |
Vkadaba | 5:0728bde67bdb | 40 | * @brief: ADMW OS-dependent wrapper layer for GPIO interface |
ADIJake | 0:85855ecd3257 | 41 | *----------------------------------------------------------------------------- |
ADIJake | 0:85855ecd3257 | 42 | */ |
ADIJake | 0:85855ecd3257 | 43 | |
ADIJake | 0:85855ecd3257 | 44 | #include <mbed.h> |
ADIJake | 0:85855ecd3257 | 45 | |
Vkadaba | 5:0728bde67bdb | 46 | #include "inc/admw_gpio.h" |
Vkadaba | 5:0728bde67bdb | 47 | #include "inc/admw_log.h" |
ADIJake | 0:85855ecd3257 | 48 | |
ADIJake | 0:85855ecd3257 | 49 | class GpioContext |
ADIJake | 0:85855ecd3257 | 50 | { |
ADIJake | 0:85855ecd3257 | 51 | public: |
ADIJake | 0:85855ecd3257 | 52 | GpioContext( |
ADIJake | 0:85855ecd3257 | 53 | PinName resetPin, |
Vkadaba | 32:52445bef314d | 54 | PinName csPin, |
Vkadaba | 5:0728bde67bdb | 55 | PinName alertErrorPin, |
ADIJake | 0:85855ecd3257 | 56 | PinName datareadyPin) |
ADIJake | 0:85855ecd3257 | 57 | : _reset(resetPin), |
Vkadaba | 32:52445bef314d | 58 | _cs(csPin), |
Vkadaba | 5:0728bde67bdb | 59 | _alertError(alertErrorPin), |
ADIJake | 0:85855ecd3257 | 60 | _dataready(datareadyPin), |
Vkadaba | 5:0728bde67bdb | 61 | _alertErrorIrq(alertErrorPin), |
ADIJake | 0:85855ecd3257 | 62 | _datareadyIrq(datareadyPin) {} |
ADIJake | 0:85855ecd3257 | 63 | |
Vkadaba | 5:0728bde67bdb | 64 | ADMW_RESULT get( |
Vkadaba | 5:0728bde67bdb | 65 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 66 | bool *pState); |
ADIJake | 0:85855ecd3257 | 67 | |
Vkadaba | 5:0728bde67bdb | 68 | ADMW_RESULT set( |
Vkadaba | 5:0728bde67bdb | 69 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 70 | bool state); |
ADIJake | 0:85855ecd3257 | 71 | |
Vkadaba | 5:0728bde67bdb | 72 | ADMW_RESULT enableIrq( |
Vkadaba | 5:0728bde67bdb | 73 | ADMW_GPIO_PIN ePinId, |
Vkadaba | 5:0728bde67bdb | 74 | ADMW_GPIO_CALLBACK callbackFn, |
ADIJake | 0:85855ecd3257 | 75 | void *pArg); |
ADIJake | 0:85855ecd3257 | 76 | |
Vkadaba | 5:0728bde67bdb | 77 | ADMW_RESULT disableIrq( |
Vkadaba | 5:0728bde67bdb | 78 | ADMW_GPIO_PIN ePinId); |
ADIJake | 0:85855ecd3257 | 79 | |
ADIJake | 0:85855ecd3257 | 80 | private: |
ADIJake | 0:85855ecd3257 | 81 | DigitalOut _reset; |
Vkadaba | 32:52445bef314d | 82 | DigitalOut _cs; |
Vkadaba | 32:52445bef314d | 83 | |
Vkadaba | 5:0728bde67bdb | 84 | DigitalIn _alertError; |
ADIJake | 0:85855ecd3257 | 85 | DigitalIn _dataready; |
ADIJake | 0:85855ecd3257 | 86 | |
Vkadaba | 5:0728bde67bdb | 87 | InterruptIn _alertErrorIrq; |
ADIJake | 0:85855ecd3257 | 88 | InterruptIn _datareadyIrq; |
ADIJake | 0:85855ecd3257 | 89 | |
Vkadaba | 5:0728bde67bdb | 90 | ADMW_GPIO_CALLBACK _alertErrorIrqCallback; |
Vkadaba | 5:0728bde67bdb | 91 | ADMW_GPIO_CALLBACK _datareadyIrqCallback; |
ADIJake | 0:85855ecd3257 | 92 | |
Vkadaba | 5:0728bde67bdb | 93 | void *_alertErrorIrqArg; |
ADIJake | 0:85855ecd3257 | 94 | void *_datareadyIrqArg; |
ADIJake | 0:85855ecd3257 | 95 | |
Vkadaba | 5:0728bde67bdb | 96 | void _alertErrorIrqHandler() |
ADIJake | 0:85855ecd3257 | 97 | { |
Vkadaba | 5:0728bde67bdb | 98 | _alertErrorIrqCallback(ADMW_GPIO_PIN_ALERT_ERROR, _alertErrorIrqArg); |
ADIJake | 0:85855ecd3257 | 99 | } |
ADIJake | 0:85855ecd3257 | 100 | void _datareadyIrqHandler() |
ADIJake | 0:85855ecd3257 | 101 | { |
Vkadaba | 5:0728bde67bdb | 102 | _datareadyIrqCallback(ADMW_GPIO_PIN_DATAREADY, _datareadyIrqArg); |
ADIJake | 0:85855ecd3257 | 103 | } |
ADIJake | 0:85855ecd3257 | 104 | }; |
ADIJake | 0:85855ecd3257 | 105 | |
Vkadaba | 5:0728bde67bdb | 106 | ADMW_RESULT GpioContext::get( |
Vkadaba | 5:0728bde67bdb | 107 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 108 | bool *pState) |
ADIJake | 0:85855ecd3257 | 109 | { |
Vkadaba | 32:52445bef314d | 110 | switch(ePinId) |
Vkadaba | 32:52445bef314d | 111 | { |
Vkadaba | 32:52445bef314d | 112 | case ADMW_GPIO_PIN_ALERT_ERROR: |
Vkadaba | 32:52445bef314d | 113 | *pState = _alertError; |
Vkadaba | 32:52445bef314d | 114 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 115 | case ADMW_GPIO_PIN_DATAREADY: |
Vkadaba | 32:52445bef314d | 116 | *pState = _dataready; |
Vkadaba | 32:52445bef314d | 117 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 118 | case ADMW_GPIO_PIN_RESET: |
Vkadaba | 32:52445bef314d | 119 | *pState = _reset; |
Vkadaba | 32:52445bef314d | 120 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 121 | case ADMW_GPIO_PIN_CS: |
Vkadaba | 32:52445bef314d | 122 | *pState = _cs; |
Vkadaba | 32:52445bef314d | 123 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 124 | default: |
Vkadaba | 32:52445bef314d | 125 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 126 | } |
ADIJake | 0:85855ecd3257 | 127 | } |
ADIJake | 0:85855ecd3257 | 128 | |
Vkadaba | 5:0728bde67bdb | 129 | ADMW_RESULT GpioContext::set( |
Vkadaba | 5:0728bde67bdb | 130 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 131 | bool state) |
ADIJake | 0:85855ecd3257 | 132 | { |
Vkadaba | 32:52445bef314d | 133 | switch(ePinId) |
Vkadaba | 32:52445bef314d | 134 | { |
Vkadaba | 32:52445bef314d | 135 | case ADMW_GPIO_PIN_RESET: |
Vkadaba | 32:52445bef314d | 136 | _reset = state; |
Vkadaba | 32:52445bef314d | 137 | break; |
Vkadaba | 32:52445bef314d | 138 | case ADMW_GPIO_PIN_CS: |
Vkadaba | 32:52445bef314d | 139 | _cs = state; |
Vkadaba | 32:52445bef314d | 140 | break; |
Vkadaba | 32:52445bef314d | 141 | default: |
Vkadaba | 32:52445bef314d | 142 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 143 | } |
ADIJake | 0:85855ecd3257 | 144 | |
Vkadaba | 5:0728bde67bdb | 145 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 146 | } |
ADIJake | 0:85855ecd3257 | 147 | |
Vkadaba | 5:0728bde67bdb | 148 | ADMW_RESULT GpioContext::enableIrq( |
Vkadaba | 5:0728bde67bdb | 149 | ADMW_GPIO_PIN ePinId, |
Vkadaba | 5:0728bde67bdb | 150 | ADMW_GPIO_CALLBACK callbackFn, |
ADIJake | 0:85855ecd3257 | 151 | void *pArg) |
ADIJake | 0:85855ecd3257 | 152 | { |
Vkadaba | 32:52445bef314d | 153 | switch(ePinId) |
Vkadaba | 32:52445bef314d | 154 | { |
Vkadaba | 32:52445bef314d | 155 | case ADMW_GPIO_PIN_ALERT_ERROR: |
Vkadaba | 32:52445bef314d | 156 | _alertErrorIrqCallback = callbackFn; |
Vkadaba | 32:52445bef314d | 157 | _alertErrorIrqArg = pArg; |
Vkadaba | 32:52445bef314d | 158 | _alertErrorIrq.rise(callback(this, &GpioContext::_alertErrorIrqHandler)); |
Vkadaba | 32:52445bef314d | 159 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 160 | case ADMW_GPIO_PIN_DATAREADY: |
Vkadaba | 32:52445bef314d | 161 | _datareadyIrqCallback = callbackFn; |
Vkadaba | 32:52445bef314d | 162 | _datareadyIrqArg = pArg; |
Vkadaba | 32:52445bef314d | 163 | _datareadyIrq.rise(callback(this, &GpioContext::_datareadyIrqHandler)); |
Vkadaba | 32:52445bef314d | 164 | return ADMW_SUCCESS; |
Vkadaba | 32:52445bef314d | 165 | default: |
Vkadaba | 32:52445bef314d | 166 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 167 | } |
ADIJake | 0:85855ecd3257 | 168 | } |
ADIJake | 0:85855ecd3257 | 169 | |
Vkadaba | 5:0728bde67bdb | 170 | ADMW_RESULT GpioContext::disableIrq( |
Vkadaba | 5:0728bde67bdb | 171 | ADMW_GPIO_PIN ePinId) |
ADIJake | 0:85855ecd3257 | 172 | { |
Vkadaba | 23:bb685f35b08b | 173 | switch(ePinId) { |
Vkadaba | 23:bb685f35b08b | 174 | case ADMW_GPIO_PIN_ALERT_ERROR: |
Vkadaba | 23:bb685f35b08b | 175 | _alertErrorIrq.rise(NULL); |
Vkadaba | 23:bb685f35b08b | 176 | return ADMW_SUCCESS; |
Vkadaba | 23:bb685f35b08b | 177 | case ADMW_GPIO_PIN_DATAREADY: |
Vkadaba | 23:bb685f35b08b | 178 | _datareadyIrq.rise(NULL); |
Vkadaba | 23:bb685f35b08b | 179 | return ADMW_SUCCESS; |
Vkadaba | 23:bb685f35b08b | 180 | default: |
Vkadaba | 23:bb685f35b08b | 181 | return ADMW_INVALID_DEVICE_NUM; |
ADIJake | 0:85855ecd3257 | 182 | } |
ADIJake | 0:85855ecd3257 | 183 | } |
ADIJake | 0:85855ecd3257 | 184 | |
ADIJake | 0:85855ecd3257 | 185 | #ifdef __cplusplus |
ADIJake | 0:85855ecd3257 | 186 | extern "C" { |
ADIJake | 0:85855ecd3257 | 187 | #endif |
ADIJake | 0:85855ecd3257 | 188 | |
ADIJake | 0:85855ecd3257 | 189 | /* |
ADIJake | 0:85855ecd3257 | 190 | * Open the GPIO interface and allocate resources |
ADIJake | 0:85855ecd3257 | 191 | */ |
Vkadaba | 5:0728bde67bdb | 192 | ADMW_RESULT admw_GpioOpen( |
Vkadaba | 5:0728bde67bdb | 193 | ADMW_PLATFORM_GPIO_CONFIG *pConfig, |
Vkadaba | 5:0728bde67bdb | 194 | ADMW_GPIO_HANDLE *phDevice) |
ADIJake | 0:85855ecd3257 | 195 | { |
ADIJake | 0:85855ecd3257 | 196 | GpioContext *pCtx = new GpioContext((PinName)pConfig->resetPin, |
Vkadaba | 32:52445bef314d | 197 | (PinName)pConfig->csPin, |
Vkadaba | 5:0728bde67bdb | 198 | (PinName)pConfig->alertErrorPin, |
ADIJake | 0:85855ecd3257 | 199 | (PinName)pConfig->datareadyPin); |
Vkadaba | 23:bb685f35b08b | 200 | if (!pCtx) { |
Vkadaba | 5:0728bde67bdb | 201 | ADMW_LOG_ERROR("Failed to allocate memory for GPIO context"); |
Vkadaba | 5:0728bde67bdb | 202 | return ADMW_NO_MEM; |
ADIJake | 0:85855ecd3257 | 203 | } |
ADIJake | 0:85855ecd3257 | 204 | |
Vkadaba | 5:0728bde67bdb | 205 | *phDevice = reinterpret_cast<ADMW_GPIO_HANDLE>(pCtx); |
Vkadaba | 5:0728bde67bdb | 206 | return ADMW_SUCCESS; |
ADIJake | 0:85855ecd3257 | 207 | } |
ADIJake | 0:85855ecd3257 | 208 | |
ADIJake | 0:85855ecd3257 | 209 | /* |
ADIJake | 0:85855ecd3257 | 210 | * Get the state of the specified GPIO pin |
ADIJake | 0:85855ecd3257 | 211 | */ |
Vkadaba | 5:0728bde67bdb | 212 | ADMW_RESULT admw_GpioGet( |
Vkadaba | 5:0728bde67bdb | 213 | ADMW_GPIO_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 214 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 215 | bool *pbState) |
ADIJake | 0:85855ecd3257 | 216 | { |
ADIJake | 0:85855ecd3257 | 217 | GpioContext *pCtx = reinterpret_cast<GpioContext *>(hDevice); |
ADIJake | 0:85855ecd3257 | 218 | |
ADIJake | 0:85855ecd3257 | 219 | return pCtx->get(ePinId, pbState); |
ADIJake | 0:85855ecd3257 | 220 | } |
ADIJake | 0:85855ecd3257 | 221 | |
ADIJake | 0:85855ecd3257 | 222 | /* |
ADIJake | 0:85855ecd3257 | 223 | * Set the state of the specified GPIO pin |
ADIJake | 0:85855ecd3257 | 224 | */ |
Vkadaba | 5:0728bde67bdb | 225 | ADMW_RESULT admw_GpioSet( |
Vkadaba | 5:0728bde67bdb | 226 | ADMW_GPIO_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 227 | ADMW_GPIO_PIN ePinId, |
ADIJake | 0:85855ecd3257 | 228 | bool bState) |
ADIJake | 0:85855ecd3257 | 229 | { |
ADIJake | 0:85855ecd3257 | 230 | GpioContext *pCtx = reinterpret_cast<GpioContext *>(hDevice); |
ADIJake | 0:85855ecd3257 | 231 | |
ADIJake | 0:85855ecd3257 | 232 | return pCtx->set(ePinId, bState); |
ADIJake | 0:85855ecd3257 | 233 | } |
ADIJake | 0:85855ecd3257 | 234 | |
ADIJake | 0:85855ecd3257 | 235 | /* |
ADIJake | 0:85855ecd3257 | 236 | * Enable interrupt notifications on the specified GPIO pin |
ADIJake | 0:85855ecd3257 | 237 | */ |
Vkadaba | 5:0728bde67bdb | 238 | ADMW_RESULT admw_GpioIrqEnable( |
Vkadaba | 5:0728bde67bdb | 239 | ADMW_GPIO_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 240 | ADMW_GPIO_PIN ePinId, |
Vkadaba | 5:0728bde67bdb | 241 | ADMW_GPIO_CALLBACK callback, |
ADIJake | 0:85855ecd3257 | 242 | void *arg) |
ADIJake | 0:85855ecd3257 | 243 | { |
ADIJake | 0:85855ecd3257 | 244 | GpioContext *pCtx = reinterpret_cast<GpioContext *>(hDevice); |
ADIJake | 0:85855ecd3257 | 245 | |
ADIJake | 0:85855ecd3257 | 246 | return pCtx->enableIrq(ePinId, callback, arg); |
ADIJake | 0:85855ecd3257 | 247 | } |
ADIJake | 0:85855ecd3257 | 248 | |
ADIJake | 0:85855ecd3257 | 249 | /* |
ADIJake | 0:85855ecd3257 | 250 | * Disable interrupt notifications on the specified GPIO pin |
ADIJake | 0:85855ecd3257 | 251 | */ |
Vkadaba | 5:0728bde67bdb | 252 | ADMW_RESULT admw_GpioIrqDisable( |
Vkadaba | 5:0728bde67bdb | 253 | ADMW_GPIO_HANDLE hDevice, |
Vkadaba | 5:0728bde67bdb | 254 | ADMW_GPIO_PIN ePinId) |
ADIJake | 0:85855ecd3257 | 255 | { |
ADIJake | 0:85855ecd3257 | 256 | GpioContext *pCtx = reinterpret_cast<GpioContext *>(hDevice); |
ADIJake | 0:85855ecd3257 | 257 | |
ADIJake | 0:85855ecd3257 | 258 | return pCtx->disableIrq(ePinId); |
ADIJake | 0:85855ecd3257 | 259 | } |
ADIJake | 0:85855ecd3257 | 260 | |
ADIJake | 0:85855ecd3257 | 261 | /* |
ADIJake | 0:85855ecd3257 | 262 | * Close the GPIO interface and free resources |
ADIJake | 0:85855ecd3257 | 263 | */ |
Vkadaba | 5:0728bde67bdb | 264 | void admw_GpioClose( |
Vkadaba | 5:0728bde67bdb | 265 | ADMW_GPIO_HANDLE hDevice) |
ADIJake | 0:85855ecd3257 | 266 | { |
ADIJake | 0:85855ecd3257 | 267 | GpioContext *pCtx = reinterpret_cast<GpioContext *>(hDevice); |
ADIJake | 0:85855ecd3257 | 268 | |
ADIJake | 0:85855ecd3257 | 269 | delete pCtx; |
ADIJake | 0:85855ecd3257 | 270 | } |
ADIJake | 0:85855ecd3257 | 271 | |
ADIJake | 0:85855ecd3257 | 272 | #ifdef __cplusplus |
ADIJake | 0:85855ecd3257 | 273 | } |
ADIJake | 0:85855ecd3257 | 274 | #endif |