1 // ********************************************************************* 2 // Custom DPA Handler code example - UART repeater * 3 // ********************************************************************* 4 // Copyright (c) MICRORISC s.r.o. 5 // 6 // File: $RCSfile: CustomDpaHandler-UARTrepeater.c,v $ 7 // Version: $Revision: 1.38 $ 8 // Date: $Date: 2022/02/25 09:41:25 $ 9 // 10 // Revision history: 11 // 2022/02/24 Release for DPA 4.17 12 // 2020/09/03 Release for DPA 4.15 13 // 2019/12/11 Release for DPA 4.11 14 // 2018/10/25 Release for DPA 3.03 15 // 2017/03/13 Release for DPA 3.00 16 // 2016/09/12 Release for DPA 2.28 17 // 2015/08/05 Release for DPA 2.20 18 // 2014/10/31 Release for DPA 2.10 19 // 20 // ********************************************************************* 21 22 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/ 23 24 // Default IQRF include (modify the path according to your setup) 25 #include "IQRF.h" 26 27 // Default DPA header (modify the path according to your setup) 28 #include "DPA.h" 29 // Default Custom DPA Handler header (modify the path according to your setup) 30 #include "DPAcustomHandler.h" 31 32 // This example opens its UART peripheral and periodically TX data previously RX from UART, the data are available at peripheral RAM too 33 // This example works only at STD mode, not at LP mode 34 35 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location! 36 //############################################################################################ 37 bit CustomDpaHandler() 38 //############################################################################################ 39 { 40 // Handler presence mark 41 clrwdt(); 42 43 // Detect DPA event to handle 44 switch ( GetDpaEvent() ) 45 { 46 // ------------------------------------------------- 47 case DpaEvent_Interrupt: 48 // Do an extra quick background interrupt work 49 50 return Carry; 51 52 // ------------------------------------------------- 53 case DpaEvent_Idle: 54 // Do a quick background work when RF packet is not received 55 56 // No data RX from UART yet 57 _DpaDataLength = 0; 58 for ( ;; ) 59 { 60 // TX and RX data to/from UART 61 _PNUM = PNUM_UART; 62 _PCMD = CMD_UART_WRITE_READ; 63 // Wait 0 ms for RX 64 _DpaMessage.PerUartWriteRead_Request.ReadTimeout = 0; 65 // Copy previously RX data to TX 66 copyMemoryBlock( PeripheralRam + offsetof( TPerUartWriteRead_Request, WrittenData ), _DpaMessage.PerUartWriteRead_Request.WrittenData, _DpaDataLength ); 67 // One more byte to the request 68 _DpaDataLength += offsetof( TPerUartWriteRead_Request, WrittenData ); 69 // TX/RX from UART 70 DpaApiLocalRequest(); 71 // Error TX/RX UART? 72 if ( _PNUM == PNUM_ERROR_FLAG ) 73 { 74 setLEDR(); 75 break; 76 } 77 78 // No data RX? 79 if ( _DpaDataLength == 0 ) 80 break; 81 82 // Indicate RX data 83 pulseLEDG(); 84 // Copy to RAM peripheral RX data length and ... 85 PeripheralRam[0] = _DpaDataLength; 86 // RX data too 87 copyMemoryBlock( _DpaMessage.Response.PData, PeripheralRam + offsetof( TPerUartWriteRead_Request, WrittenData ), _DpaDataLength + 1 ); 88 } 89 break; 90 } 91 92 return FALSE; 93 } 94 //############################################################################################ 95 // 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) 96 #include "DPAcustomHandler.h" 97 //############################################################################################