Compare commits
3 commits
9583a2aafd
...
d071775cc6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d071775cc6 | ||
|
|
2a62ce34c1 | ||
|
|
61fc1996a3 |
7 changed files with 135 additions and 22 deletions
2
Makefile
2
Makefile
|
|
@ -147,7 +147,7 @@ sources = irena mainloop parser message isr crc \
|
|||
usb controlpipe usbconfig dma stream \
|
||||
enc28j60 net udp \
|
||||
expression variables display \
|
||||
pressure gpio \
|
||||
pressure gpio ltc2656 \
|
||||
adc rtc \
|
||||
plugin \
|
||||
nomalloc strtol uart uart1 base85
|
||||
|
|
|
|||
96
ltc2656.c
Normal file
96
ltc2656.c
Normal file
|
|
@ -0,0 +1,96 @@
|
|||
|
||||
#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;
|
||||
}
|
||||
13
ltc2656.h
Normal file
13
ltc2656.h
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
#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
|
||||
|
|
@ -26,6 +26,7 @@
|
|||
#include "enc28j60.h"
|
||||
#include "plugin.h"
|
||||
#include "pressure.h"
|
||||
#include "ltc2656.h"
|
||||
#include "display.h"
|
||||
|
||||
// collect command submissions from various sources
|
||||
|
|
@ -523,6 +524,7 @@ static const struct keywords main_command_table[] = {
|
|||
{"clock", {.par=&clock_par}},
|
||||
{"spi", {.par=&plugin_command}},
|
||||
CMD_KW("pressure", bate_cmd, 360, 0),
|
||||
CMD_KW("dac", dac_cmd, 362, 0),
|
||||
{"uart", {.par=&uart_par}},
|
||||
CMD_KW("uart1", uart1_command, 196, 0),
|
||||
{"usb", {.par=&usb_command}},
|
||||
|
|
@ -867,6 +869,8 @@ static const struct keywords main_variable_names[] = {
|
|||
VARIABLE("spy_return", &spy_return),
|
||||
VARIABLE("poll_return", &poll_return),
|
||||
|
||||
VARIABLE("ssp_dac", &ssp_conf_dac),
|
||||
|
||||
VARIABLE("reboot", &reboot_magic),
|
||||
|
||||
{"", {0}}
|
||||
|
|
|
|||
16
pressure.c
16
pressure.c
|
|
@ -2,6 +2,7 @@
|
|||
#include "pressure.h"
|
||||
#include "gpio.h"
|
||||
#include "expression.h"
|
||||
#include "message.h"
|
||||
|
||||
static unsigned short pressure_reading[8];
|
||||
static unsigned short pressure_hash[2];
|
||||
|
|
@ -143,6 +144,7 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
|
|||
FLAG_VAL("verifyhash", 0x020000),
|
||||
FLAG_VAL("waitssp", 0x040000),
|
||||
FLAG_VAL("nowait", 0x080000),
|
||||
FLAG_VAL("send", 0x100000),
|
||||
KW_END };
|
||||
unsigned int what = 0;
|
||||
error_msg_t e = parse_flags(cmd, kw, &what);
|
||||
|
|
@ -175,12 +177,15 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
|
|||
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 code = par->code;
|
||||
if (r || from_phase != bate_ph_calib) {
|
||||
if (r || to_phase < bate_ph_calib) {
|
||||
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);
|
||||
}
|
||||
else {
|
||||
|
|
@ -190,6 +195,13 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
|
|||
int pp = pressure[idx] % 10;
|
||||
parser_format_message(cmd, "%03d [%d] %d.%d °C, %d.%d mbar\n",
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
16
ssp.c
16
ssp.c
|
|
@ -176,7 +176,7 @@ void ssp_reset(void)
|
|||
|
||||
struct ssp_config ssp_config;
|
||||
|
||||
void ssp_init(struct ssp_config *c)
|
||||
void ssp_init(const struct ssp_config *c)
|
||||
{
|
||||
if (c) {
|
||||
ssp_config = *c;
|
||||
|
|
@ -236,26 +236,16 @@ int ssp_wait(int timeout)
|
|||
return c;
|
||||
}
|
||||
|
||||
const struct ssp_config ssp_conf_adc =
|
||||
struct ssp_config ssp_conf_adc =
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(10000),
|
||||
.ssel = SSP_ADS8688,
|
||||
};
|
||||
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 =
|
||||
struct ssp_config ssp_conf_dac =
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(30000),
|
||||
.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[] = {
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(250),
|
||||
|
|
|
|||
8
ssp.h
8
ssp.h
|
|
@ -33,7 +33,7 @@ enum ssp_config_flags {
|
|||
ssp_flag_mclk = 0x01,
|
||||
};
|
||||
|
||||
void ssp_init(struct ssp_config *c);
|
||||
void ssp_init(const struct ssp_config *c);
|
||||
void ssp_assert_ssel(void);
|
||||
|
||||
static inline
|
||||
|
|
@ -52,10 +52,8 @@ void ssp_deassert_ssel(void)
|
|||
#define SSP_SSEL ((1<<16)|SSP_EXT)
|
||||
#define SSP_MS5534C ((1<<25)|SSP_MCLK)
|
||||
|
||||
extern const struct ssp_config ssp_conf_adc;
|
||||
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_adc;
|
||||
extern struct ssp_config ssp_conf_dac;
|
||||
extern struct ssp_config ssp_conf_bate[];
|
||||
|
||||
static inline
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue