Compare commits

..

2 commits

Author SHA1 Message Date
Stephan I. Böttcher
100f07b9f5 leia: Error codes 2025-10-28 23:58:03 +01:00
Stephan I. Böttcher
162e0c6c8a spi_slave: faster Rx_sleep() 2025-10-28 23:57:26 +01:00
2 changed files with 60 additions and 33 deletions

View file

@ -20,14 +20,13 @@
#include <stdint.h>
#include <string.h>
#include "revision.h"
const char revision[] = Id;
#include <avr/interrupt.h>
#include <avr/sleep.h>
#include <avr/pgmspace.h>
#include "revision.h"
unsigned char revision[] = Id;
#define SPI_Rx_SLEEP
#include "spi_slave.h"
@ -875,7 +874,7 @@ int main()
unsigned char resp[3];
stepper_run();
unsigned char e = spi_slave_Rx(cmd, 3);
if (error_msg[5]) {
if (e) {
error_msg[4] = 'S';
error_msg[5] = e;
spi_slave_Tx(error_msg, sizeof(error_msg));
@ -997,14 +996,14 @@ int main()
else
adc_stop();
break;
case 'V':
resp[1] = 0;
resp[2] = cmd[1];
while (revision[resp[1]] && resp[2]) {
resp[1]++;
resp[2]--;
case 'v':
if (cmd[1] >= sizeof(revision)) {
resp[1] = 0;
resp[2] = sizeof(revision);
break;
}
resp[1] = revision[resp[1]];
resp[2] = cmd[1];
reg8(revision+cmd[1], resp, cmd);
break;
case 'z': // Load/Save conf
resp[1] = cmd[1];
@ -1012,21 +1011,22 @@ int main()
if (!up) {
if (cmd[1]!='W' || eeprom_save(cmd[2]*4)) {
resp[0] = 'E';
resp[1] = 'W';
resp[2] = 'Y';
resp[1] = 'z';
resp[2] = cmd[1];
}
break;
}
if ((cmd[1] | 0x20) == 'e') {
if (eeprom_load(cmd[2]*4)) {
resp[0] = 'E';
resp[1] = 'R';
resp[2] = 'Y';
resp[1] = 'Z';
resp[2] = cmd[1];
break;
}
}
if (v.conf.magic != MAGIC || v.conf.version != VERSION) {
resp[0] = 'E';
resp[1] = 'V';
resp[2] = v.conf.version;
if (cmd[1] != 'F')
break;
@ -1037,13 +1037,17 @@ int main()
case 'x': // read/write conf Byte, read eeprom byte
resp[2] = cmd[1];
if (!up && cmd[2] & 0xf) {
if (eeprom_read_byte(frame2int(cmd+1) & 0x7ff, resp+1))
if (eeprom_read_byte(frame2int(cmd+1) & 0x7ff, resp+1)) {
resp[0] = 'E';
resp[1] = 'x';
resp[2] = cmd[2];
}
break;
}
if (cmd[1] >= sizeof(struct vars)) {
resp[0] = 'E';
resp[1] = sizeof(struct vars);
resp[1] = 'O';
resp[2] = sizeof(struct vars);
break;
}
resp[1] = ((unsigned char *)(&v))[cmd[1]];

View file

@ -26,15 +26,10 @@ unsigned char spi_slave_Rx_status()
#define SPI_LATE 0x80
#define SPI_SHORT 0x40
#define spi_slave_Rx spi_slave_Rx_n
#define spi_slave_Rx spi_slave_Rx_l
static inline
unsigned char spi_slave_Rx_n(unsigned char d[], unsigned char n)
{
if (SPSR & SPSR_IF) {
SPDR = 0xff;
d[0] = SPDR;
return n | SPI_LATE;
}
register unsigned char b;
do {
while (!(SPSR & SPSR_IF));
@ -56,6 +51,17 @@ unsigned char spi_slave_Rx_n(unsigned char d[], unsigned char n)
return 0;
}
static inline
unsigned char spi_slave_Rx_l(unsigned char d[], unsigned char n)
{
if (SPSR & SPSR_IF) {
SPDR = 0xff;
d[0] = SPDR;
return n | SPI_LATE;
}
return spi_slave_Rx_n(d, n);
}
extern volatile unsigned char wdt_tick;
static inline
unsigned char spi_slave_Rx_wdt(unsigned char d[], unsigned char n)
@ -217,6 +223,8 @@ static inline
unsigned char spi_slave_Rx_sleep(unsigned char d[], unsigned char n)
{
cli();
SPSR;
SPDR = 0;
if (!PIN_SSEL) {
while (!PIN_SSEL) {
if (SPSR & SPSR_IF) {
@ -227,17 +235,32 @@ unsigned char spi_slave_Rx_sleep(unsigned char d[], unsigned char n)
sleep_cpu();
cli();
}
d[0] = 0xff;
return n | SPI_LATE | SPI_SHORT;
return n | SPI_LATE;
}
SPSR;
SPDR;
while (PIN_SSEL) {
sei();
sleep_cpu();
cli();
register unsigned char b;
do {
while (!(SPSR & SPSR_IF))
if (PIN_SSEL) {
sei();
sleep_cpu();
cli();
}
SPDR = 0xff;
b = SPDR;
} while (b&0x80);
*d++ = b;
unsigned char s = 0;
while (--n) {
while (!(SPSR & SPSR_IF))
if (PIN_SSEL) {
if (s)
return n | SPI_SHORT;
s = n;
}
SPDR = 0xff;
*d++ = SPDR;
}
return spi_slave_Rx_n(d, n);
return 0;
}
#endif