Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean main and init files from different architectures #151

Merged
merged 48 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
0e55f4b
fix new device interface in ctfTracer test
cochicde Jun 5, 2024
8dbe5b6
first part
cochicde Jun 6, 2024
7095b0f
cleanup all archs
cochicde Jun 6, 2024
4ca64a3
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Jun 6, 2024
924e58d
fix merge conflict
cochicde Jun 6, 2024
9f8a794
add missing flag for shared library
cochicde Jun 7, 2024
242f3dc
fix windows architecture declaration and cleanup startuphook file
cochicde Jun 7, 2024
ea89b0d
Update src/arch/forte.cpp
cochicde Jun 8, 2024
581f023
Update src/arch/forte.cpp
cochicde Jun 8, 2024
ccf943e
Apply suggestions from code review
cochicde Jun 8, 2024
fe0ab41
some more cleanup
cochicde Jun 8, 2024
c885559
Merge branch 'clean-main' of github.com:cochicde/4diac-forte into cle…
cochicde Jun 8, 2024
cef37e2
fix all comments
cochicde Jun 8, 2024
7f82c8a
fix all
cochicde Jun 8, 2024
a6c0299
limit shared library test only when forte is build as shared library
cochicde Jun 8, 2024
ed7c92c
move signals hook to each arch
cochicde Jun 8, 2024
853c756
use devlog in freeRTOS
cochicde Jun 8, 2024
df4aef8
add typedef when compiling as C
cochicde Jun 14, 2024
0bc7d6f
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Jun 16, 2024
d547ea7
separate c interface library and add test for it
cochicde Jul 12, 2024
ae4b5a6
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Jul 12, 2024
8b4511d
clean freertos main
cochicde Jul 12, 2024
21acd20
try fix on windows
cochicde Jul 12, 2024
9056c2b
try windows fix 2
cochicde Jul 12, 2024
5dc7fac
do some more cleanup
cochicde Jul 13, 2024
5baf266
last cleanup, promise
cochicde Jul 13, 2024
c026dab
build libraries in github workflows
cochicde Jul 13, 2024
52faabd
link boost library only in posix
cochicde Jul 13, 2024
f33a6b0
add linker option also to new tests
cochicde Jul 13, 2024
a0b71ba
fix boost include
cochicde Jul 13, 2024
35e0c58
export windows symbols for shared library
cochicde Jul 13, 2024
21700b2
try fixing windows issue
cochicde Jul 13, 2024
e7a14ef
export windows symbols at a global level
cochicde Jul 14, 2024
986aef3
disable shared library test in windows
cochicde Jul 14, 2024
cd563e8
update headers
cochicde Jul 23, 2024
b27df14
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Jul 24, 2024
1f9ebd8
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Jul 26, 2024
6e55f1f
add delay in tests
cochicde Jul 27, 2024
44ea506
fixes after feedback
cochicde Aug 13, 2024
a41dc27
remove template parameter from general architecture
cochicde Aug 14, 2024
fd47279
use BOOST_TEST where possible
cochicde Aug 15, 2024
9ea8b84
use helper function to print response type
cochicde Aug 15, 2024
a4a624b
fix linker flags
cochicde Sep 7, 2024
663b0d7
fix linker flags properly
cochicde Sep 7, 2024
0c669d0
Merge remote-tracking branch 'origin/develop' into clean-main
cochicde Sep 7, 2024
29dca66
make linker libraries for C library PUBLIC
cochicde Sep 7, 2024
45cd92d
remove link to shared boost
cochicde Sep 8, 2024
0e9f85f
use unnamed namespace in freeRTOS main
cochicde Sep 15, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ FOREACH(STARTUP_HOOK_FUNCTION ${STARTUP_HOOK_FUNCTIONS_LIST})
SET(FORTE_STARTUP_HOOKS_CALLS "${FORTE_STARTUP_HOOKS_CALLS} ${STARTUP_HOOK_FUNCTION}(argc, arg);\n")
ENDFOREACH()

CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/arch/startuphook.cpp.in ${CMAKE_BINARY_DIR}/src_gen/startuphook_new.cpp)
CONFIGURE_FILE(${CMAKE_CURRENT_SOURCE_DIR}/startuphook.cpp.in ${CMAKE_BINARY_DIR}/src_gen/startuphook_new.cpp)
forte_replacefile_if_changed(${CMAKE_BINARY_DIR}/src_gen/startuphook_new.cpp ${CMAKE_BINARY_DIR}/src_gen/startuphook.cpp)
file(REMOVE ${CMAKE_BINARY_DIR}/src_gen/startuphook_new.cpp)

forte_add_sourcefile_with_path_cpp(${CMAKE_BINARY_DIR}/src_gen/startuphook.cpp)

#############################################################################
# Load FORTE Extension Files
#############################################################################
Expand Down Expand Up @@ -337,6 +339,7 @@ if(FORTE_BUILD_SHARED_LIBRARY)
TARGET_LINK_LIBRARIES (forte-shared ${LINK_LIBRARY})
ADD_DEPENDENCIES (forte-shared FORTE_LITE)
install(TARGETS forte-shared ARCHIVE DESTINATION bin LIBRARY DESTINATION bin)
target_compile_options(FORTE_LITE PRIVATE "-fPIC")
message("Building shared library")
endif(FORTE_BUILD_SHARED_LIBRARY)

Expand Down
4 changes: 3 additions & 1 deletion src/arch/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@ add_subdirectory(zephyr)

add_subdirectory(utils)

forte_add_sourcefile_hcpp(timerha devlog)
forte_add_include_directories(${CMAKE_CURRENT_SOURCE_DIR}/common)

forte_add_sourcefile_hcpp(timerha devlog forte)

SET(FORTE_LOGGER_BUFFER_SIZE "300" CACHE STRING "Buffer's length of the logger")
mark_as_advanced(FORTE_LOGGER_BUFFER_SIZE)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
/*******************************************************************************
* Copyright (c) 2017 fortiss GmbH
* Copyright (c) 2024
azoitl marked this conversation as resolved.
Show resolved Hide resolved
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jose Cabral, Alois Zoitl - initial API and implementation and/or initial documentation
* Jose Cabral - initial API and implementation and/or initial documentation
*******************************************************************************/

#ifndef FORTE_INSTANCE_H_
#define FORTE_INSTANCE_H_
#include "forte_specific_architecture.h"

#ifdef __cplusplus
extern "C" {
#endif

void startupFORTE();
void shutdownFORTE();

#ifdef __cplusplus
int CForteSpecificArchitecture::initialize(int , char** ){
return 0;
}
#endif

#endif
int CForteSpecificArchitecture::deinitialize() {
return 0;
}
26 changes: 26 additions & 0 deletions src/arch/common/forte_specific_architecture.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*******************************************************************************
* Copyright (c) 2024
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Jose Cabral - initial API and implementation and/or initial documentation
*******************************************************************************/

#ifndef SRC_ARCH_COMMON_FORTE_SPECIFIC_ARCHITECTURE_H_
#define SRC_ARCH_COMMON_FORTE_SPECIFIC_ARCHITECTURE_H_
cochicde marked this conversation as resolved.
Show resolved Hide resolved

#include "forte_specific_architecture.h"

class CForteSpecificArchitecture{
public:

static int initialize(int argc , char* argv[]);
cochicde marked this conversation as resolved.
Show resolved Hide resolved

static int deinitialize();
};

#endif /* SRC_ARCH_COMMON_FORTE_SPECIFIC_ARCHITECTURE_H_ */
10 changes: 10 additions & 0 deletions src/arch/ecos/ecoscppinit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,13 @@ extern "C" void
__cxa_pure_virtual(void) {
//TODO maybe add some exception handling reporting here
}

extern "C" void abort(int ) { while(1) ; }

void *__dso_handle = 0;

extern "C" int _getpid(void) {
return 1;
}

extern "C" void _kill(int ) { while(1) ; }
41 changes: 0 additions & 41 deletions src/arch/ecos/forte_architecture.cpp

This file was deleted.

2 changes: 1 addition & 1 deletion src/arch/ecos/nios2/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Nios2")
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp ../../forte_standard_time.cpp)

