Browse Source

Added ADC, H-Bridge and motor models, refactored project structure

Eyck Jentzsch 1 year ago
parent
commit
38099e3fc6
61 changed files with 696 additions and 44 deletions
  1. 1
    0
      CMakeLists.txt
  2. 10
    2
      etc/cmake DBT-RISE-RISCV Debug.launch
  3. 6
    2
      etc/cmake.sh
  4. 9
    1
      etc/dbt-riscv Debug hello gdb.launch
  5. 9
    1
      etc/dbt-riscv Debug hello w plugin.launch
  6. 3
    0
      etc/hello Debug.launch
  7. 102
    0
      platform/CMakeLists.txt
  8. 0
    0
      platform/gen_input/aon.rdl
  9. 0
    0
      platform/gen_input/clint.rdl
  10. 0
    0
      platform/gen_input/fe310.rdl
  11. 0
    0
      platform/gen_input/gpio.rdl
  12. 0
    0
      platform/gen_input/plic.rdl
  13. 0
    0
      platform/gen_input/prci.rdl
  14. 0
    0
      platform/gen_input/spi.rdl
  15. 0
    0
      platform/gen_input/uart.rdl
  16. 0
    0
      platform/incl/sysc/SiFive/aon.h
  17. 0
    0
      platform/incl/sysc/SiFive/clint.h
  18. 0
    0
      platform/incl/sysc/SiFive/gen/aon_regs.h
  19. 0
    0
      platform/incl/sysc/SiFive/gen/clint_regs.h
  20. 0
    0
      platform/incl/sysc/SiFive/gen/e300_plat_t.h
  21. 0
    0
      platform/incl/sysc/SiFive/gen/gpio_regs.h
  22. 0
    0
      platform/incl/sysc/SiFive/gen/plic_regs.h
  23. 0
    0
      platform/incl/sysc/SiFive/gen/prci_regs.h
  24. 0
    0
      platform/incl/sysc/SiFive/gen/spi_regs.h
  25. 0
    0
      platform/incl/sysc/SiFive/gen/uart_regs.h
  26. 0
    0
      platform/incl/sysc/SiFive/gpio.h
  27. 4
    4
      platform/incl/sysc/SiFive/hifive1.h
  28. 0
    0
      platform/incl/sysc/SiFive/plic.h
  29. 0
    0
      platform/incl/sysc/SiFive/prci.h
  30. 0
    0
      platform/incl/sysc/SiFive/spi.h
  31. 0
    0
      platform/incl/sysc/SiFive/uart.h
  32. 3
    3
      platform/incl/sysc/sc_comm_singleton.h
  33. 3
    3
      platform/incl/sysc/tlm_extensions.h
  34. 105
    0
      platform/incl/sysc/top/BLDC.h
  35. 38
    0
      platform/incl/sysc/top/dcmotor.h
  36. 39
    0
      platform/incl/sysc/top/h_bridge.h
  37. 3
    3
      platform/incl/sysc/top/mcp3008.h
  38. 10
    5
      platform/incl/sysc/top/system.h
  39. 3
    3
      platform/incl/sysc/top/terminal.h
  40. 4
    3
      platform/src/CMakeLists.txt
  41. 2
    2
      platform/src/sc_main.cpp
  42. 164
    0
      platform/src/sysc/BLDC.cpp
  43. 0
    0
      platform/src/sysc/aon.cpp
  44. 0
    0
      platform/src/sysc/clint.cpp
  45. 69
    0
      platform/src/sysc/dcmotor.cpp
  46. 0
    0
      platform/src/sysc/gpio.cpp
  47. 47
    0
      platform/src/sysc/h_bridge.cpp
  48. 2
    2
      platform/src/sysc/hifive1.cpp
  49. 2
    1
      platform/src/sysc/mcp3008.cpp
  50. 0
    0
      platform/src/sysc/plic.cpp
  51. 0
    0
      platform/src/sysc/prci.cpp
  52. 0
    0
      platform/src/sysc/sc_comm_singleton.cpp
  53. 0
    0
      platform/src/sysc/spi.cpp
  54. 32
    3
      platform/src/sysc/system.cpp
  55. 2
    1
      platform/src/sysc/terminal.cpp
  56. 0
    0
      platform/src/sysc/uart.cpp
  57. 20
    1
      riscv.sc/CMakeLists.txt
  58. 0
    0
      riscv.sc/incl/sysc/core_complex.h
  59. 1
    1
      riscv.sc/src/core_complex.cpp
  60. 2
    2
      riscv/src/CMakeLists.txt
  61. 1
    1
      sc-components

+ 1
- 0
CMakeLists.txt View File

@@ -58,5 +58,6 @@ add_subdirectory(softfloat)
58 58
 GET_DIRECTORY_PROPERTY(SOFTFLOAT_INCLUDE_DIRS DIRECTORY softfloat DEFINITION SOFTFLOAT_INCLUDE_DIRS)
59 59
 add_subdirectory(riscv)
60 60
 add_subdirectory(riscv.sc)
61
+add_subdirectory(platform)
61 62
 
62 63
 message(STATUS "Build Type: ${CMAKE_BUILD_TYPE}")

+ 10
- 2
etc/cmake DBT-RISE-RISCV Debug.launch View File

@@ -1,7 +1,15 @@
1 1
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 2
 <launchConfiguration type="org.eclipse.ui.externaltools.ProgramLaunchConfigurationType">
3
+<booleanAttribute key="de.toem.impulse.launchactivateLaunch" value="false"/>
4
+<booleanAttribute key="de.toem.impulse.launchactivateTermination" value="false"/>
5
+<intAttribute key="de.toem.impulse.launchdelayLaunch" value="0"/>
6
+<intAttribute key="de.toem.impulse.launchlaunch" value="2"/>
7
+<intAttribute key="de.toem.impulse.launchmode" value="3"/>
8
+<stringAttribute key="de.toem.impulse.launchport" value=""/>
9
+<booleanAttribute key="de.toem.impulse.launchrestart" value="true"/>
10
+<intAttribute key="de.toem.impulse.launchterminate" value="1"/>
3 11
 <stringAttribute key="org.eclipse.ui.externaltools.ATTR_LAUNCH_CONFIGURATION_BUILD_SCOPE" value="${none}"/>
4
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/dbt-riscv/etc/cmake.sh}"/>
12
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_LOCATION" value="${workspace_loc:/DBT-RISE-RISCV/etc/cmake.sh}"/>
5 13
 <stringAttribute key="org.eclipse.ui.externaltools.ATTR_TOOL_ARGUMENTS" value="-DCMAKE_BUILD_TYPE=Debug .."/>
6
-<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/dbt-riscv}"/>
14
+<stringAttribute key="org.eclipse.ui.externaltools.ATTR_WORKING_DIRECTORY" value="${workspace_loc:/DBT-RISE-RISCV}"/>
7 15
 </launchConfiguration>

+ 6
- 2
etc/cmake.sh View File

@@ -1,7 +1,11 @@
1 1
 #!/bin/sh
2 2
 ##
3 3
 
4
-suffix=Debug
4
+if [ -n "$1" ]; then
5
+	suffix=$1
6
+else
7
+	suffix=Debug
8
+fi
5 9
 cwd=`pwd`
6 10
 for i in $*; do	
7 11
 	if echo "$i" | grep 'CMAKE_BUILD_TYPE='; then
