Skip to content

Commit

Permalink
Add ch32v support
Browse files Browse the repository at this point in the history
  • Loading branch information
chintal committed Jan 25, 2025
1 parent 8a43283 commit 2f2664f
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 5 deletions.
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ebs-platform",
"version": "0.3.5",
"version": "0.4.0",
"description": "Common EBS Platform Interfaces",
"keywords": "ebs",
"repository": {
Expand Down
13 changes: 13 additions & 0 deletions src/platform/cpu.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@
static inline void global_interrupt_disable(void){
__disable_irq();
}
#elif defined __riscv
#if defined __CH32V00x_H
// Use definitions of ch32v003fun.h
static inline void global_interrupt_enable(void){
__enable_irq();
}

static inline void global_interrupt_disable(void){
__disable_irq();
}
#else
#error "RISC-V platform not supported"
#endif
#elif (defined __linux__ || defined _WIN32)
static inline void global_interrupt_enable(void){
;
Expand Down
28 changes: 27 additions & 1 deletion src/platform/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@ typedef union {

#endif

#ifdef __riscv
#if __riscv_xlen == 32
typedef struct {
uint32_t mstatus;
uint32_t mtval;
uint32_t mcause;
uint32_t mepc;
} RV32_FAULT_t;
#endif
#endif

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

Expand All @@ -34,6 +45,20 @@ void die(void) {
uint32_t bfar = *((HAL_SFR_t *)0xE000ED38);
(void) bfar;
#endif
#ifdef __riscv
#if __riscv_xlen == 32
RV32_FAULT_t fault;
#ifdef __CH32V00x_H
// It is unclear how portable this is. Presently used for
// CH32V00xx only, using primitives from ch32v003fun.h
fault.mstatus = __get_MSTATUS();
fault.mtval = __get_MTVAL();
fault.mcause = __get_MCAUSE();
fault.mepc = __get_MEPC();
#endif
(void) fault;
#endif
#endif
#if APP_ENABLE_OUTPUT_ERROR
#if ERROR_POLARITY
gpio_set_output_high(ERROR_GPIO);
Expand All @@ -46,6 +71,7 @@ void die(void) {

#pragma GCC pop_options

#if APP_ENABLE_DEBUG
#if DEBUG_TRANSPORT_TYPE == EBS_INTF_UART
#include <hal/uc/uart.h>

Expand Down Expand Up @@ -93,5 +119,5 @@ HAL_BASE_t _debug_printf(const char *format, ...){
void _debug_flush(void){

}

#endif
#endif
6 changes: 3 additions & 3 deletions src/platform/debug.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,18 @@

#include <application.h>
#include <stdarg.h>
#include "platform/types.h"
#include "types.h"


void die(void);

#if APP_ENABLE_DEBUG

HAL_BASE_t _debug_putchar(char c);
HAL_BASE_t _debug_write(const void *buffer, HAL_BASE_t len);
HAL_BASE_t _debug_printf(const char *format, va_list args);
void _debug_flush(void);

#if APP_ENABLE_DEBUG

static inline HAL_BASE_t debug_putchar(char c) {
return _debug_putchar(c);
}
Expand Down
15 changes: 15 additions & 0 deletions src/platform/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,21 @@ typedef uint32_t HAL_ADDRESS_t;
typedef uint32_t PORTSELECTOR_t;
typedef HAL_BASE_t PINSELECTOR_t;

#elif defined __riscv
// Targeting RISC-V
#if __riscv_xlen == 32
typedef uint32_t HAL_BASE_t;
typedef uint32_t HAL_INT_t;
typedef volatile uint32_t HAL_SFR_t;
typedef uint32_t HAL_ADDRESS_t;
#ifdef __CH32V00x_H
typedef uint32_t PORTSELECTOR_t;
typedef HAL_BASE_t PINSELECTOR_t;
#else
#error "RISC-V platform not supported."
#endif
#endif

#elif (defined __linux__ || defined _WIN32)
// 64-bit development platforms

Expand Down

0 comments on commit 2f2664f

Please sign in to comment.