Skip to content

Commit

Permalink
Merge pull request #113 from Fundacio-i2CAT/dev
Browse files Browse the repository at this point in the history
Merge dev into master
  • Loading branch information
edugrasa authored Sep 8, 2022
2 parents 30966a2 + 03fa7a1 commit 0c53686
Show file tree
Hide file tree
Showing 52 changed files with 601 additions and 963 deletions.
536 changes: 39 additions & 497 deletions CMakeLists.txt

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions cmake/lib.common.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
macro(rs_scan_cmakelists)
file(GLOB component_dirs ${CMAKE_SOURCE_DIR}/components/*)
file(GLOB mock_component_dirs ${CMAKE_SOURCE_DIR}/components_mocks/*)
list(APPEND component_dirs ${mock_component_dirs})
foreach(component_dir IN LISTS component_dirs)
message("Looking in ${component_dir}")
set(cmakelist "${component_dir}/CMakeLists.txt")
if(EXISTS ${cmakelist})
message("Including ${cmakelist}")
include(${cmakelist})
endif()
endforeach()
endmacro()
182 changes: 182 additions & 0 deletions cmake/lib.linux.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
macro(_rs_add_component component_name)
get_property(prop_components GLOBAL PROPERTY _RS_COMPONENTS)
list(APPEND prop_components ${component_name})
set_property(GLOBAL PROPERTY _RS_COMPONENTS ${prop_components})
endmacro()

macro(_rs_set_component_data component_name data value)
set(prop_name _RS_COMPONENTS_${component_name}_${data})
set_property(GLOBAL PROPERTY ${prop_name} ${value})
endmacro()

macro(_rs_get_component_data component_name data var)
set(prop_name _RS_COMPONENTS_${component_name}_${data})
get_property(${var} GLOBAL PROPERTY ${prop_name})
endmacro()

macro(rs_get_component_include_dirs component_name var)
_rs_get_component_data(${component_name} INCLUDES ${var})
endmacro()

function(rs_component component_name)
set(single_value TEST_DIR)
set(multi_values SRCS INCLUDES REQUIRES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN})

if(DEFINED __SRCS)
# Plain static library
set(${component_name}_SOURCES)

foreach(src IN LISTS __SRCS)
set(file ${CMAKE_CURRENT_LIST_DIR}/${src})
if(EXISTS ${file})
# If it's a file that exists, add it as-is.
list(APPEND ${component_name}_SOURCES ${file})
else()
# If it's not a file, assume it's globbing patern.
set(files)
# Execute the globbing pattern
file(GLOB files ${src})
# Append the result to the list of source files for this
# target.
list(APPEND ${component_name}_SOURCES ${files})
endif()
endforeach()

# We're making OBJECT libraries because CMake doesn't make it
# super easy link static libraries together as a shared library.
add_library(${component_name} OBJECT ${${component_name}_SOURCES})

# Add the locally defined include directories.
target_include_directories(${component_name} PUBLIC ${__INCLUDES})

# Save the list of include directories for resolving dependencies.
_rs_set_component_data(${component_name} INCLUDES "${__INCLUDES}")
else()
# Include-only component

add_library(${component_name} INTERFACE)
target_include_directories(${component_name} INTERFACE ${__INCLUDES})

# Save the list of include directories for resolving dependencies.
_rs_set_component_data(${component_name} INCLUDES "${__INCLUDES}")
endif()

_rs_add_component(${component_name})

if(DEFINED __REQUIRES)
set(comp_requirements)
foreach(req_name ${__REQUIRES})
list(APPEND comp_requirements ${req_name})
endforeach()

_rs_set_component_data(${component_name} REQUIRES "${comp_requirements}")
endif()

if(DEFINED __TEST_DIR)
include("${__TEST_DIR}/CMakeLists.txt" OPTIONAL)
endif()
endfunction()

function(rs_plain_component component_name)
set(single_value DIR TEST_DIR)
set(multi_values REQUIRES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN})
rs_component(${component_name}
SRCS ${__DIR}/*.c
INCLUDES ${__DIR}/include
TEST_DIR ${__TEST_DIR}
REQUIRES ${__REQUIRES})
endfunction()

function(rs_include_component component_name)
set(single_value DIR TEST_DIR)
set(multi_values REQUIRES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN})
rs_component(${component_name}
INCLUDES ${__DIR}/include
TEST_DIR ${__TEST_DIR}
REQUIRES ${__REQUIRES})
endfunction()

function(_rs_get_dep_list component_name target_var)
_rs_get_component_data(${component_name} REQUIRES component_req)
foreach(req IN LISTS component_req)
list(APPEND ${target_var} ${req})
_rs_get_dep_list(${req} ${target_var})
endforeach()
endfunction()

function(_rs_add_includes_from_component component_name from_component)
set(seen_deps)
set(req_list)

# Add the include path from the direct dependency
_rs_get_component_data(${from_component} INCLUDES from_includes)
target_include_directories(${component_name} PRIVATE ${from_includes})

# Make a list of ALL the include paths we need to add.
_rs_get_component_data(${from_component} REQUIRES req_list)
foreach(req IN LISTS req_list)
if(NOT ${req} IN_LIST seen_deps)
list(APPEND seen_deps ${req})
_rs_get_component_data(${req} REQUIRES more_reqs)
list(APPEND req_list ${more_reqs})
endif()
endforeach()

# Add all the include paths
foreach(req IN LISTS req_list)
_rs_get_component_data(${req} INCLUDES req_includes)
target_include_directories(${component_name} PUBLIC ${req_includes})
endforeach()
endfunction()

function(rs_resolve_dependencies)
# Get the list of components
get_property(components GLOBAL PROPERTY _RS_COMPONENTS)

# Iterate through all components to make sure that their dependency
# list is sound.
foreach(component_name ${components})
message("Resolving dependencies of ${component_name}")

_rs_get_component_data(${component_name} REQUIRES component_req_list)

foreach(component_req IN LISTS component_req_list)
if(${component_req} IN_LIST components)
message("... requires ${component_req}: OK")
_rs_add_includes_from_component(${component_name} ${component_req})
else()
message(FATAL_ERROR "... requires ${component_req}: NOT FOUND")
endif()
endforeach()
endforeach()
endfunction()

#
# ESP-IDF compatibility function.
#
# This does not support everything that the ESP-IDF build system has
# to offer.
#
function(idf_component_register)
set(single_value DIR)
set(multi_values SRCS INCLUDE_DIRS REQUIRES)
cmake_parse_arguments(_ "${options}" "${single_value}" "${multi_values}" ${ARGN})

cmake_path(GET CMAKE_CURRENT_LIST_DIR FILENAME comp_name)

# Automatically add the 'test' directory as TEST_DIR if it exists.
set(test_dir ${CMAKE_CURRENT_LIST_DIR}/test)
if(NOT EXISTS ${test_dir})
set(test_dir "")
endif()

# Call into our own component functions
rs_component(${comp_name}
SRCS ${CMAKE_CURRENT_LIST_DIR}/${__SRCS}
INCLUDES ${CMAKE_CURRENT_LIST_DIR}/${__INCLUDE_DIRS}
TEST_DIR ${test_dir}
REQUIRES ${__REQUIRES})
endfunction()
68 changes: 46 additions & 22 deletions components/ARP826/ARP826.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ bool_t xARPAddressGPAShrink(gpa_t *pxGpa, uint8_t ucFiller)
if (pucPosition >= pxGpa->pucAddress + pxGpa->uxLength)
{
LOGI(TAG_ARP, "GPA doesn't need to be shrinked ...");
return false;
return true;
}

uxLength = pucPosition - pxGpa->pucAddress;
Expand Down Expand Up @@ -353,7 +353,7 @@ bool_t vARPSendRequest(gpa_t *pxTpa, gpa_t *pxSpa, gha_t *pxSha)

/* Send a message to the IPCP-task to send this ARP packet. */
xSendEvent.eEventType = eNetworkTxEvent;
xSendEvent.pvData = pxNetworkBuffer;
xSendEvent.xData.PV = (void *)pxNetworkBuffer;

if (!xSendEventStructToIPCPTask(&xSendEvent, 1000))
{
Expand Down Expand Up @@ -598,7 +598,7 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame)
pxTmpTha = pxCreateGHA(MAC_ADDR_802_3, (MACAddress_t *)ucTha);
// vARPPrintCache();

if (xARPAddressGPAShrink(pxTmpSpa, 0x00))
if (!xARPAddressGPAShrink(pxTmpSpa, 0x00))
{
LOGE(TAG_ARP, "Problems parsing the source GPA");
vGPADestroy(pxTmpSpa);
Expand All @@ -607,7 +607,7 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame)
vGHADestroy(pxTmpTha);
return eReturn;
}
if (xARPAddressGPAShrink(pxTmpTpa, 0x00))
if (!xARPAddressGPAShrink(pxTmpTpa, 0x00))
{
LOGE(TAG_ARP, "Got problems parsing the target GPA");
vGPADestroy(pxTmpSpa);
Expand All @@ -625,11 +625,19 @@ eFrameProcessingResult_t eARPProcessPacket(ARPPacket_t *const pxARPFrame)
// handle = pvPortMalloc(sizeof(*handle));
// Check Cache by Address

LOGE(TAG_ARP, "ARP_REQUEST ptype 0x%04X", usOperation);
LOGI(TAG_ARP, "ARP_REQUEST for protocol type 0x%04X", usOperation);

if (eARPLookupGPA(pxTmpSpa) == eARPCacheMiss)
{
LOGE(TAG_ARP, "I don't have a table for ptype 0x%04X", usPtype);
#ifndef NDEBUG
char *psAddr;

RsAssert((psAddr = xGPAAddressToString(pxTmpSpa)) != NULL);
LOGE(TAG_ARP, "Nothing found for entry %s for protocol type 0x%04X", psAddr, usPtype);
vRsMemFree(psAddr);
#else
LOGE(TAG_ARP, "Nothing found for protocol type 0x%04X", usPtype);
#endif
vGPADestroy(pxTmpSpa);
vGPADestroy(pxTmpTpa);
vGHADestroy(pxTmpSha);
Expand Down Expand Up @@ -712,12 +720,21 @@ eARPLookupResult_t eARPLookupGPA(const gpa_t *pxGpaToLookup)
num_t x;
eARPLookupResult_t eReturn = eARPCacheMiss;

LOGI(TAG_ARP, "eARPLookupGPA loop start");

/* Loop through each entry in the ARP cache. */
for (x = 0; x < ARP_CACHE_ENTRIES; x++)
{
LOGI(TAG_ARP, "eARPLookupGPA loop: %d", x);
/* Skip empty entries. */
if (xARPCache[x].ucAge == 0)
continue;

#ifndef NDEBUG
string_t pcLoopAddr;

RsAssert((pcLoopAddr = xGPAAddressToString(xARPCache[x].pxProtocolAddress)) != NULL);
LOGD(TAG_ARP, "eARPLookupGPA -> %s", pcLoopAddr);
vRsMemFree(pcLoopAddr);
#endif

if (xGPACmp(xARPCache[x].pxProtocolAddress, pxGpaToLookup))
{
/* A matching valid entry was found. */
Expand Down Expand Up @@ -879,25 +896,28 @@ void vARPInitCache(void)
LOGI(TAG_ARP, "ARP CACHE Initialized");
}

void prvARPPrintCacheItem(int nIndex)
{
LOGD(TAG_ARP, "Arp Entry %i: %3d - %s - %02x:%02x:%02x:%02x:%02x:%02x",
nIndex,
xARPCache[nIndex].ucAge,
xARPCache[nIndex].pxProtocolAddress->pucAddress,
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[0],
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[1],
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[2],
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[3],
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[4],
xARPCache[nIndex].pxMACAddress->xAddress.ucBytes[5]);
}

void vARPPrintCache(void)
{
num_t x, xCount = 0;

for (x = 0; x < ARP_CACHE_ENTRIES; x++)
{
if ((xARPCache[x].pxProtocolAddress->pucAddress != 0UL) && (xARPCache[x].ucValid != 0))
{
LOGI(TAG_ARP, "Arp Entry %i: %3d - %s - %02x:%02x:%02x:%02x:%02x:%02x\n",
x,
xARPCache[x].ucAge,
xARPCache[x].pxProtocolAddress->pucAddress,
xARPCache[x].pxMACAddress->xAddress.ucBytes[0],
xARPCache[x].pxMACAddress->xAddress.ucBytes[1],
xARPCache[x].pxMACAddress->xAddress.ucBytes[2],
xARPCache[x].pxMACAddress->xAddress.ucBytes[3],
xARPCache[x].pxMACAddress->xAddress.ucBytes[4],
xARPCache[x].pxMACAddress->xAddress.ucBytes[5]);
}
prvARPPrintCacheItem(x);
xCount++;
}
LOGI(TAG_ARP, "Arp has %d entries\n", xCount);
Expand Down Expand Up @@ -933,7 +953,11 @@ void vARPAddCacheEntry(struct rinarpHandle_t *pxHandle, uint8_t ucAge)
xARPCache[x].pxMACAddress = pxHandle->pxHa;
xARPCache[x].ucAge = ucAge;
xARPCache[x].ucValid = 1;
LOGD(TAG_ARP, "ARP Entry successful");

#ifndef NDEBUG
prvARPPrintCacheItem(x);
LOGD(TAG_ARP, "ARP Entry added successfully");
#endif

break;
}
Expand Down
18 changes: 15 additions & 3 deletions components/ARP826/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
idf_component_register(SRCS "ARP826.c"
INCLUDE_DIRS "include"
REQUIRES NetworkInterface ShimIPCP BufferManagement configSensor Common Portability RINA_API)
set(reqs
EFCP
Rmt
NetworkInterface
ShimIPCP
BufferManagement
configSensor
Common
Portability
RINA_API
IPCP)

idf_component_register(
SRCS "ARP826.c"
INCLUDE_DIRS "include"
REQUIRES ${reqs})
2 changes: 1 addition & 1 deletion components/ARP826/test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf")
else()
add_executable(test_arp826 "${CMAKE_CURRENT_LIST_DIR}/test_arp826.c")
target_link_libraries(test_arp826 PUBLIC
ARP826
RINA
NetworkInterface_MQ
unity
)
Expand Down
22 changes: 19 additions & 3 deletions components/BufferManagement/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
idf_component_register(SRCS "BufferManagement.c"
INCLUDE_DIRS "include"
REQUIRES ShimIPCP NetworkInterface ARP826 Portability FreeRTOS-Plus-POSIX)
set(requirements
ShimIPCP
NetworkInterface
ARP826
Portability
)

# The FreeRTOS-Plus-POSIX module is only necessary for ESP-IDF
# on-device builds.
if("$ENV{TARGET_TYPE}" STREQUAL "freertos_idf")
list(APPEND requirements FreeRTOS-Plus-POSIX)
endif()

idf_component_register(
SRCS "BufferManagement.c"
INCLUDE_DIRS "include"
REQUIRES ${requirements}
)


Loading

0 comments on commit 0c53686

Please sign in to comment.