Explorar o código

application: Add low power example for RISC-V

Use system timer to trigger interrupt before wfi,
and wfi should stop processor and restore when
timer interrupt triggered.

Signed-off-by: Huaqi Fang <578567190@qq.com>
Huaqi Fang %!s(int64=3) %!d(string=hai) anos
pai
achega
dd2e04a80a

+ 13 - 0
application/baremetal/lowpower/Makefile

@@ -0,0 +1,13 @@
+TARGET = lowpower
+
+NUCLEI_SDK_ROOT = ../../..
+
+SRCDIRS = .
+
+INCDIRS = .
+
+COMMON_FLAGS := -O2
+
+STDCLIB ?= newlib_full
+
+include $(NUCLEI_SDK_ROOT)/Build/Makefile.base

+ 34 - 0
application/baremetal/lowpower/main.c

@@ -0,0 +1,34 @@
+#include <stdio.h>
+#include <stdint.h>
+
+#include "nuclei_sdk_soc.h"
+
+#if defined(SIMULATION_MODE) && (SIMULATION_MODE == SIMULATION_MODE_XLSPIKE)
+#define RECORD_START()          UART0->RXFIFO = 1
+#define RECORD_END()            UART0->RXFIFO = 2
+#else
+#define RECORD_START()
+#define RECORD_END()
+#endif
+
+int main(void)
+{
+    volatile uint64_t start, end;
+
+    __disable_irq();
+    // need to adapt the tick according to your SoC
+    SysTick_Config(1);
+    SysTimer_Start();
+
+    start = __get_rv_cycle();
+    RECORD_START();
+    // Should not enter interrupt handler due to irq disabled
+    __WFI();
+    RECORD_END();
+    end = __get_rv_cycle();
+
+    printf("CSV, WFI Start/End, %llu/%llu\n", start, end);
+    printf("CSV, WFI Cost, %llu\n", (end - start));
+
+    return 0;
+}

+ 54 - 0
application/baremetal/lowpower/npk.yml

@@ -0,0 +1,54 @@
+## Package Base Information
+name: app-nsdk_lowpower
+owner: nuclei
+version:
+description: Lowpower Example
+type: app
+keywords:
+  - baremetal
+  - get started
+category: baremetal application
+license:
+homepage:
+
+## Package Dependency
+dependencies:
+  - name: sdk-nuclei_sdk
+    version:
+
+## Package Configurations
+configuration:
+  app_commonflags:
+    value: -O2
+    type: text
+    description: Application Compile Flags
+
+## Set Configuration for other packages
+setconfig:
+
+
+## Source Code Management
+codemanage:
+  copyfiles:
+    - path: ["*.c", "*.h"]
+  incdirs:
+    - path: ["./"]
+  libdirs:
+  ldlibs:
+    - libs:
+
+## Build Configuration
+buildconfig:
+  - type: gcc
+    common_flags: # flags need to be combined together across all packages
+      - flags: ${app_commonflags}
+    ldflags:
+    cflags:
+    asmflags:
+    cxxflags:
+    prebuild_steps: # could be override by app/bsp type
+      command:
+      description:
+    postbuild_steps: # could be override by app/bsp type
+      command:
+      description: