Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions examples/helloworld/hello_world_baseline.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
%time core_I mic_click_I battery
0 0 0 0
0.001 0.303145522846001 0 1
0.002 0.286435285423908 0 1
0.003 0.297515845044595 0 1
0.004 0.580799497617467 0 0.99999999943567
15,416 changes: 15,416 additions & 0 deletions examples/periodic_sensors/periodic_sensor_baseline.log

Large diffs are not rendered by default.

20,767 changes: 20,767 additions & 0 deletions examples/read_sensor/read_sensor_baseline.log

Large diffs are not rendered by default.

Large diffs are not rendered by default.

125 changes: 125 additions & 0 deletions examples/read_write_sensor/read_write_sensor_baseline.log
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
%time core_I mic_click_I battery
0 0 0 0
0.001 0.303958823212679 0 1
0.002 0.287804420486948 0 1
0.003 0.293887482707194 0.16 1
0.004 0.243444444444444 0.16 0.999999999434157
0.005 0.243444444444444 0.16 0.999999997848082
0.006 0.243444444444444 0.16 0.999999995796142
0.007 0.243444444444444 0.16 0.999999993828106
0.008 0.243444444444444 0.16 0.999999991955444
0.009 0.243444444444444 0.16 0.999999990082775
0.01 0.243444444444444 0.16 0.999999988210105
0.011 0.243444444444444 0.16 0.999999986337436
0.012 0.243444444444444 0.16 0.999999984464767
0.013 0.243444444444444 0.16 0.999999982592097
0.014 0.243444444444444 0.16 0.999999980719428
0.015 0.243444444444444 0.16 0.999999978846759
0.016 0.243444444444444 0.16 0.999999976974089
0.017 0.243444444444444 0.16 0.99999997510142
0.018 0.243444444444444 0.16 0.999999973228751
0.019 0.243444444444444 0.16 0.999999971356081
0.02 0.243444444444444 0.16 0.999999969483412
0.021 0.243444444444444 0.16 0.999999967610743
0.022 0.243444444444444 0.16 0.999999965738073
0.023 0.243444444444444 0.16 0.999999963865404
0.024 0.243444444444444 0.16 0.999999961992735
0.025 0.243444444444444 0.16 0.999999960120065
0.026 0.243444444444444 0.16 0.999999958247396
0.027 0.243444444444444 0.16 0.999999956374726
0.028 0.243444444444444 0.16 0.999999954502057
0.029 0.243444444444444 0.16 0.999999952629388
0.03 0.243444444444444 0.16 0.999999950756718
0.031 0.243444444444444 0.16 0.999999948884049
0.032 0.243444444444444 0.16 0.99999994701138
0.033 0.243444444444444 0.12 0.99999994513871
0.034 0.243444444444444 0.12 0.999999943266041
0.035 0.243444444444444 0.12 0.999999941514784
0.036 0.243444444444444 0.12 0.999999939884933
0.037 0.243444444444444 0.12 0.999999938255073
0.038 0.243444444444444 0.12 0.999999936625214
0.039 0.243444444444444 0.12 0.999999934995354
0.04 0.243444444444444 0.12 0.999999933365495
0.041 0.243444444444444 0.12 0.999999931735636
0.042 0.243444444444444 0.12 0.999999930105776
0.043 0.243444444444444 0.12 0.999999928475917
0.044 0.243444444444444 0.12 0.999999926846057
0.045 0.243444444444444 0.12 0.999999925216198
0.046 0.243444444444444 0.12 0.999999923586338
0.047 0.243444444444444 0.12 0.999999921956479
0.048 0.243444444444444 0.12 0.999999920326619
0.049 0.243444444444444 0.12 0.99999991869676
0.05 0.243444444444444 0.12 0.9999999170669
0.051 0.243444444444444 0.12 0.999999915437041
0.052 0.243444444444444 0.12 0.999999913807181
0.053 0.243444444444444 0.12 0.999999912177322
0.054 0.243444444444444 0.12 0.999999910547462
0.055 0.243444444444444 0.12 0.999999908917603
0.056 0.243444444444444 0.12 0.999999907287743
0.057 0.243444444444444 0.12 0.999999905657884
0.058 0.243444444444444 0.12 0.999999904028025
0.059 0.243444444444444 0.12 0.999999902398165
0.06 0.243444444444444 0.12 0.999999900768306
0.061 0.243444444444444 0.12 0.999999899138446
0.062 0.243444444444444 0.12 0.999999897508587
0.063 0.289890338635395 0.16 0.999999895878727
0.064 0.243444444444444 0.16 0.999999894248868
0.065 0.243444444444444 0.16 0.999999892497594
0.066 0.243444444444444 0.16 0.999999890537101
0.067 0.243444444444444 0.16 0.999999888576623
0.068 0.243444444444444 0.16 0.999999886703961
0.069 0.243444444444444 0.16 0.999999884831292
0.07 0.243444444444444 0.16 0.999999882958622
0.071 0.243444444444444 0.16 0.999999881085953
0.072 0.243444444444444 0.16 0.999999879213284
0.073 0.243444444444444 0.16 0.999999877340615
0.074 0.243444444444444 0.16 0.999999875467945
0.075 0.243444444444444 0.16 0.999999873595276
0.076 0.243444444444444 0.16 0.999999871722607
0.077 0.243444444444444 0.16 0.999999869849938
0.078 0.243444444444444 0.16 0.999999867977268
0.079 0.243444444444444 0.16 0.999999866104599
0.08 0.243444444444444 0.16 0.99999986423193
0.081 0.243444444444444 0.16 0.999999862359261
0.082 0.243444444444444 0.16 0.999999860486591
0.083 0.243444444444444 0.16 0.999999858613922
0.084 0.243444444444444 0.16 0.999999856741253
0.085 0.243444444444444 0.16 0.999999854868584
0.086 0.243444444444444 0.16 0.999999852995914
0.087 0.243444444444444 0.16 0.999999851123245
0.088 0.243444444444444 0.16 0.999999849250576
0.089 0.243444444444444 0.16 0.999999847377907
0.09 0.243444444444444 0.16 0.999999845505237
0.091 0.243444444444444 0.16 0.999999843632568
0.092 0.243444444444444 0.16 0.999999841759899
0.093 0.243444444444444 0.12 0.99999983988723
0.094 0.243444444444444 0.12 0.99999983801456
0.095 0.243444444444444 0.12 0.999999836263304
0.096 0.243444444444444 0.12 0.999999834633452
0.097 0.243444444444444 0.12 0.999999833003593
0.098 0.243444444444444 0.12 0.999999831373734
0.099 0.243444444444444 0.12 0.999999829743874
0.1 0.243444444444444 0.12 0.999999828114015
0.101 0.243444444444444 0.12 0.999999826484156
0.102 0.243444444444444 0.12 0.999999824854296
0.103 0.243444444444444 0.12 0.999999823224437
0.104 0.243444444444444 0.12 0.999999821594578
0.105 0.243444444444444 0.12 0.999999819964718
0.106 0.243444444444444 0.12 0.999999818334859
0.107 0.243444444444444 0.12 0.999999816704999
0.108 0.243444444444444 0.12 0.99999981507514
0.109 0.243444444444444 0.12 0.999999813445281
0.11 0.243444444444444 0.12 0.999999811815421
0.111 0.243444444444444 0.12 0.999999810185562
0.112 0.243444444444444 0.12 0.999999808555703
0.113 0.243444444444444 0.12 0.999999806925843
0.114 0.243444444444444 0.12 0.999999805295984
0.115 0.243444444444444 0.12 0.999999803666125
0.116 0.243444444444444 0.12 0.999999802036265
0.117 0.243444444444444 0.12 0.999999800406406
0.118 0.243444444444444 0.12 0.999999798776547
0.119 0.243444444444444 0.12 0.999999797146687
0.12 0.243444444444444 0.12 0.999999795516828
0.121 0.243444444444444 0.12 0.999999793886968
0.122 0.243444444444444 0.12 0.999999792257109
0.123 0.290260115437856 0.0019999999999999 0.99999979062725
114 changes: 114 additions & 0 deletions messy/codegen/codegen_diagram.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
from mako.template import Template
from mako import exceptions
import argparse
from pathlib import Path
import json
from typing import List


