1 // ******************************************************************************** 2 // Custom DPA Handler code example - Shows custom bonding using remapped button * 3 // ******************************************************************************** 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-BondingButton.c,v $ 7 // Version: $Revision: 1.4 $ 8 // Date: $Date: 2021/04/26 15:13:50 $ 9 // 10 // Revision history: 11 // 2018/??/?? Release for DPA 3.03 12 // 13 // ********************************************************************* 14 15 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 16 17 // Default IQRF include (modify the path according to your setup) 18 #include "IQRF.h" 19 20 // Default DPA header (modify the path according to your setup) 21 #include "DPA.h" 22 // Default Custom DPA Handler header (modify the path according to your setup) 23 #include "DPAcustomHandler.h" 24 25 // This code illustrates bonding using a button connected to the custom pin. 26 // Except going to sleep the code behaves the same way as the standard bonding procedure. 27 28 // Custom bonding button. Change to the pin and an active level of your choice. 29 #define IsButton ( !PORTA.0 ) 30 31 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 32 //############################################################################################ 33 bit CustomDpaHandler() 34 //############################################################################################ 35 { 36 // Handler presence mark 37 clrwdt(); 38 39 // Detect DPA event to handle 40 switch ( GetDpaEvent() ) 41 { 42 // ------------------------------------------------- 43 case DpaEvent_Interrupt: 44 // Do an extra quick background interrupt work 45 // ! The time spent handling this event is critical.If there is no interrupt to handle return immediately otherwise keep the code as fast as possible. 46 // ! Make sure the event is the 1st case in the main switch statement at the handler routine.This ensures that the event is handled as the 1st one. 47 // ! It is desirable that this event is handled with immediate return even if it is not used by the custom handler because the Interrupt event is raised on every MCU interrupt and the “empty” return handler ensures the shortest possible interrupt routine response time. 48 // ! Only global variables or local ones marked by static keyword can be used to allow reentrancy. 49 // ! Make sure race condition does not occur when accessing those variables at other places. 50 // ! Make sure( inspect.lst file generated by C compiler ) compiler does not create any hidden temporary local variable( occurs when using division, multiplication or bit shifts ) at the event handler code.The name of such variable is usually Cnumbercnt. 51 // ! Do not call any OS functions except setINDFx(). 52 // ! Do not use any OS variables especially for writing access. 53 // ! All above rules apply also to any other function being called from the event handler code, although calling any function from Interrupt event is not recommended because of additional MCU stack usage. 54 55 DpaHandleReturnTRUE: 56 return TRUE; 57 58 // ------------------------------------------------- 59 case DpaEvent_BondingButton: 60 // Called to allow a bonding button customization 61 62 userReg1.0 = 0; 63 if ( IsButton ) 64 userReg1.0 = 1; 65 66 return TRUE; 67 } 68 69 return FALSE; 70 } 71 72 //############################################################################################ 73 // Default Custom DPA Handler header; 2nd include to implement Code bumper to detect too long code of the Custom DPA Handler (modify the path according to your setup) 74 #include "DPAcustomHandler.h" 75 //############################################################################################