1 // *********************************************************************** 2 // Custom DPA Handler code example - External device connected to UART * 3 // *********************************************************************** 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-UART.c,v $ 7 // Version: $Revision: 1.26 $ 8 // Date: $Date: 2022/02/25 09:41:25 $ 9 // 10 // Revision history: 11 // 2022/02/24 Release for DPA 4.17 12 // 2019/12/11 Release for DPA 4.11 13 // 2018/10/25 Release for DPA 3.03 14 // 2017/03/13 Release for DPA 3.00 15 // 2016/02/08 Release for DPA 2.26 16 // 17 // ********************************************************************* 18 19 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 20 21 // Default IQRF include (modify the path according to your setup) 22 #include "IQRF.h" 23 24 // Default DPA header (modify the path according to your setup) 25 #include "DPA.h" 26 // Default Custom DPA Handler header (modify the path according to your setup) 27 #include "DPAcustomHandler.h" 28 29 // The application demonstrates simple handler used to connect external device using UART 30 31 // Before uploading this example make sure: 32 // 1. Peripheral UART is enabled at HWP Configuration. It will be automatically opened. 33 34 //############################################################################################ 35 36 // HW Profile ID 37 #define HWPid 0x123F 38 // HW Profile ID Version 39 #define HWPidVer 0x0000 40 41 // Bonding button, must be often (depends on used DCTR module) redefined because it might conflict with UART TX signal 42 #define IsButton ( !PORTA.0 ) 43 44 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 45 //############################################################################################ 46 bit CustomDpaHandler() 47 //############################################################################################ 48 { 49 // Handler presence mark 50 clrwdt(); 51 52 // Detect DPA event to handle 53 switch ( GetDpaEvent() ) 54 { 55 // ------------------------------------------------- 56 case DpaEvent_Interrupt: 57 // Do an extra quick background interrupt work 58 // ! 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. 59 // ! 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. 60 // ! 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. 61 // ! Only global variables or local ones marked by static keyword can be used to allow reentrancy. 62 // ! Make sure race condition does not occur when accessing those variables at other places. 63 // ! 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. 64 // ! Do not call any OS functions except setINDFx(). 65 // ! Do not use any OS variables especially for writing access. 66 // ! 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. 67 68 return Carry; 69 70 // Define custom button (un)bonding only when a button is redefined 71 #ifdef IsButton 72 // ------------------------------------------------- 73 case DpaEvent_BondingButton: 74 // Called to allow a bonding button customization 75 76 userReg1.0 = 0; 77 if ( IsButton ) 78 userReg1.0 = 1; 79 80 goto DpaHandleReturnTRUE; 81 #endif 82 83 // ------------------------------------------------- 84 case DpaEvent_DpaRequest: 85 // Called to interpret DPA request for peripherals 86 // ------------------------------------------------- 87 // Peripheral enumeration 88 if ( IsDpaEnumPeripheralsRequest() ) 89 { 90 // We do not implement user peripheral 91 //_DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; 92 // Report HWPID 93 _DpaMessage.EnumPeripheralsAnswer.HWPID |= HWPid; 94 _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= HWPidVer; 95 96 DpaHandleReturnTRUE: 97 return TRUE; 98 } 99 } 100 101 return FALSE; 102 } 103 104 //############################################################################################ 105 // 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) 106 #include "DPAcustomHandler.h" 107 //############################################################################################