diff --git a/firmware/hsdaoh/hsdaoh_nano20k_misrc/top.v b/firmware/hsdaoh/hsdaoh_nano20k_misrc/top.v index 9e992a6..73d176b 100644 --- a/firmware/hsdaoh/hsdaoh_nano20k_misrc/top.v +++ b/firmware/hsdaoh/hsdaoh_nano20k_misrc/top.v @@ -10,8 +10,8 @@ module top ( tmds_d_n, tmds_d_p, adc0_data, - adc1_data, - gpio_data, + adc1_data, + gpio_data, adc_clk, uart_rx, uart_tx, @@ -27,8 +27,8 @@ module top ( output wire [2:0] tmds_d_p; input wire [11:0] adc0_data; - input wire [11:0] adc1_data; - input wire [7:0] gpio_data; + input wire [11:0] adc1_data; + input wire [7:0] gpio_data; input wire uart_rx; @@ -45,10 +45,14 @@ module top ( // assign adc_clkout = clk_data_pll0_ext; + // with FBDIV = 52 (maximum) // 477 MHz, maximum that works with the nano 20K // 477/5 = 95.4 MHz + // with FBDIV = 47 (enough for 32 bit at 40 MHz) + // 432 MHz + // 432/5 = 86.4 MHz localparam HDMI_PLL_IDIV = 2; - localparam HDMI_PLL_FBDIV = 52; + localparam HDMI_PLL_FBDIV = 47; localparam HDMI_PLL_ODIV = 2; // PLL for HDMI clock @@ -92,7 +96,7 @@ module top ( reg [31:0] fifo_in; wire write_enable; - wire dword_enable; + wire dword_enable; wire [31:0] fifo_out; wire fifo_empty; @@ -105,7 +109,7 @@ module top ( wire [31:0] settings; - assign dword_enable = settings[19]; + assign dword_enable = settings[19]; async_fifo #( .DSIZE(32), diff --git a/misrc_tools/cthreads.h b/misrc_tools/cthreads.h new file mode 100644 index 0000000..11a26fa --- /dev/null +++ b/misrc_tools/cthreads.h @@ -0,0 +1,10 @@ +#include + +typedef pthread_t thrd_t; +typedef int (*thrd_start_t) (void*); + +#define thrd_success 0 + +#define thrd_create(a,b,c) pthread_create(a,NULL,b,c) +#define thrd_join(a,b) pthread_join(a,b) +#define thrd_sleep(a,b) nanosleep(a,b) \ No newline at end of file diff --git a/misrc_tools/extract.asm b/misrc_tools/extract.asm index c59b92b..952583f 100644 --- a/misrc_tools/extract.asm +++ b/misrc_tools/extract.asm @@ -52,7 +52,9 @@ default rel %endif %endmacro -section .note.GNU-stack noalloc noexec nowrite progbits +%ifidn __OUTPUT_FORMAT__,elf64 + section .note.GNU-stack noalloc noexec nowrite progbits +%endif section .data ALIGN 16 diff --git a/misrc_tools/misrc_capture.c b/misrc_tools/misrc_capture.c index 1be1116..3c7ad3f 100644 --- a/misrc_tools/misrc_capture.c +++ b/misrc_tools/misrc_capture.c @@ -29,7 +29,11 @@ #include #include #include +#if __STDC_NO_THREADS__ +#include "cthreads.h" +#else #include +#endif #include #ifndef _WIN32 @@ -335,7 +339,7 @@ int main(int argc, char **argv) break; #endif case 'x': - output_names[2] = optarg; + output_name_aux = optarg; break; case 'r': output_name_raw = optarg; diff --git a/misrc_tools/ringbuffer.c b/misrc_tools/ringbuffer.c index 4c20c97..7ec9fee 100644 --- a/misrc_tools/ringbuffer.c +++ b/misrc_tools/ringbuffer.c @@ -21,22 +21,14 @@ * along with this program. If not, see . */ -#define _GNU_SOURCE +#include "shm_anon.h" #include #include -#include #include #include #include "ringbuffer.h" -#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 27) -#include - -static inline int memfd_create(const char *name, unsigned int flags) { - return syscall(__NR_memfd_create, name, flags); -} -#endif int rb_init(ringbuffer_t *rb, char *name, size_t size) { diff --git a/misrc_tools/shm_anon.h b/misrc_tools/shm_anon.h new file mode 100644 index 0000000..a699c6f --- /dev/null +++ b/misrc_tools/shm_anon.h @@ -0,0 +1,104 @@ +// based on: https://github.com/lassik/shm_open_anon/ + +// Copyright 2019 Lassi Kortela +// SPDX-License-Identifier: ISC + +#ifdef __linux__ +#define _GNU_SOURCE +#include +#include +#endif + +#include + +#include + +#include +#include +#include +#include +#include + +#undef IMPL_MEMFD +#undef IMPL_POSIX +#undef IMPL_SHM_ANON +#undef IMPL_SHM_MKSTEMP +#undef IMPL_UNLINK_OR_CLOSE + +#if defined(__linux__) +#if __GLIBC__ < 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 27) +#include +static inline int memfd_create(const char *name, unsigned int flags) { + return syscall(__NR_memfd_create, name, flags); +} +#endif +#elif defined(__FreeBSD__) +#define memfd_create(a,b) shm_open(SHM_ANON,O_RDWR,0) +#elif defined(__OpenBSD__) +#define IMPL_SHM_MKSTEMP +#else +#define IMPL_POSIX +#endif + +#if defined(IMPL_POSIX) || defined(IMPL_SHM_MKSTEMP) +#define IMPL_UNLINK_OR_CLOSE +#endif + +#ifdef IMPL_UNLINK_OR_CLOSE +static int +shm_unlink_or_close(const char *name, int fd) +{ + int save; + + if (shm_unlink(name) == -1) { + save = errno; + close(fd); + errno = save; + return -1; + } + return fd; +} +#endif + +#ifdef IMPL_POSIX +static int +memfd_create(const char *_name, unsigned int flags) +{ + char name[16] = "/shm-"; + struct timespec tv; + unsigned long r; + char *const limit = name + sizeof(name) - 1; + char *start; + char *fill; + int fd, tries; + + *limit = 0; + start = name + strlen(name); + for (tries = 0; tries < 4; tries++) { + clock_gettime(CLOCK_REALTIME, &tv); + r = (unsigned long)tv.tv_sec + (unsigned long)tv.tv_nsec; + for (fill = start; fill < limit; r /= 8) + *fill++ = '0' + (r % 8); + fd = shm_open( + name, O_RDWR | O_CREAT | O_EXCL | O_NOFOLLOW, 0600); + if (fd != -1) + return shm_unlink_or_close(name, fd); + if (errno != EEXIST) + break; + } + return -1; +} +#endif + +#ifdef IMPL_SHM_MKSTEMP +static int +memfd_create(const char *_name, unsigned int flags) +{ + char name[16] = "/shm-XXXXXXXXXX"; + int fd; + + if ((fd = shm_mkstemp(name)) == -1) + return -1; + return shm_unlink_or_close(name, fd); +} +#endif