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