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