1 // *********************************************************************
    2 //   Custom DPA Handler code template                                  *
    3 // *********************************************************************
    4 // Copyright (c) MICRORISC s.r.o.
    5 //
    6 // File:    $RCSfile: CustomDpaHandler-Template-Coordinator.c,v $
    7 // Version: $Revision: 1.20 $
    8 // Date:    $Date: 2023/03/07 08:03:13 $
    9 //
   10 // Revision history:
   11 //   2023/03/07  Release for DPA 4.30
   12 //   2022/10/05  Release for DPA 4.18
   13 //   2022/02/24  Release for DPA 4.17
   14 //   2021/08/20  Release for DPA 4.16
   15 //   2020/09/03  Release for DPA 4.15
   16 //   2020/02/27  Release for DPA 4.13
   17 //   2019/01/10  Release for DPA 4.00
   18 //   2017/08/14  Release for DPA 3.01
   19 //   2017/03/13  Release for DPA 3.00
   20 //   2015/08/05  Release for DPA 2.20
   21 //   2014/10/31  Release for DPA 2.10
   22 //   2014/04/30  Release for DPA 2.00
   23 //
   24 // *********************************************************************
   25 
   26 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/
   27 
   28 // Default IQRF include (modify the path according to your setup)
   29 #include "IQRF.h"
   30 
   31 // Implement Custom DPA Handler for Coordinator
   32 #define COORDINATOR_CUSTOM_HANDLER
   33 
   34 // Default DPA header (modify the path according to your setup)
   35 #include "DPA.h"
   36 // Default Custom DPA Handler header (modify the path according to your setup)
   37 #include "DPAcustomHandler.h"
   38 
   39 // Uncomment the following includes if the respective component is needed
   40 // IQRF standards header (modify the path according to your setup)
   41 //#include "IQRFstandard.h"
   42 //#include "IQRF_HWPID.h"
   43 // I2C Master library
   44 //#include "NFC.c"
   45 
   46 //############################################################################################
   47 
   48 // Place for global variables shared among CustomDpaHandler() and other function, otherwise local [static] variables are recommended
   49 // example: uns8 globalCounter;
   50 
   51 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location!
   52 //############################################################################################
   53 // https://doc.iqrf.org/DpaTechGuide/pages/custom-dpa-handler.html
   54 bit CustomDpaHandler()
   55 //############################################################################################
   56 {
   57   // Handler presence mark
   58   clrwdt();
   59 
   60   // Place for local static variables used only within CustomDpaHandler() among more events
   61   // example: static bit interruptOccured;
   62 
   63   // Detect DPA event to handle (unused event handlers can be commented out or even deleted)
   64   switch ( GetDpaEvent() )
   65   {
   66       // -------------------------------------------------
   67     case DpaEvent_Idle:
   68       // Do a quick background work when RF packet is not received
   69       // https://doc.iqrf.org/DpaTechGuide/pages/idle.html
   70       break;
   71 
   72       // -------------------------------------------------
   73     case DpaEvent_Reset:
   74       // Called after module is reset
   75       // https://doc.iqrf.org/DpaTechGuide/pages/ResetEvent.html
   76 
   77       //goto DpaHandleReturnTRUE; // return TRUE only if you handle node bonding/unbonding
   78       break;
   79 
   80       // -------------------------------------------------
   81     case DpaEvent_Init:
   82       // Do a one time initialization before main loop starts
   83       // https://doc.iqrf.org/DpaTechGuide/pages/init.html
   84       break;
   85 
   86       // -------------------------------------------------
   87     case DpaEvent_ReceiveDpaRequest:
   88       // Called after DPA request was received
   89       // https://doc.iqrf.org/DpaTechGuide/pages/receivedparequest.html
   90 
   91       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
   92       break;
   93 
   94       // -------------------------------------------------
   95     case DpaEvent_BeforeSendingDpaResponse:
   96       // Called before sending DPA response back to originator of DPA response
   97       // https://doc.iqrf.org/DpaTechGuide/pages/beforesendingdparesponse.html
   98       break;
   99 
  100       // -------------------------------------------------
  101     case DpaEvent_Notification:
  102       // Called after DPA request was processed and after DPA response was sent
  103       // https://doc.iqrf.org/DpaTechGuide/pages/notification.html
  104       break;
  105 
  106       // -------------------------------------------------
  107     case DpaEvent_AfterRouting:
  108       // Called after Notification and after routing of the DPA response was finished
  109       // https://doc.iqrf.org/DpaTechGuide/pages/afterrouting.html
  110       break;
  111 
  112       // -------------------------------------------------
  113     case DpaEvent_DisableInterrupts:
  114       // Called when device needs all hardware interrupts to be disabled (before Reset, Restart, LoadCode, Remove bond and run RFPGM)
  115       // https://doc.iqrf.org/DpaTechGuide/pages/eventDisableInterrupts.html
  116       break;
  117 
  118       // -------------------------------------------------
  119     case DpaEvent_ReceiveDpaResponse:
  120       // Called after DPA response was received at coordinator
  121       // https://doc.iqrf.org/DpaTechGuide/pages/receivedparesponse.html
  122 
  123       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  124       break;
  125 
  126       // -------------------------------------------------
  127     case DpaEvent_IFaceReceive:
  128       // Called after DPA request from interface master was received at coordinator
  129       // https://doc.iqrf.org/DpaTechGuide/pages/ifacereceive.html
  130 
  131       //goto DpaHandleReturnTRUE; // return TRUE to skip default processing
  132       break;
  133 
  134       // -------------------------------------------------
  135     case DpaEvent_PeerToPeer:
  136       // Called when peer-to-peer (non-networking) packet is received
  137       // https://doc.iqrf.org/DpaTechGuide/pages/peertopeer.html
  138       break;
  139 
  140       // -------------------------------------------------
  141     case DpaEvent_UserDpaValue:
  142       // Called when DPA is required to return User defined DPA value in the response
  143       // https://doc.iqrf.org/DpaTechGuide/pages/userdpavalue.html
  144       break;
  145 
  146       // -------------------------------------------------
  147     case DpaEvent_DpaRequest:
  148       // Called to interpret DPA request for peripherals
  149       // https://doc.iqrf.org/DpaTechGuide/pages/EventDpaRequest.html
  150       IfDpaEnumPeripherals_Else_PeripheralInfo_Else_PeripheralRequest()
  151       {
  152         // -------------------------------------------------
  153         // Peripheral enumeration
  154         // https://doc.iqrf.org/DpaTechGuide/pages/enumerate-peripherals.html
  155 
  156         _DpaMessage.EnumPeripheralsAnswer.UserPerNr |= 0; // ?
  157         // FlagUserPer( _DpaMessage.EnumPeripheralsAnswer.UserPer, PNUM_USER + 0 ); // ?
  158         _DpaMessage.EnumPeripheralsAnswer.HWPID |= 0x000F; // ????
  159         _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0; // ????
  160 
  161 DpaHandleReturnTRUE:
  162         return TRUE;
  163       }
  164       else
  165       {
  166       // -------------------------------------------------
  167       // Get information about peripheral
  168       // https://doc.iqrf.org/DpaTechGuide/pages/get-peripheral-info.html
  169 
  170       if ( _PNUM == PNUM_USER + 0 ) // ?
  171       {
  172         _DpaMessage.PeripheralInfoAnswer.PerT = 0; // PERIPHERAL_TYPE_?
  173         _DpaMessage.PeripheralInfoAnswer.PerTE = 0; // PERIPHERAL_TYPE_EXTENDED_?
  174         _DpaMessage.PeripheralInfoAnswer.Par1 = 0; // ?
  175         _DpaMessage.PeripheralInfoAnswer.Par2 = 0; // ?
  176         goto DpaHandleReturnTRUE;
  177       }
  178 
  179       break;
  180       }
  181 
  182       // -------------------------------------------------
  183       // Handle peripheral command
  184       // https://doc.iqrf.org/DpaTechGuide/pages/handle-peripheral-request.html
  185 
  186       if ( _PNUM == PNUM_USER + 0 ) // ?
  187       {
  188         if ( _PCMD == 0 ) // ????
  189         {
  190           goto DpaHandleReturnTRUE;
  191         }
  192       }
  193 
  194       break;
  195   }
  196 
  197 DpaHandleReturnFALSE:
  198   return FALSE;
  199 }
  200 
  201 //############################################################################################
  202 // Uncomment the following includes if the respective component is needed
  203 //#include "NFC.c"
  204 
  205 // 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)
  206 #include "DPAcustomHandler.h"
  207 //############################################################################################