Skip to content

Commit fe95f81

Browse files
Merge pull request #32 from ErickOF/jvillalobos/Sobel_Virtual_Prototype
Adding virtual prototype with all the TLM models
2 parents 0bbd49b + 9e5b1f7 commit fe95f81

File tree

181 files changed

+67351
-130
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

181 files changed

+67351
-130
lines changed

.gitignore

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,4 +233,16 @@ tools/datagen/src/imgs/*_sobel_*
233233
*.vcd
234234
test
235235
*.zst
236-
.vscode
236+
.vscode
237+
*.hex
238+
*.bin
239+
modules/VirtualPrototype/sw/dump
240+
modules/VirtualPrototype/sw/sw
241+
modules/VirtualPrototype/FreeRTOS/dump
242+
modules/VirtualPrototype/FreeRTOS/freertos
243+
modules/VirtualPrototype/Log.txt
244+
modules/VirtualPrototype/log.txt
245+
VirtualPrototype/Log.txt
246+
VirtualPrototype/log.txt
247+
VirtualPrototype/sw/dump
248+
VirtualPrototype/sw/log.txt

VirtualPrototype/Dockerfile

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
FROM ubuntu:bionic
2+
LABEL maintainer="Màrius Montón"
3+
ENV SYSTEMC_VERSION 2.3.3
4+
5+
RUN apt-get update -q && apt-get install -qy gcc-riscv64-linux-gnu
6+
7+
RUN apt-get update -q && apt-get install -qy --no-install-recommends \
8+
build-essential curl \
9+
cmake \
10+
git \
11+
openssh-client \
12+
wget \
13+
g++-8 \
14+
xterm \
15+
&& apt-get clean \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
RUN mkdir -p /usr/src/systemc \
19+
&& wget --no-check-certificate https://accellera.org/images/downloads/standards/systemc/systemc-$SYSTEMC_VERSION.tar.gz \
20+
&& tar fzxC systemc-$SYSTEMC_VERSION.tar.gz /usr/src/systemc \
21+
&& cd /usr/src/systemc/systemc-$SYSTEMC_VERSION \
22+
&& mkdir objs \
23+
&& cd objs \
24+
&& export CXX=g++-8 \
25+
&& mkdir -p /usr/local/systemc-$SYSTEMC_VERSION \
26+
&& ../configure --prefix=/usr/local/systemc-$SYSTEMC_VERSION CXXFLAGS="-DSC_CPLUSPLUS=201103L"\
27+
&& make \
28+
&& make install \
29+
&& cd / \
30+
&& rm -rf /usr/src/systemc
31+
32+
ENV CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/systemc-$SYSTEMC_VERSION/include
33+
ENV LIBRARY_PATH=$LIBRARY_PATH:/usr/local/systemc-$SYSTEMC_VERSION/lib-linux64
34+
ENV LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/systemc-$SYSTEMC_VERSION/lib-linux64
35+
ENV SYSTEMC=/usr/local/systemc-$SYSTEMC_VERSION
36+
37+
RUN mkdir -p /root/.ssh
38+
RUN ssh-keyscan github.com > /root/.ssh/known_hosts
39+
40+
41+
42+
RUN rm -fr /usr/src/riscv64 \
43+
&& mkdir -p /usr/src/riscv64 \
44+
&& cd /usr/src/riscv64 \
45+
&& git config --global http.sslVerify false \
46+
&& git clone https://github.com/mariusmm/RISC-V-TLM.git \
47+
&& cd RISC-V-TLM \
48+
&& mkdir obj \
49+
&& make
50+
51+
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
#include "FreeRTOS.h"
2+
#include "task.h"
3+
#include "queue.h"
4+
#include "timers.h"
5+
6+
#include <stdio.h>
7+
#include <string.h>
8+
9+
//Testbench Defines
10+
#define IMAG_ROWS 452
11+
#define IMAG_COLS 640
12+
#define RBG_CHANNELS_NUM 3
13+
#define GRAY_CHANNELS_NUM 1
14+
15+
//Testbench Includes
16+
#include "../inc/address_map.hpp"
17+
#include "../inc/common_func.hpp"
18+
// #include "tb_aux_functions.c"
19+
// #include "img_unification.c"
20+
//#include "img_filtering.cpp"
21+
22+
#define TRACE (*(unsigned char *)0x40000000)
23+
24+
extern void register_timer_isr();
25+
26+
QueueHandle_t my_queue = NULL;
27+
28+
static void task_1(void *pParameter) {
29+
30+
int data = 5;
31+
printf("Task 1 starts\n");
32+
33+
while(1) {
34+
printf("T1: Tick %ld\n", xTaskGetTickCount() );
35+
xQueueSend(my_queue, &data, portMAX_DELAY);
36+
vTaskDelay(100 / portTICK_PERIOD_MS);
37+
}
38+
}
39+
40+
static void task_2(void *pParameter) {
41+
42+
int data = 7;
43+
44+
printf("Task 2 starts\n");
45+
46+
while(1) {
47+
printf("T2: Tick %ld\n", xTaskGetTickCount() );
48+
xQueueSend(my_queue, &data, portMAX_DELAY);
49+
vTaskDelay(500 / portTICK_PERIOD_MS);
50+
}
51+
}
52+
53+
static void task_3(void *pParameter) {
54+
int data;
55+
56+
printf("Task 3 starts\n");
57+
58+
while(1) {
59+
xQueueReceive(my_queue, &data, portMAX_DELAY);
60+
printf("T3: Tick %ld. Recv: %ld\n", xTaskGetTickCount(), data);
61+
//vTaskDelay(1000 / portTICK_PERIOD_MS);
62+
}
63+
64+
}
65+
66+
static void testbench(void *pParameter) {
67+
68+
//Set the pointers to memory, where images are stored
69+
unsigned char *img_x = (unsigned char*) IMG_INPUT_ADDRESS_LO;
70+
unsigned char *img_y = (unsigned char*) IMG_INPUT_ADDRESS_LO + IMAG_ROWS*IMAG_COLS;
71+
unsigned char *img_result = (unsigned char*) IMG_OUTPUT_ADDRESS_LO;
72+
73+
printf("Starting Testbench\n");
74+
75+
printf("Starting IMG Filtering Step: \n");
76+
filter_img(img_x, img_result, IMAG_ROWS, IMAG_COLS);
77+
printf("Done IMG Filtering Step: \n");
78+
79+
// printf("Starting IMG Unification Step: \n");
80+
// unificate_img(img_x, img_y, img_result, IMAG_ROWS*IMAG_COLS, GRAY_CHANNELS_NUM);
81+
// printf("Done IMG Unification Step: \n");
82+
83+
printf("Testbench Done\n");
84+
}
85+
86+
int main( void )
87+
{
88+
BaseType_t xReturned;
89+
printf("Starting FreeRTOS test\n");
90+
91+
/* Create tasks */
92+
xReturned = xTaskCreate(testbench, "test_unificate", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
93+
94+
printf("Returned: %0d\n", xReturned);
95+
/* Start the kernel. From here on, only tasks and interrupts will run. */
96+
vTaskStartScheduler();
97+
98+
/* Exit FreeRTOS */
99+
return 0;
100+
}
101+
102+
void vApplicationMallocFailedHook( void )
103+
{
104+
/* vApplicationMallocFailedHook() will only be called if
105+
configUSE_MALLOC_FAILED_HOOK is set to 1 in FreeRTOSConfig.h. It is a hook
106+
function that will get called if a call to pvPortMalloc() fails.
107+
pvPortMalloc() is called internally by the kernel whenever a task, queue,
108+
timer or semaphore is created. It is also called by various parts of the
109+
demo application. If heap_1.c or heap_2.c are used, then the size of the
110+
heap available to pvPortMalloc() is defined by configTOTAL_HEAP_SIZE in
111+
FreeRTOSConfig.h, and the xPortGetFreeHeapSize() API function can be used
112+
to query the size of free heap space that remains (although it does not
113+
provide information on how the remaining heap might be fragmented). */
114+
taskDISABLE_INTERRUPTS();
115+
116+
TRACE='M';
117+
for( ;; );
118+
}
119+
/*-----------------------------------------------------------*/
120+
121+
void vApplicationIdleHook( void )
122+
{
123+
/* vApplicationIdleHook() will only be called if configUSE_IDLE_HOOK is set
124+
to 1 in FreeRTOSConfig.h. It will be called on each iteration of the idle
125+
task. It is essential that code added to this hook function never attempts
126+
to block in any way (for example, call xQueueReceive() with a block time
127+
specified, or call vTaskDelay()). If the application makes use of the
128+
vTaskDelete() API function (as this demo application does) then it is also
129+
important that vApplicationIdleHook() is permitted to return to its calling
130+
function, because it is the responsibility of the idle task to clean up
131+
memory allocated by the kernel to any task that has since been deleted. */
132+
}
133+
/*-----------------------------------------------------------*/
134+
135+
void vApplicationStackOverflowHook( TaskHandle_t pxTask, char *pcTaskName )
136+
{
137+
( void ) pcTaskName;
138+
( void ) pxTask;
139+
140+
/* Run time stack overflow checking is performed if
141+
configCHECK_FOR_STACK_OVERFLOW is defined to 1 or 2. This hook
142+
function is called if a stack overflow is detected. */
143+
taskDISABLE_INTERRUPTS();
144+
TRACE = 'S';
145+
for( ;; );
146+
}
147+
/*-----------------------------------------------------------*/
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
#ifndef IMG_FILTERING_CPP
2+
#define IMG_FILTERING_CPP
3+
4+
#include <string.h>
5+
#include <stdlib.h>
6+
#include "../inc/address_map.hpp"
7+
#include "../inc/common_func.hpp"
8+
9+
#define IPS_FILTER_KERNEL_SIZE 9
10+
11+
12+
void filter_img (unsigned char* input_img, unsigned char* output_img, int img_width, int img_height)
13+
{
14+
unsigned char* filter_kernel_ptr = (unsigned char*) IMG_FILTER_KERNEL_ADDRESS_LO;
15+
unsigned char* filter_output_ptr = (unsigned char*) IMG_FILTER_OUTPUT_ADDRESS_LO;
16+
unsigned char* local_window_ptr = malloc(IPS_FILTER_KERNEL_SIZE*sizeof(char));
17+
unsigned char* read_ptr;
18+
unsigned char data_returned;
19+
20+
int local_count = 0;
21+
int current_number_of_pixels = 0;
22+
int next_target_of_completion = 10;
23+
int local_group_count = 0;
24+
int total_number_of_pixels = img_width*img_height;
25+
unsigned char* local_results;
26+
27+
for (int i = 0; i < img_width; i++)
28+
{
29+
local_group_count = 0;
30+
for (int j = 0; j < img_height; j++)
31+
{
32+
extract_window(i, j, input_img, local_window_ptr, img_width, img_height);
33+
memcpy(filter_kernel_ptr, local_window_ptr, IPS_FILTER_KERNEL_SIZE*sizeof(char)); //Write to filter kernel
34+
memcpy(read_ptr, filter_output_ptr, sizeof(char)); //Read filter output
35+
data_returned = *read_ptr;
36+
37+
if (local_count == 0)
38+
{
39+
local_results = malloc(8);
40+
}
41+
42+
if (data_returned > 255) {
43+
*(local_results + local_count) = 255;
44+
}
45+
else {
46+
*(local_results + local_count) = data_returned;
47+
}
48+
49+
local_count++;
50+
51+
if (local_count == 8)
52+
{
53+
memcpy(output_img + ((i * img_height) + (local_group_count * 8 * sizeof(char))), local_results, 8 * sizeof(char));
54+
local_count = 0;
55+
local_group_count++;
56+
}
57+
58+
current_number_of_pixels++;
59+
if ((((current_number_of_pixels*100) / (total_number_of_pixels))) >= next_target_of_completion) {
60+
printf("Image Filtering completed at %f\n", next_target_of_completion);
61+
next_target_of_completion += 10.0;
62+
}
63+
}
64+
}
65+
}
66+
67+
68+
#endif // IMG_FILTERING_CPP
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#ifndef IMG_UNIFICATION_CPP
2+
#define IMG_UNIFICATION_CPP
3+
4+
#include <../inc/address_map.hpp>
5+
#include <math.h>
6+
7+
//Test Unificate in FreeRTOS
8+
int intSqrt(int x)
9+
{
10+
unsigned int s = 0;
11+
for (unsigned int i = (1 << 15); i > 0; i >>= 1){
12+
if (((s+i) * (s+i)) <= x){
13+
s += i;
14+
}
15+
}
16+
return s;
17+
}
18+
19+
int norm(int a, int b)
20+
{
21+
int norm_result = 0;
22+
23+
norm_result = intSqrt(a*a+b*b); //sqrt(pow(a, 2) + pow(b, 2));
24+
25+
26+
return norm_result;
27+
}
28+
29+
void unificate_img(unsigned char *x_img, unsigned char *y_img, unsigned char *unificated_img, int img_size)
30+
{
31+
//Iterate over image
32+
for(unsigned char *x = x_img, *y = y_img, *u = unificated_img; x < x_img + img_size && y < y_img + img_size && u < unificated_img + img_size; x++, y++, u++){
33+
int pixel_magnitude;
34+
int pixel_x = (int) *x;
35+
int pixel_y = (int) *y;
36+
37+
pixel_magnitude = norm(pixel_x, pixel_y);
38+
39+
if (pixel_magnitude > 255) {pixel_magnitude = 255;};
40+
*u = (unsigned char) pixel_magnitude;
41+
}
42+
}
43+
44+
#endif // IMG_UNIFICATION_CPP

0 commit comments

Comments
 (0)