Forked repo of Platform Drivers- Analog Devices

Committer:
Janani Sunil
Date:
Mon Nov 22 22:26:51 2021 +0530
Revision:
20:26b1a4570f4b
Parent:
17:af1f2416dd26
The following changes were made:
1.) Modified udelay() function for generating more accurate smaller usec delays
2.) Implemented the irq_enable and irq_disable functions
3.) Removed the confusion b/w application created peripheral object and interrupt specific object
4.) Created PWM extra init structure and added PWM pin as it's member for multiplatform project compatibility
5.) Added a module for timer and its related header file

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;
Janani Sunil 20:26b1a4570f4b 167 InterruptIn *ext_interrupt;
mahphalke 17:af1f2416dd26 168 mbed_irq_desc *new_mbed_desc;
mahphalke 17:af1f2416dd26 169
mahphalke 17:af1f2416dd26 170 if (!desc || !param) {
mahphalke 17:af1f2416dd26 171 return FAILURE;
mahphalke 17:af1f2416dd26 172 }
mahphalke 17:af1f2416dd26 173
mahphalke 17:af1f2416dd26 174 irq_ctrl_desc *new_desc = (irq_ctrl_desc *)malloc(sizeof(irq_ctrl_desc));
mahphalke 17:af1f2416dd26 175 if (!new_desc) {
mahphalke 17:af1f2416dd26 176 goto err_new_desc;
mahphalke 17:af1f2416dd26 177 }
mahphalke 17:af1f2416dd26 178
mahphalke 17:af1f2416dd26 179 new_mbed_desc = (mbed_irq_desc *)malloc(sizeof(mbed_irq_desc));
mahphalke 17:af1f2416dd26 180 if (!new_mbed_desc) {
mahphalke 17:af1f2416dd26 181 goto err_new_mbed_desc;
mahphalke 17:af1f2416dd26 182 }
mahphalke 17:af1f2416dd26 183
mahphalke 17:af1f2416dd26 184 new_desc->irq_ctrl_id = param->irq_ctrl_id;
mahphalke 17:af1f2416dd26 185 new_mbed_desc->int_mode = ((mbed_irq_init_param *)param->extra)->int_mode;
mahphalke 17:af1f2416dd26 186 new_mbed_desc->ext_int_pin = ((mbed_irq_init_param *)
mahphalke 17:af1f2416dd26 187 param->extra)->ext_int_pin;
mahphalke 17:af1f2416dd26 188
Janani Sunil 20:26b1a4570f4b 189 switch (param->irq_ctrl_id) {
Janani Sunil 20:26b1a4570f4b 190 case EXTERNAL_INT_ID1:
Janani Sunil 20:26b1a4570f4b 191 case EXTERNAL_INT_ID2:
Janani Sunil 20:26b1a4570f4b 192 case EXTERNAL_INT_ID3:
Janani Sunil 20:26b1a4570f4b 193 case EXTERNAL_INT_ID4:
Janani Sunil 20:26b1a4570f4b 194 case EXTERNAL_INT_ID5:
Janani Sunil 20:26b1a4570f4b 195 /* Create a new external interrupt object */
Janani Sunil 20:26b1a4570f4b 196 ext_interrupt = new InterruptIn((PinName)(new_mbed_desc->ext_int_pin));
Janani Sunil 20:26b1a4570f4b 197 if (!ext_interrupt) {
Janani Sunil 20:26b1a4570f4b 198 goto err_interrupt;
Janani Sunil 20:26b1a4570f4b 199 }
Janani Sunil 20:26b1a4570f4b 200
Janani Sunil 20:26b1a4570f4b 201 new_mbed_desc->int_obj = (mbed::InterruptIn *)ext_interrupt;
Janani Sunil 20:26b1a4570f4b 202 break;
Janani Sunil 20:26b1a4570f4b 203
Janani Sunil 20:26b1a4570f4b 204 case TICKER_INT_ID:
Janani Sunil 20:26b1a4570f4b 205 /* Ticker is a special mbed class used for generating recurring interrupt.
Janani Sunil 20:26b1a4570f4b 206 * The object of this class is created during interrupt initialization as:
Janani Sunil 20:26b1a4570f4b 207 * 1) To avoid having seperate module for it.
Janani Sunil 20:26b1a4570f4b 208 * 2) To avoid having multiple instances of Ticker class
Janani Sunil 20:26b1a4570f4b 209 * */
mahphalke 17:af1f2416dd26 210 ticker = new Ticker();
mahphalke 17:af1f2416dd26 211 if (!ticker) {
Janani Sunil 20:26b1a4570f4b 212 goto err_interrupt;
mahphalke 17:af1f2416dd26 213 }
mahphalke 17:af1f2416dd26 214
Janani Sunil 20:26b1a4570f4b 215 new_mbed_desc->int_obj = (mbed::Ticker *)ticker;
mahphalke 17:af1f2416dd26 216 new_mbed_desc->ticker_period_usec = ((mbed_irq_init_param *)
mahphalke 17:af1f2416dd26 217 param->extra)->ticker_period_usec;
Janani Sunil 20:26b1a4570f4b 218 break;
Janani Sunil 20:26b1a4570f4b 219
Janani Sunil 20:26b1a4570f4b 220 case UART_RX_INT_ID1:
Janani Sunil 20:26b1a4570f4b 221 /* UART object must be created from uart.cpp module by an application */
Janani Sunil 20:26b1a4570f4b 222 new_mbed_desc->int_obj = ((mbed_irq_init_param *)
Janani Sunil 20:26b1a4570f4b 223 param->extra)->int_obj_type;
Janani Sunil 20:26b1a4570f4b 224 break;
Janani Sunil 20:26b1a4570f4b 225
Janani Sunil 20:26b1a4570f4b 226 default:
Janani Sunil 20:26b1a4570f4b 227 goto err_interrupt;
mahphalke 17:af1f2416dd26 228 }
mahphalke 17:af1f2416dd26 229
mahphalke 17:af1f2416dd26 230 new_desc->extra = (irq_ctrl_desc *)new_mbed_desc;
mahphalke 17:af1f2416dd26 231
mahphalke 17:af1f2416dd26 232 *desc = new_desc;
mahphalke 17:af1f2416dd26 233
mahphalke 17:af1f2416dd26 234 return SUCCESS;
mahphalke 17:af1f2416dd26 235
Janani Sunil 20:26b1a4570f4b 236 err_interrupt:
mahphalke 17:af1f2416dd26 237 free(new_mbed_desc);
mahphalke 17:af1f2416dd26 238 err_new_mbed_desc:
mahphalke 17:af1f2416dd26 239 free(new_desc);
mahphalke 17:af1f2416dd26 240 err_new_desc:
mahphalke 17:af1f2416dd26 241 // Nothing to free
mahphalke 17:af1f2416dd26 242
mahphalke 17:af1f2416dd26 243 return FAILURE;
mahphalke 17:af1f2416dd26 244 }
mahphalke 17:af1f2416dd26 245
mahphalke 17:af1f2416dd26 246
mahphalke 17:af1f2416dd26 247 /**
mahphalke 17:af1f2416dd26 248 * @brief Free the resources allocated by irq_ctrl_init()
mahphalke 17:af1f2416dd26 249 * @param desc[in, out] - Interrupt controller descriptor.
mahphalke 17:af1f2416dd26 250 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 251 */
mahphalke 17:af1f2416dd26 252 int32_t irq_ctrl_remove(struct irq_ctrl_desc *desc)
mahphalke 17:af1f2416dd26 253 {
mahphalke 17:af1f2416dd26 254 uint8_t irq_id;
mahphalke 17:af1f2416dd26 255
mahphalke 17:af1f2416dd26 256 if (!desc) {
mahphalke 17:af1f2416dd26 257 return FAILURE;
mahphalke 17:af1f2416dd26 258 }
mahphalke 17:af1f2416dd26 259
mahphalke 17:af1f2416dd26 260 if (((mbed_irq_desc *)desc->extra)->int_obj) {
mahphalke 17:af1f2416dd26 261 free(((mbed_irq_desc *)desc->extra)->int_obj);
mahphalke 17:af1f2416dd26 262 }
mahphalke 17:af1f2416dd26 263
mahphalke 17:af1f2416dd26 264 /* Unregister all callbacks */
mahphalke 17:af1f2416dd26 265 for (irq_id = 0; irq_id < (uint8_t)NB_INTERRUPTS; irq_id++) {
mahphalke 17:af1f2416dd26 266 if (irq_unregister(desc, irq_id) != SUCCESS)
mahphalke 17:af1f2416dd26 267 return FAILURE;
mahphalke 17:af1f2416dd26 268 }
mahphalke 17:af1f2416dd26 269
mahphalke 17:af1f2416dd26 270 if ((irq_ctrl_desc *)desc->extra) {
mahphalke 17:af1f2416dd26 271 free((irq_ctrl_desc *)desc->extra);
mahphalke 17:af1f2416dd26 272 }
mahphalke 17:af1f2416dd26 273
mahphalke 17:af1f2416dd26 274 free(desc);
mahphalke 17:af1f2416dd26 275
mahphalke 17:af1f2416dd26 276 return SUCCESS;
mahphalke 17:af1f2416dd26 277 }
mahphalke 17:af1f2416dd26 278
mahphalke 17:af1f2416dd26 279
mahphalke 17:af1f2416dd26 280 /**
mahphalke 17:af1f2416dd26 281 * @brief Registers a IRQ callback function to irq controller.
mahphalke 17:af1f2416dd26 282 * @param desc[in] - The IRQ controller descriptor.
mahphalke 17:af1f2416dd26 283 * @param irq_id[in] - Interrupt identifier.
mahphalke 17:af1f2416dd26 284 * @param callback_desc - Descriptor of the callback. If it is NULL, the
mahphalke 17:af1f2416dd26 285 * callback will be unregistered
mahphalke 17:af1f2416dd26 286 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 287 */
mahphalke 17:af1f2416dd26 288 int32_t irq_register_callback(struct irq_ctrl_desc *desc,
mahphalke 17:af1f2416dd26 289 uint32_t irq_id,
mahphalke 17:af1f2416dd26 290 struct callback_desc *callback_desc)
mahphalke 17:af1f2416dd26 291 {
mahphalke 17:af1f2416dd26 292 InterruptIn *ext_interrupt;
mahphalke 17:af1f2416dd26 293 mbed_callback_func mbed_callback;
mahphalke 17:af1f2416dd26 294
mahphalke 17:af1f2416dd26 295 if (!desc || !callback_desc) {
mahphalke 17:af1f2416dd26 296 return FAILURE;
mahphalke 17:af1f2416dd26 297 }
mahphalke 17:af1f2416dd26 298
mahphalke 17:af1f2416dd26 299 switch (irq_id) {
mahphalke 17:af1f2416dd26 300 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 301 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 302 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 303 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 304 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 305 switch (irq_id) {
mahphalke 17:af1f2416dd26 306 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 307 mbed_irq_callbacks.callback_ext_int_id1.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 308 mbed_irq_callbacks.callback_ext_int_id1.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 309 mbed_callback = mbed_ext_int_id1_callback;
mahphalke 17:af1f2416dd26 310 break;
mahphalke 17:af1f2416dd26 311
mahphalke 17:af1f2416dd26 312 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 313 mbed_irq_callbacks.callback_ext_int_id2.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 314 mbed_irq_callbacks.callback_ext_int_id2.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 315 mbed_callback = mbed_ext_int_id2_callback;
mahphalke 17:af1f2416dd26 316 break;
mahphalke 17:af1f2416dd26 317
mahphalke 17:af1f2416dd26 318 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 319 mbed_irq_callbacks.callback_ext_int_id3.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 320 mbed_irq_callbacks.callback_ext_int_id3.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 321 mbed_callback = mbed_ext_int_id3_callback;
mahphalke 17:af1f2416dd26 322 break;
mahphalke 17:af1f2416dd26 323
mahphalke 17:af1f2416dd26 324 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 325 mbed_irq_callbacks.callback_ext_int_id4.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 326 mbed_irq_callbacks.callback_ext_int_id4.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 327 mbed_callback = mbed_ext_int_id4_callback;
mahphalke 17:af1f2416dd26 328 break;
mahphalke 17:af1f2416dd26 329
mahphalke 17:af1f2416dd26 330 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 331 mbed_irq_callbacks.callback_ext_int_id5.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 332 mbed_irq_callbacks.callback_ext_int_id5.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 333 mbed_callback = mbed_ext_int_id5_callback;
mahphalke 17:af1f2416dd26 334 break;
mahphalke 17:af1f2416dd26 335
mahphalke 17:af1f2416dd26 336 default:
mahphalke 17:af1f2416dd26 337 return FAILURE;
mahphalke 17:af1f2416dd26 338 }
mahphalke 17:af1f2416dd26 339
Janani Sunil 20:26b1a4570f4b 340 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 341
Janani Sunil 20:26b1a4570f4b 342 /* Select interrupt mode */
mahphalke 17:af1f2416dd26 343 if (((mbed_irq_desc *)(desc->extra))->int_mode == EXT_IRQ_FALL) {
mahphalke 17:af1f2416dd26 344 ext_interrupt->fall(mbed_callback);
mahphalke 17:af1f2416dd26 345 } else if (((mbed_irq_desc *)(desc->extra))->int_mode == EXT_IRQ_RISE) {
mahphalke 17:af1f2416dd26 346 ext_interrupt->rise(mbed_callback);
mahphalke 17:af1f2416dd26 347 } else {
mahphalke 17:af1f2416dd26 348 return FAILURE;
mahphalke 17:af1f2416dd26 349 }
mahphalke 17:af1f2416dd26 350
mahphalke 17:af1f2416dd26 351 break;
mahphalke 17:af1f2416dd26 352
mahphalke 17:af1f2416dd26 353 case UART_RX_INT_ID1:
mahphalke 17:af1f2416dd26 354 mbed_irq_callbacks.callback_uart_rx_id1.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 355 mbed_irq_callbacks.callback_uart_rx_id1.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 356 break;
mahphalke 17:af1f2416dd26 357
mahphalke 17:af1f2416dd26 358 case TICKER_INT_ID:
mahphalke 17:af1f2416dd26 359 mbed_irq_callbacks.callback_ticker_id.callback = callback_desc->callback;
mahphalke 17:af1f2416dd26 360 mbed_irq_callbacks.callback_ticker_id.ctx = callback_desc->ctx;
mahphalke 17:af1f2416dd26 361 break;
mahphalke 17:af1f2416dd26 362
mahphalke 17:af1f2416dd26 363 default:
mahphalke 17:af1f2416dd26 364 return FAILURE;
mahphalke 17:af1f2416dd26 365 }
mahphalke 17:af1f2416dd26 366
mahphalke 17:af1f2416dd26 367 return SUCCESS;
mahphalke 17:af1f2416dd26 368 }
mahphalke 17:af1f2416dd26 369
mahphalke 17:af1f2416dd26 370
mahphalke 17:af1f2416dd26 371 /**
mahphalke 17:af1f2416dd26 372 * @brief Unregister a IRQ callback function.
mahphalke 17:af1f2416dd26 373 * @param desc[in] - The IRQ controller descriptor.
mahphalke 17:af1f2416dd26 374 * @param irq_id[in] - Interrupt identifier.
mahphalke 17:af1f2416dd26 375 * @return SUCCESS in case of success, FAILURE otherwise.
mahphalke 17:af1f2416dd26 376 */
mahphalke 17:af1f2416dd26 377 int32_t irq_unregister(struct irq_ctrl_desc *desc, uint32_t irq_id)
mahphalke 17:af1f2416dd26 378 {
mahphalke 17:af1f2416dd26 379 if (!desc) {
mahphalke 17:af1f2416dd26 380 return FAILURE;
mahphalke 17:af1f2416dd26 381 }
mahphalke 17:af1f2416dd26 382
mahphalke 17:af1f2416dd26 383 switch (irq_id) {
mahphalke 17:af1f2416dd26 384 case EXTERNAL_INT_ID1:
mahphalke 17:af1f2416dd26 385 mbed_irq_callbacks.callback_ext_int_id1.callback = NULL;
mahphalke 17:af1f2416dd26 386 break;
mahphalke 17:af1f2416dd26 387
mahphalke 17:af1f2416dd26 388 case EXTERNAL_INT_ID2:
mahphalke 17:af1f2416dd26 389 mbed_irq_callbacks.callback_ext_int_id2.callback = NULL;
mahphalke 17:af1f2416dd26 390 break;
mahphalke 17:af1f2416dd26 391
mahphalke 17:af1f2416dd26 392 case EXTERNAL_INT_ID3:
mahphalke 17:af1f2416dd26 393 mbed_irq_callbacks.callback_ext_int_id3.callback = NULL;
mahphalke 17:af1f2416dd26 394 break;
mahphalke 17:af1f2416dd26 395
mahphalke 17:af1f2416dd26 396 case EXTERNAL_INT_ID4:
mahphalke 17:af1f2416dd26 397 mbed_irq_callbacks.callback_ext_int_id4.callback = NULL;
mahphalke 17:af1f2416dd26 398 break;
mahphalke 17:af1f2416dd26 399
mahphalke 17:af1f2416dd26 400 case EXTERNAL_INT_ID5:
mahphalke 17:af1f2416dd26 401 mbed_irq_callbacks.callback_ext_int_id5.callback = NULL;
mahphalke 17:af1f2416dd26 402 break;
mahphalke 17:af1f2416dd26 403
mahphalke 17:af1f2416dd26 404 case UART_RX_INT_ID1:
mahphalke 17:af1f2416dd26 405 mbed_irq_callbacks.callback_uart_rx_id1.callback = NULL;
mahphalke 17:af1f2416dd26 406 break;
mahphalke 17:af1f2416dd26 407
mahphalke 17:af1f2416dd26 408 case TICKER_INT_ID:
mahphalke 17:af1f2416dd26 409 mbed_irq_callbacks.callback_ticker_id.callback = NULL;
mahphalke 17:af1f2416dd26 410 break;
mahphalke 17:af1f2416dd26 411
mahphalke 17:af1f2416dd26 412 default:
mahphalke 17:af1f2416dd26 413 return FAILURE;
mahphalke 17:af1f2416dd26 414 }
mahphalke 17:af1f2416dd26 415
mahphalke 17:af1f2416dd26 416 return SUCCESS;
mahphalke 17:af1f2416dd26 417 }
mahphalke 17:af1f2416dd26 418
Janani Sunil 20:26b1a4570f4b 419 /**
Janani Sunil 20:26b1a4570f4b 420 * @brief Enable specific interrupt
Janani Sunil 20:26b1a4570f4b 421 * @param desc[in] - The IRQ controller descriptor.
Janani Sunil 20:26b1a4570f4b 422 * @param irq_id[in] - Interrupt identifier.
Janani Sunil 20:26b1a4570f4b 423 * @return SUCCESS in case of success, FAILURE otherwise.
Janani Sunil 20:26b1a4570f4b 424 */
Janani Sunil 20:26b1a4570f4b 425 int32_t irq_enable(struct irq_ctrl_desc *desc, uint32_t irq_id)
Janani Sunil 20:26b1a4570f4b 426 {
Janani Sunil 20:26b1a4570f4b 427 InterruptIn *ext_interrupt;
Janani Sunil 20:26b1a4570f4b 428 mbed::UnbufferedSerial *uart_rx_port;
Janani Sunil 20:26b1a4570f4b 429 mbed::Ticker *ticker;
Janani Sunil 20:26b1a4570f4b 430
Janani Sunil 20:26b1a4570f4b 431 if (!desc || !desc->extra) {
Janani Sunil 20:26b1a4570f4b 432 return FAILURE;
Janani Sunil 20:26b1a4570f4b 433 }
Janani Sunil 20:26b1a4570f4b 434
Janani Sunil 20:26b1a4570f4b 435 switch (irq_id) {
Janani Sunil 20:26b1a4570f4b 436 case EXTERNAL_INT_ID1:
Janani Sunil 20:26b1a4570f4b 437 case EXTERNAL_INT_ID2:
Janani Sunil 20:26b1a4570f4b 438 case EXTERNAL_INT_ID3:
Janani Sunil 20:26b1a4570f4b 439 case EXTERNAL_INT_ID4:
Janani Sunil 20:26b1a4570f4b 440 case EXTERNAL_INT_ID5:
Janani Sunil 20:26b1a4570f4b 441 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 442 ext_interrupt->enable_irq();
Janani Sunil 20:26b1a4570f4b 443 break;
Janani Sunil 20:26b1a4570f4b 444
Janani Sunil 20:26b1a4570f4b 445 case UART_RX_INT_ID1:
Janani Sunil 20:26b1a4570f4b 446 uart_rx_port = (mbed::UnbufferedSerial *)(((mbed_irq_desc *)(
Janani Sunil 20:26b1a4570f4b 447 desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 448 uart_rx_port->attach(mbed_uart_rx_id1_callback, UnbufferedSerial::RxIrq);
Janani Sunil 20:26b1a4570f4b 449 break;
Janani Sunil 20:26b1a4570f4b 450
Janani Sunil 20:26b1a4570f4b 451 case TICKER_INT_ID:
Janani Sunil 20:26b1a4570f4b 452 ticker = (mbed::Ticker *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 453 ticker->attach(mbed_ticker_id_callback,
Janani Sunil 20:26b1a4570f4b 454 microseconds(((mbed_irq_desc *)(desc->extra))->ticker_period_usec));
Janani Sunil 20:26b1a4570f4b 455 break;
Janani Sunil 20:26b1a4570f4b 456
Janani Sunil 20:26b1a4570f4b 457 default:
Janani Sunil 20:26b1a4570f4b 458 return FAILURE;
Janani Sunil 20:26b1a4570f4b 459 }
Janani Sunil 20:26b1a4570f4b 460
Janani Sunil 20:26b1a4570f4b 461 return SUCCESS;
Janani Sunil 20:26b1a4570f4b 462 }
Janani Sunil 20:26b1a4570f4b 463
Janani Sunil 20:26b1a4570f4b 464 /**
Janani Sunil 20:26b1a4570f4b 465 * @brief Disable specific interrupt
Janani Sunil 20:26b1a4570f4b 466 * @param desc[in] - The IRQ controller descriptor.
Janani Sunil 20:26b1a4570f4b 467 * @param irq_id[in] - Interrupt identifier.
Janani Sunil 20:26b1a4570f4b 468 * @return SUCCESS in case of success, FAILURE otherwise.
Janani Sunil 20:26b1a4570f4b 469 */
Janani Sunil 20:26b1a4570f4b 470 int32_t irq_disable(struct irq_ctrl_desc *desc, uint32_t irq_id)
Janani Sunil 20:26b1a4570f4b 471 {
Janani Sunil 20:26b1a4570f4b 472 InterruptIn *ext_interrupt;
Janani Sunil 20:26b1a4570f4b 473 mbed::UnbufferedSerial *uart_rx_port;
Janani Sunil 20:26b1a4570f4b 474 mbed::Ticker *ticker;
Janani Sunil 20:26b1a4570f4b 475
Janani Sunil 20:26b1a4570f4b 476 if (!desc || !desc->extra) {
Janani Sunil 20:26b1a4570f4b 477 return FAILURE;
Janani Sunil 20:26b1a4570f4b 478 }
Janani Sunil 20:26b1a4570f4b 479
Janani Sunil 20:26b1a4570f4b 480 switch (irq_id) {
Janani Sunil 20:26b1a4570f4b 481 case EXTERNAL_INT_ID1:
Janani Sunil 20:26b1a4570f4b 482 case EXTERNAL_INT_ID2:
Janani Sunil 20:26b1a4570f4b 483 case EXTERNAL_INT_ID3:
Janani Sunil 20:26b1a4570f4b 484 case EXTERNAL_INT_ID4:
Janani Sunil 20:26b1a4570f4b 485 case EXTERNAL_INT_ID5:
Janani Sunil 20:26b1a4570f4b 486 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 487 ext_interrupt->disable_irq();
Janani Sunil 20:26b1a4570f4b 488 break;
Janani Sunil 20:26b1a4570f4b 489
Janani Sunil 20:26b1a4570f4b 490 case UART_RX_INT_ID1:
Janani Sunil 20:26b1a4570f4b 491 uart_rx_port = (mbed::UnbufferedSerial *)(((mbed_irq_desc *)(
Janani Sunil 20:26b1a4570f4b 492 desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 493 uart_rx_port->attach(NULL, UnbufferedSerial::RxIrq);
Janani Sunil 20:26b1a4570f4b 494 break;
Janani Sunil 20:26b1a4570f4b 495
Janani Sunil 20:26b1a4570f4b 496 case TICKER_INT_ID:
Janani Sunil 20:26b1a4570f4b 497 ticker = (mbed::Ticker *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Janani Sunil 20:26b1a4570f4b 498 ticker->detach();
Janani Sunil 20:26b1a4570f4b 499 break;
Janani Sunil 20:26b1a4570f4b 500
Janani Sunil 20:26b1a4570f4b 501 default:
Janani Sunil 20:26b1a4570f4b 502 return FAILURE;
Janani Sunil 20:26b1a4570f4b 503 }
Janani Sunil 20:26b1a4570f4b 504
Janani Sunil 20:26b1a4570f4b 505 return SUCCESS;
Janani Sunil 20:26b1a4570f4b 506 }
Janani Sunil 20:26b1a4570f4b 507
mahphalke 17:af1f2416dd26 508 #ifdef __cplusplus // Closing extern c
mahphalke 17:af1f2416dd26 509 }
mahphalke 17:af1f2416dd26 510 #endif