Skip to content

Commit 7eb428d

Browse files
committed
Add unification of gradients
1 parent 5ae4ff0 commit 7eb428d

File tree

1 file changed

+112
-76
lines changed

1 file changed

+112
-76
lines changed

modules/VirtualPrototype/FreeRTOS/freertos_test.c

Lines changed: 112 additions & 76 deletions
Original file line numberDiff line numberDiff line change
@@ -17,46 +17,6 @@
1717

1818
extern void register_timer_isr();
1919

20-
QueueHandle_t my_queue = NULL;
21-
22-
static void task_1(void *pParameter) {
23-
24-
int data = 5;
25-
printf("Task 1 starts\n");
26-
27-
while(1) {
28-
printf("T1: Tick %ld\n", xTaskGetTickCount() );
29-
xQueueSend(my_queue, &data, portMAX_DELAY);
30-
vTaskDelay(100 / portTICK_PERIOD_MS);
31-
}
32-
}
33-
34-
static void task_2(void *pParameter) {
35-
36-
int data = 7;
37-
38-
printf("Task 2 starts\n");
39-
40-
while(1) {
41-
printf("T2: Tick %ld\n", xTaskGetTickCount() );
42-
xQueueSend(my_queue, &data, portMAX_DELAY);
43-
vTaskDelay(500 / portTICK_PERIOD_MS);
44-
}
45-
}
46-
47-
static void task_3(void *pParameter) {
48-
int data;
49-
50-
printf("Task 3 starts\n");
51-
52-
while(1) {
53-
xQueueReceive(my_queue, &data, portMAX_DELAY);
54-
printf("T3: Tick %ld. Recv: %ld\n", xTaskGetTickCount(), data);
55-
//vTaskDelay(1000 / portTICK_PERIOD_MS);
56-
}
57-
58-
}
59-
6020
void transfer_window(int i, int j, unsigned long long source_address, unsigned long long target_address)
6121
{
6222
unsigned char *source_ptr = (unsigned char *) source_address;
@@ -232,32 +192,17 @@ void transfer_window(int i, int j, unsigned long long source_address, unsigned l
232192

233193
static void task_test_sobel(void *pParameter)
234194
{
235-
unsigned char *sobel_input_0_ptr = (unsigned char*) SOBEL_INPUT_0_ADDRESS_LO;
236-
unsigned char *sobel_input_1_ptr = (unsigned char*) SOBEL_INPUT_1_ADDRESS_LO;
237195
short int *sobel_output_ptr = (short int*) SOBEL_OUTPUT_ADDRESS_LO;
238196
short int *output_image_X_ptr = (short int*) IMG_INPROCESS_B_ADDRESS_LO;
239197
short int *output_image_Y_ptr = (short int*) IMG_INPROCESS_C_ADDRESS_LO;
240-
unsigned char local_window[3 * 3];
241198
short int sobel_results[2];
242199

243-
// printf("Starting with SOBEL testing on address %p\n", (void*)sobel_input_0_ptr);
244-
// *(local_window + 0) = 150;
245-
// *(local_window + 1) = 20;
246-
// *(local_window + 2) = 38;
247-
// *(local_window + 3) = 64;
248-
// *(local_window + 4) = 32;
249-
// *(local_window + 5) = 8;
250-
// *(local_window + 6) = 16;
251-
// *(local_window + 7) = 75;
252-
// *(local_window + 8) = 99;
253-
// printf("Will copy values to SOBEL on address %p\n", (void*)sobel_input_0_ptr);
254-
// memcpy(sobel_input_0_ptr, local_window, 8 * sizeof(char));
255-
// printf("Will copy values to SOBEL on address %p\n", (void*)sobel_input_1_ptr);
256-
// memcpy(sobel_input_1_ptr, (local_window + 8), 1 * sizeof(char));
257-
// memcpy(sobel_results, sobel_output_ptr, 2 * sizeof(short int));
258-
// printf("Results of SOBEL are %d at address %p and %d at address %p\n", sobel_results[0], (void*)sobel_output_ptr, sobel_results[1], (void*)(sobel_output_ptr + 1));
259-
260-
printf("Starting to process of image with Sobel gradient\n");
200+
int final_target = IMAG_ROWS * IMAG_COLS;
201+
int current_progress = 0;
202+
int step = final_target / 10;
203+
int next_target = 1;
204+
205+
printf("Starting IMG Sobel Step: \n");
261206

262207
for (int i = 0; i < IMAG_ROWS; i++)
263208
{
@@ -267,10 +212,17 @@ static void task_test_sobel(void *pParameter)
267212
memcpy(sobel_results, sobel_output_ptr, 2 * sizeof(short int));
268213
*(output_image_X_ptr + ((i * IMAG_COLS) + j)) = sobel_results[0];
269214
*(output_image_Y_ptr + ((i * IMAG_COLS) + j)) = sobel_results[1];
215+
216+
if (current_progress == next_target * step)
217+
{
218+
printf("Current progress is at %0d%%\n", next_target * 10);
219+
next_target++;
220+
}
221+
current_progress++;
270222
}
271223
}
272224

273-
printf("Finished process of image with Sobel gradient\n");
225+
printf("Done IMG Sobel Step: \n");
274226
}
275227

276228
unsigned char compute_gray_value(unsigned char r_val, unsigned char g_val, unsigned char b_val)
@@ -285,7 +237,12 @@ void convert_to_grayscale()
285237
unsigned char rgb_val[3];
286238
unsigned char gray_val;
287239

288-
printf("Starting process of image with grayscale conversion\n");
240+
int final_target = IMAG_ROWS * IMAG_COLS;
241+
int current_progress = 0;
242+
int step = final_target / 10;
243+
int next_target = 1;
244+
245+
printf("Starting IMG Grayscale Step: \n");
289246

290247
for (int i = 0; i < IMAG_ROWS; i++)
291248
{
@@ -302,10 +259,17 @@ void convert_to_grayscale()
302259
// printf("On pixel %0d %0d gray value %0d\n", i, j, gray_val);
303260
// }
304261
*(target_ptr + ((i * IMAG_COLS) + j)) = gray_val;
262+
263+
if (current_progress == next_target * step)
264+
{
265+
printf("Current progress is at %0d%%\n", next_target * 10);
266+
next_target++;
267+
}
268+
current_progress++;
305269
}
306270
}
307271

