Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • avn/swd/miosix-kernel
  • emilio.corigliano/miosix-kernel
2 results
Show changes
Commits on Source (404)
Showing
with 1148 additions and 371 deletions
......@@ -13,3 +13,6 @@ main.map
# Exclude Mac OS X temporary
._*
.DS_Store
# CMake build directory
build
# Copyright (C) 2023 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/>
variables:
GIT_SUBMODULE_STRATEGY: recursive
stages:
- build
build:
stage: build
tags:
- miosix
script:
- ./mbs
# Copyright (C) 2023 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.25)
include(miosix/cmake/mbs.cmake)
project(MiosixExamples)
#-----------------------------------------------------------------------------#
# Examples #
#-----------------------------------------------------------------------------#
add_executable(asm miosix/_examples/asm/main.s)
mbs_target(asm stm32f407vg_stm32f4discovery)
add_executable(atsam4l_lcd miosix/_examples/atsam4l_lcd/main.cpp)
mbs_target(atsam4l_lcd atsam4lc2aa_generic)
add_executable(blinking_led miosix/_examples/blinking_led/simple.cpp)
mbs_target(blinking_led stm32f429zi_stm32f4discovery)
add_executable(datalogger
${KPATH}/_examples/datalogger/main.cpp
${KPATH}/_examples/datalogger/Logger.cpp
${KPATH}/_examples/datalogger/tscpp/buffer.cpp
)
target_include_directories(datalogger PUBLIC miosix/_examples/datalogger/)
mbs_target(datalogger stm32f407vg_stm32f4discovery)
add_executable(hd44780 miosix/_examples/hd44780/hd44780.cpp)
mbs_target(hd44780 stm32f407vg_stm32f4discovery)
add_executable(ir_decoder miosix/_examples/ir_decoder/ir_decoder.cpp)
mbs_target(ir_decoder stm32f407vg_stm32f4discovery)
add_executable(led_display miosix/_examples/led_display/main.cpp)
mbs_target(led_display stm32f100rb_stm32vldiscovery)
add_executable(sad_trombone
miosix/_examples/sad_trombone/main.cpp
miosix/_examples/sad_trombone/player.cpp
miosix/_examples/sad_trombone/adpcm.c
)
mbs_target(sad_trombone stm32f407vg_stm32f4discovery)
add_executable(servo-prompt miosix/_examples/servo/prompt.cpp)
mbs_target(servo-prompt stm32f407vg_stm32f4discovery)
add_executable(servo-sweep miosix/_examples/servo/sweep.cpp)
mbs_target(servo-sweep stm32f407vg_stm32f4discovery)
add_executable(streamwriter miosix/_examples/streamwriter/streamwriter.cpp)
mbs_target(streamwriter stm32f407vg_stm32f4discovery)
add_executable(termios miosix/_examples/termios/main.cpp)
mbs_target(termios stm32f407vg_stm32f4discovery)
add_executable(thread_native miosix/_examples/thread_native/native_thread_example.cpp)
mbs_target(thread_native stm32f407vg_stm32f4discovery)
add_executable(thread_pthread miosix/_examples/thread_pthread/pthread_example.cpp)
mbs_target(thread_pthread stm32f407vg_stm32f4discovery)
#-----------------------------------------------------------------------------#
# Others #
#-----------------------------------------------------------------------------#
add_executable(delay_test miosix/_tools/delay_test/delay_test.cpp)
mbs_target(delay_test stm32f407vg_stm32f4discovery)
add_executable(feedforward_profiling miosix/_tools/feedforward_profiling/test.cpp)
mbs_target(feedforward_profiling stm32f407vg_stm32f4discovery)
add_executable(fs_backend miosix/_tools/fs_backend/backend_benchmark.cpp)
mbs_target(fs_backend stm32f407vg_stm32f4discovery)
add_executable(fs_misc_testcode miosix/_tools/fs_misc_testcode/dirlist.cpp)
mbs_target(fs_misc_testcode stm32f407vg_stm32f4discovery)
# To build this entrypoint remember to define WITH_PROCESSES in miosix_settings.h
# add_executable(processes miosix/_tools/processes/main_processes.cpp)
# target_include_directories(processes PUBLIC miosix/_tools/processes/)
# add_custom_command(
# TARGET processes
# COMMAND make
# WORKING_DIRECTORY ${KPATH}/_tools/processes/process_template
# )
# mbs_target(processes stm32f407vg_stm32f4discovery)
add_executable(ram_test
miosix/_tools/ram_test/main.cpp
miosix/_tools/ram_test/sha1.cpp
)
mbs_target(ram_test stm32f407vg_stm32f4discovery)
# If you want to test the MPU remember to run build.sh in miosix/_tools/testsuite
# add_executable(testsuite miosix/_tools/testsuite/testsuite.cpp)
# mbs_target(testsuite stm32f407vg_stm32f4discovery)
# Build the testsuite for all supported boards to test compilation
set(TESTSUITE_BOARDS
lpc2138_miosix_board
# stm32f072rb_stm32f0discovery
efm32gg332f1024_wandstem
# stm32f100c8_microboard
# stm32f100c8_vaisala_rs41
# stm32f100cb_tempsensor
# stm32f100cx_generic
# stm32f100rb_stm32vldiscovery
stm32f100rc_solertegiard
# stm32f103c8_breakout
# stm32f103cb_als_mainboard_rev2
# stm32f103cx_generic
stm32f103ve_mp3v2
stm32f103ve_strive_mini
stm32f103ze_redbull_v2
stm32f103ze_stm3210e-eval
stm32f205_generic
stm32f205rc_skyward_stormtrooper
stm32f205rg_sony-newman
stm32f207ig_stm3220g-eval
stm32f207ze_als_camboard
stm32f207zg_EthBoardV2
stm32f207zg_nucleo
# stm32l151c8_als_mainboard
# atsam4lcc
stm32f303vc_stm32f3discovery
stm32f401re_nucleo
stm32f401vc_stm32f4discovery
stm32f407vg_bitsboard
stm32f407vg_stm32f4discovery
stm32f407vg_thermal_test_chip
stm32f411ce_blackpill
stm32f411re_nucleo
stm32f429zi_oledboard2
stm32f429zi_skyward_anakin
stm32f429zi_skyward_homeone
stm32f429zi_stm32f4discovery
stm32f469ni_stm32f469i-disco
stm32l4r9zi_sensortile
stm32l476rg_nucleo
stm32f746zg_nucleo
stm32f767zi_nucleo
# stm32f769ni_discovery
stm32h753xi_eval
)
foreach(OPT_BOARD ${TESTSUITE_BOARDS})
add_executable(testsuite-${OPT_BOARD} miosix/_tools/testsuite/testsuite.cpp)
mbs_target(testsuite-${OPT_BOARD} ${OPT_BOARD})
endforeach()
##
## Makefile for Miosix embedded OS
##
MAKEFILE_VERSION := 1.09
GCCMAJOR := $(shell arm-miosix-eabi-gcc --version | \
perl -e '$$_=<>;/\(GCC\) (\d+)/;print "$$1"')
MAKEFILE_VERSION := 1.10
## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
KPATH := miosix
## Path to config directory (edited by init_project_out_of_git_repo.pl)
......@@ -59,12 +57,7 @@ LFLAGS := $(LFLAGS_BASE)
DFLAGS := -MMD -MP
## libmiosix.a is among stdlibs because needs to be within start/end group
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc
ifneq ($(GCCMAJOR),4)
STDLIBS += -latomic
endif
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc -latomic
LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group $(STDLIBS) -Wl,--end-group
all: all-recursive main
......
#!/bin/bash
# Copyright (C) 2023 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/>
print_banner() {
cat <<EOF
+---------------------------------------------------------------+
| __ __ _ _ |
| | \\/ (_) ___ ___(_)_ __ |
| | |\\/| | |/ _ \\/ __| \\ \\/ / |
| | | | | | (_) \\__ \\ |> < |
| |_| |_|_|\\___/|___/_/_/\\_\\ |
| ____ _ _ _ ____ _ |
| | __ ) _ _(_) | __| | / ___| _ _ ___| |_ ___ _ __ ___ |
| | _ \\| | | | | |/ _\` | \\___ \\| | | / __| __/ _ \\ '_ \` _ \\ |
| | |_) | |_| | | | (_| | ___) | |_| \\__ \\ || __/ | | | | | |
| |____/ \\__,_|_|_|\\__,_| |____/ \\__, |___/\\__\\___|_| |_| |_| |
+----------------------------------|___/-------------------v1.0-+
EOF
}
usage() {
echo
cat <<EOF
Usage: $(basename "$0") [OPTIONS]
OPTIONS:
General Options:
-h, --help Show this help message and exit
-j JOBS, --jobs JOBS Build or lint in parallel using a specific number of jobs
-l, --list_targets List all targets available
-r, --list_boards List all boards available
Build Options:
-b TARGET, --build TARGET
Build a specific target
-f TARGET, --flash TARGET
Build and flash a specific target
-c, --clean Clean the working tree
-u, --configure Force configure and do not build
-d, --debug Enable debug
-v, --verbose Print a verbose output
EOF
}
ohai() {
printf "\n${TTY_BLUE}==>${TTY_RESET}${TTY_BOLD} %s${TTY_RESET}\n" "$@"
}
init_dirs() {
msb_base=$(cd -- $(dirname "$0") > /dev/null 2>&1 && pwd -P)
source_dir="$PWD"
build_dir="$source_dir/$BUILD_DEFAULT_DIRNAME"
toolchain_file="$msb_base/miosix/cmake/toolchain.cmake"
}
find_deps() {
ohai "Find dependencies"
command -v cmake > /dev/null 2>&1 && found_cmake=true
command -v arm-miosix-eabi-g++ > /dev/null 2>&1 && found_miosixgpp=true
command -v ccache > /dev/null 2>&1 && found_ccache=true
command -v ninja > /dev/null 2>&1 && found_ninja=true
command -v st-flash > /dev/null 2>&1 && found_stflash=true
printf "Found CMake: "; [ "$found_cmake" = true ] && echo "yes" || echo "no"
printf "Found arm-miosix-eabi-g++: "; [ "$found_miosixgpp" = true ] && echo "yes" || echo "no"
printf "Found Ccache: "; [ "$found_ccache" = true ] && echo "yes" || echo "no"
printf "Found Ninja: "; [ "$found_ninja" = true ] && echo "yes" || echo "no"
printf "Found st-flash: "; [ "$found_stflash" = true ] && echo "yes" || echo "no"
[ "$found_cmake" = true ] || { echo "Error: CMake must be installed"; return 1; }
[ "$found_miosixgpp" = true ] || { echo "Error: arm-miosix-eabi-g++ must be installed"; return 1; }
# TODO: Maybe prompt the user to download and intall miosix?
}
configure() {
declare build_dir="$1"
ohai "Configure"
[ -f "$toolchain_file" ] || { echo "Error: CMake Toolchain File for Miosix was not found"; return 1; }
# Always use colors when possible
defs+=(-DCMAKE_C_FLAGS=-fdiagnostics-color=always -DCMAKE_CXX_FLAGS=-fdiagnostics-color=always)
# Toolchain files
defs+=(-DCMAKE_TOOLCHAIN_FILE="$toolchain_file")
# Use ccache when available
[ "$found_ccache" = true ] && defs+=(-DCMAKE_C_COMPILER_LAUNCHER=ccache -DCMAKE_CXX_COMPILER_LAUNCHER=ccache)
# Debug or release build types
[ "$config_debug" = true ] && defs+=(-DCMAKE_BUILD_TYPE=Debug) || defs+=(-DCMAKE_BUILD_TYPE=Release)
# Verbose output
[ "$config_verbose" = true ] && defs+=(-DCMAKE_VERBOSE_MAKEFILE=ON)
# CMake generator
declare gen
[ "$found_ninja" = true ] && gen=-GNinja || gen=-G"Unix Makefiles"
# Configure build
cmake -B"$build_dir" "${defs[@]}" "$gen" "$source_dir" || return
# Save configuration to avoid reconfiguring each time
{ [ "$config_debug" = true ] && touch "$build_dir/$DEBUG_FILENAME"; } || rm -f "$build_dir/$DEBUG_FILENAME"
{ [ "$config_verbose" = true ] && touch "$build_dir/$VERBOSE_FILENAME"; } || rm -f "$build_dir/$VERBOSE_FILENAME"
}
check_configured() {
declare build_dir="$1"
declare to_reconfigure=false
if [ ! -d "$build_dir" ]; then
to_reconfigure=true
elif [ ! -f "$build_dir/$CMAKE_FILENAME" ]; then
rm -rf "$build_dir"
to_reconfigure=true
else
[ -f "$build_dir/$DEBUG_FILENAME" ] && found_debug=true || found_debug=false
[ -f "$build_dir/$VERBOSE_FILENAME" ] && found_verbose=true || found_verbose=false
if [ "$config_debug" != "$found_debug" ] \
|| [ "$config_verbose" != "$found_verbose" ]; then
to_reconfigure=true
fi
fi
if [ "$to_reconfigure" = true ]; then
configure "$build_dir"
fi
}
build() {
declare build_dir="$1"
declare target="$2"
check_configured "$build_dir" || return
ohai "Build"
get_build_opts
cmake --build "$build_dir" "${opts[@]}" --target "$target"
}
build_all() {
build "$build_dir" all
}
clean() {
ohai "Cleaning build files"
if [ -f "$build_dir/$CMAKE_FILENAME" ]; then
get_build_opts
cmake --build "$build_dir" "${opts[@]}" --target clean
fi
echo "Removing build folder..."
rm -rf "$build_dir"
}
flash() {
declare target="$1"
build "$build_dir" "$target" || return
# This variable will be evaluated in the command
declare binary=$build_dir/$target.bin
declare hex=$build_dir/$target.hex
# Check if the target has a custom build command
declare custom_command_file=$build_dir/flash-$target.txt
if [[ -f "$custom_command_file" ]]; then
ohai "Flash via custom command"
eval $(cat $custom_command_file)
elif [ "$found_stflash" = true ]; then
ohai "Flash via st-flash"
st-flash --reset write "$build_dir/$target.bin" 0x8000000
else
echo "Error: No flashing software found!"
return 1
fi
}
list_targets() {
check_configured "$build_dir" || return
ohai "List targets"
echo "[1/1] All MBS targets available:"
cmake --build "$build_dir" --target help \
| grep -o '^[^/]*\.bin' | cut -f 1 -d '.'
}
list_boards() {
check_configured "$build_dir" || return
ohai "List boards"
cmake --build "$build_dir" --target help-boards
}
set_debug() {
config_debug=true
}
set_verbose() {
config_verbose=true
}
set_jobs() {
jobs="$1"
}
get_build_opts() {
declare -a opts
[ -n "$jobs" ] && opts=("-j $jobs")
}
CMAKE_FILENAME="CMakeCache.txt"
DEBUG_FILENAME=".sbs_debug"
VERBOSE_FILENAME=".sbs_verbose"
BUILD_DEFAULT_DIRNAME="build"
TTY_BLUE="\033[34m"
TTY_BOLD="\033[1m"
TTY_RESET="\033[0m"
msb_base=
source_dir=
build_dir=
toolchain_file=
found_cmake=false
found_miosixgpp=false
found_ccache=false
found_ninja=false
found_stflash=false
config_debug=false
config_verbose=false
jobs=
print_banner
init_dirs
for arg in "$@"; do
shift
case "$arg" in
--help) set -- "$@" "-h";;
--jobs) set -- "$@" "-j";;
--list_targets) set -- "$@" "-l";;
--list_boards) set -- "$@" "-r";;
--build) set -- "$@" "-b";;
--flash) set -- "$@" "-f";;
--clean) set -- "$@" "-c";;
--configure) set -- "$@" "-u";;
--debug) set -- "$@" "-d";;
--verbose) set -- "$@" "-v";;
*) set -- "$@" "$arg"
esac
done
while getopts b:cdef:hj:lnrt:uv opt; do
case "$opt" in
h) usage; exit 0;;
j) set_jobs "$OPTARG";;
l) find_deps && list_targets; exit;;
r) find_deps && list_boards; exit;;
b) find_deps && build "$build_dir" "$OPTARG"; exit;;
f) find_deps && flash "$OPTARG"; exit;;
c) find_deps && clean; exit;;
u) find_deps && configure "$build_dir"; exit;;
d) set_debug;;
v) set_verbose;;
?) usage; exit 2;;
esac
done
shift $((OPTIND - 1))
find_deps && build_all
......@@ -2,9 +2,7 @@
## Makefile for Miosix embedded OS
## This makefile builds the whole kernel
##
MAKEFILE_VERSION := 1.09
GCCMAJOR := $(shell arm-miosix-eabi-gcc --version | \
perl -e '$$_=<>;/\(GCC\) (\d+)/;print "$$1"')
MAKEFILE_VERSION := 1.10
## KPATH and CONFPATH are forwarded by the parent Makefile
include $(CONFPATH)/config/Makefile.inc
......@@ -21,7 +19,9 @@ kernel/elf_program.cpp \
kernel/process.cpp \
kernel/process_pool.cpp \
kernel/timeconversion.cpp \
kernel/intrusive.cpp \
kernel/SystemMap.cpp \
kernel/cpu_time_counter.cpp \
kernel/scheduler/priority/priority_scheduler.cpp \
kernel/scheduler/control/control_scheduler.cpp \
kernel/scheduler/edf/edf_scheduler.cpp \
......
......@@ -2024,6 +2024,7 @@ INCLUDE_FILE_PATTERNS =
# This tag requires that the tag ENABLE_PREPROCESSING is set to YES.
PREDEFINED = WITH_FILESYSTEM \
WITH_CPU_TIME_COUNTER \
_MIOSIX \
MIOSIX_LITTLE_ENDIAN \
__DOXYGEN__
......
......@@ -76,7 +76,7 @@ interrupts @ 0x6800000, or Miosix will fail at the first interrupt.
Then run openocd in a shell:
sudo openocd -f miosix/arch/cortexM3_stm32/stm32f103ze_stm3210e-eval/stm32f10x_eval.cfg
sudo openocd -f miosix/arch/cortexM3_stm32f1/stm32f103ze_stm3210e-eval/stm32f10x_eval.cfg
and in another shell type:
......
##
## Makefile for Miosix embedded OS
##
MAKEFILE_VERSION := 1.09
GCCMAJOR := $(shell arm-miosix-eabi-gcc --version | \
perl -e '$$_=<>;/\(GCC\) (\d+)/;print "$$1"')
MAKEFILE_VERSION := 1.10
## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
KPATH := miosix
## Path to config directory (edited by init_project_out_of_git_repo.pl)
......@@ -59,12 +57,7 @@ LFLAGS := $(LFLAGS_BASE)
DFLAGS := -MMD -MP
## libmiosix.a is among stdlibs because needs to be within start/end group
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc
ifneq ($(GCCMAJOR),4)
STDLIBS += -latomic
endif
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc -latomic
LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group $(STDLIBS) -Wl,--end-group
all: all-recursive main
......
/***************************************************************************
* Copyright (C) 2019 by Marsella Daniele *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* 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 General *
* Public License. This exception does not invalidate any other reasons *
* 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/> *
***************************************************************************/
#include <cstdio>
#include "miosix.h"
using namespace std;
using namespace miosix;
int main()
{
long long int timeBefore, timeAfter;
using sleepLed = Gpio<GPIOD_BASE, 13>; // orange
using deepSleepLed = Gpio<GPIOD_BASE, 15>; // blue
sleepLed::mode(Mode::OUTPUT);
deepSleepLed::mode(Mode::OUTPUT);
int i=1;
for(;;)
{
printf("Going into deep sleep\n");
fflush(stdout);
delayMs(500);
deepSleepLed::high();
timeBefore = getTime();
Thread::sleep(i * 1000);
timeAfter = getTime();
deepSleepLed::low();
printf("Elapsed time: %lld \n", timeAfter - timeBefore);
{
DeepSleepLock dl;
printf("Going into normal sleep\n");
fflush(stdout);
delayMs(500);
sleepLed::high();
timeBefore = getTime();
Thread::sleep(i * 1000);
timeAfter = getTime();
sleepLed::low();
printf("Elapsed time: %lld \n", timeAfter - timeBefore);
}
i++;
}
}
##
## Makefile for Miosix embedded OS
##
MAKEFILE_VERSION := 1.09
GCCMAJOR := $(shell arm-miosix-eabi-gcc --version | \
perl -e '$$_=<>;/\(GCC\) (\d+)/;print "$$1"')
MAKEFILE_VERSION := 1.10
## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
KPATH := miosix
## Path to config directory (edited by init_project_out_of_git_repo.pl)
......@@ -59,12 +57,7 @@ LFLAGS := $(LFLAGS_BASE)
DFLAGS := -MMD -MP
## libmiosix.a is among stdlibs because needs to be within start/end group
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc
ifneq ($(GCCMAJOR),4)
STDLIBS += -latomic
endif
STDLIBS := -lmiosix -lstdc++ -lc -lm -lgcc -latomic
LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group $(STDLIBS) -Wl,--end-group
all: all-recursive main
......
......@@ -28,7 +28,7 @@
#include <algorithm>
#include <stdexcept>
#include <cstring>
#include "miosix/kernel/scheduler/scheduler.h"
#include <kernel/scheduler/scheduler.h>
#include "util/software_i2c.h"
#include "adpcm.h"
#include "player.h"
......
......@@ -33,11 +33,11 @@ int main()
thread=Thread::create(threadfunc,2048,1,(void*)strlen(str),Thread::JOINABLE);
{
Lock<Mutex> lock(mutex);
for(int i=0;i<strlen(str);i++)
for(int i=0;i<(int)strlen(str);i++)
{
c=str[i];
cond.signal();
if(i<strlen(str)-1) ack.wait(lock);
if(i<(int)strlen(str)-1) ack.wait(lock);
}
}
thread->join();
......
......@@ -24,6 +24,7 @@ void *threadfunc(void *argv)
c=0;
}
pthread_mutex_unlock(&mutex);
return nullptr;
}
int main()
......@@ -33,11 +34,11 @@ int main()
pthread_t thread;
pthread_create(&thread,NULL,threadfunc,(void*)strlen(str));
pthread_mutex_lock(&mutex);
for(int i=0;i<strlen(str);i++)
for(int i=0;i<(int)strlen(str);i++)
{
c=str[i];
pthread_cond_signal(&cond);
if(i<strlen(str)-1) pthread_cond_wait(&ack,&mutex);
if(i<(int)strlen(str)-1) pthread_cond_wait(&ack,&mutex);
}
pthread_mutex_unlock(&mutex);
pthread_join(thread,NULL);
......
build
......@@ -16,6 +16,7 @@ endif()
## Link libraries
set(BOOST_LIBS system)
find_package(Boost COMPONENTS ${BOOST_LIBS} REQUIRED)
target_include_directories(pc_loader PRIVATE ${Boost_INCLUDE_DIRS})
target_link_libraries(pc_loader ${Boost_LIBRARIES})
find_package(Threads REQUIRED)
target_link_libraries(pc_loader ${CMAKE_THREAD_LIBS_INIT})
Update sys/lock.h make pthread_mutex_t compatible with future decisions to
replace the custom list with IntrusiveList.
Update _pthreadtypes.h removing the forward declaration of WaitingList and
change pthread_cond_t to be two opaque pointers, comment that it should have
a memory layout compatible with IntrusiveList.
In libstdc++ header condition_variable the __wait_until_impl checks for timeout
in this way:
__gthread_cond_timedwait(&_M_cond, __lock.mutex()->native_handle(), &__ts);
return (__clock_t::now() < __atime ? cv_status::no_timeout : cv_status::timeout);
use the return value of pthread_cond_timedwait instead to optimize code
In libstdc++ header condition_variable condition_variable::wait_for calls both clock_gettime(CLOCK_REALTIME... and clock_gettime(CLOCK_MONOTONIC...
This is not needed as pthread_cond_timedwait in Miosix refuses to follow the
(broken) standard on purpose and accepts the timeout directly in terms of
CLOCK_MONOTONIC.
defiitions are in time.h, CLOCK_REALTIME is 1, wile CLOCK_MONOTONIC is 4
Some test code:
#include <cstdio>
#include <cstring>
#include <chrono>
#include <thread>
#include <mutex>
#include <condition_variable>
#include "miosix.h"
using namespace std;
using namespace std::chrono;
using namespace miosix;
mutex t25_m1;
condition_variable t25_c1;
void fail(const char *s) { iprintf("Fail %s\n",s); for(;;) ; }
int main()
{
{
unique_lock<mutex> l(t25_m1);
auto a=chrono::steady_clock::now().time_since_epoch().count();
if(t25_c1.wait_for(l,10ms)!=cv_status::timeout) fail("timedwait (1)");
auto b=chrono::steady_clock::now().time_since_epoch().count();
//iprintf("delta=%lld\n",b-a-10000000);
if(llabs(b-a-10000000)>200000) fail("timedwait (2)");
}
{
unique_lock<mutex> l(t25_m1);
auto start=chrono::steady_clock::now();
auto a=start.time_since_epoch().count();
if(t25_c1.wait_until(l,start+10ms)!=cv_status::timeout) fail("timedwait (3)");
auto b=chrono::steady_clock::now().time_since_epoch().count();
//iprintf("delta=%lld\n",b-a-10000000);
if(llabs(b-a-10000000)>200000) fail("timedwait (4)");
}
{
thread t([]{
this_thread::sleep_for(30ms);
t25_c1.notify_one();
});
auto a=chrono::steady_clock::now().time_since_epoch().count();
unique_lock<mutex> l(t25_m1);
if(t25_c1.wait_for(l,100ms)!=cv_status::no_timeout) fail("timedwait (5)");
auto b=chrono::steady_clock::now().time_since_epoch().count();
//iprintf("delta=%lld\n",b-a-30000000);
if(llabs(b-a-30000000)>500000) fail("timedwait (6)");
t.join();
}
for(;;) ;
}
......@@ -22,7 +22,7 @@ void printStat(struct dirent *de, struct stat *st)
close(fd);
}
} else st2.st_ino=st->st_ino; //Can't fstat() an fd to a directory
printf("%13s iD=%d iS=%d iF=%d dev=%d mode=%#o size=%d\n",
printf("%13s iD=%ld iS=%ld iF=%ld dev=%d mode=%#lo size=%lld\n",
de->d_name,de->d_ino,st->st_ino,st2.st_ino,st->st_dev,st->st_mode,st->st_size);
}
......@@ -40,7 +40,7 @@ int main()
if(d==NULL) perror("opendir");
else {
struct dirent *de;
while(de=readdir(d))
while((de=readdir(d)))
{
struct stat st;
if(stat(de->d_name,&st)<0) perror(de->d_name);
......
......@@ -31,8 +31,10 @@ bool shaCmp(unsigned int a[5], unsigned int b[5])
{
if(memcmp(a,b,20)==0) return false;
iprintf("Mismatch\n");
for(int i=0;i<5;i++) iprintf("%04x",a[i]); iprintf("\n");
for(int i=0;i<5;i++) iprintf("%04x",b[i]); iprintf("\n");
for(int i=0;i<5;i++) iprintf("%04x",a[i]);
iprintf("\n");
for(int i=0;i<5;i++) iprintf("%04x",b[i]);
iprintf("\n");
return true;
}
......
This diff is collapsed.