Skip to content

Commit

Permalink
CPCd Release: 4.4.2
Browse files Browse the repository at this point in the history
  • Loading branch information
silabsbot authored and Alexandre Autotte committed Apr 10, 2024
1 parent 283b31a commit 37bc19f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 23 deletions.
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.10)

project(cpcd
VERSION "4.4.1.0"
VERSION "4.4.2.0"
LANGUAGES C)
set(CPC_LIBRARY_API_VERSION "3")
set(CPC_PROTOCOL_VERSION "5")
Expand Down Expand Up @@ -88,6 +88,7 @@ endif()
add_library(cpc SHARED)
target_stds(cpc C 99 POSIX 2008)
target_link_libraries(cpc PRIVATE Interface::Warnings)
target_link_libraries(cpc PRIVATE Threads::Threads)
target_sources(cpc PRIVATE misc/sleep.c)
target_sources(cpc PRIVATE misc/sl_slist.c)
target_sources(cpc PRIVATE lib/sl_cpc.c)
Expand All @@ -98,6 +99,7 @@ if(COMPILE_LTTNG)
target_link_libraries(cpc PRIVATE LTTng::UST)
endif()

target_include_directories(cpc PUBLIC "${CMAKE_CURRENT_SOURCE_DIR}/lib")
target_include_directories(cpc PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}")
target_include_directories(cpc PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/include")
target_include_directories(cpc PRIVATE "${CMAKE_CURRENT_BINARY_DIR}/autogen")
Expand All @@ -112,7 +114,7 @@ install(

# CPCd Config file path
if(NOT DEFINED CPCD_CONFIG_FILE_PATH)
set(CPCD_CONFIG_FILE_PATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_SYSCONFDIR}/cpcd.conf)
set(CPCD_CONFIG_FILE_PATH "${CMAKE_INSTALL_FULL_SYSCONFDIR}/cpcd.conf")
endif()
add_definitions(-DCPCD_CONFIG_FILE_PATH="${CPCD_CONFIG_FILE_PATH}")
message(STATUS "CPCD_CONFIG_FILE_PATH=${CPCD_CONFIG_FILE_PATH}")
Expand Down
13 changes: 11 additions & 2 deletions driver/driver_ezsp.c
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,17 @@ static sl_status_t firmware_upgrade_fsm(struct fwu_image *image,
status = wait_irq_falling_edge(spi, IRQ_FALLING_EDGE_TIMEOUT_MS);

if (status == SL_STATUS_TIMEOUT) {
TRACE_EZSP_SPI("[FAIL] timeout");
return SL_STATUS_TIMEOUT;
if (gpio_read(spi->irq_gpio) == GPIO_VALUE_HIGH) {
TRACE_EZSP_SPI("[FAIL] timeout");
return SL_STATUS_TIMEOUT;
} else {
// On Series 1, the chip reset occurring when asking to reboot into bootloader
// seems to reset the GPIO peripheral way earlier than Series 2, resulting
// in the IRQ falling-edge happening before the SPI driver closes the IRQ
// pin and this EZSP driver opening it. This results in the event being lost.
// By doing a second check after the timeout, if the pin is low we can assume
// that the falling-edge occurred and it was just missed.
}
}

gpio_clear_irq(spi->irq_gpio);
Expand Down
20 changes: 8 additions & 12 deletions driver/driver_uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ static bool delimit_and_push_frames_to_core(uint8_t *buffer, size_t *buffer_head
/*
* Insures the start of the buffer is aligned with the start of a valid checksum
* and re-synch in case the buffer starts with garbage.
*/
static bool header_re_synch(uint8_t *buffer, size_t *buffer_head);
******************************************************************************/
static bool header_synch(uint8_t *buffer, size_t *buffer_head);

void driver_uart_init(int *fd_to_core, int *fd_notify_core, const char *device, unsigned int baudrate, bool hardflow)
{
Expand Down Expand Up @@ -521,9 +521,9 @@ static void driver_uart_process_uart(void)
while (1) {
switch (state) {
case EXPECTING_HEADER:
/* Synchronize the start of 'buffer' with the start of a valid header with valid checksum. */
if (header_re_synch(buffer, &buffer_head)) {
/* We are synchronized on a valid header, start delimiting the data that follows into a frame. */
// Synchronize the start of 'buffer' with the start of a valid header with valid checksum.
if (header_synch(buffer, &buffer_head)) {
// We are synchronized on a valid header, start delimiting the data that follows into a frame.
state = EXPECTING_PAYLOAD;
} else {
/* We went through all the data contained in 'buffer' and haven't synchronized on a header.
Expand Down Expand Up @@ -588,34 +588,30 @@ static bool validate_header(uint8_t *header_start)
return true;
}

static bool header_re_synch(uint8_t *buffer, size_t *buffer_head)
static bool header_synch(uint8_t *buffer, size_t *buffer_head)
{
if (*buffer_head < SLI_CPC_HDLC_HEADER_RAW_SIZE) {
/* There's not enough data for a header, nothing to re-synch */
// There's not enough data for a header, nothing to synch
return false;
}

/* If we think of a header like a sliding window of width SLI_CPC_HDLC_HEADER_RAW_SIZE,
* then we can slide it 'num_header_combination' times over the data. */
const size_t num_header_combination = *buffer_head - SLI_CPC_HDLC_HEADER_RAW_SIZE + 1;

TRACE_DRIVER("re-sync : Will test %i header combination", num_header_combination);

size_t i;

for (i = 0; i != num_header_combination; i++) {
if (validate_header(&buffer[i])) {
if (i == 0) {
/* The start of the buffer is aligned with a good header, don't do anything */
TRACE_DRIVER("re-sync : The start of the buffer is aligned with a good header");
// The start of the buffer is aligned with a good header, don't do anything
} else {
/* We had 'i' number of bad bytes until we struck a good header, move back the data
* to the beginning of the buffer */
memmove(&buffer[0], &buffer[i], *buffer_head - i);

/* We crushed 'i' bytes at the start of the buffer */
*buffer_head -= i;
TRACE_DRIVER("re-sync : had '%u' number of bad bytes until we struck a good header", i);
}
return true;
} else {
Expand Down
5 changes: 2 additions & 3 deletions libcpc.pc.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
prefix=@CMAKE_INSTALL_PREFIX@
exec_prefix=${prefix}
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
libdir=${exec_prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=@CMAKE_INSTALL_FULL_INCLUDEDIR@
libdir=@CMAKE_INSTALL_FULL_LIBDIR@

Name: cpc
Description: @PROJECT_DESCRIPTION@
Expand Down
8 changes: 4 additions & 4 deletions misc/exit.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,20 +65,20 @@ void exit_init(pthread_t main_thread_id)
// Block signals so that they aren't handled
// according to their default dispositions.
ret = sigprocmask(SIG_BLOCK, &mask, NULL);
FATAL_ON(ret == -1);
FATAL_SYSCALL_ON(ret == -1);

// Create crash fd and signal fd
{
crash_eventfd = eventfd(0, // Start with 0 value
EFD_CLOEXEC);
FATAL_ON(crash_eventfd == -1);
FATAL_SYSCALL_ON(crash_eventfd == -1);

graceful_exit_eventfd = eventfd(0, // Start with 0 value
EFD_CLOEXEC);
FATAL_ON(graceful_exit_eventfd == -1);
FATAL_SYSCALL_ON(graceful_exit_eventfd == -1);

graceful_exit_signalfd = signalfd(-1, &mask, SFD_CLOEXEC);
FATAL_ON(graceful_exit_signalfd == -1);
FATAL_SYSCALL_ON(graceful_exit_signalfd == -1);
}

// Setup epoll for those fds
Expand Down

0 comments on commit 37bc19f

Please sign in to comment.