Compare commits
No commits in common. "100f07b9f5b610e485977c5370b3a848e784b77d" and "684d552c1313bc2da2a91b8e7661ac68a5ec04ec" have entirely different histories.
100f07b9f5
...
684d552c13
2 changed files with 33 additions and 60 deletions
40
leia/leia.c
40
leia/leia.c
|
|
@ -20,13 +20,14 @@
|
|||
|
||||
#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"
|
||||
|
||||
|
|
@ -874,7 +875,7 @@ int main()
|
|||
unsigned char resp[3];
|
||||
stepper_run();
|
||||
unsigned char e = spi_slave_Rx(cmd, 3);
|
||||
if (e) {
|
||||
if (error_msg[5]) {
|
||||
error_msg[4] = 'S';
|
||||
error_msg[5] = e;
|
||||
spi_slave_Tx(error_msg, sizeof(error_msg));
|
||||
|
|
@ -996,14 +997,14 @@ int main()
|
|||
else
|
||||
adc_stop();
|
||||
break;
|
||||
case 'v':
|
||||
if (cmd[1] >= sizeof(revision)) {
|
||||
resp[1] = 0;
|
||||
resp[2] = sizeof(revision);
|
||||
break;
|
||||
}
|
||||
case 'V':
|
||||
resp[1] = 0;
|
||||
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;
|
||||
case 'z': // Load/Save conf
|
||||
resp[1] = cmd[1];
|
||||
|
|
@ -1011,22 +1012,21 @@ int main()
|
|||
if (!up) {
|
||||
if (cmd[1]!='W' || eeprom_save(cmd[2]*4)) {
|
||||
resp[0] = 'E';
|
||||
resp[1] = 'z';
|
||||
resp[2] = cmd[1];
|
||||
resp[1] = 'W';
|
||||
resp[2] = 'Y';
|
||||
}
|
||||
break;
|
||||
}
|
||||
if ((cmd[1] | 0x20) == 'e') {
|
||||
if (eeprom_load(cmd[2]*4)) {
|
||||
resp[0] = 'E';
|
||||
resp[1] = 'Z';
|
||||
resp[2] = cmd[1];
|
||||
resp[1] = 'R';
|
||||
resp[2] = 'Y';
|
||||
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,17 +1037,13 @@ 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] = 'O';
|
||||
resp[2] = sizeof(struct vars);
|
||||
resp[1] = sizeof(struct vars);
|
||||
break;
|
||||
}
|
||||
resp[1] = ((unsigned char *)(&v))[cmd[1]];
|
||||
|
|
|
|||
53
spi_slave.h
53
spi_slave.h
|
|
@ -26,10 +26,15 @@ unsigned char spi_slave_Rx_status()
|
|||
#define SPI_LATE 0x80
|
||||
#define SPI_SHORT 0x40
|
||||
|
||||
#define spi_slave_Rx spi_slave_Rx_l
|
||||
#define spi_slave_Rx spi_slave_Rx_n
|
||||
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));
|
||||
|
|
@ -51,17 +56,6 @@ 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)
|
||||
|
|
@ -223,8 +217,6 @@ 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) {
|
||||
|
|
@ -235,32 +227,17 @@ unsigned char spi_slave_Rx_sleep(unsigned char d[], unsigned char n)
|
|||
sleep_cpu();
|
||||
cli();
|
||||
}
|
||||
return n | SPI_LATE;
|
||||
d[0] = 0xff;
|
||||
return n | SPI_LATE | SPI_SHORT;
|
||||
}
|
||||
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;
|
||||
SPSR;
|
||||
SPDR;
|
||||
while (PIN_SSEL) {
|
||||
sei();
|
||||
sleep_cpu();
|
||||
cli();
|
||||
}
|
||||
return 0;
|
||||
return spi_slave_Rx_n(d, n);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue