diff --git a/.vscode/settings.json b/.vscode/settings.json index 1846aa58..a0e17d56 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -20,7 +20,7 @@ "editor.trimAutoWhitespace": true, "editor.autoClosingQuotes": "always", "editor.autoClosingBrackets": "always", - "editor.wordBasedSuggestions": true, + "editor.wordBasedSuggestions": "matchingDocuments", "editor.insertSpaces": false, "editor.autoIndent": "advanced", "editor.detectIndentation": true, @@ -28,7 +28,6 @@ "editor.columnSelection": false, "editor.colorDecorators": true, "editor.cursorBlinking": "blink", - "editor.lightbulb.enabled": true, "editor.lineNumbers": "on", "editor.suggest.showFunctions": true, "diffEditor.codeLens": true, diff --git a/README.md b/README.md index 3cb4dc80..73cca69f 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ </div> </body> -> **Version (arch:2 | major:4 | minor:2): 1.4.0** +> **Version (arch:2 | major:4 | minor:2): 1.4.1** > [![GitHub CI](https://github.com/VisorFolks/cyancore/actions/workflows/github_ci.yml/badge.svg)](https://github.com/VisorFolks/cyancore/actions/workflows/github_ci.yml) diff --git a/mk/mk_helper.mk b/mk/mk_helper.mk index 57c2ddd7..b9bc74c2 100644 --- a/mk/mk_helper.mk +++ b/mk/mk_helper.mk @@ -33,3 +33,7 @@ ifeq ($($(1)),1) include $(2) endif endef + +define get_tc_version + TC_VER := $(firstword $(strip $(shell $(1)-gcc --version | grep -m 1 -Po '\s(\d{1,}\.\d{1,}\.\d{1,})'))) +endef diff --git a/mk/tc.mk b/mk/tc.mk index 9e920770..cda078c8 100644 --- a/mk/tc.mk +++ b/mk/tc.mk @@ -12,6 +12,7 @@ include mk/path.mk ifeq ($(findstring arm,$(ARCH)),arm) TC ?= $(TOOLS_ROOT)/arm-toolchain/bin/arm-none-eabi +$(eval $(call get_tc_version,$(TC))) # Sets TC_VER TI := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/include-fixed/ TI += $(TOOLS_ROOT)/arm-toolchain/arm-none-eabi/include/ TL := $(TOOLS_ROOT)/arm-toolchain/lib/gcc/arm-none-eabi/$(TC_VER)/$(TL_TYPE)/ @@ -19,6 +20,7 @@ endif ifeq ($(findstring riscv,$(ARCH)),riscv) TC ?= $(TOOLS_ROOT)/risc-v-toolchain/bin/riscv64-unknown-elf +$(eval $(call get_tc_version,$(TC))) # Sets TC_VER TI := $(TOOLS_ROOT)/risc-v-toolchain/lib/gcc/riscv64-unknown-elf/$(TC_VER)/include-fixed/ TI += $(TOOLS_ROOT)/risc-v-toolchain/riscv64-unknown-elf/include/ TL := $(TOOLS_ROOT)/risc-v-toolchain/lib/gcc/riscv64-unknown-elf/$(TC_VER)/rv$(BIT)$(ARCH_VARIANT)/$(ARCH_ABI)/ @@ -26,6 +28,7 @@ endif ifeq ($(findstring avr,$(ARCH)),avr) TC ?= $(TOOLS_ROOT)/avr-toolchain/bin/avr +$(eval $(call get_tc_version,$(TC))) # Sets TC_VER TI := $(TOOLS_ROOT)/avr-toolchain/lib/gcc/avr/$(TC_VER)/include-fixed TL := $(TOOLS_ROOT)/avr-toolchain/lib/gcc/avr/$(TC_VER)/$(ARCH)$(ARCH_VARIANT)/ endif @@ -47,3 +50,5 @@ $(info < ! > Toolchain is not available !) $(info < ! > Try running 'make help' ...) $(error < x > Build Failed !) endif + + diff --git a/projects/demo_avr/config.mk b/projects/demo_avr/config.mk index 8e768966..2448f096 100644 --- a/projects/demo_avr/config.mk +++ b/projects/demo_avr/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 5.4.0 FAMILY := mega_avr PLATFORM := atmega328p STDLOG_MEMBUF := 0 diff --git a/projects/demo_avr_cpp/config.mk b/projects/demo_avr_cpp/config.mk index 9946b127..05f673c8 100644 --- a/projects/demo_avr_cpp/config.mk +++ b/projects/demo_avr_cpp/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 5.4.0 FAMILY := mega_avr PLATFORM := atmega328p STDLOG_MEMBUF := 0 diff --git a/projects/demo_avr_cpp/gpio.cpp b/projects/demo_avr_cpp/gpio.cpp index af6af35f..848c220d 100644 --- a/projects/demo_avr_cpp/gpio.cpp +++ b/projects/demo_avr_cpp/gpio.cpp @@ -16,18 +16,31 @@ extern "C" #include "gpio.h" -/* Outside declaration of the member function of class onBoardLed */ +/* Outside declaration of the member function of class onBoardLed: Utilized by the specific register allocation for the onboard LED */ onBoardLed::onBoardLed() { gpio_pin_alloc(&led13, PORTB, 5); } +/** + * @brief the setting up of the onboard-LED + * + * This function configures the specific GPIO pin for the onboard-LED as an output + * This function also sets the LED state to low (off) + */ + void onBoardLed::setup() { gpio_pin_mode(&led13, out); gpio_pin_clear(&led13); } +/** + * @brief The toggling of the onboard LED + * + * This function toggles the state of the onboard LED on and off + */ + void onBoardLed::toggle() { gpio_pin_toggle(&led13); diff --git a/projects/demo_avr_cpp/gpio.h b/projects/demo_avr_cpp/gpio.h index 5f968c52..40e9963a 100644 --- a/projects/demo_avr_cpp/gpio.h +++ b/projects/demo_avr_cpp/gpio.h @@ -10,6 +10,13 @@ #pragma once +/** + * @brief Class representing an on-board LED controlled via GPIO. + * + * This class provides methods to initialize the LED, set it up as an output, + * and toggle its state. + */ + class onBoardLed { private: diff --git a/projects/demo_avr_cpp/project.cpp b/projects/demo_avr_cpp/project.cpp index 93294c06..05edd261 100644 --- a/projects/demo_avr_cpp/project.cpp +++ b/projects/demo_avr_cpp/project.cpp @@ -21,15 +21,15 @@ extern "C" #include <hal/gpio.h> } -#include "gpio.h" +#include "gpio.h" // This has custom GPIO header functions -class onBoardLed led; +class onBoardLed led; /* Use EXPORT_C macro for calling cpp function in c file */ EXPORT_C(void plug()) { - bootstrap(); + bootstrap(); // calls the system initial bootstrap driver_setup_all(); /* call the constructor and setup member of led object */ @@ -47,13 +47,13 @@ void delay(unsigned long d) { unsigned long c; for(c = 0; c < d; c++) - asm volatile("nop"); + asm volatile("nop"); // provides the assembly instructions to create a general delay } static unsigned char i = 0; -EXPORT_C(void play()) +EXPORT_C(void play()) // the calling of the continues function check { - wdog_guard(WDT_64MS, true, NULL); + wdog_guard(WDT_64MS, true, NULL); // safety feature if the core hangs or creates interruptions /* call the toggle member of led object */ led.toggle(); diff --git a/projects/demo_helios_avr/config.mk b/projects/demo_helios_avr/config.mk index 44eb2fff..720633ae 100644 --- a/projects/demo_helios_avr/config.mk +++ b/projects/demo_helios_avr/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 5.4.0 FAMILY := mega_avr PLATFORM := atmega328p HEAP_SIZE := 500 diff --git a/projects/demo_helios_riscv/config.mk b/projects/demo_helios_riscv/config.mk index ace2ac5e..80a63301 100644 --- a/projects/demo_helios_riscv/config.mk +++ b/projects/demo_helios_riscv/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 10.2.0 FAMILY := sifive PLATFORM := fe310g002 HEAP_SIZE := 3K diff --git a/projects/demo_qemu_sifive_e/config.mk b/projects/demo_qemu_sifive_e/config.mk index 2b36c0ca..b57312e5 100644 --- a/projects/demo_qemu_sifive_e/config.mk +++ b/projects/demo_qemu_sifive_e/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 10.2.0 FAMILY := sifive PLATFORM := qemu-sifive-e STDLOG_MEMBUF := 0 diff --git a/projects/demo_riscv/config.mk b/projects/demo_riscv/config.mk index 086686f1..c93ab91c 100644 --- a/projects/demo_riscv/config.mk +++ b/projects/demo_riscv/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 10.2.0 FAMILY := sifive PLATFORM := fe310g002 STDLOG_MEMBUF := 0 diff --git a/projects/hifive1b_bl/config.mk b/projects/hifive1b_bl/config.mk index 158073c4..493b4a09 100644 --- a/projects/hifive1b_bl/config.mk +++ b/projects/hifive1b_bl/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 10.2.0 FAMILY := sifive PLATFORM := fe310g002-bl STDLOG_MEMBUF := 0 diff --git a/projects/qemu_sifive_e_bl/config.mk b/projects/qemu_sifive_e_bl/config.mk index 81f62b95..2e019580 100644 --- a/projects/qemu_sifive_e_bl/config.mk +++ b/projects/qemu_sifive_e_bl/config.mk @@ -9,7 +9,6 @@ # COMPILER := gcc -TC_VER := 10.2.0 FAMILY := sifive PLATFORM := qemu-sifive-e-bl USE_FLOAT := 0 diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c b/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c index c74180b5..0388200d 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/arch.c @@ -1,11 +1,12 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : arch.c * Description : This file consists of architecture specific function that * cannot be inlined. Hence, present in c file. - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] + * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com], + * Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ @@ -14,21 +15,50 @@ #include <assert.h> #include <status.h> #include <syslog.h> -#include <mmio.h> #include <arch.h> +#include <interrupt.h> #include <visor/workers.h> +#include <rand.h> +#include <lock/lock.h> -static void arch_ecall_handler() +/** + * arch_vcall_handler + * + * @brief This function handles svc calls. In Cyancore all exception calls + * will be called as visor-calls. + */ +static void arch_vcall_handler() { context_frame_t *frame = get_context_frame(); vret_t vres; - machine_call(frame->r0, frame->r1, frame->r3, &vres); + vcall_handler(frame->r0, frame->r1, frame->r2, frame->r3, &vres); frame->r0 = vres.p; frame->r1 = vres.size; frame->r2 = vres.status; return; } +/* This the key for boot lock */ +static lock_t boot_key = LOCK_INITAL_VALUE; +void arch_early_signal_boot_start() +{ + boot_key = LOCK_INITAL_VALUE; + return; +} + +void arch_wait_till_boot_done() +{ + lock_acquire(&boot_key); + lock_release(&boot_key); + return; +} + +void arch_signal_boot_done() +{ + lock_release(&boot_key); + return; +} + /** *arch_early_setup - This function is called in the early stages of boot * @@ -38,7 +68,6 @@ static void arch_ecall_handler() void arch_early_setup() { arch_di(); - } /** @@ -48,15 +77,15 @@ void arch_early_setup() */ void arch_setup() { + link_interrupt(int_arch, 10 ,&arch_vcall_handler); return; } -void arch_di_save_state(istate_t *sreg_i_backup) +void arch_di_save_state(istate_t *istate _UNUSED) { - * } -void arch_ei_restore_state(istate_t *sreg_i_backup) +void arch_ei_restore_state(istate_t *istate _UNUSED) { } @@ -77,14 +106,12 @@ void _NORETURN arch_panic_handler_callback() if(!frame) goto panic; syslog_stdout_enable(); - sysdbg("r0=%p\tr1=%p\tr2=%p\tr3=%p\tr4=%p\tr5=%p\n", - frame->r0, frame->r1, frame->r2, frame->r3, frame->r4, frame->r5); - sysdbg("r6=%p\tr7=%p\tr8=%p\tr9=%p\tr10=%p\tr11=%p\n", - frame->r6, frame->r7, frame->r8, frame->r9, frame->r10, frame->r11); - sysdbg("r12=%p\tr13=%p\tr14=%p\tr15=%p\tAPSR=%p\n", - frame->r12, frame->r13, frame->r14, frame->r15, frame->apsr); + sysdbg("r0=%p\tr1=%p\tr2=%p\tr3=%p\n", + frame->r0, frame->r1, frame->r2, frame->r3); + sysdbg("r12=%p\tLR=%p\tPSR=%p\tReturns To=%p\n", + frame->r12, frame->lr, frame->psr, frame->ret_addr); #if DEBUG==0 - syslog(info, "APSR=%p\n", frame->apsr); + syslog(info, "PSR=%p\n", frame->psr); #endif panic: while(1) arch_wfi(); @@ -132,3 +159,28 @@ void arch_signal_resume(void) { sleep_flag = resume; } + +/** + * arch_rseed_capture + * + * @brief This function is intended to capture unique seed value + */ +void arch_rseed_capture() +{ + extern uintptr_t *_bss_start; + srand((size_t)_bss_start); +} + +_WEAK void arch_panic_handler() +{ + syslog_stdout_enable(); + syslog(fail, "Arch Panic!\n"); + arch_panic_handler_callback(); +} + +_WEAK void arch_unhandled_irq() +{ + syslog_stdout_enable(); + syslog(fail, "Arch Unhandled IRQ!\n"); + arch_panic_handler_callback(); +} diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.S b/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.S new file mode 100644 index 00000000..0df60baf --- /dev/null +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.S @@ -0,0 +1,22 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : arch_verctors.S + * Description : This file consists of array of vector table + * specific to arm-m proile. + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include <asm.inc> + +object arch_vectors + .word _stack_start + .word init + +.set i, 1 +.rept (N_EXCEP + N_IRQ) + .word isr +.set i, i+1 +.endr diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.c b/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.c deleted file mode 100644 index 6fafacf9..00000000 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/arch_vectors.c +++ /dev/null @@ -1,62 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2022, Cyancore Team - * - * File Name : arch_verctors.c - * Description : This file consists of array of vector table - * specific to arm-m proile. - * Primary Author : Akash Kollipara [akashkollipara@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#include <status.h> -#include <stdint.h> - -extern void _stack_start(); -extern void init(void); -#define proto_irq_func(x) extern void int_##x(void) -proto_irq_func(1); -proto_irq_func(2); -proto_irq_func(3); -proto_irq_func(4); -proto_irq_func(5); -proto_irq_func(6); -proto_irq_func(7); -proto_irq_func(8); -proto_irq_func(9); -proto_irq_func(10); -proto_irq_func(11); -proto_irq_func(12); -proto_irq_func(13); -proto_irq_func(14); - -/** - * arch_vectors - Interrupt vector table defined as per arm-m spec - * @brief This is the array of interrupt/exception vectors defined - * by arm-v6/v7 spec. This is generic implementation and upon any - * irq/excep, these function will call common handler which will - * deref based on irq id and call respective handler. - */ - -void (*arch_vectors[N_IRQ+1])(void) _SECTION(".archvectors") = -{ - &_stack_start, // Stack start value has higher address of stack - // with as assumption that stack grows towards - // lower address - - &init, // CPU entry address - &int_1, // IRQ 1 -> NMI - &int_2, // IRQ 2 -> HardFault - &int_3, // IRQ 3 -> M-Manage - &int_4, // IRQ 4 -> BusFault - &int_5, // IRQ 5 -> UsageFault - &int_6, // IRQ 6 -> N/A - &int_7, // IRQ 7 -> DBG info - &int_8, // IRQ 8 -> Debugger handler - &int_9, // IRQ 9 -> N/A - &int_10, // IRQ 10 -> SVC - &int_11, // IRQ 11 -> Debug Monitor - &int_12, // IRQ 12 -> N/A - &int_13, // IRQ 13 -> PendSV - &int_14, // IRQ 14 -> SysTick -}; diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/asm.S b/src/arch/arm-m/32/common_v6_v7/supervisor/asm.S index ba30f7d4..13235d94 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/asm.S +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/asm.S @@ -1,53 +1,39 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2022-2023, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : asm.S * Description : This file consists of all the function written in asm * like ISR, context management and panic handler - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] + * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com], + * Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ #include <asm.inc> -.altmacro -.macro INT id - -function int_\id - push {r0} - mov r0, #\id - b isr -.endm +/** + * Note: + * - A.R.M. : Architecture Reference Manual + */ /** * isr - interrupt service routine function - * @brief This function is called from interrupt router. - * It is responsible to do context management before and after - * calling the interrupt handler function. + * @brief This function is called upon exceptions or irqs. + * As per the armv6-m A.R.M., upon triggering of exception + * CPU performs a minimal context management in which it + * saves registers r0-r3, r12, lr, return address, psr. + * Also it updates LR, refer to doc (B1.5.6 in A.R.M.). + * Additionally we perform saving of LR so that + * exception handler can update the LR as per need. */ .weak isr function isr - push {r1-r7, lr} - mrs r1, msp + push {lr} + mrs r0, ipsr + mov r1, sp bl exception_handler - pop {r1-r7} - pop {r0} - mov lr, r0 pop {r0} - mov pc, lr - -/** - * Interrupt Router Declaration Table - * 1-14 Interrupt routers are define as of now. If possible more can - * be added. But during compile time only necessary interrupt router - * functions will be retained and others are cleaned up. - */ -/*==========< Interrupt router functions >==========*/ -.set i, 1 -.rept 14 - INT %i -.set i, i+1 -.endr + bx r0 diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/build.mk b/src/arch/arm-m/32/common_v6_v7/supervisor/build.mk index badef973..f58ea463 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/build.mk +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/build.mk @@ -1,6 +1,6 @@ # # CYANCORE LICENSE -# Copyrights (C) 2023, Cyancore Team +# Copyrights (C) 2024, Cyancore Team # # File Name : build.mk # Description : Build script for this directory. diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/exception_handler.c b/src/arch/arm-m/32/common_v6_v7/supervisor/exception_handler.c index 92310a3f..ddab85a8 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/exception_handler.c +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/exception_handler.c @@ -1,10 +1,11 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : interrupt_handler.c * Description : This file consists of arch interrupt handler sources. - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] + * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com], + * Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ @@ -17,93 +18,58 @@ #include <arch.h> #include <assert.h> -static context_frame_t *local_frame; +static void (* exhandler[N_CORES][N_EXCEP])(void) = {{[0 ... N_EXCEP-1] = arch_panic_handler}}; +static void (* irqhandler[N_CORES][N_IRQ])(void) = {{[0 ... N_IRQ-1] = arch_unhandled_irq}}; +static context_frame_t *local_frame[N_CORES]; -static void set_context_frame(*frame) +bool in_isr(void) { - local_frame = frame; + unsigned int cpuid = arch_core_index(); + return (local_frame[cpuid] != NULL) ? true : false; } -bool in_isr(void) +static void set_context_frame(context_frame_t *frame) { - return (local_frame != NULL) ? true : false ; + unsigned int cpuid = arch_core_index(); + local_frame[cpuid] = frame; + arch_dsb(); } -/** - * int_handler - Array of Interrupt handler pointers - * - * @brief This is a function pointer array which consists of addresses of corresponding - * interrupt handler functions. This is by default assigned as arch_panic_handler. - */ -static void (* exhandler[N_EXCEP])(void) = {{[0 ... N_EXCEP-1] = arch_panic_handler}}; - -/** - * arch_register_interrupt_handlers - Registers arch interrupt handlers - * @brief This function is responsible to registers all architectural level - * Interrupt handling functions. - * - * @param[in] id: Interrupt ID - * @param[in] *handler - function pointer of interrupt handling function. - */ - -void arch_register_interrupt_handler(unsigned int id, void(* handler)(void)) +context_frame_t *get_context_frame() { - /*Check if Interrupt ID is valid*/ - assert((id > 0) && (id <= N_EXCEP)); - - /* - * Decrement ID as array indexing starts from 0. - * ID = 0 is CPU entry address. - */ - id --; + unsigned int cpuid = arch_core_index(); + return local_frame[cpuid]; +} - /*Store interrupt handler*/ - exhandler[id] = handler; +void arch_register_interrupt_handler(unsigned int id, void (*handler)(void)) +{ + unsigned int cpuid = arch_core_index(); + id--; + exhandler[cpuid][id] = handler; + arch_dsb(); } -/** - * Exception handler - Executes Interrupt handler corresponding to int ID - * - * @brief This function is called by ISR. It executes function pointed by int_handler. - * It accepts int ID as argument, which indexes the interrupt handling function. - * - * @param[in] id: Interrupt ID - */ +void local_register_interrupt_handler(unsigned int id, void (*handler)(void)) +{ + unsigned int cpuid = arch_core_index(); + id--; + irqhandler[cpuid][id] = handler; + arch_dsb(); +} -void exception_handler(unsigned int id, context_frame_t *frame) +void exception_handler(uint32_t id, context_frame_t *frame) { + unsigned int cpuid = arch_core_index(); + set_context_frame(frame); + id--; - /*Check if Interrupt ID is valid*/ - if((id > 0) && (id <= N_EXCEP)) + if(id >= N_EXCEP) + irqhandler[cpuid][id - N_EXCEP](); + else { - /* - * Decrement ID as array indexing starts from 0. - * ID = 0 is CPU entry address. - */ - id --; - - /* Get corresponding interrupt handling function */ - void (*handler)(void) = exhandler[id] - - /* Check if the handler is valid*/ - assert(handler) - - /* Execute exception handler */ - handler(); + exhandler[cpuid][id](); } - else if(id == 65535) - plat_panic_handler_callback(); - else if(id == 65536) - arch_panic_handler_callback(); - else{} set_context_frame(NULL); - return; -} - -context_frame_t *get_context_frame() -{ - if(local_frame) - return local_frame; - return NULL; + arch_dsb(); } diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h index 7e48edf3..a68cbfcd 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arch.h @@ -1,11 +1,12 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : arch.h * Description : This file prototypes arch related functions and * defines inline-able arch functions. - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] + * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com], + * Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ @@ -13,6 +14,7 @@ #define _ARCH_H_ #include <arm.h> +#include <resource.h> #include <visor_call.h> /** @@ -25,17 +27,19 @@ void arch_early_setup(); */ void arch_setup(); -/** - * arch_wfi - Wait for interrupt, with sleep mode - */ -void arch_wfi(); -void arch_di_save_state(istate *); -void arch_ei_restore_state(istate *); +void arch_di_save_state(istate_t *); +void arch_ei_restore_state(istate_t *); +unsigned int arch_core_index(); /** * arch_panic_handler - Executes when arch error occurs */ void arch_panic_handler(); +void arch_unhandled_irq(); + +void arch_early_signal_boot_start(); +void arch_wait_till_boot_done(); +void arch_signal_boot_done(); /** * arch_register_interrupt_handler - Registers interrupt handler for @@ -44,7 +48,8 @@ void arch_panic_handler(); void arch_register_interrupt_handler(unsigned int, void(*)(void)); /** - * arch_super_call - perform machine call + * arch_visor_call - perform supervisor call + * * @brief This function performs svc call * * @param[in] code: universal call code @@ -53,8 +58,7 @@ void arch_register_interrupt_handler(unsigned int, void(*)(void)); * @param[in] r2: third argument * @param[in] *ret: return struct */ -#define arch_visor_call arch_super_call -static inline void arch_super_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, vret_t *ret) +static inline void arch_visor_call(unsigned int code, unsigned int arg0, unsigned int arg1, unsigned int arg2, vret_t *ret) { if(ret == NULL) return; @@ -62,9 +66,9 @@ static inline void arch_super_call(unsigned int code, unsigned int arg0, unsigne register uint32_t r1 asm("r1") = arg0; register uint32_t r2 asm("r2") = arg1; register uint32_t r3 asm("r3") = arg2; - asm volatile("svc" + asm volatile("svc 0" :"+r" (r0), "+r" (r1), "+r"(r2) - :"r" (r0), "r" (r1), "r" (r2), "r" (r3) + :"r" (r0), "r" (r0), "r" (r1), "r" (r2), "r" (r3) :"memory"); ret->p = r0; @@ -78,7 +82,7 @@ static inline void arch_super_call(unsigned int code, unsigned int arg0, unsigne */ static inline void arch_ei() { - asm volatile("cpsie iaf"); + asm volatile("cpsie if"); } /** @@ -86,7 +90,7 @@ static inline void arch_ei() */ static inline void arch_di() { - asm volatile("cpsid iaf"); + asm volatile("cpsid if"); } static inline void arch_nop() diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arm.h b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arm.h index 832c0835..979baa22 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/include/arm.h +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/include/arm.h @@ -1,65 +1,84 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : arch.h * Description : This file prototypes arch related functions and * defines inline-able arch functions. - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] + * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com], + * Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ #pragma once #define _ARM_H -#include<stdint.h> -#include<string.h> -#include<stdbool.h> + +#include <stdint.h> +#include <stdbool.h> typedef struct context_frame { - uint8_t r15, r14, r13, r12, r11, r10, r9, r8, - r7, r6, r5, r4, r3, r2, r1, APSR, r0; -}context_frame_t; + uint32_t elr, psr, ret_addr, lr, + r12, r3, r2, r1, r0; +} context_frame_t; +typedef uint32_t call_arg_t; typedef uint32_t istate_t; +static inline unsigned int __arm_cpuid() +{ + unsigned int ret; + asm volatile("mrs %0, cpuid" : "=r" (ret)::); + return ret; +} + static inline unsigned int arch_core_impid() { unsigned int ret; - asm volatile("cpuid %0, implementer" : "=r"(ret)); + ret = __arm_cpuid(); + ret >>= 24; return ret; } static inline unsigned int arch_core_varid() { unsigned int ret; - asm volatile("cpuid %0, varid" : "=r"(ret)); + ret = __arm_cpuid(); + ret >>= 20; + ret &= 0xf; return ret; } static inline unsigned int arch_core_archid() { unsigned int ret; - asm volatile("cpuid %0, architecture" : "=r"(ret)); + ret = __arm_cpuid(); + ret >>= 16; + ret &= 0xf; return ret; } static inline unsigned int arch_core_partno() { unsigned int ret; - asm volatile("cpuid %0, partno" : "=r"(ret)); + ret = __arm_cpuid(); + ret >>= 4; + ret &= 0xfff; + return ret; } static inline unsigned int arch_core_revid() { unsigned int ret; - asm volatile("cpuid %0, revision" : "=r"(ret)); + ret = __arm_cpuid(); + ret &= 0xf; + return ret; } static inline void arch_update_sp(uint32_t *p) { - asm volatile("mov sp, %0" : : "r"(p)); + asm volatile("mov msp, %0" : : "r"(p)); } context_frame_t *get_context_frame(); diff --git a/src/arch/arm-m/32/common_v6_v7/supervisor/init.c b/src/arch/arm-m/32/common_v6_v7/supervisor/init.c index e69de29b..9120c89a 100644 --- a/src/arch/arm-m/32/common_v6_v7/supervisor/init.c +++ b/src/arch/arm-m/32/common_v6_v7/supervisor/init.c @@ -0,0 +1,47 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : init.c + * Description : This file consists of init routine of the framework. + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#include <stdint.h> +#include <stdio.h> +#include <stdlib.h> +#include <arch.h> +#include <engine.h> + +/** + * init - Entry point for the framework + * + * @brief This function runs to reset the cpu reg bank to architectrually + * reset state and jump to 'engine'. + */ +void _NAKED init() +{ +#if USE_PRNG + /* Capture unique seed value before memory initialization */ + arch_rseed_capture(); +#endif + /* Boot framework */ +#if CCSMP == 0 + engine(); +#else + if(arch_core_index() == BOOT_CORE_ID) + { + arch_early_signal_boot_start(); + engine(); + } + else + { + arch_wait_till_boot_done(); + engine_secondary(); + } +#endif + + /* Accidental trap, if control returns from framework */ + exit(EXIT_FAILURE); +} diff --git a/src/arch/riscv/32/i/terravisor/include/riscv.h b/src/arch/riscv/32/i/terravisor/include/riscv.h index c88be24e..d2afc407 100644 --- a/src/arch/riscv/32/i/terravisor/include/riscv.h +++ b/src/arch/riscv/32/i/terravisor/include/riscv.h @@ -1,6 +1,6 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : riscv.h * Description : This file prototypes riscv arch related functions and diff --git a/src/driver/onboardled/onboardled.c b/src/driver/onboardled/onboardled.c index a0966ad7..774d31aa 100644 --- a/src/driver/onboardled/onboardled.c +++ b/src/driver/onboardled/onboardled.c @@ -23,6 +23,15 @@ static gpio_port_t *obledPort; static swdev_t *obled_sp; static lock_t obledlock; +/** + * @brief Toggle the state of the onboard LED. + * + * This function toggles the state of the onboard LED by each GPIO pin + * It also works accordinlg with locks to protect the state + * + * @return status_t: Status of the operation + */ + status_t onboardled_toggle(void) { status_t ret = success; @@ -39,6 +48,14 @@ status_t onboardled_toggle(void) return ret; } +/** + * @brief Turning on the onboard LED + * + * This function turns on the onboard LED by setting each of the GPIO pin to high + * + * @return status_t: Status of the operation + */ + status_t onboardled_on(void) { status_t ret = success; @@ -55,6 +72,14 @@ status_t onboardled_on(void) return ret; } +/** + * @brief Turning off the onboard LED + * + * This function turns on the onboard LED by setting each of the GPIO pin to low (clearing) + * + * @return status_t: Status of the operation + */ + status_t onboardled_off(void) { status_t ret = success; @@ -71,6 +96,14 @@ status_t onboardled_off(void) return ret; } +/** + * @brief Initializes the onboard LED driver + * + * This function initializes the onboard LED driver by allocating GPIO ports for the LED. + * + * @return status_t: Status of the initialization + */ + static status_t onboardled_setup(void) { vret_t vres; @@ -107,6 +140,15 @@ static status_t onboardled_setup(void) return ret; } +/** + * @brief Cleanup and exit the onboard LED driver. + * + * This function frees allocated GPIO ports and resources associated with the + * onboard LED driver. + * + * @return status_t: Status of the cleanup and exit + */ + static status_t onboardled_exit(void) { status_t ret = success; @@ -125,4 +167,4 @@ static status_t onboardled_exit(void) return ret; } -INCLUDE_DRIVER(OBrdLED, onboardled_setup, onboardled_exit, 0, 255, 255); +INCLUDE_DRIVER(OBrdLED, onboardled_setup, onboardled_exit, 0, 255, 255); \ No newline at end of file diff --git a/src/engine/banner.mk b/src/engine/banner.mk index 20956703..540eae3f 100644 --- a/src/engine/banner.mk +++ b/src/engine/banner.mk @@ -9,7 +9,7 @@ # NAME = Boron -VERSION = 0x01000400 +VERSION = 0x01000401 $(eval $(call add_define,VERSION)) diff --git a/src/platform/mega_avr/README.md b/src/platform/mega_avr/README.md new file mode 100644 index 00000000..ed63def6 --- /dev/null +++ b/src/platform/mega_avr/README.md @@ -0,0 +1,27 @@ +# MegaAVR Family +This folder contains platform specific programs for MegaAVR family of controllers. + +## Some differences between the two AVR microcontrollers: + +| Controller | CPU | Memory (SRAM) | Flash | EEPROM | GPIO | +|---|---|---|---|---|---| +| AtMega328P | AVR5-8b | 2KB | 32KB | 1KB | 23 | +| AtMega2560 | AVR6-8b | 8KB | 256KB | 4KB | 86 | + +## Directories Overview +| Folder | Description | +| --------------------- | ------------------------------------------------------------- | +| [common](common) | Holds common code shared between platforms.| +| [atmega328p](atmega328p) | Houses platform-specific programs for Atmega328p. Contains: Architecture Specifics, Platform Includes, Platform Clock, and Resources| +| [atmega2560](atmega2560) | Houses platform-specific programs for Atmega2560. Contains: Architecture Specifics, Platform Includes, Platform Clock, and Resources| + +### [common](common) + +Contains code shared between Atmega328p and Atmega2560. + +| Subfolder | Description | +| --------------- | ------------------------------------------------------- | +| [arch](common/arch) | CPU architecture related src| +| [hal](common/hal) | Hardware abstraction layer src| +| [include](common/include) | Includes for platform header| +| [platform](common/platform) | Platform specific src| diff --git a/src/platform/mega_avr/common/hal/adc/adc.c b/src/platform/mega_avr/common/hal/adc/adc.c index f6763e41..e710e907 100644 --- a/src/platform/mega_avr/common/hal/adc/adc.c +++ b/src/platform/mega_avr/common/hal/adc/adc.c @@ -21,16 +21,42 @@ #include <syslog.h> #include "adc_private.h" +/** + * _adc_enable - Enables ADC + * + * @brief Enables the ADC peripheral + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_enable(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADEN); } +/** + * _adc_disable - Disables ADC + * + * @brief Disables the ADC peripheral + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_disable(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) &= ~(1 << ADEN); } +/** + * _adc_set_prescaler - Sets ADC prescaler + * + * @brief Sets the ADC prescaler value based on the clock frequency specific in the port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of prescaler setup operation + */ + static inline status_t _adc_set_prescaler(adc_port_t *port) { uint8_t pscale_value = 0; @@ -65,11 +91,30 @@ static inline status_t _adc_set_prescaler(adc_port_t *port) return ret; } +/** + * _adc_start_conv - Starts ADC conversion + * + * @brief Initiates ADC conversion process + * + * @param[in] port: Pointer to the ADC port structure + */ + static inline void _adc_start_conv(adc_port_t *port) { MMIO8(port->baddr + ADCSRA_OFFSET) |= (1 << ADSC); } +/** + * _adc_config_trigger - Configures ADC trigger mode + * + * @brief Configures the ADC trigger mode for conversion + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] trigger: ADC trigger mode + * + * @return status: Status of trigger configuration operation + */ + static inline status_t _adc_config_trigger(adc_port_t *port, adc_trig_t trigger) { status_t ret = success; @@ -81,6 +126,17 @@ static inline status_t _adc_config_trigger(adc_port_t *port, adc_trig_t trigger) return ret; } +/** + * _adc_config_resolution - Configures ADC resolution + * + * @brief Configures the ADC resolution (8-bit | 10-bit) + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] resolution: ADC resolution wanted + * + * @return status: Status of resolution configuration operation + */ + static inline status_t _adc_config_resolution(adc_port_t *port, uint8_t resolution) { status_t ret = success; @@ -91,6 +147,17 @@ static inline status_t _adc_config_resolution(adc_port_t *port, uint8_t resoluti return ret; } +/** + * _adc_config_vref - Configures ADC voltage reference + * + * @brief Configures the ADC voltage reference source based on specific reference source + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] vref: ADC voltage reference source + * + * @return status: Status of voltage reference configuration operation + */ + static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) { status_t ret = success; @@ -114,6 +181,16 @@ static inline status_t _adc_config_vref(adc_port_t *port, adc_ref_t vref) return ret; } +/** + * adc_setup - Setups ADC + * + * @brief Initializes and configures the ADC peripheral + * + * @param[out] port: Pointer to the ADC port structure + * + * @return status: Status of setup operation + */ + status_t adc_setup(adc_port_t *port) { status_t ret = success; @@ -129,6 +206,16 @@ status_t adc_setup(adc_port_t *port) return ret; } +/** + * adc_shutdown - Shutdown ADC + * + * @brief Disables and shuts down the ADC peripheral + * + * @param[out] port: Pointer to the ADC port structure + * + * @return status: Status of shutdown operation + */ + status_t adc_shutdown(adc_port_t *port) { status_t ret = success; @@ -139,6 +226,16 @@ status_t adc_shutdown(adc_port_t *port) return ret; } +/** + * adc_busy - Checks ADC busy state + * + * @brief Checks if the ADC is currently busy + * + * @param[in] port: Pointer to the ADC port structure + * + * @return state: State of ADC busy status + */ + bool adc_busy(adc_port_t *port) { bool ret; @@ -147,6 +244,16 @@ bool adc_busy(adc_port_t *port) return ret; } +/** + * adc_int_en - Enables ADC interrupts + * + * @brief Enables ADC interrupts for the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of interrupt enable operation + */ + status_t adc_int_en(adc_port_t *port) { STATUS_CHECK_POINTER(port); @@ -154,6 +261,16 @@ status_t adc_int_en(adc_port_t *port) return success; } +/** + * adc_int_dis - Disables ADC interrupts + * + * @brief Disables ADC interrupts for the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * + * @return status: Status of interrupt disable operation + */ + status_t adc_int_dis(adc_port_t *port) { STATUS_CHECK_POINTER(port); @@ -161,6 +278,20 @@ status_t adc_int_dis(adc_port_t *port) return success; } +/** + * adc_config_pin - Configures ADC pin parameters + * + * @brief Configures ADC pin settings for conversion + * + * @param[in] port: Pointer to the ADC port structure + * @param[in] pin: ADC pin to configure + * @param[in] trigger: ADC trigger mode + * @param[in] resolution: ADC resolution (8 or 10 bits) + * @param[in] vref: ADC voltage reference source + * + * @return status: Status of pin configuration operation + */ + status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8_t resolution, adc_ref_t vref) { status_t ret = success; @@ -175,6 +306,17 @@ status_t adc_config_pin(adc_port_t *port, uint8_t pin, adc_trig_t trigger, uint8 return ret; } +/** + * adc_read - Reads ADC conversion result + * + * @brief Reads the ADC conversion result from the specified ADC port + * + * @param[in] port: Pointer to the ADC port structure + * @param[out] adc_val: Pointer to store the ADC conversion value + * + * @return status: Status of read operation + */ + status_t adc_read(adc_port_t *port, uint16_t *adc_val) { status_t ret = success; @@ -195,6 +337,17 @@ status_t adc_read(adc_port_t *port, uint16_t *adc_val) return ret; } +/** + * adc_temperature_convert - Converts ADC raw value to temperature + * + * @brief Converts the raw ADC value to temperature in Celsius + * + * @param[in] raw_adc: Raw ADC value + * @param[out] temperature: Pointer to store the temperature value + * + * @return status: Status of temperature conversion operation + */ + status_t adc_temperature_convert(uint16_t raw_adc, float *temperature) { status_t ret = success; diff --git a/src/platform/mega_avr/common/hal/gpio/gpio.c b/src/platform/mega_avr/common/hal/gpio/gpio.c index 1d543770..e87f0dae 100644 --- a/src/platform/mega_avr/common/hal/gpio/gpio.c +++ b/src/platform/mega_avr/common/hal/gpio/gpio.c @@ -22,6 +22,18 @@ #include <hal/gpio.h> #include "gpio_private.h" +/** + * gpio_pin_alloc - Allocates the needed GPIO pin + * + * @brief Allocates the GPIO pin and looks for availability + * + * @param[out] port: Pointer to the GPIO port structure + * @param[in] portID: Port ID of the GPIO pin + * @param[in] pinID: Pin ID of the GPIO pin + * + * @return status: Status of allocation operation + */ + status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) { vret_t vres; @@ -59,6 +71,17 @@ status_t gpio_pin_alloc(gpio_port_t *port, uint8_t portID, uint8_t pinID) return success; } +/** + * gpio_pin_mode - Sets GPIO pin mode + * + * @brief Sets the mode of a GPIO pin (ex: Input, Output) + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] mode: Specified GPIO setting + * + * @return status: Status of mode setting operation + */ + status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; @@ -82,6 +105,16 @@ status_t gpio_pin_mode(const gpio_port_t *port, gpio_mode_t mode) return success; } +/** + * gpio_pin_free - Frees specific GPIO pin + * + * @brief Frees a previously allocated GPIO pin + * + * @param[out] port: Pointer to the GPIO port structure + * + * @return status: Status of freeing operation + */ + status_t gpio_pin_free(gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -95,6 +128,16 @@ status_t gpio_pin_free(gpio_port_t *port) return success; } +/** + * gpio_pin_set - Sets a GPIO pin high + * + * @brief Sets a GPIO pin to high logic level by setting appropriate bit in the control register + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of setting operation + */ + status_t gpio_pin_set(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -102,6 +145,16 @@ status_t gpio_pin_set(const gpio_port_t *port) return success; } +/** + * gpio_pin_clear - Sets a GPIO pin low + * + * @brief Sets a GPIO pin to low logic level by setting appropriate bit in the control register + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of clearing operation + */ + status_t gpio_pin_clear(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -109,6 +162,16 @@ status_t gpio_pin_clear(const gpio_port_t *port) return success; } +/** + * gpio_pin_toggle - Toggles a GPIO pin state + * + * @brief Toggles the state of a GPIO pin (high to low) + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return status: Status of toggling operation + */ + status_t gpio_pin_toggle(const gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -116,12 +179,33 @@ status_t gpio_pin_toggle(const gpio_port_t *port) return success; } +/** + * gpio_pin_read - Reads a GPIO pin state + * + * @brief Reads the state of a GPIO pin (high or low) + * + * @param[in] port: Pointer to the GPIO port structure + * + * @return state: State of the GPIO pin depending on high, low for true, false + */ + bool gpio_pin_read(const gpio_port_t *port) { assert(port); return (MMIO8(port->pbaddr + PIN_OFFSET) & (1 << port->pin)) ? true : false; } +/** + * gpio_port_alloc - Allocates a GPIO port + * + * @brief Allocates a GPIO port and checks for availability different from needing pinID + * + * @param[out] port: Pointer to the GPIO port structure + * @param[in] portID: Port ID of the GPIO port + * + * @return status: Status of allocation operation + */ + status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) { vret_t vres; @@ -157,6 +241,17 @@ status_t gpio_port_alloc(gpio_port_t *port, uint8_t portID) return success; } +/** + * gpio_port_mode - Sets GPIO port mode + * + * @brief Sets the mode of a GPIO port (ex: input, output, pull_up) + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] mode: GPIO mode to set + * + * @return status: Status of mode setting operation + */ + status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) { uintptr_t pbaddr; @@ -180,6 +275,16 @@ status_t gpio_port_mode(const gpio_port_t *port, gpio_mode_t mode) return success; } +/** + * gpio_port_free - Frees a GPIO port + * + * @brief Frees a previously allocated GPIO port different from freeing pin + * + * @param[out] port: Pointer to the GPIO port structure + * + * @return status: Status of freeing operation + */ + status_t gpio_port_free(gpio_port_t *port) { STATUS_CHECK_POINTER(port); @@ -193,6 +298,17 @@ status_t gpio_port_free(gpio_port_t *port) return success; } +/** + * gpio_port_write - Writes to a GPIO port + * + * @brief Writes data to a GPIO port + * + * @param[in] port: Pointer to the GPIO port structure + * @param[in] val: Data to write to the port + * + * @return status: Status of writing operation + */ + status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) { STATUS_CHECK_POINTER(port); @@ -201,6 +317,17 @@ status_t gpio_port_write(const gpio_port_t *port, gpio_parallel_t val) return success; } +/** + * gpio_port_read - Reads from a GPIO port + * + * @brief Reads data from a GPIO port + * + * @param[in] port: Pointer to the GPIO port structure + * @param[out] val: Variable to store the read data + * + * @return status: Status of reading operation + */ + status_t gpio_port_read(const gpio_port_t *port, gpio_parallel_t *val) { STATUS_CHECK_POINTER(port); diff --git a/src/platform/mega_avr/common/hal/pwm/pwm.c b/src/platform/mega_avr/common/hal/pwm/pwm.c index 11f18c66..17b3ba5c 100644 --- a/src/platform/mega_avr/common/hal/pwm/pwm.c +++ b/src/platform/mega_avr/common/hal/pwm/pwm.c @@ -19,6 +19,15 @@ #include <hal/timer.h> #include <hal/pwm.h> +/** + * pwm_to_timer - Convert PWM port to Timer port + * + * @brief Converts PWM port structure to Timer port structure + * + * @param[in] p: Pointer to the PWM port structure + * @param[out] t: Pointer to the Timer port structure + */ + static void pwm_to_timer(const pwm_port_t *p, timer_port_t *t) { t->port_id = p->port_id; @@ -29,6 +38,17 @@ static void pwm_to_timer(const pwm_port_t *p, timer_port_t *t) t->tmr_handler = p->pwm_handler; } +/** + * pwm_get_properties - Get PWM properties + * + * @brief Retrieves PWM properties and maps them to the PWM port structure. + * + * @param[out] port: Pointer to the PWM port structure + * @param[in] dev: Software device ID + * + * @return status: Status of PWM properties retrieval operation + */ + status_t pwm_get_properties(pwm_port_t *port, sw_devid_t dev) { vret_t vres; @@ -62,6 +82,17 @@ status_t pwm_get_properties(pwm_port_t *port, sw_devid_t dev) return success; } +/** + * pwm_setup - Configure PWM settings + * + * @brief Configures PWM settings using the associated Timer port + * + * @param[in] port: Pointer to the PWM port structure + * @param[in] mode: PWM mode (e.g., PWM, timer) + * + * @return status: Status of PWM setup operation + */ + status_t pwm_setup(const pwm_port_t *port, unsigned int mode) { status_t ret; @@ -81,6 +112,18 @@ status_t pwm_setup(const pwm_port_t *port, unsigned int mode) return ret; } +/** + * pwm_set - Set PWM value + * + * @brief Sets the PWM value using the associated Timer port + * + * @param[in] port: Pointer to the PWM port structure + * @param[in] value: PWM value to set + * @param[in] invert: Invert PWM signal if true + * + * @return status: Status of PWM set operation + */ + status_t pwm_set(const pwm_port_t *port, size_t value, bool invert) { status_t ret; diff --git a/src/platform/mega_avr/common/hal/spi/spi.c b/src/platform/mega_avr/common/hal/spi/spi.c index 65328d08..6209d361 100644 --- a/src/platform/mega_avr/common/hal/spi/spi.c +++ b/src/platform/mega_avr/common/hal/spi/spi.c @@ -20,6 +20,18 @@ #include <hal/spi.h> #include "spi_private.h" +/** + * spi_master_setup - Setups SPI master mode + * + * @brief Initializes SPI in master mode with specified settings + * + * @param[out] port: Pointer to the SPI port structure + * @param[in] df_format: Data frame format + * @param[in] cpol: Clock polarity + * @param[in] cpha: Clock phase + * + * @return status: Status of master setup operation + */ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol_t cpol, clk_ph_t cpha) { @@ -64,6 +76,19 @@ status_t spi_master_setup(spi_port_t *port, dataframe_format_t df_format, clk_po return ret; } +/** + * spi_slave_setup - Setups SPI slave mode + * + * @brief Initializes SPI in slave mode with specified settings + * + * @param[out] port: Pointer to the SPI port structure + * @param[in] df_format: Data frame format + * @param[in] cpol: Clock polarity + * @param[in] cpha: Clock phase + * + * @return status: Status of slave setup operation + */ + status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol_t cpol, clk_ph_t cpha) { status_t ret = success; @@ -107,18 +132,48 @@ status_t spi_slave_setup(spi_port_t *port, dataframe_format_t df_format, clk_pol return ret; } +/** + * spi_wcol_error - Checks SPI write collision error + * + * @brief Checks if a write collision error occurred during SPI communication + * + * @param[in] port: Pointer to the SPI port structure + * + * @return state: State of the write collision error (true = error, false = no error) + */ + bool spi_wcol_error(spi_port_t *port) { assert(port); return (MMIO8(port->baddr + SPSR_OFFSET) & (1 << WCOL)) ? true : false; } +/** + * spi_trx_done - Checks SPI transaction completion + * + * @brief Checks if an SPI transaction is completed + * + * @param[in] port: Pointer to the SPI port structure + * + * @return state: State of the transaction completion (true = completed, false = not completed) + */ + bool spi_trx_done(spi_port_t *port) { assert(port); return (MMIO8(port->baddr + SPSR_OFFSET) & (1 << SPIF)) ? true : false; } +/** + * spi_int_en - Enables SPI interrupts + * + * @brief Enables SPI interrupts for the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * + * @return status: Status of interrupt enable operation + */ + status_t spi_int_en(spi_port_t *port) { STATUS_CHECK_POINTER(port); @@ -126,6 +181,16 @@ status_t spi_int_en(spi_port_t *port) return success; } +/** + * spi_int_dis - Disables SPI interrupts + * + * @brief Disables SPI interrupts for the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * + * @return status: Status of interrupt disable operation + */ + status_t spi_int_dis(spi_port_t * port) { STATUS_CHECK_POINTER(port); @@ -133,6 +198,17 @@ status_t spi_int_dis(spi_port_t * port) return success; } +/** + * spi_tx - Transmits data via SPI + * + * @brief Transmits data via SPI using the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * @param[in] data: Data to be transmitted + * + * @return status: Status of data transmission operation + */ + status_t spi_tx(spi_port_t *port, char data) { STATUS_CHECK_POINTER(port); @@ -140,6 +216,17 @@ status_t spi_tx(spi_port_t *port, char data) return success; } +/** + * spi_rx - Receives data via SPI + * + * @brief Receives data via SPI using the given SPI port + * + * @param[in] port: Pointer to the SPI port structure + * @param[out] data: Pointer to store the received data + * + * @return status: Status of data reception operation + */ + status_t spi_rx(spi_port_t *port, char *data) { STATUS_CHECK_POINTER(port); diff --git a/src/platform/mega_avr/common/hal/timer/timer.c b/src/platform/mega_avr/common/hal/timer/timer.c index 801e49fd..adedfbb7 100644 --- a/src/platform/mega_avr/common/hal/timer/timer.c +++ b/src/platform/mega_avr/common/hal/timer/timer.c @@ -23,6 +23,18 @@ #include "timer8.h" #include "timer16.h" +/** + * timer_setup - Configure timer settings + * + * @brief Configures timer settings including mode and prescaler + * + * @param[in] port: Pointer to the timer port structure + * @param[in] mode: Timer mode (e.g., PWM, timer) + * @param[in] ps: Timer prescaler value + * + * @return status: Status of timer setup operation + */ + status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int ps) { status_t ret; @@ -55,6 +67,16 @@ status_t timer_setup(const timer_port_t *port, unsigned int mode, unsigned int p return ret; } +/** + * timer_shutdown - Shutdown timer + * + * @brief Disables timer and associated interrupts + * + * @param[in] port: Pointer to the timer port structure + * + * @return status: Status of timer shutdown operation + */ + status_t timer_shutdown(const timer_port_t *port) { status_t ret = success; @@ -78,6 +100,17 @@ status_t timer_shutdown(const timer_port_t *port) return ret; } +/** + * timer_read - Read timer value + * + * @brief Reads the current value of the timer. + * + * @param[in] port: Pointer to the timer port structure + * @param[out] value: Pointer to store the timer value + * + * @return status: Status of timer read operation + */ + status_t timer_read(const timer_port_t *port, size_t *value) { unsigned id; @@ -90,6 +123,17 @@ status_t timer_read(const timer_port_t *port, size_t *value) return success; } +/** + * timer_pwm_set - Set PWM value + * + * @brief Sets the PWM value and configuration + * + * @param[in] port: Pointer to the timer port structure + * @param[in] invert: Invert PWM signal if true + * @param[in] value: PWM value to set + * + * @return status: Status of PWM set operation + */ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) { @@ -109,4 +153,3 @@ status_t timer_pwm_set(const timer_port_t *port, bool invert, size_t value) } return ret; } - diff --git a/src/platform/mega_avr/common/hal/uart/uart.c b/src/platform/mega_avr/common/hal/uart/uart.c index 0243875f..3db3afc9 100644 --- a/src/platform/mega_avr/common/hal/uart/uart.c +++ b/src/platform/mega_avr/common/hal/uart/uart.c @@ -24,6 +24,19 @@ #include <arch.h> #include "uart_private.h" +/** + * uart_setup - Configure UART port settings + * + * @brief Configures UART port settings including direction, parity, baud rate, + * interrupt handling, and frame configuration. + * + * @param[in] port: Pointer to the UART port structure + * @param[in] d: Direction of UART communication (trx, rx, tx) + * @param[in] p: Parity setting for UART communication + * + * @return status: Status of UART setup operation + */ + status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) { status_t ret = success; @@ -91,6 +104,16 @@ status_t uart_setup(uart_port_t *port, direction_t d, parity_t p) return ret; } +/** + * uart_shutdown - Shutdown UART port + * + * @brief Disables UART port and associated interrupts + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART shutdown operation + */ + status_t uart_shutdown(uart_port_t *port) { status_t ret = success; @@ -109,12 +132,30 @@ status_t uart_shutdown(uart_port_t *port) return ret; } +/** + * uart_buffer_available - Check if UART buffer is free for transmission + * + * @brief Checks if UART buffer is available for data transmission. + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART buffer is available, false otherwise + */ + bool uart_buffer_available(const uart_port_t *port) { assert(port); return (bool)((MMIO8(port->baddr + UCSRA_OFFSET) >> UDRE) & 0x01); } +/** + * uart_tx_wait_till_done - Wait until UART transmission is done + * + * @brief Waits until UART transmission is complete + * + * @param[in] port: Pointer to the UART port structure + */ + void uart_tx_wait_till_done(const uart_port_t *port) { assert(port); @@ -123,12 +164,32 @@ void uart_tx_wait_till_done(const uart_port_t *port) MMIO8(port->baddr + UCSRA_OFFSET) |= (1 << TXC); } +/** + * uart_rx_done - Check if UART reception is complete + * + * @brief Checks if UART reception is complete. + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART reception is complete, false otherwise + */ + bool uart_rx_done(const uart_port_t *port) { assert(port); return (bool)((MMIO8(port->baddr + UCSRA_OFFSET) >> RXC) & 0x01); } +/** + * uart_frame_error - Check if UART frame error occurred + * + * @brief Checks if UART frame error occurred + * + * @param[in] port: Pointer to the UART port structure + * + * @return bool: True if UART frame error occurred, false otherwise + */ + bool uart_frame_error(const uart_port_t *port) { bool ret = false; @@ -138,6 +199,17 @@ bool uart_frame_error(const uart_port_t *port) return ret; } +/** + * uart_tx - Transmit data over UART + * + * @brief Function transmits the data over on UART + * + * @param[in] port: Pointer to the UART port structure + * @param[in] data: Data to be transmitted + * + * @return status: Status of UART transmission operation + */ + status_t uart_tx(const uart_port_t *port, const char data) { STATUS_CHECK_POINTER(port); @@ -147,6 +219,17 @@ status_t uart_tx(const uart_port_t *port, const char data) return success; } +/** + * uart_rx - Receive data over UART + * + * @brief Receives data over UART. + * + * @param[in] port: Pointer to the UART port structure + * @param[out] data: Pointer to store received data + * + * @return status: Status of UART reception operation + */ + status_t uart_rx(const uart_port_t *port, char *data) { STATUS_CHECK_POINTER(port); @@ -156,6 +239,16 @@ status_t uart_rx(const uart_port_t *port, char *data) return success; } +/** + * uart_tx_int_en - Enable UART transmission interrupt + * + * @brief Enables UART transmission interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART transmission interrupt enable operation + */ + status_t uart_tx_int_en(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -163,6 +256,16 @@ status_t uart_tx_int_en(const uart_port_t *port) return success; } +/** + * uart_tx_int_dis - Disable UART transmission interrupt + * + * @brief Disables UART transmission interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART transmission interrupt disable operation + */ + status_t uart_tx_int_dis(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -170,6 +273,16 @@ status_t uart_tx_int_dis(const uart_port_t *port) return success; } +/** + * uart_rx_int_en - Enable UART reception interrupt + * + * @brief Enables UART reception interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART reception interrupt enable operation + */ + status_t uart_rx_int_en(const uart_port_t *port) { STATUS_CHECK_POINTER(port); @@ -177,6 +290,16 @@ status_t uart_rx_int_en(const uart_port_t *port) return success; } +/** + * uart_rx_int_dis - Disable UART reception interrupt + * + * @brief Disables UART reception interrupt + * + * @param[in] port: Pointer to the UART port structure + * + * @return status: Status of UART reception interrupt disable operation + */ + status_t uart_rx_int_dis(const uart_port_t *port) { STATUS_CHECK_POINTER(port); diff --git a/src/platform/rpi/common_rp2/arch/build.mk b/src/platform/rpi/common_rp2/arch/build.mk new file mode 100644 index 00000000..a3b27313 --- /dev/null +++ b/src/platform/rpi/common_rp2/arch/build.mk @@ -0,0 +1,14 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file accumulates the build rp2 series +# platform arch sources +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +include mk/obj.mk diff --git a/src/platform/rpi/common_rp2/arch/platform_mem.c b/src/platform/rpi/common_rp2/arch/platform_mem.c index b16f947f..ee288e5f 100644 --- a/src/platform/rpi/common_rp2/arch/platform_mem.c +++ b/src/platform/rpi/common_rp2/arch/platform_mem.c @@ -1,6 +1,6 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : platform_mem.c * Description : This file contains implementation of platform early setup APIs. diff --git a/src/platform/rpi/common_rp2/build.mk b/src/platform/rpi/common_rp2/build.mk index abc3f18a..d6dbe37c 100644 --- a/src/platform/rpi/common_rp2/build.mk +++ b/src/platform/rpi/common_rp2/build.mk @@ -21,6 +21,6 @@ USE_DEFAULT_RESOURCES ?= 1 LOCAL_INTERRUPT_DEVICE ?= 0 PLAT_INTERRUPT_DEVICE ?= 0 -#include $(RP2_COMMON_DIR)/arch/build.mk +include $(RP2_COMMON_DIR)/arch/build.mk #include $(RP2_COMMON_DIR)/hal/build.mk -#include $(RP2_COMMON_DIR)/platform/build.mk +include $(RP2_COMMON_DIR)/platform/build.mk diff --git a/src/platform/rpi/common_rp2/include/platform.h b/src/platform/rpi/common_rp2/include/platform.h new file mode 100644 index 00000000..2b2613cf --- /dev/null +++ b/src/platform/rpi/common_rp2/include/platform.h @@ -0,0 +1,21 @@ +/* + * CYANCORE LICENSE + * Copyrights (C) 2024, Cyancore Team + * + * File Name : platform.h + * Description : This file contains prototypes of platform apis + * Primary Author : Akash Kollipara [akashkollipara@gmail.com] + * Organisation : Cyancore Core-Team + */ + +#pragma once +#define _RP2_PLATFORM_H_ + +#include <status.h> + +void plat_panic_handler(void); +void platform_print_cpu_info(void); +status_t platform_copy_data(void); +status_t platform_bss_clear(void); +status_t platform_resources_setup(void); +status_t platform_sysclk_reset(void); diff --git a/src/platform/rpi/common_rp2/platform/build.mk b/src/platform/rpi/common_rp2/platform/build.mk new file mode 100644 index 00000000..f12798b8 --- /dev/null +++ b/src/platform/rpi/common_rp2/platform/build.mk @@ -0,0 +1,17 @@ +# +# CYANCORE LICENSE +# Copyrights (C) 2024, Cyancore Team +# +# File Name : build.mk +# Description : This file builds sources from rp2 common +# platform directory +# Primary Author : Akash Kollipara [akashkollipara@gmail.com] +# Organisation : Cyancore Core-Team +# + +DIR := $(GET_PATH) + +PRINT_MEMORY_LAYOUT ?= 0 +$(eval $(call add_define,PRINT_MEMORY_LAYOUT)) + +include mk/obj.mk diff --git a/src/platform/rpi/common_rp2/platform/platform.c b/src/platform/rpi/common_rp2/platform/platform.c index 7cc83467..863e017c 100644 --- a/src/platform/rpi/common_rp2/platform/platform.c +++ b/src/platform/rpi/common_rp2/platform/platform.c @@ -1,42 +1,43 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : platform.c - * Description : This file contains sources for platform apis + * Description : This file contains sources for platform functions * Primary Author : Akash Kollipara [akashkollipara@gmail.com] * Organisation : Cyancore Core-Team */ -#include <status.h> #include <stdint.h> +#include <status.h> #include <stdlib.h> +#include <rand.h> #include <arch.h> +#include <driver.h> #include <syslog.h> +#include <driver/sysclk.h> #include <insignia.h> +#include <terravisor/platform.h> +#include <visor/workers.h> #include <platform.h> -#include <syslog.h> -uint32_t reset_syndrome; void platform_early_setup() { status_t ret = success; - - /* Setup platform memories*/ +#if USE_PRNG + unsigned int temp_randomnumber = rand(); +#endif ret |= platform_copy_data(); ret |= platform_bss_clear(); ret |= platform_init_heap(); ret |= platform_resources_setup(); - - /* Setup memory syslogger*/ +#if USE_PRNG + srand(temp_randomnumber); +#endif + syslog_stdout_disable(); driver_setup("mslog"); - reset_syndrome = MMIO32(CHIP_RESET) & 0x01110100; - MMIO32(CHIP_RESET) = 0; - - ret |= platform_clk_reset(); - if(ret != success) exit(EXIT_FAILURE); return; @@ -46,67 +47,53 @@ void platform_early_setup() static void platform_memory_layout() { extern uint32_t _text_start, _text_size, _text_end, - _data_vstart, _data_size, _data_end, - _stack_start, _stack_size, _stack_end, + _rodata_start, _rodata_size, _rodata_end, + _data_vstart, _data_size, _data_vend, + _stack_start, _stack_end, _stack_size, _bss_start, _bss_size, _bss_end, _heap_start, _heap_size, _heap_end, _flash_size, _ram_size; - syslog(info, "Memory Info >\n"); - syslog(info, "Flash Size : %u\n", &_flash_size); - syslog(info, "RAM Size : %u\n", &_ram_size); syslog(info, "\n"); syslog(info, "Program Memory Layout >\n"); - syslog(info, "text Region\t: %06p - %06p : Size: %u\n", + syslog(info, "Flash Size\t: %u\n", &_flash_size); + syslog(info, "RAM Size\t: %u\n", &_ram_size); + syslog(info, "text Region\t: %010p - %010p : Size: %u\n", &_text_start, &_text_end, &_text_size); - syslog(info, "bss Region\t: %06p - %06p : Size: %u\n", + syslog(info, "rodata Region\t: %010p - %010p : Size: %u\n", + &_rodata_start, &_rodata_end, &_rodata_size); + syslog(info, "bss Region\t: %010p - %010p : Size: %u\n", &_bss_start, &_bss_end, &_bss_size); - syslog(info, "data Region\t: %06p - %06p : Size: %u\n", + syslog(info, "data Region\t: %010p - %010p : Size: %u\n", &_data_vstart, &_data_vend, &_data_size); - syslog(info, "stack Region\t: %06p - %06p : Size: %u\n", - &_stack_start, &_stack_end, &_stack_size); - syslog(info, "heap Region\t: %06p - %06p : Size: %u\n", + syslog(info, "stack Region\t: %010p - %010p : Size: %u\n", + &_stack_end, &_stack_start, &_stack_size); + syslog(info, "heap Region\t: %010p - %010p : Size: %u\n", &_heap_start, &_heap_end, &_heap_size); syslog(info, "\n"); } #endif -/** - * platform_setup - Executes functions to make platform read to init - * - * @brief This function performs calls to function which make the - * framework ready to execute. This function should be made to run on boot core only. - */ void platform_setup() { - sysdbg3("In %s\n", __func__); + status_t ret = success; + driver_setup("earlycon"); bootmsgs_enable(); - cyancore_insignia_lite(); +#ifndef BOOTLOADER + cyancore_insignia(); +#endif + #if PRINT_MEMORY_LAYOUT platform_memory_layout(); #endif + if(ret != success) + exit(EXIT_FAILURE); return; } -/** - * platform_cpu_setup - Perform platform setup calls on all cpus - * - * @brief This function performs calls to functions that should be executed - * on all cores to make the cpu ready for the platform drivers. - */ void platform_cpu_setup() { - sysdbg3("In %s\n", __func__); arch_ei(); return; } - -void _NAKED plat_panic_handler_callback() -{ - context_frame_t *frame; - sysdbg3("In %s\n", __func__); - frame = get_context_frame(); - syslog(info, "SP=%p \tSREG = %P\n", frame, frame->sreg); - exit(EXIT_FAILURE); -} diff --git a/src/platform/rpi/common_rp2/platform/platform_reset.c b/src/platform/rpi/common_rp2/platform/platform_reset.c deleted file mode 100644 index 77980f1a..00000000 --- a/src/platform/rpi/common_rp2/platform/platform_reset.c +++ /dev/null @@ -1,64 +0,0 @@ -/* - * CYANCORE LICENSE - * Copyrights (C) 2019, Cyancore Team - * - * File Name : platform_reset.c - * Description : This file contains sources for platform - * reset apis - * Primary Author : Mayuri Lokhande [mayurilokhande01@gmail.com] - * Organisation : Cyancore Core-Team - */ - -#include <stdint.h> -#include <status.h> -#include <syslog.h> -#include <assert.h> -#include <reset.h> -#include <resource.h> -#include <arch.h> -#include <driver/watchdog.h> -#include <platform.h> -#include <terravisor/platform.h> - -extern uint32_t reset_syndrome; -/** - * platform_get_reset_syndrome - returns the cause of reset - * - * @brief This function returns the infromation related to - * the reset sources. - * - * @return reset_cause : This function returns the reset cause - */ - -reset_t platform_get_reset_syndrome() -{ - sysdbg5("Reset Syndrome = %u\n", reset_syndrome); - if(reset_syndrome & (1 << 8)) - return power_on_reset; - - if(reset_syndrome & (1 << 16)) - return external_reset; - - else - return inval_reset; -} - -/** - * platform_reset_handler - handles the reset conditions - * - * @brief This function is responsible to handle the reset - * sources like watchdog , brownout, etxernal reset, etc. - * - * @param[in] rsyn: Reset syndrome - * - * @return void - */ -void platform_reset_handler(reset_t rsyn) -{ - if(rsyn == power_on_reset) - return; - if(rsyn == external_reset) - return; - else - plat_panic_handler(); -} diff --git a/src/platform/rpi/common_rp2/platform/platform_resource.c b/src/platform/rpi/common_rp2/platform/platform_resource.c index 5ebce2bf..62025935 100644 --- a/src/platform/rpi/common_rp2/platform/platform_resource.c +++ b/src/platform/rpi/common_rp2/platform/platform_resource.c @@ -1,6 +1,6 @@ /* * CYANCORE LICENSE - * Copyrights (C) 2019-2022, Cyancore Team + * Copyrights (C) 2024, Cyancore Team * * File Name : platform_resource.c * Description : This file contains sources for platform diff --git a/src/platform/rpi/common_rp2/sections.ld.sx b/src/platform/rpi/common_rp2/sections.ld.sx index ae9b4ceb..0898e11a 100644 --- a/src/platform/rpi/common_rp2/sections.ld.sx +++ b/src/platform/rpi/common_rp2/sections.ld.sx @@ -21,6 +21,7 @@ MEMORY /* VM Addresses */ vma_imem (irx!aw) : ORIGIN = V_IMEM_START, LENGTH = IMEM_LENGTH vma_dmem (arw!xi) : ORIGIN = V_DMEM_START, LENGTH = DMEM_LENGTH + vma_stak (rw!axi) : ORIGIN = V_STAK_START, LENGTH = STACK_SIZE /* LM Addresses */ lma_mem : ORIGIN = L_MEM_START, LENGTH = L_MEM_LENGTH @@ -32,7 +33,7 @@ SECTIONS { .text : ALIGN(4) { - KEEP(*(.text.entry)) + KEEP(*(.text.arch)) *(.text) *(.text.*) . = ALIGN(8); @@ -71,7 +72,7 @@ SECTIONS *(.data.*) KEEP(*(.data)) DRIVER_TABLE - ECALL_TABLE + VCALL_TABLE } > vma_dmem AT > lma_mem .heap : ALIGN(HEAP_ALIGN) @@ -86,7 +87,7 @@ SECTIONS *(.stack) KEEP(*(.stack)) . = . + STACK_SIZE; - } > vma_dmem + } > vma_stak PROVIDE(_text_start = ADDR(.text)); PROVIDE(_text_size = SIZEOF(.text)); @@ -113,7 +114,7 @@ SECTIONS PROVIDE(_heap_size = SIZEOF(.heap)); PROVIDE(_heap_end = _heap_start + _heap_size - 1); - PROVIDE(_flash_size = _data_size + SIZEOF(.text) + _itim_size + SIZEOF(.rodata)); + PROVIDE(_flash_size = _data_size + SIZEOF(.text) + SIZEOF(.rodata)); PROVIDE(_ram_size = _bss_size + _data_size + SIZEOF(.stack) + SIZEOF(.heap)); ASSERT((_flash_size < FLASH_SIZE), "< x > Flash size exceeded ...") diff --git a/src/platform/rpi/rp2040/config.mk b/src/platform/rpi/rp2040/config.mk index 020448b2..e7d29369 100644 --- a/src/platform/rpi/rp2040/config.mk +++ b/src/platform/rpi/rp2040/config.mk @@ -32,8 +32,8 @@ FLASH_SIZE := 0x1000000 # 16M RAM_START := 0x20000000 RAM_SIZE := 0x42000 # 264K HEAP_SIZE ?= 16K -STACK_SIZE ?= 16K -STACK_SIZE_PCPU ?= 8K +STACK_SIZE ?= 8K +STACK_SIZE_PCPU ?= 4K $(eval $(call add_define,HEAP_SIZE)) $(eval $(call add_define,STACK_SIZE)) @@ -48,8 +48,8 @@ $(eval $(call add_define,ICLK)) N_EXCEP := 15 $(eval $(call add_define,N_EXCEP)) -N_PLAT_IRQS := 32 -$(eval $(call add_define,N_PLAT_IRQS)) +N_IRQ := 26 +$(eval $(call add_define,N_IRQ)) MAX_INTERRUPTS_PER_DEVICE := 1 $(eval $(call add_define,MAX_INTERRUPTS_PER_DEVICE)) diff --git a/src/platform/rpi/rp2040/include/plat_mem.h b/src/platform/rpi/rp2040/include/plat_mem.h index deea16e7..99b2f594 100644 --- a/src/platform/rpi/rp2040/include/plat_mem.h +++ b/src/platform/rpi/rp2040/include/plat_mem.h @@ -14,7 +14,8 @@ #define RAM_SIZE 264K #define V_IMEM_START 0x10000000 -#define V_DMEM_START 0x20000000 +#define V_DMEM_START 0x21000000 +#define V_STAK_START 0x20040000 #define L_MEM_START 0x10000000 #define L_MEM_LENGTH 16M @@ -23,6 +24,4 @@ #define IMEM_LENGTH 16M #define ALIGN_BOUND 4 - -#define STACK_SIZE 16K -#define STACK_SIZE_PCPU 8K +#define HEAP_ALIGN ALIGN_BOUND