Compare commits

..

No commits in common. "60d830fdaebb7a9848f48be9d1c75fe4d7e7536d" and "a91d06723f159d7e39f394e66f001dbf2f9b32f5" have entirely different histories.

6 changed files with 35 additions and 49 deletions

View file

@ -30,6 +30,7 @@ const struct keywords ads8688_variable_names[] = {
VARIABLE("adc_avr", &data.n), VARIABLE("adc_avr", &data.n),
VARIABLE("adc_sum", &data.sum), VARIABLE("adc_sum", &data.sum),
VARIABLE("adc_square", &data.square), VARIABLE("adc_square", &data.square),
VARIABLE("ssp_adc", &ssp_conf_adc),
KW_END KW_END
}; };

View file

@ -871,6 +871,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}}
@ -878,7 +880,6 @@ static const struct keywords main_variable_names[] = {
const struct keywords *variable_names[] = { const struct keywords *variable_names[] = {
main_variable_names, main_variable_names,
ssp_variable_names,
spi_variable_names, spi_variable_names,
sdcard_variable_names, sdcard_variable_names,
script_variable_names, script_variable_names,

View file

@ -16,6 +16,7 @@ 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))
@ -107,7 +108,7 @@ static const unsigned short bate_cmds[] = {
static const struct ssp_batch bate_batch[] = { static const struct ssp_batch bate_batch[] = {
{ {
.flags = ssp_b_config | ssp_b_assert, .flags = ssp_b_config | ssp_b_assert,
{ .ssel = &ssp_conf_bate }, { .ssel = ssp_conf_bate },
}, },
{ {
.flags = ssp_b_job, .flags = ssp_b_job,
@ -155,13 +156,13 @@ 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 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 (int phase = from_phase; !r && phase <= to_phase; phase++)
switch (phase) { switch (phase) {
case 0: ssp_init(&ssp_conf_bate); case 0: ssp_init(&ssp_conf_bate[!!idx]);
break; break;
case 1: case 1:
ssp_assert_ssel(); ssp_assert_ssel();
@ -260,7 +261,7 @@ int bate_cmd(struct command *cmd, const struct command_par *par)
if (from_phase >= bate_ph_calib) if (from_phase >= bate_ph_calib)
idx = !!(pressure_reading[0] & 0x80); idx = !!(pressure_reading[0] & 0x80);
int r = read_pressure(from_phase, to_phase, value); 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 || to_phase < bate_ph_calib) {

View file

@ -5,7 +5,7 @@
#include "ssp.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 read_pressure(int from_phase, int to_phase, int value, int idx);
int bate_cmd(struct command *cmd, const struct command_par *par); int bate_cmd(struct command *cmd, const struct command_par *par);
enum bate_phase { enum bate_phase {

56
ssp.c
View file

@ -23,17 +23,17 @@ volatile unsigned int ssp_frame_count;
unsigned short ssp_scratch[256]; unsigned short ssp_scratch[256];
void ssp_set_buffer(short *buf, int size) void ssp_set_buffer(void *start, int size)
{ {
unsigned int iflg = disable_irq(INT_DISABLE); unsigned int iflg = disable_irq(INT_DISABLE);
volatile struct ssp_job *j=&job; volatile struct ssp_job *j=&job;
if (!(size && buf)) { if (!(size && start)) {
buf = ssp_scratch; start = ssp_scratch;
size = sizeof(ssp_scratch)/2; size = sizeof(ssp_scratch);
} }
ssp_buffer = (unsigned short *)buf; ssp_buffer = (unsigned short *)start;
j->buf_ptr = (unsigned short *)buf; j->buf_ptr = (unsigned short *)start;
j->buf_count = size; j->buf_count = size/2;
enable_irq(iflg); enable_irq(iflg);
} }
@ -240,23 +240,25 @@ int ssp_wait(int timeout)
return c; return c;
} }
struct ssp_config ssp_confs[] = { struct ssp_config ssp_conf_adc =
{ {
.mode = SSPCR0_16bits | SSP_kHz(1000), .mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(10000),
.ssel = SSP_SSEL, .ssel = SSP_ADS8688,
}, };
{ struct ssp_config ssp_conf_dac =
.mode = SSPCR0_16bits | SSPCR0_CPHA | SSP_kHz(10000), {
.ssel = SSP_ADS8688, .mode = SSPCR0_16bits | SSP_kHz(30000),
}, .ssel = SSP_LTC2656,
{ };
.mode = SSPCR0_16bits | SSP_kHz(30000), struct ssp_config ssp_conf_bate[] = {
.ssel = SSP_LTC2656,
},
{ {
.mode = SSPCR0_16bits | SSP_kHz(250), .mode = SSPCR0_16bits | SSP_kHz(250),
.ssel = SSP_MS5534C, .ssel = SSP_MS5534C,
}, },
{
.mode = SSPCR0_16bits | SSP_kHz(120),
.ssel = SSP_EXT | SSP_MCLK,
},
}; };
const struct ssp_batch *ssp_batch; const struct ssp_batch *ssp_batch;
@ -380,17 +382,3 @@ int ssp_submit_batch(const struct ssp_batch *batch, int timeout)
ssp_callback = ssp_run_batch; ssp_callback = ssp_run_batch;
return ssp_run_batch(); return ssp_run_batch();
} }
const struct keywords ssp_variable_names[] = {
VARIABLE("ssp_buffer", ssp_scratch),
VARIABLE("ssp_response", (void *)&ssp_lastword),
VARIABLE("ssp_match", &ssp_match),
VARIABLE("ssp_ssel_mask", &ssp_ssel_mask),
VARIABLE("ssp_frame_count", (void *)&ssp_frame_count),
VARIABLE("ssp_bits", &ssp_bits),
VARIABLE("ssp_config", &ssp_conf_default),
VARIABLE("ssp_adc", &ssp_conf_adc),
VARIABLE("ssp_dac", &ssp_conf_dac),
VARIABLE("ssp_pressure", &ssp_conf_bate),
{}
};

13
ssp.h
View file

@ -4,11 +4,10 @@
#include "gpio.h" #include "gpio.h"
#include "timer.h" #include "timer.h"
#include "parser.h"
void ssp_reset(void); void ssp_reset(void);
void ssp_set_buffer(short *buf, 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(const unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc);
int ssp_busy(void); int ssp_busy(void);
@ -55,11 +54,9 @@ 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_confs[]; extern struct ssp_config ssp_conf_adc;
#define ssp_conf_default ssp_confs[0] extern struct ssp_config ssp_conf_dac;
#define ssp_conf_adc ssp_confs[1] extern struct ssp_config ssp_conf_bate[];
#define ssp_conf_dac ssp_confs[2]
#define ssp_conf_bate ssp_confs[3]
// volatile part of the job, inaccessible globally // volatile part of the job, inaccessible globally
struct ssp_job { struct ssp_job {
@ -140,6 +137,4 @@ int ssp_submit_batch(const struct ssp_batch *batch, int timeout);
int ssp_run_batch(); int ssp_run_batch();
void ssp_abort_batch(); void ssp_abort_batch();
extern const struct keywords ssp_variable_names[];
#endif #endif