Compare commits

..

No commits in common. "d071775cc62dfd4313d82806122c5cc6512172e3" and "9583a2aafd54c4c51bae23a76a117e11613d0bba" have entirely different histories.

7 changed files with 22 additions and 135 deletions

View file

@ -147,7 +147,7 @@ sources = irena mainloop parser message isr crc \
usb controlpipe usbconfig dma stream \ usb controlpipe usbconfig dma stream \
enc28j60 net udp \ enc28j60 net udp \
expression variables display \ expression variables display \
pressure gpio ltc2656 \ pressure gpio \
adc rtc \ adc rtc \
plugin \ plugin \
nomalloc strtol uart uart1 base85 nomalloc strtol uart uart1 base85

View file

@ -1,96 +0,0 @@
#include "ltc2656.h"
#include "ssp.h"
#include "expression.h"
int ltc2656(unsigned int frame, int flags, int timeout)
{
if (flags & dac_f_init)
ssp_init(&ssp_conf_dac);
ssp_assert_ssel();
ssp_set_buffer(0,0);
unsigned short cmd[2] = { frame >> 16, frame & 0xffff };
ssp_submit(cmd, 2, 0, 0);
int r = ssp_wait(timeout);
if (!r)
ssp_deassert_ssel();
return r;
}
int dac_cmd(struct command *cmd, const struct command_par *par)
{
static const struct keywords kw[] = {
FLAG_VAL("write", 0),
FLAG_VAL("update", 1),
FLAG_VAL("load", 3),
FLAG_VAL("loadall", 2),
FLAG_VAL("pdown", 4),
FLAG_VAL("pdchip", 5),
FLAG_VAL("pupref", 6),
FLAG_VAL("pdref", 7),
FLAG_VAL("nop", 15),
KW_END };
const struct keywords *k;
error_msg_t e = parse_flag(cmd, kw, &k, 2);
unsigned int n = 8;
unsigned int val = 0;
unsigned int timeout = 100;
unsigned int flags = dac_f_init;
unsigned int code = par->code;
// dac/«cmd» [«n»] [«timeout»] «value» zero or one value
// dac [«n»] [«timeout»] «value» … one or more values
if (!e)
e = parse_expression_square(cmd, &n, 1);
if (!e)
e = parse_expression_square(cmd, &timeout, 1);
if (!e && n > 8)
e = &parser_value_error;
if (e)
return parser_error_message(cmd, e);
e = parse_expression(cmd, &val);
int r = 0;
if (k) {
// one frame cmd per kw
if (n >= 8)
n = 15;
val &= 0xffff;
val |= (k->val & 15) << 20;
val |= n << 16;
r = ltc2656(val, flags, timeout);
goto done;
}
if (e)
return parser_error_message(cmd, e);
if (n>8)
n = 0;
while (!r && !e && (n<8 || val >= 0x10000)) {
// multiple frames, one per value given
// cmd/addr as part of the value
// or successive writes with a loadall last
unsigned int next;
e = parse_expression(cmd, &next);
if (val < 0x10000) {
val |= n << 16;
if (e || n==7)
val |= 0x200000;
n++;
}
r = ltc2656(val, flags, timeout);
flags = 0;
val = next;
}
done:
if (r)
code++;
parser_format_message(cmd, "%03d dac 0x%06x → %d\n", code, val, r);
return code;
}

View file

@ -1,13 +0,0 @@
#ifndef _ltc2656_h_
#define _ltc2656_h_
#include "parser.h"
int ltc2656(unsigned int frame, int flags, int timeout);
int dac_cmd(struct command *cmd, const struct command_par *par);
enum dac_flags {
dac_f_init = 1,
};
#endif

View file

@ -26,7 +26,6 @@
#include "enc28j60.h" #include "enc28j60.h"
#include "plugin.h" #include "plugin.h"
#include "pressure.h" #include "pressure.h"
#include "ltc2656.h"
#include "display.h" #include "display.h"
// collect command submissions from various sources // collect command submissions from various sources
@ -524,7 +523,6 @@ static const struct keywords main_command_table[] = {
{"clock", {.par=&clock_par}}, {"clock", {.par=&clock_par}},
{"spi", {.par=&plugin_command}}, {"spi", {.par=&plugin_command}},
CMD_KW("pressure", bate_cmd, 360, 0), CMD_KW("pressure", bate_cmd, 360, 0),
CMD_KW("dac", dac_cmd, 362, 0),
{"uart", {.par=&uart_par}}, {"uart", {.par=&uart_par}},
CMD_KW("uart1", uart1_command, 196, 0), CMD_KW("uart1", uart1_command, 196, 0),
{"usb", {.par=&usb_command}}, {"usb", {.par=&usb_command}},
@ -869,10 +867,8 @@ static const struct keywords main_variable_names[] = {
VARIABLE("spy_return", &spy_return), VARIABLE("spy_return", &spy_return),
VARIABLE("poll_return", &poll_return), VARIABLE("poll_return", &poll_return),
VARIABLE("ssp_dac", &ssp_conf_dac),
VARIABLE("reboot", &reboot_magic), VARIABLE("reboot", &reboot_magic),
{"", {0}} {"", {0}}
}; };

View file

@ -2,7 +2,6 @@
#include "pressure.h" #include "pressure.h"
#include "gpio.h" #include "gpio.h"
#include "expression.h" #include "expression.h"
#include "message.h"
static unsigned short pressure_reading[8]; static unsigned short pressure_reading[8];
static unsigned short pressure_hash[2]; static unsigned short pressure_hash[2];
@ -144,7 +143,6 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
FLAG_VAL("verifyhash", 0x020000), FLAG_VAL("verifyhash", 0x020000),
FLAG_VAL("waitssp", 0x040000), FLAG_VAL("waitssp", 0x040000),
FLAG_VAL("nowait", 0x080000), FLAG_VAL("nowait", 0x080000),
FLAG_VAL("send", 0x100000),
KW_END }; KW_END };
unsigned int what = 0; unsigned int what = 0;
error_msg_t e = parse_flags(cmd, kw, &what); error_msg_t e = parse_flags(cmd, kw, &what);
@ -177,15 +175,12 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
parse_expression(cmd, &value); parse_expression(cmd, &value);
} }
if (from_phase >= bate_ph_calib)
idx = !!(pressure_reading[0] & 0x80);
int r = read_pressure(from_phase, to_phase, value, idx); int r = read_pressure(from_phase, to_phase, value, idx);
int code = par->code; int code = par->code;
if (r || to_phase < bate_ph_calib) { if (r || from_phase != bate_ph_calib) {
code += !!r; code += !!r;
parser_format_message(cmd, "%03d bate[%d] %d … %d (%d) → %d\n", parser_format_message(cmd, "%03d bate[%d] %d -> %d(%d) = %d\n",
code, idx, from_phase, to_phase, value, r); code, idx, from_phase, to_phase, value, r);
} }
else { else {
@ -195,13 +190,6 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
int pp = pressure[idx] % 10; int pp = pressure[idx] % 10;
parser_format_message(cmd, "%03d [%d] %d.%d °C, %d.%d mbar\n", parser_format_message(cmd, "%03d [%d] %d.%d °C, %d.%d mbar\n",
code, idx, t, d, p, pp); code, idx, t, d, p, pp);
if (what & 0x1000000)
printf("P%d %04x %04x %04x %04x %04x %04x %d.%d °C %d.%d mbar\n",
idx,
pressure_reading[2], pressure_reading[3],
pressure_reading[4], pressure_reading[5],
pressure_reading[6], pressure_reading[7],
t, d, p, pp);
} }
return code; return code;
} }

16
ssp.c
View file

@ -176,7 +176,7 @@ void ssp_reset(void)
struct ssp_config ssp_config; struct ssp_config ssp_config;
void ssp_init(const struct ssp_config *c) void ssp_init(struct ssp_config *c)
{ {
if (c) { if (c) {
ssp_config = *c; ssp_config = *c;
@ -236,16 +236,26 @@ int ssp_wait(int timeout)
return c; return c;
} }
struct ssp_config ssp_conf_adc = const struct ssp_config ssp_conf_adc =
{ {
.mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(10000), .mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(10000),
.ssel = SSP_ADS8688, .ssel = SSP_ADS8688,
}; };
struct ssp_config ssp_conf_dac = const struct ssp_config ssp_conf_adc_daisy =
{
.mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(1000),
.ssel = SSP_ADS8688 | SSP_SSEL,
};
const struct ssp_config ssp_conf_dac =
{ {
.mode = SSPCR0_16bits | SSP_kHz(30000), .mode = SSPCR0_16bits | SSP_kHz(30000),
.ssel = SSP_LTC2656, .ssel = SSP_LTC2656,
}; };
const struct ssp_config ssp_conf_dac_daisy =
{
.mode = SSPCR0_16bits | SSP_kHz(1000),
.ssel = SSP_LTC2656 | SSP_SSEL,
};
struct ssp_config ssp_conf_bate[] = { struct ssp_config ssp_conf_bate[] = {
{ {
.mode = SSPCR0_16bits | SSP_kHz(250), .mode = SSPCR0_16bits | SSP_kHz(250),

8
ssp.h
View file

@ -33,7 +33,7 @@ enum ssp_config_flags {
ssp_flag_mclk = 0x01, ssp_flag_mclk = 0x01,
}; };
void ssp_init(const struct ssp_config *c); void ssp_init(struct ssp_config *c);
void ssp_assert_ssel(void); void ssp_assert_ssel(void);
static inline static inline
@ -52,8 +52,10 @@ void ssp_deassert_ssel(void)
#define SSP_SSEL ((1<<16)|SSP_EXT) #define SSP_SSEL ((1<<16)|SSP_EXT)
#define SSP_MS5534C ((1<<25)|SSP_MCLK) #define SSP_MS5534C ((1<<25)|SSP_MCLK)
extern struct ssp_config ssp_conf_adc; extern const struct ssp_config ssp_conf_adc;
extern struct ssp_config ssp_conf_dac; extern const struct ssp_config ssp_conf_adc_daisy;
extern const struct ssp_config ssp_conf_dac;
extern const struct ssp_config ssp_conf_dac_daisy;
extern struct ssp_config ssp_conf_bate[]; extern struct ssp_config ssp_conf_bate[];
static inline static inline