From 6b502b5dd3c84cd9c6eceff6b6391c4e61cf8f4e Mon Sep 17 00:00:00 2001 From: alfred gedeon Date: Fri, 4 Sep 2020 18:06:21 -0700 Subject: [PATCH] Build: replace scons with makefile (#235) * Build: transform scons into Makefile * Build: add Makefile dependencies * Build: remove some tabs from Makefile * Build: Make builds out of source, move wait for event to kernel port * Test: update the full test to print status messages * Build: replace lpthread with pthread Co-authored-by: Alfred Gedeon --- .../NetworkInterface/linux/NetworkInterface.c | 2 +- FreeRTOS/Demo/Posix_GCC/Makefile | 107 +++++++++++++ FreeRTOS/Demo/Posix_GCC/SConscript | 150 ------------------ FreeRTOS/Demo/Posix_GCC/SConstruct | 52 ------ FreeRTOS/Demo/Posix_GCC/main.c | 2 +- FreeRTOS/Demo/Posix_GCC/main_blinky.c | 2 +- FreeRTOS/Demo/Posix_GCC/main_full.c | 5 +- .../Demo/Posix_GCC/utils/wait_for_event.c | 75 --------- .../Demo/Posix_GCC/utils/wait_for_event.h | 18 --- 9 files changed, 114 insertions(+), 299 deletions(-) create mode 100644 FreeRTOS/Demo/Posix_GCC/Makefile delete mode 100644 FreeRTOS/Demo/Posix_GCC/SConscript delete mode 100644 FreeRTOS/Demo/Posix_GCC/SConstruct delete mode 100644 FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c delete mode 100644 FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h diff --git a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c index 04d9569890..4669ad35d7 100644 --- a/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c +++ b/FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c @@ -48,7 +48,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include /* ========================== Local includes =================================*/ -#include "utils/wait_for_event.h" +#include /* ======================== Macro Definitions =============================== */ #if ( ipconfigETHERNET_DRIVER_FILTERS_FRAME_TYPES == 0 ) diff --git a/FreeRTOS/Demo/Posix_GCC/Makefile b/FreeRTOS/Demo/Posix_GCC/Makefile new file mode 100644 index 0000000000..0d62070ad6 --- /dev/null +++ b/FreeRTOS/Demo/Posix_GCC/Makefile @@ -0,0 +1,107 @@ +CC := gcc +BIN := posix_demo + +BUILD_DIR := build + +FREERTOS_DIR_REL := ../../../FreeRTOS +FREERTOS_DIR := $(abspath $(FREERTOS_DIR_REL)) + +FREERTOS_PLUS_DIR_REL := ../../../FreeRTOS-Plus +FREERTOS_PLUS_DIR := $(abspath $(FREERTOS_PLUS_DIR_REL)) + +INCLUDE_DIRS := -I. +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/include +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix +INCLUDE_DIRS += -I${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils +INCLUDE_DIRS += -I${FREERTOS_DIR}/Demo/Common/include +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/Include +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/ +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/include/ +INCLUDE_DIRS += -I${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/ + +SOURCE_FILES := $(wildcard *.c) +SOURCE_FILES += $(wildcard ${FREERTOS_DIR}/Source/*.c) +# Memory manager (use malloc() / free() ) +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/MemMang/heap_3.c +# posix port +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/utils/wait_for_event.c +SOURCE_FILES += ${FREERTOS_DIR}/Source/portable/ThirdParty/GCC/Posix/port.c + +# FreeRTOS TCP +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c + +# Demo library. +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/AbortDelay.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/BlockQ.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/blocktim.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/countsem.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/death.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/dynamic.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/EventGroupsDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/flop.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/GenQTest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/integer.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/IntSemTest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferAMP.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/MessageBufferDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/PollQ.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QPeek.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueOverwrite.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSet.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/QueueSetPolling.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/recmutex.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/semtest.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StaticAllocation.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferDemo.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/StreamBufferInterrupt.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TaskNotify.c +SOURCE_FILES += ${FREERTOS_DIR}/Demo/Common/Minimal/TimerDemo.c + +# Trace library. +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcKernelPort.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c +SOURCE_FILES += ${FREERTOS_PLUS_DIR}/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c + + +CFLAGS := -ggdb3 -Og -DprojCOVERAGE_TEST=0 +LDFLAGS := -ggdb3 -Og -pthread -lpcap + +OBJ_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o) + +DEP_FILE = $(OBJ_FILES:%.o=%.d) + +${BIN} : $(BUILD_DIR)/$(BIN) + +${BUILD_DIR}/${BIN} : ${OBJ_FILES} + -mkdir -p ${@D} + $(CC) $(CFLAGS) $(INCLUDE_DIRS) ${LDFLAGS} $^ -o $@ + + +-include ${DEP_FILE} + +${BUILD_DIR}/%.o : %.c + -mkdir -p $(@D) + $(CC) $(CFLAGS) ${INCLUDE_DIRS} -MMD -c $< -o $@ + +.PHONY: clean + +clean: + -rm -rf $(BUILD_DIR) + + + + + + + diff --git a/FreeRTOS/Demo/Posix_GCC/SConscript b/FreeRTOS/Demo/Posix_GCC/SConscript deleted file mode 100644 index 5768f64d0c..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/SConscript +++ /dev/null @@ -1,150 +0,0 @@ -# FreeRTOS Kernel V10.3.0 -# Copyright (C) 2020 Cambridge Consultants Ltd. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# http://www.FreeRTOS.org -# http://aws.amazon.com/freertos - -Import("env") - -env.Append(CPPPATH = [ - ".", - "./utils", - "FreeRTOS/Source/include", - "FreeRTOS/Source/portable/ThirdParty/GCC/Posix", - "FreeRTOS/Demo/Common/include", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/Include", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/include/", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/Compiler/GCC/", -]) - -env.Append(LIBS = [ - "pthread", - "pcap", -]) - -src = [ - "console.c", - "main.c", - "main_blinky.c", - "main_full.c", - "main_networking.c", - "run-time-stats-utils.c", - "utils/wait_for_event.c", - "SimpleTCPEchoServer.c", - "TCPEchoClient_SingleTasks.c", - - # FreeRTOS kernel - "FreeRTOS/Source/event_groups.c", - "FreeRTOS/Source/list.c", - "FreeRTOS/Source/queue.c", - "FreeRTOS/Source/stream_buffer.c", - "FreeRTOS/Source/tasks.c", - "FreeRTOS/Source/timers.c", - - # Memory manager (use malloc()/free()). - "FreeRTOS/Source/portable/MemMang/heap_3.c", - - # Posix port. - "FreeRTOS/Source/portable/ThirdParty/GCC/Posix/port.c", - - # FreeRTOS TCP - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DNS.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_DHCP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_ARP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_WIN.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Stream_Buffer.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/BufferManagement/BufferAllocation_2.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_TCP_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_UDP_IP.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/FreeRTOS_Sockets.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-TCP/portable/NetworkInterface/linux/NetworkInterface.c", - - # Demo library. - "FreeRTOS/Demo/Common/Minimal/AbortDelay.c", - "FreeRTOS/Demo/Common/Minimal/BlockQ.c", - "FreeRTOS/Demo/Common/Minimal/blocktim.c", - "FreeRTOS/Demo/Common/Minimal/countsem.c", - "FreeRTOS/Demo/Common/Minimal/death.c", - "FreeRTOS/Demo/Common/Minimal/dynamic.c", - "FreeRTOS/Demo/Common/Minimal/EventGroupsDemo.c", - "FreeRTOS/Demo/Common/Minimal/flop.c", - "FreeRTOS/Demo/Common/Minimal/GenQTest.c", - "FreeRTOS/Demo/Common/Minimal/integer.c", - "FreeRTOS/Demo/Common/Minimal/IntSemTest.c", - "FreeRTOS/Demo/Common/Minimal/MessageBufferAMP.c", - "FreeRTOS/Demo/Common/Minimal/MessageBufferDemo.c", - "FreeRTOS/Demo/Common/Minimal/PollQ.c", - "FreeRTOS/Demo/Common/Minimal/QPeek.c", - "FreeRTOS/Demo/Common/Minimal/QueueOverwrite.c", - "FreeRTOS/Demo/Common/Minimal/QueueSet.c", - "FreeRTOS/Demo/Common/Minimal/QueueSetPolling.c", - "FreeRTOS/Demo/Common/Minimal/recmutex.c", - "FreeRTOS/Demo/Common/Minimal/semtest.c", - "FreeRTOS/Demo/Common/Minimal/StaticAllocation.c", - "FreeRTOS/Demo/Common/Minimal/StreamBufferDemo.c", - "FreeRTOS/Demo/Common/Minimal/StreamBufferInterrupt.c", - "FreeRTOS/Demo/Common/Minimal/TaskNotify.c", - "FreeRTOS/Demo/Common/Minimal/TimerDemo.c", -] - -if GetOption("coverage"): - env.Append(CPPDEFINES = [ - "projCOVERAGE_TEST=1", - ]) - - env.Append(CFLAGS = [ - "-fprofile-arcs", - "-ftest-coverage", - "-ggdb3", - "-Og", - ]) - env.Append(LINKFLAGS = [ - "-fprofile-arcs", - "-ftest-coverage", - "-ggdb3", - "-Og", - ]) - - src += [ - "code_coverage_additions.c", - ] -else: - env.Append(CPPDEFINES = [ - "projCOVERAGE_TEST=0", - ]) - - src += [ - # Trace library. - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcKernelPort.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcSnapshotRecorder.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/trcStreamingRecorder.c", - "FreeRTOS-Plus/Source/FreeRTOS-Plus-Trace/streamports/File/trcStreamingPort.c", - ] - -# Build the simple "blinky" demo application, or the full test -# applicaton? -if GetOption("simple"): - env.Append(CPPDEFINES = [ - "mainCREATE_SIMPLE_BLINKY_DEMO_ONLY=1", - ]) - -env.Program("posix_demo", src) diff --git a/FreeRTOS/Demo/Posix_GCC/SConstruct b/FreeRTOS/Demo/Posix_GCC/SConstruct deleted file mode 100644 index fd6ef6298f..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/SConstruct +++ /dev/null @@ -1,52 +0,0 @@ -# FreeRTOS Kernel V10.3.0 -# Copyright (C) 2020 Cambridge Consultants Ltd. -# -# Permission is hereby granted, free of charge, to any person obtaining a copy of -# this software and associated documentation files (the "Software"), to deal in -# the Software without restriction, including without limitation the rights to -# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of -# the Software, and to permit persons to whom the Software is furnished to do so, -# subject to the following conditions: -# -# The above copyright notice and this permission notice shall be included in all -# copies or substantial portions of the Software. -# -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS -# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR -# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER -# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -# -# http://www.FreeRTOS.org -# http://aws.amazon.com/freertos -# -# This is the main SCons (https://scons.org/) build file for the -# Posix/GCC demo application. - -import os - -# Create a symlink to the FreeRTOS sources. -if not os.path.exists("FreeRTOS"): - os.symlink("../..", "FreeRTOS") -if not os.path.exists("FreeRTOS-Plus"): - os.symlink("../../../FreeRTOS-Plus", "FreeRTOS-Plus") - -AddOption("--simple", - action='store_true', - help="build the simple 'blinky' demo application") - -AddOption("--coverage", - action='store_true', - help="enable code coverage") - -env = Environment() -Export("env") - -env.Append(CFLAGS = [ - "-g", - "-Wall", - "-O2", -]) - -SConscript("./SConscript", variant_dir="build", duplicate=0) diff --git a/FreeRTOS/Demo/Posix_GCC/main.c b/FreeRTOS/Demo/Posix_GCC/main.c index 93772b2c4c..4b252bbe75 100644 --- a/FreeRTOS/Demo/Posix_GCC/main.c +++ b/FreeRTOS/Demo/Posix_GCC/main.c @@ -83,7 +83,7 @@ is implemented in main_networking.c. */ #endif #ifndef mainCREATE_TCP_ECHO_TASKS_SINGLE - #define mainCREATE_TCP_ECHO_TASKS_SINGLE 1 + #define mainCREATE_TCP_ECHO_TASKS_SINGLE 0 #endif /* This demo uses heap_3.c (the libc provided malloc() and free()). */ diff --git a/FreeRTOS/Demo/Posix_GCC/main_blinky.c b/FreeRTOS/Demo/Posix_GCC/main_blinky.c index 69c7e7e237..78e98f1b01 100644 --- a/FreeRTOS/Demo/Posix_GCC/main_blinky.c +++ b/FreeRTOS/Demo/Posix_GCC/main_blinky.c @@ -246,7 +246,7 @@ uint32_t ulReceivedValue; is it an expected value? Normally calling printf() from a task is not a good idea. Here there is lots of stack space and only one task is using console IO so it is ok. However, note the comments at the top of - this file about the risks of making Windows system calls (such as + this file about the risks of making Windows system calls (such as console output) from a FreeRTOS task. */ if( ulReceivedValue == mainVALUE_SENT_FROM_TASK ) { diff --git a/FreeRTOS/Demo/Posix_GCC/main_full.c b/FreeRTOS/Demo/Posix_GCC/main_full.c index 3bdfe98241..3d9f198cf7 100644 --- a/FreeRTOS/Demo/Posix_GCC/main_full.c +++ b/FreeRTOS/Demo/Posix_GCC/main_full.c @@ -106,6 +106,7 @@ #include "StreamBufferDemo.h" #include "StreamBufferInterrupt.h" #include "MessageBufferAMP.h" +#include "console.h" /* Priorities at which the tasks are created. */ #define mainCHECK_TASK_PRIORITY ( configMAX_PRIORITIES - 2 ) @@ -182,7 +183,7 @@ static void prvReloadModeTestTimerCallback( TimerHandle_t xTimer ); /*-----------------------------------------------------------*/ /* The variable into which error messages are latched. */ -static char *pcStatusMessage = "No errors"; +static char *pcStatusMessage = "OK: No errors"; /* This semaphore is created purely to test using the vSemaphoreDelete() and semaphore tracing API functions. It has no other purpose. */ @@ -383,6 +384,8 @@ const TickType_t xCycleFrequency = pdMS_TO_TICKS( 2500UL ); pcStatusMessage = "Error: Static allocation"; } #endif /* configSUPPORT_STATIC_ALLOCATION */ + console_print("TickCount %d, pcStatusMessage %s\n", + xNextWakeTime, pcStatusMessage); } } /*-----------------------------------------------------------*/ diff --git a/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c b/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c deleted file mode 100644 index 6d0bfffda3..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.c +++ /dev/null @@ -1,75 +0,0 @@ -#include -#include -#include - -#include "wait_for_event.h" - -struct event -{ - pthread_mutex_t mutex; - pthread_cond_t cond; - bool event_triggered; -}; - -struct event * event_create() -{ - struct event * ev = malloc( sizeof( struct event ) ); - - ev->event_triggered = false; - pthread_mutex_init( &ev->mutex, NULL ); - pthread_cond_init( &ev->cond, NULL ); - return ev; -} - -void event_delete( struct event * ev ) -{ - pthread_mutex_destroy( &ev->mutex ); - pthread_cond_destroy( &ev->cond ); - free( ev ); -} - -bool event_wait( struct event * ev ) -{ - pthread_mutex_lock( &ev->mutex ); - - while( ev->event_triggered == false ) - { - pthread_cond_wait( &ev->cond, &ev->mutex ); - } - - pthread_mutex_unlock( &ev->mutex ); - return true; -} -bool event_wait_timed( struct event * ev, - time_t ms ) -{ - struct timespec ts; - int ret = 0; - - clock_gettime( CLOCK_REALTIME, &ts ); - //ts.tv_sec += ms; - ts.tv_nsec += (ms * 1000000); - pthread_mutex_lock( &ev->mutex ); - - while( (ev->event_triggered == false) && (ret == 0) ) - { - ret = pthread_cond_timedwait( &ev->cond, &ev->mutex, &ts ); - - if( ( ret == -1 ) && ( errno == ETIMEDOUT ) ) - { - return false; - } - } - - ev->event_triggered = false; - pthread_mutex_unlock( &ev->mutex ); - return true; -} - -void event_signal( struct event * ev ) -{ - pthread_mutex_lock( &ev->mutex ); - ev->event_triggered = true; - pthread_cond_signal( &ev->cond ); - pthread_mutex_unlock( &ev->mutex ); -} diff --git a/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h b/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h deleted file mode 100644 index 2693a0d8ca..0000000000 --- a/FreeRTOS/Demo/Posix_GCC/utils/wait_for_event.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef _WAIT_FOR_EVENT_H_ -#define _WAIT_FOR_EVENT_H_ - -#include -#include - -struct event; - -struct event * event_create(); -void event_delete( struct event * ); -bool event_wait( struct event * ev ); -bool event_wait_timed( struct event * ev, - time_t ms ); -void event_signal( struct event * ev ); - - - -#endif /* ifndef _WAIT_FOR_EVENT_H_ */