aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorjaseg <git@jaseg.net>2018-12-23 12:57:40 +0900
committerjaseg <git@jaseg.net>2018-12-23 12:57:40 +0900
commit62389e00fed49b7b89f465c9cd6bb586502331be (patch)
treee38348acaef07b595459057422ee6d92f8cea9c8
parent468fe59d9747078830dd489668b8c8ee8520b4a5 (diff)
download8seg-62389e00fed49b7b89f465c9cd6bb586502331be.tar.gz
8seg-62389e00fed49b7b89f465c9cd6bb586502331be.tar.bz2
8seg-62389e00fed49b7b89f465c9cd6bb586502331be.zip
ADC working
-rw-r--r--common/.gitignore12
-rw-r--r--common/8b10b.c (renamed from fw/8b10b.c)7
-rw-r--r--common/8b10b.h (renamed from fw/8b10b.h)3
-rw-r--r--common/8b10b.pp1549
-rw-r--r--common/8b10b_test_decode.c (renamed from fw/8b10b_test_decode.c)0
-rw-r--r--common/8b10b_test_encode.c (renamed from fw/8b10b_test_encode.c)0
-rwxr-xr-xcommon/8b10b_test_vector_gen.py (renamed from fw/8b10b_test_vector_gen.py)0
-rw-r--r--common/Makefile27
-rw-r--r--driver_fw/Makefile6
-rw-r--r--driver_fw/main.c96
-rw-r--r--fw/Makefile6
-rw-r--r--fw/adc.c118
-rw-r--r--fw/adc.h36
-rw-r--r--fw/cmsis_exports.c48
-rw-r--r--fw/main.c36
15 files changed, 1898 insertions, 46 deletions
diff --git a/common/.gitignore b/common/.gitignore
new file mode 100644
index 0000000..ed41bfa
--- /dev/null
+++ b/common/.gitignore
@@ -0,0 +1,12 @@
+*.elf
+*.o
+*.expand
+*.hex
+*.lst
+*.map
+*.bin
+sources.c
+sources.tar.xz
+sources.tar.xz.zip
+8b10b_test_decode
+8b10b_test_encode
diff --git a/fw/8b10b.c b/common/8b10b.c
index c5a52ca..a32b7f2 100644
--- a/fw/8b10b.c
+++ b/common/8b10b.c
@@ -4,6 +4,9 @@
#include "8b10b.h"
+/* Ignore warnings about some of the following arrays being unused. They will be removed by the linker. I want to keep
+ * them here for future reference. */
+#pragma GCC diagnostic ignored "-Wunused-const-variable=0"
static const struct entry map_5b6b[32] = {
{0b100111, 0b011000, 2}, /* D.00 */
{0b011101, 0b100010, 2}, /* D.01 */
@@ -212,7 +215,7 @@ int xfr_8b10b_encode(struct state_8b10b_enc *st, int data) {
int x5b = (st->rd == -1) ? map_5b6b[p5b].rd_neg : map_5b6b[p5b].rd_pos;
st->rd -= map_5b6b[p5b].disp * st->rd;
//fprintf(stderr, "\nnow: rd %d data %x p5b %d p3b %d\n", st->rd, data, p5b, p3b);
- assert(st->rd == -1 || st->rd == 1);
+ //assert(st->rd == -1 || st->rd == 1);
int x3b = (st->rd == -1) ? map_3b4b_d[p3b].rd_neg : map_3b4b_d[p3b].rd_pos;
if (p3b == 7) {
@@ -223,7 +226,7 @@ int xfr_8b10b_encode(struct state_8b10b_enc *st, int data) {
}
}
st->rd -= map_3b4b_d[p3b].disp * st->rd; /* D.x.A7 and D.x.P7 both have parity 2 */
- assert(st->rd == -1 || st->rd == 1);
+ //assert(st->rd == -1 || st->rd == 1);
return x5b<<4 | x3b;
}
diff --git a/fw/8b10b.h b/common/8b10b.h
index 090faaf..1028210 100644
--- a/fw/8b10b.h
+++ b/common/8b10b.h
@@ -15,7 +15,8 @@ enum k_code {
enum decoder_return_codes {
_K_CODES_LAST = K_CODES_LAST,
DECODING_ERROR,
- DECODING_IN_PROGRESS
+ DECODING_IN_PROGRESS,
+ DECODER_RETURN_CODE_LAST
};
struct entry {
diff --git a/common/8b10b.pp b/common/8b10b.pp
new file mode 100644
index 0000000..a111fdd
--- /dev/null
+++ b/common/8b10b.pp
@@ -0,0 +1,1549 @@
+# 1 "../common/8b10b.c"
+# 1 "/home/user/toys/led_tape_display/driver_fw//"
+# 1 "<built-in>"
+# 1 "<command-line>"
+# 1 "../common/8b10b.c"
+
+# 1 "/usr/arm-none-eabi/include/assert.h" 1 3
+# 9 "/usr/arm-none-eabi/include/assert.h" 3
+# 1 "/usr/arm-none-eabi/include/_ansi.h" 1 3
+# 15 "/usr/arm-none-eabi/include/_ansi.h" 3
+# 1 "/usr/arm-none-eabi/include/newlib.h" 1 3
+# 14 "/usr/arm-none-eabi/include/newlib.h" 3
+# 1 "/usr/arm-none-eabi/include/_newlib_version.h" 1 3
+# 15 "/usr/arm-none-eabi/include/newlib.h" 2 3
+# 16 "/usr/arm-none-eabi/include/_ansi.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/config.h" 1 3
+
+
+
+# 1 "/usr/arm-none-eabi/include/machine/ieeefp.h" 1 3
+# 5 "/usr/arm-none-eabi/include/sys/config.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/features.h" 1 3
+# 6 "/usr/arm-none-eabi/include/sys/config.h" 2 3
+# 17 "/usr/arm-none-eabi/include/_ansi.h" 2 3
+# 10 "/usr/arm-none-eabi/include/assert.h" 2 3
+# 39 "/usr/arm-none-eabi/include/assert.h" 3
+
+# 39 "/usr/arm-none-eabi/include/assert.h" 3
+void __assert (const char *, int, const char *) __attribute__ ((__noreturn__))
+ ;
+void __assert_func (const char *, int, const char *, const char *) __attribute__ ((__noreturn__))
+ ;
+# 3 "../common/8b10b.c" 2
+# 1 "/usr/arm-none-eabi/include/stdio.h" 1 3
+# 35 "/usr/arm-none-eabi/include/stdio.h" 3
+# 1 "/usr/arm-none-eabi/include/sys/cdefs.h" 1 3
+# 43 "/usr/arm-none-eabi/include/sys/cdefs.h" 3
+# 1 "/usr/arm-none-eabi/include/machine/_default_types.h" 1 3
+# 41 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef signed char __int8_t;
+
+typedef unsigned char __uint8_t;
+# 55 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef short int __int16_t;
+
+typedef short unsigned int __uint16_t;
+# 77 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef long int __int32_t;
+
+typedef long unsigned int __uint32_t;
+# 103 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef long long int __int64_t;
+
+typedef long long unsigned int __uint64_t;
+# 134 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef signed char __int_least8_t;
+
+typedef unsigned char __uint_least8_t;
+# 160 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef short int __int_least16_t;
+
+typedef short unsigned int __uint_least16_t;
+# 182 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef long int __int_least32_t;
+
+typedef long unsigned int __uint_least32_t;
+# 200 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef long long int __int_least64_t;
+
+typedef long long unsigned int __uint_least64_t;
+# 214 "/usr/arm-none-eabi/include/machine/_default_types.h" 3
+typedef long long int __intmax_t;
+
+
+
+
+
+
+
+typedef long long unsigned int __uintmax_t;
+
+
+
+
+
+
+
+typedef int __intptr_t;
+
+typedef unsigned int __uintptr_t;
+# 44 "/usr/arm-none-eabi/include/sys/cdefs.h" 2 3
+
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 1 3 4
+# 216 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+typedef unsigned int size_t;
+# 46 "/usr/arm-none-eabi/include/sys/cdefs.h" 2 3
+# 36 "/usr/arm-none-eabi/include/stdio.h" 2 3
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 1 3 4
+# 149 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+typedef int ptrdiff_t;
+# 328 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+typedef unsigned int wchar_t;
+# 426 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+typedef struct {
+ long long __max_align_ll __attribute__((__aligned__(__alignof__(long long))));
+ long double __max_align_ld __attribute__((__aligned__(__alignof__(long double))));
+# 437 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+} max_align_t;
+# 37 "/usr/arm-none-eabi/include/stdio.h" 2 3
+
+
+
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdarg.h" 1 3 4
+# 40 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdarg.h" 3 4
+typedef __builtin_va_list __gnuc_va_list;
+# 41 "/usr/arm-none-eabi/include/stdio.h" 2 3
+
+
+
+
+
+typedef __gnuc_va_list va_list;
+# 60 "/usr/arm-none-eabi/include/stdio.h" 3
+# 1 "/usr/arm-none-eabi/include/sys/reent.h" 1 3
+# 13 "/usr/arm-none-eabi/include/sys/reent.h" 3
+# 1 "/usr/arm-none-eabi/include/_ansi.h" 1 3
+# 14 "/usr/arm-none-eabi/include/sys/reent.h" 2 3
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 1 3 4
+# 15 "/usr/arm-none-eabi/include/sys/reent.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/_types.h" 1 3
+# 24 "/usr/arm-none-eabi/include/sys/_types.h" 3
+# 1 "/usr/arm-none-eabi/include/machine/_types.h" 1 3
+# 25 "/usr/arm-none-eabi/include/sys/_types.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/lock.h" 1 3
+
+
+
+
+
+typedef int _LOCK_T;
+typedef int _LOCK_RECURSIVE_T;
+# 26 "/usr/arm-none-eabi/include/sys/_types.h" 2 3
+
+
+typedef long __blkcnt_t;
+
+
+
+typedef long __blksize_t;
+
+
+
+typedef __uint64_t __fsblkcnt_t;
+
+
+
+typedef __uint32_t __fsfilcnt_t;
+
+
+
+typedef long _off_t;
+
+
+
+
+
+typedef int __pid_t;
+
+
+
+typedef short __dev_t;
+
+
+
+typedef unsigned short __uid_t;
+
+
+typedef unsigned short __gid_t;
+
+
+
+typedef __uint32_t __id_t;
+
+
+
+
+
+
+
+typedef unsigned short __ino_t;
+# 88 "/usr/arm-none-eabi/include/sys/_types.h" 3
+typedef __uint32_t __mode_t;
+
+
+
+
+
+__extension__ typedef long long _off64_t;
+
+
+
+
+
+typedef _off_t __off_t;
+
+
+typedef _off64_t __loff_t;
+
+
+typedef long __key_t;
+
+
+
+
+
+
+
+typedef long _fpos_t;
+# 129 "/usr/arm-none-eabi/include/sys/_types.h" 3
+typedef unsigned int __size_t;
+# 145 "/usr/arm-none-eabi/include/sys/_types.h" 3
+typedef signed int _ssize_t;
+# 156 "/usr/arm-none-eabi/include/sys/_types.h" 3
+typedef _ssize_t __ssize_t;
+
+
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 1 3 4
+# 357 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 3 4
+typedef unsigned int wint_t;
+# 160 "/usr/arm-none-eabi/include/sys/_types.h" 2 3
+
+
+
+typedef struct
+{
+ int __count;
+ union
+ {
+ wint_t __wch;
+ unsigned char __wchb[4];
+ } __value;
+} _mbstate_t;
+
+
+
+typedef _LOCK_RECURSIVE_T _flock_t;
+
+
+
+
+typedef void *_iconv_t;
+
+
+
+typedef unsigned long __clock_t;
+
+
+typedef long __time_t;
+
+
+typedef unsigned long __clockid_t;
+
+
+typedef unsigned long __timer_t;
+
+
+typedef __uint8_t __sa_family_t;
+
+
+
+typedef __uint32_t __socklen_t;
+
+
+typedef unsigned short __nlink_t;
+typedef long __suseconds_t;
+typedef unsigned long __useconds_t;
+
+
+typedef __builtin_va_list __va_list;
+# 16 "/usr/arm-none-eabi/include/sys/reent.h" 2 3
+
+
+
+
+
+
+typedef unsigned long __ULong;
+# 38 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct _reent;
+
+struct __locale_t;
+
+
+
+
+
+
+struct _Bigint
+{
+ struct _Bigint *_next;
+ int _k, _maxwds, _sign, _wds;
+ __ULong _x[1];
+};
+
+
+struct __tm
+{
+ int __tm_sec;
+ int __tm_min;
+ int __tm_hour;
+ int __tm_mday;
+ int __tm_mon;
+ int __tm_year;
+ int __tm_wday;
+ int __tm_yday;
+ int __tm_isdst;
+};
+
+
+
+
+
+
+
+struct _on_exit_args {
+ void * _fnargs[32];
+ void * _dso_handle[32];
+
+ __ULong _fntypes;
+
+
+ __ULong _is_cxa;
+};
+# 93 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct _atexit {
+ struct _atexit *_next;
+ int _ind;
+
+ void (*_fns[32])(void);
+ struct _on_exit_args _on_exit_args;
+};
+# 117 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct __sbuf {
+ unsigned char *_base;
+ int _size;
+};
+# 181 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct __sFILE {
+ unsigned char *_p;
+ int _r;
+ int _w;
+ short _flags;
+ short _file;
+ struct __sbuf _bf;
+ int _lbfsize;
+
+
+
+
+
+
+ void * _cookie;
+
+ int (* _read) (struct _reent *, void *, char *, int)
+ ;
+ int (* _write) (struct _reent *, void *, const char *, int)
+
+ ;
+ _fpos_t (* _seek) (struct _reent *, void *, _fpos_t, int);
+ int (* _close) (struct _reent *, void *);
+
+
+ struct __sbuf _ub;
+ unsigned char *_up;
+ int _ur;
+
+
+ unsigned char _ubuf[3];
+ unsigned char _nbuf[1];
+
+
+ struct __sbuf _lb;
+
+
+ int _blksize;
+ _off_t _offset;
+
+
+ struct _reent *_data;
+
+
+
+ _flock_t _lock;
+
+ _mbstate_t _mbstate;
+ int _flags2;
+};
+# 287 "/usr/arm-none-eabi/include/sys/reent.h" 3
+typedef struct __sFILE __FILE;
+
+
+
+struct _glue
+{
+ struct _glue *_next;
+ int _niobs;
+ __FILE *_iobs;
+};
+# 319 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct _rand48 {
+ unsigned short _seed[3];
+ unsigned short _mult[3];
+ unsigned short _add;
+
+
+
+
+};
+# 569 "/usr/arm-none-eabi/include/sys/reent.h" 3
+struct _reent
+{
+ int _errno;
+
+
+
+
+ __FILE *_stdin, *_stdout, *_stderr;
+
+ int _inc;
+ char _emergency[25];
+
+
+ int _unspecified_locale_info;
+ struct __locale_t *_locale;
+
+ int __sdidinit;
+
+ void (* __cleanup) (struct _reent *);
+
+
+ struct _Bigint *_result;
+ int _result_k;
+ struct _Bigint *_p5s;
+ struct _Bigint **_freelist;
+
+
+ int _cvtlen;
+ char *_cvtbuf;
+
+ union
+ {
+ struct
+ {
+ unsigned int _unused_rand;
+ char * _strtok_last;
+ char _asctime_buf[26];
+ struct __tm _localtime_buf;
+ int _gamma_signgam;
+ __extension__ unsigned long long _rand_next;
+ struct _rand48 _r48;
+ _mbstate_t _mblen_state;
+ _mbstate_t _mbtowc_state;
+ _mbstate_t _wctomb_state;
+ char _l64a_buf[8];
+ char _signal_buf[24];
+ int _getdate_err;
+ _mbstate_t _mbrlen_state;
+ _mbstate_t _mbrtowc_state;
+ _mbstate_t _mbsrtowcs_state;
+ _mbstate_t _wcrtomb_state;
+ _mbstate_t _wcsrtombs_state;
+ int _h_errno;
+ } _reent;
+
+
+
+ struct
+ {
+
+ unsigned char * _nextf[30];
+ unsigned int _nmalloc[30];
+ } _unused;
+ } _new;
+
+
+
+ struct _atexit *_atexit;
+ struct _atexit _atexit0;
+
+
+
+ void (**(_sig_func))(int);
+
+
+
+
+ struct _glue __sglue;
+ __FILE __sf[3];
+};
+# 766 "/usr/arm-none-eabi/include/sys/reent.h" 3
+extern struct _reent *_impure_ptr ;
+extern struct _reent *const _global_impure_ptr ;
+
+void _reclaim_reent (struct _reent *);
+# 61 "/usr/arm-none-eabi/include/stdio.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/types.h" 1 3
+# 28 "/usr/arm-none-eabi/include/sys/types.h" 3
+typedef __uint8_t u_int8_t;
+
+
+typedef __uint16_t u_int16_t;
+
+
+typedef __uint32_t u_int32_t;
+
+
+typedef __uint64_t u_int64_t;
+
+typedef int register_t;
+# 62 "/usr/arm-none-eabi/include/sys/types.h" 3
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stddef.h" 1 3 4
+# 63 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+
+# 1 "/usr/arm-none-eabi/include/sys/_stdint.h" 1 3
+# 20 "/usr/arm-none-eabi/include/sys/_stdint.h" 3
+typedef __int8_t int8_t ;
+
+
+
+typedef __uint8_t uint8_t ;
+
+
+
+
+
+
+
+typedef __int16_t int16_t ;
+
+
+
+typedef __uint16_t uint16_t ;
+
+
+
+
+
+
+
+typedef __int32_t int32_t ;
+
+
+
+typedef __uint32_t uint32_t ;
+
+
+
+
+
+
+
+typedef __int64_t int64_t ;
+
+
+
+typedef __uint64_t uint64_t ;
+
+
+
+
+
+
+typedef __intmax_t intmax_t;
+
+
+
+
+typedef __uintmax_t uintmax_t;
+
+
+
+
+typedef __intptr_t intptr_t;
+
+
+
+
+typedef __uintptr_t uintptr_t;
+# 65 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+
+
+# 1 "/usr/arm-none-eabi/include/machine/endian.h" 1 3
+
+
+
+
+
+# 1 "/usr/arm-none-eabi/include/machine/_endian.h" 1 3
+# 7 "/usr/arm-none-eabi/include/machine/endian.h" 2 3
+# 68 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/select.h" 1 3
+# 25 "/usr/arm-none-eabi/include/sys/select.h" 3
+# 1 "/usr/arm-none-eabi/include/sys/_sigset.h" 1 3
+# 41 "/usr/arm-none-eabi/include/sys/_sigset.h" 3
+typedef unsigned long __sigset_t;
+# 26 "/usr/arm-none-eabi/include/sys/select.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/_timeval.h" 1 3
+# 35 "/usr/arm-none-eabi/include/sys/_timeval.h" 3
+typedef __suseconds_t suseconds_t;
+
+
+
+
+typedef long time_t;
+# 52 "/usr/arm-none-eabi/include/sys/_timeval.h" 3
+struct timeval {
+ time_t tv_sec;
+ suseconds_t tv_usec;
+};
+# 27 "/usr/arm-none-eabi/include/sys/select.h" 2 3
+# 1 "/usr/arm-none-eabi/include/sys/timespec.h" 1 3
+# 38 "/usr/arm-none-eabi/include/sys/timespec.h" 3
+# 1 "/usr/arm-none-eabi/include/sys/_timespec.h" 1 3
+# 45 "/usr/arm-none-eabi/include/sys/_timespec.h" 3
+struct timespec {
+ time_t tv_sec;
+ long tv_nsec;
+};
+# 39 "/usr/arm-none-eabi/include/sys/timespec.h" 2 3
+# 58 "/usr/arm-none-eabi/include/sys/timespec.h" 3
+struct itimerspec {
+ struct timespec it_interval;
+ struct timespec it_value;
+};
+# 28 "/usr/arm-none-eabi/include/sys/select.h" 2 3
+
+
+
+typedef __sigset_t sigset_t;
+# 45 "/usr/arm-none-eabi/include/sys/select.h" 3
+typedef unsigned long fd_mask;
+
+
+
+
+
+
+
+typedef struct _types_fd_set {
+ fd_mask fds_bits[(((64)+(((sizeof (fd_mask) * 8))-1))/((sizeof (fd_mask) * 8)))];
+} _types_fd_set;
+# 71 "/usr/arm-none-eabi/include/sys/select.h" 3
+
+
+int select (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, struct timeval *__timeout)
+ ;
+
+int pselect (int __n, _types_fd_set *__readfds, _types_fd_set *__writefds, _types_fd_set *__exceptfds, const struct timespec *__timeout, const sigset_t *__set)
+
+ ;
+
+
+
+# 69 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+
+
+
+
+typedef __uint32_t in_addr_t;
+
+
+
+
+typedef __uint16_t in_port_t;
+# 87 "/usr/arm-none-eabi/include/sys/types.h" 3
+typedef unsigned char u_char;
+
+
+
+typedef unsigned short u_short;
+
+
+
+typedef unsigned int u_int;
+
+
+
+typedef unsigned long u_long;
+
+
+
+
+
+
+
+typedef unsigned short ushort;
+typedef unsigned int uint;
+typedef unsigned long ulong;
+
+
+
+typedef __blkcnt_t blkcnt_t;
+
+
+
+
+typedef __blksize_t blksize_t;
+
+
+
+
+typedef unsigned long clock_t;
+# 135 "/usr/arm-none-eabi/include/sys/types.h" 3
+typedef long daddr_t;
+
+
+
+typedef char * caddr_t;
+
+
+
+
+typedef __fsblkcnt_t fsblkcnt_t;
+typedef __fsfilcnt_t fsfilcnt_t;
+
+
+
+
+typedef __id_t id_t;
+
+
+
+
+typedef __ino_t ino_t;
+# 173 "/usr/arm-none-eabi/include/sys/types.h" 3
+typedef __off_t off_t;
+
+
+
+typedef __dev_t dev_t;
+
+
+
+typedef __uid_t uid_t;
+
+
+
+typedef __gid_t gid_t;
+
+
+
+
+typedef __pid_t pid_t;
+
+
+
+
+typedef __key_t key_t;
+
+
+
+
+typedef _ssize_t ssize_t;
+
+
+
+
+typedef __mode_t mode_t;
+
+
+
+
+typedef __nlink_t nlink_t;
+
+
+
+
+typedef __clockid_t clockid_t;
+
+
+
+
+
+typedef __timer_t timer_t;
+
+
+
+
+
+typedef __useconds_t useconds_t;
+# 236 "/usr/arm-none-eabi/include/sys/types.h" 3
+typedef __int64_t sbintime_t;
+
+
+# 1 "/usr/arm-none-eabi/include/sys/_pthreadtypes.h" 1 3
+# 240 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+# 1 "/usr/arm-none-eabi/include/machine/types.h" 1 3
+# 241 "/usr/arm-none-eabi/include/sys/types.h" 2 3
+# 62 "/usr/arm-none-eabi/include/stdio.h" 2 3
+
+
+
+
+typedef __FILE FILE;
+
+
+
+
+
+
+typedef _fpos_t fpos_t;
+
+
+
+
+
+# 1 "/usr/arm-none-eabi/include/sys/stdio.h" 1 3
+# 80 "/usr/arm-none-eabi/include/stdio.h" 2 3
+# 181 "/usr/arm-none-eabi/include/stdio.h" 3
+char * ctermid (char *);
+
+
+
+
+FILE * tmpfile (void);
+char * tmpnam (char *);
+
+char * tempnam (const char *, const char *);
+
+int fclose (FILE *);
+int fflush (FILE *);
+FILE * freopen (const char *restrict, const char *restrict, FILE *restrict);
+void setbuf (FILE *restrict, char *restrict);
+int setvbuf (FILE *restrict, char *restrict, int, size_t);
+int fprintf (FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int fscanf (FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+int printf (const char *restrict, ...) __attribute__ ((__format__ (__printf__, 1, 2)))
+ ;
+int scanf (const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 1, 2)))
+ ;
+int sscanf (const char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+int vfprintf (FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int vprintf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 1, 0)))
+ ;
+int vsprintf (char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int fgetc (FILE *);
+char * fgets (char *restrict, int, FILE *restrict);
+int fputc (int, FILE *);
+int fputs (const char *restrict, FILE *restrict);
+int getc (FILE *);
+int getchar (void);
+char * gets (char *);
+int putc (int, FILE *);
+int putchar (int);
+int puts (const char *);
+int ungetc (int, FILE *);
+size_t fread (void * restrict, size_t _size, size_t _n, FILE *restrict);
+size_t fwrite (const void * restrict , size_t _size, size_t _n, FILE *);
+
+
+
+int fgetpos (FILE *restrict, fpos_t *restrict);
+
+int fseek (FILE *, long, int);
+
+
+
+int fsetpos (FILE *, const fpos_t *);
+
+long ftell ( FILE *);
+void rewind (FILE *);
+void clearerr (FILE *);
+int feof (FILE *);
+int ferror (FILE *);
+void perror (const char *);
+
+FILE * fopen (const char *restrict _name, const char *restrict _type);
+int sprintf (char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int remove (const char *);
+int rename (const char *, const char *);
+# 257 "/usr/arm-none-eabi/include/stdio.h" 3
+int fseeko (FILE *, off_t, int);
+off_t ftello ( FILE *);
+
+
+
+
+
+
+
+int snprintf (char *restrict, size_t, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int vsnprintf (char *restrict, size_t, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int vfscanf (FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+int vscanf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 1, 0)))
+ ;
+int vsscanf (const char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+# 284 "/usr/arm-none-eabi/include/stdio.h" 3
+int asiprintf (char **, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+char * asniprintf (char *, size_t *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+char * asnprintf (char *restrict, size_t *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+
+int diprintf (int, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+
+int fiprintf (FILE *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int fiscanf (FILE *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+int iprintf (const char *, ...) __attribute__ ((__format__ (__printf__, 1, 2)))
+ ;
+int iscanf (const char *, ...) __attribute__ ((__format__ (__scanf__, 1, 2)))
+ ;
+int siprintf (char *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int siscanf (const char *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+int sniprintf (char *, size_t, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int vasiprintf (char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+char * vasniprintf (char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+char * vasnprintf (char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int vdiprintf (int, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int vfiprintf (FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int vfiscanf (FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+int viprintf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 1, 0)))
+ ;
+int viscanf (const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 1, 0)))
+ ;
+int vsiprintf (char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int vsiscanf (const char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+int vsniprintf (char *, size_t, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+# 339 "/usr/arm-none-eabi/include/stdio.h" 3
+FILE * fdopen (int, const char *);
+
+int fileno (FILE *);
+
+
+int pclose (FILE *);
+FILE * popen (const char *, const char *);
+
+
+
+void setbuffer (FILE *, char *, int);
+int setlinebuf (FILE *);
+
+
+
+int getw (FILE *);
+int putw (int, FILE *);
+
+
+int getc_unlocked (FILE *);
+int getchar_unlocked (void);
+void flockfile (FILE *);
+int ftrylockfile (FILE *);
+void funlockfile (FILE *);
+int putc_unlocked (int, FILE *);
+int putchar_unlocked (int);
+# 374 "/usr/arm-none-eabi/include/stdio.h" 3
+int dprintf (int, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+
+FILE * fmemopen (void *restrict, size_t, const char *restrict);
+
+
+FILE * open_memstream (char **, size_t *);
+int vdprintf (int, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+
+
+
+int renameat (int, const char *, int, const char *);
+
+
+
+
+
+
+int _asiprintf_r (struct _reent *, char **, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
+ ;
+char * _asnprintf_r (struct _reent *, char *restrict, size_t *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
+ ;
+int _asprintf_r (struct _reent *, char **restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _diprintf_r (struct _reent *, int, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _dprintf_r (struct _reent *, int, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _fclose_r (struct _reent *, FILE *);
+int _fcloseall_r (struct _reent *);
+FILE * _fdopen_r (struct _reent *, int, const char *);
+int _fflush_r (struct _reent *, FILE *);
+int _fgetc_r (struct _reent *, FILE *);
+int _fgetc_unlocked_r (struct _reent *, FILE *);
+char * _fgets_r (struct _reent *, char *restrict, int, FILE *restrict);
+char * _fgets_unlocked_r (struct _reent *, char *restrict, int, FILE *restrict);
+
+
+
+
+int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
+int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
+
+int _fiprintf_r (struct _reent *, FILE *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _fiscanf_r (struct _reent *, FILE *, const char *, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
+ ;
+FILE * _fmemopen_r (struct _reent *, void *restrict, size_t, const char *restrict);
+FILE * _fopen_r (struct _reent *, const char *restrict, const char *restrict);
+FILE * _freopen_r (struct _reent *, const char *restrict, const char *restrict, FILE *restrict);
+int _fprintf_r (struct _reent *, FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _fpurge_r (struct _reent *, FILE *);
+int _fputc_r (struct _reent *, int, FILE *);
+int _fputc_unlocked_r (struct _reent *, int, FILE *);
+int _fputs_r (struct _reent *, const char *restrict, FILE *restrict);
+int _fputs_unlocked_r (struct _reent *, const char *restrict, FILE *restrict);
+size_t _fread_r (struct _reent *, void * restrict, size_t _size, size_t _n, FILE *restrict);
+size_t _fread_unlocked_r (struct _reent *, void * restrict, size_t _size, size_t _n, FILE *restrict);
+int _fscanf_r (struct _reent *, FILE *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
+ ;
+int _fseek_r (struct _reent *, FILE *, long, int);
+int _fseeko_r (struct _reent *, FILE *, _off_t, int);
+long _ftell_r (struct _reent *, FILE *);
+_off_t _ftello_r (struct _reent *, FILE *);
+void _rewind_r (struct _reent *, FILE *);
+size_t _fwrite_r (struct _reent *, const void * restrict, size_t _size, size_t _n, FILE *restrict);
+size_t _fwrite_unlocked_r (struct _reent *, const void * restrict, size_t _size, size_t _n, FILE *restrict);
+int _getc_r (struct _reent *, FILE *);
+int _getc_unlocked_r (struct _reent *, FILE *);
+int _getchar_r (struct _reent *);
+int _getchar_unlocked_r (struct _reent *);
+char * _gets_r (struct _reent *, char *);
+int _iprintf_r (struct _reent *, const char *, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int _iscanf_r (struct _reent *, const char *, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+FILE * _open_memstream_r (struct _reent *, char **, size_t *);
+void _perror_r (struct _reent *, const char *);
+int _printf_r (struct _reent *, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 2, 3)))
+ ;
+int _putc_r (struct _reent *, int, FILE *);
+int _putc_unlocked_r (struct _reent *, int, FILE *);
+int _putchar_unlocked_r (struct _reent *, int);
+int _putchar_r (struct _reent *, int);
+int _puts_r (struct _reent *, const char *);
+int _remove_r (struct _reent *, const char *);
+int _rename_r (struct _reent *, const char *_old, const char *_new)
+ ;
+int _scanf_r (struct _reent *, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 2, 3)))
+ ;
+int _siprintf_r (struct _reent *, char *, const char *, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _siscanf_r (struct _reent *, const char *, const char *, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
+ ;
+int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
+ ;
+int _snprintf_r (struct _reent *, char *restrict, size_t, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 4, 5)))
+ ;
+int _sprintf_r (struct _reent *, char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__printf__, 3, 4)))
+ ;
+int _sscanf_r (struct _reent *, const char *restrict, const char *restrict, ...) __attribute__ ((__format__ (__scanf__, 3, 4)))
+ ;
+char * _tempnam_r (struct _reent *, const char *, const char *);
+FILE * _tmpfile_r (struct _reent *);
+char * _tmpnam_r (struct _reent *, char *);
+int _ungetc_r (struct _reent *, int, FILE *);
+int _vasiprintf_r (struct _reent *, char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
+ ;
+char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
+ ;
+int _vasprintf_r (struct _reent *, char **, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vdiprintf_r (struct _reent *, int, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vdprintf_r (struct _reent *, int, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vfiprintf_r (struct _reent *, FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vfiscanf_r (struct _reent *, FILE *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
+ ;
+int _vfprintf_r (struct _reent *, FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vfscanf_r (struct _reent *, FILE *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
+ ;
+int _viprintf_r (struct _reent *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int _viscanf_r (struct _reent *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+int _vprintf_r (struct _reent *, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 2, 0)))
+ ;
+int _vscanf_r (struct _reent *, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 2, 0)))
+ ;
+int _vsiprintf_r (struct _reent *, char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vsiscanf_r (struct _reent *, const char *, const char *, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
+ ;
+int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
+ ;
+int _vsnprintf_r (struct _reent *, char *restrict, size_t, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 4, 0)))
+ ;
+int _vsprintf_r (struct _reent *, char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__printf__, 3, 0)))
+ ;
+int _vsscanf_r (struct _reent *, const char *restrict, const char *restrict, __gnuc_va_list) __attribute__ ((__format__ (__scanf__, 3, 0)))
+ ;
+
+
+
+int fpurge (FILE *);
+ssize_t __getdelim (char **, size_t *, int, FILE *);
+ssize_t __getline (char **, size_t *, FILE *);
+
+
+void clearerr_unlocked (FILE *);
+int feof_unlocked (FILE *);
+int ferror_unlocked (FILE *);
+int fileno_unlocked (FILE *);
+int fflush_unlocked (FILE *);
+int fgetc_unlocked (FILE *);
+int fputc_unlocked (int, FILE *);
+size_t fread_unlocked (void * restrict, size_t _size, size_t _n, FILE *restrict);
+size_t fwrite_unlocked (const void * restrict , size_t _size, size_t _n, FILE *);
+# 574 "/usr/arm-none-eabi/include/stdio.h" 3
+int __srget_r (struct _reent *, FILE *);
+int __swbuf_r (struct _reent *, int, FILE *);
+# 598 "/usr/arm-none-eabi/include/stdio.h" 3
+FILE *funopen (const void * __cookie, int (*__readfn)(void * __cookie, char *__buf, int __n), int (*__writefn)(void * __cookie, const char *__buf, int __n), fpos_t (*__seekfn)(void * __cookie, fpos_t __off, int __whence), int (*__closefn)(void * __cookie))
+
+
+
+
+
+ ;
+FILE *_funopen_r (struct _reent *, const void * __cookie, int (*__readfn)(void * __cookie, char *__buf, int __n), int (*__writefn)(void * __cookie, const char *__buf, int __n), fpos_t (*__seekfn)(void * __cookie, fpos_t __off, int __whence), int (*__closefn)(void * __cookie))
+
+
+
+
+
+ ;
+# 684 "/usr/arm-none-eabi/include/stdio.h" 3
+static __inline__ int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
+
+
+
+
+ if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
+ return (*_p->_p++ = _c);
+ else
+ return (__swbuf_r(_ptr, _c, _p));
+}
+# 767 "/usr/arm-none-eabi/include/stdio.h" 3
+
+# 4 "../common/8b10b.c" 2
+
+# 1 "../common/8b10b.h" 1
+
+
+
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdint.h" 1 3 4
+# 9 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdint.h" 3 4
+# 1 "/usr/arm-none-eabi/include/stdint.h" 1 3 4
+# 13 "/usr/arm-none-eabi/include/stdint.h" 3 4
+# 1 "/usr/arm-none-eabi/include/sys/_intsup.h" 1 3 4
+# 35 "/usr/arm-none-eabi/include/sys/_intsup.h" 3 4
+
+
+
+
+
+
+
+# 187 "/usr/arm-none-eabi/include/sys/_intsup.h" 3 4
+
+
+
+
+
+
+
+# 14 "/usr/arm-none-eabi/include/stdint.h" 2 3 4
+
+
+
+
+
+
+
+typedef __int_least8_t int_least8_t;
+typedef __uint_least8_t uint_least8_t;
+
+
+
+
+typedef __int_least16_t int_least16_t;
+typedef __uint_least16_t uint_least16_t;
+
+
+
+
+typedef __int_least32_t int_least32_t;
+typedef __uint_least32_t uint_least32_t;
+
+
+
+
+typedef __int_least64_t int_least64_t;
+typedef __uint_least64_t uint_least64_t;
+# 51 "/usr/arm-none-eabi/include/stdint.h" 3 4
+ typedef int int_fast8_t;
+ typedef unsigned int uint_fast8_t;
+# 61 "/usr/arm-none-eabi/include/stdint.h" 3 4
+ typedef int int_fast16_t;
+ typedef unsigned int uint_fast16_t;
+# 71 "/usr/arm-none-eabi/include/stdint.h" 3 4
+ typedef int int_fast32_t;
+ typedef unsigned int uint_fast32_t;
+# 81 "/usr/arm-none-eabi/include/stdint.h" 3 4
+ typedef long long int int_fast64_t;
+ typedef long long unsigned int uint_fast64_t;
+# 10 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdint.h" 2 3 4
+# 5 "../common/8b10b.h" 2
+# 1 "/usr/lib/gcc/arm-none-eabi/7.1.0/include/stdbool.h" 1 3 4
+# 6 "../common/8b10b.h" 2
+# 1 "/usr/arm-none-eabi/include/errno.h" 1 3
+
+
+
+
+typedef int error_t;
+
+
+
+# 1 "/usr/arm-none-eabi/include/sys/errno.h" 1 3
+# 15 "/usr/arm-none-eabi/include/sys/errno.h" 3
+extern int *__errno (void);
+
+
+
+
+extern const char * const _sys_errlist[];
+extern int _sys_nerr;
+# 10 "/usr/arm-none-eabi/include/errno.h" 2 3
+# 7 "../common/8b10b.h" 2
+
+
+# 8 "../common/8b10b.h"
+enum k_code {
+ K28_0=1, K28_1, K28_2, K28_3,
+ K28_4, K28_5, K28_6, K28_7,
+ K23_7, K27_7, K29_7, K30_7,
+ K_CODES_LAST
+};
+
+enum decoder_return_codes {
+ _K_CODES_LAST = K_CODES_LAST,
+ DECODING_ERROR,
+ DECODING_IN_PROGRESS
+};
+
+struct entry {
+ uint8_t rd_neg, rd_pos, disp;
+};
+
+struct state_8b10b_dec {
+ uint32_t rx;
+ int bit_ctr;
+};
+
+struct state_8b10b_enc {
+ int rd;
+};
+
+void xfr_8b10b_reset(struct state_8b10b_dec *st);
+int xfr_8b10b_feed_bit(struct state_8b10b_dec *st, int bit);
+
+# 36 "../common/8b10b.h" 3 4
+_Bool
+# 36 "../common/8b10b.h"
+ xfr_8b10b_has_sync(struct state_8b10b_dec *st);
+
+void xfr_8b10b_encode_reset(struct state_8b10b_enc *st);
+int xfr_8b10b_encode(struct state_8b10b_enc *st, int data);
+# 6 "../common/8b10b.c" 2
+
+
+
+#pragma GCC diagnostic ignored "-Wunused-const-variable=0"
+static const struct entry map_5b6b[32] = {
+ {0b100111, 0b011000, 2},
+ {0b011101, 0b100010, 2},
+ {0b101101, 0b010010, 2},
+ {0b110001, 0b110001, 0},
+ {0b110101, 0b001010, 2},
+ {0b101001, 0b101001, 0},
+ {0b011001, 0b011001, 0},
+ {0b111000, 0b000111, 0},
+ {0b111001, 0b000110, 2},
+ {0b100101, 0b100101, 0},
+ {0b010101, 0b010101, 0},
+ {0b110100, 0b110100, 0},
+ {0b001101, 0b001101, 0},
+ {0b101100, 0b101100, 0},
+ {0b011100, 0b011100, 0},
+ {0b010111, 0b101000, 2},
+ {0b011011, 0b100100, 2},
+ {0b100011, 0b100011, 0},
+ {0b010011, 0b010011, 0},
+ {0b110010, 0b110010, 0},
+ {0b001011, 0b001011, 0},
+ {0b101010, 0b101010, 0},
+ {0b011010, 0b011010, 0},
+ {0b111010, 0b000101, 2},
+ {0b110011, 0b001100, 2},
+ {0b100110, 0b100110, 0},
+ {0b010110, 0b010110, 0},
+ {0b110110, 0b001001, 2},
+ {0b001110, 0b001110, 0},
+ {0b101110, 0b010001, 2},
+ {0b011110, 0b100001, 2},
+ {0b101011, 0b010100, 2}
+};
+
+static const int8_t map_6b5b[64] = {
+ [0b000101] = 23,
+ [0b000110] = 8,
+ [0b000111] = 7,
+ [0b001001] = 27,
+ [0b001010] = 4,
+ [0b001011] = 20,
+ [0b001100] = 24,
+ [0b001101] = 12,
+ [0b001101] = 12,
+ [0b001110] = 28,
+ [0b010001] = 29,
+ [0b010010] = 2,
+ [0b010011] = 18,
+ [0b010100] = 31,
+ [0b010101] = 10,
+ [0b010101] = 10,
+ [0b010110] = 26,
+ [0b010111] = 15,
+ [0b011000] = -1,
+ [0b011001] = 6,
+ [0b011010] = 22,
+ [0b011011] = 16,
+ [0b011100] = 14,
+ [0b011101] = 1,
+ [0b011110] = 30,
+ [0b100001] = 30,
+ [0b100010] = 1,
+ [0b100011] = 17,
+ [0b100100] = 16,
+ [0b100101] = 9,
+ [0b100110] = 25,
+ [0b100111] = -1,
+ [0b101000] = 15,
+ [0b101001] = 5,
+ [0b101010] = 21,
+ [0b101011] = 31,
+ [0b101100] = 13,
+ [0b101101] = 2,
+ [0b101110] = 29,
+ [0b110001] = 3,
+ [0b110010] = 19,
+ [0b110011] = 24,
+ [0b110100] = 11,
+ [0b110101] = 4,
+ [0b110110] = 27,
+ [0b111000] = 7,
+ [0b111001] = 8,
+ [0b111010] = 23
+};
+
+static const struct entry K28 = {0b001111, 0b110000};
+
+static const struct entry map_3b4b_d[8] = {
+ {0b1011, 0b0100, 2},
+ {0b1001, 0b1001, 0},
+ {0b0101, 0b0101, 0},
+ {0b1100, 0b0011, 0},
+ {0b1101, 0b0010, 2},
+ {0b1010, 0b1010, 0},
+ {0b0110, 0b0110, 0},
+ {0b1110, 0b0001, 2}
+};
+
+static const struct entry Dx_A7 = {0b0111, 0b1000, 2};
+
+static const struct entry map_3b4b_k[8] = {
+ {0b1011, 0b0100},
+ {0b0110, 0b1001},
+ {0b1010, 0b0101},
+ {0b1100, 0b0011},
+ {0b1101, 0b0010},
+ {0b0101, 0b1010},
+ {0b1001, 0b0110},
+ {0b0111, 0b1000}
+};
+
+static const int8_t map_4b3b[16] = {
+ [0b0001] = 7,
+ [0b0010] = 4,
+ [0b0011] = 3,
+ [0b0100] = -1,
+ [0b0101] = 2,
+ [0b0110] = 6,
+ [0b0111] = 7,
+ [0b1000] = 7,
+ [0b1001] = 1,
+ [0b1010] = 5,
+ [0b1011] = -1,
+ [0b1100] = 3,
+ [0b1101] = 4,
+ [0b1110] = 7,
+ [0b1111] = 0,
+ [0b0000] = 0
+};
+
+static const uint16_t k_sym_map[K_CODES_LAST] = {
+ [K28_0] = 0b0011110100,
+ [K28_1] = 0b0011111001,
+ [K28_2] = 0b0011110101,
+ [K28_3] = 0b0011110011,
+ [K28_4] = 0b0011110010,
+ [K28_5] = 0b0011111010,
+ [K28_6] = 0b0011110110,
+ [K28_7] = 0b0011111000,
+ [K23_7] = 0b1110101000,
+ [K27_7] = 0b1101101000,
+ [K29_7] = 0b1011101000,
+ [K30_7] = 0b0111101000
+};
+
+void xfr_8b10b_reset(struct state_8b10b_dec *st) {
+ st->rx = 0;
+ st->bit_ctr = 0;
+}
+
+int xfr_8b10b_feed_bit(struct state_8b10b_dec *st, int bit) {
+ uint32_t pattern = st->rx = (st->rx<<1 | !!bit) & 0x3ff;
+ uint16_t comma = k_sym_map[K28_1];
+ if (pattern == comma || pattern == ((~comma)&0x3ff)) {
+ st->bit_ctr = 1;
+ return -K28_1;
+ }
+
+ if (st->bit_ctr == 10) {
+ st->bit_ctr = 1;
+
+ for (int i=1; i<sizeof(k_sym_map)/sizeof(k_sym_map[0]); i++) {
+ if (pattern == k_sym_map[i])
+ return -i;
+ }
+
+ int p3b = map_4b3b[pattern & 0xf];
+ int p5b = map_6b5b[pattern >> 4];
+
+ if (p3b == 0 || p5b == 0)
+ return -DECODING_ERROR;
+
+ p3b = (p3b == -1) ? 0 : p3b;
+ p5b = (p5b == -1) ? 0 : p5b;
+ return p3b<<5 | p5b;
+
+ } else if (st->bit_ctr > 0) {
+ st->bit_ctr++;
+ }
+ return -DECODING_IN_PROGRESS;
+}
+
+
+# 193 "../common/8b10b.c" 3 4
+_Bool
+# 193 "../common/8b10b.c"
+ xfr_8b10b_has_sync(struct state_8b10b_dec *st) {
+ return st->bit_ctr != 0;
+}
+
+void xfr_8b10b_encode_reset(struct state_8b10b_enc *st) {
+ st->rd = -1;
+}
+
+int xfr_8b10b_encode(struct state_8b10b_enc *st, int data) {
+ if (data < 0) {
+ if (-data >= sizeof(k_sym_map)/sizeof(k_sym_map[0]))
+ return -
+# 204 "../common/8b10b.c" 3
+ 22
+# 204 "../common/8b10b.c"
+ ;
+
+ return k_sym_map[-data];
+ }
+
+ if (data > 255)
+ return -
+# 210 "../common/8b10b.c" 3
+ 22
+# 210 "../common/8b10b.c"
+ ;
+
+ int p5b = data&0x1f, p3b = data>>5;
+
+
+ int x5b = (st->rd == -1) ? map_5b6b[p5b].rd_neg : map_5b6b[p5b].rd_pos;
+ st->rd -= map_5b6b[p5b].disp * st->rd;
+
+
+
+ int x3b = (st->rd == -1) ? map_3b4b_d[p3b].rd_neg : map_3b4b_d[p3b].rd_pos;
+ if (p3b == 7) {
+ if ( (st->rd == -1 && (p5b == 17 || p5b == 18 || p5b == 20))
+ || (st->rd == 1 && (p5b == 11 || p5b == 13 || p5b == 14))) {
+
+ x3b = (st->rd == -1) ? Dx_A7.rd_neg : Dx_A7.rd_pos;
+ }
+ }
+ st->rd -= map_3b4b_d[p3b].disp * st->rd;
+
+
+ return x5b<<4 | x3b;
+}
diff --git a/fw/8b10b_test_decode.c b/common/8b10b_test_decode.c
index 433f7b8..433f7b8 100644
--- a/fw/8b10b_test_decode.c
+++ b/common/8b10b_test_decode.c
diff --git a/fw/8b10b_test_encode.c b/common/8b10b_test_encode.c
index 2ba75d9..2ba75d9 100644
--- a/fw/8b10b_test_encode.c
+++ b/common/8b10b_test_encode.c
diff --git a/fw/8b10b_test_vector_gen.py b/common/8b10b_test_vector_gen.py
index 12460c1..12460c1 100755
--- a/fw/8b10b_test_vector_gen.py
+++ b/common/8b10b_test_vector_gen.py
diff --git a/common/Makefile b/common/Makefile
new file mode 100644
index 0000000..b731327
--- /dev/null
+++ b/common/Makefile
@@ -0,0 +1,27 @@
+# Megumin LED display firmware
+# Copyright (C) 2018 Sebastian Götte <code@jaseg.net>
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+all: 8b10b_test_encode 8b10b_test_decode
+
+8b10b_test_encode: 8b10b_test_encode.c 8b10b.c
+ gcc -o $@ $^
+
+8b10b_test_decode: 8b10b_test_decode.c 8b10b.c
+ gcc -o $@ $^
+
+clean:
+ rm -f 8b10b_test_encode 8b10b_test_decode
+
diff --git a/driver_fw/Makefile b/driver_fw/Makefile
index de129d2..2d74acd 100644
--- a/driver_fw/Makefile
+++ b/driver_fw/Makefile
@@ -9,7 +9,7 @@ OBJCOPY := arm-none-eabi-objcopy
OBJDUMP := arm-none-eabi-objdump
SIZE := arm-none-eabi-size
-CFLAGS = -g -Wall -std=gnu11 -O1 -fdump-rtl-expand
+CFLAGS = -g -Wall -std=gnu11 -O1 -fdump-rtl-expand -Wno-discarded-qualifiers
CFLAGS += -mlittle-endian -mcpu=cortex-m3 -mthumb
#CFLAGS += -ffunction-sections -fdata-sections
LDFLAGS = -nostartfiles
@@ -22,7 +22,7 @@ LIBS = -lgcc
CFLAGS += -DSTM32F103xB -DHSE_VALUE=8000000
LDFLAGS += -Tstm32_flash.ld
-CFLAGS += -I$(CMSIS_DEV_PATH)/Include -I$(CMSIS_PATH)/Include -I$(HAL_PATH)/Inc -Iconfig
+CFLAGS += -I$(CMSIS_DEV_PATH)/Include -I$(CMSIS_PATH)/Include -I$(HAL_PATH)/Inc -Iconfig -I../common
#LDFLAGS += -L$(CMSIS_PATH)/Lib/GCC -larm_cortexM0l_math
###################################################
@@ -45,7 +45,7 @@ cmsis_exports.c: $(CMSIS_DEV_PATH)/Include/stm32f103xb.h $(CMSIS_PATH)/Include/c
%.dot: %.elf
r2 -a arm -qc 'aa;agC' $< 2>/dev/null >$@
-main.elf: main.o startup_stm32f103xb.o system_stm32f1xx.o $(HAL_PATH)/Src/stm32f1xx_ll_utils.o cmsis_exports.o
+main.elf: main.o startup_stm32f103xb.o system_stm32f1xx.o $(HAL_PATH)/Src/stm32f1xx_ll_utils.o cmsis_exports.o ../common/8b10b.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJCOPY) -O ihex $@ $(@:.elf=.hex)
$(OBJCOPY) -O binary $@ $(@:.elf=.bin)
diff --git a/driver_fw/main.c b/driver_fw/main.c
index d814b0e..e4960c7 100644
--- a/driver_fw/main.c
+++ b/driver_fw/main.c
@@ -12,6 +12,8 @@
#include <string.h>
#include <unistd.h>
+#include <8b10b.h>
+
/* Part number: STM32F030F4C6 */
static volatile unsigned int sys_time;
@@ -20,14 +22,23 @@ uint32_t get_tick() {
return SysTick->VAL;
}
+static volatile struct {
+ int current_symbol, next_symbol;
+ struct state_8b10b_enc st;
+} txstate;
+
+#define NO_SYMBOL (DECODER_RETURN_CODE_LAST + 1)
+
int main(void) {
/* External crystal: 8MHz */
RCC->CR |= RCC_CR_HSEON;
while (!(RCC->CR&RCC_CR_HSERDY));
/* Sysclk = HCLK = 48MHz */
- RCC->CFGR = (RCC->CFGR & (~RCC_CFGR_PLLMULL_Msk & ~RCC_CFGR_SW_Msk & ~RCC_CFGR_PPRE1_Msk & ~RCC_CFGR_PPRE2_Msk & ~RCC_CFGR_HPRE_Msk))
- | (10<<RCC_CFGR_PLLMULL_Pos) | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | (4<<RCC_CFGR_PPRE1_Pos) | (4<<RCC_CFGR_PPRE2_Pos);
+ RCC->CFGR = (RCC->CFGR & (~RCC_CFGR_PLLMULL_Msk & ~RCC_CFGR_SW_Msk & ~RCC_CFGR_PPRE1_Msk & ~RCC_CFGR_PPRE2_Msk &
+ ~RCC_CFGR_HPRE_Msk))
+ | (10<<RCC_CFGR_PLLMULL_Pos) | RCC_CFGR_PLLXTPRE | RCC_CFGR_PLLSRC | (4<<RCC_CFGR_PPRE1_Pos) |
+ (4<<RCC_CFGR_PPRE2_Pos);
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR&RCC_CR_PLLRDY));
@@ -38,41 +49,68 @@ int main(void) {
// | (4<<RCC_CFGR_PPRE1_Pos) | (4<<RCC_CFGR_PPRE2_Pos);
SystemCoreClockUpdate();
- RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN;
+ RCC->APB2ENR |= RCC_APB2ENR_IOPAEN | RCC_APB2ENR_IOPBEN | RCC_APB2ENR_IOPCEN | RCC_APB2ENR_TIM1EN;
- GPIOA->CRL =
- (0<<GPIO_CRL_CNF6_Pos) | (1<<GPIO_CRL_MODE6_Pos) /* PA6 - Channel 1 low side */
- | (0<<GPIO_CRL_CNF7_Pos) | (1<<GPIO_CRL_MODE7_Pos); /* PA7 - Channel 2 low side */
+ GPIOA->CRH =
+ (2<<GPIO_CRH_CNF8_Pos) | (1<<GPIO_CRH_MODE8_Pos); /* PA8 - low side */
- GPIOB->CRL =
- (0<<GPIO_CRL_CNF0_Pos) | (1<<GPIO_CRL_MODE0_Pos) /* PB0 - Channel 1 high side */
- | (0<<GPIO_CRL_CNF1_Pos) | (1<<GPIO_CRL_MODE1_Pos); /* PB1 - Channel 2 high side */
+ GPIOB->CRH =
+ (2<<GPIO_CRH_CNF13_Pos) | (1<<GPIO_CRH_MODE13_Pos); /* PB13 - high side */
GPIOC->CRH =
(0<<GPIO_CRH_CNF13_Pos) | (1<<GPIO_CRH_MODE13_Pos); /* PC13 - LED */
- /* Turn all outputs off */
- GPIOA->BRR |= 1<<6 | 1<<7;
- GPIOB->BRR |= 1<<0 | 1<<1;
-
+ /* TIM1 running off 24MHz APB2 clk, T=41.667ns */
+ TIM1->CR1 = 0; /* Disable ARR preload (double-buffering) */
+ TIM1->PSC = 24-1; /* Prescaler 24 -> f=1MHz/T=1us */
+ TIM1->DIER = TIM_DIER_UIE; /* Enable update (overflow) interrupt */
+ TIM1->CCMR1 = 6<<TIM_CCMR1_OC1M_Pos | TIM_CCMR1_OC1PE; /* Configure output compare unit 1 to PWM mode 1, enable CCR1
+ preload */
+ TIM1->CCER = TIM_CCER_CC1NE | TIM_CCER_CC1E; /* Confiugre CH1 to complementary outputs */
+ TIM1->BDTR = TIM_BDTR_MOE | 100<<TIM_BDTR_DTG_Pos; /* Enable MOE on next update event, i.e. on initial timer load.
+ Set dead-time to 100us. */
+ TIM1->CR1 |= TIM_CR1_CEN;
+ TIM1->ARR = 1000-1; /* Set f=1.0kHz/T=1.0ms */
+
+ xfr_8b10b_encode_reset(&txstate.st);
+ txstate.current_symbol = txstate.next_symbol = xfr_8b10b_encode(&txstate.st, K28_1) | 1<<10;
+ TIM1->EGR |= TIM_EGR_UG;
+
+ NVIC_EnableIRQ(TIM1_UP_IRQn);
+ NVIC_SetPriority(TIM1_UP_IRQn, 3<<4);
+
+ uint8_t txbuf[128];
+ int txpos = -1;
+ /* FIXME test code */
+ for (int i=0; i<sizeof(txbuf); i++)
+ txbuf[i] = i;
+ /* FIXME end test code */
while (42) {
-#define FOO 100000
- for (int i=0; i<FOO; i++) ;
- GPIOA->BRR |= 1<<6 | 1<<7;
- GPIOB->BRR |= 1<<0 | 1<<1;
-
- GPIOA->BSRR |= 1<<6;
- GPIOB->BSRR |= 1<<1;
-
- for (int i=0; i<FOO; i++) ;
- GPIOA->BRR |= 1<<6 | 1<<7;
- GPIOB->BRR |= 1<<0 | 1<<1;
-
- GPIOA->BSRR |= 1<<7;
- GPIOB->BSRR |= 1<<0;
+ if (txstate.next_symbol == -NO_SYMBOL) {
+ if (txpos == -1)
+ txstate.next_symbol = xfr_8b10b_encode(&txstate.st, K28_1);
+ else
+ txstate.next_symbol = xfr_8b10b_encode(&txstate.st, txbuf[txpos]);
+
+ txpos++;
+ if (txpos == sizeof(txbuf))
+ txpos = -1;
+ }
+ }
+}
- GPIOC->ODR ^= 1<<13;
+void TIM1_UP_IRQHandler() {
+ TIM1->SR &= ~TIM_SR_UIF;
+ int sym = txstate.current_symbol;
+ int bit = sym&1;
+ sym >>= 1;
+ if (sym == 1) { /* last bit shifted out */
+ sym = txstate.next_symbol | 1<<10;
+ txstate.next_symbol = -NO_SYMBOL;
}
+ txstate.current_symbol = sym;
+
+ TIM1->CCR1 = bit ? 0xffff : 0x0000;
}
void NMI_Handler(void) {
@@ -104,5 +142,5 @@ void MemManage_Handler() {
void BusFault_Handler(void) __attribute__((naked));
void BusFault_Handler() {
- asm volatile ("bkpt");
+asm volatile ("bkpt");
}
diff --git a/fw/Makefile b/fw/Makefile
index b779789..7795f0a 100644
--- a/fw/Makefile
+++ b/fw/Makefile
@@ -43,7 +43,7 @@ LIBS = -lgcc
CFLAGS += -DSTM32F030x6 -DHSE_VALUE=8000000
LDFLAGS += -Tstm32_flash.ld
-CFLAGS += -I$(CMSIS_DEV_PATH)/Include -I$(CMSIS_PATH)/Include -I$(HAL_PATH)/Inc -Iconfig -Wno-unused
+CFLAGS += -I$(CMSIS_DEV_PATH)/Include -I$(CMSIS_PATH)/Include -I$(HAL_PATH)/Inc -Iconfig -Wno-unused -I../common
LDFLAGS += -L$(CMSIS_PATH)/Lib/GCC -larm_cortexM0l_math
###################################################
@@ -66,7 +66,7 @@ cmsis_exports.c: $(CMSIS_DEV_PATH)/Include/stm32f030x6.h $(CMSIS_PATH)/Include/c
%.dot: %.elf
r2 -a arm -qc 'aa;agC' $< 2>/dev/null >$@
-sources.tar.xz: main.c Makefile
+sources.tar.xz: main.c adc.c ../common/8b10b.c Makefile
tar -caf $@ $^
# don't ask...
@@ -76,7 +76,7 @@ sources.tar.xz.zip: sources.tar.xz
sources.c: sources.tar.xz.zip
xxd -i $< | head -n -1 | sed 's/=/__attribute__((section(".source_tarball"))) =/' > $@
-main.elf: main.o startup_stm32f030x6.o system_stm32f0xx.o $(HAL_PATH)/Src/stm32f0xx_ll_utils.o base.o cmsis_exports.o 8b10b.o sources.o
+main.elf: main.o startup_stm32f030x6.o system_stm32f0xx.o $(HAL_PATH)/Src/stm32f0xx_ll_utils.o base.o cmsis_exports.o ../common/8b10b.o adc.o
$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
$(OBJCOPY) -O ihex $@ $(@:.elf=.hex)
$(OBJCOPY) -O binary $@ $(@:.elf=.bin)
diff --git a/fw/adc.c b/fw/adc.c
new file mode 100644
index 0000000..726e9a8
--- /dev/null
+++ b/fw/adc.c
@@ -0,0 +1,118 @@
+/* Megumin LED display firmware
+ * Copyright (C) 2018 Sebastian Götte <code@jaseg.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "adc.h"
+
+volatile struct adc_measurements adc_data = {0};
+
+enum adc_channels {
+ VREF_CH,
+ VMEAS_A,
+ VMEAS_B,
+ TEMP_CH,
+ NCH
+};
+static volatile uint16_t adc_buf[NCH];
+
+void adc_init(void) {
+ /* The ADC is used for temperature measurement. To compute the temperature from an ADC reading of the internal
+ * temperature sensor, the supply voltage must also be measured. Thus we are using two channels.
+ *
+ * The ADC is triggered by compare channel 4 of timer 1. The trigger is set to falling edge to trigger on compare
+ * match, not overflow.
+ */
+ ADC1->CFGR1 = ADC_CFGR1_DMAEN | ADC_CFGR1_DMACFG | (2<<ADC_CFGR1_EXTEN_Pos) | (1<<ADC_CFGR1_EXTSEL_Pos);
+ /* Clock from PCLK/4 instead of the internal exclusive high-speed RC oscillator. */
+ ADC1->CFGR2 = (2<<ADC_CFGR2_CKMODE_Pos); /* Use PCLK/4=12MHz */
+ /* Sampling time 13.5 ADC clock cycles -> total conversion time 2.17us*/
+ ADC1->SMPR = (2<<ADC_SMPR_SMP_Pos);
+ /* Internal VCC and temperature sensor channels */
+ ADC1->CHSELR = ADC_CHSELR_CHSEL0 | ADC_CHSELR_CHSEL1 | ADC_CHSELR_CHSEL16 | ADC_CHSELR_CHSEL17;
+ /* Enable internal voltage reference and temperature sensor */
+ ADC->CCR = ADC_CCR_TSEN | ADC_CCR_VREFEN;
+ /* Perform ADC calibration */
+ ADC1->CR |= ADC_CR_ADCAL;
+ while (ADC1->CR & ADC_CR_ADCAL)
+ ;
+ /* Enable ADC */
+ ADC1->CR |= ADC_CR_ADEN;
+ ADC1->CR |= ADC_CR_ADSTART;
+
+ /* Configure DMA 1 Channel 1 to get rid of all the data */
+ DMA1_Channel1->CPAR = (unsigned int)&ADC1->DR;
+ DMA1_Channel1->CMAR = (unsigned int)&adc_buf;
+ DMA1_Channel1->CNDTR = NCH;
+ DMA1_Channel1->CCR = (0<<DMA_CCR_PL_Pos);
+ DMA1_Channel1->CCR |=
+ DMA_CCR_CIRC /* circular mode so we can leave it running indefinitely */
+ | (1<<DMA_CCR_MSIZE_Pos) /* 16 bit */
+ | (1<<DMA_CCR_PSIZE_Pos) /* 16 bit */
+ | DMA_CCR_MINC
+ | DMA_CCR_TCIE; /* Enable transfer complete interrupt. */
+ DMA1_Channel1->CCR |= DMA_CCR_EN; /* Enable channel */
+
+ /* triggered on transfer completion. We use this to process the ADC data */
+ NVIC_EnableIRQ(DMA1_Channel1_IRQn);
+ NVIC_SetPriority(DMA1_Channel1_IRQn, 3<<5);
+}
+
+uint16_t buf_a[256];
+uint16_t buf_b[256];
+int bufp = 0;
+
+void DMA1_Channel1_IRQHandler(void) {
+ /* This interrupt takes either 1.2us or 13us. It can be pre-empted by the more timing-critical UART and LED timer
+ * interrupts. */
+ static int count = 0; /* oversampling accumulator sample count */
+ static uint32_t adc_aggregate[NCH] = {0}; /* oversampling accumulator */
+
+ /* Clear the interrupt flag */
+ DMA1->IFCR |= DMA_IFCR_CGIF1;
+
+ for (int i=0; i<NCH; i++)
+ adc_aggregate[i] += adc_buf[i];
+
+ if (++count == (1<<ADC_OVERSAMPLING)) {
+ for (int i=0; i<NCH; i++)
+ adc_aggregate[i] >>= ADC_OVERSAMPLING;
+ /* This has been copied from the code examples to section 12.9 ADC>"Temperature sensor and internal reference
+ * voltage" in the reference manual with the extension that we actually measure the supply voltage instead of
+ * hardcoding it. This is not strictly necessary since we're running off a bored little LDO but it's free and
+ * the current supply voltage is a nice health value.
+ */
+ adc_data.adc_vcc_mv = (3300 * VREFINT_CAL)/(adc_aggregate[VREF_CH]);
+
+ int64_t read = adc_aggregate[TEMP_CH] * 10 * 10000;
+ int64_t vcc = adc_data.adc_vcc_mv;
+ int64_t cal = TS_CAL1 * 10 * 10000;
+ adc_data.adc_temp_celsius_tenths = 300 + ((read/4096 * vcc) - (cal/4096 * 3300))/43000;
+
+ adc_data.adc_vmeas_a_mv = (adc_aggregate[VMEAS_A]*13300L)/4096 * vcc / 3300;
+ adc_data.adc_vmeas_b_mv = (adc_aggregate[VMEAS_B]*13300L)/4096 * vcc / 3300;
+
+ buf_a[bufp] = adc_data.adc_vmeas_a_mv;
+ buf_b[bufp] = adc_data.adc_vmeas_b_mv;
+ if (++bufp >= sizeof(buf_a)/sizeof(buf_a[0])) {
+ bufp = 0;
+ }
+
+ count = 0;
+ for (int i=0; i<NCH; i++)
+ adc_aggregate[i] = 0;
+ }
+}
+
diff --git a/fw/adc.h b/fw/adc.h
new file mode 100644
index 0000000..8c0c6cc
--- /dev/null
+++ b/fw/adc.h
@@ -0,0 +1,36 @@
+/* Megumin LED display firmware
+ * Copyright (C) 2018 Sebastian Götte <code@jaseg.net>
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef __ADC_H__
+#define __ADC_H__
+
+#include "global.h"
+
+#define ADC_OVERSAMPLING 0
+
+struct adc_measurements {
+ int16_t adc_vcc_mv;
+ int16_t adc_temp_celsius_tenths;
+ int16_t adc_vmeas_a_mv;
+ int16_t adc_vmeas_b_mv;
+};
+
+extern volatile struct adc_measurements adc_data;
+
+void adc_init(void);
+
+#endif/*__ADC_H__*/
diff --git a/fw/cmsis_exports.c b/fw/cmsis_exports.c
index e69de29..39874b5 100644
--- a/fw/cmsis_exports.c
+++ b/fw/cmsis_exports.c
@@ -0,0 +1,48 @@
+#ifndef __GENERATED_CMSIS_HEADER_EXPORTS__
+#define __GENERATED_CMSIS_HEADER_EXPORTS__
+
+#include <stm32f030x6.h>
+
+/* stm32f030x6.h */
+TIM_TypeDef *tim3 = TIM3;
+TIM_TypeDef *tim14 = TIM14;
+RTC_TypeDef *rtc = RTC;
+WWDG_TypeDef *wwdg = WWDG;
+IWDG_TypeDef *iwdg = IWDG;
+I2C_TypeDef *i2c1 = I2C1;
+PWR_TypeDef *pwr = PWR;
+SYSCFG_TypeDef *syscfg = SYSCFG;
+EXTI_TypeDef *exti = EXTI;
+ADC_TypeDef *adc1 = ADC1;
+ADC_Common_TypeDef *adc1_common = ADC1_COMMON;
+ADC_Common_TypeDef *adc = ADC;
+TIM_TypeDef *tim1 = TIM1;
+SPI_TypeDef *spi1 = SPI1;
+USART_TypeDef *usart1 = USART1;
+TIM_TypeDef *tim16 = TIM16;
+TIM_TypeDef *tim17 = TIM17;
+DBGMCU_TypeDef *dbgmcu = DBGMCU;
+DMA_TypeDef *dma1 = DMA1;
+DMA_Channel_TypeDef *dma1_channel1 = DMA1_Channel1;
+DMA_Channel_TypeDef *dma1_channel2 = DMA1_Channel2;
+DMA_Channel_TypeDef *dma1_channel3 = DMA1_Channel3;
+DMA_Channel_TypeDef *dma1_channel4 = DMA1_Channel4;
+DMA_Channel_TypeDef *dma1_channel5 = DMA1_Channel5;
+FLASH_TypeDef *flash = FLASH;
+OB_TypeDef *ob = OB;
+RCC_TypeDef *rcc = RCC;
+CRC_TypeDef *crc = CRC;
+GPIO_TypeDef *gpioa = GPIOA;
+GPIO_TypeDef *gpiob = GPIOB;
+GPIO_TypeDef *gpioc = GPIOC;
+GPIO_TypeDef *gpiod = GPIOD;
+GPIO_TypeDef *gpiof = GPIOF;
+
+#include <core_cm0.h>
+
+/* core_cm0.h */
+SCB_Type *scb = SCB;
+SysTick_Type *systick = SysTick;
+NVIC_Type *nvic = NVIC;
+
+#endif//__GENERATED_CMSIS_HEADER_EXPORTS__
diff --git a/fw/main.c b/fw/main.c
index e00f3a6..b766488 100644
--- a/fw/main.c
+++ b/fw/main.c
@@ -17,29 +17,34 @@
#include "global.h"
+#include "adc.h"
+
volatile unsigned int sys_time = 0;
volatile unsigned int sys_time_seconds = 0;
+void TIM1_BRK_UP_TRG_COM_Handler() {
+ TIM1->SR &= ~TIM_SR_UIF_Msk;
+}
+
int main(void) {
RCC->CR |= RCC_CR_HSEON;
while (!(RCC->CR&RCC_CR_HSERDY));
RCC->CFGR &= ~RCC_CFGR_PLLMUL_Msk & ~RCC_CFGR_SW_Msk & ~RCC_CFGR_PPRE_Msk & ~RCC_CFGR_HPRE_Msk;
- RCC->CFGR |= (2<<RCC_CFGR_PLLMUL_Pos) | RCC_CFGR_PLLSRC_HSE_PREDIV; /* PLL x4 -> 32.0MHz */
- RCC->CFGR2 &= ~RCC_CFGR2_PREDIV_Msk;
- RCC->CFGR2 |= RCC_CFGR2_PREDIV_DIV2; /* prediv :2 -> 4.0MHz */
+ RCC->CFGR |= ((6-2)<<RCC_CFGR_PLLMUL_Pos) | RCC_CFGR_PLLSRC_HSE_PREDIV; /* PLL x6 -> 48.0MHz */
RCC->CR |= RCC_CR_PLLON;
while (!(RCC->CR&RCC_CR_PLLRDY));
RCC->CFGR |= (2<<RCC_CFGR_SW_Pos);
SystemCoreClockUpdate();
+ SysTick_Config(SystemCoreClock/1000); /* 1ms interval */
/* Turn on lots of neat things */
- RCC->AHBENR |= RCC_AHBENR_GPIOAEN | RCC_AHBENR_FLITFEN;
- RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN | RCC_APB2ENR_DBGMCUEN | RCC_APB2ENR_TIM1EN;
+ RCC->AHBENR |= RCC_AHBENR_DMAEN | RCC_AHBENR_GPIOAEN | RCC_AHBENR_FLITFEN;
+ RCC->APB2ENR |= RCC_APB2ENR_SYSCFGEN | RCC_APB2ENR_ADCEN| RCC_APB2ENR_DBGMCUEN | RCC_APB2ENR_TIM1EN | RCC_APB2ENR_TIM1EN;;
RCC->APB1ENR |= RCC_APB1ENR_TIM3EN;
GPIOA->MODER |=
- (0<<GPIO_MODER_MODER0_Pos) /* PA0 - Vmeas_A */
- | (0<<GPIO_MODER_MODER1_Pos) /* PA1 - Vmeas_B */
+ (3<<GPIO_MODER_MODER0_Pos) /* PA0 - Vmeas_A to ADC */
+ | (3<<GPIO_MODER_MODER1_Pos) /* PA1 - Vmeas_B to ADC */
| (1<<GPIO_MODER_MODER2_Pos) /* PA2 - LOAD */
| (1<<GPIO_MODER_MODER3_Pos) /* PA3 - CH0 */
| (1<<GPIO_MODER_MODER4_Pos) /* PA4 - CH3 */
@@ -57,7 +62,20 @@ int main(void) {
| (2<<GPIO_OSPEEDR_OSPEEDR6_Pos) /* CH2 */
| (2<<GPIO_OSPEEDR_OSPEEDR7_Pos); /* CH1 */
- SysTick_Config(SystemCoreClock/1000); /* 1ms interval */
+ /* Setup CC1 and CC2. CC2 generates the LED drivers' STROBE, CC1 triggers the IRQ handler */
+ TIM1->BDTR = TIM_BDTR_MOE;
+ TIM1->CCMR2 = (6<<TIM_CCMR2_OC4M_Pos); /* PWM Mode 1 */
+ TIM1->CCER = TIM_CCER_CC4E;
+ TIM1->CCR4 = 1;
+ TIM1->DIER = TIM_DIER_UIE;
+
+ TIM1->PSC = SystemCoreClock/1000000 - 1; /* 1.0us/tick */
+ TIM1->ARR = 20-1; /* 20us */
+ /* Preload all values */
+ TIM1->EGR |= TIM_EGR_UG;
+ TIM1->CR1 = TIM_CR1_ARPE;
+ /* And... go! */
+ TIM1->CR1 |= TIM_CR1_CEN;
void set_outputs(uint8_t val) {
int a=!!(val&1), b=!!(val&2), c=!!(val&4), d=!!(val&8);
@@ -66,6 +84,8 @@ int main(void) {
}
set_outputs(0);
+ adc_init();
+
uint8_t out_state = 0x01;
#define DEBOUNCE 100
int debounce_ctr = 0;