updated .gitignore
added source wrote README
This commit is contained in:
70
Project/FreeRTOSConfig.h
Normal file
70
Project/FreeRTOSConfig.h
Normal file
@ -0,0 +1,70 @@
|
||||
#ifndef FREERTOS_CONFIG_H
|
||||
#define FREERTOS_CONFIG_H
|
||||
|
||||
/*-----------------------------------------------------------
|
||||
* Application specific definitions.
|
||||
*
|
||||
* These definitions should be adjusted for your particular hardware and
|
||||
* application requirements.
|
||||
*
|
||||
* THESE PARAMETERS ARE DESCRIBED WITHIN THE 'CONFIGURATION' SECTION OF THE
|
||||
* FreeRTOS API DOCUMENTATION AVAILABLE ON THE FreeRTOS.org WEB SITE.
|
||||
*
|
||||
* See http://www.freertos.org/a00110.html.
|
||||
*----------------------------------------------------------*/
|
||||
|
||||
#define configUSE_PREEMPTION 1
|
||||
#define configUSE_IDLE_HOOK 0
|
||||
#define configUSE_TICK_HOOK 1
|
||||
#define configTICK_RATE_HZ ( ( portTickType ) 1000 )
|
||||
#define configMINIMAL_STACK_SIZE ( ( unsigned portSHORT ) 64 ) /* 64words x 4byte = 256byte */
|
||||
#define configTOTAL_HEAP_SIZE ( ( size_t ) ( 64 * 1024) ) /* 65536words x 4byte = 256Kbyte */
|
||||
#define configMAX_TASK_NAME_LEN ( 16 )
|
||||
#define configUSE_TRACE_FACILITY 0
|
||||
#define configUSE_16_BIT_TICKS 0
|
||||
#define configIDLE_SHOULD_YIELD 1
|
||||
#define configUSE_MUTEXES 1
|
||||
#define configCHECK_FOR_STACK_OVERFLOW 0 /* Do not use this option on the PC port. */
|
||||
#define configUSE_RECURSIVE_MUTEXES 1
|
||||
#define configQUEUE_REGISTRY_SIZE 20
|
||||
#define configUSE_MALLOC_FAILED_HOOK 1
|
||||
#define configUSE_APPLICATION_TASK_TAG 1
|
||||
#define configUSE_COUNTING_SEMAPHORES 1
|
||||
#define configUSE_ALTERNATIVE_API 0
|
||||
//#define configMAX_SYSCALL_INTERRUPT_PRIORITY 1
|
||||
|
||||
#define configUSE_QUEUE_SETS 1
|
||||
#define configUSE_TASK_NOTIFICATIONS 1
|
||||
|
||||
/* Software timer related configuration options. */
|
||||
#define configUSE_TIMERS 1
|
||||
#define configTIMER_TASK_PRIORITY ( configMAX_PRIORITIES - 1 )
|
||||
#define configTIMER_QUEUE_LENGTH 20
|
||||
#define configTIMER_TASK_STACK_DEPTH ( configMINIMAL_STACK_SIZE * 2 )
|
||||
|
||||
#define configMAX_PRIORITIES ( 10 )
|
||||
|
||||
#define configGENERATE_RUN_TIME_STATS 1
|
||||
|
||||
/* Set the following definitions to 1 to include the API function, or zero
|
||||
to exclude the API function. In most cases the linker will remove unused
|
||||
functions anyway. */
|
||||
#define INCLUDE_vTaskPrioritySet 1
|
||||
#define INCLUDE_uxTaskPriorityGet 1
|
||||
#define INCLUDE_vTaskDelete 1
|
||||
#define INCLUDE_vTaskSuspend 1
|
||||
#define INCLUDE_vTaskDelayUntil 1
|
||||
#define INCLUDE_vTaskDelay 1
|
||||
#define INCLUDE_uxTaskGetStackHighWaterMark 0 /* Do not use this option on the PC port. */
|
||||
#define INCLUDE_xTaskGetSchedulerState 1
|
||||
#define INCLUDE_xTimerGetTimerDaemonTaskHandle 1
|
||||
#define INCLUDE_xTaskGetIdleTaskHandle 1
|
||||
#define INCLUDE_pcTaskGetTaskName 1
|
||||
#define INCLUDE_eTaskGetState 1
|
||||
#define INCLUDE_xSemaphoreGetMutexHolder 1
|
||||
#define INCLUDE_xTimerPendFunctionCall 1
|
||||
#define INCLUDE_xTaskAbortDelay 1
|
||||
#define INCLUDE_xTaskGetHandle 1
|
||||
|
||||
|
||||
#endif /* FREERTOS_CONFIG_H */
|
171
Project/demo.c
Normal file
171
Project/demo.c
Normal file
@ -0,0 +1,171 @@
|
||||
/*
|
||||
* This file is part of the distribution https://git.mosad.xyz/localhorst/ParallelTrafficRouter_FreeRTOS
|
||||
* Copyright (c) 2019 Hendrik Schutter.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "FreeRTOS.h"
|
||||
#include "task.h"
|
||||
#include "semphr.h"
|
||||
#include "demo.h"
|
||||
|
||||
#define SIMULATE_COST
|
||||
|
||||
SemaphoreHandle_t xMutexData;
|
||||
|
||||
void vApplicationMallocFailedHook( void );
|
||||
void vApplicationIdleHook( void );
|
||||
void vApplicationTickHook( void );
|
||||
void search(void* arguments);
|
||||
void show(void* arguments);
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("starting routing ...\n");
|
||||
|
||||
xMutexData = xSemaphoreCreateMutex();
|
||||
|
||||
THREAD_DATA_t* data;
|
||||
data = (THREAD_DATA_t*) pvPortMalloc(sizeof(THREAD_DATA_t));
|
||||
data->node = getStartNode();
|
||||
data->cost = 0;
|
||||
data->depth = 0;
|
||||
data->predecessors[0] = data->node->id;
|
||||
data->bestpath = (BESTPATH_t*) pvPortMalloc(sizeof(BESTPATH_t));
|
||||
data->bestpath->lowestCost = -1;
|
||||
data->bestpath->depth = 0;
|
||||
|
||||
xTaskCreate(search, "startTask", configMINIMAL_STACK_SIZE, (void*) data, 1, 0);
|
||||
xTaskCreate(show, "showTask", configMINIMAL_STACK_SIZE, (void*) data, 0, 0);
|
||||
|
||||
vTaskStartScheduler();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void search(void* arguments)
|
||||
{
|
||||
|
||||
THREAD_DATA_t *data = (THREAD_DATA_t*) arguments;
|
||||
|
||||
printf("Node: %i reached\n", data->node->id);
|
||||
|
||||
#ifdef SIMULATE_COST
|
||||
vTaskDelay(((data->cost)*20)/ portTICK_PERIOD_MS); //receive data for route
|
||||
#endif
|
||||
|
||||
if(data->node->id == 8) //end node reached
|
||||
{
|
||||
printf("Route found! Cost: %i\n", data->cost);
|
||||
|
||||
xSemaphoreTake( xMutexData, ( TickType_t ) 1 );
|
||||
|
||||
if((data->bestpath->lowestCost == -1) || (data->bestpath->lowestCost > data->cost))
|
||||
//first route found or better route found
|
||||
{
|
||||
data->bestpath->lowestCost = data->cost;
|
||||
data->bestpath->depth = data->depth;
|
||||
for(int j = 0; j < data->depth; j++)
|
||||
{
|
||||
data->bestpath->predecessorsBestPath[j] = data->predecessors[j];
|
||||
}
|
||||
data->bestpath->predecessorsBestPath[(data->bestpath->depth)] = data->node->id;
|
||||
}
|
||||
|
||||
xSemaphoreGive( xMutexData );
|
||||
}
|
||||
else
|
||||
{
|
||||
//create new tasks
|
||||
for(int i = 0; i < data->node->nodescount; i++)
|
||||
{
|
||||
THREAD_DATA_t* nextdata;
|
||||
nextdata = (THREAD_DATA_t*) pvPortMalloc(sizeof(THREAD_DATA_t));
|
||||
//nextdata = (THREAD_DATA_t*) pvPortMalloc(1000000000);
|
||||
nextdata->node = (data->node->nodesnext[i]);
|
||||
nextdata->bestpath = data->bestpath;
|
||||
nextdata->cost = data->node->nodescost[i] + data->cost; //sum up cost
|
||||
nextdata->depth = data->depth + 1;
|
||||
|
||||
for(int j = 0; j < data->depth; j++) {
|
||||
nextdata->predecessors[j] = data->predecessors[j];
|
||||
}
|
||||
nextdata->predecessors[((nextdata->depth) - 1)] = data->node->id;
|
||||
|
||||
xTaskCreate(search, "searchTask", configMINIMAL_STACK_SIZE, (void*) nextdata, 2, 0);
|
||||
}
|
||||
}
|
||||
printf("Node: %i exit\n", data->node->id);
|
||||
|
||||
vTaskDelete( NULL );
|
||||
}
|
||||
|
||||
|
||||
void show(void* arguments)
|
||||
{
|
||||
THREAD_DATA_t *data = (THREAD_DATA_t*) arguments;
|
||||
for(;;)
|
||||
{
|
||||
xSemaphoreTake( xMutexData, ( TickType_t ) 1 );
|
||||
if(data->bestpath->lowestCost > -1)
|
||||
{
|
||||
printf("\nBest route: %i", data->bestpath->predecessorsBestPath[0]);
|
||||
for(int i = 1; i <= data->bestpath->depth; i++) {
|
||||
printf(" --> %i", data->bestpath->predecessorsBestPath[i]);
|
||||
}
|
||||
printf("\nWith cost of: %i\n", data->bestpath->lowestCost);
|
||||
}
|
||||
xSemaphoreGive( xMutexData );
|
||||
vTaskDelay(1000 / portTICK_PERIOD_MS); //wait 1sec
|
||||
}
|
||||
vTaskDelete( NULL );
|
||||
}
|
||||
|
||||
|
||||
void vApplicationMallocFailedHook( void )
|
||||
{
|
||||
printf("Malloc failed\n");
|
||||
}
|
||||
|
||||
|
||||
void vApplicationIdleHook( void )
|
||||
{
|
||||
//printf("No tasks to do\n");
|
||||
}
|
||||
|
||||
|
||||
void vApplicationTickHook( void )
|
||||
{
|
||||
//printf("TickHook\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
54
Project/demo.h
Normal file
54
Project/demo.h
Normal file
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* This file is part of the distribution https://git.mosad.xyz/localhorst/ParallelTrafficRouter_FreeRTOS
|
||||
* Copyright (c) 2019 Hendrik Schutter.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef DEMO_H
|
||||
#define DEMO_H
|
||||
|
||||
#define MAX_CHILDREN 3
|
||||
#define MAX_DEPTH 4
|
||||
|
||||
typedef struct node NODE_t;
|
||||
typedef struct threadData THREAD_DATA_t;
|
||||
typedef struct bestPath BESTPATH_t;
|
||||
|
||||
|
||||
extern NODE_t* getStartNode();
|
||||
|
||||
struct node {
|
||||
int id; //identifier for this node
|
||||
int nodescount; //how many children nodes
|
||||
NODE_t* nodesnext[MAX_CHILDREN]; //array of children nodes
|
||||
int nodescost[MAX_CHILDREN]; //array of cost per children node
|
||||
};
|
||||
|
||||
|
||||
struct threadData {
|
||||
int depth; //depth of the next node, e.g. start --> 0
|
||||
NODE_t* node; //next node to go
|
||||
int cost; //cost for the next node
|
||||
int predecessors[MAX_DEPTH]; // array with all predecessor
|
||||
BESTPATH_t* bestpath;
|
||||
};
|
||||
|
||||
|
||||
struct bestPath {
|
||||
int lowestCost;
|
||||
int predecessorsBestPath[MAX_DEPTH]; // array with all predecessor of the best path
|
||||
int depth; //depth of the best path, aka. how many nodes
|
||||
};
|
||||
|
||||
#endif /* DEMO_H */
|
92
Project/nodes.c
Normal file
92
Project/nodes.c
Normal file
@ -0,0 +1,92 @@
|
||||
/*
|
||||
* This file is part of the distribution https://git.mosad.xyz/localhorst/ParallelTrafficRouter_FreeRTOS
|
||||
* Copyright (c) 2019 Hendrik Schutter.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, version 3.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "demo.h"
|
||||
#include "FreeRTOS.h"
|
||||
|
||||
NODE_t* getStartNode();
|
||||
|
||||
NODE_t* getStartNode() {
|
||||
|
||||
static NODE_t* start;
|
||||
static NODE_t* g;
|
||||
static NODE_t* f;
|
||||
static NODE_t* e;
|
||||
static NODE_t* d;
|
||||
static NODE_t* c;
|
||||
static NODE_t* b;
|
||||
static NODE_t* a;
|
||||
static NODE_t* end;
|
||||
|
||||
start = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
a = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
b = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
c = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
d = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
e = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
f = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
g = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
end = (NODE_t*) pvPortMalloc(sizeof(NODE_t));
|
||||
|
||||
end->id = 8;
|
||||
end->nodescount = 0;
|
||||
|
||||
g->id = 7;
|
||||
g->nodescount = 0;
|
||||
|
||||
f->id = 6;
|
||||
f->nodescount = 1;
|
||||
f->nodesnext[0] = end;
|
||||
f->nodescost[0] = 7;
|
||||
|
||||
e->id = 5;
|
||||
e->nodescount = 0;
|
||||
|
||||
d->id = 4;
|
||||
d->nodescount = 0;
|
||||
|
||||
c->id = 3;
|
||||
c->nodescount = 1;
|
||||
c->nodesnext[0] = end;
|
||||
c->nodescost[0] = 3;
|
||||
|
||||
b->id = 2;
|
||||
b->nodescount = 3;
|
||||
b->nodesnext[0] = e;
|
||||
b->nodescost[0] = 11;
|
||||
b->nodesnext[1] = f;
|
||||
b->nodescost[1] = 42;
|
||||
b->nodesnext[2] = g;
|
||||
b->nodescost[2] = 8;
|
||||
|
||||
a->id = 1;
|
||||
a->nodescount = 2;
|
||||
a->nodesnext[0] = c;
|
||||
a->nodescost[0] = 15;
|
||||
a->nodesnext[1] = d;
|
||||
a->nodescost[1] = 27;
|
||||
|
||||
start->id = 0;
|
||||
start->nodescount = 2;
|
||||
start->nodesnext[0] = a;
|
||||
start->nodescost[0] = 72;
|
||||
start->nodesnext[1] = b;
|
||||
start->nodescost[1] = 32;
|
||||
|
||||
return start;
|
||||
}
|
Reference in New Issue
Block a user