class Template_generator:
def __init__(self, template_file, out_file, data_to_template) -> None:
self.template_file = str(template_file)
self.out_file = str(out_file)
self.data_to_template = data_to_template


def generate_at_from_with(template_generators: List[Template_generator]):
"""
Generate code from templates

Parameters
----------
template_generators : List[Template_generator]
List of Template_generator

Returns
-------
None
"""
for template_gen in template_generators:
print(f"Generating {template_gen.out_file}")
template_file = Template(filename=template_gen.template_file)
code = ""
error_codegen = False
try:
code = template_file.render(**template_gen.data_to_template)
except:
code = exceptions.html_error_template().render()
error_codegen = True
with open(
template_gen.out_file + (".html" if error_codegen else ""),
"wb" if error_codegen else "w",
) as f:
f.write(code)
if error_codegen:
print("ERROR WHILE GENERATING CODE!")
break

def main(input_file, template_dir, output_dir):
"""
Main function for code generation.

This function reads the input settings from a JSON file, prepares the necessary
directories, and generates SystemC/SystemC-AMS code based on the provided templates.
It handles the configuration of core, sensors, and harvesters, including tracing
and power conversion settings.

Parameters
----------
input_file : Path
Path to JSON input simulation settings.
template_dir : Path
Path to templates directory.
output_dir : Path
Path where code will be generated.
"""

# Load input settings file
with open(input_file, "r") as f:
settings = json.load(f)

base_plot_dir = output_dir / "matlab"
base_plot_dir.mkdir(parents=True, exist_ok=True)
template_generators = []

# Use default sensor templates
template_generators.append(
Template_generator(
template_dir / "plotter" / "messy_diagram.m",
base_plot_dir / "messy_diagram.m"
)
)

if __name__ == "__main__":
# Create an argument parser with a description
parser = argparse.ArgumentParser(description="Generate src code")

# Add an argument for the input file path
parser.add_argument(
"-f",
"--input-file",
type=str,
metavar="PATH",
help="Path to JSON input simulation settings",
)

# Add an argument for the template directory path
parser.add_argument(
"-t",
"--template-dir",
type=str,
metavar="PATH",
default="./codegen/templates",
help="Path to templates directory",
)

# Add an argument for the output directory path
parser.add_argument(
"-o",
"--output-dir",
type=str,
metavar="PATH",
default=".",
help="Path where code will be generated",
)
29 changes: 11 additions & 18 deletions messy/codegen/templates/include/core.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,20 @@
class Core : public sc_module {
public:
// Input Ports
sc_core::sc_in<bool> request_go; /**< Flag indicating if the request can proceed */
sc_core::sc_in<uint8_t *> request_value; /**< Value of the request */
sc_core::sc_in<int> idx_sensor; /**< Index of the sensor */
sc_core::sc_in<bool> i_done_functional_bus; /**< Flag indicating if the request can proceed */
sc_core::sc_in<uint8_t *> i_data_ptr; /**< Value of the request */
sc_core::sc_in<int> i_idx_sensor; /**< Index of the sensor */

// Output Ports
sc_core::sc_out<unsigned int> request_address; /**< Address of the request */
sc_core::sc_out<uint8_t *> request_data; /**< Data of the request */
sc_core::sc_out<unsigned int> request_size; /**< Size of the request */
sc_core::sc_out<bool> functional_bus_flag; /**< Flag for the functional bus */
sc_core::sc_out<bool> request_ready; /**< Flag indicating if the request is ready */
sc_core::sc_out<unsigned int> o_address; /**< Address of the request */
sc_core::sc_out<uint8_t *> o_data_ptr; /**< Data of the request */
sc_core::sc_out<unsigned int> o_size; /**< Size of the request */
sc_core::sc_out<bool> o_is_read; /**< Flag for the functional bus */
sc_core::sc_out<bool> o_activate_functional_bus; /**< Flag indicating if the request is ready */


// Power Port
sc_core::sc_out<double> power_signal; /**< Power signal output */
sc_core::sc_out<double> o_power_state; /**< Power signal output */

// Variables
int simulation_iters = 0; /**< Number of simulation iterations. It gets incremented every time the continue_messy method is executed */
Expand Down Expand Up @@ -151,17 +151,10 @@ class Core : public sc_module {
*
* Initializes the input and output ports with their respective names.
*/
SC_CTOR(Core) : request_address("Address_From_Core_to_Func_Bus"),
request_data("Data_From_Core_to_Func_Bus"),
functional_bus_flag("Flag_From_Core_to_Func_Bus"),
request_ready("Master_Ready_to_Func_Bus"),
request_go("Master_GO_to_Func_Bus"),
request_value("Data_form_Bus_to_Master"),
power_signal("Func_to_Power_signal"),
idx_sensor("selected_sensor_of_request") {
SC_CTOR(Core) {
iss_adapter = (${adapter_class}*) new ${adapter_class}();
SC_THREAD(run);
sensitive << request_go;
sensitive << i_done_functional_bus;
}

~Core() {
Expand Down
12 changes: 4 additions & 8 deletions messy/codegen/templates/include/core_power.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,18 @@ SCA_TDF_MODULE(Core_power)
{
Core* core; /**< Pointer to the Core functional module. */
//Data from Functional Instance
sca_tdf::sc_in <double> func_signal; /**< Input port for receiving functional signals from the Core. */
sca_tdf::sc_in <double> i_power_state; /**< Input port for receiving functional signals from the Core. */
//Data to Power Bus
sca_tdf::sca_out <double> voltage_state; /**< Output port for sending the voltage state to the Power Bus. */
sca_tdf::sca_out <double> current_state; /**< Output port for sending the current state to the Power Bus. */
sca_tdf::sca_out <double> o_voltage_a; /**< Output port for sending the voltage state to the Power Bus. */
sca_tdf::sca_out <double> o_current_a; /**< Output port for sending the current state to the Power Bus. */
//sca_tdf::sca_out <int> power_to_therm;

/**
* @brief Constructor for the Core_power module.
*
* Initializes the input and output signal names for tracing and connecting to other modules.
*/
SCA_CTOR(Core_power):
func_signal("State_of_Power_From_Functional"),
voltage_state("Voltage_trace_to_Power_Bus"),
current_state("Current_trace_to_Power_Bus")
{}
SCA_CTOR(Core_power) {}

/**
* @brief Sets the attributes of the Core_power module.
Expand Down
Loading