Other Parts Discussed in Thread: C2000WARE
I have a long struct as below
#ifndef __DAB_DATAINTERFACE_H
#define __DAB_DATAINTERFACE_H
#include "dab_settings.h"
#include "dab_varsExtern.h"
#include "dab_user_macro.h"
#include "dab_debug.h"
typedef enum {
DIAGNOSTIC = 0,
DIAGNOSTIC_2_BROWN_OUT,
BROWN_OUT,
BROWN_OUT_2_BROWN_IN,
BROWN_IN,
BROWN_IN_2_PRE_CHARGE,
PRE_CHARGE,
PRE_CHARGE_2_DAB_OFF,
DAB_OFF,
DAB_OFF_2_DAB_RAMP,
DAB_RAMP,
DAB_RAMP_2_DAB_OFF,
DAB_ON,
DAB_ON_2_DAB_OFF,
DAB_FAULT
} DABSTATEMACHINE;
typedef enum {
RELAY_OPEN = 0,
RELAY_CLOSE
} RELAYCONTROL;
typedef enum {
POWER_OFF = 0,
POWER_ON
} CONVERTERCONTROL;
struct DATAINTERFACE
{
struct CAN
{
struct LINUXREQUEST
{
struct LINUXOUTPUT
{
float32_t Vout_Volt;
float32_t Iout_Amp;
CONVERTERCONTROL PowerOnOff;
} output;
union LINUXRELAY
{
uint32_t all;
struct LINUXRELAYCONTROLBITS {
uint32_t inputRelayPosNegOpenClose : 1;
uint32_t outputRelayPosOnOpenClose : 1;
uint32_t outputRelayNegOnOpenClose : 1;
uint32_t revd : 29;
} bits;
} relay;
} Linuxrequest;
struct DABRESPOND
{
float32_t vSec_Volt;
float32_t iSec_Amp;
float32_t vPrim_Volt;
float32_t iPrim_Amp;
float32_t temperature_DegreeC;
union DABFAULTSTATUS
{
uint32_t all;
struct BITS
{
uint32_t inputOVP : 1; //1 bit
uint32_t inputOCP : 1; //2
uint32_t outputOVP : 1; //3
uint32_t outputOCP : 1; //4
uint32_t outputSCP : 1; //5
uint32_t relay10Error : 1; //6
uint32_t relay11Error : 1; //7
uint32_t relay12Error : 1; //8
uint32_t ramError : 1; //9
uint32_t flashError : 1; //10
uint32_t adcError : 1; //11
uint32_t canBusHeatbeatLoss : 1; //12
uint32_t interruptError : 1; //13
uint32_t pcError : 1; //14
uint32_t timerError : 1; //15
uint32_t addressError : 1; //16
uint32_t revd : 14; //17-30
uint32_t requestedVoltInvalid : 1; //31
uint32_t brownOut : 1; //32 bit
} bits;
} dab_faultStatus;
DABSTATEMACHINE dabState;
} Dabrespond;
} can;
struct INTERNALINTERFACE
{
struct CONVERTER
{
float32_t DAB_vSecRef_Volt;
float32_t DAB_iSecRef_Amp;
CONVERTERCONTROL PowerOnOff;
} converter;
uint32_t stateMachineTransit_Counter;
struct AVG
{
float32_t vSecSensed_Volt;
float32_t iSecSensed_Amp;
float32_t vPrimSensed_Volt;
float32_t iPrimSensed_Amp;
}avg;
union DABRELAYCONTROL
{
uint32_t all;
struct DABRELAYCONTROLBITS
{
uint32_t inputRelayPosNegOpenClose : 1;
uint32_t outputRelayPosOnOpenClose : 1;
uint32_t outputRelayNegOnOpenClose : 1;
uint32_t revd : 29;
} bits;
}relay;
union INTERNALFAULTSTATUS
{
uint32_t all;
struct INTERNALFAULTSTATUSBITS
{
uint32_t inputOVP : 1; //1 bit
uint32_t inputOCP : 1; //2
uint32_t outputOVP : 1; //3
uint32_t outputOCP : 1; //4
uint32_t outputSCP : 1; //5
uint32_t relay10Error : 1; //6
uint32_t relay11Error : 1; //7
uint32_t relay12Error : 1; //8
uint32_t ramError : 1; //9
uint32_t flashError : 1; //10
uint32_t adcError : 1; //11
uint32_t canBusHeatbeatLoss : 1; //12
uint32_t interruptError : 1; //13
uint32_t pcError : 1; //14
uint32_t timerError : 1; //15
uint32_t addressError : 1; //16
uint32_t revd : 14; //17-30
uint32_t requestedVoltInvalid : 1;
uint32_t brownOut : 1; //32 bit
} bits;
} dab_faultStatus;
struct REFERDATA
{
float32_t iSec_Amp;
float32_t vSec_Volt;
}outputRef;
DABSTATEMACHINE dabState;
} InternalInterface;
struct debugVars
{
float32_t floating[10];
uint32_t unsignedInt[10];
#ifdef DEDUG_SIMULATION
struct PU
{
float32_t vSec;
float32_t iSec;
float32_t vPrim;
float32_t iPrim;
float32_t vSec_limit;
float32_t iSec_limit;
}pu;
#endif
} debugVars;
};
extern volatile struct DATAINTERFACE g_data;
#endif
I define object using "volatile struct DATAINTERFACE g.data" in main loop. I got a unexpected result in code.
1. In "if statement" below. program flow can enter Code area. g_data.data.InternalInterface.converter.DAB.vSecRef_Volt = 0.0 (In debeg expression veiw) and the value DAB_MINSEC_VOLTAGE = 300.0f. It does not make send to me.
if ((g_data.InternalInterface.converter.DAB_vSecRef_Volt > DAB_MINSEC_VOLTAGE))
{
Code area.
2. In floating point calculation, the result will be very very small sometime ( < 0.00000000000xxxx). Below is the code of calculation where g_data.debugVars.pu.iPrim = 0.5, DAB_IPRIM_MAX_SENSE = 30.0f.
g_data.InternalInterface.avg.iPrimSensed_Amp = (float32_t)(g_data.debugVars.pu.iPrim * DAB_IPRIM_MAX_SENSE);
I am using opt_level = 0. To me the problem should not due to optimization. I am not sure my structure is correct or not? Please advise.




