From 04377cc2704eb7e2fae36fffa5e67063cc40b4c0 Mon Sep 17 00:00:00 2001 From: Daniel Agar Date: Wed, 12 Aug 2020 14:32:34 -0400 Subject: [PATCH] PX4 branch remove redundant confusing libuavcan_drivers --- .gitmodules | 3 - CMakeLists.txt | 14 - libuavcan_drivers/kinetis | 1 - libuavcan_drivers/linux/CMakeLists.txt | 99 -- libuavcan_drivers/linux/apps/debug.hpp | 14 - libuavcan_drivers/linux/apps/test_clock.cpp | 70 - .../apps/test_dynamic_node_id_client.cpp | 121 -- .../linux/apps/test_file_server.cpp | 149 -- .../linux/apps/test_multithreading.cpp | 554 -------- libuavcan_drivers/linux/apps/test_node.cpp | 120 -- libuavcan_drivers/linux/apps/test_posix.cpp | 73 - libuavcan_drivers/linux/apps/test_socket.cpp | 364 ----- .../linux/apps/test_system_utils.cpp | 39 - .../linux/apps/test_time_sync.cpp | 102 -- .../apps/uavcan_dynamic_node_id_server.cpp | 666 --------- .../linux/apps/uavcan_monitor.cpp | 183 --- .../linux/apps/uavcan_nodetool.cpp | 300 ---- libuavcan_drivers/linux/cppcheck.sh | 11 - .../linux/include/uavcan_linux/clock.hpp | 196 --- .../linux/include/uavcan_linux/exception.hpp | 69 - .../linux/include/uavcan_linux/helpers.hpp | 473 ------- .../linux/include/uavcan_linux/socketcan.hpp | 804 ----------- .../include/uavcan_linux/system_utils.hpp | 177 --- .../include/uavcan_linux/uavcan_linux.hpp | 12 - .../linux/scripts/uavcan_add_slcan | 173 --- .../linux/scripts/uavcan_add_vcan | 36 - libuavcan_drivers/lpc11c24/driver/include.mk | 9 - .../driver/include/uavcan_lpc11c24/can.hpp | 93 -- .../driver/include/uavcan_lpc11c24/clock.hpp | 65 - .../uavcan_lpc11c24/uavcan_lpc11c24.hpp | 9 - .../lpc11c24/driver/src/c_can.hpp | 191 --- libuavcan_drivers/lpc11c24/driver/src/can.cpp | 649 --------- .../lpc11c24/driver/src/clock.cpp | 190 --- .../lpc11c24/driver/src/internal.hpp | 49 - .../lpc11c24/test_olimex_lpc_p11c24/Makefile | 123 -- .../test_olimex_lpc_p11c24/blackmagic.gdbinit | 11 - .../blackmagic_flash.sh | 23 - .../test_olimex_lpc_p11c24/lpc11c24.ld | 104 -- .../lpc_chip_11cxx_lib/inc/adc_11xx.h | 271 ---- .../lpc_chip_11cxx_lib/inc/ccand_11xx.h | 170 --- .../lpc_chip_11cxx_lib/inc/chip.h | 309 ----- .../lpc_chip_11cxx_lib/inc/clock_11xx.h | 547 -------- .../lpc_chip_11cxx_lib/inc/cmsis.h | 64 - .../lpc_chip_11cxx_lib/inc/cmsis_11cxx.h | 152 -- .../lpc_chip_11cxx_lib/inc/core_cm0.h | 667 --------- .../lpc_chip_11cxx_lib/inc/core_cmFunc.h | 616 -------- .../lpc_chip_11cxx_lib/inc/core_cmInstr.h | 618 --------- .../lpc_chip_11cxx_lib/inc/error.h | 134 -- .../lpc_chip_11cxx_lib/inc/fmc_11xx.h | 101 -- .../lpc_chip_11cxx_lib/inc/gpio_11xx_2.h | 642 --------- .../lpc_chip_11cxx_lib/inc/gpiogroup_11xx.h | 212 --- .../lpc_chip_11cxx_lib/inc/i2c_11xx.h | 543 -------- .../lpc_chip_11cxx_lib/inc/iocon_11xx.h | 288 ---- .../lpc_chip_11cxx_lib/inc/lpc_types.h | 216 --- .../lpc_chip_11cxx_lib/inc/pinint_11xx.h | 257 ---- .../lpc_chip_11cxx_lib/inc/pmu_11xx.h | 201 --- .../lpc_chip_11cxx_lib/inc/ring_buffer.h | 188 --- .../lpc_chip_11cxx_lib/inc/romapi_11xx.h | 78 -- .../lpc_chip_11cxx_lib/inc/ssp_11xx.h | 571 -------- .../lpc_chip_11cxx_lib/inc/sys_config.h | 33 - .../lpc_chip_11cxx_lib/inc/sysctl_11xx.h | 687 --------- .../lpc_chip_11cxx_lib/inc/timer_11xx.h | 446 ------ .../lpc_chip_11cxx_lib/inc/uart_11xx.h | 787 ----------- .../lpc_chip_11cxx_lib/inc/wwdt_11xx.h | 266 ---- .../lpc_chip_11cxx_lib/src/clock_11xx.c | 285 ---- .../lpc_chip_11cxx_lib/src/uart_11xx.c | 289 ---- .../lpc_chip_11cxx_lib/src/wwdt_11xx.c | 86 -- .../test_olimex_lpc_p11c24/src/main.cpp | 277 ---- .../test_olimex_lpc_p11c24/src/sys/board.cpp | 195 --- .../test_olimex_lpc_p11c24/src/sys/board.hpp | 32 - .../test_olimex_lpc_p11c24/src/sys/crt0.c | 223 --- .../src/sys/libstubs.cpp | 148 -- libuavcan_drivers/stm32/README.md | 11 - libuavcan_drivers/stm32/driver/CMakeLists.txt | 17 - libuavcan_drivers/stm32/driver/include.mk | 9 - .../include/uavcan_stm32/build_config.hpp | 40 - .../driver/include/uavcan_stm32/bxcan.hpp | 289 ---- .../stm32/driver/include/uavcan_stm32/can.hpp | 382 ----- .../driver/include/uavcan_stm32/clock.hpp | 121 -- .../driver/include/uavcan_stm32/thread.hpp | 239 ---- .../include/uavcan_stm32/uavcan_stm32.hpp | 11 - .../stm32/driver/src/internal.hpp | 159 --- .../stm32/driver/src/uc_stm32_can.cpp | 1235 ----------------- .../stm32/driver/src/uc_stm32_clock.cpp | 496 ------- .../stm32/driver/src/uc_stm32_thread.cpp | 287 ---- 85 files changed, 20234 deletions(-) delete mode 160000 libuavcan_drivers/kinetis delete mode 100644 libuavcan_drivers/linux/CMakeLists.txt delete mode 100644 libuavcan_drivers/linux/apps/debug.hpp delete mode 100644 libuavcan_drivers/linux/apps/test_clock.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_dynamic_node_id_client.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_file_server.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_multithreading.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_node.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_posix.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_socket.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_system_utils.cpp delete mode 100644 libuavcan_drivers/linux/apps/test_time_sync.cpp delete mode 100644 libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp delete mode 100644 libuavcan_drivers/linux/apps/uavcan_monitor.cpp delete mode 100644 libuavcan_drivers/linux/apps/uavcan_nodetool.cpp delete mode 100755 libuavcan_drivers/linux/cppcheck.sh delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/clock.hpp delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/exception.hpp delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/socketcan.hpp delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/system_utils.hpp delete mode 100644 libuavcan_drivers/linux/include/uavcan_linux/uavcan_linux.hpp delete mode 100755 libuavcan_drivers/linux/scripts/uavcan_add_slcan delete mode 100755 libuavcan_drivers/linux/scripts/uavcan_add_vcan delete mode 100644 libuavcan_drivers/lpc11c24/driver/include.mk delete mode 100644 libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/clock.hpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/uavcan_lpc11c24.hpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/src/c_can.hpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/src/can.cpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/src/clock.cpp delete mode 100644 libuavcan_drivers/lpc11c24/driver/src/internal.hpp delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic.gdbinit delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic_flash.sh delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc11c24.ld delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/adc_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ccand_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/chip.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/clock_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis_11cxx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cm0.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmFunc.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmInstr.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/error.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/fmc_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpio_11xx_2.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpiogroup_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/i2c_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/iocon_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/lpc_types.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pinint_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pmu_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ring_buffer.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/romapi_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ssp_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sys_config.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sysctl_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/timer_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/uart_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/wwdt_11xx.h delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/clock_11xx.c delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/uart_11xx.c delete mode 100755 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/crt0.c delete mode 100644 libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/libstubs.cpp delete mode 100644 libuavcan_drivers/stm32/README.md delete mode 100644 libuavcan_drivers/stm32/driver/CMakeLists.txt delete mode 100644 libuavcan_drivers/stm32/driver/include.mk delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/bxcan.hpp delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/clock.hpp delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp delete mode 100644 libuavcan_drivers/stm32/driver/include/uavcan_stm32/uavcan_stm32.hpp delete mode 100644 libuavcan_drivers/stm32/driver/src/internal.hpp delete mode 100644 libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp delete mode 100644 libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp delete mode 100644 libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp diff --git a/.gitmodules b/.gitmodules index 6bf0c6b3bd..9c772f2087 100644 --- a/.gitmodules +++ b/.gitmodules @@ -5,6 +5,3 @@ [submodule "libuavcan/dsdl_compiler/pyuavcan"] path = libuavcan/dsdl_compiler/pyuavcan url = https://github.com/UAVCAN/pyuavcan -[submodule "libuavcan_drivers/kinetis"] - path = libuavcan_drivers/kinetis - url = https://github.com/UAVCAN/libuavcan_kinetis.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 54655f2af1..3880b483b5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -110,18 +110,4 @@ endif() # library add_subdirectory(libuavcan) -# drivers -if (${UAVCAN_PLATFORM} STREQUAL "linux") - message(STATUS "Adding UAVCAN Linux platform driver") - add_subdirectory(libuavcan_drivers/posix) - add_subdirectory(libuavcan_drivers/linux) -elseif(${UAVCAN_PLATFORM} STREQUAL "stm32") - message(STATUS "Adding UAVCAN STM32 platform driver") - add_subdirectory(libuavcan_drivers/posix) - add_subdirectory(libuavcan_drivers/stm32/driver) -elseif(${UAVCAN_PLATFORM} STREQUAL "kinetis") - message(STATUS "Adding UAVCAN Kinetis platform driver") - add_subdirectory(libuavcan_drivers/posix) - add_subdirectory(libuavcan_drivers/kinetis/driver) -endif() # vim: set et ft=cmake fenc=utf-8 ff=unix sts=4 sw=4 ts=4 : diff --git a/libuavcan_drivers/kinetis b/libuavcan_drivers/kinetis deleted file mode 160000 index c11352b344..0000000000 --- a/libuavcan_drivers/kinetis +++ /dev/null @@ -1 +0,0 @@ -Subproject commit c11352b344a2e057cd26531c9a40f4fa6d1b830f diff --git a/libuavcan_drivers/linux/CMakeLists.txt b/libuavcan_drivers/linux/CMakeLists.txt deleted file mode 100644 index f96b41de3d..0000000000 --- a/libuavcan_drivers/linux/CMakeLists.txt +++ /dev/null @@ -1,99 +0,0 @@ -# -# Copyright (C) 2014 Pavel Kirienko -# - -cmake_minimum_required(VERSION 2.8) - -project(libuavcan_linux) - -# -# Library (header only) -# -install(DIRECTORY include/uavcan_linux DESTINATION include) - -# -# Scripts -# -install(DIRECTORY scripts/ - USE_SOURCE_PERMISSIONS - DESTINATION bin) - -# -# System dependecies -# -find_package(Threads REQUIRED) - -# -# Finding libuavcan - it will be a target if we're running from the top-level CMakeLists.txt, -# otherwise try to find it in the system directories. -# -if (TARGET uavcan) - message(STATUS "Using uavcan target; source dir: ${libuavcan_SOURCE_DIR}") - set(UAVCAN_LIB uavcan) - include_directories(${libuavcan_SOURCE_DIR}/include - ${libuavcan_SOURCE_DIR}/include/dsdlc_generated) - message(STATUS "POSIX source dir: ${libuavcan_posix_SOURCE_DIR}") - include_directories(${libuavcan_posix_SOURCE_DIR}/include) -else () - message(STATUS "Using installed uavcan library") - find_library(UAVCAN_LIB uavcan REQUIRED) -endif () - -# -# Applications - tests, tools. -# -include_directories(include) -set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic -std=c++11") # GCC or Clang - -if(CMAKE_BUILD_TYPE STREQUAL "Debug") - add_definitions(-DUAVCAN_DEBUG=1) -endif() - -# -# Tests -# These aren't installed, an average library user should not care about them. -# -add_executable(test_clock apps/test_clock.cpp) -target_link_libraries(test_clock ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_socket apps/test_socket.cpp) -target_link_libraries(test_socket ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_node apps/test_node.cpp) -target_link_libraries(test_node ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_time_sync apps/test_time_sync.cpp) -target_link_libraries(test_time_sync ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_system_utils apps/test_system_utils.cpp) -target_link_libraries(test_system_utils ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_posix apps/test_posix.cpp) -target_link_libraries(test_posix ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_dynamic_node_id_client apps/test_dynamic_node_id_client.cpp) -target_link_libraries(test_dynamic_node_id_client ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_file_server apps/test_file_server.cpp) -target_link_libraries(test_file_server ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(test_multithreading apps/test_multithreading.cpp) -target_link_libraries(test_multithreading ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -# -# Tools -# -add_executable(uavcan_monitor apps/uavcan_monitor.cpp) -target_link_libraries(uavcan_monitor ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(uavcan_nodetool apps/uavcan_nodetool.cpp) -target_link_libraries(uavcan_nodetool ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -add_executable(uavcan_dynamic_node_id_server apps/uavcan_dynamic_node_id_server.cpp) -target_link_libraries(uavcan_dynamic_node_id_server ${UAVCAN_LIB} rt ${CMAKE_THREAD_LIBS_INIT}) - -install(TARGETS uavcan_monitor - uavcan_nodetool - uavcan_dynamic_node_id_server - RUNTIME DESTINATION bin) - \ No newline at end of file diff --git a/libuavcan_drivers/linux/apps/debug.hpp b/libuavcan_drivers/linux/apps/debug.hpp deleted file mode 100644 index 77ee8bf4b9..0000000000 --- a/libuavcan_drivers/linux/apps/debug.hpp +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -#ifndef STRINGIZE -# define STRINGIZE2(x) #x -# define STRINGIZE(x) STRINGIZE2(x) -#endif -#define ENFORCE(x) if (!(x)) { throw std::runtime_error(__FILE__ ":" STRINGIZE(__LINE__) ": " #x); } - diff --git a/libuavcan_drivers/linux/apps/test_clock.cpp b/libuavcan_drivers/linux/apps/test_clock.cpp deleted file mode 100644 index 8cef70cd16..0000000000 --- a/libuavcan_drivers/linux/apps/test_clock.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include - -static std::string systime2str(const std::chrono::system_clock::time_point& tp) -{ - const auto tt = std::chrono::system_clock::to_time_t(tp); - return std::ctime(&tt); -} - -int main() -{ - uavcan_linux::SystemClock clock; - - /* - * Auto-detected clock adjustment mode - */ - std::cout << "Clock adjustment mode: "; - switch (clock.getAdjustmentMode()) - { - case uavcan_linux::ClockAdjustmentMode::SystemWide: - { - std::cout << "SystemWide"; - break; - } - case uavcan_linux::ClockAdjustmentMode::PerDriverPrivate: - { - std::cout << "PerDriverPrivate"; - break; - } - default: - { - std::abort(); - break; - } - } - std::cout << std::endl; - - /* - * Test adjustment - */ - double sec = 0; - std::cout << "Enter system time adjustment in seconds (fractions allowed): " << std::endl; - std::cin >> sec; - - const auto before = std::chrono::system_clock::now(); - try - { - clock.adjustUtc(uavcan::UtcDuration::fromUSec(sec * 1e6)); - } - catch (const uavcan_linux::Exception& ex) - { - std::cout << ex.what() << std::endl; - std::cout << strerror(ex.getErrno()) << std::endl; - return 1; - } - const auto after = std::chrono::system_clock::now(); - - std::cout << "Time before: " << systime2str(before) << "\n" - << "Time after: " << systime2str(after) << "\n" - << "Millisecond diff (after - before): " - << std::chrono::duration_cast(after - before).count() << std::endl; - - return 0; -} diff --git a/libuavcan_drivers/linux/apps/test_dynamic_node_id_client.cpp b/libuavcan_drivers/linux/apps/test_dynamic_node_id_client.cpp deleted file mode 100644 index c5ef2e9b73..0000000000 --- a/libuavcan_drivers/linux/apps/test_dynamic_node_id_client.cpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#include -#include "debug.hpp" -#include -#include - -namespace -{ - -uavcan_linux::NodePtr initNodeWithDynamicID(const std::vector& ifaces, - const std::uint8_t instance_id, - const uavcan::NodeID preferred_node_id, - const std::string& name) -{ - /* - * Initializing the node object - */ - auto node = uavcan_linux::makeNode(ifaces); - - node->setName(name.c_str()); - node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - - { - const auto app_id = uavcan_linux::makeApplicationID(uavcan_linux::MachineIDReader().read(), name, instance_id); - - uavcan::protocol::HardwareVersion hwver; - std::copy(app_id.begin(), app_id.end(), hwver.unique_id.begin()); - std::cout << hwver << std::endl; - - node->setHardwareVersion(hwver); - } - - /* - * Starting the node - */ - const int start_res = node->start(); - ENFORCE(0 == start_res); - - /* - * Running the dynamic node ID client until it's done - */ - uavcan::DynamicNodeIDClient client(*node); - - ENFORCE(0 <= client.start(node->getNodeStatusProvider().getHardwareVersion().unique_id, preferred_node_id)); - - std::cout << "Waiting for dynamic node ID allocation..." << std::endl; - - while (!client.isAllocationComplete()) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(100)); - if (res < 0) - { - std::cerr << "Spin error: " << res << std::endl; - } - } - - std::cout << "Node ID " << int(client.getAllocatedNodeID().get()) - << " allocated by " << int(client.getAllocatorNodeID().get()) << std::endl; - - /* - * Finishing the node initialization - */ - node->setNodeID(client.getAllocatedNodeID()); - - node->setModeOperational(); - - return node; -} - -void runForever(const uavcan_linux::NodePtr& node) -{ - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(100)); - if (res < 0) - { - std::cerr << "Spin error: " << res << std::endl; - } - } -} - -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 3) - { - std::cerr << "Usage:\n\t" - << argv[0] << " [can-iface-name-N...]\n" - << "Where is used to augment the unique node ID and also indicates\n" - << "the preferred node ID value. Valid range is [0, 127]." - << std::endl; - return 1; - } - - const int instance_id = std::stoi(argv[1]); - if (instance_id < 0 || instance_id > 127) - { - std::cerr << "Invalid instance ID: " << instance_id << std::endl; - std::exit(1); - } - - uavcan_linux::NodePtr node = initNodeWithDynamicID(std::vector(argv + 2, argv + argc), - std::uint8_t(instance_id), - std::uint8_t(instance_id), - "org.uavcan.linux_test_dynamic_node_id_client"); - runForever(node); - - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_file_server.cpp b/libuavcan_drivers/linux/apps/test_file_server.cpp deleted file mode 100644 index 2f38dc12be..0000000000 --- a/libuavcan_drivers/linux/apps/test_file_server.cpp +++ /dev/null @@ -1,149 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include -#include "debug.hpp" -// UAVCAN -#include -// UAVCAN Linux drivers -#include -// UAVCAN POSIX drivers -#include -#include // Compilability test - -namespace -{ - -uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, const std::string& name) -{ - auto node = uavcan_linux::makeNode(ifaces); - - node->setNodeID(nid); - node->setName(name.c_str()); - node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - - { - const auto app_id = uavcan_linux::makeApplicationID(uavcan_linux::MachineIDReader().read(), name, nid.get()); - - uavcan::protocol::HardwareVersion hwver; - std::copy(app_id.begin(), app_id.end(), hwver.unique_id.begin()); - std::cout << hwver << std::endl; - - node->setHardwareVersion(hwver); - } - - const int start_res = node->start(); - ENFORCE(0 == start_res); - - node->setModeOperational(); - - return node; -} - -void runForever(const uavcan_linux::NodePtr& node) -{ - uavcan_posix::BasicFileServerBackend backend(*node); - - uavcan::FileServer server(*node, backend); - - const int server_init_res = server.start(); - if (server_init_res < 0) - { - throw std::runtime_error("Failed to start the server; error " + std::to_string(server_init_res)); - } - - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(100)); - if (res < 0) - { - std::cerr << "Spin error: " << res << std::endl; - } - } -} - -struct Options -{ - uavcan::NodeID node_id; - std::vector ifaces; -}; - -Options parseOptions(int argc, const char** argv) -{ - const char* const executable_name = *argv++; - argc--; - - const auto enforce = [executable_name](bool condition, const char* error_text) { - if (!condition) - { - std::cerr << error_text << "\n" - << "Usage:\n\t" - << executable_name - << " [can-iface-name-N...]" - << std::endl; - std::exit(1); - } - }; - - enforce(argc >= 2, "Not enough arguments"); - - /* - * Node ID is always at the first position - */ - argc--; - const int node_id = std::stoi(*argv++); - enforce(node_id >= 1 && node_id <= 127, "Invalid node ID"); - - Options out; - out.node_id = uavcan::NodeID(std::uint8_t(node_id)); - - while (argc --> 0) - { - const std::string token(*argv++); - - if (token[0] != '-') - { - out.ifaces.push_back(token); - } - else - { - enforce(false, "Unexpected argument"); - } - } - - return out; -} - -} - -int main(int argc, const char** argv) -{ - try - { - auto options = parseOptions(argc, argv); - - std::cout << "Self node ID: " << int(options.node_id.get()) << "\n" - "Num ifaces: " << options.ifaces.size() << "\n" -#ifdef NDEBUG - "Build mode: Release" -#else - "Build mode: Debug" -#endif - << std::endl; - - auto node = initNode(options.ifaces, options.node_id, "org.uavcan.linux_test_file_server"); - runForever(node); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_multithreading.cpp b/libuavcan_drivers/linux/apps/test_multithreading.cpp deleted file mode 100644 index 30136ec3ed..0000000000 --- a/libuavcan_drivers/linux/apps/test_multithreading.cpp +++ /dev/null @@ -1,554 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#ifndef NDEBUG -# define UAVCAN_DEBUG 1 -#endif - -#include -#include -#include -#include -#include -#include -#include -#include "debug.hpp" - -/** - * Generic queue based on the linked list class defined in libuavcan. - * This class does not use heap memory. - */ -template -class Queue -{ - struct Item : public uavcan::LinkedListNode - { - T payload; - - template - Item(Args... args) : payload(args...) { } - }; - - uavcan::LimitedPoolAllocator allocator_; - uavcan::LinkedListRoot list_; - -public: - Queue(uavcan::IPoolAllocator& arg_allocator, std::size_t block_allocation_quota) : - allocator_(arg_allocator, block_allocation_quota) - { - uavcan::IsDynamicallyAllocatable::check(); - } - - bool isEmpty() const { return list_.isEmpty(); } - - /** - * Creates one item in-place at the end of the list. - * Returns true if the item was appended successfully, false if there's not enough memory. - * Complexity is O(N) where N is queue length. - */ - template - bool tryEmplace(Args... args) - { - // Allocating memory - void* const ptr = allocator_.allocate(sizeof(Item)); - if (ptr == nullptr) - { - return false; - } - - // Constructing the new item - Item* const item = new (ptr) Item(args...); - assert(item != nullptr); - - // Inserting the new item at the end of the list - Item* p = list_.get(); - if (p == nullptr) - { - list_.insert(item); - } - else - { - while (p->getNextListNode() != nullptr) - { - p = p->getNextListNode(); - } - assert(p->getNextListNode() == nullptr); - p->setNextListNode(item); - assert(p->getNextListNode()->getNextListNode() == nullptr); - } - - return true; - } - - /** - * Accesses the first element. - * Nullptr will be returned if the queue is empty. - * Complexity is O(1). - */ - T* peek() { return isEmpty() ? nullptr : &list_.get()->payload; } - const T* peek() const { return isEmpty() ? nullptr : &list_.get()->payload; } - - /** - * Removes the first element. - * If the queue is empty, nothing will be done and assertion failure will be triggered. - * Complexity is O(1). - */ - void pop() - { - Item* const item = list_.get(); - assert(item != nullptr); - if (item != nullptr) - { - list_.remove(item); - item->~Item(); - allocator_.deallocate(item); - } - } -}; - -/** - * Feel free to remove. - */ -static void testQueue() -{ - uavcan::PoolAllocator<1024, uavcan::MemPoolBlockSize> allocator; - Queue::Type> q(allocator, 4); - ENFORCE(q.isEmpty()); - ENFORCE(q.peek() == nullptr); - ENFORCE(q.tryEmplace("One")); - ENFORCE(q.tryEmplace("Two")); - ENFORCE(q.tryEmplace("Three")); - ENFORCE(q.tryEmplace("Four")); - ENFORCE(!q.tryEmplace("Five")); - ENFORCE(*q.peek() == "One"); - q.pop(); - ENFORCE(*q.peek() == "Two"); - q.pop(); - ENFORCE(*q.peek() == "Three"); - q.pop(); - ENFORCE(*q.peek() == "Four"); - q.pop(); - ENFORCE(q.isEmpty()); - ENFORCE(q.peek() == nullptr); -} - -/** - * Objects of this class are owned by the sub-node thread. - * This class does not use heap memory. - */ -class VirtualCanIface : public uavcan::ICanIface, - uavcan::Noncopyable -{ - struct RxItem - { - const uavcan::CanRxFrame frame; - const uavcan::CanIOFlags flags; - - RxItem(const uavcan::CanRxFrame& arg_frame, uavcan::CanIOFlags arg_flags) : - frame(arg_frame), - flags(arg_flags) - { } - }; - - std::mutex& mutex_; - uavcan::CanTxQueue prioritized_tx_queue_; - Queue rx_queue_; - - int16_t send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, uavcan::CanIOFlags flags) override - { - std::lock_guard lock(mutex_); - prioritized_tx_queue_.push(frame, tx_deadline, uavcan::CanTxQueue::Volatile, flags); - return 1; - } - - int16_t receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags) override - { - std::lock_guard lock(mutex_); - - if (rx_queue_.isEmpty()) - { - return 0; - } - - const auto item = *rx_queue_.peek(); - rx_queue_.pop(); - - out_frame = item.frame; - out_ts_monotonic = item.frame.ts_mono; - out_ts_utc = item.frame.ts_utc; - out_flags = item.flags; - - return 1; - } - - int16_t configureFilters(const uavcan::CanFilterConfig*, std::uint16_t) override { return -uavcan::ErrDriver; } - uint16_t getNumFilters() const override { return 0; } - uint64_t getErrorCount() const override { return 0; } - -public: - VirtualCanIface(uavcan::IPoolAllocator& allocator, uavcan::ISystemClock& clock, - std::mutex& arg_mutex, unsigned quota_per_queue) : - mutex_(arg_mutex), - prioritized_tx_queue_(allocator, clock, quota_per_queue), - rx_queue_(allocator, quota_per_queue) - { } - - /** - * Note that RX queue overwrites oldest items when overflowed. - * Call this from the main thread only. - * No additional locking is required. - */ - void addRxFrame(const uavcan::CanRxFrame& frame, uavcan::CanIOFlags flags) - { - std::lock_guard lock(mutex_); - if (!rx_queue_.tryEmplace(frame, flags) && !rx_queue_.isEmpty()) - { - rx_queue_.pop(); - (void)rx_queue_.tryEmplace(frame, flags); - } - } - - /** - * Call this from the main thread only. - * No additional locking is required. - */ - void flushTxQueueTo(uavcan::INode& main_node, std::uint8_t iface_index) - { - std::lock_guard lock(mutex_); - - const std::uint8_t iface_mask = static_cast(1U << iface_index); - - while (auto e = prioritized_tx_queue_.peek()) - { - UAVCAN_TRACE("VirtualCanIface", "TX injection [iface=0x%02x]: %s", - unsigned(iface_mask), e->toString().c_str()); - - const int res = main_node.injectTxFrame(e->frame, e->deadline, iface_mask, - uavcan::CanTxQueue::Qos(e->qos), e->flags); - prioritized_tx_queue_.remove(e); - if (res <= 0) - { - break; - } - } - } - - /** - * Call this from the sub-node thread only. - * No additional locking is required. - */ - bool hasDataInRxQueue() const - { - std::lock_guard lock(mutex_); - return !rx_queue_.isEmpty(); - } -}; - -/** - * This interface defines one method that will be called by the main node thread periodically in order to - * transfer contents of TX queue of the sub-node into the TX queue of the main node. - */ -class ITxQueueInjector -{ -public: - virtual ~ITxQueueInjector() { } - - /** - * Flush contents of TX queues into the main node. - * @param main_node Reference to the main node. - */ - virtual void injectTxFramesInto(uavcan::INode& main_node) = 0; -}; - -/** - * Objects of this class are owned by the sub-node thread. - * This class does not use heap memory. - * @tparam SharedMemoryPoolSize Amount of memory, in bytes, that will be statically allocated for the - * memory pool that will be shared across all interfaces for RX/TX queues. - * Typically this value should be no less than 4K per interface. - */ -template -class VirtualCanDriver : public uavcan::ICanDriver, - public uavcan::IRxFrameListener, - public ITxQueueInjector, - uavcan::Noncopyable -{ - class Event - { - std::mutex m_; - std::condition_variable cv_; - - public: - /** - * Note that this method may return spuriously. - */ - void waitFor(uavcan::MonotonicDuration duration) - { - std::unique_lock lk(m_); - (void)cv_.wait_for(lk, std::chrono::microseconds(duration.toUSec())); - } - - void signal() { cv_.notify_all(); } - }; - - Event event_; ///< Used to unblock the select() call when IO happens. - std::mutex mutex_; ///< Shared across all ifaces - uavcan::PoolAllocator allocator_; ///< Shared across all ifaces - uavcan::LazyConstructor ifaces_[uavcan::MaxCanIfaces]; - const unsigned num_ifaces_; - uavcan_linux::SystemClock clock_; - - uavcan::ICanIface* getIface(uint8_t iface_index) override - { - return (iface_index < num_ifaces_) ? ifaces_[iface_index].operator VirtualCanIface*() : nullptr; - } - - uint8_t getNumIfaces() const override { return num_ifaces_; } - - /** - * This and other methods of ICanDriver will be invoked by the sub-node thread. - */ - int16_t select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces], - uavcan::MonotonicTime blocking_deadline) override - { - bool need_block = (inout_masks.write == 0); // Write queue is infinite - for (unsigned i = 0; need_block && (i < num_ifaces_); i++) - { - const bool need_read = inout_masks.read & (1U << i); - if (need_read && ifaces_[i]->hasDataInRxQueue()) - { - need_block = false; - } - } - - if (need_block) - { - event_.waitFor(blocking_deadline - clock_.getMonotonic()); - } - - inout_masks = uavcan::CanSelectMasks(); - for (unsigned i = 0; i < num_ifaces_; i++) - { - const std::uint8_t iface_mask = 1U << i; - inout_masks.write |= iface_mask; // Always ready to write - if (ifaces_[i]->hasDataInRxQueue()) - { - inout_masks.read |= iface_mask; - } - } - - return num_ifaces_; // We're always ready to write, hence > 0. - } - - /** - * This handler will be invoked by the main node thread. - */ - void handleRxFrame(const uavcan::CanRxFrame& frame, uavcan::CanIOFlags flags) override - { - UAVCAN_TRACE("VirtualCanDriver", "RX [flags=%u]: %s", unsigned(flags), frame.toString().c_str()); - if (frame.iface_index < num_ifaces_) - { - ifaces_[frame.iface_index]->addRxFrame(frame, flags); - event_.signal(); - } - } - - /** - * This method will be invoked by the main node thread. - */ - void injectTxFramesInto(uavcan::INode& main_node) override - { - for (unsigned i = 0; i < num_ifaces_; i++) - { - ifaces_[i]->flushTxQueueTo(main_node, i); - } - event_.signal(); - } - -public: - VirtualCanDriver(unsigned arg_num_ifaces) : num_ifaces_(arg_num_ifaces) - { - assert(num_ifaces_ > 0 && num_ifaces_ <= uavcan::MaxCanIfaces); - - const unsigned quota_per_iface = allocator_.getBlockCapacity() / num_ifaces_; - const unsigned quota_per_queue = quota_per_iface; // 2x overcommit - - UAVCAN_TRACE("VirtualCanDriver", "Total blocks: %u, quota per queue: %u", - unsigned(allocator_.getBlockCapacity()), unsigned(quota_per_queue)); - - for (unsigned i = 0; i < num_ifaces_; i++) - { - ifaces_[i].template construct(allocator_, clock_, mutex_, quota_per_queue); - } - } -}; - -static uavcan_linux::NodePtr initMainNode(const std::vector& ifaces, uavcan::NodeID nid, - const std::string& name) -{ - std::cout << "Initializing main node" << std::endl; - - auto node = uavcan_linux::makeNode(ifaces, name.c_str(), - uavcan::protocol::SoftwareVersion(), uavcan::protocol::HardwareVersion(), nid); - node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - node->setModeOperational(); - return node; -} - -template -static uavcan_linux::SubNodePtr initSubNode(unsigned num_ifaces, uavcan::INode& main_node) -{ - std::cout << "Initializing sub node" << std::endl; - - typedef VirtualCanDriver Driver; - - std::shared_ptr driver(new Driver(num_ifaces)); - - auto node = uavcan_linux::makeSubNode(driver, main_node.getNodeID()); - - main_node.getDispatcher().installRxFrameListener(driver.get()); - - return node; -} - -static void runMainNode(const uavcan_linux::NodePtr& node) -{ - std::cout << "Running main node" << std::endl; - - auto timer = node->makeTimer(uavcan::MonotonicDuration::fromMSec(10000), [&node](const uavcan::TimerEvent&) - { - node->logInfo("timer", "Your time is running out."); - // coverity[dont_call] - node->setVendorSpecificStatusCode(static_cast(std::rand())); - }); - - /* - * We know that in this implementation, VirtualCanDriver inherits uavcan::IRxFrameListener, so we can simply - * restore the reference to ITxQueueInjector using dynamic_cast. In other implementations this may be - * unacceptable, so a reference to ITxQueueInjector will have to be passed using some other means. - */ - if (node->getDispatcher().getRxFrameListener() == nullptr) - { - throw std::logic_error("RX frame listener is not configured"); - } - ITxQueueInjector& tx_injector = dynamic_cast(*node->getDispatcher().getRxFrameListener()); - - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(1)); - if (res < 0) - { - node->logError("spin", "Error %*", res); - } - // TX queue transfer occurs here. - tx_injector.injectTxFramesInto(*node); - } -} - -static void runSubNode(const uavcan_linux::SubNodePtr& node) -{ - std::cout << "Running sub node" << std::endl; - - /* - * Log subscriber - */ - auto log_sub = node->makeSubscriber( - [](const uavcan::ReceivedDataStructure& msg) - { - std::cout << msg << std::endl; - }); - - /* - * Node status monitor - */ - struct NodeStatusMonitor : public uavcan::NodeStatusMonitor - { - explicit NodeStatusMonitor(uavcan::INode& node) : uavcan::NodeStatusMonitor(node) { } - - virtual void handleNodeStatusChange(const NodeStatusChangeEvent& event) override - { - std::cout << "Remote node NID " << int(event.node_id.get()) << " changed status: " - << event.old_status.toString() << " --> " << event.status.toString() << std::endl; - } - }; - NodeStatusMonitor nsm(*node); - ENFORCE(0 == nsm.start()); - - /* - * KV subscriber - */ - auto kv_sub = node->makeSubscriber( - [](const uavcan::ReceivedDataStructure& msg) - { - std::cout << msg << std::endl; - }); - - /* - * KV publisher - */ - unsigned kv_value = 0; - auto kv_pub = node->makePublisher(); - auto timer = node->makeTimer(uavcan::MonotonicDuration::fromMSec(5000), [&](const uavcan::TimerEvent&) - { - uavcan::protocol::debug::KeyValue kv; - kv.key = "five_seconds"; - kv.value = kv_value++; - const int res = kv_pub->broadcast(kv); - if (res < 0) - { - std::cerr << "Sub KV pub err " << res << std::endl; - } - }); - - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(1000)); - if (res < 0) - { - std::cerr << "SubNode spin error: " << res << std::endl; - } - } -} - -int main(int argc, const char** argv) -{ - try - { - testQueue(); - - constexpr unsigned VirtualIfacePoolSize = 32768; - - if (argc < 3) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names(argv + 2, argv + argc); - - auto node = initMainNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); - auto sub_node = initSubNode(iface_names.size(), *node); - - std::thread sub_thread([&sub_node](){ runSubNode(sub_node); }); - - runMainNode(node); - - if (sub_thread.joinable()) - { - std::cout << "Waiting for the sub thread to join" << std::endl; - sub_thread.join(); - } - - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_node.cpp b/libuavcan_drivers/linux/apps/test_node.cpp deleted file mode 100644 index 0b56f4ed88..0000000000 --- a/libuavcan_drivers/linux/apps/test_node.cpp +++ /dev/null @@ -1,120 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include "debug.hpp" - -static uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, - const std::string& name) -{ - auto node = uavcan_linux::makeNode(ifaces); - - /* - * Configuring the node. - */ - node->setNodeID(nid); - node->setName(name.c_str()); - - node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - - /* - * Starting the node. - */ - std::cout << "Starting the node..." << std::endl; - const int start_res = node->start(); - std::cout << "Start returned: " << start_res << std::endl; - ENFORCE(0 == start_res); - - std::cout << "Node started successfully" << std::endl; - - /* - * Say Hi to the world. - */ - node->setModeOperational(); - node->logInfo("init", "Hello world! I'm [%*], NID %*", - node->getNodeStatusProvider().getName().c_str(), int(node->getNodeID().get())); - return node; -} - -static void runForever(const uavcan_linux::NodePtr& node) -{ - /* - * Subscribing to the UAVCAN logging topic - */ - auto log_handler = [](const uavcan::ReceivedDataStructure& msg) - { - std::cout << msg << std::endl; - }; - auto log_sub = node->makeSubscriber(log_handler); - - /* - * Printing when other nodes enter the network or change status - */ - struct NodeStatusMonitor : public uavcan::NodeStatusMonitor - { - explicit NodeStatusMonitor(uavcan::INode& node) : uavcan::NodeStatusMonitor(node) { } - - void handleNodeStatusChange(const NodeStatusChangeEvent& event) override - { - std::cout << "Remote node NID " << int(event.node_id.get()) << " changed status: " - << event.old_status.toString() << " --> " - << event.status.toString() << std::endl; - } - }; - - NodeStatusMonitor nsm(*node); - ENFORCE(0 == nsm.start()); - - /* - * Adding a stupid timer that does nothing once a minute - */ - auto do_nothing_once_a_minute = [&node](const uavcan::TimerEvent&) - { - node->logInfo("timer", "Another minute passed..."); - // coverity[dont_call] - node->setVendorSpecificStatusCode(static_cast(std::rand())); // Setting to an arbitrary value - }; - auto timer = node->makeTimer(uavcan::MonotonicDuration::fromMSec(60000), do_nothing_once_a_minute); - - /* - * Spinning forever - */ - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::getInfinite()); - if (res < 0) - { - node->logError("spin", "Error %*", res); - } - } -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 3) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node"); - std::cout << "Node initialized successfully" << std::endl; - runForever(node); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_posix.cpp b/libuavcan_drivers/linux/apps/test_posix.cpp deleted file mode 100644 index a59aa1c3ef..0000000000 --- a/libuavcan_drivers/linux/apps/test_posix.cpp +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include "debug.hpp" - -int main(int argc, const char** argv) -{ - (void)argc; - (void)argv; - try - { - ENFORCE(0 == std::system("mkdir -p /tmp/uavcan_posix/dynamic_node_id_server")); - - /* - * Event tracer test - */ - { - using namespace uavcan::dynamic_node_id_server; - - const std::string event_log_file("/tmp/uavcan_posix/dynamic_node_id_server/event.log"); - - uavcan_posix::dynamic_node_id_server::FileEventTracer tracer; - ENFORCE(0 <= tracer.init(event_log_file.c_str())); - - // Adding a line - static_cast(tracer).onEvent(TraceError, 123456); - ENFORCE(0 == std::system(("cat " + event_log_file).c_str())); - - // Removing the log file - ENFORCE(0 == std::system(("rm -f " + event_log_file).c_str())); - - // Adding another line - static_cast(tracer).onEvent(TraceError, 789123); - ENFORCE(0 == std::system(("cat " + event_log_file).c_str())); - } - - /* - * Storage backend test - */ - { - using namespace uavcan::dynamic_node_id_server; - - uavcan_posix::dynamic_node_id_server::FileStorageBackend backend; - ENFORCE(0 <= backend.init("/tmp/uavcan_posix/dynamic_node_id_server/storage")); - - auto print_key = [&](const char* key) { - std::cout << static_cast(backend).get(key).c_str() << std::endl; - }; - - print_key("foobar"); - - static_cast(backend).set("foobar", "0123456789abcdef0123456789abcdef"); - static_cast(backend).set("the_answer", "42"); - - print_key("foobar"); - print_key("the_answer"); - print_key("nonexistent"); - } - - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_socket.cpp b/libuavcan_drivers/linux/apps/test_socket.cpp deleted file mode 100644 index a8a39a09f9..0000000000 --- a/libuavcan_drivers/linux/apps/test_socket.cpp +++ /dev/null @@ -1,364 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include "debug.hpp" - -static uavcan::CanFrame makeFrame(std::uint32_t id, const std::string& data) -{ - return uavcan::CanFrame(id, reinterpret_cast(data.c_str()), data.length()); -} - -static uavcan::MonotonicTime tsMonoOffsetMs(std::int64_t ms) -{ - return uavcan_linux::SystemClock().getMonotonic() + uavcan::MonotonicDuration::fromMSec(ms); -} - -static void testNonexistentIface() -{ - const int sock1 = uavcan_linux::SocketCanIface::openSocket("noif9"); - ENFORCE(sock1 < 0); - const int sock2 = uavcan_linux::SocketCanIface::openSocket("verylongifacenameverylongifacenameverylongifacename"); - ENFORCE(sock2 < 0); -} - -static void testSocketRxTx(const std::string& iface_name) -{ - const int sock1 = uavcan_linux::SocketCanIface::openSocket(iface_name); - const int sock2 = uavcan_linux::SocketCanIface::openSocket(iface_name); - ENFORCE(sock1 >= 0 && sock2 >= 0); - - /* - * Clocks will have some offset from the true system time - * SocketCAN driver must handle this correctly - */ - uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate); - clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(100000)); - const uavcan_linux::SystemClock& clock = clock_impl; - - uavcan_linux::SocketCanIface if1(clock, sock1); - uavcan_linux::SocketCanIface if2(clock, sock2); - - /* - * Sending two frames, one of which must be returned back - */ - ENFORCE(1 == if1.send(makeFrame(123, "if1-1"), tsMonoOffsetMs(100), 0)); - ENFORCE(1 == if1.send(makeFrame(456, "if1-2"), tsMonoOffsetMs(100), uavcan::CanIOFlagLoopback)); - if1.poll(true, true); - if1.poll(true, true); - ENFORCE(0 == if1.getErrorCount()); - ENFORCE(!if1.hasReadyTx()); - ENFORCE(if1.hasReadyRx()); // Second loopback - - /* - * Second iface, same thing - */ - ENFORCE(1 == if2.send(makeFrame(321, "if2-1"), tsMonoOffsetMs(100), 0)); - ENFORCE(1 == if2.send(makeFrame(654, "if2-2"), tsMonoOffsetMs(100), uavcan::CanIOFlagLoopback)); - ENFORCE(1 == if2.send(makeFrame(1, "discard"), tsMonoOffsetMs(-1), uavcan::CanIOFlagLoopback)); // Will timeout - if2.poll(true, true); - if2.poll(true, true); - ENFORCE(1 == if2.getErrorCount()); // One timed out - ENFORCE(!if2.hasReadyTx()); - ENFORCE(if2.hasReadyRx()); - - /* - * No-op - */ - if1.poll(true, true); - if2.poll(true, true); - - uavcan::CanFrame frame; - uavcan::MonotonicTime ts_mono; - uavcan::UtcTime ts_utc; - uavcan::CanIOFlags flags = 0; - - /* - * Read first - */ - ENFORCE(1 == if1.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(456, "if1-2")); - ENFORCE(flags == uavcan::CanIOFlagLoopback); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(1 == if1.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(321, "if2-1")); - ENFORCE(flags == 0); - ENFORCE(!ts_mono.isZero()); - ENFORCE(!ts_utc.isZero()); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(1 == if1.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(654, "if2-2")); - ENFORCE(flags == 0); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(0 == if1.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(!if1.hasReadyTx()); - ENFORCE(!if1.hasReadyRx()); - - /* - * Read second - */ - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(123, "if1-1")); - ENFORCE(flags == 0); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(456, "if1-2")); - ENFORCE(flags == 0); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(654, "if2-2")); - ENFORCE(flags == uavcan::CanIOFlagLoopback); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(0 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(!if2.hasReadyTx()); - ENFORCE(!if2.hasReadyRx()); -} - -static void testSocketFilters(const std::string& iface_name) -{ - using uavcan::CanFrame; - - const int sock1 = uavcan_linux::SocketCanIface::openSocket(iface_name); - const int sock2 = uavcan_linux::SocketCanIface::openSocket(iface_name); - ENFORCE(sock1 >= 0 && sock2 >= 0); - - /* - * Clocks will have some offset from the true system time - * SocketCAN driver must handle this correctly - */ - uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate); - clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(-1000)); - const uavcan_linux::SystemClock& clock = clock_impl; - - uavcan_linux::SocketCanIface if1(clock, sock1); - uavcan_linux::SocketCanIface if2(clock, sock2); - - /* - * Configuring filters - */ - uavcan::CanFilterConfig fcs[3]; - // STD/EXT 123 - fcs[0].id = 123; - fcs[0].mask = CanFrame::MaskExtID; - // Only EXT 456789 - fcs[1].id = 456789 | CanFrame::FlagEFF; - fcs[1].mask = CanFrame::MaskExtID | CanFrame::FlagEFF; - // Only STD 0 - fcs[2].id = 0; - fcs[2].mask = CanFrame::MaskExtID | CanFrame::FlagEFF; - - ENFORCE(0 == if2.configureFilters(fcs, 3)); - - /* - * Sending data from 1 to 2, making sure only filtered data will be accepted - */ - const auto EFF = CanFrame::FlagEFF; - ENFORCE(1 == if1.send(makeFrame(123, "1"), tsMonoOffsetMs(100), 0)); // Accept 0 - ENFORCE(1 == if1.send(makeFrame(123 | EFF, "2"), tsMonoOffsetMs(100), 0)); // Accept 0 - ENFORCE(1 == if1.send(makeFrame(456, "3"), tsMonoOffsetMs(100), 0)); // Drop - ENFORCE(1 == if1.send(makeFrame(456789, "4"), tsMonoOffsetMs(100), 0)); // Drop - ENFORCE(1 == if1.send(makeFrame(456789 | EFF, "5"), tsMonoOffsetMs(100), 0)); // Accept 1 - ENFORCE(1 == if1.send(makeFrame(0, "6"), tsMonoOffsetMs(100), 0)); // Accept 2 - ENFORCE(1 == if1.send(makeFrame(EFF, "7"), tsMonoOffsetMs(100), 0)); // Drop - - for (int i = 0; i < 7; i++) - { - if1.poll(true, true); - if2.poll(true, false); - } - ENFORCE(!if1.hasReadyTx()); - ENFORCE(!if1.hasReadyRx()); - ENFORCE(0 == if1.getErrorCount()); - ENFORCE(if2.hasReadyRx()); - - /* - * Checking RX on 2 - */ - uavcan::CanFrame frame; - uavcan::MonotonicTime ts_mono; - uavcan::UtcTime ts_utc; - uavcan::CanIOFlags flags = 0; - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(123, "1")); - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(123 | EFF, "2")); - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(456789 | EFF, "5")); - - ENFORCE(1 == if2.receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(0, "6")); - ENFORCE(flags == 0); - - ENFORCE(!if2.hasReadyRx()); -} - -static void testDriver(const std::vector& iface_names) -{ - /* - * Clocks will have some offset from the true system time - * SocketCAN driver must handle this correctly - */ - uavcan_linux::SystemClock clock_impl(uavcan_linux::ClockAdjustmentMode::PerDriverPrivate); - clock_impl.adjustUtc(uavcan::UtcDuration::fromMSec(9000000)); - const uavcan_linux::SystemClock& clock = clock_impl; - - uavcan_linux::SocketCanDriver driver(clock); - for (auto ifn : iface_names) - { - std::cout << "Adding iface " << ifn << std::endl; - ENFORCE(0 == driver.addIface(ifn)); - } - - ENFORCE(-1 == driver.addIface("noif9")); - ENFORCE(-1 == driver.addIface("noif9")); - ENFORCE(-1 == driver.addIface("noif9")); - - ENFORCE(driver.getNumIfaces() == iface_names.size()); - ENFORCE(nullptr == driver.getIface(255)); - ENFORCE(nullptr == driver.getIface(driver.getNumIfaces())); - - const uavcan::CanFrame* pending_tx[uavcan::MaxCanIfaces] = {}; - - const unsigned AllIfacesMask = (1 << driver.getNumIfaces()) - 1; - - /* - * Send, no loopback - */ - std::cout << "select() 1" << std::endl; - uavcan::CanSelectMasks masks; // Driver provides masks for all available events - ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000))); - ENFORCE(masks.read == 0); - ENFORCE(masks.write == AllIfacesMask); - - for (int i = 0; i < driver.getNumIfaces(); i++) - { - ENFORCE(1 == driver.getIface(i)->send(makeFrame(123, std::to_string(i)), tsMonoOffsetMs(10), 0)); - } - - std::cout << "select() 2" << std::endl; - ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000))); - ENFORCE(masks.read == 0); - ENFORCE(masks.write == AllIfacesMask); - - /* - * Send with loopback - */ - for (int i = 0; i < driver.getNumIfaces(); i++) - { - ENFORCE(1 == driver.getIface(i)->send(makeFrame(456, std::to_string(i)), tsMonoOffsetMs(10), - uavcan::CanIOFlagLoopback)); - ENFORCE(1 == driver.getIface(i)->send(makeFrame(789, std::to_string(i)), tsMonoOffsetMs(-1), // Will timeout - uavcan::CanIOFlagLoopback)); - } - - std::cout << "select() 3" << std::endl; - ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000))); - ENFORCE(masks.read == AllIfacesMask); - ENFORCE(masks.write == AllIfacesMask); - - /* - * Receive loopback - */ - for (int i = 0; i < driver.getNumIfaces(); i++) - { - uavcan::CanFrame frame; - uavcan::MonotonicTime ts_mono; - uavcan::UtcTime ts_utc; - uavcan::CanIOFlags flags = 0; - ENFORCE(1 == driver.getIface(i)->receive(frame, ts_mono, ts_utc, flags)); - ENFORCE(frame == makeFrame(456, std::to_string(i))); - ENFORCE(flags == uavcan::CanIOFlagLoopback); - ENFORCE((clock.getMonotonic() - ts_mono).getAbs().toMSec() < 10); - ENFORCE((clock.getUtc() - ts_utc).getAbs().toMSec() < 10); - - ENFORCE(!driver.getIface(i)->hasReadyTx()); - ENFORCE(!driver.getIface(i)->hasReadyRx()); - } - - std::cout << "select() 4" << std::endl; - masks.write = 0; - ENFORCE(driver.getNumIfaces() == driver.select(masks, pending_tx, tsMonoOffsetMs(1000))); - ENFORCE(masks.read == 0); - ENFORCE(masks.write == AllIfacesMask); - - std::cout << "exit" << std::endl; - - /* - * Error checks - */ - for (int i = 0; i < driver.getNumIfaces(); i++) - { - for (auto kv : driver.getIface(i)->getErrors()) - { - switch (kv.first) - { - case uavcan_linux::SocketCanError::SocketReadFailure: - case uavcan_linux::SocketCanError::SocketWriteFailure: - { - ENFORCE(kv.second == 0); - break; - } - case uavcan_linux::SocketCanError::TxTimeout: - { - ENFORCE(kv.second == 1); // One timed out frame from the above - break; - } - default: - { - ENFORCE(false); - break; - } - } - } - } -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 2) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - - std::vector iface_names; - for (int i = 1; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - - testNonexistentIface(); - testSocketRxTx(iface_names[0]); - testSocketFilters(iface_names[0]); - - testDriver(iface_names); - - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_system_utils.cpp b/libuavcan_drivers/linux/apps/test_system_utils.cpp deleted file mode 100644 index 719768fda5..0000000000 --- a/libuavcan_drivers/linux/apps/test_system_utils.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#include -#include -#include -#include "debug.hpp" - -int main(int argc, const char** argv) -{ - try - { - const std::vector iface_names(argv + 1, argv + argc); - - const auto res = uavcan_linux::MachineIDReader(iface_names).readAndGetLocation(); - - const auto original_flags = std::cout.flags(); - - for (auto x : res.first) - { - std::cout << std::hex << std::setw(2) << std::setfill('0') << int(x); - } - - std::cout.width(0); - std::cout.flags(original_flags); - - std::cout << std::endl; - - std::cout << res.second << std::endl; - - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/test_time_sync.cpp b/libuavcan_drivers/linux/apps/test_time_sync.cpp deleted file mode 100644 index 87629709a6..0000000000 --- a/libuavcan_drivers/linux/apps/test_time_sync.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include "debug.hpp" - - -static uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, - const std::string& name) -{ - auto node = uavcan_linux::makeNode(ifaces); - node->setNodeID(nid); - node->setName(name.c_str()); - - ENFORCE(0 == node->start()); - - node->setModeOperational(); - return node; -} - -static void runForever(const uavcan_linux::NodePtr& node) -{ - uavcan::GlobalTimeSyncMaster tsmaster(*node); - ENFORCE(0 == tsmaster.init()); - - uavcan::GlobalTimeSyncSlave tsslave(*node); - ENFORCE(0 == tsslave.start()); - - auto publish_sync_if_master = [&](const uavcan::TimerEvent&) - { - bool i_am_master = false; - if (tsslave.isActive()) - { - const uavcan::NodeID master_node = tsslave.getMasterNodeID(); - assert(master_node.isValid()); - if (node->getNodeID() < master_node) - { - std::cout << "Overriding the lower priority master " << int(master_node.get()) << std::endl; - i_am_master = true; - } - else - { - std::cout << "There is other master of higher priority " << int(master_node.get()) << std::endl; - } - } - else - { - std::cout << "No other masters present" << std::endl; - i_am_master = true; - } - - // Don't forget to disable slave adjustments if we're master - tsslave.suppress(i_am_master); - - if (i_am_master) - { - ENFORCE(0 <= tsmaster.publish()); - } - }; - - auto sync_publish_timer = node->makeTimer(uavcan::MonotonicDuration::fromMSec(1000), publish_sync_if_master); - - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::getInfinite()); - if (res < 0) - { - node->logError("spin", "Error %*", res); - } - } -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 3) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - const int self_node_id = std::stoi(argv[1]); - std::vector iface_names; - for (int i = 2; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_test_node_status_monitor"); - runForever(node); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Exception: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp b/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp deleted file mode 100644 index 91b39211dc..0000000000 --- a/libuavcan_drivers/linux/apps/uavcan_dynamic_node_id_server.cpp +++ /dev/null @@ -1,666 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "debug.hpp" -// UAVCAN -#include -// UAVCAN Linux drivers -#include -// UAVCAN POSIX drivers -#include -#include - -namespace -{ - -constexpr int MaxNumLastEvents = 30; -constexpr int MinUpdateInterval = 100; - -uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, const std::string& name) -{ - const auto app_id = uavcan_linux::makeApplicationID(uavcan_linux::MachineIDReader().read(), name, nid.get()); - - uavcan::protocol::HardwareVersion hwver; - std::copy(app_id.begin(), app_id.end(), hwver.unique_id.begin()); - std::cout << hwver << std::endl; - - auto node = uavcan_linux::makeNode(ifaces, name.c_str(), uavcan::protocol::SoftwareVersion(), hwver, nid); - - node->getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - node->setModeOperational(); - - return node; -} - - -class EventTracer : public uavcan_posix::dynamic_node_id_server::FileEventTracer -{ -public: - struct RecentEvent - { - const uavcan::MonotonicDuration time_since_startup; - const uavcan::UtcTime utc_timestamp; - const uavcan::dynamic_node_id_server::TraceCode code; - const std::int64_t argument; - - RecentEvent(uavcan::MonotonicDuration arg_time_since_startup, - uavcan::UtcTime arg_utc_timestamp, - uavcan::dynamic_node_id_server::TraceCode arg_code, - std::int64_t arg_argument) - : time_since_startup(arg_time_since_startup) - , utc_timestamp(arg_utc_timestamp) - , code(arg_code) - , argument(arg_argument) - { } - - uavcan::MakeString<81>::Type toString() const // Heapless return - { - char timebuf[12] = { }; - { - const std::time_t rawtime = utc_timestamp.toUSec() * 1e-6; - const auto tm = std::localtime(&rawtime); - std::strftime(timebuf, 10, "%H:%M:%S.", tm); - std::snprintf(&timebuf[9], 3, "%02u", static_cast((utc_timestamp.toMSec() % 1000U) / 10U)); - } - - decltype(toString()) out; - out.resize(out.capacity()); - // coverity[overflow : FALSE] - (void)std::snprintf(reinterpret_cast(out.begin()), out.size() - 1U, - "%-11s %-28s %-20lld %016llx", - timebuf, - getEventName(code), - static_cast(argument), - static_cast(argument)); - return out; - } - - static const char* getTableHeader() - { - // Matches the string format above - return "Timestamp Event name Argument (dec) Argument (hex)"; - } - }; - - struct EventStatisticsRecord - { - std::uint64_t count; - uavcan::MonotonicTime last_occurence; - - EventStatisticsRecord() - : count(0) - { } - - void hit(uavcan::MonotonicTime ts) - { - count++; - last_occurence = ts; - } - }; - -private: - struct EnumKeyHash - { - template - std::size_t operator()(T t) const { return static_cast(t); } - }; - - uavcan_linux::SystemClock clock_; - const uavcan::MonotonicTime started_at_ = clock_.getMonotonic(); - const unsigned num_last_events_; - - std::deque last_events_; - std::unordered_map event_counters_; - - bool had_events_ = false; - - void onEvent(uavcan::dynamic_node_id_server::TraceCode code, std::int64_t argument) override - { - uavcan_posix::dynamic_node_id_server::FileEventTracer::onEvent(code, argument); - - had_events_ = true; - - const auto ts_m = clock_.getMonotonic(); - const auto ts_utc = clock_.getUtc(); - const auto time_since_startup = ts_m - started_at_; - - last_events_.emplace_front(time_since_startup, ts_utc, code, argument); - if (last_events_.size() > num_last_events_) - { - last_events_.pop_back(); - } - - event_counters_[code].hit(ts_m); - } - -public: - EventTracer(unsigned num_last_events_to_keep) - : num_last_events_(num_last_events_to_keep) - { } - - using uavcan_posix::dynamic_node_id_server::FileEventTracer::init; - - const RecentEvent& getEventByIndex(unsigned index) const { return last_events_.at(index); } - - unsigned getNumEvents() const { return last_events_.size(); } - - const decltype(event_counters_)& getEventCounters() const { return event_counters_; } - - bool hadEvents() - { - if (had_events_) - { - had_events_ = false; - return true; - } - return false; - } -}; - - -::winsize getTerminalSize() -{ - auto w = ::winsize(); - ENFORCE(0 >= ioctl(STDOUT_FILENO, TIOCGWINSZ, &w)); - ENFORCE(w.ws_col > 0 && w.ws_row > 0); - return w; -} - - -std::vector> -collectRelevantEvents(const EventTracer& event_tracer, const unsigned num_events) -{ - // First, creating a vector of pairs (event code, count) - typedef std::pair Pair; - const auto counters = event_tracer.getEventCounters(); - std::vector pairs(counters.size()); - std::copy(counters.begin(), counters.end(), pairs.begin()); - - // Now, sorting the pairs so that the most recent ones are on top of the list - std::sort(pairs.begin(), pairs.end(), [](const Pair& a, const Pair& b) { - return a.second.last_occurence > b.second.last_occurence; - }); - - // Cutting the oldest events away - pairs.resize(std::min(num_events, unsigned(pairs.size()))); - - // Sorting so that the most frequent events are on top of the list - std::stable_sort(pairs.begin(), pairs.end(), [](const Pair& a, const Pair& b) { - return a.second.count > b.second.count; - }); - - return pairs; -} - -enum class CLIColor : unsigned -{ - Red = 31, - Green = 32, - Yellow = 33, - Blue = 34, - Magenta = 35, - Cyan = 36, - White = 37, - Default = 39 -}; - -CLIColor getColorHash(unsigned value) { return CLIColor(31 + value % 7); } - -class CLIColorizer -{ - const CLIColor color_; -public: - explicit CLIColorizer(CLIColor c) : color_(c) - { - std::printf("\033[%um", static_cast(color_)); - } - - ~CLIColorizer() - { - std::printf("\033[%um", static_cast(CLIColor::Default)); - } -}; - - -void redraw(const uavcan_linux::NodePtr& node, - const uavcan::MonotonicTime timestamp, - const EventTracer& event_tracer, - const uavcan::dynamic_node_id_server::DistributedServer& server) -{ - using uavcan::dynamic_node_id_server::distributed::RaftCore; - - /* - * Constants that are permanent for the designed UI layout - */ - constexpr unsigned NumRelevantEvents = 17; - constexpr unsigned NumRowsWithoutEvents = 3; - - /* - * Collecting the data - */ - const unsigned num_rows = getTerminalSize().ws_row; - - const auto relevant_events = collectRelevantEvents(event_tracer, NumRelevantEvents); - - const uavcan::dynamic_node_id_server::distributed::StateReport report(server); - - const auto time_since_last_activity = timestamp - report.last_activity_timestamp; - - /* - * Basic rendering functions - */ - unsigned next_relevant_event_index = 0; - - const auto render_next_event_counter = [&]() - { - const char* event_name = ""; - char event_count_str[10] = { }; - CLIColor event_color = CLIColor::Default; - - if (next_relevant_event_index < relevant_events.size()) - { - const auto e = relevant_events[next_relevant_event_index]; - event_name = uavcan::dynamic_node_id_server::IEventTracer::getEventName(e.first); - std::snprintf(event_count_str, sizeof(event_count_str) - 1U, "%llu", - static_cast(e.second.count)); - event_color = getColorHash(static_cast(e.first)); - } - next_relevant_event_index++; - - std::printf(" | "); - CLIColorizer izer(event_color); - std::printf("%-29s %-9s\n", event_name, event_count_str); - }; - - const auto render_top_str = [&](const char* local_state_name, const char* local_state_value, CLIColor color) - { - { - CLIColorizer izer(color); - std::printf("%-20s %-16s", local_state_name, local_state_value); - } - render_next_event_counter(); - }; - - const auto render_top_int = [&](const char* local_state_name, long long local_state_value, CLIColor color) - { - char buf[21]; - std::snprintf(buf, sizeof(buf) - 1U, "%lld", local_state_value); - render_top_str(local_state_name, buf, color); - }; - - const auto raft_state_to_string = [](uavcan::dynamic_node_id_server::distributed::RaftCore::ServerState s) - { - switch (s) - { - case RaftCore::ServerStateFollower: return "Follower"; - case RaftCore::ServerStateCandidate: return "Candidate"; - case RaftCore::ServerStateLeader: return "Leader"; - default: return "BADSTATE"; - } - }; - - const auto duration_to_string = [](uavcan::MonotonicDuration dur) - { - uavcan::MakeString<16>::Type str; // This is much faster than std::string - str.appendFormatted("%.1f", dur.toUSec() / 1e6); - return str; - }; - - const auto colorize_if = [](bool condition, CLIColor color) - { - return condition ? color : CLIColor::Default; - }; - - /* - * Rendering the data to the CLI - */ - std::printf("\x1b[1J"); // Clear screen from the current cursor position to the beginning - std::printf("\x1b[H"); // Move cursor to the coordinates 1,1 - - // Local state and relevant event counters - two columns - std::printf(" Local state | Event counters\n"); - - render_top_int("Node ID", - node->getNodeID().get(), - CLIColor::Default); - - render_top_str("State", - raft_state_to_string(report.state), - (report.state == RaftCore::ServerStateCandidate) ? CLIColor::Magenta : - (report.state == RaftCore::ServerStateLeader) ? CLIColor::Green : - CLIColor::Default); - - render_top_int("Last log index", - report.last_log_index, - CLIColor::Default); - - render_top_int("Commit index", - report.commit_index, - colorize_if(report.commit_index != report.last_log_index, CLIColor::Magenta)); - - render_top_int("Last log term", - report.last_log_term, - CLIColor::Default); - - render_top_int("Current term", - report.current_term, - CLIColor::Default); - - render_top_int("Voted for", - report.voted_for.get(), - CLIColor::Default); - - render_top_str("Since activity", - duration_to_string(time_since_last_activity).c_str(), - CLIColor::Default); - - render_top_str("Random timeout", - duration_to_string(report.randomized_timeout).c_str(), - CLIColor::Default); - - render_top_int("Unknown nodes", - report.num_unknown_nodes, - colorize_if(report.num_unknown_nodes != 0, CLIColor::Magenta)); - - render_top_int("Node failures", - node->getInternalFailureCount(), - colorize_if(node->getInternalFailureCount() != 0, CLIColor::Magenta)); - - const bool all_allocated = server.guessIfAllDynamicNodesAreAllocated(); - render_top_str("All allocated", - all_allocated ? "Yes": "No", - colorize_if(!all_allocated, CLIColor::Magenta)); - - // Empty line before the next block - std::printf(" "); - render_next_event_counter(); - - // Followers block - std::printf(" Followers "); - render_next_event_counter(); - - const auto render_followers_state = [&](const char* name, - const std::function value_getter, - const std::function color_getter) - { - std::printf("%-17s", name); - for (std::uint8_t i = 0; i < 4; i++) - { - if (i < (report.cluster_size - 1)) - { - CLIColorizer colorizer(color_getter(i)); - const auto value = value_getter(i); - if (value >= 0) - { - std::printf("%-5d", value); - } - else - { - std::printf("N/A "); - } - } - else - { - std::printf(" "); - } - } - render_next_event_counter(); - }; - - const auto follower_color_getter = [&](std::uint8_t i) - { - if (report.state != RaftCore::ServerStateLeader) { return CLIColor::Default; } - if (!report.followers[i].node_id.isValid()) { return CLIColor::Red; } - if (report.followers[i].match_index != report.last_log_index || - report.followers[i].next_index <= report.last_log_index) - { - return CLIColor::Magenta; - } - return CLIColor::Default; - }; - - render_followers_state("Node ID", [&](std::uint8_t i) - { - const auto nid = report.followers[i].node_id; - return nid.isValid() ? nid.get() : -1; - }, - follower_color_getter); - - render_followers_state("Next index", - [&](std::uint8_t i) { return report.followers[i].next_index; }, - follower_color_getter); - - render_followers_state("Match index", - [&](std::uint8_t i) { return report.followers[i].match_index; }, - follower_color_getter); - - assert(next_relevant_event_index == NumRelevantEvents); // Ensuring that all events can be printed - - // Separator - std::printf("--------------------------------------+----------------------------------------\n"); - - // Event log - std::printf("%s\n", EventTracer::RecentEvent::getTableHeader()); - const int num_events_to_render = static_cast(num_rows) - - static_cast(next_relevant_event_index) - - static_cast(NumRowsWithoutEvents) - - 1; // This allows to keep the last line empty for stdout or UAVCAN_TRACE() - for (int i = 0; - i < num_events_to_render && i < static_cast(event_tracer.getNumEvents()); - i++) - { - const auto e = event_tracer.getEventByIndex(i); - CLIColorizer colorizer(getColorHash(static_cast(e.code))); - std::printf("%s\n", e.toString().c_str()); - } - - std::fflush(stdout); -} - - -void runForever(const uavcan_linux::NodePtr& node, - const std::uint8_t cluster_size, - const std::string& event_log_file, - const std::string& persistent_storage_path) -{ - /* - * Event tracer - */ - EventTracer event_tracer(MaxNumLastEvents); - ENFORCE(0 <= event_tracer.init(event_log_file.c_str())); - - /* - * Storage backend - */ - uavcan_posix::dynamic_node_id_server::FileStorageBackend storage_backend; - ENFORCE(0 <= storage_backend.init(persistent_storage_path.c_str())); - - /* - * Server - */ - uavcan::dynamic_node_id_server::DistributedServer server(*node, storage_backend, event_tracer); - - const int server_init_res = server.init(node->getNodeStatusProvider().getHardwareVersion().unique_id, cluster_size); - if (server_init_res < 0) - { - throw std::runtime_error("Failed to start the server; error " + std::to_string(server_init_res)); - } - - /* - * Preparing the CLI - */ - std::printf("\x1b[2J"); // Clear entire screen; this will preserve initialization output in the scrollback - - /* - * Spinning the node - */ - uavcan::MonotonicTime last_redraw_at; - - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::fromMSec(MinUpdateInterval)); - if (res < 0) - { - std::cerr << "Spin error: " << res << std::endl; - } - - const auto ts = node->getMonotonicTime(); - - if (event_tracer.hadEvents() || (ts - last_redraw_at).toMSec() > 1000) - { - last_redraw_at = ts; - redraw(node, ts, event_tracer, server); - } - } -} - -struct Options -{ - uavcan::NodeID node_id; - std::vector ifaces; - std::uint8_t cluster_size = 0; - std::string storage_path; -}; - -Options parseOptions(int argc, const char** argv) -{ - const char* const executable_name = *argv++; - argc--; - - const auto enforce = [executable_name](bool condition, const char* error_text) { - if (!condition) - { - std::cerr << error_text << "\n" - << "Usage:\n\t" - << executable_name - << " [can-iface-name-N...] [-c ] -s " - << std::endl; - std::exit(1); - } - }; - - enforce(argc >= 3, "Not enough arguments"); - - /* - * Node ID is always at the first position - */ - argc--; - const int node_id = std::stoi(*argv++); - enforce(node_id >= 1 && node_id <= 127, "Invalid node ID"); - - Options out; - out.node_id = uavcan::NodeID(std::uint8_t(node_id)); - - while (argc --> 0) - { - const std::string token(*argv++); - - if (token[0] != '-') - { - out.ifaces.push_back(token); - } - else if (token[1] == 'c') - { - int cluster_size = 0; - if (token.length() > 2) // -c2 - { - cluster_size = std::stoi(token.c_str() + 2); - } - else // -c 2 - { - enforce(argc --> 0, "Expected cluster size"); - cluster_size = std::stoi(*argv++); - } - enforce(cluster_size >= 1 && - cluster_size <= uavcan::dynamic_node_id_server::distributed::ClusterManager::MaxClusterSize, - "Invalid cluster size"); - out.cluster_size = std::uint8_t(cluster_size); - } - else if (token[1] == 's') - { - if (token.length() > 2) // -s/foo/bar - { - out.storage_path = token.c_str() + 2; - } - else // -s /foo/bar - { - enforce(argc --> 0, "Expected storage path"); - out.storage_path = *argv++; - } - } - else - { - enforce(false, "Unexpected argument"); - } - } - - enforce(!out.storage_path.empty(), "Invalid storage path"); - - return out; -} - -} - -int main(int argc, const char** argv) -{ - try - { - std::srand(std::time(nullptr)); - - if (isatty(STDOUT_FILENO) != 1) - { - std::cerr << "This application cannot run if stdout is not associated with a terminal" << std::endl; - std::exit(1); - } - - auto options = parseOptions(argc, argv); - - std::cout << "Self node ID: " << int(options.node_id.get()) << "\n" - "Cluster size: " << int(options.cluster_size) << "\n" - "Storage path: " << options.storage_path << "\n" - "Num ifaces: " << options.ifaces.size() << "\n" -#ifdef NDEBUG - "Build mode: Release" -#else - "Build mode: Debug" -#endif - << std::endl; - - /* - * Preparing the storage directory - */ - options.storage_path += "/node_" + std::to_string(options.node_id.get()); - - int system_res = std::system(("mkdir -p '" + options.storage_path + "' &>/dev/null").c_str()); - (void)system_res; - - const auto event_log_file = options.storage_path + "/events.log"; - const auto storage_path = options.storage_path + "/storage/"; - - /* - * Starting the node - */ - auto node = initNode(options.ifaces, options.node_id, "org.uavcan.linux_app.dynamic_node_id_server"); - runForever(node, options.cluster_size, event_log_file, storage_path); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/uavcan_monitor.cpp b/libuavcan_drivers/linux/apps/uavcan_monitor.cpp deleted file mode 100644 index d5d39e7c24..0000000000 --- a/libuavcan_drivers/linux/apps/uavcan_monitor.cpp +++ /dev/null @@ -1,183 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include "debug.hpp" - -enum class CLIColor : unsigned -{ - Red = 31, - Green = 32, - Yellow = 33, - Blue = 34, - Magenta = 35, - Cyan = 36, - White = 37, - Default = 39 -}; - -class CLIColorizer -{ - const CLIColor color_; -public: - explicit CLIColorizer(CLIColor c) : color_(c) - { - std::printf("\033[%um", static_cast(color_)); - } - - ~CLIColorizer() - { - std::printf("\033[%um", static_cast(CLIColor::Default)); - } -}; - -class Monitor : public uavcan::NodeStatusMonitor -{ - uavcan_linux::TimerPtr timer_; - std::unordered_map status_registry_; - - void handleNodeStatusMessage(const uavcan::ReceivedDataStructure& msg) override - { - status_registry_[msg.getSrcNodeID().get()] = msg; - } - - static std::pair healthToColoredString(const std::uint8_t health) - { - static const std::unordered_map> map - { - { uavcan::protocol::NodeStatus::HEALTH_OK, { CLIColor(CLIColor::Green), "OK" }}, - { uavcan::protocol::NodeStatus::HEALTH_WARNING, { CLIColor(CLIColor::Yellow), "WARNING" }}, - { uavcan::protocol::NodeStatus::HEALTH_ERROR, { CLIColor(CLIColor::Magenta), "ERROR" }}, - { uavcan::protocol::NodeStatus::HEALTH_CRITICAL, { CLIColor(CLIColor::Red), "CRITICAL" }} - }; - try - { - return map.at(health); - } - catch (std::out_of_range&) - { - return { CLIColor(CLIColor::Red), std::to_string(health) }; - } - } - - static std::pair modeToColoredString(const std::uint8_t mode) - { - static const std::unordered_map> map - { - { uavcan::protocol::NodeStatus::MODE_OPERATIONAL, { CLIColor(CLIColor::Green), "OPERATIONAL" }}, - { uavcan::protocol::NodeStatus::MODE_INITIALIZATION, { CLIColor(CLIColor::Yellow), "INITIALIZATION" }}, - { uavcan::protocol::NodeStatus::MODE_MAINTENANCE, { CLIColor(CLIColor::Cyan), "MAINTENANCE" }}, - { uavcan::protocol::NodeStatus::MODE_SOFTWARE_UPDATE, { CLIColor(CLIColor::Magenta), "SOFTWARE_UPDATE" }}, - { uavcan::protocol::NodeStatus::MODE_OFFLINE, { CLIColor(CLIColor::Red), "OFFLINE" }} - }; - try - { - return map.at(mode); - } - catch (std::out_of_range&) - { - return { CLIColor(CLIColor::Red), std::to_string(mode) }; - } - } - - void printStatusLine(const uavcan::NodeID nid, const uavcan::NodeStatusMonitor::NodeStatus& status) - { - const auto health_and_color = healthToColoredString(status.health); - const auto mode_and_color = modeToColoredString(status.mode); - - const int nid_int = nid.get(); - const unsigned long uptime = status_registry_[nid_int].uptime_sec; - const unsigned vendor_code = status_registry_[nid_int].vendor_specific_status_code; - - std::printf(" %-3d |", nid_int); - { - CLIColorizer clz(mode_and_color.first); - std::printf(" %-15s ", mode_and_color.second.c_str()); - } - std::printf("|"); - { - CLIColorizer clz(health_and_color.first); - std::printf(" %-8s ", health_and_color.second.c_str()); - } - std::printf("| %-10lu | %04x %s'%s %u\n", uptime, vendor_code, - std::bitset<8>((vendor_code >> 8) & 0xFF).to_string().c_str(), - std::bitset<8>(vendor_code).to_string().c_str(), - vendor_code); - } - - void redraw(const uavcan::TimerEvent&) - { - std::printf("\x1b[1J"); // Clear screen from the current cursor position to the beginning - std::printf("\x1b[H"); // Move cursor to the coordinates 1,1 - std::printf(" NID | Mode | Health | Uptime [s] | Vendor-specific status code\n"); - std::printf("-----+-----------------+----------+------------+-hex---bin----------------dec--\n"); - - for (unsigned i = 1; i <= uavcan::NodeID::Max; i++) - { - if (isNodeKnown(i)) - { - printStatusLine(i, getNodeStatus(i)); - } - } - } - -public: - explicit Monitor(uavcan_linux::NodePtr node) - : uavcan::NodeStatusMonitor(*node) - , timer_(node->makeTimer(uavcan::MonotonicDuration::fromMSec(500), - std::bind(&Monitor::redraw, this, std::placeholders::_1))) - { } -}; - - -static uavcan_linux::NodePtr initNodeInPassiveMode(const std::vector& ifaces, const std::string& node_name) -{ - auto node = uavcan_linux::makeNode(ifaces, node_name.c_str(), - uavcan::protocol::SoftwareVersion(), uavcan::protocol::HardwareVersion()); - node->setModeOperational(); - return node; -} - -static void runForever(const uavcan_linux::NodePtr& node) -{ - Monitor mon(node); - ENFORCE(0 == mon.start()); - while (true) - { - const int res = node->spin(uavcan::MonotonicDuration::getInfinite()); - if (res < 0) - { - node->logError("spin", "Error %*", res); - } - } -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 2) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - std::vector iface_names; - for (int i = 1; i < argc; i++) - { - iface_names.emplace_back(argv[i]); - } - uavcan_linux::NodePtr node = initNodeInPassiveMode(iface_names, "org.uavcan.linux_app.node_status_monitor"); - runForever(node); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp b/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp deleted file mode 100644 index a949336e54..0000000000 --- a/libuavcan_drivers/linux/apps/uavcan_nodetool.cpp +++ /dev/null @@ -1,300 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include "debug.hpp" - -#include -#include -#include - -namespace -{ - -class StdinLineReader -{ - mutable std::mutex mutex_; - std::thread thread_; - std::queue queue_; - - void worker() - { - while (true) - { - std::string input; - std::getline(std::cin, input); - std::lock_guard lock(mutex_); - queue_.push(input); - } - } - -public: - StdinLineReader() - : thread_(&StdinLineReader::worker, this) - { - thread_.detach(); - } - - bool hasPendingInput() const - { - std::lock_guard lock(mutex_); - return !queue_.empty(); - } - - std::string getLine() - { - std::lock_guard lock(mutex_); - if (queue_.empty()) - { - throw std::runtime_error("Input queue is empty"); - } - auto ret = queue_.front(); - queue_.pop(); - return ret; - } - - std::vector getSplitLine() - { - std::istringstream iss(getLine()); - std::vector out; - std::copy(std::istream_iterator(iss), std::istream_iterator(), - std::back_inserter(out)); - return out; - } -}; - -uavcan_linux::NodePtr initNode(const std::vector& ifaces, uavcan::NodeID nid, const std::string& name) -{ - auto node = uavcan_linux::makeNode(ifaces, name.c_str(), - uavcan::protocol::SoftwareVersion(), uavcan::protocol::HardwareVersion(), - nid); - node->setModeOperational(); - return node; -} - -template -typename DataType::Response call(uavcan_linux::BlockingServiceClient& client, - uavcan::NodeID server_node_id, const typename DataType::Request& request) -{ - const int res = client.blockingCall(server_node_id, request, uavcan::MonotonicDuration::fromMSec(100)); - ENFORCE(res >= 0); - ENFORCE(client.wasSuccessful()); - return client.getResponse(); -} - -/* - * Command table. - * The structure is: - * command_name : (command_usage_info, command_entry_point) - * This code was written while listening to some bad dubstep so I'm not sure about its quality. - */ -const std::map&)> - > - > commands = -{ - { - "param", - { - "No arguments supplied - requests all params from a remote node\n" - " - assigns parameter to value ", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector& args) - { - auto client = node->makeBlockingServiceClient(); - uavcan::protocol::param::GetSet::Request request; - if (args.empty()) - { - while (true) - { - auto response = call(*client, node_id, request); - if (response.name.empty()) - { - break; - } - std::cout - << response - << "\n" << std::string(80, '-') - << std::endl; - request.index++; - } - } - else - { - request.name = args.at(0).c_str(); - // TODO: add support for string parameters - request.value.to() = std::stof(args.at(1)); - std::cout << call(*client, node_id, request) << std::endl; - } - } - } - }, - { - "param_save", - { - "Calls uavcan.protocol.param.ExecuteOpcode on a remote node with OPCODE_SAVE", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector&) - { - auto client = node->makeBlockingServiceClient(); - uavcan::protocol::param::ExecuteOpcode::Request request; - request.opcode = request.OPCODE_SAVE; - std::cout << call(*client, node_id, request) << std::endl; - } - } - }, - { - "param_erase", - { - "Calls uavcan.protocol.param.ExecuteOpcode on a remote node with OPCODE_ERASE", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector&) - { - auto client = node->makeBlockingServiceClient(); - uavcan::protocol::param::ExecuteOpcode::Request request; - request.opcode = request.OPCODE_ERASE; - std::cout << call(*client, node_id, request) << std::endl; - } - } - }, - { - "restart", - { - "Restarts a remote node using uavcan.protocol.RestartNode", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector&) - { - auto client = node->makeBlockingServiceClient(); - uavcan::protocol::RestartNode::Request request; - request.magic_number = request.MAGIC_NUMBER; - (void)client->blockingCall(node_id, request); - if (client->wasSuccessful()) - { - std::cout << client->getResponse() << std::endl; - } - else - { - std::cout << "" << std::endl; - } - } - } - }, - { - "info", - { - "Calls uavcan.protocol.GetNodeInfo on a remote node", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector&) - { - auto client = node->makeBlockingServiceClient(); - std::cout << call(*client, node_id, uavcan::protocol::GetNodeInfo::Request()) << std::endl; - } - } - }, - { - "transport_stats", - { - "Calls uavcan.protocol.GetTransportStats on a remote node", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID node_id, const std::vector&) - { - auto client = node->makeBlockingServiceClient(); - std::cout << call(*client, node_id, uavcan::protocol::GetTransportStats::Request()) << std::endl; - } - } - }, - { - "hardpoint", - { - "Publishes uavcan.equipment.hardpoint.Command\n" - "Expected argument: command", - [](const uavcan_linux::NodePtr& node, const uavcan::NodeID, const std::vector& args) - { - uavcan::equipment::hardpoint::Command msg; - msg.command = std::stoi(args.at(0)); - auto pub = node->makePublisher(); - (void)pub->broadcast(msg); - } - } - } -}; - -void runForever(const uavcan_linux::NodePtr& node) -{ - StdinLineReader stdin_reader; - std::cout << "> " << std::flush; - while (true) - { - ENFORCE(node->spin(uavcan::MonotonicDuration::fromMSec(10)) >= 0); - if (!stdin_reader.hasPendingInput()) - { - continue; - } - const auto words = stdin_reader.getSplitLine(); - bool command_is_known = false; - - try - { - if (words.size() >= 2) - { - const auto cmd = words.at(0); - const uavcan::NodeID node_id(std::stoi(words.at(1))); - auto it = commands.find(cmd); - if (it != std::end(commands)) - { - command_is_known = true; - it->second.second(node, node_id, std::vector(words.begin() + 2, words.end())); - } - } - } - catch (std::exception& ex) - { - std::cout << "FAILURE\n" << ex.what() << std::endl; - } - - if (!command_is_known) - { - std::cout << " [args...]\n"; - std::cout << "Say 'help' to get help.\n"; // I'll show myself out. - - if (!words.empty() && words.at(0) == "help") - { - std::cout << "Usage:\n\n"; - for (auto& cmd : commands) - { - std::cout << cmd.first << "\n" << cmd.second.first << "\n\n"; - } - } - } - std::cout << "> " << std::flush; - } -} - -} - -int main(int argc, const char** argv) -{ - try - { - if (argc < 3) - { - std::cerr << "Usage:\n\t" << argv[0] << " [can-iface-name-N...]" << std::endl; - return 1; - } - const int self_node_id = std::stoi(argv[1]); - const std::vector iface_names(argv + 2, argv + argc); - uavcan_linux::NodePtr node = initNode(iface_names, self_node_id, "org.uavcan.linux_app.nodetool"); - runForever(node); - return 0; - } - catch (const std::exception& ex) - { - std::cerr << "Error: " << ex.what() << std::endl; - return 1; - } -} diff --git a/libuavcan_drivers/linux/cppcheck.sh b/libuavcan_drivers/linux/cppcheck.sh deleted file mode 100755 index 87d6e82739..0000000000 --- a/libuavcan_drivers/linux/cppcheck.sh +++ /dev/null @@ -1,11 +0,0 @@ -#!/bin/sh - -num_cores=$(grep -c ^processor /proc/cpuinfo) -if [ -z "$num_cores" ]; then - echo "num_cores=? WTF?" - num_cores=4 -fi - -cppcheck . --error-exitcode=1 --quiet --enable=all --platform=unix64 --std=c99 --std=c++11 \ - --inline-suppr --force --template=gcc -j$num_cores \ - -Iinclude $@ diff --git a/libuavcan_drivers/linux/include/uavcan_linux/clock.hpp b/libuavcan_drivers/linux/include/uavcan_linux/clock.hpp deleted file mode 100644 index 40f5176670..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/clock.hpp +++ /dev/null @@ -1,196 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include - -#include -#include -#include - -#include -#include - -namespace uavcan_linux -{ -/** - * Different adjustment modes can be used for time synchronization - */ -enum class ClockAdjustmentMode -{ - SystemWide, ///< Adjust the clock globally for the whole system; requires root privileges - PerDriverPrivate ///< Adjust the clock only for the current driver instance -}; - -/** - * Linux system clock driver. - * Requires librt. - */ -class SystemClock : public uavcan::ISystemClock -{ - uavcan::UtcDuration private_adj_; - uavcan::UtcDuration gradual_adj_limit_; - const ClockAdjustmentMode adj_mode_; - std::uint64_t step_adj_cnt_; - std::uint64_t gradual_adj_cnt_; - - static constexpr std::int64_t Int1e6 = 1000000; - static constexpr std::uint64_t UInt1e6 = 1000000; - - bool performStepAdjustment(const uavcan::UtcDuration adjustment) - { - step_adj_cnt_++; - const std::int64_t usec = adjustment.toUSec(); - timeval tv; - if (gettimeofday(&tv, NULL) != 0) - { - return false; - } - tv.tv_sec += usec / Int1e6; - tv.tv_usec += usec % Int1e6; - return settimeofday(&tv, nullptr) == 0; - } - - bool performGradualAdjustment(const uavcan::UtcDuration adjustment) - { - gradual_adj_cnt_++; - const std::int64_t usec = adjustment.toUSec(); - timeval tv; - tv.tv_sec = usec / Int1e6; - tv.tv_usec = usec % Int1e6; - return adjtime(&tv, nullptr) == 0; - } - -public: - /** - * By default, the clock adjustment mode will be selected automatically - global if root, private otherwise. - */ - explicit SystemClock(ClockAdjustmentMode adj_mode = detectPreferredClockAdjustmentMode()) - : gradual_adj_limit_(uavcan::UtcDuration::fromMSec(4000)) - , adj_mode_(adj_mode) - , step_adj_cnt_(0) - , gradual_adj_cnt_(0) - { } - - /** - * Returns monotonic timestamp from librt. - * @throws uavcan_linux::Exception. - */ - uavcan::MonotonicTime getMonotonic() const override - { - timespec ts; - if (clock_gettime(CLOCK_MONOTONIC, &ts) != 0) - { - throw Exception("Failed to get monotonic time"); - } - return uavcan::MonotonicTime::fromUSec(std::uint64_t(ts.tv_sec) * UInt1e6 + ts.tv_nsec / 1000); - } - - /** - * Returns wall time from gettimeofday(). - * @throws uavcan_linux::Exception. - */ - uavcan::UtcTime getUtc() const override - { - timeval tv; - if (gettimeofday(&tv, NULL) != 0) - { - throw Exception("Failed to get UTC time"); - } - uavcan::UtcTime utc = uavcan::UtcTime::fromUSec(std::uint64_t(tv.tv_sec) * UInt1e6 + tv.tv_usec); - if (adj_mode_ == ClockAdjustmentMode::PerDriverPrivate) - { - utc += private_adj_; - } - return utc; - } - - /** - * Adjusts the wall clock. - * Behavior depends on the selected clock adjustment mode - @ref ClockAdjustmentMode. - * Clock adjustment mode can be set only once via constructor. - * - * If the system wide adjustment mode is selected, two ways for performing adjustment exist: - * - Gradual adjustment using adjtime(), if the phase error is less than gradual adjustment limit. - * - Step adjustment using settimeofday(), if the phase error is above gradual adjustment limit. - * The gradual adjustment limit can be configured at any time via the setter method. - * - * @throws uavcan_linux::Exception. - */ - void adjustUtc(const uavcan::UtcDuration adjustment) override - { - if (adj_mode_ == ClockAdjustmentMode::PerDriverPrivate) - { - private_adj_ += adjustment; - } - else - { - assert(private_adj_.isZero()); - assert(!gradual_adj_limit_.isNegative()); - - bool success = false; - if (adjustment.getAbs() < gradual_adj_limit_) - { - success = performGradualAdjustment(adjustment); - } - else - { - success = performStepAdjustment(adjustment); - } - if (!success) - { - throw Exception("Clock adjustment failed"); - } - } - } - - /** - * Sets the maximum phase error to use adjtime(). - * If the phase error exceeds this value, settimeofday() will be used instead. - */ - void setGradualAdjustmentLimit(uavcan::UtcDuration limit) - { - if (limit.isNegative()) - { - limit = uavcan::UtcDuration(); - } - gradual_adj_limit_ = limit; - } - - uavcan::UtcDuration getGradualAdjustmentLimit() const { return gradual_adj_limit_; } - - ClockAdjustmentMode getAdjustmentMode() const { return adj_mode_; } - - /** - * This is only applicable if the selected clock adjustment mode is private. - * In system wide mode this method will always return zero duration. - */ - uavcan::UtcDuration getPrivateAdjustment() const { return private_adj_; } - - /** - * Statistics that allows to evaluate clock sync preformance. - */ - std::uint64_t getStepAdjustmentCount() const { return step_adj_cnt_; } - std::uint64_t getGradualAdjustmentCount() const { return gradual_adj_cnt_; } - std::uint64_t getAdjustmentCount() const - { - return getStepAdjustmentCount() + getGradualAdjustmentCount(); - } - - /** - * This static method decides what is the optimal clock sync adjustment mode for the current configuration. - * It selects system wide mode if the application is running as root; otherwise it prefers - * the private adjustment mode because the system wide mode requires root privileges. - */ - static ClockAdjustmentMode detectPreferredClockAdjustmentMode() - { - const bool godmode = geteuid() == 0; - return godmode ? ClockAdjustmentMode::SystemWide : ClockAdjustmentMode::PerDriverPrivate; - } -}; - -} diff --git a/libuavcan_drivers/linux/include/uavcan_linux/exception.hpp b/libuavcan_drivers/linux/include/uavcan_linux/exception.hpp deleted file mode 100644 index 041d1a196e..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/exception.hpp +++ /dev/null @@ -1,69 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include - -namespace uavcan_linux -{ -/** - * This is the root exception class for all exceptions that can be thrown from the libuavcan Linux driver. - */ -class Exception : public std::runtime_error -{ - const int errno_; - - static std::string makeErrorString(const std::string& descr, int use_errno) - { - return descr + " [errno " + std::to_string(use_errno) + " \"" + std::strerror(use_errno) + "\"]"; - } - -public: - explicit Exception(const std::string& descr, int use_errno = errno) - : std::runtime_error(makeErrorString(descr, use_errno)) - , errno_(use_errno) - { } - - /** - * Returns standard UNIX errno value captured at the moment - * when this exception object was constructed. - */ - int getErrno() const { return errno_; } -}; - -/** - * This type is thrown when a Libuavcan API method exits with error. - * The error code is stored in the exception object and is avialable via @ref getLibuavcanErrorCode(). - */ -class LibuavcanErrorException : public Exception -{ - const std::int16_t error_; - - static std::string makeErrorString(std::int16_t e) - { - return "Libuavcan error (" + std::to_string(e) + ")"; - } - -public: - explicit LibuavcanErrorException(std::int16_t uavcan_error_code) : - Exception(makeErrorString(uavcan_error_code)), - error_(std::abs(uavcan_error_code)) - { } - - std::int16_t getLibuavcanErrorCode() const { return error_; } -}; - -/** - * This exception is thrown when all available interfaces become down. - */ -class AllIfacesDownException : public Exception -{ -public: - AllIfacesDownException() : Exception("All ifaces are down", ENETDOWN) { } -}; - -} diff --git a/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp b/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp deleted file mode 100644 index 10f7c6d38c..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/helpers.hpp +++ /dev/null @@ -1,473 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -namespace uavcan_linux -{ -/** - * Default log sink will dump everything into stderr. - * It is installed by default. - */ -class DefaultLogSink : public uavcan::ILogSink -{ - void log(const uavcan::protocol::debug::LogMessage& message) override - { - const auto tt = std::chrono::system_clock::to_time_t(std::chrono::system_clock::now()); - const auto tstr = std::ctime(&tt); - std::cerr << "### UAVCAN " << tstr << message << std::endl; - } -}; - -/** - * Wrapper over uavcan::ServiceClient<> for blocking calls. - * Blocks on uavcan::Node::spin() internally until the call is complete. - */ -template -class BlockingServiceClient : public uavcan::ServiceClient -{ - typedef uavcan::ServiceClient Super; - - typename DataType::Response response_; - bool call_was_successful_; - - void callback(const uavcan::ServiceCallResult& res) - { - response_ = res.getResponse(); - call_was_successful_ = res.isSuccessful(); - } - - void setup() - { - Super::setCallback(std::bind(&BlockingServiceClient::callback, this, std::placeholders::_1)); - call_was_successful_ = false; - response_ = typename DataType::Response(); - } - -public: - BlockingServiceClient(uavcan::INode& node) - : uavcan::ServiceClient(node) - , call_was_successful_(false) - { - setup(); - } - - /** - * Performs a blocking service call using default timeout (see the specs). - * Use @ref getResponse() to get the actual response. - * Returns negative error code. - */ - int blockingCall(uavcan::NodeID server_node_id, const typename DataType::Request& request) - { - return blockingCall(server_node_id, request, Super::getDefaultRequestTimeout()); - } - - /** - * Performs a blocking service call using the specified timeout. Please consider using default timeout instead. - * Use @ref getResponse() to get the actual response. - * Returns negative error code. - */ - int blockingCall(uavcan::NodeID server_node_id, const typename DataType::Request& request, - uavcan::MonotonicDuration timeout) - { - const auto SpinDuration = uavcan::MonotonicDuration::fromMSec(2); - setup(); - Super::setRequestTimeout(timeout); - const int call_res = Super::call(server_node_id, request); - if (call_res >= 0) - { - while (Super::hasPendingCalls()) - { - const int spin_res = Super::getNode().spin(SpinDuration); - if (spin_res < 0) - { - return spin_res; - } - } - } - return call_res; - } - - /** - * Whether the last blocking call was successful. - */ - bool wasSuccessful() const { return call_was_successful_; } - - /** - * Use this to retrieve the response of the last blocking service call. - * This method returns default constructed response object if the last service call was unsuccessful. - */ - const typename DataType::Response& getResponse() const { return response_; } -}; - -/** - * Contains all drivers needed for uavcan::Node. - */ -struct DriverPack -{ - SystemClock clock; - std::shared_ptr can; - - explicit DriverPack(ClockAdjustmentMode clock_adjustment_mode, - const std::shared_ptr& can_driver) - : clock(clock_adjustment_mode) - , can(can_driver) - { } - - explicit DriverPack(ClockAdjustmentMode clock_adjustment_mode, - const std::vector& iface_names) - : clock(clock_adjustment_mode) - { - std::shared_ptr socketcan(new SocketCanDriver(clock)); - can = socketcan; - for (auto ifn : iface_names) - { - if (socketcan->addIface(ifn) < 0) - { - throw Exception("Failed to add iface " + ifn); - } - } - } -}; - -typedef std::shared_ptr DriverPackPtr; - -typedef std::shared_ptr INodePtr; - -typedef std::shared_ptr TimerPtr; - -template -using SubscriberPtr = std::shared_ptr>; - -template -using PublisherPtr = std::shared_ptr>; - -template -using ServiceServerPtr = std::shared_ptr>; - -template -using ServiceClientPtr = std::shared_ptr>; - -template -using BlockingServiceClientPtr = std::shared_ptr>; - -static constexpr std::size_t NodeMemPoolSize = 1024 * 512; ///< This shall be enough for any possible use case - -/** - * Generic wrapper for node objects with some additional convenience functions. - */ -template -class NodeBase : public NodeType -{ -protected: - DriverPackPtr driver_pack_; - - static void enforce(int error, const std::string& msg) - { - if (error < 0) - { - std::ostringstream os; - os << msg << " [" << error << "]"; - throw Exception(os.str()); - } - } - - template - static std::string getDataTypeName() - { - return DataType::getDataTypeFullName(); - } - -public: - /** - * Simple forwarding constructor, compatible with uavcan::Node. - */ - NodeBase(uavcan::ICanDriver& can_driver, uavcan::ISystemClock& clock) : - NodeType(can_driver, clock) - { } - - /** - * Takes ownership of the driver container via the shared pointer. - */ - explicit NodeBase(DriverPackPtr driver_pack) - : NodeType(*driver_pack->can, driver_pack->clock) - , driver_pack_(driver_pack) - { } - - /** - * Allocates @ref uavcan::Subscriber in the heap using shared pointer. - * The subscriber will be started immediately. - * @throws uavcan_linux::Exception. - */ - template - SubscriberPtr makeSubscriber(const typename uavcan::Subscriber::Callback& cb) - { - SubscriberPtr p(new uavcan::Subscriber(*this)); - enforce(p->start(cb), "Subscriber start failure " + getDataTypeName()); - return p; - } - - /** - * Allocates @ref uavcan::Publisher in the heap using shared pointer. - * The publisher will be initialized immediately. - * @throws uavcan_linux::Exception. - */ - template - PublisherPtr makePublisher(uavcan::MonotonicDuration tx_timeout = - uavcan::Publisher::getDefaultTxTimeout()) - { - PublisherPtr p(new uavcan::Publisher(*this)); - enforce(p->init(), "Publisher init failure " + getDataTypeName()); - p->setTxTimeout(tx_timeout); - return p; - } - - /** - * Allocates @ref uavcan::ServiceServer in the heap using shared pointer. - * The server will be started immediately. - * @throws uavcan_linux::Exception. - */ - template - ServiceServerPtr makeServiceServer(const typename uavcan::ServiceServer::Callback& cb) - { - ServiceServerPtr p(new uavcan::ServiceServer(*this)); - enforce(p->start(cb), "ServiceServer start failure " + getDataTypeName()); - return p; - } - - /** - * Allocates @ref uavcan::ServiceClient in the heap using shared pointer. - * The service client will be initialized immediately. - * @throws uavcan_linux::Exception. - */ - template - ServiceClientPtr makeServiceClient(const typename uavcan::ServiceClient::Callback& cb) - { - ServiceClientPtr p(new uavcan::ServiceClient(*this)); - enforce(p->init(), "ServiceClient init failure " + getDataTypeName()); - p->setCallback(cb); - return p; - } - - /** - * Allocates @ref uavcan_linux::BlockingServiceClient in the heap using shared pointer. - * The service client will be initialized immediately. - * @throws uavcan_linux::Exception. - */ - template - BlockingServiceClientPtr makeBlockingServiceClient() - { - BlockingServiceClientPtr p(new BlockingServiceClient(*this)); - enforce(p->init(), "BlockingServiceClient init failure " + getDataTypeName()); - return p; - } - - /** - * Allocates @ref uavcan::Timer in the heap using shared pointer. - * The timer will be started immediately in one-shot mode. - */ - TimerPtr makeTimer(uavcan::MonotonicTime deadline, const typename uavcan::Timer::Callback& cb) - { - TimerPtr p(new uavcan::Timer(*this)); - p->setCallback(cb); - p->startOneShotWithDeadline(deadline); - return p; - } - - /** - * Allocates @ref uavcan::Timer in the heap using shared pointer. - * The timer will be started immediately in periodic mode. - */ - TimerPtr makeTimer(uavcan::MonotonicDuration period, const typename uavcan::Timer::Callback& cb) - { - TimerPtr p(new uavcan::Timer(*this)); - p->setCallback(cb); - p->startPeriodic(period); - return p; - } - - const DriverPackPtr& getDriverPack() const { return driver_pack_; } - DriverPackPtr& getDriverPack() { return driver_pack_; } -}; - -/** - * Wrapper for uavcan::Node with some additional convenience functions. - * Note that this wrapper adds stderr log sink to @ref uavcan::Logger, which can be removed if needed. - * Do not instantiate this class directly; instead use the factory functions defined below. - */ -class Node : public NodeBase> -{ - typedef NodeBase> Base; - - DefaultLogSink log_sink_; - -public: - /** - * Simple forwarding constructor, compatible with uavcan::Node. - */ - Node(uavcan::ICanDriver& can_driver, uavcan::ISystemClock& clock) : - Base(can_driver, clock) - { - getLogger().setExternalSink(&log_sink_); - } - - /** - * Takes ownership of the driver container via the shared pointer. - */ - explicit Node(DriverPackPtr driver_pack) : - Base(driver_pack) - { - getLogger().setExternalSink(&log_sink_); - } -}; - -/** - * Wrapper for uavcan::SubNode with some additional convenience functions. - * Do not instantiate this class directly; instead use the factory functions defined below. - */ -class SubNode : public NodeBase> -{ - typedef NodeBase> Base; - -public: - /** - * Simple forwarding constructor, compatible with uavcan::Node. - */ - SubNode(uavcan::ICanDriver& can_driver, uavcan::ISystemClock& clock) : Base(can_driver, clock) { } - - /** - * Takes ownership of the driver container via the shared pointer. - */ - explicit SubNode(DriverPackPtr driver_pack) : Base(driver_pack) { } -}; - -typedef std::shared_ptr NodePtr; -typedef std::shared_ptr SubNodePtr; - -/** - * Use this function to create a node instance with default SocketCAN driver. - * It accepts the list of interface names to use for the new node, e.g. "can1", "vcan2", "slcan0". - * Clock adjustment mode will be detected automatically unless provided explicitly. - * @throws uavcan_linux::Exception. - */ -static inline NodePtr makeNode(const std::vector& iface_names, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - DriverPackPtr dp(new DriverPack(clock_adjustment_mode, iface_names)); - return NodePtr(new Node(dp)); -} - -/** - * Use this function to create a node instance with a custom driver. - * Clock adjustment mode will be detected automatically unless provided explicitly. - * @throws uavcan_linux::Exception. - */ -static inline NodePtr makeNode(const std::shared_ptr& can_driver, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - DriverPackPtr dp(new DriverPack(clock_adjustment_mode, can_driver)); - return NodePtr(new Node(dp)); -} - -/** - * This function extends the other two overloads in such a way that it instantiates and initializes - * the node immediately; if initialization fails, it throws. - * - * If NodeID is not provided, it will not be initialized, and therefore the node will be started in - * listen-only (i.e. silent) mode. The node can be switched to normal (i.e. non-silent) mode at any - * later time by calling setNodeID() explicitly. Read the Node class docs for more info. - * - * Clock adjustment mode will be detected automatically unless provided explicitly. - * - * @throws uavcan_linux::Exception, uavcan_linux::LibuavcanErrorException. - */ -template -static inline NodePtr makeNode(const DriverType& driver, - const uavcan::NodeStatusProvider::NodeName& name, - const uavcan::protocol::SoftwareVersion& software_version, - const uavcan::protocol::HardwareVersion& hardware_version, - const uavcan::NodeID node_id = uavcan::NodeID(), - const uavcan::TransferPriority node_status_transfer_priority = - uavcan::TransferPriority::Default, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - NodePtr node = makeNode(driver, clock_adjustment_mode); - - node->setName(name); - node->setSoftwareVersion(software_version); - node->setHardwareVersion(hardware_version); - - if (node_id.isValid()) - { - node->setNodeID(node_id); - } - - const auto res = node->start(node_status_transfer_priority); - if (res < 0) - { - throw LibuavcanErrorException(res); - } - - return node; -} - -/** - * Use this function to create a sub-node instance with default SocketCAN driver. - * It accepts the list of interface names to use for the new node, e.g. "can1", "vcan2", "slcan0". - * Clock adjustment mode will be detected automatically unless provided explicitly. - * @throws uavcan_linux::Exception. - */ -static inline SubNodePtr makeSubNode(const std::vector& iface_names, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - DriverPackPtr dp(new DriverPack(clock_adjustment_mode, iface_names)); - return SubNodePtr(new SubNode(dp)); -} - -/** - * Use this function to create a sub-node instance with a custom driver. - * Clock adjustment mode will be detected automatically unless provided explicitly. - * @throws uavcan_linux::Exception. - */ -static inline SubNodePtr makeSubNode(const std::shared_ptr& can_driver, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - DriverPackPtr dp(new DriverPack(clock_adjustment_mode, can_driver)); - return SubNodePtr(new SubNode(dp)); -} - -/** - * This function extends the other two overloads in such a way that it instantiates the node - * and sets its Node ID immediately. - * - * Clock adjustment mode will be detected automatically unless provided explicitly. - * - * @throws uavcan_linux::Exception, uavcan_linux::LibuavcanErrorException. - */ -template -static inline SubNodePtr makeSubNode(const DriverType& driver, - const uavcan::NodeID node_id, - ClockAdjustmentMode clock_adjustment_mode = - SystemClock::detectPreferredClockAdjustmentMode()) -{ - SubNodePtr sub_node = makeSubNode(driver, clock_adjustment_mode); - sub_node->setNodeID(node_id); - return sub_node; -} - -} diff --git a/libuavcan_drivers/linux/include/uavcan_linux/socketcan.hpp b/libuavcan_drivers/linux/include/uavcan_linux/socketcan.hpp deleted file mode 100644 index ef3c727b23..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/socketcan.hpp +++ /dev/null @@ -1,804 +0,0 @@ -/* - * Copyright (C) 2014-2015 Pavel Kirienko - * Ilia Sheremet - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - - -namespace uavcan_linux -{ -/** - * SocketCan driver class keeps number of each kind of errors occurred since the object was created. - */ -enum class SocketCanError -{ - SocketReadFailure, - SocketWriteFailure, - TxTimeout -}; - -/** - * Single SocketCAN socket interface. - * - * SocketCAN socket adapter maintains TX and RX queues in user space. At any moment socket's buffer contains - * no more than 'max_frames_in_socket_tx_queue_' TX frames, rest is waiting in the user space TX queue; when the - * socket produces loopback for the previously sent TX frame the next frame from the user space TX queue will - * be sent into the socket. - * - * This approach allows to properly maintain TX timeouts (http://stackoverflow.com/questions/19633015/). - * TX timestamping is implemented by means of reading RX timestamps of loopback frames (see "TX timestamping" on - * linux-can mailing list, http://permalink.gmane.org/gmane.linux.can/5322). - * - * Note that if max_frames_in_socket_tx_queue_ is greater than one, frame reordering may occur (depending on the - * unrderlying logic). - * - * This class is too complex and needs to be refactored later. At least, basic socket IO and configuration - * should be extracted into a different class. - */ -class SocketCanIface : public uavcan::ICanIface -{ - static inline ::can_frame makeSocketCanFrame(const uavcan::CanFrame& uavcan_frame) - { - ::can_frame sockcan_frame = ::can_frame(); - sockcan_frame.can_id = uavcan_frame.id & uavcan::CanFrame::MaskExtID; - sockcan_frame.can_dlc = uavcan_frame.dlc; - (void)std::copy(uavcan_frame.data, uavcan_frame.data + uavcan_frame.dlc, sockcan_frame.data); - if (uavcan_frame.isExtended()) - { - sockcan_frame.can_id |= CAN_EFF_FLAG; - } - if (uavcan_frame.isErrorFrame()) - { - sockcan_frame.can_id |= CAN_ERR_FLAG; - } - if (uavcan_frame.isRemoteTransmissionRequest()) - { - sockcan_frame.can_id |= CAN_RTR_FLAG; - } - return sockcan_frame; - } - - static inline uavcan::CanFrame makeUavcanFrame(const ::can_frame& sockcan_frame) - { - uavcan::CanFrame uavcan_frame(sockcan_frame.can_id & CAN_EFF_MASK, sockcan_frame.data, sockcan_frame.can_dlc); - if (sockcan_frame.can_id & CAN_EFF_FLAG) - { - uavcan_frame.id |= uavcan::CanFrame::FlagEFF; - } - if (sockcan_frame.can_id & CAN_ERR_FLAG) - { - uavcan_frame.id |= uavcan::CanFrame::FlagERR; - } - if (sockcan_frame.can_id & CAN_RTR_FLAG) - { - uavcan_frame.id |= uavcan::CanFrame::FlagRTR; - } - return uavcan_frame; - } - - struct TxItem - { - uavcan::CanFrame frame; - uavcan::MonotonicTime deadline; - uavcan::CanIOFlags flags = 0; - std::uint64_t order = 0; - - TxItem(const uavcan::CanFrame& arg_frame, uavcan::MonotonicTime arg_deadline, - uavcan::CanIOFlags arg_flags, std::uint64_t arg_order) - : frame(arg_frame) - , deadline(arg_deadline) - , flags(arg_flags) - , order(arg_order) - { } - - bool operator<(const TxItem& rhs) const - { - if (frame.priorityLowerThan(rhs.frame)) - { - return true; - } - if (frame.priorityHigherThan(rhs.frame)) - { - return false; - } - return order > rhs.order; - } - }; - - struct RxItem - { - uavcan::CanFrame frame; - uavcan::MonotonicTime ts_mono; - uavcan::UtcTime ts_utc; - uavcan::CanIOFlags flags; - - RxItem() - : flags(0) - { } - }; - - const SystemClock& clock_; - const int fd_; - - const unsigned max_frames_in_socket_tx_queue_; - unsigned frames_in_socket_tx_queue_ = 0; - - std::uint64_t tx_frame_counter_ = 0; ///< Increments with every frame pushed into the TX queue - - std::map errors_; - - std::priority_queue tx_queue_; // TODO: Use pool allocator - std::queue rx_queue_; // TODO: Use pool allocator - std::unordered_multiset pending_loopback_ids_; // TODO: Use pool allocator - - std::vector<::can_filter> hw_filters_container_; - - void registerError(SocketCanError e) { errors_[e]++; } - - void incrementNumFramesInSocketTxQueue() - { - assert(frames_in_socket_tx_queue_ < max_frames_in_socket_tx_queue_); - frames_in_socket_tx_queue_++; - } - - void confirmSentFrame() - { - if (frames_in_socket_tx_queue_ > 0) - { - frames_in_socket_tx_queue_--; - } - else - { - assert(0); // Loopback for a frame that we didn't send. - } - } - - bool wasInPendingLoopbackSet(const uavcan::CanFrame& frame) - { - if (pending_loopback_ids_.count(frame.id) > 0) - { - (void)pending_loopback_ids_.erase(frame.id); - return true; - } - return false; - } - - int write(const uavcan::CanFrame& frame) const - { - errno = 0; - - const ::can_frame sockcan_frame = makeSocketCanFrame(frame); - - const int res = ::write(fd_, &sockcan_frame, sizeof(sockcan_frame)); - if (res <= 0) - { - if (errno == ENOBUFS || errno == EAGAIN) // Writing is not possible atm, not an error - { - return 0; - } - return res; - } - if (res != sizeof(sockcan_frame)) - { - return -1; - } - return 1; - } - - /** - * SocketCAN git show 1e55659ce6ddb5247cee0b1f720d77a799902b85 - * MSG_DONTROUTE is set for any packet from localhost, - * MSG_CONFIRM is set for any pakcet of your socket. - * Diff: https://git.ucsd.edu/abuss/linux/commit/1e55659ce6ddb5247cee0b1f720d77a799902b85 - * Man: https://www.kernel.org/doc/Documentation/networking/can.txt (chapter 4.1.6). - */ - int read(uavcan::CanFrame& frame, uavcan::UtcTime& ts_utc, bool& loopback) const - { - auto iov = ::iovec(); - auto sockcan_frame = ::can_frame(); - iov.iov_base = &sockcan_frame; - iov.iov_len = sizeof(sockcan_frame); - - static constexpr size_t ControlSize = sizeof(cmsghdr) + sizeof(::timeval); - using ControlStorage = typename std::aligned_storage::type; - ControlStorage control_storage; - auto control = reinterpret_cast(&control_storage); - std::fill(control, control + ControlSize, 0x00); - - auto msg = ::msghdr(); - msg.msg_iov = &iov; - msg.msg_iovlen = 1; - msg.msg_control = control; - msg.msg_controllen = ControlSize; - - const int res = ::recvmsg(fd_, &msg, MSG_DONTWAIT); - if (res <= 0) - { - return (res < 0 && errno == EWOULDBLOCK) ? 0 : res; - } - /* - * Flags - */ - loopback = (msg.msg_flags & static_cast(MSG_CONFIRM)) != 0; - - if (!loopback && !checkHWFilters(sockcan_frame)) - { - return 0; - } - - frame = makeUavcanFrame(sockcan_frame); - /* - * Timestamp - */ - const ::cmsghdr* const cmsg = CMSG_FIRSTHDR(&msg); - assert(cmsg != nullptr); - if (cmsg->cmsg_level == SOL_SOCKET && cmsg->cmsg_type == SO_TIMESTAMP) - { - auto tv = ::timeval(); - (void)std::memcpy(&tv, CMSG_DATA(cmsg), sizeof(tv)); // Copy to avoid alignment problems - assert(tv.tv_sec >= 0 && tv.tv_usec >= 0); - ts_utc = uavcan::UtcTime::fromUSec(std::uint64_t(tv.tv_sec) * 1000000ULL + tv.tv_usec); - } - else - { - assert(0); - return -1; - } - return 1; - } - - void pollWrite() - { - while (hasReadyTx()) - { - const TxItem tx = tx_queue_.top(); - - if (tx.deadline >= clock_.getMonotonic()) - { - const int res = write(tx.frame); - if (res == 1) // Transmitted successfully - { - incrementNumFramesInSocketTxQueue(); - if (tx.flags & uavcan::CanIOFlagLoopback) - { - (void)pending_loopback_ids_.insert(tx.frame.id); - } - } - else if (res == 0) // Not transmitted, nor is it an error - { - break; // Leaving the loop, the frame remains enqueued for the next retry - } - else // Transmission error - { - registerError(SocketCanError::SocketWriteFailure); - } - } - else - { - registerError(SocketCanError::TxTimeout); - } - - // Removing the frame from the queue even if transmission failed - tx_queue_.pop(); - } - } - - void pollRead() - { - while (true) - { - RxItem rx; - rx.ts_mono = clock_.getMonotonic(); // Monotonic timestamp is not required to be precise (unlike UTC) - bool loopback = false; - const int res = read(rx.frame, rx.ts_utc, loopback); - if (res == 1) - { - assert(!rx.ts_utc.isZero()); - bool accept = true; - if (loopback) // We receive loopback for all CAN frames - { - confirmSentFrame(); - rx.flags |= uavcan::CanIOFlagLoopback; - accept = wasInPendingLoopbackSet(rx.frame); // Do we need to send this loopback into the lib? - } - if (accept) - { - rx.ts_utc += clock_.getPrivateAdjustment(); - rx_queue_.push(rx); - } - } - else if (res == 0) - { - break; - } - else - { - registerError(SocketCanError::SocketReadFailure); - break; - } - } - } - - /** - * Returns true if a frame accepted by HW filters - */ - bool checkHWFilters(const ::can_frame& frame) const - { - if (!hw_filters_container_.empty()) - { - for (auto& f : hw_filters_container_) - { - if (((frame.can_id & f.can_mask) ^ f.can_id) == 0) - { - return true; - } - } - return false; - } - else - { - return true; - } - } - -public: - /** - * Takes ownership of socket's file descriptor. - * - * @ref max_frames_in_socket_tx_queue See a note in the class comment. - */ - SocketCanIface(const SystemClock& clock, int socket_fd, int max_frames_in_socket_tx_queue = 2) - : clock_(clock) - , fd_(socket_fd) - , max_frames_in_socket_tx_queue_(max_frames_in_socket_tx_queue) - { - assert(fd_ >= 0); - } - - /** - * Socket file descriptor will be closed. - */ - virtual ~SocketCanIface() - { - UAVCAN_TRACE("SocketCAN", "SocketCanIface: Closing fd %d", fd_); - (void)::close(fd_); - } - - /** - * Assumes that the socket is writeable - */ - std::int16_t send(const uavcan::CanFrame& frame, const uavcan::MonotonicTime tx_deadline, - const uavcan::CanIOFlags flags) override - { - tx_queue_.emplace(frame, tx_deadline, flags, tx_frame_counter_); - tx_frame_counter_++; - pollRead(); // Read poll is necessary because it can release the pending TX flag - pollWrite(); - return 1; - } - - /** - * Will read the socket only if RX queue is empty. - * Normally, poll() needs to be executed first. - */ - std::int16_t receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags) override - { - if (rx_queue_.empty()) - { - pollRead(); // This allows to use the socket not calling poll() explicitly. - if (rx_queue_.empty()) - { - return 0; - } - } - { - const RxItem& rx = rx_queue_.front(); - out_frame = rx.frame; - out_ts_monotonic = rx.ts_mono; - out_ts_utc = rx.ts_utc; - out_flags = rx.flags; - } - rx_queue_.pop(); - return 1; - } - - /** - * Performs socket read/write. - * @param read Socket is readable - * @param write Socket is writeable - */ - void poll(bool read, bool write) - { - if (read) - { - pollRead(); // Read poll must be executed first because it may decrement frames_in_socket_tx_queue_ - } - if (write) - { - pollWrite(); - } - } - - bool hasReadyRx() const { return !rx_queue_.empty(); } - bool hasReadyTx() const - { - return !tx_queue_.empty() && (frames_in_socket_tx_queue_ < max_frames_in_socket_tx_queue_); - } - - std::int16_t configureFilters(const uavcan::CanFilterConfig* const filter_configs, - const std::uint16_t num_configs) override - { - if (filter_configs == nullptr) - { - assert(0); - return -1; - } - hw_filters_container_.clear(); - hw_filters_container_.resize(num_configs); - - for (unsigned i = 0; i < num_configs; i++) - { - const uavcan::CanFilterConfig& fc = filter_configs[i]; - hw_filters_container_[i].can_id = fc.id & uavcan::CanFrame::MaskExtID; - hw_filters_container_[i].can_mask = fc.mask & uavcan::CanFrame::MaskExtID; - if (fc.id & uavcan::CanFrame::FlagEFF) - { - hw_filters_container_[i].can_id |= CAN_EFF_FLAG; - } - if (fc.id & uavcan::CanFrame::FlagRTR) - { - hw_filters_container_[i].can_id |= CAN_RTR_FLAG; - } - if (fc.mask & uavcan::CanFrame::FlagEFF) - { - hw_filters_container_[i].can_mask |= CAN_EFF_FLAG; - } - if (fc.mask & uavcan::CanFrame::FlagRTR) - { - hw_filters_container_[i].can_mask |= CAN_RTR_FLAG; - } - } - - return 0; - } - - /** - * SocketCAN emulates the CAN filters in software, so the number of filters is virtually unlimited. - * This method returns a constant value. - */ - static constexpr unsigned NumFilters = 8; - std::uint16_t getNumFilters() const override { return NumFilters; } - - - /** - * Returns total number of errors of each kind detected since the object was created. - */ - std::uint64_t getErrorCount() const override - { - std::uint64_t ec = 0; - for (auto& kv : errors_) { ec += kv.second; } - return ec; - } - - /** - * Returns number of errors of each kind in a map. - */ - const decltype(errors_) & getErrors() const { return errors_; } - - int getFileDescriptor() const { return fd_; } - - /** - * Open and configure a CAN socket on iface specified by name. - * @param iface_name String containing iface name, e.g. "can0", "vcan1", "slcan0" - * @return Socket descriptor or negative number on error. - */ - static int openSocket(const std::string& iface_name) - { - errno = 0; - - const int s = ::socket(PF_CAN, SOCK_RAW, CAN_RAW); - if (s < 0) - { - return s; - } - - class RaiiCloser - { - int fd_; - public: - RaiiCloser(int filedesc) : fd_(filedesc) - { - assert(fd_ >= 0); - } - ~RaiiCloser() - { - if (fd_ >= 0) - { - UAVCAN_TRACE("SocketCAN", "RaiiCloser: Closing fd %d", fd_); - (void)::close(fd_); - } - } - void disarm() { fd_ = -1; } - } raii_closer(s); - - // Detect the iface index - auto ifr = ::ifreq(); - if (iface_name.length() >= IFNAMSIZ) - { - errno = ENAMETOOLONG; - return -1; - } - (void)std::strncpy(ifr.ifr_name, iface_name.c_str(), iface_name.length()); - if (::ioctl(s, SIOCGIFINDEX, &ifr) < 0 || ifr.ifr_ifindex < 0) - { - return -1; - } - - // Bind to the specified CAN iface - { - auto addr = ::sockaddr_can(); - addr.can_family = AF_CAN; - addr.can_ifindex = ifr.ifr_ifindex; - if (::bind(s, reinterpret_cast(&addr), sizeof(addr)) < 0) - { - return -1; - } - } - - // Configure - { - const int on = 1; - // Timestamping - if (::setsockopt(s, SOL_SOCKET, SO_TIMESTAMP, &on, sizeof(on)) < 0) - { - return -1; - } - // Socket loopback - if (::setsockopt(s, SOL_CAN_RAW, CAN_RAW_RECV_OWN_MSGS, &on, sizeof(on)) < 0) - { - return -1; - } - // Non-blocking - if (::fcntl(s, F_SETFL, O_NONBLOCK) < 0) - { - return -1; - } - } - - // Validate the resulting socket - { - int socket_error = 0; - ::socklen_t errlen = sizeof(socket_error); - (void)::getsockopt(s, SOL_SOCKET, SO_ERROR, reinterpret_cast(&socket_error), &errlen); - if (socket_error != 0) - { - errno = socket_error; - return -1; - } - } - - raii_closer.disarm(); - return s; - } -}; - -/** - * Multiplexing container for multiple SocketCAN sockets. - * Uses ppoll() for multiplexing. - * - * When an interface becomes down/disconnected while the node is running, - * the driver will silently exclude it from the IO loop and continue to run on the remaining interfaces. - * When all interfaces become down/disconnected, the driver will throw @ref AllIfacesDownException - * from @ref SocketCanDriver::select(). - * Whether a certain interface is down can be checked with @ref SocketCanDriver::isIfaceDown(). - */ -class SocketCanDriver : public uavcan::ICanDriver -{ - class IfaceWrapper : public SocketCanIface - { - bool down_ = false; - - public: - IfaceWrapper(const SystemClock& clock, int fd) : SocketCanIface(clock, fd) { } - - void updateDownStatusFromPollResult(const ::pollfd& pfd) - { - assert(pfd.fd == this->getFileDescriptor()); - if (!down_ && (pfd.revents & POLLERR)) - { - int error = 0; - ::socklen_t errlen = sizeof(error); - (void)::getsockopt(pfd.fd, SOL_SOCKET, SO_ERROR, reinterpret_cast(&error), &errlen); - - down_ = error == ENETDOWN || error == ENODEV; - - UAVCAN_TRACE("SocketCAN", "Iface %d is dead; error %d", this->getFileDescriptor(), error); - } - } - - bool isDown() const { return down_; } - }; - - const SystemClock& clock_; - std::vector> ifaces_; - -public: - /** - * Reference to the clock object shall remain valid. - */ - explicit SocketCanDriver(const SystemClock& clock) - : clock_(clock) - { - ifaces_.reserve(uavcan::MaxCanIfaces); - } - - /** - * This function may return before deadline expiration even if no requested IO operations become possible. - * This behavior makes implementation way simpler, and it is OK since libuavcan can properly handle such - * early returns. - * Also it can return more events than were originally requested by uavcan, which is also acceptable. - */ - std::int16_t select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces], - uavcan::MonotonicTime blocking_deadline) override - { - // Detecting whether we need to block at all - bool need_block = (inout_masks.write == 0); // Write queue is infinite - for (unsigned i = 0; need_block && (i < ifaces_.size()); i++) - { - const bool need_read = inout_masks.read & (1 << i); - if (need_read && ifaces_[i]->hasReadyRx()) - { - need_block = false; - } - } - - if (need_block) - { - // Poll FD set setup - ::pollfd pollfds[uavcan::MaxCanIfaces] = {}; - unsigned num_pollfds = 0; - IfaceWrapper* pollfd_index_to_iface[uavcan::MaxCanIfaces] = { }; - - for (unsigned i = 0; i < ifaces_.size(); i++) - { - if (!ifaces_[i]->isDown()) - { - pollfds[num_pollfds].fd = ifaces_[i]->getFileDescriptor(); - pollfds[num_pollfds].events = POLLIN; - if (ifaces_[i]->hasReadyTx() || (inout_masks.write & (1U << i))) - { - pollfds[num_pollfds].events |= POLLOUT; - } - pollfd_index_to_iface[num_pollfds] = ifaces_[i].get(); - num_pollfds++; - } - } - - // This is where we abort when the last iface goes down - if (num_pollfds == 0) - { - throw AllIfacesDownException(); - } - - // Timeout conversion - const std::int64_t timeout_usec = (blocking_deadline - clock_.getMonotonic()).toUSec(); - auto ts = ::timespec(); - if (timeout_usec > 0) - { - ts.tv_sec = timeout_usec / 1000000LL; - ts.tv_nsec = (timeout_usec % 1000000LL) * 1000; - } - - // Blocking here - const int res = ::ppoll(pollfds, num_pollfds, &ts, nullptr); - if (res < 0) - { - return res; - } - - // Handling poll output - for (unsigned i = 0; i < num_pollfds; i++) - { - pollfd_index_to_iface[i]->updateDownStatusFromPollResult(pollfds[i]); - - const bool poll_read = pollfds[i].revents & POLLIN; - const bool poll_write = pollfds[i].revents & POLLOUT; - pollfd_index_to_iface[i]->poll(poll_read, poll_write); - } - } - - // Writing the output masks - inout_masks = uavcan::CanSelectMasks(); - for (unsigned i = 0; i < ifaces_.size(); i++) - { - if (!ifaces_[i]->isDown()) - { - inout_masks.write |= std::uint8_t(1U << i); // Always ready to write if not down - } - if (ifaces_[i]->hasReadyRx()) - { - inout_masks.read |= std::uint8_t(1U << i); // Readability depends only on RX buf, even if down - } - } - - // Return value is irrelevant as long as it's non-negative - return ifaces_.size(); - } - - SocketCanIface* getIface(std::uint8_t iface_index) override - { - return (iface_index >= ifaces_.size()) ? nullptr : ifaces_[iface_index].get(); - } - - std::uint8_t getNumIfaces() const override { return ifaces_.size(); } - - /** - * Adds one iface by name. Will fail if there are @ref MaxIfaces ifaces registered already. - * @param iface_name E.g. "can0", "vcan1" - * @return Negative on error, interface index on success. - * @throws uavcan_linux::Exception. - */ - int addIface(const std::string& iface_name) - { - if (ifaces_.size() >= uavcan::MaxCanIfaces) - { - return -1; - } - - // Open the socket - const int fd = SocketCanIface::openSocket(iface_name); - if (fd < 0) - { - return fd; - } - - // Construct the iface - upon successful construction the iface will take ownership of the fd. - try - { - ifaces_.emplace_back(new IfaceWrapper(clock_, fd)); - } - catch (...) - { - (void)::close(fd); - throw; - } - - UAVCAN_TRACE("SocketCAN", "New iface '%s' fd %d", iface_name.c_str(), fd); - - return ifaces_.size() - 1; - } - - /** - * Returns false if the specified interface is functioning, true if it became unavailable. - */ - bool isIfaceDown(std::uint8_t iface_index) const - { - return ifaces_.at(iface_index)->isDown(); - } -}; - -} diff --git a/libuavcan_drivers/linux/include/uavcan_linux/system_utils.hpp b/libuavcan_drivers/linux/include/uavcan_linux/system_utils.hpp deleted file mode 100644 index 7e1eae9940..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/system_utils.hpp +++ /dev/null @@ -1,177 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -namespace uavcan_linux -{ -/** - * This class can find and read machine ID from a text file, represented as 32-char (16-byte) long hexadecimal string, - * possibly with separators (like dashes or colons). If the available ID is more than 16 bytes, extra bytes will be - * ignored. A shorter ID will not be accepted as valid. - * In order to be read, the ID must be located on the first line of the file and must not contain any whitespace - * characters. - * - * Examples of valid ID: - * 0123456789abcdef0123456789abcdef - * 20CE0b1E-8C03-07C8-13EC-00242C491652 - */ -class MachineIDReader -{ -public: - static constexpr int MachineIDSize = 16; - - typedef std::array MachineID; - - static std::vector getDefaultSearchLocations() - { - return - { - "/etc/machine-id", - "/var/lib/dbus/machine-id", - "/sys/class/dmi/id/product_uuid" - }; - } - -private: - const std::vector search_locations_; - - static std::vector mergeLists(const std::vector& a, const std::vector& b) - { - std::vector ab; - ab.reserve(a.size() + b.size()); - ab.insert(ab.end(), a.begin(), a.end()); - ab.insert(ab.end(), b.begin(), b.end()); - return ab; - } - - bool tryRead(const std::string& location, MachineID& out_id) const - { - /* - * Reading the file - */ - std::string token; - try - { - std::ifstream infile(location); - infile >> token; - } - catch (std::exception&) - { - return false; - } - - /* - * Preprocessing the input string - convert to lowercase, remove all non-hex characters, limit to 32 chars - */ - std::transform(token.begin(), token.end(), token.begin(), [](char x) { return std::tolower(x); }); - token.erase(std::remove_if(token.begin(), token.end(), - [](char x){ return (x < 'a' || x > 'f') && !std::isdigit(x); }), - token.end()); - - if (token.length() < (MachineIDSize * 2)) - { - return false; - } - token.resize(MachineIDSize * 2); // Truncating - - /* - * Parsing the string as hex bytes - */ - auto sym = std::begin(token); - for (auto& byte : out_id) - { - assert(sym != std::end(token)); - byte = std::stoi(std::string{*sym++, *sym++}, nullptr, 16); - } - - return true; - } - -public: - /** - * This class can use extra seach locations. If provided, they will be checked first, before default ones. - */ - MachineIDReader(const std::vector& extra_search_locations = {}) - : search_locations_(mergeLists(extra_search_locations, getDefaultSearchLocations())) - { } - - /** - * Just like @ref readAndGetLocation(), but this one doesn't return location where this ID was obtained from. - */ - MachineID read() const { return readAndGetLocation().first; } - - /** - * This function checks available search locations and reads the ID from the first valid location. - * It returns std::pair<> with ID and the file path where it was read from. - * In case if none of the search locations turned out to be valid, @ref uavcan_linux::Exception will be thrown. - */ - std::pair readAndGetLocation() const - { - for (auto x : search_locations_) - { - auto out = MachineID(); - if (tryRead(x, out)) - { - return {out, x}; - } - } - throw Exception("Failed to read machine ID"); - } -}; - -/** - * This class computes unique ID for a UAVCAN node in a Linux application. - * It takes the following inputs: - * - Unique machine ID - * - Node name string (e.g. "org.uavcan.linux_app.dynamic_node_id_server") - * - Instance ID byte, e.g. node ID (optional) - */ -inline std::array makeApplicationID(const MachineIDReader::MachineID& machine_id, - const std::string& node_name, - const std::uint8_t instance_id = 0) -{ - union HalfID - { - std::uint64_t num; - std::uint8_t bytes[8]; - - HalfID(std::uint64_t arg_num) : num(arg_num) { } - }; - - std::array out; - - // First 8 bytes of the application ID are CRC64 of the machine ID in native byte order - { - uavcan::DataTypeSignatureCRC crc; - crc.add(machine_id.data(), static_cast(machine_id.size())); - HalfID half(crc.get()); - std::copy_n(half.bytes, 8, out.begin()); - } - - // Last 8 bytes of the application ID are CRC64 of the node name and optionally node ID - { - uavcan::DataTypeSignatureCRC crc; - crc.add(reinterpret_cast(node_name.c_str()), static_cast(node_name.length())); - crc.add(instance_id); - HalfID half(crc.get()); - std::copy_n(half.bytes, 8, out.begin() + 8); - } - - return out; -} - -} diff --git a/libuavcan_drivers/linux/include/uavcan_linux/uavcan_linux.hpp b/libuavcan_drivers/linux/include/uavcan_linux/uavcan_linux.hpp deleted file mode 100644 index 4886fa66bd..0000000000 --- a/libuavcan_drivers/linux/include/uavcan_linux/uavcan_linux.hpp +++ /dev/null @@ -1,12 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -#include -#include -#include -#include diff --git a/libuavcan_drivers/linux/scripts/uavcan_add_slcan b/libuavcan_drivers/linux/scripts/uavcan_add_slcan deleted file mode 100755 index 38c6883e73..0000000000 --- a/libuavcan_drivers/linux/scripts/uavcan_add_slcan +++ /dev/null @@ -1,173 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2014 Pavel Kirienko -# - -HELP="Register slcan-enabled Serial-to-CAN adapters as network interfaces. -Usage: - `basename $0` [options] [[options] ...] - -Interface indexes will be assigned automatically in ascending order, i.e. -first device will be mapped to the interface slcan0, second will be mapped to -slcan1, and so on. Each added option affects only the interfaces that follow -it, which means that options must be properly ordered (see examples below). -This tool requires superuser priveleges. - -The package 'can-utils' must be installed. On Debian/Ubuntu-based systems it -can be installed via APT: apt-get install can-utils - -Options: - --speed-code (where X is a number in range [0, 8]; default: 8) - -s - Set CAN speed to: - 0 - 10 Kbps - 1 - 20 Kbps - 2 - 50 Kbps - 3 - 100 Kbps - 4 - 125 Kbps (UAVCAN recommended) - 5 - 250 Kbps (UAVCAN recommended) - 6 - 500 Kbps (UAVCAN recommended) - 7 - 800 Kbps - 8 - 1 Mbps (UAVCAN recommended, default) - - --remove-all - -r - Remove all SLCAN interfaces. - If this option is used, it MUST be provided FIRST, otherwise it - will remove the interfaces added earlier. - - --basename (where X is a string containing [a-z], default: slcan) - -b - Base name to use for the interfaces that follow this option. - Default value is 'slcan'. This option can be provided multiple times, - it will only affect the interfaces that were provided after it. If you - want to affect all added interfaces, provide this option first (see - examples below). - - --baudrate (where X is an integer, default: 921600) - -S - Configure baud rate to use on the interface. - This option is mostly irrelevant for USB to CAN adapters. - -Example 1: - `basename $0` --remove-all /dev/ttyUSB3 --basename can --baudrate 115200 \\ - /dev/ttyUSB0 --speed-code 4 /dev/ttyACM0 -The example above initializes the interfaces as follows: - /dev/ttyUSB3 --> slcan0 1 Mbps baudrate 921600 - /dev/ttyUSB0 --> can0 1 Mbps baudrate 115200 - /dev/ttyACM0 --> can1 125 kbps baudrate 115200 - -Example 2: - `basename $0` --remove-all -The example above only removes all SLCAN interfaces without adding new ones." - -function die() { echo $@ >&2; exit 1; } - -if [ "$1" == '--help' ] || [ "$1" == '-h' ]; then echo "$HELP"; exit; fi - -[ -n "$1" ] || die "Invalid usage. Use --help to get help." - -[ "$(id -u)" == "0" ] || die "Must be root." - -which slcan_attach > /dev/null || die "Please install can-utils first." - -# --------------------------------------------------------- - -function deinitialize() { - echo "Stopping slcand..." >&2 - # Trying SIGINT first - killall -INT slcand &> /dev/null - sleep 0.3 - # Then trying the default signal, which is SIGTERM, if SIGINT didn't help - slcand_kill_retries=10 - while killall slcand &> /dev/null - do - (( slcand_kill_retries -= 1 )) - [[ "$slcand_kill_retries" > 0 ]] || die "Failed to stop slcand" - sleep 1 - done -} - -function handle_tty() { - tty=$(readlink -f $1) - tty=${tty/'/dev/'} - - iface_index=0 - while ifconfig "$IFACE_BASENAME$iface_index" &> /dev/null - do - iface_index=$((iface_index + 1)) - done - - slcan_iface_index=0 - while ifconfig "slcan$slcan_iface_index" &> /dev/null - do - slcan_iface_index=$((slcan_iface_index + 1)) - done - - iface="$IFACE_BASENAME$iface_index" - slcan_iface="slcan$slcan_iface_index" - - echo "Attaching $tty to $iface speed code $SPEED_CODE baudrate $BAUDRATE" >&2 - - # Configuring the baudrate - stty -F /dev/$tty ispeed $BAUDRATE ospeed $BAUDRATE || return 1 - - # Attaching the line discipline. Note that slcan_attach has option -n but it doesn't work. - slcan_attach -f -o -s$SPEED_CODE /dev/$tty > /dev/null || return 2 - slcand $tty || return 3 - sleep 1 # FIXME - - # ...therefore we need to rename the interface manually - ip link set $slcan_iface name $iface - - ifconfig $iface up || return 4 -} - -IFACE_BASENAME='slcan' -SPEED_CODE=8 -BAUDRATE=921600 - -next_option='' -while [ -n "$1" ]; do - case $1 in - -r | --remove-all) - deinitialize - ;; - - -b*) - IFACE_BASENAME=${1:2} - ;; - - -S*) - BAUDRATE=${1:2} - ;; - - -s[0-8]) - SPEED_CODE=${1:2} - ;; - - --*) - next_option=${1:2} - ;; - - -*) - die "Invalid option: $1" - ;; - - *) - if [ "$next_option" = 'basename' ]; then IFACE_BASENAME=$1 - elif [ "$next_option" = 'speed-code' ]; then SPEED_CODE=$1 - elif [ "$next_option" = 'baudrate' ]; then BAUDRATE=$1 - elif [ "$next_option" = '' ] - then - handle_tty $1 || die "Failed to configure the interface $1" - else - die "Invalid option '$next_option'" - fi - next_option='' - ;; - esac - shift -done - -[ "$next_option" = '' ] || die "Expected argument for option '$next_option'" diff --git a/libuavcan_drivers/linux/scripts/uavcan_add_vcan b/libuavcan_drivers/linux/scripts/uavcan_add_vcan deleted file mode 100755 index 138007927f..0000000000 --- a/libuavcan_drivers/linux/scripts/uavcan_add_vcan +++ /dev/null @@ -1,36 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2014 Pavel Kirienko -# - -HELP="Initializes and brings up a virtual CAN interface. -Usage: - `basename $0` -Example: - `basename $0` vcan0" - -function die() { echo $@ >&2; exit 1; } - -if [ "$1" == '--help' ] || [ "$1" == '-h' ]; then echo "$HELP"; exit; fi -[ -n "$1" ] || die "Invalid usage. Use --help to get help." -[ "$(id -u)" == "0" ] || die "Must be root" - -# --------------------------------------------------------- - -IFACE="$1" - -ip link show $IFACE > /dev/null -if [ $? == 0 ]; then - ip link set up $IFACE - exit -fi - -modprobe can -modprobe can_raw -modprobe can_bcm -modprobe vcan - -ip link add dev $IFACE type vcan -ip link set up $IFACE - -echo "New iface $IFACE added successfully. To delete: ip link delete $IFACE" diff --git a/libuavcan_drivers/lpc11c24/driver/include.mk b/libuavcan_drivers/lpc11c24/driver/include.mk deleted file mode 100644 index f47e698f01..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/include.mk +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright (C) 2014 Pavel Kirienko -# - -LIBUAVCAN_LPC11C24_DIR := $(dir $(lastword $(MAKEFILE_LIST))) - -LIBUAVCAN_LPC11C24_SRC := $(shell find $(LIBUAVCAN_LPC11C24_DIR)/src -type f -name '*.cpp') - -LIBUAVCAN_LPC11C24_INC := $(LIBUAVCAN_LPC11C24_DIR)/include/ diff --git a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp b/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp deleted file mode 100644 index 35de4619be..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/can.hpp +++ /dev/null @@ -1,93 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -namespace uavcan_lpc11c24 -{ -/** - * This class implements CAN driver interface for libuavcan. - * No configuration needed other than CAN baudrate. - * This class is a singleton. - */ -class CanDriver - : public uavcan::ICanDriver - , public uavcan::ICanIface - , uavcan::Noncopyable -{ - static CanDriver self; - - CanDriver() { } - -public: - /** - * Returns the singleton reference. - * No other copies can be created. - */ - static CanDriver& instance() { return self; } - - /** - * Attempts to detect bit rate of the CAN bus. - * This function may block for up to X seconds, where X is the number of bit rates to try. - * This function is NOT guaranteed to reset the CAN controller upon return. - * @return On success: detected bit rate, in bits per second. - * On failure: zero. - */ - static uavcan::uint32_t detectBitRate(void (*idle_callback)() = nullptr); - - /** - * Returns negative value if the requested baudrate can't be used. - * Returns zero if OK. - */ - int init(uavcan::uint32_t bitrate); - - bool hasReadyRx() const; - bool hasEmptyTx() const; - - /** - * This method will return true only if there was any CAN bus activity since previous call of this method. - * This is intended to be used for LED iface activity indicators. - */ - bool hadActivity(); - - /** - * Returns the number of times the RX queue was overrun. - */ - uavcan::uint32_t getRxQueueOverflowCount() const; - - /** - * Whether the controller is currently in bus off state. - * Note that the driver recovers the CAN controller from the bus off state automatically! - * Therefore, this method serves only monitoring purposes and is not necessary to use. - */ - bool isInBusOffState() const; - - uavcan::int16_t send(const uavcan::CanFrame& frame, - uavcan::MonotonicTime tx_deadline, - uavcan::CanIOFlags flags) override; - - uavcan::int16_t receive(uavcan::CanFrame& out_frame, - uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, - uavcan::CanIOFlags& out_flags) override; - - uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces], - uavcan::MonotonicTime blocking_deadline) override; - - uavcan::int16_t configureFilters(const uavcan::CanFilterConfig* filter_configs, - uavcan::uint16_t num_configs) override; - - uavcan::uint64_t getErrorCount() const override; - - uavcan::uint16_t getNumFilters() const override; - - uavcan::ICanIface* getIface(uavcan::uint8_t iface_index) override; - - uavcan::uint8_t getNumIfaces() const override; -}; - -} diff --git a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/clock.hpp b/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/clock.hpp deleted file mode 100644 index 47f3b5fea5..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/clock.hpp +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -namespace uavcan_lpc11c24 -{ -namespace clock -{ -/** - * Starts the clock. - * Can be called multiple times, only the first call will be effective. - */ -void init(); - -/** - * Returns current monotonic time passed since the moment when clock::init() was called. - * Note that both monotonic and UTC clocks are implemented using SysTick timer. - */ -uavcan::MonotonicTime getMonotonic(); - -/** - * Returns UTC time if it has been set, otherwise returns zero time. - * Note that both monotonic and UTC clocks are implemented using SysTick timer. - */ -uavcan::UtcTime getUtc(); - -/** - * Performs UTC time adjustment. - * The UTC time will be zero until first adjustment has been performed. - */ -void adjustUtc(uavcan::UtcDuration adjustment); - -/** - * Returns clock error sampled at previous UTC adjustment. - * Positive if the hardware timer is slower than reference time. - */ -uavcan::UtcDuration getPrevUtcAdjustment(); - -} - -/** - * Adapter for uavcan::ISystemClock. - */ -class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable -{ - static SystemClock self; - - SystemClock() { } - - uavcan::MonotonicTime getMonotonic() const override { return clock::getMonotonic(); } - uavcan::UtcTime getUtc() const override { return clock::getUtc(); } - void adjustUtc(uavcan::UtcDuration adjustment) override { clock::adjustUtc(adjustment); } - -public: - /** - * Calls clock::init() as needed. - */ - static SystemClock& instance(); -}; - -} diff --git a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/uavcan_lpc11c24.hpp b/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/uavcan_lpc11c24.hpp deleted file mode 100644 index e09051d134..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/include/uavcan_lpc11c24/uavcan_lpc11c24.hpp +++ /dev/null @@ -1,9 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include diff --git a/libuavcan_drivers/lpc11c24/driver/src/c_can.hpp b/libuavcan_drivers/lpc11c24/driver/src/c_can.hpp deleted file mode 100644 index 4882e65f41..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/src/c_can.hpp +++ /dev/null @@ -1,191 +0,0 @@ -/* - * Bosch C_CAN controller API. - * - * Copyright (C) 2015 Pavel Kirienko - */ - -#pragma once - -#include -#include - -namespace uavcan_lpc11c24 -{ -namespace c_can -{ - -struct MsgIfaceType -{ - std::uint32_t CMDREQ; - - union - { - std::uint32_t W; - std::uint32_t R; - } CMDMSK; - - std::uint32_t MSK1; - std::uint32_t MSK2; - - std::uint32_t ARB1; - std::uint32_t ARB2; - - std::uint32_t MCTRL; - - std::uint32_t DA1; - std::uint32_t DA2; - std::uint32_t DB1; - std::uint32_t DB2; - - const std::uint32_t _skip[13]; -}; - -static_assert(offsetof(MsgIfaceType, CMDMSK) == 0x04, "C_CAN offset"); -static_assert(offsetof(MsgIfaceType, MSK1) == 0x08, "C_CAN offset"); -static_assert(offsetof(MsgIfaceType, ARB1) == 0x10, "C_CAN offset"); -static_assert(offsetof(MsgIfaceType, MCTRL) == 0x18, "C_CAN offset"); -static_assert(offsetof(MsgIfaceType, DA1) == 0x1c, "C_CAN offset"); -static_assert(offsetof(MsgIfaceType, DB2) == 0x28, "C_CAN offset"); - -static_assert(sizeof(MsgIfaceType) == 96, "C_CAN size"); - - -struct Type -{ - std::uint32_t CNTL; - std::uint32_t STAT; - const std::uint32_t EC; - std::uint32_t BT; - const std::uint32_t INT; - std::uint32_t TEST; - std::uint32_t BRPE; - - const std::uint32_t _skip_a[1]; - - MsgIfaceType IF[2]; // [0] @ 0x020, [1] @ 0x080 - - const std::uint32_t _skip_b[8]; - - const std::uint32_t TXREQ[2]; // 0x100 - - const std::uint32_t _skip_c[6]; - - const std::uint32_t ND[2]; // 0x120 - - const std::uint32_t _skip_d[6]; - - const std::uint32_t IR[2]; // 0x140 - - const std::uint32_t _skip_e[6]; - - const std::uint32_t MSGV[2]; // 0x160 - - const std::uint32_t _skip_f[6]; - - std::uint32_t CLKDIV; // 0x180 -}; - -static_assert(offsetof(Type, CNTL) == 0x000, "C_CAN offset"); -static_assert(offsetof(Type, STAT) == 0x004, "C_CAN offset"); -static_assert(offsetof(Type, TEST) == 0x014, "C_CAN offset"); -static_assert(offsetof(Type, BRPE) == 0x018, "C_CAN offset"); -static_assert(offsetof(Type, IF[0]) == 0x020, "C_CAN offset"); -static_assert(offsetof(Type, IF[1]) == 0x080, "C_CAN offset"); -static_assert(offsetof(Type, TXREQ) == 0x100, "C_CAN offset"); -static_assert(offsetof(Type, ND) == 0x120, "C_CAN offset"); -static_assert(offsetof(Type, IR) == 0x140, "C_CAN offset"); -static_assert(offsetof(Type, MSGV) == 0x160, "C_CAN offset"); -static_assert(offsetof(Type, CLKDIV) == 0x180, "C_CAN offset"); - -static_assert(offsetof(Type, IF[0].DB2) == 0x048, "C_CAN offset"); -static_assert(offsetof(Type, IF[1].DB2) == 0x0A8, "C_CAN offset"); - - -volatile Type& CAN = *reinterpret_cast(0x40050000); - - -/* - * CNTL - */ -static constexpr std::uint32_t CNTL_TEST = 1 << 7; -static constexpr std::uint32_t CNTL_CCE = 1 << 6; -static constexpr std::uint32_t CNTL_DAR = 1 << 5; -static constexpr std::uint32_t CNTL_EIE = 1 << 3; -static constexpr std::uint32_t CNTL_SIE = 1 << 2; -static constexpr std::uint32_t CNTL_IE = 1 << 1; -static constexpr std::uint32_t CNTL_INIT = 1 << 0; - -static constexpr std::uint32_t CNTL_IRQ_MASK = CNTL_EIE | CNTL_IE | CNTL_SIE; - -/* - * TEST - */ -static constexpr std::uint32_t TEST_RX = 1 << 7; -static constexpr std::uint32_t TEST_LBACK = 1 << 4; -static constexpr std::uint32_t TEST_SILENT = 1 << 3; -static constexpr std::uint32_t TEST_BASIC = 1 << 2; -static constexpr std::uint32_t TEST_TX_SHIFT = 5; - -enum class TestTx : std::uint32_t -{ - Controller = 0, - SamplePoint = 1, - LowDominant = 2, - HighRecessive = 3 -}; - -/* - * STAT - */ -static constexpr std::uint32_t STAT_BOFF = 1 << 7; -static constexpr std::uint32_t STAT_EWARN = 1 << 6; -static constexpr std::uint32_t STAT_EPASS = 1 << 5; -static constexpr std::uint32_t STAT_RXOK = 1 << 4; -static constexpr std::uint32_t STAT_TXOK = 1 << 3; -static constexpr std::uint32_t STAT_LEC_MASK = 7; -static constexpr std::uint32_t STAT_LEC_SHIFT = 0; - -enum class StatLec : std::uint32_t -{ - NoError = 0, - StuffError = 1, - FormError = 2, - AckError = 3, - Bit1Error = 4, - Bit0Error = 5, - CRCError = 6, - Unused = 7 -}; - -/* - * IF.CMDREQ - */ -static constexpr std::uint32_t IF_CMDREQ_BUSY = 1 << 15; - -/* - * IF.CMDMSK - */ -static constexpr std::uint32_t IF_CMDMSK_W_DATA_A = 1 << 0; -static constexpr std::uint32_t IF_CMDMSK_W_DATA_B = 1 << 1; -static constexpr std::uint32_t IF_CMDMSK_W_TXRQST = 1 << 2; -static constexpr std::uint32_t IF_CMDMSK_W_CTRL = 1 << 4; -static constexpr std::uint32_t IF_CMDMSK_W_ARB = 1 << 5; -static constexpr std::uint32_t IF_CMDMSK_W_MASK = 1 << 6; -static constexpr std::uint32_t IF_CMDMSK_W_WR_RD = 1 << 7; - -/* - * IF.MCTRL - */ -static constexpr std::uint32_t IF_MCTRL_NEWDAT = 1 << 15; -static constexpr std::uint32_t IF_MCTRL_MSGLST = 1 << 14; -static constexpr std::uint32_t IF_MCTRL_INTPND = 1 << 13; -static constexpr std::uint32_t IF_MCTRL_UMASK = 1 << 12; -static constexpr std::uint32_t IF_MCTRL_TXIE = 1 << 11; -static constexpr std::uint32_t IF_MCTRL_RXIE = 1 << 10; -static constexpr std::uint32_t IF_MCTRL_RMTEN = 1 << 9; -static constexpr std::uint32_t IF_MCTRL_TXRQST = 1 << 8; -static constexpr std::uint32_t IF_MCTRL_EOB = 1 << 7; -static constexpr std::uint32_t IF_MCTRL_DLC_MASK = 15; - -} -} diff --git a/libuavcan_drivers/lpc11c24/driver/src/can.cpp b/libuavcan_drivers/lpc11c24/driver/src/can.cpp deleted file mode 100644 index 7e7614ffc9..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/src/can.cpp +++ /dev/null @@ -1,649 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include "c_can.hpp" -#include "internal.hpp" - -/** - * The default value should be OK for any use case. - */ -#ifndef UAVCAN_LPC11C24_RX_QUEUE_LEN -# define UAVCAN_LPC11C24_RX_QUEUE_LEN 8 -#endif - -#if UAVCAN_LPC11C24_RX_QUEUE_LEN > 254 -# error UAVCAN_LPC11C24_RX_QUEUE_LEN is too large -#endif - -extern "C" void canRxCallback(std::uint8_t msg_obj_num); -extern "C" void canTxCallback(std::uint8_t msg_obj_num); -extern "C" void canErrorCallback(std::uint32_t error_info); - -namespace uavcan_lpc11c24 -{ -namespace -{ -/** - * Hardware message objects are allocated as follows: - * - 1 - Single TX object - * - 2..32 - RX objects - * TX priority is defined by the message object number, not by the CAN ID (chapter 16.7.3.5 of the user manual), - * hence we can't use more than one object because that would cause priority inversion on long transfers. - */ -constexpr unsigned NumberOfMessageObjects = 32; -constexpr unsigned NumberOfTxMessageObjects = 1; -constexpr unsigned NumberOfRxMessageObjects = NumberOfMessageObjects - NumberOfTxMessageObjects; -constexpr unsigned TxMessageObjectNumber = 1; - -/** - * Total number of CAN errors. - * Does not overflow. - */ -volatile std::uint32_t error_cnt = 0; - -/** - * False if there's no pending TX frame, i.e. write is possible. - */ -volatile bool tx_pending = false; - -/** - * Currently pending frame must be aborted on first error. - */ -volatile bool tx_abort_on_error = false; - -/** - * Gets updated every time the CAN IRQ handler is being called. - */ -volatile std::uint64_t last_irq_utc_timestamp = 0; - -/** - * Set by the driver on every successful TX or RX; reset by the application. - */ -volatile bool had_activity = false; - -/** - * After a received message gets extracted from C_CAN, it will be stored in the RX queue until libuavcan - * reads it via select()/receive() calls. - */ -class RxQueue -{ - struct Item - { - std::uint64_t utc_usec = 0; - uavcan::CanFrame frame; - }; - - Item buf_[UAVCAN_LPC11C24_RX_QUEUE_LEN]; - std::uint32_t overflow_cnt_ = 0; - std::uint8_t in_ = 0; - std::uint8_t out_ = 0; - std::uint8_t len_ = 0; - -public: - void push(const uavcan::CanFrame& frame, const volatile std::uint64_t& utc_usec) - { - buf_[in_].frame = frame; - buf_[in_].utc_usec = utc_usec; - in_++; - if (in_ >= UAVCAN_LPC11C24_RX_QUEUE_LEN) - { - in_ = 0; - } - len_++; - if (len_ > UAVCAN_LPC11C24_RX_QUEUE_LEN) - { - len_ = UAVCAN_LPC11C24_RX_QUEUE_LEN; - if (overflow_cnt_ < 0xFFFFFFFF) - { - overflow_cnt_++; - } - out_++; - if (out_ >= UAVCAN_LPC11C24_RX_QUEUE_LEN) - { - out_ = 0; - } - } - } - - void pop(uavcan::CanFrame& out_frame, std::uint64_t& out_utc_usec) - { - if (len_ > 0) - { - out_frame = buf_[out_].frame; - out_utc_usec = buf_[out_].utc_usec; - out_++; - if (out_ >= UAVCAN_LPC11C24_RX_QUEUE_LEN) - { - out_ = 0; - } - len_--; - } - } - - unsigned getLength() const { return len_; } - - std::uint32_t getOverflowCount() const { return overflow_cnt_; } -}; - -RxQueue rx_queue; - - -struct BitTimingSettings -{ - std::uint32_t canclkdiv; - std::uint32_t canbtr; - - bool isValid() const { return canbtr != 0; } -}; - -/** - * http://www.bittiming.can-wiki.info - */ -BitTimingSettings computeBitTimings(std::uint32_t bitrate) -{ - if (Chip_Clock_GetSystemClockRate() == 48000000) // 48 MHz is optimal for CAN timings - { - switch (bitrate) - { - case 1000000: return BitTimingSettings{ 0, 0x0505 }; // 8 quanta, 87.5% - case 500000: return BitTimingSettings{ 0, 0x1c05 }; // 16 quanta, 87.5% - case 250000: return BitTimingSettings{ 0, 0x1c0b }; // 16 quanta, 87.5% - case 125000: return BitTimingSettings{ 0, 0x1c17 }; // 16 quanta, 87.5% - case 100000: return BitTimingSettings{ 0, 0x1c1d }; // 16 quanta, 87.5% - default: return BitTimingSettings{ 0, 0 }; - } - } - else - { - return BitTimingSettings{ 0, 0 }; - } -} - -} // namespace - -CanDriver CanDriver::self; - -uavcan::uint32_t CanDriver::detectBitRate(void (*idle_callback)()) -{ - static constexpr uavcan::uint32_t BitRatesToTry[] = - { - 1000000, - 500000, - 250000, - 125000, - 100000 - }; - - const auto ListeningDuration = uavcan::MonotonicDuration::fromMSec(1050); - - NVIC_DisableIRQ(CAN_IRQn); - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CAN); - - for (auto bitrate : BitRatesToTry) - { - // Computing bit timings - const auto bit_timings = computeBitTimings(bitrate); - if (!bit_timings.isValid()) - { - return 0; - } - - // Configuring the CAN controller - { - CriticalSectionLocker locker; - - LPC_SYSCTL->PRESETCTRL |= (1U << RESET_CAN0); - - // Entering initialization mode - c_can::CAN.CNTL = c_can::CNTL_INIT | c_can::CNTL_CCE; - - while ((c_can::CAN.CNTL & c_can::CNTL_INIT) == 0) - { - ; // Nothing to do - } - - // Configuring bit rate - c_can::CAN.CLKDIV = bit_timings.canclkdiv; - c_can::CAN.BT = bit_timings.canbtr; - c_can::CAN.BRPE = 0; - - // Configuring silent mode - c_can::CAN.CNTL |= c_can::CNTL_TEST; - c_can::CAN.TEST = c_can::TEST_SILENT; - - // Configuring status monitor - c_can::CAN.STAT = (unsigned(c_can::StatLec::Unused) << c_can::STAT_LEC_SHIFT); - - // Leaving initialization mode - c_can::CAN.CNTL &= ~(c_can::CNTL_INIT | c_can::CNTL_CCE); - - while ((c_can::CAN.CNTL & c_can::CNTL_INIT) != 0) - { - ; // Nothing to do - } - } - - // Listening - const auto deadline = clock::getMonotonic() + ListeningDuration; - bool match_detected = false; - while (clock::getMonotonic() < deadline) - { - if (idle_callback != nullptr) - { - idle_callback(); - } - - const auto LastErrorCode = (c_can::CAN.STAT >> c_can::STAT_LEC_SHIFT) & c_can::STAT_LEC_MASK; - - if (LastErrorCode == unsigned(c_can::StatLec::NoError)) - { - match_detected = true; - break; - } - } - - // De-configuring the CAN controller back to reset state - { - CriticalSectionLocker locker; - - c_can::CAN.CNTL = c_can::CNTL_INIT; - - while ((c_can::CAN.CNTL & c_can::CNTL_INIT) == 0) - { - ; // Nothing to do - } - - LPC_SYSCTL->PRESETCTRL &= ~(1U << RESET_CAN0); - } - - // Termination condition - if (match_detected) - { - return bitrate; - } - } - - return 0; // No match -} - -int CanDriver::init(uavcan::uint32_t bitrate) -{ - { - auto bit_timings = computeBitTimings(bitrate); - if (!bit_timings.isValid()) - { - return -1; - } - - CriticalSectionLocker locker; - - error_cnt = 0; - tx_abort_on_error = false; - tx_pending = false; - last_irq_utc_timestamp = 0; - had_activity = false; - - /* - * C_CAN init - */ - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_CAN); - - LPC_CCAN_API->init_can(reinterpret_cast(&bit_timings), true); - - static CCAN_CALLBACKS_T ccan_callbacks = - { - canRxCallback, - canTxCallback, - canErrorCallback, - nullptr, - nullptr, - nullptr, - nullptr, - nullptr - }; - LPC_CCAN_API->config_calb(&ccan_callbacks); - - /* - * Interrupts - */ - c_can::CAN.CNTL |= c_can::CNTL_SIE; // This is necessary for transmission aborts on error - - NVIC_EnableIRQ(CAN_IRQn); - } - - /* - * Applying default filter configuration (accept all) - */ - if (configureFilters(nullptr, 0) < 0) - { - return -1; - } - - return 0; -} - -bool CanDriver::hasReadyRx() const -{ - CriticalSectionLocker locker; - return rx_queue.getLength() > 0; -} - -bool CanDriver::hasEmptyTx() const -{ - CriticalSectionLocker locker; - return !tx_pending; -} - -bool CanDriver::hadActivity() -{ - CriticalSectionLocker locker; - const bool ret = had_activity; - had_activity = false; - return ret; -} - -uavcan::uint32_t CanDriver::getRxQueueOverflowCount() const -{ - CriticalSectionLocker locker; - return rx_queue.getOverflowCount(); -} - -bool CanDriver::isInBusOffState() const -{ - return (c_can::CAN.STAT & c_can::STAT_BOFF) != 0; -} - -uavcan::int16_t CanDriver::send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, - uavcan::CanIOFlags flags) -{ - if (frame.isErrorFrame() || - frame.dlc > 8 || - (flags & uavcan::CanIOFlagLoopback) != 0) // TX timestamping is not supported by this driver. - { - return -1; - } - - /* - * Frame conversion - */ - CCAN_MSG_OBJ_T msgobj = CCAN_MSG_OBJ_T(); - msgobj.mode_id = frame.id & uavcan::CanFrame::MaskExtID; - if (frame.isExtended()) - { - msgobj.mode_id |= CAN_MSGOBJ_EXT; - } - if (frame.isRemoteTransmissionRequest()) - { - msgobj.mode_id |= CAN_MSGOBJ_RTR; - } - msgobj.dlc = frame.dlc; - uavcan::copy(frame.data, frame.data + frame.dlc, msgobj.data); - - /* - * Transmission - */ - (void)tx_deadline; // TX timeouts are not supported by this driver yet (and hardly going to be). - - CriticalSectionLocker locker; - - if (!tx_pending) - { - tx_pending = true; // Mark as pending - will be released in TX callback - tx_abort_on_error = (flags & uavcan::CanIOFlagAbortOnError) != 0; - msgobj.msgobj = TxMessageObjectNumber; - LPC_CCAN_API->can_transmit(&msgobj); - return 1; - } - return 0; -} - -uavcan::int16_t CanDriver::receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags) -{ - out_ts_monotonic = clock::getMonotonic(); - out_flags = 0; // We don't support any IO flags - - CriticalSectionLocker locker; - if (rx_queue.getLength() == 0) - { - return 0; - } - std::uint64_t ts_utc = 0; - rx_queue.pop(out_frame, ts_utc); - out_ts_utc = uavcan::UtcTime::fromUSec(ts_utc); - return 1; -} - -uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (&)[uavcan::MaxCanIfaces], - uavcan::MonotonicTime blocking_deadline) -{ - const bool bus_off = isInBusOffState(); - if (bus_off) // Recover automatically on bus-off - { - CriticalSectionLocker locker; - if ((c_can::CAN.CNTL & c_can::CNTL_INIT) != 0) - { - c_can::CAN.CNTL &= ~c_can::CNTL_INIT; - } - } - - const bool noblock = ((inout_masks.read == 1) && hasReadyRx()) || - ((inout_masks.write == 1) && hasEmptyTx()); - - if (!noblock && (clock::getMonotonic() > blocking_deadline)) - { -#if defined(UAVCAN_LPC11C24_USE_WFE) && UAVCAN_LPC11C24_USE_WFE - /* - * It's not cool (literally) to burn cycles in a busyloop, and we have no OS to pass control to other - * tasks, thus solution is to halt the core until a hardware event occurs - e.g. clock timer overflow. - * Upon such event the select() call will return, even if no requested IO operations became available. - * It's OK to do that, libuavcan can handle such behavior. - * - * Note that it is not possible to precisely control the sleep duration with WFE, since we can't predict when - * the next hardware event occurs. Worst case conditions: - * - WFE gets executed right after the clock timer interrupt; - * - CAN bus is completely silent (no traffic); - * - User's application has no interrupts and generates no hardware events. - * In such scenario execution will stuck here for one period of the clock timer interrupt, even if - * blocking_deadline expires sooner. - * If the user's application requires higher timing precision, an extra dummy IRQ can be added just to - * break WFE every once in a while. - */ - __WFE(); -#endif - } - - inout_masks.read = hasReadyRx() ? 1 : 0; - - inout_masks.write = (hasEmptyTx() && !bus_off) ? 1 : 0; // Disable write while in bus-off - - return 0; // Return value doesn't matter as long as it is non-negative -} - -uavcan::int16_t CanDriver::configureFilters(const uavcan::CanFilterConfig* filter_configs, - uavcan::uint16_t num_configs) -{ - CriticalSectionLocker locker; - - /* - * If C_CAN is active (INIT=0) and the CAN bus has intensive traffic, RX object configuration may fail. - * The solution is to disable the controller while configuration is in progress. - * The documentation, as always, doesn't bother to mention this detail. Shame on you, NXP. - */ - struct RAIIDisabler - { - RAIIDisabler() - { - c_can::CAN.CNTL |= c_can::CNTL_INIT; - } - ~RAIIDisabler() - { - c_can::CAN.CNTL &= ~c_can::CNTL_INIT; - } - } can_disabler; // Must be instantiated AFTER the critical section locker - - if (num_configs == 0) - { - auto msg_obj = CCAN_MSG_OBJ_T(); - msg_obj.msgobj = NumberOfTxMessageObjects + 1; - LPC_CCAN_API->config_rxmsgobj(&msg_obj); // all STD frames - - msg_obj.mode_id = CAN_MSGOBJ_EXT; - msg_obj.msgobj = NumberOfTxMessageObjects + 2; - LPC_CCAN_API->config_rxmsgobj(&msg_obj); // all EXT frames - } - else if (num_configs <= NumberOfRxMessageObjects) - { - // Making sure the configs use only EXT frames; otherwise we can't accept them - for (unsigned i = 0; i < num_configs; i++) - { - auto& f = filter_configs[i]; - if ((f.id & f.mask & uavcan::CanFrame::FlagEFF) == 0) - { - return -1; - } - } - - // Installing the configuration - for (unsigned i = 0; i < NumberOfRxMessageObjects; i++) - { - auto msg_obj = CCAN_MSG_OBJ_T(); - msg_obj.msgobj = std::uint8_t(i + 1U + NumberOfTxMessageObjects); // Message objects are numbered from 1 - - if (i < num_configs) - { - msg_obj.mode_id = (filter_configs[i].id & uavcan::CanFrame::MaskExtID) | CAN_MSGOBJ_EXT; // Only EXT - msg_obj.mask = filter_configs[i].mask & uavcan::CanFrame::MaskExtID; - } - else - { - msg_obj.mode_id = CAN_MSGOBJ_RTR; // Using this configuration to disable the object - msg_obj.mask = uavcan::CanFrame::MaskStdID; - } - - LPC_CCAN_API->config_rxmsgobj(&msg_obj); - } - } - else - { - return -1; - } - - return 0; -} - -uavcan::uint64_t CanDriver::getErrorCount() const -{ - CriticalSectionLocker locker; - return std::uint64_t(error_cnt) + std::uint64_t(rx_queue.getOverflowCount()); -} - -uavcan::uint16_t CanDriver::getNumFilters() const -{ - return NumberOfRxMessageObjects; -} - -uavcan::ICanIface* CanDriver::getIface(uavcan::uint8_t iface_index) -{ - return (iface_index == 0) ? this : nullptr; -} - -uavcan::uint8_t CanDriver::getNumIfaces() const -{ - return 1; -} - -} - -/* - * C_CAN handlers - */ -extern "C" -{ - -void canRxCallback(std::uint8_t msg_obj_num) -{ - using namespace uavcan_lpc11c24; - - auto msg_obj = CCAN_MSG_OBJ_T(); - msg_obj.msgobj = msg_obj_num; - LPC_CCAN_API->can_receive(&msg_obj); - - uavcan::CanFrame frame; - - // CAN ID, EXT or not - if (msg_obj.mode_id & CAN_MSGOBJ_EXT) - { - frame.id = msg_obj.mode_id & uavcan::CanFrame::MaskExtID; - frame.id |= uavcan::CanFrame::FlagEFF; - } - else - { - frame.id = msg_obj.mode_id & uavcan::CanFrame::MaskStdID; - } - - // RTR - if (msg_obj.mode_id & CAN_MSGOBJ_RTR) - { - frame.id |= uavcan::CanFrame::FlagRTR; - } - - // Payload - frame.dlc = msg_obj.dlc; - uavcan::copy(msg_obj.data, msg_obj.data + msg_obj.dlc, frame.data); - - rx_queue.push(frame, last_irq_utc_timestamp); - had_activity = true; -} - -void canTxCallback(std::uint8_t msg_obj_num) -{ - using namespace uavcan_lpc11c24; - - (void)msg_obj_num; - - tx_pending = false; - had_activity = true; -} - -void canErrorCallback(std::uint32_t error_info) -{ - using namespace uavcan_lpc11c24; - - // Updating the error counter - if ((error_info != 0) && (error_cnt < 0xFFFFFFFFUL)) - { - error_cnt++; - } - - // Serving abort requests - if (tx_pending && tx_abort_on_error) - { - tx_pending = false; - tx_abort_on_error = false; - - // Using the first interface, because this approach seems to be compliant with the BASIC mode (just in case) - c_can::CAN.IF[0].CMDREQ = TxMessageObjectNumber; - c_can::CAN.IF[0].CMDMSK.W = c_can::IF_CMDMSK_W_WR_RD; // Clearing IF_CMDMSK_W_TXRQST - c_can::CAN.IF[0].MCTRL &= ~c_can::IF_MCTRL_TXRQST; // Clearing IF_MCTRL_TXRQST - } -} - -void CAN_IRQHandler(); - -void CAN_IRQHandler() -{ - using namespace uavcan_lpc11c24; - - last_irq_utc_timestamp = clock::getUtcUSecFromCanInterrupt(); - - LPC_CCAN_API->isr(); -} - -} diff --git a/libuavcan_drivers/lpc11c24/driver/src/clock.cpp b/libuavcan_drivers/lpc11c24/driver/src/clock.cpp deleted file mode 100644 index a9d299f063..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/src/clock.cpp +++ /dev/null @@ -1,190 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include "internal.hpp" - -namespace uavcan_lpc11c24 -{ -namespace clock -{ -namespace -{ - -bool initialized = false; -bool utc_set = false; - -std::int32_t utc_correction_usec_per_overflow_x16 = 0; -std::int64_t prev_adjustment = 0; - -std::uint64_t time_mono = 0; -std::uint64_t time_utc = 0; - -/** - * If this value is too large for the given core clock, reload value will be out of the 24-bit integer range. - * This will be detected at run time during timer initialization - refer to SysTick_Config(). - */ -constexpr std::uint32_t USecPerOverflow = 65536 * 2; -constexpr std::int32_t MaxUtcSpeedCorrectionX16 = 100 * 16; - -} - -#if __GNUC__ -__attribute__((noreturn)) -#endif -static void fail() -{ - while (true) { } -} - -void init() -{ - CriticalSectionLocker lock; - if (!initialized) - { - initialized = true; - - if ((SystemCoreClock % 1000000) != 0) // Core clock frequency validation - { - fail(); - } - - if (SysTick_Config((SystemCoreClock / 1000000) * USecPerOverflow) != 0) - { - fail(); - } - } -} - -static std::uint64_t sampleFromCriticalSection(const volatile std::uint64_t* const value) -{ - const std::uint32_t reload = SysTick->LOAD + 1; // SysTick counts downwards, hence the value subtracted from reload - - volatile std::uint64_t time = *value; - volatile std::uint32_t cycles = reload - SysTick->VAL; - - if ((SCB->ICSR & SCB_ICSR_PENDSTSET_Msk) == SCB_ICSR_PENDSTSET_Msk) - { - cycles = reload - SysTick->VAL; - time += USecPerOverflow; - } - const std::uint32_t cycles_per_usec = SystemCoreClock / 1000000; - return time + (cycles / cycles_per_usec); -} - -std::uint64_t getUtcUSecFromCanInterrupt() -{ - return utc_set ? sampleFromCriticalSection(&time_utc) : 0; -} - -uavcan::MonotonicTime getMonotonic() -{ - if (!initialized) - { - fail(); - } - std::uint64_t usec = 0; - { - CriticalSectionLocker locker; - usec = sampleFromCriticalSection(&time_mono); - } - return uavcan::MonotonicTime::fromUSec(usec); -} - -uavcan::UtcTime getUtc() -{ - if (!initialized) - { - fail(); - } - std::uint64_t usec = 0; - if (utc_set) - { - CriticalSectionLocker locker; - usec = sampleFromCriticalSection(&time_utc); - } - return uavcan::UtcTime::fromUSec(usec); -} - -uavcan::UtcDuration getPrevUtcAdjustment() -{ - return uavcan::UtcDuration::fromUSec(prev_adjustment); -} - -void adjustUtc(uavcan::UtcDuration adjustment) -{ - const std::int64_t adj_delta = adjustment.toUSec() - prev_adjustment; // This is the P term - prev_adjustment = adjustment.toUSec(); - - utc_correction_usec_per_overflow_x16 += adjustment.isPositive() ? 1 : -1; // I - utc_correction_usec_per_overflow_x16 += (adj_delta > 0) ? 1 : -1; // P - - utc_correction_usec_per_overflow_x16 = - uavcan::max(utc_correction_usec_per_overflow_x16, -MaxUtcSpeedCorrectionX16); - utc_correction_usec_per_overflow_x16 = - uavcan::min(utc_correction_usec_per_overflow_x16, MaxUtcSpeedCorrectionX16); - - if (adjustment.getAbs().toMSec() > 9 || !utc_set) - { - const std::int64_t adj_usec = adjustment.toUSec(); - { - CriticalSectionLocker locker; - if ((adj_usec < 0) && std::uint64_t(-adj_usec) > time_utc) - { - time_utc = 1; - } - else - { - time_utc = std::uint64_t(std::int64_t(time_utc) + adj_usec); - } - } - if (!utc_set) - { - utc_set = true; - utc_correction_usec_per_overflow_x16 = 0; - } - } -} - -} // namespace clock - -SystemClock SystemClock::self; - -SystemClock& SystemClock::instance() -{ - clock::init(); - return self; -} - -} - -/* - * Timer interrupt handler - */ -extern "C" -{ - -void SysTick_Handler(); - -void SysTick_Handler() -{ - using namespace uavcan_lpc11c24::clock; - if (initialized) - { - time_mono += USecPerOverflow; - if (utc_set) - { - // Values below 16 are ignored - time_utc += std::uint64_t(std::int32_t(USecPerOverflow) + (utc_correction_usec_per_overflow_x16 / 16)); - } - } - else - { - fail(); - } -} - -} diff --git a/libuavcan_drivers/lpc11c24/driver/src/internal.hpp b/libuavcan_drivers/lpc11c24/driver/src/internal.hpp deleted file mode 100644 index 80be9f1032..0000000000 --- a/libuavcan_drivers/lpc11c24/driver/src/internal.hpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include - -/* - * Compiler version check - */ -#ifdef __GNUC__ -# if (__GNUC__ * 10 + __GNUC_MINOR__) < 49 -# error "Use GCC 4.9 or newer" -# endif -#endif - - -namespace uavcan_lpc11c24 -{ - -/** - * Locks UAVCAN driver interrupts. - * TODO: priority. - */ -struct CriticalSectionLocker -{ - CriticalSectionLocker() - { - __disable_irq(); - } - ~CriticalSectionLocker() - { - __enable_irq(); - } -}; - -/** - * Internal for the driver - */ -namespace clock -{ - -std::uint64_t getUtcUSecFromCanInterrupt(); - -} - -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile deleted file mode 100644 index 9a503bc4ef..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/Makefile +++ /dev/null @@ -1,123 +0,0 @@ -# -# Pavel Kirienko, 2014 -# - -CPPSRC := $(wildcard src/*.cpp) \ - $(wildcard src/sys/*.cpp) - -CSRC := $(wildcard lpc_chip_11cxx_lib/src/*.c) \ - $(wildcard src/sys/*.c) - -DEF = -DFW_VERSION_MAJOR=1 -DFW_VERSION_MINOR=0 - -INC = -Isrc/sys \ - -isystem lpc_chip_11cxx_lib/inc - -# -# UAVCAN library -# - -DEF += -DUAVCAN_TINY=1 - -include ../../../libuavcan/include.mk -CPPSRC += $(LIBUAVCAN_SRC) -INC += -I$(LIBUAVCAN_INC) - -include ../driver/include.mk -CPPSRC += $(LIBUAVCAN_LPC11C24_SRC) -INC += -I$(LIBUAVCAN_LPC11C24_INC) - -$(info $(shell $(LIBUAVCAN_DSDLC) $(UAVCAN_DSDL_DIR))) -INC += -Idsdlc_generated - -# -# Git commit hash -# - -GIT_HASH := $(shell git rev-parse --short HEAD) -ifeq ($(words $(GIT_HASH)),1) - DEF += -DGIT_HASH=0x$(GIT_HASH) -endif - -# -# Build configuration -# - -BUILDDIR = build -OBJDIR = $(BUILDDIR)/obj -DEPDIR = $(BUILDDIR)/dep - -DEF += -DNDEBUG -DCHIP_LPC11CXX -DCORE_M0 -DTHUMB_NO_INTERWORKING -U__STRICT_ANSI__ - -FLAGS = -mthumb -mcpu=cortex-m0 -mno-thumb-interwork -flto -Os -g3 -Wall -Wextra -Werror -Wundef -ffunction-sections \ - -fdata-sections -fno-common -fno-exceptions -fno-unwind-tables -fno-stack-protector -fomit-frame-pointer \ - -Wfloat-equal -Wconversion -Wsign-conversion -Wmissing-declarations - -C_CPP_FLAGS = $(FLAGS) -MD -MP -MF $(DEPDIR)/$(@F).d - -CFLAGS = $(C_CPP_FLAGS) -std=c99 - -CPPFLAGS = $(C_CPP_FLAGS) -pedantic -std=c++11 -fno-rtti -fno-threadsafe-statics - -LDFLAGS = $(FLAGS) -nodefaultlibs -lc -lgcc -nostartfiles -Tlpc11c24.ld -Xlinker --gc-sections \ - -Wl,-Map,$(BUILDDIR)/output.map - -# Link with nano newlib. Other toolchains may not support this option, so it can be safely removed. -LDFLAGS += --specs=nano.specs - -COBJ = $(addprefix $(OBJDIR)/, $(notdir $(CSRC:.c=.o))) -CPPOBJ = $(addprefix $(OBJDIR)/, $(notdir $(CPPSRC:.cpp=.o))) -OBJ = $(COBJ) $(CPPOBJ) - -VPATH = $(sort $(dir $(CSRC)) $(dir $(CPPSRC))) - -ELF = $(BUILDDIR)/firmware.elf -BIN = $(BUILDDIR)/firmware.bin - -# -# Rules -# - -TOOLCHAIN ?= arm-none-eabi- -CC = $(TOOLCHAIN)gcc -CPPC = $(TOOLCHAIN)g++ -AS = $(TOOLCHAIN)gcc -LD = $(TOOLCHAIN)g++ -CP = $(TOOLCHAIN)objcopy -SIZE = $(TOOLCHAIN)size - -all: $(OBJ) $(ELF) $(BIN) size - -$(OBJ): | $(BUILDDIR) - -$(BUILDDIR): - @mkdir -p $(BUILDDIR) - @mkdir -p $(DEPDIR) - @mkdir -p $(OBJDIR) - -$(BIN): $(ELF) - @echo - $(CP) -O binary $(ELF) $@ - -$(ELF): $(OBJ) - @echo - $(LD) $(OBJ) $(LDFLAGS) -o $@ - -$(COBJ): $(OBJDIR)/%.o: %.c - @echo - $(CC) -c $(DEF) $(INC) $(CFLAGS) $< -o $@ - -$(CPPOBJ): $(OBJDIR)/%.o: %.cpp - @echo - $(CPPC) -c $(DEF) $(INC) $(CPPFLAGS) $< -o $@ - -clean: - rm -rf $(BUILDDIR) dsdlc_generated - -size: $(ELF) - @if [ -f $(ELF) ]; then echo; $(SIZE) $(ELF); echo; fi; - -.PHONY: all clean size $(BUILDDIR) - -# Include the dependency files, should be the last of the makefile --include $(shell mkdir $(DEPDIR) 2>/dev/null) $(wildcard $(DEPDIR)/*) diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic.gdbinit b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic.gdbinit deleted file mode 100644 index cea99657df..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic.gdbinit +++ /dev/null @@ -1,11 +0,0 @@ -# -# Template for .gdbinit -# Copy the file to .gdbinit in your project root, and adjust the path below to match your system -# - -target extended /dev/serial/by-id/usb-Black_Sphere_Technologies_Black_Magic_Probe_DDE578CC-if00 -# target extended /dev/ttyACM0 - -monitor swdp_scan -attach 1 -monitor vector_catch disable hard diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic_flash.sh b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic_flash.sh deleted file mode 100755 index ed8dc7e8d2..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/blackmagic_flash.sh +++ /dev/null @@ -1,23 +0,0 @@ -#!/bin/bash -# -# Copyright (C) 2014 Pavel Kirienko -# - -PORT=${1:-'/dev/ttyACM0'} -#/dev/serial/by-id/usb-Black_Sphere_Technologies_Black_Magic_Probe_DDE578CC-if00 - -elf=build/firmware.elf - -arm-none-eabi-size $elf || exit 1 - -tmpfile=fwupload.tempfile -cat > $tmpfile < - * Linker script for LPC11C24 - */ - -MEMORY -{ - FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 32K - /* Notice RAM offset - this is needed for on-chip CCAN */ - RAM (rwx) : ORIGIN = 0x100000C0, LENGTH = 0x1F40 -} - -ENTRY(Reset_Handler) - -SECTIONS -{ - . = 0; - _text = .; - - startup : - { - KEEP(*(vectors)) - } > FLASH - - constructors : ALIGN(4) SUBALIGN(4) - { - PROVIDE(__init_array_start = .); - KEEP(*(SORT(.init_array.*))) - KEEP(*(.init_array)) - PROVIDE(__init_array_end = .); - } > FLASH - - /* NO DESTRUCTORS */ - - .text : - { - *(.text.startup.*) - *(.text) - *(.text.*) - *(.rodata) - *(.rodata.*) - *(.glue_7t) - *(.glue_7) - *(.gcc*) - } > FLASH - - .ARM.extab : - { - *(.ARM.extab* .gnu.linkonce.armextab.*) - } > FLASH - - .ARM.exidx : { - PROVIDE(__exidx_start = .); - *(.ARM.exidx* .gnu.linkonce.armexidx.*) - PROVIDE(__exidx_end = .); - } > FLASH - - .eh_frame_hdr : - { - *(.eh_frame_hdr) - } > FLASH - - .eh_frame : ONLY_IF_RO - { - *(.eh_frame) - } > FLASH - - .textalign : ONLY_IF_RO - { - . = ALIGN(8); - } > FLASH - - . = ALIGN(4); - _etext = .; - _textdata = _etext; - - .data : - { - . = ALIGN(4); - PROVIDE(_data = .); - *(.data) - . = ALIGN(4); - *(.data.*) - . = ALIGN(4); - *(.ramtext) - . = ALIGN(4); - PROVIDE(_edata = .); - } > RAM AT > FLASH - - .bss : - { - . = ALIGN(4); - PROVIDE(_bss = .); - *(.bss) - . = ALIGN(4); - *(.bss.*) - . = ALIGN(4); - *(COMMON) - . = ALIGN(4); - PROVIDE(_ebss = .); - } > RAM - - PROVIDE(__stack_end = ORIGIN(RAM) + LENGTH(RAM)); -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/adc_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/adc_11xx.h deleted file mode 100755 index af894e71d1..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/adc_11xx.h +++ /dev/null @@ -1,271 +0,0 @@ -/* - * @brief LPC11xx A/D conversion driver (except LPC1125) - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __ADC_11XX_H_ -#define __ADC_11XX_H_ - -#if !defined(CHIP_LPC1125) - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup ADC_11XX CHIP: LPC11xx A/D conversion driver - * @ingroup CHIP_11XX_Drivers - * This ADC driver is for LPC11xx variants except for LPC1125. - * @{ - */ - -#define ADC_MAX_SAMPLE_RATE 400000 - -/** - * @brief 10 or 12-bit ADC register block structure - */ -typedef struct { /*!< ADCn Structure */ - __IO uint32_t CR; /*!< A/D Control Register. The AD0CR register must be written to select the operating mode before A/D conversion can occur. */ - __I uint32_t GDR; /*!< A/D Global Data Register. Contains the result of the most recent A/D conversion. */ - __I uint32_t RESERVED0; - __IO uint32_t INTEN; /*!< A/D Interrupt Enable Register. This register contains enable bits that allow the DONE flag of each A/D channel to be included or excluded from contributing to the generation of an A/D interrupt. */ - __I uint32_t DR[8]; /*!< A/D Channel Data Register. This register contains the result of the most recent conversion completed on channel n. */ - __I uint32_t STAT; /*!< A/D Status Register. This register contains DONE and OVERRUN flags for all of the A/D channels, as well as the A/D interrupt flag. */ -} LPC_ADC_T; - -/** - * @brief ADC register support bitfields and mask - */ - #define ADC_DR_RESULT(n) ((((n) >> 6) & 0x3FF)) /*!< Mask for getting the 10 bits ADC data read value */ - #define ADC_CR_BITACC(n) ((((n) & 0x7) << 17)) /*!< Number of ADC accuracy bits */ - -#define ADC_DR_DONE(n) (((n) >> 31)) /*!< Mask for reading the ADC done status */ -#define ADC_DR_OVERRUN(n) ((((n) >> 30) & (1UL))) /*!< Mask for reading the ADC overrun status */ -#define ADC_CR_CH_SEL(n) ((1UL << (n))) /*!< Selects which of the AD0.0:7 pins is (are) to be sampled and converted */ -#define ADC_CR_CLKDIV(n) ((((n) & 0xFF) << 8)) /*!< The APB clock (PCLK) is divided by (this value plus one) to produce the clock for the A/D */ -#define ADC_CR_BURST ((1UL << 16)) /*!< Repeated conversions A/D enable bit */ -#define ADC_CR_PDN ((1UL << 21)) /*!< ADC convert is operational */ -#define ADC_CR_START_MASK ((7UL << 24)) /*!< ADC start mask bits */ -#define ADC_CR_START_MODE_SEL(SEL) ((SEL << 24)) /*!< Select Start Mode */ -#define ADC_CR_START_NOW ((1UL << 24)) /*!< Start conversion now */ -#define ADC_CR_START_CTOUT15 ((2UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_15 */ -#define ADC_CR_START_CTOUT8 ((3UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_8 */ -#define ADC_CR_START_ADCTRIG0 ((4UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG0 */ -#define ADC_CR_START_ADCTRIG1 ((5UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG1 */ -#define ADC_CR_START_MCOA2 ((6UL << 24)) /*!< Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2 */ -#define ADC_CR_EDGE ((1UL << 27)) /*!< Start conversion on a falling edge on the selected CAP/MAT signal */ -#define ADC_SAMPLE_RATE_CONFIG_MASK (ADC_CR_CLKDIV(0xFF) | ADC_CR_BITACC(0x07)) - -/** - * @brief ADC status register used for IP drivers - */ -typedef enum IP_ADC_STATUS { - ADC_DR_DONE_STAT, /*!< ADC data register staus */ - ADC_DR_OVERRUN_STAT,/*!< ADC data overrun staus */ - ADC_DR_ADINT_STAT /*!< ADC interrupt status */ -} ADC_STATUS_T; - -/** The channels on one ADC peripheral*/ -typedef enum CHIP_ADC_CHANNEL { - ADC_CH0 = 0, /**< ADC channel 0 */ - ADC_CH1, /**< ADC channel 1 */ - ADC_CH2, /**< ADC channel 2 */ - ADC_CH3, /**< ADC channel 3 */ - ADC_CH4, /**< ADC channel 4 */ - ADC_CH5, /**< ADC channel 5 */ - ADC_CH6, /**< ADC channel 6 */ - ADC_CH7, /**< ADC channel 7 */ -} ADC_CHANNEL_T; - -/** The number of bits of accuracy of the result in the LS bits of ADDR*/ -typedef enum CHIP_ADC_RESOLUTION { - ADC_10BITS = 0, /**< ADC 10 bits */ - ADC_9BITS, /**< ADC 9 bits */ - ADC_8BITS, /**< ADC 8 bits */ - ADC_7BITS, /**< ADC 7 bits */ - ADC_6BITS, /**< ADC 6 bits */ - ADC_5BITS, /**< ADC 5 bits */ - ADC_4BITS, /**< ADC 4 bits */ - ADC_3BITS, /**< ADC 3 bits */ -} ADC_RESOLUTION_T; - -/** Edge configuration, which controls rising or falling edge on the selected signal for the start of a conversion */ -typedef enum CHIP_ADC_EDGE_CFG { - ADC_TRIGGERMODE_RISING = 0, /**< Trigger event: rising edge */ - ADC_TRIGGERMODE_FALLING, /**< Trigger event: falling edge */ -} ADC_EDGE_CFG_T; - -/** Start mode, which controls the start of an A/D conversion when the BURST bit is 0. */ -typedef enum CHIP_ADC_START_MODE { - ADC_NO_START = 0, - ADC_START_NOW, /*!< Start conversion now */ - ADC_START_ON_CTOUT15, /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_15 */ - ADC_START_ON_CTOUT8, /*!< Start conversion when the edge selected by bit 27 occurs on CTOUT_8 */ - ADC_START_ON_ADCTRIG0, /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG0 */ - ADC_START_ON_ADCTRIG1, /*!< Start conversion when the edge selected by bit 27 occurs on ADCTRIG1 */ - ADC_START_ON_MCOA2 /*!< Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2 */ -} ADC_START_MODE_T; - -/** Clock setup structure for ADC controller passed to the initialize function */ -typedef struct { - uint32_t adcRate; /*!< ADC rate */ - uint8_t bitsAccuracy; /*!< ADC bit accuracy */ - bool burstMode; /*!< ADC Burt Mode */ -} ADC_CLOCK_SETUP_T; - -/** - * @brief Initialize the ADC peripheral and the ADC setup structure to default value - * @param pADC : The base of ADC peripheral on the chip - * @param ADCSetup : ADC setup structure to be set - * @return Nothing - * @note Default setting for ADC is 400kHz - 10bits - */ -void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup); - -/** - * @brief Shutdown ADC - * @param pADC : The base of ADC peripheral on the chip - * @return Nothing - */ -void Chip_ADC_DeInit(LPC_ADC_T *pADC); - -/** - * @brief Read the ADC value from a channel - * @param pADC : The base of ADC peripheral on the chip - * @param channel : ADC channel to read - * @param data : Pointer to where to put data - * @return SUCCESS or ERROR if no conversion is ready - */ -Status Chip_ADC_ReadValue(LPC_ADC_T *pADC, uint8_t channel, uint16_t *data); - -/** - * @brief Read the ADC value and convert it to 8bits value - * @param pADC : The base of ADC peripheral on the chip - * @param channel: selected channel - * @param data : Storage for data - * @return Status : ERROR or SUCCESS - */ -Status Chip_ADC_ReadByte(LPC_ADC_T *pADC, ADC_CHANNEL_T channel, uint8_t *data); - -/** - * @brief Read the ADC channel status - * @param pADC : The base of ADC peripheral on the chip - * @param channel : ADC channel to read - * @param StatusType : Status type of ADC_DR_* - * @return SET or RESET - */ -FlagStatus Chip_ADC_ReadStatus(LPC_ADC_T *pADC, uint8_t channel, uint32_t StatusType); - -/** - * @brief Enable/Disable interrupt for ADC channel - * @param pADC : The base of ADC peripheral on the chip - * @param channel : ADC channel to read - * @param NewState : New state, ENABLE or DISABLE - * @return SET or RESET - */ -void Chip_ADC_Int_SetChannelCmd(LPC_ADC_T *pADC, uint8_t channel, FunctionalState NewState); - -/** - * @brief Enable/Disable global interrupt for ADC channel - * @param pADC : The base of ADC peripheral on the chip - * @param NewState : New state, ENABLE or DISABLE - * @return Nothing - */ -STATIC INLINE void Chip_ADC_Int_SetGlobalCmd(LPC_ADC_T *pADC, FunctionalState NewState) -{ - Chip_ADC_Int_SetChannelCmd(pADC, 8, NewState); -} - -/** - * @brief Select the mode starting the AD conversion - * @param pADC : The base of ADC peripheral on the chip - * @param mode : Stating mode, should be : - * - ADC_NO_START : Must be set for Burst mode - * - ADC_START_NOW : Start conversion now - * - ADC_START_ON_CTOUT15 : Start conversion when the edge selected by bit 27 occurs on CTOUT_15 - * - ADC_START_ON_CTOUT8 : Start conversion when the edge selected by bit 27 occurs on CTOUT_8 - * - ADC_START_ON_ADCTRIG0 : Start conversion when the edge selected by bit 27 occurs on ADCTRIG0 - * - ADC_START_ON_ADCTRIG1 : Start conversion when the edge selected by bit 27 occurs on ADCTRIG1 - * - ADC_START_ON_MCOA2 : Start conversion when the edge selected by bit 27 occurs on Motocon PWM output MCOA2 - * @param EdgeOption : Stating Edge Condition, should be : - * - ADC_TRIGGERMODE_RISING : Trigger event on rising edge - * - ADC_TRIGGERMODE_FALLING : Trigger event on falling edge - * @return Nothing - */ -void Chip_ADC_SetStartMode(LPC_ADC_T *pADC, ADC_START_MODE_T mode, ADC_EDGE_CFG_T EdgeOption); - -/** - * @brief Set the ADC Sample rate - * @param pADC : The base of ADC peripheral on the chip - * @param ADCSetup : ADC setup structure to be modified - * @param rate : Sample rate, should be set so the clock for A/D converter is less than or equal to 4.5MHz. - * @return Nothing - */ -void Chip_ADC_SetSampleRate(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup, uint32_t rate); - -/** - * @brief Set the ADC accuracy bits - * @param pADC : The base of ADC peripheral on the chip - * @param ADCSetup : ADC setup structure to be modified - * @param resolution : The resolution, should be ADC_10BITS -> ADC_3BITS - * @return Nothing - */ -void Chip_ADC_SetResolution(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup, ADC_RESOLUTION_T resolution); - -/** - * @brief Enable or disable the ADC channel on ADC peripheral - * @param pADC : The base of ADC peripheral on the chip - * @param channel : Channel to be enable or disable - * @param NewState : New state, should be: - * - ENABLE - * - DISABLE - * @return Nothing - */ -void Chip_ADC_EnableChannel(LPC_ADC_T *pADC, ADC_CHANNEL_T channel, FunctionalState NewState); - -/** - * @brief Enable burst mode - * @param pADC : The base of ADC peripheral on the chip - * @param NewState : New state, should be: - * - ENABLE - * - DISABLE - * @return Nothing - */ -void Chip_ADC_SetBurstCmd(LPC_ADC_T *pADC, FunctionalState NewState); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* !defined(CHIP_LPC1125) */ - -#endif /* __ADC_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ccand_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ccand_11xx.h deleted file mode 100755 index 820d7c0d59..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ccand_11xx.h +++ /dev/null @@ -1,170 +0,0 @@ -/* - * @brief LPC11xx CCAN ROM API declarations and functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __CCAND_11XX_H_ -#define __CCAND_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup CCANROM_11XX CHIP: LPC11xx CCAN ROM Driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * CCAN ROM error status bits - */ -#define CAN_ERROR_NONE 0x00000000UL -#define CAN_ERROR_PASS 0x00000001UL -#define CAN_ERROR_WARN 0x00000002UL -#define CAN_ERROR_BOFF 0x00000004UL -#define CAN_ERROR_STUF 0x00000008UL -#define CAN_ERROR_FORM 0x00000010UL -#define CAN_ERROR_ACK 0x00000020UL -#define CAN_ERROR_BIT1 0x00000040UL -#define CAN_ERROR_BIT0 0x00000080UL -#define CAN_ERROR_CRC 0x00000100UL - -/** - * CCAN ROM control bits for CAN_MSG_OBJ.mode_id - */ -#define CAN_MSGOBJ_STD 0x00000000UL /* CAN 2.0a 11-bit ID */ -#define CAN_MSGOBJ_EXT 0x20000000UL /* CAN 2.0b 29-bit ID */ -#define CAN_MSGOBJ_DAT 0x00000000UL /* data frame */ -#define CAN_MSGOBJ_RTR 0x40000000UL /* rtr frame */ - -typedef struct CCAN_MSG_OBJ { - uint32_t mode_id; - uint32_t mask; - uint8_t data[8]; - uint8_t dlc; - uint8_t msgobj; -} CCAN_MSG_OBJ_T; - -/************************************************************************** - SDO Abort Codes -**************************************************************************/ -#define SDO_ABORT_TOGGLE 0x05030000UL // Toggle bit not alternated -#define SDO_ABORT_SDOTIMEOUT 0x05040000UL // SDO protocol timed out -#define SDO_ABORT_UNKNOWN_COMMAND 0x05040001UL // Client/server command specifier not valid or unknown -#define SDO_ABORT_UNSUPPORTED 0x06010000UL // Unsupported access to an object -#define SDO_ABORT_WRITEONLY 0x06010001UL // Attempt to read a write only object -#define SDO_ABORT_READONLY 0x06010002UL // Attempt to write a read only object -#define SDO_ABORT_NOT_EXISTS 0x06020000UL // Object does not exist in the object dictionary -#define SDO_ABORT_PARAINCOMP 0x06040043UL // General parameter incompatibility reason -#define SDO_ABORT_ACCINCOMP 0x06040047UL // General internal incompatibility in the device -#define SDO_ABORT_TYPEMISMATCH 0x06070010UL // Data type does not match, length of service parameter does not match -#define SDO_ABORT_UNKNOWNSUB 0x06090011UL // Sub-index does not exist -#define SDO_ABORT_VALUE_RANGE 0x06090030UL // Value range of parameter exceeded (only for write access) -#define SDO_ABORT_TRANSFER 0x08000020UL // Data cannot be transferred or stored to the application -#define SDO_ABORT_LOCAL 0x08000021UL // Data cannot be transferred or stored to the application because of local control -#define SDO_ABORT_DEVSTAT 0x08000022UL // Data cannot be transferred or stored to the application because of the present device state - -typedef struct CCAN_ODCONSTENTRY { - uint16_t index; - uint8_t subindex; - uint8_t len; - uint32_t val; -} CCAN_ODCONSTENTRY_T; - -// upper-nibble values for CAN_ODENTRY.entrytype_len -#define OD_NONE 0x00 // Object Dictionary entry doesn't exist -#define OD_EXP_RO 0x10 // Object Dictionary entry expedited, read-only -#define OD_EXP_WO 0x20 // Object Dictionary entry expedited, write-only -#define OD_EXP_RW 0x30 // Object Dictionary entry expedited, read-write -#define OD_SEG_RO 0x40 // Object Dictionary entry segmented, read-only -#define OD_SEG_WO 0x50 // Object Dictionary entry segmented, write-only -#define OD_SEG_RW 0x60 // Object Dictionary entry segmented, read-write - -typedef struct CCAN_ODENTRY { - uint16_t index; - uint8_t subindex; - uint8_t entrytype_len; - uint8_t *val; -} CCAN_ODENTRY_T; - -typedef struct CCAN_CANOPENCFG { - uint8_t node_id; - uint8_t msgobj_rx; - uint8_t msgobj_tx; - uint8_t isr_handled; - uint32_t od_const_num; - CCAN_ODCONSTENTRY_T *od_const_table; - uint32_t od_num; - CCAN_ODENTRY_T *od_table; -} CCAN_CANOPENCFG_T; - -// Return values for CANOPEN_sdo_req() callback -#define CAN_SDOREQ_NOTHANDLED 0 // process regularly, no impact -#define CAN_SDOREQ_HANDLED_SEND 1 // processed in callback, auto-send returned msg -#define CAN_SDOREQ_HANDLED_NOSEND 2 // processed in callback, don't send response - -// Values for CANOPEN_sdo_seg_read/write() callback 'openclose' parameter -#define CAN_SDOSEG_SEGMENT 0 // segment read/write -#define CAN_SDOSEG_OPEN 1 // channel is opened -#define CAN_SDOSEG_CLOSE 2 // channel is closed - -typedef struct CCAN_CALLBACKS { - void (*CAN_rx)(uint8_t msg_obj_num); - void (*CAN_tx)(uint8_t msg_obj_num); - void (*CAN_error)(uint32_t error_info); - uint32_t (*CANOPEN_sdo_read)(uint16_t index, uint8_t subindex); - uint32_t (*CANOPEN_sdo_write)(uint16_t index, uint8_t subindex, uint8_t *dat_ptr); - uint32_t (*CANOPEN_sdo_seg_read)(uint16_t index, uint8_t subindex, uint8_t openclose, uint8_t *length, - uint8_t *data, uint8_t *last); - uint32_t (*CANOPEN_sdo_seg_write)(uint16_t index, uint8_t subindex, uint8_t openclose, uint8_t length, - uint8_t *data, uint8_t *fast_resp); - uint8_t (*CANOPEN_sdo_req)(uint8_t length_req, uint8_t *req_ptr, uint8_t *length_resp, uint8_t *resp_ptr); -} CCAN_CALLBACKS_T; - -typedef struct CCAN_API { - void (*init_can)(uint32_t *can_cfg, uint8_t isr_ena); - void (*isr)(void); - void (*config_rxmsgobj)(CCAN_MSG_OBJ_T *msg_obj); - uint8_t (*can_receive)(CCAN_MSG_OBJ_T *msg_obj); - void (*can_transmit)(CCAN_MSG_OBJ_T *msg_obj); - void (*config_canopen)(CCAN_CANOPENCFG_T *canopen_cfg); - void (*canopen_handler)(void); - void (*config_calb)(CCAN_CALLBACKS_T *callback_cfg); -} CCAN_API_T; - -#define LPC_CCAN_API ((CCAN_API_T *) (LPC_ROM_API->candApiBase)) -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CCAND_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/chip.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/chip.h deleted file mode 100755 index 9d4951da30..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/chip.h +++ /dev/null @@ -1,309 +0,0 @@ -/* - * @brief LPC11xx basic chip inclusion file - * - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __CHIP_H_ -#define __CHIP_H_ - -#include "lpc_types.h" -#include "sys_config.h" -#include "cmsis.h" - -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef CORE_M0 -#error CORE_M0 is not defined for the LPC11xx architecture -#error CORE_M0 should be defined as part of your compiler define list -#endif - -#if !defined(ENABLE_UNTESTED_CODE) -#if defined(CHIP_LPC110X) -#warning The LCP110X code has not been tested with a platform. This code should \ -build without errors but may not work correctly for the device. To disable this \ -#warning message, define ENABLE_UNTESTED_CODE. -#endif -#if defined(CHIP_LPC11XXLV) -#warning The LPC11XXLV code has not been tested with a platform. This code should \ -build without errors but may not work correctly for the device. To disable this \ -#warning message, define ENABLE_UNTESTED_CODE. -#endif -#if defined(CHIP_LPC11AXX) -#warning The LPC11AXX code has not been tested with a platform. This code should \ -build without errors but may not work correctly for the device. To disable this \ -#warning message, define ENABLE_UNTESTED_CODE. -#endif -#if defined(CHIP_LPC11EXX) -#warning The LPC11EXX code has not been tested with a platform. This code should \ -build without errors but may not work correctly for the device. To disable this \ -warning message, define ENABLE_UNTESTED_CODE. -#endif -#endif - -#if !defined(CHIP_LPC110X) && !defined(CHIP_LPC11XXLV) && !defined(CHIP_LPC11AXX) && \ - !defined(CHIP_LPC11CXX) && !defined(CHIP_LPC11EXX) && !defined(CHIP_LPC11UXX) && \ - !defined(CHIP_LPC1125) -#error CHIP_LPC110x/CHIP_LPC11XXLV/CHIP_LPC11AXX/CHIP_LPC11CXX/CHIP_LPC11EXX/CHIP_LPC11UXX/CHIP_LPC1125 is not defined! -#endif - -/* Peripheral mapping per device - Peripheral Device(s) - ---------------------------- ------------------------------------------------------------------------------------------------------------- - I2C(40000000) CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - WDT(40004000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - UART0(40008000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX CHIP_LPC1125 - UART1(40020000) CHIP_LPC1125 - UART2(40024000) CHIP_LPC1125 - USART/SMARTCARD(40008000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX - TIMER0_16(4000C000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - TIMER1_16(40010000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - TIMER0_32(40014000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - TIMER1_32(40018000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - ADC(4001C000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - DAC(40024000) CHIP_LPC11AXX - ACMP(40028000) CHIP_LPC11AXX - PMU(40038000) CHIP_LPC110x/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX CHIP_LPC1125 - FLASH_CTRL(4003C000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX CHIP_LPC1125 - FLASH_EEPROM(4003C000) CHIP_LPC11EXX/ CHIP_LPC11AXX - SPI0(40040000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX - SSP0(40040000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - IOCONF(40044000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - SYSCON(40048000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX/ CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - GPIOINTS(4004C000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX - USB(40080000) CHIP_LPC11UXX - CCAN(40050000) CHIP_LPC11CXX - SPI1(40058000) CHIP_LPC11CXX - SSP1(40058000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX CHIP_LPC1125 - GPIO_GRP0_INT(4005C000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX - GPIO_GRP1_INT(40060000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX - GPIO_PORT(50000000) CHIP_LPC11UXX/ CHIP_LPC11EXX/ CHIP_LPC11AXX - GPIO_PIO0(50000000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX CHIP_LPC1125 - GPIO_PIO1(50010000) CHIP_LPC110x/ CHIP_LPC11XXLV/ CHIP_LPC11CXX CHIP_LPC1125 - GPIO_PIO2(50020000) CHIP_LPC11XXLV/ CHIP_LPC11CXX CHIP_LPC1125 - GPIO_PIO3(50030000) CHIP_LPC11XXLV/ CHIP_LPC11CXX CHIP_LPC1125 - */ - -/** @defgroup PERIPH_11XX_BASE CHIP: LPC11xx Peripheral addresses and register set declarations - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -#define LPC_I2C_BASE 0x40000000 -#define LPC_WWDT_BASE 0x40004000 -#define LPC_USART_BASE 0x40008000 -#define LPC_TIMER16_0_BASE 0x4000C000 -#define LPC_TIMER16_1_BASE 0x40010000 -#define LPC_TIMER32_0_BASE 0x40014000 -#define LPC_TIMER32_1_BASE 0x40018000 -#define LPC_ADC_BASE 0x4001C000 -#define LPC_DAC_BASE 0x40024000 -#define LPC_ACMP_BASE 0x40028000 -#define LPC_PMU_BASE 0x40038000 -#define LPC_FLASH_BASE 0x4003C000 -#define LPC_SSP0_BASE 0x40040000 -#define LPC_IOCON_BASE 0x40044000 -#define LPC_SYSCTL_BASE 0x40048000 -#define LPC_USB0_BASE 0x40080000 -#define LPC_CAN0_BASE 0x40050000 -#define LPC_SSP1_BASE 0x40058000 -#if defined(CHIP_LPC1125) -#define LPC_USART1_BASE 0x40020000 -#define LPC_USART2_BASE 0x40024000 -#endif -#if defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) -#define LPC_GPIO_PIN_INT_BASE 0x4004C000 -#define LPC_GPIO_GROUP_INT0_BASE 0x4005C000 -#define LPC_GPIO_GROUP_INT1_BASE 0x40060000 -#define LPC_GPIO_PORT_BASE 0x50000000 -#else -#define LPC_GPIO_PORT0_BASE 0x50000000 -#define LPC_GPIO_PORT1_BASE 0x50010000 -#if defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC1125) -#define LPC_GPIO_PORT2_BASE 0x50020000 -#define LPC_GPIO_PORT3_BASE 0x50030000 -#endif /* defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC1125) */ -#endif /* defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) */ -#define IAP_ENTRY_LOCATION 0X1FFF1FF1 -#define LPC_ROM_API_BASE_LOC 0x1FFF1FF8 - -#if !defined(CHIP_LPC110x) -#define LPC_I2C ((LPC_I2C_T *) LPC_I2C_BASE) -#endif - -#define LPC_WWDT ((LPC_WWDT_T *) LPC_WWDT_BASE) -#define LPC_USART ((LPC_USART_T *) LPC_USART_BASE) -#define LPC_TIMER16_0 ((LPC_TIMER_T *) LPC_TIMER16_0_BASE) -#define LPC_TIMER16_1 ((LPC_TIMER_T *) LPC_TIMER16_1_BASE) -#define LPC_TIMER32_0 ((LPC_TIMER_T *) LPC_TIMER32_0_BASE) -#define LPC_TIMER32_1 ((LPC_TIMER_T *) LPC_TIMER32_1_BASE) -#define LPC_ADC ((LPC_ADC_T *) LPC_ADC_BASE) - -#if defined(CHIP_LPC1125) -#define LPC_USART0 LPC_USART -#define LPC_USART1 ((LPC_USART_T *) LPC_USART1_BASE) -#define LPC_USART2 ((LPC_USART_T *) LPC_USART2_BASE) -#endif - -#if defined(CHIP_LPC11AXX) -#define LPC_DAC ((LPC_DAC_T *) LPC_DAC_BASE) -#define LPC_CMP ((LPC_CMP_T *) LPC_ACMP_BASE) -#endif - -#define LPC_PMU ((LPC_PMU_T *) LPC_PMU_BASE) -#define LPC_FMC ((LPC_FMC_T *) LPC_FLASH_BASE) -#define LPC_SSP0 ((LPC_SSP_T *) LPC_SSP0_BASE) -#define LPC_IOCON ((LPC_IOCON_T *) LPC_IOCON_BASE) -#define LPC_SYSCTL ((LPC_SYSCTL_T *) LPC_SYSCTL_BASE) -#if defined(CHIP_LPC11CXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) || defined(CHIP_LPC1125) -#define LPC_SSP1 ((LPC_SSP_T *) LPC_SSP1_BASE) -#endif -#define LPC_USB ((LPC_USB_T *) LPC_USB0_BASE) - -#if defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) -#define LPC_PININT ((LPC_PIN_INT_T *) LPC_GPIO_PIN_INT_BASE) -#define LPC_GPIOGROUP ((LPC_GPIOGROUPINT_T *) LPC_GPIO_GROUP_INT0_BASE) -#define LPC_GPIO ((LPC_GPIO_T *) LPC_GPIO_PORT_BASE) -#else -#define LPC_GPIO ((LPC_GPIO_T *) LPC_GPIO_PORT0_BASE) -#endif - -#define LPC_ROM_API (*((LPC_ROM_API_T * *) LPC_ROM_API_BASE_LOC)) - - -/** - * @} - */ - -/** @ingroup CHIP_11XX_DRIVER_OPTIONS - */ - -/** - * @brief System oscillator rate - * This value is defined externally to the chip layer and contains - * the value in Hz for the external oscillator for the board. If using the - * internal oscillator, this rate can be 0. - */ -extern const uint32_t OscRateIn; - -/** - * @} - */ - -/** @ingroup CHIP_11XX_DRIVER_OPTIONS - */ - -/** - * @brief Clock rate on the CLKIN pin - * This value is defined externally to the chip layer and contains - * the value in Hz for the CLKIN pin for the board. If this pin isn't used, - * this rate can be 0. - */ -extern const uint32_t ExtRateIn; - -/** - * @} - */ - -#include "pmu_11xx.h" -#include "fmc_11xx.h" -#include "sysctl_11xx.h" -#include "clock_11xx.h" -#include "iocon_11xx.h" -#include "timer_11xx.h" -#include "uart_11xx.h" -#include "wwdt_11xx.h" -#include "ssp_11xx.h" -#include "romapi_11xx.h" - -#if !defined(CHIP_LPC1125) -/* All LPC1xx devices except the LPC1125 */ -#include "adc_11xx.h" - -#else -/* LPC1125 has different IP than other LPC11xx devices */ -#include "adc_1125.h" -#endif - -/* Different GPIO/GPIOGROUP/PININT blocks for parts with similar numbers */ -#if defined(CHIP_LPC11CXX) || defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC1125) -#include "gpio_11xx_2.h" -#else -#include "gpio_11xx_1.h" -#include "gpiogroup_11xx.h" -#include "pinint_11xx.h" -#endif - -/* Family specific drivers */ -#if defined(CHIP_LPC11AXX) -#include "acmp_11xx.h" -#include "dac_11xx.h" -#endif -#if !defined(CHIP_LPC110X) -#include "i2c_11xx.h" -#endif -#if defined(CHIP_LPC11CXX) -#include "ccand_11xx.h" -#endif -#if defined(CHIP_LPC11UXX) -#include "usbd_11xx.h" -#endif - -/** @defgroup SUPPORT_11XX_FUNC CHIP: LPC11xx support functions - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief Current system clock rate, mainly used for sysTick - */ -extern uint32_t SystemCoreClock; - -/** - * @brief Update system core clock rate, should be called if the - * system has a clock rate change - * @return None - */ -void SystemCoreClockUpdate(void); - -/** - * @brief Set up and initialize hardware prior to call to main() - * @return None - * @note Chip_SystemInit() is called prior to the application and sets up - * system clocking prior to the application starting. - */ -void Chip_SystemInit(void); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CHIP_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/clock_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/clock_11xx.h deleted file mode 100755 index e19ae6eaa5..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/clock_11xx.h +++ /dev/null @@ -1,547 +0,0 @@ -/* - * @brief LPC11XX Clock control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __CLOCK_11XX_H_ -#define __CLOCK_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup CLOCK_11XX CHIP: LPC11xx Clock Control block driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** Internal oscillator frequency */ -#define SYSCTL_IRC_FREQ (12000000) - -/** - * @brief Set System PLL divider values - * @param msel : PLL feedback divider value. M = msel + 1. - * @param psel : PLL post divider value. P = (1<SYSPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5); -} - -/** - * @brief Read System PLL lock status - * @return true of the PLL is locked. false if not locked - */ -STATIC INLINE bool Chip_Clock_IsSystemPLLLocked(void) -{ - return (bool) ((LPC_SYSCTL->SYSPLLSTAT & 1) != 0); -} - -/** - * Clock sources for system and USB PLLs - */ -typedef enum CHIP_SYSCTL_PLLCLKSRC { - SYSCTL_PLLCLKSRC_IRC = 0, /*!< Internal oscillator in */ - SYSCTL_PLLCLKSRC_MAINOSC, /*!< Crystal (main) oscillator in */ -#if defined(CHIP_LPC11AXX) - SYSCTL_PLLCLKSRC_EXT_CLKIN, /*!< External clock in (11Axx only) */ -#else - SYSCTL_PLLCLKSRC_RESERVED1, /*!< Reserved */ -#endif - SYSCTL_PLLCLKSRC_RESERVED2, /*!< Reserved */ -} CHIP_SYSCTL_PLLCLKSRC_T; - -/** - * @brief Set System PLL clock source - * @param src : Clock source for system PLL - * @return Nothing - * @note This function will also toggle the clock source update register - * to update the clock source. - */ -void Chip_Clock_SetSystemPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src); - -#if defined(CHIP_LPC11UXX) -/** - * @brief Set USB PLL divider values - * @param msel : PLL feedback divider value. M = msel + 1. - * @param psel : PLL post divider value. P = (1<USBPLLCTRL = (msel & 0x1F) | ((psel & 0x3) << 5); -} - -/** - * @brief Read USB PLL lock status - * @return true of the PLL is locked. false if not locked - */ -STATIC INLINE bool Chip_Clock_IsUSBPLLLocked(void) -{ - return (bool) ((LPC_SYSCTL->USBPLLSTAT & 1) != 0); -} - -/** - * @brief Set USB PLL clock source - * @param src : Clock source for USB PLL - * @return Nothing - * @note This function will also toggle the clock source update register - * to update the clock source. - */ -void Chip_Clock_SetUSBPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src); - -#endif /*defined(CHIP_LPC11UXX)*/ - -/** - * @brief Bypass System Oscillator and set oscillator frequency range - * @param bypass : Flag to bypass oscillator - * @param highfr : Flag to set oscillator range from 15-25 MHz - * @return Nothing - * @note Sets the PLL input to bypass the oscillator. This would be - * used if an external clock that is not an oscillator is attached - * to the XTALIN pin. - */ -void Chip_Clock_SetPLLBypass(bool bypass, bool highfr); - -/** - * Watchdog and low frequency oscillator frequencies plus or minus 40% - */ -typedef enum CHIP_WDTLFO_OSC { - WDTLFO_OSC_ILLEGAL, - WDTLFO_OSC_0_60, /*!< 0.6 MHz watchdog/LFO rate */ - WDTLFO_OSC_1_05, /*!< 1.05 MHz watchdog/LFO rate */ - WDTLFO_OSC_1_40, /*!< 1.4 MHz watchdog/LFO rate */ - WDTLFO_OSC_1_75, /*!< 1.75 MHz watchdog/LFO rate */ - WDTLFO_OSC_2_10, /*!< 2.1 MHz watchdog/LFO rate */ - WDTLFO_OSC_2_40, /*!< 2.4 MHz watchdog/LFO rate */ - WDTLFO_OSC_2_70, /*!< 2.7 MHz watchdog/LFO rate */ - WDTLFO_OSC_3_00, /*!< 3.0 MHz watchdog/LFO rate */ - WDTLFO_OSC_3_25, /*!< 3.25 MHz watchdog/LFO rate */ - WDTLFO_OSC_3_50, /*!< 3.5 MHz watchdog/LFO rate */ - WDTLFO_OSC_3_75, /*!< 3.75 MHz watchdog/LFO rate */ - WDTLFO_OSC_4_00, /*!< 4.0 MHz watchdog/LFO rate */ - WDTLFO_OSC_4_20, /*!< 4.2 MHz watchdog/LFO rate */ - WDTLFO_OSC_4_40, /*!< 4.4 MHz watchdog/LFO rate */ - WDTLFO_OSC_4_60 /*!< 4.6 MHz watchdog/LFO rate */ -} CHIP_WDTLFO_OSC_T; - -/** - * @brief Setup Watchdog oscillator rate and divider - * @param wdtclk : Selected watchdog clock rate - * @param div : Watchdog divider value, even value between 2 and 64 - * @return Nothing - * @note Watchdog rate = selected rate divided by divider rate - */ -STATIC INLINE void Chip_Clock_SetWDTOSC(CHIP_WDTLFO_OSC_T wdtclk, uint8_t div) -{ - LPC_SYSCTL->WDTOSCCTRL = (((uint32_t) wdtclk) << 5) | ((div >> 1) - 1); -} - -#if defined(CHIP_LPC11AXX) -/** - * @brief Setup low frequency oscillator rate and divider - * @param lfoclk : Selected low frequency clock rate - * @param div : Low frequency divider value, even value between 2 and 64 - * @return Nothing - * @note Low frequency oscillator rate = selected rate divided by divider rate - */ -STATIC INLINE void Chip_Clock_SetLFOSC(CHIP_WDTLFO_OSC_T lfoclk, uint8_t div) -{ - LPC_SYSCTL->LFOSCCTRL = (((uint32_t) lfoclk) << 5) | ((div >> 1) - 1); -} - -#endif /*CHIP_LPC11AXX*/ - -/** - * Clock sources for main system clock - */ -typedef enum CHIP_SYSCTL_MAINCLKSRC { - SYSCTL_MAINCLKSRC_IRC = 0, /*!< Internal oscillator */ - SYSCTL_MAINCLKSRC_PLLIN, /*!< System PLL input */ - SYSCTL_MAINCLKSRC_LFOSC, /*!< LF oscillator rate (11Axx only) */ - SYSCTL_MAINCLKSRC_WDTOSC = SYSCTL_MAINCLKSRC_LFOSC, /*!< Watchdog oscillator rate */ - SYSCTL_MAINCLKSRC_PLLOUT, /*!< System PLL output */ -} CHIP_SYSCTL_MAINCLKSRC_T; - -/** - * @brief Set main system clock source - * @param src : Clock source for main system - * @return Nothing - * @note This function will also toggle the clock source update register - * to update the clock source. - */ -void Chip_Clock_SetMainClockSource(CHIP_SYSCTL_MAINCLKSRC_T src); - -/** - * @brief Returns the main clock source - * @return Which clock is used for the core clock source? - */ -STATIC INLINE CHIP_SYSCTL_MAINCLKSRC_T Chip_Clock_GetMainClockSource(void) -{ - return (CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL); -} - -/** - * @brief Set system clock divider - * @param div : divider for system clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The system clock - * rate is the main system clock divided by this value. - */ -STATIC INLINE void Chip_Clock_SetSysClockDiv(uint32_t div) -{ - LPC_SYSCTL->SYSAHBCLKDIV = div; -} - -/** - * System and peripheral clocks - */ -typedef enum CHIP_SYSCTL_CLOCK { - SYSCTL_CLOCK_SYS = 0, /*!< 0: System clock */ - SYSCTL_CLOCK_ROM, /*!<1: ROM clock */ - SYSCTL_CLOCK_RAM, /*!< 2: RAM clock */ - SYSCTL_CLOCK_FLASHREG, /*!< 3: FLASH register interface clock */ - SYSCTL_CLOCK_FLASHARRAY, /*!< 4: FLASH array access clock */ -#if defined(CHIP_LPC110X) - SYSCTL_CLOCK_RESERVED5, /*!< 5: Reserved */ -#else - SYSCTL_CLOCK_I2C, /*!< 5: I2C clock, not on LPC110x */ -#endif - SYSCTL_CLOCK_GPIO, /*!< 6: GPIO clock */ - SYSCTL_CLOCK_CT16B0, /*!< 7: 16-bit Counter/timer 0 clock */ - SYSCTL_CLOCK_CT16B1, /*!< 8: 16-bit Counter/timer 1 clock */ - SYSCTL_CLOCK_CT32B0, /*!< 9: 32-bit Counter/timer 0 clock */ - SYSCTL_CLOCK_CT32B1, /*!< 10: 32-bit Counter/timer 1 clock */ - SYSCTL_CLOCK_SSP0, /*!< 11: SSP0 clock */ - SYSCTL_CLOCK_UART0, /*!< 12: UART0 clock */ - SYSCTL_CLOCK_ADC, /*!< 13: ADC clock */ -#if defined(CHIP_LPC11UXX) - SYSCTL_CLOCK_USB, /*!< 14: USB clock, LPC11Uxx only */ -#else - SYSCTL_CLOCK_RESERVED14, /*!< 14: Reserved */ -#endif - SYSCTL_CLOCK_WDT, /*!< 15: Watchdog timer clock */ - SYSCTL_CLOCK_IOCON, /*!< 16: IOCON block clock */ -#if defined(CHIP_LPC11CXX) - SYSCTL_CLOCK_CAN, /*!< 17: CAN clock, LPC11Cxx only */ -#else - SYSCTL_CLOCK_RESERVED17, /*!< 17: Reserved */ -#endif -#if !(defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV)) - SYSCTL_CLOCK_SSP1, /*!< 18: SSP1 clock, LPC11A/C/E/Uxx//1125 only */ -#if !defined(CHIP_LPC11CXX) - SYSCTL_CLOCK_PINT, /*!< 19: GPIO Pin int register interface clock, LPC11A/E/Uxx only */ -#if defined(CHIP_LPC11AXX) - SYSCTL_CLOCK_ACOMP, /*!< 20: Analog comparator clock, LPC11Axx only */ - SYSCTL_CLOCK_DAC, /*!< 21: DAC clock, LPC11Axx only */ -#else - SYSCTL_CLOCK_RESERVED20, /*!< 20: Reserved */ - SYSCTL_CLOCK_RESERVED21, /*!< 21: Reserved */ -#endif - SYSCTL_CLOCK_RESERVED22, /*!< 22: Reserved */ - SYSCTL_CLOCK_P0INT, /*!< 23: GPIO GROUP1 interrupt register clock, LPC11Axx only */ - SYSCTL_CLOCK_GROUP0INT = SYSCTL_CLOCK_P0INT,/*!< 23: GPIO GROUP0 interrupt register interface clock, LPC11E/Uxx only */ - SYSCTL_CLOCK_P1INT, /*!< 24: GPIO GROUP1 interrupt register clock, LPC11Axx only */ - SYSCTL_CLOCK_GROUP1INT = SYSCTL_CLOCK_P1INT,/*!< 24: GPIO GROUP1 interrupt register interface clock, LPC11E/Uxx only */ - SYSCTL_CLOCK_RESERVED25, /*!< 25: Reserved */ -#if defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) - SYSCTL_CLOCK_RAM1, /*!< 26: SRAM block (0x20000000) clock, LPC11E/Uxx only */ -#else - SYSCTL_CLOCK_RESERVED26, /*!< 26: Reserved */ -#endif -#if defined(CHIP_LPC11UXX) - SYSCTL_CLOCK_USBRAM, /*!< 27: USB SRAM block clock, LPC11Uxx only */ -#else - SYSCTL_CLOCK_RESERVED27, /*!< 27: Reserved */ -#endif -#endif /* !defined(CHIP_LPC11CXX) */ -#endif /* !(defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV)) */ -} CHIP_SYSCTL_CLOCK_T; - -/** - * @brief Enable a system or peripheral clock - * @param clk : Clock to enable - * @return Nothing - */ -STATIC INLINE void Chip_Clock_EnablePeriphClock(CHIP_SYSCTL_CLOCK_T clk) -{ - LPC_SYSCTL->SYSAHBCLKCTRL |= (1 << clk); -} - -/** - * @brief Disable a system or peripheral clock - * @param clk : Clock to disable - * @return Nothing - */ -STATIC INLINE void Chip_Clock_DisablePeriphClock(CHIP_SYSCTL_CLOCK_T clk) -{ - LPC_SYSCTL->SYSAHBCLKCTRL &= ~(1 << clk); -} - -/** - * @brief Set SSP0 divider - * @param div : divider for SSP0 clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The SSP0 clock - * rate is the main system clock divided by this value. - */ -STATIC INLINE void Chip_Clock_SetSSP0ClockDiv(uint32_t div) -{ - LPC_SYSCTL->SSP0CLKDIV = div; -} - -/** - * @brief Return SSP0 divider - * @return divider for SSP0 clock - * @note A value of 0 means the clock is disabled. - */ -STATIC INLINE uint32_t Chip_Clock_GetSSP0ClockDiv(void) -{ - return LPC_SYSCTL->SSP0CLKDIV; -} - -/** - * @brief Set UART divider clock - * @param div : divider for UART clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The UART clock - * rate is the main system clock divided by this value. - */ -STATIC INLINE void Chip_Clock_SetUARTClockDiv(uint32_t div) -{ - LPC_SYSCTL->USARTCLKDIV = div; -} - -/** - * @brief Return UART divider - * @return divider for UART clock - * @note A value of 0 means the clock is disabled. - */ -STATIC INLINE uint32_t Chip_Clock_GetUARTClockDiv(void) -{ - return LPC_SYSCTL->USARTCLKDIV; -} - -#if defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC1125) -/** - * @brief Set SSP1 divider clock - * @param div : divider for SSP1 clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The SSP1 clock - * rate is the main system clock divided by this value. - */ -STATIC INLINE void Chip_Clock_SetSSP1ClockDiv(uint32_t div) -{ - LPC_SYSCTL->SSP1CLKDIV = div; -} - -/** - * @brief Return SSP1 divider - * @return divider for SSP1 clock - * @note A value of 0 means the clock is disabled. - */ -STATIC INLINE uint32_t Chip_Clock_GetSSP1ClockDiv(void) -{ - return LPC_SYSCTL->SSP1CLKDIV; -} - -#endif /*defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) || defined(CHIP_LPC11UXX)*/ - -#if defined(CHIP_LPC11UXX) -/** - * Clock sources for USB - */ -typedef enum CHIP_SYSCTL_USBCLKSRC { - SYSCTL_USBCLKSRC_PLLOUT = 0, /*!< USB PLL out */ - SYSCTL_USBCLKSRC_MAINSYSCLK, /*!< Main system clock */ -} CHIP_SYSCTL_USBCLKSRC_T; - -/** - * @brief Set USB clock source and divider - * @param src : Clock source for USB - * @param div : divider for USB clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The USB clock - * rate is either the main system clock or USB PLL output clock divided - * by this value. This function will also toggle the clock source - * update register to update the clock source. - */ -void Chip_Clock_SetUSBClockSource(CHIP_SYSCTL_USBCLKSRC_T src, uint32_t div); - -#endif /*CHIP_LPC11UXX*/ - -#if defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC1125) -/** - * Clock sources for WDT - */ -typedef enum CHIP_SYSCTL_WDTCLKSRC { - SYSCTL_WDTCLKSRC_IRC = 0, /*!< Internal oscillator for watchdog clock */ - SYSCTL_WDTCLKSRC_MAINSYSCLK, /*!< Main system clock for watchdog clock */ - SYSCTL_WDTCLKSRC_WDTOSC, /*!< Watchdog oscillator for watchdog clock */ -} CHIP_SYSCTL_WDTCLKSRC_T; - -/** - * @brief Set WDT clock source and divider - * @param src : Clock source for WDT - * @param div : divider for WDT clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The WDT clock - * rate is the clock source divided by the divider. This function will - * also toggle the clock source update register to update the clock - * source. - */ -void Chip_Clock_SetWDTClockSource(CHIP_SYSCTL_WDTCLKSRC_T src, uint32_t div); - -#endif - -#if !defined(CHIP_LPC110X) -/** - * Clock sources for CLKOUT - */ -typedef enum CHIP_SYSCTL_CLKOUTSRC { - SYSCTL_CLKOUTSRC_IRC = 0, /*!< Internal oscillator for CLKOUT */ - SYSCTL_CLKOUTSRC_MAINOSC, /*!< Main oscillator for CLKOUT */ - SYSCTL_CLKOUTSRC_WDTOSC, /*!< Watchdog oscillator for CLKOUT */ - SYSCTL_CLKOUTSRC_LFOSC = SYSCTL_CLKOUTSRC_WDTOSC, /*!< LF oscillator rate (LPC11A/Exx only) for CLKOUT */ - SYSCTL_CLKOUTSRC_MAINSYSCLK, /*!< Main system clock for CLKOUT */ -} CHIP_SYSCTL_CLKOUTSRC_T; - -/** - * @brief Set CLKOUT clock source and divider - * @param src : Clock source for CLKOUT - * @param div : divider for CLKOUT clock - * @return Nothing - * @note Use 0 to disable, or a divider value of 1 to 255. The CLKOUT clock - * rate is the clock source divided by the divider. This function will - * also toggle the clock source update register to update the clock - * source. - */ -void Chip_Clock_SetCLKOUTSource(CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div); - -#endif - -/** - * @brief Returns the main oscillator clock rate - * @return main oscillator clock rate - */ -STATIC INLINE uint32_t Chip_Clock_GetMainOscRate(void) -{ - return OscRateIn; -} - -/** - * @brief Returns the internal oscillator (IRC) clock rate - * @return internal oscillator (IRC) clock rate - */ -STATIC INLINE uint32_t Chip_Clock_GetIntOscRate(void) -{ - return SYSCTL_IRC_FREQ; -} - -#if defined(CHIP_LPC11AXX) -/** - * @brief Returns the external clock input rate - * @return internal external clock input rate - * @note LPC11Axx devices only - */ -STATIC INLINE uint32_t Chip_Clock_GetExtClockInRate(void) -{ - return ExtRateIn; -} - -#endif - -/** - * @brief Return estimated watchdog oscillator rate - * @return Estimated watchdog oscillator rate - * @note This rate is accurate to plus or minus 40%. - */ -uint32_t Chip_Clock_GetWDTOSCRate(void); - -#if defined(CHIP_LPC11AXX) -/** - * @brief Return estimated low frequency oscillator rate - * @return Estimated low frequency oscillator rate - * @note This rate is accurate to plus or minus 40%. - */ -uint32_t Chip_Clock_GetLFOOSCRate(void); - -#endif - -/** - * @brief Return System PLL input clock rate - * @return System PLL input clock rate - */ -uint32_t Chip_Clock_GetSystemPLLInClockRate(void); - -/** - * @brief Return System PLL output clock rate - * @return System PLL output clock rate - */ -uint32_t Chip_Clock_GetSystemPLLOutClockRate(void); - -#if defined(CHIP_LPC11UXX) -/** - * @brief Return USB PLL input clock rate - * @return USB PLL input clock rate - */ -uint32_t Chip_Clock_GetUSBPLLInClockRate(void); - -/** - * @brief Return USB PLL output clock rate - * @return USB PLL output clock rate - */ -uint32_t Chip_Clock_GetUSBPLLOutClockRate(void); - -#endif - -/** - * @brief Return main clock rate - * @return main clock rate - */ -uint32_t Chip_Clock_GetMainClockRate(void); - -/** - * @brief Return system clock rate - * @return system clock rate - */ -uint32_t Chip_Clock_GetSystemClockRate(void); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CLOCK_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis.h deleted file mode 100755 index 81300fface..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * @brief LPC11xx selective CMSIS inclusion file - * - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __CMSIS_H_ -#define __CMSIS_H_ - -#include "lpc_types.h" -#include "sys_config.h" - -/* Select correct CMSIS include file based on CHIP_* definition */ -#if defined(CHIP_LPC110X) -#include "cmsis_110x.h" -typedef LPC110X_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC1125) -#include "cmsis_1125.h" -typedef LPC1125_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC11AXX) -#include "cmsis_11axx.h" -typedef LPC11AXX_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC11CXX) -#include "cmsis_11cxx.h" -typedef LPC11CXX_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC11EXX) -#include "cmsis_11exx.h" -typedef LPC11EXX_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC11UXX) -#include "cmsis_11uxx.h" -typedef LPC11UXX_IRQn_Type IRQn_Type; -#elif defined(CHIP_LPC11XXLV) -#include "cmsis_11lvxx.h" -typedef LPC11XXLV_IRQn_Type IRQn_Type; -#else -#error "No CHIP_* definition is defined" -#endif - -/* Cortex-M0 processor and core peripherals */ -#include "core_cm0.h" - -#endif /* __CMSIS_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis_11cxx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis_11cxx.h deleted file mode 100755 index b906346350..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/cmsis_11cxx.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * @brief Basic CMSIS include file for LPC11CXX - * - * @note - * Copyright(C) NXP Semiconductors, 2013 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __CMSIS_11CXX_H_ -#define __CMSIS_11CXX_H_ - -#include "lpc_types.h" -#include "sys_config.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup CMSIS_11CXX CHIP: LPC11Cxx CMSIS include file - * @ingroup CHIP_11XX_CMSIS_Drivers - * Applies to LPC1111, LPC1112, LPC1113, LPC1114, LPC11D14, LPC1115, - * LPC11C12, LPC11C13, LPC11C22, and LPC11C34 devices. - * @{ - */ - -#if defined(__ARMCC_VERSION) -// Kill warning "#pragma push with no matching #pragma pop" - #pragma diag_suppress 2525 - #pragma push - #pragma anon_unions -#elif defined(__CWCC__) - #pragma push - #pragma cpp_extensions on -#elif defined(__GNUC__) -/* anonymous unions are enabled by default */ -#elif defined(__IAR_SYSTEMS_ICC__) -// #pragma push // FIXME not usable for IAR - #pragma language=extended -#else - #error Not supported compiler type -#endif - -/* - * ========================================================================== - * ---------- Interrupt Number Definition ----------------------------------- - * ========================================================================== - */ - -#if !defined(CHIP_LPC11CXX) -#error Incorrect or missing device variant (CHIP_LPC11AXX) -#endif - -/** @defgroup CMSIS_11CXX_IRQ CHIP_LPC11CXX: LPC11CXX/LPC111X peripheral interrupt numbers - * @{ - */ - -typedef enum LPC11CXX_IRQn { - NonMaskableInt_IRQn = -14, /*!< 2 Non Maskable Interrupt */ - HardFault_IRQn = -13, /*!< 3 Cortex-M0 Hard Fault Interrupt */ - SVCall_IRQn = -5, /*!< 11 Cortex-M0 SV Call Interrupt */ - PendSV_IRQn = -2, /*!< 14 Cortex-M0 Pend SV Interrupt */ - SysTick_IRQn = -1, /*!< 15 Cortex-M0 System Tick Interrupt */ - - PIO0_0_IRQn = 0, /*!< GPIO port 0, pin 0 Interrupt */ - PIO0_1_IRQn = 1, /*!< GPIO port 0, pin 1 Interrupt */ - PIO0_2_IRQn = 2, /*!< GPIO port 0, pin 2 Interrupt */ - PIO0_3_IRQn = 3, /*!< GPIO port 0, pin 3 Interrupt */ - PIO0_4_IRQn = 4, /*!< GPIO port 0, pin 4 Interrupt */ - PIO0_5_IRQn = 5, /*!< GPIO port 0, pin 5 Interrupt */ - PIO0_6_IRQn = 6, /*!< GPIO port 0, pin 6 Interrupt */ - PIO0_7_IRQn = 7, /*!< GPIO port 0, pin 7 Interrupt */ - PIO0_8_IRQn = 8, /*!< GPIO port 0, pin 8 Interrupt */ - PIO0_9_IRQn = 9, /*!< GPIO port 0, pin 9 Interrupt */ - PIO0_10_IRQn = 10, /*!< GPIO port 0, pin 10 Interrupt */ - PIO0_11_IRQn = 11, /*!< GPIO port 0, pin 11 Interrupt */ - PIO1_0_IRQn = 12, /*!< GPIO port 1, pin 0 Interrupt */ - CAN_IRQn = 13, /*!< CAN Interrupt */ - SSP1_IRQn = 14, /*!< SSP1 Interrupt */ - I2C0_IRQn = 15, /*!< I2C Interrupt */ - TIMER_16_0_IRQn = 16, /*!< 16-bit Timer0 Interrupt */ - TIMER_16_1_IRQn = 17, /*!< 16-bit Timer1 Interrupt */ - TIMER_32_0_IRQn = 18, /*!< 32-bit Timer0 Interrupt */ - TIMER_32_1_IRQn = 19, /*!< 32-bit Timer1 Interrupt */ - SSP0_IRQn = 20, /*!< SSP0 Interrupt */ - UART0_IRQn = 21, /*!< UART Interrupt */ - Reserved22_IRQn = 22, - Reserved23_IRQn = 23, - ADC_IRQn = 24, /*!< A/D Converter Interrupt */ - WDT_IRQn = 25, /*!< Watchdog timer Interrupt */ - BOD_IRQn = 26, /*!< Brown Out Detect(BOD) Interrupt */ - Reserved27_IRQn = 27, - EINT3_IRQn = 28, /*!< External Interrupt 3 Interrupt */ - EINT2_IRQn = 29, /*!< External Interrupt 2 Interrupt */ - EINT1_IRQn = 30, /*!< External Interrupt 1 Interrupt */ - EINT0_IRQn = 31, /*!< External Interrupt 0 Interrupt */ -} LPC11CXX_IRQn_Type; - -/** - * @} - */ - -/* - * ========================================================================== - * ----------- Processor and Core Peripheral Section ------------------------ - * ========================================================================== - */ - -/** @defgroup CMSIS_11CXX_COMMON CHIP: LPC11Cxx Cortex CMSIS definitions - * @{ - */ - -/* Configuration of the Cortex-M0 Processor and Core Peripherals */ -#define __MPU_PRESENT 0 /*!< MPU present or not */ -#define __NVIC_PRIO_BITS 2 /*!< Number of Bits used for Priority Levels */ -#define __Vendor_SysTickConfig 0 /*!< Set to 1 if different SysTick Config is used */ - -/** - * @} - */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __CMSIS_11CXX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cm0.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cm0.h deleted file mode 100755 index 0d7cfd85e2..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cm0.h +++ /dev/null @@ -1,667 +0,0 @@ -/**************************************************************************//** - * @file core_cm0.h - * @brief CMSIS Cortex-M0 Core Peripheral Access Layer Header File - * @version V3.01 - * @date 13. March 2012 - * - * @note - * Copyright (C) 2009-2012 ARM Limited. All rights reserved. - * - * @par - * ARM Limited (ARM) is supplying this software for use with Cortex-M - * processor based microcontrollers. This file can be freely distributed - * within development tools that are supporting such ARM based processors. - * - * @par - * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED - * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. - * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. - * - ******************************************************************************/ -#if defined ( __ICCARM__ ) - #pragma system_include /* treat file as system include file for MISRA check */ -#endif - -#ifdef __cplusplus - extern "C" { -#endif - -#ifndef __CORE_CM0_H_GENERIC -#define __CORE_CM0_H_GENERIC - -/** \page CMSIS_MISRA_Exceptions MISRA-C:2004 Compliance Exceptions - CMSIS violates the following MISRA-C:2004 rules: - - \li Required Rule 8.5, object/function definition in header file.
- Function definitions in header files are used to allow 'inlining'. - - \li Required Rule 18.4, declaration of union type or object of union type: '{...}'.
- Unions are used for effective representation of core registers. - - \li Advisory Rule 19.7, Function-like macro defined.
- Function-like macros are used to allow more efficient code. - */ - - -/******************************************************************************* - * CMSIS definitions - ******************************************************************************/ -/** \ingroup Cortex_M0 - @{ - */ - -/* CMSIS CM0 definitions */ -#define __CM0_CMSIS_VERSION_MAIN (0x03) /*!< [31:16] CMSIS HAL main version */ -#define __CM0_CMSIS_VERSION_SUB (0x01) /*!< [15:0] CMSIS HAL sub version */ -#define __CM0_CMSIS_VERSION ((__CM0_CMSIS_VERSION_MAIN << 16) | \ - __CM0_CMSIS_VERSION_SUB ) /*!< CMSIS HAL version number */ - -#define __CORTEX_M (0x00) /*!< Cortex-M Core */ - - -#if defined ( __CC_ARM ) - #define __ASM __asm /*!< asm keyword for ARM Compiler */ - #define __INLINE __inline /*!< inline keyword for ARM Compiler */ - #define __STATIC_INLINE static __inline - -#elif defined ( __ICCARM__ ) - #define __ASM __asm /*!< asm keyword for IAR Compiler */ - #define __INLINE inline /*!< inline keyword for IAR Compiler. Only available in High optimization mode! */ - #define __STATIC_INLINE static inline - -#elif defined ( __GNUC__ ) - #define __ASM __asm /*!< asm keyword for GNU Compiler */ - #define __INLINE inline /*!< inline keyword for GNU Compiler */ - #define __STATIC_INLINE static inline - -#elif defined ( __TASKING__ ) - #define __ASM __asm /*!< asm keyword for TASKING Compiler */ - #define __INLINE inline /*!< inline keyword for TASKING Compiler */ - #define __STATIC_INLINE static inline - -#endif - -/** __FPU_USED indicates whether an FPU is used or not. This core does not support an FPU at all -*/ -#define __FPU_USED 0 - -#if defined ( __CC_ARM ) - #if defined __TARGET_FPU_VFP - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #endif - -#elif defined ( __ICCARM__ ) - #if defined __ARMVFP__ - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #endif - -#elif defined ( __GNUC__ ) - #if defined (__VFP_FP__) && !defined(__SOFTFP__) - #warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #endif - -#elif defined ( __TASKING__ ) - #if defined __FPU_VFP__ - #error "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" - #endif -#endif - -#include /* standard types definitions */ -#include /* Core Instruction Access */ -#include /* Core Function Access */ - -#endif /* __CORE_CM0_H_GENERIC */ - -#ifndef __CMSIS_GENERIC - -#ifndef __CORE_CM0_H_DEPENDANT -#define __CORE_CM0_H_DEPENDANT - -/* check device defines and use defaults */ -#if defined __CHECK_DEVICE_DEFINES - #ifndef __CM0_REV - #define __CM0_REV 0x0000 - #warning "__CM0_REV not defined in device header file; using default!" - #endif - - #ifndef __NVIC_PRIO_BITS - #define __NVIC_PRIO_BITS 2 - #warning "__NVIC_PRIO_BITS not defined in device header file; using default!" - #endif - - #ifndef __Vendor_SysTickConfig - #define __Vendor_SysTickConfig 0 - #warning "__Vendor_SysTickConfig not defined in device header file; using default!" - #endif -#endif - -/* IO definitions (access restrictions to peripheral registers) */ -/** - \defgroup CMSIS_glob_defs CMSIS Global Defines - - IO Type Qualifiers are used - \li to specify the access to peripheral variables. - \li for automatic generation of peripheral register debug information. -*/ -#ifdef __cplusplus - #define __I volatile /*!< Defines 'read only' permissions */ -#else - #define __I volatile const /*!< Defines 'read only' permissions */ -#endif -#define __O volatile /*!< Defines 'write only' permissions */ -#define __IO volatile /*!< Defines 'read / write' permissions */ - -/*@} end of group Cortex_M0 */ - - - -/******************************************************************************* - * Register Abstraction - Core Register contain: - - Core Register - - Core NVIC Register - - Core SCB Register - - Core SysTick Register - ******************************************************************************/ -/** \defgroup CMSIS_core_register Defines and Type Definitions - \brief Type definitions and defines for Cortex-M processor based devices. -*/ - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_CORE Status and Control Registers - \brief Core Register type definitions. - @{ - */ - -/** \brief Union type to access the Application Program Status Register (APSR). - */ -typedef union -{ - struct - { -#if (__CORTEX_M != 0x04) - uint32_t _reserved0:27; /*!< bit: 0..26 Reserved */ -#else - uint32_t _reserved0:16; /*!< bit: 0..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:7; /*!< bit: 20..26 Reserved */ -#endif - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ - uint32_t C:1; /*!< bit: 29 Carry condition code flag */ - uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ - uint32_t N:1; /*!< bit: 31 Negative condition code flag */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} APSR_Type; - - -/** \brief Union type to access the Interrupt Program Status Register (IPSR). - */ -typedef union -{ - struct - { - uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ - uint32_t _reserved0:23; /*!< bit: 9..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} IPSR_Type; - - -/** \brief Union type to access the Special-Purpose Program Status Registers (xPSR). - */ -typedef union -{ - struct - { - uint32_t ISR:9; /*!< bit: 0.. 8 Exception number */ -#if (__CORTEX_M != 0x04) - uint32_t _reserved0:15; /*!< bit: 9..23 Reserved */ -#else - uint32_t _reserved0:7; /*!< bit: 9..15 Reserved */ - uint32_t GE:4; /*!< bit: 16..19 Greater than or Equal flags */ - uint32_t _reserved1:4; /*!< bit: 20..23 Reserved */ -#endif - uint32_t T:1; /*!< bit: 24 Thumb bit (read 0) */ - uint32_t IT:2; /*!< bit: 25..26 saved IT state (read 0) */ - uint32_t Q:1; /*!< bit: 27 Saturation condition flag */ - uint32_t V:1; /*!< bit: 28 Overflow condition code flag */ - uint32_t C:1; /*!< bit: 29 Carry condition code flag */ - uint32_t Z:1; /*!< bit: 30 Zero condition code flag */ - uint32_t N:1; /*!< bit: 31 Negative condition code flag */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} xPSR_Type; - - -/** \brief Union type to access the Control Registers (CONTROL). - */ -typedef union -{ - struct - { - uint32_t nPRIV:1; /*!< bit: 0 Execution privilege in Thread mode */ - uint32_t SPSEL:1; /*!< bit: 1 Stack to be used */ - uint32_t FPCA:1; /*!< bit: 2 FP extension active flag */ - uint32_t _reserved0:29; /*!< bit: 3..31 Reserved */ - } b; /*!< Structure used for bit access */ - uint32_t w; /*!< Type used for word access */ -} CONTROL_Type; - -/*@} end of group CMSIS_CORE */ - - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_NVIC Nested Vectored Interrupt Controller (NVIC) - \brief Type definitions for the NVIC Registers - @{ - */ - -/** \brief Structure type to access the Nested Vectored Interrupt Controller (NVIC). - */ -typedef struct -{ - __IO uint32_t ISER[1]; /*!< Offset: 0x000 (R/W) Interrupt Set Enable Register */ - uint32_t RESERVED0[31]; - __IO uint32_t ICER[1]; /*!< Offset: 0x080 (R/W) Interrupt Clear Enable Register */ - uint32_t RSERVED1[31]; - __IO uint32_t ISPR[1]; /*!< Offset: 0x100 (R/W) Interrupt Set Pending Register */ - uint32_t RESERVED2[31]; - __IO uint32_t ICPR[1]; /*!< Offset: 0x180 (R/W) Interrupt Clear Pending Register */ - uint32_t RESERVED3[31]; - uint32_t RESERVED4[64]; - __IO uint32_t IP[8]; /*!< Offset: 0x300 (R/W) Interrupt Priority Register */ -} NVIC_Type; - -/*@} end of group CMSIS_NVIC */ - - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_SCB System Control Block (SCB) - \brief Type definitions for the System Control Block Registers - @{ - */ - -/** \brief Structure type to access the System Control Block (SCB). - */ -typedef struct -{ - __I uint32_t CPUID; /*!< Offset: 0x000 (R/ ) CPUID Base Register */ - __IO uint32_t ICSR; /*!< Offset: 0x004 (R/W) Interrupt Control and State Register */ - uint32_t RESERVED0; - __IO uint32_t AIRCR; /*!< Offset: 0x00C (R/W) Application Interrupt and Reset Control Register */ - __IO uint32_t SCR; /*!< Offset: 0x010 (R/W) System Control Register */ - __IO uint32_t CCR; /*!< Offset: 0x014 (R/W) Configuration Control Register */ - uint32_t RESERVED1; - __IO uint32_t SHP[2]; /*!< Offset: 0x01C (R/W) System Handlers Priority Registers. [0] is RESERVED */ - __IO uint32_t SHCSR; /*!< Offset: 0x024 (R/W) System Handler Control and State Register */ -} SCB_Type; - -/* SCB CPUID Register Definitions */ -#define SCB_CPUID_IMPLEMENTER_Pos 24 /*!< SCB CPUID: IMPLEMENTER Position */ -#define SCB_CPUID_IMPLEMENTER_Msk (0xFFUL << SCB_CPUID_IMPLEMENTER_Pos) /*!< SCB CPUID: IMPLEMENTER Mask */ - -#define SCB_CPUID_VARIANT_Pos 20 /*!< SCB CPUID: VARIANT Position */ -#define SCB_CPUID_VARIANT_Msk (0xFUL << SCB_CPUID_VARIANT_Pos) /*!< SCB CPUID: VARIANT Mask */ - -#define SCB_CPUID_ARCHITECTURE_Pos 16 /*!< SCB CPUID: ARCHITECTURE Position */ -#define SCB_CPUID_ARCHITECTURE_Msk (0xFUL << SCB_CPUID_ARCHITECTURE_Pos) /*!< SCB CPUID: ARCHITECTURE Mask */ - -#define SCB_CPUID_PARTNO_Pos 4 /*!< SCB CPUID: PARTNO Position */ -#define SCB_CPUID_PARTNO_Msk (0xFFFUL << SCB_CPUID_PARTNO_Pos) /*!< SCB CPUID: PARTNO Mask */ - -#define SCB_CPUID_REVISION_Pos 0 /*!< SCB CPUID: REVISION Position */ -#define SCB_CPUID_REVISION_Msk (0xFUL << SCB_CPUID_REVISION_Pos) /*!< SCB CPUID: REVISION Mask */ - -/* SCB Interrupt Control State Register Definitions */ -#define SCB_ICSR_NMIPENDSET_Pos 31 /*!< SCB ICSR: NMIPENDSET Position */ -#define SCB_ICSR_NMIPENDSET_Msk (1UL << SCB_ICSR_NMIPENDSET_Pos) /*!< SCB ICSR: NMIPENDSET Mask */ - -#define SCB_ICSR_PENDSVSET_Pos 28 /*!< SCB ICSR: PENDSVSET Position */ -#define SCB_ICSR_PENDSVSET_Msk (1UL << SCB_ICSR_PENDSVSET_Pos) /*!< SCB ICSR: PENDSVSET Mask */ - -#define SCB_ICSR_PENDSVCLR_Pos 27 /*!< SCB ICSR: PENDSVCLR Position */ -#define SCB_ICSR_PENDSVCLR_Msk (1UL << SCB_ICSR_PENDSVCLR_Pos) /*!< SCB ICSR: PENDSVCLR Mask */ - -#define SCB_ICSR_PENDSTSET_Pos 26 /*!< SCB ICSR: PENDSTSET Position */ -#define SCB_ICSR_PENDSTSET_Msk (1UL << SCB_ICSR_PENDSTSET_Pos) /*!< SCB ICSR: PENDSTSET Mask */ - -#define SCB_ICSR_PENDSTCLR_Pos 25 /*!< SCB ICSR: PENDSTCLR Position */ -#define SCB_ICSR_PENDSTCLR_Msk (1UL << SCB_ICSR_PENDSTCLR_Pos) /*!< SCB ICSR: PENDSTCLR Mask */ - -#define SCB_ICSR_ISRPREEMPT_Pos 23 /*!< SCB ICSR: ISRPREEMPT Position */ -#define SCB_ICSR_ISRPREEMPT_Msk (1UL << SCB_ICSR_ISRPREEMPT_Pos) /*!< SCB ICSR: ISRPREEMPT Mask */ - -#define SCB_ICSR_ISRPENDING_Pos 22 /*!< SCB ICSR: ISRPENDING Position */ -#define SCB_ICSR_ISRPENDING_Msk (1UL << SCB_ICSR_ISRPENDING_Pos) /*!< SCB ICSR: ISRPENDING Mask */ - -#define SCB_ICSR_VECTPENDING_Pos 12 /*!< SCB ICSR: VECTPENDING Position */ -#define SCB_ICSR_VECTPENDING_Msk (0x1FFUL << SCB_ICSR_VECTPENDING_Pos) /*!< SCB ICSR: VECTPENDING Mask */ - -#define SCB_ICSR_VECTACTIVE_Pos 0 /*!< SCB ICSR: VECTACTIVE Position */ -#define SCB_ICSR_VECTACTIVE_Msk (0x1FFUL << SCB_ICSR_VECTACTIVE_Pos) /*!< SCB ICSR: VECTACTIVE Mask */ - -/* SCB Application Interrupt and Reset Control Register Definitions */ -#define SCB_AIRCR_VECTKEY_Pos 16 /*!< SCB AIRCR: VECTKEY Position */ -#define SCB_AIRCR_VECTKEY_Msk (0xFFFFUL << SCB_AIRCR_VECTKEY_Pos) /*!< SCB AIRCR: VECTKEY Mask */ - -#define SCB_AIRCR_VECTKEYSTAT_Pos 16 /*!< SCB AIRCR: VECTKEYSTAT Position */ -#define SCB_AIRCR_VECTKEYSTAT_Msk (0xFFFFUL << SCB_AIRCR_VECTKEYSTAT_Pos) /*!< SCB AIRCR: VECTKEYSTAT Mask */ - -#define SCB_AIRCR_ENDIANESS_Pos 15 /*!< SCB AIRCR: ENDIANESS Position */ -#define SCB_AIRCR_ENDIANESS_Msk (1UL << SCB_AIRCR_ENDIANESS_Pos) /*!< SCB AIRCR: ENDIANESS Mask */ - -#define SCB_AIRCR_SYSRESETREQ_Pos 2 /*!< SCB AIRCR: SYSRESETREQ Position */ -#define SCB_AIRCR_SYSRESETREQ_Msk (1UL << SCB_AIRCR_SYSRESETREQ_Pos) /*!< SCB AIRCR: SYSRESETREQ Mask */ - -#define SCB_AIRCR_VECTCLRACTIVE_Pos 1 /*!< SCB AIRCR: VECTCLRACTIVE Position */ -#define SCB_AIRCR_VECTCLRACTIVE_Msk (1UL << SCB_AIRCR_VECTCLRACTIVE_Pos) /*!< SCB AIRCR: VECTCLRACTIVE Mask */ - -/* SCB System Control Register Definitions */ -#define SCB_SCR_SEVONPEND_Pos 4 /*!< SCB SCR: SEVONPEND Position */ -#define SCB_SCR_SEVONPEND_Msk (1UL << SCB_SCR_SEVONPEND_Pos) /*!< SCB SCR: SEVONPEND Mask */ - -#define SCB_SCR_SLEEPDEEP_Pos 2 /*!< SCB SCR: SLEEPDEEP Position */ -#define SCB_SCR_SLEEPDEEP_Msk (1UL << SCB_SCR_SLEEPDEEP_Pos) /*!< SCB SCR: SLEEPDEEP Mask */ - -#define SCB_SCR_SLEEPONEXIT_Pos 1 /*!< SCB SCR: SLEEPONEXIT Position */ -#define SCB_SCR_SLEEPONEXIT_Msk (1UL << SCB_SCR_SLEEPONEXIT_Pos) /*!< SCB SCR: SLEEPONEXIT Mask */ - -/* SCB Configuration Control Register Definitions */ -#define SCB_CCR_STKALIGN_Pos 9 /*!< SCB CCR: STKALIGN Position */ -#define SCB_CCR_STKALIGN_Msk (1UL << SCB_CCR_STKALIGN_Pos) /*!< SCB CCR: STKALIGN Mask */ - -#define SCB_CCR_UNALIGN_TRP_Pos 3 /*!< SCB CCR: UNALIGN_TRP Position */ -#define SCB_CCR_UNALIGN_TRP_Msk (1UL << SCB_CCR_UNALIGN_TRP_Pos) /*!< SCB CCR: UNALIGN_TRP Mask */ - -/* SCB System Handler Control and State Register Definitions */ -#define SCB_SHCSR_SVCALLPENDED_Pos 15 /*!< SCB SHCSR: SVCALLPENDED Position */ -#define SCB_SHCSR_SVCALLPENDED_Msk (1UL << SCB_SHCSR_SVCALLPENDED_Pos) /*!< SCB SHCSR: SVCALLPENDED Mask */ - -/*@} end of group CMSIS_SCB */ - - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_SysTick System Tick Timer (SysTick) - \brief Type definitions for the System Timer Registers. - @{ - */ - -/** \brief Structure type to access the System Timer (SysTick). - */ -typedef struct -{ - __IO uint32_t CTRL; /*!< Offset: 0x000 (R/W) SysTick Control and Status Register */ - __IO uint32_t LOAD; /*!< Offset: 0x004 (R/W) SysTick Reload Value Register */ - __IO uint32_t VAL; /*!< Offset: 0x008 (R/W) SysTick Current Value Register */ - __I uint32_t CALIB; /*!< Offset: 0x00C (R/ ) SysTick Calibration Register */ -} SysTick_Type; - -/* SysTick Control / Status Register Definitions */ -#define SysTick_CTRL_COUNTFLAG_Pos 16 /*!< SysTick CTRL: COUNTFLAG Position */ -#define SysTick_CTRL_COUNTFLAG_Msk (1UL << SysTick_CTRL_COUNTFLAG_Pos) /*!< SysTick CTRL: COUNTFLAG Mask */ - -#define SysTick_CTRL_CLKSOURCE_Pos 2 /*!< SysTick CTRL: CLKSOURCE Position */ -#define SysTick_CTRL_CLKSOURCE_Msk (1UL << SysTick_CTRL_CLKSOURCE_Pos) /*!< SysTick CTRL: CLKSOURCE Mask */ - -#define SysTick_CTRL_TICKINT_Pos 1 /*!< SysTick CTRL: TICKINT Position */ -#define SysTick_CTRL_TICKINT_Msk (1UL << SysTick_CTRL_TICKINT_Pos) /*!< SysTick CTRL: TICKINT Mask */ - -#define SysTick_CTRL_ENABLE_Pos 0 /*!< SysTick CTRL: ENABLE Position */ -#define SysTick_CTRL_ENABLE_Msk (1UL << SysTick_CTRL_ENABLE_Pos) /*!< SysTick CTRL: ENABLE Mask */ - -/* SysTick Reload Register Definitions */ -#define SysTick_LOAD_RELOAD_Pos 0 /*!< SysTick LOAD: RELOAD Position */ -#define SysTick_LOAD_RELOAD_Msk (0xFFFFFFUL << SysTick_LOAD_RELOAD_Pos) /*!< SysTick LOAD: RELOAD Mask */ - -/* SysTick Current Register Definitions */ -#define SysTick_VAL_CURRENT_Pos 0 /*!< SysTick VAL: CURRENT Position */ -#define SysTick_VAL_CURRENT_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick VAL: CURRENT Mask */ - -/* SysTick Calibration Register Definitions */ -#define SysTick_CALIB_NOREF_Pos 31 /*!< SysTick CALIB: NOREF Position */ -#define SysTick_CALIB_NOREF_Msk (1UL << SysTick_CALIB_NOREF_Pos) /*!< SysTick CALIB: NOREF Mask */ - -#define SysTick_CALIB_SKEW_Pos 30 /*!< SysTick CALIB: SKEW Position */ -#define SysTick_CALIB_SKEW_Msk (1UL << SysTick_CALIB_SKEW_Pos) /*!< SysTick CALIB: SKEW Mask */ - -#define SysTick_CALIB_TENMS_Pos 0 /*!< SysTick CALIB: TENMS Position */ -#define SysTick_CALIB_TENMS_Msk (0xFFFFFFUL << SysTick_VAL_CURRENT_Pos) /*!< SysTick CALIB: TENMS Mask */ - -/*@} end of group CMSIS_SysTick */ - - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_CoreDebug Core Debug Registers (CoreDebug) - \brief Cortex-M0 Core Debug Registers (DCB registers, SHCSR, and DFSR) - are only accessible over DAP and not via processor. Therefore - they are not covered by the Cortex-M0 header file. - @{ - */ -/*@} end of group CMSIS_CoreDebug */ - - -/** \ingroup CMSIS_core_register - \defgroup CMSIS_core_base Core Definitions - \brief Definitions for base addresses, unions, and structures. - @{ - */ - -/* Memory mapping of Cortex-M0 Hardware */ -#define SCS_BASE (0xE000E000UL) /*!< System Control Space Base Address */ -#define SysTick_BASE (SCS_BASE + 0x0010UL) /*!< SysTick Base Address */ -#define NVIC_BASE (SCS_BASE + 0x0100UL) /*!< NVIC Base Address */ -#define SCB_BASE (SCS_BASE + 0x0D00UL) /*!< System Control Block Base Address */ - -#define SCB ((SCB_Type *) SCB_BASE ) /*!< SCB configuration struct */ -#define SysTick ((SysTick_Type *) SysTick_BASE ) /*!< SysTick configuration struct */ -#define NVIC ((NVIC_Type *) NVIC_BASE ) /*!< NVIC configuration struct */ - - -/*@} */ - - - -/******************************************************************************* - * Hardware Abstraction Layer - Core Function Interface contains: - - Core NVIC Functions - - Core SysTick Functions - - Core Register Access Functions - ******************************************************************************/ -/** \defgroup CMSIS_Core_FunctionInterface Functions and Instructions Reference -*/ - - - -/* ########################## NVIC functions #################################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_NVICFunctions NVIC Functions - \brief Functions that manage interrupts and exceptions via the NVIC. - @{ - */ - -/* Interrupt Priorities are WORD accessible only under ARMv6M */ -/* The following MACROS handle generation of the register offset and byte masks */ -#define _BIT_SHIFT(IRQn) ( (((uint32_t)(IRQn) ) & 0x03) * 8 ) -#define _SHP_IDX(IRQn) ( ((((uint32_t)(IRQn) & 0x0F)-8) >> 2) ) -#define _IP_IDX(IRQn) ( ((uint32_t)(IRQn) >> 2) ) - - -/** \brief Enable External Interrupt - - The function enables a device-specific interrupt in the NVIC interrupt controller. - - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_EnableIRQ(IRQn_Type IRQn) -{ - NVIC->ISER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); -} - - -/** \brief Disable External Interrupt - - The function disables a device-specific interrupt in the NVIC interrupt controller. - - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_DisableIRQ(IRQn_Type IRQn) -{ - NVIC->ICER[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); -} - - -/** \brief Get Pending Interrupt - - The function reads the pending register in the NVIC and returns the pending bit - for the specified interrupt. - - \param [in] IRQn Interrupt number. - - \return 0 Interrupt status is not pending. - \return 1 Interrupt status is pending. - */ -__STATIC_INLINE uint32_t NVIC_GetPendingIRQ(IRQn_Type IRQn) -{ - return((uint32_t) ((NVIC->ISPR[0] & (1 << ((uint32_t)(IRQn) & 0x1F)))?1:0)); -} - - -/** \brief Set Pending Interrupt - - The function sets the pending bit of an external interrupt. - - \param [in] IRQn Interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_SetPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ISPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); -} - - -/** \brief Clear Pending Interrupt - - The function clears the pending bit of an external interrupt. - - \param [in] IRQn External interrupt number. Value cannot be negative. - */ -__STATIC_INLINE void NVIC_ClearPendingIRQ(IRQn_Type IRQn) -{ - NVIC->ICPR[0] = (1 << ((uint32_t)(IRQn) & 0x1F)); /* Clear pending interrupt */ -} - - -/** \brief Set Interrupt Priority - - The function sets the priority of an interrupt. - - \note The priority cannot be set for every core interrupt. - - \param [in] IRQn Interrupt number. - \param [in] priority Priority to set. - */ -__STATIC_INLINE void NVIC_SetPriority(IRQn_Type IRQn, uint32_t priority) -{ - if(IRQn < 0) { - SCB->SHP[_SHP_IDX(IRQn)] = (SCB->SHP[_SHP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | - (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } - else { - NVIC->IP[_IP_IDX(IRQn)] = (NVIC->IP[_IP_IDX(IRQn)] & ~(0xFF << _BIT_SHIFT(IRQn))) | - (((priority << (8 - __NVIC_PRIO_BITS)) & 0xFF) << _BIT_SHIFT(IRQn)); } -} - - -/** \brief Get Interrupt Priority - - The function reads the priority of an interrupt. The interrupt - number can be positive to specify an external (device specific) - interrupt, or negative to specify an internal (core) interrupt. - - - \param [in] IRQn Interrupt number. - \return Interrupt Priority. Value is aligned automatically to the implemented - priority bits of the microcontroller. - */ -__STATIC_INLINE uint32_t NVIC_GetPriority(IRQn_Type IRQn) -{ - - if(IRQn < 0) { - return((uint32_t)((SCB->SHP[_SHP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for Cortex-M0 system interrupts */ - else { - return((uint32_t)((NVIC->IP[ _IP_IDX(IRQn)] >> _BIT_SHIFT(IRQn) ) >> (8 - __NVIC_PRIO_BITS))); } /* get priority for device specific interrupts */ -} - - -/** \brief System Reset - - The function initiates a system reset request to reset the MCU. - */ -__STATIC_INLINE void NVIC_SystemReset(void) -{ - __DSB(); /* Ensure all outstanding memory accesses included - buffered write are completed before reset */ - SCB->AIRCR = ((0x5FA << SCB_AIRCR_VECTKEY_Pos) | - SCB_AIRCR_SYSRESETREQ_Msk); - __DSB(); /* Ensure completion of memory access */ - while(1); /* wait until reset */ -} - -/*@} end of CMSIS_Core_NVICFunctions */ - - - -/* ################################## SysTick function ############################################ */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_SysTickFunctions SysTick Functions - \brief Functions that configure the System. - @{ - */ - -#if (__Vendor_SysTickConfig == 0) - -/** \brief System Tick Configuration - - The function initializes the System Timer and its interrupt, and starts the System Tick Timer. - Counter is in free running mode to generate periodic interrupts. - - \param [in] ticks Number of ticks between two interrupts. - - \return 0 Function succeeded. - \return 1 Function failed. - - \note When the variable __Vendor_SysTickConfig is set to 1, then the - function SysTick_Config is not included. In this case, the file device.h - must contain a vendor-specific implementation of this function. - - */ -__STATIC_INLINE uint32_t SysTick_Config(uint32_t ticks) -{ - if (ticks > SysTick_LOAD_RELOAD_Msk) return (1); /* Reload value impossible */ - - SysTick->LOAD = (ticks & SysTick_LOAD_RELOAD_Msk) - 1; /* set reload register */ - NVIC_SetPriority (SysTick_IRQn, (1<<__NVIC_PRIO_BITS) - 1); /* set Priority for Systick Interrupt */ - SysTick->VAL = 0; /* Load the SysTick Counter Value */ - SysTick->CTRL = SysTick_CTRL_CLKSOURCE_Msk | - SysTick_CTRL_TICKINT_Msk | - SysTick_CTRL_ENABLE_Msk; /* Enable SysTick IRQ and SysTick Timer */ - return (0); /* Function successful */ -} - -#endif - -/*@} end of CMSIS_Core_SysTickFunctions */ - - - - -#endif /* __CORE_CM0_H_DEPENDANT */ - -#endif /* __CMSIS_GENERIC */ - -#ifdef __cplusplus -} -#endif diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmFunc.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmFunc.h deleted file mode 100755 index adb07b5d34..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmFunc.h +++ /dev/null @@ -1,616 +0,0 @@ -/**************************************************************************//** - * @file core_cmFunc.h - * @brief CMSIS Cortex-M Core Function Access Header File - * @version V3.01 - * @date 06. March 2012 - * - * @note - * Copyright (C) 2009-2012 ARM Limited. All rights reserved. - * - * @par - * ARM Limited (ARM) is supplying this software for use with Cortex-M - * processor based microcontrollers. This file can be freely distributed - * within development tools that are supporting such ARM based processors. - * - * @par - * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED - * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. - * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. - * - ******************************************************************************/ - -#ifndef __CORE_CMFUNC_H -#define __CORE_CMFUNC_H - - -/* ########################### Core Function Access ########################### */ -/** \ingroup CMSIS_Core_FunctionInterface - \defgroup CMSIS_Core_RegAccFunctions CMSIS Core Register Access Functions - @{ - */ - -#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ -/* ARM armcc specific functions */ - -#if (__ARMCC_VERSION < 400677) - #error "Please use ARM Compiler Toolchain V4.0.677 or later!" -#endif - -/* intrinsic void __enable_irq(); */ -/* intrinsic void __disable_irq(); */ - -/** \brief Get Control Register - - This function returns the content of the Control Register. - - \return Control Register value - */ -__STATIC_INLINE uint32_t __get_CONTROL(void) -{ - register uint32_t __regControl __ASM("control"); - return(__regControl); -} - - -/** \brief Set Control Register - - This function writes the given value to the Control Register. - - \param [in] control Control Register value to set - */ -__STATIC_INLINE void __set_CONTROL(uint32_t control) -{ - register uint32_t __regControl __ASM("control"); - __regControl = control; -} - - -/** \brief Get IPSR Register - - This function returns the content of the IPSR Register. - - \return IPSR Register value - */ -__STATIC_INLINE uint32_t __get_IPSR(void) -{ - register uint32_t __regIPSR __ASM("ipsr"); - return(__regIPSR); -} - - -/** \brief Get APSR Register - - This function returns the content of the APSR Register. - - \return APSR Register value - */ -__STATIC_INLINE uint32_t __get_APSR(void) -{ - register uint32_t __regAPSR __ASM("apsr"); - return(__regAPSR); -} - - -/** \brief Get xPSR Register - - This function returns the content of the xPSR Register. - - \return xPSR Register value - */ -__STATIC_INLINE uint32_t __get_xPSR(void) -{ - register uint32_t __regXPSR __ASM("xpsr"); - return(__regXPSR); -} - - -/** \brief Get Process Stack Pointer - - This function returns the current value of the Process Stack Pointer (PSP). - - \return PSP Register value - */ -__STATIC_INLINE uint32_t __get_PSP(void) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - return(__regProcessStackPointer); -} - - -/** \brief Set Process Stack Pointer - - This function assigns the given value to the Process Stack Pointer (PSP). - - \param [in] topOfProcStack Process Stack Pointer value to set - */ -__STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) -{ - register uint32_t __regProcessStackPointer __ASM("psp"); - __regProcessStackPointer = topOfProcStack; -} - - -/** \brief Get Main Stack Pointer - - This function returns the current value of the Main Stack Pointer (MSP). - - \return MSP Register value - */ -__STATIC_INLINE uint32_t __get_MSP(void) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - return(__regMainStackPointer); -} - - -/** \brief Set Main Stack Pointer - - This function assigns the given value to the Main Stack Pointer (MSP). - - \param [in] topOfMainStack Main Stack Pointer value to set - */ -__STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) -{ - register uint32_t __regMainStackPointer __ASM("msp"); - __regMainStackPointer = topOfMainStack; -} - - -/** \brief Get Priority Mask - - This function returns the current state of the priority mask bit from the Priority Mask Register. - - \return Priority Mask value - */ -__STATIC_INLINE uint32_t __get_PRIMASK(void) -{ - register uint32_t __regPriMask __ASM("primask"); - return(__regPriMask); -} - - -/** \brief Set Priority Mask - - This function assigns the given value to the Priority Mask Register. - - \param [in] priMask Priority Mask - */ -__STATIC_INLINE void __set_PRIMASK(uint32_t priMask) -{ - register uint32_t __regPriMask __ASM("primask"); - __regPriMask = (priMask); -} - - -#if (__CORTEX_M >= 0x03) - -/** \brief Enable FIQ - - This function enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -#define __enable_fault_irq __enable_fiq - - -/** \brief Disable FIQ - - This function disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -#define __disable_fault_irq __disable_fiq - - -/** \brief Get Base Priority - - This function returns the current value of the Base Priority register. - - \return Base Priority register value - */ -__STATIC_INLINE uint32_t __get_BASEPRI(void) -{ - register uint32_t __regBasePri __ASM("basepri"); - return(__regBasePri); -} - - -/** \brief Set Base Priority - - This function assigns the given value to the Base Priority register. - - \param [in] basePri Base Priority value to set - */ -__STATIC_INLINE void __set_BASEPRI(uint32_t basePri) -{ - register uint32_t __regBasePri __ASM("basepri"); - __regBasePri = (basePri & 0xff); -} - - -/** \brief Get Fault Mask - - This function returns the current value of the Fault Mask register. - - \return Fault Mask register value - */ -__STATIC_INLINE uint32_t __get_FAULTMASK(void) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - return(__regFaultMask); -} - - -/** \brief Set Fault Mask - - This function assigns the given value to the Fault Mask register. - - \param [in] faultMask Fault Mask value to set - */ -__STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) -{ - register uint32_t __regFaultMask __ASM("faultmask"); - __regFaultMask = (faultMask & (uint32_t)1); -} - -#endif /* (__CORTEX_M >= 0x03) */ - - -#if (__CORTEX_M == 0x04) - -/** \brief Get FPSCR - - This function returns the current value of the Floating Point Status/Control register. - - \return Floating Point Status/Control register value - */ -__STATIC_INLINE uint32_t __get_FPSCR(void) -{ -#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) - register uint32_t __regfpscr __ASM("fpscr"); - return(__regfpscr); -#else - return(0); -#endif -} - - -/** \brief Set FPSCR - - This function assigns the given value to the Floating Point Status/Control register. - - \param [in] fpscr Floating Point Status/Control value to set - */ -__STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ -#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) - register uint32_t __regfpscr __ASM("fpscr"); - __regfpscr = (fpscr); -#endif -} - -#endif /* (__CORTEX_M == 0x04) */ - - -#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ -/* IAR iccarm specific functions */ - -#include - - -#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ -/* TI CCS specific functions */ - -#include - - -#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ -/* GNU gcc specific functions */ - -/** \brief Enable IRQ Interrupts - - This function enables IRQ interrupts by clearing the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_irq(void) -{ - __ASM volatile ("cpsie i"); -} - - -/** \brief Disable IRQ Interrupts - - This function disables IRQ interrupts by setting the I-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_irq(void) -{ - __ASM volatile ("cpsid i"); -} - - -/** \brief Get Control Register - - This function returns the content of the Control Register. - - \return Control Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_CONTROL(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, control" : "=r" (result) ); - return(result); -} - - -/** \brief Set Control Register - - This function writes the given value to the Control Register. - - \param [in] control Control Register value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_CONTROL(uint32_t control) -{ - __ASM volatile ("MSR control, %0" : : "r" (control) ); -} - - -/** \brief Get IPSR Register - - This function returns the content of the IPSR Register. - - \return IPSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_IPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, ipsr" : "=r" (result) ); - return(result); -} - - -/** \brief Get APSR Register - - This function returns the content of the APSR Register. - - \return APSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_APSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, apsr" : "=r" (result) ); - return(result); -} - - -/** \brief Get xPSR Register - - This function returns the content of the xPSR Register. - - \return xPSR Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_xPSR(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, xpsr" : "=r" (result) ); - return(result); -} - - -/** \brief Get Process Stack Pointer - - This function returns the current value of the Process Stack Pointer (PSP). - - \return PSP Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PSP(void) -{ - register uint32_t result; - - __ASM volatile ("MRS %0, psp\n" : "=r" (result) ); - return(result); -} - - -/** \brief Set Process Stack Pointer - - This function assigns the given value to the Process Stack Pointer (PSP). - - \param [in] topOfProcStack Process Stack Pointer value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PSP(uint32_t topOfProcStack) -{ - __ASM volatile ("MSR psp, %0\n" : : "r" (topOfProcStack) ); -} - - -/** \brief Get Main Stack Pointer - - This function returns the current value of the Main Stack Pointer (MSP). - - \return MSP Register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_MSP(void) -{ - register uint32_t result; - - __ASM volatile ("MRS %0, msp\n" : "=r" (result) ); - return(result); -} - - -/** \brief Set Main Stack Pointer - - This function assigns the given value to the Main Stack Pointer (MSP). - - \param [in] topOfMainStack Main Stack Pointer value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_MSP(uint32_t topOfMainStack) -{ - __ASM volatile ("MSR msp, %0\n" : : "r" (topOfMainStack) ); -} - - -/** \brief Get Priority Mask - - This function returns the current state of the priority mask bit from the Priority Mask Register. - - \return Priority Mask value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_PRIMASK(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, primask" : "=r" (result) ); - return(result); -} - - -/** \brief Set Priority Mask - - This function assigns the given value to the Priority Mask Register. - - \param [in] priMask Priority Mask - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_PRIMASK(uint32_t priMask) -{ - __ASM volatile ("MSR primask, %0" : : "r" (priMask) ); -} - - -#if (__CORTEX_M >= 0x03) - -/** \brief Enable FIQ - - This function enables FIQ interrupts by clearing the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __enable_fault_irq(void) -{ - __ASM volatile ("cpsie f"); -} - - -/** \brief Disable FIQ - - This function disables FIQ interrupts by setting the F-bit in the CPSR. - Can only be executed in Privileged modes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __disable_fault_irq(void) -{ - __ASM volatile ("cpsid f"); -} - - -/** \brief Get Base Priority - - This function returns the current value of the Base Priority register. - - \return Base Priority register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_BASEPRI(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, basepri_max" : "=r" (result) ); - return(result); -} - - -/** \brief Set Base Priority - - This function assigns the given value to the Base Priority register. - - \param [in] basePri Base Priority value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_BASEPRI(uint32_t value) -{ - __ASM volatile ("MSR basepri, %0" : : "r" (value) ); -} - - -/** \brief Get Fault Mask - - This function returns the current value of the Fault Mask register. - - \return Fault Mask register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FAULTMASK(void) -{ - uint32_t result; - - __ASM volatile ("MRS %0, faultmask" : "=r" (result) ); - return(result); -} - - -/** \brief Set Fault Mask - - This function assigns the given value to the Fault Mask register. - - \param [in] faultMask Fault Mask value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FAULTMASK(uint32_t faultMask) -{ - __ASM volatile ("MSR faultmask, %0" : : "r" (faultMask) ); -} - -#endif /* (__CORTEX_M >= 0x03) */ - - -#if (__CORTEX_M == 0x04) - -/** \brief Get FPSCR - - This function returns the current value of the Floating Point Status/Control register. - - \return Floating Point Status/Control register value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __get_FPSCR(void) -{ -#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) - uint32_t result; - - __ASM volatile ("VMRS %0, fpscr" : "=r" (result) ); - return(result); -#else - return(0); -#endif -} - - -/** \brief Set FPSCR - - This function assigns the given value to the Floating Point Status/Control register. - - \param [in] fpscr Floating Point Status/Control value to set - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __set_FPSCR(uint32_t fpscr) -{ -#if (__FPU_PRESENT == 1) && (__FPU_USED == 1) - __ASM volatile ("VMSR fpscr, %0" : : "r" (fpscr) ); -#endif -} - -#endif /* (__CORTEX_M == 0x04) */ - - -#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ -/* TASKING carm specific functions */ - -/* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all instrinsics, - * Including the CMSIS ones. - */ - -#endif - -/*@} end of CMSIS_Core_RegAccFunctions */ - - -#endif /* __CORE_CMFUNC_H */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmInstr.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmInstr.h deleted file mode 100755 index 624c175fd5..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/core_cmInstr.h +++ /dev/null @@ -1,618 +0,0 @@ -/**************************************************************************//** - * @file core_cmInstr.h - * @brief CMSIS Cortex-M Core Instruction Access Header File - * @version V3.01 - * @date 06. March 2012 - * - * @note - * Copyright (C) 2009-2012 ARM Limited. All rights reserved. - * - * @par - * ARM Limited (ARM) is supplying this software for use with Cortex-M - * processor based microcontrollers. This file can be freely distributed - * within development tools that are supporting such ARM based processors. - * - * @par - * THIS SOFTWARE IS PROVIDED "AS IS". NO WARRANTIES, WHETHER EXPRESS, IMPLIED - * OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE APPLY TO THIS SOFTWARE. - * ARM SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR SPECIAL, INCIDENTAL, OR - * CONSEQUENTIAL DAMAGES, FOR ANY REASON WHATSOEVER. - * - ******************************************************************************/ - -#ifndef __CORE_CMINSTR_H -#define __CORE_CMINSTR_H - - -/* ########################## Core Instruction Access ######################### */ -/** \defgroup CMSIS_Core_InstructionInterface CMSIS Core Instruction Interface - Access to dedicated instructions - @{ -*/ - -#if defined ( __CC_ARM ) /*------------------RealView Compiler -----------------*/ -/* ARM armcc specific functions */ - -#if (__ARMCC_VERSION < 400677) - #error "Please use ARM Compiler Toolchain V4.0.677 or later!" -#endif - - -/** \brief No Operation - - No Operation does nothing. This instruction can be used for code alignment purposes. - */ -#define __NOP __nop - - -/** \brief Wait For Interrupt - - Wait For Interrupt is a hint instruction that suspends execution - until one of a number of events occurs. - */ -#define __WFI __wfi - - -/** \brief Wait For Event - - Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. - */ -#define __WFE __wfe - - -/** \brief Send Event - - Send Event is a hint instruction. It causes an event to be signaled to the CPU. - */ -#define __SEV __sev - - -/** \brief Instruction Synchronization Barrier - - Instruction Synchronization Barrier flushes the pipeline in the processor, - so that all instructions following the ISB are fetched from cache or - memory, after the instruction has been completed. - */ -#define __ISB() __isb(0xF) - - -/** \brief Data Synchronization Barrier - - This function acts as a special kind of Data Memory Barrier. - It completes when all explicit memory accesses before this instruction complete. - */ -#define __DSB() __dsb(0xF) - - -/** \brief Data Memory Barrier - - This function ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. - */ -#define __DMB() __dmb(0xF) - - -/** \brief Reverse byte order (32 bit) - - This function reverses the byte order in integer value. - - \param [in] value Value to reverse - \return Reversed value - */ -#define __REV __rev - - -/** \brief Reverse byte order (16 bit) - - This function reverses the byte order in two unsigned short values. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__((section(".rev16_text"))) __STATIC_INLINE __ASM uint32_t __REV16(uint32_t value) -{ - rev16 r0, r0 - bx lr -} - - -/** \brief Reverse byte order in signed short value - - This function reverses the byte order in a signed short value with sign extension to integer. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__((section(".revsh_text"))) __STATIC_INLINE __ASM int32_t __REVSH(int32_t value) -{ - revsh r0, r0 - bx lr -} - - -/** \brief Rotate Right in unsigned value (32 bit) - - This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - - \param [in] value Value to rotate - \param [in] value Number of Bits to rotate - \return Rotated value - */ -#define __ROR __ror - - -#if (__CORTEX_M >= 0x03) - -/** \brief Reverse bit order of value - - This function reverses the bit order of the given value. - - \param [in] value Value to reverse - \return Reversed value - */ -#define __RBIT __rbit - - -/** \brief LDR Exclusive (8 bit) - - This function performs a exclusive LDR command for 8 bit value. - - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) - */ -#define __LDREXB(ptr) ((uint8_t ) __ldrex(ptr)) - - -/** \brief LDR Exclusive (16 bit) - - This function performs a exclusive LDR command for 16 bit values. - - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) - */ -#define __LDREXH(ptr) ((uint16_t) __ldrex(ptr)) - - -/** \brief LDR Exclusive (32 bit) - - This function performs a exclusive LDR command for 32 bit values. - - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) - */ -#define __LDREXW(ptr) ((uint32_t ) __ldrex(ptr)) - - -/** \brief STR Exclusive (8 bit) - - This function performs a exclusive STR command for 8 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -#define __STREXB(value, ptr) __strex(value, ptr) - - -/** \brief STR Exclusive (16 bit) - - This function performs a exclusive STR command for 16 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -#define __STREXH(value, ptr) __strex(value, ptr) - - -/** \brief STR Exclusive (32 bit) - - This function performs a exclusive STR command for 32 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -#define __STREXW(value, ptr) __strex(value, ptr) - - -/** \brief Remove the exclusive lock - - This function removes the exclusive lock which is created by LDREX. - - */ -#define __CLREX __clrex - - -/** \brief Signed Saturate - - This function saturates a signed value. - - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value - */ -#define __SSAT __ssat - - -/** \brief Unsigned Saturate - - This function saturates an unsigned value. - - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value - */ -#define __USAT __usat - - -/** \brief Count leading zeros - - This function counts the number of leading zeros of a data value. - - \param [in] value Value to count the leading zeros - \return number of leading zeros in value - */ -#define __CLZ __clz - -#endif /* (__CORTEX_M >= 0x03) */ - - - -#elif defined ( __ICCARM__ ) /*------------------ ICC Compiler -------------------*/ -/* IAR iccarm specific functions */ - -#include - - -#elif defined ( __TMS470__ ) /*---------------- TI CCS Compiler ------------------*/ -/* TI CCS specific functions */ - -#include - - -#elif defined ( __GNUC__ ) /*------------------ GNU Compiler ---------------------*/ -/* GNU gcc specific functions */ - -/** \brief No Operation - - No Operation does nothing. This instruction can be used for code alignment purposes. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __NOP(void) -{ - __ASM volatile ("nop"); -} - - -/** \brief Wait For Interrupt - - Wait For Interrupt is a hint instruction that suspends execution - until one of a number of events occurs. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFI(void) -{ - __ASM volatile ("wfi"); -} - - -/** \brief Wait For Event - - Wait For Event is a hint instruction that permits the processor to enter - a low-power state until one of a number of events occurs. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __WFE(void) -{ - __ASM volatile ("wfe"); -} - - -/** \brief Send Event - - Send Event is a hint instruction. It causes an event to be signaled to the CPU. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __SEV(void) -{ - __ASM volatile ("sev"); -} - - -/** \brief Instruction Synchronization Barrier - - Instruction Synchronization Barrier flushes the pipeline in the processor, - so that all instructions following the ISB are fetched from cache or - memory, after the instruction has been completed. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __ISB(void) -{ - __ASM volatile ("isb"); -} - - -/** \brief Data Synchronization Barrier - - This function acts as a special kind of Data Memory Barrier. - It completes when all explicit memory accesses before this instruction complete. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __DSB(void) -{ - __ASM volatile ("dsb"); -} - - -/** \brief Data Memory Barrier - - This function ensures the apparent order of the explicit memory operations before - and after the instruction, without ensuring their completion. - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __DMB(void) -{ - __ASM volatile ("dmb"); -} - - -/** \brief Reverse byte order (32 bit) - - This function reverses the byte order in integer value. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV(uint32_t value) -{ - uint32_t result; - - __ASM volatile ("rev %0, %1" : "=r" (result) : "r" (value) ); - return(result); -} - - -/** \brief Reverse byte order (16 bit) - - This function reverses the byte order in two unsigned short values. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __REV16(uint32_t value) -{ - uint32_t result; - - __ASM volatile ("rev16 %0, %1" : "=r" (result) : "r" (value) ); - return(result); -} - - -/** \brief Reverse byte order in signed short value - - This function reverses the byte order in a signed short value with sign extension to integer. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE int32_t __REVSH(int32_t value) -{ - uint32_t result; - - __ASM volatile ("revsh %0, %1" : "=r" (result) : "r" (value) ); - return(result); -} - - -/** \brief Rotate Right in unsigned value (32 bit) - - This function Rotate Right (immediate) provides the value of the contents of a register rotated by a variable number of bits. - - \param [in] value Value to rotate - \param [in] value Number of Bits to rotate - \return Rotated value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __ROR(uint32_t op1, uint32_t op2) -{ - - __ASM volatile ("ror %0, %0, %1" : "+r" (op1) : "r" (op2) ); - return(op1); -} - - -#if (__CORTEX_M >= 0x03) - -/** \brief Reverse bit order of value - - This function reverses the bit order of the given value. - - \param [in] value Value to reverse - \return Reversed value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __RBIT(uint32_t value) -{ - uint32_t result; - - __ASM volatile ("rbit %0, %1" : "=r" (result) : "r" (value) ); - return(result); -} - - -/** \brief LDR Exclusive (8 bit) - - This function performs a exclusive LDR command for 8 bit value. - - \param [in] ptr Pointer to data - \return value of type uint8_t at (*ptr) - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __LDREXB(volatile uint8_t *addr) -{ - uint8_t result; - - __ASM volatile ("ldrexb %0, [%1]" : "=r" (result) : "r" (addr) ); - return(result); -} - - -/** \brief LDR Exclusive (16 bit) - - This function performs a exclusive LDR command for 16 bit values. - - \param [in] ptr Pointer to data - \return value of type uint16_t at (*ptr) - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint16_t __LDREXH(volatile uint16_t *addr) -{ - uint16_t result; - - __ASM volatile ("ldrexh %0, [%1]" : "=r" (result) : "r" (addr) ); - return(result); -} - - -/** \brief LDR Exclusive (32 bit) - - This function performs a exclusive LDR command for 32 bit values. - - \param [in] ptr Pointer to data - \return value of type uint32_t at (*ptr) - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __LDREXW(volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("ldrex %0, [%1]" : "=r" (result) : "r" (addr) ); - return(result); -} - - -/** \brief STR Exclusive (8 bit) - - This function performs a exclusive STR command for 8 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXB(uint8_t value, volatile uint8_t *addr) -{ - uint32_t result; - - __ASM volatile ("strexb %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) ); - return(result); -} - - -/** \brief STR Exclusive (16 bit) - - This function performs a exclusive STR command for 16 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXH(uint16_t value, volatile uint16_t *addr) -{ - uint32_t result; - - __ASM volatile ("strexh %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) ); - return(result); -} - - -/** \brief STR Exclusive (32 bit) - - This function performs a exclusive STR command for 32 bit values. - - \param [in] value Value to store - \param [in] ptr Pointer to location - \return 0 Function succeeded - \return 1 Function failed - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint32_t __STREXW(uint32_t value, volatile uint32_t *addr) -{ - uint32_t result; - - __ASM volatile ("strex %0, %2, [%1]" : "=&r" (result) : "r" (addr), "r" (value) ); - return(result); -} - - -/** \brief Remove the exclusive lock - - This function removes the exclusive lock which is created by LDREX. - - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE void __CLREX(void) -{ - __ASM volatile ("clrex"); -} - - -/** \brief Signed Saturate - - This function saturates a signed value. - - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (1..32) - \return Saturated value - */ -#define __SSAT(ARG1,ARG2) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("ssat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - - -/** \brief Unsigned Saturate - - This function saturates an unsigned value. - - \param [in] value Value to be saturated - \param [in] sat Bit position to saturate to (0..31) - \return Saturated value - */ -#define __USAT(ARG1,ARG2) \ -({ \ - uint32_t __RES, __ARG1 = (ARG1); \ - __ASM ("usat %0, %1, %2" : "=r" (__RES) : "I" (ARG2), "r" (__ARG1) ); \ - __RES; \ - }) - - -/** \brief Count leading zeros - - This function counts the number of leading zeros of a data value. - - \param [in] value Value to count the leading zeros - \return number of leading zeros in value - */ -__attribute__( ( always_inline ) ) __STATIC_INLINE uint8_t __CLZ(uint32_t value) -{ - uint8_t result; - - __ASM volatile ("clz %0, %1" : "=r" (result) : "r" (value) ); - return(result); -} - -#endif /* (__CORTEX_M >= 0x03) */ - - - - -#elif defined ( __TASKING__ ) /*------------------ TASKING Compiler --------------*/ -/* TASKING carm specific functions */ - -/* - * The CMSIS functions have been implemented as intrinsics in the compiler. - * Please use "carm -?i" to get an up to date list of all intrinsics, - * Including the CMSIS ones. - */ - -#endif - -/*@}*/ /* end of group CMSIS_Core_InstructionInterface */ - -#endif /* __CORE_CMINSTR_H */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/error.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/error.h deleted file mode 100755 index be63f81db7..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/error.h +++ /dev/null @@ -1,134 +0,0 @@ -/* - * @brief Error code returned by Boot ROM drivers/library functions - * @ingroup Common - * - * This file contains unified error codes to be used across driver, - * middleware, applications, hal and demo software. - * - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __LPC_ERROR_H__ -#define __LPC_ERROR_H__ - -/** Error code returned by Boot ROM drivers/library functions -* -* Error codes are a 32-bit value with : -* - The 16 MSB contains the peripheral code number -* - The 16 LSB contains an error code number associated to that peripheral -* -*/ -typedef enum -{ - /**\b 0x00000000*/ LPC_OK=0, /**< enum value returned on Success */ - /**\b 0xFFFFFFFF*/ ERR_FAILED = -1, /**< enum value returned on general failure */ - /**\b 0xFFFFFFFE*/ ERR_TIME_OUT = -2, /**< enum value returned on general timeout */ - /**\b 0xFFFFFFFD*/ ERR_BUSY = -3, /**< enum value returned when resource is busy */ - - /* ISP related errors */ - ERR_ISP_BASE = 0x00000000, - /*0x00000001*/ ERR_ISP_INVALID_COMMAND = ERR_ISP_BASE + 1, - /*0x00000002*/ ERR_ISP_SRC_ADDR_ERROR, /* Source address not on word boundary */ - /*0x00000003*/ ERR_ISP_DST_ADDR_ERROR, /* Destination address not on word or 256 byte boundary */ - /*0x00000004*/ ERR_ISP_SRC_ADDR_NOT_MAPPED, - /*0x00000005*/ ERR_ISP_DST_ADDR_NOT_MAPPED, - /*0x00000006*/ ERR_ISP_COUNT_ERROR, /* Byte count is not multiple of 4 or is not a permitted value */ - /*0x00000007*/ ERR_ISP_INVALID_SECTOR, - /*0x00000008*/ ERR_ISP_SECTOR_NOT_BLANK, - /*0x00000009*/ ERR_ISP_SECTOR_NOT_PREPARED_FOR_WRITE_OPERATION, - /*0x0000000A*/ ERR_ISP_COMPARE_ERROR, - /*0x0000000B*/ ERR_ISP_BUSY, /* Flash programming hardware interface is busy */ - /*0x0000000C*/ ERR_ISP_PARAM_ERROR, /* Insufficient number of parameters */ - /*0x0000000D*/ ERR_ISP_ADDR_ERROR, /* Address not on word boundary */ - /*0x0000000E*/ ERR_ISP_ADDR_NOT_MAPPED, - /*0x0000000F*/ ERR_ISP_CMD_LOCKED, /* Command is locked */ - /*0x00000010*/ ERR_ISP_INVALID_CODE, /* Unlock code is invalid */ - /*0x00000011*/ ERR_ISP_INVALID_BAUD_RATE, - /*0x00000012*/ ERR_ISP_INVALID_STOP_BIT, - /*0x00000013*/ ERR_ISP_CODE_READ_PROTECTION_ENABLED, - - /* ROM API related errors */ - ERR_API_BASE = 0x00010000, - /**\b 0x00010001*/ ERR_API_INVALID_PARAMS = ERR_API_BASE + 1, /**< Invalid parameters*/ - /**\b 0x00010002*/ ERR_API_INVALID_PARAM1, /**< PARAM1 is invalid */ - /**\b 0x00010003*/ ERR_API_INVALID_PARAM2, /**< PARAM2 is invalid */ - /**\b 0x00010004*/ ERR_API_INVALID_PARAM3, /**< PARAM3 is invalid */ - /**\b 0x00010005*/ ERR_API_MOD_INIT, /**< API is called before module init */ - - /* SPIFI API related errors */ - ERR_SPIFI_BASE = 0x00020000, - /*0x00020001*/ ERR_SPIFI_DEVICE_ERROR =ERR_SPIFI_BASE+1, - /*0x00020002*/ ERR_SPIFI_INTERNAL_ERROR, - /*0x00020003*/ ERR_SPIFI_TIMEOUT, - /*0x00020004*/ ERR_SPIFI_OPERAND_ERROR, - /*0x00020005*/ ERR_SPIFI_STATUS_PROBLEM, - /*0x00020006*/ ERR_SPIFI_UNKNOWN_EXT, - /*0x00020007*/ ERR_SPIFI_UNKNOWN_ID, - /*0x00020008*/ ERR_SPIFI_UNKNOWN_TYPE, - /*0x00020009*/ ERR_SPIFI_UNKNOWN_MFG, - - /* Security API related errors */ - ERR_SEC_BASE = 0x00030000, - /*0x00030001*/ ERR_SEC_AES_WRONG_CMD=ERR_SEC_BASE+1, - /*0x00030002*/ ERR_SEC_AES_NOT_SUPPORTED, - /*0x00030003*/ ERR_SEC_AES_KEY_ALREADY_PROGRAMMED, - - - /* USB device stack related errors */ - ERR_USBD_BASE = 0x00040000, - /**\b 0x00040001*/ ERR_USBD_INVALID_REQ = ERR_USBD_BASE + 1, /**< invalid request */ - /**\b 0x00040002*/ ERR_USBD_UNHANDLED, /**< Callback did not process the event */ - /**\b 0x00040003*/ ERR_USBD_STALL, /**< Stall the endpoint on which the call back is called */ - /**\b 0x00040004*/ ERR_USBD_SEND_ZLP, /**< Send ZLP packet on the endpoint on which the call back is called */ - /**\b 0x00040005*/ ERR_USBD_SEND_DATA, /**< Send data packet on the endpoint on which the call back is called */ - /**\b 0x00040006*/ ERR_USBD_BAD_DESC, /**< Bad descriptor*/ - /**\b 0x00040007*/ ERR_USBD_BAD_CFG_DESC,/**< Bad config descriptor*/ - /**\b 0x00040008*/ ERR_USBD_BAD_INTF_DESC,/**< Bad interface descriptor*/ - /**\b 0x00040009*/ ERR_USBD_BAD_EP_DESC,/**< Bad endpoint descriptor*/ - /**\b 0x0004000a*/ ERR_USBD_BAD_MEM_BUF, /**< Bad alignment of buffer passed. */ - /**\b 0x0004000b*/ ERR_USBD_TOO_MANY_CLASS_HDLR, /**< Too many class handlers. */ - - /* CGU related errors */ - ERR_CGU_BASE = 0x00050000, - /*0x00050001*/ ERR_CGU_NOT_IMPL=ERR_CGU_BASE+1, - /*0x00050002*/ ERR_CGU_INVALID_PARAM, - /*0x00050003*/ ERR_CGU_INVALID_SLICE, - /*0x00050004*/ ERR_CGU_OUTPUT_GEN, - /*0x00050005*/ ERR_CGU_DIV_SRC, - /*0x00050006*/ ERR_CGU_DIV_VAL, - /*0x00050007*/ ERR_CGU_SRC - -} ErrorCode_t; - - - -//#define offsetof(s,m) (int)&(((s *)0)->m) -#define COMPILE_TIME_ASSERT(pred) switch(0){case 0:case pred:;} - -#endif /* __LPC_ERROR_H__ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/fmc_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/fmc_11xx.h deleted file mode 100755 index c8ad69a817..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/fmc_11xx.h +++ /dev/null @@ -1,101 +0,0 @@ -/* - * @brief FLASH Memory Controller (FMC) registers and control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __FMC_11XX_H_ -#define __FMC_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup FMC_11XX CHIP: LPC11xx FLASH Memory Controller driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief FLASH Memory Controller Unit register block structure - */ -typedef struct {/*!< FMC Structure */ - __I uint32_t RESERVED1[4]; - __IO uint32_t FLASHTIM; - __I uint32_t RESERVED2[3]; - __IO uint32_t FMSSTART; - __IO uint32_t FMSSTOP; - __I uint32_t RESERVED3; - __I uint32_t FMSW[4]; - __I uint32_t RESERVED4[25]; -#if defined(CHIP_LPC1125) - __I uint32_t RESERVED5[977]; -#else - __IO uint32_t EEMSSTART; - __IO uint32_t EEMSSTOP; - __I uint32_t EEMSSIG; - __I uint32_t RESERVED5[974]; -#endif - __I uint32_t FMSTAT; - __I uint32_t RESERVED6; - __O uint32_t FMSTATCLR; -} LPC_FMC_T; - -/** - * @brief FLASH Access time definitions - */ -typedef enum { - FLASHTIM_20MHZ_CPU = 0, /*!< Flash accesses use 1 CPU clocks. Use for up to 20 MHz CPU clock*/ - FLASHTIM_40MHZ_CPU = 1, /*!< Flash accesses use 2 CPU clocks. Use for up to 40 MHz CPU clock*/ - FLASHTIM_50MHZ_CPU = 2, /*!< Flash accesses use 3 CPU clocks. Use for up to 50 MHz CPU clock*/ -} FMC_FLASHTIM_T; - -/** - * @brief Set FLASH access time in clocks - * @param clks : Clock cycles for FLASH access (minus 1) - * @return Nothing - * @note For CPU speed up to 20MHz, use a value of 0. For up to 40MHz, use - * a value of 1. For up to 50MHz, use a value of 2. - */ -STATIC INLINE void Chip_FMC_SetFLASHAccess(FMC_FLASHTIM_T clks) -{ - uint32_t tmp = LPC_FMC->FLASHTIM & (~(0x3)); - - /* Don't alter upper bits */ - LPC_FMC->FLASHTIM = tmp | clks; -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __FMC_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpio_11xx_2.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpio_11xx_2.h deleted file mode 100755 index c25f6d66ef..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpio_11xx_2.h +++ /dev/null @@ -1,642 +0,0 @@ -/* - * @brief LPC11xx GPIO driver for CHIP_LPC11CXX, CHIP_LPC110X, CHIP_LPC11XXLV, - * and CHIP_LPC1125 families only. - * - * @note - * Copyright(C) NXP Semiconductors, 2013 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __GPIO_11XX_2_H_ -#define __GPIO_11XX_2_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup GPIO_11XX_2 CHIP: LPC11xx GPIO driver for CHIP_LPC11CXX, CHIP_LPC110X, and CHIP_LPC11XXLV families - * @ingroup CHIP_11XX_Drivers - * For device familes identified with CHIP definitions CHIP_LPC11CXX, - * CHIP_LPC110X, and CHIP_LPC11XXLV only. - * @{ - */ - -#if defined(CHIP_LPC11CXX) || defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC1125) - -/** - * @brief GPIO port register block structure - */ -typedef struct { /*!< GPIO_PORT Structure */ - __IO uint32_t DATA[4096]; /*!< Offset: 0x0000 to 0x3FFC Data address masking register (R/W) */ - uint32_t RESERVED1[4096]; - __IO uint32_t DIR; /*!< Offset: 0x8000 Data direction register (R/W) */ - __IO uint32_t IS; /*!< Offset: 0x8004 Interrupt sense register (R/W) */ - __IO uint32_t IBE; /*!< Offset: 0x8008 Interrupt both edges register (R/W) */ - __IO uint32_t IEV; /*!< Offset: 0x800C Interrupt event register (R/W) */ - __IO uint32_t IE; /*!< Offset: 0x8010 Interrupt mask register (R/W) */ - __I uint32_t RIS; /*!< Offset: 0x8014 Raw interrupt status register (R/ ) */ - __I uint32_t MIS; /*!< Offset: 0x8018 Masked interrupt status register (R/ ) */ - __O uint32_t IC; /*!< Offset: 0x801C Interrupt clear register (W) */ - uint32_t RESERVED2[8184]; /* Padding added for aligning contiguous GPIO blocks */ -} LPC_GPIO_T; - -/** - * @brief Initialize GPIO block - * @param pGPIO : The base of GPIO peripheral on the chip - * @return Nothing - */ -void Chip_GPIO_Init(LPC_GPIO_T *pGPIO); - -/** - * @brief De-Initialize GPIO block - * @param pGPIO : The base of GPIO peripheral on the chip - * @return Nothing - */ -void Chip_GPIO_DeInit(LPC_GPIO_T *pGPIO); - -/** - * @brief Set a GPIO port/bit state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : GPIO port to set - * @param bit : GPIO bit to set - * @param setting : true for high, false for low - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_WritePortBit(LPC_GPIO_T *pGPIO, uint32_t port, uint8_t bit, bool setting) -{ - pGPIO[port].DATA[1 << bit] = setting << bit; -} - -/** - * @brief Set a GPIO pin state via the GPIO byte register - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to set - * @param setting : true for high, false for low - * @return Nothing - * @note This function replaces Chip_GPIO_WritePortBit() - */ -STATIC INLINE void Chip_GPIO_SetPinState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool setting) -{ - pGPIO[port].DATA[1 << pin] = setting << pin; -} - -/** - * @brief Read a GPIO state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : GPIO port to read - * @param bit : GPIO bit to read - * @return true of the GPIO is high, false if low - * @note It is recommended to use the Chip_GPIO_GetPinState() function instead. - */ -STATIC INLINE bool Chip_GPIO_ReadPortBit(LPC_GPIO_T *pGPIO, uint32_t port, uint8_t bit) -{ - return (bool) ((pGPIO[port].DATA[1 << bit] >> bit) & 1); -} - -/** - * @brief Get a GPIO pin state via the GPIO byte register - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to get state for - * @return true if the GPIO is high, false if low - * @note This function replaces Chip_GPIO_ReadPortBit() - */ -STATIC INLINE bool Chip_GPIO_GetPinState(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - return (pGPIO[port].DATA[1 << pin]) != 0; -} - -/** - * @brief Seta GPIO direction - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : GPIO port to set - * @param bit : GPIO bit to set - * @param setting : true for output, false for input - * @return Nothing - * @note It is recommended to use the Chip_GPIO_SetPinDIROutput(), - * Chip_GPIO_SetPinDIRInput() or Chip_GPIO_SetPinDIR() functions instead - * of this function. - */ -void Chip_GPIO_WriteDirBit(LPC_GPIO_T *pGPIO, uint32_t port, uint8_t bit, bool setting); - -/** - * @brief Set GPIO direction for a single GPIO pin to an output - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to set direction on as output - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetPinDIROutput(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - pGPIO[port].DIR |= (1UL << pin); -} - -/** - * @brief Set GPIO direction for a single GPIO pin to an input - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to set direction on as input - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetPinDIRInput(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - pGPIO[port].DIR &= ~(1UL << pin); -} - -/** - * @brief Set GPIO direction for a single GPIO pin - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to set direction for - * @param output : true for output, false for input - * @return Nothing - */ -void Chip_GPIO_SetPinDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, bool output); - -/** - * @brief Read a GPIO direction (out or in) - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : GPIO port to read - * @param bit : GPIO bit to read - * @return true of the GPIO is an output, false if input - * @note It is recommended to use the Chip_GPIO_GetPinDIR() function instead. - */ -STATIC INLINE bool Chip_GPIO_ReadDirBit(LPC_GPIO_T *pGPIO, uint32_t port, uint8_t bit) -{ - return (bool) (((pGPIO[port].DIR) >> bit) & 1); -} - -/** - * @brief Get GPIO direction for a single GPIO pin - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : GPIO pin to get direction for - * @return true if the GPIO is an output, false if input - */ -STATIC INLINE bool Chip_GPIO_GetPinDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - return (bool) (pGPIO[port].DIR >> pin) & 1; -} - -/** - * @brief Set Direction for a GPIO port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port Number - * @param bit : GPIO bit to set - * @param out : Direction value, 0 = input, !0 = output - * @return None - * @note Bits set to '0' are not altered. It is recommended to use the - * Chip_GPIO_SetPortDIR() function instead. - */ -void Chip_GPIO_SetDir(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t bit, uint8_t out); - -/** - * @brief Set GPIO direction for a all selected GPIO pins to an output - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinMask : GPIO pin mask to set direction on as output (bits 0..n for pins 0..n) - * @return Nothing - * @note Sets multiple GPIO pins to the output direction, each bit's position that is - * high sets the corresponding pin number for that bit to an output. - */ -STATIC INLINE void Chip_GPIO_SetPortDIROutput(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinMask) -{ - pGPIO[port].DIR |= pinMask; -} - -/** - * @brief Set GPIO direction for a all selected GPIO pins to an input - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinMask : GPIO pin mask to set direction on as input (bits 0..b for pins 0..n) - * @return Nothing - * @note Sets multiple GPIO pins to the input direction, each bit's position that is - * high sets the corresponding pin number for that bit to an input. - */ -STATIC INLINE void Chip_GPIO_SetPortDIRInput(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinMask) -{ - pGPIO[port].DIR &= ~pinMask; -} - -/** - * @brief Set GPIO direction for a all selected GPIO pins to an input or output - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinMask : GPIO pin mask to set direction on (bits 0..b for pins 0..n) - * @param outSet : Direction value, false = set as inputs, true = set as outputs - * @return Nothing - * @note Sets multiple GPIO pins to the input direction, each bit's position that is - * high sets the corresponding pin number for that bit to an input. - */ -void Chip_GPIO_SetPortDIR(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinMask, bool outSet); - -/** - * @brief Get GPIO direction for a all GPIO pins - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return a bitfield containing the input and output states for each pin - * @note For pins 0..n, a high state in a bit corresponds to an output state for the - * same pin, while a low state corresponds to an input state. - */ -STATIC INLINE uint32_t Chip_GPIO_GetPortDIR(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].DIR; -} - -/** - * @brief Set all GPIO raw pin states (regardless of masking) - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param value : Value to set all GPIO pin states (0..n) to - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetPortValue(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t value) -{ - pGPIO[port].DATA[0xFFF] = value; -} - -/** - * @brief Get all GPIO raw pin states (regardless of masking) - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return Current (raw) state of all GPIO pins - */ -STATIC INLINE uint32_t Chip_GPIO_GetPortValue(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].DATA[0xFFF]; -} - -/** - * @brief Set a GPIO port/bit to the high state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param bit : Bit(s) in the port to set high - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. It is recommended to use the - * Chip_GPIO_SetPortOutHigh() function instead. - */ -STATIC INLINE void Chip_GPIO_SetValue(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t bit) -{ - pGPIO[port].DATA[bit] = bit; -} - -/** - * @brief Set selected GPIO output pins to the high state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pins : pins (0..n) to set high - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPortOutHigh(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pins) -{ - pGPIO[port].DATA[pins] = 0xFFF; -} - -/** - * @brief Set an individual GPIO output pin to the high state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : pin number (0..n) to set high - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPinOutHigh(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - pGPIO[port].DATA[1 << pin] = (1 << pin); -} - -/** - * @brief Set a GPIO port/bit to the low state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param bit : Bit(s) in the port to set low - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_ClearValue(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t bit) -{ - pGPIO[port].DATA[bit] = ~bit; -} - -/** - * @brief Set selected GPIO output pins to the low state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pins : pins (0..n) to set low - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPortOutLow(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pins) -{ - pGPIO[port].DATA[pins] = 0; -} - -/** - * @brief Set an individual GPIO output pin to the low state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : pin number (0..n) to set low - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPinOutLow(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - pGPIO[port].DATA[1 << pin] = 0; -} - -/** - * @brief Toggle selected GPIO output pins to the opposite state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pins : pins (0..n) to toggle - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPortToggle(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pins) -{ - pGPIO[port].DATA[pins] ^= 0xFFF; -} - -/** - * @brief Toggle an individual GPIO output pin to the opposite state - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : pin number (0..n) to toggle - * @return None - * @note Any bit set as a '0' will not have it's state changed. This only - * applies to ports configured as an output. - */ -STATIC INLINE void Chip_GPIO_SetPinToggle(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin) -{ - pGPIO[port].DATA[1 << pin] ^= (1 << pin); -} - -/** - * @brief Read current bit states for the selected port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number to read - * @return Current value of GPIO port - * @note The current states of the bits for the port are read, regardless of - * whether the GPIO port bits are input or output. - */ -STATIC INLINE uint32_t Chip_GPIO_ReadValue(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].DATA[4095]; -} - -/** - * @brief Configure the pins as edge sensitive for interrupts - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to edge mode (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetPinModeEdge(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IS &= ~pinmask; -} - -/** - * @brief Configure the pins as level sensitive for interrupts - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to level mode (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetPinModeLevel(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IS |= pinmask; -} - -/** - * @brief Returns current GPIO edge or high level interrupt configuration for all pins for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the edge/level interrupt configuration for each - * pin for the selected port. Bit 0 = pin 0, 1 = pin 1. - * For each bit, a 0 means the edge interrupt is configured, while a 1 means a level - * interrupt is configured. Mask with this return value to determine the - * edge/level configuration for each pin in a port. - */ -STATIC INLINE uint32_t Chip_GPIO_IsLevelEnabled(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].IS; -} - -/** - * @brief Sets GPIO interrupt configuration for both edges for selected pins - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to dual edge mode (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetEdgeModeBoth(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IBE |= pinmask; -} - -/** - * @brief Sets GPIO interrupt configuration for a single edge for selected pins - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to single edge mode (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_SetEdgeModeSingle(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IBE &= ~pinmask; -} - -/** - * @brief Returns current GPIO interrupt dual or single edge configuration for all pins for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the single/dual interrupt configuration for each - * pin for the selected port. Bit 0 = pin 0, 1 = pin 1. - * For each bit, a 0 means the interrupt triggers on a single edge (use the - * Chip_GPIO_SetEdgeModeHigh() and Chip_GPIO_SetEdgeModeLow() functions to configure - * selected edge), while a 1 means the interrupt triggers on both edges. Mask - * with this return value to determine the edge/level configuration for each pin in - * a port. - */ -STATIC INLINE uint32_t Chip_GPIO_GetEdgeModeDir(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].IBE; -} - -/** - * @brief Sets GPIO interrupt configuration when in single edge or level mode to high edge trigger or high level - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to high mode (ORed value of bits 0..11) - * @return Nothing - * @note Use this function to select high level or high edge interrupt mode - * for the selected pins on the selected port when not in dual edge mode. - */ -STATIC INLINE void Chip_GPIO_SetModeHigh(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IEV |= pinmask; -} - -/** - * @brief Sets GPIO interrupt configuration when in single edge or level mode to low edge trigger or low level - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to set to low mode (ORed value of bits 0..11) - * @return Nothing - * @note Use this function to select low level or low edge interrupt mode - * for the selected pins on the selected port when not in dual edge mode. - */ -STATIC INLINE void Chip_GPIO_SetModeLow(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IEV &= ~pinmask; -} - -/** - * @brief Returns current GPIO interrupt edge direction or level mode - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the low or high direction of the interrupt - * configuration for each pin for the selected port. Bit 0 = pin 0, 1 = pin 1. - * For each bit, a 0 means the interrupt triggers on a low level or edge, while a - * 1 means the interrupt triggers on a high level or edge. Mask with this - * return value to determine the high/low configuration for each pin in a port. - */ -STATIC INLINE uint32_t Chip_GPIO_GetModeHighLow(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].IEV; -} - -/** - * @brief Enables interrupts for selected pins on a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to enable interrupts for (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_EnableInt(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IE |= pinmask; -} - -/** - * @brief Disables interrupts for selected pins on a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to disable interrupts for (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_DisableInt(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IE &= ~pinmask; -} - -/** - * @brief Returns current enable pin interrupts for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the enabled pin interrupts (0..11) - */ -STATIC INLINE uint32_t Chip_GPIO_GetEnabledInts(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].IE; -} - -/** - * @brief Returns raw interrupt pending status for pin interrupts for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the raw pending interrupt states for each pin (0..11) on the port - */ -STATIC INLINE uint32_t Chip_GPIO_GetRawInts(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].RIS; -} - -/** - * @brief Returns masked interrupt pending status for pin interrupts for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @return A bifield containing the masked pending interrupt states for each pin (0..11) on the port - */ -STATIC INLINE uint32_t Chip_GPIO_GetMaskedInts(LPC_GPIO_T *pGPIO, uint8_t port) -{ - return pGPIO[port].MIS; -} - -/** - * @brief Clears pending interrupts for selected pins for a port - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pinmask : Pins to clear interrupts for (ORed value of bits 0..11) - * @return Nothing - */ -STATIC INLINE void Chip_GPIO_ClearInts(LPC_GPIO_T *pGPIO, uint8_t port, uint32_t pinmask) -{ - pGPIO[port].IC = pinmask; -} - -/** - * @brief GPIO interrupt mode definitions - */ -typedef enum { - GPIO_INT_ACTIVE_LOW_LEVEL = 0x0, /*!< Selects interrupt on pin to be triggered on LOW level */ - GPIO_INT_ACTIVE_HIGH_LEVEL = 0x1, /*!< Selects interrupt on pin to be triggered on HIGH level */ - GPIO_INT_FALLING_EDGE = 0x2, /*!< Selects interrupt on pin to be triggered on FALLING level */ - GPIO_INT_RISING_EDGE = 0x3, /*!< Selects interrupt on pin to be triggered on RISING level */ - GPIO_INT_BOTH_EDGES = 0x6 /*!< Selects interrupt on pin to be triggered on both edges */ -} GPIO_INT_MODE_T; - -/** - * @brief Composite function for setting up a full interrupt configuration for a single pin - * @param pGPIO : The base of GPIO peripheral on the chip - * @param port : Port number - * @param pin : Pin number (0..11) - * @param modeFlags : GPIO interrupt mode selection - * @return Nothing - */ -void Chip_GPIO_SetupPinInt(LPC_GPIO_T *pGPIO, uint8_t port, uint8_t pin, GPIO_INT_MODE_T mode); - -#endif /* defined(CHIP_LPC11CXX) || defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC1125) */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __GPIO_11XX_2_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpiogroup_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpiogroup_11xx.h deleted file mode 100755 index a04f63f752..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/gpiogroup_11xx.h +++ /dev/null @@ -1,212 +0,0 @@ -/* - * @brief LPC11xx GPIO group driver for CHIP_LPC11AXX, CHIP_LPC11EXX, and - * CHIP_LPC11UXX families only. - * - * @note - * Copyright(C) NXP Semiconductors, 2013 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __GPIOGROUP_11XX_H_ -#define __GPIOGROUP_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup GPIOGP_11XX CHIP: LPC11xx GPIO group driver for CHIP_LPC11(A/E/U)XX families - * @ingroup CHIP_11XX_Drivers - * For device familes identified with CHIP definitions CHIP_LPC11AXX, - * CHIP_LPC11EXX, and CHIP_LPC11UXX only. - * @{ - */ - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) - -/** - * @brief GPIO grouped interrupt register block structure - */ -typedef struct { /*!< GPIO_GROUP_INTn Structure */ - __IO uint32_t CTRL; /*!< GPIO grouped interrupt control register */ - __I uint32_t RESERVED0[7]; - __IO uint32_t PORT_POL[8]; /*!< GPIO grouped interrupt port polarity register */ - __IO uint32_t PORT_ENA[8]; /*!< GPIO grouped interrupt port m enable register */ - uint32_t RESERVED1[4072]; -} LPC_GPIOGROUPINT_T; - -/** - * LPC11xx GPIO group bit definitions - */ -#define GPIOGR_INT (1 << 0) /*!< GPIO interrupt pending/clear bit */ -#define GPIOGR_COMB (1 << 1) /*!< GPIO interrupt OR(0)/AND(1) mode bit */ -#define GPIOGR_TRIG (1 << 2) /*!< GPIO interrupt edge(0)/level(1) mode bit */ - -/** - * @brief Clear interrupt pending status for the selected group - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return None - */ -STATIC INLINE void Chip_GPIOGP_ClearIntStatus(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - uint32_t temp; - - temp = pGPIOGPINT[group].CTRL; - pGPIOGPINT[group].CTRL = temp | GPIOGR_INT; -} - -/** - * @brief Returns current GPIO group inetrrupt pending status - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return true if the group interrupt is pending, otherwise false. - */ -STATIC INLINE bool Chip_GPIOGP_GetIntStatus(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - return (bool) ((pGPIOGPINT[group].CTRL & GPIOGR_INT) != 0); -} - -/** - * @brief Selected GPIO group functionality for trigger on any pin in group (OR mode) - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectOrMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - pGPIOGPINT[group].CTRL &= ~GPIOGR_COMB; -} - -/** - * @brief Selected GPIO group functionality for trigger on all matching pins in group (AND mode) - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectAndMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - pGPIOGPINT[group].CTRL |= GPIOGR_COMB; -} - -/** - * @brief Selected GPIO group functionality edge trigger mode - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectEdgeMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - pGPIOGPINT[group].CTRL &= ~GPIOGR_TRIG; -} - -/** - * @brief Selected GPIO group functionality level trigger mode - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectLevelMode(LPC_GPIOGROUPINT_T *pGPIOGPINT, uint8_t group) -{ - pGPIOGPINT[group].CTRL |= GPIOGR_TRIG; -} - -/** - * @brief Set selected pins for the group and port to low level trigger - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @param port : GPIO port number - * @param pinMask : Or'ed value of pins to select for low level (bit 0 = pin 0, 1 = pin1, etc.) - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectLowLevel(LPC_GPIOGROUPINT_T *pGPIOGPINT, - uint8_t group, - uint8_t port, - uint32_t pinMask) -{ - pGPIOGPINT[group].PORT_POL[port] &= ~pinMask; -} - -/** - * @brief Set selected pins for the group and port to high level trigger - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @param port : GPIO port number - * @param pinMask : Or'ed value of pins to select for high level (bit 0 = pin 0, 1 = pin1, etc.) - * @return None - */ -STATIC INLINE void Chip_GPIOGP_SelectHighLevel(LPC_GPIOGROUPINT_T *pGPIOGPINT, - uint8_t group, - uint8_t port, - uint32_t pinMask) -{ - pGPIOGPINT[group].PORT_POL[port] = pinMask; -} - -/** - * @brief Disabled selected pins for the group interrupt - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @param port : GPIO port number - * @param pinMask : Or'ed value of pins to disable interrupt for (bit 0 = pin 0, 1 = pin1, etc.) - * @return None - * @note Disabled pins do not contrinute to the group interrupt. - */ -STATIC INLINE void Chip_GPIOGP_DisableGroupPins(LPC_GPIOGROUPINT_T *pGPIOGPINT, - uint8_t group, - uint8_t port, - uint32_t pinMask) -{ - pGPIOGPINT[group].PORT_ENA[port] &= ~pinMask; -} - -/** - * @brief Enable selected pins for the group interrupt - * @param pGPIOGPINT : Pointer to GPIO group register block - * @param group : GPIO group number - * @param port : GPIO port number - * @param pinMask : Or'ed value of pins to enable interrupt for (bit 0 = pin 0, 1 = pin1, etc.) - * @return None - * @note Enables pins contrinute to the group interrupt. - */ -STATIC INLINE void Chip_GPIOGP_EnableGroupPins(LPC_GPIOGROUPINT_T *pGPIOGPINT, - uint8_t group, - uint8_t port, - uint32_t pinMask) -{ - pGPIOGPINT[group].PORT_ENA[port] = pinMask; -} - -#endif /* defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __GPIOGROUP_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/i2c_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/i2c_11xx.h deleted file mode 100755 index a657ad0dd8..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/i2c_11xx.h +++ /dev/null @@ -1,543 +0,0 @@ -/* - * @brief LPC11xx I2C driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __I2C_11XX_H_ -#define __I2C_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup I2C_11XX CHIP: LPC11xx I2C driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -#if !defined(CHIP_LPC110X) - -/** - * @brief I2C register block structure - */ -typedef struct { /* I2C0 Structure */ - __IO uint32_t CONSET; /*!< I2C Control Set Register. When a one is written to a bit of this register, the corresponding bit in the I2C control register is set. Writing a zero has no effect on the corresponding bit in the I2C control register. */ - __I uint32_t STAT; /*!< I2C Status Register. During I2C operation, this register provides detailed status codes that allow software to determine the next action needed. */ - __IO uint32_t DAT; /*!< I2C Data Register. During master or slave transmit mode, data to be transmitted is written to this register. During master or slave receive mode, data that has been received may be read from this register. */ - __IO uint32_t ADR0; /*!< I2C Slave Address Register 0. Contains the 7-bit slave address for operation of the I2C interface in slave mode, and is not used in master mode. The least significant bit determines whether a slave responds to the General Call address. */ - __IO uint32_t SCLH; /*!< SCH Duty Cycle Register High Half Word. Determines the high time of the I2C clock. */ - __IO uint32_t SCLL; /*!< SCL Duty Cycle Register Low Half Word. Determines the low time of the I2C clock. SCLL and SCLH together determine the clock frequency generated by an I2C master and certain times used in slave mode. */ - __O uint32_t CONCLR; /*!< I2C Control Clear Register. When a one is written to a bit of this register, the corresponding bit in the I2C control register is cleared. Writing a zero has no effect on the corresponding bit in the I2C control register. */ - __IO uint32_t MMCTRL; /*!< Monitor mode control register. */ - __IO uint32_t ADR1; /*!< I2C Slave Address Register. Contains the 7-bit slave address for operation of the I2C interface in slave mode, and is not used in master mode. The least significant bit determines whether a slave responds to the General Call address. */ - __IO uint32_t ADR2; /*!< I2C Slave Address Register. Contains the 7-bit slave address for operation of the I2C interface in slave mode, and is not used in master mode. The least significant bit determines whether a slave responds to the General Call address. */ - __IO uint32_t ADR3; /*!< I2C Slave Address Register. Contains the 7-bit slave address for operation of the I2C interface in slave mode, and is not used in master mode. The least significant bit determines whether a slave responds to the General Call address. */ - __I uint32_t DATA_BUFFER; /*!< Data buffer register. The contents of the 8 MSBs of the DAT shift register will be transferred to the DATA_BUFFER automatically after every nine bits (8 bits of data plus ACK or NACK) has been received on the bus. */ - __IO uint32_t MASK[4]; /*!< I2C Slave address mask register */ -} LPC_I2C_T; - -/** - * @brief Return values for SLAVE handler - * @note - * Chip drivers will usally be designed to match their events with this value - */ -#define RET_SLAVE_TX 6 /**< Return value, when 1 byte TX'd successfully */ -#define RET_SLAVE_RX 5 /**< Return value, when 1 byte RX'd successfully */ -#define RET_SLAVE_IDLE 2 /**< Return value, when slave enter idle mode */ -#define RET_SLAVE_BUSY 0 /**< Return value, when slave is busy */ - -/** - * @brief I2C state handle return values - */ -#define I2C_STA_STO_RECV 0x20 - -/* - * @brief I2C Control Set register description - */ -#define I2C_I2CONSET_AA ((0x04))/*!< Assert acknowledge flag */ -#define I2C_I2CONSET_SI ((0x08))/*!< I2C interrupt flag */ -#define I2C_I2CONSET_STO ((0x10))/*!< STOP flag */ -#define I2C_I2CONSET_STA ((0x20))/*!< START flag */ -#define I2C_I2CONSET_I2EN ((0x40))/*!< I2C interface enable */ - -/* - * @brief I2C Control Clear register description - */ -#define I2C_I2CONCLR_AAC ((1 << 2)) /*!< Assert acknowledge Clear bit */ -#define I2C_I2CONCLR_SIC ((1 << 3)) /*!< I2C interrupt Clear bit */ -#define I2C_I2CONCLR_STOC ((1 << 4)) /*!< I2C STOP Clear bit */ -#define I2C_I2CONCLR_STAC ((1 << 5)) /*!< START flag Clear bit */ -#define I2C_I2CONCLR_I2ENC ((1 << 6)) /*!< I2C interface Disable bit */ - -/* - * @brief I2C Common Control register description - */ -#define I2C_CON_AA (1UL << 2) /*!< Assert acknowledge bit */ -#define I2C_CON_SI (1UL << 3) /*!< I2C interrupt bit */ -#define I2C_CON_STO (1UL << 4) /*!< I2C STOP bit */ -#define I2C_CON_STA (1UL << 5) /*!< START flag bit */ -#define I2C_CON_I2EN (1UL << 6) /*!< I2C interface bit */ - -/* - * @brief I2C Status Code definition (I2C Status register) - */ -#define I2C_STAT_CODE_BITMASK ((0xF8))/*!< Return Code mask in I2C status register */ -#define I2C_STAT_CODE_ERROR ((0xFF))/*!< Return Code error mask in I2C status register */ - -/* - * @brief I2C return status code definitions - */ -#define I2C_I2STAT_NO_INF ((0xF8))/*!< No relevant information */ -#define I2C_I2STAT_BUS_ERROR ((0x00))/*!< Bus Error */ - -/* - * @brief I2C Master transmit mode - */ -#define I2C_I2STAT_M_TX_START ((0x08))/*!< A start condition has been transmitted */ -#define I2C_I2STAT_M_TX_RESTART ((0x10))/*!< A repeat start condition has been transmitted */ -#define I2C_I2STAT_M_TX_SLAW_ACK ((0x18))/*!< SLA+W has been transmitted, ACK has been received */ -#define I2C_I2STAT_M_TX_SLAW_NACK ((0x20))/*!< SLA+W has been transmitted, NACK has been received */ -#define I2C_I2STAT_M_TX_DAT_ACK ((0x28))/*!< Data has been transmitted, ACK has been received */ -#define I2C_I2STAT_M_TX_DAT_NACK ((0x30))/*!< Data has been transmitted, NACK has been received */ -#define I2C_I2STAT_M_TX_ARB_LOST ((0x38))/*!< Arbitration lost in SLA+R/W or Data bytes */ - -/* - * @brief I2C Master receive mode - */ -#define I2C_I2STAT_M_RX_START ((0x08))/*!< A start condition has been transmitted */ -#define I2C_I2STAT_M_RX_RESTART ((0x10))/*!< A repeat start condition has been transmitted */ -#define I2C_I2STAT_M_RX_ARB_LOST ((0x38))/*!< Arbitration lost */ -#define I2C_I2STAT_M_RX_SLAR_ACK ((0x40))/*!< SLA+R has been transmitted, ACK has been received */ -#define I2C_I2STAT_M_RX_SLAR_NACK ((0x48))/*!< SLA+R has been transmitted, NACK has been received */ -#define I2C_I2STAT_M_RX_DAT_ACK ((0x50))/*!< Data has been received, ACK has been returned */ -#define I2C_I2STAT_M_RX_DAT_NACK ((0x58))/*!< Data has been received, NACK has been returned */ - -/* - * @brief I2C Slave receive mode - */ -#define I2C_I2STAT_S_RX_SLAW_ACK ((0x60))/*!< Own slave address has been received, ACK has been returned */ -#define I2C_I2STAT_S_RX_ARB_LOST_M_SLA ((0x68))/*!< Arbitration lost in SLA+R/W as master */ -// #define I2C_I2STAT_S_RX_SLAW_ACK ((0x68)) /*!< Own SLA+W has been received, ACK returned */ -#define I2C_I2STAT_S_RX_GENCALL_ACK ((0x70))/*!< General call address has been received, ACK has been returned */ -#define I2C_I2STAT_S_RX_ARB_LOST_M_GENCALL ((0x78))/*!< Arbitration lost in SLA+R/W (GENERAL CALL) as master */ -// #define I2C_I2STAT_S_RX_GENCALL_ACK ((0x78)) /*!< General call address has been received, ACK has been returned */ -#define I2C_I2STAT_S_RX_PRE_SLA_DAT_ACK ((0x80))/*!< Previously addressed with own SLA; Data has been received, ACK has been returned */ -#define I2C_I2STAT_S_RX_PRE_SLA_DAT_NACK ((0x88))/*!< Previously addressed with own SLA;Data has been received and NOT ACK has been returned */ -#define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_ACK ((0x90))/*!< Previously addressed with General Call; Data has been received and ACK has been returned */ -#define I2C_I2STAT_S_RX_PRE_GENCALL_DAT_NACK ((0x98))/*!< Previously addressed with General Call; Data has been received and NOT ACK has been returned */ -#define I2C_I2STAT_S_RX_STA_STO_SLVREC_SLVTRX ((0xA0))/*!< A STOP condition or repeated START condition has been received while still addressed as SLV/REC (Slave Receive) or - SLV/TRX (Slave Transmit) */ - -/* - * @brief I2C Slave transmit mode - */ -#define I2C_I2STAT_S_TX_SLAR_ACK ((0xA8))/*!< Own SLA+R has been received, ACK has been returned */ -#define I2C_I2STAT_S_TX_ARB_LOST_M_SLA ((0xB0))/*!< Arbitration lost in SLA+R/W as master */ -// #define I2C_I2STAT_S_TX_SLAR_ACK ((0xB0)) /*!< Own SLA+R has been received, ACK has been returned */ -#define I2C_I2STAT_S_TX_DAT_ACK ((0xB8))/*!< Data has been transmitted, ACK has been received */ -#define I2C_I2STAT_S_TX_DAT_NACK ((0xC0))/*!< Data has been transmitted, NACK has been received */ -#define I2C_I2STAT_S_TX_LAST_DAT_ACK ((0xC8))/*!< Last data byte in I2DAT has been transmitted (AA = 0); ACK has been received */ -#define I2C_SLAVE_TIME_OUT 0x10000000UL/*!< Time out in case of using I2C slave mode */ - -/* - * @brief I2C Data register definition - */ -#define I2C_I2DAT_BITMASK ((0xFF))/*!< Mask for I2DAT register */ -#define I2C_I2DAT_IDLE_CHAR (0xFF) /*!< Idle data value will be send out in slave mode in case of the actual expecting data requested from the master is greater than - its sending data length that can be supported */ - -/* - * @brief I2C Monitor mode control register description - */ -#define I2C_I2MMCTRL_MM_ENA ((1 << 0)) /**< Monitor mode enable */ -#define I2C_I2MMCTRL_ENA_SCL ((1 << 1)) /**< SCL output enable */ -#define I2C_I2MMCTRL_MATCH_ALL ((1 << 2)) /**< Select interrupt register match */ -#define I2C_I2MMCTRL_BITMASK ((0x07)) /**< Mask for I2MMCTRL register */ - -/* - * @brief I2C Data buffer register description - */ -#define I2DATA_BUFFER_BITMASK ((0xFF))/*!< I2C Data buffer register bit mask */ - -/* - * @brief I2C Slave Address registers definition - */ -#define I2C_I2ADR_GC ((1 << 0)) /*!< General Call enable bit */ -#define I2C_I2ADR_BITMASK ((0xFF))/*!< I2C Slave Address registers bit mask */ - -/* - * @brief I2C Mask Register definition - */ -#define I2C_I2MASK_MASK(n) ((n & 0xFE))/*!< I2C Mask Register mask field */ - -/* - * @brief I2C SCL HIGH duty cycle Register definition - */ -#define I2C_I2SCLH_BITMASK ((0xFFFF)) /*!< I2C SCL HIGH duty cycle Register bit mask */ - -/* - * @brief I2C SCL LOW duty cycle Register definition - */ -#define I2C_I2SCLL_BITMASK ((0xFFFF)) /*!< I2C SCL LOW duty cycle Register bit mask */ - -/* - * @brief I2C status values - */ -#define I2C_SETUP_STATUS_ARBF (1 << 8) /**< Arbitration false */ -#define I2C_SETUP_STATUS_NOACKF (1 << 9) /**< No ACK returned */ -#define I2C_SETUP_STATUS_DONE (1 << 10) /**< Status DONE */ - -/* - * @brief I2C state handle return values - */ -#define I2C_OK 0x00 -#define I2C_BYTE_SENT 0x01 -#define I2C_BYTE_RECV 0x02 -#define I2C_LAST_BYTE_RECV 0x04 -#define I2C_SEND_END 0x08 -#define I2C_RECV_END 0x10 -#define I2C_STA_STO_RECV 0x20 - -#define I2C_ERR (0x10000000) -#define I2C_NAK_RECV (0x10000000 | 0x01) - -#define I2C_CheckError(ErrorCode) (ErrorCode & 0x10000000) - -/* - * @brief I2C monitor control configuration defines - */ -#define I2C_MONITOR_CFG_SCL_OUTPUT I2C_I2MMCTRL_ENA_SCL /**< SCL output enable */ -#define I2C_MONITOR_CFG_MATCHALL I2C_I2MMCTRL_MATCH_ALL /**< Select interrupt register match */ - -/** - * @brief I2C Slave Identifiers - */ -typedef enum { - I2C_SLAVE_GENERAL, /**< Slave ID for general calls */ - I2C_SLAVE_0, /**< Slave ID fo Slave Address 0 */ - I2C_SLAVE_1, /**< Slave ID fo Slave Address 1 */ - I2C_SLAVE_2, /**< Slave ID fo Slave Address 2 */ - I2C_SLAVE_3, /**< Slave ID fo Slave Address 3 */ - I2C_SLAVE_NUM_INTERFACE /**< Number of slave interfaces */ -} I2C_SLAVE_ID; - -/** - * @brief I2C transfer status - */ -typedef enum { - I2C_STATUS_DONE, /**< Transfer done successfully */ - I2C_STATUS_NAK, /**< NAK received during transfer */ - I2C_STATUS_ARBLOST, /**< Aribitration lost during transfer */ - I2C_STATUS_BUSERR, /**< Bus error in I2C transfer */ - I2C_STATUS_BUSY, /**< I2C is busy doing transfer */ -} I2C_STATUS_T; - -/** - * @brief Master transfer data structure definitions - */ -typedef struct { - uint8_t slaveAddr; /**< 7-bit I2C Slave address */ - const uint8_t *txBuff; /**< Pointer to array of bytes to be transmitted */ - int txSz; /**< Number of bytes in transmit array, - if 0 only receive transfer will be carried on */ - uint8_t *rxBuff; /**< Pointer memory where bytes received from I2C be stored */ - int rxSz; /**< Number of bytes to received, - if 0 only transmission we be carried on */ - I2C_STATUS_T status; /**< Status of the current I2C transfer */ -} I2C_XFER_T; - -/** - * @brief I2C interface IDs - * @note - * All Chip functions will take this as the first parameter, - * I2C_NUM_INTERFACE must never be used for calling any Chip - * functions, it is only used to find the number of interfaces - * available in the Chip. - */ -typedef enum I2C_ID { - I2C0, /**< ID I2C0 */ - I2C_NUM_INTERFACE /**< Number of I2C interfaces in the chip */ -} I2C_ID_T; - -/** - * @brief I2C master events - */ -typedef enum { - I2C_EVENT_WAIT = 1, /**< I2C Wait event */ - I2C_EVENT_DONE, /**< Done event that wakes up Wait event */ - I2C_EVENT_LOCK, /**< Re-entrency lock event for I2C transfer */ - I2C_EVENT_UNLOCK, /**< Re-entrency unlock event for I2C transfer */ - I2C_EVENT_SLAVE_RX, /**< Slave receive event */ - I2C_EVENT_SLAVE_TX, /**< Slave transmit event */ -} I2C_EVENT_T; - -/** - * @brief Event handler function type - */ -typedef void (*I2C_EVENTHANDLER_T)(I2C_ID_T, I2C_EVENT_T); - -/** - * @brief Initializes the LPC_I2C peripheral with specified parameter. - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Nothing - */ -void Chip_I2C_Init(I2C_ID_T id); - -/** - * @brief De-initializes the I2C peripheral registers to their default reset values - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Nothing - */ -void Chip_I2C_DeInit(I2C_ID_T id); - -/** - * @brief Set up clock rate for LPC_I2C peripheral. - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param clockrate : Target clock rate value to initialized I2C peripheral (Hz) - * @return Nothing - * @note - * Parameter @a clockrate for I2C0 should be from 1000 up to 1000000 - * (1 KHz to 1 MHz), as I2C0 support Fast Mode Plus. If the @a clockrate - * is more than 400 KHz (Fast Plus Mode) Board_I2C_EnableFastPlus() - * must be called prior to calling this function. - */ -void Chip_I2C_SetClockRate(I2C_ID_T id, uint32_t clockrate); - -/** - * @brief Get current clock rate for LPC_I2C peripheral. - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return The current I2C peripheral clock rate - */ -uint32_t Chip_I2C_GetClockRate(I2C_ID_T id); - -/** - * @brief Transmit and Receive data in master mode - * @param id : I2C peripheral selected (I2C0, I2C1 etc) - * @param xfer : Pointer to a I2C_XFER_T structure see notes below - * @return - * Any of #I2C_STATUS_T values, xfer->txSz will have number of bytes - * not sent due to error, xfer->rxSz will have the number of bytes yet - * to be received. - * @note - * The parameter @a xfer should have its member @a slaveAddr initialized - * to the 7-Bit slave address to which the master will do the xfer, Bit0 - * to bit6 should have the address and Bit8 is ignored. During the transfer - * no code (like event handler) must change the content of the memory - * pointed to by @a xfer. The member of @a xfer, @a txBuff and @a txSz be - * initialized to the memory from which the I2C must pick the data to be - * transfered to slave and the number of bytes to send respectively, similarly - * @a rxBuff and @a rxSz must have pointer to memroy where data received - * from slave be stored and the number of data to get from slave respectilvely. - */ -int Chip_I2C_MasterTransfer(I2C_ID_T id, I2C_XFER_T *xfer); - -/** - * @brief Transmit data to I2C slave using I2C Master mode - * @param id : I2C peripheral ID (I2C0, I2C1 .. etc) - * @param slaveAddr : Slave address to which the data be written - * @param buff : Pointer to buffer having the array of data - * @param len : Number of bytes to be transfered from @a buff - * @return Number of bytes successfully transfered - */ -int Chip_I2C_MasterSend(I2C_ID_T id, uint8_t slaveAddr, const uint8_t *buff, uint8_t len); - -/** - * @brief Transfer a command to slave and receive data from slave after a repeated start - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param slaveAddr : Slave address of the I2C device - * @param cmd : Command (Address/Register) to be written - * @param buff : Pointer to memory that will hold the data received - * @param len : Number of bytes to receive - * @return Number of bytes successfully received - */ -int Chip_I2C_MasterCmdRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t cmd, uint8_t *buff, int len); - -/** - * @brief Get pointer to current function handling the events - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Pointer to function handing events of I2C - */ -I2C_EVENTHANDLER_T Chip_I2C_GetMasterEventHandler(I2C_ID_T id); - -/** - * @brief Set function that must handle I2C events - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param event : Pointer to function that will handle the event (Should not be NULL) - * @return 1 when successful, 0 when a transfer is on going with its own event handler - */ -int Chip_I2C_SetMasterEventHandler(I2C_ID_T id, I2C_EVENTHANDLER_T event); - -/** - * @brief Set function that must handle I2C events - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param slaveAddr : Slave address from which data be read - * @param buff : Pointer to memory where data read be stored - * @param len : Number of bytes to read from slave - * @return Number of bytes read successfully - */ -int Chip_I2C_MasterRead(I2C_ID_T id, uint8_t slaveAddr, uint8_t *buff, int len); - -/** - * @brief Default event handler for polling operation - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param event : Event ID of the event that called the function - * @return Nothing - */ -void Chip_I2C_EventHandlerPolling(I2C_ID_T id, I2C_EVENT_T event); - -/** - * @brief Default event handler for interrupt base operation - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param event : Event ID of the event that called the function - * @return Nothing - */ -void Chip_I2C_EventHandler(I2C_ID_T id, I2C_EVENT_T event); - -/** - * @brief I2C Master transfer state change handler - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Nothing - * @note Usually called from the appropriate Interrupt handler - */ -void Chip_I2C_MasterStateHandler(I2C_ID_T id); - -/** - * @brief Disable I2C peripheral's operation - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Nothing - */ -void Chip_I2C_Disable(I2C_ID_T id); - -/** - * @brief Checks if master xfer in progress - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return 1 if master xfer in progress 0 otherwise - * @note - * This API is generally used in interrupt handler - * of the application to decide whether to call - * master state handler or to call slave state handler - */ -int Chip_I2C_IsMasterActive(I2C_ID_T id); - -/** - * @brief Setup a slave I2C device - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @param sid : I2C Slave peripheral ID (I2C_SLAVE_0, I2C_SLAVE_1 etc) - * @param xfer : Pointer to transfer structure (see note below for more info) - * @param event : Event handler for slave transfers - * @param addrMask : Address mask to use along with slave address (see notes below for more info) - * @return Nothing - * @note - * Parameter @a xfer should point to a valid I2C_XFER_T structure object - * and must have @a slaveAddr initialized with 7bit Slave address (From Bit1 to Bit7), - * Bit0 when set enables general call handling, @a slaveAddr along with @a addrMask will - * be used to match the slave address. @a rxBuff and @a txBuff must point to valid buffers - * where slave can receive or send the data from, size of which will be provided by - * @a rxSz and @a txSz respectively. Function pointed to by @a event will be called - * for the following events #I2C_EVENT_SLAVE_RX (One byte of data received successfully - * from the master and stored inside memory pointed by xfer->rxBuff, incremented - * the pointer and decremented the @a xfer->rxSz), #I2C_EVENT_SLAVE_TX (One byte of - * data from xfer->txBuff was sent to master successfully, incremented the pointer - * and decremented xfer->txSz), #I2C_EVENT_DONE (Master is done doing its transfers - * with the slave).
- *
Bit-0 of the parameter @a addrMask is reserved and should always be 0. Any bit (BIT1 - * to BIT7) set in @a addrMask will make the corresponding bit in *xfer->slaveAddr* as - * don't care. Thit is, if *xfer->slaveAddr* is (0x10 << 1) and @a addrMask is (0x03 << 1) then - * 0x10, 0x11, 0x12, 0x13 will all be considered as valid slave addresses for the registered - * slave. Upon receving any event *xfer->slaveAddr* (BIT1 to BIT7) will hold the actual - * address which was received from master.
- *
General Call Handling
- * Slave can receive data from master using general call address (0x00). General call - * handling must be setup as given below - * - Call Chip_I2C_SlaveSetup() with argument @a sid as I2C_SLAVE_GENERAL - * - xfer->slaveAddr ignored, argument @a addrMask ignored - * - function provided by @a event will registered to be called when slave received data using addr 0x00 - * - xfer->rxBuff and xfer->rxSz should be valid in argument @a xfer - * - To handle General Call only (No other slaves are configured) - * - Call Chip_I2C_SlaveSetup() with sid as I2C_SLAVE_X (X=0,1,2,3) - * - setup @a xfer with slaveAddr member set to 0, @a event is ignored hence can be NULL - * - provide @a addrMask (typically 0, if not you better be knowing what you are doing) - * - To handler General Call when other slave is active - * - Call Chip_I2C_SlaveSetup() with sid as I2C_SLAVE_X (X=0,1,2,3) - * - setup @a xfer with slaveAddr member set to 7-Bit Slave address [from Bit1 to 7] - * - Set Bit0 of @a xfer->slaveAddr as 1 - * - Provide appropriate @a addrMask - * - Argument @a event must point to function, that handles events from actual slaveAddress and not the GC - * @warning - * If the slave has only one byte in its txBuff, once that byte is transfered to master the event handler - * will be called for event #I2C_EVENT_DONE. If the master attempts to read more bytes in the same transfer - * then the slave hardware will send 0xFF to master till the end of transfer, event handler will not be - * called to notify this. For more info see section below
- *
Last data handling in slave
- * If the user wants to implement a slave which will read a byte from a specific location over and over - * again whenever master reads the slave. If the user initializes the xfer->txBuff as the location to read - * the byte from and xfer->txSz as 1, then say, if master reads one byte; slave will send the byte read from - * xfer->txBuff and will call the event handler with #I2C_EVENT_DONE. If the master attempts to read another - * byte instead of sending the byte read from xfer->txBuff the slave hardware will send 0xFF and no event will - * occur. To handle this issue, slave should set xfer->txSz to 2, in which case when master reads the byte - * event handler will be called with #I2C_EVENT_SLAVE_TX, in which the slave implementation can reset the buffer - * and size back to original location (i.e, xfer->txBuff--, xfer->txSz++), if the master reads another byte - * in the same transfer, byte read from xfer->txBuff will be sent and #I2C_EVENT_SLAVE_TX will be called again, and - * the process repeats. - */ -void Chip_I2C_SlaveSetup(I2C_ID_T id, - I2C_SLAVE_ID sid, - I2C_XFER_T *xfer, - I2C_EVENTHANDLER_T event, - uint8_t addrMask); - -/** - * @brief I2C Slave event handler - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return Nothing - */ -void Chip_I2C_SlaveStateHandler(I2C_ID_T id); - -/** - * @brief I2C peripheral state change checking - * @param id : I2C peripheral ID (I2C0, I2C1 ... etc) - * @return 1 if I2C peripheral @a id has changed its state, - * 0 if there is no state change - * @note - * This function must be used by the application when - * the polling has to be done based on state change. - */ -int Chip_I2C_IsStateChanged(I2C_ID_T id); - -#endif /* !defined(CHIP_LPC110X) */ - -/** - * @} - */ - - #ifdef __cplusplus -} -#endif - -#endif /* __I2C_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/iocon_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/iocon_11xx.h deleted file mode 100755 index be83679515..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/iocon_11xx.h +++ /dev/null @@ -1,288 +0,0 @@ -/* - * @brief IOCON registers and control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __IOCON_11XX_H_ -#define __IOCON_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup IOCON_11XX CHIP: LPC11xx IO Control driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief IO Configuration Unit register block structure - */ -#if defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) -typedef struct { /*!< LPC11AXX/LPC11UXX/LPC11EXX IOCON Structure */ - __IO uint32_t PIO0[24]; - __IO uint32_t PIO1[32]; -} LPC_IOCON_T; - -#else -/** - * @brief LPC11XX I/O Configuration register offset - */ -typedef enum CHIP_IOCON_PIO { - IOCON_PIO0_0 = (0x00C >> 2), - IOCON_PIO0_1 = (0x010 >> 2), - IOCON_PIO0_2 = (0x01C >> 2), - IOCON_PIO0_3 = (0x02C >> 2), - IOCON_PIO0_4 = (0x030 >> 2), - IOCON_PIO0_5 = (0x034 >> 2), - IOCON_PIO0_6 = (0x04C >> 2), - IOCON_PIO0_7 = (0x050 >> 2), - IOCON_PIO0_8 = (0x060 >> 2), - IOCON_PIO0_9 = (0x064 >> 2), - IOCON_PIO0_10 = (0x070 >> 2), - IOCON_PIO0_11 = (0x074 >> 2), - - IOCON_PIO1_0 = (0x078 >> 2), - IOCON_PIO1_1 = (0x07C >> 2), - IOCON_PIO1_2 = (0x080 >> 2), - IOCON_PIO1_3 = (0x090 >> 2), - IOCON_PIO1_4 = (0x094 >> 2), - IOCON_PIO1_5 = (0x0A0 >> 2), - IOCON_PIO1_6 = (0x0A4 >> 2), - IOCON_PIO1_7 = (0x0A8 >> 2), - IOCON_PIO1_8 = (0x014 >> 2), - IOCON_PIO1_9 = (0x038 >> 2), - IOCON_PIO1_10 = (0x06C >> 2), - IOCON_PIO1_11 = (0x098 >> 2), - - IOCON_PIO2_0 = (0x008 >> 2), - IOCON_PIO2_1 = (0x028 >> 2), - IOCON_PIO2_2 = (0x05C >> 2), - IOCON_PIO2_3 = (0x08C >> 2), - IOCON_PIO2_4 = (0x040 >> 2), - IOCON_PIO2_5 = (0x044 >> 2), - IOCON_PIO2_6 = (0x000 >> 2), - IOCON_PIO2_7 = (0x020 >> 2), - IOCON_PIO2_8 = (0x024 >> 2), - IOCON_PIO2_9 = (0x054 >> 2), - IOCON_PIO2_10 = (0x058 >> 2), -#if !defined(CHIP_LPC1125) - IOCON_PIO2_11 = (0x070 >> 2), -#endif - - IOCON_PIO3_0 = (0x084 >> 2), -#if !defined(CHIP_LPC1125) - IOCON_PIO3_1 = (0x088 >> 2), -#endif - IOCON_PIO3_2 = (0x09C >> 2), - IOCON_PIO3_3 = (0x0AC >> 2), - IOCON_PIO3_4 = (0x03C >> 2), - IOCON_PIO3_5 = (0x048 >> 2), -} CHIP_IOCON_PIO_T; - -/** - * @brief LPC11XX Pin location select - */ -typedef enum CHIP_IOCON_PIN_LOC { - IOCON_SCKLOC_PIO0_10 = (0xB0), /*!< Selects SCK0 function in pin location PIO0_10 */ -#if !defined(CHIP_LPC1125) - IOCON_SCKLOC_PIO2_11 = (0xB0 | 1), /*!< Selects SCK0 function in pin location PIO2_11 */ -#endif - IOCON_SCKLOC_PIO0_6 = (0xB0 | 2), /*!< Selects SCK0 function in pin location PIO0_6 */ - - IOCON_DSRLOC_PIO2_1 = (0xB4), /*!< Selects DSR function in pin location PIO2_1 */ -#if !defined(CHIP_LPC1125) - IOCON_DSRLOC_PIO3_1 = (0xB4 | 1), /*!< Selects DSR function in pin location PIO3_1 */ -#endif - - IOCON_DCDLOC_PIO2_2 = (0xB8), /*!< Selects DCD function in pin location PIO2_2 */ - IOCON_DCDLOC_PIO3_2 = (0xB8 | 1), /*!< Selects DCD function in pin location PIO3_2 */ - - IOCON_RILOC_PIO2_3 = (0xBC), /*!< Selects RI function in pin location PIO2_3 */ - IOCON_RILOC_PIO3_3 = (0xBC | 1), /*!< Selects Ri function in pin location PIO3_3 */ - -#if defined(CHIP_LPC1125) - IOCON_SSEL1_LOC_PIO2_2 = (0x18), /*!< Selects SSEL1 function in pin location PIO2_2 */ - IOCON_SSEL1_LOC_PIO2_4 = (0x18 | 1), /*!< Selects SSEL1 function in pin location PIO2_4 */ - - IOCON_CT16B0_CAP0_LOC_PIO0_2 = (0xC0), /*!< Selects SSEL1 CTB16B0_CAP0 function in pin location PIO0_2 */ - IOCON_CT16B0_CAP0_LOC_PIO3_3 = (0xC0 | 1), /*!< Selects SSEL1 CTB16B0_CAP0 function in pin location PIO3_3 */ - - IOCON_SCK1_LOC_PIO2_1 = (0xC4), /*!< Selects SCK1 function in pin location PIO2_1 */ - IOCON_SCK1_LOC_PIO3_2 = (0xC4 | 1), /*!< Selects SCK1 function in pin location PIO3_2 */ - - IOCON_MISO1_LOC_PIO2_2 = (0xC8), /*!< Selects MISO1 function in pin location PIO2_2 */ - IOCON_MISO1_LOC_PIO1_10 = (0xC8 | 1), /*!< Selects MISO1 function in pin location PIO1_10 */ - - IOCON_MOSI1_LOC_PIO2_3 = (0xCC), /*!< Selects MOSI1 function in pin location PIO2_3 */ - IOCON_MOSI1_LOC_PIO1_9 = (0xCC), /*!< Selects MOSI1 function in pin location PIO1_9 */ - - IOCON_CT326B0_CAP0_LOC_PIO1_5 = (0xD0), /*!< Selects CT32B0_CAP0 function in pin location PIO1_5 */ - IOCON_CT326B0_CAP0_LOC_PIO2_9 = (0xD0 | 1), /*!< Selects CT32B0_CAP0 function in pin location PIO2_9 */ - - IOCON_U0_RXD_LOC_PIO1_6 = (0xD4), /*!< Selects U0 RXD function in pin location PIO1_6 */ - IOCON_U0_RXD_LOC_PIO2_7 = (0xD4 | 1), /*!< Selects U0 RXD function in pin location PIO2_7 */ - IOCON_U0_RXD_LOC_PIO3_4 = (0xD4 | 3), /*!< Selects U0 RXD function in pin location PIO3_4 */ -#endif - -} CHIP_IOCON_PIN_LOC_T; - -typedef struct { /*!< LPC11XX/LPC11XXLV/LPC11UXX IOCON Structure */ - __IO uint32_t REG[48]; -} LPC_IOCON_T; -#endif - -/** - * IOCON function and mode selection definitions - * See the User Manual for specific modes and functions supported by the - * various LPC11xx devices. Functionality can vary per device. - */ -#define IOCON_FUNC0 0x0 /*!< Selects pin function 0 */ -#define IOCON_FUNC1 0x1 /*!< Selects pin function 1 */ -#define IOCON_FUNC2 0x2 /*!< Selects pin function 2 */ -#define IOCON_FUNC3 0x3 /*!< Selects pin function 3 */ -#define IOCON_FUNC4 0x4 /*!< Selects pin function 4 */ -#define IOCON_FUNC5 0x5 /*!< Selects pin function 5 */ -#define IOCON_FUNC6 0x6 /*!< Selects pin function 6 */ -#define IOCON_FUNC7 0x7 /*!< Selects pin function 7 */ -#define IOCON_MODE_INACT (0x0 << 3) /*!< No addition pin function */ -#define IOCON_MODE_PULLDOWN (0x1 << 3) /*!< Selects pull-down function */ -#define IOCON_MODE_PULLUP (0x2 << 3) /*!< Selects pull-up function */ -#define IOCON_MODE_REPEATER (0x3 << 3) /*!< Selects pin repeater function */ -#define IOCON_HYS_EN (0x1 << 5) /*!< Enables hysteresis */ -#define IOCON_INV_EN (0x1 << 6) /*!< Enables invert function on input */ -#define IOCON_ADMODE_EN (0x0 << 7) /*!< Enables analog input function (analog pins only) */ -#define IOCON_DIGMODE_EN (0x1 << 7) /*!< Enables digital function (analog pins only) */ -#define IOCON_SFI2C_EN (0x0 << 8) /*!< I2C standard mode/fast-mode */ -#define IOCON_STDI2C_EN (0x1 << 8) /*!< I2C standard I/O functionality */ -#define IOCON_FASTI2C_EN (0x2 << 8) /*!< I2C Fast-mode Plus */ -#define IOCON_FILT_DIS (0x1 << 8) /*!< Disables noise pulses filtering (10nS glitch filter) */ -#define IOCON_OPENDRAIN_EN (0x1 << 10) /*!< Enables open-drain function */ - -/** - * IOCON function and mode selection definitions (old) - * For backwards compatibility. - */ -#define MD_PLN (0x0 << 3) /*!< Disable pull-down and pull-up resistor at resistor at pad */ -#define MD_PDN (0x1 << 3) /*!< Enable pull-down resistor at pad */ -#define MD_PUP (0x2 << 3) /*!< Enable pull-up resistor at pad */ -#define MD_BUK (0x3 << 3) /*!< Enable pull-down and pull-up resistor at resistor at pad (repeater mode) */ -#define MD_HYS (0x1 << 5) /*!< Enable hysteresis */ -#define MD_INV (0x1 << 6) /*!< Invert enable */ -#define MD_ADMODE (0x0 << 7) /*!< Select analog mode */ -#define MD_DIGMODE (0x1 << 7) /*!< Select digitial mode */ -#define MD_DISFIL (0x0 << 8) /*!< Disable 10nS input glitch filter */ -#define MD_ENFIL (0x1 << 8) /*!< Enable 10nS input glitch filter */ -#define MD_SFI2C (0x0 << 8) /*!< I2C standard mode/fast-mode */ -#define MD_STDI2C (0x1 << 8) /*!< I2C standard I/O functionality */ -#define MD_FASTI2C (0x2 << 8) /*!< I2C Fast-mode Plus */ -#define MD_OPENDRAIN (0x1 << 10) /*!< Open drain mode bit */ -#define FUNC0 0x0 -#define FUNC1 0x1 -#define FUNC2 0x2 -#define FUNC3 0x3 -#define FUNC4 0x4 -#define FUNC5 0x5 -#define FUNC6 0x6 -#define FUNC7 0x7 - -#if defined(CHIP_LPC11UXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11AXX) -/** - * @brief Sets I/O Control pin mux - * @param pIOCON : The base of IOCON peripheral on the chip - * @param port : GPIO port to mux - * @param pin : GPIO pin to mux - * @param modefunc : OR'ed values or type IOCON_* - * @return Nothing - */ -void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint32_t modefunc); - -/** - * @brief I/O Control pin mux - * @param pIOCON : The base of IOCON peripheral on the chip - * @param port : GPIO port to mux - * @param pin : GPIO pin to mux - * @param mode : OR'ed values or type IOCON_* - * @param func : Pin function, value of type IOCON_FUNC? - * @return Nothing - */ -STATIC INLINE void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, uint8_t port, uint8_t pin, uint16_t mode, uint8_t func) -{ - Chip_IOCON_PinMuxSet(pIOCON, port, pin, (uint32_t) (mode | func)); -} - -#else - -/** - * @brief Sets I/O Control pin mux - * @param pIOCON : The base of IOCON peripheral on the chip - * @param pin : GPIO pin to mux - * @param modefunc : OR'ed values or type IOCON_* - * @return Nothing - */ -STATIC INLINE void Chip_IOCON_PinMuxSet(LPC_IOCON_T *pIOCON, CHIP_IOCON_PIO_T pin, uint32_t modefunc) -{ - pIOCON->REG[pin] = modefunc; -} - -/** - * @brief I/O Control pin mux - * @param pIOCON : The base of IOCON peripheral on the chip - * @param pin : GPIO pin to mux - * @param mode : OR'ed values or type IOCON_* - * @param func : Pin function, value of type IOCON_FUNC? - * @return Nothing - */ -STATIC INLINE void Chip_IOCON_PinMux(LPC_IOCON_T *pIOCON, CHIP_IOCON_PIO_T pin, uint16_t mode, uint8_t func) -{ - Chip_IOCON_PinMuxSet(pIOCON, pin, (uint32_t) (mode | func)); -} - -/** - * @brief Select pin location - * @param pIOCON : The base of IOCON peripheral on the chip - * @param sel : location selection - * @return Nothing - */ -STATIC INLINE void Chip_IOCON_PinLocSel(LPC_IOCON_T *pIOCON, CHIP_IOCON_PIN_LOC_T sel) -{ - pIOCON->REG[sel >> 2] = sel & 0x03; -} - -#endif /* defined(CHIP_LPC11UXX) || defined (CHIP_LPC11EXX) || defined (CHIP_LPC11AXX) */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __IOCON_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/lpc_types.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/lpc_types.h deleted file mode 100755 index 772143e5e5..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/lpc_types.h +++ /dev/null @@ -1,216 +0,0 @@ -/* - * @brief Common types used in LPC functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __LPC_TYPES_H_ -#define __LPC_TYPES_H_ - -#include -#include - -/** @defgroup LPC_Types CHIP: LPC Common Types - * @ingroup CHIP_Common - * @{ - */ - -/** @defgroup LPC_Types_Public_Types LPC Public Types - * @{ - */ - -/** - * @brief Boolean Type definition - */ -typedef enum {FALSE = 0, TRUE = !FALSE} Bool; - -/** - * @brief Boolean Type definition - */ -#if !defined(__cplusplus) -// typedef enum {false = 0, true = !false} bool; -#endif - -/** - * @brief Flag Status and Interrupt Flag Status type definition - */ -typedef enum {RESET = 0, SET = !RESET} FlagStatus, IntStatus, SetState; -#define PARAM_SETSTATE(State) ((State == RESET) || (State == SET)) - -/** - * @brief Functional State Definition - */ -typedef enum {DISABLE = 0, ENABLE = !DISABLE} FunctionalState; -#define PARAM_FUNCTIONALSTATE(State) ((State == DISABLE) || (State == ENABLE)) - -/** - * @ Status type definition - */ -typedef enum {ERROR = 0, SUCCESS = !ERROR} Status; - -/** - * Read/Write transfer type mode (Block or non-block) - */ -typedef enum { - NONE_BLOCKING = 0, /**< None Blocking type */ - BLOCKING, /**< Blocking type */ -} TRANSFER_BLOCK_T; - -/** Pointer to Function returning Void (any number of parameters) */ -typedef void (*PFV)(); - -/** Pointer to Function returning int32_t (any number of parameters) */ -typedef int32_t (*PFI)(); - -/** - * @} - */ - -/** @defgroup LPC_Types_Public_Macros LPC Public Macros - * @{ - */ - -/* _BIT(n) sets the bit at position "n" - * _BIT(n) is intended to be used in "OR" and "AND" expressions: - * e.g., "(_BIT(3) | _BIT(7))". - */ -#undef _BIT -/* Set bit macro */ -#define _BIT(n) (1 << (n)) - -/* _SBF(f,v) sets the bit field starting at position "f" to value "v". - * _SBF(f,v) is intended to be used in "OR" and "AND" expressions: - * e.g., "((_SBF(5,7) | _SBF(12,0xF)) & 0xFFFF)" - */ -#undef _SBF -/* Set bit field macro */ -#define _SBF(f, v) ((v) << (f)) - -/* _BITMASK constructs a symbol with 'field_width' least significant - * bits set. - * e.g., _BITMASK(5) constructs '0x1F', _BITMASK(16) == 0xFFFF - * The symbol is intended to be used to limit the bit field width - * thusly: - * = (any_expression) & _BITMASK(x), where 0 < x <= 32. - * If "any_expression" results in a value that is larger than can be - * contained in 'x' bits, the bits above 'x - 1' are masked off. When - * used with the _SBF example above, the example would be written: - * a_reg = ((_SBF(5,7) | _SBF(12,0xF)) & _BITMASK(16)) - * This ensures that the value written to a_reg is no wider than - * 16 bits, and makes the code easier to read and understand. - */ -#undef _BITMASK -/* Bitmask creation macro */ -#define _BITMASK(field_width) ( _BIT(field_width) - 1) - -/* NULL pointer */ -#ifndef NULL -#define NULL ((void *) 0) -#endif - -/* Number of elements in an array */ -#define NELEMENTS(array) (sizeof(array) / sizeof(array[0])) - -/* Static data/function define */ -#define STATIC static -/* External data/function define */ -#define EXTERN extern - -#if !defined(MAX) -#define MAX(a, b) (((a) > (b)) ? (a) : (b)) -#endif -#if !defined(MIN) -#define MIN(a, b) (((a) < (b)) ? (a) : (b)) -#endif - -/** - * @} - */ - -/* Old Type Definition compatibility */ -/** @addtogroup LPC_Types_Public_Types - * @{ - */ - -/** LPC type for character type */ -typedef char CHAR; - -/** LPC type for 8 bit unsigned value */ -typedef uint8_t UNS_8; - -/** LPC type for 8 bit signed value */ -typedef int8_t INT_8; - -/** LPC type for 16 bit unsigned value */ -typedef uint16_t UNS_16; - -/** LPC type for 16 bit signed value */ -typedef int16_t INT_16; - -/** LPC type for 32 bit unsigned value */ -typedef uint32_t UNS_32; - -/** LPC type for 32 bit signed value */ -typedef int32_t INT_32; - -/** LPC type for 64 bit signed value */ -typedef int64_t INT_64; - -/** LPC type for 64 bit unsigned value */ -typedef uint64_t UNS_64; - -#ifdef __CODE_RED -#define BOOL_32 bool -#define BOOL_16 bool -#define BOOL_8 bool -#else -/** 32 bit boolean type */ -typedef bool BOOL_32; - -/** 16 bit boolean type */ -typedef bool BOOL_16; - -/** 8 bit boolean type */ -typedef bool BOOL_8; -#endif - -#ifdef __CC_ARM -#define INLINE __inline -#else -#define INLINE inline -#endif - -/** - * @} - */ - -/** - * @} - */ - -#endif /* __LPC_TYPES_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pinint_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pinint_11xx.h deleted file mode 100755 index 680fa8e622..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pinint_11xx.h +++ /dev/null @@ -1,257 +0,0 @@ -/* - * @brief LPC11xx Pin Interrupt and Pattern Match Registers and driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __PININT_11XX_H_ -#define __PININT_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup PININT_11XX CHIP: LPC11xx Pin Interrupt and Pattern Match driver - * @ingroup CHIP_11XX_Drivers - * For device familes identified with CHIP definitions CHIP_LPC11AXX, - * CHIP_LPC11EXX, and CHIP_LPC11UXX only. - * @{ - */ - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) - -/** - * @brief LPC11xx Pin Interrupt and Pattern Match register block structure - */ -typedef struct { /*!< PIN_INT Structure */ - __IO uint32_t ISEL; /*!< Pin Interrupt Mode register */ - __IO uint32_t IENR; /*!< Pin Interrupt Enable (Rising) register */ - __IO uint32_t SIENR; /*!< Set Pin Interrupt Enable (Rising) register */ - __IO uint32_t CIENR; /*!< Clear Pin Interrupt Enable (Rising) register */ - __IO uint32_t IENF; /*!< Pin Interrupt Enable Falling Edge / Active Level register */ - __IO uint32_t SIENF; /*!< Set Pin Interrupt Enable Falling Edge / Active Level register */ - __IO uint32_t CIENF; /*!< Clear Pin Interrupt Enable Falling Edge / Active Level address */ - __IO uint32_t RISE; /*!< Pin Interrupt Rising Edge register */ - __IO uint32_t FALL; /*!< Pin Interrupt Falling Edge register */ - __IO uint32_t IST; /*!< Pin Interrupt Status register */ -} LPC_PIN_INT_T; - -/** - * LPC11xx Pin Interrupt channel values - */ -#define PININTCH0 (1 << 0) -#define PININTCH1 (1 << 1) -#define PININTCH2 (1 << 2) -#define PININTCH3 (1 << 3) -#define PININTCH4 (1 << 4) -#define PININTCH5 (1 << 5) -#define PININTCH6 (1 << 6) -#define PININTCH7 (1 << 7) -#define PININTCH(ch) (1 << (ch)) - -/** - * @brief Initialize Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @return Nothing - * @note This function should be used after the Chip_GPIO_Init() function. - */ -STATIC INLINE void Chip_PININT_Init(LPC_PIN_INT_T *pPININT) {} - -/** - * @brief De-Initialize Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @return Nothing - */ -STATIC INLINE void Chip_PININT_DeInit(LPC_PIN_INT_T *pPININT) {} - -/** - * @brief Configure the pins as edge sensitive in Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_SetPinModeEdge(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->ISEL &= ~pins; -} - -/** - * @brief Configure the pins as level sensitive in Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_SetPinModeLevel(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->ISEL |= pins; -} - -/** - * @brief Return current PININT rising edge or high level interrupt enable state - * @param pPININT : The base address of Pin interrupt block - * @return A bifield containing the high edge/level interrupt enables for each - * interrupt. Bit 0 = PININT0, 1 = PININT1, etc. - * For each bit, a 0 means the high edge/level interrupt is disabled, while a 1 - * means it's enabled. - */ -STATIC INLINE uint32_t Chip_PININT_GetHighEnabled(LPC_PIN_INT_T *pPININT) -{ - return pPININT->IENR; -} - -/** - * @brief Enable high edge/level PININT interrupts for pins - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins to enable (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_EnableIntHigh(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->SIENR = pins; -} - -/** - * @brief Disable high edge/level PININT interrupts for pins - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins to disable (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_DisableIntHigh(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->CIENR = pins; -} - -/** - * @brief Return current PININT falling edge or low level interrupt enable state - * @param pPININT : The base address of Pin interrupt block - * @return A bifield containing the low edge/level interrupt enables for each - * interrupt. Bit 0 = PININT0, 1 = PININT1, etc. - * For each bit, a 0 means the low edge/level interrupt is disabled, while a 1 - * means it's enabled. - */ -STATIC INLINE uint32_t Chip_PININT_GetLowEnabled(LPC_PIN_INT_T *pPININT) -{ - return pPININT->IENF; -} - -/** - * @brief Enable low edge/level PININT interrupts for pins - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins to enable (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_EnableIntLow(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->SIENF = pins; -} - -/** - * @brief Disable low edge/level PININT interrupts for pins - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins to disable (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_DisableIntLow(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->CIENF = pins; -} - -/** - * @brief Return pin states that have a detected latched high edge (RISE) state - * @param pPININT : The base address of Pin interrupt block - * @return PININT states (bit n = high) with a latched rise state detected - */ -STATIC INLINE uint32_t Chip_PININT_GetRiseStates(LPC_PIN_INT_T *pPININT) -{ - return pPININT->RISE; -} - -/** - * @brief Clears pin states that had a latched high edge (RISE) state - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins with latched states to clear - * @return Nothing - */ -STATIC INLINE void Chip_PININT_ClearRiseStates(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->RISE = pins; -} - -/** - * @brief Return pin states that have a detected latched falling edge (FALL) state - * @param pPININT : The base address of Pin interrupt block - * @return PININT states (bit n = high) with a latched rise state detected - */ -STATIC INLINE uint32_t Chip_PININT_GetFallStates(LPC_PIN_INT_T *pPININT) -{ - return pPININT->FALL; -} - -/** - * @brief Clears pin states that had a latched falling edge (FALL) state - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pins with latched states to clear - * @return Nothing - */ -STATIC INLINE void Chip_PININT_ClearFallStates(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->FALL = pins; -} - -/** - * @brief Get interrupt status from Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @return Interrupt status (bit n for PININTn = high means interrupt ie pending) - */ -STATIC INLINE uint32_t Chip_PININT_GetIntStatus(LPC_PIN_INT_T *pPININT) -{ - return pPININT->IST; -} - -/** - * @brief Clear interrupt status in Pin interrupt block - * @param pPININT : The base address of Pin interrupt block - * @param pins : Pin interrupts to clear (ORed value of PININTCH*) - * @return Nothing - */ -STATIC INLINE void Chip_PININT_ClearIntStatus(LPC_PIN_INT_T *pPININT, uint32_t pins) -{ - pPININT->IST = pins; -} - -#endif /* defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __PININT_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pmu_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pmu_11xx.h deleted file mode 100755 index d08d8a5e29..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/pmu_11xx.h +++ /dev/null @@ -1,201 +0,0 @@ -/* - * @brief LPC11xx PMU chip driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __PMU_11XX_H_ -#define __PMU_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup PMU_11XX CHIP: LPC11xx Power Management Unit block driver - * @ingroup CHIP_11XX_Drivers - * This driver only applies to devices in the CHIP_LPC11AXX, CHIP_LPC11CXX, - * CHIP_LPC11EXX, CHIP_LPC11UXX, and CHIP_LPC1125 families. Note different - * families may have slightly different PMU support. - * @{ - */ - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC1125) -#if defined(CHIP_LPC1125) -#error "LPC1125 support for the PMU driver is not ready" -#endif - -/** - * @brief LPC11xx Power Management Unit register block structure - */ -typedef struct { - __IO uint32_t PCON; /*!< Offset: 0x000 Power control Register (R/W) */ - __IO uint32_t GPREG[4]; /*!< Offset: 0x004 General purpose Registers 0..3 (R/W) */ -} LPC_PMU_T; - -/** - * @brief LPC11xx low power mode type definitions - */ -typedef enum CHIP_PMU_MCUPOWER { - PMU_MCU_SLEEP = 0, /*!< Sleep mode */ -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) - PMU_MCU_DEEP_SLEEP, /*!< Deep Sleep mode */ - PMU_MCU_POWER_DOWN, /*!< Power down mode */ - PMU_MCU_DEEP_PWRDOWN /*!< Deep power down mode */ -#elif defined(CHIP_LPC11CXX) - PMU_MCU_DEEP_PWRDOWN = 3 /*!< Deep power down mode */ -#endif -} CHIP_PMU_MCUPOWER_T; - -/** - * PMU PCON register bit fields & masks - */ -#define PMU_PCON_PM_SLEEP (0x0) /*!< ARM WFI enter sleep mode */ -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) -#define PMU_PCON_PM_DEEPSLEEP (0x1) /*!< ARM WFI enter Deep-sleep mode */ -#define PMU_PCON_PM_POWERDOWN (0x2) /*!< ARM WFI enter Power-down mode */ -#define PMU_PCON_PM_DEEPPOWERDOWN (0x3) /*!< ARM WFI enter Deep Power-down mode */ -#elif defined(CHIP_LPC11CXX) -#define PMU_PCON_PM_DEEPPOWERDOWN (0x2) -#endif -#define PMU_PCON_SLEEPFLAG (1 << 8) /*!< Sleep mode flag */ -#define PMU_PCON_DPDFLAG (1 << 11) /*!< Deep power-down flag */ - -/** - * @brief Write a value to a GPREG register - * @param pPMU : Pointer to PMU register block - * @param regIndex : Register index to write to, must be 0..3 - * @param value : Value to write - * @return None - */ -STATIC INLINE void Chip_PMU_WriteGPREG(LPC_PMU_T *pPMU, uint8_t regIndex, uint32_t value) -{ - pPMU->GPREG[regIndex] = value; -} - -/** - * @brief Read a value to a GPREG register - * @param pPMU : Pointer to PMU register block - * @param regIndex : Register index to read from, must be 0..3 - * @return Value read from the GPREG register - */ -STATIC INLINE uint32_t Chip_PMU_ReadGPREG(LPC_PMU_T *pPMU, uint8_t regIndex) -{ - return pPMU->GPREG[regIndex]; -} - -/** - * @brief Enter MCU Sleep mode - * @param pPMU : Pointer to PMU register block - * @return None - * @note The sleep mode affects the ARM Cortex-M0+ core only. Peripherals - * and memories are active. - */ -void Chip_PMU_SleepState(LPC_PMU_T *pPMU); - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) -/** - * @brief Enter MCU Deep Sleep mode - * @param pPMU : Pointer to PMU register block - * @return None - * @note In Deep-sleep mode, the peripherals receive no internal clocks. - * The flash is in stand-by mode. The SRAM memory and all peripheral registers - * as well as the processor maintain their internal states. The WWDT, WKT, - * and BOD can remain active to wake up the system on an interrupt. - */ -void Chip_PMU_DeepSleepState(LPC_PMU_T *pPMU); - -/** - * @brief Enter MCU Power down mode - * @param pPMU : Pointer to PMU register block - * @return None - * @note In Power-down mode, the peripherals receive no internal clocks. - * The internal SRAM memory and all peripheral registers as well as the - * processor maintain their internal states. The flash memory is powered - * down. The WWDT, WKT, and BOD can remain active to wake up the system - * on an interrupt. - */ -void Chip_PMU_PowerDownState(LPC_PMU_T *pPMU); -#endif - -/** - * @brief Enter MCU Deep Power down mode - * @param pPMU : Pointer to PMU register block - * @return None - * @note For maximal power savings, the entire system is shut down - * except for the general purpose registers in the PMU and the self - * wake-up timer. Only the general purpose registers in the PMU maintain - * their internal states. The part can wake up on a pulse on the WAKEUP - * pin or when the self wake-up timer times out. On wake-up, the part - * reboots. - */ -void Chip_PMU_DeepPowerDownState(LPC_PMU_T *pPMU); - -/** - * @brief Place the MCU in a low power state - * @param pPMU : Pointer to PMU register block - * @param SleepMode : Sleep mode - * @return None - */ -void Chip_PMU_Sleep(LPC_PMU_T *pPMU, CHIP_PMU_MCUPOWER_T SleepMode); - -/** - * @brief Returns sleep/power-down flags - * @param pPMU : Pointer to PMU register block - * @return Or'ed values of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG - * @note These indicate that the PMU is setup for entry into a low - * power state on the next WFI() instruction. - */ -STATIC INLINE uint32_t Chip_PMU_GetSleepFlags(LPC_PMU_T *pPMU) -{ - return (pPMU->PCON & (PMU_PCON_SLEEPFLAG | PMU_PCON_DPDFLAG)); -} - -/** - * @brief Clears sleep/power-down flags - * @param pPMU : Pointer to PMU register block - * @param flags : Or'ed value of PMU_PCON_SLEEPFLAG and PMU_PCON_DPDFLAG - * @return Nothing - * @note Use this function to clear a low power state prior to calling - * WFI(). - */ -STATIC INLINE void Chip_PMU_ClearSleepFlags(LPC_PMU_T *pPMU, uint32_t flags) -{ - pPMU->PCON &= ~flags; -} - -#endif /* defined(CHIP_LPC11AXX) || defined(CHIP_LPC11CXX) || ... */ - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __PMU_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ring_buffer.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ring_buffer.h deleted file mode 100755 index 30412d9c2f..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ring_buffer.h +++ /dev/null @@ -1,188 +0,0 @@ -/* - * @brief Common ring buffer support functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __RING_BUFFER_H_ -#define __RING_BUFFER_H_ - -#include "lpc_types.h" - -/** @defgroup Ring_Buffer CHIP: Simple ring buffer implementation - * @ingroup CHIP_Common - * @{ - */ - -/** - * @brief Ring buffer structure - */ -typedef struct { - void *data; - int count; - int itemSz; - uint32_t head; - uint32_t tail; -} RINGBUFF_T; - -/** - * @def RB_VHEAD(rb) - * volatile typecasted head index - */ -#define RB_VHEAD(rb) (*(volatile uint32_t *) &(rb)->head) - -/** - * @def RB_VTAIL(rb) - * volatile typecasted tail index - */ -#define RB_VTAIL(rb) (*(volatile uint32_t *) &(rb)->tail) - -/** - * @brief Initialize ring buffer - * @param RingBuff : Pointer to ring buffer to initialize - * @param buffer : Pointer to buffer to associate with RingBuff - * @param itemSize : Size of each buffer item size - * @param count : Size of ring buffer - * @note Memory pointed by @a buffer must have correct alignment of - * @a itemSize, and @a count must be a power of 2 and must at - * least be 2 or greater. - * @return Nothing - */ -int RingBuffer_Init(RINGBUFF_T *RingBuff, void *buffer, int itemSize, int count); - -/** - * @brief Resets the ring buffer to empty - * @param RingBuff : Pointer to ring buffer - * @return Nothing - */ -STATIC INLINE void RingBuffer_Flush(RINGBUFF_T *RingBuff) -{ - RingBuff->head = RingBuff->tail = 0; -} - -/** - * @brief Return size the ring buffer - * @param RingBuff : Pointer to ring buffer - * @return Size of the ring buffer in bytes - */ -STATIC INLINE int RingBuffer_GetSize(RINGBUFF_T *RingBuff) -{ - return RingBuff->count; -} - -/** - * @brief Return number of items in the ring buffer - * @param RingBuff : Pointer to ring buffer - * @return Number of items in the ring buffer - */ -STATIC INLINE int RingBuffer_GetCount(RINGBUFF_T *RingBuff) -{ - return RB_VHEAD(RingBuff) - RB_VTAIL(RingBuff); -} - -/** - * @brief Return number of free items in the ring buffer - * @param RingBuff : Pointer to ring buffer - * @return Number of free items in the ring buffer - */ -STATIC INLINE int RingBuffer_GetFree(RINGBUFF_T *RingBuff) -{ - return RingBuff->count - RingBuffer_GetCount(RingBuff); -} - -/** - * @brief Return number of items in the ring buffer - * @param RingBuff : Pointer to ring buffer - * @return 1 if the ring buffer is full, otherwise 0 - */ -STATIC INLINE int RingBuffer_IsFull(RINGBUFF_T *RingBuff) -{ - return (RingBuffer_GetCount(RingBuff) >= RingBuff->count); -} - -/** - * @brief Return empty status of ring buffer - * @param RingBuff : Pointer to ring buffer - * @return 1 if the ring buffer is empty, otherwise 0 - */ -STATIC INLINE int RingBuffer_IsEmpty(RINGBUFF_T *RingBuff) -{ - return RB_VHEAD(RingBuff) == RB_VTAIL(RingBuff); -} - -/** - * @brief Insert a single item into ring buffer - * @param RingBuff : Pointer to ring buffer - * @param data : pointer to item - * @return 1 when successfully inserted, - * 0 on error (Buffer not initialized using - * RingBuffer_Init() or attempted to insert - * when buffer is full) - */ -int RingBuffer_Insert(RINGBUFF_T *RingBuff, const void *data); - -/** - * @brief Insert an array of items into ring buffer - * @param RingBuff : Pointer to ring buffer - * @param data : Pointer to first element of the item array - * @param num : Number of items in the array - * @return number of items successfully inserted, - * 0 on error (Buffer not initialized using - * RingBuffer_Init() or attempted to insert - * when buffer is full) - */ -int RingBuffer_InsertMult(RINGBUFF_T *RingBuff, const void *data, int num); - -/** - * @brief Pop an item from the ring buffer - * @param RingBuff : Pointer to ring buffer - * @param data : Pointer to memory where popped item be stored - * @return 1 when item popped successfuly onto @a data, - * 0 When error (Buffer not initialized using - * RingBuffer_Init() or attempted to pop item when - * the buffer is empty) - */ -int RingBuffer_Pop(RINGBUFF_T *RingBuff, void *data); - -/** - * @brief Pop an array of items from the ring buffer - * @param RingBuff : Pointer to ring buffer - * @param data : Pointer to memory where popped items be stored - * @param num : Max number of items array @a data can hold - * @return Number of items popped onto @a data, - * 0 on error (Buffer not initialized using RingBuffer_Init() - * or attempted to pop when the buffer is empty) - */ -int RingBuffer_PopMult(RINGBUFF_T *RingBuff, void *data, int num); - - -/** - * @} - */ - -#endif /* __RING_BUFFER_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/romapi_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/romapi_11xx.h deleted file mode 100755 index 2ca6cc485b..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/romapi_11xx.h +++ /dev/null @@ -1,78 +0,0 @@ -/* - * @brief LPC11xx ROM API declarations and functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __ROMAPI_11XX_H_ -#define __ROMAPI_11XX_H_ - -#include "error.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup ROMAPI_11XX CHIP: LPC11XX ROM API declarations and functions - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief LPC11XX High level ROM API structure - */ -typedef struct { - const uint32_t usbdApiBase; /*!< USBD API function table base address */ - const uint32_t reserved0; /*!< Reserved */ - const uint32_t candApiBase; /*!< CAN API function table base address */ - const uint32_t pwrApiBase; /*!< Power API function table base address */ - const uint32_t reserved1; /*!< Reserved */ - const uint32_t reserved2; /*!< Reserved */ - const uint32_t reserved3; /*!< Reserved */ - const uint32_t reserved4; /*!< Reserved */ -} LPC_ROM_API_T; - -/** - * @brief LPC11XX IAP_ENTRY API function type - */ -typedef void (*IAP_ENTRY_T)(unsigned int[], unsigned int[]); - -static INLINE void iap_entry(unsigned int cmd_param[], unsigned int status_result[]) -{ - ((IAP_ENTRY_T) IAP_ENTRY_LOCATION)(cmd_param, status_result); -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __ROMAPI_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ssp_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ssp_11xx.h deleted file mode 100755 index 4fe1181f9c..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/ssp_11xx.h +++ /dev/null @@ -1,571 +0,0 @@ -/* - * @brief LPC11xx SSP Registers and control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __SSP_11XX_H_ -#define __SSP_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup SSP_11XX CHIP: LPC11xx SSP register block and driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief SSP register block structure - */ -typedef struct { /*!< SSPn Structure */ - __IO uint32_t CR0; /*!< Control Register 0. Selects the serial clock rate, bus type, and data size. */ - __IO uint32_t CR1; /*!< Control Register 1. Selects master/slave and other modes. */ - __IO uint32_t DR; /*!< Data Register. Writes fill the transmit FIFO, and reads empty the receive FIFO. */ - __I uint32_t SR; /*!< Status Register */ - __IO uint32_t CPSR; /*!< Clock Prescale Register */ - __IO uint32_t IMSC; /*!< Interrupt Mask Set and Clear Register */ - __I uint32_t RIS; /*!< Raw Interrupt Status Register */ - __I uint32_t MIS; /*!< Masked Interrupt Status Register */ - __O uint32_t ICR; /*!< SSPICR Interrupt Clear Register */ -} LPC_SSP_T; - -/** - * Macro defines for CR0 register - */ - -/** SSP data size select, must be 4 bits to 16 bits */ -#define SSP_CR0_DSS(n) ((uint32_t) ((n) & 0xF)) -/** SSP control 0 Motorola SPI mode */ -#define SSP_CR0_FRF_SPI ((uint32_t) (0 << 4)) -/** SSP control 0 TI synchronous serial mode */ -#define SSP_CR0_FRF_TI ((uint32_t) (1 << 4)) -/** SSP control 0 National Micro-wire mode */ -#define SSP_CR0_FRF_MICROWIRE ((uint32_t) (2 << 4)) -/** SPI clock polarity bit (used in SPI mode only), (1) = maintains the - bus clock high between frames, (0) = low */ -#define SSP_CR0_CPOL_LO ((uint32_t) (0)) -#define SSP_CR0_CPOL_HI ((uint32_t) (1 << 6)) -/** SPI clock out phase bit (used in SPI mode only), (1) = captures data - on the second clock transition of the frame, (0) = first */ -#define SSP_CR0_CPHA_FIRST ((uint32_t) (0)) -#define SSP_CR0_CPHA_SECOND ((uint32_t) (1 << 7)) -/** SSP serial clock rate value load macro, divider rate is - PERIPH_CLK / (cpsr * (SCR + 1)) */ -#define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8)) -/** SSP CR0 bit mask */ -#define SSP_CR0_BITMASK ((uint32_t) (0xFFFF)) -/** SSP CR0 bit mask */ -#define SSP_CR0_BITMASK ((uint32_t) (0xFFFF)) -/** SSP serial clock rate value load macro, divider rate is - PERIPH_CLK / (cpsr * (SCR + 1)) */ -#define SSP_CR0_SCR(n) ((uint32_t) ((n & 0xFF) << 8)) - -/** - * Macro defines for CR1 register - */ - -/** SSP control 1 loopback mode enable bit */ -#define SSP_CR1_LBM_EN ((uint32_t) (1 << 0)) -/** SSP control 1 enable bit */ -#define SSP_CR1_SSP_EN ((uint32_t) (1 << 1)) -/** SSP control 1 slave enable */ -#define SSP_CR1_SLAVE_EN ((uint32_t) (1 << 2)) -#define SSP_CR1_MASTER_EN ((uint32_t) (0)) -/** SSP control 1 slave out disable bit, disables transmit line in slave - mode */ -#define SSP_CR1_SO_DISABLE ((uint32_t) (1 << 3)) -/** SSP CR1 bit mask */ -#define SSP_CR1_BITMASK ((uint32_t) (0x0F)) - -/** SSP CPSR bit mask */ -#define SSP_CPSR_BITMASK ((uint32_t) (0xFF)) -/** - * Macro defines for DR register - */ - -/** SSP data bit mask */ -#define SSP_DR_BITMASK(n) ((n) & 0xFFFF) - -/** - * Macro defines for SR register - */ - -/** SSP SR bit mask */ -#define SSP_SR_BITMASK ((uint32_t) (0x1F)) - -/** ICR bit mask */ -#define SSP_ICR_BITMASK ((uint32_t) (0x03)) - -/** - * @brief SSP Type of Status - */ -typedef enum _SSP_STATUS { - SSP_STAT_TFE = ((uint32_t)(1 << 0)),/**< TX FIFO Empty */ - SSP_STAT_TNF = ((uint32_t)(1 << 1)),/**< TX FIFO not full */ - SSP_STAT_RNE = ((uint32_t)(1 << 2)),/**< RX FIFO not empty */ - SSP_STAT_RFF = ((uint32_t)(1 << 3)),/**< RX FIFO full */ - SSP_STAT_BSY = ((uint32_t)(1 << 4)),/**< SSP Busy */ -} SSP_STATUS_T; - -/** - * @brief SSP Type of Interrupt Mask - */ -typedef enum _SSP_INTMASK { - SSP_RORIM = ((uint32_t)(1 << 0)), /**< Overun */ - SSP_RTIM = ((uint32_t)(1 << 1)),/**< TimeOut */ - SSP_RXIM = ((uint32_t)(1 << 2)),/**< Rx FIFO is at least half full */ - SSP_TXIM = ((uint32_t)(1 << 3)),/**< Tx FIFO is at least half empty */ - SSP_INT_MASK_BITMASK = ((uint32_t)(0xF)), -} SSP_INTMASK_T; - -/** - * @brief SSP Type of Mask Interrupt Status - */ -typedef enum _SSP_MASKINTSTATUS { - SSP_RORMIS = ((uint32_t)(1 << 0)), /**< Overun */ - SSP_RTMIS = ((uint32_t)(1 << 1)), /**< TimeOut */ - SSP_RXMIS = ((uint32_t)(1 << 2)), /**< Rx FIFO is at least half full */ - SSP_TXMIS = ((uint32_t)(1 << 3)), /**< Tx FIFO is at least half empty */ - SSP_MASK_INT_STAT_BITMASK = ((uint32_t)(0xF)), -} SSP_MASKINTSTATUS_T; - -/** - * @brief SSP Type of Raw Interrupt Status - */ -typedef enum _SSP_RAWINTSTATUS { - SSP_RORRIS = ((uint32_t)(1 << 0)), /**< Overun */ - SSP_RTRIS = ((uint32_t)(1 << 1)), /**< TimeOut */ - SSP_RXRIS = ((uint32_t)(1 << 2)), /**< Rx FIFO is at least half full */ - SSP_TXRIS = ((uint32_t)(1 << 3)), /**< Tx FIFO is at least half empty */ - SSP_RAW_INT_STAT_BITMASK = ((uint32_t)(0xF)), -} SSP_RAWINTSTATUS_T; - -typedef enum _SSP_INTCLEAR { - SSP_RORIC = 0x0, - SSP_RTIC = 0x1, - SSP_INT_CLEAR_BITMASK = 0x3, -} SSP_INTCLEAR_T; - -/* - * @brief SSP clock format - */ -typedef enum CHIP_SSP_CLOCK_FORMAT { - SSP_CLOCK_CPHA0_CPOL0 = (0 << 6), /**< CPHA = 0, CPOL = 0 */ - SSP_CLOCK_CPHA0_CPOL1 = (1u << 6), /**< CPHA = 0, CPOL = 1 */ - SSP_CLOCK_CPHA1_CPOL0 = (2u << 6), /**< CPHA = 1, CPOL = 0 */ - SSP_CLOCK_CPHA1_CPOL1 = (3u << 6), /**< CPHA = 1, CPOL = 1 */ - SSP_CLOCK_MODE0 = SSP_CLOCK_CPHA0_CPOL0,/**< alias */ - SSP_CLOCK_MODE1 = SSP_CLOCK_CPHA1_CPOL0,/**< alias */ - SSP_CLOCK_MODE2 = SSP_CLOCK_CPHA0_CPOL1,/**< alias */ - SSP_CLOCK_MODE3 = SSP_CLOCK_CPHA1_CPOL1,/**< alias */ -} CHIP_SSP_CLOCK_MODE_T; - -/* - * @brief SSP frame format - */ -typedef enum CHIP_SSP_FRAME_FORMAT { - SSP_FRAMEFORMAT_SPI = (0 << 4), /**< Frame format: SPI */ - CHIP_SSP_FRAME_FORMAT_TI = (1u << 4), /**< Frame format: TI SSI */ - SSP_FRAMEFORMAT_MICROWIRE = (2u << 4), /**< Frame format: Microwire */ -} CHIP_SSP_FRAME_FORMAT_T; - -/* - * @brief Number of bits per frame - */ -typedef enum CHIP_SSP_BITS { - SSP_BITS_4 = (3u << 0), /*!< 4 bits/frame */ - SSP_BITS_5 = (4u << 0), /*!< 5 bits/frame */ - SSP_BITS_6 = (5u << 0), /*!< 6 bits/frame */ - SSP_BITS_7 = (6u << 0), /*!< 7 bits/frame */ - SSP_BITS_8 = (7u << 0), /*!< 8 bits/frame */ - SSP_BITS_9 = (8u << 0), /*!< 9 bits/frame */ - SSP_BITS_10 = (9u << 0), /*!< 10 bits/frame */ - SSP_BITS_11 = (10u << 0), /*!< 11 bits/frame */ - SSP_BITS_12 = (11u << 0), /*!< 12 bits/frame */ - SSP_BITS_13 = (12u << 0), /*!< 13 bits/frame */ - SSP_BITS_14 = (13u << 0), /*!< 14 bits/frame */ - SSP_BITS_15 = (14u << 0), /*!< 15 bits/frame */ - SSP_BITS_16 = (15u << 0), /*!< 16 bits/frame */ -} CHIP_SSP_BITS_T; - -/* - * @brief SSP config format - */ -typedef struct SSP_ConfigFormat { - CHIP_SSP_BITS_T bits; /*!< Format config: bits/frame */ - CHIP_SSP_CLOCK_MODE_T clockMode; /*!< Format config: clock phase/polarity */ - CHIP_SSP_FRAME_FORMAT_T frameFormat; /*!< Format config: SPI/TI/Microwire */ -} SSP_ConfigFormat; - -/** - * @brief Enable SSP operation - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - */ -STATIC INLINE void Chip_SSP_Enable(LPC_SSP_T *pSSP) -{ - pSSP->CR1 |= SSP_CR1_SSP_EN; -} - -/** - * @brief Disable SSP operation - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - */ -STATIC INLINE void Chip_SSP_Disable(LPC_SSP_T *pSSP) -{ - pSSP->CR1 &= (~SSP_CR1_SSP_EN) & SSP_CR1_BITMASK; -} - -/** - * @brief Enable loopback mode - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - * @note Serial input is taken from the serial output (MOSI or MISO) rather - * than the serial input pin - */ -STATIC INLINE void Chip_SSP_EnableLoopBack(LPC_SSP_T *pSSP) -{ - pSSP->CR1 |= SSP_CR1_LBM_EN; -} - -/** - * @brief Disable loopback mode - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - * @note Serial input is taken from the serial output (MOSI or MISO) rather - * than the serial input pin - */ -STATIC INLINE void Chip_SSP_DisableLoopBack(LPC_SSP_T *pSSP) -{ - pSSP->CR1 &= (~SSP_CR1_LBM_EN) & SSP_CR1_BITMASK; -} - -/** - * @brief Get the current status of SSP controller - * @param pSSP : The base of SSP peripheral on the chip - * @param Stat : Type of status, should be : - * - SSP_STAT_TFE - * - SSP_STAT_TNF - * - SSP_STAT_RNE - * - SSP_STAT_RFF - * - SSP_STAT_BSY - * @return SSP controller status, SET or RESET - */ -STATIC INLINE FlagStatus Chip_SSP_GetStatus(LPC_SSP_T *pSSP, SSP_STATUS_T Stat) -{ - return (pSSP->SR & Stat) ? SET : RESET; -} - -/** - * @brief Get the masked interrupt status - * @param pSSP : The base of SSP peripheral on the chip - * @return SSP Masked Interrupt Status Register value - * @note The return value contains a 1 for each interrupt condition that is asserted and enabled (masked) - */ -STATIC INLINE uint32_t Chip_SSP_GetIntStatus(LPC_SSP_T *pSSP) -{ - return pSSP->MIS; -} - -/** - * @brief Get the raw interrupt status - * @param pSSP : The base of SSP peripheral on the chip - * @param RawInt : Interrupt condition to be get status, shoud be : - * - SSP_RORRIS - * - SSP_RTRIS - * - SSP_RXRIS - * - SSP_TXRIS - * @return Raw interrupt status corresponding to interrupt condition , SET or RESET - * @note Get the status of each interrupt condition ,regardless of whether or not the interrupt is enabled - */ -STATIC INLINE IntStatus Chip_SSP_GetRawIntStatus(LPC_SSP_T *pSSP, SSP_RAWINTSTATUS_T RawInt) -{ - return (pSSP->RIS & RawInt) ? SET : RESET; -} - -/** - * @brief Get the number of bits transferred in each frame - * @param pSSP : The base of SSP peripheral on the chip - * @return the number of bits transferred in each frame minus one - * @note The return value is 0x03 -> 0xF corresponding to 4bit -> 16bit transfer - */ -STATIC INLINE uint8_t Chip_SSP_GetDataSize(LPC_SSP_T *pSSP) -{ - return SSP_CR0_DSS(pSSP->CR0); -} - -/** - * @brief Clear the corresponding interrupt condition(s) in the SSP controller - * @param pSSP : The base of SSP peripheral on the chip - * @param IntClear: Type of cleared interrupt, should be : - * - SSP_RORIC - * - SSP_RTIC - * @return Nothing - * @note Software can clear one or more interrupt condition(s) in the SSP controller - */ -STATIC INLINE void Chip_SSP_ClearIntPending(LPC_SSP_T *pSSP, SSP_INTCLEAR_T IntClear) -{ - pSSP->ICR = IntClear; -} - -/** - * @brief Enable interrupt for the SSP - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - */ -STATIC INLINE void Chip_SSP_Int_Enable(LPC_SSP_T *pSSP) -{ - pSSP->IMSC |= SSP_TXIM; -} - -/** - * @brief Disable interrupt for the SSP - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - */ -STATIC INLINE void Chip_SSP_Int_Disable(LPC_SSP_T *pSSP) -{ - pSSP->IMSC &= (~SSP_TXIM); -} - -/** - * @brief Get received SSP data - * @param pSSP : The base of SSP peripheral on the chip - * @return SSP 16-bit data received - */ -STATIC INLINE uint16_t Chip_SSP_ReceiveFrame(LPC_SSP_T *pSSP) -{ - return (uint16_t) (SSP_DR_BITMASK(pSSP->DR)); -} - -/** - * @brief Send SSP 16-bit data - * @param pSSP : The base of SSP peripheral on the chip - * @param tx_data : SSP 16-bit data to be transmited - * @return Nothing - */ -STATIC INLINE void Chip_SSP_SendFrame(LPC_SSP_T *pSSP, uint16_t tx_data) -{ - pSSP->DR = SSP_DR_BITMASK(tx_data); -} - -/** - * @brief Set up output clocks per bit for SSP bus - * @param pSSP : The base of SSP peripheral on the chip - * @param clk_rate fs: The number of prescaler-output clocks per bit on the bus, minus one - * @param prescale : The factor by which the Prescaler divides the SSP peripheral clock PCLK - * @return Nothing - * @note The bit frequency is PCLK / (prescale x[clk_rate+1]) - */ -void Chip_SSP_SetClockRate(LPC_SSP_T *pSSP, uint32_t clk_rate, uint32_t prescale); - -/** - * @brief Set up the SSP frame format - * @param pSSP : The base of SSP peripheral on the chip - * @param bits : The number of bits transferred in each frame, should be SSP_BITS_4 to SSP_BITS_16 - * @param frameFormat : Frame format, should be : - * - SSP_FRAMEFORMAT_SPI - * - SSP_FRAME_FORMAT_TI - * - SSP_FRAMEFORMAT_MICROWIRE - * @param clockMode : Select Clock polarity and Clock phase, should be : - * - SSP_CLOCK_CPHA0_CPOL0 - * - SSP_CLOCK_CPHA0_CPOL1 - * - SSP_CLOCK_CPHA1_CPOL0 - * - SSP_CLOCK_CPHA1_CPOL1 - * @return Nothing - * @note Note: The clockFormat is only used in SPI mode - */ -STATIC INLINE void Chip_SSP_SetFormat(LPC_SSP_T *pSSP, uint32_t bits, uint32_t frameFormat, uint32_t clockMode) -{ - pSSP->CR0 = (pSSP->CR0 & ~0xFF) | bits | frameFormat | clockMode; -} - -/** - * @brief Set the SSP working as master or slave mode - * @param pSSP : The base of SSP peripheral on the chip - * @param mode : Operating mode, should be - * - SSP_MODE_MASTER - * - SSP_MODE_SLAVE - * @return Nothing - */ -STATIC INLINE void Chip_SSP_Set_Mode(LPC_SSP_T *pSSP, uint32_t mode) -{ - pSSP->CR1 = (pSSP->CR1 & ~(1 << 2)) | mode; -} - -/* - * @brief SSP mode - */ -typedef enum CHIP_SSP_MODE { - SSP_MODE_MASTER = (0 << 2), /**< Master mode */ - SSP_MODE_SLAVE = (1u << 2), /**< Slave mode */ -} CHIP_SSP_MODE_T; - -/* - * @brief SPI address - */ -typedef struct { - uint8_t port; /*!< Port Number */ - uint8_t pin; /*!< Pin number */ -} SPI_Address_t; - -/* - * @brief SSP data setup structure - */ -typedef struct { - void *tx_data; /*!< Pointer to transmit data */ - uint32_t tx_cnt; /*!< Transmit counter */ - void *rx_data; /*!< Pointer to transmit data */ - uint32_t rx_cnt; /*!< Receive counter */ - uint32_t length; /*!< Length of transfer data */ -} Chip_SSP_DATA_SETUP_T; - -/** SSP configuration parameter defines */ -/** Clock phase control bit */ -#define SSP_CPHA_FIRST SSP_CR0_CPHA_FIRST -#define SSP_CPHA_SECOND SSP_CR0_CPHA_SECOND - -/** Clock polarity control bit */ -/* There's no bug here!!! - * - If bit[6] in SSPnCR0 is 0: SSP controller maintains the bus clock low between frames. - * That means the active clock is in HI state. - * - If bit[6] in SSPnCR0 is 1 (SSP_CR0_CPOL_HI): SSP controller maintains the bus clock - * high between frames. That means the active clock is in LO state. - */ -#define SSP_CPOL_HI SSP_CR0_CPOL_LO -#define SSP_CPOL_LO SSP_CR0_CPOL_HI - -/** SSP master mode enable */ -#define SSP_SLAVE_MODE SSP_CR1_SLAVE_EN -#define SSP_MASTER_MODE SSP_CR1_MASTER_EN - -/** - * @brief Clean all data in RX FIFO of SSP - * @param pSSP : The base SSP peripheral on the chip - * @return Nothing - */ -void Chip_SSP_Int_FlushData(LPC_SSP_T *pSSP); - -/** - * @brief SSP Interrupt Read/Write with 8-bit frame width - * @param pSSP : The base SSP peripheral on the chip - * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified - * information about transmit/receive data configuration - * @return SUCCESS or ERROR - */ -Status Chip_SSP_Int_RWFrames8Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup); - -/** - * @brief SSP Interrupt Read/Write with 16-bit frame width - * @param pSSP : The base SSP peripheral on the chip - * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified - * information about transmit/receive data configuration - * @return SUCCESS or ERROR - */ -Status Chip_SSP_Int_RWFrames16Bits(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup); - -/** - * @brief SSP Polling Read/Write in blocking mode - * @param pSSP : The base SSP peripheral on the chip - * @param xf_setup : Pointer to a SSP_DATA_SETUP_T structure that contains specified - * information about transmit/receive data configuration - * @return Actual data length has been transferred - * @note - * This function can be used in both master and slave mode. It starts with writing phase and after that, - * a reading phase is generated to read any data available in RX_FIFO. All needed information is prepared - * through xf_setup param. - */ -uint32_t Chip_SSP_RWFrames_Blocking(LPC_SSP_T *pSSP, Chip_SSP_DATA_SETUP_T *xf_setup); - -/** - * @brief SSP Polling Write in blocking mode - * @param pSSP : The base SSP peripheral on the chip - * @param buffer : Buffer address - * @param buffer_len : Buffer length - * @return Actual data length has been transferred - * @note - * This function can be used in both master and slave mode. First, a writing operation will send - * the needed data. After that, a dummy reading operation is generated to clear data buffer - */ -uint32_t Chip_SSP_WriteFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len); - -/** - * @brief SSP Polling Read in blocking mode - * @param pSSP : The base SSP peripheral on the chip - * @param buffer : Buffer address - * @param buffer_len : The length of buffer - * @return Actual data length has been transferred - * @note - * This function can be used in both master and slave mode. First, a dummy writing operation is generated - * to clear data buffer. After that, a reading operation will receive the needed data - */ -uint32_t Chip_SSP_ReadFrames_Blocking(LPC_SSP_T *pSSP, uint8_t *buffer, uint32_t buffer_len); - -/** - * @brief Initialize the SSP - * @param pSSP : The base SSP peripheral on the chip - * @return Nothing - */ -void Chip_SSP_Init(LPC_SSP_T *pSSP); - -/** - * @brief Deinitialise the SSP - * @param pSSP : The base of SSP peripheral on the chip - * @return Nothing - * @note The SSP controller is disabled - */ -void Chip_SSP_DeInit(LPC_SSP_T *pSSP); - -/** - * @brief Set the SSP operating modes, master or slave - * @param pSSP : The base SSP peripheral on the chip - * @param master : 1 to set master, 0 to set slave - * @return Nothing - */ -void Chip_SSP_SetMaster(LPC_SSP_T *pSSP, bool master); - -/** - * @brief Set the clock frequency for SSP interface - * @param pSSP : The base SSP peripheral on the chip - * @param bitRate : The SSP bit rate - * @return Nothing - */ -void Chip_SSP_SetBitRate(LPC_SSP_T *pSSP, uint32_t bitRate); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __SSP_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sys_config.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sys_config.h deleted file mode 100755 index c6e4aeafb6..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sys_config.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __SYS_CONFIG_H_ -#define __SYS_CONFIG_H_ - -#endif /* __SYS_CONFIG_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sysctl_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sysctl_11xx.h deleted file mode 100755 index 6c61a10a74..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/sysctl_11xx.h +++ /dev/null @@ -1,687 +0,0 @@ -/* - * @brief LPC11XX System Control registers and control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __SYSCTL_11XX_H_ -#define __SYSCTL_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup SYSCTL_11XX CHIP: LPC11xx System Control block driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief LPC11XX System Control block structure - */ -typedef struct { /*!< SYSCTL Structure */ - __IO uint32_t SYSMEMREMAP; /*!< System Memory remap register */ - __IO uint32_t PRESETCTRL; /*!< Peripheral reset Control register */ - __IO uint32_t SYSPLLCTRL; /*!< System PLL control register */ - __I uint32_t SYSPLLSTAT; /*!< System PLL status register */ - __IO uint32_t USBPLLCTRL; /*!< USB PLL control register, LPC11UXX only*/ - __I uint32_t USBPLLSTAT; /*!< USB PLL status register, LPC11UXX only */ - __I uint32_t RESERVED1[2]; - __IO uint32_t SYSOSCCTRL; /*!< System Oscillator control register */ - __IO uint32_t WDTOSCCTRL; /*!< Watchdog Oscillator control register */ - __IO uint32_t IRCCTRL; /*!< IRC control register, not on LPC11UXX and LPC11EXX */ - __IO uint32_t LFOSCCTRL; /*!< LF oscillator control, LPC11AXX only */ - __IO uint32_t SYSRSTSTAT; /*!< System Reset Status register */ - __I uint32_t RESERVED2[3]; - __IO uint32_t SYSPLLCLKSEL; /*!< System PLL clock source select register */ - __IO uint32_t SYSPLLCLKUEN; /*!< System PLL clock source update enable register*/ - __IO uint32_t USBPLLCLKSEL; /*!< USB PLL clock source select register, LPC11UXX only */ - __IO uint32_t USBPLLCLKUEN; /*!< USB PLL clock source update enable register, LPC11UXX only */ - __I uint32_t RESERVED3[8]; - __IO uint32_t MAINCLKSEL; /*!< Main clock source select register */ - __IO uint32_t MAINCLKUEN; /*!< Main clock source update enable register */ - __IO uint32_t SYSAHBCLKDIV; /*!< System Clock divider register */ - __I uint32_t RESERVED4; - __IO uint32_t SYSAHBCLKCTRL; /*!< System clock control register */ - __I uint32_t RESERVED5[4]; - __IO uint32_t SSP0CLKDIV; /*!< SSP0 clock divider register */ - __IO uint32_t USARTCLKDIV; /*!< UART clock divider register */ - __IO uint32_t SSP1CLKDIV; /*!< SSP1 clock divider register, not on CHIP_LPC110X, CHIP_LPC11XXLV */ - __I uint32_t RESERVED6[8]; - __IO uint32_t USBCLKSEL; /*!< USB clock source select register, LPC11UXX only */ - __IO uint32_t USBCLKUEN; /*!< USB clock source update enable register, LPC11UXX only */ - __IO uint32_t USBCLKDIV; /*!< USB clock source divider register, LPC11UXX only */ - __I uint32_t RESERVED7; - __IO uint32_t WDTCLKSEL; /*!< WDT clock source select register, some parts only */ - __IO uint32_t WDTCLKUEN; /*!< WDT clock source update enable register, some parts only */ - __IO uint32_t WDTCLKDIV; /*!< WDT clock divider register, some parts only */ - __I uint32_t RESERVED8; - __IO uint32_t CLKOUTSEL; /*!< Clock out source select register, not on LPC1102/04 */ - __IO uint32_t CLKOUTUEN; /*!< Clock out source update enable register, not on LPC1102/04 */ - __IO uint32_t CLKOUTDIV; /*!< Clock out divider register, not on LPC1102/04 */ - __I uint32_t RESERVED9[5]; - __I uint32_t PIOPORCAP[2];/*!< POR captured PIO status registers, index 1 on LPC1102/04 */ - __I uint32_t RESERVED10[18]; - __IO uint32_t BODCTRL; /*!< Brown Out Detect register */ - __IO uint32_t SYSTCKCAL; /*!< System tick counter calibration register */ - __I uint32_t RESERVED11[6]; - __IO uint32_t IRQLATENCY; /*!< IRQ delay register, on LPC11UXX and LPC11EXX only */ - __IO uint32_t NMISRC; /*!< NMI source control register,some parts only */ - __IO uint32_t PINTSEL[8]; /*!< GPIO pin interrupt select register 0-7, not on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */ - __IO uint32_t USBCLKCTRL; /*!< USB clock control register, LPC11UXX only */ - __I uint32_t USBCLKST; /*!< USB clock status register, LPC11UXX only */ - __I uint32_t RESERVED12[24]; - __IO uint32_t STARTAPRP0; /*!< Start loigc 0 interrupt wake up enable register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */ - __IO uint32_t STARTERP0; /*!< Start loigc signal enable register 0, not on LPC11AXX */ - __IO uint32_t STARTRSRP0CLR; /*!< Start loigc reset register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */ - __IO uint32_t STARTSRP0; /*!< Start loigc status register 0, on CHIP_LPC110X, CHIP_LPC11XXLV, CHIP_LPC11CXX */ - __I uint32_t RESERVED13; - __IO uint32_t STARTERP1; /*!< Start logic 1 interrupt wake up enable register 1, on LPC11UXX and LPC11EXX only */ - __I uint32_t RESERVED14[6]; - __IO uint32_t PDSLEEPCFG; /*!< Power down states in deep sleep mode register, not on LPC11AXX */ - __IO uint32_t PDWAKECFG; /*!< Power down states in wake up from deep sleep register, not on LPC11AXX */ - __IO uint32_t PDRUNCFG; /*!< Power configuration register*/ - __I uint32_t RESERVED15[110]; - __I uint32_t DEVICEID; /*!< Device ID register */ -} LPC_SYSCTL_T; - -/** - * System memory remap modes used to remap interrupt vectors - */ -typedef enum CHIP_SYSCTL_BOOT_MODE_REMAP { - REMAP_BOOT_LOADER_MODE, /*!< Interrupt vectors are re-mapped to Boot ROM */ - REMAP_USER_RAM_MODE, /*!< Interrupt vectors are re-mapped to Static RAM */ - REMAP_USER_FLASH_MODE /*!< Interrupt vectors are not re-mapped and reside in Flash */ -} CHIP_SYSCTL_BOOT_MODE_REMAP_T; - -/** - * @brief Re-map interrupt vectors - * @param remap : system memory map value - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_Map(CHIP_SYSCTL_BOOT_MODE_REMAP_T remap) -{ - LPC_SYSCTL->SYSMEMREMAP = (uint32_t) remap; -} - -/** - * Peripheral reset identifiers, not available on all devices - */ -typedef enum { - RESET_SSP0, /*!< SSP0 reset control */ - RESET_I2C0, /*!< I2C0 reset control */ - RESET_SSP1, /*!< SSP1 reset control */ -#if !defined(CHIP_LPC1125) - RESET_CAN0, /*!< CAN0 reset control */ - RESET_UART0, /*!< UART0 reset control */ - RESET_TIMER0_16, /*!< 16-bit Timer 0 reset control */ - RESET_TIMER1_16, /*!< 16-bit Timer 1 reset control */ - RESET_TIMER0_32, /*!< 32-bit Timer 0 reset control */ - RESET_TIMER1_32, /*!< 32-bit Timer 1 reset control */ - RESET_ACMP, /*!< Analog comparator reset control */ - RESET_DAC0, /*!< DAC reset control */ - RESET_ADC0 /*!< ADC reset control */ -#endif -} CHIP_SYSCTL_PERIPH_RESET_T; - -/** - * @brief Assert reset for a peripheral - * @param periph : Peripheral to assert reset for - * @return Nothing - * @note The peripheral will stay in reset until reset is de-asserted. Call - * Chip_SYSCTL_DeassertPeriphReset() to de-assert the reset. - */ -STATIC INLINE void Chip_SYSCTL_AssertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph) -{ - LPC_SYSCTL->PRESETCTRL &= ~(1 << (uint32_t) periph); -} - -/** - * @brief De-assert reset for a peripheral - * @param periph : Peripheral to de-assert reset for - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_DeassertPeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph) -{ - LPC_SYSCTL->PRESETCTRL |= (1 << (uint32_t) periph); -} - -/** - * @brief Resets a peripheral - * @param periph : Peripheral to reset - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_PeriphReset(CHIP_SYSCTL_PERIPH_RESET_T periph) -{ - Chip_SYSCTL_AssertPeriphReset(periph); - Chip_SYSCTL_DeassertPeriphReset(periph); -} - -/** - * System reset status - */ -#define SYSCTL_RST_POR (1 << 0) /*!< POR reset status */ -#define SYSCTL_RST_EXTRST (1 << 1) /*!< External reset status */ -#define SYSCTL_RST_WDT (1 << 2) /*!< Watchdog reset status */ -#define SYSCTL_RST_BOD (1 << 3) /*!< Brown-out detect reset status */ -#define SYSCTL_RST_SYSRST (1 << 4) /*!< software system reset status */ - -/** - * Non-Maskable Interrupt Enable/Disable value - */ -#define SYSCTL_NMISRC_ENABLE ((uint32_t) 1 << 31) /*!< Enable the Non-Maskable Interrupt (NMI) source */ - -/** - * @brief Get system reset status - * @return An Or'ed value of SYSCTL_RST_* - * @note This function returns the detected reset source(s). - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetSystemRSTStatus(void) -{ - return LPC_SYSCTL->SYSRSTSTAT; -} - -/** - * @brief Clear system reset status - * @param reset : An Or'ed value of SYSCTL_RST_* status to clear - * @return Nothing - * @note This function returns the detected reset source(s). - */ -STATIC INLINE void Chip_SYSCTL_ClearSystemRSTStatus(uint32_t reset) -{ - LPC_SYSCTL->SYSRSTSTAT = reset; -} - -/** - * @brief Read POR captured PIO status - * @param index : POR register index, 0 or 1 - * @return captured POR PIO status - * @note Some devices only support index 0. - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetPORPIOStatus(int index) -{ - return LPC_SYSCTL->PIOPORCAP[index]; -} - -/** - * Brown-out detector reset level - */ -typedef enum CHIP_SYSCTL_BODRSTLVL { -#if defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC1125) - SYSCTL_BODRSTLVL_1_46V, /*!< Brown-out reset at 1.46v */ -#else - SYSCTL_BODRSTLVL_RESERVED1, /*!< Only possible value for LPC11A/02/XXLV */ -#endif -#if defined(CHIP_LPC11XXLV) - SYSCTL_BODRSTLVL_RESERVED1, - SYSCTL_BODRSTLVL_RESERVED2, - SYSCTL_BODRSTLVL_RESERVED3, -#elif defined(CHIP_LPC11AXX) - SYSCTL_BODRSTLVL_RESERVED2, - SYSCTL_BODRSTLVL_2_52V, /*!< Brown-out reset at 2.52v */ - SYSCTL_BODRSTLVL_2_80V, /*!< Brown-out reset at 2.80v */ -#else - SYSCTL_BODRSTLVL_2_06V, /*!< Brown-out reset at 2.06v */ - SYSCTL_BODRSTLVL_2_35V, /*!< Brown-out reset at 2.35v */ - SYSCTL_BODRSTLVL_2_63V, /*!< Brown-out reset at 2.63v */ -#endif -} CHIP_SYSCTL_BODRSTLVL_T; - -/** - * Brown-out detector interrupt level - */ -typedef enum CHIP_SYSCTL_BODRINTVAL { - SYSCTL_BODINTVAL_RESERVED1, -#if defined(CHIP_LPC110X) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC1125) - SYSCTL_BODINTVAL_2_22V, /*!< Brown-out interrupt at 2.22v */ - SYSCTL_BODINTVAL_2_52V, /*!< Brown-out interrupt at 2.52v */ - SYSCTL_BODINTVAL_2_80V, /*!< Brown-out interrupt at 2.8v */ -#endif -} CHIP_SYSCTL_BODRINTVAL_T; - -/** - * @brief Set brown-out detection interrupt and reset levels - * @param rstlvl : Brown-out detector reset level - * @param intlvl : Brown-out interrupt level - * @return Nothing - * @note Brown-out detection reset will be disabled upon exiting this function. - * Use Chip_SYSCTL_EnableBODReset() to re-enable. - */ -STATIC INLINE void Chip_SYSCTL_SetBODLevels(CHIP_SYSCTL_BODRSTLVL_T rstlvl, - CHIP_SYSCTL_BODRINTVAL_T intlvl) -{ - LPC_SYSCTL->BODCTRL = ((uint32_t) rstlvl) | (((uint32_t) intlvl) << 2); -} - -#if defined(CHIP_LPC11AXX) -/** - * @brief Returns brown-out detection interrupt status - * @return true if the BOD interrupt is pending, otherwise false - */ -STATIC INLINE bool Chip_SYSCTL_GetBODIntStatus(void) -{ - return (bool) ((LPC_SYSCTL->BODCTRL & (1 << 6)) != 0); -} - -#else -/** - * @brief Enable brown-out detection reset - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_EnableBODReset(void) -{ - LPC_SYSCTL->BODCTRL |= (1 << 4); -} - -/** - * @brief Disable brown-out detection reset - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_DisableBODReset(void) -{ - LPC_SYSCTL->BODCTRL &= ~(1 << 4); -} - -#endif - -/** - * @brief Set System tick timer calibration value - * @param sysCalVal : System tick timer calibration value - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_SetSYSTCKCAL(uint32_t sysCalVal) -{ - LPC_SYSCTL->SYSTCKCAL = sysCalVal; -} - -#if defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC1125) -/** - * @brief Set System IRQ latency - * @param latency : Latency in clock ticks - * @return Nothing - * @note Sets the IRQ latency, a value between 0 and 255 clocks. Lower - * values allow better latency. - */ -STATIC INLINE void Chip_SYSCTL_SetIRQLatency(uint32_t latency) -{ - LPC_SYSCTL->IRQLATENCY = latency; -} - -/** - * @brief Get System IRQ latency - * @return Latency in clock ticks - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetIRQLatency(void) -{ - return LPC_SYSCTL->IRQLATENCY; -} - -#endif - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) || defined(CHIP_LPC1125) -/** - * @brief Set source for non-maskable interrupt (NMI) - * @param intsrc : IRQ number to assign to the NMI - * @return Nothing - * @note The NMI source will be disabled upon exiting this function. use the - * Chip_SYSCTL_EnableNMISource() function to enable the NMI source. - */ -STATIC INLINE void Chip_SYSCTL_SetNMISource(uint32_t intsrc) -{ - LPC_SYSCTL->NMISRC = intsrc; -} - -/** - * @brief Enable interrupt used for NMI source - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_EnableNMISource(void) -{ - LPC_SYSCTL->NMISRC |= SYSCTL_NMISRC_ENABLE; -} - -/** - * @brief Disable interrupt used for NMI source - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_DisableNMISource(void) -{ - LPC_SYSCTL->NMISRC &= ~(SYSCTL_NMISRC_ENABLE); -} - -#endif - -#if defined(CHIP_LPC11AXX) -/** - * @brief Setup a pin source for the pin interrupts (0-7) - * @param intno : IRQ number - * @param port : port number 0/1) - * @param pin : pin number (0->31) - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_SetPinInterrupt(uint32_t intno, uint8_t port, uint8_t pin) -{ - LPC_SYSCTL->PINTSEL[intno] = (uint32_t) ((port << 5) | pin); -} - -#elif defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) -/** - * @brief Setup a pin source for the pin interrupts (0-7) - * @param intno : IRQ number - * @param port : port number 0/1) - * @param pin : pin number (0->23 for GPIO Port 0 and 0->31 for GPIO Port 1) - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_SetPinInterrupt(uint32_t intno, uint8_t port, uint8_t pin) -{ - LPC_SYSCTL->PINTSEL[intno] = (uint32_t) (port * 24 + pin); -} - -#endif - -#if defined(CHIP_LPC11UXX) -/** - * @brief Setup USB clock control - * @param ap_clk : USB need_clock signal control (0 or 1) - * @param pol_clk : USB need_clock polarity for triggering the USB wake-up interrupt (0 or 1) - * @return Nothing - * @note See the USBCLKCTRL register in the user manual for these settings. - */ -STATIC INLINE void Chip_SYSCTL_SetUSBCLKCTRL(uint32_t ap_clk, uint32_t pol_clk) -{ - LPC_SYSCTL->USBCLKCTRL = ap_clk | (pol_clk << 1); -} - -/** - * @brief Returns the status of the USB need_clock signal - * @return true if USB need_clock statis is high, otherwise false - */ -STATIC INLINE bool Chip_SYSCTL_GetUSBCLKStatus(void) -{ - return (bool) ((LPC_SYSCTL->USBCLKST & 0x1) != 0); -} - -#endif - -#if defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC1125) -/** - * @brief Set edge for PIO start logic - * @param pin : PIO pin number - * @param edge : 0 for falling edge, 1 for rising edge - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_SetStartPin(uint32_t pin, uint32_t edge) -{ - if (edge) { - LPC_SYSCTL->STARTAPRP0 |= (1 << pin); - } - else { - LPC_SYSCTL->STARTAPRP0 &= ~(1 << pin); - } -} - -/** - * @brief Enable PIO start logic for a pin - * @param pin : PIO pin number - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_EnableStartPin(uint32_t pin) -{ - LPC_SYSCTL->STARTERP0 |= (1 << pin); -} - -/** - * @brief Disable PIO start logic for a pin - * @param pin : PIO pin number - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_DisableStartPin(uint32_t pin) -{ - LPC_SYSCTL->STARTERP0 &= ~(1 << pin); -} - -/** - * @brief Clear PIO start logic state - * @param pin : PIO pin number - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_ResetStartPin(uint32_t pin) -{ - LPC_SYSCTL->STARTRSRP0CLR = (1 << pin); -} - -/** - * @brief Returns status of pin wakeup - * @param pin : PIO pin number - * @return true if a pin start signal is pending, otherwise false - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE bool Chip_SYSCTL_GetStartPinStatus(uint32_t pin) -{ - return (bool) ((LPC_SYSCTL->STARTSRP0 & (1 << pin)) != 0); -} - -#endif - -#if defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) -/** - * @brief Enables a pin's (PINT) wakeup logic - * @param pin : pin number - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_EnablePINTWakeup(uint32_t pin) -{ - LPC_SYSCTL->STARTERP0 |= (1 << pin); -} - -/** - * @brief Disables a pin's (PINT) wakeup logic - * @param pin : pin number - * @return Nothing - * @note Different devices support different pins, see the user manual for supported pins. - */ -STATIC INLINE void Chip_SYSCTL_DisablePINTWakeup(uint32_t pin) -{ - LPC_SYSCTL->STARTERP0 &= ~(1 << pin); -} - -/** - * Peripheral interrupt wakeup events, LPC11E/Uxx only - */ -#define SYSCTL_WAKEUP_WWDTINT (1 << 12) /*!< WWDT interrupt wake-up */ -#define SYSCTL_WAKEUP_BODINT (1 << 13) /*!< Brown Out Detect (BOD) interrupt wake-up */ -#define SYSCTL_WAKEUP_USB_WAKEUP (1 << 19) /*!< USB need_clock signal wake-up, LPC11Uxx only */ -#define SYSCTL_WAKEUP_GPIOINT0 (1 << 20) /*!< GPIO GROUP0 interrupt wake-up */ -#define SYSCTL_WAKEUP_GPIOINT1 (1 << 21) /*!< GPIO GROUP1 interrupt wake-up */ - -/** - * @brief Enables a peripheral's wakeup logic - * @param periphmask : OR'ed values of SYSCTL_WAKEUP_* for wakeup - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_EnablePeriphWakeup(uint32_t periphmask) -{ - LPC_SYSCTL->STARTERP1 |= periphmask; -} - -/** - * @brief Disables a peripheral's wakeup logic - * @param periphmask : OR'ed values of SYSCTL_WAKEUP_* for wakeup - * @return Nothing - */ -STATIC INLINE void Chip_SYSCTL_DisablePeriphWakeup(uint32_t periphmask) -{ - LPC_SYSCTL->STARTERP1 &= ~periphmask; -} - -#endif - -#if !defined(LPC11AXX) -/** - * Deep sleep setup values - */ -#define SYSCTL_DEEPSLP_BOD_PD (1 << 3) /*!< BOD power-down control in Deep-sleep mode, powered down */ -#define SYSCTL_DEEPSLP_WDTOSC_PD (1 << 6) /*!< Watchdog oscillator power control in Deep-sleep, powered down */ -#if defined(CHIP_LPC11XXLV) -#define SYSCTL_DEEPSLP_IRCOUT_PD (1 << 0) /*!< IRC oscillator output in Deep-sleep mode, powered down */ -#define SYSCTL_DEEPSLP_IRC_PD (1 << 1) /*!< IRC oscillator in Deep-sleep, powered down */ -#endif - -/** - * @brief Setup deep sleep behaviour for power down - * @param sleepmask : OR'ed values of SYSCTL_DEEPSLP_* values (high to powerdown on deepsleep) - * @return Nothing - * @note This must be setup prior to using deep sleep. See the user manual - ***(PDSLEEPCFG register) for more info on setting this up. This function selects - * which peripherals are powered down on deep sleep. - * This function should only be called once with all options for power-down - * in that call. - */ -void Chip_SYSCTL_SetDeepSleepPD(uint32_t sleepmask); - -/** - * @brief Returns current deep sleep mask - * @return OR'ed values of SYSCTL_DEEPSLP_* values - * @note A high bit indicates the peripheral will power down on deep sleep. - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetDeepSleepPD(void) -{ - return LPC_SYSCTL->PDSLEEPCFG; -} - -/** - * Deep sleep to wakeup setup values - */ -#define SYSCTL_SLPWAKE_IRCOUT_PD (1 << 0) /*!< IRC oscillator output wake-up configuration */ -#define SYSCTL_SLPWAKE_IRC_PD (1 << 1) /*!< IRC oscillator power-down wake-up configuration */ -#define SYSCTL_SLPWAKE_FLASH_PD (1 << 2) /*!< Flash wake-up configuration */ -#define SYSCTL_SLPWAKE_BOD_PD (1 << 3) /*!< BOD wake-up configuration */ -#define SYSCTL_SLPWAKE_ADC_PD (1 << 4) /*!< ADC wake-up configuration */ -#define SYSCTL_SLPWAKE_SYSOSC_PD (1 << 5) /*!< System oscillator wake-up configuration */ -#define SYSCTL_SLPWAKE_WDTOSC_PD (1 << 6) /*!< Watchdog oscillator wake-up configuration */ -#define SYSCTL_SLPWAKE_SYSPLL_PD (1 << 7) /*!< System PLL wake-up configuration */ -#if defined(CHIP_LPC11UXX) -#define SYSCTL_SLPWAKE_USBPLL_PD (1 << 8) /*!< USB PLL wake-up configuration */ -#define SYSCTL_SLPWAKE_USBPAD_PD (1 << 10) /*!< USB transceiver wake-up configuration */ -#endif - -/** - * @brief Setup wakeup behaviour from deep sleep - * @param wakeupmask : OR'ed values of SYSCTL_SLPWAKE_* values (high is powered down) - * @return Nothing - * @note This must be setup prior to using deep sleep. See the user manual - * (PDWAKECFG register) for more info on setting this up. This function selects - * which peripherals are powered up on exit from deep sleep. - * This function should only be called once with all options for wakeup - * in that call. - */ -void Chip_SYSCTL_SetWakeup(uint32_t wakeupmask); - -/** - * @brief Return current wakeup mask - * @return OR'ed values of SYSCTL_SLPWAKE_* values - * @note A high state indicates the peripehral will powerup on wakeup. - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetWakeup(void) -{ - return LPC_SYSCTL->PDWAKECFG; -} - -#endif - -/** - * Power down configuration values - */ -#define SYSCTL_POWERDOWN_IRCOUT_PD (1 << 0) /*!< IRC oscillator output power down */ -#define SYSCTL_POWERDOWN_IRC_PD (1 << 1) /*!< IRC oscillator power-down */ -#define SYSCTL_POWERDOWN_FLASH_PD (1 << 2) /*!< Flash power down */ -#if !defined(CHIP_LPC11AXX) -#define SYSCTL_POWERDOWN_BOD_PD (1 << 3) /*!< BOD power down */ -#endif -#define SYSCTL_POWERDOWN_ADC_PD (1 << 4) /*!< ADC power down */ -#define SYSCTL_POWERDOWN_SYSOSC_PD (1 << 5) /*!< System oscillator power down */ -#define SYSCTL_POWERDOWN_WDTOSC_PD (1 << 6) /*!< Watchdog oscillator power down */ -#define SYSCTL_POWERDOWN_SYSPLL_PD (1 << 7) /*!< System PLL power down */ -#if defined(CHIP_LPC11UXX) -#define SYSCTL_POWERDOWN_USBPLL_PD (1 << 8) /*!< USB PLL power-down */ -#define SYSCTL_POWERDOWN_USBPAD_PD (1 << 10)/*!< USB transceiver power-down */ -#endif -#if defined(CHIP_LPC11AXX) -#define SYSCTL_POWERDOWN_LFOSC_PD (1 << 13) /*!< Low frequency oscillator power-down */ -#define SYSCTL_POWERDOWN_DAC_PD (1 << 14) /*!< DAC power-down */ -#define SYSCTL_POWERDOWN_TS_PD (1 << 15) /*!< Temperature Sensor power-down */ -#define SYSCTL_POWERDOWN_ACOMP_PD (1 << 16) /*!< Analog Comparator power-down */ -#endif - -/** - * @brief Power down one or more blocks or peripherals - * @param powerdownmask : OR'ed values of SYSCTL_POWERDOWN_* values - * @return Nothing - */ -void Chip_SYSCTL_PowerDown(uint32_t powerdownmask); - -/** - * @brief Power up one or more blocks or peripherals - * @param powerupmask : OR'ed values of SYSCTL_POWERDOWN_* values - * @return Nothing - */ -void Chip_SYSCTL_PowerUp(uint32_t powerupmask); - -/** - * @brief Get power status - * @return OR'ed values of SYSCTL_POWERDOWN_* values - * @note A high state indicates the peripheral is powered down. - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetPowerStates(void) -{ - return LPC_SYSCTL->PDRUNCFG; -} - -/** - * @brief Return the device ID - * @return the device ID - */ -STATIC INLINE uint32_t Chip_SYSCTL_GetDeviceID(void) -{ - return LPC_SYSCTL->DEVICEID; -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /*!< __SYSCTL_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/timer_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/timer_11xx.h deleted file mode 100755 index ad1c5c306d..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/timer_11xx.h +++ /dev/null @@ -1,446 +0,0 @@ -/* - * @brief LPC11xx 16/32-bit Timer/PWM control functions - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __TIMER_11XX_H_ -#define __TIMER_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup TIMER_11XX CHIP: LPC11xx 16/32-bit Timer driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief 32-bit Standard timer register block structure - */ -typedef struct { /*!< TIMERn Structure */ - __IO uint32_t IR; /*!< Interrupt Register. The IR can be written to clear interrupts. The IR can be read to identify which of eight possible interrupt sources are pending. */ - __IO uint32_t TCR; /*!< Timer Control Register. The TCR is used to control the Timer Counter functions. The Timer Counter can be disabled or reset through the TCR. */ - __IO uint32_t TC; /*!< Timer Counter. The 32 bit TC is incremented every PR+1 cycles of PCLK. The TC is controlled through the TCR. */ - __IO uint32_t PR; /*!< Prescale Register. The Prescale Counter (below) is equal to this value, the next clock increments the TC and clears the PC. */ - __IO uint32_t PC; /*!< Prescale Counter. The 32 bit PC is a counter which is incremented to the value stored in PR. When the value in PR is reached, the TC is incremented and the PC is cleared. The PC is observable and controllable through the bus interface. */ - __IO uint32_t MCR; /*!< Match Control Register. The MCR is used to control if an interrupt is generated and if the TC is reset when a Match occurs. */ - __IO uint32_t MR[4]; /*!< Match Register. MR can be enabled through the MCR to reset the TC, stop both the TC and PC, and/or generate an interrupt every time MR matches the TC. */ - __IO uint32_t CCR; /*!< Capture Control Register. The CCR controls which edges of the capture inputs are used to load the Capture Registers and whether or not an interrupt is generated when a capture takes place. */ - __IO uint32_t CR[4]; /*!< Capture Register. CR is loaded with the value of TC when there is an event on the CAPn.0 input. */ - __IO uint32_t EMR; /*!< External Match Register. The EMR controls the external match pins MATn.0-3 (MAT0.0-3 and MAT1.0-3 respectively). */ - __I uint32_t RESERVED0[12]; - __IO uint32_t CTCR; /*!< Count Control Register. The CTCR selects between Timer and Counter mode, and in Counter mode selects the signal and edge(s) for counting. */ - __IO uint32_t PWMC; -} LPC_TIMER_T; - -/** Macro to clear interrupt pending */ -#define TIMER_IR_CLR(n) _BIT(n) - -/** Macro for getting a timer match interrupt bit */ -#define TIMER_MATCH_INT(n) (_BIT((n) & 0x0F)) -/** Macro for getting a capture event interrupt bit */ -#define TIMER_CAP_INT(n) (_BIT((((n) & 0x0F) + 4))) - -/** Timer/counter enable bit */ -#define TIMER_ENABLE ((uint32_t) (1 << 0)) -/** Timer/counter reset bit */ -#define TIMER_RESET ((uint32_t) (1 << 1)) - -/** Bit location for interrupt on MRx match, n = 0 to 3 */ -#define TIMER_INT_ON_MATCH(n) (_BIT(((n) * 3))) -/** Bit location for reset on MRx match, n = 0 to 3 */ -#define TIMER_RESET_ON_MATCH(n) (_BIT((((n) * 3) + 1))) -/** Bit location for stop on MRx match, n = 0 to 3 */ -#define TIMER_STOP_ON_MATCH(n) (_BIT((((n) * 3) + 2))) - -/** Bit location for CAP.n on CRx rising edge, n = 0 to 3 */ -#define TIMER_CAP_RISING(n) (_BIT(((n) * 3))) -/** Bit location for CAP.n on CRx falling edge, n = 0 to 3 */ -#define TIMER_CAP_FALLING(n) (_BIT((((n) * 3) + 1))) -/** Bit location for CAP.n on CRx interrupt enable, n = 0 to 3 */ -#define TIMER_INT_ON_CAP(n) (_BIT((((n) * 3) + 2))) - -/** - * @brief Initialize a timer - * @param pTMR : Pointer to timer IP register address - * @return Nothing - */ -void Chip_TIMER_Init(LPC_TIMER_T *pTMR); - -/** - * @brief Shutdown a timer - * @param pTMR : Pointer to timer IP register address - * @return Nothing - */ -void Chip_TIMER_DeInit(LPC_TIMER_T *pTMR); - -/** - * @brief Determine if a match interrupt is pending - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match interrupt number to check - * @return false if the interrupt is not pending, otherwise true - * @note Determine if the match interrupt for the passed timer and match - * counter is pending. - */ -STATIC INLINE bool Chip_TIMER_MatchPending(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - return (bool) ((pTMR->IR & TIMER_MATCH_INT(matchnum)) != 0); -} - -/** - * @brief Determine if a capture interrupt is pending - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture interrupt number to check - * @return false if the interrupt is not pending, otherwise true - * @note Determine if the capture interrupt for the passed capture pin is - * pending. - */ -STATIC INLINE bool Chip_TIMER_CapturePending(LPC_TIMER_T *pTMR, int8_t capnum) -{ - return (bool) ((pTMR->IR & TIMER_CAP_INT(capnum)) != 0); -} - -/** - * @brief Clears a (pending) match interrupt - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match interrupt number to clear - * @return Nothing - * @note Clears a pending timer match interrupt. - */ -STATIC INLINE void Chip_TIMER_ClearMatch(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->IR = TIMER_IR_CLR(matchnum); -} - -/** - * @brief Clears a (pending) capture interrupt - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture interrupt number to clear - * @return Nothing - * @note Clears a pending timer capture interrupt. - */ -STATIC INLINE void Chip_TIMER_ClearCapture(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->IR = (0x10 << capnum); -} - -/** - * @brief Enables the timer (starts count) - * @param pTMR : Pointer to timer IP register address - * @return Nothing - * @note Enables the timer to start counting. - */ -STATIC INLINE void Chip_TIMER_Enable(LPC_TIMER_T *pTMR) -{ - pTMR->TCR |= TIMER_ENABLE; -} - -/** - * @brief Disables the timer (stops count) - * @param pTMR : Pointer to timer IP register address - * @return Nothing - * @note Disables the timer to stop counting. - */ -STATIC INLINE void Chip_TIMER_Disable(LPC_TIMER_T *pTMR) -{ - pTMR->TCR &= ~TIMER_ENABLE; -} - -/** - * @brief Returns the current timer count - * @param pTMR : Pointer to timer IP register address - * @return Current timer terminal count value - * @note Returns the current timer terminal count. - */ -STATIC INLINE uint32_t Chip_TIMER_ReadCount(LPC_TIMER_T *pTMR) -{ - return pTMR->TC; -} - -/** - * @brief Returns the current prescale count - * @param pTMR : Pointer to timer IP register address - * @return Current timer prescale count value - * @note Returns the current prescale count. - */ -STATIC INLINE uint32_t Chip_TIMER_ReadPrescale(LPC_TIMER_T *pTMR) -{ - return pTMR->PC; -} - -/** - * @brief Sets the prescaler value - * @param pTMR : Pointer to timer IP register address - * @param prescale : Prescale value to set the prescale register to - * @return Nothing - * @note Sets the prescale count value. - */ -STATIC INLINE void Chip_TIMER_PrescaleSet(LPC_TIMER_T *pTMR, uint32_t prescale) -{ - pTMR->PR = prescale; -} - -/** - * @brief Sets a timer match value - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer to set match count for - * @param matchval : Match value for the selected match count - * @return Nothing - * @note Sets one of the timer match values. - */ -STATIC INLINE void Chip_TIMER_SetMatch(LPC_TIMER_T *pTMR, int8_t matchnum, uint32_t matchval) -{ - pTMR->MR[matchnum] = matchval; -} - -/** - * @brief Reads a capture register - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture register to read - * @return The selected capture register value - * @note Returns the selected capture register value. - */ -STATIC INLINE uint32_t Chip_TIMER_ReadCapture(LPC_TIMER_T *pTMR, int8_t capnum) -{ - return pTMR->CR[capnum]; -} - -/** - * @brief Resets the timer terminal and prescale counts to 0 - * @param pTMR : Pointer to timer IP register address - * @return Nothing - */ -void Chip_TIMER_Reset(LPC_TIMER_T *pTMR); - -/** - * @brief Enables a match interrupt that fires when the terminal count - * matches the match counter value. - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_MatchEnableInt(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR |= TIMER_INT_ON_MATCH(matchnum); -} - -/** - * @brief Disables a match interrupt for a match counter. - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_MatchDisableInt(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR &= ~TIMER_INT_ON_MATCH(matchnum); -} - -/** - * @brief For the specific match counter, enables reset of the terminal count register when a match occurs - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_ResetOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR |= TIMER_RESET_ON_MATCH(matchnum); -} - -/** - * @brief For the specific match counter, disables reset of the terminal count register when a match occurs - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_ResetOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR &= ~TIMER_RESET_ON_MATCH(matchnum); -} - -/** - * @brief Enable a match timer to stop the terminal count when a - * match count equals the terminal count. - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_StopOnMatchEnable(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR |= TIMER_STOP_ON_MATCH(matchnum); -} - -/** - * @brief Disable stop on match for a match timer. Disables a match timer - * to stop the terminal count when a match count equals the terminal count. - * @param pTMR : Pointer to timer IP register address - * @param matchnum : Match timer, 0 to 3 - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_StopOnMatchDisable(LPC_TIMER_T *pTMR, int8_t matchnum) -{ - pTMR->MCR &= ~TIMER_STOP_ON_MATCH(matchnum); -} - -/** - * @brief Enables capture on on rising edge of selected CAP signal for the - * selected capture register, enables the selected CAPn.capnum signal to load - * the capture register with the terminal coount on a rising edge. - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureRisingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR |= TIMER_CAP_RISING(capnum); -} - -/** - * @brief Disables capture on on rising edge of selected CAP signal. For the - * selected capture register, disables the selected CAPn.capnum signal to load - * the capture register with the terminal coount on a rising edge. - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureRisingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR &= ~TIMER_CAP_RISING(capnum); -} - -/** - * @brief Enables capture on on falling edge of selected CAP signal. For the - * selected capture register, enables the selected CAPn.capnum signal to load - * the capture register with the terminal coount on a falling edge. - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureFallingEdgeEnable(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR |= TIMER_CAP_FALLING(capnum); -} - -/** - * @brief Disables capture on on falling edge of selected CAP signal. For the - * selected capture register, disables the selected CAPn.capnum signal to load - * the capture register with the terminal coount on a falling edge. - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureFallingEdgeDisable(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR &= ~TIMER_CAP_FALLING(capnum); -} - -/** - * @brief Enables interrupt on capture of selected CAP signal. For the - * selected capture register, an interrupt will be generated when the enabled - * rising or falling edge on CAPn.capnum is detected. - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureEnableInt(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR |= TIMER_INT_ON_CAP(capnum); -} - -/** - * @brief Disables interrupt on capture of selected CAP signal - * @param pTMR : Pointer to timer IP register address - * @param capnum : Capture signal/register to use - * @return Nothing - */ -STATIC INLINE void Chip_TIMER_CaptureDisableInt(LPC_TIMER_T *pTMR, int8_t capnum) -{ - pTMR->CCR &= ~TIMER_INT_ON_CAP(capnum); -} - -/** - * @brief Standard timer initial match pin state and change state - */ -typedef enum IP_TIMER_PIN_MATCH_STATE { - TIMER_EXTMATCH_DO_NOTHING = 0, /*!< Timer match state does nothing on match pin */ - TIMER_EXTMATCH_CLEAR = 1, /*!< Timer match state sets match pin low */ - TIMER_EXTMATCH_SET = 2, /*!< Timer match state sets match pin high */ - TIMER_EXTMATCH_TOGGLE = 3 /*!< Timer match state toggles match pin */ -} TIMER_PIN_MATCH_STATE_T; - -/** - * @brief Sets external match control (MATn.matchnum) pin control. For the pin - * selected with matchnum, sets the function of the pin that occurs on - * a terminal count match for the match count. - * @param pTMR : Pointer to timer IP register address - * @param initial_state : Initial state of the pin, high(1) or low(0) - * @param matchState : Selects the match state for the pin - * @param matchnum : MATn.matchnum signal to use - * @return Nothing - * @note For the pin selected with matchnum, sets the function of the pin that occurs on - * a terminal count match for the match count. - */ -void Chip_TIMER_ExtMatchControlSet(LPC_TIMER_T *pTMR, int8_t initial_state, - TIMER_PIN_MATCH_STATE_T matchState, int8_t matchnum); - -/** - * @brief Standard timer clock and edge for count source - */ -typedef enum IP_TIMER_CAP_SRC_STATE { - TIMER_CAPSRC_RISING_PCLK = 0, /*!< Timer ticks on PCLK rising edge */ - TIMER_CAPSRC_RISING_CAPN = 1, /*!< Timer ticks on CAPn.x rising edge */ - TIMER_CAPSRC_FALLING_CAPN = 2, /*!< Timer ticks on CAPn.x falling edge */ - TIMER_CAPSRC_BOTH_CAPN = 3 /*!< Timer ticks on CAPn.x both edges */ -} TIMER_CAP_SRC_STATE_T; - -/** - * @brief Sets timer count source and edge with the selected passed from CapSrc. - * If CapSrc selected a CAPn pin, select the specific CAPn pin with the capnum value. - * @param pTMR : Pointer to timer IP register address - * @param capSrc : timer clock source and edge - * @param capnum : CAPn.capnum pin to use (if used) - * @return Nothing - * @note If CapSrc selected a CAPn pin, select the specific CAPn pin with the capnum value. - */ -STATIC INLINE void Chip_TIMER_TIMER_SetCountClockSrc(LPC_TIMER_T *pTMR, - TIMER_CAP_SRC_STATE_T capSrc, - int8_t capnum) -{ - pTMR->CTCR = (uint32_t) capSrc | ((uint32_t) capnum) << 2; -} - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __TIMER_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/uart_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/uart_11xx.h deleted file mode 100755 index 8c15b24c06..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/uart_11xx.h +++ /dev/null @@ -1,787 +0,0 @@ -/* - * @brief LPC11xx UART chip driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __UART_11XX_H_ -#define __UART_11XX_H_ - -#include "ring_buffer.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup UART_11XX CHIP: LPC11xx UART driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -/** - * @brief USART register block structure - */ -typedef struct { /*!< USARTn Structure */ - - union { - __IO uint32_t DLL; /*!< Divisor Latch LSB. Least significant byte of the baud rate divisor value. The full divisor is used to generate a baud rate from the fractional rate divider (DLAB = 1). */ - __O uint32_t THR; /*!< Transmit Holding Register. The next character to be transmitted is written here (DLAB = 0). */ - __I uint32_t RBR; /*!< Receiver Buffer Register. Contains the next received character to be read (DLAB = 0). */ - }; - - union { - __IO uint32_t IER; /*!< Interrupt Enable Register. Contains individual interrupt enable bits for the 7 potential UART interrupts (DLAB = 0). */ - __IO uint32_t DLM; /*!< Divisor Latch MSB. Most significant byte of the baud rate divisor value. The full divisor is used to generate a baud rate from the fractional rate divider (DLAB = 1). */ - }; - - union { - __O uint32_t FCR; /*!< FIFO Control Register. Controls UART FIFO usage and modes. */ - __I uint32_t IIR; /*!< Interrupt ID Register. Identifies which interrupt(s) are pending. */ - }; - - __IO uint32_t LCR; /*!< Line Control Register. Contains controls for frame formatting and break generation. */ - __IO uint32_t MCR; /*!< Modem Control Register. Only present on USART ports with full modem support. */ - __I uint32_t LSR; /*!< Line Status Register. Contains flags for transmit and receive status, including line errors. */ - __I uint32_t MSR; /*!< Modem Status Register. Only present on USART ports with full modem support. */ - __IO uint32_t SCR; /*!< Scratch Pad Register. Eight-bit temporary storage for software. */ - __IO uint32_t ACR; /*!< Auto-baud Control Register. Contains controls for the auto-baud feature. */ - __IO uint32_t ICR; /*!< IrDA control register (not all UARTS) */ - __IO uint32_t FDR; /*!< Fractional Divider Register. Generates a clock input for the baud rate divider. */ - __IO uint32_t OSR; /*!< Oversampling Register. Controls the degree of oversampling during each bit time. Only on some UARTS. */ - __IO uint32_t TER1; /*!< Transmit Enable Register. Turns off USART transmitter for use with software flow control. */ - uint32_t RESERVED0[3]; - __IO uint32_t HDEN; /*!< Half-duplex enable Register- only on some UARTs */ - __I uint32_t RESERVED1[1]; - __IO uint32_t SCICTRL; /*!< Smart card interface control register- only on some UARTs */ - - __IO uint32_t RS485CTRL; /*!< RS-485/EIA-485 Control. Contains controls to configure various aspects of RS-485/EIA-485 modes. */ - __IO uint32_t RS485ADRMATCH; /*!< RS-485/EIA-485 address match. Contains the address match value for RS-485/EIA-485 mode. */ - __IO uint32_t RS485DLY; /*!< RS-485/EIA-485 direction control delay. */ - - union { - __IO uint32_t SYNCCTRL; /*!< Synchronous mode control register. Only on USARTs. */ - __I uint32_t FIFOLVL; /*!< FIFO Level register. Provides the current fill levels of the transmit and receive FIFOs. */ - }; - - __IO uint32_t TER2; /*!< Transmit Enable Register. Only on LPC177X_8X UART4 and LPC18XX/43XX USART0/2/3. */ -} LPC_USART_T; - - -/** - * @brief Macro defines for UART Receive Buffer register - */ -#define UART_RBR_MASKBIT (0xFF) /*!< UART Received Buffer mask bit (8 bits) */ - -/** - * @brief Macro defines for UART Divisor Latch LSB register - */ -#define UART_LOAD_DLL(div) ((div) & 0xFF) /*!< Macro for loading LSB of divisor */ -#define UART_DLL_MASKBIT (0xFF) /*!< Divisor latch LSB bit mask */ - -/** - * @brief Macro defines for UART Divisor Latch MSB register - */ -#define UART_LOAD_DLM(div) (((div) >> 8) & 0xFF) /*!< Macro for loading MSB of divisors */ -#define UART_DLM_MASKBIT (0xFF) /*!< Divisor latch MSB bit mask */ - -/** - * @brief Macro defines for UART Interrupt Enable Register - */ -#define UART_IER_RBRINT (1 << 0) /*!< RBR Interrupt enable */ -#define UART_IER_THREINT (1 << 1) /*!< THR Interrupt enable */ -#define UART_IER_RLSINT (1 << 2) /*!< RX line status interrupt enable */ -#define UART_IER_MSINT (1 << 3) /*!< Modem status interrupt enable - valid for 11xx, 17xx/40xx UART1, 18xx/43xx UART1 only */ -#define UART_IER_CTSINT (1 << 7) /*!< CTS signal transition interrupt enable - valid for 17xx/40xx UART1, 18xx/43xx UART1 only */ -#define UART_IER_ABEOINT (1 << 8) /*!< Enables the end of auto-baud interrupt */ -#define UART_IER_ABTOINT (1 << 9) /*!< Enables the auto-baud time-out interrupt */ -#define UART_IER_BITMASK (0x307) /*!< UART interrupt enable register bit mask - valid for 13xx, 17xx/40xx UART0/2/3, 18xx/43xx UART0/2/3 only*/ -#define UART1_IER_BITMASK (0x30F) /*!< UART1 interrupt enable register bit mask - valid for 11xx only */ -#define UART2_IER_BITMASK (0x38F) /*!< UART2 interrupt enable register bit mask - valid for 17xx/40xx UART1, 18xx/43xx UART1 only */ - -/** - * @brief Macro defines for UART Interrupt Identification Register - */ -#define UART_IIR_INTSTAT_PEND (1 << 0) /*!< Interrupt pending status - Active low */ -#define UART_IIR_FIFO_EN (3 << 6) /*!< These bits are equivalent to FCR[0] */ -#define UART_IIR_ABEO_INT (1 << 8) /*!< End of auto-baud interrupt */ -#define UART_IIR_ABTO_INT (1 << 9) /*!< Auto-baud time-out interrupt */ -#define UART_IIR_BITMASK (0x3CF) /*!< UART interrupt identification register bit mask */ - -/* Interrupt ID bit definitions */ -#define UART_IIR_INTID_MASK (7 << 1) /*!< Interrupt identification: Interrupt ID mask */ -#define UART_IIR_INTID_RLS (3 << 1) /*!< Interrupt identification: Receive line interrupt */ -#define UART_IIR_INTID_RDA (2 << 1) /*!< Interrupt identification: Receive data available interrupt */ -#define UART_IIR_INTID_CTI (6 << 1) /*!< Interrupt identification: Character time-out indicator interrupt */ -#define UART_IIR_INTID_THRE (1 << 1) /*!< Interrupt identification: THRE interrupt */ -#define UART_IIR_INTID_MODEM (0 << 1) /*!< Interrupt identification: Modem interrupt */ - -/** - * @brief Macro defines for UART FIFO Control Register - */ -#define UART_FCR_FIFO_EN (1 << 0) /*!< UART FIFO enable */ -#define UART_FCR_RX_RS (1 << 1) /*!< UART RX FIFO reset */ -#define UART_FCR_TX_RS (1 << 2) /*!< UART TX FIFO reset */ -#define UART_FCR_DMAMODE_SEL (1 << 3) /*!< UART DMA mode selection - valid for 17xx/40xx, 18xx/43xx only */ -#define UART_FCR_BITMASK (0xCF) /*!< UART FIFO control bit mask */ - -#define UART_TX_FIFO_SIZE (16) - -/* FIFO trigger level bit definitions */ -#define UART_FCR_TRG_LEV0 (0) /*!< UART FIFO trigger level 0: 1 character */ -#define UART_FCR_TRG_LEV1 (1 << 6) /*!< UART FIFO trigger level 1: 4 character */ -#define UART_FCR_TRG_LEV2 (2 << 6) /*!< UART FIFO trigger level 2: 8 character */ -#define UART_FCR_TRG_LEV3 (3 << 6) /*!< UART FIFO trigger level 3: 14 character */ - -/** - * @brief Macro defines for UART Line Control Register - */ -/* UART word length select bit definitions */ -#define UART_LCR_WLEN_MASK (3 << 0) /*!< UART word length select bit mask */ -#define UART_LCR_WLEN5 (0 << 0) /*!< UART word length select: 5 bit data mode */ -#define UART_LCR_WLEN6 (1 << 0) /*!< UART word length select: 6 bit data mode */ -#define UART_LCR_WLEN7 (2 << 0) /*!< UART word length select: 7 bit data mode */ -#define UART_LCR_WLEN8 (3 << 0) /*!< UART word length select: 8 bit data mode */ - -/* UART Stop bit select bit definitions */ -#define UART_LCR_SBS_MASK (1 << 2) /*!< UART stop bit select: bit mask */ -#define UART_LCR_SBS_1BIT (0 << 2) /*!< UART stop bit select: 1 stop bit */ -#define UART_LCR_SBS_2BIT (1 << 2) /*!< UART stop bit select: 2 stop bits (in 5 bit data mode, 1.5 stop bits) */ - -/* UART Parity enable bit definitions */ -#define UART_LCR_PARITY_EN (1 << 3) /*!< UART Parity Enable */ -#define UART_LCR_PARITY_DIS (0 << 3) /*!< UART Parity Disable */ -#define UART_LCR_PARITY_ODD (0 << 4) /*!< UART Parity select: Odd parity */ -#define UART_LCR_PARITY_EVEN (1 << 4) /*!< UART Parity select: Even parity */ -#define UART_LCR_PARITY_F_1 (2 << 4) /*!< UART Parity select: Forced 1 stick parity */ -#define UART_LCR_PARITY_F_0 (3 << 4) /*!< UART Parity select: Forced 0 stick parity */ -#define UART_LCR_BREAK_EN (1 << 6) /*!< UART Break transmission enable */ -#define UART_LCR_DLAB_EN (1 << 7) /*!< UART Divisor Latches Access bit enable */ -#define UART_LCR_BITMASK (0xFF) /*!< UART line control bit mask */ - -/** - * @brief Macro defines for UART Modem Control Register - */ -#define UART_MCR_DTR_CTRL (1 << 0) /*!< Source for modem output pin DTR */ -#define UART_MCR_RTS_CTRL (1 << 1) /*!< Source for modem output pin RTS */ -#define UART_MCR_LOOPB_EN (1 << 4) /*!< Loop back mode select */ -#define UART_MCR_AUTO_RTS_EN (1 << 6) /*!< Enable Auto RTS flow-control */ -#define UART_MCR_AUTO_CTS_EN (1 << 7) /*!< Enable Auto CTS flow-control */ -#define UART_MCR_BITMASK (0xD3) /*!< UART bit mask value */ - -/** - * @brief Macro defines for UART Line Status Register - */ -#define UART_LSR_RDR (1 << 0) /*!< Line status: Receive data ready */ -#define UART_LSR_OE (1 << 1) /*!< Line status: Overrun error */ -#define UART_LSR_PE (1 << 2) /*!< Line status: Parity error */ -#define UART_LSR_FE (1 << 3) /*!< Line status: Framing error */ -#define UART_LSR_BI (1 << 4) /*!< Line status: Break interrupt */ -#define UART_LSR_THRE (1 << 5) /*!< Line status: Transmit holding register empty */ -#define UART_LSR_TEMT (1 << 6) /*!< Line status: Transmitter empty */ -#define UART_LSR_RXFE (1 << 7) /*!< Line status: Error in RX FIFO */ -#define UART_LSR_TXFE (1 << 8) /*!< Line status: Error in RX FIFO */ -#define UART_LSR_BITMASK (0xFF) /*!< UART Line status bit mask */ -#define UART1_LSR_BITMASK (0x1FF) /*!< UART1 Line status bit mask - valid for 11xx, 18xx/43xx UART0/2/3 only */ - -/** - * @brief Macro defines for UART Modem Status Register - */ -#define UART_MSR_DELTA_CTS (1 << 0) /*!< Modem status: State change of input CTS */ -#define UART_MSR_DELTA_DSR (1 << 1) /*!< Modem status: State change of input DSR */ -#define UART_MSR_LO2HI_RI (1 << 2) /*!< Modem status: Low to high transition of input RI */ -#define UART_MSR_DELTA_DCD (1 << 3) /*!< Modem status: State change of input DCD */ -#define UART_MSR_CTS (1 << 4) /*!< Modem status: Clear To Send State */ -#define UART_MSR_DSR (1 << 5) /*!< Modem status: Data Set Ready State */ -#define UART_MSR_RI (1 << 6) /*!< Modem status: Ring Indicator State */ -#define UART_MSR_DCD (1 << 7) /*!< Modem status: Data Carrier Detect State */ -#define UART_MSR_BITMASK (0xFF) /*!< Modem status: MSR register bit-mask value */ - -/** - * @brief Macro defines for UART Auto baudrate control register - */ -#define UART_ACR_START (1 << 0) /*!< UART Auto-baud start */ -#define UART_ACR_MODE (1 << 1) /*!< UART Auto baudrate Mode 1 */ -#define UART_ACR_AUTO_RESTART (1 << 2) /*!< UART Auto baudrate restart */ -#define UART_ACR_ABEOINT_CLR (1 << 8) /*!< UART End of auto-baud interrupt clear */ -#define UART_ACR_ABTOINT_CLR (1 << 9) /*!< UART Auto-baud time-out interrupt clear */ -#define UART_ACR_BITMASK (0x307) /*!< UART Auto Baudrate register bit mask */ - -/** - * @brief Macro defines for UART RS485 Control register - */ -#define UART_RS485CTRL_NMM_EN (1 << 0) /*!< RS-485/EIA-485 Normal Multi-drop Mode (NMM) is disabled */ -#define UART_RS485CTRL_RX_DIS (1 << 1) /*!< The receiver is disabled */ -#define UART_RS485CTRL_AADEN (1 << 2) /*!< Auto Address Detect (AAD) is enabled */ -#define UART_RS485CTRL_SEL_DTR (1 << 3) /*!< If direction control is enabled (bit DCTRL = 1), pin DTR is - used for direction control */ -#define UART_RS485CTRL_DCTRL_EN (1 << 4) /*!< Enable Auto Direction Control */ -#define UART_RS485CTRL_OINV_1 (1 << 5) /*!< This bit reverses the polarity of the direction - control signal on the RTS (or DTR) pin. The direction control pin - will be driven to logic "1" when the transmitter has data to be sent */ -#define UART_RS485CTRL_BITMASK (0x3F) /*!< RS485 control bit-mask value */ - -/** - * @brief Macro defines for UART IrDA Control Register - valid for 11xx, 17xx/40xx UART0/2/3, 18xx/43xx UART3 only - */ -#define UART_ICR_IRDAEN (1 << 0) /*!< IrDA mode enable */ -#define UART_ICR_IRDAINV (1 << 1) /*!< IrDA serial input inverted */ -#define UART_ICR_FIXPULSE_EN (1 << 2) /*!< IrDA fixed pulse width mode */ -#define UART_ICR_PULSEDIV(n) ((n & 0x07) << 3) /*!< PulseDiv - Configures the pulse when FixPulseEn = 1 */ -#define UART_ICR_BITMASK (0x3F) /*!< UART IRDA bit mask */ - -/** - * @brief Macro defines for UART half duplex register - ???? - */ -#define UART_HDEN_HDEN ((1 << 0)) /*!< enable half-duplex mode*/ - -/** - * @brief Macro defines for UART Smart card interface Control Register - valid for 11xx, 18xx/43xx UART0/2/3 only - */ -#define UART_SCICTRL_SCIEN (1 << 0) /*!< enable asynchronous half-duplex smart card interface*/ -#define UART_SCICTRL_NACKDIS (1 << 1) /*!< NACK response is inhibited*/ -#define UART_SCICTRL_PROTSEL_T1 (1 << 2) /*!< ISO7816-3 protocol T1 is selected*/ -#define UART_SCICTRL_TXRETRY(n) ((n & 0x07) << 5) /*!< number of retransmission*/ -#define UART_SCICTRL_GUARDTIME(n) ((n & 0xFF) << 8) /*!< Extra guard time*/ - -/** - * @brief Macro defines for UART Fractional Divider Register - */ -#define UART_FDR_DIVADDVAL(n) (n & 0x0F) /*!< Baud-rate generation pre-scaler divisor */ -#define UART_FDR_MULVAL(n) ((n << 4) & 0xF0) /*!< Baud-rate pre-scaler multiplier value */ -#define UART_FDR_BITMASK (0xFF) /*!< UART Fractional Divider register bit mask */ - -/** - * @brief Macro defines for UART Tx Enable Register - */ -#define UART_TER1_TXEN (1 << 7) /*!< Transmit enable bit - valid for 11xx, 13xx, 17xx/40xx only */ -#define UART_TER2_TXEN (1 << 0) /*!< Transmit enable bit - valid for 18xx/43xx only */ - -/** - * @brief Macro defines for UART Synchronous Control Register - 11xx, 18xx/43xx UART0/2/3 only - */ -#define UART_SYNCCTRL_SYNC (1 << 0) /*!< enable synchronous mode*/ -#define UART_SYNCCTRL_CSRC_MASTER (1 << 1) /*!< synchronous master mode*/ -#define UART_SYNCCTRL_FES (1 << 2) /*!< sample on falling edge*/ -#define UART_SYNCCTRL_TSBYPASS (1 << 3) /*!< to be defined*/ -#define UART_SYNCCTRL_CSCEN (1 << 4) /*!< Continuous running clock enable (master mode only)*/ -#define UART_SYNCCTRL_STARTSTOPDISABLE (1 << 5) /*!< Do not send start/stop bit*/ -#define UART_SYNCCTRL_CCCLR (1 << 6) /*!< stop continuous clock*/ - -/** - * @brief Enable transmission on UART TxD pin - * @param pUART : Pointer to selected pUART peripheral - * @return Nothing - */ -STATIC INLINE void Chip_UART_TXEnable(LPC_USART_T *pUART) -{ - pUART->TER1 = UART_TER1_TXEN; -} - -/** - * @brief Disable transmission on UART TxD pin - * @param pUART : Pointer to selected pUART peripheral - * @return Nothing - */ -STATIC INLINE void Chip_UART_TXDisable(LPC_USART_T *pUART) -{ - pUART->TER1 = 0; -} - -/** - * @brief Transmit a single data byte through the UART peripheral - * @param pUART : Pointer to selected UART peripheral - * @param data : Byte to transmit - * @return Nothing - * @note This function attempts to place a byte into the UART transmit - * FIFO or transmit hold register regard regardless of UART state - */ -STATIC INLINE void Chip_UART_SendByte(LPC_USART_T *pUART, uint8_t data) -{ - pUART->THR = (uint32_t) data; -} - -/** - * @brief Read a single byte data from the UART peripheral - * @param pUART : Pointer to selected UART peripheral - * @return A single byte of data read - * @note This function reads a byte from the UART receive FIFO or - * receive hold register regard regardless of UART state. The - * FIFO status should be read first prior to using this function - */ -STATIC INLINE uint8_t Chip_UART_ReadByte(LPC_USART_T *pUART) -{ - return (uint8_t) (pUART->RBR & UART_RBR_MASKBIT); -} - -/** - * @brief Enable UART interrupts - * @param pUART : Pointer to selected UART peripheral - * @param intMask : OR'ed Interrupts to enable in the Interrupt Enable Register (IER) - * @return Nothing - * @note Use an OR'ed value of UART_IER_* definitions with this function - * to enable specific UART interrupts. The Divisor Latch Access Bit - * (DLAB) in LCR must be cleared in order to access the IER register. - * This function doesn't alter the DLAB state - */ -STATIC INLINE void Chip_UART_IntEnable(LPC_USART_T *pUART, uint32_t intMask) -{ - pUART->IER |= intMask; -} - -/** - * @brief Disable UART interrupts - * @param pUART : Pointer to selected UART peripheral - * @param intMask : OR'ed Interrupts to disable in the Interrupt Enable Register (IER) - * @return Nothing - * @note Use an OR'ed value of UART_IER_* definitions with this function - * to disable specific UART interrupts. The Divisor Latch Access Bit - * (DLAB) in LCR must be cleared in order to access the IER register. - * This function doesn't alter the DLAB state - */ -STATIC INLINE void Chip_UART_IntDisable(LPC_USART_T *pUART, uint32_t intMask) -{ - pUART->IER &= ~intMask; -} - -/** - * @brief Returns UART interrupts that are enabled - * @param pUART : Pointer to selected UART peripheral - * @return Returns the enabled UART interrupts - * @note Use an OR'ed value of UART_IER_* definitions with this function - * to determine which interrupts are enabled. You can check - * for multiple enabled bits if needed. - */ -STATIC INLINE uint32_t Chip_UART_GetIntsEnabled(LPC_USART_T *pUART) -{ - return pUART->IER; -} - -/** - * @brief Read the Interrupt Identification Register (IIR) - * @param pUART : Pointer to selected UART peripheral - * @return Current pending interrupt status per the IIR register - */ -STATIC INLINE uint32_t Chip_UART_ReadIntIDReg(LPC_USART_T *pUART) -{ - return pUART->IIR; -} - -/** - * @brief Setup the UART FIFOs - * @param pUART : Pointer to selected UART peripheral - * @param fcr : FIFO control register setup OR'ed flags - * @return Nothing - * @note Use OR'ed value of UART_FCR_* definitions with this function - * to select specific options. For example, to enable the FIFOs - * with a RX trip level of 8 characters, use something like - * (UART_FCR_FIFO_EN | UART_FCR_TRG_LEV2) - */ -STATIC INLINE void Chip_UART_SetupFIFOS(LPC_USART_T *pUART, uint32_t fcr) -{ - pUART->FCR = fcr; -} - -/** - * @brief Configure data width, parity and stop bits - * @param pUART : Pointer to selected pUART peripheral - * @param config : UART configuration, OR'ed values of UART_LCR_* defines - * @return Nothing - * @note Select OR'ed config options for the UART from the UART_LCR_* - * definitions. For example, a configuration of 8 data bits, 1 - * stop bit, and even (enabled) parity would be - * (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_EN | UART_LCR_PARITY_EVEN) - */ -STATIC INLINE void Chip_UART_ConfigData(LPC_USART_T *pUART, uint32_t config) -{ - pUART->LCR = config; -} - -/** - * @brief Enable access to Divisor Latches - * @param pUART : Pointer to selected UART peripheral - * @return Nothing - */ -STATIC INLINE void Chip_UART_EnableDivisorAccess(LPC_USART_T *pUART) -{ - pUART->LCR |= UART_LCR_DLAB_EN; -} - -/** - * @brief Disable access to Divisor Latches - * @param pUART : Pointer to selected UART peripheral - * @return Nothing - */ -STATIC INLINE void Chip_UART_DisableDivisorAccess(LPC_USART_T *pUART) -{ - pUART->LCR &= ~UART_LCR_DLAB_EN; -} - -/** - * @brief Set LSB and MSB divisor latch registers - * @param pUART : Pointer to selected UART peripheral - * @param dll : Divisor Latch LSB value - * @param dlm : Divisor Latch MSB value - * @return Nothing - * @note The Divisor Latch Access Bit (DLAB) in LCR must be set in - * order to access the USART Divisor Latches. This function - * doesn't alter the DLAB state. - */ -STATIC INLINE void Chip_UART_SetDivisorLatches(LPC_USART_T *pUART, uint8_t dll, uint8_t dlm) -{ - pUART->DLL = (uint32_t) dll; - pUART->DLM = (uint32_t) dlm; -} - -/** - * @brief Return modem control register/status - * @param pUART : Pointer to selected UART peripheral - * @return Modem control register (status) - * @note Mask bits of the returned status value with UART_MCR_* - * definitions for specific statuses. - */ -STATIC INLINE uint32_t Chip_UART_ReadModemControl(LPC_USART_T *pUART) -{ - return pUART->MCR; -} - -/** - * @brief Set modem control register/status - * @param pUART : Pointer to selected UART peripheral - * @param mcr : Modem control register flags to set - * @return Nothing - * @note Use an Or'ed value of UART_MCR_* definitions with this - * call to set specific options. - */ -STATIC INLINE void Chip_UART_SetModemControl(LPC_USART_T *pUART, uint32_t mcr) -{ - pUART->MCR |= mcr; -} - -/** - * @brief Clear modem control register/status - * @param pUART : Pointer to selected UART peripheral - * @param mcr : Modem control register flags to clear - * @return Nothing - * @note Use an Or'ed value of UART_MCR_* definitions with this - * call to clear specific options. - */ -STATIC INLINE void Chip_UART_ClearModemControl(LPC_USART_T *pUART, uint32_t mcr) -{ - pUART->MCR &= ~mcr; -} - -/** - * @brief Return Line Status register/status (LSR) - * @param pUART : Pointer to selected UART peripheral - * @return Line Status register (status) - * @note Mask bits of the returned status value with UART_LSR_* - * definitions for specific statuses. - */ -STATIC INLINE uint32_t Chip_UART_ReadLineStatus(LPC_USART_T *pUART) -{ - return pUART->LSR; -} - -/** - * @brief Return Modem Status register/status (MSR) - * @param pUART : Pointer to selected UART peripheral - * @return Modem Status register (status) - * @note Mask bits of the returned status value with UART_MSR_* - * definitions for specific statuses. - */ -STATIC INLINE uint32_t Chip_UART_ReadModemStatus(LPC_USART_T *pUART) -{ - return pUART->MSR; -} - -/** - * @brief Write a byte to the scratchpad register - * @param pUART : Pointer to selected UART peripheral - * @param data : Byte value to write - * @return Nothing - */ -STATIC INLINE void Chip_UART_SetScratch(LPC_USART_T *pUART, uint8_t data) -{ - pUART->SCR = (uint32_t) data; -} - -/** - * @brief Returns current byte value in the scratchpad register - * @param pUART : Pointer to selected UART peripheral - * @return Byte value read from scratchpad register - */ -STATIC INLINE uint8_t Chip_UART_ReadScratch(LPC_USART_T *pUART) -{ - return (uint8_t) (pUART->SCR & 0xFF); -} - -/** - * @brief Set autobaud register options - * @param pUART : Pointer to selected UART peripheral - * @param acr : Or'ed values to set for ACR register - * @return Nothing - * @note Use an Or'ed value of UART_ACR_* definitions with this - * call to set specific options. - */ -STATIC INLINE void Chip_UART_SetAutoBaudReg(LPC_USART_T *pUART, uint32_t acr) -{ - pUART->ACR |= acr; -} - -/** - * @brief Clear autobaud register options - * @param pUART : Pointer to selected UART peripheral - * @param acr : Or'ed values to clear for ACR register - * @return Nothing - * @note Use an Or'ed value of UART_ACR_* definitions with this - * call to clear specific options. - */ -STATIC INLINE void Chip_UART_ClearAutoBaudReg(LPC_USART_T *pUART, uint32_t acr) -{ - pUART->ACR &= ~acr; -} - -/** - * @brief Set RS485 control register options - * @param pUART : Pointer to selected UART peripheral - * @param ctrl : Or'ed values to set for RS485 control register - * @return Nothing - * @note Use an Or'ed value of UART_RS485CTRL_* definitions with this - * call to set specific options. - */ -STATIC INLINE void Chip_UART_SetRS485Flags(LPC_USART_T *pUART, uint32_t ctrl) -{ - pUART->RS485CTRL |= ctrl; -} - -/** - * @brief Clear RS485 control register options - * @param pUART : Pointer to selected UART peripheral - * @param ctrl : Or'ed values to clear for RS485 control register - * @return Nothing - * @note Use an Or'ed value of UART_RS485CTRL_* definitions with this - * call to clear specific options. - */ -STATIC INLINE void Chip_UART_ClearRS485Flags(LPC_USART_T *pUART, uint32_t ctrl) -{ - pUART->RS485CTRL &= ~ctrl; -} - -/** - * @brief Set RS485 address match value - * @param pUART : Pointer to selected UART peripheral - * @param addr : Address match value for RS-485/EIA-485 mode - * @return Nothing - */ -STATIC INLINE void Chip_UART_SetRS485Addr(LPC_USART_T *pUART, uint8_t addr) -{ - pUART->RS485ADRMATCH = (uint32_t) addr; -} - -/** - * @brief Read RS485 address match value - * @param pUART : Pointer to selected UART peripheral - * @return Address match value for RS-485/EIA-485 mode - */ -STATIC INLINE uint8_t Chip_UART_GetRS485Addr(LPC_USART_T *pUART) -{ - return (uint8_t) (pUART->RS485ADRMATCH & 0xFF); -} - -/** - * @brief Set RS485 direction control (RTS or DTR) delay value - * @param pUART : Pointer to selected UART peripheral - * @param dly : direction control (RTS or DTR) delay value - * @return Nothing - * @note This delay time is in periods of the baud clock. Any delay - * time from 0 to 255 bit times may be programmed. - */ -STATIC INLINE void Chip_UART_SetRS485Delay(LPC_USART_T *pUART, uint8_t dly) -{ - pUART->RS485DLY = (uint32_t) dly; -} - -/** - * @brief Read RS485 direction control (RTS or DTR) delay value - * @param pUART : Pointer to selected UART peripheral - * @return direction control (RTS or DTR) delay value - * @note This delay time is in periods of the baud clock. Any delay - * time from 0 to 255 bit times may be programmed. - */ -STATIC INLINE uint8_t Chip_UART_GetRS485Delay(LPC_USART_T *pUART) -{ - return (uint8_t) (pUART->RS485DLY & 0xFF); -} - -/** - * @brief Initializes the pUART peripheral - * @param pUART : Pointer to selected pUART peripheral - * @return Nothing - */ -void Chip_UART_Init(LPC_USART_T *pUART); - -/** - * @brief De-initializes the pUART peripheral. - * @param pUART : Pointer to selected pUART peripheral - * @return Nothing - */ -void Chip_UART_DeInit(LPC_USART_T *pUART); - -/** - * @brief Transmit a byte array through the UART peripheral (non-blocking) - * @param pUART : Pointer to selected UART peripheral - * @param data : Pointer to bytes to transmit - * @param numBytes : Number of bytes to transmit - * @return The actual number of bytes placed into the FIFO - * @note This function places data into the transmit FIFO until either - * all the data is in the FIFO or the FIFO is full. This function - * will not block in the FIFO is full. The actual number of bytes - * placed into the FIFO is returned. This function ignores errors. - */ -int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes); - -/** - * @brief Read data through the UART peripheral (non-blocking) - * @param pUART : Pointer to selected UART peripheral - * @param data : Pointer to bytes array to fill - * @param numBytes : Size of the passed data array - * @return The actual number of bytes read - * @note This function reads data from the receive FIFO until either - * all the data has been read or the passed buffer is completely full. - * This function will not block. This function ignores errors. - */ -int Chip_UART_Read(LPC_USART_T *pUART, void *data, int numBytes); - -/** - * @brief Sets best dividers to get a target bit rate (without fractional divider) - * @param pUART : Pointer to selected UART peripheral - * @param baudrate : Target baud rate (baud rate = bit rate) - * @return The actual baud rate, or 0 if no rate can be found - */ -uint32_t Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate); - -/** - * @brief Sets best dividers to get a target bit rate (with fractional divider) - * @param pUART : Pointer to selected UART peripheral - * @param baudrate : Target baud rate (baud rate = bit rate) - * @return The actual baud rate, or 0 if no rate can be found - */ -uint32_t Chip_UART_SetBaudFDR(LPC_USART_T *pUART, uint32_t baudrate); - -/** - * @brief Transmit a byte array through the UART peripheral (blocking) - * @param pUART : Pointer to selected UART peripheral - * @param data : Pointer to data to transmit - * @param numBytes : Number of bytes to transmit - * @return The number of bytes transmitted - * @note This function will send or place all bytes into the transmit - * FIFO. This function will block until the last bytes are in the FIFO. - */ -int Chip_UART_SendBlocking(LPC_USART_T *pUART, const void *data, int numBytes); - -/** - * @brief Read data through the UART peripheral (blocking) - * @param pUART : Pointer to selected UART peripheral - * @param data : Pointer to data array to fill - * @param numBytes : Size of the passed data array - * @return The size of the dat array - * @note This function reads data from the receive FIFO until the passed - * buffer is completely full. The function will block until full. - * This function ignores errors. - */ -int Chip_UART_ReadBlocking(LPC_USART_T *pUART, void *data, int numBytes); - -/** - * @brief UART receive-only interrupt handler for ring buffers - * @param pUART : Pointer to selected UART peripheral - * @param pRB : Pointer to ring buffer structure to use - * @return Nothing - * @note If ring buffer support is desired for the receive side - * of data transfer, the UART interrupt should call this - * function for a receive based interrupt status. - */ -void Chip_UART_RXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB); - -/** - * @brief UART transmit-only interrupt handler for ring buffers - * @param pUART : Pointer to selected UART peripheral - * @param pRB : Pointer to ring buffer structure to use - * @return Nothing - * @note If ring buffer support is desired for the transmit side - * of data transfer, the UART interrupt should call this - * function for a transmit based interrupt status. - */ -void Chip_UART_TXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB); - -/** - * @brief Populate a transmit ring buffer and start UART transmit - * @param pUART : Pointer to selected UART peripheral - * @param pRB : Pointer to ring buffer structure to use - * @param data : Pointer to buffer to move to ring buffer - * @param bytes : Number of bytes to move - * @return The number of bytes placed into the ring buffer - * @note Will move the data into the TX ring buffer and start the - * transfer. If the number of bytes returned is less than the - * number of bytes to send, the ring buffer is considered full. - */ -uint32_t Chip_UART_SendRB(LPC_USART_T *pUART, RINGBUFF_T *pRB, const void *data, int bytes); - -/** - * @brief Copy data from a receive ring buffer - * @param pUART : Pointer to selected UART peripheral - * @param pRB : Pointer to ring buffer structure to use - * @param data : Pointer to buffer to fill from ring buffer - * @param bytes : Size of the passed buffer in bytes - * @return The number of bytes placed into the ring buffer - * @note Will move the data from the RX ring buffer up to the - * the maximum passed buffer size. Returns 0 if there is - * no data in the ring buffer. - */ -int Chip_UART_ReadRB(LPC_USART_T *pUART, RINGBUFF_T *pRB, void *data, int bytes); - -/** - * @brief UART receive/transmit interrupt handler for ring buffers - * @param pUART : Pointer to selected UART peripheral - * @param pRXRB : Pointer to transmit ring buffer - * @param pTXRB : Pointer to receive ring buffer - * @return Nothing - * @note This provides a basic implementation of the UART IRQ - * handler for support of a ring buffer implementation for - * transmit and receive. - */ -void Chip_UART_IRQRBHandler(LPC_USART_T *pUART, RINGBUFF_T *pRXRB, RINGBUFF_T *pTXRB); - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __UART_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/wwdt_11xx.h b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/wwdt_11xx.h deleted file mode 100755 index 9dfdff808b..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/inc/wwdt_11xx.h +++ /dev/null @@ -1,266 +0,0 @@ -/* - * @brief LPC11xx WWDT chip driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#ifndef __WWDT_11XX_H_ -#define __WWDT_11XX_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -/** @defgroup WWDT_11XX CHIP: LPC11xx Windowed Watchdog driver - * @ingroup CHIP_11XX_Drivers - * @{ - */ - -#if !defined(CHIP_LPC11CXX) || defined(CHIP_LPC1125) -#define WATCHDOG_WINDOW_SUPPORT -#endif - -#if defined(CHIP_LPC11AXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC11UXX) -#define WATCHDOG_CLKSEL_SUPPORT -#endif - -/** - * @brief Windowed Watchdog register block structure - */ -typedef struct { /*!< WWDT Structure */ - __IO uint32_t MOD; /*!< Watchdog mode register. This register contains the basic mode and status of the Watchdog Timer. */ - __IO uint32_t TC; /*!< Watchdog timer constant register. This register determines the time-out value. */ - __O uint32_t FEED; /*!< Watchdog feed sequence register. Writing 0xAA followed by 0x55 to this register reloads the Watchdog timer with the value contained in WDTC. */ - __I uint32_t TV; /*!< Watchdog timer value register. This register reads out the current value of the Watchdog timer. */ -#ifdef WATCHDOG_CLKSEL_SUPPORT - __IO uint32_t CLKSEL; /*!< Watchdog clock select register. */ -#else - __I uint32_t RESERVED0; -#endif -#ifdef WATCHDOG_WINDOW_SUPPORT - __IO uint32_t WARNINT; /*!< Watchdog warning interrupt register. This register contains the Watchdog warning interrupt compare value. */ - __IO uint32_t WINDOW; /*!< Watchdog timer window register. This register contains the Watchdog window value. */ -#endif -} LPC_WWDT_T; - -/** - * @brief Watchdog Mode register definitions - */ -/** Watchdog Mode Bitmask */ -#define WWDT_WDMOD_BITMASK ((uint32_t) 0x1F) -/** WWDT interrupt enable bit */ -#define WWDT_WDMOD_WDEN ((uint32_t) (1 << 0)) -/** WWDT interrupt enable bit */ -#define WWDT_WDMOD_WDRESET ((uint32_t) (1 << 1)) -/** WWDT time out flag bit */ -#define WWDT_WDMOD_WDTOF ((uint32_t) (1 << 2)) -/** WDT Time Out flag bit */ -#define WWDT_WDMOD_WDINT ((uint32_t) (1 << 3)) -/** WWDT Protect flag bit */ -#define WWDT_WDMOD_WDPROTECT ((uint32_t) (1 << 4)) - -/** - * @brief Initialize the Watchdog timer - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return None - */ -void Chip_WWDT_Init(LPC_WWDT_T *pWWDT); - -/** - * @brief Shutdown the Watchdog timer - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return None - */ -void Chip_WWDT_DeInit(LPC_WWDT_T *pWWDT); - -/** - * @brief Set WDT timeout constant value used for feed - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX - * @return none - */ -STATIC INLINE void Chip_WWDT_SetTimeOut(LPC_WWDT_T *pWWDT, uint32_t timeout) -{ - pWWDT->TC = timeout; -} - -/** - * @brief Feed watchdog timer - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return None - * @note If this function isn't called, a watchdog timer warning will occur. - * After the warning, a timeout will occur if a feed has happened. - */ -STATIC INLINE void Chip_WWDT_Feed(LPC_WWDT_T *pWWDT) -{ - pWWDT->FEED = 0xAA; - pWWDT->FEED = 0x55; -} - -#if defined(WATCHDOG_WINDOW_SUPPORT) -/** - * @brief Set WWDT warning interrupt - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param timeout : WDT warning in ticks, between 0 and 1023 - * @return None - * @note This is the number of ticks after the watchdog interrupt that the - * warning interrupt will be generated. - */ -STATIC INLINE void Chip_WWDT_SetWarning(LPC_WWDT_T *pWWDT, uint32_t timeout) -{ - pWWDT->WARNINT = timeout; -} - -/** - * @brief Set WWDT window time - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param timeout : WDT timeout in ticks, between WWDT_TICKS_MIN and WWDT_TICKS_MAX - * @return None - * @note The watchdog timer must be fed between the timeout from the Chip_WWDT_SetTimeOut() - * function and this function, with this function defining the last tick before the - * watchdog window interrupt occurs. - */ -STATIC INLINE void Chip_WWDT_SetWindow(LPC_WWDT_T *pWWDT, uint32_t timeout) -{ - pWWDT->WINDOW = timeout; -} - -#endif - -/** - * @brief Enable watchdog timer options - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param options : An or'ed set of options of values - * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT - * @return None - * @note You can enable more than one option at once (ie, WWDT_WDMOD_WDRESET | - * WWDT_WDMOD_WDPROTECT), but use the WWDT_WDMOD_WDEN after all other options - * are set (or unset) with no other options. If WWDT_WDMOD_LOCK is used, it cannot - * be unset. - */ -STATIC INLINE void Chip_WWDT_SetOption(LPC_WWDT_T *pWWDT, uint32_t options) -{ - pWWDT->MOD |= options; -} - -/** - * @brief Disable/clear watchdog timer options - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param options : An or'ed set of options of values - * WWDT_WDMOD_WDEN, WWDT_WDMOD_WDRESET, and WWDT_WDMOD_WDPROTECT - * @return None - * @note You can disable more than one option at once (ie, WWDT_WDMOD_WDRESET | - * WWDT_WDMOD_WDTOF). - */ -STATIC INLINE void Chip_WWDT_UnsetOption(LPC_WWDT_T *pWWDT, uint32_t options) -{ - pWWDT->MOD &= (~options) & WWDT_WDMOD_BITMASK; -} - -/** - * @brief Enable WWDT activity - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return None - */ -STATIC INLINE void Chip_WWDT_Start(LPC_WWDT_T *pWWDT) -{ - Chip_WWDT_SetOption(pWWDT, WWDT_WDMOD_WDEN); - Chip_WWDT_Feed(pWWDT); -} - -/** - * @brief Read WWDT status flag - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return Watchdog status, an Or'ed value of WWDT_WDMOD_* - */ -STATIC INLINE uint32_t Chip_WWDT_GetStatus(LPC_WWDT_T *pWWDT) -{ - return pWWDT->MOD; -} - -/** - * @brief Clear WWDT interrupt status flags - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param status : Or'ed value of status flag(s) that you want to clear, should be: - * - WWDT_WDMOD_WDTOF: Clear watchdog timeout flag - * - WWDT_WDMOD_WDINT: Clear watchdog warning flag - * @return None - */ -void Chip_WWDT_ClearStatusFlag(LPC_WWDT_T *pWWDT, uint32_t status); - -/** - * @brief Get the current value of WDT - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @return current value of WDT - */ -STATIC INLINE uint32_t Chip_WWDT_GetCurrentCount(LPC_WWDT_T *pWWDT) -{ - return pWWDT->TV; -} - -#if defined(WATCHDOG_CLKSEL_SUPPORT) -/** - * @brief Watchdog Timer Clock Source Selection register definitions - */ -/** Clock source select bitmask */ -#define WWDT_CLKSEL_BITMASK ((uint32_t) 0x10000003) -/** Clock source select */ -#define WWDT_CLKSEL_SOURCE(n) ((uint32_t) (n & 0x03)) -/** Lock the clock source selection */ -#define WWDT_CLKSEL_LOCK ((uint32_t) (1 << 31)) - -/** - * @brief Watchdog Clock Source definitions - */ -typedef enum { - WWDT_CLKSRC_IRC = WWDT_CLKSEL_SOURCE(0), /*!< Internal RC oscillator */ - WWDT_CLKSRC_WATCHDOG_WDOSC = WWDT_CLKSEL_SOURCE(1), /*!< Watchdog oscillator (WDOSC) */ -} CHIP_WWDT_CLK_SRC_T; - -/** - * @brief Get the current value of WDT - * @param pWWDT : The base of WatchDog Timer peripheral on the chip - * @param wdtClkSrc : Selected watchdog clock source - * @return Nothing - */ -STATIC INLINE void Chip_WWDT_SelClockSource(LPC_WWDT_T *pWWDT, CHIP_WWDT_CLK_SRC_T wdtClkSrc) -{ - pWWDT->CLKSEL = wdtClkSrc & WWDT_CLKSEL_BITMASK; -} - -#endif - -/** - * @} - */ - -#ifdef __cplusplus -} -#endif - -#endif /* __WWDT_11XX_H_ */ diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/clock_11xx.c b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/clock_11xx.c deleted file mode 100755 index bd6b953abb..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/clock_11xx.c +++ /dev/null @@ -1,285 +0,0 @@ -/* - * @brief LPC11XX System clock control functions - * - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#include "chip.h" - -/***************************************************************************** - * Private types/enumerations/variables - ****************************************************************************/ - -/* Inprecise clock rates for the watchdog oscillator */ -STATIC const uint32_t wdtOSCRate[WDTLFO_OSC_4_60 + 1] = { - 0, /* WDT_OSC_ILLEGAL */ - 600000, /* WDT_OSC_0_60 */ - 1050000, /* WDT_OSC_1_05 */ - 1400000, /* WDT_OSC_1_40 */ - 1750000, /* WDT_OSC_1_75 */ - 2100000, /* WDT_OSC_2_10 */ - 2400000, /* WDT_OSC_2_40 */ - 2700000, /* WDT_OSC_2_70 */ - 3000000, /* WDT_OSC_3_00 */ - 3250000, /* WDT_OSC_3_25 */ - 3500000, /* WDT_OSC_3_50 */ - 3750000, /* WDT_OSC_3_75 */ - 4000000, /* WDT_OSC_4_00 */ - 4200000, /* WDT_OSC_4_20 */ - 4400000, /* WDT_OSC_4_40 */ - 4600000 /* WDT_OSC_4_60 */ -}; - -/***************************************************************************** - * Public types/enumerations/variables - ****************************************************************************/ - -/***************************************************************************** - * Private functions - ****************************************************************************/ - -/* Compute a WDT or LFO rate */ -STATIC uint32_t Chip_Clock_GetWDTLFORate(uint32_t reg) -{ - uint32_t div; - CHIP_WDTLFO_OSC_T clk; - - /* Get WDT oscillator settings */ - clk = (CHIP_WDTLFO_OSC_T) ((reg >> 5) & 0xF); - div = reg & 0x1F; - - /* Compute clock rate and divided by divde value */ - return wdtOSCRate[clk] / ((div + 1) << 1); -} - -/* Compute a PLL frequency */ -STATIC uint32_t Chip_Clock_GetPLLFreq(uint32_t PLLReg, uint32_t inputRate) -{ - uint32_t msel = ((PLLReg & 0x1F) + 1); - - return inputRate * msel; -} - -/***************************************************************************** - * Public functions - ****************************************************************************/ - -/* Set System PLL clock source */ -void Chip_Clock_SetSystemPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src) -{ - LPC_SYSCTL->SYSPLLCLKSEL = (uint32_t) src; - LPC_SYSCTL->SYSPLLCLKUEN = 0; - LPC_SYSCTL->SYSPLLCLKUEN = 1; -} - -/* Bypass System Oscillator and set oscillator frequency range */ -void Chip_Clock_SetPLLBypass(bool bypass, bool highfr) -{ - uint32_t ctrl = 0; - - if (bypass) { - ctrl |= (1 << 0); - } - if (highfr) { - ctrl |= (1 << 1); - } - - LPC_SYSCTL->SYSOSCCTRL = ctrl; -} - -#if defined(CHIP_LPC11UXX) -/* Set USB PLL clock source */ -void Chip_Clock_SetUSBPLLSource(CHIP_SYSCTL_PLLCLKSRC_T src) -{ - LPC_SYSCTL->USBPLLCLKSEL = (uint32_t) src; - LPC_SYSCTL->USBPLLCLKUEN = 0; - LPC_SYSCTL->USBPLLCLKUEN = 1; -} - -#endif - -/* Set main system clock source */ -void Chip_Clock_SetMainClockSource(CHIP_SYSCTL_MAINCLKSRC_T src) -{ - LPC_SYSCTL->MAINCLKSEL = (uint32_t) src; - LPC_SYSCTL->MAINCLKUEN = 0; - LPC_SYSCTL->MAINCLKUEN = 1; -} - -#if defined(CHIP_LPC11UXX) -/* Set USB clock source and divider */ -void Chip_Clock_SetUSBClockSource(CHIP_SYSCTL_USBCLKSRC_T src, uint32_t div) -{ - LPC_SYSCTL->USBCLKSEL = (uint32_t) src; - LPC_SYSCTL->USBCLKUEN = 0; - LPC_SYSCTL->USBCLKUEN = 1; - LPC_SYSCTL->USBCLKDIV = div; -} - -#endif /*CHIP_LPC11UXX*/ - -#if defined(CHIP_LPC110X) || defined(CHIP_LPC11XXLV) || defined(CHIP_LPC11CXX) || defined(CHIP_LPC11EXX) || defined(CHIP_LPC1125) -/* Set WDT clock source and divider */ -void Chip_Clock_SetWDTClockSource(CHIP_SYSCTL_WDTCLKSRC_T src, uint32_t div) -{ - LPC_SYSCTL->WDTCLKSEL = (uint32_t) src; - LPC_SYSCTL->WDTCLKUEN = 0; - LPC_SYSCTL->WDTCLKUEN = 1; - LPC_SYSCTL->WDTCLKDIV = div; -} - -#endif - -#if !defined(CHIP_LPC110X) -/* Set CLKOUT clock source and divider */ -void Chip_Clock_SetCLKOUTSource(CHIP_SYSCTL_CLKOUTSRC_T src, uint32_t div) -{ - LPC_SYSCTL->CLKOUTSEL = (uint32_t) src; - LPC_SYSCTL->CLKOUTUEN = 0; - LPC_SYSCTL->CLKOUTUEN = 1; - LPC_SYSCTL->CLKOUTDIV = div; -} - -#endif - -/* Return estimated watchdog oscillator rate */ -uint32_t Chip_Clock_GetWDTOSCRate(void) -{ - return Chip_Clock_GetWDTLFORate(LPC_SYSCTL->WDTOSCCTRL); -} - -#if defined(CHIP_LPC11AXX) -/* Return estimated low frequency oscillator rate */ -uint32_t Chip_Clock_GetLFOOSCRate(void) -{ - return Chip_Clock_GetWDTLFORate(LPC_SYSCTL->LFOSCCTRL); -} - -#endif - -/* Return System PLL input clock rate */ -uint32_t Chip_Clock_GetSystemPLLInClockRate(void) -{ - uint32_t clkRate; - - switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->SYSPLLCLKSEL & 0x3)) { - case SYSCTL_PLLCLKSRC_IRC: - clkRate = Chip_Clock_GetIntOscRate(); - break; - - case SYSCTL_PLLCLKSRC_MAINOSC: - clkRate = Chip_Clock_GetMainOscRate(); - break; - -#if defined(CHIP_LPC11AXX) - case SYSCTL_PLLCLKSRC_EXT_CLKIN: - clkRate = Chip_Clock_GetExtClockInRate(); - break; -#endif - - default: - clkRate = 0; - } - - return clkRate; -} - -/* Return System PLL output clock rate */ -uint32_t Chip_Clock_GetSystemPLLOutClockRate(void) -{ - return Chip_Clock_GetPLLFreq(LPC_SYSCTL->SYSPLLCTRL, - Chip_Clock_GetSystemPLLInClockRate()); -} - -#if defined(CHIP_LPC11UXX) -/* Return USB PLL input clock rate */ -uint32_t Chip_Clock_GetUSBPLLInClockRate(void) -{ - uint32_t clkRate; - - switch ((CHIP_SYSCTL_PLLCLKSRC_T) (LPC_SYSCTL->USBPLLCLKSEL & 0x3)) { - case SYSCTL_PLLCLKSRC_IRC: - clkRate = Chip_Clock_GetIntOscRate(); - break; - - case SYSCTL_PLLCLKSRC_MAINOSC: - clkRate = Chip_Clock_GetMainOscRate(); - break; - - default: - clkRate = 0; - } - - return clkRate; -} - -/* Return USB PLL output clock rate */ -uint32_t Chip_Clock_GetUSBPLLOutClockRate(void) -{ - return Chip_Clock_GetPLLFreq(LPC_SYSCTL->USBPLLCTRL, - Chip_Clock_GetUSBPLLInClockRate()); -} - -#endif - -/* Return main clock rate */ -uint32_t Chip_Clock_GetMainClockRate(void) -{ - uint32_t clkRate = 0; - - switch ((CHIP_SYSCTL_MAINCLKSRC_T) (LPC_SYSCTL->MAINCLKSEL & 0x3)) { - case SYSCTL_MAINCLKSRC_IRC: - clkRate = Chip_Clock_GetIntOscRate(); - break; - - case SYSCTL_MAINCLKSRC_PLLIN: - clkRate = Chip_Clock_GetSystemPLLInClockRate(); - break; - -#if defined(CHIP_LPC11AXX) - case SYSCTL_MAINCLKSRC_LFOSC: - clkRate = Chip_Clock_GetLFOOSCRate(); - break; - -#else - case SYSCTL_MAINCLKSRC_WDTOSC: - clkRate = Chip_Clock_GetWDTOSCRate(); - break; -#endif - - case SYSCTL_MAINCLKSRC_PLLOUT: - clkRate = Chip_Clock_GetSystemPLLOutClockRate(); - break; - } - - return clkRate; -} - -/* Return system clock rate */ -uint32_t Chip_Clock_GetSystemClockRate(void) -{ - /* No point in checking for divide by 0 */ - return Chip_Clock_GetMainClockRate() / LPC_SYSCTL->SYSAHBCLKDIV; -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/uart_11xx.c b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/uart_11xx.c deleted file mode 100644 index ae404b0dc0..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/uart_11xx.c +++ /dev/null @@ -1,289 +0,0 @@ -/* - * @brief LPC11xx UART chip driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -#include "chip.h" - -#if __GNUC__ -# pragma GCC diagnostic ignored "-Wsign-conversion" -# pragma GCC diagnostic ignored "-Wconversion" -# pragma GCC diagnostic ignored "-Wmissing-declarations" -# pragma GCC diagnostic ignored "-Wunused-parameter" -#endif - -/***************************************************************************** - * Private types/enumerations/variables - ****************************************************************************/ - -/***************************************************************************** - * Public types/enumerations/variables - ****************************************************************************/ - -/***************************************************************************** - * Private functions - ****************************************************************************/ - -/***************************************************************************** - * Public functions - ****************************************************************************/ - -/* Initializes the pUART peripheral */ -void Chip_UART_Init(LPC_USART_T *pUART) -{ - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_UART0); - Chip_Clock_SetUARTClockDiv(1); - - /* Enable FIFOs by default, reset them */ - Chip_UART_SetupFIFOS(pUART, (UART_FCR_FIFO_EN | UART_FCR_RX_RS | UART_FCR_TX_RS)); - - /* Default 8N1, with DLAB disabled */ - Chip_UART_ConfigData(pUART, (UART_LCR_WLEN8 | UART_LCR_SBS_1BIT | UART_LCR_PARITY_DIS)); - - /* Disable fractional divider */ - pUART->FDR = 0x10; -} - -/* De-initializes the pUART peripheral */ -void Chip_UART_DeInit(LPC_USART_T *pUART) -{ - Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_UART0); -} - -/* Transmit a byte array through the UART peripheral (non-blocking) */ -int Chip_UART_Send(LPC_USART_T *pUART, const void *data, int numBytes) -{ - int sent = 0; - uint8_t *p8 = (uint8_t *) data; - - /* Send until the transmit FIFO is full or out of bytes */ - while ((sent < numBytes) && - ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0)) { - Chip_UART_SendByte(pUART, *p8); - p8++; - sent++; - } - - return sent; -} - -/* Transmit a byte array through the UART peripheral (blocking) */ -int Chip_UART_SendBlocking(LPC_USART_T *pUART, const void *data, int numBytes) -{ - int pass, sent = 0; - uint8_t *p8 = (uint8_t *) data; - - while (numBytes > 0) { - pass = Chip_UART_Send(pUART, p8, numBytes); - numBytes -= pass; - sent += pass; - p8 += pass; - } - - return sent; -} - -/* Read data through the UART peripheral (non-blocking) */ -int Chip_UART_Read(LPC_USART_T *pUART, void *data, int numBytes) -{ - int readBytes = 0; - uint8_t *p8 = (uint8_t *) data; - - /* Send until the transmit FIFO is full or out of bytes */ - while ((readBytes < numBytes) && - ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) != 0)) { - *p8 = Chip_UART_ReadByte(pUART); - p8++; - readBytes++; - } - - return readBytes; -} - -/* Read data through the UART peripheral (blocking) */ -int Chip_UART_ReadBlocking(LPC_USART_T *pUART, void *data, int numBytes) -{ - int pass, readBytes = 0; - uint8_t *p8 = (uint8_t *) data; - - while (readBytes < numBytes) { - pass = Chip_UART_Read(pUART, p8, numBytes); - numBytes -= pass; - readBytes += pass; - p8 += pass; - } - - return readBytes; -} - -/* Determines and sets best dividers to get a target bit rate */ -uint32_t Chip_UART_SetBaud(LPC_USART_T *pUART, uint32_t baudrate) -{ - uint32_t div, divh, divl, clkin; - - /* Determine UART clock in rate without FDR */ - clkin = Chip_Clock_GetMainClockRate(); - div = clkin / (baudrate * 16); - - /* High and low halves of the divider */ - divh = div / 256; - divl = div - (divh * 256); - - Chip_UART_EnableDivisorAccess(pUART); - Chip_UART_SetDivisorLatches(pUART, divl, divh); - Chip_UART_DisableDivisorAccess(pUART); - - /* Fractional FDR alreadt setup for 1 in UART init */ - - return clkin / div; -} - -/* UART receive-only interrupt handler for ring buffers */ -void Chip_UART_RXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) -{ - /* New data will be ignored if data not popped in time */ - while (Chip_UART_ReadLineStatus(pUART) & UART_LSR_RDR) { - uint8_t ch = Chip_UART_ReadByte(pUART); - RingBuffer_Insert(pRB, &ch); - } -} - -/* UART transmit-only interrupt handler for ring buffers */ -void Chip_UART_TXIntHandlerRB(LPC_USART_T *pUART, RINGBUFF_T *pRB) -{ - uint8_t ch; - - /* Fill FIFO until full or until TX ring buffer is empty */ - while ((Chip_UART_ReadLineStatus(pUART) & UART_LSR_THRE) != 0 && - RingBuffer_Pop(pRB, &ch)) { - Chip_UART_SendByte(pUART, ch); - } -} - -/* Populate a transmit ring buffer and start UART transmit */ -uint32_t Chip_UART_SendRB(LPC_USART_T *pUART, RINGBUFF_T *pRB, const void *data, int bytes) -{ - uint32_t ret; - uint8_t *p8 = (uint8_t *) data; - - /* Don't let UART transmit ring buffer change in the UART IRQ handler */ - Chip_UART_IntDisable(pUART, UART_IER_THREINT); - - /* Move as much data as possible into transmit ring buffer */ - ret = RingBuffer_InsertMult(pRB, p8, bytes); - Chip_UART_TXIntHandlerRB(pUART, pRB); - - /* Add additional data to transmit ring buffer if possible */ - ret += RingBuffer_InsertMult(pRB, (p8 + ret), (bytes - ret)); - - /* Enable UART transmit interrupt */ - Chip_UART_IntEnable(pUART, UART_IER_THREINT); - - return ret; -} - -/* Copy data from a receive ring buffer */ -int Chip_UART_ReadRB(LPC_USART_T *pUART, RINGBUFF_T *pRB, void *data, int bytes) -{ - (void) pUART; - - return RingBuffer_PopMult(pRB, (uint8_t *) data, bytes); -} - -/* UART receive/transmit interrupt handler for ring buffers */ -void Chip_UART_IRQRBHandler(LPC_USART_T *pUART, RINGBUFF_T *pRXRB, RINGBUFF_T *pTXRB) -{ - /* Handle transmit interrupt if enabled */ - if (pUART->IER & UART_IER_THREINT) { - Chip_UART_TXIntHandlerRB(pUART, pTXRB); - - /* Disable transmit interrupt if the ring buffer is empty */ - if (RingBuffer_IsEmpty(pTXRB)) { - Chip_UART_IntDisable(pUART, UART_IER_THREINT); - } - } - - /* Handle receive interrupt */ - Chip_UART_RXIntHandlerRB(pUART, pRXRB); -} - -/* Determines and sets best dividers to get a target baud rate */ -uint32_t Chip_UART_SetBaudFDR(LPC_USART_T *pUART, uint32_t baudrate) - -{ - uint32_t uClk = 0; - uint32_t dval = 0; - uint32_t mval = 0; - uint32_t dl = 0; - uint32_t rate16 = 16 * baudrate; - uint32_t actualRate = 0; - - /* Get Clock rate */ - uClk = Chip_Clock_GetMainClockRate(); - - /* The fractional is calculated as (PCLK % (16 * Baudrate)) / (16 * Baudrate) - * Let's make it to be the ratio DivVal / MulVal - */ - dval = uClk % rate16; - - /* The PCLK / (16 * Baudrate) is fractional - * => dval = pclk % rate16 - * mval = rate16; - * now mormalize the ratio - * dval / mval = 1 / new_mval - * new_mval = mval / dval - * new_dval = 1 - */ - if (dval > 0) { - mval = rate16 / dval; - dval = 1; - - /* In case mval still bigger then 4 bits - * no adjustment require - */ - if (mval > 12) { - dval = 0; - } - } - dval &= 0xf; - mval &= 0xf; - dl = uClk / (rate16 + rate16 *dval / mval); - - /* Update UART registers */ - Chip_UART_EnableDivisorAccess(pUART); - Chip_UART_SetDivisorLatches(pUART, UART_LOAD_DLL(dl), UART_LOAD_DLM(dl)); - Chip_UART_DisableDivisorAccess(pUART); - - /* Set best fractional divider */ - pUART->FDR = (UART_FDR_MULVAL(mval) | UART_FDR_DIVADDVAL(dval)); - - /* Return actual baud rate */ - actualRate = uClk / (16 * dl + 16 * dl * dval / mval); - return actualRate; -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c deleted file mode 100755 index c78656d2ea..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/lpc_chip_11cxx_lib/src/wwdt_11xx.c +++ /dev/null @@ -1,86 +0,0 @@ -/* - * @brief LPC11xx WWDT chip driver - * - * @note - * Copyright(C) NXP Semiconductors, 2012 - * All rights reserved. - * - * @par - * Software that is described herein is for illustrative purposes only - * which provides customers with programming information regarding the - * LPC products. This software is supplied "AS IS" without any warranties of - * any kind, and NXP Semiconductors and its licensor disclaim any and - * all warranties, express or implied, including all implied warranties of - * merchantability, fitness for a particular purpose and non-infringement of - * intellectual property rights. NXP Semiconductors assumes no responsibility - * or liability for the use of the software, conveys no license or rights under any - * patent, copyright, mask work right, or any other intellectual property rights in - * or to any products. NXP Semiconductors reserves the right to make changes - * in the software without notification. NXP Semiconductors also makes no - * representation or warranty that such application will be suitable for the - * specified use without further testing or modification. - * - * @par - * Permission to use, copy, modify, and distribute this software and its - * documentation is hereby granted, under NXP Semiconductors' and its - * licensor's relevant copyrights in the software, without fee, provided that it - * is used in conjunction with NXP Semiconductors microcontrollers. This - * copyright, permission, and disclaimer notice must appear in all copies of - * this code. - */ - -/* - * Compiler warning fixes - * Pavel Kirienko, 2014 - */ - -#include "chip.h" - -/***************************************************************************** - * Private types/enumerations/variables - ****************************************************************************/ - -/***************************************************************************** - * Public types/enumerations/variables - ****************************************************************************/ - -/***************************************************************************** - * Private functions - ****************************************************************************/ - -/***************************************************************************** - * Public functions - ****************************************************************************/ - -/* Initialize the Watchdog timer */ -void Chip_WWDT_Init(LPC_WWDT_T *pWWDT) -{ - Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_WDT); - - /* Disable watchdog */ - pWWDT->MOD = 0; - pWWDT->TC = 0xFF; -#if defined(WATCHDOG_WINDOW_SUPPORT) - pWWDT->WARNINT = 0xFFFF; - pWWDT->WINDOW = 0xFFFFFF; -#endif -} - -/* Shutdown the Watchdog timer */ -void Chip_WWDT_DeInit(LPC_WWDT_T *pWWDT) -{ - (void)pWWDT; - Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_WDT); -} - -/* Clear WWDT interrupt status flags */ -void Chip_WWDT_ClearStatusFlag(LPC_WWDT_T *pWWDT, uint32_t status) -{ - if (status & WWDT_WDMOD_WDTOF) { - pWWDT->MOD &= (~WWDT_WDMOD_WDTOF) & WWDT_WDMOD_BITMASK; - } - - if (status & WWDT_WDMOD_WDINT) { - pWWDT->MOD |= WWDT_WDMOD_WDINT; - } -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp deleted file mode 100644 index 9f81263c06..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/main.cpp +++ /dev/null @@ -1,277 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -/* - * GCC 4.9 cannot generate a working binary with higher optimization levels, although - * rest of the firmware can be compiled with -Os. - * GCC 4.8 and earlier don't work at all on this firmware. - */ -#if __GNUC__ -# pragma GCC optimize 1 -#endif - -/** - * This function re-defines the standard ::rand(), which is used by the class uavcan::DynamicNodeIDClient. - * Redefinition is normally not needed, but GCC 4.9 tends to generate broken binaries if it is not redefined. - */ -int rand() -{ - static int x = 1; - x = x * 48271 % 2147483647; - return x; -} - -namespace -{ - -static constexpr unsigned NodeMemoryPoolSize = 2800; - -/** - * This is a compact, reentrant and thread-safe replacement to standard llto(). - * It returns the string by value, no extra storage is needed. - */ -typename uavcan::MakeString<22>::Type intToString(long long n) -{ - char buf[24] = {}; - const short sign = (n < 0) ? -1 : 1; - if (sign < 0) - { - n = -n; - } - unsigned pos = 0; - do - { - buf[pos++] = char(n % 10 + '0'); - } - while ((n /= 10) > 0); - if (sign < 0) - { - buf[pos++] = '-'; - } - buf[pos] = '\0'; - for (unsigned i = 0, j = pos - 1U; i < j; i++, j--) - { - std::swap(buf[i], buf[j]); - } - return static_cast(buf); -} - -uavcan::Node& getNode() -{ - static uavcan::Node node(uavcan_lpc11c24::CanDriver::instance(), - uavcan_lpc11c24::SystemClock::instance()); - return node; -} - -uavcan::GlobalTimeSyncSlave& getTimeSyncSlave() -{ - static uavcan::GlobalTimeSyncSlave tss(getNode()); - return tss; -} - -uavcan::Logger& getLogger() -{ - static uavcan::Logger logger(getNode()); - return logger; -} - -uavcan::NodeID performDynamicNodeIDAllocation() -{ - uavcan::DynamicNodeIDClient client(getNode()); - - const int client_start_res = client.start(getNode().getHardwareVersion().unique_id); - if (client_start_res < 0) - { - board::die(); - } - - while (!client.isAllocationComplete()) - { - board::resetWatchdog(); - (void)getNode().spin(uavcan::MonotonicDuration::fromMSec(100)); - } - - return client.getAllocatedNodeID(); -} - -void init() -{ - board::resetWatchdog(); - board::syslog("Boot\r\n"); - - board::setErrorLed(false); - board::setStatusLed(true); - - /* - * Configuring the clock - this must be done before the CAN controller is initialized - */ - uavcan_lpc11c24::clock::init(); - - /* - * Configuring the CAN controller - */ - std::uint32_t bit_rate = 0; - while (bit_rate == 0) - { - board::syslog("CAN auto bitrate...\r\n"); - bit_rate = uavcan_lpc11c24::CanDriver::detectBitRate(&board::resetWatchdog); - } - board::syslog("Bitrate: "); - board::syslog(intToString(bit_rate).c_str()); - board::syslog("\r\n"); - - if (uavcan_lpc11c24::CanDriver::instance().init(bit_rate) < 0) - { - board::die(); - } - - board::syslog("CAN init ok\r\n"); - - board::resetWatchdog(); - - /* - * Configuring the node - */ - getNode().setName("org.uavcan.lpc11c24_test"); - - uavcan::protocol::SoftwareVersion swver; - swver.major = FW_VERSION_MAJOR; - swver.minor = FW_VERSION_MINOR; - swver.vcs_commit = GIT_HASH; - swver.optional_field_flags = swver.OPTIONAL_FIELD_FLAG_VCS_COMMIT; - getNode().setSoftwareVersion(swver); - - uavcan::protocol::HardwareVersion hwver; - std::uint8_t uid[board::UniqueIDSize] = {}; - board::readUniqueID(uid); - std::copy(std::begin(uid), std::end(uid), std::begin(hwver.unique_id)); - getNode().setHardwareVersion(hwver); - - board::resetWatchdog(); - - /* - * Starting the node and performing dynamic node ID allocation - */ - if (getNode().start() < 0) - { - board::die(); - } - - board::syslog("Node ID allocation...\r\n"); - - getNode().setNodeID(performDynamicNodeIDAllocation()); - - board::syslog("Node ID "); - board::syslog(intToString(getNode().getNodeID().get()).c_str()); - board::syslog("\r\n"); - - board::resetWatchdog(); - - /* - * Example filter configuration. - * Can be removed safely. - */ - { - constexpr unsigned NumFilters = 3; - uavcan::CanFilterConfig filters[NumFilters]; - - // Acepting all service transfers addressed to us - filters[0].id = (unsigned(getNode().getNodeID().get()) << 8) | (1U << 7) | uavcan::CanFrame::FlagEFF; - filters[0].mask = 0x7F80 | uavcan::CanFrame::FlagEFF; - - // Accepting time sync messages - filters[1].id = (4U << 8) | uavcan::CanFrame::FlagEFF; - filters[1].mask = 0xFFFF80 | uavcan::CanFrame::FlagEFF; - - // Accepting zero CAN ID (just for the sake of testing) - filters[2].id = 0 | uavcan::CanFrame::FlagEFF; - filters[2].mask = uavcan::CanFrame::MaskExtID | uavcan::CanFrame::FlagEFF; - - if (uavcan_lpc11c24::CanDriver::instance().configureFilters(filters, NumFilters) < 0) - { - board::syslog("Filter init failed\r\n"); - board::die(); - } - } - - /* - * Initializing other libuavcan-related objects - */ - if (getTimeSyncSlave().start() < 0) - { - board::die(); - } - - if (getLogger().init() < 0) - { - board::die(); - } - - getLogger().setLevel(uavcan::protocol::debug::LogLevel::DEBUG); - - board::resetWatchdog(); -} - -} - -int main() -{ - init(); - - getNode().setModeOperational(); - - uavcan::MonotonicTime prev_log_at; - - while (true) - { - const int res = getNode().spin(uavcan::MonotonicDuration::fromMSec(25)); - board::setErrorLed(res < 0); - board::setStatusLed(uavcan_lpc11c24::CanDriver::instance().hadActivity()); - - const auto ts = uavcan_lpc11c24::clock::getMonotonic(); - if ((ts - prev_log_at).toMSec() >= 1000) - { - prev_log_at = ts; - - /* - * CAN bus off state monitoring - */ - if (uavcan_lpc11c24::CanDriver::instance().isInBusOffState()) - { - board::syslog("CAN BUS OFF\r\n"); - } - - /* - * CAN error counter, for debugging purposes - */ - board::syslog("CAN errors: "); - board::syslog(intToString(static_cast(uavcan_lpc11c24::CanDriver::instance().getErrorCount())).c_str()); - board::syslog(" "); - board::syslog(intToString(uavcan_lpc11c24::CanDriver::instance().getRxQueueOverflowCount()).c_str()); - board::syslog("\r\n"); - - /* - * We don't want to use formatting functions provided by libuavcan because they rely on std::snprintf(), - * so we need to construct the message manually: - */ - uavcan::protocol::debug::LogMessage logmsg; - logmsg.level.value = uavcan::protocol::debug::LogLevel::INFO; - logmsg.source = "app"; - logmsg.text = intToString(uavcan_lpc11c24::clock::getPrevUtcAdjustment().toUSec()).c_str(); - (void)getLogger().log(logmsg); - } - - board::resetWatchdog(); - } -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp deleted file mode 100644 index b3429843aa..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.cpp +++ /dev/null @@ -1,195 +0,0 @@ -/* - * Pavel Kirienko, 2014 - * Board initialization for Olimex LPC11C24 - */ - -#include "board.hpp" -#include -#include -#include -#include - -static constexpr unsigned long PDRUNCFGUSEMASK = 0x0000ED00U; -static constexpr unsigned long PDRUNCFGMASKTMP = 0x000000FFU; - -const std::uint32_t OscRateIn = 12000000; ///< External crystal -const std::uint32_t ExtRateIn = 0; - -std::uint32_t SystemCoreClock = 12000000; ///< Initialized to default clock value, will be changed on init - -namespace board -{ -namespace -{ - -constexpr unsigned TargetSystemCoreClock = 48000000; - -constexpr unsigned ErrorLedPort = 1; -constexpr unsigned ErrorLedPin = 10; - -constexpr unsigned StatusLedPort = 1; -constexpr unsigned StatusLedPin = 11; - -struct PinMuxGroup -{ - unsigned pin : 8; - unsigned modefunc : 24; -}; - -constexpr PinMuxGroup pinmux[] = -{ - { IOCON_PIO1_10, IOCON_FUNC0 | IOCON_MODE_INACT }, // Error LED - { IOCON_PIO1_11, IOCON_FUNC0 | IOCON_MODE_INACT }, // Status LED - { IOCON_PIO1_7, IOCON_FUNC1 | IOCON_HYS_EN | IOCON_MODE_PULLUP }, // UART_TXD -}; - - -void sysctlPowerDown(unsigned long powerdownmask) -{ - unsigned long pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP; - pdrun |= (powerdownmask & PDRUNCFGMASKTMP); - LPC_SYSCTL->PDRUNCFG = pdrun | PDRUNCFGUSEMASK; -} - -void sysctlPowerUp(unsigned long powerupmask) -{ - unsigned long pdrun = LPC_SYSCTL->PDRUNCFG & PDRUNCFGMASKTMP; - pdrun &= ~(powerupmask & PDRUNCFGMASKTMP); - LPC_SYSCTL->PDRUNCFG = pdrun | PDRUNCFGUSEMASK; -} - -void initWatchdog() -{ - Chip_WWDT_Init(LPC_WWDT); // Initialize watchdog - sysctlPowerUp(SYSCTL_POWERDOWN_WDTOSC_PD); // Enable watchdog oscillator - Chip_Clock_SetWDTOSC(WDTLFO_OSC_0_60, 4); // WDT osc rate 0.6 MHz / 4 = 150 kHz - Chip_Clock_SetWDTClockSource(SYSCTL_WDTCLKSRC_WDTOSC, 1); // Clocking watchdog from its osc, div rate 1 - Chip_WWDT_SetTimeOut(LPC_WWDT, 37500); // 1 sec (hardcoded to reduce code size) - Chip_WWDT_SetOption(LPC_WWDT, WWDT_WDMOD_WDRESET); // Mode: reset on timeout - Chip_WWDT_Start(LPC_WWDT); // Go -} - -void initClock() -{ - sysctlPowerUp(SYSCTL_POWERDOWN_SYSOSC_PD); // Enable system oscillator - for (volatile int i = 0; i < 1000; i++) { } - - Chip_Clock_SetSystemPLLSource(SYSCTL_PLLCLKSRC_MAINOSC); - sysctlPowerDown(SYSCTL_POWERDOWN_SYSPLL_PD); - - /* - * Setup PLL for main oscillator rate (FCLKIN = 12MHz) * 4 = 48MHz - * MSEL = 3 (this is pre-decremented), PSEL = 1 (for P = 2) - * FCLKOUT = FCLKIN * (MSEL + 1) = 12MHz * 4 = 48MHz - * FCCO = FCLKOUT * 2 * P = 48MHz * 2 * 2 = 192MHz (within FCCO range) - */ - Chip_Clock_SetupSystemPLL(3, 1); - sysctlPowerUp(SYSCTL_POWERDOWN_SYSPLL_PD); - while (!Chip_Clock_IsSystemPLLLocked()) { } - - Chip_Clock_SetSysClockDiv(1); - - Chip_FMC_SetFLASHAccess(FLASHTIM_50MHZ_CPU); - - Chip_Clock_SetMainClockSource(SYSCTL_MAINCLKSRC_PLLOUT); - - SystemCoreClock = Chip_Clock_GetSystemClockRate(); - - while (SystemCoreClock != TargetSystemCoreClock) { } // Loop forever if the clock failed to initialize properly -} - -void initGpio() -{ - LPC_SYSCTL->SYSAHBCLKCTRL |= 1 << SYSCTL_CLOCK_IOCON; - LPC_SYSCTL->SYSAHBCLKCTRL |= 1 << SYSCTL_CLOCK_GPIO; - - for (unsigned i = 0; i < (sizeof(pinmux) / sizeof(PinMuxGroup)); i++) - { - LPC_IOCON->REG[pinmux[i].pin] = pinmux[i].modefunc; - } - - LPC_GPIO[ErrorLedPort].DIR |= 1 << ErrorLedPin; - LPC_GPIO[StatusLedPort].DIR |= 1 << StatusLedPin; -} - -void initUart() -{ - Chip_UART_Init(LPC_USART); - Chip_UART_SetBaud(LPC_USART, 115200); - Chip_UART_TXEnable(LPC_USART); -} - -void init() -{ - Chip_SYSCTL_SetBODLevels(SYSCTL_BODRSTLVL_2_06V, SYSCTL_BODINTVAL_RESERVED1); - Chip_SYSCTL_EnableBODReset(); - - initWatchdog(); - initClock(); - initGpio(); - initUart(); - - resetWatchdog(); -} - -} // namespace - -void die() -{ - static const volatile unsigned& DHCSR = *reinterpret_cast(0xE000EDF0U); - - syslog("FATAL\r\n"); - - while (true) - { - if ((DHCSR & 1U) != 0) - { - __asm volatile ("bkpt #0\n"); // Break into the debugger - } - } -} - -#if __GNUC__ -__attribute__((optimize(0))) // Optimization must be disabled lest it hardfaults in the IAP call -#endif -void readUniqueID(std::uint8_t out_uid[UniqueIDSize]) -{ - unsigned aligned_array[5] = {}; // out_uid may be unaligned, so we need to use temp array - unsigned iap_command = 58; - reinterpret_cast(0x1FFF1FF1)(&iap_command, aligned_array); - std::memcpy(out_uid, &aligned_array[1], 16); -} - -void setStatusLed(bool state) -{ - LPC_GPIO[StatusLedPort].DATA[1 << StatusLedPin] = static_cast(!state) << StatusLedPin; -} - -void setErrorLed(bool state) -{ - LPC_GPIO[ErrorLedPort].DATA[1 << ErrorLedPin] = static_cast(!state) << ErrorLedPin; -} - -void resetWatchdog() -{ - Chip_WWDT_Feed(LPC_WWDT); -} - -void syslog(const char* msg) -{ - Chip_UART_SendBlocking(LPC_USART, msg, static_cast(std::strlen(msg))); -} - -} // namespace board - -extern "C" -{ - -void SystemInit(); - -void SystemInit() -{ - board::init(); -} - -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp deleted file mode 100644 index 21a64c4424..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/board.hpp +++ /dev/null @@ -1,32 +0,0 @@ -/* - * Pavel Kirienko, 2014 - */ - -#include - -namespace board -{ - -#if __GNUC__ -__attribute__((noreturn)) -#endif -void die(); - -static constexpr unsigned UniqueIDSize = 16; - -/** - * Reads the globally unique 128-bit hardware ID from the MCU. - */ -void readUniqueID(std::uint8_t out_uid[UniqueIDSize]); - -void setStatusLed(bool state); -void setErrorLed(bool state); - -void resetWatchdog(); - -/** - * Sends the string to UART. - */ -void syslog(const char* msg); - -} diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/crt0.c b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/crt0.c deleted file mode 100644 index c0de66a51b..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/crt0.c +++ /dev/null @@ -1,223 +0,0 @@ -/* - * Pavel Kirienko, 2014 - * ARM Cortex-M0(+)/M1/M3 startup file. - */ - -typedef void (*funptr_t)(void); - -#define fill32(start, end, filler) { \ - unsigned *p1 = start; \ - const unsigned * const p2 = end; \ - while (p1 < p2) \ - *p1++ = filler; \ -} - -extern const unsigned _etext; - -extern unsigned _data; -extern unsigned _edata; - -extern unsigned _bss; -extern unsigned _ebss; - -extern funptr_t __init_array_start; -extern funptr_t __init_array_end; - -__attribute__((noreturn)) -extern int main(void); - -extern void SystemInit(void); - -#pragma GCC optimize 1 - -/** - * Prototypes for the functions below - */ -void Reset_Handler(void); -void Default_Handler(void); -void NMI_Handler(void); -void HardFault_Handler(void); -void SVC_Handler(void); -void PendSV_Handler(void); -void SysTick_Handler(void); - -/** - * Firmware entry point - */ -__attribute__((naked, noreturn)) -void Reset_Handler(void) -{ - // Data section - { - const unsigned* tp = &_etext; - unsigned* dp = &_data; - while (dp < &_edata) - { - *dp++ = *tp++; - } - } - - // BSS section - fill32(&_bss, &_ebss, 0); - - SystemInit(); - - // Constructors - { - funptr_t* fpp = &__init_array_start; - while (fpp < &__init_array_end) - { - (*fpp)(); - fpp++; - } - } - - (void)main(); - - while (1) { } -} - -/** - * Default handlers - */ -__attribute__((weak)) -void Default_Handler(void) -{ - while(1) { } -} - -__attribute__((weak)) -void NMI_Handler(void) -{ - while(1) { } -} - -__attribute__((weak)) -void HardFault_Handler(void) -{ - while(1) { } -} - -__attribute__((weak)) -void SVC_Handler(void) -{ - while(1) { } -} - -__attribute__((weak)) -void PendSV_Handler(void) -{ - while(1) { } -} - -__attribute__((weak)) -void SysTick_Handler(void) -{ - while(1) { } -} - -/** - * Default vectors for LPC11C24, to be overriden by the firmware as needed - */ -#define ALIAS(f) __attribute__ ((weak, alias (#f))) - -void CAN_IRQHandler(void) ALIAS(Default_Handler); -void SSP1_IRQHandler(void) ALIAS(Default_Handler); -void I2C_IRQHandler(void) ALIAS(Default_Handler); -void TIMER16_0_IRQHandler(void) ALIAS(Default_Handler); -void TIMER16_1_IRQHandler(void) ALIAS(Default_Handler); -void TIMER32_0_IRQHandler(void) ALIAS(Default_Handler); -void TIMER32_1_IRQHandler(void) ALIAS(Default_Handler); -void SSP0_IRQHandler(void) ALIAS(Default_Handler); -void UART_IRQHandler(void) ALIAS(Default_Handler); -void ADC_IRQHandler(void) ALIAS(Default_Handler); -void WDT_IRQHandler(void) ALIAS(Default_Handler); -void BOD_IRQHandler(void) ALIAS(Default_Handler); -void PIOINT3_IRQHandler(void) ALIAS(Default_Handler); -void PIOINT2_IRQHandler(void) ALIAS(Default_Handler); -void PIOINT1_IRQHandler(void) ALIAS(Default_Handler); -void PIOINT0_IRQHandler(void) ALIAS(Default_Handler); -void WAKEUP_IRQHandler(void) ALIAS(Default_Handler); - -/** - * Refer to the linker script - */ -extern void __stack_end(void); - -/** - * Vector table for LPC11Cxx - * Must be explicitly defined 'used', otherwise LTO optimizer will discard it. - */ -__attribute__ ((used, section("vectors"))) -void (* const VectorTable[64])(void) = -{ - __stack_end, // The initial stack pointer - Reset_Handler, // The reset handler - NMI_Handler, // The NMI handler - HardFault_Handler, // The hard fault handler - 0, // Reserved - 0, // Reserved - 0, // Reserved - 0, // Reserved - 0, // Reserved - 0, // Reserved - 0, // Reserved - SVC_Handler, // SVCall handler - 0, // Reserved - 0, // Reserved - PendSV_Handler, // The PendSV handler - SysTick_Handler, // The SysTick handler - - WAKEUP_IRQHandler, // PIO0_0 Wakeup - WAKEUP_IRQHandler, // PIO0_1 Wakeup - WAKEUP_IRQHandler, // PIO0_2 Wakeup - WAKEUP_IRQHandler, // PIO0_3 Wakeup - WAKEUP_IRQHandler, // PIO0_4 Wakeup - WAKEUP_IRQHandler, // PIO0_5 Wakeup - WAKEUP_IRQHandler, // PIO0_6 Wakeup - WAKEUP_IRQHandler, // PIO0_7 Wakeup - WAKEUP_IRQHandler, // PIO0_8 Wakeup - WAKEUP_IRQHandler, // PIO0_9 Wakeup - WAKEUP_IRQHandler, // PIO0_10 Wakeup - WAKEUP_IRQHandler, // PIO0_11 Wakeup - WAKEUP_IRQHandler, // PIO1_0 Wakeup - - CAN_IRQHandler, // C_CAN Interrupt - SSP1_IRQHandler, // SPI/SSP1 Interrupt - I2C_IRQHandler, // I2C0 - TIMER16_0_IRQHandler, // CT16B0 (16-bit Timer 0) - TIMER16_1_IRQHandler, // CT16B1 (16-bit Timer 1) - TIMER32_0_IRQHandler, // CT32B0 (32-bit Timer 0) - TIMER32_1_IRQHandler, // CT32B1 (32-bit Timer 1) - SSP0_IRQHandler, // SPI/SSP0 Interrupt - UART_IRQHandler, // UART0 - - 0, // Reserved - 0, // Reserved - - ADC_IRQHandler, // ADC (A/D Converter) - WDT_IRQHandler, // WDT (Watchdog Timer) - BOD_IRQHandler, // BOD (Brownout Detect) - 0, // Reserved - PIOINT3_IRQHandler, // PIO INT3 - PIOINT2_IRQHandler, // PIO INT2 - PIOINT1_IRQHandler, // PIO INT1 - PIOINT0_IRQHandler, // PIO INT0 - - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0, - 0 -}; diff --git a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/libstubs.cpp b/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/libstubs.cpp deleted file mode 100644 index ca63b91640..0000000000 --- a/libuavcan_drivers/lpc11c24/test_olimex_lpc_p11c24/src/sys/libstubs.cpp +++ /dev/null @@ -1,148 +0,0 @@ -/* - * Pavel Kirienko, 2014 - * Standard library stubs - */ - -#include -#include -#include - -#if __GNUC__ -# pragma GCC diagnostic ignored "-Wmissing-declarations" -#endif - -void* __dso_handle; - -void* operator new(std::size_t) -{ - std::abort(); - return reinterpret_cast(0xFFFFFFFF); -} - -void* operator new[](std::size_t) -{ - std::abort(); - return reinterpret_cast(0xFFFFFFFF); -} - -void operator delete(void*) -{ - std::abort(); -} - -void operator delete[](void*) -{ - std::abort(); -} - -namespace __gnu_cxx -{ - -void __verbose_terminate_handler() -{ - std::abort(); -} - -} - -/* - * libstdc++ stubs - */ -extern "C" -{ - -int __aeabi_atexit(void*, void(*)(void*), void*) -{ - return 0; -} - -__extension__ typedef int __guard __attribute__((mode (__DI__))); - -void __cxa_atexit(void(*)(void *), void*, void*) -{ -} - -int __cxa_guard_acquire(__guard* g) -{ - return !*g; -} - -void __cxa_guard_release (__guard* g) -{ - *g = 1; -} - -void __cxa_guard_abort (__guard*) -{ -} - -void __cxa_pure_virtual() -{ - std::abort(); -} - -} - -/* - * stdio - */ -extern "C" -{ - -__attribute__((used)) -void abort() -{ - while (true) { } -} - -int _read_r(struct _reent*, int, char*, int) -{ - return -1; -} - -int _lseek_r(struct _reent*, int, int, int) -{ - return -1; -} - -int _write_r(struct _reent*, int, char*, int) -{ - return -1; -} - -int _close_r(struct _reent*, int) -{ - return -1; -} - -__attribute__((used)) -caddr_t _sbrk_r(struct _reent*, int) -{ - return 0; -} - -int _fstat_r(struct _reent*, int, struct stat*) -{ - return -1; -} - -int _isatty_r(struct _reent*, int) -{ - return -1; -} - -void _exit(int) -{ - abort(); -} - -pid_t _getpid(void) -{ - return 1; -} - -void _kill(pid_t) -{ -} - -} diff --git a/libuavcan_drivers/stm32/README.md b/libuavcan_drivers/stm32/README.md deleted file mode 100644 index 11cf01662f..0000000000 --- a/libuavcan_drivers/stm32/README.md +++ /dev/null @@ -1,11 +0,0 @@ -STM32 platform driver -===================== - -The directory `driver` contains the STM32 platform driver for Libuavcan. - -A dedicated example application may be added later here. -For now, please consider the following open source projects as a reference: - -- https://github.com/PX4/sapog -- https://github.com/Zubax/zubax_gnss -- https://github.com/PX4/Firmware diff --git a/libuavcan_drivers/stm32/driver/CMakeLists.txt b/libuavcan_drivers/stm32/driver/CMakeLists.txt deleted file mode 100644 index ce8ef00234..0000000000 --- a/libuavcan_drivers/stm32/driver/CMakeLists.txt +++ /dev/null @@ -1,17 +0,0 @@ -include_directories( - ./include - ) - -add_library(uavcan_stm32_driver STATIC - ./src/uc_stm32_can.cpp - ./src/uc_stm32_clock.cpp - ./src/uc_stm32_thread.cpp - ) - -add_dependencies(uavcan_stm32_driver uavcan) - -install(DIRECTORY include/uavcan_stm32 DESTINATION include) -install(TARGETS uavcan_stm32_driver DESTINATION lib) - -# vim: set et ft=cmake fenc=utf-8 ff=unix sts=4 sw=4 ts=4 :) - diff --git a/libuavcan_drivers/stm32/driver/include.mk b/libuavcan_drivers/stm32/driver/include.mk deleted file mode 100644 index b7c4ed6e49..0000000000 --- a/libuavcan_drivers/stm32/driver/include.mk +++ /dev/null @@ -1,9 +0,0 @@ -# -# Copyright (C) 2014 Pavel Kirienko -# - -LIBUAVCAN_STM32_DIR := $(dir $(lastword $(MAKEFILE_LIST))) - -LIBUAVCAN_STM32_SRC := $(shell find $(LIBUAVCAN_STM32_DIR)src -type f -name '*.cpp') - -LIBUAVCAN_STM32_INC := $(LIBUAVCAN_STM32_DIR)include/ diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp deleted file mode 100644 index 0160cc662d..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/build_config.hpp +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (C) 2015 Pavel Kirienko - */ - -#pragma once - -/** - * OS detection - */ -#ifndef UAVCAN_STM32_CHIBIOS -# define UAVCAN_STM32_CHIBIOS 0 -#endif - -#ifndef UAVCAN_STM32_NUTTX -# define UAVCAN_STM32_NUTTX 0 -#endif - -#ifndef UAVCAN_STM32_BAREMETAL -# define UAVCAN_STM32_BAREMETAL 0 -#endif - -#ifndef UAVCAN_STM32_FREERTOS -# define UAVCAN_STM32_FREERTOS 0 -#endif - -/** - * Number of interfaces must be enabled explicitly - */ -#if !defined(UAVCAN_STM32_NUM_IFACES) || (UAVCAN_STM32_NUM_IFACES != 1 && UAVCAN_STM32_NUM_IFACES != 2) -# error "UAVCAN_STM32_NUM_IFACES must be set to either 1 or 2" -#endif - -/** - * Any General-Purpose timer (TIM2, TIM3, TIM4, TIM5) - * e.g. -DUAVCAN_STM32_TIMER_NUMBER=2 - */ -#ifndef UAVCAN_STM32_TIMER_NUMBER -// In this case the clock driver should be implemented by the application -# define UAVCAN_STM32_TIMER_NUMBER 0 -#endif diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/bxcan.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/bxcan.hpp deleted file mode 100644 index 7e4679443a..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/bxcan.hpp +++ /dev/null @@ -1,289 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - * Bit definitions were copied from NuttX STM32 CAN driver. - */ - -#pragma once - -#include - -#include -#include - -#ifndef UAVCAN_CPP_VERSION -# error UAVCAN_CPP_VERSION -#endif - -#if UAVCAN_CPP_VERSION < UAVCAN_CPP11 -// #undef'ed at the end of this file -# define constexpr const -#endif - -namespace uavcan_stm32 -{ -namespace bxcan -{ - -struct TxMailboxType -{ - volatile uint32_t TIR; - volatile uint32_t TDTR; - volatile uint32_t TDLR; - volatile uint32_t TDHR; -}; - -struct RxMailboxType -{ - volatile uint32_t RIR; - volatile uint32_t RDTR; - volatile uint32_t RDLR; - volatile uint32_t RDHR; -}; - -struct FilterRegisterType -{ - volatile uint32_t FR1; - volatile uint32_t FR2; -}; - -struct CanType -{ - volatile uint32_t MCR; /*!< CAN master control register, Address offset: 0x00 */ - volatile uint32_t MSR; /*!< CAN master status register, Address offset: 0x04 */ - volatile uint32_t TSR; /*!< CAN transmit status register, Address offset: 0x08 */ - volatile uint32_t RF0R; /*!< CAN receive FIFO 0 register, Address offset: 0x0C */ - volatile uint32_t RF1R; /*!< CAN receive FIFO 1 register, Address offset: 0x10 */ - volatile uint32_t IER; /*!< CAN interrupt enable register, Address offset: 0x14 */ - volatile uint32_t ESR; /*!< CAN error status register, Address offset: 0x18 */ - volatile uint32_t BTR; /*!< CAN bit timing register, Address offset: 0x1C */ - uint32_t RESERVED0[88]; /*!< Reserved, 0x020 - 0x17F */ - TxMailboxType TxMailbox[3]; /*!< CAN Tx MailBox, Address offset: 0x180 - 0x1AC */ - RxMailboxType RxMailbox[2]; /*!< CAN FIFO MailBox, Address offset: 0x1B0 - 0x1CC */ - uint32_t RESERVED1[12]; /*!< Reserved, 0x1D0 - 0x1FF */ - volatile uint32_t FMR; /*!< CAN filter master register, Address offset: 0x200 */ - volatile uint32_t FM1R; /*!< CAN filter mode register, Address offset: 0x204 */ - uint32_t RESERVED2; /*!< Reserved, 0x208 */ - volatile uint32_t FS1R; /*!< CAN filter scale register, Address offset: 0x20C */ - uint32_t RESERVED3; /*!< Reserved, 0x210 */ - volatile uint32_t FFA1R; /*!< CAN filter FIFO assignment register, Address offset: 0x214 */ - uint32_t RESERVED4; /*!< Reserved, 0x218 */ - volatile uint32_t FA1R; /*!< CAN filter activation register, Address offset: 0x21C */ - uint32_t RESERVED5[8]; /*!< Reserved, 0x220-0x23F */ - FilterRegisterType FilterRegister[28]; /*!< CAN Filter Register, Address offset: 0x240-0x31C */ -}; - -/** - * CANx register sets - */ -CanType* const Can[UAVCAN_STM32_NUM_IFACES] = -{ - reinterpret_cast(0x40006400) -#if UAVCAN_STM32_NUM_IFACES > 1 - , - reinterpret_cast(0x40006800) -#endif -}; - -/* CAN master control register */ - -constexpr unsigned long MCR_INRQ = (1U << 0); /* Bit 0: Initialization Request */ -constexpr unsigned long MCR_SLEEP = (1U << 1); /* Bit 1: Sleep Mode Request */ -constexpr unsigned long MCR_TXFP = (1U << 2); /* Bit 2: Transmit FIFO Priority */ -constexpr unsigned long MCR_RFLM = (1U << 3); /* Bit 3: Receive FIFO Locked Mode */ -constexpr unsigned long MCR_NART = (1U << 4); /* Bit 4: No Automatic Retransmission */ -constexpr unsigned long MCR_AWUM = (1U << 5); /* Bit 5: Automatic Wakeup Mode */ -constexpr unsigned long MCR_ABOM = (1U << 6); /* Bit 6: Automatic Bus-Off Management */ -constexpr unsigned long MCR_TTCM = (1U << 7); /* Bit 7: Time Triggered Communication Mode Enable */ -constexpr unsigned long MCR_RESET = (1U << 15);/* Bit 15: bxCAN software master reset */ -constexpr unsigned long MCR_DBF = (1U << 16);/* Bit 16: Debug freeze */ - -/* CAN master status register */ - -constexpr unsigned long MSR_INAK = (1U << 0); /* Bit 0: Initialization Acknowledge */ -constexpr unsigned long MSR_SLAK = (1U << 1); /* Bit 1: Sleep Acknowledge */ -constexpr unsigned long MSR_ERRI = (1U << 2); /* Bit 2: Error Interrupt */ -constexpr unsigned long MSR_WKUI = (1U << 3); /* Bit 3: Wakeup Interrupt */ -constexpr unsigned long MSR_SLAKI = (1U << 4); /* Bit 4: Sleep acknowledge interrupt */ -constexpr unsigned long MSR_TXM = (1U << 8); /* Bit 8: Transmit Mode */ -constexpr unsigned long MSR_RXM = (1U << 9); /* Bit 9: Receive Mode */ -constexpr unsigned long MSR_SAMP = (1U << 10);/* Bit 10: Last Sample Point */ -constexpr unsigned long MSR_RX = (1U << 11);/* Bit 11: CAN Rx Signal */ - -/* CAN transmit status register */ - -constexpr unsigned long TSR_RQCP0 = (1U << 0); /* Bit 0: Request Completed Mailbox 0 */ -constexpr unsigned long TSR_TXOK0 = (1U << 1); /* Bit 1 : Transmission OK of Mailbox 0 */ -constexpr unsigned long TSR_ALST0 = (1U << 2); /* Bit 2 : Arbitration Lost for Mailbox 0 */ -constexpr unsigned long TSR_TERR0 = (1U << 3); /* Bit 3 : Transmission Error of Mailbox 0 */ -constexpr unsigned long TSR_ABRQ0 = (1U << 7); /* Bit 7 : Abort Request for Mailbox 0 */ -constexpr unsigned long TSR_RQCP1 = (1U << 8); /* Bit 8 : Request Completed Mailbox 1 */ -constexpr unsigned long TSR_TXOK1 = (1U << 9); /* Bit 9 : Transmission OK of Mailbox 1 */ -constexpr unsigned long TSR_ALST1 = (1U << 10);/* Bit 10 : Arbitration Lost for Mailbox 1 */ -constexpr unsigned long TSR_TERR1 = (1U << 11);/* Bit 11 : Transmission Error of Mailbox 1 */ -constexpr unsigned long TSR_ABRQ1 = (1U << 15);/* Bit 15 : Abort Request for Mailbox 1 */ -constexpr unsigned long TSR_RQCP2 = (1U << 16);/* Bit 16 : Request Completed Mailbox 2 */ -constexpr unsigned long TSR_TXOK2 = (1U << 17);/* Bit 17 : Transmission OK of Mailbox 2 */ -constexpr unsigned long TSR_ALST2 = (1U << 18);/* Bit 18: Arbitration Lost for Mailbox 2 */ -constexpr unsigned long TSR_TERR2 = (1U << 19);/* Bit 19: Transmission Error of Mailbox 2 */ -constexpr unsigned long TSR_ABRQ2 = (1U << 23);/* Bit 23: Abort Request for Mailbox 2 */ -constexpr unsigned long TSR_CODE_SHIFT = (24U); /* Bits 25-24: Mailbox Code */ -constexpr unsigned long TSR_CODE_MASK = (3U << TSR_CODE_SHIFT); -constexpr unsigned long TSR_TME0 = (1U << 26);/* Bit 26: Transmit Mailbox 0 Empty */ -constexpr unsigned long TSR_TME1 = (1U << 27);/* Bit 27: Transmit Mailbox 1 Empty */ -constexpr unsigned long TSR_TME2 = (1U << 28);/* Bit 28: Transmit Mailbox 2 Empty */ -constexpr unsigned long TSR_LOW0 = (1U << 29);/* Bit 29: Lowest Priority Flag for Mailbox 0 */ -constexpr unsigned long TSR_LOW1 = (1U << 30);/* Bit 30: Lowest Priority Flag for Mailbox 1 */ -constexpr unsigned long TSR_LOW2 = (1U << 31);/* Bit 31: Lowest Priority Flag for Mailbox 2 */ - -/* CAN receive FIFO 0/1 registers */ - -constexpr unsigned long RFR_FMP_SHIFT = (0U); /* Bits 1-0: FIFO Message Pending */ -constexpr unsigned long RFR_FMP_MASK = (3U << RFR_FMP_SHIFT); -constexpr unsigned long RFR_FULL = (1U << 3); /* Bit 3: FIFO 0 Full */ -constexpr unsigned long RFR_FOVR = (1U << 4); /* Bit 4: FIFO 0 Overrun */ -constexpr unsigned long RFR_RFOM = (1U << 5); /* Bit 5: Release FIFO 0 Output Mailbox */ - -/* CAN interrupt enable register */ - -constexpr unsigned long IER_TMEIE = (1U << 0); /* Bit 0: Transmit Mailbox Empty Interrupt Enable */ -constexpr unsigned long IER_FMPIE0 = (1U << 1); /* Bit 1: FIFO Message Pending Interrupt Enable */ -constexpr unsigned long IER_FFIE0 = (1U << 2); /* Bit 2: FIFO Full Interrupt Enable */ -constexpr unsigned long IER_FOVIE0 = (1U << 3); /* Bit 3: FIFO Overrun Interrupt Enable */ -constexpr unsigned long IER_FMPIE1 = (1U << 4); /* Bit 4: FIFO Message Pending Interrupt Enable */ -constexpr unsigned long IER_FFIE1 = (1U << 5); /* Bit 5: FIFO Full Interrupt Enable */ -constexpr unsigned long IER_FOVIE1 = (1U << 6); /* Bit 6: FIFO Overrun Interrupt Enable */ -constexpr unsigned long IER_EWGIE = (1U << 8); /* Bit 8: Error Warning Interrupt Enable */ -constexpr unsigned long IER_EPVIE = (1U << 9); /* Bit 9: Error Passive Interrupt Enable */ -constexpr unsigned long IER_BOFIE = (1U << 10);/* Bit 10: Bus-Off Interrupt Enable */ -constexpr unsigned long IER_LECIE = (1U << 11);/* Bit 11: Last Error Code Interrupt Enable */ -constexpr unsigned long IER_ERRIE = (1U << 15);/* Bit 15: Error Interrupt Enable */ -constexpr unsigned long IER_WKUIE = (1U << 16);/* Bit 16: Wakeup Interrupt Enable */ -constexpr unsigned long IER_SLKIE = (1U << 17);/* Bit 17: Sleep Interrupt Enable */ - -/* CAN error status register */ - -constexpr unsigned long ESR_EWGF = (1U << 0); /* Bit 0: Error Warning Flag */ -constexpr unsigned long ESR_EPVF = (1U << 1); /* Bit 1: Error Passive Flag */ -constexpr unsigned long ESR_BOFF = (1U << 2); /* Bit 2: Bus-Off Flag */ -constexpr unsigned long ESR_LEC_SHIFT = (4U); /* Bits 6-4: Last Error Code */ -constexpr unsigned long ESR_LEC_MASK = (7U << ESR_LEC_SHIFT); -constexpr unsigned long ESR_NOERROR = (0U << ESR_LEC_SHIFT);/* 000: No Error */ -constexpr unsigned long ESR_STUFFERROR = (1U << ESR_LEC_SHIFT);/* 001: Stuff Error */ -constexpr unsigned long ESR_FORMERROR = (2U << ESR_LEC_SHIFT);/* 010: Form Error */ -constexpr unsigned long ESR_ACKERROR = (3U << ESR_LEC_SHIFT);/* 011: Acknowledgment Error */ -constexpr unsigned long ESR_BRECERROR = (4U << ESR_LEC_SHIFT);/* 100: Bit recessive Error */ -constexpr unsigned long ESR_BDOMERROR = (5U << ESR_LEC_SHIFT);/* 101: Bit dominant Error */ -constexpr unsigned long ESR_CRCERRPR = (6U << ESR_LEC_SHIFT);/* 110: CRC Error */ -constexpr unsigned long ESR_SWERROR = (7U << ESR_LEC_SHIFT);/* 111: Set by software */ -constexpr unsigned long ESR_TEC_SHIFT = (16U); /* Bits 23-16: LS byte of the 9-bit Transmit Error Counter */ -constexpr unsigned long ESR_TEC_MASK = (0xFFU << ESR_TEC_SHIFT); -constexpr unsigned long ESR_REC_SHIFT = (24U); /* Bits 31-24: Receive Error Counter */ -constexpr unsigned long ESR_REC_MASK = (0xFFU << ESR_REC_SHIFT); - -/* CAN bit timing register */ - -constexpr unsigned long BTR_BRP_SHIFT = (0U); /* Bits 9-0: Baud Rate Prescaler */ -constexpr unsigned long BTR_BRP_MASK = (0x03FFU << BTR_BRP_SHIFT); -constexpr unsigned long BTR_TS1_SHIFT = (16U); /* Bits 19-16: Time Segment 1 */ -constexpr unsigned long BTR_TS1_MASK = (0x0FU << BTR_TS1_SHIFT); -constexpr unsigned long BTR_TS2_SHIFT = (20U); /* Bits 22-20: Time Segment 2 */ -constexpr unsigned long BTR_TS2_MASK = (7U << BTR_TS2_SHIFT); -constexpr unsigned long BTR_SJW_SHIFT = (24U); /* Bits 25-24: Resynchronization Jump Width */ -constexpr unsigned long BTR_SJW_MASK = (3U << BTR_SJW_SHIFT); -constexpr unsigned long BTR_LBKM = (1U << 30);/* Bit 30: Loop Back Mode (Debug);*/ -constexpr unsigned long BTR_SILM = (1U << 31);/* Bit 31: Silent Mode (Debug);*/ - -constexpr unsigned long BTR_BRP_MAX = (1024U); /* Maximum BTR value (without decrement);*/ -constexpr unsigned long BTR_TSEG1_MAX = (16U); /* Maximum TSEG1 value (without decrement);*/ -constexpr unsigned long BTR_TSEG2_MAX = (8U); /* Maximum TSEG2 value (without decrement);*/ - -/* TX mailbox identifier register */ - -constexpr unsigned long TIR_TXRQ = (1U << 0); /* Bit 0: Transmit Mailbox Request */ -constexpr unsigned long TIR_RTR = (1U << 1); /* Bit 1: Remote Transmission Request */ -constexpr unsigned long TIR_IDE = (1U << 2); /* Bit 2: Identifier Extension */ -constexpr unsigned long TIR_EXID_SHIFT = (3U); /* Bit 3-31: Extended Identifier */ -constexpr unsigned long TIR_EXID_MASK = (0x1FFFFFFFU << TIR_EXID_SHIFT); -constexpr unsigned long TIR_STID_SHIFT = (21U); /* Bits 21-31: Standard Identifier */ -constexpr unsigned long TIR_STID_MASK = (0x07FFU << TIR_STID_SHIFT); - -/* Mailbox data length control and time stamp register */ - -constexpr unsigned long TDTR_DLC_SHIFT = (0U); /* Bits 3:0: Data Length Code */ -constexpr unsigned long TDTR_DLC_MASK = (0x0FU << TDTR_DLC_SHIFT); -constexpr unsigned long TDTR_TGT = (1U << 8); /* Bit 8: Transmit Global Time */ -constexpr unsigned long TDTR_TIME_SHIFT = (16U); /* Bits 31:16: Message Time Stamp */ -constexpr unsigned long TDTR_TIME_MASK = (0xFFFFU << TDTR_TIME_SHIFT); - -/* Mailbox data low register */ - -constexpr unsigned long TDLR_DATA0_SHIFT = (0U); /* Bits 7-0: Data Byte 0 */ -constexpr unsigned long TDLR_DATA0_MASK = (0xFFU << TDLR_DATA0_SHIFT); -constexpr unsigned long TDLR_DATA1_SHIFT = (8U); /* Bits 15-8: Data Byte 1 */ -constexpr unsigned long TDLR_DATA1_MASK = (0xFFU << TDLR_DATA1_SHIFT); -constexpr unsigned long TDLR_DATA2_SHIFT = (16U); /* Bits 23-16: Data Byte 2 */ -constexpr unsigned long TDLR_DATA2_MASK = (0xFFU << TDLR_DATA2_SHIFT); -constexpr unsigned long TDLR_DATA3_SHIFT = (24U); /* Bits 31-24: Data Byte 3 */ -constexpr unsigned long TDLR_DATA3_MASK = (0xFFU << TDLR_DATA3_SHIFT); - -/* Mailbox data high register */ - -constexpr unsigned long TDHR_DATA4_SHIFT = (0U); /* Bits 7-0: Data Byte 4 */ -constexpr unsigned long TDHR_DATA4_MASK = (0xFFU << TDHR_DATA4_SHIFT); -constexpr unsigned long TDHR_DATA5_SHIFT = (8U); /* Bits 15-8: Data Byte 5 */ -constexpr unsigned long TDHR_DATA5_MASK = (0xFFU << TDHR_DATA5_SHIFT); -constexpr unsigned long TDHR_DATA6_SHIFT = (16U); /* Bits 23-16: Data Byte 6 */ -constexpr unsigned long TDHR_DATA6_MASK = (0xFFU << TDHR_DATA6_SHIFT); -constexpr unsigned long TDHR_DATA7_SHIFT = (24U); /* Bits 31-24: Data Byte 7 */ -constexpr unsigned long TDHR_DATA7_MASK = (0xFFU << TDHR_DATA7_SHIFT); - -/* Rx FIFO mailbox identifier register */ - -constexpr unsigned long RIR_RTR = (1U << 1); /* Bit 1: Remote Transmission Request */ -constexpr unsigned long RIR_IDE = (1U << 2); /* Bit 2: Identifier Extension */ -constexpr unsigned long RIR_EXID_SHIFT = (3U); /* Bit 3-31: Extended Identifier */ -constexpr unsigned long RIR_EXID_MASK = (0x1FFFFFFFU << RIR_EXID_SHIFT); -constexpr unsigned long RIR_STID_SHIFT = (21U); /* Bits 21-31: Standard Identifier */ -constexpr unsigned long RIR_STID_MASK = (0x07FFU << RIR_STID_SHIFT); - -/* Receive FIFO mailbox data length control and time stamp register */ - -constexpr unsigned long RDTR_DLC_SHIFT = (0U); /* Bits 3:0: Data Length Code */ -constexpr unsigned long RDTR_DLC_MASK = (0x0FU << RDTR_DLC_SHIFT); -constexpr unsigned long RDTR_FM_SHIFT = (8U); /* Bits 15-8: Filter Match Index */ -constexpr unsigned long RDTR_FM_MASK = (0xFFU << RDTR_FM_SHIFT); -constexpr unsigned long RDTR_TIME_SHIFT = (16U); /* Bits 31:16: Message Time Stamp */ -constexpr unsigned long RDTR_TIME_MASK = (0xFFFFU << RDTR_TIME_SHIFT); - -/* Receive FIFO mailbox data low register */ - -constexpr unsigned long RDLR_DATA0_SHIFT = (0U); /* Bits 7-0: Data Byte 0 */ -constexpr unsigned long RDLR_DATA0_MASK = (0xFFU << RDLR_DATA0_SHIFT); -constexpr unsigned long RDLR_DATA1_SHIFT = (8U); /* Bits 15-8: Data Byte 1 */ -constexpr unsigned long RDLR_DATA1_MASK = (0xFFU << RDLR_DATA1_SHIFT); -constexpr unsigned long RDLR_DATA2_SHIFT = (16U); /* Bits 23-16: Data Byte 2 */ -constexpr unsigned long RDLR_DATA2_MASK = (0xFFU << RDLR_DATA2_SHIFT); -constexpr unsigned long RDLR_DATA3_SHIFT = (24U); /* Bits 31-24: Data Byte 3 */ -constexpr unsigned long RDLR_DATA3_MASK = (0xFFU << RDLR_DATA3_SHIFT); - -/* Receive FIFO mailbox data high register */ - -constexpr unsigned long RDHR_DATA4_SHIFT = (0U); /* Bits 7-0: Data Byte 4 */ -constexpr unsigned long RDHR_DATA4_MASK = (0xFFU << RDHR_DATA4_SHIFT); -constexpr unsigned long RDHR_DATA5_SHIFT = (8U); /* Bits 15-8: Data Byte 5 */ -constexpr unsigned long RDHR_DATA5_MASK = (0xFFU << RDHR_DATA5_SHIFT); -constexpr unsigned long RDHR_DATA6_SHIFT = (16U); /* Bits 23-16: Data Byte 6 */ -constexpr unsigned long RDHR_DATA6_MASK = (0xFFU << RDHR_DATA6_SHIFT); -constexpr unsigned long RDHR_DATA7_SHIFT = (24U); /* Bits 31-24: Data Byte 7 */ -constexpr unsigned long RDHR_DATA7_MASK = (0xFFU << RDHR_DATA7_SHIFT); - -/* CAN filter master register */ - -constexpr unsigned long FMR_FINIT = (1U << 0); /* Bit 0: Filter Init Mode */ - -} -} - -#if UAVCAN_CPP_VERSION < UAVCAN_CPP11 -# undef constexpr -#endif diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp deleted file mode 100644 index 1e743296f4..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/can.hpp +++ /dev/null @@ -1,382 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include -#include -#include - -namespace uavcan_stm32 -{ -/** - * Driver error codes. - * These values can be returned from driver functions negated. - */ -//static const uavcan::int16_t ErrUnknown = 1000; ///< Reserved for future use -static const uavcan::int16_t ErrNotImplemented = 1001; ///< Feature not implemented -static const uavcan::int16_t ErrInvalidBitRate = 1002; ///< Bit rate not supported -static const uavcan::int16_t ErrLogic = 1003; ///< Internal logic error -static const uavcan::int16_t ErrUnsupportedFrame = 1004; ///< Frame not supported (e.g. RTR, CAN FD, etc) -static const uavcan::int16_t ErrMsrInakNotSet = 1005; ///< INAK bit of the MSR register is not 1 -static const uavcan::int16_t ErrMsrInakNotCleared = 1006; ///< INAK bit of the MSR register is not 0 -static const uavcan::int16_t ErrBitRateNotDetected = 1007; ///< Auto bit rate detection could not be finished -static const uavcan::int16_t ErrFilterNumConfigs = 1008; ///< Number of filters is more than supported - -/** - * RX queue item. - * The application shall not use this directly. - */ -struct CanRxItem -{ - uavcan::uint64_t utc_usec; - uavcan::CanFrame frame; - uavcan::CanIOFlags flags; - CanRxItem() - : utc_usec(0) - , flags(0) - { } -}; - -/** - * Single CAN iface. - * The application shall not use this directly. - */ -class CanIface : public uavcan::ICanIface, uavcan::Noncopyable -{ - class RxQueue - { - CanRxItem* const buf_; - const uavcan::uint8_t capacity_; - uavcan::uint8_t in_; - uavcan::uint8_t out_; - uavcan::uint8_t len_; - uavcan::uint32_t overflow_cnt_; - - void registerOverflow(); - - public: - RxQueue(CanRxItem* buf, uavcan::uint8_t capacity) - : buf_(buf) - , capacity_(capacity) - , in_(0) - , out_(0) - , len_(0) - , overflow_cnt_(0) - { } - - void push(const uavcan::CanFrame& frame, const uint64_t& utc_usec, uavcan::CanIOFlags flags); - void pop(uavcan::CanFrame& out_frame, uavcan::uint64_t& out_utc_usec, uavcan::CanIOFlags& out_flags); - - void reset(); - - unsigned getLength() const { return len_; } - - uavcan::uint32_t getOverflowCount() const { return overflow_cnt_; } - }; - - struct Timings - { - uavcan::uint16_t prescaler; - uavcan::uint8_t sjw; - uavcan::uint8_t bs1; - uavcan::uint8_t bs2; - - Timings() - : prescaler(0) - , sjw(0) - , bs1(0) - , bs2(0) - { } - }; - - struct TxItem - { - uavcan::MonotonicTime deadline; - uavcan::CanFrame frame; - bool pending; - bool loopback; - bool abort_on_error; - - TxItem() - : pending(false) - , loopback(false) - , abort_on_error(false) - { } - }; - - enum { NumTxMailboxes = 3 }; - enum { NumFilters = 14 }; - - static const uavcan::uint32_t TSR_ABRQx[NumTxMailboxes]; - - RxQueue rx_queue_; - bxcan::CanType* const can_; - uavcan::uint64_t error_cnt_; - uavcan::uint32_t served_aborts_cnt_; - BusEvent& update_event_; - TxItem pending_tx_[NumTxMailboxes]; - uavcan::uint8_t peak_tx_mailbox_index_; - const uavcan::uint8_t self_index_; - bool had_activity_; - - int computeTimings(uavcan::uint32_t target_bitrate, Timings& out_timings); - - virtual uavcan::int16_t send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, - uavcan::CanIOFlags flags); - - virtual uavcan::int16_t receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags); - - virtual uavcan::int16_t configureFilters(const uavcan::CanFilterConfig* filter_configs, - uavcan::uint16_t num_configs); - - virtual uavcan::uint16_t getNumFilters() const { return NumFilters; } - - void handleTxMailboxInterrupt(uavcan::uint8_t mailbox_index, bool txok, uavcan::uint64_t utc_usec); - - bool waitMsrINakBitStateChange(bool target_state); - -public: - enum { MaxRxQueueCapacity = 254 }; - - enum OperatingMode - { - NormalMode, - SilentMode - }; - - CanIface(bxcan::CanType* can, BusEvent& update_event, uavcan::uint8_t self_index, - CanRxItem* rx_queue_buffer, uavcan::uint8_t rx_queue_capacity) - : rx_queue_(rx_queue_buffer, rx_queue_capacity) - , can_(can) - , error_cnt_(0) - , served_aborts_cnt_(0) - , update_event_(update_event) - , peak_tx_mailbox_index_(0) - , self_index_(self_index) - , had_activity_(false) - { - UAVCAN_ASSERT(self_index_ < UAVCAN_STM32_NUM_IFACES); - } - - /** - * Initializes the hardware CAN controller. - * Assumes: - * - Iface clock is enabled - * - Iface has been resetted via RCC - * - Caller will configure NVIC by itself - */ - int init(const uavcan::uint32_t bitrate, const OperatingMode mode); - - void handleTxInterrupt(uavcan::uint64_t utc_usec); - void handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t utc_usec); - - /** - * This method is used to count errors and abort transmission on error if necessary. - * This functionality used to be implemented in the SCE interrupt handler, but that approach was - * generating too much processing overhead, especially on disconnected interfaces. - * - * Should be called from RX ISR, TX ISR, and select(); interrupts must be enabled. - */ - void pollErrorFlagsFromISR(); - - void discardTimedOutTxMailboxes(uavcan::MonotonicTime current_time); - - bool canAcceptNewTxFrame(const uavcan::CanFrame& frame) const; - bool isRxBufferEmpty() const; - - /** - * Number of RX frames lost due to queue overflow. - * This is an atomic read, it doesn't require a critical section. - */ - uavcan::uint32_t getRxQueueOverflowCount() const { return rx_queue_.getOverflowCount(); } - - /** - * Total number of hardware failures and other kinds of errors (e.g. queue overruns). - * May increase continuously if the interface is not connected to the bus. - */ - virtual uavcan::uint64_t getErrorCount() const; - - /** - * Number of times the driver exercised library's requirement to abort transmission on first error. - * This is an atomic read, it doesn't require a critical section. - * See @ref uavcan::CanIOFlagAbortOnError. - */ - uavcan::uint32_t getVoluntaryTxAbortCount() const { return served_aborts_cnt_; } - - /** - * Returns the number of frames pending in the RX queue. - * This is intended for debug use only. - */ - unsigned getRxQueueLength() const; - - /** - * Whether this iface had at least one successful IO since the previous call of this method. - * This is designed for use with iface activity LEDs. - */ - bool hadActivity(); - - /** - * Peak number of TX mailboxes used concurrently since initialization. - * Range is [1, 3]. - * Value of 3 suggests that priority inversion could be taking place. - */ - uavcan::uint8_t getPeakNumTxMailboxesUsed() const { return uavcan::uint8_t(peak_tx_mailbox_index_ + 1); } -}; - -/** - * CAN driver, incorporates all available CAN ifaces. - * Please avoid direct use, prefer @ref CanInitHelper instead. - */ -class CanDriver : public uavcan::ICanDriver, uavcan::Noncopyable -{ - BusEvent update_event_; - CanIface if0_; -#if UAVCAN_STM32_NUM_IFACES > 1 - CanIface if1_; -#endif - - virtual uavcan::int16_t select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces], - uavcan::MonotonicTime blocking_deadline); - - static void initOnce(); - -public: - template - CanDriver(CanRxItem (&rx_queue_storage)[UAVCAN_STM32_NUM_IFACES][RxQueueCapacity]) - : update_event_(*this) - , if0_(bxcan::Can[0], update_event_, 0, rx_queue_storage[0], RxQueueCapacity) -#if UAVCAN_STM32_NUM_IFACES > 1 - , if1_(bxcan::Can[1], update_event_, 1, rx_queue_storage[1], RxQueueCapacity) -#endif - { - uavcan::StaticAssert<(RxQueueCapacity <= CanIface::MaxRxQueueCapacity)>::check(); - } - - /** - * This function returns select masks indicating which interfaces are available for read/write. - */ - uavcan::CanSelectMasks makeSelectMasks(const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces]) const; - - /** - * Whether there's at least one interface where receive() would return a frame. - */ - bool hasReadableInterfaces() const; - - /** - * Returns zero if OK. - * Returns negative value if failed (e.g. invalid bitrate). - */ - int init(const uavcan::uint32_t bitrate, const CanIface::OperatingMode mode); - - virtual CanIface* getIface(uavcan::uint8_t iface_index); - - virtual uavcan::uint8_t getNumIfaces() const { return UAVCAN_STM32_NUM_IFACES; } - - /** - * Whether at least one iface had at least one successful IO since previous call of this method. - * This is designed for use with iface activity LEDs. - */ - bool hadActivity(); -}; - -/** - * Helper class. - * Normally only this class should be used by the application. - * 145 usec per Extended CAN frame @ 1 Mbps, e.g. 32 RX slots * 145 usec --> 4.6 msec before RX queue overruns. - */ -template -class CanInitHelper -{ - CanRxItem queue_storage_[UAVCAN_STM32_NUM_IFACES][RxQueueCapacity]; - -public: - enum { BitRateAutoDetect = 0 }; - - CanDriver driver; - - CanInitHelper() : - driver(queue_storage_) - { } - - /** - * This overload simply configures the provided bitrate. - * Auto bit rate detection will not be performed. - * Bitrate value must be positive. - * @return Negative value on error; non-negative on success. Refer to constants Err*. - */ - int init(uavcan::uint32_t bitrate) - { - return driver.init(bitrate, CanIface::NormalMode); - } - - /** - * This function can either initialize the driver at a fixed bit rate, or it can perform - * automatic bit rate detection. For theory please refer to the CiA application note #801. - * - * @param delay_callable A callable entity that suspends execution for strictly more than one second. - * The callable entity will be invoked without arguments. - * @ref getRecommendedListeningDelay(). - * - * @param inout_bitrate Fixed bit rate or zero. Zero invokes the bit rate detection process. - * If auto detection was used, the function will update the argument - * with established bit rate. In case of an error the value will be undefined. - * - * @return Negative value on error; non-negative on success. Refer to constants Err*. - */ - template - int init(DelayCallable delay_callable, uavcan::uint32_t& inout_bitrate = BitRateAutoDetect) - { - if (inout_bitrate > 0) - { - return driver.init(inout_bitrate, CanIface::NormalMode); - } - else - { - static const uavcan::uint32_t StandardBitRates[] = - { - 1000000, - 500000, - 250000, - 125000 - }; - - for (uavcan::uint8_t br = 0; br < sizeof(StandardBitRates) / sizeof(StandardBitRates[0]); br++) - { - inout_bitrate = StandardBitRates[br]; - - const int res = driver.init(inout_bitrate, CanIface::SilentMode); - - delay_callable(); - - if (res >= 0) - { - for (uavcan::uint8_t iface = 0; iface < driver.getNumIfaces(); iface++) - { - if (!driver.getIface(iface)->isRxBufferEmpty()) - { - // Re-initializing in normal mode - return driver.init(inout_bitrate, CanIface::NormalMode); - } - } - } - } - - return -ErrBitRateNotDetected; - } - } - - /** - * Use this value for listening delay during automatic bit rate detection. - */ - static uavcan::MonotonicDuration getRecommendedListeningDelay() - { - return uavcan::MonotonicDuration::fromMSec(1050); - } -}; - -} diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/clock.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/clock.hpp deleted file mode 100644 index 1f422f02dd..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/clock.hpp +++ /dev/null @@ -1,121 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include -#include - -namespace uavcan_stm32 -{ - -namespace clock -{ -/** - * Starts the clock. - * Can be called multiple times, only the first call will be effective. - */ -void init(); - -/** - * Returns current monotonic time since the moment when clock::init() was called. - * This function is thread safe. - */ -uavcan::MonotonicTime getMonotonic(); - -/** - * Sets the driver's notion of the system UTC. It should be called - * at startup and any time the system clock is updated from an - * external source that is not the UAVCAN Timesync master. - * This function is thread safe. - */ -void setUtc(uavcan::UtcTime time); - -/** - * Returns UTC time if it has been set, otherwise returns zero time. - * This function is thread safe. - */ -uavcan::UtcTime getUtc(); - -/** - * Performs UTC phase and frequency adjustment. - * The UTC time will be zero until first adjustment has been performed. - * This function is thread safe. - */ -void adjustUtc(uavcan::UtcDuration adjustment); - -/** - * UTC clock synchronization parameters - */ -struct UtcSyncParams -{ - float offset_p; ///< PPM per one usec error - float rate_i; ///< PPM per one PPM error for second - float rate_error_corner_freq; - float max_rate_correction_ppm; - float lock_thres_rate_ppm; - uavcan::UtcDuration lock_thres_offset; - uavcan::UtcDuration min_jump; ///< Min error to jump rather than change rate - - UtcSyncParams() - : offset_p(0.01F) - , rate_i(0.02F) - , rate_error_corner_freq(0.01F) - , max_rate_correction_ppm(300.0F) - , lock_thres_rate_ppm(2.0F) - , lock_thres_offset(uavcan::UtcDuration::fromMSec(4)) - , min_jump(uavcan::UtcDuration::fromMSec(10)) - { } -}; - -/** - * Clock rate error. - * Positive if the hardware timer is slower than reference time. - * This function is thread safe. - */ -float getUtcRateCorrectionPPM(); - -/** - * Number of non-gradual adjustments performed so far. - * Ideally should be zero. - * This function is thread safe. - */ -uavcan::uint32_t getUtcJumpCount(); - -/** - * Whether UTC is synchronized and locked. - * This function is thread safe. - */ -bool isUtcLocked(); - -/** - * UTC sync params get/set. - * Both functions are thread safe. - */ -UtcSyncParams getUtcSyncParams(); -void setUtcSyncParams(const UtcSyncParams& params); - -} - -/** - * Adapter for uavcan::ISystemClock. - */ -class SystemClock : public uavcan::ISystemClock, uavcan::Noncopyable -{ - SystemClock() { } - - virtual void adjustUtc(uavcan::UtcDuration adjustment) { clock::adjustUtc(adjustment); } - -public: - virtual uavcan::MonotonicTime getMonotonic() const { return clock::getMonotonic(); } - virtual uavcan::UtcTime getUtc() const { return clock::getUtc(); } - - /** - * Calls clock::init() as needed. - * This function is thread safe. - */ - static SystemClock& instance(); -}; - -} diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp deleted file mode 100644 index b2eac2a65c..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/thread.hpp +++ /dev/null @@ -1,239 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -#if UAVCAN_STM32_CHIBIOS -# include -#elif UAVCAN_STM32_NUTTX -# include -# include -# include -# include -# include -# include -# include -#elif UAVCAN_STM32_BAREMETAL -#elif UAVCAN_STM32_FREERTOS -# include -#else -# error "Unknown OS" -#endif - -#include - -namespace uavcan_stm32 -{ - -class CanDriver; - -#if UAVCAN_STM32_CHIBIOS - -class BusEvent -{ - chibios_rt::CounterSemaphore sem_; - -public: - BusEvent(CanDriver& can_driver) - : sem_(0) - { - (void)can_driver; - } - - bool wait(uavcan::MonotonicDuration duration); - - void signal(); - - void signalFromInterrupt(); -}; - -class Mutex -{ - chibios_rt::Mutex mtx_; - -public: - void lock(); - void unlock(); -}; - -#elif UAVCAN_STM32_NUTTX - -/** - * All bus events are reported as POLLIN. - */ -class BusEvent : uavcan::Noncopyable -{ - static const unsigned MaxPollWaiters = 8; - - ::file_operations file_ops_; - ::pollfd* pollset_[MaxPollWaiters]; - CanDriver& can_driver_; - bool signal_; - - static int openTrampoline(::file* filp); - static int closeTrampoline(::file* filp); - static int pollTrampoline(::file* filp, ::pollfd* fds, bool setup); - - int open(::file* filp); - int close(::file* filp); - int poll(::file* filp, ::pollfd* fds, bool setup); - - int addPollWaiter(::pollfd* fds); - int removePollWaiter(::pollfd* fds); - -public: - static const char* const DevName; - - BusEvent(CanDriver& can_driver); - ~BusEvent(); - - bool wait(uavcan::MonotonicDuration duration); - - void signalFromInterrupt(); -}; - -class Mutex -{ - pthread_mutex_t mutex_; - -public: - Mutex() - { - init(); - } - - int init() - { - return pthread_mutex_init(&mutex_, UAVCAN_NULLPTR); - } - - int deinit() - { - return pthread_mutex_destroy(&mutex_); - } - - void lock() - { - (void)pthread_mutex_lock(&mutex_); - } - - void unlock() - { - (void)pthread_mutex_unlock(&mutex_); - } -}; -#elif UAVCAN_STM32_BAREMETAL - -class BusEvent -{ - volatile bool ready; - -public: - BusEvent(CanDriver& can_driver) - : ready(false) - { - (void)can_driver; - } - - bool wait(uavcan::MonotonicDuration duration) - { - (void)duration; - bool lready = ready; - #if defined ( __CC_ARM ) - return __sync_lock_test_and_set(&lready, false); - #elif defined ( __GNUC__ ) - return __atomic_exchange_n (&lready, false, __ATOMIC_SEQ_CST); - #else - # error "This compiler is not supported" - #endif - } - - void signal() - { - #if defined ( __CC_ARM ) - __sync_lock_release(&ready); - #elif defined ( __GNUC__ ) - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); - #else - # error "This compiler is not supported" - #endif - } - - void signalFromInterrupt() - { - #if defined ( __CC_ARM ) - __sync_lock_release(&ready); - #elif defined ( __GNUC__ ) - __atomic_store_n (&ready, true, __ATOMIC_SEQ_CST); - #else - # error "This compiler is not supported" - #endif - } -}; - -class Mutex -{ -public: - void lock() { } - void unlock() { } -}; - -#elif UAVCAN_STM32_FREERTOS - -class BusEvent -{ - SemaphoreHandle_t sem_; - BaseType_t higher_priority_task_woken; - -public: - BusEvent(CanDriver& can_driver) - { - (void)can_driver; - sem_ = xSemaphoreCreateBinary(); - } - - bool wait(uavcan::MonotonicDuration duration); - - void signal(); - - void signalFromInterrupt(); - - void yieldFromISR(); -}; - -class Mutex -{ - SemaphoreHandle_t mtx_; - -public: - Mutex(void) - { - mtx_ = xSemaphoreCreateMutex(); - } - void lock(); - void unlock(); -}; - -#endif - - -class MutexLocker -{ - Mutex& mutex_; - -public: - MutexLocker(Mutex& mutex) - : mutex_(mutex) - { - mutex_.lock(); - } - ~MutexLocker() - { - mutex_.unlock(); - } -}; - -} diff --git a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/uavcan_stm32.hpp b/libuavcan_drivers/stm32/driver/include/uavcan_stm32/uavcan_stm32.hpp deleted file mode 100644 index e55d48506c..0000000000 --- a/libuavcan_drivers/stm32/driver/include/uavcan_stm32/uavcan_stm32.hpp +++ /dev/null @@ -1,11 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -#include -#include -#include diff --git a/libuavcan_drivers/stm32/driver/src/internal.hpp b/libuavcan_drivers/stm32/driver/src/internal.hpp deleted file mode 100644 index 267d15392f..0000000000 --- a/libuavcan_drivers/stm32/driver/src/internal.hpp +++ /dev/null @@ -1,159 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#pragma once - -#include - -#if UAVCAN_STM32_CHIBIOS -# include -#elif UAVCAN_STM32_NUTTX -# include -# include -#include -# include -#elif UAVCAN_STM32_BAREMETAL -#include // See http://uavcan.org/Implementations/Libuavcan/Platforms/STM32/ -#elif UAVCAN_STM32_FREERTOS -# include -# include -#else -# error "Unknown OS" -#endif - -/** - * Debug output - */ -#ifndef UAVCAN_STM32_LOG -// syslog() crashes the system in this context -// # if UAVCAN_STM32_NUTTX && CONFIG_ARCH_LOWPUTC -# if 0 -# define UAVCAN_STM32_LOG(fmt, ...) syslog("uavcan_stm32: " fmt "\n", ##__VA_ARGS__) -# else -# define UAVCAN_STM32_LOG(...) ((void)0) -# endif -#endif - -/** - * IRQ handler macros - */ -#if UAVCAN_STM32_CHIBIOS -# define UAVCAN_STM32_IRQ_HANDLER(id) CH_IRQ_HANDLER(id) -# define UAVCAN_STM32_IRQ_PROLOGUE() CH_IRQ_PROLOGUE() -# define UAVCAN_STM32_IRQ_EPILOGUE() CH_IRQ_EPILOGUE() -#elif UAVCAN_STM32_NUTTX -# define UAVCAN_STM32_IRQ_HANDLER(id) int id(int irq, FAR void* context, FAR void *arg) -# define UAVCAN_STM32_IRQ_PROLOGUE() -# define UAVCAN_STM32_IRQ_EPILOGUE() return 0; -#else -# define UAVCAN_STM32_IRQ_HANDLER(id) void id(void) -# define UAVCAN_STM32_IRQ_PROLOGUE() -# define UAVCAN_STM32_IRQ_EPILOGUE() -#endif - -#if UAVCAN_STM32_CHIBIOS -/** - * Priority mask for timer and CAN interrupts. - */ -# ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK -# if (CH_KERNEL_MAJOR == 2) -# define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_PRIORITY_MASK(CORTEX_MAX_KERNEL_PRIORITY) -# else // ChibiOS 3+ -# define UAVCAN_STM32_IRQ_PRIORITY_MASK CORTEX_MAX_KERNEL_PRIORITY -# endif -# endif -#endif - -#if UAVCAN_STM32_BAREMETAL -/** - * Priority mask for timer and CAN interrupts. - */ -# ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK -# define UAVCAN_STM32_IRQ_PRIORITY_MASK 0 -# endif -#endif - -#if UAVCAN_STM32_FREERTOS -/** - * Priority mask for timer and CAN interrupts. - */ -# ifndef UAVCAN_STM32_IRQ_PRIORITY_MASK -# define UAVCAN_STM32_IRQ_PRIORITY_MASK configLIBRARY_MAX_SYSCALL_INTERRUPT_PRIORITY -# endif -#endif - -/** - * Glue macros - */ -#define UAVCAN_STM32_GLUE2_(A, B) A##B -#define UAVCAN_STM32_GLUE2(A, B) UAVCAN_STM32_GLUE2_(A, B) - -#define UAVCAN_STM32_GLUE3_(A, B, C) A##B##C -#define UAVCAN_STM32_GLUE3(A, B, C) UAVCAN_STM32_GLUE3_(A, B, C) - -namespace uavcan_stm32 -{ -#if UAVCAN_STM32_CHIBIOS - -struct CriticalSectionLocker -{ - CriticalSectionLocker() { chSysSuspend(); } - ~CriticalSectionLocker() { chSysEnable(); } -}; - -#elif UAVCAN_STM32_NUTTX - -struct CriticalSectionLocker -{ - const irqstate_t flags_; - - CriticalSectionLocker() - : flags_(enter_critical_section()) - { } - - ~CriticalSectionLocker() - { - leave_critical_section(flags_); - } -}; - -#elif UAVCAN_STM32_BAREMETAL - -struct CriticalSectionLocker -{ - - CriticalSectionLocker() - { - __disable_irq(); - } - - ~CriticalSectionLocker() - { - __enable_irq(); - } -}; - -#elif UAVCAN_STM32_FREERTOS - -struct CriticalSectionLocker -{ - - CriticalSectionLocker() - { - taskENTER_CRITICAL(); - } - - ~CriticalSectionLocker() - { - taskEXIT_CRITICAL(); - } -}; - -#endif - -namespace clock -{ -uavcan::uint64_t getUtcUSecFromCanInterrupt(); -} -} diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp deleted file mode 100644 index 2fe8ad67e0..0000000000 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_can.cpp +++ /dev/null @@ -1,1235 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include -#include "internal.hpp" - -#if UAVCAN_STM32_CHIBIOS -# include -#elif UAVCAN_STM32_NUTTX -# include -# include -# include -#elif UAVCAN_STM32_BAREMETAL -#include // See http://uavcan.org/Implementations/Libuavcan/Platforms/STM32/ -#elif UAVCAN_STM32_FREERTOS -#else -# error "Unknown OS" -#endif - -#if (UAVCAN_STM32_CHIBIOS && CH_KERNEL_MAJOR == 2) || UAVCAN_STM32_BAREMETAL -# if !(defined(STM32F10X_CL) || defined(STM32F2XX) || defined(STM32F3XX) || defined(STM32F4XX)) -// IRQ numbers -# define CAN1_RX0_IRQn USB_LP_CAN1_RX0_IRQn -# define CAN1_TX_IRQn USB_HP_CAN1_TX_IRQn -// IRQ vectors -# if !defined(CAN1_RX0_IRQHandler) || !defined(CAN1_TX_IRQHandler) -# define CAN1_TX_IRQHandler USB_HP_CAN1_TX_IRQHandler -# define CAN1_RX0_IRQHandler USB_LP_CAN1_RX0_IRQHandler -# endif -# endif -#endif - -#if (UAVCAN_STM32_CHIBIOS && (CH_KERNEL_MAJOR == 3 || CH_KERNEL_MAJOR == 4 || CH_KERNEL_MAJOR == 5)) -#define CAN1_TX_IRQHandler STM32_CAN1_TX_HANDLER -#define CAN1_RX0_IRQHandler STM32_CAN1_RX0_HANDLER -#define CAN1_RX1_IRQHandler STM32_CAN1_RX1_HANDLER -#define CAN2_TX_IRQHandler STM32_CAN2_TX_HANDLER -#define CAN2_RX0_IRQHandler STM32_CAN2_RX0_HANDLER -#define CAN2_RX1_IRQHandler STM32_CAN2_RX1_HANDLER -#endif - -#if UAVCAN_STM32_NUTTX -# if !defined(STM32_IRQ_CAN1TX) && !defined(STM32_IRQ_CAN1RX0) -# define STM32_IRQ_CAN1TX STM32_IRQ_USBHPCANTX -# define STM32_IRQ_CAN1RX0 STM32_IRQ_USBLPCANRX0 -# endif -extern "C" -{ -static int can1_irq(const int irq, void*, void*); -#if UAVCAN_STM32_NUM_IFACES > 1 -static int can2_irq(const int irq, void*, void*); -#endif -} -#endif - -/* STM32F3's only CAN inteface does not have a number. */ -#if defined(STM32F3XX) -#define RCC_APB1ENR_CAN1EN RCC_APB1ENR_CANEN -#define RCC_APB1RSTR_CAN1RST RCC_APB1RSTR_CANRST -#define CAN1_TX_IRQn CAN_TX_IRQn -#define CAN1_RX0_IRQn CAN_RX0_IRQn -#define CAN1_RX1_IRQn CAN_RX1_IRQn -# if UAVCAN_STM32_BAREMETAL -# define CAN1_TX_IRQHandler CAN_TX_IRQHandler -# define CAN1_RX0_IRQHandler CAN_RX0_IRQHandler -# define CAN1_RX1_IRQHandler CAN_RX1_IRQHandler -# endif -#endif - - -namespace uavcan_stm32 -{ -namespace -{ - -CanIface* ifaces[UAVCAN_STM32_NUM_IFACES] = -{ - UAVCAN_NULLPTR -#if UAVCAN_STM32_NUM_IFACES > 1 - , UAVCAN_NULLPTR -#endif -}; - -inline void handleTxInterrupt(uavcan::uint8_t iface_index) -{ - UAVCAN_ASSERT(iface_index < UAVCAN_STM32_NUM_IFACES); - uavcan::uint64_t utc_usec = clock::getUtcUSecFromCanInterrupt(); - if (utc_usec > 0) - { - utc_usec--; - } - if (ifaces[iface_index] != UAVCAN_NULLPTR) - { - ifaces[iface_index]->handleTxInterrupt(utc_usec); - } - else - { - UAVCAN_ASSERT(0); - } -} - -inline void handleRxInterrupt(uavcan::uint8_t iface_index, uavcan::uint8_t fifo_index) -{ - UAVCAN_ASSERT(iface_index < UAVCAN_STM32_NUM_IFACES); - uavcan::uint64_t utc_usec = clock::getUtcUSecFromCanInterrupt(); - if (utc_usec > 0) - { - utc_usec--; - } - if (ifaces[iface_index] != UAVCAN_NULLPTR) - { - ifaces[iface_index]->handleRxInterrupt(fifo_index, utc_usec); - } - else - { - UAVCAN_ASSERT(0); - } -} - -} // namespace - -/* - * CanIface::RxQueue - */ -void CanIface::RxQueue::registerOverflow() -{ - if (overflow_cnt_ < 0xFFFFFFFF) - { - overflow_cnt_++; - } -} - -void CanIface::RxQueue::push(const uavcan::CanFrame& frame, const uint64_t& utc_usec, uavcan::CanIOFlags flags) -{ - buf_[in_].frame = frame; - buf_[in_].utc_usec = utc_usec; - buf_[in_].flags = flags; - in_++; - if (in_ >= capacity_) - { - in_ = 0; - } - len_++; - if (len_ > capacity_) - { - len_ = capacity_; - registerOverflow(); - out_++; - if (out_ >= capacity_) - { - out_ = 0; - } - } -} - -void CanIface::RxQueue::pop(uavcan::CanFrame& out_frame, uavcan::uint64_t& out_utc_usec, uavcan::CanIOFlags& out_flags) -{ - if (len_ > 0) - { - out_frame = buf_[out_].frame; - out_utc_usec = buf_[out_].utc_usec; - out_flags = buf_[out_].flags; - out_++; - if (out_ >= capacity_) - { - out_ = 0; - } - len_--; - } - else { UAVCAN_ASSERT(0); } -} - -void CanIface::RxQueue::reset() -{ - in_ = 0; - out_ = 0; - len_ = 0; - overflow_cnt_ = 0; -} - -/* - * CanIface - */ -const uavcan::uint32_t CanIface::TSR_ABRQx[CanIface::NumTxMailboxes] = -{ - bxcan::TSR_ABRQ0, - bxcan::TSR_ABRQ1, - bxcan::TSR_ABRQ2 -}; - -int CanIface::computeTimings(const uavcan::uint32_t target_bitrate, Timings& out_timings) -{ - if (target_bitrate < 1) - { - return -ErrInvalidBitRate; - } - - /* - * Hardware configuration - */ -#if UAVCAN_STM32_BAREMETAL - const uavcan::uint32_t pclk = STM32_PCLK1; -#elif UAVCAN_STM32_CHIBIOS - const uavcan::uint32_t pclk = STM32_PCLK1; -#elif UAVCAN_STM32_NUTTX - const uavcan::uint32_t pclk = STM32_PCLK1_FREQUENCY; -#elif UAVCAN_STM32_FREERTOS - const uavcan::uint32_t pclk = HAL_RCC_GetPCLK1Freq(); -#else -# error "Unknown OS" -#endif - - static const int MaxBS1 = 16; - static const int MaxBS2 = 8; - - /* - * Ref. "Automatic Baudrate Detection in CANopen Networks", U. Koppe, MicroControl GmbH & Co. KG - * CAN in Automation, 2003 - * - * According to the source, optimal quanta per bit are: - * Bitrate Optimal Maximum - * 1000 kbps 8 10 - * 500 kbps 16 17 - * 250 kbps 16 17 - * 125 kbps 16 17 - */ - const int max_quanta_per_bit = (target_bitrate >= 1000000) ? 10 : 17; - - UAVCAN_ASSERT(max_quanta_per_bit <= (MaxBS1 + MaxBS2)); - - static const int MaxSamplePointLocation = 900; - - /* - * Computing (prescaler * BS): - * BITRATE = 1 / (PRESCALER * (1 / PCLK) * (1 + BS1 + BS2)) -- See the Reference Manual - * BITRATE = PCLK / (PRESCALER * (1 + BS1 + BS2)) -- Simplified - * let: - * BS = 1 + BS1 + BS2 -- Number of time quanta per bit - * PRESCALER_BS = PRESCALER * BS - * ==> - * PRESCALER_BS = PCLK / BITRATE - */ - const uavcan::uint32_t prescaler_bs = pclk / target_bitrate; - - /* - * Searching for such prescaler value so that the number of quanta per bit is highest. - */ - uavcan::uint8_t bs1_bs2_sum = uavcan::uint8_t(max_quanta_per_bit - 1); - - while ((prescaler_bs % (1 + bs1_bs2_sum)) != 0) - { - if (bs1_bs2_sum <= 2) - { - return -ErrInvalidBitRate; // No solution - } - bs1_bs2_sum--; - } - - const uavcan::uint32_t prescaler = prescaler_bs / (1 + bs1_bs2_sum); - if ((prescaler < 1U) || (prescaler > 1024U)) - { - return -ErrInvalidBitRate; // No solution - } - - /* - * Now we have a constraint: (BS1 + BS2) == bs1_bs2_sum. - * We need to find the values so that the sample point is as close as possible to the optimal value. - * - * Solve[(1 + bs1)/(1 + bs1 + bs2) == 7/8, bs2] (* Where 7/8 is 0.875, the recommended sample point location *) - * {{bs2 -> (1 + bs1)/7}} - * - * Hence: - * bs2 = (1 + bs1) / 7 - * bs1 = (7 * bs1_bs2_sum - 1) / 8 - * - * Sample point location can be computed as follows: - * Sample point location = (1 + bs1) / (1 + bs1 + bs2) - * - * Since the optimal solution is so close to the maximum, we prepare two solutions, and then pick the best one: - * - With rounding to nearest - * - With rounding to zero - */ - struct BsPair - { - uavcan::uint8_t bs1; - uavcan::uint8_t bs2; - uavcan::uint16_t sample_point_permill; - - BsPair() : - bs1(0), - bs2(0), - sample_point_permill(0) - { } - - BsPair(uavcan::uint8_t bs1_bs2_sum, uavcan::uint8_t arg_bs1) : - bs1(arg_bs1), - bs2(uavcan::uint8_t(bs1_bs2_sum - bs1)), - sample_point_permill(uavcan::uint16_t(1000 * (1 + bs1) / (1 + bs1 + bs2))) - { - UAVCAN_ASSERT(bs1_bs2_sum > arg_bs1); - } - - bool isValid() const { return (bs1 >= 1) && (bs1 <= MaxBS1) && (bs2 >= 1) && (bs2 <= MaxBS2); } - }; - - // First attempt with rounding to nearest - BsPair solution(bs1_bs2_sum, uavcan::uint8_t(((7 * bs1_bs2_sum - 1) + 4) / 8)); - - if (solution.sample_point_permill > MaxSamplePointLocation) - { - // Second attempt with rounding to zero - solution = BsPair(bs1_bs2_sum, uavcan::uint8_t((7 * bs1_bs2_sum - 1) / 8)); - } - - /* - * Final validation - * Helpful Python: - * def sample_point_from_btr(x): - * assert 0b0011110010000000111111000000000 & x == 0 - * ts2,ts1,brp = (x>>20)&7, (x>>16)&15, x&511 - * return (1+ts1+1)/(1+ts1+1+ts2+1) - * - */ - if ((target_bitrate != (pclk / (prescaler * (1 + solution.bs1 + solution.bs2)))) || !solution.isValid()) - { - UAVCAN_ASSERT(0); - return -ErrLogic; - } - - UAVCAN_STM32_LOG("Timings: quanta/bit: %d, sample point location: %.1f%%", - int(1 + solution.bs1 + solution.bs2), float(solution.sample_point_permill) / 10.F); - - out_timings.prescaler = uavcan::uint16_t(prescaler - 1U); - out_timings.sjw = 0; // Which means one - out_timings.bs1 = uavcan::uint8_t(solution.bs1 - 1); - out_timings.bs2 = uavcan::uint8_t(solution.bs2 - 1); - return 0; -} - -uavcan::int16_t CanIface::send(const uavcan::CanFrame& frame, uavcan::MonotonicTime tx_deadline, - uavcan::CanIOFlags flags) -{ - if (frame.isErrorFrame() || frame.dlc > 8) - { - return -ErrUnsupportedFrame; - } - - /* - * Normally we should perform the same check as in @ref canAcceptNewTxFrame(), because - * it is possible that the highest-priority frame between select() and send() could have been - * replaced with a lower priority one due to TX timeout. But we don't do this check because: - * - * - It is a highly unlikely scenario. - * - * - Frames do not timeout on a properly functioning bus. Since frames do not timeout, the new - * frame can only have higher priority, which doesn't break the logic. - * - * - If high-priority frames are timing out in the TX queue, there's probably a lot of other - * issues to take care of before this one becomes relevant. - * - * - It takes CPU time. Not just CPU time, but critical section time, which is expensive. - */ - CriticalSectionLocker lock; - - /* - * Seeking for an empty slot - */ - uavcan::uint8_t txmailbox = 0xFF; - if ((can_->TSR & bxcan::TSR_TME0) == bxcan::TSR_TME0) - { - txmailbox = 0; - } - else if ((can_->TSR & bxcan::TSR_TME1) == bxcan::TSR_TME1) - { - txmailbox = 1; - } - else if ((can_->TSR & bxcan::TSR_TME2) == bxcan::TSR_TME2) - { - txmailbox = 2; - } - else - { - return 0; // No transmission for you. - } - - peak_tx_mailbox_index_ = uavcan::max(peak_tx_mailbox_index_, txmailbox); // Statistics - - /* - * Setting up the mailbox - */ - bxcan::TxMailboxType& mb = can_->TxMailbox[txmailbox]; - if (frame.isExtended()) - { - mb.TIR = ((frame.id & uavcan::CanFrame::MaskExtID) << 3) | bxcan::TIR_IDE; - } - else - { - mb.TIR = ((frame.id & uavcan::CanFrame::MaskStdID) << 21); - } - - if (frame.isRemoteTransmissionRequest()) - { - mb.TIR |= bxcan::TIR_RTR; - } - - mb.TDTR = frame.dlc; - - mb.TDHR = (uavcan::uint32_t(frame.data[7]) << 24) | - (uavcan::uint32_t(frame.data[6]) << 16) | - (uavcan::uint32_t(frame.data[5]) << 8) | - (uavcan::uint32_t(frame.data[4]) << 0); - mb.TDLR = (uavcan::uint32_t(frame.data[3]) << 24) | - (uavcan::uint32_t(frame.data[2]) << 16) | - (uavcan::uint32_t(frame.data[1]) << 8) | - (uavcan::uint32_t(frame.data[0]) << 0); - - mb.TIR |= bxcan::TIR_TXRQ; // Go. - - /* - * Registering the pending transmission so we can track its deadline and loopback it as needed - */ - TxItem& txi = pending_tx_[txmailbox]; - txi.deadline = tx_deadline; - txi.frame = frame; - txi.loopback = (flags & uavcan::CanIOFlagLoopback) != 0; - txi.abort_on_error = (flags & uavcan::CanIOFlagAbortOnError) != 0; - txi.pending = true; - return 1; -} - -uavcan::int16_t CanIface::receive(uavcan::CanFrame& out_frame, uavcan::MonotonicTime& out_ts_monotonic, - uavcan::UtcTime& out_ts_utc, uavcan::CanIOFlags& out_flags) -{ - out_ts_monotonic = clock::getMonotonic(); // High precision is not required for monotonic timestamps - uavcan::uint64_t utc_usec = 0; - { - CriticalSectionLocker lock; - if (rx_queue_.getLength() == 0) - { - return 0; - } - rx_queue_.pop(out_frame, utc_usec, out_flags); - } - out_ts_utc = uavcan::UtcTime::fromUSec(utc_usec); - return 1; -} - -uavcan::int16_t CanIface::configureFilters(const uavcan::CanFilterConfig* filter_configs, - uavcan::uint16_t num_configs) -{ - if (num_configs <= NumFilters) - { - CriticalSectionLocker lock; - - can_->FMR |= bxcan::FMR_FINIT; - - // Slave (CAN2) gets half of the filters - can_->FMR &= ~0x00003F00UL; - can_->FMR |= static_cast(NumFilters) << 8; - - can_->FFA1R = 0x0AAAAAAA; // FIFO's are interleaved between filters - can_->FM1R = 0; // Identifier Mask mode - can_->FS1R = 0x7ffffff; // Single 32-bit for all - - const uint8_t filter_start_index = (self_index_ == 0) ? 0 : NumFilters; - - if (num_configs == 0) - { - can_->FilterRegister[filter_start_index].FR1 = 0; - can_->FilterRegister[filter_start_index].FR2 = 0; - // We can't directly overwrite FA1R because that breaks the other CAN interface - can_->FA1R |= 1U << filter_start_index; // Other filters may still be enabled, we don't care - } - else - { - for (uint8_t i = 0; i < NumFilters; i++) - { - if (i < num_configs) - { - uint32_t id = 0; - uint32_t mask = 0; - - const uavcan::CanFilterConfig* const cfg = filter_configs + i; - - if ((cfg->id & uavcan::CanFrame::FlagEFF) || !(cfg->mask & uavcan::CanFrame::FlagEFF)) - { - id = (cfg->id & uavcan::CanFrame::MaskExtID) << 3; - mask = (cfg->mask & uavcan::CanFrame::MaskExtID) << 3; - id |= bxcan::RIR_IDE; - } - else - { - id = (cfg->id & uavcan::CanFrame::MaskStdID) << 21; // Regular std frames, nothing fancy. - mask = (cfg->mask & uavcan::CanFrame::MaskStdID) << 21; // Boring. - } - - if (cfg->id & uavcan::CanFrame::FlagRTR) - { - id |= bxcan::RIR_RTR; - } - - if (cfg->mask & uavcan::CanFrame::FlagEFF) - { - mask |= bxcan::RIR_IDE; - } - - if (cfg->mask & uavcan::CanFrame::FlagRTR) - { - mask |= bxcan::RIR_RTR; - } - - can_->FilterRegister[filter_start_index + i].FR1 = id; - can_->FilterRegister[filter_start_index + i].FR2 = mask; - - can_->FA1R |= (1 << (filter_start_index + i)); - } - else - { - can_->FA1R &= ~(1 << (filter_start_index + i)); - } - } - } - - can_->FMR &= ~bxcan::FMR_FINIT; - - return 0; - } - - return -ErrFilterNumConfigs; -} - -bool CanIface::waitMsrINakBitStateChange(bool target_state) -{ -#if UAVCAN_STM32_NUTTX || UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_FREERTOS - const unsigned Timeout = 1000; -#else - const unsigned Timeout = 2000000; -#endif - for (unsigned wait_ack = 0; wait_ack < Timeout; wait_ack++) - { - const bool state = (can_->MSR & bxcan::MSR_INAK) != 0; - if (state == target_state) - { - return true; - } -#if UAVCAN_STM32_NUTTX - ::usleep(1000); -#endif -#if UAVCAN_STM32_CHIBIOS -#ifdef MS2ST - ::chThdSleep(MS2ST(1)); -#else - ::chThdSleep(TIME_MS2I(1)); -#endif -#endif -#if UAVCAN_STM32_FREERTOS - ::osDelay(1); -#endif - } - return false; -} - -int CanIface::init(const uavcan::uint32_t bitrate, const OperatingMode mode) -{ - /* - * We need to silence the controller in the first order, otherwise it may interfere with the following operations. - */ - { - CriticalSectionLocker lock; - - can_->MCR &= ~bxcan::MCR_SLEEP; // Exit sleep mode - can_->MCR |= bxcan::MCR_INRQ; // Request init - - can_->IER = 0; // Disable interrupts while initialization is in progress - } - - if (!waitMsrINakBitStateChange(true)) - { - UAVCAN_STM32_LOG("MSR INAK not set"); - can_->MCR = bxcan::MCR_RESET; - return -ErrMsrInakNotSet; - } - - /* - * Object state - interrupts are disabled, so it's safe to modify it now - */ - rx_queue_.reset(); - error_cnt_ = 0; - served_aborts_cnt_ = 0; - uavcan::fill_n(pending_tx_, NumTxMailboxes, TxItem()); - peak_tx_mailbox_index_ = 0; - had_activity_ = false; - - /* - * CAN timings for this bitrate - */ - Timings timings; - const int timings_res = computeTimings(bitrate, timings); - if (timings_res < 0) - { - can_->MCR = bxcan::MCR_RESET; - return timings_res; - } - UAVCAN_STM32_LOG("Timings: presc=%u sjw=%u bs1=%u bs2=%u", - unsigned(timings.prescaler), unsigned(timings.sjw), unsigned(timings.bs1), unsigned(timings.bs2)); - - /* - * Hardware initialization (the hardware has already confirmed initialization mode, see above) - */ - can_->MCR = bxcan::MCR_ABOM | bxcan::MCR_AWUM | bxcan::MCR_INRQ; // RM page 648 - - can_->BTR = ((timings.sjw & 3U) << 24) | - ((timings.bs1 & 15U) << 16) | - ((timings.bs2 & 7U) << 20) | - (timings.prescaler & 1023U) | - ((mode == SilentMode) ? bxcan::BTR_SILM : 0); - - can_->IER = bxcan::IER_TMEIE | // TX mailbox empty - bxcan::IER_FMPIE0 | // RX FIFO 0 is not empty - bxcan::IER_FMPIE1; // RX FIFO 1 is not empty - - can_->MCR &= ~bxcan::MCR_INRQ; // Leave init mode - - if (!waitMsrINakBitStateChange(false)) - { - UAVCAN_STM32_LOG("MSR INAK not cleared"); - can_->MCR = bxcan::MCR_RESET; - return -ErrMsrInakNotCleared; - } - - /* - * Default filter configuration - */ - if (self_index_ == 0) - { - can_->FMR |= bxcan::FMR_FINIT; - - can_->FMR &= 0xFFFFC0F1; - can_->FMR |= static_cast(NumFilters) << 8; // Slave (CAN2) gets half of the filters - - can_->FFA1R = 0; // All assigned to FIFO0 by default - can_->FM1R = 0; // Indentifier Mask mode - -#if UAVCAN_STM32_NUM_IFACES > 1 - can_->FS1R = 0x7ffffff; // Single 32-bit for all - can_->FilterRegister[0].FR1 = 0; // CAN1 accepts everything - can_->FilterRegister[0].FR2 = 0; - can_->FilterRegister[NumFilters].FR1 = 0; // CAN2 accepts everything - can_->FilterRegister[NumFilters].FR2 = 0; - can_->FA1R = 1 | (1 << NumFilters); // One filter per each iface -#else - can_->FS1R = 0x1fff; - can_->FilterRegister[0].FR1 = 0; - can_->FilterRegister[0].FR2 = 0; - can_->FA1R = 1; -#endif - - can_->FMR &= ~bxcan::FMR_FINIT; - } - - return 0; -} - -void CanIface::handleTxMailboxInterrupt(uavcan::uint8_t mailbox_index, bool txok, const uavcan::uint64_t utc_usec) -{ - UAVCAN_ASSERT(mailbox_index < NumTxMailboxes); - - had_activity_ = had_activity_ || txok; - - TxItem& txi = pending_tx_[mailbox_index]; - - if (txi.loopback && txok && txi.pending) - { - rx_queue_.push(txi.frame, utc_usec, uavcan::CanIOFlagLoopback); - } - - txi.pending = false; -} - -void CanIface::handleTxInterrupt(const uavcan::uint64_t utc_usec) -{ - // TXOK == false means that there was a hardware failure - if (can_->TSR & bxcan::TSR_RQCP0) - { - const bool txok = can_->TSR & bxcan::TSR_TXOK0; - can_->TSR = bxcan::TSR_RQCP0; - handleTxMailboxInterrupt(0, txok, utc_usec); - } - if (can_->TSR & bxcan::TSR_RQCP1) - { - const bool txok = can_->TSR & bxcan::TSR_TXOK1; - can_->TSR = bxcan::TSR_RQCP1; - handleTxMailboxInterrupt(1, txok, utc_usec); - } - if (can_->TSR & bxcan::TSR_RQCP2) - { - const bool txok = can_->TSR & bxcan::TSR_TXOK2; - can_->TSR = bxcan::TSR_RQCP2; - handleTxMailboxInterrupt(2, txok, utc_usec); - } - update_event_.signalFromInterrupt(); - - pollErrorFlagsFromISR(); - - #if UAVCAN_STM32_FREERTOS - update_event_.yieldFromISR(); - #endif -} - -void CanIface::handleRxInterrupt(uavcan::uint8_t fifo_index, uavcan::uint64_t utc_usec) -{ - UAVCAN_ASSERT(fifo_index < 2); - - volatile uavcan::uint32_t* const rfr_reg = (fifo_index == 0) ? &can_->RF0R : &can_->RF1R; - if ((*rfr_reg & bxcan::RFR_FMP_MASK) == 0) - { - UAVCAN_ASSERT(0); // Weird, IRQ is here but no data to read - return; - } - - /* - * Register overflow as a hardware error - */ - if ((*rfr_reg & bxcan::RFR_FOVR) != 0) - { - error_cnt_++; - } - - /* - * Read the frame contents - */ - uavcan::CanFrame frame; - const bxcan::RxMailboxType& rf = can_->RxMailbox[fifo_index]; - - if ((rf.RIR & bxcan::RIR_IDE) == 0) - { - frame.id = uavcan::CanFrame::MaskStdID & (rf.RIR >> 21); - } - else - { - frame.id = uavcan::CanFrame::MaskExtID & (rf.RIR >> 3); - frame.id |= uavcan::CanFrame::FlagEFF; - } - - if ((rf.RIR & bxcan::RIR_RTR) != 0) - { - frame.id |= uavcan::CanFrame::FlagRTR; - } - - frame.dlc = rf.RDTR & 15; - - frame.data[0] = uavcan::uint8_t(0xFF & (rf.RDLR >> 0)); - frame.data[1] = uavcan::uint8_t(0xFF & (rf.RDLR >> 8)); - frame.data[2] = uavcan::uint8_t(0xFF & (rf.RDLR >> 16)); - frame.data[3] = uavcan::uint8_t(0xFF & (rf.RDLR >> 24)); - frame.data[4] = uavcan::uint8_t(0xFF & (rf.RDHR >> 0)); - frame.data[5] = uavcan::uint8_t(0xFF & (rf.RDHR >> 8)); - frame.data[6] = uavcan::uint8_t(0xFF & (rf.RDHR >> 16)); - frame.data[7] = uavcan::uint8_t(0xFF & (rf.RDHR >> 24)); - - *rfr_reg = bxcan::RFR_RFOM | bxcan::RFR_FOVR | bxcan::RFR_FULL; // Release FIFO entry we just read - - /* - * Store with timeout into the FIFO buffer and signal update event - */ - rx_queue_.push(frame, utc_usec, 0); - had_activity_ = true; - update_event_.signalFromInterrupt(); - - pollErrorFlagsFromISR(); - - #if UAVCAN_STM32_FREERTOS - update_event_.yieldFromISR(); - #endif -} - -void CanIface::pollErrorFlagsFromISR() -{ - const uavcan::uint8_t lec = uavcan::uint8_t((can_->ESR & bxcan::ESR_LEC_MASK) >> bxcan::ESR_LEC_SHIFT); - if (lec != 0) - { - can_->ESR = 0; - error_cnt_++; - - // Serving abort requests - for (int i = 0; i < NumTxMailboxes; i++) // Dear compiler, may I suggest you to unroll this loop please. - { - TxItem& txi = pending_tx_[i]; - if (txi.pending && txi.abort_on_error) - { - can_->TSR = TSR_ABRQx[i]; - txi.pending = false; - served_aborts_cnt_++; - } - } - } -} - -void CanIface::discardTimedOutTxMailboxes(uavcan::MonotonicTime current_time) -{ - CriticalSectionLocker lock; - for (int i = 0; i < NumTxMailboxes; i++) - { - TxItem& txi = pending_tx_[i]; - if (txi.pending && txi.deadline < current_time) - { - can_->TSR = TSR_ABRQx[i]; // Goodnight sweet transmission - txi.pending = false; - error_cnt_++; - } - } -} - -bool CanIface::canAcceptNewTxFrame(const uavcan::CanFrame& frame) const -{ - /* - * We can accept more frames only if the following conditions are satisfied: - * - There is at least one TX mailbox free (obvious enough); - * - The priority of the new frame is higher than priority of all TX mailboxes. - */ - { - static const uavcan::uint32_t TME = bxcan::TSR_TME0 | bxcan::TSR_TME1 | bxcan::TSR_TME2; - const uavcan::uint32_t tme = can_->TSR & TME; - - if (tme == TME) // All TX mailboxes are free (as in freedom). - { - return true; - } - - if (tme == 0) // All TX mailboxes are busy transmitting. - { - return false; - } - } - - /* - * The second condition requires a critical section. - */ - CriticalSectionLocker lock; - - for (int mbx = 0; mbx < NumTxMailboxes; mbx++) - { - if (pending_tx_[mbx].pending && !frame.priorityHigherThan(pending_tx_[mbx].frame)) - { - return false; // There's a mailbox whose priority is higher or equal the priority of the new frame. - } - } - - return true; // This new frame will be added to a free TX mailbox in the next @ref send(). -} - -bool CanIface::isRxBufferEmpty() const -{ - CriticalSectionLocker lock; - return rx_queue_.getLength() == 0; -} - -uavcan::uint64_t CanIface::getErrorCount() const -{ - CriticalSectionLocker lock; - return error_cnt_ + rx_queue_.getOverflowCount(); -} - -unsigned CanIface::getRxQueueLength() const -{ - CriticalSectionLocker lock; - return rx_queue_.getLength(); -} - -bool CanIface::hadActivity() -{ - CriticalSectionLocker lock; - const bool ret = had_activity_; - had_activity_ = false; - return ret; -} - -/* - * CanDriver - */ -uavcan::CanSelectMasks CanDriver::makeSelectMasks(const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces]) const -{ - uavcan::CanSelectMasks msk; - - // Iface 0 - msk.read = if0_.isRxBufferEmpty() ? 0 : 1; - - if (pending_tx[0] != UAVCAN_NULLPTR) - { - msk.write = if0_.canAcceptNewTxFrame(*pending_tx[0]) ? 1 : 0; - } - - // Iface 1 -#if UAVCAN_STM32_NUM_IFACES > 1 - if (!if1_.isRxBufferEmpty()) - { - msk.read |= 1 << 1; - } - - if (pending_tx[1] != UAVCAN_NULLPTR) - { - if (if1_.canAcceptNewTxFrame(*pending_tx[1])) - { - msk.write |= 1 << 1; - } - } -#endif - return msk; -} - -bool CanDriver::hasReadableInterfaces() const -{ -#if UAVCAN_STM32_NUM_IFACES == 1 - return !if0_.isRxBufferEmpty(); -#elif UAVCAN_STM32_NUM_IFACES == 2 - return !if0_.isRxBufferEmpty() || !if1_.isRxBufferEmpty(); -#else -# error UAVCAN_STM32_NUM_IFACES -#endif -} - -uavcan::int16_t CanDriver::select(uavcan::CanSelectMasks& inout_masks, - const uavcan::CanFrame* (& pending_tx)[uavcan::MaxCanIfaces], - const uavcan::MonotonicTime blocking_deadline) -{ - const uavcan::CanSelectMasks in_masks = inout_masks; - const uavcan::MonotonicTime time = clock::getMonotonic(); - - if0_.discardTimedOutTxMailboxes(time); // Check TX timeouts - this may release some TX slots - { - CriticalSectionLocker cs_locker; - if0_.pollErrorFlagsFromISR(); - } - -#if UAVCAN_STM32_NUM_IFACES > 1 - if1_.discardTimedOutTxMailboxes(time); - { - CriticalSectionLocker cs_locker; - if1_.pollErrorFlagsFromISR(); - } -#endif - - inout_masks = makeSelectMasks(pending_tx); // Check if we already have some of the requested events - if ((inout_masks.read & in_masks.read) != 0 || - (inout_masks.write & in_masks.write) != 0) - { - return 1; - } - - (void)update_event_.wait(blocking_deadline - time); // Block until timeout expires or any iface updates - inout_masks = makeSelectMasks(pending_tx); // Return what we got even if none of the requested events are set - return 1; // Return value doesn't matter as long as it is non-negative -} - - -#if UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - -static void nvicEnableVector(IRQn_Type irq, uint8_t prio) -{ - #if !defined (USE_HAL_DRIVER) - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = irq; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - #else - HAL_NVIC_SetPriority(irq, prio, 0); - HAL_NVIC_EnableIRQ(irq); - #endif -} - -#endif - -void CanDriver::initOnce() -{ - /* - * CAN1, CAN2 - */ - { - CriticalSectionLocker lock; -#if UAVCAN_STM32_NUTTX - modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_CAN1EN); - modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_CAN1RST); - modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_CAN1RST, 0); -# if UAVCAN_STM32_NUM_IFACES > 1 - modifyreg32(STM32_RCC_APB1ENR, 0, RCC_APB1ENR_CAN2EN); - modifyreg32(STM32_RCC_APB1RSTR, 0, RCC_APB1RSTR_CAN2RST); - modifyreg32(STM32_RCC_APB1RSTR, RCC_APB1RSTR_CAN2RST, 0); -# endif -#else - RCC->APB1ENR |= RCC_APB1ENR_CAN1EN; - RCC->APB1RSTR |= RCC_APB1RSTR_CAN1RST; - RCC->APB1RSTR &= ~RCC_APB1RSTR_CAN1RST; -# if UAVCAN_STM32_NUM_IFACES > 1 - RCC->APB1ENR |= RCC_APB1ENR_CAN2EN; - RCC->APB1RSTR |= RCC_APB1RSTR_CAN2RST; - RCC->APB1RSTR &= ~RCC_APB1RSTR_CAN2RST; -# endif -#endif - } - - /* - * IRQ - */ -#if UAVCAN_STM32_NUTTX -# define IRQ_ATTACH(irq, handler) \ - { \ - const int res = irq_attach(irq, handler, NULL); \ - (void)res; \ - assert(res >= 0); \ - up_enable_irq(irq); \ - } - IRQ_ATTACH(STM32_IRQ_CAN1TX, can1_irq); - IRQ_ATTACH(STM32_IRQ_CAN1RX0, can1_irq); - IRQ_ATTACH(STM32_IRQ_CAN1RX1, can1_irq); -# if UAVCAN_STM32_NUM_IFACES > 1 - IRQ_ATTACH(STM32_IRQ_CAN2TX, can2_irq); - IRQ_ATTACH(STM32_IRQ_CAN2RX0, can2_irq); - IRQ_ATTACH(STM32_IRQ_CAN2RX1, can2_irq); -# endif -# undef IRQ_ATTACH -#elif UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - { - CriticalSectionLocker lock; - nvicEnableVector(CAN1_TX_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); - nvicEnableVector(CAN1_RX0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); - nvicEnableVector(CAN1_RX1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); -# if UAVCAN_STM32_NUM_IFACES > 1 - nvicEnableVector(CAN2_TX_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); - nvicEnableVector(CAN2_RX0_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); - nvicEnableVector(CAN2_RX1_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); -# endif - } -#endif -} - -int CanDriver::init(const uavcan::uint32_t bitrate, const CanIface::OperatingMode mode) -{ - int res = 0; - - UAVCAN_STM32_LOG("Bitrate %lu mode %d", static_cast(bitrate), static_cast(mode)); - - static bool initialized_once = false; - if (!initialized_once) - { - initialized_once = true; - UAVCAN_STM32_LOG("First initialization"); - initOnce(); - } - - /* - * CAN1 - */ - UAVCAN_STM32_LOG("Initing iface 0..."); - ifaces[0] = &if0_; // This link must be initialized first, - res = if0_.init(bitrate, mode); // otherwise an IRQ may fire while the interface is not linked yet; - if (res < 0) // a typical race condition. - { - UAVCAN_STM32_LOG("Iface 0 init failed %i", res); - ifaces[0] = UAVCAN_NULLPTR; - goto fail; - } - - /* - * CAN2 - */ -#if UAVCAN_STM32_NUM_IFACES > 1 - UAVCAN_STM32_LOG("Initing iface 1..."); - ifaces[1] = &if1_; // Same thing here. - res = if1_.init(bitrate, mode); - if (res < 0) - { - UAVCAN_STM32_LOG("Iface 1 init failed %i", res); - ifaces[1] = UAVCAN_NULLPTR; - goto fail; - } -#endif - - UAVCAN_STM32_LOG("CAN drv init OK"); - UAVCAN_ASSERT(res >= 0); - return res; - -fail: - UAVCAN_STM32_LOG("CAN drv init failed %i", res); - UAVCAN_ASSERT(res < 0); - return res; -} - -CanIface* CanDriver::getIface(uavcan::uint8_t iface_index) -{ - if (iface_index < UAVCAN_STM32_NUM_IFACES) - { - return ifaces[iface_index]; - } - return UAVCAN_NULLPTR; -} - -bool CanDriver::hadActivity() -{ - bool ret = if0_.hadActivity(); -#if UAVCAN_STM32_NUM_IFACES > 1 - ret |= if1_.hadActivity(); -#endif - return ret; -} - -} // namespace uavcan_stm32 - -/* - * Interrupt handlers - */ -extern "C" -{ - -#if UAVCAN_STM32_NUTTX - -static int can1_irq(const int irq, void*, void*) -{ - if (irq == STM32_IRQ_CAN1TX) - { - uavcan_stm32::handleTxInterrupt(0); - } - else if (irq == STM32_IRQ_CAN1RX0) - { - uavcan_stm32::handleRxInterrupt(0, 0); - } - else if (irq == STM32_IRQ_CAN1RX1) - { - uavcan_stm32::handleRxInterrupt(0, 1); - } - else - { - PANIC(); - } - return 0; -} - -# if UAVCAN_STM32_NUM_IFACES > 1 - -static int can2_irq(const int irq, void*, void*) -{ - if (irq == STM32_IRQ_CAN2TX) - { - uavcan_stm32::handleTxInterrupt(1); - } - else if (irq == STM32_IRQ_CAN2RX0) - { - uavcan_stm32::handleRxInterrupt(1, 0); - } - else if (irq == STM32_IRQ_CAN2RX1) - { - uavcan_stm32::handleRxInterrupt(1, 1); - } - else - { - PANIC(); - } - return 0; -} - -# endif - -#else // UAVCAN_STM32_NUTTX - -#if !defined(CAN1_TX_IRQHandler) ||\ - !defined(CAN1_RX0_IRQHandler) ||\ - !defined(CAN1_RX1_IRQHandler) -# error "Misconfigured build" -#endif - -UAVCAN_STM32_IRQ_HANDLER(CAN1_TX_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN1_TX_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleTxInterrupt(0); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -UAVCAN_STM32_IRQ_HANDLER(CAN1_RX0_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN1_RX0_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleRxInterrupt(0, 0); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -UAVCAN_STM32_IRQ_HANDLER(CAN1_RX1_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN1_RX1_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleRxInterrupt(0, 1); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -# if UAVCAN_STM32_NUM_IFACES > 1 - -#if !defined(CAN2_TX_IRQHandler) ||\ - !defined(CAN2_RX0_IRQHandler) ||\ - !defined(CAN2_RX1_IRQHandler) -# error "Misconfigured build" -#endif - -UAVCAN_STM32_IRQ_HANDLER(CAN2_TX_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN2_TX_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleTxInterrupt(1); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -UAVCAN_STM32_IRQ_HANDLER(CAN2_RX0_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN2_RX0_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleRxInterrupt(1, 0); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -UAVCAN_STM32_IRQ_HANDLER(CAN2_RX1_IRQHandler); -UAVCAN_STM32_IRQ_HANDLER(CAN2_RX1_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - uavcan_stm32::handleRxInterrupt(1, 1); - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -# endif -#endif // UAVCAN_STM32_NUTTX - -} // extern "C" diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp deleted file mode 100644 index 1a4cd1e682..0000000000 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_clock.cpp +++ /dev/null @@ -1,496 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include "internal.hpp" - -#if UAVCAN_STM32_TIMER_NUMBER - -#include -#include - -/* - * Timer instance - */ -# if (UAVCAN_STM32_CHIBIOS && CH_KERNEL_MAJOR == 2) || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS -# define TIMX UAVCAN_STM32_GLUE2(TIM, UAVCAN_STM32_TIMER_NUMBER) -# define TIMX_IRQn UAVCAN_STM32_GLUE3(TIM, UAVCAN_STM32_TIMER_NUMBER, _IRQn) -# define TIMX_INPUT_CLOCK STM32_TIMCLK1 -# endif - -# if (UAVCAN_STM32_CHIBIOS && (CH_KERNEL_MAJOR == 3 || CH_KERNEL_MAJOR == 4 || CH_KERNEL_MAJOR == 5)) -# define TIMX UAVCAN_STM32_GLUE2(STM32_TIM, UAVCAN_STM32_TIMER_NUMBER) -# define TIMX_IRQn UAVCAN_STM32_GLUE3(STM32_TIM, UAVCAN_STM32_TIMER_NUMBER, _NUMBER) -# define TIMX_IRQHandler UAVCAN_STM32_GLUE3(STM32_TIM, UAVCAN_STM32_TIMER_NUMBER, _HANDLER) -# define TIMX_INPUT_CLOCK STM32_TIMCLK1 -# else -# define TIMX_IRQHandler UAVCAN_STM32_GLUE3(TIM, UAVCAN_STM32_TIMER_NUMBER, _IRQHandler) -# endif - -# if UAVCAN_STM32_NUTTX -# define TIMX UAVCAN_STM32_GLUE3(STM32_TIM, UAVCAN_STM32_TIMER_NUMBER, _BASE) -# define TMR_REG(o) (TIMX + (o)) -# define TIMX_INPUT_CLOCK UAVCAN_STM32_GLUE3(STM32_APB1_TIM, UAVCAN_STM32_TIMER_NUMBER, _CLKIN) - -# define TIMX_IRQn UAVCAN_STM32_GLUE2(STM32_IRQ_TIM, UAVCAN_STM32_TIMER_NUMBER) -# endif - -# if UAVCAN_STM32_TIMER_NUMBER >= 2 && UAVCAN_STM32_TIMER_NUMBER <= 7 -# define TIMX_RCC_ENR RCC->APB1ENR -# define TIMX_RCC_RSTR RCC->APB1RSTR -# define TIMX_RCC_ENR_MASK UAVCAN_STM32_GLUE3(RCC_APB1ENR_TIM, UAVCAN_STM32_TIMER_NUMBER, EN) -# define TIMX_RCC_RSTR_MASK UAVCAN_STM32_GLUE3(RCC_APB1RSTR_TIM, UAVCAN_STM32_TIMER_NUMBER, RST) -# else -# error "This UAVCAN_STM32_TIMER_NUMBER is not supported yet" -# endif - -/** - * UAVCAN_STM32_TIMX_INPUT_CLOCK can be used to manually override the auto-detected timer clock speed. - * This is useful at least with certain versions of ChibiOS which do not support the bit - * RCC_DKCFGR.TIMPRE that is available in newer models of STM32. In that case, if TIMPRE is active, - * the auto-detected value of TIMX_INPUT_CLOCK will be twice lower than the actual clock speed. - * Read this for additional context: http://www.chibios.com/forum/viewtopic.php?f=35&t=3870 - * A normal way to use the override feature is to provide an alternative macro, e.g.: - * - * -DUAVCAN_STM32_TIMX_INPUT_CLOCK=STM32_HCLK - * - * Alternatively, the new clock rate can be specified directly. - */ -# ifdef UAVCAN_STM32_TIMX_INPUT_CLOCK -# undef TIMX_INPUT_CLOCK -# define TIMX_INPUT_CLOCK UAVCAN_STM32_TIMX_INPUT_CLOCK -# endif - -extern "C" UAVCAN_STM32_IRQ_HANDLER(TIMX_IRQHandler); - -namespace uavcan_stm32 -{ -namespace clock -{ -namespace -{ - -const uavcan::uint32_t USecPerOverflow = 65536; - -Mutex mutex; - -bool initialized = false; - -bool utc_set = false; -bool utc_locked = false; -uavcan::uint32_t utc_jump_cnt = 0; -UtcSyncParams utc_sync_params; -float utc_prev_adj = 0; -float utc_rel_rate_ppm = 0; -float utc_rel_rate_error_integral = 0; -uavcan::int32_t utc_accumulated_correction_nsec = 0; -uavcan::int32_t utc_correction_nsec_per_overflow = 0; -uavcan::MonotonicTime prev_utc_adj_at; - -uavcan::uint64_t time_mono = 0; -uavcan::uint64_t time_utc = 0; - -} - -#if UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - -static void nvicEnableVector(IRQn_Type irq, uint8_t prio) -{ - #if !defined (USE_HAL_DRIVER) - NVIC_InitTypeDef NVIC_InitStructure; - NVIC_InitStructure.NVIC_IRQChannel = irq; - NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = prio; - NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; - NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; - NVIC_Init(&NVIC_InitStructure); - #else - HAL_NVIC_SetPriority(irq, prio, 0); - HAL_NVIC_EnableIRQ(irq); - #endif - -} - -#endif - -void init() -{ - CriticalSectionLocker lock; - if (initialized) - { - return; - } - initialized = true; - - -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - // Power-on and reset - TIMX_RCC_ENR |= TIMX_RCC_ENR_MASK; - TIMX_RCC_RSTR |= TIMX_RCC_RSTR_MASK; - TIMX_RCC_RSTR &= ~TIMX_RCC_RSTR_MASK; - - // Enable IRQ - nvicEnableVector(TIMX_IRQn, UAVCAN_STM32_IRQ_PRIORITY_MASK); - -# if (TIMX_INPUT_CLOCK % 1000000) != 0 -# error "No way, timer clock must be divisible by 1e6. FIXME!" -# endif - - // Start the timer - TIMX->ARR = 0xFFFF; - TIMX->PSC = (TIMX_INPUT_CLOCK / 1000000) - 1; // 1 tick == 1 microsecond - TIMX->CR1 = TIM_CR1_URS; - TIMX->SR = 0; - TIMX->EGR = TIM_EGR_UG; // Reload immediately - TIMX->DIER = TIM_DIER_UIE; - TIMX->CR1 = TIM_CR1_CEN; // Start - -# endif - -# if UAVCAN_STM32_NUTTX - - // Attach IRQ - irq_attach(TIMX_IRQn, &TIMX_IRQHandler, NULL); - - // Power-on and reset - modifyreg32(STM32_RCC_APB1ENR, 0, TIMX_RCC_ENR_MASK); - modifyreg32(STM32_RCC_APB1RSTR, 0, TIMX_RCC_RSTR_MASK); - modifyreg32(STM32_RCC_APB1RSTR, TIMX_RCC_RSTR_MASK, 0); - - - // Start the timer - putreg32(0xFFFF, TMR_REG(STM32_BTIM_ARR_OFFSET)); - putreg16(((TIMX_INPUT_CLOCK / 1000000)-1), TMR_REG(STM32_BTIM_PSC_OFFSET)); - putreg16(BTIM_CR1_URS, TMR_REG(STM32_BTIM_CR1_OFFSET)); - putreg16(0, TMR_REG(STM32_BTIM_SR_OFFSET)); - putreg16(BTIM_EGR_UG, TMR_REG(STM32_BTIM_EGR_OFFSET)); // Reload immediately - putreg16(BTIM_DIER_UIE, TMR_REG(STM32_BTIM_DIER_OFFSET)); - putreg16(BTIM_CR1_CEN, TMR_REG(STM32_BTIM_CR1_OFFSET)); // Start - - // Prioritize and Enable IRQ -// todo: Currently changing the NVIC_SYSH_HIGH_PRIORITY is HARD faulting -// need to investigate -// up_prioritize_irq(TIMX_IRQn, NVIC_SYSH_HIGH_PRIORITY); - up_enable_irq(TIMX_IRQn); - -# endif -} - -void setUtc(uavcan::UtcTime time) -{ - MutexLocker mlocker(mutex); - UAVCAN_ASSERT(initialized); - - { - CriticalSectionLocker locker; - time_utc = time.toUSec(); - } - - utc_set = true; - utc_locked = false; - utc_jump_cnt++; - utc_prev_adj = 0; - utc_rel_rate_ppm = 0; -} - -static uavcan::uint64_t sampleUtcFromCriticalSection() -{ -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - UAVCAN_ASSERT(initialized); - UAVCAN_ASSERT(TIMX->DIER & TIM_DIER_UIE); - - volatile uavcan::uint64_t time = time_utc; - volatile uavcan::uint32_t cnt = TIMX->CNT; - - if (TIMX->SR & TIM_SR_UIF) - { - cnt = TIMX->CNT; - const uavcan::int32_t add = uavcan::int32_t(USecPerOverflow) + - (utc_accumulated_correction_nsec + utc_correction_nsec_per_overflow) / 1000; - time = uavcan::uint64_t(uavcan::int64_t(time) + add); - } - return time + cnt; -# endif - -# if UAVCAN_STM32_NUTTX - - UAVCAN_ASSERT(initialized); - UAVCAN_ASSERT(getreg16(TMR_REG(STM32_BTIM_DIER_OFFSET)) & BTIM_DIER_UIE); - - volatile uavcan::uint64_t time = time_utc; - volatile uavcan::uint32_t cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET)); - - if (getreg16(TMR_REG(STM32_BTIM_SR_OFFSET)) & BTIM_SR_UIF) - { - cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET)); - const uavcan::int32_t add = uavcan::int32_t(USecPerOverflow) + - (utc_accumulated_correction_nsec + utc_correction_nsec_per_overflow) / 1000; - time = uavcan::uint64_t(uavcan::int64_t(time) + add); - } - return time + cnt; -# endif -} - -uavcan::uint64_t getUtcUSecFromCanInterrupt() -{ - return utc_set ? sampleUtcFromCriticalSection() : 0; -} - -uavcan::MonotonicTime getMonotonic() -{ - uavcan::uint64_t usec = 0; - // Scope Critical section - { - CriticalSectionLocker locker; - - volatile uavcan::uint64_t time = time_mono; - -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - - volatile uavcan::uint32_t cnt = TIMX->CNT; - if (TIMX->SR & TIM_SR_UIF) - { - cnt = TIMX->CNT; -# endif - -# if UAVCAN_STM32_NUTTX - - volatile uavcan::uint32_t cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET)); - - if (getreg16(TMR_REG(STM32_BTIM_SR_OFFSET)) & BTIM_SR_UIF) - { - cnt = getreg16(TMR_REG(STM32_BTIM_CNT_OFFSET)); -# endif - time += USecPerOverflow; - } - usec = time + cnt; - -# ifndef NDEBUG - static uavcan::uint64_t prev_usec = 0; // Self-test - UAVCAN_ASSERT(prev_usec <= usec); - (void)prev_usec; - prev_usec = usec; -# endif - } // End Scope Critical section - - return uavcan::MonotonicTime::fromUSec(usec); -} - -uavcan::UtcTime getUtc() -{ - if (utc_set) - { - uavcan::uint64_t usec = 0; - { - CriticalSectionLocker locker; - usec = sampleUtcFromCriticalSection(); - } - return uavcan::UtcTime::fromUSec(usec); - } - return uavcan::UtcTime(); -} - -static float lowpass(float xold, float xnew, float corner, float dt) -{ - const float tau = 1.F / corner; - return (dt * xnew + tau * xold) / (dt + tau); -} - -static void updateRatePID(uavcan::UtcDuration adjustment) -{ - const uavcan::MonotonicTime ts = getMonotonic(); - const float dt = float((ts - prev_utc_adj_at).toUSec()) / 1e6F; - prev_utc_adj_at = ts; - const float adj_usec = float(adjustment.toUSec()); - - /* - * Target relative rate in PPM - * Positive to go faster - */ - const float target_rel_rate_ppm = adj_usec * utc_sync_params.offset_p; - - /* - * Current relative rate in PPM - * Positive if the local clock is faster - */ - const float new_rel_rate_ppm = (utc_prev_adj - adj_usec) / dt; // rate error in [usec/sec], which is PPM - utc_prev_adj = adj_usec; - utc_rel_rate_ppm = lowpass(utc_rel_rate_ppm, new_rel_rate_ppm, utc_sync_params.rate_error_corner_freq, dt); - - const float rel_rate_error = target_rel_rate_ppm - utc_rel_rate_ppm; - - if (dt > 10) - { - utc_rel_rate_error_integral = 0; - } - else - { - utc_rel_rate_error_integral += rel_rate_error * dt * utc_sync_params.rate_i; - utc_rel_rate_error_integral = - uavcan::max(utc_rel_rate_error_integral, -utc_sync_params.max_rate_correction_ppm); - utc_rel_rate_error_integral = - uavcan::min(utc_rel_rate_error_integral, utc_sync_params.max_rate_correction_ppm); - } - - /* - * Rate controller - */ - float total_rate_correction_ppm = rel_rate_error + utc_rel_rate_error_integral; - total_rate_correction_ppm = uavcan::max(total_rate_correction_ppm, -utc_sync_params.max_rate_correction_ppm); - total_rate_correction_ppm = uavcan::min(total_rate_correction_ppm, utc_sync_params.max_rate_correction_ppm); - - utc_correction_nsec_per_overflow = uavcan::int32_t((USecPerOverflow * 1000) * (total_rate_correction_ppm / 1e6F)); - -// syslog("$ adj=%f rel_rate=%f rel_rate_eint=%f tgt_rel_rate=%f ppm=%f\n", -// adj_usec, utc_rel_rate_ppm, utc_rel_rate_error_integral, target_rel_rate_ppm, -// total_rate_correction_ppm); -} - -void adjustUtc(uavcan::UtcDuration adjustment) -{ - MutexLocker mlocker(mutex); - UAVCAN_ASSERT(initialized); - - if (adjustment.getAbs() > utc_sync_params.min_jump || !utc_set) - { - const uavcan::int64_t adj_usec = adjustment.toUSec(); - - { - CriticalSectionLocker locker; - if ((adj_usec < 0) && uavcan::uint64_t(-adj_usec) > time_utc) - { - time_utc = 1; - } - else - { - time_utc = uavcan::uint64_t(uavcan::int64_t(time_utc) + adj_usec); - } - } - - utc_set = true; - utc_locked = false; - utc_jump_cnt++; - utc_prev_adj = 0; - utc_rel_rate_ppm = 0; - } - else - { - updateRatePID(adjustment); - - if (!utc_locked) - { - utc_locked = - (std::abs(utc_rel_rate_ppm) < utc_sync_params.lock_thres_rate_ppm) && - (std::abs(utc_prev_adj) < float(utc_sync_params.lock_thres_offset.toUSec())); - } - } -} - -float getUtcRateCorrectionPPM() -{ - MutexLocker mlocker(mutex); - const float rate_correction_mult = float(utc_correction_nsec_per_overflow) / float(USecPerOverflow * 1000); - return 1e6F * rate_correction_mult; -} - -uavcan::uint32_t getUtcJumpCount() -{ - MutexLocker mlocker(mutex); - return utc_jump_cnt; -} - -bool isUtcLocked() -{ - MutexLocker mlocker(mutex); - return utc_locked; -} - -UtcSyncParams getUtcSyncParams() -{ - MutexLocker mlocker(mutex); - return utc_sync_params; -} - -void setUtcSyncParams(const UtcSyncParams& params) -{ - MutexLocker mlocker(mutex); - // Add some sanity check - utc_sync_params = params; -} - -} // namespace clock - -SystemClock& SystemClock::instance() -{ - static union SystemClockStorage - { - uavcan::uint8_t buffer[sizeof(SystemClock)]; - long long _aligner_1; - long double _aligner_2; - } storage; - - SystemClock* const ptr = reinterpret_cast(storage.buffer); - - if (!clock::initialized) - { - MutexLocker mlocker(clock::mutex); - clock::init(); - new (ptr)SystemClock(); - } - return *ptr; -} - -} // namespace uavcan_stm32 - - -/** - * Timer interrupt handler - */ - -extern "C" -UAVCAN_STM32_IRQ_HANDLER(TIMX_IRQHandler) -{ - UAVCAN_STM32_IRQ_PROLOGUE(); - -# if UAVCAN_STM32_CHIBIOS || UAVCAN_STM32_BAREMETAL || UAVCAN_STM32_FREERTOS - TIMX->SR = 0; -# endif -# if UAVCAN_STM32_NUTTX - putreg16(0, TMR_REG(STM32_BTIM_SR_OFFSET)); -# endif - - using namespace uavcan_stm32::clock; - UAVCAN_ASSERT(initialized); - - time_mono += USecPerOverflow; - - if (utc_set) - { - time_utc += USecPerOverflow; - utc_accumulated_correction_nsec += utc_correction_nsec_per_overflow; - if (std::abs(utc_accumulated_correction_nsec) >= 1000) - { - time_utc = uavcan::uint64_t(uavcan::int64_t(time_utc) + utc_accumulated_correction_nsec / 1000); - utc_accumulated_correction_nsec %= 1000; - } - - // Correction decay - 1 nsec per 65536 usec - if (utc_correction_nsec_per_overflow > 0) - { - utc_correction_nsec_per_overflow--; - } - else if (utc_correction_nsec_per_overflow < 0) - { - utc_correction_nsec_per_overflow++; - } - else - { - ; // Zero - } - } - - UAVCAN_STM32_IRQ_EPILOGUE(); -} - -#endif diff --git a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp b/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp deleted file mode 100644 index a347dcb0f8..0000000000 --- a/libuavcan_drivers/stm32/driver/src/uc_stm32_thread.cpp +++ /dev/null @@ -1,287 +0,0 @@ -/* - * Copyright (C) 2014 Pavel Kirienko - */ - -#include -#include -#include -#include "internal.hpp" - - -namespace uavcan_stm32 -{ - -#if UAVCAN_STM32_CHIBIOS -/* - * BusEvent - */ -bool BusEvent::wait(uavcan::MonotonicDuration duration) -{ - // set maximum time to allow for 16 bit timers running at 1MHz - static const uavcan::int64_t MaxDelayUSec = 0x000FFFF; - - const uavcan::int64_t usec = duration.toUSec(); - msg_t ret = msg_t(); - - if (usec <= 0) - { -# if (CH_KERNEL_MAJOR == 2) - ret = sem_.waitTimeout(TIME_IMMEDIATE); -# else // ChibiOS 3+ - ret = sem_.wait(TIME_IMMEDIATE); -# endif - } - else - { -# if (CH_KERNEL_MAJOR == 2) - ret = sem_.waitTimeout((usec > MaxDelayUSec) ? US2ST(MaxDelayUSec) : US2ST(usec)); -# elif defined(MS2ST) // ChibiOS 3+ - ret = sem_.wait((usec > MaxDelayUSec) ? US2ST(MaxDelayUSec) : US2ST(usec)); -# else // ChibiOS 17+ - ret = sem_.wait(::systime_t((usec > MaxDelayUSec) ? TIME_US2I(MaxDelayUSec) : TIME_US2I(usec))); -# endif - } -# if (CH_KERNEL_MAJOR == 2) - return ret == RDY_OK; -# else // ChibiOS 3+ - return ret == MSG_OK; -# endif -} - -void BusEvent::signal() -{ - sem_.signal(); -} - -void BusEvent::signalFromInterrupt() -{ -# if (CH_KERNEL_MAJOR == 2) - chSysLockFromIsr(); - sem_.signalI(); - chSysUnlockFromIsr(); -# else // ChibiOS 3+ - chSysLockFromISR(); - sem_.signalI(); - chSysUnlockFromISR(); -# endif -} - -/* - * Mutex - */ -void Mutex::lock() -{ - mtx_.lock(); -} - -void Mutex::unlock() -{ -# if (CH_KERNEL_MAJOR == 2) - chibios_rt::BaseThread::unlockMutex(); -# else // ChibiOS 3+ - mtx_.unlock(); -# endif -} - - -#elif UAVCAN_STM32_FREERTOS - -bool BusEvent::wait(uavcan::MonotonicDuration duration) -{ - static const uavcan::int64_t MaxDelayMSec = 0x000FFFFF; - - const uavcan::int64_t msec = duration.toMSec(); - - BaseType_t ret; - - if (msec <= 0) - { - ret = xSemaphoreTake( sem_, ( TickType_t ) 0 ); - } - else - { - ret = xSemaphoreTake( sem_, (msec > MaxDelayMSec) ? (MaxDelayMSec/portTICK_RATE_MS) : (msec/portTICK_RATE_MS)); - } - return ret == pdTRUE; -} - -void BusEvent::signal() -{ - xSemaphoreGive( sem_ ); -} - -void BusEvent::signalFromInterrupt() -{ - higher_priority_task_woken = pdFALSE; - - xSemaphoreGiveFromISR( sem_, &higher_priority_task_woken ); -} - -void BusEvent::yieldFromISR() -{ - portYIELD_FROM_ISR( higher_priority_task_woken ); -} - -/* - * Mutex - */ -void Mutex::lock() -{ - xSemaphoreTake( mtx_, portMAX_DELAY ); -} - -void Mutex::unlock() -{ - xSemaphoreGive( mtx_ ); -} - - -#elif UAVCAN_STM32_NUTTX - -const unsigned BusEvent::MaxPollWaiters; -const char* const BusEvent::DevName = "/dev/uavcan/busevent"; - -int BusEvent::openTrampoline(::file* filp) -{ - return static_cast(filp->f_inode->i_private)->open(filp); -} - -int BusEvent::closeTrampoline(::file* filp) -{ - return static_cast(filp->f_inode->i_private)->close(filp); -} - -int BusEvent::pollTrampoline(::file* filp, ::pollfd* fds, bool setup) -{ - return static_cast(filp->f_inode->i_private)->poll(filp, fds, setup); -} - -int BusEvent::open(::file* filp) -{ - (void)filp; - return 0; -} - -int BusEvent::close(::file* filp) -{ - (void)filp; - return 0; -} - -int BusEvent::poll(::file* filp, ::pollfd* fds, bool setup) -{ - CriticalSectionLocker locker; - int ret = -1; - - if (setup) - { - ret = addPollWaiter(fds); - if (ret == 0) - { - /* - * Two events can be reported via POLLIN: - * - The RX queue is not empty. This event is level-triggered. - * - Transmission complete. This event is edge-triggered. - * FIXME Since TX event is edge-triggered, it can be lost between poll() calls. - */ - fds->revents |= fds->events & (can_driver_.hasReadableInterfaces() ? POLLIN : 0); - if (fds->revents != 0) - { - (void)sem_post(fds->sem); - } - } - } - else - { - ret = removePollWaiter(fds); - } - - return ret; -} - -int BusEvent::addPollWaiter(::pollfd* fds) -{ - for (unsigned i = 0; i < MaxPollWaiters; i++) - { - if (pollset_[i] == UAVCAN_NULLPTR) - { - pollset_[i] = fds; - return 0; - } - } - return -ENOMEM; -} - -int BusEvent::removePollWaiter(::pollfd* fds) -{ - for (unsigned i = 0; i < MaxPollWaiters; i++) - { - if (fds == pollset_[i]) - { - pollset_[i] = UAVCAN_NULLPTR; - return 0; - } - } - return -EINVAL; -} - -BusEvent::BusEvent(CanDriver& can_driver) - : can_driver_(can_driver) - , signal_(false) -{ - std::memset(&file_ops_, 0, sizeof(file_ops_)); - std::memset(pollset_, 0, sizeof(pollset_)); - file_ops_.open = &BusEvent::openTrampoline; - file_ops_.close = &BusEvent::closeTrampoline; - file_ops_.poll = &BusEvent::pollTrampoline; - // TODO: move to init(), add proper error handling - if (register_driver(DevName, &file_ops_, 0666, static_cast(this)) != 0) - { - std::abort(); - } -} - -BusEvent::~BusEvent() -{ - (void)unregister_driver(DevName); -} - -bool BusEvent::wait(uavcan::MonotonicDuration duration) -{ - // TODO blocking wait - const uavcan::MonotonicTime deadline = clock::getMonotonic() + duration; - while (clock::getMonotonic() < deadline) - { - { - CriticalSectionLocker locker; - if (signal_) - { - signal_ = false; - return true; - } - } - ::usleep(1000); - } - return false; -} - -void BusEvent::signalFromInterrupt() -{ - signal_ = true; // HACK - for (unsigned i = 0; i < MaxPollWaiters; i++) - { - ::pollfd* const fd = pollset_[i]; - if (fd != UAVCAN_NULLPTR) - { - fd->revents |= fd->events & POLLIN; - if ((fd->revents != 0) && (fd->sem->semcount <= 0)) - { - (void)sem_post(fd->sem); - } - } - } -} - -#endif - -}