Compare commits

...

2 commits

Author SHA1 Message Date
Stephan I. Böttcher
60d830fdae ssp variable names 2024-11-03 21:14:33 +01:00
Stephan I. Böttcher
71e567fdc5 ssp_start_buffer, size in short words 2024-11-03 20:21:05 +01:00
6 changed files with 49 additions and 35 deletions

View file

@ -30,7 +30,6 @@ 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,8 +871,6 @@ 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}}
@ -880,6 +878,7 @@ 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,7 +16,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))
@ -108,7 +107,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,
@ -156,13 +155,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 idx) int read_pressure(int from_phase, int to_phase, int value)
{ {
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[!!idx]); case 0: ssp_init(&ssp_conf_bate);
break; break;
case 1: case 1:
ssp_assert_ssel(); ssp_assert_ssel();
@ -261,7 +260,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, idx); int r = read_pressure(from_phase, to_phase, value);
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 idx); int read_pressure(int from_phase, int to_phase, int value);
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 {

44
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(void *start, int size) void ssp_set_buffer(short *buf, 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 && start)) { if (!(size && buf)) {
start = ssp_scratch; buf = ssp_scratch;
size = sizeof(ssp_scratch); size = sizeof(ssp_scratch)/2;
} }
ssp_buffer = (unsigned short *)start; ssp_buffer = (unsigned short *)buf;
j->buf_ptr = (unsigned short *)start; j->buf_ptr = (unsigned short *)buf;
j->buf_count = size/2; j->buf_count = size;
enable_irq(iflg); enable_irq(iflg);
} }
@ -240,25 +240,23 @@ int ssp_wait(int timeout)
return c; return c;
} }
struct ssp_config ssp_conf_adc = struct ssp_config ssp_confs[] = {
{
.mode = SSPCR0_16bits | SSP_kHz(1000),
.ssel = SSP_SSEL,
},
{ {
.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 =
{ {
.mode = SSPCR0_16bits | SSP_kHz(30000), .mode = SSPCR0_16bits | SSP_kHz(30000),
.ssel = SSP_LTC2656, .ssel = SSP_LTC2656,
}; },
struct ssp_config ssp_conf_bate[] = {
{ {
.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;
@ -382,3 +380,17 @@ 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,10 +4,11 @@
#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(void *start, int size); void ssp_set_buffer(short *buf, 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);
@ -54,9 +55,11 @@ 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 struct ssp_config ssp_confs[];
extern struct ssp_config ssp_conf_dac; #define ssp_conf_default ssp_confs[0]
extern struct ssp_config ssp_conf_bate[]; #define ssp_conf_adc ssp_confs[1]
#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 {
@ -137,4 +140,6 @@ 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