forte_add_sourcefile_cpp(../ecoscppinit.cpp ../../genforte_printer.cpp ../forte_architecture.cpp)
forte_add_sourcefile_cpp(../ecoscppinit.cpp ../../genforte_printer.cpp ../../common/forte_specific_architecture.cpp)
forte_add_sourcefile_h(../../forte_architecture_time.h)
forte_add_sourcefile_cpp(../../genforte_realFunctions.cpp)

Expand Down
2 changes: 1 addition & 1 deletion src/arch/ecos/phycoreat91/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ if("${FORTE_ARCHITECTURE}" STREQUAL "Phycore AT91")
else(FORTE_FAKE_TIME)
forte_add_sourcefile_hcpp(../ecostiha)
endif(FORTE_FAKE_TIME)
forte_add_sourcefile_cpp(../../posix/forte_architecture_time.cpp ../../forte_standard_time.cpp)
forte_add_sourcefile_cpp(../ecoscppinit.cpp ../../posix/forte_architecture_time.cpp ../../forte_standard_time.cpp ../../common/forte_specific_architecture.cpp)

forte_add_sourcefile_cpp(../../genforte_printer.cpp)
forte_add_sourcefile_h(../../forte_architecture_time.h)
Expand Down
84 changes: 46 additions & 38 deletions src/arch/ecos/forte_instance.cpp → src/arch/forte.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,42 +11,42 @@
* Tarik Terzimehic - make OPC UA server port setable from the command line
*******************************************************************************/

#include "forte_instance.h"
#include "forteinstance.h"
#include <forte_printer.h>

#include "fortenew.h"
#include "forte_architecture.h"
#include <stdio.h>
#include <stdlib.h>
#include "../../stdfblib/ita/RMT_DEV.h"
#include "forte.h"

#include "../utils/mainparam_utils.h"
#include "forte_architecture.h"
#include "forte_printer.h"
#include "forteinstance.h"

unsigned const int cgForteDefaultPort = 61499;
static const unsigned int scForteDefaultPort = 61499;
static const unsigned int scMaxPortValue = 65535;

/*!\brief Check if the correct endianess has been configured.
*
* If the right endianess is not set this function will end FORTE.
cochicde marked this conversation as resolved.
Show resolved Hide resolved
*/
bool checkEndianess();

