* build hello world on ax630c

This commit is contained in:
lxowalle
2025-02-06 17:04:46 +08:00
parent 46126eb240
commit 229e3be5ae
5 changed files with 175 additions and 0 deletions

View File

@@ -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")

View File

@@ -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);
}
}

View File

@@ -0,0 +1,70 @@
#include "maix_thread.hpp"
#define THREAD_USE_PTHREAD 0
#if THREAD_USE_PTHREAD
#include <pthread.h>
#else
#include <thread>
#endif
using namespace std;
namespace maix::thread
{
Thread::Thread(std::function<void(void*)> 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

View File

@@ -0,0 +1,66 @@
#include "maix_util.hpp"
#include <fcntl.h>
#include <sys/ioctl.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <vector>
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<void(*)()> *exit_function_list;
void register_exit_function(void (*process)(void)) {
if (exit_function_list == nullptr) {
exit_function_list = new std::vector<void(*)()>;
}
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);
}
}

14
platforms/maixcam2.yaml Normal file
View File

@@ -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: ''