summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYour Name <you@example.com>2019-04-30 14:16:53 +0100
committerYour Name <you@example.com>2019-04-30 14:16:53 +0100
commit2d7f0dd25f9d80c7361ead9995a735a63ef27020 (patch)
tree5df4fcadd9c187fab32442ed5eea7c6546d2c99b
parent259ee0e7022ce15f4f2c8294a4fc3de7005d7fab (diff)
downloadadapter-2d7f0dd25f9d80c7361ead9995a735a63ef27020.tar.gz
adapter-2d7f0dd25f9d80c7361ead9995a735a63ef27020.tar.bz2
adapter-2d7f0dd25f9d80c7361ead9995a735a63ef27020.zip
working with 2 sets of stripes
-rw-r--r--.gitignore2
-rw-r--r--app/prototypes.h3
-rw-r--r--app/ring.c2
-rw-r--r--app/timex.c222
4 files changed, 172 insertions, 57 deletions
diff --git a/.gitignore b/.gitignore
index e46adcb..aa17e75 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,5 @@
*.hex
*~
*.dfu
+.*.swp
+
diff --git a/app/prototypes.h b/app/prototypes.h
index f153902..967b9b8 100644
--- a/app/prototypes.h
+++ b/app/prototypes.h
@@ -16,7 +16,7 @@ extern void ring_init(ring_t *r, uint8_t *buf, size_t len);
extern int ring_write_byte(ring_t *r, uint8_t c);
extern int ring_empty(ring_t *r);
extern int ring_read_byte(ring_t *r, uint8_t *c);
-extern int ring_write(ring_t *r, uint8_t *buf, size_t len);
+extern int ring_write(ring_t *r, const uint8_t *buf, size_t len);
/* usart.c */
extern ring_t usart_rx_ring;
extern ring_t usart_tx_ring;
@@ -32,4 +32,5 @@ extern void ticker_init(void);
/* timex.c */
extern ring_t timex_ring;
extern void timex_tick(void);
+extern uint8_t ex[];
extern void timex_init(void);
diff --git a/app/ring.c b/app/ring.c
index 26bba3a..1f3ba4e 100644
--- a/app/ring.c
+++ b/app/ring.c
@@ -53,7 +53,7 @@ ring_read_byte (ring_t *r, uint8_t *c)
}
int
-ring_write (ring_t *r, uint8_t *buf, size_t len)
+ring_write (ring_t *r, const uint8_t *buf, size_t len)
{
while (len--) {
if (ring_write_byte (r, * (buf++)))
diff --git a/app/timex.c b/app/timex.c
index 40f43ad..f982024 100644
--- a/app/timex.c
+++ b/app/timex.c
@@ -1,32 +1,77 @@
#include "project.h"
+#define TWO_BYTES_PER_FRAME
+#undef SEND_EXAMPLE_DATA
+
/*
- * VGA 640x480 mode timings are
+ * VGA 640x480x4 mode timings are
*
* 48 640 16 96
* 10 480 33 2
*
- * at 25.175 Hz
+ * at 25.175 MHz
+ *
+ * That gives horizontal sync of 25.175MHz/800 = 31.46875 kHz
*
*/
/*
- * Two bytes are shown per video frame one starting at
- * scanline 70, the other at 255, and there are 15
- * scanlines between bits.
+ * Two bytes are shown per video frame with RS232 8,n,1 framing
+ * using the following scanlines
+ *
+ * 078 start
+ * 093 +15 0
+ * 108 +15 1
+ * 124 +16 2
+ * 139 +15 3
+ * 155 +16 4
+ * 170 +15 5
+ * 186 +16 6
+ * 201 +15 7
+ * (216 +15) stop
+ *
+ * 263 +62 (+47) start
+ * 279 +16 0
+ * 294 +15 1
+ * 310 +16 2
+ * 325 +15 3
+ * 340 +15 4
+ * 356 +16 5
+ * 371 +15 6
+ * 387 +16 7
+ * (402 +15) stop
+ *
+ * (25175000 / 800) *(8 / (201-78)) = 2046.75
+ *
+ * That's supiciously close to 2048 baud
*
*/
-#define SL_BYTE_1_START 70
-#define SL_BIT 15
-#define SL_BYTE_2_START 255
-
-#undef PAD
-#undef EX
-
-#define SL_ON(byte,bit) ((SL_BYTE_ ## byte ## _START) + (SL_BIT * (bit)))
+#define SL_BIT_0_0 78
+#define SL_BIT_0_1 93
+#define SL_BIT_0_2 108
+#define SL_BIT_0_3 124
+#define SL_BIT_0_4 139
+#define SL_BIT_0_5 155
+#define SL_BIT_0_6 170
+#define SL_BIT_0_7 186
+#define SL_BIT_0_8 201
+#define SL_BIT_0_9 216
+
+#define SL_BIT_1_0 263
+#define SL_BIT_1_1 279
+#define SL_BIT_1_2 294
+#define SL_BIT_1_3 310
+#define SL_BIT_1_4 325
+#define SL_BIT_1_5 340
+#define SL_BIT_1_6 356
+#define SL_BIT_1_7 371
+#define SL_BIT_1_8 387
+#define SL_BIT_1_9 402
+
+#define SL_ON(byte,bit) (SL_BIT_ ## byte ## _ ## bit)
#define SL_OFF(byte,bit) (SL_ON(byte,bit) + 1)
-
+#define SL_PREPARE(byte) (SL_ON(byte,0) - 2)
#define SEND_BIT(byte,bit,data) \
case SL_ON(byte,bit): \
@@ -66,8 +111,10 @@
#define BUFFER_SIZE 512
-#define TIMEX_BANK GPIOB
-#define TIMEX_GPIO GPIO9
+#define TIMEX_INPUT_BANK GPIOB
+#define TIMEX_INPUT_GPIO GPIO9
+#define TIMEX_OUTPUT_BANK GPIOB
+#define TIMEX_OUTPUT_GPIO GPIO8
ring_t timex_ring;
static uint8_t timex_ring_buf[BUFFER_SIZE];
@@ -76,14 +123,15 @@ static uint8_t timex_ring_buf[BUFFER_SIZE];
static inline void timex_led (int v)
{
if (v)
- gpio_set (TIMEX_BANK, TIMEX_GPIO);
+ gpio_set (TIMEX_OUTPUT_BANK, TIMEX_OUTPUT_GPIO);
else
- gpio_clear (TIMEX_BANK, TIMEX_GPIO);
+ gpio_clear (TIMEX_OUTPUT_BANK, TIMEX_OUTPUT_GPIO);
}
#define SYNCS 200
typedef enum {
+ STATE_MAGIC0,
STATE_MAGIC1,
STATE_MAGIC2,
STATE_MAGIC3,
@@ -93,30 +141,49 @@ typedef enum {
STATE_SYNC2,
STATE_PACKET_HEADER,
STATE_PACKET_DATA,
- STATE_PACKET_PAD,
+ STATE_PACKET_TWO_BYTES_PER_FRAME,
STATE_PACKET_RECOVERY,
} Timex_state;
+static const uint8_t magic[5] = "Timex";
+
static int get_data (uint8_t *start, uint8_t *data)
{
- static Timex_state state = STATE_MAGIC1;
+ static Timex_state state = STATE_MAGIC0;
static unsigned len;
static unsigned pad;
-
*start = 0;
switch (state) {
+
+ case STATE_MAGIC0:
case STATE_MAGIC1:
- if (ring_empty (&timex_ring))
+ case STATE_MAGIC2:
+ case STATE_MAGIC3:
+ case STATE_MAGIC4:
+
+ if (ring_read_byte (&timex_ring, data)) {
+ state = STATE_MAGIC0;
+ return 1;
+ }
+
+ if (*data != magic [state - STATE_MAGIC0]) {
+ state = STATE_MAGIC0;
return 1;
-
+ }
+
+ state++;
+ break;
+
case STATE_IDLE:
- if (ring_empty (&timex_ring))
+ if (ring_empty (&timex_ring)) {
+ state = STATE_MAGIC0;
return 1;
+ }
state = STATE_SYNC1;
len = SYNCS;
@@ -126,27 +193,38 @@ static int get_data (uint8_t *start, uint8_t *data)
*data = 0x55;
len--;
- if (!len) state = STATE_SYNC2;
+ if (!len) {
+ len = 2;
+ state = STATE_SYNC2;
+ }
break;
case STATE_SYNC2:
*data = 0xaa;
- state = STATE_PACKET_HEADER;
+
+ len--;
+
+ if (!len)
+ state = STATE_PACKET_HEADER;
+
break;
case STATE_PACKET_HEADER:
if (ring_read_byte (&timex_ring, data)) {
/*No more data*/
- state = STATE_MAGIC1;
+ state = STATE_MAGIC0;
return 1;
}
- len = *data -1 ;
+
+ len = *data - 1 ;
+
state = STATE_PACKET_DATA;
-#ifdef PAD
- pad =(*data &1);
+
+#ifdef TWO_BYTES_PER_FRAME
+ pad = !! (*data & 1);
#else
- pad=0;
+ pad = 0;
#endif
break;
@@ -155,24 +233,24 @@ static int get_data (uint8_t *start, uint8_t *data)
len--;
if (!len) {
-#ifdef PAD
+#ifdef TWO_BYTES_PER_FRAME
len = 20;
#else
len = 10;
#endif
if (pad)
- state = STATE_PACKET_PAD;
- else
- state = STATE_PACKET_RECOVERY;
+ state = STATE_PACKET_TWO_BYTES_PER_FRAME;
+ else
+ state = STATE_PACKET_RECOVERY;
}
break;
- case STATE_PACKET_PAD:
- *data=0x00;
- state = STATE_PACKET_RECOVERY;
- break;
+ case STATE_PACKET_TWO_BYTES_PER_FRAME:
+ *data = 0x00;
+ state = STATE_PACKET_RECOVERY;
+ break;
case STATE_PACKET_RECOVERY:
@@ -196,53 +274,87 @@ void timex_tick (void)
switch (line) {
- case (SL_BYTE_1_START-2):
+ case SL_PREPARE (0):
if (get_data (&start, &data)) {
line = 0;
return;
}
+
break;
- SEND_BYTE (1, start, data);
+ SEND_BYTE (0, start, data);
+
+#ifdef TWO_BYTES_PER_FRAME
-#ifdef PAD
- case (SL_BYTE_2_START-2):
+ case SL_PREPARE (1):
if (get_data (&start, &data)) {
line = 0;
return;
}
+
break;
- SEND_BYTE (2, start, data);
+ SEND_BYTE (1, start, data);
#endif
-
-
}
-
line++;
if (line == 525)
line = 0;
}
-#ifdef EX
-uint8_t ex[]={
-#include "/root/projects/timex_datalink/datalink-1.0.1/fish.h"
+#ifdef SEND_EXAMPLE_DATA
+uint8_t ex[] = {
+ 0x07, 0x20, 0x00, 0x00, 0x01, 0xc0, 0x7f, // 0x00
+ 0x0d, 0x30, 0x02, 0x13, 0x11, 0x04, 0x1d, 0x13, 0x00, 0x2c, 0x01, 0x29, 0x56, // 0x00,
+ 0x0d, 0x30, 0x01, 0x0b, 0x11, 0x04, 0x1d, 0x13, 0x00, 0x2c, 0x01, 0x73, 0x42, // 0x00,
+ 0x05, 0x60, 0x03, 0x00, 0x78, // 0x00,
+ 0x20, 0x61, 0x01, 0x00, 0x0e, 0x00, 0x1b, 0x00, 0x26, 0x00, 0x39, 0x01, 0x01, 0x01, 0x01, 0x13,
+ /**/ 0x03, 0x0d, 0x05, 0x05, 0x28, 0x9c, 0x62, 0x65, 0x95, 0x43, 0x2a, 0x59, 0xd6, 0xfd, 0x38, 0xc2,
+ 0x20, 0x61, 0x02, 0x0b, 0x01, 0x9c, 0x62, 0x65, 0x95, 0x43, 0x76, 0x0a, 0x47, 0xfd, 0x13, 0x04,
+ /**/ 0x54, 0x55, 0x55, 0x55, 0xcf, 0x8b, 0xb7, 0x35, 0x4e, 0x55, 0x91, 0x90, 0x83, 0x6d, 0xb6, 0x6a,
+ 0x17, 0x61, 0x03, 0x90, 0xf3, 0x03, 0x0f, 0x05, 0x01, 0x9c, 0x62, 0x65, 0x95, 0x43, 0x2e, 0xd2,
+ /**/ 0xd6, 0x45, 0x8d, 0x22, 0xfe, 0xd4, 0x6e, // 0x00,
+ 0x04, 0x62, 0x29, 0x83,
+ 0x08, 0x31, 0x01, 0x15, 0x18, 0x17, 0xba, 0x26,
+ 0x08, 0x31, 0x02, 0x11, 0x17, 0x10, 0x0d, 0x23,
+ 0x12, 0x50, 0x01, 0x09, 0x00, 0x00, 0x00, 0x1c, 0x0a, 0x16, 0x19, 0x15, 0x0e, 0x24, 0x24, 0x01,
+ /**/ 0x0e, 0x39,
+ 0x12, 0x50, 0x02, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x0a, 0x1b, 0x16, 0x24, 0x27, 0x02, 0x00,
+ /**/ 0x73, 0x3b,
+ 0x07, 0x70, 0x00, 0x63, 0x00, 0xf0, 0x87, // 0x00,
+ 0x12, 0x50, 0x03, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x0a, 0x1b, 0x16, 0x24, 0x27, 0x03, 0x00,
+ /**/ 0x22, 0x3a,
+ 0x07, 0x70, 0x00, 0x64, 0x00, 0xc0, 0x85, // 0x00,
+ 0x12, 0x50, 0x04, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x0a, 0x1b, 0x16, 0x24, 0x27, 0x04, 0x00,
+ /**/ 0xd5, 0x3e,
+ 0x07, 0x70, 0x00, 0x65, 0x00, 0x50, 0x84, // 0x00,
+ 0x12, 0x50, 0x05, 0x00, 0x00, 0x00, 0x00, 0x0a, 0x15, 0x0a, 0x1b, 0x16, 0x24, 0x27, 0x05, 0x00,
+ /**/ 0x84, 0x3f,
+ 0x07, 0x70, 0x00, 0x66, 0x00, 0xa0, 0x84, // 0x00,
+ 0x04, 0x21, 0xd8, 0xc2,
};
+
+static void send_example_data (void)
+{
+ ring_write (&timex_ring, magic, sizeof (magic));
+ ring_write (&timex_ring, ex, sizeof (ex));
+}
+
#endif
-
+
void
timex_init (void)
{
ring_init (&timex_ring, timex_ring_buf, sizeof (timex_ring_buf));
-#ifdef EX
- ring_write(&timex_ring,ex,sizeof(ex));
+#ifdef SEND_EXAMPLE_DATA
+ send_example_data();
#endif
- gpio_set_mode (TIMEX_BANK, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, TIMEX_GPIO);
-
+ gpio_set_mode (TIMEX_INPUT_BANK, GPIO_MODE_INPUT, GPIO_CNF_INPUT_FLOAT, TIMEX_INPUT_GPIO);
+ gpio_set_mode (TIMEX_OUTPUT_BANK, GPIO_MODE_OUTPUT_2_MHZ, GPIO_CNF_OUTPUT_OPENDRAIN, TIMEX_OUTPUT_GPIO);
timex_led (1);
}