add transplant to linux

This commit is contained in:
Chen Han
2019-10-25 17:27:54 +08:00
parent f48e74764a
commit d27bafc82e
13 changed files with 1682 additions and 0 deletions

View File

@@ -0,0 +1,41 @@
cmake_minimum_required(VERSION 3.8)
project(hello_world)
set(CMAKE_BUILD_TYPE "Debug")
set(CMAKE_CXX_FLAGS_DEBUG "$ENV{CXXFLAGS} -O0 -Wall -g2 -ggdb")
set(CMAKE_CXX_FLAGS_RELEASE "$ENV{CXXFLAGS} -O3 -Wall")
set(TINY_ROOT ../../../)
include_directories(${TINY_ROOT}/osal/cmsis_os)
include_directories(${TINY_ROOT}/kernel/core/include)
include_directories(${TINY_ROOT}/kernel/evtdrv/include)
include_directories(${TINY_ROOT}/kernel/hal/include)
include_directories(${TINY_ROOT}/kernel/pm/include)
aux_source_directory(${TINY_ROOT}/osal/cmsis_os CMSIS_SRCS)
aux_source_directory(${TINY_ROOT}/kernel/core CORE_SRCS)
aux_source_directory(${TINY_ROOT}/kernel/evtdrv EVTDRV_SRCS)
aux_source_directory(${TINY_ROOT}/kernel/pm PM_SRCS)
set(ARCH_ROOT ${TINY_ROOT}/arch/linux)
include_directories(${ARCH_ROOT}/common/include)
include_directories(${ARCH_ROOT}/posix/gcc)
aux_source_directory(${ARCH_ROOT}/common ARCH_COMMON_SRCS)
aux_source_directory(${ARCH_ROOT}/posix/gcc ARCH_POSIX_SRCS)
set(ARCH_SRCS ${ARCH_COMMON_SRCS} ${ARCH_POSIX_SRCS})
set(TINY_SRCS ${ARCH_SRCS} ${CMSIS_SRCS} ${EVTDRV_SRCS} ${PM_SRCS} ${CORE_SRCS} )
include_directories(./)
include_directories(./inc)
set(APP_SRCS src/main.c)
add_executable(hello_world ${APP_SRCS} ${TINY_SRCS})
target_link_libraries(hello_world pthread)

View File

@@ -0,0 +1,46 @@
#ifndef _TOS_CONFIG_H_
#define _TOS_CONFIG_H_
#include "stddef.h"
#define TOS_CFG_TASK_PRIO_MAX 10u // 配置TencentOS tiny默认支持的最大优先级数量
#define TOS_CFG_ROUND_ROBIN_EN 1u // 配置TencentOS tiny的内核是否开启时间片轮转
#define TOS_CFG_OBJECT_VERIFY 0u // 配置TencentOS tiny是否校验指针合法
#define TOS_CFG_EVENT_EN 1u // TencentOS tiny 事件模块功能宏
#define TOS_CFG_MMHEAP_EN 1u // 配置TencentOS tiny是否开启动态内存模块
#define TOS_CFG_MMHEAP_POOL_SIZE 0x100 // 配置TencentOS tiny动态内存池大小
#define TOS_CFG_MMHEAP_DEFAULT_POOL_SIZE 0x100 // 配置TencentOS tiny动态内存池大小
#define TOS_CFG_MUTEX_EN 1u // 配置TencentOS tiny是否开启互斥锁模块
#define TOS_CFG_QUEUE_EN 1u // 配置TencentOS tiny是否开启队列模块
#define TOS_CFG_TIMER_EN 1u // 配置TencentOS tiny是否开启软件定时器模块
#define TOS_CFG_SEM_EN 1u // 配置TencentOS tiny是否开启信号量模块
#define TOS_CFG_MMBLK_EN 1u
#if (TOS_CFG_QUEUE_EN > 0u)
#define TOS_CFG_MSG_EN 1u
#else
#define TOS_CFG_MSG_EN 0u
#endif
#define TOS_CFG_MSG_POOL_SIZE 10u // 配置TencentOS tiny消息队列大小
#define TOS_CFG_IDLE_TASK_STK_SIZE 256u // 配置TencentOS tiny空闲任务栈大小
#define TOS_CFG_CPU_TICK_PER_SECOND 1000u // 配置TencentOS tiny的tick频率
#define TOS_CFG_CPU_CLOCK 1000000u // 配置TencentOS tiny CPU频率
#define TOS_CFG_TIMER_AS_PROC 1u // 配置是否将TIMER配置成函数模式
#endif

View File

@@ -0,0 +1,36 @@
# How to run the demo in linux
## step1
make sure your develop environment.
+ `cmake` and version greater than 3.8.2
+ `gcc` `gdb` `make` is installed
## step2
make `build` directory and compile in `build`
```bash
mkdir build && cd build
cmake ..
make
```
## step3
run program !!
```bash
# in build directory
./hello_world
```
## other
you can copy this demo to other path, but if you want do it,
you need modify `CMakeLists.txt`. find line
```cmake
set(TINY_ROOT ../../../)
```
and modify `path-to-tinyos`
```cmake
set(TINY_ROOT path-to-tinyos)
```

View File

@@ -0,0 +1,53 @@
#include "cmsis_os.h"
#define TASK1_STK_SIZE 512
void task1(void *arg);
osThreadDef(task1, osPriorityNormal, 1, TASK1_STK_SIZE);
#define TASK2_STK_SIZE 512
void task2(void *arg);
osThreadDef(task2, osPriorityNormal, 1, TASK2_STK_SIZE);
void task1(void *arg)
{
int count = 1;
while (1) {
printf("###This is task1, %d\r\n", count++);
osDelay(2000);
}
}
void task2(void *arg)
{
int count = 1;
while (1) {
#if TOS_CFG_TASK_STACK_DRAUGHT_DEPTH_DETACT_EN > 0u
k_err_t rc;
int depth;
rc = tos_task_stack_draught_depth(K_NULL, &depth);
printf("%d %d\n", rc, depth);
#endif
printf("***This is task2, %d\r\n", count++);
osDelay(1000);
}
}
void application_entry(void *arg)
{
osThreadCreate(osThread(task1), NULL); // Create task1
osThreadCreate(osThread(task2), NULL); // Create task2
}
int main(void)
{
osKernelInitialize(); //TOS Tiny kernel initialize
application_entry(NULL);
osKernelStart(); //Start TOS Tiny
while (1)
{
}
}