@@ -58,6 +58,9 @@ Private global variables and functions
5858***********************************************************************************************************************/ 
5959/* This array holds callback functions. */ 
6060static  void  (*  g_bsp_vectors [BSP_INT_SRC_TOTAL_ITEMS ])(void  *  pdata );
61+ #if  defined(BSP_MCU_RX26T )
62+ static  void  * g_bsp_contexts [BSP_INT_SRC_TOTAL_ITEMS ];
63+ #endif 
6164
6265static  bsp_int_err_t  bsp_fit_interrupts_control  (bool  enable , bsp_int_ctrl_t  *  pdata );
6366
@@ -140,6 +143,9 @@ void bsp_interrupt_open(void)
140143    {
141144        /* Casting is valid because it matches the type to the right side or argument. */ 
142145        g_bsp_vectors [i ] =  FIT_NO_FUNC ;
146+ #if  defined(BSP_MCU_RX26T )
147+         g_bsp_contexts [i ] =  NULL ;
148+ #endif 
143149    }
144150
145151#ifdef  BSP_MCU_SOFTWARE_CONFIGURABLE_INTERRUPT 
@@ -202,6 +208,58 @@ bsp_int_err_t R_BSP_InterruptWrite(bsp_int_src_t vector,  bsp_int_cb_t callback)
202208    return  err ;
203209} /* End of function R_BSP_InterruptWrite() */ 
204210
211+ #if  defined(BSP_MCU_RX26T )
212+ /********************************************************************************************************************** 
213+  * Function Name: R_BSP_InterruptWrite_EX 
214+  ******************************************************************************************************************/ /** 
215+  * @brief Registers a callback function for an interrupt. 
216+  * @param[in] vector Which interrupt to register a callback for. 
217+  * @param[in] callback Pointer to function to call when interrupt occurs. 
218+  * @param[in] context Pointer to the callback function's argument. 
219+  * @retval BSP_INT_SUCCESS Successful, callback has been registered. 
220+  * @retval BSP_INT_ERR_INVALID_ARG An invalid interrupt source was specified for vector. 
221+  * @details This function registers a callback function for an interrupt. If FIT_NO_FUNC, NULL, or any other invalid 
222+  * function address is passed for the callback argument then any previously registered callbacks are unregistered. 
223+  * If one of the interrupts that is handled by this code is triggered then the interrupt handler will query this code 
224+  * to see if a valid callback function is registered. If one is found then the callback function will be called. 
225+  * If one is not found then the interrupt handler will clear the appropriate flag(s) and exit. If the user has a 
226+  * callback function registered and wishes to no longer handle the interrupt then the user should call this function 
227+  * again with FIT_NO_FUNC as the vector parameter. 
228+  * @note Use of FIT_NO_FUNC is preferred over NULL since access to the address defined by FIT_NO_FUNC will cause a 
229+  * bus error which is easy for the user to catch. NULL typically resolves to 0 which is a valid address on RX MCUs. 
230+  */ 
231+ bsp_int_err_t  R_BSP_InterruptWrite_EX (bsp_int_src_t  vector ,  bsp_int_cb_t  callback , void  * context )
232+ {
233+     bsp_int_err_t  err ;
234+ 
235+     err  =  BSP_INT_SUCCESS ;
236+ 
237+     /* Check for valid address. */ 
238+     if  (((uint32_t )callback  ==  (uint32_t )NULL ) ||  ((uint32_t )callback  ==  (uint32_t )FIT_NO_FUNC ))
239+     {
240+         /* Casting is valid because it matches the type to the right side or argument. */ 
241+         g_bsp_vectors [vector ] =  FIT_NO_FUNC ;
242+         g_bsp_contexts [vector ] =  NULL ;
243+     }
244+     else 
245+     {
246+         if  ((BSP_INT_SRC_BUS_ERROR_ILLEGAL_ACCESS  ==  vector ) ||  (BSP_INT_SRC_BUS_ERROR_TIMEOUT  ==  vector ) || 
247+             (BSP_INT_SRC_EMPTY  <= vector ))
248+         {
249+             /* When registering a bus error callback function, specify BSP_INT_SRC_BUS_ERROR in the vector. */ 
250+             err  =  BSP_INT_ERR_INVALID_ARG ;
251+         }
252+         else 
253+         {
254+             g_bsp_vectors [vector ] =  callback ;
255+             g_bsp_contexts [vector ] =  context ;
256+         }
257+     }
258+ 
259+     return  err ;
260+ } /* End of function R_BSP_InterruptWrite_EX() */ 
261+ #endif 
262+ 
205263/********************************************************************************************************************** 
206264 * Function Name: R_BSP_InterruptRead 
207265 ******************************************************************************************************************/ /** 
@@ -297,7 +355,9 @@ bsp_int_err_t R_BSP_InterruptControl(bsp_int_src_t vector, bsp_int_cmd_t cmd, vo
297355            {
298356                /* Fill in callback info. */ 
299357                cb_args .vector  =  vector ;
300- 
358+ #if  defined(BSP_MCU_RX26T )               
359+                 cb_args .p_context  =  g_bsp_contexts [vector ];
360+ #endif 
301361                g_bsp_vectors [vector ](& cb_args );
302362            }
303363            else 
0 commit comments