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