You know I never actually compiled any of this yet
This commit is contained in:
parent
2fd9cfdc3d
commit
d4dfd3e34e
5 changed files with 67 additions and 55 deletions
73
avr/main.c
73
avr/main.c
|
@ -22,6 +22,9 @@ static volatile tabby_avr_buffer buffer = {
|
||||||
.cur = 0
|
.cur = 0
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static tabby_clock_source source = TABBY_CLOCK_SOURCE_INTERNAL;
|
||||||
|
static tabby_clock_speed speed = TABBY_CLOCK_SPEED_8192HZ;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Internal clock source interrupt vector
|
* Internal clock source interrupt vector
|
||||||
*/
|
*/
|
||||||
|
@ -44,10 +47,11 @@ ISR(TIM0_COMPB_vect) {
|
||||||
uart_putchar(value_in, NULL);
|
uart_putchar(value_in, NULL);
|
||||||
|
|
||||||
if (buffer.cur < buffer.len) {
|
if (buffer.cur < buffer.len) {
|
||||||
value_out = buffer.data[++buffer.cur];
|
value_out = buffer.data[buffer.cur++];
|
||||||
} else {
|
} else {
|
||||||
buffer.len = 0;
|
buffer.len = 0;
|
||||||
buffer.cur = 0;
|
buffer.cur = 0;
|
||||||
|
buffer.read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
bits = 8;
|
bits = 8;
|
||||||
|
@ -67,10 +71,11 @@ ISR(SPI_STC_vect) {
|
||||||
uart_putchar(SPDR);
|
uart_putchar(SPDR);
|
||||||
|
|
||||||
if (buffer.cur < buffer.len) {
|
if (buffer.cur < buffer.len) {
|
||||||
SPDR = buffer.data[++buffer.cur];
|
SPDR = buffer.data[buffer.cur++];
|
||||||
} else {
|
} else {
|
||||||
buffer.len = 0;
|
buffer.len = 0;
|
||||||
buffer.cur = 0;
|
buffer.cur = 0;
|
||||||
|
buffer.read = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,46 +190,78 @@ int main() {
|
||||||
received++;
|
received++;
|
||||||
|
|
||||||
switch (state) {
|
switch (state) {
|
||||||
case TABBY_COMMAND_NONE: {
|
case TABBY_COMMAND_NONE:
|
||||||
if (last == 0 && c == TABBY_PACKET_START) {
|
|
||||||
continue;
|
|
||||||
} else if (last == TABBY_PACKET_START) {
|
|
||||||
state = c;
|
state = c;
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case TABBY_COMMAND_SEND: {
|
case TABBY_COMMAND_SEND:
|
||||||
if (received == 3 || received == 4) {
|
if (received == 2 || received == 3) {
|
||||||
buffer.len = (buffer.len >> 8) | (c << 8);
|
buffer.len = (buffer.len >> 8) | (c << 8);
|
||||||
} else {
|
} else {
|
||||||
buffer.data[buffer.cur++] = c;
|
buffer.data[buffer.read++] = c;
|
||||||
|
|
||||||
|
if (buffer.read == buffer.len) {
|
||||||
|
goto reset;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
|
||||||
|
|
||||||
case TABBY_COMMAND_CLOCK_SOURCE:
|
case TABBY_COMMAND_CLOCK_SOURCE:
|
||||||
case TABBY_COMMAND_CLOCK_SPEED:
|
switch (c) {
|
||||||
|
case TABBY_CLOCK_SOURCE_INTERNAL:
|
||||||
|
source = c;
|
||||||
|
|
||||||
|
setup_clock_internal(speed);
|
||||||
|
|
||||||
|
goto reset;
|
||||||
|
|
||||||
|
case TABBY_CLOCK_SOURCE_EXTERNAL:
|
||||||
|
source = c;
|
||||||
|
|
||||||
|
setup_clock_external();
|
||||||
|
|
||||||
|
goto reset;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
goto error_invalid_packet;
|
goto reset;
|
||||||
|
}
|
||||||
|
|
||||||
|
case TABBY_COMMAND_CLOCK_SPEED:
|
||||||
|
switch (c) {
|
||||||
|
case TABBY_CLOCK_SPEED_8192HZ:
|
||||||
|
case TABBY_CLOCK_SPEED_16384HZ:
|
||||||
|
case TABBY_CLOCK_SPEED_262144HZ:
|
||||||
|
case TABBY_CLOCK_SPEED_524288HZ:
|
||||||
|
speed = c;
|
||||||
|
|
||||||
|
if (source == TABBY_CLOCK_SOURCE_INTERNAL) {
|
||||||
|
setup_clock_internal(speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
goto reset;
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto reset;
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
goto reset;
|
||||||
}
|
}
|
||||||
|
|
||||||
last = c;
|
last = c;
|
||||||
|
|
||||||
received++;
|
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
error_invalid_packet:
|
reset:
|
||||||
state = TABBY_COMMAND_NONE;
|
state = TABBY_COMMAND_NONE;
|
||||||
last = 0;
|
last = 0;
|
||||||
received = 0;
|
received = 0;
|
||||||
|
|
||||||
buffer.cur = 0;
|
|
||||||
buffer.len = 0;
|
buffer.len = 0;
|
||||||
|
buffer.cur = 0;
|
||||||
|
buffer.read = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
|
@ -3,6 +3,5 @@
|
||||||
|
|
||||||
#include <tabby/clock.h>
|
#include <tabby/clock.h>
|
||||||
#include <tabby/command.h>
|
#include <tabby/command.h>
|
||||||
#include <tabby/packet.h>
|
|
||||||
|
|
||||||
#endif /* _TABBY_H */
|
#endif /* _TABBY_H */
|
||||||
|
|
|
@ -3,19 +3,14 @@
|
||||||
|
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include <tabby/packet.h>
|
|
||||||
|
|
||||||
#define TABBY_AVR_BUFFER_SIZE 1024
|
#define TABBY_AVR_BUFFER_SIZE 1024
|
||||||
|
|
||||||
typedef struct _tabby_avr_buffer {
|
typedef struct _tabby_avr_buffer {
|
||||||
uint16_t len,
|
uint16_t len,
|
||||||
cur;
|
cur,
|
||||||
|
read;
|
||||||
union {
|
|
||||||
tabby_packet header;
|
|
||||||
|
|
||||||
uint8_t data[TABBY_AVR_BUFFER_SIZE];
|
uint8_t data[TABBY_AVR_BUFFER_SIZE];
|
||||||
};
|
|
||||||
} tabby_avr_buffer;
|
} tabby_avr_buffer;
|
||||||
|
|
||||||
#endif /* _TABBY_AVR_BUFFER_H */
|
#endif /* _TABBY_AVR_BUFFER_H */
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
#ifndef _TABBY_PACKET_H
|
|
||||||
#define _TABBY_PACKET_H
|
|
||||||
|
|
||||||
#define TABBY_PACKET_START 0xff
|
|
||||||
#define TABBY_PACKET_MAX_LEN 1024
|
|
||||||
|
|
||||||
#include <tabby/command.h>
|
|
||||||
|
|
||||||
typedef struct _tabby_packet {
|
|
||||||
uint8_t start,
|
|
||||||
command;
|
|
||||||
|
|
||||||
uint16_t len;
|
|
||||||
} tabby_packet;
|
|
||||||
|
|
||||||
#endif /* _TABBY_PACKET_H */
|
|
15
src/link.c
15
src/link.c
|
@ -40,9 +40,8 @@ int tabby_link_close(int fd) {
|
||||||
}
|
}
|
||||||
|
|
||||||
ssize_t tabby_link_send(int fd, char *buf, uint16_t len) {
|
ssize_t tabby_link_send(int fd, char *buf, uint16_t len) {
|
||||||
tabby_packet header = {
|
uint8_t header[3] = {
|
||||||
.type = htobe16(TABBY_COMMAND_SEND),
|
TABBY_COMMAND_SEND, len & 0xff00 >> 8, len & 0xff
|
||||||
.value = htobe16(len)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if (write(fd, &header, sizeof(header)) < 0) {
|
if (write(fd, &header, sizeof(header)) < 0) {
|
||||||
|
@ -60,18 +59,16 @@ ssize_t tabby_link_recv(int fd, char *buf, uint16_t len) {
|
||||||
}
|
}
|
||||||
|
|
||||||
int tabby_link_set_clock_source(int fd, tabby_clock_source source) {
|
int tabby_link_set_clock_source(int fd, tabby_clock_source source) {
|
||||||
tabby_packet packet = {
|
uint8_t packet[2] = {
|
||||||
.command = htobe16(TABBY_COMMAND_CLOCK_SOURCE),
|
TABBY_COMMAND_CLOCK_SOURCE, source
|
||||||
.value = htobe16(source)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return write(fd, &packet, sizeof(packet));
|
return write(fd, &packet, sizeof(packet));
|
||||||
}
|
}
|
||||||
|
|
||||||
int tabby_link_set_clock_speed(int fd, tabby_clock_speed speed) {
|
int tabby_link_set_clock_speed(int fd, tabby_clock_speed speed) {
|
||||||
tabby_packet packet = {
|
uint8_t packet[2] = {
|
||||||
.command = htobe16(TABBY_COMMAND_CLOCK_SPEED),
|
TABBY_COMMAND_CLOCK_SPEED, speed
|
||||||
.value = htobe16(speed)
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return write(fd, &packet, sizeof(packet));
|
return write(fd, &packet, sizeof(packet));
|
||||||
|
|
Loading…
Add table
Reference in a new issue