Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Several improvements and fixes #285

Merged
merged 36 commits into from
Nov 17, 2024
Merged
Changes from 1 commit
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
7a0894a
Moved *ParamsConst to C++20 style
vanvught Oct 19, 2024
bab159a
Moved ARM related include files to directory /arm
vanvught Oct 19, 2024
5aeda7f
Converted malloc.c to malloc.cpp
vanvught Oct 19, 2024
bdd937e
TCNet is now header file only
vanvught Oct 19, 2024
bc15291
W.I.P. #186
vanvught Oct 19, 2024
3e285d9
Introduced callback handler for UDP packets
vanvught Oct 19, 2024
b9118f2
RDMNet LLRP fixed issue with GetDefaultRoute
vanvught Oct 19, 2024
c87f41a
Minor code cleanup
vanvught Oct 19, 2024
a82f112
Updates for previous commits
vanvught Oct 19, 2024
b59bf80
Fix for GD32
vanvught Oct 19, 2024
40f4149
Fix for workflow run
vanvught Oct 19, 2024
1645a65
Improved ArtNetNode::SendPollReply
vanvught Oct 20, 2024
57cfb8f
Added support for SPI LCD driver ST7735S
vanvught Nov 8, 2024
f5e8148
Updated Eclipse project settings
vanvught Nov 8, 2024
b744eb4
Added optimize ("-fprefetch-loop-arrays")
vanvught Nov 8, 2024
cded66a
Added defines DEBUG_EMAC and DEBUG_NET_PHY
vanvught Nov 8, 2024
69a9dd8
Moved timers.h to softwaretimers.h
vanvught Nov 8, 2024
e833856
Minor code cleanup
vanvught Nov 8, 2024
04a7d22
Added atexit.cpp
vanvught Nov 8, 2024
7c8d48c
Changed compiler setting -O2 to -Os
vanvught Nov 10, 2024
9e540e8
Updated Eclipse project settings
vanvught Nov 10, 2024
7cfcc63
Major cleanup spi_flash.cpp
vanvught Nov 11, 2024
bc3b560
Fixed issue with pixel multi and dmx sync
vanvught Nov 11, 2024
e738921
Removed rdmsoftwareversion.cpp
vanvught Nov 11, 2024
5577fc9
Added CONFIG_CLIB_ASSERT_REBOOT
vanvught Nov 11, 2024
7dbaedd
Removed pragma GCC optimize ("Os")
vanvught Nov 11, 2024
b9537f7
Fixed issue with pixel multi and dmx sync
vanvught Nov 11, 2024
d0f6882
Minor code cleanup
vanvught Nov 11, 2024
8d8e71d
Fixed issue with pixel multi and dmx sync
vanvught Nov 11, 2024
60f7858
Added support for bitbang SPI
vanvught Nov 11, 2024
1d3ac61
Removed #include "networkconst.h"
vanvught Nov 11, 2024
0a4bd13
Updated build_h3-firmware.sh
vanvught Nov 12, 2024
aa5e3ec
Updated SOFTWARE_VERSION[]
vanvught Nov 12, 2024
b3dba55
Moved RDM E1.37-2 code from network.cpp to rdmhandlere137.cpp
vanvught Nov 16, 2024
950cce5
Updated make files
vanvught Nov 16, 2024
ed4468e
Fix for Sync
vanvught Nov 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
W.I.P. #186
- Moved SoftwareTimers to timers.cpp
- Converted class I2cDetect to free standing function i2c_detect
  • Loading branch information
vanvught committed Oct 19, 2024
commit bc15291b5e50a33232c4d39c7ff693e0de167fa3
13 changes: 5 additions & 8 deletions lib-dmx/src/h3/multi/dmx.cpp
Original file line number Diff line number Diff line change
@@ -154,9 +154,6 @@ static volatile uint32_t s_nRdmDataReadIndex[dmx::config::max::PORTS];

static volatile PortState sv_PortState[dmx::config::max::PORTS] ALIGNED;

static char CONSOLE_ERROR[] ALIGNED = "DMXDATA %\n";
static constexpr auto CONSOLE_ERROR_LENGTH = (sizeof(CONSOLE_ERROR) / sizeof(CONSOLE_ERROR[0]));

static void irq_timer0_dmx_multi_sender([[maybe_unused]]uint32_t clo) {
logic_analyzer::ch0_set();

@@ -413,29 +410,29 @@ static void __attribute__((interrupt("FIQ"))) fiq_dmx_multi(void) {
if (nIIR & UART_IIR_IID_RD) {
fiq_in_handler(0, reinterpret_cast<H3_UART_TypeDef *>(H3_UART1_BASE), nIIR);
H3_GIC_CPUIF->EOI = H3_UART1_IRQn;
gic_unpend(H3_UART1_IRQn);
gic_unpend<H3_UART1_IRQn>();
}

nIIR = H3_UART2->O08.IIR;
if (nIIR & UART_IIR_IID_RD) {
fiq_in_handler(1, reinterpret_cast<H3_UART_TypeDef *>(H3_UART2_BASE), nIIR);
H3_GIC_CPUIF->EOI = H3_UART2_IRQn;
gic_unpend(H3_UART2_IRQn);
gic_unpend<H3_UART2_IRQn>();
}
#if defined (ORANGE_PI_ONE)
nIIR = H3_UART3->O08.IIR;
if (nIIR & UART_IIR_IID_RD) {
fiq_in_handler(2, reinterpret_cast<H3_UART_TypeDef *>(H3_UART3_BASE), nIIR);
H3_GIC_CPUIF->EOI = H3_UART3_IRQn;
gic_unpend(H3_UART3_IRQn);
gic_unpend<H3_UART3_IRQn>();
}

# ifndef DO_NOT_USE_UART0
nIIR = H3_UART0->O08.IIR;
if (nIIR & UART_IIR_IID_RD) {
fiq_in_handler(3, reinterpret_cast<H3_UART_TypeDef *>(H3_UART0_BASE), nIIR);
H3_GIC_CPUIF->EOI = H3_UART0_IRQn;
gic_unpend(H3_UART0_IRQn);
gic_unpend<H3_UART0_IRQn>();
}
# endif
#endif
@@ -656,7 +653,7 @@ Dmx::Dmx() {
# endif
#endif

irq_timer_init();
irq_handler_init();
irq_timer_set(IRQ_TIMER_0, irq_timer0_dmx_multi_sender);
irq_timer_set(IRQ_TIMER_1, irq_timer1_dmx_receive);

4 changes: 2 additions & 2 deletions lib-dmx/src/h3/single/dmx.cpp
Original file line number Diff line number Diff line change
@@ -422,7 +422,7 @@ static void __attribute__((interrupt("FIQ"))) fiq_dmx(void) {
}

H3_GIC_CPUIF->EOI = UART_IRQN;
gic_unpend(UART_IRQN);
gic_unpend<UART_IRQN>();
} else {
console_error("spurious interrupt\n");
}
@@ -539,7 +539,7 @@ Dmx::Dmx() {

sv_DmxTransmitState = IDLE;

irq_timer_init();
irq_handler_init();

irq_timer_set(IRQ_TIMER_1, irq_timer1_dmx_receive);
H3_TIMER->TMR1_INTV = 0xB71B00; // 1 second
2 changes: 1 addition & 1 deletion lib-dmx/src/rpi/dmx.cpp
Original file line number Diff line number Diff line change
@@ -420,7 +420,7 @@ Dmx::Dmx() {
sv_DmxTransmitState = IDLE;
sv_doDmxTransmitAlways = false;

irq_timer_init();
irq_handler_init();

irq_timer_set(IRQ_TIMER_3, irq_timer3_dmx_receive);
BCM2835_ST->C3 = BCM2835_ST->CLO + (uint32_t) 1000000;
215 changes: 163 additions & 52 deletions lib-h3/.cproject

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions lib-h3/.settings/language.settings.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project>
<configuration id="cdt.managedbuild.toolchain.gnu.cross.base.2012143185" name="H3">
<configuration id="ilg.gnuarmeclipse.managedbuild.cross.toolchain.base.309283989.303033930.282193158" name="H3">
<extension point="org.eclipse.cdt.core.LanguageSettingsProvider">
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider copy-of="extension" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser"/>
<provider class="org.eclipse.cdt.internal.build.crossgcc.CrossGCCBuiltinSpecsDetector" console="false" env-hash="-869088479795149684" id="org.eclipse.cdt.build.crossgcc.CrossGCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="true" env-hash="677701191608133647" id="org.eclipse.embedcdt.managedbuild.cross.arm.core.GCCBuiltinSpecsDetector" keep-relative-paths="false" name="CDT Arm Cross GCC Built-in Compiler Settings" parameter="${COMMAND} ${FLAGS} ${cross_toolchain_flags} -E -P -v -dD &quot;${INPUTS}&quot;" prefer-non-shared="true">
<language-scope id="org.eclipse.cdt.core.gcc"/>
<language-scope id="org.eclipse.cdt.core.g++"/>
</provider>
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuildCommandParser" id="org.eclipse.cdt.managedbuilder.core.GCCBuildCommandParser" keep-relative-paths="false" name="CDT GCC Build Output Parser" parameter="([^/\\\\]*)((g?cc)|([gc]\+\+)|(clang))" prefer-non-shared="true"/>
<provider-reference id="org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider" ref="shared-provider"/>
</extension>
</configuration>
82 changes: 20 additions & 62 deletions lib-h3/arm/gic.c → lib-h3/arm/gic.cpp
Original file line number Diff line number Diff line change
@@ -29,12 +29,9 @@
# include <stdio.h>
#endif

#include "arm/synchronize.h"
#include "h3.h"
#include "arm/gic.h"

static uint16_t max_interrupts;
static uint8_t impemented_cpu_interfaces;

#define ICENABLE_N (sizeof(H3_GIC_DIST->ICENABLE) / sizeof(H3_GIC_DIST->ICENABLE[0]))
#define ICPEND_N (sizeof(H3_GIC_DIST->ICPEND) / sizeof(H3_GIC_DIST->ICPEND[0]))
#define ICACTIVE_N (sizeof(H3_GIC_DIST->ICACTIVE) / sizeof(H3_GIC_DIST->ICACTIVE[0]))
@@ -54,82 +51,44 @@ static uint8_t impemented_cpu_interfaces;
#define GICC_CTL_ENABLE_GRP1 (1 << 1)
#define GICC_CTL_ENABLE_FIQ (1 << 3)

void __attribute__((cold)) gic_init(void) {
unsigned i;

max_interrupts = (uint16_t) (((H3_GIC_DIST->TYPE & 0x1F) + 1) * 32);
impemented_cpu_interfaces = (uint8_t) (1 + (uint8_t) ((H3_GIC_DIST->TYPE >> 5) & 0x7));

/* Initialize Distributor */

H3_GIC_DIST->CTL = 0;

for (i = 0; i < ICENABLE_N; i++) {
H3_GIC_DIST->ICENABLE[i] = 0xFFFFFFFF; // Writing 1 to a Clear-enable bit disables forwarding
}

for (i = 0; i < ICPEND_N; i++) {
H3_GIC_DIST->ICPEND[i] = 0xFFFFFFFF; // Writing 1 to a Clear-pending bit clears the pending states
}

for (i = 0; i < ICACTIVE_N; i++) {
H3_GIC_DIST->ICACTIVE[i] = 0xFFFFFFFF; // Writing 1 to a Clear-active bit Deactivates the corresponding interrupt
}

for (i = 0; i < IPRIORITY_N; i++) {
H3_GIC_DIST->IPRIORITY[i] = 0x0; // TODO What is this?
}

for (i = 0; i < ITARGETS_N; i++) {
H3_GIC_DIST->ITARGETS[i] = 0x01010101; // TODO This needs be changed for multi-core support
}

for (i = 0; i < ICFG_N; i++) {
H3_GIC_DIST->ICFG[i] = 0x0; // 0 => Corresponding interrupt is level-sensitive.
}
extern "C" void clean_data_cache() __attribute__ ((optimize (3)));

void __attribute__((cold)) gic_init() {
GIC_Enable();
H3_GIC_DIST->CTL = CTL_GRP0_ENABLE | CTL_GRP1_ENABLE; // Group 1 -> IRQ, Group 0 -> FIQ

/* Initialize CPU Interface */
H3_GIC_CPUIF->PM = 0xFFFFFFFF;

H3_GIC_CPUIF->CTL = GICC_CTL_ENABLE_GRP0 | GICC_CTL_ENABLE_GRP1 | GICC_CTL_ENABLE_FIQ;
GICInterface->CTLR = GICC_CTL_ENABLE_GRP0 | GICC_CTL_ENABLE_GRP1 | GICC_CTL_ENABLE_FIQ;
}

static void int_config(H3_IRQn_TypeDef n, __attribute__((unused)) GIC_CORE_TypeDef cpu, GIC_GROUP_TypeDef group) {
static void int_config(H3_IRQn_TypeDef nIRQ, [[maybe_unused]] GIC_CORE_TypeDef cpu, GIC_GROUP_TypeDef group) {
#ifndef NDEBUG
printf("int_config(H3_IRQn_TypeDef %d,cpu %d, GIC_GROUP_TypeDef %d)\n", n, cpu, group);
printf("int_config(H3_IRQn_TypeDef %d,cpu %d, GIC_GROUP_TypeDef %d)\n", nIRQ, cpu, group);
#endif

clean_data_cache();
dmb();
__DMB();

const uint32_t index = n / 32;
uint32_t mask = 1U << (n % 32);
GIC_EnableIRQ(nIRQ);
GIC_SetGroup(nIRQ, static_cast<uint32_t>(group));

H3_GIC_DIST->ISENABLE[index] = mask;
__ISB();

#ifndef NDEBUG
const auto index = nIRQ / 32;
auto mask = 1U << (nIRQ % 32);
printf("H3_GIC_DIST->ISENABLE[%d] = %p [%p]\n", index, mask, H3_GIC_DIST->ISENABLE[index]);
#endif

mask = (uint32_t)group << (n % 32);

H3_GIC_DIST->IGROUP[index] |= mask;

isb();

#ifndef NDEBUG
mask = static_cast<uint32_t>(group << (nIRQ % 32));
printf("H3_GIC_DIST->IGROUP[%d] = %p [%p]\n", index, mask, H3_GIC_DIST->IGROUP[index]);
#endif
}

void gic_irq_config(H3_IRQn_TypeDef n, GIC_CORE_TypeDef cpu) {
int_config(n, cpu, GIC_GROUP1);
void gic_irq_config(H3_IRQn_TypeDef nIRQ, GIC_CORE_TypeDef nCPU) {
int_config(nIRQ, nCPU, GIC_GROUP1);
gic_int_dump(nIRQ);
}

void gic_fiq_config(H3_IRQn_TypeDef n, GIC_CORE_TypeDef cpu) {
int_config(n, cpu, GIC_GROUP0);
void gic_fiq_config(H3_IRQn_TypeDef nIRQ, GIC_CORE_TypeDef nCPU) {
int_config(nIRQ, nCPU, GIC_GROUP0);
}

void gic_init_dump(void) {
@@ -174,11 +133,10 @@ void gic_int_dump(__attribute__((unused)) H3_IRQn_TypeDef n) {
uint32_t index = n / 32;
uint32_t mask = 1U << (n % 32);

GIC_GROUP_TypeDef group = (GIC_GROUP_TypeDef) ((H3_GIC_DIST->IGROUP[index] & mask) == mask);
GIC_GROUP_TypeDef group = static_cast<GIC_GROUP_TypeDef>((H3_GIC_DIST->IGROUP[index] & mask) == mask);
bool is_enabled = (H3_GIC_DIST->ISENABLE[index] & mask) == mask;
bool is_pending = (H3_GIC_DIST->ISPEND[index] & mask) == mask;

printf("H3_IRQn=%d (index=%d,mask=%p), group=%d, enabled=%d, pending=%d\n", n, index, mask, group, is_enabled, is_pending);
#endif
}

46 changes: 18 additions & 28 deletions lib-h3/include/arm/gic.h
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
* @file gic.h
*
*/
/* Copyright (C) 2018-2020 by Arjan van Vught mailto:info@orangepi-dmx.nl
/* Copyright (C) 2018-2024 by Arjan van Vught mailto:info@gd32-dmx.org
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
@@ -107,45 +107,39 @@ typedef struct {
#define H3_GIC_DIST (_CAST(GIC_DIST_TypeDef *)(H3_GIC_DIST_BASE))
#define H3_GIC_CPUIF (_CAST(GIC_CPUIF_TypeDef *)(H3_GIC_CPUIF_BASE))

#ifdef __cplusplus
extern "C" {
#endif

extern void gic_init(void);
void gic_init();

extern void gic_irq_config(H3_IRQn_TypeDef n, GIC_CORE_TypeDef cpu);
extern void gic_fiq_config(H3_IRQn_TypeDef n, GIC_CORE_TypeDef cpu);
void gic_irq_config(H3_IRQn_TypeDef, GIC_CORE_TypeDef);
void gic_fiq_config(H3_IRQn_TypeDef, GIC_CORE_TypeDef);

extern void gic_init_dump(void);
extern void gic_int_dump(H3_IRQn_TypeDef n);
void gic_init_dump();
void gic_int_dump(H3_IRQn_TypeDef);

inline static void gic_unpend(H3_IRQn_TypeDef irq) {
const uint32_t index = irq / 32;
const uint32_t mask = 1U << (irq % 32);

H3_GIC_DIST->ICPEND[index] = mask;
template<H3_IRQn_TypeDef IRQn>
inline void gic_unpend() {
constexpr auto nIndex = IRQn / 32;
constexpr auto nMask = 1U << (IRQn % 32);
GICDistributor->ICPENDR[nIndex] = nMask;
}

#include "arm/synchronize.h"

inline static uint32_t gic_get_priority(H3_IRQn_TypeDef IRQn) {
inline uint32_t gic_get_priority(H3_IRQn_TypeDef IRQn) {
return (H3_GIC_DIST->IPRIORITY[IRQn / 4U] >> ((IRQn % 4U) * 8U)) & 0xFFUL;
}

inline static void gic_set_priority(H3_IRQn_TypeDef IRQn, uint32_t priority) {
inline void gic_set_priority(H3_IRQn_TypeDef IRQn, uint32_t priority) {
const uint32_t mask = H3_GIC_DIST->IPRIORITY[IRQn / 4U] & ~(0xFFUL << ((IRQn % 4U) * 8U));
H3_GIC_DIST->IPRIORITY[IRQn / 4U] = mask | ((priority & 0xFFUL) << ((IRQn % 4U) * 8U));
}

/**
* https://github.com/ARM-software/CMSIS_5/blob/develop/CMSIS/Core_A/Source/irq_ctrl_gic.c#L239
*/
inline static uint32_t gic_get_active_fiq() {
inline uint32_t gic_get_active_fiq() {
/* Dummy read to avoid GIC 390 errata 801120 */
(void) H3_GIC_CPUIF->HPPI;

const uint32_t fiqn = H3_GIC_CPUIF->IA;
dsb();
__DSB();

/* Workaround GIC 390 errata 733075 (GIC-390_Errata_Notice_v6.pdf, 09-Jul-2014) */
/* The following workaround code is for a single-core system. It would be */
@@ -157,18 +151,14 @@ inline static uint32_t gic_get_active_fiq() {

if ((fiqn == 0) || (fiqn >= 0x3FE)) {
/* Unlock the CPU interface with a dummy write to Interrupt Priority Register */
const uint32_t prio = gic_get_priority((H3_IRQn_TypeDef) 0);
gic_set_priority((H3_IRQn_TypeDef) 0, prio);
const uint32_t prio = gic_get_priority(static_cast<H3_IRQn_TypeDef>(0));
gic_set_priority(static_cast<H3_IRQn_TypeDef>(0), prio);

dsb();
__DSB();
/* End of Workaround GIC 390 errata 733075 */
}

return fiqn;
}

#ifdef __cplusplus
}
#endif

#endif /* GIC_H_ */
11 changes: 10 additions & 1 deletion lib-h3/include/h3.h
Original file line number Diff line number Diff line change
@@ -163,6 +163,7 @@ typedef enum T_H3_IRQn {
H3_UART2_IRQn = 34,
H3_UART3_IRQn = 35,
H3_PA_EINT_IRQn = 43,
H3_PG_EINT_IRQn = 49,
H3_TIMER0_IRQn = 50,
H3_TIMER1_IRQn = 51,
H3_AUDIO_CODEC_IRQn = 61,
@@ -826,8 +827,16 @@ extern void h3_dump_memory_mapping(void);
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#pragma GCC diagnostic ignored "-Wsign-conversion"

#ifdef __cplusplus
#pragma GCC diagnostic ignored "-Wold-style-cast"
#endif
#include "core_ca.h"
#ifdef __cplusplus
extern "C" {
#endif
#include "irq_ctrl.h"
#ifdef __cplusplus
}
#endif

#endif /* H3_H_ */
10 changes: 1 addition & 9 deletions lib-h3/include/irq_timer.h
Original file line number Diff line number Diff line change
@@ -36,18 +36,10 @@ typedef enum irq_timers {
typedef void (*thunk_irq_timer_t)(const uint32_t);
typedef void (*thunk_irq_timer_arm_t)();

#ifdef __cplusplus
extern "C" {
#endif

extern void irq_timer_set(_irq_timers, thunk_irq_timer_t);
extern void irq_timer_arm_physical_set(thunk_irq_timer_arm_t);
extern void irq_timer_arm_virtual_set(thunk_irq_timer_arm_t, uint32_t);

extern void irq_timer_init(void);

#ifdef __cplusplus
}
#endif
extern void irq_handler_init();

#endif /* IRQ_TIMER_H_ */
4 changes: 1 addition & 3 deletions lib-h3/src/debug_exception.c
Original file line number Diff line number Diff line change
@@ -25,9 +25,7 @@

#include <stdio.h>

#if defined (H3)
# include "h3.h"
#endif
#include "h3.h"

void console_set_fg_color(int);

2 changes: 1 addition & 1 deletion lib-h3/src/h3_codec.cpp
Original file line number Diff line number Diff line change
@@ -425,7 +425,7 @@ static void __attribute__((interrupt("FIQ"))) codec_fiq_handler(void) {
H3_DMA->IRQ_PEND0 |= H3_DMA->IRQ_PEND0;

H3_GIC_CPUIF->EOI = H3_DMA_IRQn;
gic_unpend(H3_DMA_IRQn);
gic_unpend<H3_DMA_IRQn>();
isb();

#ifdef LOGIC_ANALYZER
Loading