@@ -9,4 +13,4 @@ for i in $*; do
9 13
 	fi
10 14
 done
11 15
 mkdir -p build/$suffix && cd build/$suffix
12
-cmake $* $cwd
16
+cmake $* $cwd

+ 9
- 1
etc/dbt-riscv Debug hello gdb.launch View File

@@ -1,5 +1,13 @@
1 1
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 2
 <launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
3
+<booleanAttribute key="de.toem.impulse.launchactivateLaunch" value="false"/>
4
+<booleanAttribute key="de.toem.impulse.launchactivateTermination" value="false"/>
5
+<intAttribute key="de.toem.impulse.launchdelayLaunch" value="0"/>
6
+<intAttribute key="de.toem.impulse.launchlaunch" value="2"/>
7
+<intAttribute key="de.toem.impulse.launchmode" value="3"/>
8
+<stringAttribute key="de.toem.impulse.launchport" value=""/>
9
+<booleanAttribute key="de.toem.impulse.launchrestart" value="true"/>
10
+<intAttribute key="de.toem.impulse.launchterminate" value="1"/>
3 11
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB" value="true"/>
4 12
 <listAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB_LIST"/>
5 13
 <stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="gdb"/>
@@ -19,7 +27,7 @@
19 27
 <booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
20 28
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
21 29
 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="-v4&#10;-g10000&#10;${project_loc:hello}/hello"/>
22
-<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Debug/riscv/bin/riscv"/>
30
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Debug/riscv/bin/riscv-sim"/>
23 31
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="DBT-RISE-RISCV"/>
24 32
 <booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
25 33
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.debug.1751741082"/>

+ 9
- 1
etc/dbt-riscv Debug hello w plugin.launch View File

@@ -1,5 +1,13 @@
1 1
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
2 2
 <launchConfiguration type="org.eclipse.cdt.launch.applicationLaunchType">
3
+<booleanAttribute key="de.toem.impulse.launchactivateLaunch" value="false"/>
4
+<booleanAttribute key="de.toem.impulse.launchactivateTermination" value="false"/>
5
+<intAttribute key="de.toem.impulse.launchdelayLaunch" value="0"/>
6
+<intAttribute key="de.toem.impulse.launchlaunch" value="2"/>
7
+<intAttribute key="de.toem.impulse.launchmode" value="3"/>
8
+<stringAttribute key="de.toem.impulse.launchport" value=""/>
9
+<booleanAttribute key="de.toem.impulse.launchrestart" value="true"/>
10
+<intAttribute key="de.toem.impulse.launchterminate" value="1"/>
3 11
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB" value="true"/>
4 12
 <listAttribute key="org.eclipse.cdt.dsf.gdb.AUTO_SOLIB_LIST"/>
5 13
 <stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="gdb"/>
@@ -19,7 +27,7 @@
19 27
 <booleanAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN" value="true"/>
20 28
 <stringAttribute key="org.eclipse.cdt.launch.DEBUGGER_STOP_AT_MAIN_SYMBOL" value="main"/>
21 29
 <stringAttribute key="org.eclipse.cdt.launch.PROGRAM_ARGUMENTS" value="-v4&#10;-p ic=${workspace_loc:DBT-RISE-RISCV}/cycles.txt&#10;${project_loc:hello}/hello"/>
22
-<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Debug/riscv/bin/riscv"/>
30
+<stringAttribute key="org.eclipse.cdt.launch.PROGRAM_NAME" value="build/Debug/riscv/bin/riscv-sim"/>
23 31
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_ATTR" value="DBT-RISE-RISCV"/>
24 32
 <booleanAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_AUTO_ATTR" value="false"/>
25 33
 <stringAttribute key="org.eclipse.cdt.launch.PROJECT_BUILD_CONFIG_ID_ATTR" value="cdt.managedbuild.config.gnu.exe.debug.1751741082"/>

+ 3
- 0
etc/hello Debug.launch View File

@@ -8,6 +8,7 @@
8 8
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.initCommands" value=""/>
9 9
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.ipAddress" value="localhost"/>
10 10
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDevice" value="Generic TCP/IP"/>
11
+<stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.jtagDeviceId" value="org.eclipse.cdt.debug.gdbjtag.core.jtagdevice.genericDevice"/>
11 12
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadImage" value="false"/>
12 13
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.loadSymbols" value="true"/>
13 14
 <stringAttribute key="org.eclipse.cdt.debug.gdbjtag.core.pcRegister" value=""/>
@@ -25,6 +26,8 @@
25 26
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useProjBinaryForSymbols" value="true"/>
26 27
 <booleanAttribute key="org.eclipse.cdt.debug.gdbjtag.core.useRemoteTarget" value="true"/>
27 28
 <stringAttribute key="org.eclipse.cdt.dsf.gdb.DEBUG_NAME" value="riscv64-unknown-elf-gdb"/>
29
+<booleanAttribute key="org.eclipse.cdt.dsf.gdb.REMOTE_TIMEOUT_ENABLED" value="false"/>
30
+<stringAttribute key="org.eclipse.cdt.dsf.gdb.REMOTE_TIMEOUT_VALUE" value=""/>
28 31
 <booleanAttribute key="org.eclipse.cdt.dsf.gdb.UPDATE_THREADLIST_ON_SUSPEND" value="true"/>
29 32
 <intAttribute key="org.eclipse.cdt.launch.ATTR_BUILD_BEFORE_LAUNCH_ATTR" value="0"/>
30 33
 <stringAttribute key="org.eclipse.cdt.launch.COREFILE_PATH" value=""/>

+ 102
- 0
platform/CMakeLists.txt View File

@@ -0,0 +1,102 @@
1
+cmake_minimum_required(VERSION 3.3)
2
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/../cmake) # main (top) cmake dir
3
+set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_CURRENT_SOURCE_DIR}/cmake) # project specific cmake dir
4
+
5
+# CMake useful variables
6
+set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin")
7
+set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib") 
8
+set(CMAKE_LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib")
9
+
10
+# Set the name of your project here
11
+project("riscv.sc")
12
+
13
+# Set the version number of your project here (format is MAJOR.MINOR.PATCHLEVEL - e.g. 1.0.0)
14
+set(VERSION_MAJOR "0")
15
+set(VERSION_MINOR "0")
16
+set(VERSION_PATCH "1")
17
+set(VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH})
18
+
19
+include(Common)
20
+
21
+## Git (and its revision)
22
+find_package(Git QUIET) # if we don't find git or FindGit.cmake is not on the system we ignore it.
23
+## The Git module will trigger a reconfiguration for each pull that will bring a new revision on the local repository
24
+set (VCS_REVISION "-1")
25
+if(GIT_FOUND)
26
+    include(GetGitRevisionDescription)
27
+    get_git_head_revision(GIT_REFSPEC GIT_SHA1)
28
+    message(STATUS "GIT branch ${GIT_REFSPEC}")
29
+    message(STATUS "GIT revision ${GIT_SHA1}")
30
+    set (VCS_REVISION ${GIT_SHA1})
31
+endif()
32
+
33
+# This line finds the boost lib and headers. 
34
+set(Boost_NO_BOOST_CMAKE ON) #  Don't do a find_package in config mode before searching for a regular boost install.
35
+find_package(Boost COMPONENTS program_options system thread REQUIRED)
36
+
37
+find_package(LLVM REQUIRED CONFIG)
38
+message(STATUS "Found LLVM ${LLVM_PACKAGE_VERSION}")
39
+message(STATUS "Using LLVMConfig.cmake in: ${LLVM_DIR}")
40
+llvm_map_components_to_libnames(llvm_libs support core mcjit x86codegen x86asmparser)
41
+
42
+find_package(SystemC)
43
+if(SystemC_FOUND)
44
+    add_definitions(-DWITH_SYSTEMC)
45
+    include_directories(${SystemC_INCLUDE_DIRS})
46
+    link_directories(${SystemC_LIBRARY_DIRS})
47
+else(SystemC_FOUND)
48
+    message( FATAL_ERROR "SystemC library not found." )
49
+endif(SystemC_FOUND)
50
+
51
+if(CCI_FOUND)
52
+    include_directories(${CCI_INCLUDE_DIRS})
53
+    link_directories(${CCI_LIBRARY_DIRS})
54
+else()
55
+    message( FATAL_ERROR "SystemC CCI library not found." )
56
+endif()
57
+
58
+if(SCV_FOUND)   
59
+    add_definitions(-DWITH_SCV)
60
+    link_directories(${SCV_LIBRARY_DIRS})
61
+endif(SCV_FOUND)
62
+
63
+# This sets the include directory for the reference project. This is the -I flag in gcc.
64
+include_directories(
65
+    ${PROJECT_SOURCE_DIR}/incl
66
+    ${LLVM_INCLUDE_DIRS}
67
+)
68
+
69
+add_dependent_subproject(dbt-core)
70
+add_dependent_subproject(sc-components)
71
+add_dependent_subproject(riscv)
72
+add_dependent_subproject(riscv.sc)
73
+
74
+include_directories(
75
+    ${PROJECT_SOURCE_DIR}/incl
76
+    ${PROJECT_SOURCE_DIR}/../riscv/incl
77
+    ${PROJECT_SOURCE_DIR}/../external/elfio
78
+    ${PROJECT_SOURCE_DIR}/../external/libGIS
79
+    ${Boost_INCLUDE_DIRS}
80
+)
81
+
82
+
83
+# Mac needed variables (adapt for your needs - http://www.cmake.org/Wiki/CMake_RPATH_handling#Mac_OS_X_and_the_RPATH)
84
+set(CMAKE_MACOSX_RPATH ON)
85
+set(CMAKE_SKIP_BUILD_RPATH FALSE)
86
+set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
87
+set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
88
+set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
89
+
90
+add_subdirectory(src)
91
+
92
+#
93
+# SYSTEM PACKAGING (RPM, TGZ, ...)
94
+# _____________________________________________________________________________
95
+
96
+#include(CPackConfig)
97
+
98
+#
99
+# CMAKE PACKAGING (for other CMake projects to use this one easily)
100
+# _____________________________________________________________________________
101
+
102
+#include(PackageConfigurator)

riscv.sc/gen_input/aon.rdl → platform/gen_input/aon.rdl View File


riscv.sc/gen_input/clint.rdl → platform/gen_input/clint.rdl View File


riscv.sc/gen_input/fe310.rdl → platform/gen_input/fe310.rdl View File


riscv.sc/gen_input/gpio.rdl → platform/gen_input/gpio.rdl View File


riscv.sc/gen_input/plic.rdl → platform/gen_input/plic.rdl View File


riscv.sc/gen_input/prci.rdl → platform/gen_input/prci.rdl View File


riscv.sc/gen_input/spi.rdl → platform/gen_input/spi.rdl View File


riscv.sc/gen_input/uart.rdl → platform/gen_input/uart.rdl View File


riscv.sc/incl/sysc/SiFive/aon.h → platform/incl/sysc/SiFive/aon.h View File


riscv.sc/incl/sysc/SiFive/clint.h → platform/incl/sysc/SiFive/clint.h View File


riscv.sc/incl/sysc/SiFive/gen/aon_regs.h → platform/incl/sysc/SiFive/gen/aon_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/clint_regs.h → platform/incl/sysc/SiFive/gen/clint_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/e300_plat_t.h → platform/incl/sysc/SiFive/gen/e300_plat_t.h View File


riscv.sc/incl/sysc/SiFive/gen/gpio_regs.h → platform/incl/sysc/SiFive/gen/gpio_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/plic_regs.h → platform/incl/sysc/SiFive/gen/plic_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/prci_regs.h → platform/incl/sysc/SiFive/gen/prci_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/spi_regs.h → platform/incl/sysc/SiFive/gen/spi_regs.h View File


riscv.sc/incl/sysc/SiFive/gen/uart_regs.h → platform/incl/sysc/SiFive/gen/uart_regs.h View File


riscv.sc/incl/sysc/SiFive/gpio.h → platform/incl/sysc/SiFive/gpio.h View File


riscv.sc/incl/sysc/SiFive/platform.h → platform/incl/sysc/SiFive/hifive1.h View File

@@ -44,7 +44,7 @@
44 44
 #include "prci.h"
45 45
 #include "spi.h"
46 46
 #include "uart.h"
47
-#include "core_complex.h"
47
+#include "sysc/core_complex.h"
48 48
 
49 49
 #include "scc/memory.h"
50 50
 #include "scc/router.h"
@@ -56,16 +56,16 @@
56 56
 
