mirror of https://github.com/ARMmbed/mbed-os.git
Remove hal
Remove all the hal files in preparation for pulling in mbedmicro/mbed.
parent
99098d035a
commit
966ef8c35e
|
@ -1,14 +0,0 @@
|
|||
# ignore files for targets that aren't supported by the yotta build (to
|
||||
# minimise the size of the published module)
|
||||
|
||||
TARGET_ARM_SSG
|
||||
TARGET_Freescale
|
||||
TARGET_RENESAS
|
||||
TARGET_Silicon_Labs
|
||||
TARGET_Atmel
|
||||
TARGET_Maxim
|
||||
TARGET_NXP
|
||||
TARGET_STM
|
||||
TARGET_WIZNET
|
||||
TOOLCHAIN_IAR
|
||||
|
|
@ -1,112 +0,0 @@
|
|||
#
|
||||
# mbed-2 yotta-compatible build system
|
||||
#
|
||||
|
||||
# make sure necessary features are enabled:
|
||||
project(mbed-classic)
|
||||
enable_language(ASM)
|
||||
|
||||
# override compilation flags:
|
||||
if(CMAKE_C_COMPILER_ID MATCHES GNU)
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -std=gnu99")
|
||||
endif()
|
||||
|
||||
# the mbed.a library is built from two sets of source files + include
|
||||
# directories:
|
||||
#
|
||||
# MBED_COMMON_SOURCES: the source files that are the same for all targets,
|
||||
# these are easily found by globbing:
|
||||
#
|
||||
file(GLOB MBED_COMMON_SOURCES "common/*.cpp" "common/*.c")
|
||||
#
|
||||
# (always include the hal header directory, too)
|
||||
set(MBED_COMMON_INCLUDE_DIRS "hal")
|
||||
|
||||
# and MBED_TARGET_SOURCES: these depend on which target we are building for. To
|
||||
# find these we need to walk the directories in targets/, and wherever we see a
|
||||
# TARGET_<something> name, recurse only if <something> matches what we're
|
||||
# currently building for
|
||||
macro(mbed_find_target_dirs PARENT_DIRECTORY SOURCES_LIST INCLUDES_LIST)
|
||||
# append this directory to the search path:
|
||||
list(APPEND ${INCLUDES_LIST} "${PARENT_DIRECTORY}")
|
||||
# add all source files in this directory to the sources list:
|
||||
file(GLOB sources "${PARENT_DIRECTORY}/*.cpp" "${PARENT_DIRECTORY}/*.c" "${PARENT_DIRECTORY}/*.s" "${PARENT_DIRECTORY}/*.S" )
|
||||
list(APPEND ${SOURCES_LIST} ${sources})
|
||||
|
||||
# get a list of all subdirectories that we want to recurse into:
|
||||
file(GLOB dir_children RELATIVE "${PARENT_DIRECTORY}" "${PARENT_DIRECTORY}/*")
|
||||
set(matching_subdirs "")
|
||||
foreach(child ${dir_children})
|
||||
if(IS_DIRECTORY "${PARENT_DIRECTORY}/${child}")
|
||||
# is this directory name a magic one?
|
||||
if("${child}" MATCHES "^TARGET_")
|
||||
# target-magic: recurse if the MBED_LEGACY_TARGET_DEFINITIONS **list**
|
||||
# contains a matching value:
|
||||
foreach(legacy_magic_def ${MBED_LEGACY_TARGET_DEFINITIONS})
|
||||
# we could probably unroll the list into a single regex if
|
||||
# this is a performance problem:
|
||||
if("${child}" MATCHES "^TARGET_${legacy_magic_def}$")
|
||||
list(APPEND matching_subdirs ${child})
|
||||
break()
|
||||
endif()
|
||||
endforeach()
|
||||
elseif("${child}" MATCHES "^TOOLCHAIN_")
|
||||
# toolchain-magic: (recurse if the MBED_LEGACY_TOOLCHAIN matches
|
||||
# this name)
|
||||
if("${child}" MATCHES "^TOOLCHAIN_${MBED_LEGACY_TOOLCHAIN}$")
|
||||
list(APPEND matching_subdirs "${child}")
|
||||
endif()
|
||||
else()
|
||||
# not special: always recurse into this directory
|
||||
list(APPEND matching_subdirs "${child}")
|
||||
endif()
|
||||
endif()
|
||||
endforeach()
|
||||
#message("matching_subdirs: ${matching_subdirs}")
|
||||
|
||||
# recurse:
|
||||
foreach(subdir ${matching_subdirs})
|
||||
mbed_find_target_dirs("${PARENT_DIRECTORY}/${subdir}" ${SOURCES_LIST} ${INCLUDES_LIST})
|
||||
endforeach()
|
||||
endmacro()
|
||||
|
||||
set(MBED_TARGET_SOURCES "")
|
||||
set(MBED_TARGET_INCLUDE_DIRS "")
|
||||
mbed_find_target_dirs("${CMAKE_CURRENT_SOURCE_DIR}/targets" MBED_TARGET_SOURCES MBED_TARGET_INCLUDE_DIRS)
|
||||
#message("found target sources: ${MBED_TARGET_SOURCES}")
|
||||
#message("found target include dirs: ${MBED_TARGET_INCLUDE_DIRS}")
|
||||
|
||||
# unfortunately, for ARMCC, the startup code needs to be provided as an object
|
||||
# on the command line (not as part of an archive). To do this we override the
|
||||
# CMake add_executable command.
|
||||
if(CMAKE_C_COMPILER_ID STREQUAL "ARMCC")
|
||||
set(MBED_TARGET_STARTUP_CODE_SOURCES "")
|
||||
foreach(src ${MBED_TARGET_SOURCES})
|
||||
if("${src}" MATCHES .*startup_.*\\.[sS])
|
||||
LIST(APPEND MBED_TARGET_STARTUP_CODE_SOURCES "${src}")
|
||||
endif()
|
||||
endforeach()
|
||||
add_library(mbed_classic_startupcod OBJECT ${MBED_TARGET_STARTUP_CODE_SOURCES})
|
||||
macro (add_executable _name)
|
||||
_add_executable(${ARGV} $<TARGET_OBJECTS:mbed_classic_startupcod>)
|
||||
endmacro()
|
||||
endif()
|
||||
|
||||
# we have to append any target-specific include dirs to the global include dirs
|
||||
# list, so that any indirect includes (e.g. via mbed.h) of files in those
|
||||
# directories will work:
|
||||
# (non-target-specific include dirs are listed in extraIncludes in module.json)
|
||||
foreach(dir ${MBED_TARGET_INCLUDE_DIRS})
|
||||
set_property(GLOBAL APPEND PROPERTY YOTTA_GLOBAL_INCLUDE_DIRS ${dir})
|
||||
endforeach()
|
||||
|
||||
# finally, we can construct a library using the determined set of include paths
|
||||
# + source files. Note that the library name must match the name of the yotta
|
||||
# module (defined in module.json) for this module to link properly with other
|
||||
# yotta modules.
|
||||
include_directories(${MBED_COMMON_INCLUDE_DIRS})
|
||||
include_directories(${MBED_TARGET_INCLUDE_DIRS})
|
||||
add_library(mbed-classic
|
||||
${MBED_COMMON_SOURCES}
|
||||
${MBED_TARGET_SOURCES}
|
||||
)
|
|
@ -1,267 +0,0 @@
|
|||
#include "mbed.h"
|
||||
#include "test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
// static functions
|
||||
template <typename T>
|
||||
T static_func5(T a0, T a1, T a2, T a3, T a4) { return a0 | a1 | a2 | a3 | a4; }
|
||||
template <typename T>
|
||||
T static_func4(T a0, T a1, T a2, T a3) { return a0 | a1 | a2 | a3; }
|
||||
template <typename T>
|
||||
T static_func3(T a0, T a1, T a2) { return a0 | a1 | a2; }
|
||||
template <typename T>
|
||||
T static_func2(T a0, T a1) { return a0 | a1; }
|
||||
template <typename T>
|
||||
T static_func1(T a0) { return a0; }
|
||||
template <typename T>
|
||||
T static_func0() { return 0; }
|
||||
|
||||
// class functions
|
||||
template <typename T>
|
||||
struct Thing {
|
||||
T t;
|
||||
Thing() : t(0x80) {}
|
||||
|
||||
T member_func5(T a0, T a1, T a2, T a3, T a4) { return t | a0 | a1 | a2 | a3 | a4; }
|
||||
T member_func4(T a0, T a1, T a2, T a3) { return t | a0 | a1 | a2 | a3; }
|
||||
T member_func3(T a0, T a1, T a2) { return t | a0 | a1 | a2; }
|
||||
T member_func2(T a0, T a1) { return t | a0 | a1; }
|
||||
T member_func1(T a0) { return t | a0; }
|
||||
T member_func0() { return t; }
|
||||
};
|
||||
|
||||
// bound functions
|
||||
template <typename T>
|
||||
T bound_func5(Thing<T> *t, T a0, T a1, T a2, T a3, T a4) { return t->t | a0 | a1 | a2 | a3 | a4; }
|
||||
template <typename T>
|
||||
T bound_func4(Thing<T> *t, T a0, T a1, T a2, T a3) { return t->t | a0 | a1 | a2 | a3; }
|
||||
template <typename T>
|
||||
T bound_func3(Thing<T> *t, T a0, T a1, T a2) { return t->t | a0 | a1 | a2; }
|
||||
template <typename T>
|
||||
T bound_func2(Thing<T> *t, T a0, T a1) { return t->t | a0 | a1; }
|
||||
template <typename T>
|
||||
T bound_func1(Thing<T> *t, T a0) { return t->t | a0; }
|
||||
template <typename T>
|
||||
T bound_func0(Thing<T> *t) { return t->t; }
|
||||
|
||||
|
||||
// function call and result verification
|
||||
template <typename T>
|
||||
struct Verifier {
|
||||
static void verify5(Callback<T(T,T,T,T,T)> func) {
|
||||
T result = func(0x01, 0x02, 0x04, 0x08, 0x10);
|
||||
TEST_ASSERT_EQUAL(result, 0x1f);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify5(O *obj, M method) {
|
||||
Callback<T(T,T,T,T,T)> func(obj, method);
|
||||
T result = func(0x01, 0x02, 0x04, 0x08, 0x10);
|
||||
TEST_ASSERT_EQUAL(result, 0x9f);
|
||||
}
|
||||
|
||||
static void verify4(Callback<T(T,T,T,T)> func) {
|
||||
T result = func(0x01, 0x02, 0x04, 0x08);
|
||||
TEST_ASSERT_EQUAL(result, 0x0f);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify4(O *obj, M method) {
|
||||
Callback<T(T,T,T,T)> func(obj, method);
|
||||
T result = func(0x01, 0x02, 0x04, 0x08);
|
||||
TEST_ASSERT_EQUAL(result, 0x8f);
|
||||
}
|
||||
|
||||
static void verify3(Callback<T(T,T,T)> func) {
|
||||
T result = func(0x01, 0x02, 0x04);
|
||||
TEST_ASSERT_EQUAL(result, 0x07);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify3(O *obj, M method) {
|
||||
Callback<T(T,T,T)> func(obj, method);
|
||||
T result = func(0x01, 0x02, 0x04);
|
||||
TEST_ASSERT_EQUAL(result, 0x87);
|
||||
}
|
||||
|
||||
static void verify2(Callback<T(T,T)> func) {
|
||||
T result = func(0x01, 0x02);
|
||||
TEST_ASSERT_EQUAL(result, 0x03);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify2(O *obj, M method) {
|
||||
Callback<T(T,T)> func(obj, method);
|
||||
T result = func(0x01, 0x02);
|
||||
TEST_ASSERT_EQUAL(result, 0x83);
|
||||
}
|
||||
|
||||
static void verify1(Callback<T(T)> func) {
|
||||
T result = func(0x01);
|
||||
TEST_ASSERT_EQUAL(result, 0x01);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify1(O *obj, M method) {
|
||||
Callback<T(T)> func(obj, method);
|
||||
T result = func(0x01);
|
||||
TEST_ASSERT_EQUAL(result, 0x81);
|
||||
}
|
||||
|
||||
static void verify0(Callback<T()> func) {
|
||||
T result = func();
|
||||
TEST_ASSERT_EQUAL(result, 0x00);
|
||||
}
|
||||
|
||||
template <typename O, typename M>
|
||||
static void verify0(O *obj, M method) {
|
||||
Callback<T()> func(obj, method);
|
||||
T result = func();
|
||||
TEST_ASSERT_EQUAL(result, 0x80);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// test dispatch
|
||||
template <typename T>
|
||||
void test_dispatch5() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify5(static_func5<T>);
|
||||
Verifier<T>::verify5(&thing, &Thing<T>::member_func5);
|
||||
Verifier<T>::verify5(&thing, &bound_func5<T>);
|
||||
|
||||
Callback<T(T,T,T,T,T)> callback(static_func5);
|
||||
Verifier<T>::verify5(callback);
|
||||
callback.attach(&thing, &bound_func5<T>);
|
||||
Verifier<T>::verify5(&callback, &Callback<T(T,T,T,T,T)>::call);
|
||||
Verifier<T>::verify5((void*)&callback, &Callback<T(T,T,T,T,T)>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_dispatch4() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify4(static_func4<T>);
|
||||
Verifier<T>::verify4(&thing, &Thing<T>::member_func4);
|
||||
Verifier<T>::verify4(&thing, &bound_func4<T>);
|
||||
|
||||
Callback<T(T,T,T,T)> callback(static_func4);
|
||||
Verifier<T>::verify4(callback);
|
||||
callback.attach(&thing, &bound_func4<T>);
|
||||
Verifier<T>::verify4(&callback, &Callback<T(T,T,T,T)>::call);
|
||||
Verifier<T>::verify4((void*)&callback, &Callback<T(T,T,T,T)>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_dispatch3() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify3(static_func3<T>);
|
||||
Verifier<T>::verify3(&thing, &Thing<T>::member_func3);
|
||||
Verifier<T>::verify3(&thing, &bound_func3<T>);
|
||||
|
||||
Callback<T(T,T,T)> callback(static_func3);
|
||||
Verifier<T>::verify3(callback);
|
||||
callback.attach(&thing, &bound_func3<T>);
|
||||
Verifier<T>::verify3(&callback, &Callback<T(T,T,T)>::call);
|
||||
Verifier<T>::verify3((void*)&callback, &Callback<T(T,T,T)>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_dispatch2() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify2(static_func2<T>);
|
||||
Verifier<T>::verify2(&thing, &Thing<T>::member_func2);
|
||||
Verifier<T>::verify2(&thing, &bound_func2<T>);
|
||||
|
||||
Callback<T(T,T)> callback(static_func2);
|
||||
Verifier<T>::verify2(callback);
|
||||
callback.attach(&thing, &bound_func2<T>);
|
||||
Verifier<T>::verify2(&callback, &Callback<T(T,T)>::call);
|
||||
Verifier<T>::verify2((void*)&callback, &Callback<T(T,T)>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_dispatch1() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify1(static_func1<T>);
|
||||
Verifier<T>::verify1(&thing, &Thing<T>::member_func1);
|
||||
Verifier<T>::verify1(&thing, &bound_func1<T>);
|
||||
|
||||
Callback<T(T)> callback(static_func1);
|
||||
Verifier<T>::verify1(callback);
|
||||
callback.attach(&thing, &bound_func1<T>);
|
||||
Verifier<T>::verify1(&callback, &Callback<T(T)>::call);
|
||||
Verifier<T>::verify1((void*)&callback, &Callback<T(T)>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_dispatch0() {
|
||||
Thing<T> thing;
|
||||
Verifier<T>::verify0(static_func0<T>);
|
||||
Verifier<T>::verify0(&thing, &Thing<T>::member_func0);
|
||||
Verifier<T>::verify0(&thing, &bound_func0<T>);
|
||||
|
||||
Callback<T()> callback(static_func0);
|
||||
Verifier<T>::verify0(callback);
|
||||
callback.attach(&thing, &bound_func0<T>);
|
||||
Verifier<T>::verify0(&callback, &Callback<T()>::call);
|
||||
Verifier<T>::verify0((void*)&callback, &Callback<T()>::thunk);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_fparg1() {
|
||||
Thing<T> thing;
|
||||
FunctionPointerArg1<T,T> fp(static_func1<T>);
|
||||
Verifier<T>::verify1(fp);
|
||||
Verifier<T>::verify1(fp.get_function());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void test_fparg0() {
|
||||
Thing<T> thing;
|
||||
FunctionPointerArg1<T,void> fp(static_func0<T>);
|
||||
Verifier<T>::verify0(fp);
|
||||
Verifier<T>::verify0(fp.get_function());
|
||||
}
|
||||
|
||||
|
||||
// Test setup
|
||||
status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(40, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Testing callbacks with 5 ints", test_dispatch5<int>),
|
||||
Case("Testing callbacks with 4 ints", test_dispatch4<int>),
|
||||
Case("Testing callbacks with 3 ints", test_dispatch3<int>),
|
||||
Case("Testing callbacks with 2 ints", test_dispatch2<int>),
|
||||
Case("Testing callbacks with 1 ints", test_dispatch1<int>),
|
||||
Case("Testing callbacks with 0 ints", test_dispatch0<int>),
|
||||
|
||||
Case("Testing callbacks with 5 uchars", test_dispatch5<unsigned char>),
|
||||
Case("Testing callbacks with 4 uchars", test_dispatch4<unsigned char>),
|
||||
Case("Testing callbacks with 3 uchars", test_dispatch3<unsigned char>),
|
||||
Case("Testing callbacks with 2 uchars", test_dispatch2<unsigned char>),
|
||||
Case("Testing callbacks with 1 uchars", test_dispatch1<unsigned char>),
|
||||
Case("Testing callbacks with 0 uchars", test_dispatch0<unsigned char>),
|
||||
|
||||
Case("Testing callbacks with 5 uint64s", test_dispatch5<uint64_t>),
|
||||
Case("Testing callbacks with 4 uint64s", test_dispatch4<uint64_t>),
|
||||
Case("Testing callbacks with 3 uint64s", test_dispatch3<uint64_t>),
|
||||
Case("Testing callbacks with 2 uint64s", test_dispatch2<uint64_t>),
|
||||
Case("Testing callbacks with 1 uint64s", test_dispatch1<uint64_t>),
|
||||
Case("Testing callbacks with 0 uint64s", test_dispatch0<uint64_t>),
|
||||
|
||||
Case("Testing FunctionPointerArg1 compatibility", test_fparg1<int>),
|
||||
Case("Testing FunctionPointer compatibility", test_fparg0<int>),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,133 +0,0 @@
|
|||
#include "toolchain.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
typedef struct {
|
||||
char a;
|
||||
int x;
|
||||
} PACKED TestAttrPackedStruct;
|
||||
|
||||
int testPacked() {
|
||||
int failed = 0;
|
||||
|
||||
if (sizeof(TestAttrPackedStruct) != sizeof(int) + sizeof(char)) {
|
||||
failed++;
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
ALIGN(8) static char a_align_test;
|
||||
ALIGN(8) static char b_align_test;
|
||||
ALIGN(16)static char c_align_test;
|
||||
ALIGN(8) static char d_align_test;
|
||||
ALIGN(16)static char e_align_test;
|
||||
|
||||
int testAlign() {
|
||||
int failed = 0;
|
||||
|
||||
if(((uintptr_t)&a_align_test) & 0x7){
|
||||
failed++;
|
||||
}
|
||||
if(((uintptr_t)&b_align_test) & 0x7){
|
||||
failed++;
|
||||
}
|
||||
if(((uintptr_t)&c_align_test) & 0xf){
|
||||
failed++;
|
||||
}
|
||||
if(((uintptr_t)&d_align_test) & 0x7){
|
||||
failed++;
|
||||
}
|
||||
if(((uintptr_t)&e_align_test) & 0xf){
|
||||
failed++;
|
||||
}
|
||||
|
||||
return failed;
|
||||
}
|
||||
|
||||
|
||||
int testUnused1(UNUSED int arg) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testUnused() {
|
||||
return testUnused1(0);
|
||||
}
|
||||
|
||||
|
||||
int testWeak1();
|
||||
int testWeak2();
|
||||
|
||||
WEAK int testWeak1() {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int testWeak2() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testWeak() {
|
||||
return testWeak1() | testWeak2();
|
||||
}
|
||||
|
||||
|
||||
PURE int testPure1() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testPure() {
|
||||
return testPure1();
|
||||
}
|
||||
|
||||
|
||||
FORCEINLINE int testForceInline1() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testForceInline() {
|
||||
return testForceInline1();
|
||||
}
|
||||
|
||||
|
||||
NORETURN int testNoReturn1() {
|
||||
while (1) {}
|
||||
}
|
||||
|
||||
int testNoReturn() {
|
||||
if (0) {
|
||||
testNoReturn1();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int testUnreachable1(int i) {
|
||||
switch (i) {
|
||||
case 0:
|
||||
return 0;
|
||||
}
|
||||
|
||||
UNREACHABLE;
|
||||
}
|
||||
|
||||
int testUnreachable() {
|
||||
return testUnreachable1(0);
|
||||
}
|
||||
|
||||
|
||||
DEPRECATED("this message should not be displayed")
|
||||
void testDeprecatedUnused();
|
||||
void testDeprecatedUnused() { }
|
||||
|
||||
DEPRECATED("this message should be displayed")
|
||||
int testDeprecatedUsed();
|
||||
int testDeprecatedUsed() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int testDeprecated() {
|
||||
return testDeprecatedUsed();
|
||||
}
|
||||
|
|
@ -1,53 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "toolchain.h"
|
||||
#include "test_env.h"
|
||||
#include "unity.h"
|
||||
#include "utest.h"
|
||||
|
||||
using namespace utest::v1;
|
||||
|
||||
|
||||
// Test functions declared as C functions to avoid issues with name mangling
|
||||
extern "C" {
|
||||
int testPacked();
|
||||
int testAlign();
|
||||
int testUnused();
|
||||
int testWeak();
|
||||
int testPure();
|
||||
int testForceInline();
|
||||
int testNoReturn();
|
||||
int testUnreachable();
|
||||
int testDeprecated();
|
||||
}
|
||||
|
||||
|
||||
// Test wrapper and test cases for utest
|
||||
template <int (*F)()>
|
||||
void test_wrapper() {
|
||||
TEST_ASSERT_UNLESS(F());
|
||||
}
|
||||
|
||||
status_t test_setup(const size_t number_of_cases) {
|
||||
GREENTEA_SETUP(40, "default_auto");
|
||||
return verbose_test_setup_handler(number_of_cases);
|
||||
}
|
||||
|
||||
Case cases[] = {
|
||||
Case("Testing PACKED attribute", test_wrapper<testPacked>),
|
||||
Case("Testing ALIGN attribute", test_wrapper<testAlign>),
|
||||
Case("Testing UNUSED attribute", test_wrapper<testUnused>),
|
||||
Case("Testing WEAK attribute", test_wrapper<testWeak>),
|
||||
Case("Testing PURE attribute", test_wrapper<testPure>),
|
||||
Case("Testing FORCEINLINE attribute", test_wrapper<testForceInline>),
|
||||
Case("Testing NORETURN attribute", test_wrapper<testNoReturn>),
|
||||
Case("Testing UNREACHABLE attribute", test_wrapper<testUnreachable>),
|
||||
Case("Testing DEPRECATED attribute", test_wrapper<testDeprecated>),
|
||||
};
|
||||
|
||||
Specification specification(test_setup, cases);
|
||||
|
||||
int main() {
|
||||
return !Harness::run(specification);
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
#include "toolchain.h"
|
||||
|
||||
int testWeak1() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
WEAK int testWeak2() {
|
||||
return 1;
|
||||
}
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ANALOGIN_H
|
||||
#define MBED_ANALOGIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_ANALOGIN
|
||||
|
||||
#include "analogin_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An analog input, used for reading the voltage on a pin
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Print messages when the AnalogIn is greater than 50%
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* AnalogIn temperature(p20);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* if(temperature > 0.5) {
|
||||
* printf("Too hot! (%f)", temperature.read());
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class AnalogIn {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an AnalogIn, connected to the specified pin
|
||||
*
|
||||
* @param pin AnalogIn pin to connect to
|
||||
* @param name (optional) A string to identify the object
|
||||
*/
|
||||
AnalogIn(PinName pin) {
|
||||
analogin_init(&_adc, pin);
|
||||
}
|
||||
|
||||
/** Read the input voltage, represented as a float in the range [0.0, 1.0]
|
||||
*
|
||||
* @returns A floating-point value representing the current input voltage, measured as a percentage
|
||||
*/
|
||||
float read() {
|
||||
return analogin_read(&_adc);
|
||||
}
|
||||
|
||||
/** Read the input voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
|
||||
*
|
||||
* @returns
|
||||
* 16-bit unsigned short representing the current input voltage, normalised to a 16-bit value
|
||||
*/
|
||||
unsigned short read_u16() {
|
||||
return analogin_read_u16(&_adc);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** An operator shorthand for read()
|
||||
*
|
||||
* The float() operator can be used as a shorthand for read() to simplify common code sequences
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* float x = volume.read();
|
||||
* float x = volume;
|
||||
*
|
||||
* if(volume.read() > 0.25) { ... }
|
||||
* if(volume > 0.25) { ... }
|
||||
* @endcode
|
||||
*/
|
||||
operator float() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
analogin_t _adc;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,121 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ANALOGOUT_H
|
||||
#define MBED_ANALOGOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_ANALOGOUT
|
||||
|
||||
#include "analogout_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An analog output, used for setting the voltage on a pin
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Make a sawtooth output
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* AnalogOut tri(p18);
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* tri = tri + 0.01;
|
||||
* wait_us(1);
|
||||
* if(tri == 1) {
|
||||
* tri = 0;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class AnalogOut {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an AnalogOut connected to the specified pin
|
||||
*
|
||||
* @param AnalogOut pin to connect to (18)
|
||||
*/
|
||||
AnalogOut(PinName pin) {
|
||||
analogout_init(&_dac, pin);
|
||||
}
|
||||
|
||||
/** Set the output voltage, specified as a percentage (float)
|
||||
*
|
||||
* @param value A floating-point value representing the output voltage,
|
||||
* specified as a percentage. The value should lie between
|
||||
* 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
|
||||
* Values outside this range will be saturated to 0.0f or 1.0f.
|
||||
*/
|
||||
void write(float value) {
|
||||
analogout_write(&_dac, value);
|
||||
}
|
||||
|
||||
/** Set the output voltage, represented as an unsigned short in the range [0x0, 0xFFFF]
|
||||
*
|
||||
* @param value 16-bit unsigned short representing the output voltage,
|
||||
* normalised to a 16-bit value (0x0000 = 0v, 0xFFFF = 3.3v)
|
||||
*/
|
||||
void write_u16(unsigned short value) {
|
||||
analogout_write_u16(&_dac, value);
|
||||
}
|
||||
|
||||
/** Return the current output voltage setting, measured as a percentage (float)
|
||||
*
|
||||
* @returns
|
||||
* A floating-point value representing the current voltage being output on the pin,
|
||||
* measured as a percentage. The returned value will lie between
|
||||
* 0.0f (representing 0v / 0%) and 1.0f (representing 3.3v / 100%).
|
||||
*
|
||||
* @note
|
||||
* This value may not match exactly the value set by a previous write().
|
||||
*/
|
||||
float read() {
|
||||
return analogout_read(&_dac);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** An operator shorthand for write()
|
||||
*/
|
||||
AnalogOut& operator= (float percent) {
|
||||
write(percent);
|
||||
return *this;
|
||||
}
|
||||
|
||||
AnalogOut& operator= (AnalogOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** An operator shorthand for read()
|
||||
*/
|
||||
operator float() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
dac_t _dac;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,98 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_BUSIN_H
|
||||
#define MBED_BUSIN_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "DigitalIn.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital input bus, used for reading the state of a collection of pins
|
||||
*/
|
||||
class BusIn {
|
||||
|
||||
public:
|
||||
/* Group: Configuration Methods */
|
||||
|
||||
/** Create an BusIn, connected to the specified pins
|
||||
*
|
||||
* @param <n> DigitalIn pin to connect to bus bit <n> (p5-p30, NC)
|
||||
*
|
||||
* @note
|
||||
* It is only required to specify as many pin variables as is required
|
||||
* for the bus; the rest will default to NC (not connected)
|
||||
*/
|
||||
BusIn(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
|
||||
PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
|
||||
PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
|
||||
PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
|
||||
|
||||
BusIn(PinName pins[16]);
|
||||
|
||||
virtual ~BusIn();
|
||||
|
||||
/** Read the value of the input bus
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to the value read from the associated DigitalIn pin
|
||||
*/
|
||||
int read();
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone
|
||||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalIn & operator[] (int index);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DigitalIn* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusIn(const BusIn&);
|
||||
BusIn & operator = (const BusIn&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,117 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_BUSINOUT_H
|
||||
#define MBED_BUSINOUT_H
|
||||
|
||||
#include "DigitalInOut.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital input output bus, used for setting the state of a collection of pins
|
||||
*/
|
||||
class BusInOut {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an BusInOut, connected to the specified pins
|
||||
*
|
||||
* @param p<n> DigitalInOut pin to connect to bus bit p<n> (p5-p30, NC)
|
||||
*
|
||||
* @note
|
||||
* It is only required to specify as many pin variables as is required
|
||||
* for the bus; the rest will default to NC (not connected)
|
||||
*/
|
||||
BusInOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
|
||||
PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
|
||||
PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
|
||||
PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
|
||||
|
||||
BusInOut(PinName pins[16]);
|
||||
|
||||
virtual ~BusInOut();
|
||||
|
||||
/* Group: Access Methods */
|
||||
|
||||
/** Write the value to the output bus
|
||||
*
|
||||
* @param value An integer specifying a bit to write for every corresponding DigitalInOut pin
|
||||
*/
|
||||
void write(int value);
|
||||
|
||||
/** Read the value currently output on the bus
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to associated DigitalInOut pin setting
|
||||
*/
|
||||
int read();
|
||||
|
||||
/** Set as an output
|
||||
*/
|
||||
void output();
|
||||
|
||||
/** Set as an input
|
||||
*/
|
||||
void input();
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone
|
||||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
BusInOut& operator= (int v);
|
||||
BusInOut& operator= (BusInOut& rhs);
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalInOut& operator[] (int index);
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DigitalInOut* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusInOut(const BusInOut&);
|
||||
BusInOut & operator = (const BusInOut&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
101
hal/api/BusOut.h
101
hal/api/BusOut.h
|
@ -1,101 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_BUSOUT_H
|
||||
#define MBED_BUSOUT_H
|
||||
|
||||
#include "DigitalOut.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital output bus, used for setting the state of a collection of pins
|
||||
*/
|
||||
class BusOut {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an BusOut, connected to the specified pins
|
||||
*
|
||||
* @param p<n> DigitalOut pin to connect to bus bit <n> (p5-p30, NC)
|
||||
*
|
||||
* @note
|
||||
* It is only required to specify as many pin variables as is required
|
||||
* for the bus; the rest will default to NC (not connected)
|
||||
*/
|
||||
BusOut(PinName p0, PinName p1 = NC, PinName p2 = NC, PinName p3 = NC,
|
||||
PinName p4 = NC, PinName p5 = NC, PinName p6 = NC, PinName p7 = NC,
|
||||
PinName p8 = NC, PinName p9 = NC, PinName p10 = NC, PinName p11 = NC,
|
||||
PinName p12 = NC, PinName p13 = NC, PinName p14 = NC, PinName p15 = NC);
|
||||
|
||||
BusOut(PinName pins[16]);
|
||||
|
||||
virtual ~BusOut();
|
||||
|
||||
/** Write the value to the output bus
|
||||
*
|
||||
* @param value An integer specifying a bit to write for every corresponding DigitalOut pin
|
||||
*/
|
||||
void write(int value);
|
||||
|
||||
/** Read the value currently output on the bus
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to associated DigitalOut pin setting
|
||||
*/
|
||||
int read();
|
||||
|
||||
/** Binary mask of bus pins connected to actual pins (not NC pins)
|
||||
* If bus pin is in NC state make corresponding bit will be cleared (set to 0), else bit will be set to 1
|
||||
*
|
||||
* @returns
|
||||
* Binary mask of connected pins
|
||||
*/
|
||||
int mask() {
|
||||
return _nc_mask;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
BusOut& operator= (int v);
|
||||
BusOut& operator= (BusOut& rhs);
|
||||
|
||||
/** Access to particular bit in random-iterator fashion
|
||||
*/
|
||||
DigitalOut& operator[] (int index);
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
DigitalOut* _pin[16];
|
||||
|
||||
/** Mask of bus's NC pins
|
||||
* If bit[n] is set to 1 - pin is connected
|
||||
* if bit[n] is cleared - pin is not connected (NC)
|
||||
*/
|
||||
int _nc_mask;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
BusOut(const BusOut&);
|
||||
BusOut & operator = (const BusOut&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
249
hal/api/CAN.h
249
hal/api/CAN.h
|
@ -1,249 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CAN_H
|
||||
#define MBED_CAN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_CAN
|
||||
|
||||
#include "can_api.h"
|
||||
#include "can_helper.h"
|
||||
#include "Callback.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** CANMessage class
|
||||
*/
|
||||
class CANMessage : public CAN_Message {
|
||||
|
||||
public:
|
||||
/** Creates empty CAN message.
|
||||
*/
|
||||
CANMessage() : CAN_Message() {
|
||||
len = 8;
|
||||
type = CANData;
|
||||
format = CANStandard;
|
||||
id = 0;
|
||||
memset(data, 0, 8);
|
||||
}
|
||||
|
||||
/** Creates CAN message with specific content.
|
||||
*/
|
||||
CANMessage(int _id, const char *_data, char _len = 8, CANType _type = CANData, CANFormat _format = CANStandard) {
|
||||
len = _len & 0xF;
|
||||
type = _type;
|
||||
format = _format;
|
||||
id = _id;
|
||||
memcpy(data, _data, _len);
|
||||
}
|
||||
|
||||
/** Creates CAN remote message.
|
||||
*/
|
||||
CANMessage(int _id, CANFormat _format = CANStandard) {
|
||||
len = 0;
|
||||
type = CANRemote;
|
||||
format = _format;
|
||||
id = _id;
|
||||
memset(data, 0, 8);
|
||||
}
|
||||
};
|
||||
|
||||
/** A can bus client, used for communicating with can devices
|
||||
*/
|
||||
class CAN {
|
||||
|
||||
public:
|
||||
/** Creates an CAN interface connected to specific pins.
|
||||
*
|
||||
* @param rd read from transmitter
|
||||
* @param td transmit to transmitter
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ticker ticker;
|
||||
* DigitalOut led1(LED1);
|
||||
* DigitalOut led2(LED2);
|
||||
* CAN can1(p9, p10);
|
||||
* CAN can2(p30, p29);
|
||||
*
|
||||
* char counter = 0;
|
||||
*
|
||||
* void send() {
|
||||
* if(can1.write(CANMessage(1337, &counter, 1))) {
|
||||
* printf("Message sent: %d\n", counter);
|
||||
* counter++;
|
||||
* }
|
||||
* led1 = !led1;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* ticker.attach(&send, 1);
|
||||
* CANMessage msg;
|
||||
* while(1) {
|
||||
* if(can2.read(msg)) {
|
||||
* printf("Message received: %d\n\n", msg.data[0]);
|
||||
* led2 = !led2;
|
||||
* }
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
CAN(PinName rd, PinName td);
|
||||
virtual ~CAN();
|
||||
|
||||
/** Set the frequency of the CAN interface
|
||||
*
|
||||
* @param hz The bus frequency in hertz
|
||||
*
|
||||
* @returns
|
||||
* 1 if successful,
|
||||
* 0 otherwise
|
||||
*/
|
||||
int frequency(int hz);
|
||||
|
||||
/** Write a CANMessage to the bus.
|
||||
*
|
||||
* @param msg The CANMessage to write.
|
||||
*
|
||||
* @returns
|
||||
* 0 if write failed,
|
||||
* 1 if write was successful
|
||||
*/
|
||||
int write(CANMessage msg);
|
||||
|
||||
/** Read a CANMessage from the bus.
|
||||
*
|
||||
* @param msg A CANMessage to read to.
|
||||
* @param handle message filter handle (0 for any message)
|
||||
*
|
||||
* @returns
|
||||
* 0 if no message arrived,
|
||||
* 1 if message arrived
|
||||
*/
|
||||
int read(CANMessage &msg, int handle = 0);
|
||||
|
||||
/** Reset CAN interface.
|
||||
*
|
||||
* To use after error overflow.
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/** Puts or removes the CAN interface into silent monitoring mode
|
||||
*
|
||||
* @param silent boolean indicating whether to go into silent mode or not
|
||||
*/
|
||||
void monitor(bool silent);
|
||||
|
||||
enum Mode {
|
||||
Reset = 0,
|
||||
Normal,
|
||||
Silent,
|
||||
LocalTest,
|
||||
GlobalTest,
|
||||
SilentTest
|
||||
};
|
||||
|
||||
/** Change CAN operation to the specified mode
|
||||
*
|
||||
* @param mode The new operation mode (CAN::Normal, CAN::Silent, CAN::LocalTest, CAN::GlobalTest, CAN::SilentTest)
|
||||
*
|
||||
* @returns
|
||||
* 0 if mode change failed or unsupported,
|
||||
* 1 if mode change was successful
|
||||
*/
|
||||
int mode(Mode mode);
|
||||
|
||||
/** Filter out incomming messages
|
||||
*
|
||||
* @param id the id to filter on
|
||||
* @param mask the mask applied to the id
|
||||
* @param format format to filter on (Default CANAny)
|
||||
* @param handle message filter handle (Optional)
|
||||
*
|
||||
* @returns
|
||||
* 0 if filter change failed or unsupported,
|
||||
* new filter handle if successful
|
||||
*/
|
||||
int filter(unsigned int id, unsigned int mask, CANFormat format = CANAny, int handle = 0);
|
||||
|
||||
/** Returns number of read errors to detect read overflow errors.
|
||||
*/
|
||||
unsigned char rderror();
|
||||
|
||||
/** Returns number of write errors to detect write overflow errors.
|
||||
*/
|
||||
unsigned char tderror();
|
||||
|
||||
enum IrqType {
|
||||
RxIrq = 0,
|
||||
TxIrq,
|
||||
EwIrq,
|
||||
DoIrq,
|
||||
WuIrq,
|
||||
EpIrq,
|
||||
AlIrq,
|
||||
BeIrq,
|
||||
IdIrq
|
||||
};
|
||||
|
||||
/** Attach a function to call whenever a CAN frame received interrupt is
|
||||
* generated.
|
||||
*
|
||||
* @param func A pointer to a void function, or 0 to set as none
|
||||
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, CAN::TxIrq for transmitted or aborted, CAN::EwIrq for error warning, CAN::DoIrq for data overrun, CAN::WuIrq for wake-up, CAN::EpIrq for error passive, CAN::AlIrq for arbitration lost, CAN::BeIrq for bus error)
|
||||
*/
|
||||
void attach(Callback<void()> func, IrqType type=RxIrq);
|
||||
|
||||
/** Attach a member function to call whenever a CAN frame received interrupt
|
||||
* is generated.
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T* obj, void (T::*method)(), IrqType type=RxIrq) {
|
||||
attach(Callback<void()>(obj, method), type);
|
||||
}
|
||||
|
||||
/** Attach a member function to call whenever a CAN frame received interrupt
|
||||
* is generated.
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
* @param event Which CAN interrupt to attach the member function to (CAN::RxIrq for message received, TxIrq for transmitted or aborted, EwIrq for error warning, DoIrq for data overrun, WuIrq for wake-up, EpIrq for error passive, AlIrq for arbitration lost, BeIrq for bus error)
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T* obj, void (*method)(T*), IrqType type=RxIrq) {
|
||||
attach(Callback<void()>(obj, method), type);
|
||||
}
|
||||
|
||||
static void _irq_handler(uint32_t id, CanIrqType type);
|
||||
|
||||
protected:
|
||||
can_t _can;
|
||||
Callback<void()> _irq[9];
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MBED_CAN_H
|
202
hal/api/CThunk.h
202
hal/api/CThunk.h
|
@ -1,202 +0,0 @@
|
|||
/* General C++ Object Thunking class
|
||||
*
|
||||
* - allows direct callbacks to non-static C++ class functions
|
||||
* - keeps track for the corresponding class instance
|
||||
* - supports an optional context parameter for the called function
|
||||
* - ideally suited for class object receiving interrupts (NVIC_SetVector)
|
||||
*
|
||||
* Copyright (c) 2014-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef __CTHUNK_H__
|
||||
#define __CTHUNK_H__
|
||||
|
||||
#define CTHUNK_ADDRESS 1
|
||||
|
||||
#if defined(__CORTEX_M3) || defined(__CORTEX_M4) || defined(__thumb2__)
|
||||
#define CTHUNK_VARIABLES volatile uint32_t code[1]
|
||||
/**
|
||||
* CTHUNK disassembly for Cortex-M3/M4 (thumb2):
|
||||
* * ldm.w pc,{r0,r1,r2,pc}
|
||||
*
|
||||
* This instruction loads the arguments for the static thunking function to r0-r2, and
|
||||
* branches to that function by loading its address into PC.
|
||||
*
|
||||
* This is safe for both regular calling and interrupt calling, since it only touches scratch registers
|
||||
* which should be saved by the caller, and are automatically saved as part of the IRQ context switch.
|
||||
*/
|
||||
#define CTHUNK_ASSIGMENT m_thunk.code[0] = 0x8007E89F
|
||||
|
||||
#elif defined(__CORTEX_M0PLUS) || defined(__CORTEX_M0)
|
||||
/*
|
||||
* CTHUNK disassembly for Cortex M0 (thumb):
|
||||
* * push {r0,r1,r2,r3,r4,lr} save touched registers and return address
|
||||
* * movs r4,#4 set up address to load arguments from (immediately following this code block) (1)
|
||||
* * add r4,pc set up address to load arguments from (immediately following this code block) (2)
|
||||
* * ldm r4!,{r0,r1,r2,r3} load arguments for static thunk function
|
||||
* * blx r3 call static thunk function
|
||||
* * pop {r0,r1,r2,r3,r4,pc} restore scratch registers and return from function
|
||||
*/
|
||||
#define CTHUNK_VARIABLES volatile uint32_t code[3]
|
||||
#define CTHUNK_ASSIGMENT do { \
|
||||
m_thunk.code[0] = 0x2404B51F; \
|
||||
m_thunk.code[1] = 0xCC0F447C; \
|
||||
m_thunk.code[2] = 0xBD1F4798; \
|
||||
} while (0)
|
||||
|
||||
#else
|
||||
#error "Target is not currently suported."
|
||||
#endif
|
||||
|
||||
/* IRQ/Exception compatible thunk entry function */
|
||||
typedef void (*CThunkEntry)(void);
|
||||
|
||||
template<class T>
|
||||
class CThunk
|
||||
{
|
||||
public:
|
||||
typedef void (T::*CCallbackSimple)(void);
|
||||
typedef void (T::*CCallback)(void* context);
|
||||
|
||||
inline CThunk(T *instance)
|
||||
{
|
||||
init(instance, NULL, NULL);
|
||||
}
|
||||
|
||||
inline CThunk(T *instance, CCallback callback)
|
||||
{
|
||||
init(instance, callback, NULL);
|
||||
}
|
||||
|
||||
~CThunk() {
|
||||
|
||||
}
|
||||
|
||||
inline CThunk(T *instance, CCallbackSimple callback)
|
||||
{
|
||||
init(instance, (CCallback)callback, NULL);
|
||||
}
|
||||
|
||||
inline CThunk(T &instance, CCallback callback)
|
||||
{
|
||||
init(instance, callback, NULL);
|
||||
}
|
||||
|
||||
inline CThunk(T &instance, CCallbackSimple callback)
|
||||
{
|
||||
init(instance, (CCallback)callback, NULL);
|
||||
}
|
||||
|
||||
inline CThunk(T &instance, CCallback callback, void* context)
|
||||
{
|
||||
init(instance, callback, context);
|
||||
}
|
||||
|
||||
inline void callback(CCallback callback)
|
||||
{
|
||||
m_callback = callback;
|
||||
}
|
||||
|
||||
inline void callback(CCallbackSimple callback)
|
||||
{
|
||||
m_callback = (CCallback)callback;
|
||||
}
|
||||
|
||||
inline void context(void* context)
|
||||
{
|
||||
m_thunk.context = (uint32_t)context;
|
||||
}
|
||||
|
||||
inline void context(uint32_t context)
|
||||
{
|
||||
m_thunk.context = context;
|
||||
}
|
||||
|
||||
inline uint32_t entry(void)
|
||||
{
|
||||
return (((uint32_t)&m_thunk)|CTHUNK_ADDRESS);
|
||||
}
|
||||
|
||||
/* get thunk entry point for connecting rhunk to an IRQ table */
|
||||
inline operator CThunkEntry(void)
|
||||
{
|
||||
return (CThunkEntry)entry();
|
||||
}
|
||||
|
||||
/* get thunk entry point for connecting rhunk to an IRQ table */
|
||||
inline operator uint32_t(void)
|
||||
{
|
||||
return entry();
|
||||
}
|
||||
|
||||
/* simple test function */
|
||||
inline void call(void)
|
||||
{
|
||||
(((CThunkEntry)(entry()))());
|
||||
}
|
||||
|
||||
private:
|
||||
T* m_instance;
|
||||
volatile CCallback m_callback;
|
||||
|
||||
// TODO: this needs proper fix, to refactor toolchain header file and all its use
|
||||
// PACKED there is not defined properly for IAR
|
||||
#if defined (__ICCARM__)
|
||||
typedef __packed struct
|
||||
{
|
||||
CTHUNK_VARIABLES;
|
||||
volatile uint32_t instance;
|
||||
volatile uint32_t context;
|
||||
volatile uint32_t callback;
|
||||
volatile uint32_t trampoline;
|
||||
} CThunkTrampoline;
|
||||
#else
|
||||
typedef struct
|
||||
{
|
||||
CTHUNK_VARIABLES;
|
||||
volatile uint32_t instance;
|
||||
volatile uint32_t context;
|
||||
volatile uint32_t callback;
|
||||
volatile uint32_t trampoline;
|
||||
} __attribute__((__packed__)) CThunkTrampoline;
|
||||
#endif
|
||||
|
||||
static void trampoline(T* instance, void* context, CCallback* callback)
|
||||
{
|
||||
if(instance && *callback) {
|
||||
(static_cast<T*>(instance)->**callback)(context);
|
||||
}
|
||||
}
|
||||
|
||||
volatile CThunkTrampoline m_thunk;
|
||||
|
||||
inline void init(T *instance, CCallback callback, void* context)
|
||||
{
|
||||
/* remember callback - need to add this level of redirection
|
||||
as pointer size for member functions differs between platforms */
|
||||
m_callback = callback;
|
||||
|
||||
/* populate thunking trampoline */
|
||||
CTHUNK_ASSIGMENT;
|
||||
m_thunk.context = (uint32_t)context;
|
||||
m_thunk.instance = (uint32_t)instance;
|
||||
m_thunk.callback = (uint32_t)&m_callback;
|
||||
m_thunk.trampoline = (uint32_t)&trampoline;
|
||||
|
||||
__ISB();
|
||||
__DSB();
|
||||
}
|
||||
};
|
||||
|
||||
#endif/*__CTHUNK_H__*/
|
|
@ -1,179 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CALLCHAIN_H
|
||||
#define MBED_CALLCHAIN_H
|
||||
|
||||
#include "Callback.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Group one or more functions in an instance of a CallChain, then call them in
|
||||
* sequence using CallChain::call(). Used mostly by the interrupt chaining code,
|
||||
* but can be used for other purposes.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* CallChain chain;
|
||||
*
|
||||
* void first(void) {
|
||||
* printf("'first' function.\n");
|
||||
* }
|
||||
*
|
||||
* void second(void) {
|
||||
* printf("'second' function.\n");
|
||||
* }
|
||||
*
|
||||
* class Test {
|
||||
* public:
|
||||
* void f(void) {
|
||||
* printf("A::f (class member).\n");
|
||||
* }
|
||||
* };
|
||||
*
|
||||
* int main() {
|
||||
* Test test;
|
||||
*
|
||||
* chain.add(second);
|
||||
* chain.add_front(first);
|
||||
* chain.add(&test, &Test::f);
|
||||
* chain.call();
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
typedef Callback<void()> *pFunctionPointer_t;
|
||||
|
||||
class CallChain {
|
||||
public:
|
||||
/** Create an empty chain
|
||||
*
|
||||
* @param size (optional) Initial size of the chain
|
||||
*/
|
||||
CallChain(int size = 4);
|
||||
virtual ~CallChain();
|
||||
|
||||
/** Add a function at the end of the chain
|
||||
*
|
||||
* @param func A pointer to a void function
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'func'
|
||||
*/
|
||||
pFunctionPointer_t add(Callback<void()> func);
|
||||
|
||||
/** Add a function at the end of the chain
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'obj' and 'method'
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
pFunctionPointer_t add(T *obj, M method) {
|
||||
return add(Callback<void()>(obj, method));
|
||||
}
|
||||
|
||||
/** Add a function at the beginning of the chain
|
||||
*
|
||||
* @param func A pointer to a void function
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'func'
|
||||
*/
|
||||
pFunctionPointer_t add_front(Callback<void()> func);
|
||||
|
||||
/** Add a function at the beginning of the chain
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
pFunctionPointer_t add_front(T *obj, M method) {
|
||||
return add_front(Callback<void()>(obj, method));
|
||||
}
|
||||
|
||||
/** Get the number of functions in the chain
|
||||
*/
|
||||
int size() const;
|
||||
|
||||
/** Get a function object from the chain
|
||||
*
|
||||
* @param i function object index
|
||||
*
|
||||
* @returns
|
||||
* The function object at position 'i' in the chain
|
||||
*/
|
||||
pFunctionPointer_t get(int i) const;
|
||||
|
||||
/** Look for a function object in the call chain
|
||||
*
|
||||
* @param f the function object to search
|
||||
*
|
||||
* @returns
|
||||
* The index of the function object if found, -1 otherwise.
|
||||
*/
|
||||
int find(pFunctionPointer_t f) const;
|
||||
|
||||
/** Clear the call chain (remove all functions in the chain).
|
||||
*/
|
||||
void clear();
|
||||
|
||||
/** Remove a function object from the chain
|
||||
*
|
||||
* @arg f the function object to remove
|
||||
*
|
||||
* @returns
|
||||
* true if the function object was found and removed, false otherwise.
|
||||
*/
|
||||
bool remove(pFunctionPointer_t f);
|
||||
|
||||
/** Call all the functions in the chain in sequence
|
||||
*/
|
||||
void call();
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
void operator ()(void) {
|
||||
call();
|
||||
}
|
||||
pFunctionPointer_t operator [](int i) const {
|
||||
return get(i);
|
||||
}
|
||||
#endif
|
||||
|
||||
private:
|
||||
void _check_size();
|
||||
|
||||
pFunctionPointer_t* _chain;
|
||||
int _size;
|
||||
int _elements;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
CallChain(const CallChain&);
|
||||
CallChain & operator = (const CallChain&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
|
@ -1,879 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CALLBACK_H
|
||||
#define MBED_CALLBACK_H
|
||||
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
|
||||
/** Callback class based on template specialization
|
||||
*/
|
||||
template <typename F>
|
||||
class Callback;
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R, typename A0, typename A1, typename A2, typename A3, typename A4>
|
||||
class Callback<R(A0, A1, A2, A3, A4)> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)(A0, A1, A2, A3, A4) = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R(A0, A1, A2, A3, A4)> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)(A0, A1, A2, A3, A4)) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*, A0, A1, A2, A3, A4)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)(A0, A1, A2, A3, A4)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R(A0, A1, A2, A3, A4)> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func, a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()(A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
return call(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
return static_cast<Callback<R(A0, A1, A2, A3, A4)>*>(func)
|
||||
->call(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
return (*reinterpret_cast<R (**)(A0, A1, A2, A3, A4)>(func))
|
||||
(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
return (*reinterpret_cast<R (**)(T*, A0, A1, A2, A3, A4)>(func))
|
||||
(static_cast<T*>(obj), a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3, A4 a4) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)(A0, A1, A2, A3, A4)>(func)))
|
||||
(a0, a1, a2, a3, a4);
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*, A0, A1, A2, A3, A4);
|
||||
};
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R, typename A0, typename A1, typename A2, typename A3>
|
||||
class Callback<R(A0, A1, A2, A3)> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)(A0, A1, A2, A3) = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*, A0, A1, A2, A3)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)(A0, A1, A2, A3)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R(A0, A1, A2, A3)> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)(A0, A1, A2, A3)) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*, A0, A1, A2, A3)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)(A0, A1, A2, A3)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R(A0, A1, A2, A3)> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call(A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func, a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()(A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
return call(a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
return static_cast<Callback<R(A0, A1, A2, A3)>*>(func)
|
||||
->call(a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
return (*reinterpret_cast<R (**)(A0, A1, A2, A3)>(func))
|
||||
(a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
return (*reinterpret_cast<R (**)(T*, A0, A1, A2, A3)>(func))
|
||||
(static_cast<T*>(obj), a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2, A3 a3) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)(A0, A1, A2, A3)>(func)))
|
||||
(a0, a1, a2, a3);
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*, A0, A1, A2, A3);
|
||||
};
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R, typename A0, typename A1, typename A2>
|
||||
class Callback<R(A0, A1, A2)> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)(A0, A1, A2) = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*, A0, A1, A2)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)(A0, A1, A2)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R(A0, A1, A2)> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)(A0, A1, A2)) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*, A0, A1, A2)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)(A0, A1, A2)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R(A0, A1, A2)> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call(A0 a0, A1 a1, A2 a2) {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func, a0, a1, a2);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()(A0 a0, A1 a1, A2 a2) {
|
||||
return call(a0, a1, a2);
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func, A0 a0, A1 a1, A2 a2) {
|
||||
return static_cast<Callback<R(A0, A1, A2)>*>(func)
|
||||
->call(a0, a1, a2);
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func, A0 a0, A1 a1, A2 a2) {
|
||||
return (*reinterpret_cast<R (**)(A0, A1, A2)>(func))
|
||||
(a0, a1, a2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2) {
|
||||
return (*reinterpret_cast<R (**)(T*, A0, A1, A2)>(func))
|
||||
(static_cast<T*>(obj), a0, a1, a2);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func, A0 a0, A1 a1, A2 a2) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)(A0, A1, A2)>(func)))
|
||||
(a0, a1, a2);
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*, A0, A1, A2);
|
||||
};
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R, typename A0, typename A1>
|
||||
class Callback<R(A0, A1)> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)(A0, A1) = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*, A0, A1)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)(A0, A1)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R(A0, A1)> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)(A0, A1)) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*, A0, A1)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)(A0, A1)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R(A0, A1)> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call(A0 a0, A1 a1) {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func, a0, a1);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()(A0 a0, A1 a1) {
|
||||
return call(a0, a1);
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func, A0 a0, A1 a1) {
|
||||
return static_cast<Callback<R(A0, A1)>*>(func)
|
||||
->call(a0, a1);
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func, A0 a0, A1 a1) {
|
||||
return (*reinterpret_cast<R (**)(A0, A1)>(func))
|
||||
(a0, a1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func, A0 a0, A1 a1) {
|
||||
return (*reinterpret_cast<R (**)(T*, A0, A1)>(func))
|
||||
(static_cast<T*>(obj), a0, a1);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func, A0 a0, A1 a1) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)(A0, A1)>(func)))
|
||||
(a0, a1);
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*, A0, A1);
|
||||
};
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R, typename A0>
|
||||
class Callback<R(A0)> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)(A0) = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*, A0)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)(A0)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R(A0)> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)(A0)) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*, A0)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)(A0)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R(A0)> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call(A0 a0) {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func, a0);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()(A0 a0) {
|
||||
return call(a0);
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func, A0 a0) {
|
||||
return static_cast<Callback<R(A0)>*>(func)
|
||||
->call(a0);
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func, A0 a0) {
|
||||
return (*reinterpret_cast<R (**)(A0)>(func))
|
||||
(a0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func, A0 a0) {
|
||||
return (*reinterpret_cast<R (**)(T*, A0)>(func))
|
||||
(static_cast<T*>(obj), a0);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func, A0 a0) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)(A0)>(func)))
|
||||
(a0);
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*, A0);
|
||||
};
|
||||
|
||||
/** Templated function class
|
||||
*/
|
||||
template <typename R>
|
||||
class Callback<R()> {
|
||||
public:
|
||||
/** Create a Callback with a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
Callback(R (*func)() = 0) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a static function and bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (*func)(T*)) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
Callback(T *obj, R (T::*func)()) {
|
||||
attach(obj, func);
|
||||
}
|
||||
|
||||
/** Create a Callback with another Callback
|
||||
* @param func Callback to attach
|
||||
*/
|
||||
Callback(const Callback<R()> &func) {
|
||||
attach(func);
|
||||
}
|
||||
|
||||
/** Attach a static function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
void attach(R (*func)()) {
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = func ? &Callback::_staticthunk : 0;
|
||||
}
|
||||
|
||||
/** Attach a static function with a bound pointer
|
||||
* @param obj Pointer to object to bind to function
|
||||
* @param func Static function to attach
|
||||
*/
|
||||
template <typename T>
|
||||
void attach(T *obj, R (*func)(T*)) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_boundthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a member function
|
||||
* @param obj Pointer to object to invoke member function on
|
||||
* @param func Member function to attach
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, R (T::*func)()) {
|
||||
_obj = static_cast<void*>(obj);
|
||||
memcpy(&_func, &func, sizeof func);
|
||||
_thunk = &Callback::_methodthunk<T>;
|
||||
}
|
||||
|
||||
/** Attach a Callback
|
||||
* @param func The Callback to attach
|
||||
*/
|
||||
void attach(const Callback<R()> &func) {
|
||||
_obj = func._obj;
|
||||
memcpy(&_func, &func._func, sizeof _func);
|
||||
_thunk = func._thunk;
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R call() {
|
||||
if (!_thunk) {
|
||||
return (R)0;
|
||||
}
|
||||
return _thunk(_obj, &_func);
|
||||
}
|
||||
|
||||
/** Call the attached function
|
||||
*/
|
||||
R operator()() {
|
||||
return call();
|
||||
}
|
||||
|
||||
/** Test if function has been attached
|
||||
*/
|
||||
operator bool() const {
|
||||
return _thunk;
|
||||
}
|
||||
|
||||
/** Static thunk for passing as C-style function
|
||||
* @param func Callback to call passed as void pointer
|
||||
*/
|
||||
static R thunk(void *func) {
|
||||
return static_cast<Callback<R()>*>(func)
|
||||
->call();
|
||||
}
|
||||
|
||||
private:
|
||||
// Internal thunks for various function types
|
||||
static R _staticthunk(void*, void *func) {
|
||||
return (*reinterpret_cast<R (**)()>(func))
|
||||
();
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _boundthunk(void *obj, void *func) {
|
||||
return (*reinterpret_cast<R (**)(T*)>(func))
|
||||
(static_cast<T*>(obj));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
static R _methodthunk(void *obj, void *func) {
|
||||
return (static_cast<T*>(obj)->*
|
||||
(*reinterpret_cast<R (T::**)()>(func)))
|
||||
();
|
||||
}
|
||||
|
||||
// Stored as pointer to function and pointer to optional object
|
||||
// Function pointer is stored as union of possible function types
|
||||
// to garuntee proper size and alignment
|
||||
struct _class;
|
||||
union {
|
||||
void (*_staticfunc)();
|
||||
void (*_boundfunc)(_class *);
|
||||
void (_class::*_methodfunc)();
|
||||
} _func;
|
||||
|
||||
void *_obj;
|
||||
|
||||
// Thunk registered on attach to dispatch calls
|
||||
R (*_thunk)(void*, void*);
|
||||
};
|
||||
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,98 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CIRCULARBUFFER_H
|
||||
#define MBED_CIRCULARBUFFER_H
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Templated Circular buffer class
|
||||
*/
|
||||
template<typename T, uint32_t BufferSize, typename CounterType = uint32_t>
|
||||
class CircularBuffer {
|
||||
public:
|
||||
CircularBuffer() : _head(0), _tail(0), _full(false) {
|
||||
}
|
||||
|
||||
~CircularBuffer() {
|
||||
}
|
||||
|
||||
/** Push the transaction to the buffer. This overwrites the buffer if it's
|
||||
* full
|
||||
*
|
||||
* @param data Data to be pushed to the buffer
|
||||
*/
|
||||
void push(const T& data) {
|
||||
if (full()) {
|
||||
_tail++;
|
||||
_tail %= BufferSize;
|
||||
}
|
||||
_pool[_head++] = data;
|
||||
_head %= BufferSize;
|
||||
if (_head == _tail) {
|
||||
_full = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** Pop the transaction from the buffer
|
||||
*
|
||||
* @param data Data to be pushed to the buffer
|
||||
* @return True if the buffer is not empty and data contains a transaction, false otherwise
|
||||
*/
|
||||
bool pop(T& data) {
|
||||
if (!empty()) {
|
||||
data = _pool[_tail++];
|
||||
_tail %= BufferSize;
|
||||
_full = false;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Check if the buffer is empty
|
||||
*
|
||||
* @return True if the buffer is empty, false if not
|
||||
*/
|
||||
bool empty() {
|
||||
return (_head == _tail) && !_full;
|
||||
}
|
||||
|
||||
/** Check if the buffer is full
|
||||
*
|
||||
* @return True if the buffer is full, false if not
|
||||
*/
|
||||
bool full() {
|
||||
return _full;
|
||||
}
|
||||
|
||||
/** Reset the buffer
|
||||
*
|
||||
*/
|
||||
void reset() {
|
||||
_head = 0;
|
||||
_tail = 0;
|
||||
_full = false;
|
||||
}
|
||||
|
||||
private:
|
||||
T _pool[BufferSize];
|
||||
volatile CounterType _head;
|
||||
volatile CounterType _tail;
|
||||
volatile bool _full;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,107 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_DIGITALIN_H
|
||||
#define MBED_DIGITALIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "gpio_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital input, used for reading the state of a pin
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Flash an LED while a DigitalIn is true
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* DigitalIn enable(p5);
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* if(enable) {
|
||||
* led = !led;
|
||||
* }
|
||||
* wait(0.25);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class DigitalIn {
|
||||
|
||||
public:
|
||||
/** Create a DigitalIn connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalIn pin to connect to
|
||||
*/
|
||||
DigitalIn(PinName pin) : gpio() {
|
||||
gpio_init_in(&gpio, pin);
|
||||
}
|
||||
|
||||
/** Create a DigitalIn connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalIn pin to connect to
|
||||
* @param mode the initial mode of the pin
|
||||
*/
|
||||
DigitalIn(PinName pin, PinMode mode) : gpio() {
|
||||
gpio_init_in_ex(&gpio, pin, mode);
|
||||
}
|
||||
/** Read the input, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* An integer representing the state of the input pin,
|
||||
* 0 for logical 0, 1 for logical 1
|
||||
*/
|
||||
int read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone, OpenDrain
|
||||
*/
|
||||
void mode(PinMode pull) {
|
||||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** An operator shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
gpio_t gpio;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,124 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_DIGITALINOUT_H
|
||||
#define MBED_DIGITALINOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "gpio_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital input/output, used for setting or reading a bi-directional pin
|
||||
*/
|
||||
class DigitalInOut {
|
||||
|
||||
public:
|
||||
/** Create a DigitalInOut connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalInOut pin to connect to
|
||||
*/
|
||||
DigitalInOut(PinName pin) : gpio() {
|
||||
gpio_init_in(&gpio, pin);
|
||||
}
|
||||
|
||||
/** Create a DigitalInOut connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalInOut pin to connect to
|
||||
* @param direction the initial direction of the pin
|
||||
* @param mode the initial mode of the pin
|
||||
* @param value the initial value of the pin if is an output
|
||||
*/
|
||||
DigitalInOut(PinName pin, PinDirection direction, PinMode mode, int value) : gpio() {
|
||||
gpio_init_inout(&gpio, pin, direction, mode, value);
|
||||
}
|
||||
|
||||
/** Set the output, specified as 0 or 1 (int)
|
||||
*
|
||||
* @param value An integer specifying the pin output value,
|
||||
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
|
||||
*/
|
||||
void write(int value) {
|
||||
gpio_write(&gpio, value);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* an integer representing the output setting of the pin if it is an output,
|
||||
* or read the input if set as an input
|
||||
*/
|
||||
int read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
/** Set as an output
|
||||
*/
|
||||
void output() {
|
||||
gpio_dir(&gpio, PIN_OUTPUT);
|
||||
}
|
||||
|
||||
/** Set as an input
|
||||
*/
|
||||
void input() {
|
||||
gpio_dir(&gpio, PIN_INPUT);
|
||||
}
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone, OpenDrain
|
||||
*/
|
||||
void mode(PinMode pull) {
|
||||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
DigitalInOut& operator= (int value) {
|
||||
write(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
DigitalInOut& operator= (DigitalInOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
gpio_t gpio;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,116 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_DIGITALOUT_H
|
||||
#define MBED_DIGITALOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "gpio_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital output, used for setting the state of a pin
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Toggle a LED
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* led = !led;
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class DigitalOut {
|
||||
|
||||
public:
|
||||
/** Create a DigitalOut connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalOut pin to connect to
|
||||
*/
|
||||
DigitalOut(PinName pin) : gpio() {
|
||||
gpio_init_out(&gpio, pin);
|
||||
}
|
||||
|
||||
/** Create a DigitalOut connected to the specified pin
|
||||
*
|
||||
* @param pin DigitalOut pin to connect to
|
||||
* @param value the initial pin value
|
||||
*/
|
||||
DigitalOut(PinName pin, int value) : gpio() {
|
||||
gpio_init_out_ex(&gpio, pin, value);
|
||||
}
|
||||
|
||||
/** Set the output, specified as 0 or 1 (int)
|
||||
*
|
||||
* @param value An integer specifying the pin output value,
|
||||
* 0 for logical 0, 1 (or any other non-zero value) for logical 1
|
||||
*/
|
||||
void write(int value) {
|
||||
gpio_write(&gpio, value);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* an integer representing the output setting of the pin,
|
||||
* 0 for logical 0, 1 for logical 1
|
||||
*/
|
||||
int read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
/** Return the output setting, represented as 0 or 1 (int)
|
||||
*
|
||||
* @returns
|
||||
* Non zero value if pin is connected to uc GPIO
|
||||
* 0 if gpio object was initialized with NC
|
||||
*/
|
||||
int is_connected() {
|
||||
return gpio_is_connected(&gpio);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
DigitalOut& operator= (int value) {
|
||||
write(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
DigitalOut& operator= (DigitalOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
gpio_t gpio;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,104 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_DIRHANDLE_H
|
||||
#define MBED_DIRHANDLE_H
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
|
||||
# define NAME_MAX 255
|
||||
typedef int mode_t;
|
||||
|
||||
#else
|
||||
# include <sys/syslimits.h>
|
||||
#endif
|
||||
|
||||
#include "FileHandle.h"
|
||||
|
||||
struct dirent {
|
||||
char d_name[NAME_MAX+1];
|
||||
};
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Represents a directory stream. Objects of this type are returned
|
||||
* by a FileSystemLike's opendir method. Implementations must define
|
||||
* at least closedir, readdir and rewinddir.
|
||||
*
|
||||
* If a FileSystemLike class defines the opendir method, then the
|
||||
* directories of an object of that type can be accessed by
|
||||
* DIR *d = opendir("/example/directory") (or opendir("/example")
|
||||
* to open the root of the filesystem), and then using readdir(d) etc.
|
||||
*
|
||||
* The root directory is considered to contain all FileLike and
|
||||
* FileSystemLike objects, so the DIR* returned by opendir("/") will
|
||||
* reflect this.
|
||||
*/
|
||||
class DirHandle {
|
||||
|
||||
public:
|
||||
/** Closes the directory.
|
||||
*
|
||||
* @returns
|
||||
* 0 on success,
|
||||
* -1 on error.
|
||||
*/
|
||||
virtual int closedir()=0;
|
||||
|
||||
/** Return the directory entry at the current position, and
|
||||
* advances the position to the next entry.
|
||||
*
|
||||
* @returns
|
||||
* A pointer to a dirent structure representing the
|
||||
* directory entry at the current position, or NULL on reaching
|
||||
* end of directory or error.
|
||||
*/
|
||||
virtual struct dirent *readdir()=0;
|
||||
|
||||
/** Resets the position to the beginning of the directory.
|
||||
*/
|
||||
virtual void rewinddir()=0;
|
||||
|
||||
/** Returns the current position of the DirHandle.
|
||||
*
|
||||
* @returns
|
||||
* the current position,
|
||||
* -1 on error.
|
||||
*/
|
||||
virtual off_t telldir() { return -1; }
|
||||
|
||||
/** Sets the position of the DirHandle.
|
||||
*
|
||||
* @param location The location to seek to. Must be a value returned by telldir.
|
||||
*/
|
||||
virtual void seekdir(off_t location) { }
|
||||
|
||||
virtual ~DirHandle() {}
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
typedef mbed::DirHandle DIR;
|
||||
|
||||
extern "C" {
|
||||
DIR *opendir(const char*);
|
||||
struct dirent *readdir(DIR *);
|
||||
int closedir(DIR*);
|
||||
void rewinddir(DIR*);
|
||||
long telldir(DIR*);
|
||||
void seekdir(DIR*, long);
|
||||
int mkdir(const char *name, mode_t n);
|
||||
};
|
||||
|
||||
#endif /* MBED_DIRHANDLE_H */
|
|
@ -1,170 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ETHERNET_H
|
||||
#define MBED_ETHERNET_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_ETHERNET
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An ethernet interface, to use with the ethernet pins.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Read destination and source from every ethernet packet
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ethernet eth;
|
||||
*
|
||||
* int main() {
|
||||
* char buf[0x600];
|
||||
*
|
||||
* while(1) {
|
||||
* int size = eth.receive();
|
||||
* if(size > 0) {
|
||||
* eth.read(buf, size);
|
||||
* printf("Destination: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
* buf[0], buf[1], buf[2], buf[3], buf[4], buf[5]);
|
||||
* printf("Source: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
* buf[6], buf[7], buf[8], buf[9], buf[10], buf[11]);
|
||||
* }
|
||||
*
|
||||
* wait(1);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Ethernet {
|
||||
|
||||
public:
|
||||
|
||||
/** Initialise the ethernet interface.
|
||||
*/
|
||||
Ethernet();
|
||||
|
||||
/** Powers the hardware down.
|
||||
*/
|
||||
virtual ~Ethernet();
|
||||
|
||||
enum Mode {
|
||||
AutoNegotiate,
|
||||
HalfDuplex10,
|
||||
FullDuplex10,
|
||||
HalfDuplex100,
|
||||
FullDuplex100
|
||||
};
|
||||
|
||||
/** Writes into an outgoing ethernet packet.
|
||||
*
|
||||
* It will append size bytes of data to the previously written bytes.
|
||||
*
|
||||
* @param data An array to write.
|
||||
* @param size The size of data.
|
||||
*
|
||||
* @returns
|
||||
* The number of written bytes.
|
||||
*/
|
||||
int write(const char *data, int size);
|
||||
|
||||
/** Send an outgoing ethernet packet.
|
||||
*
|
||||
* After filling in the data in an ethernet packet it must be send.
|
||||
* Send will provide a new packet to write to.
|
||||
*
|
||||
* @returns
|
||||
* 0 if the sending was failed,
|
||||
* or the size of the packet successfully sent.
|
||||
*/
|
||||
int send();
|
||||
|
||||
/** Recevies an arrived ethernet packet.
|
||||
*
|
||||
* Receiving an ethernet packet will drop the last received ethernet packet
|
||||
* and make a new ethernet packet ready to read.
|
||||
* If no ethernet packet is arrived it will return 0.
|
||||
*
|
||||
* @returns
|
||||
* 0 if no ethernet packet is arrived,
|
||||
* or the size of the arrived packet.
|
||||
*/
|
||||
int receive();
|
||||
|
||||
/** Read from an recevied ethernet packet.
|
||||
*
|
||||
* After receive returnd a number bigger than 0it is
|
||||
* possible to read bytes from this packet.
|
||||
* Read will write up to size bytes into data.
|
||||
*
|
||||
* It is possible to use read multible times.
|
||||
* Each time read will start reading after the last read byte before.
|
||||
*
|
||||
* @returns
|
||||
* The number of byte read.
|
||||
*/
|
||||
int read(char *data, int size);
|
||||
|
||||
/** Gives the ethernet address of the mbed.
|
||||
*
|
||||
* @param mac Must be a pointer to a 6 byte char array to copy the ethernet address in.
|
||||
*/
|
||||
void address(char *mac);
|
||||
|
||||
/** Returns if an ethernet link is pressent or not. It takes a wile after Ethernet initializion to show up.
|
||||
*
|
||||
* @returns
|
||||
* 0 if no ethernet link is pressent,
|
||||
* 1 if an ethernet link is pressent.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Using the Ethernet link function
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ethernet eth;
|
||||
*
|
||||
* int main() {
|
||||
* wait(1); // Needed after startup.
|
||||
* if (eth.link()) {
|
||||
* printf("online\n");
|
||||
* } else {
|
||||
* printf("offline\n");
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
int link();
|
||||
|
||||
/** Sets the speed and duplex parameters of an ethernet link
|
||||
*
|
||||
* - AutoNegotiate Auto negotiate speed and duplex
|
||||
* - HalfDuplex10 10 Mbit, half duplex
|
||||
* - FullDuplex10 10 Mbit, full duplex
|
||||
* - HalfDuplex100 100 Mbit, half duplex
|
||||
* - FullDuplex100 100 Mbit, full duplex
|
||||
*
|
||||
* @param mode the speed and duplex mode to set the link to:
|
||||
*/
|
||||
void set_link(Mode mode);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,80 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FILEBASE_H
|
||||
#define MBED_FILEBASE_H
|
||||
|
||||
typedef int FILEHANDLE;
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
|
||||
# define O_RDONLY 0
|
||||
# define O_WRONLY 1
|
||||
# define O_RDWR 2
|
||||
# define O_CREAT 0x0200
|
||||
# define O_TRUNC 0x0400
|
||||
# define O_APPEND 0x0008
|
||||
|
||||
# define NAME_MAX 255
|
||||
|
||||
typedef int mode_t;
|
||||
typedef int ssize_t;
|
||||
typedef long off_t;
|
||||
|
||||
#else
|
||||
# include <sys/fcntl.h>
|
||||
# include <sys/types.h>
|
||||
# include <sys/syslimits.h>
|
||||
#endif
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
typedef enum {
|
||||
FilePathType,
|
||||
FileSystemPathType
|
||||
} PathType;
|
||||
|
||||
class FileBase {
|
||||
public:
|
||||
FileBase(const char *name, PathType t);
|
||||
|
||||
virtual ~FileBase();
|
||||
|
||||
const char* getName(void);
|
||||
PathType getPathType(void);
|
||||
|
||||
static FileBase *lookup(const char *name, unsigned int len);
|
||||
|
||||
static FileBase *get(int n);
|
||||
|
||||
protected:
|
||||
static FileBase *_head;
|
||||
|
||||
FileBase *_next;
|
||||
const char *_name;
|
||||
PathType _path_type;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
FileBase(const FileBase&);
|
||||
FileBase & operator = (const FileBase&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,119 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FILEHANDLE_H
|
||||
#define MBED_FILEHANDLE_H
|
||||
|
||||
typedef int FILEHANDLE;
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#if defined(__ARMCC_VERSION) || defined(__ICCARM__)
|
||||
typedef int ssize_t;
|
||||
typedef long off_t;
|
||||
|
||||
#else
|
||||
# include <sys/types.h>
|
||||
#endif
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An OO equivalent of the internal FILEHANDLE variable
|
||||
* and associated _sys_* functions.
|
||||
*
|
||||
* FileHandle is an abstract class, needing at least sys_write and
|
||||
* sys_read to be implmented for a simple interactive device.
|
||||
*
|
||||
* No one ever directly tals to/instanciates a FileHandle - it gets
|
||||
* created by FileSystem, and wrapped up by stdio.
|
||||
*/
|
||||
class FileHandle {
|
||||
|
||||
public:
|
||||
/** Write the contents of a buffer to the file
|
||||
*
|
||||
* @param buffer the buffer to write from
|
||||
* @param length the number of characters to write
|
||||
*
|
||||
* @returns
|
||||
* The number of characters written (possibly 0) on success, -1 on error.
|
||||
*/
|
||||
virtual ssize_t write(const void* buffer, size_t length) = 0;
|
||||
|
||||
/** Close the file
|
||||
*
|
||||
* @returns
|
||||
* Zero on success, -1 on error.
|
||||
*/
|
||||
virtual int close() = 0;
|
||||
|
||||
/** Function read
|
||||
* Reads the contents of the file into a buffer
|
||||
*
|
||||
* @param buffer the buffer to read in to
|
||||
* @param length the number of characters to read
|
||||
*
|
||||
* @returns
|
||||
* The number of characters read (zero at end of file) on success, -1 on error.
|
||||
*/
|
||||
virtual ssize_t read(void* buffer, size_t length) = 0;
|
||||
|
||||
/** Check if the handle is for a interactive terminal device.
|
||||
* If so, line buffered behaviour is used by default
|
||||
*
|
||||
* @returns
|
||||
* 1 if it is a terminal,
|
||||
* 0 otherwise
|
||||
*/
|
||||
virtual int isatty() = 0;
|
||||
|
||||
/** Move the file position to a given offset from a given location.
|
||||
*
|
||||
* @param offset The offset from whence to move to
|
||||
* @param whence SEEK_SET for the start of the file, SEEK_CUR for the
|
||||
* current file position, or SEEK_END for the end of the file.
|
||||
*
|
||||
* @returns
|
||||
* new file position on success,
|
||||
* -1 on failure or unsupported
|
||||
*/
|
||||
virtual off_t lseek(off_t offset, int whence) = 0;
|
||||
|
||||
/** Flush any buffers associated with the FileHandle, ensuring it
|
||||
* is up to date on disk
|
||||
*
|
||||
* @returns
|
||||
* 0 on success or un-needed,
|
||||
* -1 on error
|
||||
*/
|
||||
virtual int fsync() = 0;
|
||||
|
||||
virtual off_t flen() {
|
||||
/* remember our current position */
|
||||
off_t pos = lseek(0, SEEK_CUR);
|
||||
if(pos == -1) return -1;
|
||||
/* seek to the end to get the file length */
|
||||
off_t res = lseek(0, SEEK_END);
|
||||
/* return to our old position */
|
||||
lseek(pos, SEEK_SET);
|
||||
return res;
|
||||
}
|
||||
|
||||
virtual ~FileHandle();
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FILELIKE_H
|
||||
#define MBED_FILELIKE_H
|
||||
|
||||
#include "FileBase.h"
|
||||
#include "FileHandle.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/* Class FileLike
|
||||
* A file-like object is one that can be opened with fopen by
|
||||
* fopen("/name", mode). It is intersection of the classes Base and
|
||||
* FileHandle.
|
||||
*/
|
||||
class FileLike : public FileHandle, public FileBase {
|
||||
|
||||
public:
|
||||
/* Constructor FileLike
|
||||
*
|
||||
* Variables
|
||||
* name - The name to use to open the file.
|
||||
*/
|
||||
FileLike(const char *name);
|
||||
|
||||
virtual ~FileLike();
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,46 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FILEPATH_H
|
||||
#define MBED_FILEPATH_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "FileSystemLike.h"
|
||||
#include "FileLike.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class FilePath {
|
||||
public:
|
||||
FilePath(const char* file_path);
|
||||
|
||||
const char* fileName(void);
|
||||
|
||||
bool isFileSystem(void);
|
||||
FileSystemLike* fileSystem(void);
|
||||
|
||||
bool isFile(void);
|
||||
FileLike* file(void);
|
||||
bool exists(void);
|
||||
|
||||
private:
|
||||
const char* file_name;
|
||||
FileBase* fb;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,104 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FILESYSTEMLIKE_H
|
||||
#define MBED_FILESYSTEMLIKE_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#include "FileBase.h"
|
||||
#include "FileHandle.h"
|
||||
#include "DirHandle.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A filesystem-like object is one that can be used to open files
|
||||
* though it by fopen("/name/filename", mode)
|
||||
*
|
||||
* Implementations must define at least open (the default definitions
|
||||
* of the rest of the functions just return error values).
|
||||
*/
|
||||
class FileSystemLike : public FileBase {
|
||||
|
||||
public:
|
||||
/** FileSystemLike constructor
|
||||
*
|
||||
* @param name The name to use for the filesystem.
|
||||
*/
|
||||
FileSystemLike(const char *name);
|
||||
|
||||
virtual ~FileSystemLike();
|
||||
|
||||
static DirHandle *opendir();
|
||||
friend class BaseDirHandle;
|
||||
|
||||
/** Opens a file from the filesystem
|
||||
*
|
||||
* @param filename The name of the file to open.
|
||||
* @param flags One of O_RDONLY, O_WRONLY, or O_RDWR, OR'd with
|
||||
* zero or more of O_CREAT, O_TRUNC, or O_APPEND.
|
||||
*
|
||||
* @returns
|
||||
* A pointer to a FileHandle object representing the
|
||||
* file on success, or NULL on failure.
|
||||
*/
|
||||
virtual FileHandle *open(const char *filename, int flags) = 0;
|
||||
|
||||
/** Remove a file from the filesystem.
|
||||
*
|
||||
* @param filename the name of the file to remove.
|
||||
* @param returns 0 on success, -1 on failure.
|
||||
*/
|
||||
virtual int remove(const char *filename) { return -1; };
|
||||
|
||||
/** Rename a file in the filesystem.
|
||||
*
|
||||
* @param oldname the name of the file to rename.
|
||||
* @param newname the name to rename it to.
|
||||
*
|
||||
* @returns
|
||||
* 0 on success,
|
||||
* -1 on failure.
|
||||
*/
|
||||
virtual int rename(const char *oldname, const char *newname) { return -1; };
|
||||
|
||||
/** Opens a directory in the filesystem and returns a DirHandle
|
||||
* representing the directory stream.
|
||||
*
|
||||
* @param name The name of the directory to open.
|
||||
*
|
||||
* @returns
|
||||
* A DirHandle representing the directory stream, or
|
||||
* NULL on failure.
|
||||
*/
|
||||
virtual DirHandle *opendir(const char *name) { return NULL; };
|
||||
|
||||
/** Creates a directory in the filesystem.
|
||||
*
|
||||
* @param name The name of the directory to create.
|
||||
* @param mode The permissions to create the directory with.
|
||||
*
|
||||
* @returns
|
||||
* 0 on success,
|
||||
* -1 on failure.
|
||||
*/
|
||||
virtual int mkdir(const char *name, mode_t mode) { return -1; }
|
||||
|
||||
// TODO other filesystem functions (mkdir, rm, rn, ls etc)
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,64 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_FUNCTIONPOINTER_H
|
||||
#define MBED_FUNCTIONPOINTER_H
|
||||
|
||||
#include "Callback.h"
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
|
||||
// Declarations for backwards compatibility
|
||||
// To be foward compatible, code should adopt the Callback class
|
||||
template <typename R, typename A1>
|
||||
class FunctionPointerArg1 : public Callback<R(A1)> {
|
||||
public:
|
||||
FunctionPointerArg1(R (*function)(A1) = 0)
|
||||
: Callback<R(A1)>(function) {}
|
||||
|
||||
template<typename T>
|
||||
FunctionPointerArg1(T *object, R (T::*member)(A1))
|
||||
: Callback<R(A1)>(object, member) {}
|
||||
|
||||
R (*get_function())(A1) {
|
||||
return *reinterpret_cast<R (**)(A1)>(this);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename R>
|
||||
class FunctionPointerArg1<R, void> : public Callback<R()> {
|
||||
public:
|
||||
FunctionPointerArg1(R (*function)() = 0)
|
||||
: Callback<R()>(function) {}
|
||||
|
||||
template<typename T>
|
||||
FunctionPointerArg1(T *object, R (T::*member)())
|
||||
: Callback<R()>(object, member) {}
|
||||
|
||||
R (*get_function())() {
|
||||
return *reinterpret_cast<R (**)()>(this);
|
||||
}
|
||||
};
|
||||
|
||||
typedef FunctionPointerArg1<void, void> FunctionPointer;
|
||||
typedef FunctionPointerArg1<void, int> event_callback_t;
|
||||
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
176
hal/api/I2C.h
176
hal/api/I2C.h
|
@ -1,176 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_I2C_H
|
||||
#define MBED_I2C_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_I2C
|
||||
|
||||
#include "i2c_api.h"
|
||||
|
||||
#if DEVICE_I2C_ASYNCH
|
||||
#include "CThunk.h"
|
||||
#include "dma_api.h"
|
||||
#include "FunctionPointer.h"
|
||||
#endif
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An I2C Master, used for communicating with I2C slave devices
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Read from I2C slave at address 0x62
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* I2C i2c(p28, p27);
|
||||
*
|
||||
* int main() {
|
||||
* int address = 0x62;
|
||||
* char data[2];
|
||||
* i2c.read(address, data, 2);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class I2C {
|
||||
|
||||
public:
|
||||
enum RxStatus {
|
||||
NoData,
|
||||
MasterGeneralCall,
|
||||
MasterWrite,
|
||||
MasterRead
|
||||
};
|
||||
|
||||
enum Acknowledge {
|
||||
NoACK = 0,
|
||||
ACK = 1
|
||||
};
|
||||
|
||||
/** Create an I2C Master interface, connected to the specified pins
|
||||
*
|
||||
* @param sda I2C data line pin
|
||||
* @param scl I2C clock line pin
|
||||
*/
|
||||
I2C(PinName sda, PinName scl);
|
||||
|
||||
/** Set the frequency of the I2C interface
|
||||
*
|
||||
* @param hz The bus frequency in hertz
|
||||
*/
|
||||
void frequency(int hz);
|
||||
|
||||
/** Read from an I2C slave
|
||||
*
|
||||
* Performs a complete read transaction. The bottom bit of
|
||||
* the address is forced to 1 to indicate a read.
|
||||
*
|
||||
* @param address 8-bit I2C slave address [ addr | 1 ]
|
||||
* @param data Pointer to the byte-array to read data in to
|
||||
* @param length Number of bytes to read
|
||||
* @param repeated Repeated start, true - don't send stop at end
|
||||
*
|
||||
* @returns
|
||||
* 0 on success (ack),
|
||||
* non-0 on failure (nack)
|
||||
*/
|
||||
int read(int address, char *data, int length, bool repeated = false);
|
||||
|
||||
/** Read a single byte from the I2C bus
|
||||
*
|
||||
* @param ack indicates if the byte is to be acknowledged (1 = acknowledge)
|
||||
*
|
||||
* @returns
|
||||
* the byte read
|
||||
*/
|
||||
int read(int ack);
|
||||
|
||||
/** Write to an I2C slave
|
||||
*
|
||||
* Performs a complete write transaction. The bottom bit of
|
||||
* the address is forced to 0 to indicate a write.
|
||||
*
|
||||
* @param address 8-bit I2C slave address [ addr | 0 ]
|
||||
* @param data Pointer to the byte-array data to send
|
||||
* @param length Number of bytes to send
|
||||
* @param repeated Repeated start, true - do not send stop at end
|
||||
*
|
||||
* @returns
|
||||
* 0 on success (ack),
|
||||
* non-0 on failure (nack)
|
||||
*/
|
||||
int write(int address, const char *data, int length, bool repeated = false);
|
||||
|
||||
/** Write single byte out on the I2C bus
|
||||
*
|
||||
* @param data data to write out on bus
|
||||
*
|
||||
* @returns
|
||||
* '1' if an ACK was received,
|
||||
* '0' otherwise
|
||||
*/
|
||||
int write(int data);
|
||||
|
||||
/** Creates a start condition on the I2C bus
|
||||
*/
|
||||
|
||||
void start(void);
|
||||
|
||||
/** Creates a stop condition on the I2C bus
|
||||
*/
|
||||
void stop(void);
|
||||
|
||||
#if DEVICE_I2C_ASYNCH
|
||||
|
||||
/** Start non-blocking I2C transfer.
|
||||
*
|
||||
* @param address 8/10 bit I2c slave address
|
||||
* @param tx_buffer The TX buffer with data to be transfered
|
||||
* @param tx_length The length of TX buffer in bytes
|
||||
* @param rx_buffer The RX buffer which is used for received data
|
||||
* @param rx_length The length of RX buffer in bytes
|
||||
* @param event The logical OR of events to modify
|
||||
* @param callback The event callback function
|
||||
* @param repeated Repeated start, true - do not send stop at end
|
||||
* @return Zero if the transfer has started, or -1 if I2C peripheral is busy
|
||||
*/
|
||||
int transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event = I2C_EVENT_TRANSFER_COMPLETE, bool repeated = false);
|
||||
|
||||
/** Abort the on-going I2C transfer
|
||||
*/
|
||||
void abort_transfer();
|
||||
protected:
|
||||
void irq_handler_asynch(void);
|
||||
event_callback_t _callback;
|
||||
CThunk<I2C> _irq;
|
||||
DMAUsage _usage;
|
||||
#endif
|
||||
|
||||
protected:
|
||||
void aquire();
|
||||
|
||||
i2c_t _i2c;
|
||||
static I2C *_owner;
|
||||
int _hz;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,154 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_I2C_SLAVE_H
|
||||
#define MBED_I2C_SLAVE_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
|
||||
#include "i2c_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** An I2C Slave, used for communicating with an I2C Master device
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Simple I2C responder
|
||||
* #include <mbed.h>
|
||||
*
|
||||
* I2CSlave slave(p9, p10);
|
||||
*
|
||||
* int main() {
|
||||
* char buf[10];
|
||||
* char msg[] = "Slave!";
|
||||
*
|
||||
* slave.address(0xA0);
|
||||
* while (1) {
|
||||
* int i = slave.receive();
|
||||
* switch (i) {
|
||||
* case I2CSlave::ReadAddressed:
|
||||
* slave.write(msg, strlen(msg) + 1); // Includes null char
|
||||
* break;
|
||||
* case I2CSlave::WriteGeneral:
|
||||
* slave.read(buf, 10);
|
||||
* printf("Read G: %s\n", buf);
|
||||
* break;
|
||||
* case I2CSlave::WriteAddressed:
|
||||
* slave.read(buf, 10);
|
||||
* printf("Read A: %s\n", buf);
|
||||
* break;
|
||||
* }
|
||||
* for(int i = 0; i < 10; i++) buf[i] = 0; // Clear buffer
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class I2CSlave {
|
||||
|
||||
public:
|
||||
enum RxStatus {
|
||||
NoData = 0,
|
||||
ReadAddressed = 1,
|
||||
WriteGeneral = 2,
|
||||
WriteAddressed = 3
|
||||
};
|
||||
|
||||
/** Create an I2C Slave interface, connected to the specified pins.
|
||||
*
|
||||
* @param sda I2C data line pin
|
||||
* @param scl I2C clock line pin
|
||||
*/
|
||||
I2CSlave(PinName sda, PinName scl);
|
||||
|
||||
/** Set the frequency of the I2C interface
|
||||
*
|
||||
* @param hz The bus frequency in hertz
|
||||
*/
|
||||
void frequency(int hz);
|
||||
|
||||
/** Checks to see if this I2C Slave has been addressed.
|
||||
*
|
||||
* @returns
|
||||
* A status indicating if the device has been addressed, and how
|
||||
* - NoData - the slave has not been addressed
|
||||
* - ReadAddressed - the master has requested a read from this slave
|
||||
* - WriteAddressed - the master is writing to this slave
|
||||
* - WriteGeneral - the master is writing to all slave
|
||||
*/
|
||||
int receive(void);
|
||||
|
||||
/** Read from an I2C master.
|
||||
*
|
||||
* @param data pointer to the byte array to read data in to
|
||||
* @param length maximum number of bytes to read
|
||||
*
|
||||
* @returns
|
||||
* 0 on success,
|
||||
* non-0 otherwise
|
||||
*/
|
||||
int read(char *data, int length);
|
||||
|
||||
/** Read a single byte from an I2C master.
|
||||
*
|
||||
* @returns
|
||||
* the byte read
|
||||
*/
|
||||
int read(void);
|
||||
|
||||
/** Write to an I2C master.
|
||||
*
|
||||
* @param data pointer to the byte array to be transmitted
|
||||
* @param length the number of bytes to transmite
|
||||
*
|
||||
* @returns
|
||||
* 0 on success,
|
||||
* non-0 otherwise
|
||||
*/
|
||||
int write(const char *data, int length);
|
||||
|
||||
/** Write a single byte to an I2C master.
|
||||
*
|
||||
* @data the byte to write
|
||||
*
|
||||
* @returns
|
||||
* '1' if an ACK was received,
|
||||
* '0' otherwise
|
||||
*/
|
||||
int write(int data);
|
||||
|
||||
/** Sets the I2C slave address.
|
||||
*
|
||||
* @param address The address to set for the slave (ignoring the least
|
||||
* signifcant bit). If set to 0, the slave will only respond to the
|
||||
* general call address.
|
||||
*/
|
||||
void address(int address);
|
||||
|
||||
/** Reset the I2C slave back into the known ready receiving state.
|
||||
*/
|
||||
void stop(void);
|
||||
|
||||
protected:
|
||||
i2c_t _i2c;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,133 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_INTERRUPTIN_H
|
||||
#define MBED_INTERRUPTIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
#include "gpio_api.h"
|
||||
#include "gpio_irq_api.h"
|
||||
#include "Callback.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A digital interrupt input, used to call a function on a rising or falling edge
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Flash an LED while waiting for events
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* InterruptIn event(p16);
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* void trigger() {
|
||||
* printf("triggered!\n");
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* event.rise(&trigger);
|
||||
* while(1) {
|
||||
* led = !led;
|
||||
* wait(0.25);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class InterruptIn {
|
||||
|
||||
public:
|
||||
|
||||
/** Create an InterruptIn connected to the specified pin
|
||||
*
|
||||
* @param pin InterruptIn pin to connect to
|
||||
* @param name (optional) A string to identify the object
|
||||
*/
|
||||
InterruptIn(PinName pin);
|
||||
virtual ~InterruptIn();
|
||||
|
||||
int read();
|
||||
#ifdef MBED_OPERATORS
|
||||
operator int();
|
||||
|
||||
#endif
|
||||
|
||||
/** Attach a function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param func A pointer to a void function, or 0 to set as none
|
||||
*/
|
||||
void rise(Callback<void()> func);
|
||||
|
||||
/** Attach a member function to call when a rising edge occurs on the input
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
void rise(T *obj, M method) {
|
||||
rise(Callback<void()>(obj, method));
|
||||
}
|
||||
|
||||
/** Attach a function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param func A pointer to a void function, or 0 to set as none
|
||||
*/
|
||||
void fall(Callback<void()> func);
|
||||
|
||||
/** Attach a member function to call when a falling edge occurs on the input
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
void fall(T *obj, M method) {
|
||||
fall(Callback<void()>(obj, method));
|
||||
}
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone
|
||||
*/
|
||||
void mode(PinMode pull);
|
||||
|
||||
/** Enable IRQ. This method depends on hw implementation, might enable one
|
||||
* port interrupts. For further information, check gpio_irq_enable().
|
||||
*/
|
||||
void enable_irq();
|
||||
|
||||
/** Disable IRQ. This method depends on hw implementation, might disable one
|
||||
* port interrupts. For further information, check gpio_irq_disable().
|
||||
*/
|
||||
void disable_irq();
|
||||
|
||||
static void _irq_handler(uint32_t id, gpio_irq_event event);
|
||||
|
||||
protected:
|
||||
gpio_t gpio;
|
||||
gpio_irq_t gpio_irq;
|
||||
|
||||
Callback<void()> _rise;
|
||||
Callback<void()> _fall;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,143 +0,0 @@
|
|||
#ifndef MBED_INTERRUPTMANAGER_H
|
||||
#define MBED_INTERRUPTMANAGER_H
|
||||
|
||||
#include "cmsis.h"
|
||||
#include "CallChain.h"
|
||||
#include <string.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Use this singleton if you need to chain interrupt handlers.
|
||||
*
|
||||
* Example (for LPC1768):
|
||||
* @code
|
||||
* #include "InterruptManager.h"
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ticker flipper;
|
||||
* DigitalOut led1(LED1);
|
||||
* DigitalOut led2(LED2);
|
||||
*
|
||||
* void flip(void) {
|
||||
* led1 = !led1;
|
||||
* }
|
||||
*
|
||||
* void handler(void) {
|
||||
* led2 = !led1;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* led1 = led2 = 0;
|
||||
* flipper.attach(&flip, 1.0);
|
||||
* InterruptManager::get()->add_handler(handler, TIMER3_IRQn);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class InterruptManager {
|
||||
public:
|
||||
/** Return the only instance of this class
|
||||
*/
|
||||
static InterruptManager* get();
|
||||
|
||||
/** Destroy the current instance of the interrupt manager
|
||||
*/
|
||||
static void destroy();
|
||||
|
||||
/** Add a handler for an interrupt at the end of the handler list
|
||||
*
|
||||
* @param function the handler to add
|
||||
* @param irq interrupt number
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'function'
|
||||
*/
|
||||
pFunctionPointer_t add_handler(void (*function)(void), IRQn_Type irq) {
|
||||
return add_common(function, irq);
|
||||
}
|
||||
|
||||
/** Add a handler for an interrupt at the beginning of the handler list
|
||||
*
|
||||
* @param function the handler to add
|
||||
* @param irq interrupt number
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'function'
|
||||
*/
|
||||
pFunctionPointer_t add_handler_front(void (*function)(void), IRQn_Type irq) {
|
||||
return add_common(function, irq, true);
|
||||
}
|
||||
|
||||
/** Add a handler for an interrupt at the end of the handler list
|
||||
*
|
||||
* @param tptr pointer to the object that has the handler function
|
||||
* @param mptr pointer to the actual handler function
|
||||
* @param irq interrupt number
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
|
||||
return add_common(tptr, mptr, irq);
|
||||
}
|
||||
|
||||
/** Add a handler for an interrupt at the beginning of the handler list
|
||||
*
|
||||
* @param tptr pointer to the object that has the handler function
|
||||
* @param mptr pointer to the actual handler function
|
||||
* @param irq interrupt number
|
||||
*
|
||||
* @returns
|
||||
* The function object created for 'tptr' and 'mptr'
|
||||
*/
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IRQn_Type irq) {
|
||||
return add_common(tptr, mptr, irq, true);
|
||||
}
|
||||
|
||||
/** Remove a handler from an interrupt
|
||||
*
|
||||
* @param handler the function object for the handler to remove
|
||||
* @param irq the interrupt number
|
||||
*
|
||||
* @returns
|
||||
* true if the handler was found and removed, false otherwise
|
||||
*/
|
||||
bool remove_handler(pFunctionPointer_t handler, IRQn_Type irq);
|
||||
|
||||
private:
|
||||
InterruptManager();
|
||||
~InterruptManager();
|
||||
|
||||
// We declare the copy contructor and the assignment operator, but we don't
|
||||
// implement them. This way, if someone tries to copy/assign our instance,
|
||||
// he will get an error at compile time.
|
||||
InterruptManager(const InterruptManager&);
|
||||
InterruptManager& operator =(const InterruptManager&);
|
||||
|
||||
template<typename T>
|
||||
pFunctionPointer_t add_common(T *tptr, void (T::*mptr)(void), IRQn_Type irq, bool front=false) {
|
||||
int irq_pos = get_irq_index(irq);
|
||||
bool change = must_replace_vector(irq);
|
||||
|
||||
pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(tptr, mptr) : _chains[irq_pos]->add(tptr, mptr);
|
||||
if (change)
|
||||
NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
|
||||
return pf;
|
||||
}
|
||||
|
||||
pFunctionPointer_t add_common(void (*function)(void), IRQn_Type irq, bool front=false);
|
||||
bool must_replace_vector(IRQn_Type irq);
|
||||
int get_irq_index(IRQn_Type irq);
|
||||
void irq_helper();
|
||||
void add_helper(void (*function)(void), IRQn_Type irq, bool front=false);
|
||||
static void static_irq_helper();
|
||||
|
||||
CallChain* _chains[NVIC_NUM_VECTORS];
|
||||
static InterruptManager* _instance;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
|
@ -1,103 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_LOCALFILESYSTEM_H
|
||||
#define MBED_LOCALFILESYSTEM_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_LOCALFILESYSTEM
|
||||
|
||||
#include "FileSystemLike.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FILEHANDLE local_file_open(const char* name, int flags);
|
||||
|
||||
class LocalFileHandle : public FileHandle {
|
||||
|
||||
public:
|
||||
LocalFileHandle(FILEHANDLE fh);
|
||||
|
||||
virtual int close();
|
||||
|
||||
virtual ssize_t write(const void *buffer, size_t length);
|
||||
|
||||
virtual ssize_t read(void *buffer, size_t length);
|
||||
|
||||
virtual int isatty();
|
||||
|
||||
virtual off_t lseek(off_t position, int whence);
|
||||
|
||||
virtual int fsync();
|
||||
|
||||
virtual off_t flen();
|
||||
|
||||
protected:
|
||||
FILEHANDLE _fh;
|
||||
int pos;
|
||||
};
|
||||
|
||||
/** A filesystem for accessing the local mbed Microcontroller USB disk drive
|
||||
*
|
||||
* This allows programs to read and write files on the same disk drive that is used to program the
|
||||
* mbed Microcontroller. Once created, the standard C file access functions are used to open,
|
||||
* read and write files.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* LocalFileSystem local("local"); // Create the local filesystem under the name "local"
|
||||
*
|
||||
* int main() {
|
||||
* FILE *fp = fopen("/local/out.txt", "w"); // Open "out.txt" on the local file system for writing
|
||||
* fprintf(fp, "Hello World!");
|
||||
* fclose(fp);
|
||||
* remove("/local/out.txt"); // Removes the file "out.txt" from the local file system
|
||||
*
|
||||
* DIR *d = opendir("/local"); // Opens the root directory of the local file system
|
||||
* struct dirent *p;
|
||||
* while((p = readdir(d)) != NULL) { // Print the names of the files in the local file system
|
||||
* printf("%s\n", p->d_name); // to stdout.
|
||||
* }
|
||||
* closedir(d);
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @note
|
||||
* If the microcontroller program makes an access to the local drive, it will be marked as "removed"
|
||||
* on the Host computer. This means it is no longer accessible from the Host Computer.
|
||||
*
|
||||
* The drive will only re-appear when the microcontroller program exists. Note that if the program does
|
||||
* not exit, you will need to hold down reset on the mbed Microcontroller to be able to see the drive again!
|
||||
*/
|
||||
class LocalFileSystem : public FileSystemLike {
|
||||
|
||||
public:
|
||||
LocalFileSystem(const char* n) : FileSystemLike(n) {
|
||||
|
||||
}
|
||||
|
||||
virtual FileHandle *open(const char* name, int flags);
|
||||
virtual int remove(const char *filename);
|
||||
virtual DirHandle *opendir(const char *name);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,44 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_LOWPOWERTICKER_H
|
||||
#define MBED_LOWPOWERTICKER_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "Ticker.h"
|
||||
|
||||
#if DEVICE_LOWPOWERTIMER
|
||||
|
||||
#include "lp_ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Low Power Ticker
|
||||
*/
|
||||
class LowPowerTicker : public Ticker {
|
||||
|
||||
public:
|
||||
LowPowerTicker() : Ticker(get_lp_ticker_data()) {
|
||||
}
|
||||
|
||||
virtual ~LowPowerTicker() {
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_LOWPOWERTIMEOUT_H
|
||||
#define MBED_LOWPOWERTIMEOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_LOWPOWERTIMER
|
||||
|
||||
#include "lp_ticker_api.h"
|
||||
#include "LowPowerTicker.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Low Power Timout
|
||||
*/
|
||||
class LowPowerTimeout : public LowPowerTicker {
|
||||
|
||||
private:
|
||||
virtual void handler(void) {
|
||||
_function.call();
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,42 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_LOWPOWERTIMER_H
|
||||
#define MBED_LOWPOWERTIMER_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "Timer.h"
|
||||
|
||||
#if DEVICE_LOWPOWERTIMER
|
||||
|
||||
#include "lp_ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Low power timer
|
||||
*/
|
||||
class LowPowerTimer : public Timer {
|
||||
|
||||
public:
|
||||
LowPowerTimer() : Timer(get_lp_ticker_data()) {
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,93 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PORTIN_H
|
||||
#define MBED_PORTIN_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_PORTIN
|
||||
|
||||
#include "port_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A multiple pin digital input
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Switch on an LED if any of mbed pins 21-26 is high
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* PortIn p(Port2, 0x0000003F); // p21-p26
|
||||
* DigitalOut ind(LED4);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* int pins = p.read();
|
||||
* if(pins) {
|
||||
* ind = 1;
|
||||
* } else {
|
||||
* ind = 0;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class PortIn {
|
||||
public:
|
||||
|
||||
/** Create an PortIn, connected to the specified port
|
||||
*
|
||||
* @param port Port to connect to (Port0-Port5)
|
||||
* @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
|
||||
*/
|
||||
PortIn(PortName port, int mask = 0xFFFFFFFF) {
|
||||
port_init(&_port, port, mask, PIN_INPUT);
|
||||
}
|
||||
|
||||
/** Read the value currently output on the port
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to associated port pin setting
|
||||
*/
|
||||
int read() {
|
||||
return port_read(&_port);
|
||||
}
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone, OpenDrain
|
||||
*/
|
||||
void mode(PinMode mode) {
|
||||
port_mode(&_port, mode);
|
||||
}
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
|
||||
private:
|
||||
port_t _port;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,104 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PORTINOUT_H
|
||||
#define MBED_PORTINOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_PORTINOUT
|
||||
|
||||
#include "port_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A multiple pin digital in/out used to set/read multiple bi-directional pins
|
||||
*/
|
||||
class PortInOut {
|
||||
public:
|
||||
|
||||
/** Create an PortInOut, connected to the specified port
|
||||
*
|
||||
* @param port Port to connect to (Port0-Port5)
|
||||
* @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
|
||||
*/
|
||||
PortInOut(PortName port, int mask = 0xFFFFFFFF) {
|
||||
port_init(&_port, port, mask, PIN_INPUT);
|
||||
}
|
||||
|
||||
/** Write the value to the output port
|
||||
*
|
||||
* @param value An integer specifying a bit to write for every corresponding port pin
|
||||
*/
|
||||
void write(int value) {
|
||||
port_write(&_port, value);
|
||||
}
|
||||
|
||||
/** Read the value currently output on the port
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to associated port pin setting
|
||||
*/
|
||||
int read() {
|
||||
return port_read(&_port);
|
||||
}
|
||||
|
||||
/** Set as an output
|
||||
*/
|
||||
void output() {
|
||||
port_dir(&_port, PIN_OUTPUT);
|
||||
}
|
||||
|
||||
/** Set as an input
|
||||
*/
|
||||
void input() {
|
||||
port_dir(&_port, PIN_INPUT);
|
||||
}
|
||||
|
||||
/** Set the input pin mode
|
||||
*
|
||||
* @param mode PullUp, PullDown, PullNone, OpenDrain
|
||||
*/
|
||||
void mode(PinMode mode) {
|
||||
port_mode(&_port, mode);
|
||||
}
|
||||
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
PortInOut& operator= (int value) {
|
||||
write(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PortInOut& operator= (PortInOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
|
||||
private:
|
||||
port_t _port;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,104 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PORTOUT_H
|
||||
#define MBED_PORTOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_PORTOUT
|
||||
|
||||
#include "port_api.h"
|
||||
|
||||
namespace mbed {
|
||||
/** A multiple pin digital out
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Toggle all four LEDs
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* // LED1 = P1.18 LED2 = P1.20 LED3 = P1.21 LED4 = P1.23
|
||||
* #define LED_MASK 0x00B40000
|
||||
*
|
||||
* PortOut ledport(Port1, LED_MASK);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* ledport = LED_MASK;
|
||||
* wait(1);
|
||||
* ledport = 0;
|
||||
* wait(1);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class PortOut {
|
||||
public:
|
||||
|
||||
/** Create an PortOut, connected to the specified port
|
||||
*
|
||||
* @param port Port to connect to (Port0-Port5)
|
||||
* @param mask A bitmask to identify which bits in the port should be included (0 - ignore)
|
||||
*/
|
||||
PortOut(PortName port, int mask = 0xFFFFFFFF) {
|
||||
port_init(&_port, port, mask, PIN_OUTPUT);
|
||||
}
|
||||
|
||||
/** Write the value to the output port
|
||||
*
|
||||
* @param value An integer specifying a bit to write for every corresponding PortOut pin
|
||||
*/
|
||||
void write(int value) {
|
||||
port_write(&_port, value);
|
||||
}
|
||||
|
||||
/** Read the value currently output on the port
|
||||
*
|
||||
* @returns
|
||||
* An integer with each bit corresponding to associated PortOut pin setting
|
||||
*/
|
||||
int read() {
|
||||
return port_read(&_port);
|
||||
}
|
||||
|
||||
/** A shorthand for write()
|
||||
*/
|
||||
PortOut& operator= (int value) {
|
||||
write(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PortOut& operator= (PortOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** A shorthand for read()
|
||||
*/
|
||||
operator int() {
|
||||
return read();
|
||||
}
|
||||
|
||||
private:
|
||||
port_t _port;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
158
hal/api/PwmOut.h
158
hal/api/PwmOut.h
|
@ -1,158 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PWMOUT_H
|
||||
#define MBED_PWMOUT_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_PWMOUT
|
||||
#include "pwmout_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A pulse-width modulation digital output
|
||||
*
|
||||
* Example
|
||||
* @code
|
||||
* // Fade a led on.
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* PwmOut led(LED1);
|
||||
*
|
||||
* int main() {
|
||||
* while(1) {
|
||||
* led = led + 0.01;
|
||||
* wait(0.2);
|
||||
* if(led == 1.0) {
|
||||
* led = 0;
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*
|
||||
* @note
|
||||
* On the LPC1768 and LPC2368, the PWMs all share the same
|
||||
* period - if you change the period for one, you change it for all.
|
||||
* Although routines that change the period maintain the duty cycle
|
||||
* for its PWM, all other PWMs will require their duty cycle to be
|
||||
* refreshed.
|
||||
*/
|
||||
class PwmOut {
|
||||
|
||||
public:
|
||||
|
||||
/** Create a PwmOut connected to the specified pin
|
||||
*
|
||||
* @param pin PwmOut pin to connect to
|
||||
*/
|
||||
PwmOut(PinName pin) {
|
||||
pwmout_init(&_pwm, pin);
|
||||
}
|
||||
|
||||
/** Set the ouput duty-cycle, specified as a percentage (float)
|
||||
*
|
||||
* @param value A floating-point value representing the output duty-cycle,
|
||||
* specified as a percentage. The value should lie between
|
||||
* 0.0f (representing on 0%) and 1.0f (representing on 100%).
|
||||
* Values outside this range will be saturated to 0.0f or 1.0f.
|
||||
*/
|
||||
void write(float value) {
|
||||
pwmout_write(&_pwm, value);
|
||||
}
|
||||
|
||||
/** Return the current output duty-cycle setting, measured as a percentage (float)
|
||||
*
|
||||
* @returns
|
||||
* A floating-point value representing the current duty-cycle being output on the pin,
|
||||
* measured as a percentage. The returned value will lie between
|
||||
* 0.0f (representing on 0%) and 1.0f (representing on 100%).
|
||||
*
|
||||
* @note
|
||||
* This value may not match exactly the value set by a previous <write>.
|
||||
*/
|
||||
float read() {
|
||||
return pwmout_read(&_pwm);
|
||||
}
|
||||
|
||||
/** Set the PWM period, specified in seconds (float), keeping the duty cycle the same.
|
||||
*
|
||||
* @note
|
||||
* The resolution is currently in microseconds; periods smaller than this
|
||||
* will be set to zero.
|
||||
*/
|
||||
void period(float seconds) {
|
||||
pwmout_period(&_pwm, seconds);
|
||||
}
|
||||
|
||||
/** Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.
|
||||
*/
|
||||
void period_ms(int ms) {
|
||||
pwmout_period_ms(&_pwm, ms);
|
||||
}
|
||||
|
||||
/** Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.
|
||||
*/
|
||||
void period_us(int us) {
|
||||
pwmout_period_us(&_pwm, us);
|
||||
}
|
||||
|
||||
/** Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.
|
||||
*/
|
||||
void pulsewidth(float seconds) {
|
||||
pwmout_pulsewidth(&_pwm, seconds);
|
||||
}
|
||||
|
||||
/** Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.
|
||||
*/
|
||||
void pulsewidth_ms(int ms) {
|
||||
pwmout_pulsewidth_ms(&_pwm, ms);
|
||||
}
|
||||
|
||||
/** Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.
|
||||
*/
|
||||
void pulsewidth_us(int us) {
|
||||
pwmout_pulsewidth_us(&_pwm, us);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
/** A operator shorthand for write()
|
||||
*/
|
||||
PwmOut& operator= (float value) {
|
||||
write(value);
|
||||
return *this;
|
||||
}
|
||||
|
||||
PwmOut& operator= (PwmOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
/** An operator shorthand for read()
|
||||
*/
|
||||
operator float() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
protected:
|
||||
pwmout_t _pwm;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,90 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_RAW_SERIAL_H
|
||||
#define MBED_RAW_SERIAL_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#include "SerialBase.h"
|
||||
#include "serial_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A serial port (UART) for communication with other serial devices
|
||||
* This is a variation of the Serial class that doesn't use streams,
|
||||
* thus making it safe to use in interrupt handlers with the RTOS.
|
||||
*
|
||||
* Can be used for Full Duplex communication, or Simplex by specifying
|
||||
* one pin as NC (Not Connected)
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Send a char to the PC
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* RawSerial pc(USBTX, USBRX);
|
||||
*
|
||||
* int main() {
|
||||
* pc.putc('A');
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class RawSerial: public SerialBase {
|
||||
|
||||
public:
|
||||
/** Create a RawSerial port, connected to the specified transmit and receive pins
|
||||
*
|
||||
* @param tx Transmit pin
|
||||
* @param rx Receive pin
|
||||
*
|
||||
* @note
|
||||
* Either tx or rx may be specified as NC if unused
|
||||
*/
|
||||
RawSerial(PinName tx, PinName rx);
|
||||
|
||||
/** Write a char to the serial port
|
||||
*
|
||||
* @param c The char to write
|
||||
*
|
||||
* @returns The written char or -1 if an error occured
|
||||
*/
|
||||
int putc(int c);
|
||||
|
||||
/** Read a char from the serial port
|
||||
*
|
||||
* @returns The char read from the serial port
|
||||
*/
|
||||
int getc();
|
||||
|
||||
/** Write a string to the serial port
|
||||
*
|
||||
* @param str The string to write
|
||||
*
|
||||
* @returns 0 if the write succeeds, EOF for error
|
||||
*/
|
||||
int puts(const char *str);
|
||||
|
||||
int printf(const char *format, ...);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
245
hal/api/SPI.h
245
hal/api/SPI.h
|
@ -1,245 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SPI_H
|
||||
#define MBED_SPI_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
#include "spi_api.h"
|
||||
|
||||
#if DEVICE_SPI_ASYNCH
|
||||
#include "CThunk.h"
|
||||
#include "dma_api.h"
|
||||
#include "CircularBuffer.h"
|
||||
#include "FunctionPointer.h"
|
||||
#include "Transaction.h"
|
||||
#endif
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A SPI Master, used for communicating with SPI slave devices
|
||||
*
|
||||
* The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
|
||||
*
|
||||
* Most SPI devices will also require Chip Select and Reset signals. These
|
||||
* can be controlled using <DigitalOut> pins
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Send a byte to a SPI slave, and record the response
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* // hardware ssel (where applicable)
|
||||
* //SPI device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
|
||||
*
|
||||
* // software ssel
|
||||
* SPI device(p5, p6, p7); // mosi, miso, sclk
|
||||
* DigitalOut cs(p8); // ssel
|
||||
*
|
||||
* int main() {
|
||||
* // hardware ssel (where applicable)
|
||||
* //int response = device.write(0xFF);
|
||||
*
|
||||
* // software ssel
|
||||
* cs = 0;
|
||||
* int response = device.write(0xFF);
|
||||
* cs = 1;
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class SPI {
|
||||
|
||||
public:
|
||||
|
||||
/** Create a SPI master connected to the specified pins
|
||||
*
|
||||
* mosi or miso can be specfied as NC if not used
|
||||
*
|
||||
* @param mosi SPI Master Out, Slave In pin
|
||||
* @param miso SPI Master In, Slave Out pin
|
||||
* @param sclk SPI Clock pin
|
||||
* @param ssel SPI chip select pin
|
||||
*/
|
||||
SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel=NC);
|
||||
|
||||
/** Configure the data transmission format
|
||||
*
|
||||
* @param bits Number of bits per SPI frame (4 - 16)
|
||||
* @param mode Clock polarity and phase mode (0 - 3)
|
||||
*
|
||||
* @code
|
||||
* mode | POL PHA
|
||||
* -----+--------
|
||||
* 0 | 0 0
|
||||
* 1 | 0 1
|
||||
* 2 | 1 0
|
||||
* 3 | 1 1
|
||||
* @endcode
|
||||
*/
|
||||
void format(int bits, int mode = 0);
|
||||
|
||||
/** Set the spi bus clock frequency
|
||||
*
|
||||
* @param hz SCLK frequency in hz (default = 1MHz)
|
||||
*/
|
||||
void frequency(int hz = 1000000);
|
||||
|
||||
/** Write to the SPI Slave and return the response
|
||||
*
|
||||
* @param value Data to be sent to the SPI slave
|
||||
*
|
||||
* @returns
|
||||
* Response from the SPI slave
|
||||
*/
|
||||
virtual int write(int value);
|
||||
|
||||
#if DEVICE_SPI_ASYNCH
|
||||
|
||||
/** Start non-blocking SPI transfer using 8bit buffers.
|
||||
*
|
||||
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
|
||||
* the default SPI value is sent
|
||||
* @param tx_length The length of TX buffer in bytes
|
||||
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
|
||||
* received data are ignored
|
||||
* @param rx_length The length of RX buffer in bytes
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of events to modify. Look at spi hal header file for SPI events.
|
||||
* @return Zero if the transfer has started, or -1 if SPI peripheral is busy
|
||||
*/
|
||||
template<typename Type>
|
||||
int transfer(const Type *tx_buffer, int tx_length, Type *rx_buffer, int rx_length, const event_callback_t& callback, int event = SPI_EVENT_COMPLETE) {
|
||||
if (spi_active(&_spi)) {
|
||||
return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
|
||||
}
|
||||
start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, sizeof(Type)*8, callback, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** Abort the on-going SPI transfer, and continue with transfer's in the queue if any.
|
||||
*/
|
||||
void abort_transfer();
|
||||
|
||||
/** Clear the transaction buffer
|
||||
*/
|
||||
void clear_transfer_buffer();
|
||||
|
||||
/** Clear the transaction buffer and abort on-going transfer.
|
||||
*/
|
||||
void abort_all_transfers();
|
||||
|
||||
/** Configure DMA usage suggestion for non-blocking transfers
|
||||
*
|
||||
* @param usage The usage DMA hint for peripheral
|
||||
* @return Zero if the usage was set, -1 if a transaction is on-going
|
||||
*/
|
||||
int set_dma_usage(DMAUsage usage);
|
||||
|
||||
protected:
|
||||
/** SPI IRQ handler
|
||||
*
|
||||
*/
|
||||
void irq_handler_asynch(void);
|
||||
|
||||
/** Common transfer method
|
||||
*
|
||||
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
|
||||
* the default SPI value is sent
|
||||
* @param tx_length The length of TX buffer in bytes
|
||||
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
|
||||
* received data are ignored
|
||||
* @param rx_length The length of RX buffer in bytes
|
||||
* @param bit_width The buffers element width
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of events to modify
|
||||
* @return Zero if the transfer has started or was added to the queue, or -1 if SPI peripheral is busy/buffer is full
|
||||
*/
|
||||
int transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
|
||||
|
||||
/**
|
||||
*
|
||||
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
|
||||
* the default SPI value is sent
|
||||
* @param tx_length The length of TX buffer in bytes
|
||||
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
|
||||
* received data are ignored
|
||||
* @param rx_length The length of RX buffer in bytes
|
||||
* @param bit_width The buffers element width
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of events to modify
|
||||
* @return Zero if a transfer was added to the queue, or -1 if the queue is full
|
||||
*/
|
||||
int queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
|
||||
|
||||
/** Configures a callback, spi peripheral and initiate a new transfer
|
||||
*
|
||||
* @param tx_buffer The TX buffer with data to be transfered. If NULL is passed,
|
||||
* the default SPI value is sent
|
||||
* @param tx_length The length of TX buffer in bytes
|
||||
* @param rx_buffer The RX buffer which is used for received data. If NULL is passed,
|
||||
* received data are ignored
|
||||
* @param rx_length The length of RX buffer in bytes
|
||||
* @param bit_width The buffers element width
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of events to modify
|
||||
*/
|
||||
void start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event);
|
||||
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
|
||||
/** Start a new transaction
|
||||
*
|
||||
* @param data Transaction data
|
||||
*/
|
||||
void start_transaction(transaction_t *data);
|
||||
|
||||
/** Dequeue a transaction
|
||||
*
|
||||
*/
|
||||
void dequeue_transaction();
|
||||
static CircularBuffer<Transaction<SPI>, TRANSACTION_QUEUE_SIZE_SPI> _transaction_buffer;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
virtual ~SPI() {
|
||||
}
|
||||
|
||||
protected:
|
||||
spi_t _spi;
|
||||
|
||||
#if DEVICE_SPI_ASYNCH
|
||||
CThunk<SPI> _irq;
|
||||
event_callback_t _callback;
|
||||
DMAUsage _usage;
|
||||
#endif
|
||||
|
||||
void aquire(void);
|
||||
static SPI *_owner;
|
||||
int _bits;
|
||||
int _mode;
|
||||
int _hz;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,122 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SPISLAVE_H
|
||||
#define MBED_SPISLAVE_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SPISLAVE
|
||||
|
||||
#include "spi_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A SPI slave, used for communicating with a SPI Master device
|
||||
*
|
||||
* The default format is set to 8-bits, mode 0, and a clock frequency of 1MHz
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Reply to a SPI master as slave
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* SPISlave device(p5, p6, p7, p8); // mosi, miso, sclk, ssel
|
||||
*
|
||||
* int main() {
|
||||
* device.reply(0x00); // Prime SPI with first reply
|
||||
* while(1) {
|
||||
* if(device.receive()) {
|
||||
* int v = device.read(); // Read byte from master
|
||||
* v = (v + 1) % 0x100; // Add one to it, modulo 256
|
||||
* device.reply(v); // Make this the next reply
|
||||
* }
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class SPISlave {
|
||||
|
||||
public:
|
||||
|
||||
/** Create a SPI slave connected to the specified pins
|
||||
*
|
||||
* mosi or miso can be specfied as NC if not used
|
||||
*
|
||||
* @param mosi SPI Master Out, Slave In pin
|
||||
* @param miso SPI Master In, Slave Out pin
|
||||
* @param sclk SPI Clock pin
|
||||
* @param ssel SPI chip select pin
|
||||
*/
|
||||
SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel);
|
||||
|
||||
/** Configure the data transmission format
|
||||
*
|
||||
* @param bits Number of bits per SPI frame (4 - 16)
|
||||
* @param mode Clock polarity and phase mode (0 - 3)
|
||||
*
|
||||
* @code
|
||||
* mode | POL PHA
|
||||
* -----+--------
|
||||
* 0 | 0 0
|
||||
* 1 | 0 1
|
||||
* 2 | 1 0
|
||||
* 3 | 1 1
|
||||
* @endcode
|
||||
*/
|
||||
void format(int bits, int mode = 0);
|
||||
|
||||
/** Set the spi bus clock frequency
|
||||
*
|
||||
* @param hz SCLK frequency in hz (default = 1MHz)
|
||||
*/
|
||||
void frequency(int hz = 1000000);
|
||||
|
||||
/** Polls the SPI to see if data has been received
|
||||
*
|
||||
* @returns
|
||||
* 0 if no data,
|
||||
* 1 otherwise
|
||||
*/
|
||||
int receive(void);
|
||||
|
||||
/** Retrieve data from receive buffer as slave
|
||||
*
|
||||
* @returns
|
||||
* the data in the receive buffer
|
||||
*/
|
||||
int read(void);
|
||||
|
||||
/** Fill the transmission buffer with the value to be written out
|
||||
* as slave on the next received message from the master.
|
||||
*
|
||||
* @param value the data to be transmitted next
|
||||
*/
|
||||
void reply(int value);
|
||||
|
||||
protected:
|
||||
spi_t _spi;
|
||||
|
||||
int _bits;
|
||||
int _mode;
|
||||
int _hz;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,74 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SERIAL_H
|
||||
#define MBED_SERIAL_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#include "Stream.h"
|
||||
#include "SerialBase.h"
|
||||
#include "serial_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A serial port (UART) for communication with other serial devices
|
||||
*
|
||||
* Can be used for Full Duplex communication, or Simplex by specifying
|
||||
* one pin as NC (Not Connected)
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Print "Hello World" to the PC
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Serial pc(USBTX, USBRX);
|
||||
*
|
||||
* int main() {
|
||||
* pc.printf("Hello World\n");
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Serial : public SerialBase, public Stream {
|
||||
|
||||
public:
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
using SerialBase::read;
|
||||
using SerialBase::write;
|
||||
#endif
|
||||
|
||||
/** Create a Serial port, connected to the specified transmit and receive pins
|
||||
*
|
||||
* @param tx Transmit pin
|
||||
* @param rx Receive pin
|
||||
*
|
||||
* @note
|
||||
* Either tx or rx may be specified as NC if unused
|
||||
*/
|
||||
Serial(PinName tx, PinName rx, const char *name=NULL);
|
||||
|
||||
protected:
|
||||
virtual int _getc();
|
||||
virtual int _putc(int c);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,229 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SERIALBASE_H
|
||||
#define MBED_SERIALBASE_H
|
||||
|
||||
#include "platform.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#include "Stream.h"
|
||||
#include "Callback.h"
|
||||
#include "serial_api.h"
|
||||
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
#include "CThunk.h"
|
||||
#include "dma_api.h"
|
||||
#endif
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A base class for serial port implementations
|
||||
* Can't be instantiated directly (use Serial or RawSerial)
|
||||
*/
|
||||
class SerialBase {
|
||||
|
||||
public:
|
||||
/** Set the baud rate of the serial port
|
||||
*
|
||||
* @param baudrate The baudrate of the serial port (default = 9600).
|
||||
*/
|
||||
void baud(int baudrate);
|
||||
|
||||
enum Parity {
|
||||
None = 0,
|
||||
Odd,
|
||||
Even,
|
||||
Forced1,
|
||||
Forced0
|
||||
};
|
||||
|
||||
enum IrqType {
|
||||
RxIrq = 0,
|
||||
TxIrq
|
||||
};
|
||||
|
||||
enum Flow {
|
||||
Disabled = 0,
|
||||
RTS,
|
||||
CTS,
|
||||
RTSCTS
|
||||
};
|
||||
|
||||
/** Set the transmission format used by the serial port
|
||||
*
|
||||
* @param bits The number of bits in a word (5-8; default = 8)
|
||||
* @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None)
|
||||
* @param stop The number of stop bits (1 or 2; default = 1)
|
||||
*/
|
||||
void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1);
|
||||
|
||||
/** Determine if there is a character available to read
|
||||
*
|
||||
* @returns
|
||||
* 1 if there is a character available to read,
|
||||
* 0 otherwise
|
||||
*/
|
||||
int readable();
|
||||
|
||||
/** Determine if there is space available to write a character
|
||||
*
|
||||
* @returns
|
||||
* 1 if there is space to write a character,
|
||||
* 0 otherwise
|
||||
*/
|
||||
int writeable();
|
||||
|
||||
/** Attach a function to call whenever a serial interrupt is generated
|
||||
*
|
||||
* @param func A pointer to a void function, or 0 to set as none
|
||||
* @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
|
||||
*/
|
||||
void attach(Callback<void()> func, IrqType type=RxIrq);
|
||||
|
||||
/** Attach a member function to call whenever a serial interrupt is generated
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
* @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, void (T::*method)(), IrqType type=RxIrq) {
|
||||
attach(Callback<void()>(obj, method), type);
|
||||
}
|
||||
|
||||
/** Attach a member function to call whenever a serial interrupt is generated
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
* @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty)
|
||||
*/
|
||||
template<typename T>
|
||||
void attach(T *obj, void (*method)(T*), IrqType type=RxIrq) {
|
||||
attach(Callback<void()>(obj, method), type);
|
||||
}
|
||||
|
||||
/** Generate a break condition on the serial line
|
||||
*/
|
||||
void send_break();
|
||||
|
||||
#if DEVICE_SERIAL_FC
|
||||
/** Set the flow control type on the serial port
|
||||
*
|
||||
* @param type the flow control type (Disabled, RTS, CTS, RTSCTS)
|
||||
* @param flow1 the first flow control pin (RTS for RTS or RTSCTS, CTS for CTS)
|
||||
* @param flow2 the second flow control pin (CTS for RTSCTS)
|
||||
*/
|
||||
void set_flow_control(Flow type, PinName flow1=NC, PinName flow2=NC);
|
||||
#endif
|
||||
|
||||
static void _irq_handler(uint32_t id, SerialIrq irq_type);
|
||||
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
|
||||
/** Begin asynchronous write using 8bit buffer. The completition invokes registered TX event callback
|
||||
*
|
||||
* @param buffer The buffer where received data will be stored
|
||||
* @param length The buffer length in bytes
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of TX events
|
||||
*/
|
||||
int write(const uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
|
||||
|
||||
/** Begin asynchronous write using 16bit buffer. The completition invokes registered TX event callback
|
||||
*
|
||||
* @param buffer The buffer where received data will be stored
|
||||
* @param length The buffer length in bytes
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of TX events
|
||||
*/
|
||||
int write(const uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_TX_COMPLETE);
|
||||
|
||||
/** Abort the on-going write transfer
|
||||
*/
|
||||
void abort_write();
|
||||
|
||||
/** Begin asynchronous reading using 8bit buffer. The completition invokes registred RX event callback.
|
||||
*
|
||||
* @param buffer The buffer where received data will be stored
|
||||
* @param length The buffer length in bytes
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of RX events
|
||||
* @param char_match The matching character
|
||||
*/
|
||||
int read(uint8_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
|
||||
|
||||
/** Begin asynchronous reading using 16bit buffer. The completition invokes registred RX event callback.
|
||||
*
|
||||
* @param buffer The buffer where received data will be stored
|
||||
* @param length The buffer length in bytes
|
||||
* @param callback The event callback function
|
||||
* @param event The logical OR of RX events
|
||||
* @param char_match The matching character
|
||||
*/
|
||||
int read(uint16_t *buffer, int length, const event_callback_t& callback, int event = SERIAL_EVENT_RX_COMPLETE, unsigned char char_match = SERIAL_RESERVED_CHAR_MATCH);
|
||||
|
||||
/** Abort the on-going read transfer
|
||||
*/
|
||||
void abort_read();
|
||||
|
||||
/** Configure DMA usage suggestion for non-blocking TX transfers
|
||||
*
|
||||
* @param usage The usage DMA hint for peripheral
|
||||
* @return Zero if the usage was set, -1 if a transaction is on-going
|
||||
*/
|
||||
int set_dma_usage_tx(DMAUsage usage);
|
||||
|
||||
/** Configure DMA usage suggestion for non-blocking RX transfers
|
||||
*
|
||||
* @param usage The usage DMA hint for peripheral
|
||||
* @return Zero if the usage was set, -1 if a transaction is on-going
|
||||
*/
|
||||
int set_dma_usage_rx(DMAUsage usage);
|
||||
|
||||
protected:
|
||||
void start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match);
|
||||
void start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event);
|
||||
void interrupt_handler_asynch(void);
|
||||
#endif
|
||||
|
||||
protected:
|
||||
SerialBase(PinName tx, PinName rx);
|
||||
virtual ~SerialBase() {
|
||||
}
|
||||
|
||||
int _base_getc();
|
||||
int _base_putc(int c);
|
||||
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
CThunk<SerialBase> _thunk_irq;
|
||||
event_callback_t _tx_callback;
|
||||
event_callback_t _rx_callback;
|
||||
DMAUsage _tx_usage;
|
||||
DMAUsage _rx_usage;
|
||||
#endif
|
||||
|
||||
serial_t _serial;
|
||||
Callback<void()> _irq[2];
|
||||
int _baud;
|
||||
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,68 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_STREAM_H
|
||||
#define MBED_STREAM_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "FileLike.h"
|
||||
#include <cstdarg>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
extern void mbed_set_unbuffered_stream(FILE *_file);
|
||||
extern int mbed_getc(FILE *_file);
|
||||
extern char* mbed_gets(char *s, int size, FILE *_file);
|
||||
|
||||
class Stream : public FileLike {
|
||||
|
||||
public:
|
||||
Stream(const char *name=NULL);
|
||||
virtual ~Stream();
|
||||
|
||||
int putc(int c);
|
||||
int puts(const char *s);
|
||||
int getc();
|
||||
char *gets(char *s, int size);
|
||||
int printf(const char* format, ...);
|
||||
int scanf(const char* format, ...);
|
||||
int vprintf(const char* format, std::va_list args);
|
||||
int vscanf(const char* format, std::va_list args);
|
||||
|
||||
operator std::FILE*() {return _file;}
|
||||
|
||||
protected:
|
||||
virtual int close();
|
||||
virtual ssize_t write(const void* buffer, size_t length);
|
||||
virtual ssize_t read(void* buffer, size_t length);
|
||||
virtual off_t lseek(off_t offset, int whence);
|
||||
virtual int isatty();
|
||||
virtual int fsync();
|
||||
virtual off_t flen();
|
||||
|
||||
virtual int _putc(int c) = 0;
|
||||
virtual int _getc() = 0;
|
||||
|
||||
std::FILE *_file;
|
||||
|
||||
/* disallow copy constructor and assignment operators */
|
||||
private:
|
||||
Stream(const Stream&);
|
||||
Stream & operator = (const Stream&);
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
126
hal/api/Ticker.h
126
hal/api/Ticker.h
|
@ -1,126 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TICKER_H
|
||||
#define MBED_TICKER_H
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "Callback.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A Ticker is used to call a function at a recurring interval
|
||||
*
|
||||
* You can use as many seperate Ticker objects as you require.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Toggle the blinking led after 5 seconds
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Ticker timer;
|
||||
* DigitalOut led1(LED1);
|
||||
* DigitalOut led2(LED2);
|
||||
*
|
||||
* int flip = 0;
|
||||
*
|
||||
* void attime() {
|
||||
* flip = !flip;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* timer.attach(&attime, 5);
|
||||
* while(1) {
|
||||
* if(flip == 0) {
|
||||
* led1 = !led1;
|
||||
* } else {
|
||||
* led2 = !led2;
|
||||
* }
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Ticker : public TimerEvent {
|
||||
|
||||
public:
|
||||
Ticker() : TimerEvent() {
|
||||
}
|
||||
|
||||
Ticker(const ticker_data_t *data) : TimerEvent(data) {
|
||||
}
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param func pointer to the function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*/
|
||||
void attach(Callback<void()> func, float t) {
|
||||
attach_us(func, t * 1000000.0f);
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in seconds
|
||||
*
|
||||
* @param obj pointer to the object to call the member function on
|
||||
* @param method pointer to the member function to be called
|
||||
* @param t the time between calls in seconds
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
void attach(T *obj, M method, float t) {
|
||||
attach(Callback<void()>(obj, method), t);
|
||||
}
|
||||
|
||||
/** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param fptr pointer to the function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*/
|
||||
void attach_us(Callback<void()> func, timestamp_t t) {
|
||||
_function.attach(func);
|
||||
setup(t);
|
||||
}
|
||||
|
||||
/** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds
|
||||
*
|
||||
* @param tptr pointer to the object to call the member function on
|
||||
* @param mptr pointer to the member function to be called
|
||||
* @param t the time between calls in micro-seconds
|
||||
*/
|
||||
template<typename T, typename M>
|
||||
void attach_us(T *obj, M method, timestamp_t t) {
|
||||
attach_us(Callback<void()>(obj, method), t);
|
||||
}
|
||||
|
||||
virtual ~Ticker() {
|
||||
detach();
|
||||
}
|
||||
|
||||
/** Detach the function
|
||||
*/
|
||||
void detach();
|
||||
|
||||
protected:
|
||||
void setup(timestamp_t t);
|
||||
virtual void handler();
|
||||
|
||||
protected:
|
||||
timestamp_t _delay; /**< Time delay (in microseconds) for re-setting the multi-shot callback. */
|
||||
Callback<void()> _function; /**< Callback. */
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,59 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TIMEOUT_H
|
||||
#define MBED_TIMEOUT_H
|
||||
|
||||
#include "Ticker.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A Timeout is used to call a function at a point in the future
|
||||
*
|
||||
* You can use as many seperate Timeout objects as you require.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Blink until timeout.
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Timeout timeout;
|
||||
* DigitalOut led(LED1);
|
||||
*
|
||||
* int on = 1;
|
||||
*
|
||||
* void attimeout() {
|
||||
* on = 0;
|
||||
* }
|
||||
*
|
||||
* int main() {
|
||||
* timeout.attach(&attimeout, 5);
|
||||
* while(on) {
|
||||
* led = !led;
|
||||
* wait(0.2);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Timeout : public Ticker {
|
||||
|
||||
protected:
|
||||
virtual void handler();
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,91 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TIMER_H
|
||||
#define MBED_TIMER_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** A general purpose timer
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* // Count the time to toggle a LED
|
||||
*
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* Timer timer;
|
||||
* DigitalOut led(LED1);
|
||||
* int begin, end;
|
||||
*
|
||||
* int main() {
|
||||
* timer.start();
|
||||
* begin = timer.read_us();
|
||||
* led = !led;
|
||||
* end = timer.read_us();
|
||||
* printf("Toggle the led takes %d us", end - begin);
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
class Timer {
|
||||
|
||||
public:
|
||||
Timer();
|
||||
Timer(const ticker_data_t *data);
|
||||
|
||||
/** Start the timer
|
||||
*/
|
||||
void start();
|
||||
|
||||
/** Stop the timer
|
||||
*/
|
||||
void stop();
|
||||
|
||||
/** Reset the timer to 0.
|
||||
*
|
||||
* If it was already counting, it will continue
|
||||
*/
|
||||
void reset();
|
||||
|
||||
/** Get the time passed in seconds
|
||||
*/
|
||||
float read();
|
||||
|
||||
/** Get the time passed in mili-seconds
|
||||
*/
|
||||
int read_ms();
|
||||
|
||||
/** Get the time passed in micro-seconds
|
||||
*/
|
||||
int read_us();
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
operator float();
|
||||
#endif
|
||||
|
||||
protected:
|
||||
int slicetime();
|
||||
int _running; // whether the timer is running
|
||||
unsigned int _start; // the start time of the latest slice
|
||||
int _time; // any accumulated time from previous slices
|
||||
const ticker_data_t *_ticker_data;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,56 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TIMEREVENT_H
|
||||
#define MBED_TIMEREVENT_H
|
||||
|
||||
#include "ticker_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Base abstraction for timer interrupts
|
||||
*/
|
||||
class TimerEvent {
|
||||
public:
|
||||
TimerEvent();
|
||||
TimerEvent(const ticker_data_t *data);
|
||||
|
||||
/** The handler registered with the underlying timer interrupt
|
||||
*/
|
||||
static void irq(uint32_t id);
|
||||
|
||||
/** Destruction removes it...
|
||||
*/
|
||||
virtual ~TimerEvent();
|
||||
|
||||
protected:
|
||||
// The handler called to service the timer event of the derived class
|
||||
virtual void handler() = 0;
|
||||
|
||||
// insert in to linked list
|
||||
void insert(timestamp_t timestamp);
|
||||
|
||||
// remove from linked list, if in it
|
||||
void remove();
|
||||
|
||||
ticker_event_t event;
|
||||
|
||||
const ticker_data_t *_ticker_data;
|
||||
};
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,73 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TRANSACTION_H
|
||||
#define MBED_TRANSACTION_H
|
||||
|
||||
#include "platform.h"
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/** Transaction structure
|
||||
*/
|
||||
typedef struct {
|
||||
void *tx_buffer; /**< Tx buffer */
|
||||
size_t tx_length; /**< Length of Tx buffer*/
|
||||
void *rx_buffer; /**< Rx buffer */
|
||||
size_t rx_length; /**< Length of Rx buffer */
|
||||
uint32_t event; /**< Event for a transaction */
|
||||
event_callback_t callback; /**< User's callback */
|
||||
uint8_t width; /**< Buffer's word width (8, 16, 32, 64) */
|
||||
} transaction_t;
|
||||
|
||||
/** Transaction class defines a transaction.
|
||||
*/
|
||||
template<typename Class>
|
||||
class Transaction {
|
||||
public:
|
||||
Transaction(Class *tpointer, const transaction_t& transaction) : _obj(tpointer), _data(transaction) {
|
||||
}
|
||||
|
||||
Transaction() : _obj(), _data() {
|
||||
}
|
||||
|
||||
~Transaction() {
|
||||
}
|
||||
|
||||
/** Get object's instance for the transaction
|
||||
*
|
||||
* @return The object which was stored
|
||||
*/
|
||||
Class* get_object() {
|
||||
return _obj;
|
||||
}
|
||||
|
||||
/** Get the transaction
|
||||
*
|
||||
* @return The transaction which was stored
|
||||
*/
|
||||
transaction_t* get_transaction() {
|
||||
return &_data;
|
||||
}
|
||||
|
||||
private:
|
||||
Class* _obj;
|
||||
transaction_t _data;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,53 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_CAN_HELPER_H
|
||||
#define MBED_CAN_HELPER_H
|
||||
|
||||
#if DEVICE_CAN
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
enum CANFormat {
|
||||
CANStandard = 0,
|
||||
CANExtended = 1,
|
||||
CANAny = 2
|
||||
};
|
||||
typedef enum CANFormat CANFormat;
|
||||
|
||||
enum CANType {
|
||||
CANData = 0,
|
||||
CANRemote = 1
|
||||
};
|
||||
typedef enum CANType CANType;
|
||||
|
||||
struct CAN_Message {
|
||||
unsigned int id; // 29 bit identifier
|
||||
unsigned char data[8]; // Data field
|
||||
unsigned char len; // Length of data field in bytes
|
||||
CANFormat format; // 0 - STANDARD, 1- EXTENDED IDENTIFIER
|
||||
CANType type; // 0 - DATA FRAME, 1 - REMOTE FRAME
|
||||
};
|
||||
typedef struct CAN_Message CAN_Message;
|
||||
|
||||
#ifdef __cplusplus
|
||||
};
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#endif // MBED_CAN_HELPER_H
|
|
@ -1,21 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_STUB_H
|
||||
#define MBED_STUB_H
|
||||
|
||||
#include "../mbed.h"
|
||||
|
||||
#endif
|
|
@ -1,74 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_H
|
||||
#define MBED_H
|
||||
|
||||
#define MBED_LIBRARY_VERSION 117
|
||||
|
||||
#include "toolchain.h"
|
||||
#include "platform.h"
|
||||
|
||||
// Useful C libraries
|
||||
#include <math.h>
|
||||
#include <time.h>
|
||||
|
||||
// mbed Debug libraries
|
||||
#include "mbed_error.h"
|
||||
#include "mbed_interface.h"
|
||||
|
||||
// mbed Peripheral components
|
||||
#include "DigitalIn.h"
|
||||
#include "DigitalOut.h"
|
||||
#include "DigitalInOut.h"
|
||||
#include "BusIn.h"
|
||||
#include "BusOut.h"
|
||||
#include "BusInOut.h"
|
||||
#include "PortIn.h"
|
||||
#include "PortInOut.h"
|
||||
#include "PortOut.h"
|
||||
#include "AnalogIn.h"
|
||||
#include "AnalogOut.h"
|
||||
#include "PwmOut.h"
|
||||
#include "Serial.h"
|
||||
#include "SPI.h"
|
||||
#include "SPISlave.h"
|
||||
#include "I2C.h"
|
||||
#include "I2CSlave.h"
|
||||
#include "Ethernet.h"
|
||||
#include "CAN.h"
|
||||
#include "RawSerial.h"
|
||||
|
||||
// mbed Internal components
|
||||
#include "Timer.h"
|
||||
#include "Ticker.h"
|
||||
#include "Timeout.h"
|
||||
#include "LowPowerTimeout.h"
|
||||
#include "LowPowerTicker.h"
|
||||
#include "LowPowerTimer.h"
|
||||
#include "LocalFileSystem.h"
|
||||
#include "InterruptIn.h"
|
||||
#include "wait_api.h"
|
||||
#include "sleep_api.h"
|
||||
#include "rtc_time.h"
|
||||
|
||||
// mbed Non-hardware components
|
||||
#include "Callback.h"
|
||||
#include "FunctionPointer.h"
|
||||
|
||||
using namespace mbed;
|
||||
using namespace std;
|
||||
|
||||
#endif
|
|
@ -1,49 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ASSERT_H
|
||||
#define MBED_ASSERT_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Internal mbed assert function which is invoked when MBED_ASSERT macro failes.
|
||||
* This function is active only if NDEBUG is not defined prior to including this
|
||||
* assert header file.
|
||||
* In case of MBED_ASSERT failing condition, error() is called with the assertation message.
|
||||
* @param expr Expresion to be checked.
|
||||
* @param file File where assertation failed.
|
||||
* @param line Failing assertation line number.
|
||||
*/
|
||||
void mbed_assert_internal(const char *expr, const char *file, int line);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef NDEBUG
|
||||
#define MBED_ASSERT(expr) ((void)0)
|
||||
|
||||
#else
|
||||
#define MBED_ASSERT(expr) \
|
||||
do { \
|
||||
if (!(expr)) { \
|
||||
mbed_assert_internal(#expr, __FILE__, __LINE__); \
|
||||
} \
|
||||
} while (0)
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,66 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_DEBUG_H
|
||||
#define MBED_DEBUG_H
|
||||
#include "device.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
/** Output a debug message
|
||||
*
|
||||
* @param format printf-style format string, followed by variables
|
||||
*/
|
||||
static inline void debug(const char *format, ...) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
|
||||
/** Conditionally output a debug message
|
||||
*
|
||||
* NOTE: If the condition is constant false (!= 1) and the compiler optimization
|
||||
* level is greater than 0, then the whole function will be compiled away.
|
||||
*
|
||||
* @param condition output only if condition is true (== 1)
|
||||
* @param format printf-style format string, followed by variables
|
||||
*/
|
||||
static inline void debug_if(int condition, const char *format, ...) {
|
||||
if (condition == 1) {
|
||||
va_list args;
|
||||
va_start(args, format);
|
||||
vfprintf(stderr, format, args);
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
|
||||
#else
|
||||
static inline void debug(const char *format, ...) {}
|
||||
static inline void debug_if(int condition, const char *format, ...) {}
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,66 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_ERROR_H
|
||||
#define MBED_ERROR_H
|
||||
|
||||
/** To generate a fatal compile-time error, you can use the pre-processor #error directive.
|
||||
*
|
||||
* @code
|
||||
* #error "That shouldn't have happened!"
|
||||
* @endcode
|
||||
*
|
||||
* If the compiler evaluates this line, it will report the error and stop the compile.
|
||||
*
|
||||
* For example, you could use this to check some user-defined compile-time variables:
|
||||
*
|
||||
* @code
|
||||
* #define NUM_PORTS 7
|
||||
* #if (NUM_PORTS > 4)
|
||||
* #error "NUM_PORTS must be less than 4"
|
||||
* #endif
|
||||
* @endcode
|
||||
*
|
||||
* Reporting Run-Time Errors:
|
||||
* To generate a fatal run-time error, you can use the mbed error() function.
|
||||
*
|
||||
* @code
|
||||
* error("That shouldn't have happened!");
|
||||
* @endcode
|
||||
*
|
||||
* If the mbed running the program executes this function, it will print the
|
||||
* message via the USB serial port, and then die with the blue lights of death!
|
||||
*
|
||||
* The message can use printf-style formatting, so you can report variables in the
|
||||
* message too. For example, you could use this to check a run-time condition:
|
||||
*
|
||||
* @code
|
||||
* if(x >= 5) {
|
||||
* error("expected x to be less than 5, but got %d", x);
|
||||
* }
|
||||
* #endcode
|
||||
*/
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
void error(const char* format, ...);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,114 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_INTERFACE_H
|
||||
#define MBED_INTERFACE_H
|
||||
|
||||
#include "device.h"
|
||||
|
||||
/* Mbed interface mac address
|
||||
* if MBED_MAC_ADD_x are zero, interface uid sets mac address,
|
||||
* otherwise MAC_ADD_x are used.
|
||||
*/
|
||||
#define MBED_MAC_ADDR_INTERFACE 0x00
|
||||
#define MBED_MAC_ADDR_0 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDR_1 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDR_2 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDR_3 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDR_4 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDR_5 MBED_MAC_ADDR_INTERFACE
|
||||
#define MBED_MAC_ADDRESS_SUM (MBED_MAC_ADDR_0 | MBED_MAC_ADDR_1 | MBED_MAC_ADDR_2 | MBED_MAC_ADDR_3 | MBED_MAC_ADDR_4 | MBED_MAC_ADDR_5)
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if DEVICE_SEMIHOST
|
||||
|
||||
/** Functions to control the mbed interface
|
||||
*
|
||||
* mbed Microcontrollers have a built-in interface to provide functionality such as
|
||||
* drag-n-drop download, reset, serial-over-usb, and access to the mbed local file
|
||||
* system. These functions provide means to control the interface suing semihost
|
||||
* calls it supports.
|
||||
*/
|
||||
|
||||
/** Determine whether the mbed interface is connected, based on whether debug is enabled
|
||||
*
|
||||
* @returns
|
||||
* 1 if interface is connected,
|
||||
* 0 otherwise
|
||||
*/
|
||||
int mbed_interface_connected(void);
|
||||
|
||||
/** Instruct the mbed interface to reset, as if the reset button had been pressed
|
||||
*
|
||||
* @returns
|
||||
* 1 if successful,
|
||||
* 0 otherwise (e.g. interface not present)
|
||||
*/
|
||||
int mbed_interface_reset(void);
|
||||
|
||||
/** This will disconnect the debug aspect of the interface, so semihosting will be disabled.
|
||||
* The interface will still support the USB serial aspect
|
||||
*
|
||||
* @returns
|
||||
* 0 if successful,
|
||||
* -1 otherwise (e.g. interface not present)
|
||||
*/
|
||||
int mbed_interface_disconnect(void);
|
||||
|
||||
/** This will disconnect the debug aspect of the interface, and if the USB cable is not
|
||||
* connected, also power down the interface. If the USB cable is connected, the interface
|
||||
* will remain powered up and visible to the host
|
||||
*
|
||||
* @returns
|
||||
* 0 if successful,
|
||||
* -1 otherwise (e.g. interface not present)
|
||||
*/
|
||||
int mbed_interface_powerdown(void);
|
||||
|
||||
/** This returns a string containing the 32-character UID of the mbed interface
|
||||
* This is a weak function that can be overwritten if required
|
||||
*
|
||||
* @param uid A 33-byte array to write the null terminated 32-byte string
|
||||
*
|
||||
* @returns
|
||||
* 0 if successful,
|
||||
* -1 otherwise (e.g. interface not present)
|
||||
*/
|
||||
int mbed_interface_uid(char *uid);
|
||||
|
||||
#endif
|
||||
|
||||
/** This returns a unique 6-byte MAC address, based on the interface UID
|
||||
* If the interface is not present, it returns a default fixed MAC address (00:02:F7:F0:00:00)
|
||||
*
|
||||
* This is a weak function that can be overwritten if you want to provide your own mechanism to
|
||||
* provide a MAC address.
|
||||
*
|
||||
* @param mac A 6-byte array to write the MAC address
|
||||
*/
|
||||
void mbed_mac_address(char *mac);
|
||||
|
||||
/** Cause the mbed to flash the BLOD (Blue LEDs Of Death) sequence
|
||||
*/
|
||||
void mbed_die(void);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,30 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_PLATFORM_H
|
||||
#define MBED_PLATFORM_H
|
||||
|
||||
#define MBED_OPERATORS 1
|
||||
|
||||
#include "device.h"
|
||||
#include "PinNames.h"
|
||||
#include "PeripheralNames.h"
|
||||
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#endif
|
|
@ -1,85 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Implementation of the C time.h functions
|
||||
*
|
||||
* Provides mechanisms to set and read the current time, based
|
||||
* on the microcontroller Real-Time Clock (RTC), plus some
|
||||
* standard C manipulation and formating functions.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* int main() {
|
||||
* set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
|
||||
*
|
||||
* while(1) {
|
||||
* time_t seconds = time(NULL);
|
||||
*
|
||||
* printf("Time as seconds since January 1, 1970 = %d\n", seconds);
|
||||
*
|
||||
* printf("Time as a basic string = %s", ctime(&seconds));
|
||||
*
|
||||
* char buffer[32];
|
||||
* strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
|
||||
* printf("Time as a custom formatted string = %s", buffer);
|
||||
*
|
||||
* wait(1);
|
||||
* }
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
|
||||
/** Set the current time
|
||||
*
|
||||
* Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
|
||||
* to the time represented by the number of seconds since January 1, 1970
|
||||
* (the UNIX timestamp).
|
||||
*
|
||||
* @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* int main() {
|
||||
* set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
void set_time(time_t t);
|
||||
|
||||
/** Attach an external RTC to be used for the C time functions
|
||||
*
|
||||
* Do not call this function from an interrupt while an RTC read/write operation may be occurring
|
||||
*
|
||||
* @param read_rtc pointer to function which returns current UNIX timestamp
|
||||
* @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL
|
||||
* @param init_rtc pointer to funtion which initializes RTC, can be NULL
|
||||
* @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL
|
||||
*/
|
||||
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void));
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,93 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_SEMIHOST_H
|
||||
#define MBED_SEMIHOST_H
|
||||
|
||||
#include "device.h"
|
||||
#include "toolchain.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#if DEVICE_SEMIHOST
|
||||
|
||||
#ifndef __CC_ARM
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
inline int __semihost(int reason, const void *arg) {
|
||||
return __semihosting(reason, (void*)arg);
|
||||
}
|
||||
#else
|
||||
|
||||
#ifdef __thumb__
|
||||
# define AngelSWI 0xAB
|
||||
# define AngelSWIInsn "bkpt"
|
||||
# define AngelSWIAsm bkpt
|
||||
#else
|
||||
# define AngelSWI 0x123456
|
||||
# define AngelSWIInsn "swi"
|
||||
# define AngelSWIAsm swi
|
||||
#endif
|
||||
|
||||
static inline int __semihost(int reason, const void *arg) {
|
||||
int value;
|
||||
|
||||
asm volatile (
|
||||
"mov r0, %1" "\n\t"
|
||||
"mov r1, %2" "\n\t"
|
||||
AngelSWIInsn " %a3" "\n\t"
|
||||
"mov %0, r0"
|
||||
: "=r" (value) /* output operands */
|
||||
: "r" (reason), "r" (arg), "i" (AngelSWI) /* input operands */
|
||||
: "r0", "r1", "r2", "r3", "ip", "lr", "memory", "cc" /* list of clobbered registers */
|
||||
);
|
||||
|
||||
return value;
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if DEVICE_LOCALFILESYSTEM
|
||||
FILEHANDLE semihost_open(const char* name, int openmode);
|
||||
int semihost_close (FILEHANDLE fh);
|
||||
int semihost_read (FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode);
|
||||
int semihost_write (FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode);
|
||||
int semihost_ensure(FILEHANDLE fh);
|
||||
long semihost_flen (FILEHANDLE fh);
|
||||
int semihost_seek (FILEHANDLE fh, long position);
|
||||
int semihost_istty (FILEHANDLE fh);
|
||||
|
||||
int semihost_remove(const char *name);
|
||||
int semihost_rename(const char *old_name, const char *new_name);
|
||||
#endif
|
||||
|
||||
int semihost_uid(char *uid);
|
||||
int semihost_reset(void);
|
||||
int semihost_vbus(void);
|
||||
int semihost_powerdown(void);
|
||||
int semihost_exit(void);
|
||||
|
||||
int semihost_connected(void);
|
||||
int semihost_disabledebug(void);
|
||||
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,241 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_TOOLCHAIN_H
|
||||
#define MBED_TOOLCHAIN_H
|
||||
|
||||
|
||||
// Warning for unsupported compilers
|
||||
#if !defined(__GNUC__) /* GCC */ \
|
||||
&& !defined(__CC_ARM) /* ARMCC */ \
|
||||
&& !defined(__clang__) /* LLVM/Clang */ \
|
||||
&& !defined(__ICCARM__) /* IAR */
|
||||
#warning "This compiler is not yet supported."
|
||||
#endif
|
||||
|
||||
|
||||
// Attributes
|
||||
|
||||
/** PACKED
|
||||
* Pack a structure, preventing any padding from being added between fields.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* typedef struct {
|
||||
* char x;
|
||||
* int y;
|
||||
* } PACKED foo;
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef PACKED
|
||||
#if defined(__ICCARM__)
|
||||
#define PACKED __packed
|
||||
#else
|
||||
#define PACKED __attribute__((packed))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** ALIGN(N)
|
||||
* Declare a variable to be aligned on an N-byte boundary.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* ALIGN(16) char a;
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef ALIGN
|
||||
#if defined(__ICCARM__)
|
||||
#define _ALIGN(N) _Pragma(#N)
|
||||
#define ALIGN(N) _ALIGN(data_alignment=N)
|
||||
#else
|
||||
#define ALIGN(N) __attribute__((aligned(N)))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** UNUSED
|
||||
* Declare a function argument to be unused, suppressing compiler warnings
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* void foo(UNUSED int arg) {
|
||||
*
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef UNUSED
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
#define UNUSED __attribute__((__unused__))
|
||||
#else
|
||||
#define UNUSED
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** WEAK
|
||||
* Mark a function as being weak.
|
||||
*
|
||||
* @note
|
||||
* weak functions are not friendly to making code re-usable, as they can only
|
||||
* be overridden once (and if they are multiply overridden the linker will emit
|
||||
* no warning). You should not normally use weak symbols as part of the API to
|
||||
* re-usable modules.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* WEAK void foo() {
|
||||
* // a weak implementation of foo that can be overriden by a definition
|
||||
* // without __weak
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef WEAK
|
||||
#if defined(__ICCARM__)
|
||||
#define WEAK __weak
|
||||
#else
|
||||
#define WEAK __attribute__((weak))
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** PURE
|
||||
* Hint to the compiler that a function depends only on parameters
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* PURE int foo(int arg){
|
||||
* // no access to global variables
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef PURE
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
#define PURE __attribute__((const))
|
||||
#else
|
||||
#define PURE
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** FORCEINLINE
|
||||
* Declare a function that must always be inlined. Failure to inline
|
||||
* such a function will result in an error.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* FORCEINLINE void foo() {
|
||||
*
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef FORCEINLINE
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
#define FORCEINLINE static inline __attribute__((always_inline))
|
||||
#elif defined(__ICCARM__)
|
||||
#define FORCEINLINE _Pragma("inline=forced") static
|
||||
#else
|
||||
#define FORCEINLINE static inline
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** NORETURN
|
||||
* Declare a function that will never return.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* NORETURN void foo() {
|
||||
* // must never return
|
||||
* while (1) {}
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef NORETURN
|
||||
#if defined(__GNUC__) || defined(__clang__) || defined(__CC_ARM)
|
||||
#define NORETURN __attribute__((noreturn))
|
||||
#elif defined(__ICCARM__)
|
||||
#define NORETURN __noreturn
|
||||
#else
|
||||
#define NORETURN
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** UNREACHABLE
|
||||
* An unreachable statement. If the statement is reached,
|
||||
* behaviour is undefined. Useful in situations where the compiler
|
||||
* cannot deduce the unreachability of code.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* void foo(int arg) {
|
||||
* switch (arg) {
|
||||
* case 1: return 1;
|
||||
* case 2: return 2;
|
||||
* ...
|
||||
* }
|
||||
* UNREACHABLE;
|
||||
* }
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef UNREACHABLE
|
||||
#if (defined(__GNUC__) || defined(__clang__)) && !defined(__CC_ARM)
|
||||
#define UNREACHABLE __builtin_unreachable()
|
||||
#else
|
||||
#define UNREACHABLE while (1)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/** DEPRECATED("message string")
|
||||
* Mark a function declaration as deprecated, if it used then a warning will be
|
||||
* issued by the compiler possibly including the provided message. Note that not
|
||||
* all compilers are able to display the message.
|
||||
*
|
||||
* @code
|
||||
* #include "toolchain.h"
|
||||
*
|
||||
* DEPRECATED("don't foo any more, bar instead")
|
||||
* void foo(int arg);
|
||||
* @endcode
|
||||
*/
|
||||
#ifndef DEPRECATED
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
#define DEPRECATED(M) __attribute__((deprecated(M)))
|
||||
#elif defined(__CC_ARM)
|
||||
#define DEPRECATED(M) __attribute__((deprecated))
|
||||
#else
|
||||
#define DEPRECATED(M)
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
// FILEHANDLE declaration
|
||||
#if defined(TOOLCHAIN_ARM)
|
||||
#include <rt_sys.h>
|
||||
#endif
|
||||
|
||||
#ifndef FILEHANDLE
|
||||
typedef int FILEHANDLE;
|
||||
#endif
|
||||
|
||||
// Backwards compatibility
|
||||
#ifndef EXTERN
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
|
@ -1,66 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MBED_WAIT_API_H
|
||||
#define MBED_WAIT_API_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/** Generic wait functions.
|
||||
*
|
||||
* These provide simple NOP type wait capabilities.
|
||||
*
|
||||
* Example:
|
||||
* @code
|
||||
* #include "mbed.h"
|
||||
*
|
||||
* DigitalOut heartbeat(LED1);
|
||||
*
|
||||
* int main() {
|
||||
* while (1) {
|
||||
* heartbeat = 1;
|
||||
* wait(0.5);
|
||||
* heartbeat = 0;
|
||||
* wait(0.5);
|
||||
* }
|
||||
* }
|
||||
*/
|
||||
|
||||
/** Waits for a number of seconds, with microsecond resolution (within
|
||||
* the accuracy of single precision floating point).
|
||||
*
|
||||
* @param s number of seconds to wait
|
||||
*/
|
||||
void wait(float s);
|
||||
|
||||
/** Waits a number of milliseconds.
|
||||
*
|
||||
* @param ms the whole number of milliseconds to wait
|
||||
*/
|
||||
void wait_ms(int ms);
|
||||
|
||||
/** Waits a number of microseconds.
|
||||
*
|
||||
* @param us the whole number of microseconds to wait
|
||||
*/
|
||||
void wait_us(int us);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,82 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "BusIn.h"
|
||||
#include "mbed_assert.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
BusIn::BusIn(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusIn::BusIn(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalIn(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusIn::~BusIn() {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
delete _pin[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BusIn::read() {
|
||||
int v = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
v |= _pin[i]->read() << i;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void BusIn::mode(PinMode pull) {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->mode(pull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
BusIn::operator int() {
|
||||
return read();
|
||||
}
|
||||
|
||||
DigitalIn& BusIn::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
|
@ -1,115 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "BusInOut.h"
|
||||
#include "mbed_assert.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
BusInOut::BusInOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusInOut::BusInOut(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalInOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusInOut::~BusInOut() {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
delete _pin[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusInOut::write(int value) {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->write((value >> i) & 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BusInOut::read() {
|
||||
int v = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
v |= _pin[i]->read() << i;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
void BusInOut::output() {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->output();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusInOut::input() {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->input();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusInOut::mode(PinMode pull) {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->mode(pull);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
BusInOut& BusInOut::operator= (int v) {
|
||||
write(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BusInOut& BusInOut::operator= (BusInOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
DigitalInOut& BusInOut::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
BusInOut::operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
|
@ -1,91 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "BusOut.h"
|
||||
#include "mbed_assert.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
BusOut::BusOut(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4, PinName p5, PinName p6, PinName p7, PinName p8, PinName p9, PinName p10, PinName p11, PinName p12, PinName p13, PinName p14, PinName p15) {
|
||||
PinName pins[16] = {p0, p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15};
|
||||
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusOut::BusOut(PinName pins[16]) {
|
||||
_nc_mask = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
_pin[i] = (pins[i] != NC) ? new DigitalOut(pins[i]) : 0;
|
||||
if (pins[i] != NC) {
|
||||
_nc_mask |= (1 << i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
BusOut::~BusOut() {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
delete _pin[i];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BusOut::write(int value) {
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
_pin[i]->write((value >> i) & 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int BusOut::read() {
|
||||
int v = 0;
|
||||
for (int i=0; i<16; i++) {
|
||||
if (_pin[i] != 0) {
|
||||
v |= _pin[i]->read() << i;
|
||||
}
|
||||
}
|
||||
return v;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
BusOut& BusOut::operator= (int v) {
|
||||
write(v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
BusOut& BusOut::operator= (BusOut& rhs) {
|
||||
write(rhs.read());
|
||||
return *this;
|
||||
}
|
||||
|
||||
DigitalOut& BusOut::operator[] (int index) {
|
||||
MBED_ASSERT(index >= 0 && index <= 16);
|
||||
MBED_ASSERT(_pin[index]);
|
||||
return *_pin[index];
|
||||
}
|
||||
|
||||
BusOut::operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
|
@ -1,86 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "CAN.h"
|
||||
|
||||
#if DEVICE_CAN
|
||||
|
||||
#include "cmsis.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
CAN::CAN(PinName rd, PinName td) : _can(), _irq() {
|
||||
can_init(&_can, rd, td);
|
||||
can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
|
||||
}
|
||||
|
||||
CAN::~CAN() {
|
||||
can_irq_free(&_can);
|
||||
can_free(&_can);
|
||||
}
|
||||
|
||||
int CAN::frequency(int f) {
|
||||
return can_frequency(&_can, f);
|
||||
}
|
||||
|
||||
int CAN::write(CANMessage msg) {
|
||||
return can_write(&_can, msg, 0);
|
||||
}
|
||||
|
||||
int CAN::read(CANMessage &msg, int handle) {
|
||||
return can_read(&_can, &msg, handle);
|
||||
}
|
||||
|
||||
void CAN::reset() {
|
||||
can_reset(&_can);
|
||||
}
|
||||
|
||||
unsigned char CAN::rderror() {
|
||||
return can_rderror(&_can);
|
||||
}
|
||||
|
||||
unsigned char CAN::tderror() {
|
||||
return can_tderror(&_can);
|
||||
}
|
||||
|
||||
void CAN::monitor(bool silent) {
|
||||
can_monitor(&_can, (silent) ? 1 : 0);
|
||||
}
|
||||
|
||||
int CAN::mode(Mode mode) {
|
||||
return can_mode(&_can, (CanMode)mode);
|
||||
}
|
||||
|
||||
int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) {
|
||||
return can_filter(&_can, id, mask, format, handle);
|
||||
}
|
||||
|
||||
void CAN::attach(Callback<void()> func, IrqType type) {
|
||||
if (func) {
|
||||
_irq[(CanIrqType)type].attach(func);
|
||||
can_irq_set(&_can, (CanIrqType)type, 1);
|
||||
} else {
|
||||
can_irq_set(&_can, (CanIrqType)type, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void CAN::_irq_handler(uint32_t id, CanIrqType type) {
|
||||
CAN *handler = (CAN*)id;
|
||||
handler->_irq[type].call();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,82 +0,0 @@
|
|||
#include "CallChain.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
CallChain::CallChain(int size) : _chain(), _size(size), _elements(0) {
|
||||
_chain = new pFunctionPointer_t[size]();
|
||||
}
|
||||
|
||||
CallChain::~CallChain() {
|
||||
clear();
|
||||
delete _chain;
|
||||
}
|
||||
|
||||
pFunctionPointer_t CallChain::add(Callback<void()> func) {
|
||||
_check_size();
|
||||
_chain[_elements] = new Callback<void()>(func);
|
||||
_elements ++;
|
||||
return _chain[_elements];
|
||||
}
|
||||
|
||||
pFunctionPointer_t CallChain::add_front(Callback<void()> func) {
|
||||
_check_size();
|
||||
memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t));
|
||||
_chain[0] = new Callback<void()>(func);
|
||||
_elements ++;
|
||||
return _chain[0];
|
||||
}
|
||||
|
||||
int CallChain::size() const {
|
||||
return _elements;
|
||||
}
|
||||
|
||||
pFunctionPointer_t CallChain::get(int i) const {
|
||||
if (i < 0 || i >= _elements)
|
||||
return NULL;
|
||||
return _chain[i];
|
||||
}
|
||||
|
||||
int CallChain::find(pFunctionPointer_t f) const {
|
||||
for (int i = 0; i < _elements; i++)
|
||||
if (f == _chain[i])
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
void CallChain::clear() {
|
||||
for(int i = 0; i < _elements; i ++) {
|
||||
delete _chain[i];
|
||||
_chain[i] = NULL;
|
||||
}
|
||||
_elements = 0;
|
||||
}
|
||||
|
||||
bool CallChain::remove(pFunctionPointer_t f) {
|
||||
int i;
|
||||
|
||||
if ((i = find(f)) == -1)
|
||||
return false;
|
||||
if (i != _elements - 1)
|
||||
memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t));
|
||||
delete f;
|
||||
_elements --;
|
||||
return true;
|
||||
}
|
||||
|
||||
void CallChain::call() {
|
||||
for(int i = 0; i < _elements; i++)
|
||||
_chain[i]->call();
|
||||
}
|
||||
|
||||
void CallChain::_check_size() {
|
||||
if (_elements < _size)
|
||||
return;
|
||||
_size = (_size < 4) ? 4 : _size + 4;
|
||||
pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size]();
|
||||
memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t));
|
||||
delete _chain;
|
||||
_chain = new_chain;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,73 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Ethernet.h"
|
||||
|
||||
#if DEVICE_ETHERNET
|
||||
|
||||
#include "ethernet_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
Ethernet::Ethernet() {
|
||||
ethernet_init();
|
||||
}
|
||||
|
||||
Ethernet::~Ethernet() {
|
||||
ethernet_free();
|
||||
}
|
||||
|
||||
int Ethernet::write(const char *data, int size) {
|
||||
return ethernet_write(data, size);
|
||||
}
|
||||
|
||||
int Ethernet::send() {
|
||||
return ethernet_send();
|
||||
}
|
||||
|
||||
int Ethernet::receive() {
|
||||
return ethernet_receive();
|
||||
}
|
||||
|
||||
int Ethernet::read(char *data, int size) {
|
||||
return ethernet_read(data, size);
|
||||
}
|
||||
|
||||
void Ethernet::address(char *mac) {
|
||||
return ethernet_address(mac);
|
||||
}
|
||||
|
||||
int Ethernet::link() {
|
||||
return ethernet_link();
|
||||
}
|
||||
|
||||
void Ethernet::set_link(Mode mode) {
|
||||
int speed = -1;
|
||||
int duplex = 0;
|
||||
|
||||
switch(mode) {
|
||||
case AutoNegotiate : speed = -1; duplex = 0; break;
|
||||
case HalfDuplex10 : speed = 0; duplex = 0; break;
|
||||
case FullDuplex10 : speed = 0; duplex = 1; break;
|
||||
case HalfDuplex100 : speed = 1; duplex = 0; break;
|
||||
case FullDuplex100 : speed = 1; duplex = 1; break;
|
||||
}
|
||||
|
||||
ethernet_set_link(speed, duplex);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,82 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FileBase.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FileBase *FileBase::_head = NULL;
|
||||
|
||||
FileBase::FileBase(const char *name, PathType t) : _next(NULL),
|
||||
_name(name),
|
||||
_path_type(t) {
|
||||
if (name != NULL) {
|
||||
// put this object at head of the list
|
||||
_next = _head;
|
||||
_head = this;
|
||||
} else {
|
||||
_next = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
FileBase::~FileBase() {
|
||||
if (_name != NULL) {
|
||||
// remove this object from the list
|
||||
if (_head == this) { // first in the list, so just drop me
|
||||
_head = _next;
|
||||
} else { // find the object before me, then drop me
|
||||
FileBase *p = _head;
|
||||
while (p->_next != this) {
|
||||
p = p->_next;
|
||||
}
|
||||
p->_next = _next;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FileBase *FileBase::lookup(const char *name, unsigned int len) {
|
||||
FileBase *p = _head;
|
||||
while (p != NULL) {
|
||||
/* Check that p->_name matches name and is the correct length */
|
||||
if (p->_name != NULL && std::strncmp(p->_name, name, len) == 0 && std::strlen(p->_name) == len) {
|
||||
return p;
|
||||
}
|
||||
p = p->_next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FileBase *FileBase::get(int n) {
|
||||
FileBase *p = _head;
|
||||
int m = 0;
|
||||
while (p != NULL) {
|
||||
if (m == n) return p;
|
||||
|
||||
m++;
|
||||
p = p->_next;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
const char* FileBase::getName(void) {
|
||||
return _name;
|
||||
}
|
||||
|
||||
PathType FileBase::getPathType(void) {
|
||||
return _path_type;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FileLike.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FileLike::FileLike(const char *name) : FileHandle(), FileBase(name, FilePathType) {
|
||||
|
||||
}
|
||||
|
||||
FileLike::~FileLike() {
|
||||
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,76 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FilePath.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
FilePath::FilePath(const char* file_path) : file_name(NULL), fb(NULL) {
|
||||
if ((file_path[0] != '/') || (file_path[1] == 0)) return;
|
||||
|
||||
const char* file_system = &file_path[1];
|
||||
file_name = file_system;
|
||||
int len = 0;
|
||||
while (true) {
|
||||
char c = *file_name;
|
||||
if (c == '/') { // end of object name
|
||||
file_name++; // point to one char after the '/'
|
||||
break;
|
||||
}
|
||||
if (c == 0) { // end of object name, with no filename
|
||||
break;
|
||||
}
|
||||
len++;
|
||||
file_name++;
|
||||
}
|
||||
|
||||
fb = FileBase::lookup(file_system, len);
|
||||
}
|
||||
|
||||
const char* FilePath::fileName(void) {
|
||||
return file_name;
|
||||
}
|
||||
|
||||
bool FilePath::isFileSystem(void) {
|
||||
if (NULL == fb)
|
||||
return false;
|
||||
return (fb->getPathType() == FileSystemPathType);
|
||||
}
|
||||
|
||||
FileSystemLike* FilePath::fileSystem(void) {
|
||||
if (isFileSystem()) {
|
||||
return (FileSystemLike*)fb;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool FilePath::isFile(void) {
|
||||
if (NULL == fb)
|
||||
return false;
|
||||
return (fb->getPathType() == FilePathType);
|
||||
}
|
||||
|
||||
FileLike* FilePath::file(void) {
|
||||
if (isFile()) {
|
||||
return (FileLike*)fb;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool FilePath::exists(void) {
|
||||
return fb != NULL;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,77 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "FileSystemLike.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
class BaseDirHandle : public DirHandle {
|
||||
public:
|
||||
/*
|
||||
We keep track of our current location as the n'th object in the
|
||||
FileSystemLike list. Using a Base* instead would cause problems if that
|
||||
object were to be destroyed between readdirs.
|
||||
Using this method does mean though that destroying/creating objects can
|
||||
give unusual results from readdir.
|
||||
*/
|
||||
off_t n;
|
||||
struct dirent cur_entry;
|
||||
|
||||
BaseDirHandle() : n(0), cur_entry() {
|
||||
}
|
||||
|
||||
virtual int closedir() {
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual struct dirent *readdir() {
|
||||
FileBase *ptr = FileBase::get(n);
|
||||
if (ptr == NULL) return NULL;
|
||||
|
||||
/* Increment n, so next readdir gets the next item */
|
||||
n++;
|
||||
|
||||
/* Setup cur entry and return a pointer to it */
|
||||
std::strncpy(cur_entry.d_name, ptr->getName(), NAME_MAX);
|
||||
return &cur_entry;
|
||||
}
|
||||
|
||||
virtual off_t telldir() {
|
||||
return n;
|
||||
}
|
||||
|
||||
virtual void seekdir(off_t offset) {
|
||||
n = offset;
|
||||
}
|
||||
|
||||
virtual void rewinddir() {
|
||||
n = 0;
|
||||
}
|
||||
};
|
||||
|
||||
FileSystemLike::FileSystemLike(const char *name) : FileBase(name, FileSystemPathType) {
|
||||
|
||||
}
|
||||
|
||||
FileSystemLike::~FileSystemLike() {
|
||||
|
||||
}
|
||||
|
||||
DirHandle *FileSystemLike::opendir() {
|
||||
return new BaseDirHandle();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,128 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "I2C.h"
|
||||
|
||||
#if DEVICE_I2C
|
||||
|
||||
namespace mbed {
|
||||
|
||||
I2C *I2C::_owner = NULL;
|
||||
|
||||
I2C::I2C(PinName sda, PinName scl) :
|
||||
#if DEVICE_I2C_ASYNCH
|
||||
_irq(this), _usage(DMA_USAGE_NEVER),
|
||||
#endif
|
||||
_i2c(), _hz(100000) {
|
||||
// The init function also set the frequency to 100000
|
||||
i2c_init(&_i2c, sda, scl);
|
||||
|
||||
// Used to avoid unnecessary frequency updates
|
||||
_owner = this;
|
||||
}
|
||||
|
||||
void I2C::frequency(int hz) {
|
||||
_hz = hz;
|
||||
|
||||
// We want to update the frequency even if we are already the bus owners
|
||||
i2c_frequency(&_i2c, _hz);
|
||||
|
||||
// Updating the frequency of the bus we become the owners of it
|
||||
_owner = this;
|
||||
}
|
||||
|
||||
void I2C::aquire() {
|
||||
if (_owner != this) {
|
||||
i2c_frequency(&_i2c, _hz);
|
||||
_owner = this;
|
||||
}
|
||||
}
|
||||
|
||||
// write - Master Transmitter Mode
|
||||
int I2C::write(int address, const char* data, int length, bool repeated) {
|
||||
aquire();
|
||||
|
||||
int stop = (repeated) ? 0 : 1;
|
||||
int written = i2c_write(&_i2c, address, data, length, stop);
|
||||
|
||||
return length != written;
|
||||
}
|
||||
|
||||
int I2C::write(int data) {
|
||||
return i2c_byte_write(&_i2c, data);
|
||||
}
|
||||
|
||||
// read - Master Reciever Mode
|
||||
int I2C::read(int address, char* data, int length, bool repeated) {
|
||||
aquire();
|
||||
|
||||
int stop = (repeated) ? 0 : 1;
|
||||
int read = i2c_read(&_i2c, address, data, length, stop);
|
||||
|
||||
return length != read;
|
||||
}
|
||||
|
||||
int I2C::read(int ack) {
|
||||
if (ack) {
|
||||
return i2c_byte_read(&_i2c, 0);
|
||||
} else {
|
||||
return i2c_byte_read(&_i2c, 1);
|
||||
}
|
||||
}
|
||||
|
||||
void I2C::start(void) {
|
||||
i2c_start(&_i2c);
|
||||
}
|
||||
|
||||
void I2C::stop(void) {
|
||||
i2c_stop(&_i2c);
|
||||
}
|
||||
|
||||
#if DEVICE_I2C_ASYNCH
|
||||
|
||||
int I2C::transfer(int address, const char *tx_buffer, int tx_length, char *rx_buffer, int rx_length, const event_callback_t& callback, int event, bool repeated)
|
||||
{
|
||||
if (i2c_active(&_i2c)) {
|
||||
return -1; // transaction ongoing
|
||||
}
|
||||
aquire();
|
||||
|
||||
_callback = callback;
|
||||
int stop = (repeated) ? 0 : 1;
|
||||
_irq.callback(&I2C::irq_handler_asynch);
|
||||
i2c_transfer_asynch(&_i2c, (void *)tx_buffer, tx_length, (void *)rx_buffer, rx_length, address, stop, _irq.entry(), event, _usage);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void I2C::abort_transfer(void)
|
||||
{
|
||||
i2c_abort_asynch(&_i2c);
|
||||
}
|
||||
|
||||
void I2C::irq_handler_asynch(void)
|
||||
{
|
||||
int event = i2c_irq_handler_asynch(&_i2c);
|
||||
if (_callback && event) {
|
||||
_callback.call(event);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,63 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "I2CSlave.h"
|
||||
|
||||
#if DEVICE_I2CSLAVE
|
||||
|
||||
namespace mbed {
|
||||
|
||||
I2CSlave::I2CSlave(PinName sda, PinName scl) : _i2c() {
|
||||
i2c_init(&_i2c, sda, scl);
|
||||
i2c_frequency(&_i2c, 100000);
|
||||
i2c_slave_mode(&_i2c, 1);
|
||||
}
|
||||
|
||||
void I2CSlave::frequency(int hz) {
|
||||
i2c_frequency(&_i2c, hz);
|
||||
}
|
||||
|
||||
void I2CSlave::address(int address) {
|
||||
int addr = (address & 0xFF) | 1;
|
||||
i2c_slave_address(&_i2c, 0, addr, 0);
|
||||
}
|
||||
|
||||
int I2CSlave::receive(void) {
|
||||
return i2c_slave_receive(&_i2c);
|
||||
}
|
||||
|
||||
int I2CSlave::read(char *data, int length) {
|
||||
return i2c_slave_read(&_i2c, data, length) != length;
|
||||
}
|
||||
|
||||
int I2CSlave::read(void) {
|
||||
return i2c_byte_read(&_i2c, 0);
|
||||
}
|
||||
|
||||
int I2CSlave::write(const char *data, int length) {
|
||||
return i2c_slave_write(&_i2c, data, length) != length;
|
||||
}
|
||||
|
||||
int I2CSlave::write(int data) {
|
||||
return i2c_byte_write(&_i2c, data);
|
||||
}
|
||||
|
||||
void I2CSlave::stop(void) {
|
||||
i2c_stop(&_i2c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,87 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "InterruptIn.h"
|
||||
|
||||
#if DEVICE_INTERRUPTIN
|
||||
|
||||
namespace mbed {
|
||||
|
||||
InterruptIn::InterruptIn(PinName pin) : gpio(),
|
||||
gpio_irq(),
|
||||
_rise(),
|
||||
_fall() {
|
||||
gpio_irq_init(&gpio_irq, pin, (&InterruptIn::_irq_handler), (uint32_t)this);
|
||||
gpio_init_in(&gpio, pin);
|
||||
}
|
||||
|
||||
InterruptIn::~InterruptIn() {
|
||||
gpio_irq_free(&gpio_irq);
|
||||
}
|
||||
|
||||
int InterruptIn::read() {
|
||||
return gpio_read(&gpio);
|
||||
}
|
||||
|
||||
void InterruptIn::mode(PinMode pull) {
|
||||
gpio_mode(&gpio, pull);
|
||||
}
|
||||
|
||||
void InterruptIn::rise(Callback<void()> func) {
|
||||
if (func) {
|
||||
_rise.attach(func);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 1);
|
||||
} else {
|
||||
_rise.attach(NULL);
|
||||
gpio_irq_set(&gpio_irq, IRQ_RISE, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void InterruptIn::fall(Callback<void()> func) {
|
||||
if (func) {
|
||||
_fall.attach(func);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 1);
|
||||
} else {
|
||||
_fall.attach(NULL);
|
||||
gpio_irq_set(&gpio_irq, IRQ_FALL, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) {
|
||||
InterruptIn *handler = (InterruptIn*)id;
|
||||
switch (event) {
|
||||
case IRQ_RISE: handler->_rise.call(); break;
|
||||
case IRQ_FALL: handler->_fall.call(); break;
|
||||
case IRQ_NONE: break;
|
||||
}
|
||||
}
|
||||
|
||||
void InterruptIn::enable_irq() {
|
||||
gpio_irq_enable(&gpio_irq);
|
||||
}
|
||||
|
||||
void InterruptIn::disable_irq() {
|
||||
gpio_irq_disable(&gpio_irq);
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
InterruptIn::operator int() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,86 +0,0 @@
|
|||
#include "cmsis.h"
|
||||
#if defined(NVIC_NUM_VECTORS)
|
||||
|
||||
#include "InterruptManager.h"
|
||||
#include <string.h>
|
||||
|
||||
#define CHAIN_INITIAL_SIZE 4
|
||||
|
||||
namespace mbed {
|
||||
|
||||
typedef void (*pvoidf)(void);
|
||||
|
||||
InterruptManager* InterruptManager::_instance = (InterruptManager*)NULL;
|
||||
|
||||
InterruptManager* InterruptManager::get() {
|
||||
if (NULL == _instance)
|
||||
_instance = new InterruptManager();
|
||||
return _instance;
|
||||
}
|
||||
|
||||
InterruptManager::InterruptManager() {
|
||||
memset(_chains, 0, NVIC_NUM_VECTORS * sizeof(CallChain*));
|
||||
}
|
||||
|
||||
void InterruptManager::destroy() {
|
||||
// Not a good idea to call this unless NO interrupt at all
|
||||
// is under the control of the handler; otherwise, a system crash
|
||||
// is very likely to occur
|
||||
if (NULL != _instance) {
|
||||
delete _instance;
|
||||
_instance = (InterruptManager*)NULL;
|
||||
}
|
||||
}
|
||||
|
||||
InterruptManager::~InterruptManager() {
|
||||
for(int i = 0; i < NVIC_NUM_VECTORS; i++)
|
||||
if (NULL != _chains[i])
|
||||
delete _chains[i];
|
||||
}
|
||||
|
||||
bool InterruptManager::must_replace_vector(IRQn_Type irq) {
|
||||
int irq_pos = get_irq_index(irq);
|
||||
|
||||
if (NULL == _chains[irq_pos]) {
|
||||
_chains[irq_pos] = new CallChain(CHAIN_INITIAL_SIZE);
|
||||
_chains[irq_pos]->add((pvoidf)NVIC_GetVector(irq));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pFunctionPointer_t InterruptManager::add_common(void (*function)(void), IRQn_Type irq, bool front) {
|
||||
int irq_pos = get_irq_index(irq);
|
||||
bool change = must_replace_vector(irq);
|
||||
|
||||
pFunctionPointer_t pf = front ? _chains[irq_pos]->add_front(function) : _chains[irq_pos]->add(function);
|
||||
if (change)
|
||||
NVIC_SetVector(irq, (uint32_t)&InterruptManager::static_irq_helper);
|
||||
return pf;
|
||||
}
|
||||
|
||||
bool InterruptManager::remove_handler(pFunctionPointer_t handler, IRQn_Type irq) {
|
||||
int irq_pos = get_irq_index(irq);
|
||||
|
||||
if (NULL == _chains[irq_pos])
|
||||
return false;
|
||||
if (!_chains[irq_pos]->remove(handler))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
void InterruptManager::irq_helper() {
|
||||
_chains[__get_IPSR()]->call();
|
||||
}
|
||||
|
||||
int InterruptManager::get_irq_index(IRQn_Type irq) {
|
||||
return (int)irq + NVIC_USER_IRQ_OFFSET;
|
||||
}
|
||||
|
||||
void InterruptManager::static_irq_helper() {
|
||||
InterruptManager::get()->irq_helper();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,223 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "LocalFileSystem.h"
|
||||
|
||||
#if DEVICE_LOCALFILESYSTEM
|
||||
|
||||
#include "semihost_api.h"
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
|
||||
namespace mbed {
|
||||
|
||||
/* Extension to FINFO type defined in RTL.h (in Keil RL) - adds 'create time'. */
|
||||
typedef struct {
|
||||
unsigned char hr; /* Hours [0..23] */
|
||||
unsigned char min; /* Minutes [0..59] */
|
||||
unsigned char sec; /* Seconds [0..59] */
|
||||
unsigned char day; /* Day [1..31] */
|
||||
unsigned char mon; /* Month [1..12] */
|
||||
unsigned short year; /* Year [1980..2107] */
|
||||
} FTIME;
|
||||
|
||||
typedef struct { /* File Search info record */
|
||||
char name[32]; /* File name */
|
||||
long size; /* File size in bytes */
|
||||
int fileID; /* System File Identification */
|
||||
FTIME create_time; /* Date & time file was created */
|
||||
FTIME write_time; /* Date & time of last write */
|
||||
} XFINFO;
|
||||
|
||||
#define RESERVED_FOR_USER_APPLICATIONS (0x100) /* 0x100 - 0x1ff */
|
||||
#define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
|
||||
|
||||
static int xffind (const char *pattern, XFINFO *info) {
|
||||
unsigned param[4];
|
||||
|
||||
param[0] = (unsigned long)pattern;
|
||||
param[1] = (unsigned long)strlen(pattern);
|
||||
param[2] = (unsigned long)info;
|
||||
param[3] = (unsigned long)sizeof(XFINFO);
|
||||
|
||||
return __semihost(USR_XFFIND, param);
|
||||
}
|
||||
|
||||
#define OPEN_R 0
|
||||
#define OPEN_B 1
|
||||
#define OPEN_PLUS 2
|
||||
#define OPEN_W 4
|
||||
#define OPEN_A 8
|
||||
#define OPEN_INVALID -1
|
||||
|
||||
int posix_to_semihost_open_flags(int flags) {
|
||||
/* POSIX flags -> semihosting open mode */
|
||||
int openmode;
|
||||
if (flags & O_RDWR) {
|
||||
/* a plus mode */
|
||||
openmode = OPEN_PLUS;
|
||||
if (flags & O_APPEND) {
|
||||
openmode |= OPEN_A;
|
||||
} else if (flags & O_TRUNC) {
|
||||
openmode |= OPEN_W;
|
||||
} else {
|
||||
openmode |= OPEN_R;
|
||||
}
|
||||
} else if (flags & O_WRONLY) {
|
||||
/* write or append */
|
||||
if (flags & O_APPEND) {
|
||||
openmode = OPEN_A;
|
||||
} else {
|
||||
openmode = OPEN_W;
|
||||
}
|
||||
} else if (flags == O_RDONLY) {
|
||||
/* read mode */
|
||||
openmode = OPEN_R;
|
||||
} else {
|
||||
/* invalid flags */
|
||||
openmode = OPEN_INVALID;
|
||||
}
|
||||
|
||||
return openmode;
|
||||
}
|
||||
|
||||
FILEHANDLE local_file_open(const char* name, int flags) {
|
||||
int openmode = posix_to_semihost_open_flags(flags);
|
||||
if (openmode == OPEN_INVALID) {
|
||||
return (FILEHANDLE)NULL;
|
||||
}
|
||||
|
||||
FILEHANDLE fh = semihost_open(name, openmode);
|
||||
if (fh == -1) {
|
||||
return (FILEHANDLE)NULL;
|
||||
}
|
||||
|
||||
return fh;
|
||||
}
|
||||
|
||||
LocalFileHandle::LocalFileHandle(FILEHANDLE fh) : _fh(fh), pos(0) {
|
||||
}
|
||||
|
||||
int LocalFileHandle::close() {
|
||||
int retval = semihost_close(_fh);
|
||||
delete this;
|
||||
return retval;
|
||||
}
|
||||
|
||||
ssize_t LocalFileHandle::write(const void *buffer, size_t length) {
|
||||
ssize_t n = semihost_write(_fh, (const unsigned char*)buffer, length, 0); // number of characters not written
|
||||
n = length - n; // number of characters written
|
||||
pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
ssize_t LocalFileHandle::read(void *buffer, size_t length) {
|
||||
ssize_t n = semihost_read(_fh, (unsigned char*)buffer, length, 0); // number of characters not read
|
||||
n = length - n; // number of characters read
|
||||
pos += n;
|
||||
return n;
|
||||
}
|
||||
|
||||
int LocalFileHandle::isatty() {
|
||||
return semihost_istty(_fh);
|
||||
}
|
||||
|
||||
off_t LocalFileHandle::lseek(off_t position, int whence) {
|
||||
if (whence == SEEK_CUR) {
|
||||
position += pos;
|
||||
} else if (whence == SEEK_END) {
|
||||
position += semihost_flen(_fh);
|
||||
} /* otherwise SEEK_SET, so position is fine */
|
||||
|
||||
/* Always seems to return -1, so just ignore for now. */
|
||||
semihost_seek(_fh, position);
|
||||
pos = position;
|
||||
return position;
|
||||
}
|
||||
|
||||
int LocalFileHandle::fsync() {
|
||||
return semihost_ensure(_fh);
|
||||
}
|
||||
|
||||
off_t LocalFileHandle::flen() {
|
||||
return semihost_flen(_fh);
|
||||
}
|
||||
|
||||
class LocalDirHandle : public DirHandle {
|
||||
|
||||
public:
|
||||
struct dirent cur_entry;
|
||||
XFINFO info;
|
||||
|
||||
LocalDirHandle() : cur_entry(), info() {
|
||||
}
|
||||
|
||||
virtual int closedir() {
|
||||
delete this;
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual struct dirent *readdir() {
|
||||
if (xffind("*", &info)!=0) {
|
||||
return NULL;
|
||||
}
|
||||
memcpy(cur_entry.d_name, info.name, sizeof(info.name));
|
||||
return &cur_entry;
|
||||
}
|
||||
|
||||
virtual void rewinddir() {
|
||||
info.fileID = 0;
|
||||
}
|
||||
|
||||
virtual off_t telldir() {
|
||||
return info.fileID;
|
||||
}
|
||||
|
||||
virtual void seekdir(off_t offset) {
|
||||
info.fileID = offset;
|
||||
}
|
||||
};
|
||||
|
||||
FileHandle *LocalFileSystem::open(const char* name, int flags) {
|
||||
/* reject filenames with / in them */
|
||||
for (const char *tmp = name; *tmp; tmp++) {
|
||||
if (*tmp == '/') {
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
int openmode = posix_to_semihost_open_flags(flags);
|
||||
if (openmode == OPEN_INVALID) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
FILEHANDLE fh = semihost_open(name, openmode);
|
||||
if (fh == -1) {
|
||||
return NULL;
|
||||
}
|
||||
return new LocalFileHandle(fh);
|
||||
}
|
||||
|
||||
int LocalFileSystem::remove(const char *filename) {
|
||||
return semihost_remove(filename);
|
||||
}
|
||||
|
||||
DirHandle *LocalFileSystem::opendir(const char *name) {
|
||||
return new LocalDirHandle();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,70 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "RawSerial.h"
|
||||
#include "wait_api.h"
|
||||
#include <cstdarg>
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
#define STRING_STACK_LIMIT 120
|
||||
|
||||
namespace mbed {
|
||||
|
||||
RawSerial::RawSerial(PinName tx, PinName rx) : SerialBase(tx, rx) {
|
||||
}
|
||||
|
||||
int RawSerial::getc() {
|
||||
return _base_getc();
|
||||
}
|
||||
|
||||
int RawSerial::putc(int c) {
|
||||
return _base_putc(c);
|
||||
}
|
||||
|
||||
int RawSerial::puts(const char *str) {
|
||||
while (*str)
|
||||
putc(*str ++);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Experimental support for printf in RawSerial. No Stream inheritance
|
||||
// means we can't call printf() directly, so we use sprintf() instead.
|
||||
// We only call malloc() for the sprintf() buffer if the buffer
|
||||
// length is above a certain threshold, otherwise we use just the stack.
|
||||
int RawSerial::printf(const char *format, ...) {
|
||||
std::va_list arg;
|
||||
va_start(arg, format);
|
||||
// ARMCC microlib does not properly handle a size of 0.
|
||||
// As a workaround supply a dummy buffer with a size of 1.
|
||||
char dummy_buf[1];
|
||||
int len = vsnprintf(dummy_buf, sizeof(dummy_buf), format, arg);
|
||||
if (len < STRING_STACK_LIMIT) {
|
||||
char temp[STRING_STACK_LIMIT];
|
||||
vsprintf(temp, format, arg);
|
||||
puts(temp);
|
||||
} else {
|
||||
char *temp = new char[len + 1];
|
||||
vsprintf(temp, format, arg);
|
||||
puts(temp);
|
||||
delete[] temp;
|
||||
}
|
||||
va_end(arg);
|
||||
return len;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,180 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "SPI.h"
|
||||
|
||||
#if DEVICE_SPI
|
||||
|
||||
namespace mbed {
|
||||
|
||||
#if DEVICE_SPI_ASYNCH && TRANSACTION_QUEUE_SIZE_SPI
|
||||
CircularBuffer<Transaction<SPI>, TRANSACTION_QUEUE_SIZE_SPI> SPI::_transaction_buffer;
|
||||
#endif
|
||||
|
||||
SPI::SPI(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
|
||||
_spi(),
|
||||
#if DEVICE_SPI_ASYNCH
|
||||
_irq(this),
|
||||
_usage(DMA_USAGE_NEVER),
|
||||
#endif
|
||||
_bits(8),
|
||||
_mode(0),
|
||||
_hz(1000000) {
|
||||
spi_init(&_spi, mosi, miso, sclk, ssel);
|
||||
spi_format(&_spi, _bits, _mode, 0);
|
||||
spi_frequency(&_spi, _hz);
|
||||
}
|
||||
|
||||
void SPI::format(int bits, int mode) {
|
||||
_bits = bits;
|
||||
_mode = mode;
|
||||
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
|
||||
aquire();
|
||||
}
|
||||
|
||||
void SPI::frequency(int hz) {
|
||||
_hz = hz;
|
||||
SPI::_owner = NULL; // Not that elegant, but works. rmeyer
|
||||
aquire();
|
||||
}
|
||||
|
||||
SPI* SPI::_owner = NULL;
|
||||
|
||||
// ignore the fact there are multiple physical spis, and always update if it wasnt us last
|
||||
void SPI::aquire() {
|
||||
if (_owner != this) {
|
||||
spi_format(&_spi, _bits, _mode, 0);
|
||||
spi_frequency(&_spi, _hz);
|
||||
_owner = this;
|
||||
}
|
||||
}
|
||||
|
||||
int SPI::write(int value) {
|
||||
aquire();
|
||||
return spi_master_write(&_spi, value);
|
||||
}
|
||||
|
||||
#if DEVICE_SPI_ASYNCH
|
||||
|
||||
int SPI::transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
|
||||
{
|
||||
if (spi_active(&_spi)) {
|
||||
return queue_transfer(tx_buffer, tx_length, rx_buffer, rx_length, bit_width, callback, event);
|
||||
}
|
||||
start_transfer(tx_buffer, tx_length, rx_buffer, rx_length, bit_width, callback, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SPI::abort_transfer()
|
||||
{
|
||||
spi_abort_asynch(&_spi);
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
dequeue_transaction();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void SPI::clear_transfer_buffer()
|
||||
{
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
_transaction_buffer.reset();
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPI::abort_all_transfers()
|
||||
{
|
||||
clear_transfer_buffer();
|
||||
abort_transfer();
|
||||
}
|
||||
|
||||
int SPI::set_dma_usage(DMAUsage usage)
|
||||
{
|
||||
if (spi_active(&_spi)) {
|
||||
return -1;
|
||||
}
|
||||
_usage = usage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SPI::queue_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
|
||||
{
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
transaction_t t;
|
||||
|
||||
t.tx_buffer = const_cast<void *>(tx_buffer);
|
||||
t.tx_length = tx_length;
|
||||
t.rx_buffer = rx_buffer;
|
||||
t.rx_length = rx_length;
|
||||
t.event = event;
|
||||
t.callback = callback;
|
||||
t.width = bit_width;
|
||||
Transaction<SPI> transaction(this, t);
|
||||
if (_transaction_buffer.full()) {
|
||||
return -1; // the buffer is full
|
||||
} else {
|
||||
_transaction_buffer.push(transaction);
|
||||
return 0;
|
||||
}
|
||||
#else
|
||||
return -1;
|
||||
#endif
|
||||
}
|
||||
|
||||
void SPI::start_transfer(const void *tx_buffer, int tx_length, void *rx_buffer, int rx_length, unsigned char bit_width, const event_callback_t& callback, int event)
|
||||
{
|
||||
aquire();
|
||||
_callback = callback;
|
||||
_irq.callback(&SPI::irq_handler_asynch);
|
||||
spi_master_transfer(&_spi, tx_buffer, tx_length, rx_buffer, rx_length, bit_width, _irq.entry(), event , _usage);
|
||||
}
|
||||
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
|
||||
void SPI::start_transaction(transaction_t *data)
|
||||
{
|
||||
start_transfer(data->tx_buffer, data->tx_length, data->rx_buffer, data->rx_length, data->width, data->callback, data->event);
|
||||
}
|
||||
|
||||
void SPI::dequeue_transaction()
|
||||
{
|
||||
Transaction<SPI> t;
|
||||
if (_transaction_buffer.pop(t)) {
|
||||
SPI* obj = t.get_object();
|
||||
transaction_t* data = t.get_transaction();
|
||||
obj->start_transaction(data);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void SPI::irq_handler_asynch(void)
|
||||
{
|
||||
int event = spi_irq_handler_asynch(&_spi);
|
||||
if (_callback && (event & SPI_EVENT_ALL)) {
|
||||
_callback.call(event & SPI_EVENT_ALL);
|
||||
}
|
||||
#if TRANSACTION_QUEUE_SIZE_SPI
|
||||
if (event & (SPI_EVENT_ALL | SPI_EVENT_INTERNAL_TRANSFER_COMPLETE)) {
|
||||
// SPI peripheral is free (event happend), dequeue transaction
|
||||
dequeue_transaction();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,58 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "SPISlave.h"
|
||||
|
||||
#if DEVICE_SPISLAVE
|
||||
|
||||
namespace mbed {
|
||||
|
||||
SPISlave::SPISlave(PinName mosi, PinName miso, PinName sclk, PinName ssel) :
|
||||
_spi(),
|
||||
_bits(8),
|
||||
_mode(0),
|
||||
_hz(1000000)
|
||||
{
|
||||
spi_init(&_spi, mosi, miso, sclk, ssel);
|
||||
spi_format(&_spi, _bits, _mode, 1);
|
||||
spi_frequency(&_spi, _hz);
|
||||
}
|
||||
|
||||
void SPISlave::format(int bits, int mode) {
|
||||
_bits = bits;
|
||||
_mode = mode;
|
||||
spi_format(&_spi, _bits, _mode, 1);
|
||||
}
|
||||
|
||||
void SPISlave::frequency(int hz) {
|
||||
_hz = hz;
|
||||
spi_frequency(&_spi, _hz);
|
||||
}
|
||||
|
||||
int SPISlave::receive(void) {
|
||||
return(spi_slave_receive(&_spi));
|
||||
}
|
||||
|
||||
int SPISlave::read(void) {
|
||||
return(spi_slave_read(&_spi));
|
||||
}
|
||||
|
||||
void SPISlave::reply(int value) {
|
||||
spi_slave_write(&_spi, value);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,36 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Serial.h"
|
||||
#include "wait_api.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
namespace mbed {
|
||||
|
||||
Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), Stream(name) {
|
||||
}
|
||||
|
||||
int Serial::_getc() {
|
||||
return _base_getc();
|
||||
}
|
||||
|
||||
int Serial::_putc(int c) {
|
||||
return _base_putc(c);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,212 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "SerialBase.h"
|
||||
#include "wait_api.h"
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
|
||||
namespace mbed {
|
||||
|
||||
SerialBase::SerialBase(PinName tx, PinName rx) :
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
_thunk_irq(this), _tx_usage(DMA_USAGE_NEVER),
|
||||
_rx_usage(DMA_USAGE_NEVER),
|
||||
#endif
|
||||
_serial(), _baud(9600) {
|
||||
serial_init(&_serial, tx, rx);
|
||||
serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this);
|
||||
}
|
||||
|
||||
void SerialBase::baud(int baudrate) {
|
||||
serial_baud(&_serial, baudrate);
|
||||
_baud = baudrate;
|
||||
}
|
||||
|
||||
void SerialBase::format(int bits, Parity parity, int stop_bits) {
|
||||
serial_format(&_serial, bits, (SerialParity)parity, stop_bits);
|
||||
}
|
||||
|
||||
int SerialBase::readable() {
|
||||
return serial_readable(&_serial);
|
||||
}
|
||||
|
||||
|
||||
int SerialBase::writeable() {
|
||||
return serial_writable(&_serial);
|
||||
}
|
||||
|
||||
void SerialBase::attach(Callback<void()> func, IrqType type) {
|
||||
if (func) {
|
||||
_irq[type].attach(func);
|
||||
serial_irq_set(&_serial, (SerialIrq)type, 1);
|
||||
} else {
|
||||
serial_irq_set(&_serial, (SerialIrq)type, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) {
|
||||
SerialBase *handler = (SerialBase*)id;
|
||||
handler->_irq[irq_type].call();
|
||||
}
|
||||
|
||||
int SerialBase::_base_getc() {
|
||||
return serial_getc(&_serial);
|
||||
}
|
||||
|
||||
int SerialBase::_base_putc(int c) {
|
||||
serial_putc(&_serial, c);
|
||||
return c;
|
||||
}
|
||||
|
||||
void SerialBase::send_break() {
|
||||
// Wait for 1.5 frames before clearing the break condition
|
||||
// This will have different effects on our platforms, but should
|
||||
// ensure that we keep the break active for at least one frame.
|
||||
// We consider a full frame (1 start bit + 8 data bits bits +
|
||||
// 1 parity bit + 2 stop bits = 12 bits) for computation.
|
||||
// One bit time (in us) = 1000000/_baud
|
||||
// Twelve bits: 12000000/baud delay
|
||||
// 1.5 frames: 18000000/baud delay
|
||||
serial_break_set(&_serial);
|
||||
wait_us(18000000/_baud);
|
||||
serial_break_clear(&_serial);
|
||||
}
|
||||
|
||||
#if DEVICE_SERIAL_FC
|
||||
void SerialBase::set_flow_control(Flow type, PinName flow1, PinName flow2) {
|
||||
FlowControl flow_type = (FlowControl)type;
|
||||
switch(type) {
|
||||
case RTS:
|
||||
serial_set_flow_control(&_serial, flow_type, flow1, NC);
|
||||
break;
|
||||
|
||||
case CTS:
|
||||
serial_set_flow_control(&_serial, flow_type, NC, flow1);
|
||||
break;
|
||||
|
||||
case RTSCTS:
|
||||
case Disabled:
|
||||
serial_set_flow_control(&_serial, flow_type, flow1, flow2);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if DEVICE_SERIAL_ASYNCH
|
||||
|
||||
int SerialBase::write(const uint8_t *buffer, int length, const event_callback_t& callback, int event)
|
||||
{
|
||||
if (serial_tx_active(&_serial)) {
|
||||
return -1; // transaction ongoing
|
||||
}
|
||||
start_write((void *)buffer, length, 8, callback, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SerialBase::write(const uint16_t *buffer, int length, const event_callback_t& callback, int event)
|
||||
{
|
||||
if (serial_tx_active(&_serial)) {
|
||||
return -1; // transaction ongoing
|
||||
}
|
||||
start_write((void *)buffer, length, 16, callback, event);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void SerialBase::start_write(const void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event)
|
||||
{
|
||||
_tx_callback = callback;
|
||||
|
||||
_thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
|
||||
serial_tx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, _tx_usage);
|
||||
}
|
||||
|
||||
void SerialBase::abort_write(void)
|
||||
{
|
||||
serial_tx_abort_asynch(&_serial);
|
||||
}
|
||||
|
||||
void SerialBase::abort_read(void)
|
||||
{
|
||||
serial_rx_abort_asynch(&_serial);
|
||||
}
|
||||
|
||||
int SerialBase::set_dma_usage_tx(DMAUsage usage)
|
||||
{
|
||||
if (serial_tx_active(&_serial)) {
|
||||
return -1;
|
||||
}
|
||||
_tx_usage = usage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SerialBase::set_dma_usage_rx(DMAUsage usage)
|
||||
{
|
||||
if (serial_tx_active(&_serial)) {
|
||||
return -1;
|
||||
}
|
||||
_rx_usage = usage;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int SerialBase::read(uint8_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
|
||||
{
|
||||
if (serial_rx_active(&_serial)) {
|
||||
return -1; // transaction ongoing
|
||||
}
|
||||
start_read((void*)buffer, length, 8, callback, event, char_match);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int SerialBase::read(uint16_t *buffer, int length, const event_callback_t& callback, int event, unsigned char char_match)
|
||||
{
|
||||
if (serial_rx_active(&_serial)) {
|
||||
return -1; // transaction ongoing
|
||||
}
|
||||
start_read((void*)buffer, length, 16, callback, event, char_match);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void SerialBase::start_read(void *buffer, int buffer_size, char buffer_width, const event_callback_t& callback, int event, unsigned char char_match)
|
||||
{
|
||||
_rx_callback = callback;
|
||||
_thunk_irq.callback(&SerialBase::interrupt_handler_asynch);
|
||||
serial_rx_asynch(&_serial, buffer, buffer_size, buffer_width, _thunk_irq.entry(), event, char_match, _rx_usage);
|
||||
}
|
||||
|
||||
void SerialBase::interrupt_handler_asynch(void)
|
||||
{
|
||||
int event = serial_irq_handler_asynch(&_serial);
|
||||
int rx_event = event & SERIAL_EVENT_RX_MASK;
|
||||
if (_rx_callback && rx_event) {
|
||||
_rx_callback.call(rx_event);
|
||||
}
|
||||
|
||||
int tx_event = event & SERIAL_EVENT_TX_MASK;
|
||||
if (_tx_callback && tx_event) {
|
||||
_tx_callback.call(tx_event);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
||||
|
||||
#endif
|
|
@ -1,121 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Stream.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
Stream::Stream(const char *name) : FileLike(name), _file(NULL) {
|
||||
/* open ourselves */
|
||||
char buf[12]; /* :0x12345678 + null byte */
|
||||
std::sprintf(buf, ":%p", this);
|
||||
_file = std::fopen(buf, "w+");
|
||||
mbed_set_unbuffered_stream(_file);
|
||||
}
|
||||
|
||||
Stream::~Stream() {
|
||||
fclose(_file);
|
||||
}
|
||||
|
||||
int Stream::putc(int c) {
|
||||
fflush(_file);
|
||||
return std::fputc(c, _file);
|
||||
}
|
||||
int Stream::puts(const char *s) {
|
||||
fflush(_file);
|
||||
return std::fputs(s, _file);
|
||||
}
|
||||
int Stream::getc() {
|
||||
fflush(_file);
|
||||
return mbed_getc(_file);
|
||||
}
|
||||
char* Stream::gets(char *s, int size) {
|
||||
fflush(_file);
|
||||
return mbed_gets(s,size,_file);
|
||||
}
|
||||
|
||||
int Stream::close() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
ssize_t Stream::write(const void* buffer, size_t length) {
|
||||
const char* ptr = (const char*)buffer;
|
||||
const char* end = ptr + length;
|
||||
while (ptr != end) {
|
||||
if (_putc(*ptr++) == EOF) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return ptr - (const char*)buffer;
|
||||
}
|
||||
|
||||
ssize_t Stream::read(void* buffer, size_t length) {
|
||||
char* ptr = (char*)buffer;
|
||||
char* end = ptr + length;
|
||||
while (ptr != end) {
|
||||
int c = _getc();
|
||||
if (c==EOF) break;
|
||||
*ptr++ = c;
|
||||
}
|
||||
return ptr - (const char*)buffer;
|
||||
}
|
||||
|
||||
off_t Stream::lseek(off_t offset, int whence) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Stream::isatty() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Stream::fsync() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
off_t Stream::flen() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Stream::printf(const char* format, ...) {
|
||||
std::va_list arg;
|
||||
va_start(arg, format);
|
||||
fflush(_file);
|
||||
int r = vfprintf(_file, format, arg);
|
||||
va_end(arg);
|
||||
return r;
|
||||
}
|
||||
|
||||
int Stream::scanf(const char* format, ...) {
|
||||
std::va_list arg;
|
||||
va_start(arg, format);
|
||||
fflush(_file);
|
||||
int r = vfscanf(_file, format, arg);
|
||||
va_end(arg);
|
||||
return r;
|
||||
}
|
||||
|
||||
int Stream::vprintf(const char* format, std::va_list args) {
|
||||
fflush(_file);
|
||||
int r = vfprintf(_file, format, args);
|
||||
return r;
|
||||
}
|
||||
|
||||
int Stream::vscanf(const char* format, std::va_list args) {
|
||||
fflush(_file);
|
||||
int r = vfscanf(_file, format, args);
|
||||
return r;
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,40 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Ticker.h"
|
||||
|
||||
#include "TimerEvent.h"
|
||||
#include "FunctionPointer.h"
|
||||
#include "ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Ticker::detach() {
|
||||
remove();
|
||||
_function.attach(0);
|
||||
}
|
||||
|
||||
void Ticker::setup(timestamp_t t) {
|
||||
remove();
|
||||
_delay = t;
|
||||
insert(_delay + ticker_read(_ticker_data));
|
||||
}
|
||||
|
||||
void Ticker::handler() {
|
||||
insert(event.timestamp + _delay);
|
||||
_function.call();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,24 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Timeout.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void Timeout::handler() {
|
||||
_function.call();
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,73 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "Timer.h"
|
||||
#include "ticker_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
Timer::Timer() : _running(), _start(), _time(), _ticker_data(get_us_ticker_data()) {
|
||||
reset();
|
||||
}
|
||||
|
||||
Timer::Timer(const ticker_data_t *data) : _running(), _start(), _time(), _ticker_data(data) {
|
||||
reset();
|
||||
}
|
||||
|
||||
void Timer::start() {
|
||||
if (!_running) {
|
||||
_start = ticker_read(_ticker_data);
|
||||
_running = 1;
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::stop() {
|
||||
_time += slicetime();
|
||||
_running = 0;
|
||||
}
|
||||
|
||||
int Timer::read_us() {
|
||||
return _time + slicetime();
|
||||
}
|
||||
|
||||
float Timer::read() {
|
||||
return (float)read_us() / 1000000.0f;
|
||||
}
|
||||
|
||||
int Timer::read_ms() {
|
||||
return read_us() / 1000;
|
||||
}
|
||||
|
||||
int Timer::slicetime() {
|
||||
if (_running) {
|
||||
return ticker_read(_ticker_data) - _start;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Timer::reset() {
|
||||
_start = ticker_read(_ticker_data);
|
||||
_time = 0;
|
||||
}
|
||||
|
||||
#ifdef MBED_OPERATORS
|
||||
Timer::operator float() {
|
||||
return read();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace mbed
|
|
@ -1,51 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "TimerEvent.h"
|
||||
#include "cmsis.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include "ticker_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
namespace mbed {
|
||||
|
||||
TimerEvent::TimerEvent() : event(), _ticker_data(get_us_ticker_data()) {
|
||||
ticker_set_handler(_ticker_data, (&TimerEvent::irq));
|
||||
}
|
||||
|
||||
TimerEvent::TimerEvent(const ticker_data_t *data) : event(), _ticker_data(data) {
|
||||
ticker_set_handler(_ticker_data, (&TimerEvent::irq));
|
||||
}
|
||||
|
||||
void TimerEvent::irq(uint32_t id) {
|
||||
TimerEvent *timer_event = (TimerEvent*)id;
|
||||
timer_event->handler();
|
||||
}
|
||||
|
||||
TimerEvent::~TimerEvent() {
|
||||
remove();
|
||||
}
|
||||
|
||||
// insert in to linked list
|
||||
void TimerEvent::insert(timestamp_t timestamp) {
|
||||
ticker_insert_event(_ticker_data, &event, timestamp, (uint32_t)this);
|
||||
}
|
||||
|
||||
void TimerEvent::remove() {
|
||||
ticker_remove_event(_ticker_data, &event);
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,22 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "mbed_assert.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
void mbed_assert_internal(const char *expr, const char *file, int line)
|
||||
{
|
||||
error("mbed assertation failed: %s, file: %s, line %d \n", expr, file, line);
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "gpio_api.h"
|
||||
#include "wait_api.h"
|
||||
#include "toolchain.h"
|
||||
#include "mbed_interface.h"
|
||||
|
||||
WEAK void mbed_die(void) {
|
||||
#if !defined (NRF51_H) && !defined(TARGET_EFM32)
|
||||
__disable_irq(); // dont allow interrupts to disturb the flash pattern
|
||||
#endif
|
||||
#if (DEVICE_ERROR_RED == 1)
|
||||
gpio_t led_red; gpio_init_out(&led_red, LED_RED);
|
||||
#elif (DEVICE_ERROR_PATTERN == 1)
|
||||
gpio_t led_1; gpio_init_out(&led_1, LED1);
|
||||
gpio_t led_2; gpio_init_out(&led_2, LED2);
|
||||
gpio_t led_3; gpio_init_out(&led_3, LED3);
|
||||
gpio_t led_4; gpio_init_out(&led_4, LED4);
|
||||
#endif
|
||||
|
||||
while (1) {
|
||||
#if (DEVICE_ERROR_RED == 1)
|
||||
gpio_write(&led_red, 1);
|
||||
|
||||
#elif (DEVICE_ERROR_PATTERN == 1)
|
||||
gpio_write(&led_1, 1);
|
||||
gpio_write(&led_2, 0);
|
||||
gpio_write(&led_3, 0);
|
||||
gpio_write(&led_4, 1);
|
||||
#endif
|
||||
|
||||
wait_ms(150);
|
||||
|
||||
#if (DEVICE_ERROR_RED == 1)
|
||||
gpio_write(&led_red, 0);
|
||||
|
||||
#elif (DEVICE_ERROR_PATTERN == 1)
|
||||
gpio_write(&led_1, 0);
|
||||
gpio_write(&led_2, 1);
|
||||
gpio_write(&led_3, 1);
|
||||
gpio_write(&led_4, 0);
|
||||
#endif
|
||||
|
||||
wait_ms(150);
|
||||
}
|
||||
}
|
|
@ -1,61 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "gpio_api.h"
|
||||
|
||||
static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode)
|
||||
{
|
||||
gpio_init(gpio, pin);
|
||||
if (pin != NC) {
|
||||
gpio_dir(gpio, PIN_INPUT);
|
||||
gpio_mode(gpio, mode);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value)
|
||||
{
|
||||
gpio_init(gpio, pin);
|
||||
if (pin != NC) {
|
||||
gpio_write(gpio, value);
|
||||
gpio_dir(gpio, PIN_OUTPUT);
|
||||
gpio_mode(gpio, mode);
|
||||
}
|
||||
}
|
||||
|
||||
void gpio_init_in(gpio_t* gpio, PinName pin) {
|
||||
gpio_init_in_ex(gpio, pin, PullDefault);
|
||||
}
|
||||
|
||||
void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) {
|
||||
_gpio_init_in(gpio, pin, mode);
|
||||
}
|
||||
|
||||
void gpio_init_out(gpio_t* gpio, PinName pin) {
|
||||
gpio_init_out_ex(gpio, pin, 0);
|
||||
}
|
||||
|
||||
void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) {
|
||||
_gpio_init_out(gpio, pin, PullNone, value);
|
||||
}
|
||||
|
||||
void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) {
|
||||
if (direction == PIN_INPUT) {
|
||||
_gpio_init_in(gpio, pin, mode);
|
||||
if (pin != NC)
|
||||
gpio_write(gpio, value); // we prepare the value in case it is switched later
|
||||
} else {
|
||||
_gpio_init_out(gpio, pin, mode, value);
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "lp_ticker_api.h"
|
||||
|
||||
#if DEVICE_LOWPOWERTIMER
|
||||
|
||||
static ticker_event_queue_t events;
|
||||
|
||||
static const ticker_interface_t lp_interface = {
|
||||
.init = lp_ticker_init,
|
||||
.read = lp_ticker_read,
|
||||
.disable_interrupt = lp_ticker_disable_interrupt,
|
||||
.clear_interrupt = lp_ticker_clear_interrupt,
|
||||
.set_interrupt = lp_ticker_set_interrupt,
|
||||
};
|
||||
|
||||
static const ticker_data_t lp_data = {
|
||||
.interface = &lp_interface,
|
||||
.queue = &events,
|
||||
};
|
||||
|
||||
const ticker_data_t* get_lp_ticker_data(void)
|
||||
{
|
||||
return &lp_data;
|
||||
}
|
||||
|
||||
void lp_ticker_irq_handler(void)
|
||||
{
|
||||
ticker_irq_handler(&lp_data);
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,33 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include "device.h"
|
||||
#include "toolchain.h"
|
||||
#include "mbed_error.h"
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
|
||||
WEAK void error(const char* format, ...) {
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
va_list arg;
|
||||
va_start(arg, format);
|
||||
vfprintf(stderr, format, arg);
|
||||
va_end(arg);
|
||||
#endif
|
||||
exit(1);
|
||||
}
|
|
@ -1,113 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include "mbed_interface.h"
|
||||
|
||||
#include "gpio_api.h"
|
||||
#include "wait_api.h"
|
||||
#include "semihost_api.h"
|
||||
#include "mbed_error.h"
|
||||
#include "toolchain.h"
|
||||
|
||||
#if DEVICE_SEMIHOST
|
||||
|
||||
// return true if a debugger is attached, indicating mbed interface is connected
|
||||
int mbed_interface_connected(void) {
|
||||
return semihost_connected();
|
||||
}
|
||||
|
||||
int mbed_interface_reset(void) {
|
||||
if (mbed_interface_connected()) {
|
||||
semihost_reset();
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
WEAK int mbed_interface_uid(char *uid) {
|
||||
if (mbed_interface_connected()) {
|
||||
return semihost_uid(uid); // Returns 0 if successful, -1 on failure
|
||||
} else {
|
||||
uid[0] = 0;
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int mbed_interface_disconnect(void) {
|
||||
int res;
|
||||
if (mbed_interface_connected()) {
|
||||
if ((res = semihost_disabledebug()) != 0)
|
||||
return res;
|
||||
while (mbed_interface_connected());
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int mbed_interface_powerdown(void) {
|
||||
int res;
|
||||
if (mbed_interface_connected()) {
|
||||
if ((res = semihost_powerdown()) != 0)
|
||||
return res;
|
||||
while (mbed_interface_connected());
|
||||
return 0;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
// for backward compatibility
|
||||
void mbed_reset(void) {
|
||||
mbed_interface_reset();
|
||||
}
|
||||
|
||||
WEAK int mbed_uid(char *uid) {
|
||||
return mbed_interface_uid(uid);
|
||||
}
|
||||
#endif
|
||||
|
||||
WEAK void mbed_mac_address(char *mac) {
|
||||
#if DEVICE_SEMIHOST
|
||||
char uid[DEVICE_ID_LENGTH + 1];
|
||||
int i;
|
||||
|
||||
// if we have a UID, extract the MAC
|
||||
if (mbed_interface_uid(uid) == 0) {
|
||||
char *p = uid;
|
||||
#if defined(DEVICE_MAC_OFFSET)
|
||||
p += DEVICE_MAC_OFFSET;
|
||||
#endif
|
||||
for (i=0; i<6; i++) {
|
||||
int byte;
|
||||
sscanf(p, "%2x", &byte);
|
||||
mac[i] = byte;
|
||||
p += 2;
|
||||
}
|
||||
mac[0] &= ~0x01; // reset the IG bit in the address; see IEE 802.3-2002, Section 3.2.3(b)
|
||||
} else { // else return a default MAC
|
||||
#endif
|
||||
mac[0] = 0x00;
|
||||
mac[1] = 0x02;
|
||||
mac[2] = 0xF7;
|
||||
mac[3] = 0xF0;
|
||||
mac[4] = 0x00;
|
||||
mac[5] = 0x00;
|
||||
#if DEVICE_SEMIHOST
|
||||
}
|
||||
#endif
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "pinmap.h"
|
||||
#include "mbed_error.h"
|
||||
|
||||
void pinmap_pinout(PinName pin, const PinMap *map) {
|
||||
if (pin == NC)
|
||||
return;
|
||||
|
||||
while (map->pin != NC) {
|
||||
if (map->pin == pin) {
|
||||
pin_function(pin, map->function);
|
||||
|
||||
pin_mode(pin, PullNone);
|
||||
return;
|
||||
}
|
||||
map++;
|
||||
}
|
||||
error("could not pinout");
|
||||
}
|
||||
|
||||
uint32_t pinmap_merge(uint32_t a, uint32_t b) {
|
||||
// both are the same (inc both NC)
|
||||
if (a == b)
|
||||
return a;
|
||||
|
||||
// one (or both) is not connected
|
||||
if (a == (uint32_t)NC)
|
||||
return b;
|
||||
if (b == (uint32_t)NC)
|
||||
return a;
|
||||
|
||||
// mis-match error case
|
||||
error("pinmap mis-match");
|
||||
return (uint32_t)NC;
|
||||
}
|
||||
|
||||
uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) {
|
||||
while (map->pin != NC) {
|
||||
if (map->pin == pin)
|
||||
return map->peripheral;
|
||||
map++;
|
||||
}
|
||||
return (uint32_t)NC;
|
||||
}
|
||||
|
||||
uint32_t pinmap_peripheral(PinName pin, const PinMap* map) {
|
||||
uint32_t peripheral = (uint32_t)NC;
|
||||
|
||||
if (pin == (PinName)NC)
|
||||
return (uint32_t)NC;
|
||||
peripheral = pinmap_find_peripheral(pin, map);
|
||||
if ((uint32_t)NC == peripheral) // no mapping available
|
||||
error("pinmap not found for peripheral");
|
||||
return peripheral;
|
||||
}
|
||||
|
||||
uint32_t pinmap_find_function(PinName pin, const PinMap* map) {
|
||||
while (map->pin != NC) {
|
||||
if (map->pin == pin)
|
||||
return map->function;
|
||||
map++;
|
||||
}
|
||||
return (uint32_t)NC;
|
||||
}
|
||||
|
||||
uint32_t pinmap_function(PinName pin, const PinMap* map) {
|
||||
uint32_t function = (uint32_t)NC;
|
||||
|
||||
if (pin == (PinName)NC)
|
||||
return (uint32_t)NC;
|
||||
function = pinmap_find_function(pin, map);
|
||||
if ((uint32_t)NC == function) // no mapping available
|
||||
error("pinmap not found for function");
|
||||
return function;
|
||||
}
|
|
@ -1,568 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "platform.h"
|
||||
#include "FileHandle.h"
|
||||
#include "FileSystemLike.h"
|
||||
#include "FilePath.h"
|
||||
#include "serial_api.h"
|
||||
#include "toolchain.h"
|
||||
#include "semihost_api.h"
|
||||
#include "mbed_interface.h"
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
#include <stdio.h>
|
||||
#endif
|
||||
#include <errno.h>
|
||||
|
||||
#if defined(__ARMCC_VERSION)
|
||||
# include <rt_sys.h>
|
||||
# define PREFIX(x) _sys##x
|
||||
# define OPEN_MAX _SYS_OPEN
|
||||
# ifdef __MICROLIB
|
||||
# pragma import(__use_full_stdio)
|
||||
# endif
|
||||
|
||||
#elif defined(__ICCARM__)
|
||||
# include <yfuns.h>
|
||||
# define PREFIX(x) _##x
|
||||
# define OPEN_MAX 16
|
||||
|
||||
# define STDIN_FILENO 0
|
||||
# define STDOUT_FILENO 1
|
||||
# define STDERR_FILENO 2
|
||||
|
||||
#else
|
||||
# include <sys/stat.h>
|
||||
# include <sys/unistd.h>
|
||||
# include <sys/syslimits.h>
|
||||
# define PREFIX(x) x
|
||||
#endif
|
||||
|
||||
using namespace mbed;
|
||||
|
||||
#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000)
|
||||
// Before version 5.03, we were using a patched version of microlib with proper names
|
||||
extern const char __stdin_name[] = ":tt";
|
||||
extern const char __stdout_name[] = ":tt";
|
||||
extern const char __stderr_name[] = ":tt";
|
||||
|
||||
#else
|
||||
extern const char __stdin_name[] = "/stdin";
|
||||
extern const char __stdout_name[] = "/stdout";
|
||||
extern const char __stderr_name[] = "/stderr";
|
||||
#endif
|
||||
|
||||
/* newlib has the filehandle field in the FILE struct as a short, so
|
||||
* we can't just return a Filehandle* from _open and instead have to
|
||||
* put it in a filehandles array and return the index into that array
|
||||
* (or rather index+3, as filehandles 0-2 are stdin/out/err).
|
||||
*/
|
||||
static FileHandle *filehandles[OPEN_MAX];
|
||||
|
||||
FileHandle::~FileHandle() {
|
||||
/* Remove all open filehandles for this */
|
||||
for (unsigned int fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
|
||||
if (filehandles[fh_i] == this) {
|
||||
filehandles[fh_i] = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if DEVICE_SERIAL
|
||||
extern int stdio_uart_inited;
|
||||
extern serial_t stdio_uart;
|
||||
#endif
|
||||
|
||||
static void init_serial() {
|
||||
#if DEVICE_SERIAL
|
||||
if (stdio_uart_inited) return;
|
||||
serial_init(&stdio_uart, STDIO_UART_TX, STDIO_UART_RX);
|
||||
#endif
|
||||
}
|
||||
|
||||
static inline int openmode_to_posix(int openmode) {
|
||||
int posix = openmode;
|
||||
#ifdef __ARMCC_VERSION
|
||||
if (openmode & OPEN_PLUS) {
|
||||
posix = O_RDWR;
|
||||
} else if(openmode & OPEN_W) {
|
||||
posix = O_WRONLY;
|
||||
} else if(openmode & OPEN_A) {
|
||||
posix = O_WRONLY|O_APPEND;
|
||||
} else {
|
||||
posix = O_RDONLY;
|
||||
}
|
||||
/* a, w, a+, w+ all create if file does not already exist */
|
||||
if (openmode & (OPEN_A|OPEN_W)) {
|
||||
posix |= O_CREAT;
|
||||
}
|
||||
/* w and w+ truncate */
|
||||
if (openmode & OPEN_W) {
|
||||
posix |= O_TRUNC;
|
||||
}
|
||||
#elif defined(__ICCARM__)
|
||||
switch (openmode & _LLIO_RDWRMASK) {
|
||||
case _LLIO_RDONLY: posix = O_RDONLY; break;
|
||||
case _LLIO_WRONLY: posix = O_WRONLY; break;
|
||||
case _LLIO_RDWR : posix = O_RDWR ; break;
|
||||
}
|
||||
if (openmode & _LLIO_CREAT ) posix |= O_CREAT;
|
||||
if (openmode & _LLIO_APPEND) posix |= O_APPEND;
|
||||
if (openmode & _LLIO_TRUNC ) posix |= O_TRUNC;
|
||||
#elif defined(TOOLCHAIN_GCC)
|
||||
posix &= ~O_BINARY;
|
||||
#endif
|
||||
return posix;
|
||||
}
|
||||
|
||||
extern "C" FILEHANDLE PREFIX(_open)(const char* name, int openmode) {
|
||||
#if defined(__MICROLIB) && (__ARMCC_VERSION>5030000)
|
||||
// Before version 5.03, we were using a patched version of microlib with proper names
|
||||
// This is the workaround that the microlib author suggested us
|
||||
static int n = 0;
|
||||
if (!std::strcmp(name, ":tt")) return n++;
|
||||
|
||||
#else
|
||||
/* Use the posix convention that stdin,out,err are filehandles 0,1,2.
|
||||
*/
|
||||
if (std::strcmp(name, __stdin_name) == 0) {
|
||||
init_serial();
|
||||
return 0;
|
||||
} else if (std::strcmp(name, __stdout_name) == 0) {
|
||||
init_serial();
|
||||
return 1;
|
||||
} else if (std::strcmp(name, __stderr_name) == 0) {
|
||||
init_serial();
|
||||
return 2;
|
||||
}
|
||||
#endif
|
||||
|
||||
// find the first empty slot in filehandles
|
||||
unsigned int fh_i;
|
||||
for (fh_i = 0; fh_i < sizeof(filehandles)/sizeof(*filehandles); fh_i++) {
|
||||
if (filehandles[fh_i] == NULL) break;
|
||||
}
|
||||
if (fh_i >= sizeof(filehandles)/sizeof(*filehandles)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FileHandle *res;
|
||||
|
||||
/* FILENAME: ":0x12345678" describes a FileLike* */
|
||||
if (name[0] == ':') {
|
||||
void *p;
|
||||
sscanf(name, ":%p", &p);
|
||||
res = (FileHandle*)p;
|
||||
|
||||
/* FILENAME: "/file_system/file_name" */
|
||||
} else {
|
||||
FilePath path(name);
|
||||
|
||||
if (!path.exists())
|
||||
return -1;
|
||||
else if (path.isFile()) {
|
||||
res = path.file();
|
||||
} else {
|
||||
FileSystemLike *fs = path.fileSystem();
|
||||
if (fs == NULL) return -1;
|
||||
int posix_mode = openmode_to_posix(openmode);
|
||||
res = fs->open(path.fileName(), posix_mode); /* NULL if fails */
|
||||
}
|
||||
}
|
||||
|
||||
if (res == NULL) return -1;
|
||||
filehandles[fh_i] = res;
|
||||
|
||||
return fh_i + 3; // +3 as filehandles 0-2 are stdin/out/err
|
||||
}
|
||||
|
||||
extern "C" int PREFIX(_close)(FILEHANDLE fh) {
|
||||
if (fh < 3) return 0;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
filehandles[fh-3] = NULL;
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
return fhc->close();
|
||||
}
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
extern "C" size_t __write (int fh, const unsigned char *buffer, size_t length) {
|
||||
#else
|
||||
extern "C" int PREFIX(_write)(FILEHANDLE fh, const unsigned char *buffer, unsigned int length, int mode) {
|
||||
#endif
|
||||
int n; // n is the number of bytes written
|
||||
if (fh < 3) {
|
||||
#if DEVICE_SERIAL
|
||||
if (!stdio_uart_inited) init_serial();
|
||||
for (unsigned int i = 0; i < length; i++) {
|
||||
serial_putc(&stdio_uart, buffer[i]);
|
||||
}
|
||||
#endif
|
||||
n = length;
|
||||
} else {
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
n = fhc->write(buffer, length);
|
||||
}
|
||||
#ifdef __ARMCC_VERSION
|
||||
return length-n;
|
||||
#else
|
||||
return n;
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(__ICCARM__)
|
||||
extern "C" size_t __read (int fh, unsigned char *buffer, size_t length) {
|
||||
#else
|
||||
extern "C" int PREFIX(_read)(FILEHANDLE fh, unsigned char *buffer, unsigned int length, int mode) {
|
||||
#endif
|
||||
int n; // n is the number of bytes read
|
||||
if (fh < 3) {
|
||||
// only read a character at a time from stdin
|
||||
#if DEVICE_SERIAL
|
||||
if (!stdio_uart_inited) init_serial();
|
||||
*buffer = serial_getc(&stdio_uart);
|
||||
#endif
|
||||
n = 1;
|
||||
} else {
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
n = fhc->read(buffer, length);
|
||||
}
|
||||
#ifdef __ARMCC_VERSION
|
||||
return length-n;
|
||||
#else
|
||||
return n;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ARMCC_VERSION
|
||||
extern "C" int PREFIX(_istty)(FILEHANDLE fh)
|
||||
#else
|
||||
extern "C" int _isatty(FILEHANDLE fh)
|
||||
#endif
|
||||
{
|
||||
/* stdin, stdout and stderr should be tty */
|
||||
if (fh < 3) return 1;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
return fhc->isatty();
|
||||
}
|
||||
|
||||
extern "C"
|
||||
#if defined(__ARMCC_VERSION)
|
||||
int _sys_seek(FILEHANDLE fh, long position)
|
||||
#elif defined(__ICCARM__)
|
||||
long __lseek(int fh, long offset, int whence)
|
||||
#else
|
||||
int _lseek(FILEHANDLE fh, int offset, int whence)
|
||||
#endif
|
||||
{
|
||||
if (fh < 3) return 0;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
#if defined(__ARMCC_VERSION)
|
||||
return fhc->lseek(position, SEEK_SET);
|
||||
#else
|
||||
return fhc->lseek(offset, whence);
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef __ARMCC_VERSION
|
||||
extern "C" int PREFIX(_ensure)(FILEHANDLE fh) {
|
||||
if (fh < 3) return 0;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
return fhc->fsync();
|
||||
}
|
||||
|
||||
extern "C" long PREFIX(_flen)(FILEHANDLE fh) {
|
||||
if (fh < 3) return 0;
|
||||
|
||||
FileHandle* fhc = filehandles[fh-3];
|
||||
if (fhc == NULL) return -1;
|
||||
|
||||
return fhc->flen();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if !defined(__ARMCC_VERSION) && !defined(__ICCARM__)
|
||||
extern "C" int _fstat(int fd, struct stat *st) {
|
||||
if ((STDOUT_FILENO == fd) || (STDERR_FILENO == fd) || (STDIN_FILENO == fd)) {
|
||||
st->st_mode = S_IFCHR;
|
||||
return 0;
|
||||
}
|
||||
|
||||
errno = EBADF;
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
namespace std {
|
||||
extern "C" int remove(const char *path) {
|
||||
FilePath fp(path);
|
||||
FileSystemLike *fs = fp.fileSystem();
|
||||
if (fs == NULL) return -1;
|
||||
|
||||
return fs->remove(fp.fileName());
|
||||
}
|
||||
|
||||
extern "C" int rename(const char *oldname, const char *newname) {
|
||||
FilePath fpOld(oldname);
|
||||
FilePath fpNew(newname);
|
||||
FileSystemLike *fsOld = fpOld.fileSystem();
|
||||
FileSystemLike *fsNew = fpNew.fileSystem();
|
||||
|
||||
/* rename only if both files are on the same FS */
|
||||
if (fsOld != fsNew || fsOld == NULL) return -1;
|
||||
|
||||
return fsOld->rename(fpOld.fileName(), fpNew.fileName());
|
||||
}
|
||||
|
||||
extern "C" char *tmpnam(char *s) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
extern "C" FILE *tmpfile() {
|
||||
return NULL;
|
||||
}
|
||||
} // namespace std
|
||||
|
||||
#ifdef __ARMCC_VERSION
|
||||
extern "C" char *_sys_command_string(char *cmd, int len) {
|
||||
return NULL;
|
||||
}
|
||||
#endif
|
||||
|
||||
extern "C" DIR *opendir(const char *path) {
|
||||
/* root dir is FileSystemLike */
|
||||
if (path[0] == '/' && path[1] == 0) {
|
||||
return FileSystemLike::opendir();
|
||||
}
|
||||
|
||||
FilePath fp(path);
|
||||
FileSystemLike* fs = fp.fileSystem();
|
||||
if (fs == NULL) return NULL;
|
||||
|
||||
return fs->opendir(fp.fileName());
|
||||
}
|
||||
|
||||
extern "C" struct dirent *readdir(DIR *dir) {
|
||||
return dir->readdir();
|
||||
}
|
||||
|
||||
extern "C" int closedir(DIR *dir) {
|
||||
return dir->closedir();
|
||||
}
|
||||
|
||||
extern "C" void rewinddir(DIR *dir) {
|
||||
dir->rewinddir();
|
||||
}
|
||||
|
||||
extern "C" off_t telldir(DIR *dir) {
|
||||
return dir->telldir();
|
||||
}
|
||||
|
||||
extern "C" void seekdir(DIR *dir, off_t off) {
|
||||
dir->seekdir(off);
|
||||
}
|
||||
|
||||
extern "C" int mkdir(const char *path, mode_t mode) {
|
||||
FilePath fp(path);
|
||||
FileSystemLike *fs = fp.fileSystem();
|
||||
if (fs == NULL) return -1;
|
||||
|
||||
return fs->mkdir(fp.fileName(), mode);
|
||||
}
|
||||
|
||||
#if defined(TOOLCHAIN_GCC)
|
||||
/* prevents the exception handling name demangling code getting pulled in */
|
||||
#include "mbed_error.h"
|
||||
namespace __gnu_cxx {
|
||||
void __verbose_terminate_handler() {
|
||||
error("Exception");
|
||||
}
|
||||
}
|
||||
extern "C" WEAK void __cxa_pure_virtual(void);
|
||||
extern "C" WEAK void __cxa_pure_virtual(void) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
// ****************************************************************************
|
||||
// mbed_main is a function that is called before main()
|
||||
// mbed_sdk_init() is also a function that is called before main(), but unlike
|
||||
// mbed_main(), it is not meant for user code, but for the SDK itself to perform
|
||||
// initializations before main() is called.
|
||||
|
||||
extern "C" WEAK void mbed_main(void);
|
||||
extern "C" WEAK void mbed_main(void) {
|
||||
}
|
||||
|
||||
extern "C" WEAK void mbed_sdk_init(void);
|
||||
extern "C" WEAK void mbed_sdk_init(void) {
|
||||
}
|
||||
|
||||
#if defined(TOOLCHAIN_ARM)
|
||||
extern "C" int $Super$$main(void);
|
||||
|
||||
extern "C" int $Sub$$main(void) {
|
||||
mbed_sdk_init();
|
||||
mbed_main();
|
||||
return $Super$$main();
|
||||
}
|
||||
#elif defined(TOOLCHAIN_GCC)
|
||||
extern "C" int __real_main(void);
|
||||
|
||||
extern "C" int __wrap_main(void) {
|
||||
mbed_sdk_init();
|
||||
mbed_main();
|
||||
return __real_main();
|
||||
}
|
||||
#elif defined(TOOLCHAIN_IAR)
|
||||
// IAR doesn't have the $Super/$Sub mechanism of armcc, nor something equivalent
|
||||
// to ld's --wrap. It does have a --redirect, but that doesn't help, since redirecting
|
||||
// 'main' to another symbol looses the original 'main' symbol. However, its startup
|
||||
// code will call a function to setup argc and argv (__iar_argc_argv) if it is defined.
|
||||
// Since mbed doesn't use argc/argv, we use this function to call our mbed_main.
|
||||
extern "C" void __iar_argc_argv() {
|
||||
mbed_sdk_init();
|
||||
mbed_main();
|
||||
}
|
||||
#endif
|
||||
|
||||
// Provide implementation of _sbrk (low-level dynamic memory allocation
|
||||
// routine) for GCC_ARM which compares new heap pointer with MSP instead of
|
||||
// SP. This make it compatible with RTX RTOS thread stacks.
|
||||
#if defined(TOOLCHAIN_GCC_ARM)
|
||||
// Linker defined symbol used by _sbrk to indicate where heap should start.
|
||||
extern "C" int __end__;
|
||||
|
||||
extern "C" uint32_t __HeapLimit;
|
||||
|
||||
// Turn off the errno macro and use actual global variable instead.
|
||||
#undef errno
|
||||
extern "C" int errno;
|
||||
|
||||
// Stack pointer handling
|
||||
#ifdef __ICCARM__
|
||||
#define __current_sp() __get_SP()
|
||||
#else
|
||||
static inline unsigned int __current_sp(void)
|
||||
{
|
||||
register unsigned sp asm("sp");
|
||||
return sp;
|
||||
}
|
||||
#endif /* __ICCARM__ */
|
||||
|
||||
// Dynamic memory allocation related syscall.
|
||||
extern "C" caddr_t _sbrk(int incr) {
|
||||
static unsigned char* heap = (unsigned char*)&__end__;
|
||||
unsigned char* prev_heap = heap;
|
||||
unsigned char* new_heap = heap + incr;
|
||||
|
||||
if (new_heap >= (unsigned char*)&__HeapLimit) { /* __HeapLimit is end of heap section */
|
||||
errno = ENOMEM;
|
||||
return (caddr_t)-1;
|
||||
}
|
||||
|
||||
heap = new_heap;
|
||||
return (caddr_t) prev_heap;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
#if defined TOOLCHAIN_GCC_ARM
|
||||
extern "C" void _exit(int return_code) {
|
||||
#else
|
||||
namespace std {
|
||||
extern "C" void exit(int return_code) {
|
||||
#endif
|
||||
|
||||
#if DEVICE_STDIO_MESSAGES
|
||||
fflush(stdout);
|
||||
fflush(stderr);
|
||||
#endif
|
||||
|
||||
#if DEVICE_SEMIHOST
|
||||
if (mbed_interface_connected()) {
|
||||
semihost_exit();
|
||||
}
|
||||
#endif
|
||||
if (return_code) {
|
||||
mbed_die();
|
||||
}
|
||||
|
||||
while (1);
|
||||
}
|
||||
|
||||
#if !defined(TOOLCHAIN_GCC_ARM)
|
||||
} //namespace std
|
||||
#endif
|
||||
|
||||
|
||||
namespace mbed {
|
||||
|
||||
void mbed_set_unbuffered_stream(FILE *_file) {
|
||||
#if defined (__ICCARM__)
|
||||
char buf[2];
|
||||
std::setvbuf(_file,buf,_IONBF,NULL);
|
||||
#else
|
||||
setbuf(_file, NULL);
|
||||
#endif
|
||||
}
|
||||
|
||||
int mbed_getc(FILE *_file){
|
||||
#if defined (__ICCARM__)
|
||||
/*This is only valid for unbuffered streams*/
|
||||
int res = std::fgetc(_file);
|
||||
if (res>=0){
|
||||
_file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
|
||||
_file->_Rend = _file->_Wend;
|
||||
_file->_Next = _file->_Wend;
|
||||
}
|
||||
return res;
|
||||
#else
|
||||
return std::fgetc(_file);
|
||||
#endif
|
||||
}
|
||||
|
||||
char* mbed_gets(char*s, int size, FILE *_file){
|
||||
#if defined (__ICCARM__)
|
||||
/*This is only valid for unbuffered streams*/
|
||||
char *str = fgets(s,size,_file);
|
||||
if (str!=NULL){
|
||||
_file->_Mode = (unsigned short)(_file->_Mode & ~ 0x1000);/* Unset read mode */
|
||||
_file->_Rend = _file->_Wend;
|
||||
_file->_Next = _file->_Wend;
|
||||
}
|
||||
return str;
|
||||
#else
|
||||
return std::fgets(s,size,_file);
|
||||
#endif
|
||||
}
|
||||
|
||||
} // namespace mbed
|
|
@ -1,90 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "rtc_api.h"
|
||||
|
||||
#include <time.h>
|
||||
#include "critical.h"
|
||||
#include "rtc_time.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
#if DEVICE_RTC
|
||||
static void (*_rtc_init)(void) = rtc_init;
|
||||
static int (*_rtc_isenabled)(void) = rtc_isenabled;
|
||||
static time_t (*_rtc_read)(void) = rtc_read;
|
||||
static void (*_rtc_write)(time_t t) = rtc_write;
|
||||
#else
|
||||
static void (*_rtc_init)(void) = NULL;
|
||||
static int (*_rtc_isenabled)(void) = NULL;
|
||||
static time_t (*_rtc_read)(void) = NULL;
|
||||
static void (*_rtc_write)(time_t t) = NULL;
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
#if defined (__ICCARM__)
|
||||
time_t __time32(time_t *timer)
|
||||
#else
|
||||
time_t time(time_t *timer)
|
||||
#endif
|
||||
|
||||
{
|
||||
if (_rtc_isenabled != NULL) {
|
||||
if (!(_rtc_isenabled())) {
|
||||
set_time(0);
|
||||
}
|
||||
}
|
||||
|
||||
time_t t = 0;
|
||||
if (_rtc_read != NULL) {
|
||||
t = _rtc_read();
|
||||
}
|
||||
|
||||
if (timer != NULL) {
|
||||
*timer = t;
|
||||
}
|
||||
return t;
|
||||
}
|
||||
|
||||
void set_time(time_t t) {
|
||||
if (_rtc_init != NULL) {
|
||||
_rtc_init();
|
||||
}
|
||||
if (_rtc_write != NULL) {
|
||||
_rtc_write(t);
|
||||
}
|
||||
}
|
||||
|
||||
clock_t clock() {
|
||||
clock_t t = us_ticker_read();
|
||||
t /= 1000000 / CLOCKS_PER_SEC; // convert to processor time
|
||||
return t;
|
||||
}
|
||||
|
||||
void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)) {
|
||||
core_util_critical_section_enter();
|
||||
_rtc_read = read_rtc;
|
||||
_rtc_write = write_rtc;
|
||||
_rtc_init = init_rtc;
|
||||
_rtc_isenabled = isenabled_rtc;
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
|
@ -1,162 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "cmsis.h"
|
||||
#include "semihost_api.h"
|
||||
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
|
||||
#if DEVICE_SEMIHOST
|
||||
|
||||
// ARM Semihosting Commands
|
||||
#define SYS_OPEN (0x1)
|
||||
#define SYS_CLOSE (0x2)
|
||||
#define SYS_WRITE (0x5)
|
||||
#define SYS_READ (0x6)
|
||||
#define SYS_ISTTY (0x9)
|
||||
#define SYS_SEEK (0xa)
|
||||
#define SYS_ENSURE (0xb)
|
||||
#define SYS_FLEN (0xc)
|
||||
#define SYS_REMOVE (0xe)
|
||||
#define SYS_RENAME (0xf)
|
||||
#define SYS_EXIT (0x18)
|
||||
|
||||
// mbed Semihosting Commands
|
||||
#define RESERVED_FOR_USER_APPLICATIONS (0x100) // 0x100 - 0x1ff
|
||||
#define USR_XFFIND (RESERVED_FOR_USER_APPLICATIONS + 0)
|
||||
#define USR_UID (RESERVED_FOR_USER_APPLICATIONS + 1)
|
||||
#define USR_RESET (RESERVED_FOR_USER_APPLICATIONS + 2)
|
||||
#define USR_VBUS (RESERVED_FOR_USER_APPLICATIONS + 3)
|
||||
#define USR_POWERDOWN (RESERVED_FOR_USER_APPLICATIONS + 4)
|
||||
#define USR_DISABLEDEBUG (RESERVED_FOR_USER_APPLICATIONS + 5)
|
||||
|
||||
#if DEVICE_LOCALFILESYSTEM
|
||||
FILEHANDLE semihost_open(const char* name, int openmode) {
|
||||
uint32_t args[3];
|
||||
args[0] = (uint32_t)name;
|
||||
args[1] = (uint32_t)openmode;
|
||||
args[2] = (uint32_t)strlen(name);
|
||||
return __semihost(SYS_OPEN, args);
|
||||
}
|
||||
|
||||
int semihost_close(FILEHANDLE fh) {
|
||||
return __semihost(SYS_CLOSE, &fh);
|
||||
}
|
||||
|
||||
int semihost_write(FILEHANDLE fh, const unsigned char* buffer, unsigned int length, int mode) {
|
||||
if (length == 0) return 0;
|
||||
|
||||
uint32_t args[3];
|
||||
args[0] = (uint32_t)fh;
|
||||
args[1] = (uint32_t)buffer;
|
||||
args[2] = (uint32_t)length;
|
||||
return __semihost(SYS_WRITE, args);
|
||||
}
|
||||
|
||||
int semihost_read(FILEHANDLE fh, unsigned char* buffer, unsigned int length, int mode) {
|
||||
uint32_t args[3];
|
||||
args[0] = (uint32_t)fh;
|
||||
args[1] = (uint32_t)buffer;
|
||||
args[2] = (uint32_t)length;
|
||||
return __semihost(SYS_READ, args);
|
||||
}
|
||||
|
||||
int semihost_istty(FILEHANDLE fh) {
|
||||
return __semihost(SYS_ISTTY, &fh);
|
||||
}
|
||||
|
||||
int semihost_seek(FILEHANDLE fh, long position) {
|
||||
uint32_t args[2];
|
||||
args[0] = (uint32_t)fh;
|
||||
args[1] = (uint32_t)position;
|
||||
return __semihost(SYS_SEEK, args);
|
||||
}
|
||||
|
||||
int semihost_ensure(FILEHANDLE fh) {
|
||||
return __semihost(SYS_ENSURE, &fh);
|
||||
}
|
||||
|
||||
long semihost_flen(FILEHANDLE fh) {
|
||||
return __semihost(SYS_FLEN, &fh);
|
||||
}
|
||||
|
||||
int semihost_remove(const char *name) {
|
||||
uint32_t args[2];
|
||||
args[0] = (uint32_t)name;
|
||||
args[1] = (uint32_t)strlen(name);
|
||||
return __semihost(SYS_REMOVE, args);
|
||||
}
|
||||
|
||||
int semihost_rename(const char *old_name, const char *new_name) {
|
||||
uint32_t args[4];
|
||||
args[0] = (uint32_t)old_name;
|
||||
args[1] = (uint32_t)strlen(old_name);
|
||||
args[0] = (uint32_t)new_name;
|
||||
args[1] = (uint32_t)strlen(new_name);
|
||||
return __semihost(SYS_RENAME, args);
|
||||
}
|
||||
#endif
|
||||
|
||||
int semihost_exit(void) {
|
||||
uint32_t args[4];
|
||||
return __semihost(SYS_EXIT, args);
|
||||
}
|
||||
|
||||
int semihost_uid(char *uid) {
|
||||
uint32_t args[2];
|
||||
args[0] = (uint32_t)uid;
|
||||
args[1] = DEVICE_ID_LENGTH + 1;
|
||||
return __semihost(USR_UID, &args);
|
||||
}
|
||||
|
||||
int semihost_reset(void) {
|
||||
// Does not normally return, however if used with older firmware versions
|
||||
// that do not support this call it will return -1.
|
||||
return __semihost(USR_RESET, NULL);
|
||||
}
|
||||
|
||||
int semihost_vbus(void) {
|
||||
return __semihost(USR_VBUS, NULL);
|
||||
}
|
||||
|
||||
int semihost_powerdown(void) {
|
||||
return __semihost(USR_POWERDOWN, NULL);
|
||||
}
|
||||
|
||||
#if DEVICE_DEBUG_AWARENESS
|
||||
|
||||
int semihost_connected(void) {
|
||||
return (CoreDebug->DHCSR & CoreDebug_DHCSR_C_DEBUGEN_Msk) ? 1 : 0;
|
||||
}
|
||||
|
||||
#else
|
||||
// These processors cannot know if the interface is connect, assume so:
|
||||
static int is_debugger_attached = 1;
|
||||
|
||||
int semihost_connected(void) {
|
||||
return is_debugger_attached;
|
||||
}
|
||||
#endif
|
||||
|
||||
int semihost_disabledebug(void) {
|
||||
#if !(DEVICE_DEBUG_AWARENESS)
|
||||
is_debugger_attached = 0;
|
||||
#endif
|
||||
return __semihost(USR_DISABLEDEBUG, NULL);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
@ -1,135 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include <stddef.h>
|
||||
#include "ticker_api.h"
|
||||
#include "critical.h"
|
||||
|
||||
void ticker_set_handler(const ticker_data_t *const data, ticker_event_handler handler) {
|
||||
data->interface->init();
|
||||
|
||||
data->queue->event_handler = handler;
|
||||
}
|
||||
|
||||
void ticker_irq_handler(const ticker_data_t *const data) {
|
||||
data->interface->clear_interrupt();
|
||||
|
||||
/* Go through all the pending TimerEvents */
|
||||
while (1) {
|
||||
if (data->queue->head == NULL) {
|
||||
// There are no more TimerEvents left, so disable matches.
|
||||
data->interface->disable_interrupt();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((int)(data->queue->head->timestamp - data->interface->read()) <= 0) {
|
||||
// This event was in the past:
|
||||
// point to the following one and execute its handler
|
||||
ticker_event_t *p = data->queue->head;
|
||||
data->queue->head = data->queue->head->next;
|
||||
if (data->queue->event_handler != NULL) {
|
||||
(*data->queue->event_handler)(p->id); // NOTE: the handler can set new events
|
||||
}
|
||||
/* Note: We continue back to examining the head because calling the
|
||||
* event handler may have altered the chain of pending events. */
|
||||
} else {
|
||||
// This event and the following ones in the list are in the future:
|
||||
// set it as next interrupt and return
|
||||
data->interface->set_interrupt(data->queue->head->timestamp);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ticker_insert_event(const ticker_data_t *const data, ticker_event_t *obj, timestamp_t timestamp, uint32_t id) {
|
||||
/* disable interrupts for the duration of the function */
|
||||
core_util_critical_section_enter();
|
||||
|
||||
// initialise our data
|
||||
obj->timestamp = timestamp;
|
||||
obj->id = id;
|
||||
|
||||
/* Go through the list until we either reach the end, or find
|
||||
an element this should come before (which is possibly the
|
||||
head). */
|
||||
ticker_event_t *prev = NULL, *p = data->queue->head;
|
||||
while (p != NULL) {
|
||||
/* check if we come before p */
|
||||
if ((int)(timestamp - p->timestamp) < 0) {
|
||||
break;
|
||||
}
|
||||
/* go to the next element */
|
||||
prev = p;
|
||||
p = p->next;
|
||||
}
|
||||
/* if prev is NULL we're at the head */
|
||||
if (prev == NULL) {
|
||||
data->queue->head = obj;
|
||||
data->interface->set_interrupt(timestamp);
|
||||
} else {
|
||||
prev->next = obj;
|
||||
}
|
||||
/* if we're at the end p will be NULL, which is correct */
|
||||
obj->next = p;
|
||||
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
void ticker_remove_event(const ticker_data_t *const data, ticker_event_t *obj) {
|
||||
core_util_critical_section_enter();
|
||||
|
||||
// remove this object from the list
|
||||
if (data->queue->head == obj) {
|
||||
// first in the list, so just drop me
|
||||
data->queue->head = obj->next;
|
||||
if (data->queue->head == NULL) {
|
||||
data->interface->disable_interrupt();
|
||||
} else {
|
||||
data->interface->set_interrupt(data->queue->head->timestamp);
|
||||
}
|
||||
} else {
|
||||
// find the object before me, then drop me
|
||||
ticker_event_t* p = data->queue->head;
|
||||
while (p != NULL) {
|
||||
if (p->next == obj) {
|
||||
p->next = obj->next;
|
||||
break;
|
||||
}
|
||||
p = p->next;
|
||||
}
|
||||
}
|
||||
|
||||
core_util_critical_section_exit();
|
||||
}
|
||||
|
||||
timestamp_t ticker_read(const ticker_data_t *const data)
|
||||
{
|
||||
return data->interface->read();
|
||||
}
|
||||
|
||||
int ticker_get_next_timestamp(const ticker_data_t *const data, timestamp_t *timestamp)
|
||||
{
|
||||
int ret = 0;
|
||||
|
||||
/* if head is NULL, there are no pending events */
|
||||
core_util_critical_section_enter();
|
||||
if (data->queue->head != NULL) {
|
||||
*timestamp = data->queue->head->timestamp;
|
||||
ret = 1;
|
||||
}
|
||||
core_util_critical_section_exit();
|
||||
|
||||
return ret;
|
||||
}
|
|
@ -1,41 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2015 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
static ticker_event_queue_t events;
|
||||
|
||||
static const ticker_interface_t us_interface = {
|
||||
.init = us_ticker_init,
|
||||
.read = us_ticker_read,
|
||||
.disable_interrupt = us_ticker_disable_interrupt,
|
||||
.clear_interrupt = us_ticker_clear_interrupt,
|
||||
.set_interrupt = us_ticker_set_interrupt,
|
||||
};
|
||||
|
||||
static const ticker_data_t us_data = {
|
||||
.interface = &us_interface,
|
||||
.queue = &events,
|
||||
};
|
||||
|
||||
const ticker_data_t* get_us_ticker_data(void)
|
||||
{
|
||||
return &us_data;
|
||||
}
|
||||
|
||||
void us_ticker_irq_handler(void)
|
||||
{
|
||||
ticker_irq_handler(&us_data);
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
/* mbed Microcontroller Library
|
||||
* Copyright (c) 2006-2013 ARM Limited
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#include "wait_api.h"
|
||||
#include "us_ticker_api.h"
|
||||
|
||||
void wait(float s) {
|
||||
wait_us(s * 1000000.0f);
|
||||
}
|
||||
|
||||
void wait_ms(int ms) {
|
||||
wait_us(ms * 1000);
|
||||
}
|
||||
|
||||
void wait_us(int us) {
|
||||
uint32_t start = us_ticker_read();
|
||||
while ((us_ticker_read() - start) < (uint32_t)us);
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue