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

Firefly dev #10

Merged
merged 7 commits into from
Aug 17, 2019
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
23 changes: 23 additions & 0 deletions common/smbus_units.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* smbus_units.c
*
* Created on: Jul 17, 2019
* Author: pw94
*/
#include "common/smbus_units.h"

float linear11_to_float(linear11_val_t t)
{
return t.linear.base * pow(2, t.linear.mantissa);
}

float linear16u_to_float(uint16_t t )
{
const float mantissa = -13;
return 1.0*t*pow(2,mantissa);
}

uint16_t float_to_linear11(float t)
{
return (uint16_t)(t * (1 << 5));
}
16 changes: 3 additions & 13 deletions common/smbus_units.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,10 @@ typedef union
uint16_t raw;
} linear11_val_t;

float linear11_to_float(linear11_val_t t)
{
return t.linear.base * pow(2, t.linear.mantissa);
}
float linear11_to_float(linear11_val_t t);

float linear16u_to_float(uint16_t t )
{
const float mantissa = -13;
return 1.0*t*pow(2,mantissa);
}
float linear16u_to_float(uint16_t t );

uint16_t float_to_linear11(float t)
{
return (uint16_t)(t * (1 << 5));
}
uint16_t float_to_linear11(float t);

#endif // _COMMON_SMBUS_UNITS_H
8 changes: 3 additions & 5 deletions projects/project2/ADCMonitorTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,8 @@ struct ADC_Info_t {
float scale; // scaling, if needed, for signals bigger than 2.5V
};

// These are not in order of channel number but instead grouped by
// which ADC they have been assigned to in the TI PinMux tool. I could
// probably consider reassigning them in the PinMUX tool to make it more
// logical.
// parameters for how data is organized in the fADC arrays and how the
// sequencers are organized
#define ADCs_ADC1_START 0
#define ADCs_ADC1_FIRST_SEQ_LENGTH 8
#define ADCs_ADC1_SECOND_SEQ_LENGTH 5
Expand Down Expand Up @@ -236,7 +234,7 @@ void initADC0SecondSequence()
}


// playground to test various things
// ADC monitoring task.
void ADCMonitorTask(void *parameters)
{
// initialize to the current tick time
Expand Down
73 changes: 60 additions & 13 deletions projects/project2/CommandLineTask.c
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ static BaseType_t i2c_ctl_reg_r(char *m, size_t s, const char *mm)
if ( nbytes > MAX_BYTES )
nbytes = MAX_BYTES;
snprintf(m, s, "i2c_ctl_reg_r: Read %d bytes from I2C address 0x%x, reg 0x%x\n", nbytes, address, reg_address);
Print(m);
DPRINT(m);

tSMBusStatus r = SMBusMasterI2CWriteRead(p_sMaster,address,&txdata,1,data,nbytes);
if (r != SMBUS_OK) {
Expand Down Expand Up @@ -426,18 +426,18 @@ static BaseType_t mon_ctl(char *m, size_t s, const char *mm)
p1[p1l] = 0x00; // terminate strings
BaseType_t i1 = strtol(p1, NULL, 10);

if ( i1 < 0 || i1 >= NCOMMANDS ) {
if ( i1 < 0 || i1 >= NCOMMANDS_PS ) {
snprintf(m, s, "%s: Invalid argument, must be between 0 and %d\n", __func__,
NCOMMANDS-1);
NCOMMANDS_PS-1);
return pdFALSE;
}

int copied = 0;
copied += snprintf(m+copied, s-copied, "%s\n", pm_command_dcdc[i1].name);
for (int ps = 0; ps < NSUPPLIES; ++ps) {
for (int ps = 0; ps < NSUPPLIES_PS; ++ps) {
copied += snprintf(m+copied, s-copied, "SUPPLY %d\n", ps);
for (int page = 0; page < NPAGES; ++page ) {
float val = pm_values[ps*(NCOMMANDS*NPAGES)+page*NCOMMANDS+i1];
for (int page = 0; page < NPAGES_PS; ++page ) {
float val = pm_values[ps*(NCOMMANDS_PS*NPAGES_PS)+page*NCOMMANDS_PS+i1];
int tens = val;
int frac = ABS((val - tens)*100.0);

Expand All @@ -458,17 +458,56 @@ float getADCvalue(const int i);
static BaseType_t adc_ctl(char *m, size_t s, const char *mm)
{
int copied = 0;
copied += snprintf(m+copied, s-copied, "ADC outputs\n");
for ( int i = 0; i < 21; ++i ) {
float val = getADCvalue(i);
static int whichadc = 0;
if ( whichadc == 0 ) {
copied += snprintf(m+copied, s-copied, "ADC outputs\n");
}
for ( ; whichadc < 21; ++whichadc ) {
float val = getADCvalue(whichadc);
int tens = val;
int frac = ABS((val-tens)*100.);
copied += snprintf(m+copied, s-copied, "%14s: %02d.%02d\n", getADCname(i), tens, frac);

copied += snprintf(m+copied, s-copied, "%14s: %02d.%02d\n", getADCname(whichadc), tens, frac);
if ( (s-copied) < 20 ) {
++whichadc;
return pdTRUE;
}
}
whichadc = 0;
return pdFALSE;
}

const char* getFFname(const uint8_t i);
int8_t getFFvalue(const uint8_t i);


// this command takes no arguments
static BaseType_t ff_ctl(char *m, size_t s, const char *mm)
{
int copied = 0;
static int whichff = 0;
if ( whichff == 0 ) {
copied += snprintf(m+copied, s-copied, "FF temperatures\n");
}
for ( ; whichff < 25; ++whichff ) {
int8_t val = getFFvalue(whichff);
copied += snprintf(m+copied, s-copied, "%17s: %3d", getFFname(whichff), val);
if ( whichff%2 == 1 )
copied += snprintf(m+copied, s-copied, "\n");
else
copied += snprintf(m+copied, s-copied, "\t");
if ( (s-copied ) < 20 ) {
++whichff;
return pdTRUE;
}

}
if ( whichff%2 ==1 ) {
m[copied++] = '\n';
m[copied] = '\0';
}
whichff = 0;
return pdFALSE;
}


static
Expand Down Expand Up @@ -697,6 +736,13 @@ CLI_Command_Definition_t task_command = {
2
};

static
CLI_Command_Definition_t ff_command = {
.pcCommand="ff",
.pcHelpString="ff\n Displays a table showing the state of FF modules.\r\n",
.pxCommandInterpreter = ff_ctl,
0
};

extern StreamBufferHandle_t xUARTStreamBuffer;

Expand All @@ -711,6 +757,7 @@ void vCommandLineTask( void *pvParameters )

// register the commands
FreeRTOS_CLIRegisterCommand(&task_stats_command );
FreeRTOS_CLIRegisterCommand(&task_command );
FreeRTOS_CLIRegisterCommand(&i2c_read_command );
FreeRTOS_CLIRegisterCommand(&i2c_set_dev_command );
FreeRTOS_CLIRegisterCommand(&i2c_read_reg_command );
Expand All @@ -720,8 +767,8 @@ void vCommandLineTask( void *pvParameters )
FreeRTOS_CLIRegisterCommand(&pwr_ctl_command );
FreeRTOS_CLIRegisterCommand(&led_ctl_command );
FreeRTOS_CLIRegisterCommand(&monitor_command );
FreeRTOS_CLIRegisterCommand(&adc_command );
FreeRTOS_CLIRegisterCommand(&task_command );
FreeRTOS_CLIRegisterCommand(&adc_command );
FreeRTOS_CLIRegisterCommand(&ff_command );



Expand Down
Loading