Forked repo of Platform Drivers- Analog Devices

Committer:
mahphalke
Date:
Tue Jul 13 13:58:07 2021 +0530
Revision:
17:af1f2416dd26
Child:
20:26b1a4570f4b
Restructured the directory- Removed inc/ and src/ folders and moved all source/header files at root

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mahphalke 17:af1f2416dd26 1 /***************************************************************************//**
mahphalke 17:af1f2416dd26 2 * @file irq.cpp
mahphalke 17:af1f2416dd26 3 * @brief Implementation of Interrupt Mbed platform driver interfaces
mahphalke 17:af1f2416dd26 4 ********************************************************************************
mahphalke 17:af1f2416dd26 5 * Copyright (c) 2020-2021 Analog Devices, Inc.
mahphalke 17:af1f2416dd26 6 * All rights reserved.
mahphalke 17:af1f2416dd26 7 *
mahphalke 17:af1f2416dd26 8 * This software is proprietary to Analog Devices, Inc. and its licensors.
mahphalke 17:af1f2416dd26 9 * By using this software you agree to the terms of the associated
mahphalke 17:af1f2416dd26 10 * Analog Devices Software License Agreement.
mahphalke 17:af1f2416dd26 11 *******************************************************************************/
mahphalke 17:af1f2416dd26 12
mahphalke 17:af1f2416dd26 13 /******************************************************************************/
mahphalke 17:af1f2416dd26 14 /***************************** Include Files **********************************/
mahphalke 17:af1f2416dd26 15 /******************************************************************************/
mahphalke 17:af1f2416dd26 16
mahphalke 17:af1f2416dd26 17 #include <stdio.h>
mahphalke 17:af1f2416dd26 18 #include <mbed.h>
mahphalke 17:af1f2416dd26 19
mahphalke 17:af1f2416dd26 20 // Platform support needs to be C-compatible to work with other drivers
mahphalke 17:af1f2416dd26 21 #ifdef __cplusplus
mahphalke 17:af1f2416dd26 22 extern "C"
mahphalke 17:af1f2416dd26 23 {
mahphalke 17:af1f2416dd26 24 #endif
mahphalke 17:af1f2416dd26 25
mahphalke 17:af1f2416dd26 26 #include "error.h"
mahphalke 17:af1f2416dd26 27 #include "irq.h"
mahphalke 17:af1f2416dd26 28 #include "irq_extra.h"
mahphalke 17:af1f2416dd26 29 #include "uart_extra.h"
mahphalke 17:af1f2416dd26 30
mahphalke 17:af1f2416dd26 31 /******************************************************************************/
mahphalke 17:af1f2416dd26 32 /*************************** Types Declarations *******************************/
mahphalke 17:af1f2416dd26 33 /******************************************************************************/
mahphalke 17:af1f2416dd26 34
mahphalke 17:af1f2416dd26 35 using namespace std::chrono;
mahphalke 17:af1f2416dd26 36
mahphalke 17:af1f2416dd26 37 /**
mahphalke 17:af1f2416dd26 38 * @struct mbed_irq_callback_desc
mahphalke 17:af1f2416dd26 39 * @brief Structure holding the callback functions for mbed irqs
mahphalke 17:af1f2416dd26 40 * @note The callback functions are mapped with 'irq_id' structure
mahphalke 17:af1f2416dd26 41 */
mahphalke 17:af1f2416dd26 42 typedef struct {
mahphalke 17:af1f2416dd26 43 struct callback_desc callback_ext_int_id1;
mahphalke 17:af1f2416dd26 44 struct callback_desc callback_ext_int_id2;
mahphalke 17:af1f2416dd26 45 struct callback_desc callback_ext_int_id3;
mahphalke 17:af1f2416dd26 46 struct callback_desc callback_ext_int_id4;
mahphalke 17:af1f2416dd26 47 struct callback_desc callback_ext_int_id5;
mahphalke 17:af1f2416dd26 48 struct callback_desc callback_uart_rx_id1;
mahphalke 17:af1f2416dd26 49 struct callback_desc callback_ticker_id;
mahphalke 17:af1f2416dd26 50 } mbed_irq_callback_desc;
mahphalke 17:af1f2416dd26 51
mahphalke 17:af1f2416dd26 52 /* Mbed callback function pointer typedef */
mahphalke 17:af1f2416dd26 53 typedef void(*mbed_callback_func)(void);
mahphalke 17:af1f2416dd26 54
mahphalke 17:af1f2416dd26 55 /* Mbed irq callback structure variable */
mahphalke 17:af1f2416dd26 56 static mbed_irq_callback_desc mbed_irq_callbacks;
mahphalke 17:af1f2416dd26 57
mahphalke 17:af1f2416dd26 58 /******************************************************************************/
mahphalke 17:af1f2416dd26 59 /************************ Functions Declarations ******************************/
mahphalke 17:af1f2416dd26 60 /******************************************************************************/
mahphalke 17:af1f2416dd26 61
mahphalke 17:af1f2416dd26 62 /******************************************************************************/
mahphalke 17:af1f2416dd26 63 /************************ Functions Definitions *******************************/
mahphalke 17:af1f2416dd26 64 /******************************************************************************/
mahphalke 17:af1f2416dd26 65
mahphalke 17:af1f2416dd26 66 /**
mahphalke 17:af1f2416dd26 67 * @brief Mbed callback function for external interrupt ID1 event
mahphalke 17:af1f2416dd26 68 * @return none
mahphalke 17:af1f2416dd26 69 */
mahphalke 17:af1f2416dd26 70 static void mbed_ext_int_id1_callback(void)
mahphalke 17:af1f2416dd26 71 {
mahphalke 17:af1f2416dd26 72 if (mbed_irq_callbacks.callback_ext_int_id1.callback) {
mahphalke 17:af1f2416dd26 73 mbed_irq_callbacks.callback_ext_int_id1.callback(
mahphalke 17:af1f2416dd26 74 mbed_irq_callbacks.callback_ext_int_id1.ctx, EXTERNAL_INT_ID1, NULL);
mahphalke 17:af1f2416dd26 75 }
mahphalke 17:af1f2416dd26 76 }
mahphalke 17:af1f2416dd26 77
mahphalke 17:af1f2416dd26 78
mahphalke 17:af1f2416dd26 79 /**
mahphalke 17:af1f2416dd26 80 * @brief Mbed callback function for external interrupt ID2 event
mahphalke 17:af1f2416dd26 81 * @return none
mahphalke 17:af1f2416dd26 82 */
mahphalke 17:af1f2416dd26 83 static void mbed_ext_int_id2_callback(void)
mahphalke 17:af1f2416dd26 84 {
mahphalke 17:af1f2416dd26 85 if (mbed_irq_callbacks.callback_ext_int_id2.callback) {
mahphalke 17:af1f2416dd26 86 mbed_irq_callbacks.callback_ext_int_id2.callback(
mahphalke 17:af1f2416dd26 87 mbed_irq_callbacks.callback_ext_int_id2.ctx, EXTERNAL_INT_ID2, NULL);
mahphalke 17:af1f2416dd26 88 }
mahphalke 17:af1f2416dd26 89 }
mahphalke 17:af1f2416dd26 90
mahphalke 17:af1f2416dd26 91
mahphalke 17:af1f2416dd26 92 /**
mahphalke 17:af1f2416dd26 93 * @brief Mbed callback function for external interrupt ID3 event
mahphalke 17:af1f2416dd26 94 * @return none
mahphalke 17:af1f2416dd26 95 */
mahphalke 17:af1f2416dd26 96 static void mbed_ext_int_id3_callback(void)
mahphalke 17:af1f2416dd26 97 {
mahphalke 17:af1f2416dd26 98 if (mbed_irq_callbacks.callback_ext_int_id3.callback) {
mahphalke 17:af1f2416dd26 99 mbed_irq_callbacks.callback_ext_int_id3.callback(
mahphalke 17:af1f2416dd26 100 mbed_irq_callbacks.callback_ext_int_id3.ctx, EXTERNAL_INT_ID3, NULL);
mahphalke 17:af1f2416dd26 101 }
mahphalke 17:af1f2416dd26 102 }
mahphalke 17:af1f2416dd26 103
mahphalke 17:af1f2416dd26 104
mahphalke 17:af1f2416dd26 105 /**
mahphalke 17:af1f2416dd26 106 * @brief Mbed callback function for external interrupt ID4 event
mahphalke 17:af1f2416dd26 107 * @return none
mahphalke 17:af1f2416dd26 108 */
mahphalke 17:af1f2416dd26 109 static void mbed_ext_int_id4_callback(void)
mahphalke 17:af1f2416dd26 110 {
mahphalke 17:af1f2416dd26 111 if (mbed_irq_callbacks.callback_ext_int_id4.callback) {
mahphalke 17:af1f2416dd26 112 mbed_irq_callbacks.callback_ext_int_id4.callback(
mahphalke 17:af1f2416dd26 113 mbed_irq_callbacks.callback_ext_int_id4.ctx, EXTERNAL_INT_ID4, NULL);
mahphalke 17:af1f2416dd26 114 }
mahphalke 17:af1f2416dd26 115 }
mahphalke 17:af1f2416dd26 116
mahphalke 17:af1f2416dd26 117
mahphalke 17:af1f2416dd26 118 /**
mahphalke 17:af1f2416dd26 119 * @brief Mbed callback function for external interrupt ID5 event
mahphalke 17:af1f2416dd26 120 * @return none
mahphalke 17:af1f2416dd26 121 */
mahphalke 17:af1f2416dd26 122 static void mbed_ext_int_id5_callback(void)
mahphalke 17:af1f2416dd26 123 {
mahphalke 17:af1f2416dd26 124 if (mbed_irq_callbacks.callback_ext_int_id5.callback) {
mahphalke 17:af1f2416dd26 125 mbed_irq_callbacks.callback_ext_int_id5.callback(
mahphalke 17:af1f2416dd26 126 mbed_irq_callbacks.callback_ext_int_id5.ctx, EXTERNAL_INT_ID5, NULL);
mahphalke 17:af1f2416dd26 127 }
mahphalke 17:af1f2416dd26 128 }
mahphalke 17:af1f2416dd26 129
mahphalke 17:af1f2416dd26 130
mahphalke 17:af1f2416dd26 131 /**
mahphalke 17:af1f2416dd26 132 * @brief Mbed callback function for UART Rx ID1 event
mahphalke 17:af1f2416dd26 133 * @return none
mahphalke 17:af1f2416dd26 134 */
mahphalke 17:af1f2416dd26 135 static void mbed_uart_rx_id1_callback(void)
mahphalke 17:af1f2416dd26 136 {
mahphalke 17:af1f2416dd26 137 if (mbed_irq_callbacks.callback_uart_rx_id1.callback) {
mahphalke 17:af1f2416dd26 138 mbed_irq_callbacks.callback_uart_rx_id1.callback(
mahphalke 17:af1f2416dd26 139 mbed_irq_callbacks.callback_uart_rx_id1.ctx, UART_RX_INT_ID1, NULL);
mahphalke 17:af1f2416dd26 140 }
mahphalke 17:af1f2416dd26 141 }
mahphalke 17:af1f2416dd26 142
mahphalke 17:af1f2416dd26 143
mahphalke 17:af1f2416dd26 144 /**
mahphalke 17:af1f2416dd26 145 * @brief Mbed callback function for ticker ID event
mahphalke 17:af1f2416dd26 146 * @return none
mahphalke 17:af1f2416dd26 147 */
mahphalke 17:af1f2416dd26 148 static void mbed_ticker_id_callback(void)
mahphalke 17:af1f2416dd26 149 {
mahphalke 17:af1f2416dd26 150 if (mbed_irq_callbacks.callback_ticker_id.callback) {
mahphalke 17:af1f2416dd26 151 mbed_irq_callbacks.callback_ticker_id.callback(
mahphalke 17:af1f2416dd26 152 mbed_irq_callbacks.callback_ticker_id.ctx, TICKER_INT_ID, NULL);
mahphalke 17:af1f2416dd26 153 }
mahphalke 17:af1f2416dd26 154 }
mahphalke 17:af1f2416dd26 155
mahphalke 17:af1f2416dd26 156
mahphalke 17:af1f2416dd26 157 /**
mahphalke 17:af1f2416dd26 158 * @brief Initialized the controller for the peripheral interrupts
mahphalke 17:af1f2416dd26 159 * @param desc[in, out] - Pointer where the configured instance is stored
mahphalke 17:af1f2416dd26 160 * @param param[in] - Configuration information for the instance
mahphalke 17:af1f2416dd26 161 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 162 */
mahphalke 17:af1f2416dd26 163 int32_t irq_ctrl_init(struct irq_ctrl_desc **desc,
mahphalke 17:af1f2416dd26 164 const struct irq_init_param *param)
mahphalke 17:af1f2416dd26 165 {
mahphalke 17:af1f2416dd26 166 mbed::Ticker *ticker;
mahphalke 17:af1f2416dd26 167 mbed_irq_desc *new_mbed_desc;
mahphalke 17:af1f2416dd26 168
mahphalke 17:af1f2416dd26 169 if (!desc || !param) {
mahphalke 17:af1f2416dd26 170 return FAILURE;
mahphalke 17:af1f2416dd26 171 }
mahphalke 17:af1f2416dd26 172
mahphalke 17:af1f2416dd26 173 irq_ctrl_desc *new_desc = (irq_ctrl_desc *)malloc(sizeof(irq_ctrl_desc));
mahphalke 17:af1f2416dd26 174 if (!new_desc) {
mahphalke 17:af1f2416dd26 175 goto err_new_desc;
mahphalke 17:af1f2416dd26 176 }
mahphalke 17:af1f2416dd26 177
mahphalke 17:af1f2416dd26 178 new_mbed_desc = (mbed_irq_desc *)malloc(sizeof(mbed_irq_desc));
mahphalke 17:af1f2416dd26 179 if (!new_mbed_desc) {
mahphalke 17:af1f2416dd26 180 goto err_new_mbed_desc;
mahphalke 17:af1f2416dd26 181 }
mahphalke 17:af1f2416dd26 182
mahphalke 17:af1f2416dd26 183 new_desc->irq_ctrl_id = param->irq_ctrl_id;
mahphalke 17:af1f2416dd26 184
mahphalke 17:af1f2416dd26 185 new_mbed_desc->int_mode = ((mbed_irq_init_param *)param->extra)->int_mode;
mahphalke 17:af1f2416dd26 186 new_mbed_desc->int_obj_type = ((mbed_irq_init_param *)
mahphalke 17:af1f2416dd26 187 param->extra)->int_obj_type;
mahphalke 17:af1f2416dd26 188 new_mbed_desc->ext_int_pin = ((mbed_irq_init_param *)
mahphalke 17:af1f2416dd26 189 param->extra)->ext_int_pin;
mahphalke 17:af1f2416dd26 190
mahphalke 17:af1f2416dd26 191 /* Ticker is a special mbed class used for generating recurring interrupt.
mahphalke 17:af1f2416dd26 192 * The object of this class is created during interrupt initialization as:
mahphalke 17:af1f2416dd26 193 * 1) To avoid having seperate module for it.
mahphalke 17:af1f2416dd26 194 * 2) To avoid having multiple instances of Ticker class
mahphalke 17:af1f2416dd26 195 * */
mahphalke 17:af1f2416dd26 196 if (param->irq_ctrl_id == TICKER_INT_ID) {
mahphalke 17:af1f2416dd26 197 /* Create new instance of Ticker class */
mahphalke 17:af1f2416dd26 198 ticker = new Ticker();
mahphalke 17:af1f2416dd26 199 if (!ticker) {
mahphalke 17:af1f2416dd26 200 goto err_ticker;
mahphalke 17:af1f2416dd26 201 }
mahphalke 17:af1f2416dd26 202
mahphalke 17:af1f2416dd26 203 new_mbed_desc->int_obj_type = (mbed::Ticker *)ticker;
mahphalke 17:af1f2416dd26 204 new_mbed_desc->ticker_period_usec = ((mbed_irq_init_param *)
mahphalke 17:af1f2416dd26 205 param->extra)->ticker_period_usec;
mahphalke 17:af1f2416dd26 206 }
mahphalke 17:af1f2416dd26 207
mahphalke 17:af1f2416dd26 208 new_desc->extra = (irq_ctrl_desc *)new_mbed_desc;
mahphalke 17:af1f2416dd26 209
mahphalke 17:af1f2416dd26 210 *desc = new_desc;
mahphalke 17:af1f2416dd26 211
mahphalke 17:af1f2416dd26 212 return SUCCESS;
mahphalke 17:af1f2416dd26 213
mahphalke 17:af1f2416dd26 214 err_ticker:
mahphalke 17:af1f2416dd26 215 free(new_mbed_desc);
mahphalke 17:af1f2416dd26 216 err_new_mbed_desc:
mahphalke 17:af1f2416dd26 217 free(new_desc);
mahphalke 17:af1f2416dd26 218 err_new_desc:
mahphalke 17:af1f2416dd26 219 // Nothing to free
mahphalke 17:af1f2416dd26 220
mahphalke 17:af1f2416dd26 221 return FAILURE;
mahphalke 17:af1f2416dd26 222 }
mahphalke 17:af1f2416dd26 223
mahphalke 17:af1f2416dd26 224
mahphalke 17:af1f2416dd26 225 /**
mahphalke 17:af1f2416dd26 226 * @brief Free the resources allocated by irq_ctrl_init()
mahphalke 17:af1f2416dd26 227 * @param desc[in, out] - Interrupt controller descriptor.
mahphalke 17:af1f2416dd26 228 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 229 */
mahphalke 17:af1f2416dd26 230 int32_t irq_ctrl_remove(struct irq_ctrl_desc *desc)
mahphalke 17:af1f2416dd26 231 {
mahphalke 17:af1f2416dd26 232 uint8_t irq_id;
mahphalke 17:af1f2416dd26 233
mahphalke 17:af1f2416dd26 234 if (!desc) {
mahphalke 17:af1f2416dd26 235 return FAILURE;
mahphalke 17:af1f2416dd26 236 }
mahphalke 17:af1f2416dd26 237
mahphalke 17:af1f2416dd26 238 if (((mbed_irq_desc *)desc->extra)->int_obj) {
mahphalke 17:af1f2416dd26 239 free(((mbed_irq_desc *)desc->extra)->int_obj);
mahphalke 17:af1f2416dd26 240 }
mahphalke 17:af1f2416dd26 241
mahphalke 17:af1f2416dd26 242 /* Unregister all callbacks */
mahphalke 17:af1f2416dd26 243 for (irq_id = 0; irq_id < (uint8_t)NB_INTERRUPTS; irq_id++) {
mahphalke 17:af1f2416dd26 244 if (irq_unregister(desc, irq_id) != SUCCESS)
mahphalke 17:af1f2416dd26 245 return FAILURE;
mahphalke 17:af1f2416dd26 246 }
mahphalke 17:af1f2416dd26 247
mahphalke 17:af1f2416dd26 248 if ((irq_ctrl_desc *)desc->extra) {
mahphalke 17:af1f2416dd26 249 free((irq_ctrl_desc *)desc->extra);
mahphalke 17:af1f2416dd26 250 }
mahphalke 17:af1f2416dd26 251
mahphalke 17:af1f2416dd26 252 free(desc);
mahphalke 17:af1f2416dd26 253
mahphalke 17:af1f2416dd26 254 return SUCCESS;
mahphalke 17:af1f2416dd26 255 }
mahphalke 17:af1f2416dd26 256
mahphalke 17:af1f2416dd26 257
mahphalke 17:af1f2416dd26 258 /**
mahphalke 17:af1f2416dd26 259 * @brief Registers a IRQ callback function to irq controller.
mahphalke 17:af1f2416dd26 260 * @param desc[in] - The IRQ controller descriptor.
mahphalke 17:af1f2416dd26 261 * @param irq_id[in] - Interrupt identifier.
mahphalke 17:af1f2416dd26 262 * @param callback_desc - Descriptor of the callback. If it is NULL, the
mahphalke 17:af1f2416dd26 263 * callback will be unregistered
mahphalke 17:af1f2416dd26 264 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 265 */
mahphalke 17:af1f2416dd26 266 int32_t irq_register_callback(struct irq_ctrl_desc *desc,
mahphalke 17:af1f2416dd26 267 uint32_t irq_id,
mahphalke 17:af1f2416dd26 268 struct callback_desc *callback_desc)
mahphalke 17:af1f2416dd26 269 {
mahphalke 17:af1f2416dd26 270 InterruptIn *ext_interrupt;
mahphalke 17:af1f2416dd26 271 mbed::UnbufferedSerial *uart_rx_port;
mahphalke 17:af1f2416dd26 272 mbed::Ticker *ticker;
mahphalke 17:af1f2416dd26 273 PinName ext_int_pin;
mahphalke 17:af1f2416dd26 274 mbed_callback_func mbed_callback;
mahphalke 17:af1f2416dd26 275
mahphalke 17:af1f2416dd26 276 if (!desc || !callback_desc) {
mahphalke 17:af1f2416dd26 277 return FAILURE;
mahphalke 17:af1f2416dd26 278 }
mahphalke 17:af1f2416dd26 279
mahphalke 17:af1f2416dd26 280 switch (irq_id) {
mahphalke 17:af1f2416dd26 281 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 282 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 283 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 284 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 285 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 286 /* Attach external interrupt to input pin */
mahphalke 17:af1f2416dd26 287 ext_int_pin = (PinName)((mbed_irq_desc *)(desc->extra))->ext_int_pin;
mahphalke 17:af1f2416dd26 288 if (!ext_int_pin) {
mahphalke 17:af1f2416dd26 289 return FAILURE;
mahphalke 17:af1f2416dd26 290 }
mahphalke 17:af1f2416dd26 291
mahphalke 17:af1f2416dd26 292 ext_interrupt = new InterruptIn(ext_int_pin);
mahphalke 17:af1f2416dd26 293 if (!ext_interrupt) {
mahphalke 17:af1f2416dd26 294 return FAILURE;
mahphalke 17:af1f2416dd26 295 }
mahphalke 17:af1f2416dd26 296
mahphalke 17:af1f2416dd26 297 switch (irq_id) {
mahphalke 17:af1f2416dd26 298 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 299 mbed_irq_callbacks.callback_ext_int_id1.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 300 mbed_irq_callbacks.callback_ext_int_id1.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 301 mbed_callback = mbed_ext_int_id1_callback;
mahphalke 17:af1f2416dd26 302 break;
mahphalke 17:af1f2416dd26 303
mahphalke 17:af1f2416dd26 304 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 305 mbed_irq_callbacks.callback_ext_int_id2.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 306 mbed_irq_callbacks.callback_ext_int_id2.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 307 mbed_callback = mbed_ext_int_id2_callback;
mahphalke 17:af1f2416dd26 308 break;
mahphalke 17:af1f2416dd26 309
mahphalke 17:af1f2416dd26 310 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 311 mbed_irq_callbacks.callback_ext_int_id3.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 312 mbed_irq_callbacks.callback_ext_int_id3.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 313 mbed_callback = mbed_ext_int_id3_callback;
mahphalke 17:af1f2416dd26 314 break;
mahphalke 17:af1f2416dd26 315
mahphalke 17:af1f2416dd26 316 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 317 mbed_irq_callbacks.callback_ext_int_id4.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 318 mbed_irq_callbacks.callback_ext_int_id4.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 319 mbed_callback = mbed_ext_int_id4_callback;
mahphalke 17:af1f2416dd26 320 break;
mahphalke 17:af1f2416dd26 321
mahphalke 17:af1f2416dd26 322 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 323 mbed_irq_callbacks.callback_ext_int_id5.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 324 mbed_irq_callbacks.callback_ext_int_id5.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 325 mbed_callback = mbed_ext_int_id5_callback;
mahphalke 17:af1f2416dd26 326 break;
mahphalke 17:af1f2416dd26 327
mahphalke 17:af1f2416dd26 328 default:
mahphalke 17:af1f2416dd26 329 return FAILURE;
mahphalke 17:af1f2416dd26 330 }
mahphalke 17:af1f2416dd26 331
mahphalke 17:af1f2416dd26 332 /* Register a callback function to external interrupt event */
mahphalke 17:af1f2416dd26 333 if (((mbed_irq_desc *)(desc->extra))->int_mode == EXT_IRQ_FALL) {
mahphalke 17:af1f2416dd26 334 ext_interrupt->fall(mbed_callback);
mahphalke 17:af1f2416dd26 335 } else if (((mbed_irq_desc *)(desc->extra))->int_mode == EXT_IRQ_RISE) {
mahphalke 17:af1f2416dd26 336 ext_interrupt->rise(mbed_callback);
mahphalke 17:af1f2416dd26 337 } else {
mahphalke 17:af1f2416dd26 338 return FAILURE;
mahphalke 17:af1f2416dd26 339 }
mahphalke 17:af1f2416dd26 340
mahphalke 17:af1f2416dd26 341 /* Store the external interrupt object to be freed from irq_ctrl_remove() */
mahphalke 17:af1f2416dd26 342 ((mbed_irq_desc *)(desc->extra))->int_obj = ext_interrupt;
mahphalke 17:af1f2416dd26 343
mahphalke 17:af1f2416dd26 344 ext_interrupt->enable_irq();
mahphalke 17:af1f2416dd26 345
mahphalke 17:af1f2416dd26 346 break;
mahphalke 17:af1f2416dd26 347
mahphalke 17:af1f2416dd26 348 case UART_RX_INT_ID1:
mahphalke 17:af1f2416dd26 349 uart_rx_port = (mbed::UnbufferedSerial *)(((mbed_irq_desc *)(
mahphalke 17:af1f2416dd26 350 desc->extra))->int_obj_type);
mahphalke 17:af1f2416dd26 351 if (!uart_rx_port) {
mahphalke 17:af1f2416dd26 352 return FAILURE;
mahphalke 17:af1f2416dd26 353 }
mahphalke 17:af1f2416dd26 354
mahphalke 17:af1f2416dd26 355 mbed_irq_callbacks.callback_uart_rx_id1.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 356 mbed_irq_callbacks.callback_uart_rx_id1.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 357
mahphalke 17:af1f2416dd26 358 /* Register a callback function to receive UnbufferedSerial port event */
mahphalke 17:af1f2416dd26 359 uart_rx_port->attach(mbed_uart_rx_id1_callback, UnbufferedSerial::RxIrq);
mahphalke 17:af1f2416dd26 360
mahphalke 17:af1f2416dd26 361 break;
mahphalke 17:af1f2416dd26 362
mahphalke 17:af1f2416dd26 363 case TICKER_INT_ID:
mahphalke 17:af1f2416dd26 364 /* Create the new ticker instance */
mahphalke 17:af1f2416dd26 365 ticker = (mbed::Ticker *)(((mbed_irq_desc *)(
mahphalke 17:af1f2416dd26 366 desc->extra))->int_obj_type);
mahphalke 17:af1f2416dd26 367 if (!ticker) {
mahphalke 17:af1f2416dd26 368 return FAILURE;
mahphalke 17:af1f2416dd26 369 }
mahphalke 17:af1f2416dd26 370
mahphalke 17:af1f2416dd26 371 mbed_irq_callbacks.callback_ticker_id.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 372 mbed_irq_callbacks.callback_ticker_id.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 373
mahphalke 17:af1f2416dd26 374 ticker->attach(mbed_ticker_id_callback,
mahphalke 17:af1f2416dd26 375 microseconds(((mbed_irq_desc *)(desc->extra))->ticker_period_usec));
mahphalke 17:af1f2416dd26 376 break;
mahphalke 17:af1f2416dd26 377
mahphalke 17:af1f2416dd26 378 default:
mahphalke 17:af1f2416dd26 379 return FAILURE;
mahphalke 17:af1f2416dd26 380 }
mahphalke 17:af1f2416dd26 381
mahphalke 17:af1f2416dd26 382 return SUCCESS;
mahphalke 17:af1f2416dd26 383 }
mahphalke 17:af1f2416dd26 384
mahphalke 17:af1f2416dd26 385
mahphalke 17:af1f2416dd26 386 /**
mahphalke 17:af1f2416dd26 387 * @brief Unregister a IRQ callback function.
mahphalke 17:af1f2416dd26 388 * @param desc[in] - The IRQ controller descriptor.
mahphalke 17:af1f2416dd26 389 * @param irq_id[in] - Interrupt identifier.
mahphalke 17:af1f2416dd26 390 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 391 */
mahphalke 17:af1f2416dd26 392 int32_t irq_unregister(struct irq_ctrl_desc *desc, uint32_t irq_id)
mahphalke 17:af1f2416dd26 393 {
mahphalke 17:af1f2416dd26 394 if (!desc) {
mahphalke 17:af1f2416dd26 395 return FAILURE;
mahphalke 17:af1f2416dd26 396 }
mahphalke 17:af1f2416dd26 397
mahphalke 17:af1f2416dd26 398 switch (irq_id) {
mahphalke 17:af1f2416dd26 399 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 400 mbed_irq_callbacks.callback_ext_int_id1.callback = NULL;
mahphalke 17:af1f2416dd26 401 break;
mahphalke 17:af1f2416dd26 402
mahphalke 17:af1f2416dd26 403 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 404 mbed_irq_callbacks.callback_ext_int_id2.callback = NULL;
mahphalke 17:af1f2416dd26 405 break;
mahphalke 17:af1f2416dd26 406
mahphalke 17:af1f2416dd26 407 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 408 mbed_irq_callbacks.callback_ext_int_id3.callback = NULL;
mahphalke 17:af1f2416dd26 409 break;
mahphalke 17:af1f2416dd26 410
mahphalke 17:af1f2416dd26 411 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 412 mbed_irq_callbacks.callback_ext_int_id4.callback = NULL;
mahphalke 17:af1f2416dd26 413 break;
mahphalke 17:af1f2416dd26 414
mahphalke 17:af1f2416dd26 415 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 416 mbed_irq_callbacks.callback_ext_int_id5.callback = NULL;
mahphalke 17:af1f2416dd26 417 break;
mahphalke 17:af1f2416dd26 418
mahphalke 17:af1f2416dd26 419 case UART_RX_INT_ID1:
mahphalke 17:af1f2416dd26 420 mbed_irq_callbacks.callback_uart_rx_id1.callback = NULL;
mahphalke 17:af1f2416dd26 421 break;
mahphalke 17:af1f2416dd26 422
mahphalke 17:af1f2416dd26 423 case TICKER_INT_ID:
mahphalke 17:af1f2416dd26 424 mbed_irq_callbacks.callback_ticker_id.callback = NULL;
mahphalke 17:af1f2416dd26 425 break;
mahphalke 17:af1f2416dd26 426
mahphalke 17:af1f2416dd26 427 default:
mahphalke 17:af1f2416dd26 428 return FAILURE;
mahphalke 17:af1f2416dd26 429 }
mahphalke 17:af1f2416dd26 430
mahphalke 17:af1f2416dd26 431 return SUCCESS;
mahphalke 17:af1f2416dd26 432 }
mahphalke 17:af1f2416dd26 433
mahphalke 17:af1f2416dd26 434 #ifdef __cplusplus // Closing extern c
mahphalke 17:af1f2416dd26 435 }
mahphalke 17:af1f2416dd26 436 #endif