1 // *********************************************************************
    2 //   Custom DPA Handler code template                                  *
    3 // *********************************************************************
    4 // Copyright (c) IQRF Tech s.r.o.
    5 //
    6 // File:    $RCSfile: CustomDpaHandler-Template.c,v $
    7 // Version: $Revision: 1.46 $
    8 // Date:    $Date: 2020/03/20 17:02:58 $
    9 //
   10 // Revision history:
   11 //   2020/02/27  Release for DPA 4.13
   12 //   2019/01/10  Release for DPA 4.00
   13 //   2017/08/14  Release for DPA 3.01
   14 //   2017/03/13  Release for DPA 3.00
   15 //   2015/08/05  Release for DPA 2.20
   16 //   2014/10/31  Release for DPA 2.10
   17 //   2014/04/30  Release for DPA 2.00
   18 //
   19 // *********************************************************************
   20 
   21 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/
   22 
   23 // Default IQRF include (modify the path according to your setup)
   24 #include "IQRF.h"
   25 
   26 // Uncomment to implement Custom DPA Handler for Coordinator
   27 //#define COORDINATOR_CUSTOM_HANDLER
   28 
   29 // Default DPA header (modify the path according to your setup)
   30 #include "DPA.h"
   31 // Default Custom DPA Handler header (modify the path according to your setup)
   32 #include "DPAcustomHandler.h"
   33 
   34 //############################################################################################
   35 
   36 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended
   37 // example: uns8 globalCounter;
   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   // Place for local static variables used only within CustomDpaHandler() among more events
   48   // example: static bit interruptOccured;
   49 
   50   // Detect DPA event to handle (unused event handlers can be commented out or even deleted)
   51   switch ( GetDpaEvent() )
   52   {
   53 #ifdef DpaEvent_Interrupt
   54     // -------------------------------------------------
   55     case DpaEvent_Interrupt:
   56       // Do an extra quick background interrupt work
   57       // ! 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.
   58       // ! 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.
   59       // ! 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.
   60       // ! Only global variables or local ones marked by static keyword can be used to allow reentrancy.
   61       // ! Make sure race condition does not occur when accessing those variables at other places.
   62       // ! 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.
   63       // ! Do not call any OS functions except setINDFx().
   64       // ! Do not use any OS variables especially for writing access.
   65       // ! 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.
   66 
   67       return Carry;
   68 #endif
   69       // -------------------------------------------------
   70     case DpaEvent_Idle:
   71       // Do a quick background work when RF packet is not received
   72     break;
   73 
   74     // -------------------------------------------------
   75     case DpaEvent_Reset:
   76       // Called after module is reset
   77       //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding
   78       break;
   79 
   80       // -------------------------------------------------
   81     case DpaEvent_BondingButton:
   82       // Called to allow a bonding button customization
   83       //goto DpaHandleReturnTRUE; // return TRUE to handle bonding button
   84       break;
   85 
   86       // -------------------------------------------------
   87     case DpaEvent_Indicate:
   88       // Called to allow a customization of the device indication
   89       //goto DpaHandleReturnTRUE; // return TRUE to skip default indication
   90       break;
   91 
   92       // -------------------------------------------------
   93     case DpaEvent_Init:
   94       // Do a one time initialization before main loop starts
   95       break;
   96 
   97       // -------------------------------------------------
   98     case DpaEvent_ReceiveDpaRequest:
   99       // Called after DPA request was received
  100       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  101       break;
  102 
  103       // -------------------------------------------------
  104     case DpaEvent_BeforeSendingDpaResponse:
  105       // Called before sending DPA response back to originator of DPA response
  106       break;
  107 
  108       // -------------------------------------------------
  109     case DpaEvent_Notification:
  110       // Called after DPA request was processed and after DPA response was sent
  111       break;
  112 
  113       // -------------------------------------------------
  114     case DpaEvent_AfterRouting:
  115       // Called after Notification and after routing of the DPA response was finished
  116       break;
  117 
  118 #ifndef COORDINATOR_CUSTOM_HANDLER
  119       // -------------------------------------------------
  120     case DpaEvent_FrcValue:
  121       // Called to get FRC value
  122       break;
  123 #endif
  124 
  125 #ifndef COORDINATOR_CUSTOM_HANDLER
  126       // -------------------------------------------------
  127     case DpaEvent_FrcResponseTime:
  128       // Called to get FRC response time
  129       break;
  130 #endif
  131 
  132 #ifndef COORDINATOR_CUSTOM_HANDLER
  133       // -------------------------------------------------
  134     case DpaEvent_BeforeSleep:
  135       // Called before going to sleep
  136       break;
  137 #endif
  138 
  139 #ifndef COORDINATOR_CUSTOM_HANDLER
  140       // -------------------------------------------------
  141     case DpaEvent_AfterSleep:
  142       // Called after woken up after sleep
  143       break;
  144 #endif
  145 
  146       // -------------------------------------------------
  147     case DpaEvent_DisableInterrupts:
  148       // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM)
  149       break;
  150 
  151 #ifdef COORDINATOR_CUSTOM_HANDLER
  152       // -------------------------------------------------
  153     case DpaEvent_ReceiveDpaResponse:
  154       // Called after DPA response was received at coordinator
  155       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  156       break;
  157 #endif
  158 
  159 #ifdef COORDINATOR_CUSTOM_HANDLER
  160       // -------------------------------------------------
  161     case DpaEvent_IFaceReceive:
  162       // Called after DPA request from interface master was received at coordinator
  163       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  164       break;
  165 #endif
  166 
  167       // -------------------------------------------------
  168     case DpaEvent_PeerToPeer:
  169       // Called when peer-to-peer (non-networking) packet is received
  170       break;
  171 
  172       // -------------------------------------------------
  173     case DpaEvent_UserDpaValue:
  174       // Called when DPA is required to return User defined DPA value in the response
  175       break;
  176 
  177       // -------------------------------------------------
  178     case DpaEvent_DpaRequest:
  179       // Called to interpret DPA request for peripherals
  180       IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest()
  181       {
  182         // -------------------------------------------------
  183         // Peripheral enumeration
  184 
  185         _DpaMessage.EnumPeripheralsAnswer.UserPerNr = 0; // ?
  186         // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ?
  187         _DpaMessage.EnumPeripheralsAnswer.HWPID = 0x000F; // ????
  188         _DpaMessage.EnumPeripheralsAnswer.HWPIDver = 0; // ????
  189 
  190 DpaHandleReturnTRUE:
  191         return TRUE;
  192       }
  193       else
  194       {
  195       // -------------------------------------------------
  196       // Get information about peripheral
  197 
  198       if ( _PNUM == PNUM_USER + 0 ) // ?
  199       {
  200         _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_?
  201         _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_?
  202         _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ?
  203         _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ?
  204         goto DpaHandleReturnTRUE;
  205       }
  206 
  207       break;
  208       }
  209 
  210       // -------------------------------------------------
  211       // Handle peripheral command
  212 
  213       if ( _PNUM == PNUM_USER + 0 ) // ?
  214       {
  215         if ( _PCMD == 0 ) // ????
  216         {
  217           goto DpaHandleReturnTRUE;
  218         }
  219       }
  220 
  221       break;
  222   }
  223 
  224 DpaHandleReturnFALSE:
  225   return FALSE;
  226 }
  227 
  228 //############################################################################################
  229 // 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)
  230 #include "DPAcustomHandler.h"
  231 //############################################################################################