diff --git a/components/basic/CMakeLists.txt b/components/basic/CMakeLists.txt index 22967b77..16a2c531 100644 --- a/components/basic/CMakeLists.txt +++ b/components/basic/CMakeLists.txt @@ -18,6 +18,8 @@ if(PLATFORM_LINUX) append_srcs_dir(ADD_SRCS "port/linux") elseif(PLATFORM_MAIXCAM) append_srcs_dir(ADD_SRCS "port/maixcam") +elseif(PLATFORM_MAIXCAM2) +append_srcs_dir(ADD_SRCS "port/maixcam2") endif() # list(REMOVE_ITEM COMPONENT_SRCS "src/test.c") diff --git a/components/basic/port/maixcam2/maix_sys_maixcam2.cpp b/components/basic/port/maixcam2/maix_sys_maixcam2.cpp new file mode 100644 index 00000000..c1c4338b --- /dev/null +++ b/components/basic/port/maixcam2/maix_sys_maixcam2.cpp @@ -0,0 +1,23 @@ +#include "maix_sys.hpp" +#include "maix_app.hpp" +#include "signal.h" + +namespace maix::sys +{ + static void signal_handle(int signal) + { + switch (signal) { + case SIGINT: + maix::app::set_exit_flag(true); +#if CONFIG_BUILD_WITH_MAIXPY + raise(SIGINT); +#endif + break; + default: break; + } + } + + void register_default_signal_handle() { + signal(SIGINT, signal_handle); + } +} \ No newline at end of file diff --git a/components/basic/port/maixcam2/maix_thread_maixcam2.cpp b/components/basic/port/maixcam2/maix_thread_maixcam2.cpp new file mode 100644 index 00000000..8ce18170 --- /dev/null +++ b/components/basic/port/maixcam2/maix_thread_maixcam2.cpp @@ -0,0 +1,70 @@ +#include "maix_thread.hpp" + +#define THREAD_USE_PTHREAD 0 + +#if THREAD_USE_PTHREAD +#include +#else +#include +#endif + +using namespace std; +namespace maix::thread +{ + Thread::Thread(std::function func, void *args) + { + this->_func = func; + this->_args = args; +#if THREAD_USE_PTHREAD + this->_thread = new pthread_t; + pthread_create((pthread_t *)this->_thread, NULL, (void *(*)(void *))func, args); +#else + this->_thread = new std::thread(func, args); +#endif + } + + Thread::~Thread() + { + delete (std::thread *)this->_thread; + } + + void Thread::join() + { +#if THREAD_USE_PTHREAD + pthread_join(*(pthread_t *)this->_thread, NULL); +#else + if (((std::thread *)this->_thread)->joinable()) + { + ((std::thread *)this->_thread)->join(); + } +#endif + } + + void Thread::detach() + { +#if THREAD_USE_PTHREAD + pthread_detach(*(pthread_t *)this->_thread); +#else + ((std::thread *)this->_thread)->detach(); +#endif + } + + void sleep_ms(uint32_t ms) + { +#if THREAD_USE_PTHREAD + usleep(ms * 1000); +#else + this_thread::sleep_for(chrono::milliseconds(ms)); +#endif + } + + bool Thread::joinable() + { +#if THREAD_USE_PTHREAD + return true; +#else + return ((std::thread *)this->_thread)->joinable(); +#endif + } + +} // namespace maix::thread diff --git a/components/basic/port/maixcam2/maix_util_maixcam2.cpp b/components/basic/port/maixcam2/maix_util_maixcam2.cpp new file mode 100644 index 00000000..7dd24e22 --- /dev/null +++ b/components/basic/port/maixcam2/maix_util_maixcam2.cpp @@ -0,0 +1,66 @@ +#include "maix_util.hpp" +#include +#include +#include +#include +#include +#include + +namespace maix::util +{ + void disable_kernel_debug() { + char name[] = "/dev/tty1"; + int fd = open(name, O_RDONLY | O_WRONLY); + if (fd < 0) { + log::warn("open %s failed!\r\n", name); + return; + } + if (0 < ioctl(fd, TIOCCONS)) { + log::warn("ioctl(fd, TIOCCONS) failed!\r\n"); + return; + } + + close(fd); + + system("echo 0 > /proc/sys/kernel/printk"); + } + + void enable_kernel_debug() { + char name[] = "/dev/console"; + int fd = open(name, O_RDONLY | O_WRONLY); + if (fd < 0) { + log::warn("open %s failed!\r\n", name); + return; + } + if (0 < ioctl(fd, TIOCCONS)) { + log::warn("ioctl(fd, TIOCCONS) failed!\r\n"); + return; + } + + close(fd); + + system("echo 9 > /proc/sys/kernel/printk"); + } + + static std::vector *exit_function_list; + + void register_exit_function(void (*process)(void)) { + if (exit_function_list == nullptr) { + exit_function_list = new std::vector; + } + exit_function_list->push_back(process); + } + + void do_exit_function() { + if (exit_function_list) { + for (auto& func : *exit_function_list) { + func(); + } + } + } + + void register_atexit() { + atexit(do_exit_function); + } +} + diff --git a/platforms/maixcam2.yaml b/platforms/maixcam2.yaml new file mode 100644 index 00000000..9cd935c8 --- /dev/null +++ b/platforms/maixcam2.yaml @@ -0,0 +1,14 @@ +toolchain: + - name: ARM toolchain + id: gcc-arm-9.10 + default: true + url: https://developer.arm.com/-/media/Files/downloads/gnu-a/9.2-2019.12/binrel/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz + urls: + sites: + sha256sum: 8dfe681531f0bd04fb9c53cf3c0a3368c616aa85d48938eebe2b516376e06a66 + filename: gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu.tar.xz + path: toolchains/maixcam2 + bin_path: toolchains/maixcam2/gcc-arm-9.2-2019.12-x86_64-aarch64-none-linux-gnu/bin + prefix: aarch64-none-linux-gnu- + c_flags: '' + cxx_flags: '' \ No newline at end of file