From 837873c3d719597bb86f5b40adbef858e547f362 Mon Sep 17 00:00:00 2001
From: Florian Sylvestre <fsylvestre@baylibre.com>
Date: Wed, 22 Mar 2023 14:47:48 +0100
Subject: [PATCH 11/27] Add blink example for renesas platform

---
 examples/renesas/blink/blink.c                | 30 ++++++++
 examples/renesas/blink/blink.oil              | 68 +++++++++++++++++++
 examples/renesas/blink/build.sh               | 17 +++++
 .../blink/cs_plus_rcar_download_all.py        | 37 ++++++++++
 4 files changed, 152 insertions(+)
 create mode 100644 examples/renesas/blink/blink.c
 create mode 100644 examples/renesas/blink/blink.oil
 create mode 100644 examples/renesas/blink/build.sh
 create mode 100644 examples/renesas/blink/cs_plus_rcar_download_all.py

diff --git a/examples/renesas/blink/blink.c b/examples/renesas/blink/blink.c
new file mode 100644
index 0000000..1b59819
--- /dev/null
+++ b/examples/renesas/blink/blink.c
@@ -0,0 +1,30 @@
+#include "tpl_os.h"
+
+#define APP_Task_blink_START_SEC_CODE
+#include "tpl_memmap.h"
+
+
+DeclareCounter(Software_Counter);
+
+FUNC(int, OS_APPL_CODE) main(void)
+{
+	StartOS(OSDEFAULTAPPMODE);
+	return 0;
+}
+
+
+
+TASK(blink)
+{
+	TickType XXXXX;
+	GetCounterValue(Software_Counter, &XXXXX);
+	TerminateTask();
+}
+
+ISR(isr_button2)
+{
+
+}
+
+#define APP_Task_blink_STOP_SEC_CODE
+#include "tpl_memmap.h"
diff --git a/examples/renesas/blink/blink.oil b/examples/renesas/blink/blink.oil
new file mode 100644
index 0000000..c1a9fea
--- /dev/null
+++ b/examples/renesas/blink/blink.oil
@@ -0,0 +1,68 @@
+OIL_VERSION = "4.0";
+
+IMPLEMENTATION trampoline {
+   //This fix the default STACKSIZE of tasks
+  TASK {
+    UINT32 STACKSIZE = 1000 ; // FSY: Why??
+  } ;
+
+  // This fix the default STACKSIZE of ISRs
+  ISR {
+    UINT32 STACKSIZE = 1000 ;
+  } ;
+};
+
+CPU blink {
+  OS config {
+    STATUS = EXTENDED;
+    PAINT_STACK = TRUE;
+    PAINT_REGISTERS = TRUE;
+    
+    BUILD = TRUE {
+      TRAMPOLINE_BASE_PATH = "../../../";
+      APP_SRC = "blink.c";
+      APP_NAME = "blink_exe";
+      LDFLAGS="-debug -nocompress -NOOPtimize -memory=high -nologo -SHow=ALL";
+      CFLAGS="-Xcpu=g4mh -g -g_line -Xfxu=off -Xasm_path=.";
+      LINKER = "rlink";
+      SYSTEM = CMAKE;
+    };
+    SYSTEM_CALL = TRUE;
+  };
+
+  APPMODE std {};
+
+  TASK blink {
+    PRIORITY = 3;
+    AUTOSTART = FALSE;
+    ACTIVATION = 1;
+    SCHEDULE = FULL;
+  };
+
+  ISR isr_button2 {
+    CATEGORY = 2;
+    PRIORITY = 1;
+    SOURCE = SysTick2;
+  };
+
+  COUNTER Software_Counter {
+    MAXALLOWEDVALUE = 100;
+    TICKSPERBASE = 1;
+    MINCYCLE = 1;
+    TYPE = SOFTWARE;
+    SOURCE = SysTick;
+  };
+
+  ALARM blink_blink {
+    COUNTER = SystemCounter;
+    ACTION = ACTIVATETASK {
+      TASK = blink;
+    };
+    
+    AUTOSTART = TRUE {
+      APPMODE = std;
+      ALARMTIME = 200;
+      CYCLETIME = 200;
+    };
+  };
+};
diff --git a/examples/renesas/blink/build.sh b/examples/renesas/blink/build.sh
new file mode 100644
index 0000000..053a7f8
--- /dev/null
+++ b/examples/renesas/blink/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/ blink.oil
+cd _build
+echo "*** Run CMake ***"
+cmake -G "Unix Makefiles" -D CMAKE_TOOLCHAIN_FILE=../blink/compiler.cmake ..
+echo "*** Run Make ***"
+make
diff --git a/examples/renesas/blink/cs_plus_rcar_download_all.py b/examples/renesas/blink/cs_plus_rcar_download_all.py
new file mode 100644
index 0000000..86dff2f
--- /dev/null
+++ b/examples/renesas/blink/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/blink_exe.abs", downloadOption = DownloadOption.SymbolOnly, append = False, flashErase = False, vendorType = VendorType.Auto)
+print "Download Trampoline/Hello_world (RUN)"
+debugger.Download.Hex("_build/blink_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()
-- 
2.34.1