308-
printf("Finished process of image with grayscale conversion\n");
272+
printf("Done IMG Grayscale Step: \n");
309273
}
310274

311275
static void task_test_grayscale(void *pParameter)
@@ -318,40 +282,112 @@ void filter_image()
318282
unsigned char *filter_output_ptr = (unsigned char*) IMG_FILTER_OUTPUT_ADDRESS_LO;
319283
unsigned char *output_image_ptr = (unsigned char*) IMG_COMPRESSED_ADDRESS_LO;
320284

321-
printf("Starting filtering of image\n");
285+
int final_target = IMAG_ROWS * IMAG_COLS;
286+
int current_progress = 0;
287+
int step = final_target / 10;
288+
int next_target = 1;
289+
290+
printf("Starting IMG Filtering Step: \n");
322291

323292
for (int i = 0; i < IMAG_ROWS; i++)
324293
{
325294
for (int j = 0; j < IMAG_COLS; j++)
326295
{
327296
transfer_window(i, j, IMG_INPROCESS_A_ADDRESS_LO, IMG_FILTER_KERNEL_ADDRESS_LO);
328297
*(output_image_ptr + ((i * IMAG_COLS) + j)) = *(filter_output_ptr);
298+
299+
if (current_progress == next_target * step)
300+
{
301+
printf("Current progress is at %0d%%\n", next_target * 10);
302+
next_target++;
303+
}
304+
current_progress++;
329305
}
330306
}
331307

332-
printf("Finished filtering of image\n");
308+
printf("Done IMG Filtering Step: \n");
333309
}
334310

335311
static void task_test_filtering(void *pParameter)
336312
{
337313
filter_image();
338314
}
339315

316+
int intSqrt(int x)
317+
{
318+
unsigned int s = 0;
319+
for (unsigned int i = (1 << 15); i > 0; i >>= 1){
320+
if (((s+i) * (s+i)) <= x){
321+
s += i;
322+
}
323+
}
324+
return s;
325+
}
326+
327+
int norm(int a, int b)
328+
{
329+
int norm_result = 0;
330+
331+
norm_result = intSqrt(a*a+b*b); //sqrt(pow(a, 2) + pow(b, 2));
332+
333+
334+
return norm_result;
335+
}
336+
337+
void unificate_img()
338+
{
339+
short int *x_img = (short int *) IMG_INPROCESS_B_ADDRESS_LO;
340+
short int *y_img = (short int *) IMG_INPROCESS_C_ADDRESS_LO;
341+
unsigned char *unificated_img = (unsigned char *) IMG_INPROCESS_A_ADDRESS_LO;
342+
343+
int final_target = IMAG_ROWS * IMAG_COLS;
344+
int current_progress = 0;
345+
int step = final_target / 10;
346+
int next_target = 1;
347+
348+
printf("Starting IMG Unification Step: \n");
349+
350+
//Iterate over image
351+
for (int i = 0; i < IMAG_ROWS * IMAG_COLS; i++)
352+
{
353+
int pixel_magnitude;
354+
int pixel_x = (int) *x_img;
355+
int pixel_y = (int) *y_img;
356+
357+
pixel_magnitude = norm(pixel_x, pixel_y);
358+
359+
if (pixel_magnitude > 255)
360+
{
361+
pixel_magnitude = 255;
362+
}
363+
*unificated_img = (unsigned char) pixel_magnitude;
364+
365+
x_img++;
366+
y_img++;
367+
unificated_img++;
368+
369+
if (current_progress == next_target * step)
370+
{
371+
printf("Current progress is at %0d%%\n", next_target * 10);
372+
next_target++;
373+
}
374+
current_progress++;
375+
}
376+
377+
printf("Done IMG Unification Step: \n");
378+
}
379+
380+
static void testbench(void *pParameter) {
381+
// filter_image();
382+
unificate_img();
383+
}
384+
340385
int main( void )
341386
{
342387

343388
printf("Starting FreeRTOS test\n");
344389

345-
my_queue = xQueueCreate(10, sizeof(int));
346-
347-
/* Create tasks */
348-
xTaskCreate(task_1, "Task1", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
349-
xTaskCreate(task_2, "Task2", 10000, NULL, tskIDLE_PRIORITY+1, NULL);
350-
xTaskCreate(task_3, "Task3", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
351-
352-
// xTaskCreate(task_test_sobel, "TaskSobel", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
353-
// xTaskCreate(task_test_grayscale, "TaskGrayscale", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
354-
xTaskCreate(task_test_filtering, "TaskFiltering", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
390+
xTaskCreate(testbench, "testbench", configMINIMAL_STACK_SIZE, NULL, tskIDLE_PRIORITY+1, NULL);
355391
/* Start the kernel. From here on, only tasks and interrupts will run. */
356392
vTaskStartScheduler();
357393

0 commit comments

Comments
 (0)