1 // ********************************************************************* 2 // Custom DPA Handler code example - HW peripheral memory mapping * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-LED-MemoryMapping.c,v $ 7 // Version: $Revision: 1.29 $ 8 // Date: $Date: 2022/02/25 09:41:25 $ 9 // 10 // Revision history: 11 // 2022/02/24 Release for DPA 4.17 12 // 2018/10/25 Release for DPA 3.03 13 // 2017/03/13 Release for DPA 3.00 14 // 2015/08/05 Release for DPA 2.20 15 // 2014/10/31 Release for DPA 2.10 16 // 2014/07/26 Release for DPA 2.01 17 // 18 // ********************************************************************* 19 20 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 21 22 // The application demonstrates memory mapping of the actual MCU peripheral to the DPA RAM peripheral 23 // byte @ PeripheralRam[0] = controls red LED 24 // byte @ PeripheralRam[1] = controls green LED 25 // 26 // bytes @ PeripheralRam[0..1] 27 // 0: LED off 28 // 1: LED on 29 // 2: LED pulse 30 // 3: LED pulsing 31 // other: no change 32 33 // Default IQRF include (modify the path according to your setup) 34 #include "IQRF.h" 35 36 // Default DPA header (modify the path according to your setup) 37 #include "DPA.h" 38 // Default Custom DPA Handler header (modify the path according to your setup) 39 #include "DPAcustomHandler.h" 40 41 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 42 //############################################################################################ 43 bit CustomDpaHandler() 44 //############################################################################################ 45 { 46 // Handler presence mark 47 clrwdt(); 48 49 // Detect DPA event to handle (unused event handlers can be commented out or even deleted) 50 switch ( GetDpaEvent() ) 51 { 52 #ifdef DpaEvent_Interrupt 53 // ------------------------------------------------- 54 case DpaEvent_Interrupt: 55 // Do an extra quick background interrupt work 56 57 return Carry; 58 #endif 59 60 // ------------------------------------------------- 61 case DpaEvent_Notification: 62 // Called after DPA request was processed and after DPA response was sent 63 64 // Anything written to the RAM? 65 // (could be optimized by checking the RAM address that was written to and based on its value control the appropriate LED) 66 if ( _PNUM == PNUM_RAM && _PCMD == CMD_RAM_WRITE ) 67 { 68 // Control red LED 69 switch ( PeripheralRam[0] ) 70 { 71 // Switch the LED off 72 case 0: 73 stopLEDR(); 74 break; 75 76 // Switch the LED on (first make sure that the optional pulsing is disabled) 77 case 1: 78 setLEDR(); 79 // Make sure LED is visible at LP mode 80 waitMS( 20 ); 81 break; 82 83 // Make one pulse 84 case 2: 85 pulseLEDR(); 86 // Make sure LED is visible at LP mode 87 waitMS( 20 ); 88 break; 89 90 // Start pulsing 91 case 3: 92 pulsingLEDR(); 93 break; 94 } 95 96 // Control green LED 97 switch ( PeripheralRam[1] ) 98 { 99 // Switch the LED off 100 case 0: 101 stopLEDG(); 102 break; 103 104 // Switch the LED on (first make sure that the optional pulsing is disabled) 105 case 1: 106 setLEDG(); 107 // Make sure LED is visible at LP mode 108 waitMS( 20 ); 109 break; 110 111 // Make one pulse 112 case 2: 113 pulseLEDG(); 114 // Make sure LED is visible at LP mode 115 waitMS( 20 ); 116 break; 117 118 // Start pulsing 119 case 3: 120 pulsingLEDG(); 121 break; 122 } 123 } 124 125 break; 126 } 127 128 return FALSE; 129 } 130 //############################################################################################ 131 // 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) 132 #include "DPAcustomHandler.h" 133 //############################################################################################