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