|
| 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 | +/*-----------------------------------------------------------*/ |
0 commit comments