You know I never actually compiled any of this yet

This commit is contained in:
XANTRONIX Development 2016-05-27 01:27:17 -05:00
parent 2fd9cfdc3d
commit d4dfd3e34e
5 changed files with 67 additions and 55 deletions

View file

@ -22,6 +22,9 @@ static volatile tabby_avr_buffer buffer = {
.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
*/
@ -44,10 +47,11 @@ ISR(TIM0_COMPB_vect) {
uart_putchar(value_in, NULL);
if (buffer.cur < buffer.len) {
value_out = buffer.data[++buffer.cur];
value_out = buffer.data[buffer.cur++];
} else {
buffer.len = 0;
buffer.cur = 0;
buffer.read = 0;
}
bits = 8;
@ -67,10 +71,11 @@ ISR(SPI_STC_vect) {
uart_putchar(SPDR);
if (buffer.cur < buffer.len) {
SPDR = buffer.data[++buffer.cur];
SPDR = buffer.data[buffer.cur++];
} else {
buffer.len = 0;
buffer.cur = 0;
buffer.len = 0;
buffer.cur = 0;
buffer.read = 0;
}
}
@ -185,46 +190,78 @@ int main() {
received++;
switch (state) {
case TABBY_COMMAND_NONE: {
if (last == 0 && c == TABBY_PACKET_START) {
continue;
} else if (last == TABBY_PACKET_START) {
state = c;
}
case TABBY_COMMAND_NONE:
state = c;
break;
}
case TABBY_COMMAND_SEND: {
if (received == 3 || received == 4) {
case TABBY_COMMAND_SEND:
if (received == 2 || received == 3) {
buffer.len = (buffer.len >> 8) | (c << 8);
} else {
buffer.data[buffer.cur++] = c;
buffer.data[buffer.read++] = c;
if (buffer.read == buffer.len) {
goto reset;
}
}
break;
}
case TABBY_COMMAND_CLOCK_SOURCE:
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:
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 error_invalid_packet;
goto reset;
}
last = c;
received++;
continue;
error_invalid_packet:
reset:
state = TABBY_COMMAND_NONE;
last = 0;
received = 0;
buffer.cur = 0;
buffer.len = 0;
buffer.len = 0;
buffer.cur = 0;
buffer.read = 0;
}
return 0;

View file

@ -3,6 +3,5 @@
#include <tabby/clock.h>
#include <tabby/command.h>
#include <tabby/packet.h>
#endif /* _TABBY_H */

View file

@ -3,19 +3,14 @@
#include <sys/types.h>
#include <tabby/packet.h>
#define TABBY_AVR_BUFFER_SIZE 1024
typedef struct _tabby_avr_buffer {
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;
#endif /* _TABBY_AVR_BUFFER_H */

View file

@ -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 */

View file

@ -40,9 +40,8 @@ int tabby_link_close(int fd) {
}
ssize_t tabby_link_send(int fd, char *buf, uint16_t len) {
tabby_packet header = {
.type = htobe16(TABBY_COMMAND_SEND),
.value = htobe16(len)
uint8_t header[3] = {
TABBY_COMMAND_SEND, len & 0xff00 >> 8, len & 0xff
};
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) {
tabby_packet packet = {
.command = htobe16(TABBY_COMMAND_CLOCK_SOURCE),
.value = htobe16(source)
uint8_t packet[2] = {
TABBY_COMMAND_CLOCK_SOURCE, source
};
return write(fd, &packet, sizeof(packet));
}
int tabby_link_set_clock_speed(int fd, tabby_clock_speed speed) {
tabby_packet packet = {
.command = htobe16(TABBY_COMMAND_CLOCK_SPEED),
.value = htobe16(speed)
uint8_t packet[2] = {
TABBY_COMMAND_CLOCK_SPEED, speed
};
return write(fd, &packet, sizeof(packet));