Skip to content

Commit

Permalink
[sw] Clean-up software framework (#752)
Browse files Browse the repository at this point in the history
  • Loading branch information
stnolting authored Dec 16, 2023
2 parents 9a1d370 + 95aa676 commit 513f04b
Show file tree
Hide file tree
Showing 11 changed files with 307 additions and 324 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ mimpid = 0x01040312 -> Version 01.04.03.12 -> v1.4.3.12

| Date | Version | Comment | Link |
|:----:|:-------:|:--------|:----:|
| 11.12.2023 | 1.9.2.5 | clean-up software framework | [#752](https://github.com/stnolting/neorv32/pull/752) |
| 09.12.2023 | 1.9.2.4 | minor rtl code cleanups | [#747](https://github.com/stnolting/neorv32/pull/747) |
| 09.12.2023 | 1.9.2.3 | refine behavior of CPU's sleep state & signal | [#746](https://github.com/stnolting/neorv32/pull/746) |
| 05.12.2023 | 1.9.2.2 | reset `mstatus.mpp` to "machine-mode" | [#745](https://github.com/stnolting/neorv32/pull/745) |
Expand Down
35 changes: 0 additions & 35 deletions docs/datasheet/software.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,6 @@ The `crt0.S` start-up performs the following operations:
** All interrupt sources are disabled by clearing <<_mie>>.
** The return value of `main` is copied to the <<_mscratch>> CSR to allow inspection by the debugger.
** Call all _destructors_ (if there are any).
** An optional <<_after_main_handler>> is called (if defined at all).
** The CPU enters sleep mode executing the `wfi` instruction in an endless loop.

.Bootloader Start-Up Code
Expand All @@ -535,40 +534,6 @@ The early-trap handler should be replaced by a more capable / informative one as
(for example by using the <<_neorv32_runtime_environment>>).


:sectnums:
===== After-Main Handler

If the application's `main()` function actually returns, an _after main handler_ can be executed. This handler is a "normal" function
as the C runtime is still available when executed. If this handler uses any kind of peripheral/IO modules make sure these are
already initialized within the application. Otherwise you have to initialize them _inside_ the handler.

.After-main handler - function prototype
[source,c]
----
void __neorv32_crt0_after_main(int32_t return_code);
----

The function has exactly one argument (`return_code`) that provides the _return value_ of the application's main function.
For instance, this variable contains `-1` if the main function returned with `return -1;`. The after-main handler itself does
not provide a return value.

A simple UART output can be used to inform the user when the application's main function returns
(this example assumes that UART0 has been already properly configured in the actual application):

.After-main handler - simple example
[source,c]
----
void __neorv32_crt0_after_main(int32_t return_code) {
neorv32_uart0_printf("\n<RTE> main function returned with exit code %i. </RTE>\n", return_code); <1>
}
----
<1> Use `<RTE>` here to make clear this is a message comes from the runtime environment.

[NOTE]
The after-main handler is executed _after_ executing all destructor functions (if there are any at all).


<<<
// ####################################################################################################################

Expand Down
36 changes: 18 additions & 18 deletions rtl/core/neorv32_application_image.vhd
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@
-- Auto-generated memory initialization file (for APPLICATION) from source file <demo_blink_led/main.bin>
-- Size: 1080 bytes
-- MARCH: default
-- Built: 31.10.2023 17:08:39
-- Built: 15.12.2023 13:24:38

-- prototype defined in 'neorv32_package.vhd'
package body neorv32_application_image is

constant application_init_image : mem32_t := (
x"30005073",
x"000020b7",
x"80008093",
x"30009073",
x"00000097",
x"13808093",
x"12c08093",
x"30509073",
x"30401073",
x"80002117",
x"fe810113",
x"fe010113",
x"80000197",
x"7e418193",
x"7dc18193",
x"00000213",
x"00000293",
x"00000313",
Expand All @@ -41,9 +43,9 @@ x"00000f13",
x"00000f93",
x"43800593",
x"80000617",
x"f8060613",
x"f7860613",
x"80000697",
x"f7868693",
x"f7068693",
x"00c58e63",
x"00d65c63",
x"0005a703",
Expand All @@ -52,44 +54,42 @@ x"00458593",
x"00460613",
x"fedff06f",
x"80000717",
x"f5470713",
x"f4c70713",
x"80000797",
x"f4c78793",
x"f4478793",
x"00f75863",
x"00072023",
x"00470713",
x"ff5ff06f",
x"00000417",
x"36c40413",
x"36440413",
x"00000497",
x"36448493",
x"35c48493",
x"00945a63",
x"00042083",
x"000080e7",
x"00440413",
x"ff1ff06f",
x"00000513",
x"00000593",
x"080000ef",
x"078000ef",
x"30401073",
x"34051073",
x"00000417",
x"33440413",
x"32c40413",
x"00000497",
x"32c48493",
x"32448493",
x"00945a63",
x"00042083",
x"000080e7",
x"00440413",
x"ff1ff06f",
x"00000093",
x"00008463",
x"000080e7",
x"10500073",
x"ffdff06f",
x"34041073",
x"34202473",
x"02044663",
x"01f45413",
x"02041663",
x"34102473",
x"00240413",
x"34141073",
Expand Down
Loading

0 comments on commit 513f04b

Please sign in to comment.