57 57
 namespace sysc {
58 58
 
59
-class platform : public sc_core::sc_module {
59
+class hifive1 : public sc_core::sc_module {
60 60
 public:
61
-    SC_HAS_PROCESS(platform);
61
+    SC_HAS_PROCESS(hifive1);
62 62
 
63 63
     sc_core::sc_vector<tlm::tlm_signal_initiator_socket<sc_dt::sc_logic>> pins_o;
64 64
     sc_core::sc_vector<tlm::tlm_signal_target_socket<sc_dt::sc_logic>>    pins_i;
65 65
 
66 66
     sc_core::sc_in<bool> erst_n;
67 67
 
68
-    platform(sc_core::sc_module_name nm);
68
+    hifive1(sc_core::sc_module_name nm);
69 69
 
70 70
 private:
71 71
     SiFive::core_complex i_core_complex;

riscv.sc/incl/sysc/SiFive/plic.h → platform/incl/sysc/SiFive/plic.h View File


riscv.sc/incl/sysc/SiFive/prci.h → platform/incl/sysc/SiFive/prci.h View File


riscv.sc/incl/sysc/SiFive/spi.h → platform/incl/sysc/SiFive/spi.h View File


riscv.sc/incl/sysc/SiFive/uart.h → platform/incl/sysc/SiFive/uart.h View File


riscv.sc/incl/sysc/sc_comm_singleton.h → platform/incl/sysc/sc_comm_singleton.h View File

@@ -34,8 +34,8 @@
34 34
 //
35 35
 ////////////////////////////////////////////////////////////////////////////////
36 36
 
37
-#ifndef RISCV_SC_INCL_SYSC_SC_COMM_SINGLETON_H_
38
-#define RISCV_SC_INCL_SYSC_SC_COMM_SINGLETON_H_
37
+#ifndef _SYSC_SC_COMM_SINGLETON_H_
38
+#define _SYSC_SC_COMM_SINGLETON_H_
39 39
 
40 40
 #include <sysc/kernel/sc_module.h>
41 41
 #include <seasocks/PageHandler.h>
@@ -110,4 +110,4 @@ private:
110 110
 
111 111
 } /* namespace sysc */
112 112
 
113
-#endif /* RISCV_SC_INCL_SYSC_SC_COMM_SINGLETON_H_ */
113
+#endif /* _SYSC_SC_COMM_SINGLETON_H_ */

riscv.sc/incl/sysc/tlm_extensions.h → platform/incl/sysc/tlm_extensions.h View File

@@ -5,8 +5,8 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#ifndef RISCV_SC_INCL_SYSC_TLM_EXTENSIONS_H_
9
-#define RISCV_SC_INCL_SYSC_TLM_EXTENSIONS_H_
8
+#ifndef _SYSC_TLM_EXTENSIONS_H_
9
+#define _SYSC_TLM_EXTENSIONS_H_
10 10
 
11 11
 #include "tlm/tlm_extensions.h"
12 12
 
@@ -45,4 +45,4 @@ struct tlm_signal_spi_extension : public tlm::tlm_unmanaged_extension<tlm_signal
45 45
 
46 46
 
47 47
 
48
-#endif /* RISCV_SC_INCL_SYSC_TLM_EXTENSIONS_H_ */
48
+#endif /* _SYSC_TLM_EXTENSIONS_H_ */

+ 105
- 0
platform/incl/sysc/top/BLDC.h View File

@@ -0,0 +1,105 @@
1
+/*
2
+ * BLDC.h
3
+ *
4
+ *  Created on: 26.06.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#ifndef BLDC_H_
9
+#define BLDC_H_
10
+
11
+#include <boost/numeric/odeint.hpp>
12
+namespace odeint = boost::numeric::odeint;
13
+
14
+inline
15
+double norm_angle(double alpha){
16
+  double alpha_n = fmod(alpha, M_PI * 2);
17
+  if (alpha_n < 0.) alpha_n += (M_PI * 2);
18
+  return alpha_n;
19
+}
20
+
21
+
22
+class BLDC {
23
+public:
24
+    struct Config {
25
+        double inertia = 0.0005;        /* aka 'J' in kg/(m^2) */
26
+        double damping = 0.000089;      /* aka 'B' in Nm/(rad/s) */
27
+        double static_friction = 0.0;   /* in Nm */
28
+        //double Kv = 0.0042;             /* motor constant in RPM/V */
29
+        double Ke = 0.0042;             /* back emf constant in V/rad/s*/
30
+        double L = 0.0027;              /* Coil inductance in H */
31
+        double M = -0.000069;            /* Mutual coil inductance in H */
32
+        double R = 2.875;               /* Coil resistence in Ohm */
33
+        int NbPoles = 2;                /* NbPoles / 2 = Number of pole pairs (you count the permanent magnets on the rotor to get NbPoles) */
34
+    };
35
+
36
+    using StateVector = std::array<double, 5>;
37
+
38
+    struct State{
39
+        double& theta;   /* angle of the rotor */
40
+        double& omega;   /* angular speed of the rotor */
41
+        double& ia;          /* phase a current */
42
+        double& ib;          /* phase b current */
43
+        double& ic;          /* phase c current */
44
+        explicit State(StateVector& v):theta(v[0]), omega(v[1]), ia(v[2]), ib(v[3]), ic(v[4]){}
45
+        State(State&&) = delete;
46
+        State(const State&) = delete;
47
+        State& operator=(const State&) = delete;  // Copy assignment operator
48
+        State& operator=(const State&&) = delete;  // Move assignment operator
49
+        ~State(){}
50
+        void init(){
51
+            theta = ia = ib = ic = 0;
52
+            omega = 0.;
53
+        }
54
+    };
55
+
56
+    explicit BLDC(const Config config);
57
+
58
+    virtual ~BLDC();
59
+
60
+    void set_input(std::array<double, 3> vin){
61
+        this->vin=vin;
62
+    }
63
+
64
+    void run(double dt);
65
+
66
+    void printToStream(std::ostream&) const;
67
+
68
+    double get_current_time(){return current_time;}
69
+
70
+    std::tuple<double, double, double> get_voltages(){
71
+        return std::tuple<double, double, double>(
72
+                voltages[VA]+voltages[EA]+state.ia*config.R,
73
+                voltages[VB]+voltages[EB]+state.ib*config.R,
74
+                voltages[VC]+voltages[EC]+state.ic*config.R
75
+                );
76
+    }
77
+    const State& getState(){ return state;}
78
+
79
+    void setLoad(double torque){torque_load=torque;}
80
+protected:
81
+    Config config;
82
+    StateVector stateVector;
83
+    State state;
84
+    std::array<double, 3> vin;
85
+    double current_time = 0.0;
86
+    double torque_load=0.0;
87
+    double etorque=0.0, mtorque=0.0;
88
+    const double dt = 0.000001;
89
+    std::array<double, 7> voltages;
90
+    enum VoltageNames {EA=0, EB=1, EC=2, VA=3, VB=4, VC=5, VCENTER=6};
91
+    double calc_bemf_factor(const State& state, double theta );
92
+    void calc_back_emf(const State& state, double theta_e );
93
+    void calc_voltages();
94
+    // ODE part
95
+    //boost::numeric::odeint::runge_kutta4< StateVector > stepper;
96
+    //boost::numeric::odeint::runge_kutta_cash_karp54<StateVector > stepper;
97
+    //using  stepper_type = odeint::runge_kutta_dopri5<StateVector>;
98
+    //using  stepper_type = odeint::runge_kutta_cash_karp54< StateVector>;
99
+    using  stepper_type = odeint::runge_kutta_fehlberg78< StateVector>;
100
+    void rotor_dyn( const StateVector& x , StateVector& dxdt , const double t );
101
+};
102
+
103
+std::ostream& operator<<(std::ostream& os, const BLDC& bldc);
104
+
105
+#endif /* BLDC_H_ */

+ 38
- 0
platform/incl/sysc/top/dcmotor.h View File

@@ -0,0 +1,38 @@
1
+/*
2
+ * dcmotor.h
3
+ *
4
+ *  Created on: 25.07.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#ifndef _SYSC_TOP_DCMOTOR_H_
9
+#define _SYSC_TOP_DCMOTOR_H_
10
+
11
+#include "BLDC.h"
12
+#include "scc/traceable.h"
13
+#include <systemc>
14
+
15
+namespace sysc {
16
+
17
+class dc_motor: public sc_core::sc_module, public scc::traceable {
18
+public:
19
+    SC_HAS_PROCESS(dc_motor);
20
+
21
+    sc_core::sc_in<double> va_i, vb_i, vc_i;
22
+    sc_core::sc_out<double> va_o, vb_o, vc_o;
23
+
24
+    dc_motor(const sc_core::sc_module_name& nm );
25
+
26
+    virtual ~dc_motor();
27
+
28
+    void trace(sc_core::sc_trace_file *trf) override;
29
+
30
+private:
31
+    void thread(void);
32
+    BLDC bldc_model;
33
+    const BLDC::State& bldc_state;
34
+};
35
+
36
+} /* namespace sysc */
37
+
38
+#endif /* RISCV_SC_INCL_SYSC_TOP_DCMOTOR_H_ */

+ 39
- 0
platform/incl/sysc/top/h_bridge.h View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * h_bridge.h
3
+ *
4
+ *  Created on: 25.07.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#ifndef RISCV_SC_INCL_SYSC_TOP_H_BRIDGE_H_
9
+#define RISCV_SC_INCL_SYSC_TOP_H_BRIDGE_H_
10
+
11
+#include "cci_configuration"
12
+#include <sysc/kernel/sc_module.h>
13
+
14
+namespace sysc {
15
+
16
+class h_bridge: public sc_core::sc_module {
17
+public:
18
+    SC_HAS_PROCESS(h_bridge);
19
+
20
+    sc_core::sc_in<sc_dt::sc_logic> ha_i, la_i;
21
+    sc_core::sc_in<sc_dt::sc_logic> hb_i, lb_i;
22
+    sc_core::sc_in<sc_dt::sc_logic> hc_i, lc_i;
23
+
24
+    sc_core::sc_out<double> va_o, vb_o, vc_o;
25
+
26
+    cci::cci_param<double> vcc;
27
+
28
+    h_bridge(const sc_core::sc_module_name& nm);
29
+
30
+    virtual ~h_bridge();
31
+private:
32
+    void ain_cb();
33
+    void bin_cb();
34
+    void cin_cb();
35
+};
36
+
37
+} /* namespace sysc */
38
+
39
+#endif /* RISCV_SC_INCL_SYSC_TOP_H_BRIDGE_H_ */

riscv.sc/incl/sysc/General/mcp3008.h → platform/incl/sysc/top/mcp3008.h View File

@@ -5,8 +5,8 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#ifndef RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_
9
-#define RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_
8
+#ifndef _SYSC_TOP_MCP3008_H_
9
+#define _SYSC_TOP_MCP3008_H_
10 10
 
11 11
 #include "scc/signal_target_mixin.h"
12 12
 #include "scc/signal_initiator_mixin.h"
@@ -44,4 +44,4 @@ private:
44 44
 
45 45
 } /* namespace sysc */
46 46
 
47
-#endif /* RISCV_SC_INCL_SYSC_GENERAL_MCP3008_H_ */
47
+#endif /* _SYSC_TOP_MCP3008_H_ */

riscv.sc/incl/sysc/General/system.h → platform/incl/sysc/top/system.h View File

@@ -8,10 +8,12 @@
8 8
 #ifndef __SYSC_GENERAL_SYSTEM_H_
9 9
 #define __SYSC_GENERAL_SYSTEM_H_
10 10
 
11
-#include "sysc/SiFive/platform.h"
12
-#include "sysc/General/terminal.h"
13
-#include "sysc/General/mcp3008.h"
14 11
 #include <systemc>
12
+#include "sysc/SiFive/hifive1.h"
13
+#include "mcp3008.h"
14
+#include "terminal.h"
15
+#include "h_bridge.h"
16
+#include "dcmotor.h"
15 17
 
16 18
 namespace sysc {
17 19
 
@@ -22,14 +24,17 @@ public:
22 24
     system(sc_core::sc_module_name nm);
23 25
     virtual ~system();
24 26
 
27
+
25 28
 private:
26 29
     sc_core::sc_vector<tlm::tlm_signal<sc_dt::sc_logic>> s_gpio;
27 30
     sc_core::sc_signal<bool> s_rst_n;
28
-    sc_core::sc_signal<double> s_vref;
31
+    sc_core::sc_signal<double> s_vref, s_va, s_vb, s_vc, s_vasens, s_vbsens, s_vcsens;
29 32
     sc_core::sc_vector<sc_core::sc_signal<double>> s_ana;
30
-    sysc::platform i_platform;
33
+    sysc::hifive1 i_platform;
31 34
     sysc::terminal i_terminal;
32 35
     sysc::mcp3008 i_adc;
36
+    sysc::h_bridge i_h_bridge;
37
+    sysc::dc_motor i_motor;
33 38
     void gen_por();
34 39
 };
35 40
 

riscv.sc/incl/sysc/General/terminal.h → platform/incl/sysc/top/terminal.h View File

@@ -5,8 +5,8 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#ifndef RISCV_SC_INCL_SYSC_GENERAL_TERMINAL_H_
9
-#define RISCV_SC_INCL_SYSC_GENERAL_TERMINAL_H_
8
+#ifndef _SYSC_TOP_TERMINAL_H_
9
+#define _SYSC_TOP_TERMINAL_H_
10 10
 
11 11
 #include "scc/signal_target_mixin.h"
12 12
 #include "scc/signal_initiator_mixin.h"
@@ -41,4 +41,4 @@ protected:
41 41
 };
42 42
 }
43 43
 
44
-#endif /* RISCV_SC_INCL_SYSC_GENERAL_TERMINAL_H_ */
44
+#endif /* _SYSC_TOP_TERMINAL_H_ */

riscv.sc/src/CMakeLists.txt → platform/src/CMakeLists.txt View File

@@ -9,7 +9,7 @@ set(APP_HEADERS )
9 9
 set(APP_SOURCES sc_main.cpp)
10 10
 
11 11
 # Define two variables in order not to repeat ourselves.
12
-set(LIBRARY_NAME risc-v.sc)
12
+set(LIBRARY_NAME platform)
13 13
 
14 14
 ## the following setting needs to be consistent with the library
15 15
 #add_definitions(-DSC_DEFAULT_WRITER_POLICY=SC_MANY_WRITERS)
@@ -24,7 +24,7 @@ set_target_properties(${LIBRARY_NAME} PROPERTIES
24 24
 )
25 25
 
26 26
 # This is a make target, so you can do a "make riscv-sc"
27
-set(APPLICATION_NAME riscv.sc)
27
+set(APPLICATION_NAME riscv.vp)
28 28
 
29 29
 include_directories(${CONAN_INCLUDE_DIRS_SEASOCKS})
30 30
 include_directories(${SystemC_INCLUDE_DIRS})
@@ -39,7 +39,8 @@ add_executable(${APPLICATION_NAME} ${APP_SOURCES})
39 39
 # Links the target exe against the libraries
40 40
 
41 41
 target_link_libraries(${APPLICATION_NAME} ${LIBRARY_NAME})
42
-target_link_libraries(${APPLICATION_NAME} risc-v)
42
+target_link_libraries(${APPLICATION_NAME} riscv.sc)
43
+target_link_libraries(${APPLICATION_NAME} riscv)
43 44
 target_link_libraries(${APPLICATION_NAME} dbt-core)
44 45
 target_link_libraries(${APPLICATION_NAME} softfloat)
45 46
 target_link_libraries(${APPLICATION_NAME} sc-components)

riscv.sc/src/sc_main.cpp → platform/src/sc_main.cpp View File

@@ -37,13 +37,13 @@
37 37
 #include <boost/program_options.hpp>
38 38
 #include <iss/log_categories.h>
39 39
 #include <sstream>
40
-#include <sysc/General/system.h>
41 40
 #include "scc/configurer.h"
42 41
 #include "scc/report.h"
43 42
 #include "scc/scv_tr_db.h"
44 43
 #include "scc/tracer.h"
45 44
 #include <cci_utils/broker.h>
46 45
 #include <iss/jit/jit_helper.h>
46
+#include "../incl/sysc/top/system.h"
47 47
 
48 48
 using namespace sysc;
49 49
 namespace po = boost::program_options;
@@ -128,7 +128,7 @@ int sc_main(int argc, char *argv[]) {
128 128
     ///////////////////////////////////////////////////////////////////////////
129 129
     // instantiate top level
130 130
     ///////////////////////////////////////////////////////////////////////////
131
-    sysc::system i_system("i_system");
131
+    auto i_system = std::make_unique<sysc::system>("i_system");
132 132
     ///////////////////////////////////////////////////////////////////////////
133 133
     // set up tracing & transaction recording
134 134
     ///////////////////////////////////////////////////////////////////////////

+ 164
- 0
platform/src/sysc/BLDC.cpp View File

@@ -0,0 +1,164 @@
1
+/*
2
+ * BLDC.cpp
3
+ *
4
+ *  Created on: 26.06.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#include "sysc/top/BLDC.h"
9
+
10
+// implementation according to Modeling of BLDC Motor with Ideal Back-EMF for Automotive Applications
11
+// Proceedings of the World Congress on Engineering 2011 Vol II WCE 2011, July 6 - 8, 2011, London, U.K.
12
+BLDC::BLDC(const Config config)
13
+: config(config)
14
+, stateVector({{0.0, 0.0, 0.0, 0.0, 0.0}})
15
+, state(stateVector)
16
+, vin({{0.0, 0.0, 0.0}})
17
+, voltages({{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0}})
18
+{
19
+    state.init();
20
+}
21
+
22
+BLDC::~BLDC() {
23
+
24
+}
25
+
26
+double BLDC::calc_bemf_factor(const State& x, double theta){
27
+    if(theta>=0 && theta < 2./3.*M_PI){
28
+        return 1;
29
+    } else if(theta>=2./3.*M_PI && theta < M_PI){
30
+        return 1-6/M_PI*(theta-2./3.*M_PI);
31
+    } else if(theta>=M_PI && theta < 5./3. * M_PI){
32
+        return -1;
33
+    } else if(theta>=5./3. * M_PI && theta < 2. * M_PI){
34
+        return -1+6/M_PI*(theta-5./3.*M_PI);
35
+    } else {
36
+        fprintf(stderr, "ERROR: angle out of bounds can not calculate bemf %f\n", theta);
37
+        throw std::runtime_error("angle out of bounds can not calculate bemf");
38
+    }
39
+}
40
+
41
+void BLDC::calc_back_emf(const State& state, double theta_e) {
42
+    double max_bemf = config.Ke * state.omega;
43
+    voltages[EA] = max_bemf*calc_bemf_factor(state, norm_angle(theta_e));
44
+    voltages[EB] = max_bemf*calc_bemf_factor(state, norm_angle(theta_e + M_PI * (2. / 3.)));
45
+    voltages[EC] = max_bemf*calc_bemf_factor(state, norm_angle(theta_e + M_PI * (4. / 3.)));
46
+}
47
+
48
+
49
+void BLDC::calc_voltages(){
50
+    const double NaN = nan("");
51
+    /* Check which phases are excited. */
52
+    bool pa = isnan(vin[0])?false:true;
53
+    bool pb = isnan(vin[1])?false:true;
54
+    bool pc = isnan(vin[2])?false:true;
55
+
56
+    if (pa && pb && pc) {
57
+        voltages[VA] = vin[0];
58
+        voltages[VB] = vin[1];
59
+        voltages[VC] = vin[2];
60
+        voltages[VCENTER] = (voltages[VA] + voltages[VB] + voltages[VC] - voltages[EA] - voltages[EB] - voltages[EC]) / 3.;
61
+    } else if (pa && pb) {
62
+        voltages[VA] = vin[0];
63
+        voltages[VB] = vin[1];
64
+        voltages[VCENTER] = (voltages[VA] + voltages[VB] - voltages[EA] - voltages[EB]) / 2.;
65
+        voltages[VC] = voltages[EC] + voltages[VCENTER];
66
+    } else if (pa && pc) {
67
+        voltages[VA] = vin[0];
68
+        voltages[VC] = vin[2];
69
+        voltages[VCENTER] = (voltages[VA] + voltages[VC] - voltages[EA] - voltages[EC]) / 2.;
70
+        voltages[VB] = voltages[EB] + voltages[VCENTER];
71
+    } else if (pb && pc) {
72
+        voltages[VB] = vin[1];
73
+        voltages[VC] = vin[2];
74
+        voltages[VCENTER] = (voltages[VB] + voltages[VC] - voltages[EB] - voltages[EC]) / 2.;
75
+        voltages[VA] = voltages[EA] + voltages[VCENTER];
76
+    } else if (pa) {
77
+        voltages[VA] = vin[0];
78
+        voltages[VCENTER] = (voltages[VA] - voltages[EA]);
79
+        voltages[VB] = voltages[EB] + voltages[VCENTER];
80
+        voltages[VC] = voltages[EC] + voltages[VCENTER];
81
+    } else if (pb) {
82
+        voltages[VB] = vin[1];
83
+        voltages[VCENTER] = (voltages[VB] - voltages[EB]);
84
+        voltages[VA] = voltages[EA] + voltages[VCENTER];
85
+        voltages[VC] = voltages[EC] + voltages[VCENTER];
86
+    } else if (pc) {
87
+        voltages[VC] = vin[0];
88
+        voltages[VCENTER] = (voltages[VC] - voltages[EC]);
89
+        voltages[VA] = voltages[EA] + voltages[VCENTER];
90
+        voltages[VB] = voltages[EB] + voltages[VCENTER];
91
+    } else {
92
+        voltages[VA] = voltages[EA];
93
+        voltages[VB] = voltages[EB];
94
+        voltages[VC] = voltages[EC];
95
+        voltages[VCENTER] = 0;
96
+    }
97
+}
98
+
99
+void BLDC::printToStream(std::ostream& os) const {
100
+    os<<state.omega<<";"<<state.theta<<";"
101
+            <<state.ia<<";"<<state.ib<<";"<<state.ic<<";"
102
+            <<voltages[VA]<<";"<<voltages[VB]<<";"<<voltages[VC]<<";"
103
+            <<voltages[EA]<<";"<<voltages[EB]<<";"<<voltages[EC]<<";"<<voltages[VCENTER]<<";"
104
+            <<vin[0]<<";"<<vin[1]<<";"<<vin[2]<<";"<<etorque;
105
+}
106
+
107
+void BLDC::rotor_dyn(const StateVector& x_, StateVector& dxdt_, const double t) {
108
+    const State x(const_cast<StateVector&>(x_));
109
+    State dxdt(dxdt_);
110
+    double theta_e = state.theta * (config.NbPoles / 2.);
111
+    /* Calculate backemf voltages. */
112
+    calc_back_emf(x, theta_e);
113
+    /* Calculate voltages. */
114
+    calc_voltages();
115
+    /* Electromagnetic torque. */
116
+//    if (x.omega == 0) {
117
+//        printf("ERROR: input state vector omega equals 0!!!\n");
118
+//        throw std::runtime_error("input state vector omega equals 0");
119
+//    }
120
+    /* electrical torque */
121
+    //etorque = ((voltages[EA] * x.ia) + (voltages[EB] * x.ib) + (voltages[EC] * x.ic)) / x.omega;
122
+    // which is equivalent to:
123
+    etorque = config.Ke*(
124
+            x.ia * (calc_bemf_factor(state, norm_angle(theta_e))) +
125
+            x.ib * (calc_bemf_factor(state, norm_angle(theta_e + M_PI * (2. / 3.)))) +
126
+            x.ic * (calc_bemf_factor(state, norm_angle(theta_e + M_PI * (4. / 3.))))
127
+            );
128
+    /* Mechanical torque. */
129
+    mtorque = ((etorque * (config.NbPoles / 2)) - (config.damping * x.omega) - torque_load);
130
+
131
+    if ((mtorque > 0) && (mtorque <= config.static_friction)) {
132
+        mtorque = 0;
133
+    } else if (mtorque > config.static_friction) {
134
+        mtorque -= config.static_friction;
135
+    } else if ((mtorque < 0) && (mtorque >= -(config.static_friction))) {
136
+        mtorque = 0;
137
+    } else if (mtorque < -(config.static_friction)) {
138
+        mtorque += config.static_friction;
139
+    }
140
+    /* Position of the rotor */
141
+    dxdt.theta = x.omega;
142
+    /* Acceleration of the rotor. (omega_dot) */
143
+    // a=M/J with M->torque, J->Inertia, a->angular acceleration
144
+    dxdt.omega = mtorque / config.inertia;
145
+    /* Calculate dot currents. */
146
+    dxdt.ia = (voltages[VA] - (config.R * x.ia) - voltages[EA] - voltages[VCENTER]) / (config.L - config.M);
147
+    dxdt.ib = (voltages[VB] - (config.R * x.ib) - voltages[EB] - voltages[VCENTER]) / (config.L - config.M);
148
+    dxdt.ic = (voltages[VC] - (config.R * x.ic) - voltages[EC] - voltages[VCENTER]) / (config.L - config.M);
149
+}
150
+
151
+void BLDC::run(double incr) {
152
+    if(dt>incr) throw std::runtime_error("incr needs to be larger than dt");
153
+    double next_time = current_time+incr;
154
+    odeint::integrate_adaptive(make_controlled( 1.0e-10 , 1.0e-6 , stepper_type() ),
155
+            [this]( const StateVector &x , StateVector &dxdt , double t ) {this->rotor_dyn(x, dxdt,t);},
156
+            stateVector, current_time, next_time, dt);
157
+    current_time=next_time;
158
+    state.theta=norm_angle(state.theta);
159
+}
160
+
161
+std::ostream& operator <<(std::ostream& os, const BLDC& bldc) {
162
+    bldc.printToStream(os);
163
+    return os;
164
+}

