Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Temperature messages for error buffer #45

Merged
merged 9 commits into from
Mar 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion common/power_ctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ disable_ps(void)
// to finish their activity. For Rev2 of the CM (when the I2C
// pullups are from management power) this delay can be reduced or
// removed.
vTaskDelay(pdMS_TO_TICKS(200));
vTaskDelay(pdMS_TO_TICKS(500));

// disable in reverse order
for (int prio = num_priorities; prio > 0; --prio) {
Expand Down
16 changes: 8 additions & 8 deletions common/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ void errbuffer_reset(errbuf_handle_t ebuf){
ebuf->head = ebuf->minaddr;
ebuf->counter=0;
ebuf->last=0;
errbuffer_put(ebuf, RESET_BUFFER,0);
errbuffer_put(ebuf, EBUF_RESET_BUFFER,0);
return;
}

Expand All @@ -174,17 +174,17 @@ void errbuffer_put(errbuf_handle_t ebuf, uint16_t errcode, uint16_t errdata){
// If duplicated error code...
if(errcode == ebuf->last){

// if counter is not a multiple of 4, don't write new entry
if(oldcount%4!=0){ ebuf->counter=ebuf->counter+1; }
// if counter is not a multiple of COUNTER_UPDATE, don't write new entry
if(oldcount%COUNTER_UPDATE!=0){ ebuf->counter=ebuf->counter+1; }

// if counter has already reached max value, increment head
if(oldcount%16==0){ //Change this to use COUNTER_OFFSET
if(oldcount%(1<<COUNTER_OFFSET)==0){ //Change this to use COUNTER_OFFSET
ebuf->counter=0;
ebuf->head = increase_head(ebuf);
write_eeprom(0,increase_head(ebuf)); }

// if counter is multiple of 4, write entry and increment counter
if(oldcount%4==0){
// if counter is multiple of COUNTER_UPDATE, write entry and increment counter
if(oldcount%COUNTER_UPDATE==0){
ebuf->counter=ebuf->counter+1;
write_eeprom(errbuffer_entry(errcode,errdata),decrease_head(ebuf)); }
}
Expand All @@ -198,8 +198,8 @@ void errbuffer_put(errbuf_handle_t ebuf, uint16_t errcode, uint16_t errdata){
return;
}

void errbuffer_get(errbuf_handle_t ebuf, uint32_t (*arrptr)[EBUF_NGET]){
int i=0,j=0,max=EBUF_NGET;
void errbuffer_get(errbuf_handle_t ebuf, uint32_t num, uint32_t (*arrptr)[num]){
int i=0,j=0,max=num;
while(i<max){i++; ebuf->head = decrease_head(ebuf);}
while(j<max){
(*arrptr)[j] = read_eeprom_single(ebuf->head);
Expand Down
43 changes: 25 additions & 18 deletions common/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,6 @@
#include <stdbool.h>


// write to and read from eeprom
void write_eeprom(uint32_t data, uint32_t addr);
uint32_t read_eeprom_single(uint32_t addr);
uint64_t read_eeprom_multi(uint32_t addr);


// write, read or toggle GPIO pin by name
void write_gpio_pin(int pin, uint8_t value);
uint8_t read_gpio_pin(int pin);
Expand All @@ -26,25 +20,38 @@ uint8_t toggle_gpio_pin(int pin);

void setupActiveLowPins(void);


// EEPROM
#define SN_ADDR 64
#define FF_ADDR (SN_ADDR+4)

void write_eeprom(uint32_t data, uint32_t addr);
uint32_t read_eeprom_single(uint32_t addr);
uint64_t read_eeprom_multi(uint32_t addr);

// EEPROM buffer
#define EBUF_MINBLK 2
#define EBUF_MAXBLK 5
#define EBUF_NGET 5 // Number of entries returned with errbuffer_get

#define ERRDATA_OFFSET 8 // Number of bits reserved for error data
#define ERRCODE_OFFSET 4 // Number of bits reserved for error codes
#define ERRDATA_OFFSET 7 // Number of bits reserved for error data
#define ERRCODE_OFFSET 5 // Number of bits reserved for error codes
#define COUNTER_OFFSET (16-ERRDATA_OFFSET-ERRCODE_OFFSET) // Number of bits reserved for message counter

#define ERRDATA_MASK 255
#define ERRCODE_MASK 3840
#define COUNTER_MASK 61440
#define ERRDATA_MASK ((1<<(ERRDATA_OFFSET))-1)
#define ERRCODE_MASK ((1<<(ERRDATA_OFFSET+ERRCODE_OFFSET))-1-ERRDATA_MASK)
#define COUNTER_MASK ((1<<(ERRDATA_OFFSET+ERRCODE_OFFSET+COUNTER_OFFSET))-1-ERRDATA_MASK-ERRCODE_MASK)

#define COUNTER_UPDATE 4 //Number of repeated entries that initiates a hardware counter update (re-write entry)

// error codes
#define RESTART 1
#define RESET_BUFFER 2
#define TEMP_HIGH 3
#define TEMP_NORMAL 4
#define PWR_OFF_TEMP 5 // add other pwr_off codes for different reasons
#define EBUF_RESTART 1
#define EBUF_RESET_BUFFER 2
#define EBUF_POWER_OFF 3
#define EBUF_POWER_OFF_TEMP 4
#define EBUF_POWER_ON 5

#define EBUF_TEMP_HIGH(status) ((1<<(ERRCODE_OFFSET-1))|status)
#define EBUF_TEMP_NORMAL EBUF_TEMP_HIGH(0)

typedef struct error_buffer_t error_buffer_t;
typedef error_buffer_t* errbuf_handle_t;
Expand All @@ -55,7 +62,7 @@ void errbuffer_init(errbuf_handle_t ebuf, uint8_t minblk, uint8_t maxblk);
void errbuffer_reset(errbuf_handle_t ebuf);

void errbuffer_put(errbuf_handle_t ebuf, uint16_t errcode, uint16_t errdata);
void errbuffer_get(errbuf_handle_t ebuf, uint32_t (*arrptr)[EBUF_NGET]);
void errbuffer_get(errbuf_handle_t ebuf, uint32_t num, uint32_t (*arrptr)[num]);

uint32_t errbuffer_capacity(errbuf_handle_t ebuf);
uint32_t errbuffer_minaddr(errbuf_handle_t ebuf);
Expand Down
74 changes: 55 additions & 19 deletions projects/cm_mcu/AlarmTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,28 +24,45 @@ enum temp_state {TEMP_UNKNOWN, TEMP_GOOD, TEMP_BAD};
enum alarm_state {ALM_UNKNOWN, ALM_GOOD, ALM_BAD};



// Status of the alarm task
static uint32_t status = 0x0;
uint32_t oldstatus;

// read-only, so no need to use queue
uint32_t getAlarmStatus()
{
return status;
}

#define INITIAL_ALARM_TEMP 65.0 // in Celsius duh
static float alarm_temp = INITIAL_ALARM_TEMP;
#define INITIAL_ALARM_TEMP_FF 50.0 // in Celsius duh
#define INITIAL_ALARM_TEMP_DCDC 75.0
#define INITIAL_ALARM_TEMP_TM4C 75.0
#define INITIAL_ALARM_TEMP_FPGA 75.0
static float alarm_temp_ff = INITIAL_ALARM_TEMP_FF;
static float alarm_temp_dcdc = INITIAL_ALARM_TEMP_DCDC;
static float alarm_temp_tm4c = INITIAL_ALARM_TEMP_TM4C;
static float alarm_temp_fpga = INITIAL_ALARM_TEMP_FPGA;

float getAlarmTemperature()
float getAlarmTemperature(enum device device_name)
{
return alarm_temp;
switch(device_name){
case TM4C: return alarm_temp_tm4c;
case DCDC: return alarm_temp_dcdc;
case FPGA: return alarm_temp_fpga;
case FF: return alarm_temp_ff;
default: return 0;
}
}

void setAlarmTemperature(const float newtemp)
void setAlarmTemperature(enum device device_name,const float newtemp)
{
alarm_temp = newtemp;
return;
switch(device_name){
case TM4C: alarm_temp_tm4c = newtemp; return;
case DCDC: alarm_temp_dcdc = newtemp; return;
case FPGA: alarm_temp_fpga = newtemp; return;
case FF: alarm_temp_ff = newtemp; return;
default: return;
}
}


Expand All @@ -54,8 +71,10 @@ void AlarmTask(void *parameters)
// initialize to the current tick time
TickType_t xLastWakeTime = xTaskGetTickCount();
uint32_t message; // this must be in a semi-permanent scope
uint16_t errbuf_data,errbuf_olddata=0;
enum temp_state current_temp_state = TEMP_UNKNOWN;
float buffer_maxtemp = INITIAL_ALARM_TEMP;
float temp_over_ff, temp_over_fpga, temp_over_tm4c, temp_over_dcdc, temp_over_max, worst_temp;
// todo: should be able to do this w just max_temp_over and worst_temp, just to clean it up

vTaskDelayUntil( &xLastWakeTime, pdMS_TO_TICKS( 2500 ) );

Expand All @@ -81,11 +100,17 @@ void AlarmTask(void *parameters)

// microcontroller
float tm4c_temp = getADCvalue(ADC_INFO_TEMP_ENTRY);
if ( tm4c_temp > alarm_temp ) status |= ALM_STAT_TM4C_OVERTEMP;
if ((tm4c_temp-buffer_maxtemp)/5>0) buffer_maxtemp=tm4c_temp;
if ( tm4c_temp > alarm_temp_tm4c ) status |= ALM_STAT_TM4C_OVERTEMP;
temp_over_tm4c = alarm_temp_tm4c-tm4c_temp;
temp_over_max = temp_over_tm4c;
worst_temp=tm4c_temp;
// FPGA
float max_fpga = MAX(fpga_args.pm_values[0], fpga_args.pm_values[1]);
if ( max_fpga > alarm_temp) status |= ALM_STAT_FPGA_OVERTEMP;
if ( max_fpga > alarm_temp_fpga) status |= ALM_STAT_FPGA_OVERTEMP;
temp_over_fpga = alarm_temp_fpga-max_fpga;
if (temp_over_fpga>temp_over_max){
temp_over_max = temp_over_fpga;
worst_temp=max_fpga;}

// DCDC. The first command is READ_TEMPERATURE_1.
// I am assuming it stays that way!!!!!!!!
Expand All @@ -98,7 +123,11 @@ void AlarmTask(void *parameters)
max_dcdc_temp = thistemp;
}
}
if ( max_dcdc_temp > alarm_temp ) status |= ALM_STAT_DCDC_OVERTEMP;
if ( max_dcdc_temp > alarm_temp_tm4c ) status |= ALM_STAT_DCDC_OVERTEMP;
temp_over_dcdc = alarm_temp_dcdc-max_dcdc_temp;
if (temp_over_dcdc>temp_over_max){
temp_over_max = temp_over_dcdc;
worst_temp=max_dcdc_temp;}
// Fireflies. These are reported as ints but we are asked
// to report a float.
int8_t imax_ff_temp = -99;
Expand All @@ -107,21 +136,28 @@ void AlarmTask(void *parameters)
if ( v > imax_ff_temp )
imax_ff_temp = v;
}
if ( (float)imax_ff_temp > alarm_temp ) status |= ALM_STAT_FIREFLY_OVERTEMP;
if ( (float)imax_ff_temp > alarm_temp_ff ) status |= ALM_STAT_FIREFLY_OVERTEMP;
temp_over_ff = alarm_temp_ff-imax_ff_temp;
if (temp_over_ff>temp_over_max){
temp_over_max=temp_over_ff;
worst_temp=imax_ff_temp;}

if ( status && current_temp_state != TEMP_BAD ) {
// If temp goes from good to bad, turn on alarm, send error message to buffer
// data field takes the status bitmask plus temp divided by 4 (rounded)
uint16_t errbuf_data=((uint16_t)status<<4)|((uint16_t)(buffer_maxtemp+2)>>2);
errbuffer_put(ebuf, TEMP_HIGH,errbuf_data);
errbuf_data=(0x0FFFFFFFU)&(uint8_t)worst_temp;
if ((errbuf_data!=errbuf_olddata)||(status!=oldstatus)){
// only send message when status or temp have changed, to avoid filling up buffer
errbuffer_put(ebuf, EBUF_TEMP_HIGH(status),errbuf_data);
errbuf_olddata=errbuf_data;
oldstatus=status;}
message = TEMP_ALARM;
xQueueSendToFront(xPwrQueue, &message, pdMS_TO_TICKS(100));
current_temp_state = TEMP_BAD;
}
else if ( !status && current_temp_state == TEMP_BAD ) {
// If temp goes from bad to good, turn off alarm, send message to buffer
errbuffer_put(ebuf, TEMP_NORMAL, 0);
buffer_maxtemp = INITIAL_ALARM_TEMP;
errbuf_data=(0x0FFFFFFFU&(uint8_t)worst_temp);
errbuffer_put(ebuf, EBUF_TEMP_NORMAL, errbuf_data);
message = TEMP_ALARM_CLEAR;
xQueueSendToFront(xPwrQueue, &message, pdMS_TO_TICKS(100));
current_temp_state = TEMP_GOOD;
Expand Down
Loading