Compare commits

..

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

8 changed files with 42 additions and 141 deletions

2
gpio.h
View file

@ -90,8 +90,6 @@
* to readout external ADS8688 in a chain with the internal one. * to readout external ADS8688 in a chain with the internal one.
*/ */
#include <lpc2148/gpio.h>
static inline void init_gpio(void) {} static inline void init_gpio(void) {}
#define SSP_SSEL_MASK0 0x00110800 // gpio0 pins to set high on deassert ssel #define SSP_SSEL_MASK0 0x00110800 // gpio0 pins to set high on deassert ssel

View file

@ -132,7 +132,7 @@ void irena_init()
rtc_init(pclk); rtc_init(pclk);
dma_init(); dma_init();
usb_init(); usb_init();
ssp_init(0); ssp_init(pclk);
} }
char irena_name[12]; char irena_name[12];

View file

@ -521,8 +521,7 @@ static const struct keywords main_command_table[] = {
{"variable",{.par=&variable_commands}}, {"variable",{.par=&variable_commands}},
{"sleep", {.par=&sleep_par}}, {"sleep", {.par=&sleep_par}},
{"clock", {.par=&clock_par}}, {"clock", {.par=&clock_par}},
{"spi", {.par=&plugin_command}}, {"spi", {.par=&plugin_command}},
CMD_KW("pressure", bate_cmd, 360, 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}},

View file

