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