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