@ -114,7 +114,7 @@ int printf(const char *fmt, ...)
{ {
if (!poll_dma_ready()) if (!poll_dma_ready())
return -1; return -1;
int size = 512 - poll_dma_buffer_size; size_t size = 512 - poll_dma_buffer_size;
if (!size) { if (!size) {
poll_dma_submit(0,0); poll_dma_submit(0,0);
size = 512 - poll_dma_buffer_size; size = 512 - poll_dma_buffer_size;

View file

@ -1,7 +1,5 @@
#include "pressure.h" #include "pressure.h"
#include "gpio.h"
#include "expression.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];
@ -15,7 +13,6 @@ const struct keywords pressure_variable_names[] = {
{"bate_hash", {.par=(unsigned int *)(pressure_hash)}}, {"bate_hash", {.par=(unsigned int *)(pressure_hash)}},
{"pressure", {.par=pressure}}, {"pressure", {.par=pressure}},
{"temperature", {.par=temperature}}, {"temperature", {.par=temperature}},
VARIABLE("bate_mode", ssp_conf_bate),
{"", {0}}}; {"", {0}}};
__attribute__((noinline)) __attribute__((noinline))
@ -58,7 +55,7 @@ int pressure_wait_for_conversion(int timeout)
return SSP_MISO; return SSP_MISO;
} }
int read_pressure(int from_phase, int to_phase, int value, int idx) int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *sspc)
{ {
static const unsigned short cmds[] = { static const unsigned short cmds[] = {
0b0000000010101010, // 0 reset part 1 0b0000000010101010, // 0 reset part 1
@ -78,12 +75,14 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
}; };
int r = 0; int r = 0;
int timeout; int timeout;
for (int phase = from_phase; !r && phase <= to_phase; phase++) for (phase = from_phase; !r && phase <= to_phase; phase++)
switch (phase) { switch (phase) {
case 0: ssp_init(&ssp_conf_bate[!!idx]); case 0: if (!sspc)
sspc = spi_conf_bate;
ssp_init(sspc);
break; break;
case 1: case 1:
ssp_assert_ssel(); ssp_assert_ssel(ssp_ssel);
ssp_set_buffer(pressure_reading, 8); ssp_set_buffer(pressure_reading, 8);
ssp_set_match(0, 0, 3, 0, 8); ssp_set_match(0, 0, 3, 0, 8);
r = ssp_submit(cmds, 11, 0, 0); r = ssp_submit(cmds, 11, 0, 0);
@ -91,7 +90,7 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
case 2: case 2:
case 6: case 6:
case 9: if (phase==to_phase) case 9: if (phase==to_phase)
timeout = value; timeout = value
else else
timeout = 1000; timeout = 1000;
r = ssp_wait(timeout); r = ssp_wait(timeout);
@ -115,7 +114,7 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
break; break;
case 10: case 10:
ssp_deassert_ssel(); ssp_deassert_ssel();
if (ssp_config.ssel & SSP_EXT) if (ssp_ssel & SSP_EXT)
pressure_reading[0] = 0xbafe; pressure_reading[0] = 0xbafe;
else else
pressure_reading[0] = 0xba7e; pressure_reading[0] = 0xba7e;
@ -128,68 +127,3 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
} }
return r; return r;
} }
int bate_cmd(struct command *cmd, const struct command_par *par)
{
static const struct keywords kw[] = {
FLAG_VAL("external", 0x0100),
FLAG_VAL("init", bate_ph_init | 0x20),
FLAG_VAL("start", bate_ph_cmd1),
FLAG_VAL("cont1", bate_ph_wait_ssp1),
FLAG_VAL("cont2", bate_ph_wait_ssp2),
FLAG_VAL("cont3", bate_ph_wait_ssp3),
FLAG_VAL("calibrate", bate_ph_calib),
FLAG_VAL("sethash", 0x010000),
FLAG_VAL("verifyhash", 0x020000),
FLAG_VAL("waitssp", 0x040000),
FLAG_VAL("nowait", 0x080000),
KW_END };
unsigned int what = 0;
error_msg_t e = parse_flags(cmd, kw, &what);
what |= (unsigned int)par->par;
int idx = !!(what & 0x100);
int from_phase = what & 0x1f;
int to_phase = 0;
int value = 0;
if (what & 0x030000) {
value = (what & 0x030000)>>16;
to_phase = bate_ph_calib;
}
else if (what & 0x080000) {
if (from_phase <= bate_ph_wait_ssp1 && !(what & 0x040000))
to_phase = bate_ph_wait_ssp1;
else if (from_phase <= bate_ph_wait_conv1)
to_phase = bate_ph_wait_conv1;
else if (from_phase <= bate_ph_wait_ssp2 && !(what & 0x040000))
to_phase = bate_ph_wait_ssp2;
else if (from_phase <= bate_ph_wait_conv2)
to_phase = bate_ph_wait_conv2;
else if (from_phase <= bate_ph_wait_ssp3 && !(what & 0x040000))
to_phase = bate_ph_wait_ssp3;
parse_expression(cmd, &value);
}
else {
to_phase = bate_ph_calib;
if (what & 0x2f || !parse_expression(cmd, &from_phase))
if (!parse_expression(cmd, &to_phase))
parse_expression(cmd, &value);
}
int r = read_pressure(from_phase, to_phase, value, idx);
int code = par->code;
if (r || from_phase != bate_ph_calib) {
code += !!r;
parser_format_message(cmd, "%03d bate[%d] %d -> %d(%d) = %d\n",
code, idx, from_phase, to_phase, value, r);
}
else {
int t = (temperature[idx]-2) / 10 - 273;
int d = (temperature[idx]-2) % 10;
int p = pressure[idx] / 10;
int pp = pressure[idx] % 10;
parser_format_message(cmd, "%03d [%d] %d.%d °C, %d.%d mbar\n",
code, idx, t, d, p, pp);
}
return code;
}

View file

