Compare commits
4 commits
3b667318cb
...
9583a2aafd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9583a2aafd | ||
|
|
3f378da7ea | ||
|
|
1a93e99d96 | ||
|
|
1997030377 |
8 changed files with 141 additions and 42 deletions
2
gpio.h
2
gpio.h
|
|
@ -90,6 +90,8 @@
|
|||
* to readout external ADS8688 in a chain with the internal one.
|
||||
*/
|
||||
|
||||
#include <lpc2148/gpio.h>
|
||||
|
||||
static inline void init_gpio(void) {}
|
||||
|
||||
#define SSP_SSEL_MASK0 0x00110800 // gpio0 pins to set high on deassert ssel
|
||||
|
|
|
|||
2
irena.c
2
irena.c
|
|
@ -132,7 +132,7 @@ void irena_init()
|
|||
rtc_init(pclk);
|
||||
dma_init();
|
||||
usb_init();
|
||||
ssp_init(pclk);
|
||||
ssp_init(0);
|
||||
}
|
||||
|
||||
char irena_name[12];
|
||||
|
|
|
|||
|
|
@ -522,6 +522,7 @@ static const struct keywords main_command_table[] = {
|
|||
{"sleep", {.par=&sleep_par}},
|
||||
{"clock", {.par=&clock_par}},
|
||||
{"spi", {.par=&plugin_command}},
|
||||
CMD_KW("pressure", bate_cmd, 360, 0),
|
||||
{"uart", {.par=&uart_par}},
|
||||
CMD_KW("uart1", uart1_command, 196, 0),
|
||||
{"usb", {.par=&usb_command}},
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ int printf(const char *fmt, ...)
|
|||
{
|
||||
if (!poll_dma_ready())
|
||||
return -1;
|
||||
size_t size = 512 - poll_dma_buffer_size;
|
||||
int size = 512 - poll_dma_buffer_size;
|
||||
if (!size) {
|
||||
poll_dma_submit(0,0);
|
||||
size = 512 - poll_dma_buffer_size;
|
||||
|
|
|
|||
82
pressure.c
82
pressure.c
|
|
@ -1,5 +1,7 @@
|
|||
|
||||
#include "pressure.h"
|
||||
#include "gpio.h"
|
||||
#include "expression.h"
|
||||
|
||||
static unsigned short pressure_reading[8];
|
||||
static unsigned short pressure_hash[2];
|
||||
|
|
@ -13,6 +15,7 @@ const struct keywords pressure_variable_names[] = {
|
|||
{"bate_hash", {.par=(unsigned int *)(pressure_hash)}},
|
||||
{"pressure", {.par=pressure}},
|
||||
{"temperature", {.par=temperature}},
|
||||
VARIABLE("bate_mode", ssp_conf_bate),
|
||||
{"", {0}}};
|
||||
|
||||
__attribute__((noinline))
|
||||
|
|
@ -55,7 +58,7 @@ int pressure_wait_for_conversion(int timeout)
|
|||
return SSP_MISO;
|
||||
}
|
||||
|
||||
int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *sspc)
|
||||
int read_pressure(int from_phase, int to_phase, int value, int idx)
|
||||
{
|
||||
static const unsigned short cmds[] = {
|
||||
0b0000000010101010, // 0 reset part 1
|
||||
|
|
@ -75,14 +78,12 @@ int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *ss
|
|||
};
|
||||
int r = 0;
|
||||
int timeout;
|
||||
for (phase = from_phase; !r && phase <= to_phase; phase++)
|
||||
for (int phase = from_phase; !r && phase <= to_phase; phase++)
|
||||
switch (phase) {
|
||||
case 0: if (!sspc)
|
||||
sspc = spi_conf_bate;
|
||||
ssp_init(sspc);
|
||||
case 0: ssp_init(&ssp_conf_bate[!!idx]);
|
||||
break;
|
||||
case 1:
|
||||
ssp_assert_ssel(ssp_ssel);
|
||||
ssp_assert_ssel();
|
||||
ssp_set_buffer(pressure_reading, 8);
|
||||
ssp_set_match(0, 0, 3, 0, 8);
|
||||
r = ssp_submit(cmds, 11, 0, 0);
|
||||
|
|
@ -90,7 +91,7 @@ int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *ss
|
|||
case 2:
|
||||
case 6:
|
||||
case 9: if (phase==to_phase)
|
||||
timeout = value
|
||||
timeout = value;
|
||||
else
|
||||
timeout = 1000;
|
||||
r = ssp_wait(timeout);
|
||||
|
|
@ -114,7 +115,7 @@ int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *ss
|
|||
break;
|
||||
case 10:
|
||||
ssp_deassert_ssel();
|
||||
if (ssp_ssel & SSP_EXT)
|
||||
if (ssp_config.ssel & SSP_EXT)
|
||||
pressure_reading[0] = 0xbafe;
|
||||
else
|
||||
pressure_reading[0] = 0xba7e;
|
||||
|
|
@ -127,3 +128,68 @@ int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *ss
|
|||
}
|
||||
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;
|
||||
}
|
||||
|
|
|
|||
26
pressure.h
26
pressure.h
|
|
@ -1,4 +1,26 @@
|
|||
#ifndef _pressure_h_
|
||||
#define _pressure_h_
|
||||
|
||||
#include "parser.h"
|
||||
#include "ssp.h"
|
||||
|
||||
extern const struct keywords pressure_variable_names[];
|
||||
extern const struct command_par pressure_command;
|
||||
error_msg_t read_pressure(unsigned int fifo, int what);
|
||||
int read_pressure(int from_phase, int to_phase, int value, int idx);
|
||||
int bate_cmd(struct command *cmd, const struct command_par *par);
|
||||
|
||||
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
44
ssp.c
|
|
@ -1,12 +1,10 @@
|
|||
#include <string.h>
|
||||
|
||||
#include <lpc2148/ssp.h>
|
||||
#include <lpc2148/gpio.h>
|
||||
#include <lpc2148/pcb.h>
|
||||
#include <lpc2148/vic.h>
|
||||
|
||||
#include "ssp.h"
|
||||
#include "gpio.h"
|
||||
#include "isr.h"
|
||||
|
||||
// The SSP keeps its state in these private static variables.
|
||||
|
|
@ -17,7 +15,7 @@ static volatile struct ssp_job {
|
|||
unsigned int read_count;
|
||||
unsigned int idle_count;
|
||||
unsigned int buf_count;
|
||||
unsigned short *command;
|
||||
const unsigned short *command;
|
||||
unsigned short *buf_ptr;
|
||||
} job;
|
||||
|
||||
|
|
@ -151,7 +149,7 @@ static void ssp_isr(void)
|
|||
// idle=0x8000 RFIFO, send what the acquisition fifos provide.
|
||||
// idle=0x8001 NOOPP, just drain the FPGA buffer.
|
||||
|
||||
int ssp_submit(unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc)
|
||||
int ssp_submit(const unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc)
|
||||
{
|
||||
volatile struct ssp_job *j=&job;
|
||||
unsigned int iflg = disable_irq(INT_DISABLE);
|
||||
|
|
@ -178,33 +176,31 @@ void ssp_reset(void)
|
|||
|
||||
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)
|
||||
{
|
||||
if (c) {
|
||||
ssp_config = *c;
|
||||
ssp_ssel_mask |= c->ssel;
|
||||
}
|
||||
ssp_reset();
|
||||
ssp_ssel_mask |= c->ssel;
|
||||
ssp_deassert_ssel();
|
||||
ssp_config = *c;
|
||||
ssp_bits = (c->mode & 15) + 1;
|
||||
ssp_bits = (ssp_config.mode & 15) + 1;
|
||||
SSPCR1 = 0;
|
||||
SSPCPSR = SSPCPSR_MIN; // 30 MHz
|
||||
SSPCR0 = c->mode;
|
||||
SSPCR0 = ssp_config.mode;
|
||||
// 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.
|
||||
// Route the SSP IRQ through the VIC
|
||||
VICVectAddrs[IrqVec_SSP] = ssp_isr;
|
||||
VICVectCntl[IrqVec_SSP] = VICVectCntl_SSP;
|
||||
VICIntEnable = VIC_SSP;
|
||||
ssp_set_match(0, 0, 0, 0, 0);
|
||||
SSPCR1 = SSPCR1_SSE; // enable
|
||||
}
|
||||
|
||||
void ssp_assert_ssel(unsigned int ssel)
|
||||
void ssp_assert_ssel(void)
|
||||
{
|
||||
unsigned int ssel = ssp_config.ssel;
|
||||
if (ssel & ssp_flag_mclk)
|
||||
PCB_PINSEL1 |= PCB_PINSEL1_P016_Match0_2;
|
||||
else
|
||||
|
|
@ -260,13 +256,13 @@ const struct ssp_config ssp_conf_dac_daisy =
|
|||
.mode = SSPCR0_16bits | SSP_kHz(1000),
|
||||
.ssel = SSP_LTC2656 | SSP_SSEL,
|
||||
};
|
||||
const struct ssp_config ssp_conf_bate =
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(250),
|
||||
.ssel = SSP_MS5534C,
|
||||
};
|
||||
const struct ssp_config ssp_conf_bate_ext =
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(120),
|
||||
.ssel = SSP_EXT | SSP_MCLK,
|
||||
struct ssp_config ssp_conf_bate[] = {
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(250),
|
||||
.ssel = SSP_MS5534C,
|
||||
},
|
||||
{
|
||||
.mode = SSPCR0_16bits | SSP_kHz(120),
|
||||
.ssel = SSP_EXT | SSP_MCLK,
|
||||
},
|
||||
};
|
||||
|
|
|
|||
22
ssp.h
22
ssp.h
|
|
@ -1,9 +1,14 @@
|
|||
|
||||
#ifndef _ssp_h_
|
||||
#define _ssp_h_
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
void ssp_reset(void);
|
||||
|
||||
void ssp_set_buffer(void *start, int size);
|
||||
void ssp_poll(void);
|
||||
int ssp_submit(unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc);
|
||||
int ssp_submit(const unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc);
|
||||
int ssp_busy(void);
|
||||
int ssp_wait(int timeout);
|
||||
|
||||
|
|
@ -29,8 +34,14 @@ enum ssp_config_flags {
|
|||
};
|
||||
|
||||
void ssp_init(struct ssp_config *c);
|
||||
void ssp_deassert_ssel();
|
||||
void ssp_assert_ssel(unsigned int ssel);
|
||||
void ssp_assert_ssel(void);
|
||||
|
||||
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))
|
||||
|
||||
|
|
@ -45,8 +56,7 @@ 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 const struct ssp_config ssp_conf_bate;
|
||||
extern const struct ssp_config ssp_conf_bate_ext;
|
||||
extern struct ssp_config ssp_conf_bate[];
|
||||
|
||||
static inline
|
||||
void ssp_set_match(unsigned int mask, unsigned int value,
|
||||
|
|
@ -59,3 +69,5 @@ void ssp_set_match(unsigned int mask, unsigned int value,
|
|||
ssp_match_count = count;
|
||||
ssp_read_size = size;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue