1 // *********************************************************************
    2 //   Custom DPA Handler code example - Custom indication               *
    3 // *********************************************************************
    4 // Copyright (c) MICRORISC s.r.o.
    5 //
    6 // File:    $RCSfile: CustomDpaHandler-CustomIndicate.c,v $
    7 // Version: $Revision: 1.10 $
    8 // Date:    $Date: 2021/04/26 15:13:50 $
    9 //
   10 // Revision history:
   11 //   2020/04/03  Release for DPA 4.14
   12 //   2020/02/27  Release for DPA 4.13
   13 //
   14 // *********************************************************************
   15 
   16 // Online DPA documentation https://doc.iqrf.org/DpaTechGuide/
   17 
   18 // Default IQRF include (modify the path according to your setup)
   19 #include "IQRF.h"
   20 
   21 // Default DPA header (modify the path according to your setup)
   22 #include "DPA.h"
   23 // Default Custom DPA Handler header (modify the path according to your setup)
   24 #include "DPAcustomHandler.h"
   25 
   26 // Must be the 1st defined function in the source code in order to be placed at the correct FLASH location!
   27 //############################################################################################
   28 bit CustomDpaHandler()
   29 //############################################################################################
   30 {
   31   // Handler presence mark
   32   clrwdt();
   33 
   34   // Detect DPA event to handle (unused event handlers can be commented out or even deleted)
   35   switch ( GetDpaEvent() )
   36   {
   37     // -------------------------------------------------
   38     case DpaEvent_Interrupt:
   39       // Do an extra quick background interrupt work
   40       return Carry;
   41 
   42       // -------------------------------------------------
   43     case DpaEvent_Init:
   44       // Do a one time initialization before main loop starts
   45 
   46       // Set custom indication GPIO to output
   47       TRISA.0 = 0;
   48       break;
   49 
   50       // -------------------------------------------------
   51     case DpaEvent_Indicate:
   52       // Called to allow a customization of the device indication
   53 
   54       // userReg1 = Control byte with only valid bit.0-1, bit.2-7 = 0
   55 
   56       // Control == 0 (indication off) ?
   57       if ( userReg1 == 0 )
   58       {
   59 _IndicateOff:
   60         stopLEDR();
   61         LATA.0 = 0;
   62       }
   63       else
   64       {
   65         // Indication on
   66         setLEDR();
   67         LATA.0 = 1;
   68 
   69         // Timed indication?
   70         if ( userReg1.1 )
   71         {
   72           // 1 s
   73           W = 10 * 2;
   74           // Control != 2
   75           if ( userReg1.0 )
   76             // 10 s
   77             userReg1 = W;
   78           do
   79           {
   80             // 0.5 s step
   81             waitDelay( 50 );
   82             clrwdt();
   83           } while ( --userReg1 != 0 );
   84 
   85           // Switch off the indication
   86           goto _IndicateOff;
   87         }
   88       }
   89 
   90       // return TRUE to skip default indication by LEDR and LEDG (userReg1 might be thus modified)
   91       return TRUE;
   92 
   93       // -------------------------------------------------
   94     case DpaEvent_BeforeSleep:
   95       // Called before going to sleep
   96 
   97       // Switch off custom indication via GPIO
   98       goto _IndicateOff;
   99 
  100       // -------------------------------------------------
  101     case DpaEvent_DpaRequest:
  102       // Called to interpret DPA request for peripherals
  103       // -------------------------------------------------
  104       // Peripheral enumeration
  105       if ( IsDpaEnumPeripheralsRequest() )
  106       {
  107         // We implement no user peripheral
  108         _DpaMessage.EnumPeripheralsAnswer.HWPID = 0x15DF;
  109         _DpaMessage.EnumPeripheralsAnswer.HWPIDver |= 0x0000;
  110         return TRUE;
  111       }
  112       break;
  113   }
  114 
  115   return FALSE;
  116 }
  117 
  118 //############################################################################################
  119 // 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)
  120 #include "DPAcustomHandler.h"
  121 //############################################################################################