|
| 1 | +cmake_minimum_required(VERSION 3.13) |
| 2 | +project(freertos_sim C) |
| 3 | + |
| 4 | +# Set build type if not specified |
| 5 | +if(NOT CMAKE_BUILD_TYPE) |
| 6 | + set(CMAKE_BUILD_TYPE Debug) |
| 7 | +endif() |
| 8 | + |
| 9 | +# FreeRTOS source files |
| 10 | +set(FREERTOS_DIR "${CMAKE_CURRENT_SOURCE_DIR}/freertos") |
| 11 | +set(FREERTOS_KERNEL_DIR "${FREERTOS_DIR}/FreeRTOS-Kernel") |
| 12 | + |
| 13 | +# wolfSSL directories |
| 14 | +set(WOLFSSL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfssl") |
| 15 | +set(WOLFIP_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfip") |
| 16 | +set(WOLFMQTT_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../wolfMQTT") |
| 17 | + |
| 18 | +# Certificate paths |
| 19 | +set(WOLFSSL_CERTS_DIR "${WOLFSSL_DIR}/certs") |
| 20 | + |
| 21 | +# Add definitions for certificate paths |
| 22 | +add_definitions( |
| 23 | + -DMQTT_TLS_CA_CERT="${WOLFSSL_CERTS_DIR}/ca-cert.pem" |
| 24 | + -DMQTT_TLS_CLIENT_CERT="${WOLFSSL_CERTS_DIR}/client-cert.pem" |
| 25 | + -DMQTT_TLS_CLIENT_KEY="${WOLFSSL_CERTS_DIR}/client-key.pem" |
| 26 | +) |
| 27 | + |
| 28 | +# FreeRTOS configuration |
| 29 | +add_definitions( |
| 30 | + -DPOSIX_PORT |
| 31 | + -DPOSIX |
| 32 | + -D_POSIX_C_SOURCE=200809L |
| 33 | + -D_POSIX_THREAD_SAFE_FUNCTIONS |
| 34 | + -DENABLE_MQTT_TLS |
| 35 | + -DDEBUG=0 |
| 36 | +) |
| 37 | + |
| 38 | +# wolfSSL configuration |
| 39 | +add_definitions( |
| 40 | + -DWOLFSSL_USER_SETTINGS |
| 41 | + -DHAVE_TLS_EXTENSIONS |
| 42 | + -DHAVE_SUPPORTED_CURVES |
| 43 | + -DTFM_TIMING_RESISTANT |
| 44 | + -DECC_TIMING_RESISTANT |
| 45 | + -DWC_RSA_BLINDING |
| 46 | + -DHAVE_AESGCM |
| 47 | + -DHAVE_CHACHA |
| 48 | + -DHAVE_POLY1305 |
| 49 | + -DHAVE_ECC |
| 50 | + -DHAVE_CURVE25519 |
| 51 | + -DHAVE_ED25519 |
| 52 | + -DENABLE_MQTT_TLS |
| 53 | +) |
| 54 | + |
| 55 | +# wolfIP definitions |
| 56 | +add_definitions( |
| 57 | + -DLINK_MTU=1500 |
| 58 | + -DRXBUF_SIZE=8192 |
| 59 | + -DTXBUF_SIZE=8192 |
| 60 | + -DMAX_TCPSOCKETS=8 |
| 61 | + -DMAX_UDPSOCKETS=8 |
| 62 | + -DMAX_TIMERS=24 |
| 63 | + -DWOLFIP_DEBUG |
| 64 | + -DWOLFSSL_DEBUG |
| 65 | + -DWOLFMQTT_DEBUG |
| 66 | + -DETH_TYPE_IP=0x0800 |
| 67 | +) |
| 68 | + |
| 69 | +# FreeRTOS source files |
| 70 | +set(FREERTOS_SRC |
| 71 | + ${FREERTOS_KERNEL_DIR}/tasks.c |
| 72 | + ${FREERTOS_KERNEL_DIR}/queue.c |
| 73 | + ${FREERTOS_KERNEL_DIR}/list.c |
| 74 | + ${FREERTOS_KERNEL_DIR}/timers.c |
| 75 | + ${FREERTOS_KERNEL_DIR}/event_groups.c |
| 76 | + ${FREERTOS_KERNEL_DIR}/stream_buffer.c |
| 77 | + ${FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Posix/port.c |
| 78 | + ${FREERTOS_KERNEL_DIR}/portable/MemMang/heap_3.c |
| 79 | + ${FREERTOS_DIR}/utils/posix_utils.c |
| 80 | +) |
| 81 | + |
| 82 | +# Create utils.c if it doesn't exist |
| 83 | +if(NOT EXISTS "${FREERTOS_DIR}/utils/utils.c") |
| 84 | + file(MAKE_DIRECTORY "${FREERTOS_DIR}/utils") |
| 85 | + file(WRITE "${FREERTOS_DIR}/utils/utils.c" "/* utils.c |
| 86 | + * |
| 87 | + * Copyright (C) 2006-2024 wolfSSL Inc. |
| 88 | + * |
| 89 | + * This file is part of wolfSSL. |
| 90 | + * |
| 91 | + * wolfSSL is free software; you can redistribute it and/or modify |
| 92 | + * it under the terms of the GNU General Public License as published by |
| 93 | + * the Free Software Foundation; either version 2 of the License, or |
| 94 | + * (at your option) any later version. |
| 95 | + * |
| 96 | + * wolfSSL is distributed in the hope that it will be useful, |
| 97 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 98 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 99 | + * GNU General Public License for more details. |
| 100 | + * |
| 101 | + * You should have received a copy of the GNU General Public License |
| 102 | + * along with this program; if not, write to the Free Software |
| 103 | + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA |
| 104 | + */ |
| 105 | +
|
| 106 | +#include <stdio.h> |
| 107 | +#include <stdlib.h> |
| 108 | +#include <string.h> |
| 109 | +#include <time.h> |
| 110 | +
|
| 111 | +/* Utility functions for FreeRTOS */ |
| 112 | +void utils_init(void) |
| 113 | +{ |
| 114 | + /* Initialize random seed */ |
| 115 | + srand(time(NULL)); |
| 116 | +} |
| 117 | +") |
| 118 | +endif() |
| 119 | + |
| 120 | +# Add utils.c to FreeRTOS sources |
| 121 | +list(APPEND FREERTOS_SRC ${FREERTOS_DIR}/utils/utils.c) |
| 122 | + |
| 123 | +# wolfIP source files - use stub implementation |
| 124 | +set(WOLFIP_SRC |
| 125 | + ${CMAKE_CURRENT_SOURCE_DIR}/src/wolfip_stub.c |
| 126 | +) |
| 127 | + |
| 128 | +# Application source files |
| 129 | +set(APP_SRC |
| 130 | + src/main.c |
| 131 | + src/wolfip_freertos.c |
| 132 | + src/mqtt_client.c |
| 133 | + src/mqtt_net.c |
| 134 | + src/wolfip_utils.c |
| 135 | + src/wolfmqtt_stub.c |
| 136 | + src/tap_interface.c |
| 137 | +) |
| 138 | + |
| 139 | +# Include directories |
| 140 | +include_directories( |
| 141 | + ${CMAKE_CURRENT_SOURCE_DIR}/include |
| 142 | + ${CMAKE_CURRENT_SOURCE_DIR}/include/FreeRTOSConfig |
| 143 | + ${CMAKE_CURRENT_SOURCE_DIR}/src |
| 144 | + ${FREERTOS_KERNEL_DIR}/include |
| 145 | + ${FREERTOS_KERNEL_DIR}/portable/ThirdParty/GCC/Posix |
| 146 | + ${WOLFSSL_DIR} |
| 147 | + ${WOLFIP_DIR} |
| 148 | + ${WOLFIP_DIR}/src/include |
| 149 | + ${WOLFMQTT_DIR} |
| 150 | +) |
| 151 | + |
| 152 | +# Create static library for wolfIP |
| 153 | +add_library(wolfip STATIC ${WOLFIP_SRC}) |
| 154 | + |
| 155 | +# Set compiler flags for wolfIP library |
| 156 | +target_compile_options(wolfip PRIVATE |
| 157 | + -Wall |
| 158 | + -Wextra |
| 159 | + -g |
| 160 | + -fpack-struct |
| 161 | +) |
| 162 | + |
| 163 | +# Create executable |
| 164 | +add_executable(freertos_sim |
| 165 | + ${FREERTOS_SRC} |
| 166 | + ${APP_SRC} |
| 167 | +) |
| 168 | + |
| 169 | +# Link libraries |
| 170 | +target_link_libraries(freertos_sim |
| 171 | + wolfip |
| 172 | + wolfssl |
| 173 | + pthread |
| 174 | + m |
| 175 | + rt |
| 176 | +) |
| 177 | + |
| 178 | +# Compiler flags |
| 179 | +target_compile_options(freertos_sim PRIVATE |
| 180 | + -Wall |
| 181 | + -Wextra |
| 182 | + -g |
| 183 | + -fpack-struct |
| 184 | +) |
0 commit comments