Skip to content

Commit

Permalink
Sync with local development
Browse files Browse the repository at this point in the history
  • Loading branch information
vanvught committed Apr 17, 2024
1 parent 1f3d876 commit 9ef6749
Show file tree
Hide file tree
Showing 64 changed files with 832 additions and 517 deletions.
1 change: 1 addition & 0 deletions firmware-template-gd32/Includes.mk
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ INCLUDES+=-I../lib-gd32/${FAMILY}/${FAMILY_UC}_standard_peripheral/Include
INCLUDES+=-I../lib-gd32/${FAMILY}/CMSIS/GD/${FAMILY_UC}/Include
INCLUDES+=-I../lib-gd32/include
INCLUDES+=$(addprefix -I,$(EXTRA_INCLUDES))
INCLUDES+=

ifeq ($(findstring ENABLE_USB_HOST,$(DEFINES)), ENABLE_USB_HOST)
USB_HOST=1
Expand Down
28 changes: 14 additions & 14 deletions firmware-template-gd32/hardfault_handler.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,24 +50,24 @@ void hardfault_handler(unsigned long *hardfault_args, unsigned int lr_value) {

printf("[HardFault]\n");
printf("- Stack frame:\n");
printf(" R0 = %x\n", stacked_r0);
printf(" R1 = %x\n", stacked_r1);
printf(" R2 = %x\n", stacked_r2);
printf(" R3 = %x\n", stacked_r3);
printf(" R12 = %x\n", stacked_r12);
printf(" LR = %x\n", stacked_lr);
printf(" PC = %x\n", stacked_pc);
printf(" PSR = %x\n", stacked_psr);
printf(" R0 = %x\n", (unsigned int) stacked_r0);
printf(" R1 = %x\n", (unsigned int) stacked_r1);
printf(" R2 = %x\n", (unsigned int) stacked_r2);
printf(" R3 = %x\n", (unsigned int) stacked_r3);
printf(" R12 = %x\n", (unsigned int) stacked_r12);
printf(" LR = %x\n", (unsigned int) stacked_lr);
printf(" PC = %x\n", (unsigned int) stacked_pc);
printf(" PSR = %x\n", (unsigned int) stacked_psr);
printf("- FSR/FAR:\n");
printf(" CFSR = %x\n", cfsr);
printf(" HFSR = %x\n", SCB->HFSR);
printf(" DFSR = %x\n", SCB->DFSR);
printf(" AFSR = %x\n", SCB->AFSR);
printf(" CFSR = %x\n", (unsigned int) cfsr);
printf(" HFSR = %x\n", (unsigned int) SCB->HFSR);
printf(" DFSR = %x\n", (unsigned int) SCB->DFSR);
printf(" AFSR = %x\n", (unsigned int) SCB->AFSR);
if (cfsr & 0x0080) {
printf(" MMFAR = %x\n", memmanage_fault_address);
printf(" MMFAR = %x\n", (unsigned int) memmanage_fault_address);
}
if (cfsr & 0x8000) {
printf(" BFAR = %x\n", bus_fault_address);
printf(" BFAR = %x\n", (unsigned int) bus_fault_address);
}
printf("- Misc\n");
printf(" LR/EXC_RETURN= %x\n", lr_value);
Expand Down
8 changes: 4 additions & 4 deletions firmware-template/libs.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@ ifeq ($(findstring RDM_RESPONDER,$(DEFINES)),RDM_RESPONDER)
LIBS+=rdmsensor device
endif
ifneq ($(findstring NODE_ARTNET,$(DEFINES)),NODE_ARTNET)
ifneq ($(findstring dmxreceiver,$(LIBS)),dmxreceiver)
LIBS+=dmxreceiver
ifneq ($(findstring ,$(LIBS)),)
LIBS+=
endif
endif
endif

ifeq ($(findstring NODE_DMX,$(DEFINES)),NODE_DMX)
LIBS+=dmxreceiver
LIBS+=
endif

ifeq ($(findstring OUTPUT_DMX_SEND,$(DEFINES)),OUTPUT_DMX_SEND)
LIBS+=dmxsend
LIBS+=
endif

LIBS+=rdm dmx
Expand Down
2 changes: 1 addition & 1 deletion gd32_dmx_usb_pro/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
static constexpr char widget_mode_names[4][12] ALIGNED = {"DMX_RDM", "DMX", "RDM" , "RDM_SNIFFER" };
static constexpr TRDMDeviceInfoData deviceLabel ALIGNED = { const_cast<char*>("GD32F103RC DMX USB Pro"), 22 };

void main() {
int main() {
Hardware hw;
Display display; // Not supported, yet.
ConfigStore configStore;
Expand Down
2 changes: 1 addition & 1 deletion gd32_rdm_responder/firmware/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ void Hardware::RebootHandler() {
WS28xx::Get()->Blackout();
}

void main() {
int main() {
Hardware hw;
DisplayUdf display;
ConfigStore configStore;
Expand Down
1 change: 1 addition & 0 deletions include/stdio.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ FILE *fopen(const char *path, const char *mode);
int fclose(FILE *stream);

int fgetc(FILE *stream);
int fputc(int c, FILE *stream);

char *fgets(char *s, int size, FILE *stream);
int fputs(const char *s, FILE *stream);
Expand Down
26 changes: 26 additions & 0 deletions lib-c++/src/cxa_atexit.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* cxa_atexit.cpp
*/

#include <cstddef>

typedef void (*exitfunc_t)(void);

static exitfunc_t atexit_funcs[32];
static size_t atexit_count = 0;

extern "C" int __cxa_atexit(exitfunc_t func, [[maybe_unused]] void *arg, [[maybe_unused]] void *dso_handle) {
if (atexit_count >= sizeof(atexit_funcs) / sizeof(atexit_funcs[0]))
return -1;

atexit_funcs[atexit_count++] = func;
return 0; // Success
}

extern "C" void __call_atexit_funcs() {
for (size_t i = atexit_count; i > 0; --i) {
exitfunc_t func = atexit_funcs[i - 1];
if (func)
func();
}
}
12 changes: 6 additions & 6 deletions lib-c++/src/dso_handle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
* THE SOFTWARE.
*/

extern "C" int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {
static_cast<void>(object);
static_cast<void>(destructor);
static_cast<void>(dso_handle);
return 0;
}
//extern "C" int __aeabi_atexit(void *object, void (*destructor)(void *), void *dso_handle) {
// static_cast<void>(object);
// static_cast<void>(destructor);
// static_cast<void>(dso_handle);
// return 0;
//}

void *__dso_handle = nullptr;
11 changes: 11 additions & 0 deletions lib-c++/src/impure_prt.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* impure_prt.cpp
*/

typedef struct _reent {
int _errno; // Placeholder for the actual contents of _reent
} _reent;

// Define the global _impure_ptr. Normally points to reentrant data.
static struct _reent _reent_data = {0};
struct _reent *_impure_ptr = &_reent_data;
15 changes: 15 additions & 0 deletions lib-c/src/abort.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/*
* abort.c
*/


#ifdef NDEBUG
# undef NDEBUG
#endif

#include <assert.h>

void abort(void) {
assert(0);
for(;;);
}
5 changes: 4 additions & 1 deletion lib-c/src/gd32/time.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* @file time.c
*
*/
/* Copyright (C) 2021 by Arjan van Vught mailto:[email protected]
/* Copyright (C) 2021-2024 by Arjan van Vught mailto:[email protected]
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
Expand All @@ -23,6 +23,9 @@
* THE SOFTWARE.
*/

#pragma GCC push_options
#pragma GCC optimize ("O2")

#include <stddef.h>
#include <sys/time.h>
#include <stdint.h>
Expand Down
19 changes: 19 additions & 0 deletions lib-c/src/memchr.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*
* Copyright (c) 2013-2019, Arm Limited and Contributors. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/

#include <stddef.h>

void* memchr(const void *src, int c, size_t len) {
const unsigned char *s = src;

while (len--) {
if (*s == (unsigned char) c)
return (void*) s;
s++;
}

return NULL;
}
51 changes: 51 additions & 0 deletions lib-c/src/strncmp.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*-
* SPDX-License-Identifier: BSD-3-Clause
*
* Copyright (c) 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/

/*
* Portions copyright (c) 2018, Arm Limited and Contributors.
* All rights reserved.
*/

#include <stddef.h>

int strncmp(const char *s1, const char *s2, size_t n) {

if (n == 0)
return (0);
do {
if (*s1 != *s2++)
return (*(const unsigned char*) s1
- *(const unsigned char*) (s2 - 1));
if (*s1++ == '\0')
break;
} while (--n != 0);
return (0);
}
57 changes: 29 additions & 28 deletions lib-c/src/strstr.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,36 +35,37 @@

#include <stddef.h>

char *
strstr(string, substring)
register char *string; /* String to search. */
char *substring; /* Substring to try to find in string. */
{
register char *a, *b;
char *strstr(const char *string, const char *substring) {
/* First scan quickly through the two strings looking for a
* single-character match. When it's found, then compare the
* rest of the substring.
*/

/* First scan quickly through the two strings looking for a
* single-character match. When it's found, then compare the
* rest of the substring.
*/
const char *b = substring;

b = substring;
if (*b == 0) {
return string;
}
for ( ; *string != 0; string += 1) {
if (*string != *b) {
continue;
if (*b == 0) {
return (char *)string;
}
a = string;
while (1) {
if (*b == 0) {
return string;
}
if (*a++ != *b++) {
break;
}

for (; *string != 0; string += 1) {
if (*string != *b) {
continue;
}

const char *a = string;

while (1) {
if (*b == 0) {
return (char *)string;
}

if (*a++ != *b++) {
break;
}
}

b = substring;
}
b = substring;
}
return NULL;

return NULL;
}
Loading

0 comments on commit 9ef6749

Please sign in to comment.