@ -1,26 +1,4 @@
#ifndef _pressure_h_
#define _pressure_h_
#include "parser.h" #include "parser.h"
#include "ssp.h"
extern const struct keywords pressure_variable_names[]; extern const struct keywords pressure_variable_names[];
int read_pressure(int from_phase, int to_phase, int value, int idx); extern const struct command_par pressure_command;
int bate_cmd(struct command *cmd, const struct command_par *par); error_msg_t read_pressure(unsigned int fifo, int what);
enum bate_phase {
bate_ph_init = 0,
bate_ph_cmd1 = 1,
bate_ph_wait_ssp1 = 2,
bate_ph_save_cal = 3,
bate_ph_wait_conv1 = 4,
bate_ph_cmd2 = 5,
bate_ph_wait_ssp2 = 6,
bate_ph_wait_conv2 = 7,
bate_ph_cmd3 = 8,
bate_ph_wait_ssp3 = 9,
bate_ph_save_idx = 10,
bate_ph_calib = 11,
};
#endif

44
ssp.c
View file

@ -1,10 +1,12 @@
#include <string.h> #include <string.h>
#include <lpc2148/ssp.h> #include <lpc2148/ssp.h>
#include <lpc2148/gpio.h>
#include <lpc2148/pcb.h> #include <lpc2148/pcb.h>
#include <lpc2148/vic.h> #include <lpc2148/vic.h>
#include "ssp.h" #include "ssp.h"
#include "gpio.h"
#include "isr.h" #include "isr.h"
// The SSP keeps its state in these private static variables. // The SSP keeps its state in these private static variables.
@ -15,7 +17,7 @@ static volatile struct ssp_job {
unsigned int read_count; unsigned int read_count;
unsigned int idle_count; unsigned int idle_count;
unsigned int buf_count; unsigned int buf_count;
const unsigned short *command; unsigned short *command;
unsigned short *buf_ptr; unsigned short *buf_ptr;
} job; } job;
@ -149,7 +151,7 @@ static void ssp_isr(void)
// idle=0x8000 RFIFO, send what the acquisition fifos provide. // idle=0x8000 RFIFO, send what the acquisition fifos provide.
// idle=0x8001 NOOPP, just drain the FPGA buffer. // idle=0x8001 NOOPP, just drain the FPGA buffer.
int ssp_submit(const unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc) int ssp_submit(unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc)
{ {
volatile struct ssp_job *j=&job; volatile struct ssp_job *j=&job;
unsigned int iflg = disable_irq(INT_DISABLE); unsigned int iflg = disable_irq(INT_DISABLE);
@ -176,31 +178,33 @@ void ssp_reset(void)
struct ssp_config ssp_config; struct ssp_config ssp_config;
void ssp_deassert_ssel()
{
GPIO_FIO1SET = ssp_ssel_mask & SSP_SSEL_CONF1;
GPIO_FIO0SET = ssp_ssel_mask & SSP_SSEL_CONF0;
}
void ssp_init(struct ssp_config *c) void ssp_init(struct ssp_config *c)
{ {
if (c) {
ssp_config = *c;
ssp_ssel_mask |= c->ssel;
}
ssp_reset(); ssp_reset();
ssp_ssel_mask |= c->ssel;
ssp_deassert_ssel(); ssp_deassert_ssel();
ssp_bits = (ssp_config.mode & 15) + 1; ssp_config = *c;
ssp_bits = (c->mode & 15) + 1;
SSPCR1 = 0; SSPCR1 = 0;
SSPCPSR = SSPCPSR_MIN; // 30 MHz SSPCPSR = SSPCPSR_MIN; // 30 MHz
SSPCR0 = ssp_config.mode; SSPCR0 = c->mode;
// 16 bit frames, SPI mode, CPOL=0, CPHA=1, clock div by 1 (30 MHz). // 16 bit frames, SPI mode, CPOL=0, CPHA=1, clock div by 1 (30 MHz).
SSPICR = SSP_INT_ROR|SSP_INT_RT; // clear any pending irqs. SSPICR = SSP_INT_ROR|SSP_INT_RT; // clear any pending irqs.
// Route the SSP IRQ through the VIC // Route the SSP IRQ through the VIC
VICVectAddrs[IrqVec_SSP] = ssp_isr; VICVectAddrs[IrqVec_SSP] = ssp_isr;
VICVectCntl[IrqVec_SSP] = VICVectCntl_SSP; VICVectCntl[IrqVec_SSP] = VICVectCntl_SSP;
VICIntEnable = VIC_SSP; VICIntEnable = VIC_SSP;
ssp_set_match(0, 0, 0, 0, 0);
SSPCR1 = SSPCR1_SSE; // enable SSPCR1 = SSPCR1_SSE; // enable
} }
void ssp_assert_ssel(void) void ssp_assert_ssel(unsigned int ssel)
{ {
unsigned int ssel = ssp_config.ssel;
if (ssel & ssp_flag_mclk) if (ssel & ssp_flag_mclk)
PCB_PINSEL1 |= PCB_PINSEL1_P016_Match0_2; PCB_PINSEL1 |= PCB_PINSEL1_P016_Match0_2;
else else
@ -256,13 +260,13 @@ const struct ssp_config ssp_conf_dac_daisy =
.mode = SSPCR0_16bits | SSP_kHz(1000), .mode = SSPCR0_16bits | SSP_kHz(1000),
.ssel = SSP_LTC2656 | SSP_SSEL, .ssel = SSP_LTC2656 | SSP_SSEL,
}; };
struct ssp_config ssp_conf_bate[] = { const struct ssp_config ssp_conf_bate =
{ {
.mode = SSPCR0_16bits | SSP_kHz(250), .mode = SSPCR0_16bits | SSP_kHz(250),
.ssel = SSP_MS5534C, .ssel = SSP_MS5534C,
}, };
{ const struct ssp_config ssp_conf_bate_ext =
.mode = SSPCR0_16bits | SSP_kHz(120), {
.ssel = SSP_EXT | SSP_MCLK, .mode = SSPCR0_16bits | SSP_kHz(120),
}, .ssel = SSP_EXT | SSP_MCLK,
}; };

22
ssp.h
View file

@ -1,14 +1,9 @@
#ifndef _ssp_h_
#define _ssp_h_
#include "gpio.h"
void ssp_reset(void); void ssp_reset(void);
void ssp_set_buffer(void *start, int size); void ssp_set_buffer(void *start, int size);
void ssp_poll(void); void ssp_poll(void);
int ssp_submit(const unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc); int ssp_submit(unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc);
int ssp_busy(void); int ssp_busy(void);
int ssp_wait(int timeout); int ssp_wait(int timeout);
@ -34,14 +29,8 @@ enum ssp_config_flags {
}; };
void ssp_init(struct ssp_config *c); void ssp_init(struct ssp_config *c);
void ssp_assert_ssel(void); void ssp_deassert_ssel();
void ssp_assert_ssel(unsigned int ssel);
static inline
void ssp_deassert_ssel(void)
{
GPIO_FIO1SET = ssp_ssel_mask & SSP_SSEL_CONF1;
GPIO_FIO0SET = ssp_ssel_mask & SSP_SSEL_CONF0;
}
#define SSP_kHz(kHz) SSPCR0_SCR(30000/(kHz)) #define SSP_kHz(kHz) SSPCR0_SCR(30000/(kHz))
@ -56,7 +45,8 @@ extern const struct ssp_config ssp_conf_adc;
extern const struct ssp_config ssp_conf_adc_daisy; 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;
extern const struct ssp_config ssp_conf_dac_daisy; extern const struct ssp_config ssp_conf_dac_daisy;
extern struct ssp_config ssp_conf_bate[]; extern const struct ssp_config ssp_conf_bate;
extern const struct ssp_config ssp_conf_bate_ext;
static inline static inline
void ssp_set_match(unsigned int mask, unsigned int value, void ssp_set_match(unsigned int mask, unsigned int value,
@ -69,5 +59,3 @@ void ssp_set_match(unsigned int mask, unsigned int value,
ssp_match_count = count; ssp_match_count = count;
ssp_read_size = size; ssp_read_size = size;
} }
#endif