Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt

This code example performs a simple initialization and AutoProgrma AutoProgram based on https://elprotronic.atlassian.net/wiki/spaces/FPGPARM/pages/57770262/Basic+demo+code+sequence and follows it with an infinite loop that prints voltage Voltage and current Current samples from the adapter. For this example code to work properly, the user must be programming with the XStream-Iso, or XStreamPro-Iso (black) adapters.

This code sequence is taken from the LinuxCommandLineDemo installation directory for Linux, however, the same sequence of calls will work in other environments:

The code sequence is as follows:

  • Find adapters and perform initialization using F_OpenInstancesAndFPAs((char *)input.c_str()) and F_Initialization()

    • In this example, F_Set_FPA_index (0) is called, which means that all adapters will be initialized.

  • Read configuration and code files using input parameters, these are paths to local files, F_ConfigFileLoad( argv[1] ) and F_ReadCodeFile( argv[2] ) respectively. If the config file already has code paths included, then the latter is not required.

  • Standard Auto Program and print report message sequence, F_AutoProgram() followed by F_Report_Message()

  • The crux of this example is in the last loop. First clear sample history using F_XS_Clr_ADC_av_history and repeatedly call F_Get_Power_Results(xs_adc.members)

    • xs_adc will contain the details of the last sample taken.

  • Some optional code can be added before the loop depending on settings to improve monitoring:

    Code Block
    languagecpp
    //turn on target if config file did not select "Start Application Program"
    F_Power_Target(1); 
    
    //tri-state pins to minimize leakage
    F_Set_fpa_io_state( DEFAULT_JTAG_3ST, DEFAULT_RESET_3ST, 1 ); 
    
    //XStreamPro-Iso only
    //disable pull-up to minimize leakage
    //max. 10nA leakage
    F_XS_Update_HW_State(MODE_XS_IO_CLR_FLAGS, IO_PULLUP_EN);

Demo code:

Code Block
languagecpp
#include <stdio.h>
#include <string>
#include <iostream>

#ifdef FLASHPROARM
#include "../FlashProARM-Dll.h"
#endif

#ifdef GANGPROARM
#include "../GangProARM-Dll.h"
#endif

using namespace std;

union XS_ADC
{
  double	members[ XS_ADC_NUM_MEMBERS ];
  struct
  {
    double ExtVcc;				//actual external Vcc value in V
    double Vcc;					//actual Vcc from programmer value in V
    double Vpp;					//actual Vpp for fuse blown from programmer value in V
    double ExtVccMin;			//external Vcc value in V - min value from the last read up to now
    double ExtVccMax;			//external Vcc value in V - max value from the last read up to now
    double VccMin;				//Vcc value in V - min value from the last read up to now
    double VccMax;				//Vcc value in V - max value from the last read up to now
    double Icc_mA;				//Icc value in mA - current value
    double Icc_mA_av4;			//Icc value in mA - average for last 4 read (interval ~ 10ms)
    double Icc_mA_av16;			//Icc value in mA - average for last 16 read (interval ~ 10ms)
    double Icc_mA_min;			//Icc value in mA - min value from the last read up to now
    double Icc_mA_max;			//Icc value in mA - max value from the last read up to now
    double Temperature;			//Temperature inside XStream in C deg
    double Icc_mA_av64;			//Icc value in mA - average for alpha 1/64
    double Icc_mA_av;			//Icc value in mA - average for defined alpha 1/N
  } data;
};

int main(int argc, char* argv[])
{
  int st;

  string input = "*# *";
  if(argc < 3)
  {
    cout<< "Usage: <config> <code>" << endl;
    return 1;
  }

  F_Trace_ON();
  cout << "F_OpenInstancesAndFPAs : " << dec <<   F_OpenInstancesAndFPAs((char *)input.c_str()) << endl;
  cout << "F_Get_FPA_SN : " << F_Get_FPA_SN(1) << endl;
  cout << "F_Set_FPA_index : " << dec << F_Set_FPA_index (0) << endl;
  cout << "F_Initialization : " << dec << F_Initialization() << endl;
  cout << "API Version " << hex << (0xFFF & F_DLLTypeVer()) << endl;
  cout << "Multi Version " << hex << (0xFFF & F_Multi_DLLTypeVer()) << endl;
  F_Set_FPA_index(1);
  cout << "F_ConfigFileLoad : " << dec << F_ConfigFileLoad( argv[1] ) << endl;
  cout << "F_ReadCodeFile : " << dec << F_ReadCodeFile( argv[2] ) << endl;
  cout << "F_Clear_Locked_Device : " << dec << F_Clear_Locked_Device() << endl;
  cout << "F_AutoProgram : " << dec << F_AutoProgram() << endl;
  F_Trace_OFF();
  cout << F_Report_Message() << endl;
  cout << "Press any key to continue power measurement in infinite loop" << endl;
  char c = getchar();
	
  F_XS_Clr_ADC_av_history();  
  
  F_Set_fpa_io_state( DEFAULT_JTAG_3ST, DEFAULT_RESET_3ST, 1 ); 
  F_XS_Update_HW_State(MODE_XS_IO_CLR_FLAGS, IO_PULLUP_EN);
  
  XS_ADC xs_adc;
  while(1)
  {
    F_Get_Power_Results(xs_adc.members);
    cout << "ExtVcc= " << xs_adc.data.ExtVcc;
    cout << " Vcc= " << xs_adc.data.Vcc;
    cout << " Vpp= " << xs_adc.data.Vpp;
    cout << " ExtVccMin= " << xs_adc.data.ExtVccMin;
    cout << " ExtVccMax= " << xs_adc.data.ExtVccMax;
    cout << " VccMin= " << xs_adc.data.VccMin;
    cout << " VccMax= " << xs_adc.data.VccMax;
    cout << " Icc_mA= " << xs_adc.data.Icc_mA;
    cout << " Icc_mA_av4= " << xs_adc.data.Icc_mA_av4;
    cout << " Icc_mA_av16= " << xs_adc.data.Icc_mA_av16;
    cout << " Icc_mA_min= " << xs_adc.data.Icc_mA_min;
    cout << " Icc_mA_max= " << xs_adc.data.Icc_mA_max;
    cout << " Temperature= " << xs_adc.data.Temperature;
    cout << " Icc_mA_av64= " << xs_adc.data.Icc_mA_av64;
    cout << " Icc_mA_av= " << xs_adc.data.Icc_mA_av;
    cout << endl;
    cout.flush();
  }
  return 0;
}