Skip to content

Commit

Permalink
upgrade packer
Browse files Browse the repository at this point in the history
  • Loading branch information
pkotamnives committed Nov 16, 2023
1 parent 035e085 commit 79fa15c
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 13 deletions.
2 changes: 1 addition & 1 deletion projects/cm_mcu/LocalTasks.c
Original file line number Diff line number Diff line change
Expand Up @@ -719,7 +719,7 @@ uint16_t getFFtemp(const uint8_t i)
}

#ifdef REV2
uint16_t getFFoptpow(const uint8_t i)
uint16_t getFFavgoptpow(const uint8_t i)
{

uint16_t avg_val = 0;
Expand Down
2 changes: 1 addition & 1 deletion projects/cm_mcu/Tasks.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ bool isEnabledFF(int ff);
void setFFmask(uint32_t ff_combined_mask);
void readFFpresent(void);
uint16_t getFFtemp(const uint8_t i);
uint16_t getFFoptpow(const uint8_t i);
uint16_t getFFavgoptpow(const uint8_t i);
uint16_t getFFpresentbit(const uint8_t i);
#ifdef REV2
void getFFpart(void);
Expand Down
42 changes: 31 additions & 11 deletions projects/cm_mcu/ZynqMonTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,26 +44,46 @@
// See Google Docs, 'CM uC Sensor register map'

#define SENSOR_MESSAGE_START_OF_FRAME_NIB 2
#define SENSOR_MESSAGE_START_OF_FRAME_NIB_V2 3
#define RESERVED_DATA_V2 0x9 // 0b1001
#define SENSOR_MESSAGE_DATA_FRAME_NIB 0
#define SENSOR_MESSAGE_HEADER_OFFSET 6
#define SENSOR_SIX_BITS 0x3F
#define DATA_FOUR_BITS 0xF
#define DATA_TWO_BITS_MASK0 0x3 // a mask for 0b11
#define DATA_TWO_BITS_MASK1 0xC // a mask for 0b1100
#define DATA_TWO_BITS_MASK2 0x30 // a mask for 0b110000
#define SENSOR_MESSAGE_START_OF_FRAME \
(SENSOR_MESSAGE_START_OF_FRAME_NIB << SENSOR_MESSAGE_HEADER_OFFSET)
#define SENSOR_MESSAGE_START_OF_FRAME_V2 \
(SENSOR_MESSAGE_START_OF_FRAME_NIB_V2 << SENSOR_MESSAGE_HEADER_OFFSET)
#define SENSOR_MESSAGE_DATA_FRAME (SENSOR_MESSAGE_DATA_FRAME_NIB << SENSOR_MESSAGE_HEADER_OFFSET)

static void format_data(const uint8_t sensor, const uint16_t data, uint8_t message[4])
static void format_data(const uint8_t sensor, const uint16_t data, uint8_t message[5])
{
// header and start of sensor (6 bits, sensor[7:2]
message[0] = SENSOR_MESSAGE_START_OF_FRAME | ((sensor >> 2) & SENSOR_SIX_BITS);
// data frame 1, rest of sensor[1:0] (2 bits) and start of data[15:12] (4 bits)
uint8_t tmp_message_0;
uint8_t tmp_message_1;
// version2 modifies version1's bytes
// modified version1 header and start of sensor (6 bits, sensor[7:2]
message[0] = SENSOR_MESSAGE_START_OF_FRAME_V2;
tmp_message_0 = ((sensor >> 2) & SENSOR_SIX_BITS);
message[0] |= (SENSOR_MESSAGE_START_OF_FRAME_NIB_V2 << 4) | ((tmp_message_0 >> 2) & DATA_FOUR_BITS);
// modified version1 data frame with a reserved-data byte
// version1 data frame : rest of sensor[1:0] (2 bits) and start of data[15:12] (4 bits)
message[1] = SENSOR_MESSAGE_DATA_FRAME;
message[1] |= ((sensor & 0x3) << 4) | ((data >> 12) & 0xF);
// data frame 2, data[11:6] (6 bits)
tmp_message_1 = ((sensor & 0x3) << 4) | ((data >> 12) & 0xF);
message[1] |= (tmp_message_0 & DATA_TWO_BITS_MASK0) << 4 | ((tmp_message_1 & DATA_TWO_BITS_MASK2) >> 2) | ((RESERVED_DATA_V2 & DATA_TWO_BITS_MASK1)>>2);

// modified version1 data frame with a reserved-data byte
message[2] = SENSOR_MESSAGE_DATA_FRAME;
message[2] |= (data >> 6) & 0x3F;
// data frame 3, data[5:0] ( 6 bits )
message[2] |= ((RESERVED_DATA_V2 & DATA_TWO_BITS_MASK0 ) << 4) | (tmp_message_1 & DATA_FOUR_BITS);

// take version1 data frame 2, data[11:6] (6 bits)
message[3] = SENSOR_MESSAGE_DATA_FRAME;
message[3] |= data & 0x3F;
message[3] |= (data >> 6) & 0x3F;
// take version1 data frame 3, data[5:0] ( 6 bits )
message[4] = SENSOR_MESSAGE_DATA_FRAME;
message[4] |= data & 0x3F;
}

#ifdef ZYNQMON_TEST_MODE
Expand Down Expand Up @@ -382,8 +402,8 @@ void zm_set_firefly_info(struct zynqmon_data_t data[], int start)
data[ll].data.us = 0xff; // special stale value
}
else {
data[ll].data.us = getFFoptpow(j); // sensor value and type
log_debug(LOG_SERVICE, "opt power ? for ff %d: 0x%02x\r\n", j, getFFoptpow(j));
data[ll].data.us = getFFavgoptpow(j); // sensor value and type
log_debug(LOG_SERVICE, "opt power ? for ff %d: 0x%02x\r\n", j, getFFavgoptpow(j));
}
data[ll].sensor = ll + start;
++ll;
Expand Down

0 comments on commit 79fa15c

Please sign in to comment.