Compare commits

..

3 commits

Author SHA1 Message Date
Stephan I. Böttcher
47be0651b0 pressure: struct ssp_batch bate_batch[] 2024-11-03 12:17:52 +01:00
Stephan I. Böttcher
bcf8f25f7a Makefile: -Wno-missing-field-initializers 2024-11-03 12:17:13 +01:00
Stephan I. Böttcher
bff7cdb5d4 ssp_abort_batch() 2024-11-03 12:16:28 +01:00
4 changed files with 87 additions and 22 deletions

View file

@ -107,7 +107,9 @@ CPUA= -mlittle-endian -mcpu=arm7tdmi
CPUC= $(CPUA) -msoft-float -mno-thumb-interwork -mpoke-function-name CPUC= $(CPUA) -msoft-float -mno-thumb-interwork -mpoke-function-name
DEBUGFORMAT=-g -gdwarf-2 DEBUGFORMAT=-g -gdwarf-2
WARN = -Wall -Wextra -Wno-char-subscripts -Wno-unused -Wno-pointer-sign -Wno-parentheses $(WWARN) WARN = -Wall -Wextra -Wno-char-subscripts -Wno-unused -Wno-pointer-sign \
-Wno-parentheses -Wno-missing-field-initializers \
$(WWARN)
BUILTIN = --no-builtin-snprintf -fno-builtin-printf BUILTIN = --no-builtin-snprintf -fno-builtin-printf
CC=$(ARCH)-gcc-$(GCC) -std=gnu99 -O3 $(CPUC) $(WARN) $(BUILTIN) CC=$(ARCH)-gcc-$(GCC) -std=gnu99 -O3 $(CPUC) $(WARN) $(BUILTIN)

View file

@ -52,6 +52,78 @@ int calib_pressure(int hashit)
return idx; return idx;
} }
extern const struct timer_wait wait_conversion;
unsigned int bate_status;
static void bate_callback(const volatile struct timer_tick* tick) {
if (timer_wait_pin_status(&wait_conversion))
ssp_run_batch();
else {
bate_status = 9;
ssp_abort_batch();
}
}
const struct timer_wait wait_conversion = {
.mclk = 3333, // 50 ms
.pinmask = 1<<18, // wait for port0.18 to go low
.callback = bate_callback,
};
static const unsigned short bate_cmds[] = {
0b0000000010101010, // 0 reset part 1
0b1010101000000000, // 1 reset part 2
0b0001110101010000, // 2 word 1 cmd
0, // 3 word 1 value
0b0001110101100000, // 4 word 2 cmd
0, // 5 word 2 value
0b0001110110010000, // 6 word 3 cmd
0, // 7 word 3 value
0b0001110110100000, // 8 word 4 cmd
0, // 9 word 5 value
0b0000111101000000, // 10 data 1 cmd
// wait
0, // 11 data 1,2 value
0b0000111100100000, // 12 data 2 cmd
};
unsigned short bate_buffer[16];
static const struct ssp_batch bate_batch[] = {
[0] = {
.ssel = ssp_conf_bate,
.job = &(const struct ssp_job) {
.command = bate_cmds,
.cmd_count = 11,
.buf_count = 16,
.buf_ptr = bate_buffer,
},
.match = &(const struct ssp_match) {
.count = 3,
.size = 7,
},
},
[1] = {
.wait = &wait_conversion,
.job = &(const struct ssp_job) {
.command = bate_cmds+11,
.cmd_count = 2,
.read_count = 1,
},
},
[2] = {
.wait = &wait_conversion,
.job = &(const struct ssp_job) {
.command = bate_cmds+11,
.cmd_count = 1,
.read_count = 1,
},
},
[3] = { }
};
static inline static inline
int pressure_wait_for_conversion(int timeout) int pressure_wait_for_conversion(int timeout)
{ {
@ -61,22 +133,6 @@ int pressure_wait_for_conversion(int timeout)
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 idx)
{ {
static const unsigned short cmds[] = {
0b0000000010101010, // 0 reset part 1
0b1010101000000000, // 1 reset part 2
0b0001110101010000, // 2 word 1 cmd
0, // 3 word 1 value
0b0001110101100000, // 4 word 2 cmd
0, // 5 word 2 value
0b0001110110010000, // 6 word 3 cmd
0, // 7 word 3 value
0b0001110110100000, // 8 word 4 cmd
0, // 9 word 5 value
0b0000111101000000, // 10 data 1 cmd
// wait
0, // 11 data 1,2 value
0b0000111100100000, // 12 data 2 cmd
};
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++)
@ -87,7 +143,7 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
ssp_assert_ssel(); ssp_assert_ssel();
ssp_set_buffer(pressure_reading, 8); ssp_set_buffer(pressure_reading, 8);
ssp_set_read(3, 8); ssp_set_read(3, 8);
r = ssp_submit(cmds, 11, 0, 0); r = ssp_submit(bate_cmds, 11, 0, 0);
break; break;
case 2: case 2:
case 6: case 6:
@ -110,9 +166,9 @@ int read_pressure(int from_phase, int to_phase, int value, int idx)
break; break;
case 5: ssp_set_buffer(pressure_reading+6, 2); case 5: ssp_set_buffer(pressure_reading+6, 2);
ssp_set_read(0, 0); ssp_set_read(0, 0);
r = ssp_submit(cmds+11, 2, 0, 1); r = ssp_submit(bate_cmds+11, 2, 0, 1);
break; break;
case 8: r = ssp_submit(cmds+11, 1, 0, 1); case 8: r = ssp_submit(bate_cmds+11, 1, 0, 1);
break; break;
case 10: case 10:
ssp_deassert_ssel(); ssp_deassert_ssel();

10
ssp.c
View file

@ -303,13 +303,19 @@ int ssp_run_batch()
return ssp_submit_job(batch->job); return ssp_submit_job(batch->job);
} }
void ssp_abort_batch()
{
ssp_batch_repeats = 0;
ssp_batch_wait = 0;
ssp_batch = 0;
}
int ssp_submit_batch(const struct ssp_batch *batch, int timeout) int ssp_submit_batch(const struct ssp_batch *batch, int timeout)
{ {
unsigned int c = ssp_wait(timeout); unsigned int c = ssp_wait(timeout);
if (c) if (c)
return c; return c;
ssp_batch_repeats = 0; ssp_abort_batch();
ssp_batch = batch; ssp_batch = batch;
ssp_batch_wait = 0;
return ssp_run_batch(); return ssp_run_batch();
} }

1
ssp.h
View file

@ -107,5 +107,6 @@ void ssp_set_read(unsigned int count, unsigned int size)
int ssp_submit_job(const struct ssp_job *jj); int ssp_submit_job(const struct ssp_job *jj);
int ssp_submit_batch(const struct ssp_batch *batch, int timeout); int ssp_submit_batch(const struct ssp_batch *batch, int timeout);
int ssp_run_batch(); int ssp_run_batch();
void ssp_abort_batch();
#endif #endif