From 3eb8e4c9c51d9a3193067b39724cac94255f9960 Mon Sep 17 00:00:00 2001
From: Florian Sylvestre <fsylvestre@baylibre.com>
Date: Fri, 16 Dec 2022 13:33:59 +0100
Subject: [PATCH 06/27] Add one_task example for Renesas platform

---
 examples/renesas/one_task/build.sh            | 17 +++++++++
 .../one_task/cs_plus_rcar_download_all.py     | 37 +++++++++++++++++++
 examples/renesas/one_task/one_task.c          | 14 +++++++
 examples/renesas/one_task/one_task.oil        | 25 +++++++++++++
 4 files changed, 93 insertions(+)
 create mode 100644 examples/renesas/one_task/build.sh
 create mode 100644 examples/renesas/one_task/cs_plus_rcar_download_all.py
 create mode 100644 examples/renesas/one_task/one_task.c
 create mode 100644 examples/renesas/one_task/one_task.oil

diff --git a/examples/renesas/one_task/build.sh b/examples/renesas/one_task/build.sh
new file mode 100644
index 0000000..65f2fe2
--- /dev/null
+++ b/examples/renesas/one_task/build.sh
@@ -0,0 +1,17 @@
+#!/usr/bin/env bash
+
+#stop on errors
+set -e
+
+if [[ ! -d "_build" ]]
+then
+    mkdir _build
+fi
+
+echo "*** Run Goil ***"
+goil --target=renesas/g4mh --templates=../../../goil/templates/ one_task.oil
+cd _build
+echo "*** Run CMake ***"
+cmake -G "Unix Makefiles" -D CMAKE_TOOLCHAIN_FILE=../one_task/compiler.cmake ..
+echo "*** Run Make ***"
+make
diff --git a/examples/renesas/one_task/cs_plus_rcar_download_all.py b/examples/renesas/one_task/cs_plus_rcar_download_all.py
new file mode 100644
index 0000000..c32d981
--- /dev/null
+++ b/examples/renesas/one_task/cs_plus_rcar_download_all.py
@@ -0,0 +1,37 @@
+﻿
+import time
+ClearConsole()
+print "1PE_ATK2"
+print "Resetting debugger"
+debugger.Reset()
+time.sleep(2)
+print "SYSCTRL 0x0003"
+debugger.Register.SetValue("SYSCTRL.BOOTCTRL", 0x0003)
+time.sleep(2)
+print "CPU Stop"
+debugger.Stop()
+time.sleep(2)
+print "HBG_CS 0x00000003"
+debugger.Register.SetValue("HBG_CS0.HBGPROT0", 0x00000003)
+debugger.Register.SetValue("HBG_CS1.HBGPROT0", 0x00000003)
+debugger.Register.SetValue("HBG_CS2.HBGPROT0", 0x00000003)
+#time.sleep(1)
+print "CSRM 0x12B9B0A0"
+debugger.Register.SetValue("CSRM0.CSRM0CSIFCODE", 0x12B9B0A0)
+debugger.Register.SetValue("CSRM1.CSRM1CSIFCODE", 0x12B9B0A0)
+debugger.Register.SetValue("CSRM2.CSRM2CSIFCODE", 0x12B9B0A0)
+#time.sleep(1)
+print "Download Trampoline/Hello_world"
+debugger.Download.LoadModule("_build/one_task_exe.abs", downloadOption = DownloadOption.SymbolOnly, append = False, flashErase = False, vendorType = VendorType.Auto)
+print "Download Trampoline/Hello_world (RUN)"
+debugger.Download.Hex("_build/one_task_exe.run", offset = 0xF0000000, append = True, flashErase = False)
+print "CSRM 0x12B9B0A1"
+debugger.Register.SetValue("CSRM0.CSRM0CSIFCODE", 0x12B9B0A1)
+debugger.Register.SetValue("CSRM1.CSRM1CSIFCODE", 0x12B9B0A1)
+debugger.Register.SetValue("CSRM2.CSRM2CSIFCODE", 0x12B9B0A1)
+#time.sleep(1)
+print "Set Reset PC"
+debugger.Register.SetValue("PC", 0x200)
+#time.sleep(1)
+print "Starting G4"
+debugger.Go()
diff --git a/examples/renesas/one_task/one_task.c b/examples/renesas/one_task/one_task.c
new file mode 100644
index 0000000..e0f2de0
--- /dev/null
+++ b/examples/renesas/one_task/one_task.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include "tpl_os.h"
+
+int main(void)
+{
+    StartOS(OSDEFAULTAPPMODE);
+    return 0;
+}
+
+TASK(my_only_task)
+{
+  TerminateTask();
+}
+
diff --git a/examples/renesas/one_task/one_task.oil b/examples/renesas/one_task/one_task.oil
new file mode 100644
index 0000000..3479d5a
--- /dev/null
+++ b/examples/renesas/one_task/one_task.oil
@@ -0,0 +1,25 @@
+OIL_VERSION = "4.2";
+
+CPU only_one_task {  	
+  OS config {			
+    STATUS = EXTENDED;
+    BUILD = TRUE { 
+      APP_SRC = "one_task.c";
+      TRAMPOLINE_BASE_PATH = "../../../";
+      LDFLAGS="-debug -nocompress -NOOPtimize -memory=high -nologo -SHow=ALL";
+      CFLAGS="-Xcpu=g4mh -g -g_line -Xfxu=off -Xasm_path=.";
+      APP_NAME = "one_task_exe";
+      LINKER = "rlink";
+      SYSTEM = CMAKE;
+    };
+  };
+  
+  APPMODE stdAppmode {}; 
+  
+  TASK my_only_task { 
+    PRIORITY = 1;
+    AUTOSTART = TRUE { APPMODE = stdAppmode; };
+    ACTIVATION = 1;
+    SCHEDULE = FULL;
+  };
+};
-- 
2.34.1

