Skip to content

Commit 0afa0bd

Browse files
committed
Fix DMX input indexing and simplify timer clears
Use an explicit index variable when storing DMX data to avoid the post-increment-in-assignment pattern (prevents potential undefined behavior/overflow when updating slots_in_packet). Also remove redundant static_cast<uint32_t> around bitwise negation when clearing timer interrupt flags in multiple IRQ handlers (TIMER1, TIMER4, TIMER6 and their channel clears) to simplify the code and improve clarity.
1 parent b4b5316 commit 0afa0bd

2 files changed

Lines changed: 15 additions & 12 deletions

File tree

lib-dmx/.settings/language.settings.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<provider copy-of="extension" id="org.eclipse.cdt.ui.UserLanguageSettingsProvider"/>
66
<provider-reference id="org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider" ref="shared-provider"/>
77
<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"/>
8-
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1502105070734755712" 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">
8+
<provider class="org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector" console="false" env-hash="1502105672097326095" 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">
99
<language-scope id="org.eclipse.cdt.core.gcc"/>
1010
<language-scope id="org.eclipse.cdt.core.g++"/>
1111
</provider>

lib-dmx/src/gd32/dmx.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,11 @@ void IrqHandlerDmxRdmInput() {
372372
case dmx::TxRxState::kDmxData: {
373373
#if defined(CONFIG_DMX_DOUBLE_INPUT_BUFFER)
374374
dmx_data_buffer.slots_in_packet &= ~dmx::kDmxSlotsCompleteFlag;
375-
dmx_data_buffer.data[dmx_data_buffer.slots_in_packet++] = kData;
376-
375+
auto index = dmx_data_buffer.slots_in_packet;
376+
dmx_data_buffer.data[index] = kData;
377+
index++;
378+
dmx_data_buffer.slots_in_packet = index;
379+
377380
if (dmx_data_buffer.slots_in_packet > dmx::kChannelsMax) {
378381
dmx_data_buffer.slots_in_packet |= dmx::kDmxSlotsCompleteFlag;
379382

@@ -604,7 +607,7 @@ void TIMER1_IRQHandler() {
604607
}
605608
}
606609

607-
TIMER_INTF(TIMER1) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH0);
610+
TIMER_INTF(TIMER1) = ~TIMER_INT_FLAG_CH0;
608611
}
609612
#endif // defined(DMX_USE_USART0)
610613
// USART 1
@@ -673,7 +676,7 @@ void TIMER1_IRQHandler() {
673676
assert(false);
674677
}
675678

676-
TIMER_INTF(TIMER1) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH1);
679+
TIMER_INTF(TIMER1) = ~TIMER_INT_FLAG_CH1;
677680
}
678681
#endif // defined(DMX_USE_USART1)
679682
// USART 2
@@ -743,7 +746,7 @@ void TIMER1_IRQHandler() {
743746
assert(false);
744747
}
745748

746-
TIMER_INTF(TIMER1) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH2);
749+
TIMER_INTF(TIMER1) = ~TIMER_INT_FLAG_CH2;
747750
}
748751
#endif // defined(DMX_USE_USART2)
749752
// UART 3
@@ -811,7 +814,7 @@ void TIMER1_IRQHandler() {
811814
assert(false);
812815
}
813816

814-
TIMER_INTF(TIMER1) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH3);
817+
TIMER_INTF(TIMER1) = ~TIMER_INT_FLAG_CH3;
815818
}
816819
#endif // defined(DMX_USE_UART3)
817820
// Clear all remaining interrupt flags (safety measure)
@@ -888,7 +891,7 @@ void TIMER4_IRQHandler() {
888891
assert(false);
889892
}
890893

891-
TIMER_INTF(TIMER4) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH0);
894+
TIMER_INTF(TIMER4) = ~TIMER_INT_FLAG_CH0;
892895
}
893896
#endif // defined(DMX_USE_UART4)
894897
// USART 5
@@ -959,7 +962,7 @@ void TIMER4_IRQHandler() {
959962
assert(false);
960963
}
961964

962-
TIMER_INTF(TIMER4) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH1);
965+
TIMER_INTF(TIMER4) = ~TIMER_INT_FLAG_CH1;
963966
}
964967
#endif // defined(DMX_USE_USART5)
965968
// UART 6
@@ -1020,7 +1023,7 @@ void TIMER4_IRQHandler() {
10201023
assert(false);
10211024
}
10221025

1023-
TIMER_INTF(TIMER4) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH2);
1026+
TIMER_INTF(TIMER4) = ~TIMER_INT_FLAG_CH2;
10241027
}
10251028
#endif // defined(DMX_USE_UART6)
10261029
// UART 7
@@ -1081,7 +1084,7 @@ void TIMER4_IRQHandler() {
10811084
assert(false);
10821085
}
10831086

1084-
TIMER_INTF(TIMER4) = static_cast<uint32_t>(~TIMER_INT_FLAG_CH3);
1087+
TIMER_INTF(TIMER4) = ~TIMER_INT_FLAG_CH3;
10851088
}
10861089
#endif // defined(DMX_USE_UART7)
10871090
// Clear all remaining interrupt flags (safety measure)
@@ -1103,7 +1106,7 @@ void TIMER6_IRQHandler() {
11031106
}
11041107

11051108
// Clear all remaining interrupt flags (safety measure)
1106-
TIMER_INTF(TIMER6) = static_cast<uint32_t>(~kIntFlag);
1109+
TIMER_INTF(TIMER6) = ~kIntFlag;
11071110
}
11081111

11091112
// USART 0

0 commit comments

Comments
 (0)