riscv.sc/src/sysc/aon.cpp → platform/src/sysc/aon.cpp View File


riscv.sc/src/sysc/clint.cpp → platform/src/sysc/clint.cpp View File


+ 69
- 0
platform/src/sysc/dcmotor.cpp View File

@@ -0,0 +1,69 @@
1
+/*
2
+ * dcmotor.cpp
3
+ *
4
+ *  Created on: 25.07.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#include "sysc/top/dcmotor.h"
9
+#include "scc/utilities.h"
10
+#include <future>
11
+
12
+namespace sysc {
13
+
14
+using namespace sc_core;
15
+
16
+auto get_config = []() -> BLDC::Config {
17
+    BLDC::Config config{};
18
+    config.Ke=1./4000. ,//0.01; // V/rad/s, = 1/Kv
19
+    config.R=0.5; // Ohm
20
+    config.inertia = 0.0005;
21
+    config.NbPoles = 2;
22
+    config.damping = 0.00001;
23
+    return config;
24
+};
25
+
26
+dc_motor::dc_motor(const sc_module_name& nm )
27
+: sc_module(nm)
28
+, bldc_model(get_config())
29
+, bldc_state(bldc_model.getState())
30
+{
31
+    bldc_model.setLoad(0.0001);
32
+    SC_THREAD(thread);
33
+}
34
+
35
+dc_motor::~dc_motor() {
36
+}
37
+
38
+void dc_motor::trace(sc_trace_file* trf) {
39
+    auto ia=bldc_state.ia;       TRACE_VAR(trf, ia);
40
+    auto ib=bldc_state.ib;       TRACE_VAR(trf, ib);
41
+    auto ic=bldc_state.ic;       TRACE_VAR(trf, ic);
42
+    auto theta=bldc_state.theta; TRACE_VAR(trf, theta);
43
+    auto omega=bldc_state.omega; TRACE_VAR(trf, omega);
44
+}
45
+
46
+void dc_motor::thread(void) {
47
+    wait(SC_ZERO_TIME);
48
+    std::array<double, 3> vin{0., 0., 0.};
49
+    const sc_time step(1, SC_US);
50
+    auto eval_model = [this](std::array<double, 3> vin, const sc_time step)->std::tuple<double, double, double> {
51
+        bldc_model.set_input(vin);
52
+        bldc_model.run(step.to_seconds());
53
+        return bldc_model.get_voltages();
54
+    };
55
+    while(true){
56
+        vin[0]=va_i.read();
57
+        vin[1]=vb_i.read();
58
+        vin[2]=vc_i.read();
59
+//        auto sim_res=std::async(std::launch::async, eval_model, vin, step);
60
+        wait(step);
61
+//        auto vout=sim_res.get();
62
+        auto vout = eval_model(vin, step);
63
+        va_o=std::get<0>(vout);
64
+        vb_o=std::get<1>(vout);
65
+        vc_o=std::get<2>(vout);
66
+    }
67
+}
68
+
69
+} /* namespace sysc */

riscv.sc/src/sysc/gpio.cpp → platform/src/sysc/gpio.cpp View File


+ 47
- 0
platform/src/sysc/h_bridge.cpp View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * h_bridge.cpp
3
+ *
4
+ *  Created on: 25.07.2018
5
+ *      Author: eyck
6
+ */
7
+
8
+#include "sysc/top/h_bridge.h"
9
+#include "scc/utilities.h"
10
+
11
+namespace sysc {
12
+using namespace sc_core;
13
+
14
+h_bridge::h_bridge(const sc_module_name& nm)
15
+:sc_module(nm)
16
+, NAMED(ha_i)
17
+, NAMED(la_i)
18
+, NAMED(hb_i)
19
+, NAMED(lb_i)
20
+, NAMED(hc_i)
21
+, NAMED(lc_i)
22
+, NAMED(va_o)
23
+, NAMED(vb_o)
24
+, NAMED(vc_o)
25
+, NAMED(vcc, 48.0)
26
+{
27
+    SC_METHOD(ain_cb);
28
+    sensitive<<ha_i<<la_i;
29
+    SC_METHOD(bin_cb);
30
+    sensitive<<hb_i<<lb_i;
31
+    SC_METHOD(cin_cb);
32
+    sensitive<<hc_i<<lc_i;
33
+}
34
+
35
+h_bridge::~h_bridge() {
36
+}
37
+
38
+void h_bridge::ain_cb() {
39
+}
40
+
41
+void h_bridge::bin_cb() {
42
+}
43
+
44
+void h_bridge::cin_cb() {
45
+}
46
+
47
+} /* namespace sysc */

riscv.sc/src/sysc/platform.cpp → platform/src/sysc/hifive1.cpp View File

@@ -34,11 +34,11 @@
34 34
 //
35 35
 ////////////////////////////////////////////////////////////////////////////////
36 36
 
37
-#include <sysc/SiFive/platform.h>
37
+#include "sysc/SiFive/hifive1.h"
38 38
 
