Platform drivers for Mbed.

Dependents:   EVAL-CN0535-FMCZ EVAL-CN0535-FMCZ EVAL-AD568x-AD569x EVAL-AD7606 ... more

Committer:
Kjansen
Date:
Mon Nov 29 12:39:54 2021 +0000
Revision:
20:4951ea6abee5
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
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;
Kjansen 20:4951ea6abee5 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
Kjansen 20:4951ea6abee5 189 switch (param->irq_ctrl_id) {
Kjansen 20:4951ea6abee5 190 case EXTERNAL_INT_ID1:
Kjansen 20:4951ea6abee5 191 case EXTERNAL_INT_ID2:
Kjansen 20:4951ea6abee5 192 case EXTERNAL_INT_ID3:
Kjansen 20:4951ea6abee5 193 case EXTERNAL_INT_ID4:
Kjansen 20:4951ea6abee5 194 case EXTERNAL_INT_ID5:
Kjansen 20:4951ea6abee5 195 /* Create a new external interrupt object */
Kjansen 20:4951ea6abee5 196 ext_interrupt = new InterruptIn((PinName)(new_mbed_desc->ext_int_pin));
Kjansen 20:4951ea6abee5 197 if (!ext_interrupt) {
Kjansen 20:4951ea6abee5 198 goto err_interrupt;
Kjansen 20:4951ea6abee5 199 }
Kjansen 20:4951ea6abee5 200
Kjansen 20:4951ea6abee5 201 new_mbed_desc->int_obj = (mbed::InterruptIn *)ext_interrupt;
Kjansen 20:4951ea6abee5 202 break;
Kjansen 20:4951ea6abee5 203
Kjansen 20:4951ea6abee5 204 case TICKER_INT_ID:
Kjansen 20:4951ea6abee5 205 /* Ticker is a special mbed class used for generating recurring interrupt.
Kjansen 20:4951ea6abee5 206 * The object of this class is created during interrupt initialization as:
Kjansen 20:4951ea6abee5 207 * 1) To avoid having seperate module for it.
Kjansen 20:4951ea6abee5 208 * 2) To avoid having multiple instances of Ticker class
Kjansen 20:4951ea6abee5 209 * */
mahphalke 17:af1f2416dd26 210 ticker = new Ticker();
mahphalke 17:af1f2416dd26 211 if (!ticker) {
Kjansen 20:4951ea6abee5 212 goto err_interrupt;
mahphalke 17:af1f2416dd26 213 }
mahphalke 17:af1f2416dd26 214
Kjansen 20:4951ea6abee5 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;
Kjansen 20:4951ea6abee5 218 break;
Kjansen 20:4951ea6abee5 219
Kjansen 20:4951ea6abee5 220 case UART_RX_INT_ID1:
Kjansen 20:4951ea6abee5 221 /* UART object must be created from uart.cpp module by an application */
Kjansen 20:4951ea6abee5 222 new_mbed_desc->int_obj = ((mbed_irq_init_param *)
Kjansen 20:4951ea6abee5 223 param->extra)->int_obj_type;
Kjansen 20:4951ea6abee5 224 break;
Kjansen 20:4951ea6abee5 225
Kjansen 20:4951ea6abee5 226 default:
Kjansen 20:4951ea6abee5 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
Kjansen 20:4951ea6abee5 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
Kjansen 20:4951ea6abee5 340 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 341
Kjansen 20:4951ea6abee5 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
Kjansen 20:4951ea6abee5 419 /**
Kjansen 20:4951ea6abee5 420 * @brief Enable specific interrupt
Kjansen 20:4951ea6abee5 421 * @param desc[in] - The IRQ controller descriptor.
Kjansen 20:4951ea6abee5 422 * @param irq_id[in] - Interrupt identifier.
Kjansen 20:4951ea6abee5 423 * @return SUCCESS in case of success, FAILURE otherwise.
Kjansen 20:4951ea6abee5 424 */
Kjansen 20:4951ea6abee5 425 int32_t irq_enable(struct irq_ctrl_desc *desc, uint32_t irq_id)
Kjansen 20:4951ea6abee5 426 {
Kjansen 20:4951ea6abee5 427 InterruptIn *ext_interrupt;
Kjansen 20:4951ea6abee5 428 mbed::UnbufferedSerial *uart_rx_port;
Kjansen 20:4951ea6abee5 429 mbed::Ticker *ticker;
Kjansen 20:4951ea6abee5 430
Kjansen 20:4951ea6abee5 431 if (!desc || !desc->extra) {
Kjansen 20:4951ea6abee5 432 return FAILURE;
Kjansen 20:4951ea6abee5 433 }
Kjansen 20:4951ea6abee5 434
Kjansen 20:4951ea6abee5 435 switch (irq_id) {
Kjansen 20:4951ea6abee5 436 case EXTERNAL_INT_ID1:
Kjansen 20:4951ea6abee5 437 case EXTERNAL_INT_ID2:
Kjansen 20:4951ea6abee5 438 case EXTERNAL_INT_ID3:
Kjansen 20:4951ea6abee5 439 case EXTERNAL_INT_ID4:
Kjansen 20:4951ea6abee5 440 case EXTERNAL_INT_ID5:
Kjansen 20:4951ea6abee5 441 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 442 ext_interrupt->enable_irq();
Kjansen 20:4951ea6abee5 443 break;
Kjansen 20:4951ea6abee5 444
Kjansen 20:4951ea6abee5 445 case UART_RX_INT_ID1:
Kjansen 20:4951ea6abee5 446 uart_rx_port = (mbed::UnbufferedSerial *)(((mbed_irq_desc *)(
Kjansen 20:4951ea6abee5 447 desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 448 uart_rx_port->attach(mbed_uart_rx_id1_callback, UnbufferedSerial::RxIrq);
Kjansen 20:4951ea6abee5 449 break;
Kjansen 20:4951ea6abee5 450
Kjansen 20:4951ea6abee5 451 case TICKER_INT_ID:
Kjansen 20:4951ea6abee5 452 ticker = (mbed::Ticker *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 453 ticker->attach(mbed_ticker_id_callback,
Kjansen 20:4951ea6abee5 454 microseconds(((mbed_irq_desc *)(desc->extra))->ticker_period_usec));
Kjansen 20:4951ea6abee5 455 break;
Kjansen 20:4951ea6abee5 456
Kjansen 20:4951ea6abee5 457 default:
Kjansen 20:4951ea6abee5 458 return FAILURE;
Kjansen 20:4951ea6abee5 459 }
Kjansen 20:4951ea6abee5 460
Kjansen 20:4951ea6abee5 461 return SUCCESS;
Kjansen 20:4951ea6abee5 462 }
Kjansen 20:4951ea6abee5 463
Kjansen 20:4951ea6abee5 464 /**
Kjansen 20:4951ea6abee5 465 * @brief Disable specific interrupt
Kjansen 20:4951ea6abee5 466 * @param desc[in] - The IRQ controller descriptor.
Kjansen 20:4951ea6abee5 467 * @param irq_id[in] - Interrupt identifier.
Kjansen 20:4951ea6abee5 468 * @return SUCCESS in case of success, FAILURE otherwise.
Kjansen 20:4951ea6abee5 469 */
Kjansen 20:4951ea6abee5 470 int32_t irq_disable(struct irq_ctrl_desc *desc, uint32_t irq_id)
Kjansen 20:4951ea6abee5 471 {
Kjansen 20:4951ea6abee5 472 InterruptIn *ext_interrupt;
Kjansen 20:4951ea6abee5 473 mbed::UnbufferedSerial *uart_rx_port;
Kjansen 20:4951ea6abee5 474 mbed::Ticker *ticker;
Kjansen 20:4951ea6abee5 475
Kjansen 20:4951ea6abee5 476 if (!desc || !desc->extra) {
Kjansen 20:4951ea6abee5 477 return FAILURE;
Kjansen 20:4951ea6abee5 478 }
Kjansen 20:4951ea6abee5 479
Kjansen 20:4951ea6abee5 480 switch (irq_id) {
Kjansen 20:4951ea6abee5 481 case EXTERNAL_INT_ID1:
Kjansen 20:4951ea6abee5 482 case EXTERNAL_INT_ID2:
Kjansen 20:4951ea6abee5 483 case EXTERNAL_INT_ID3:
Kjansen 20:4951ea6abee5 484 case EXTERNAL_INT_ID4:
Kjansen 20:4951ea6abee5 485 case EXTERNAL_INT_ID5:
Kjansen 20:4951ea6abee5 486 ext_interrupt = (InterruptIn *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 487 ext_interrupt->disable_irq();
Kjansen 20:4951ea6abee5 488 break;
Kjansen 20:4951ea6abee5 489
Kjansen 20:4951ea6abee5 490 case UART_RX_INT_ID1:
Kjansen 20:4951ea6abee5 491 uart_rx_port = (mbed::UnbufferedSerial *)(((mbed_irq_desc *)(
Kjansen 20:4951ea6abee5 492 desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 493 uart_rx_port->attach(NULL, UnbufferedSerial::RxIrq);
Kjansen 20:4951ea6abee5 494 break;
Kjansen 20:4951ea6abee5 495
Kjansen 20:4951ea6abee5 496 case TICKER_INT_ID:
Kjansen 20:4951ea6abee5 497 ticker = (mbed::Ticker *)(((mbed_irq_desc *)(desc->extra))->int_obj);
Kjansen 20:4951ea6abee5 498 ticker->detach();
Kjansen 20:4951ea6abee5 499 break;
Kjansen 20:4951ea6abee5 500
Kjansen 20:4951ea6abee5 501 default:
Kjansen 20:4951ea6abee5 502 return FAILURE;
Kjansen 20:4951ea6abee5 503 }
Kjansen 20:4951ea6abee5 504
Kjansen 20:4951ea6abee5 505 return SUCCESS;
Kjansen 20:4951ea6abee5 506 }
Kjansen 20:4951ea6abee5 507
mahphalke 17:af1f2416dd26 508 #ifdef __cplusplus // Closing extern c
mahphalke 17:af1f2416dd26 509 }
mahphalke 17:af1f2416dd26 510 #endif