1 // ********************************************************************* 2 // Custom DPA Handler code example - Custom indication * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-CustomIndicate.c,v $ 7 // Version: $Revision: 1.21 $ 8 // Date: $Date: 2024/04/17 12:50:13 $ 9 // 10 // Revision history: 11 // 2024/04/17 Release for DPA 4.31 12 // 2022/02/24 Release for DPA 4.17 13 // 2020/04/03 Release for DPA 4.14 14 // 2020/02/27 Release for DPA 4.13 15 // 16 // ********************************************************************* 17 18 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 19 20 // Default IQRF include (modify the path according to your setup) 21 #include "IQRF.h" 22 23 // Default DPA header (modify the path according to your setup) 24 #include "DPA.h" 25 // Default Custom DPA Handler header (modify the path according to your setup) 26 #include "DPAcustomHandler.h" 27 28 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 29 //############################################################################################ 30 bit CustomDpaHandler() 31 //############################################################################################ 32 { 33 // Handler presence mark 34 clrwdt(); 35 36 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 37 switch ( GetDpaEvent() ) 38 { 39 // ------------------------------------------------- 40 case DpaEvent_Interrupt: 41 // Do an extra quick background interrupt work 42 return Carry; 43 44 // ------------------------------------------------- 45 case DpaEvent_Init: 46 // Do a one time initialization before main loop starts 47 48 // Set custom indication GPIO to output 49 TRISA.0 = 0; 50 break; 51 52 // ------------------------------------------------- 53 case DpaEvent_Indicate: 54 // Called to allow a customization of the device indication 55 56 // userReg1 = Control byte with only valid bit.0-1, bit.2-7 = 0 57 58 // Control == 0 (indication off) ? 59 if ( userReg1 == 0 ) 60 { 61 _IndicateOff: 62 stopLEDR(); 63 LATA.0 = 0; 64 } 65 else 66 { 67 // Indication on 68 setLEDR(); 69 LATA.0 = 1; 70 71 // Timed indication? 72 if ( userReg1.1 ) 73 { 74 // 1 s in 0.5 s 75 W = 1 * 2; 76 // Control != 2 77 if ( userReg1.0 ) 78 // 10 s in 0.5 s 79 W = 10 * 2; 80 userReg1 = W; 81 do 82 { 83 // 0.5 s step 84 waitDelay( 50 ); 85 clrwdt(); 86 } while ( --userReg1 != 0 ); 87 88 // Switch off the indication 89 goto _IndicateOff; 90 } 91 } 92 93 // return TRUE to skip default indication by LEDR and LEDG (userReg1 might be thus modified) 94 return TRUE; 95 96 // ------------------------------------------------- 97 case DpaEvent_BeforeSleep: 98 // Called before going to sleep 99 100 // Switch off custom indication via GPIO 101 goto _IndicateOff; 102 103 // ------------------------------------------------- 104 case DpaEvent_DpaRequest: 105 // Called to interpret DPA request for peripherals 106 // ------------------------------------------------- 107 // Peripheral enumeration 108 if ( IsDpaEnumPeripheralsRequest() ) 109 { 110 // We implement no user peripheral 111 _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x15DF; 112 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0x0000; 113 return TRUE; 114 } 115 break; 116 } 117 118 return FALSE; 119 } 120 121 //############################################################################################ 122 // Default Custom DPA Handler header; 2nd include implementing a Code bumper to detect too long code of the Custom DPA Handler (modify the path according to your setup) 123 #include "DPAcustomHandler.h" 124 //############################################################################################