Compare commits

...

4 commits

Author SHA1 Message Date
Stephan I. Böttcher
3b667318cb pressure.c: read_pressure()
Implement readout of the MS5534C pressure sensor.
2024-11-01 10:18:32 +01:00
Stephan I. Böttcher
6aaced18ad gpio.h: define SSP_MISO
define macro `SSP_MISO` to read the status of the miso line.  Waiting
for the MS5534C pressure sensor conversion need to look at the status of
this pin.

The pin could be configured as an edge sensitive interrupt
via timer1 capture.  With a neat gimick to measure the conversion time.
2024-11-01 10:14:27 +01:00
Stephan I. Böttcher
de392895d7 ssp.h: ssp_set_match(), …
- helper to set all five match vars in one line.
- fix arg names of `ssp_submit()`
2024-11-01 10:12:49 +01:00
Stephan I. Böttcher
ce64c3ac74 ssp.c: fixes
- decrement `ssp_frame_count` also when `rc`
- do not reset buffer in `ssp_reset()`
- return from `ssp_busy()` returned by `ssp_wait()`
2024-11-01 10:10:26 +01:00
4 changed files with 99 additions and 6 deletions

1
gpio.h
View file

@ -96,6 +96,7 @@ static inline void init_gpio(void) {}
#define SSP_SSEL_MASK1 0x03000000 // gpio1 pins to set high on deassert ssel
#define SSP_SSEL_CONF0 0x00113f00 // ssel bits associated with gpio0 pins
#define SSP_SSEL_CONF1 0x03ee0000 // ssel bits associated with gpio1 pins
#define SSP_MISO (GPIO_FIO0PIN2 & 4)
extern unsigned int gpio1_mask;
void gpio_set(unsigned int pins);

View file

@ -47,3 +47,83 @@ int calib_pressure(int hashit)
pressure[idx] = ((8000+X)*10)>>5;
return idx;
}
static inline
int pressure_wait_for_conversion(int timeout)
{
while (SSP_MISO && timeout-->0);
return SSP_MISO;
}
int read_pressure(int from_phase, int to_phase, int value, struct ssp_config *sspc)
{
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 timeout;
for (phase = from_phase; !r && phase <= to_phase; phase++)
switch (phase) {
case 0: if (!sspc)
sspc = spi_conf_bate;
ssp_init(sspc);
break;
case 1:
ssp_assert_ssel(ssp_ssel);
ssp_set_buffer(pressure_reading, 8);
ssp_set_match(0, 0, 3, 0, 8);
r = ssp_submit(cmds, 11, 0, 0);
break;
case 2:
case 6:
case 9: if (phase==to_phase)
timeout = value
else
timeout = 1000;
r = ssp_wait(timeout);
break;
case 3: pressure_reading[3] = pressure_reading[2];
pressure_reading[2] = pressure_reading[0];
pressure_reading[5] = pressure_reading[6];
break;
case 4:
case 7: if (phase==to_phase)
timeout = value;
else
timeout = 1000000;
r = pressure_wait_for_conversion(timeout);
break;
case 5: ssp_set_buffer(pressure_reading+6, 2);
ssp_set_match(0, 0, 0, 0, 0);
r = ssp_submit(cmds+11, 2, 0, 1);
break;
case 8: r = ssp_submit(cmds+11, 1, 0, 1);
break;
case 10:
ssp_deassert_ssel();
if (ssp_ssel & SSP_EXT)
pressure_reading[0] = 0xbafe;
else
pressure_reading[0] = 0xba7e;
break;
case 11:
calib_pressure(value);
break;
default:
r = -1;
}
return r;
}

10
ssp.c
View file

@ -77,8 +77,8 @@ static void ssp_isr(void)
sr=SSPSR;
nread++;
ssp_lastword = ssp_lastword << ssp_bits | dr;
if (!rc
&& ssp_frame_count++ >= ssp_match_count
if (ssp_frame_count++ >= ssp_match_count
&& !rc
&& (dr & ssp_match_mask) == ssp_match_value) {
rc = ssp_read_size;
j->idle_count = 0;
@ -173,7 +173,6 @@ void ssp_reset(void)
j->cmd_count = 0;
j->idle_count = 0;
j->read_count = 0;
ssp_set_buffer(0,0);
enable_irq(iflg);
}
@ -236,8 +235,9 @@ done:
int ssp_wait(int timeout)
{
while (ssp_busy() && timeout-->0);
return !timeout;
unsigned int c;
while ((c=ssp_busy()) && timeout-->0);
return c;
}
const struct ssp_config ssp_conf_adc =

14
ssp.h
View file

@ -3,7 +3,7 @@ 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 idle, unsigned int compress);
int ssp_submit(unsigned short *cmd, int cmd_size, unsigned int ic, unsigned int rc);
int ssp_busy(void);
int ssp_wait(int timeout);
@ -47,3 +47,15 @@ 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;
static inline
void ssp_set_match(unsigned int mask, unsigned int value,
unsigned int count, unsigned int idle,
unsigned int size)
{
ssp_idle = idle;
ssp_match_mask = mask;
ssp_match_value = value;
ssp_match_count = count;
ssp_read_size = size;
}