Showing posts with label PIC. Show all posts
Showing posts with label PIC. Show all posts

Tuesday, December 16, 2008

Avoid auto padding by PIC32 compiler for data structure

Using __attribute__((packed)) for variable and structure member.




typedef struct sDaq2ComAggregationRaw001
{
GSNTYPES_BYTE FeederAndPhase; //0x01:Va 0x02:Vb....
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval; //Optional to be logged.--advanced feature ToDo
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval; //Optional to be logged.--advanced feature ToDo

}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_001;



typedef struct sDaq2ComAggregationRaw002
{
GSNTYPES_BYTE FeederAndPhase; //0x11:Feeder1PhaseA, 0x12:Feeder1PhaseB...0x41:Feeder4PhaseA
GSNTYPES_BYTE TimeStampCycles;
GSNTYPES_ULONG TimeStampSeconds;
GSNTYPES_DOUBLE llDft_Goertzel_Aggregation_SquareSumImgReal[CABLE_TRACKER_MAX_NUM_HARMONICS]; GSNTYPES_DOUBLE llSquareSumForAggregationLog;
GSNTYPES_DOUBLE llSquareSumPerCycleMaxOverLoggingInterval;
GSNTYPES_DOUBLE llSquareSumPerCycleMinOverLoggingInterval;
GSNTYPES_DOUBLE llActivePwrSumForAggregationLog; //

}
__attribute__((packed)) S_DAQ2COM_AGGREGATION_RAW_002;



typedef struct sStructureID
{
GSNTYPES_USHORT variation;
GSNTYPES_BYTE version;
GSNTYPES_BYTE type; //config, log, events. see E_StructType definition.

}__attribute__((packed)) S_StructureID;


typedef struct sRdHeadDataStorage
{
GSNTYPES_USHORT len; //is based on the struct ID,number bytes of record body,exclude record header.
S_StructureID structID;
}S_RecordHeadDataStorage;



typedef union sDataRecordBody
{
//The ptrDataBody could point to following data Structures.

S_COM_CONFIG_BLOCK_001 com_configuration_001;
S_COM_CONFIG_BLOCK_002 com_configuration_002;
S_DAQ_CONFIG_BLOCK_001 daq_configuration_001;
S_DAQ_CONFIG_BLOCK_002 daq_configuration_002;
S_DAQ2COM_AGGREGATION_RAW_001 daq2com_aggregation_raw_001;
S_DAQ2COM_AGGREGATION_RAW_002 daq2com_aggregation_raw_002;
S_DAQ2COM_AGGREGATION_RAW_003 daq2com_aggregation_raw_003;
S_DAQ2COM_EVENTS_RAW_001 daq2com_events_raw_001;
S_DAQ2COM_EVENTS_RAW_002 daq2com_events_raw_002;
S_DAQ2COM_EVENTS_RAW_003 daq2com_events_raw_003;
S_COM2EEP_AGGREGATION_REAL_001 com2eep_aggregation_real_001;
S_COM2EEP_AGGREGATION_REAL_002 com2eep_aggregation_real_002;
S_COM2EEP_AGGREGATION_REAL_003 com2eep_aggregation_real_003;
S_COM2EEP_EVENTS_REAL_001 com2eep_events_real_001;
S_COM2EEP_EVENTS_REAL_002 com2eep_events_real_002;
S_COM2EEP_EVENTS_REAL_003 com2eep_events_real_003;

}U_DataRecordBody;


typedef struct sDataRecord
{
S_RecordHeadDataStorage rdHead;
U_DataRecordBody rdDataBody;

}__attribute__((packed)) S_DataRecord;

Monday, November 24, 2008

ICSP pinouts

From:

http://www.embedinc.com/picprg/icsp.htm

ICSP Overview

In-circuit Serial Programming (ICSP)


PICs are programmed using 5 signals. The data is transferred using a two wire synchronous serial scheme, with the clock always controlled by the programmer. The ICSP signals are:

GND

Negative power input to the PIC and the ground reference for the remaining signals. Voltages of the other signals are implicitly with respect to GND unless otherwise specified.

Vdd

This is the positive power input to the PIC. Some programmers require this to be provided by the circuit (circuit must be at least partially powered up), some programmers expect to drive this line themselves and require the circuit to be off, while others can be configured either way (like the Microchip ICD2). The Embed Inc programmers expect to drive the Vdd line themselves and require the target circuit to be off during programming.

Vpp

Programming mode voltage. This must be connected to the MCLR pin of the target PIC. To put the PIC into programming mode, this line must be in a specified range that varies between PICs, but is always above Vdd. The highest maximum allowed Vpp voltage that we know of is 13.5 volts. There is no one Vpp voltage that is within the valid Vpp range of all PICs.

PGC

Clock line of the serial data interface. This line swings from GND to Vdd and is always driven by the programmer. Data is transferred on the falling edge.

PGD

Serial data line. The serial interface is bi-directional, so this line can be driven by either the programmer or the PIC depending on the current operation. In either case this line swings from GND to Vdd. A bit is transferred on the falling edge of PGC.