1 // *********************************************************************
    2 //   Custom DPA Handler code template                                  *
    3 // *********************************************************************
    4 // Copyright (c) MICRORISC s.r.o.
    5 //
    6 // File:    $RCSfile: CustomDpaHandler-Template-OptimizedSwitch-Coordinator.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 // Implement Custom DPA Handler for Coordinator
   30 #define COORDINATOR_CUSTOM_HANDLER
   31 
   32 // Default DPA header (modify the path according to your setup)
   33 #include "DPA.h"
   34 // Default Custom DPA Handler header (modify the path according to your setup)
   35 #include "DPAcustomHandler.h"
   36 
   37 // Uncomment the following includes if the respective component is needed
   38 // IQRF standards header (modify the path according to your setup)
   39 //#include "IQRFstandard.h"
   40 //#include "IQRF_HWPID.h"
   41 //#include "NFC.c"
   42 
   43 //############################################################################################
   44 
   45 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended
   46 // example: uns8 globalCounter;
   47 
   48 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location!
   49 //############################################################################################
   50 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html
   51 bit CustomDpaHandler()
   52 //############################################################################################
   53 {
   54   // Handler presence mark
   55   clrwdt();
   56 
   57   // Place for local static variables used only within CustomDpaHandler() among more events
   58   // example: static bit interruptOccured;
   59 
   60   // Detect DPA event to handle
   61   // Do not handle "out of range" events. The handled event with the highest value can be used instead of DpaEvent_LAST and "computedGoto" section made thus event shorter.
   62   W = DpaEvent_LAST - GetDpaEvent();
   63   if ( !Carry )
   64     goto DpaHandleReturnFALSE;
   65 
   66   skip( W );
   67 #pragma computedGoto 1
   68   // Reverse order of events because of subtraction
   69   goto DpaHandleReturnFALSE; // DpaEvent_VerifyLocalFrc : not implemented at Node
   70   goto DpaHandleReturnFALSE; // DpaEvent_Indicate : not implemented at Node
   71   goto DpaHandleReturnFALSE; // DpaEvent_BondingButton : not implemented at Node
   72   goto DpaHandleReturnFALSE; // DpaEvent_FrcResponseTime : not implemented at Node
   73   goto _DpaEvent_UserDpaValue;
   74   goto DpaHandleReturnFALSE; // Formerly DpaEvent_AuthorizePreBonding
   75   goto _DpaEvent_PeerToPeer;
   76   goto _DpaEvent_BeforeSendingDpaResponse;
   77   goto _DpaEvent_ReceiveDpaRequest;
   78   goto _DpaEvent_IFaceReceive;
   79   goto _DpaEvent_ReceiveDpaResponse;
   80   goto DpaHandleReturnFALSE; // DpaEvent_FrcValue : not implemented at Node
   81   goto _DpaEvent_DisableInterrupts;
   82   goto _DpaEvent_Reset;
   83   goto DpaHandleReturnFALSE; // DpaEvent_AfterSleep : not implemented at Node
   84   goto DpaHandleReturnFALSE; // DpaEvent_BeforeSleep : not implemented at Node
   85   goto _DpaEvent_AfterRouting;
   86   goto _DpaEvent_Notification;
   87   goto _DpaEvent_Init;
   88   goto _DpaEvent_Idle;
   89   goto DpaHandleReturnFALSE; // DpaEvent_Interrupt : not implemented at Node
   90   goto _DpaEvent_DpaRequest;
   91 #pragma computedGoto 0
   92   ;
   93   // -------------------------------------------------
   94 _DpaEvent_DpaRequest:
   95   // Called to interpret DPA request for peripherals
   96   // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html
   97   // -------------------------------------------------
   98   // Peripheral enumeration
   99   // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html
  100   IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest()
  101   {
  102     _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ?
  103     // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ?
  104     _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ????
  105     _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ????
  106 
  107 DpaHandleReturnTRUE:
  108     return TRUE;
  109   }
  110   // -------------------------------------------------
  111   // Get information about peripheral
  112   // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html
  113   else
  114   {
  115     if ( _PNUM == PNUM_USER + 0 ) // ?
  116     {
  117       _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_?
  118       _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_?
  119       _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ?
  120       _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ?
  121       goto DpaHandleReturnTRUE;
  122     }
  123 
  124     goto DpaHandleReturnFALSE;
  125   }
  126   // -------------------------------------------------
  127   // Handle peripheral command
  128   // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html
  129   if ( _PNUM == PNUM_USER + 0 ) // ?
  130   {
  131     if ( _PCMD == 0 ) // ????
  132     {
  133       goto DpaHandleReturnTRUE;
  134     }
  135   }
  136 
  137   goto DpaHandleReturnFALSE;
  138 
  139   // -------------------------------------------------
  140 _DpaEvent_Idle:
  141   // Do a quick background work when RF packet is not received
  142   // https://doc.iqrf.org/DpaTechGuide/pages/idle.html
  143   goto DpaHandleReturnFALSE;
  144 
  145   // -------------------------------------------------
  146 _DpaEvent_Reset:
  147   // Called after module is reset
  148   // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html
  149 
  150   //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding
  151   goto DpaHandleReturnFALSE;
  152 
  153   // -------------------------------------------------
  154 _DpaEvent_Init:
  155   // Do a one time initialization before main loop starts
  156   // https://doc.iqrf.org/DpaTechGuide/pages/init.html
  157   goto DpaHandleReturnFALSE;
  158 
  159   // -------------------------------------------------
  160 _DpaEvent_ReceiveDpaRequest:
  161   // Called after DPA request was received
  162   // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html
  163 
  164   //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  165   goto DpaHandleReturnFALSE;
  166 
  167   // -------------------------------------------------
  168 _DpaEvent_BeforeSendingDpaResponse:
  169   // Called before sending DPA response back to originator of DPA response
  170   // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html
  171 
  172   goto DpaHandleReturnFALSE;
  173 
  174   // -------------------------------------------------
  175 _DpaEvent_Notification:
  176   // Called after DPA request was processed and after DPA response was sent
  177   // https://doc.iqrf.org/DpaTechGuide/pages/notification.html
  178   goto DpaHandleReturnFALSE;
  179 
  180   // -------------------------------------------------
  181 _DpaEvent_AfterRouting:
  182   // Called after Notification and after routing of the DPA response was finished
  183   // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html
  184   goto DpaHandleReturnFALSE;
  185 
  186   // -------------------------------------------------
  187 _DpaEvent_DisableInterrupts:
  188   // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM)
  189   // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html
  190   goto DpaHandleReturnFALSE;
  191 
  192   // -------------------------------------------------
  193 _DpaEvent_ReceiveDpaResponse:
  194   // Called after DPA response was received at coordinator
  195   // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html
  196 
  197   //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  198   goto DpaHandleReturnFALSE;
  199 
  200   // -------------------------------------------------
  201 _DpaEvent_IFaceReceive:
  202   // Called after DPA request from interface master was received at coordinator
  203   // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html
  204 
  205   //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  206   goto DpaHandleReturnFALSE;
  207 
  208   // -------------------------------------------------
  209 _DpaEvent_PeerToPeer:
  210   // Called when peer-to-peer (non-networking) packet is received
  211   // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html
  212   goto DpaHandleReturnFALSE;
  213 
  214   // -------------------------------------------------
  215 _DpaEvent_UserDpaValue:
  216   // Called when DPA is required to return User defined DPA value in the response
  217   // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html
  218   goto DpaHandleReturnFALSE;
  219 
  220   // -------------------------------------------------
  221 
  222 DpaHandleReturnFALSE:
  223   return FALSE;
  224 }
  225 
  226 //############################################################################################
  227 
  228 // Uncomment the following includes if the respective component is needed
  229 //#include "NFC.c"
  230 
  231 // 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)
  232 #include "DPAcustomHandler.h"
  233 //############################################################################################