Compare commits

..

No commits in common. "100f07b9f5b610e485977c5370b3a848e784b77d" and "684d552c1313bc2da2a91b8e7661ac68a5ec04ec" have entirely different histories.

2 changed files with 33 additions and 60 deletions

View file

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

View file

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