void forteGlobalInitialize(){
CForteArchitecture::initialize();
int forteGlobalInitialize(int argc, char *argv[]){
if(auto result = CForteArchitecture::initialize(argc, argv); result != 0){
return result;
}
return 0;
cochicde marked this conversation as resolved.
Show resolved Hide resolved
}

void forteGlobalDeinitialize(){
CForteArchitecture::deinitialize();
int forteGlobalDeinitialize(){
return CForteArchitecture::deinitialize();
}

int forteStartInstance(unsigned int paPort, TForteInstance* paResultInstance){
FORTE_STATUS forteStartInstance(unsigned int paPort, TForteInstance* paResultInstance){

if(65535 < paPort){
if(scMaxPortValue < paPort){
DEVLOG_ERROR("Provided port %d not valid\n", paPort);
cochicde marked this conversation as resolved.
Show resolved Hide resolved
return FORTE_WRONG_PARAMETERS;
}

if(0 == paPort){
paPort = cgForteDefaultPort;
paPort = scForteDefaultPort;
}

char progName[] = "forte";
Expand All @@ -60,50 +60,58 @@ int forteStartInstance(unsigned int paPort, TForteInstance* paResultInstance){
return forteStartInstanceGeneric(3, arguments, paResultInstance);
}

int forteStartInstanceGeneric(int argc, char *arg[], TForteInstance* paResultInstance){

if(!CForteArchitecture::isInitialized()){
return FORTE_ARCHITECTURE_NOT_READY;
}
FORTE_STATUS forteStartInstanceGeneric(int argc, char *argv[], TForteInstance* paResultInstance){

if(0 == paResultDevice){
if(nullptr == paResultInstance){
DEVLOG_ERROR("Provided result instance parameter not valid\n");
cochicde marked this conversation as resolved.
Show resolved Hide resolved
return FORTE_WRONG_PARAMETERS;
}

if(0 != *paResultDevice){
if(nullptr != *paResultInstance){
DEVLOG_ERROR("Provided result instance already started\n");
return FORTE_DEVICE_ALREADY_STARTED;
}

if(!checkEndianess()){
// logged already in the function
return FORTE_WRONG_ENDIANESS;
}

const char *pIpPort = parseCommandLineArguments(argc, arg);
if((0 != strlen(pIpPort)) && (nullptr != strchr(pIpPort, ':'))){
C4diacFORTEInstance *instance = new C4diacFORTEInstance();
if(!instance->startupNewDevice(ipPort)) {
delete instance;
return FORTE_COULD_NOT_CREATE_DEVICE;
}
*paResultInstance = instance;
DEVLOG_INFO("FORTE is up and running\n");
if(!CForteArchitecture::isInitialized()){
DEVLOG_ERROR("The low level platform should be initialized before starting a forte instance\n");
return FORTE_ARCHITECTURE_NOT_READY;
}
else{ //! If needed call listHelp() to list the help for FORTE

const auto ipPort = parseCommandLineArguments(argc, argv);
if((0 == strlen(ipPort)) || (nullptr == strchr(ipPort, ':'))){
return FORTE_WRONG_PARAMETERS;
}

C4diacFORTEInstance *instance = new C4diacFORTEInstance();
if(!instance->startupNewDevice(ipPort)) {
delete instance;
return FORTE_COULD_NOT_CREATE_DEVICE;
}
*paResultInstance = instance;

return FORTE_OK;
}

void forteStopInstance(int, TForteInstance paInstance){
if(!CForteArchitecture::isInitialized() || paResultInstance == nullptr){
void forteRequestStopInstance(TForteInstance paInstance){
if(!CForteArchitecture::isInitialized() || paInstance == nullptr){
return;
}
C4diacFORTEInstance *instance = static_cast<C4diacFORTEInstance *>(paResultInstance);
auto *instance = static_cast<C4diacFORTEInstance *>(paInstance);
instance->triggerDeviceShutdown();
}

void forteWaitForInstanceToStop(TForteInstance paInstance) {
if(!CForteArchitecture::isInitialized() || paInstance == nullptr){
return;
}
auto *instance = static_cast<C4diacFORTEInstance *>(paInstance);
instance->awaitDeviceShutdown();
delete instance;
DEVLOG_INFO("FORTE finished\n");
}

bool checkEndianess(){
Expand Down
41 changes: 25 additions & 16 deletions src/arch/ecos/forte_instance.h → src/arch/forte.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
* Jose Cabral - initial API and implementation and/or initial documentation
*******************************************************************************/

#ifndef FORTE_INSTANCE_H_
#define FORTE_INSTANCE_H_
#ifndef SRC_ARCH_FORTE_H_
#define SRC_ARCH_FORTE_H_

/* When moving this file to the outside of the architecture,
* the corresponding defines for exporting in windows or other platform
Expand All @@ -32,7 +32,7 @@ extern "C" {
#endif

enum FORTE_STATUS{
FORTE_OK,
FORTE_OK = 0,
FORTE_DEVICE_ALREADY_STARTED,
FORTE_WRONG_ENDIANESS,
FORTE_WRONG_PARAMETERS,
Expand All @@ -44,41 +44,50 @@ extern "C" {

/**
* \brief Start forte instance
* @param pa_port The port on which to forte will listen. Use 0 for default (normally 61499)
* @param pa_resultDevice Address of an instance of forte
* @param paPort The port on which to forte will listen. Use 0 for default (normally 61499)
cochicde marked this conversation as resolved.
Show resolved Hide resolved
* @param paResultInstance Address of an instance of forte
cochicde marked this conversation as resolved.
Show resolved Hide resolved
* @return FORTE_OK if no error occurred, other values otherwise
cochicde marked this conversation as resolved.
Show resolved Hide resolved
*/
FORTE_SHARED_PREFIX int FORTE_SHARED_CALL forteStartInstance(unsigned int pa_port, TForteInstance* paResultInstance);
FORTE_SHARED_PREFIX FORTE_STATUS FORTE_SHARED_CALL forteStartInstance(unsigned int paPort, TForteInstance* paResultInstance);
cochicde marked this conversation as resolved.
Show resolved Hide resolved

/**
* \brief Start forte instance with posibilities of more arguments
* @param argc Number of arguments in arg
* @param arg Arguments
* @param pa_resultDevice Address of an instance of forte
* @param argv Arguments
* @param paResultInstance Address of an instance of forte
cochicde marked this conversation as resolved.
Show resolved Hide resolved
* @return FORTE_OK if no error occurred, other values otherwise
*/
FORTE_SHARED_PREFIX int FORTE_SHARED_CALL forteStartInstanceGeneric(int argc, char *arg[], TForteInstance* paResultInstance);
FORTE_SHARED_PREFIX FORTE_STATUS FORTE_SHARED_CALL forteStartInstanceGeneric(int argc, char *argv[], TForteInstance* paResultInstance);

/**
* \brief Terminates a Forte instance
* @param signal Signal value to terminate instance
* @param pa_resultDevice Instance to terminate
* \brief Request termination of a Forte instance
* @param paInstance Instance to terminate
cochicde marked this conversation as resolved.
Show resolved Hide resolved
*/
FORTE_SHARED_PREFIX void FORTE_SHARED_CALL forteStopInstance(int signal, TForteInstance paInstance);
FORTE_SHARED_PREFIX void FORTE_SHARED_CALL forteRequestStopInstance(TForteInstance paInstance);

/**
* \brief Waits indefinitely for the intance to stop
cochicde marked this conversation as resolved.
Show resolved Hide resolved
* @param paInstance Instance to terminate
*/
FORTE_SHARED_PREFIX void FORTE_SHARED_CALL forteWaitForInstanceToStop(TForteInstance paInstance);

/**
* \brief Initializes the architecture. Prepare all resources needed by the Forte's instances. Must be called once before the first Forte instance is started
* @param argc Number of arguments in arg
* @param argv Arguments
* @return 0 if no error occurred, other values otherwise
cochicde marked this conversation as resolved.
Show resolved Hide resolved
*/
FORTE_SHARED_PREFIX void FORTE_SHARED_CALL forteGlobalInitialize();
FORTE_SHARED_PREFIX int FORTE_SHARED_CALL forteGlobalInitialize(int argc, char *argv[]);

/**
* \brief Deinitializes the architecture. Frees all resources used by Forte's instances. Must be called after the last instance is ended
* @return 0 if no error occurred, other values otherwise
cochicde marked this conversation as resolved.
Show resolved Hide resolved
*/
FORTE_SHARED_PREFIX void FORTE_SHARED_CALL forteGlobalDeinitialize();
FORTE_SHARED_PREFIX int FORTE_SHARED_CALL forteGlobalDeinitialize();


#ifdef __cplusplus
}
#endif

#endif /* FORTE_INSTANCE_H_ */
#endif /* SRC_ARCH_FORTE_H_ */
Loading
Loading