-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented new build system with CMake
- Loading branch information
1 parent
463dd1c
commit 6a66ef0
Showing
29 changed files
with
1,879 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
# Copyright (C) 2024 by Skyward | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# it under the terms of the GNU General Public License as published | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# 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. | ||
# | ||
# As a special exception, if other files instantiate templates or use | ||
# macros or inline functions from this file, or you compile this file | ||
# and link it with other works to produce a work based on this file, | ||
# this file does not by itself cause the resulting work to be covered | ||
# by the GNU General Public License. However the source code for this | ||
# file must still be made available in accordance with the GNU | ||
# Public License. This exception does not invalidate any other | ||
# why a work based on this file might be covered by the GNU General | ||
# Public License. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(Main C CXX ASM) | ||
|
||
# Set here your board of choice | ||
set(MIOSIX_OPT_BOARD NOT_SET CACHE STRING "Target board") | ||
|
||
add_subdirectory(miosix EXCLUDE_FROM_ALL) | ||
include(LinkTarget) | ||
|
||
# List here your source files (.s, .c and .cpp) | ||
add_executable(main main.cpp) | ||
miosix_link_target(main) | ||
|
||
# List here additional include directories | ||
# target_include_directories(main PRIVATE here_your_includes) | ||
|
||
# List here additional static libraries | ||
# target_link_libraries(main PRIVATE here_your_libraries) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
# Copyright (C) 2024 by Skyward | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# it under the terms of the GNU General Public License as published | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# 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. | ||
# | ||
# As a special exception, if other files instantiate templates or use | ||
# macros or inline functions from this file, or you compile this file | ||
# and link it with other works to produce a work based on this file, | ||
# this file does not by itself cause the resulting work to be covered | ||
# by the GNU General Public License. However the source code for this | ||
# file must still be made available in accordance with the GNU | ||
# Public License. This exception does not invalidate any other | ||
# why a work based on this file might be covered by the GNU General | ||
# Public License. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(Miosix | ||
VERSION 2.7 | ||
DESCRIPTION "OS kernel designed to run on 32bit microcontrollers." | ||
HOMEPAGE_URL "https://miosix.org" | ||
LANGUAGES C CXX | ||
) | ||
|
||
set(MIOSIX_KPATH ${CMAKE_CURRENT_LIST_DIR} CACHE PATH "Path to the miosix kernel") | ||
|
||
set(MIOSIX_KERNEL_SRC | ||
${MIOSIX_KPATH}/kernel/kernel.cpp | ||
${MIOSIX_KPATH}/kernel/sync.cpp | ||
${MIOSIX_KPATH}/kernel/error.cpp | ||
${MIOSIX_KPATH}/kernel/pthread.cpp | ||
${MIOSIX_KPATH}/kernel/boot.cpp | ||
${MIOSIX_KPATH}/kernel/elf_program.cpp | ||
${MIOSIX_KPATH}/kernel/process.cpp | ||
${MIOSIX_KPATH}/kernel/process_pool.cpp | ||
${MIOSIX_KPATH}/kernel/timeconversion.cpp | ||
${MIOSIX_KPATH}/kernel/intrusive.cpp | ||
${MIOSIX_KPATH}/kernel/cpu_time_counter.cpp | ||
${MIOSIX_KPATH}/kernel/scheduler/priority/priority_scheduler.cpp | ||
${MIOSIX_KPATH}/kernel/scheduler/control/control_scheduler.cpp | ||
${MIOSIX_KPATH}/kernel/scheduler/edf/edf_scheduler.cpp | ||
${MIOSIX_KPATH}/filesystem/file_access.cpp | ||
${MIOSIX_KPATH}/filesystem/file.cpp | ||
${MIOSIX_KPATH}/filesystem/path.cpp | ||
${MIOSIX_KPATH}/filesystem/stringpart.cpp | ||
${MIOSIX_KPATH}/filesystem/pipe/pipe.cpp | ||
${MIOSIX_KPATH}/filesystem/console/console_device.cpp | ||
${MIOSIX_KPATH}/filesystem/mountpointfs/mountpointfs.cpp | ||
${MIOSIX_KPATH}/filesystem/devfs/devfs.cpp | ||
${MIOSIX_KPATH}/filesystem/fat32/fat32.cpp | ||
${MIOSIX_KPATH}/filesystem/fat32/ff.cpp | ||
${MIOSIX_KPATH}/filesystem/fat32/diskio.cpp | ||
${MIOSIX_KPATH}/filesystem/fat32/wtoupper.cpp | ||
${MIOSIX_KPATH}/filesystem/fat32/ccsbcs.cpp | ||
${MIOSIX_KPATH}/filesystem/littlefs/lfs_miosix.cpp | ||
${MIOSIX_KPATH}/filesystem/littlefs/lfs.c | ||
${MIOSIX_KPATH}/filesystem/littlefs/lfs_util.c | ||
${MIOSIX_KPATH}/filesystem/romfs/romfs.cpp | ||
${MIOSIX_KPATH}/stdlib_integration/libc_integration.cpp | ||
${MIOSIX_KPATH}/stdlib_integration/libstdcpp_integration.cpp | ||
${MIOSIX_KPATH}/e20/e20.cpp | ||
${MIOSIX_KPATH}/e20/unmember.cpp | ||
${MIOSIX_KPATH}/util/util.cpp | ||
${MIOSIX_KPATH}/util/unicode.cpp | ||
${MIOSIX_KPATH}/util/version.cpp | ||
${MIOSIX_KPATH}/util/crc16.cpp | ||
${MIOSIX_KPATH}/util/lcd44780.cpp | ||
) | ||
|
||
# Include the architecture options | ||
include(${MIOSIX_KPATH}/arch/CMakeLists.txt) | ||
|
||
# Verify that all the required variables have been defined, otherwise abort | ||
set(REQUIRED_VARIABLES | ||
MIOSIX_OPT_BOARD | ||
MIOSIX_ARCH_INC | ||
MIOSIX_BOARD_INC | ||
MIOSIX_BOARD_SETTINGS_INC | ||
MIOSIX_LINKER_SCRIPT | ||
MIOSIX_A_FLAGS | ||
MIOSIX_C_FLAGS | ||
MIOSIX_CXX_FLAGS | ||
MIOSIX_L_FLAGS | ||
MIOSIX_ARCH_SRC | ||
) | ||
foreach(VARIABLE ${REQUIRED_VARIABLES}) | ||
if(NOT DEFINED ${VARIABLE}) | ||
message(FATAL_ERROR "arch/CMakeLists.txt must define ${VARIABLE}") | ||
endif() | ||
endforeach() | ||
|
||
# The user can set a custom path for miosix_settings.h | ||
set(MIOSIX_SETTINGS_PATH ${MIOSIX_KPATH}/default CACHE PATH "Include directory for miosix_settings.h") | ||
mark_as_advanced(MIOSIX_SETTINGS_PATH) | ||
if(NOT MIOSIX_SETTINGS_PATH STREQUAL ${MIOSIX_KPATH}/default) | ||
message(NOTICE "You have set a custom path for miosix_settings.h") | ||
endif() | ||
|
||
# Define the miosix library with kernel and architecture sources | ||
add_library(miosix STATIC ${MIOSIX_KERNEL_SRC} ${MIOSIX_ARCH_SRC}) | ||
|
||
target_include_directories(miosix PUBLIC | ||
${MIOSIX_KPATH} | ||
${MIOSIX_KPATH}/arch/common | ||
${MIOSIX_ARCH_INC} | ||
${MIOSIX_BOARD_INC} | ||
${MIOSIX_BOARD_SETTINGS_INC} | ||
${MIOSIX_SETTINGS_PATH} | ||
) | ||
|
||
target_compile_options(miosix PUBLIC | ||
$<$<COMPILE_LANGUAGE:ASM>:${MIOSIX_A_FLAGS}> | ||
$<$<COMPILE_LANGUAGE:C>:${MIOSIX_C_FLAGS}> | ||
$<$<COMPILE_LANGUAGE:CXX>:${MIOSIX_CXX_FLAGS}> | ||
) | ||
|
||
# Configure program command as a propery of the miosix library | ||
set_property(TARGET miosix PROPERTY PROGRAM_CMDLINE ${PROGRAM_CMDLINE}) | ||
|
||
# Add COMPILING_MIOSIX define for private headers | ||
target_compile_definitions(miosix PRIVATE $<$<COMPILE_LANGUAGE:C,CXX>:COMPILING_MIOSIX>) | ||
|
||
# Configure linker file and options needed to link agains this library | ||
set_property(TARGET miosix PROPERTY LINK_DEPENDS ${MIOSIX_BOARD_INC}/${MIOSIX_LINKER_SCRIPT}) | ||
target_link_options(miosix INTERFACE ${MIOSIX_L_FLAGS}) | ||
|
||
# Run the kernel_global_objects.pl script on all kernel objects | ||
add_custom_command( | ||
TARGET miosix PRE_LINK | ||
COMMAND perl ${MIOSIX_KPATH}/_tools/kernel_global_objects.pl $<TARGET_OBJECTS:miosix> | ||
VERBATIM | ||
COMMAND_EXPAND_LISTS | ||
) | ||
|
||
# Optionally print the board list | ||
option(MIOSIX_PRINT_BOARD_LIST "Prints a list of the available boards" OFF) | ||
if(MIOSIX_PRINT_BOARD_LIST) | ||
message(STATUS "Available boards:") | ||
foreach(MIOSIX_OPT_BOARD ${MIOSIX_BOARDS}) | ||
message(STATUS "\t${MIOSIX_OPT_BOARD}") | ||
endforeach() | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright (C) 2024 by Skyward | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# it under the terms of the GNU General Public License as published | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# 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. | ||
# | ||
# As a special exception, if other files instantiate templates or use | ||
# macros or inline functions from this file, or you compile this file | ||
# and link it with other works to produce a work based on this file, | ||
# this file does not by itself cause the resulting work to be covered | ||
# by the GNU General Public License. However the source code for this | ||
# file must still be made available in accordance with the GNU | ||
# Public License. This exception does not invalidate any other | ||
# why a work based on this file might be covered by the GNU General | ||
# Public License. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(BlinkingLED C CXX ASM) | ||
|
||
# Set Miosix definitions and options | ||
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:MIOSIX_SKIP_SETTINGS_EDIT>) | ||
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board") | ||
|
||
add_subdirectory(../.. miosix EXCLUDE_FROM_ALL) | ||
|
||
include(LinkTarget) | ||
|
||
add_executable(blinking_led simple.cpp) | ||
miosix_link_target(blinking_led) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,22 @@ | ||
#include <cstdio> | ||
#include <unistd.h> | ||
|
||
#include "interfaces/bsp.h" | ||
#include "miosix.h" | ||
|
||
using namespace std; | ||
using namespace miosix; | ||
|
||
typedef Gpio<GPIOC_BASE,7> led; | ||
|
||
int main() | ||
{ | ||
|
||
led::mode(Mode::OUTPUT); | ||
|
||
for(;;) { | ||
led::high(); | ||
sleep(1); | ||
led::low(); | ||
sleep(1); | ||
} | ||
|
||
return 0; | ||
|
||
} | ||
while(true) | ||
{ | ||
ledOn(); | ||
printf("Led on\n"); | ||
sleep(1); | ||
|
||
ledOff(); | ||
printf("Led off\n"); | ||
sleep(1); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
# Copyright (C) 2024 by Skyward | ||
# | ||
# This program is free software; you can redistribute it and/or | ||
# it under the terms of the GNU General Public License as published | ||
# the Free Software Foundation; either version 2 of the License, or | ||
# (at your option) any later version. | ||
# | ||
# 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. | ||
# | ||
# As a special exception, if other files instantiate templates or use | ||
# macros or inline functions from this file, or you compile this file | ||
# and link it with other works to produce a work based on this file, | ||
# this file does not by itself cause the resulting work to be covered | ||
# by the GNU General Public License. However the source code for this | ||
# file must still be made available in accordance with the GNU | ||
# Public License. This exception does not invalidate any other | ||
# why a work based on this file might be covered by the GNU General | ||
# Public License. | ||
# | ||
# You should have received a copy of the GNU General Public License | ||
# along with this program; if not, see <http://www.gnu.org/licenses/> | ||
|
||
cmake_minimum_required(VERSION 3.16) | ||
|
||
project(ProcessesExamples C CXX ASM) | ||
|
||
# Set Miosix definitions and options | ||
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:PARSING_FROM_IDE>) | ||
add_compile_definitions($<$<COMPILE_LANGUAGE:C,CXX>:WITH_PROCESSES>) | ||
set(MIOSIX_OPT_BOARD stm32f429zi_stm32f4discovery CACHE STRING "Target board") | ||
set(MIOSIX_LINKER_SCRIPT stm32_2m+256k_rom_processes.ld CACHE FILEPATH "Linker script") | ||
|
||
add_subdirectory(../.. miosix EXCLUDE_FROM_ALL) | ||
add_subdirectory(../../libsyscalls libsyscalls EXCLUDE_FROM_ALL) | ||
|
||
include(LinkTarget) | ||
include(AddProcess) | ||
include(AddRomfsImage) | ||
|
||
# Kernel level program | ||
add_executable(main main.cpp) | ||
miosix_link_target(main) | ||
|
||
# Processes | ||
miosix_add_process(process1 process1.cpp) | ||
miosix_add_process(process2 process2.cpp) | ||
|
||
# RomFS image | ||
miosix_add_romfs_image( | ||
IMAGE_NAME image | ||
DIR_NAME bin | ||
KERNEL main | ||
PROCESSES process1 process2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
#include <spawn.h> | ||
#include <sys/wait.h> | ||
|
||
#include <cstdio> | ||
|
||
int main() | ||
{ | ||
pid_t pid1, pid2; | ||
|
||
// Arguments and environment variables | ||
const char *arg1[] = {"/bin/process1", nullptr}; | ||
const char *arg2[] = {"/bin/process2", nullptr}; | ||
const char *env[] = {nullptr}; | ||
|
||
// Start the processes | ||
posix_spawn(&pid1, arg1[0], NULL, NULL, (char *const *)arg1, | ||
(char *const *)env); | ||
posix_spawn(&pid2, arg2[0], NULL, NULL, (char *const *)arg2, | ||
(char *const *)env); | ||
|
||
// Wait for them to end | ||
wait(NULL); | ||
wait(NULL); | ||
|
||
printf("All processes ended\n"); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include <cstdio> | ||
#include <ctime> | ||
|
||
int main() | ||
{ | ||
printf("Hi! I'm the process #1\n"); | ||
|
||
printf("I'll count to 10\n"); | ||
const timespec sleep_time{.tv_sec = 1, .tv_nsec = 0}; | ||
for (int i = 1; i <= 10; i++) | ||
{ | ||
nanosleep(&sleep_time, NULL); | ||
printf("%d\n", i); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.