39 39
 namespace sysc {
40 40
 
41
-platform::platform(sc_core::sc_module_name nm)
41
+hifive1::hifive1(sc_core::sc_module_name nm)
42 42
 : sc_core::sc_module(nm)
43 43
 , NAMED(pins_o, 32)
44 44
 , NAMED(pins_i, 32)

riscv.sc/src/sysc/mcp3008.cpp → platform/src/sysc/mcp3008.cpp View File

@@ -5,7 +5,8 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#include "sysc/General/mcp3008.h"
8
+#include "sysc/top/mcp3008.h"
9
+
9 10
 #include <scc/report.h>
10 11
 #include <util/ities.h>
11 12
 

riscv.sc/src/sysc/plic.cpp → platform/src/sysc/plic.cpp View File


riscv.sc/src/sysc/prci.cpp → platform/src/sysc/prci.cpp View File


riscv.sc/src/sysc/sc_comm_singleton.cpp → platform/src/sysc/sc_comm_singleton.cpp View File


riscv.sc/src/sysc/spi.cpp → platform/src/sysc/spi.cpp View File


riscv.sc/src/sysc/system.cpp → platform/src/sysc/system.cpp View File

@@ -5,7 +5,7 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#include "sysc/General/system.h"
8
+#include "sysc/top/system.h"
9 9
 
10 10
 using namespace sysc;
11 11
 
@@ -14,10 +14,15 @@ system::system(sc_core::sc_module_name nm)
14 14
 , NAMED(s_gpio, 32)
15 15
 , NAMED(s_rst_n)
16 16
 , NAMED(s_vref)
17
-, NAMED(s_ana, 8)
17
+, NAMED(s_va)
18
+, NAMED(s_vb)
19
+, NAMED(s_vc)
20
+, NAMED(s_ana, 5)
18 21
 , NAMED(i_platform)
19 22
 , NAMED(i_terminal)
20 23
 , NAMED(i_adc)
24
+, NAMED(i_h_bridge)
25
+, NAMED(i_motor)
21 26
 {
22 27
     // connect platform
23 28
     i_platform.erst_n(s_rst_n);
@@ -36,8 +41,32 @@ system::system(sc_core::sc_module_name nm)
36 41
     i_adc.miso_o(s_gpio[4].in);
37 42
     s_gpio[5].out(i_adc.sck_i);
38 43
     // adc analog inputs
39
-    i_adc.ch_i(s_ana);
40 44
     i_adc.vref_i(s_vref);
45
+    i_adc.ch_i[0](s_vasens);
46
+    i_adc.ch_i[1](s_vbsens);
47
+    i_adc.ch_i[2](s_vcsens);
48
+    i_adc.ch_i[3](s_ana[0]);
49
+    i_adc.ch_i[4](s_ana[1]);
50
+    i_adc.ch_i[5](s_ana[2]);
51
+    i_adc.ch_i[6](s_ana[3]);
52
+    i_adc.ch_i[7](s_ana[4]);
53
+
54
+    i_h_bridge.ha_i(s_gpio[0]);
55
+    i_h_bridge.la_i(s_gpio[1]);
56
+    i_h_bridge.hb_i(s_gpio[10]);
57
+    i_h_bridge.lb_i(s_gpio[11]);
58
+    i_h_bridge.hc_i(s_gpio[19]);
59
+    i_h_bridge.lc_i(s_gpio[20]);
60
+    i_h_bridge.va_o(s_va);
61
+    i_h_bridge.vb_o(s_vb);
62
+    i_h_bridge.vc_o(s_vc);
63
+
64
+    i_motor.va_i(s_va);
65
+    i_motor.vb_i(s_vb);
66
+    i_motor.vc_i(s_vc);
67
+    i_motor.va_o(s_vasens);
68
+    i_motor.vb_o(s_vbsens);
69
+    i_motor.vc_o(s_vcsens);
41 70
 
42 71
     SC_THREAD(gen_por);
43 72
 }

riscv.sc/src/sysc/terminal.cpp → platform/src/sysc/terminal.cpp View File

@@ -5,7 +5,8 @@
5 5
  *      Author: eyck
6 6
  */
7 7
 
8
-#include "sysc/General/terminal.h"
8
+#include "sysc/top/terminal.h"
9
+
9 10
 #include "sysc/sc_comm_singleton.h"
10 11
 #include "sysc/tlm_extensions.h"
11 12
 #include "scc/report.h"

riscv.sc/src/sysc/uart.cpp → platform/src/sysc/uart.cpp View File


+ 20
- 1
riscv.sc/CMakeLists.txt View File

@@ -86,7 +86,26 @@ set(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
86 86
 set(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
87 87
 set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
88 88
 
89
-add_subdirectory(src)
89
+# library files
90
+FILE(GLOB RiscVSCHeaders *.h */*.h)
91
+
92
+set(LIB_HEADERS ${RiscVSCHeaders} )
93
+set(LIB_SOURCES src/core_complex.cpp )
94
+
95
+# Define two variables in order not to repeat ourselves.
96
+set(LIBRARY_NAME riscv.sc)
97
+
98
+## the following setting needs to be consistent with the library
99
+#add_definitions(-DSC_DEFAULT_WRITER_POLICY=SC_MANY_WRITERS)
100
+
101
+# Define the library
102
+add_library(${LIBRARY_NAME} ${LIB_SOURCES})
103
+
104
+set_target_properties(${LIBRARY_NAME} PROPERTIES
105
+  VERSION ${VERSION}  # ${VERSION} was defined in the main CMakeLists.
106
+  FRAMEWORK FALSE
107
+  PUBLIC_HEADER "${LIB_HEADERS}" # specify the public headers
108
+)
90 109
 
91 110
 #
92 111
 # SYSTEM PACKAGING (RPM, TGZ, ...)

riscv.sc/incl/sysc/SiFive/core_complex.h → riscv.sc/incl/sysc/core_complex.h View File


riscv.sc/src/sysc/core_complex.cpp → riscv.sc/src/core_complex.cpp View File

@@ -43,7 +43,7 @@
43 43
 #include "iss/debugger/gdb_session.h"
44 44
 #include "iss/debugger/target_adapter_if.h"
45 45
 #include "iss/debugger/encoderdecoder.h"
46
-#include "sysc/SiFive/core_complex.h"
46
+#include "sysc/core_complex.h"
47 47
 
48 48
 #ifdef WITH_SCV
49 49
 #include <scv.h>

+ 2
- 2
riscv/src/CMakeLists.txt View File

@@ -15,7 +15,7 @@ set(APP_HEADERS )
15 15
 set(APP_SOURCES main.cpp)
16 16
 
17 17
 # Define two variables in order not to repeat ourselves.
18
-set(LIBRARY_NAME risc-v)
18
+set(LIBRARY_NAME riscv)
19 19
 
20 20
 # Define the library
21 21
 #add_library(${LIBRARY_NAME} SHARED ${LIB_SOURCES})
@@ -28,7 +28,7 @@ set_target_properties(${LIBRARY_NAME} PROPERTIES
28 28
 )
29 29
 
30 30
 # This is a make target, so you can do a "make riscv-sc"
31
-set(APPLICATION_NAME riscv)
31
+set(APPLICATION_NAME riscv-sim)
32 32
 
33 33
 add_executable(${APPLICATION_NAME} ${APP_SOURCES})
34 34
 

+ 1
- 1
sc-components

@@ -1 +1 @@
1
-Subproject commit 57853f5df2ee573c35ef598a8a259696ae6059c0
1
+Subproject commit 0e5cf3fb3ac199a47f073f2bcee0abd4b3951896