add threads
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "chrg_north.h"
|
||||
|
||||
#define LOG_TAG "chrg.nor"
|
||||
#define DBG_ENABLE
|
||||
#define DBG_SECTION_NAME LOG_TAG
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#define DBG_COLOR
|
||||
#include <rtdbg.h>
|
||||
|
||||
struct chrg_north_t chrgnor = {
|
||||
.tid = RT_NULL,
|
||||
.name = THRED_NAME_NORTH,
|
||||
|
||||
};
|
||||
|
||||
static void chrg_north_entry (void *data)
|
||||
{
|
||||
struct chrg_north_t *pNOR = (struct chrg_north_t *)data;
|
||||
|
||||
if (RT_NULL == pNOR) {
|
||||
return ;
|
||||
}
|
||||
|
||||
char *str = RT_NULL;
|
||||
|
||||
while (1) {
|
||||
if (rt_mb_recv(&pNOR->mb, (rt_uint32_t *)&str, RT_WAITING_FOREVER) == RT_EOK) {
|
||||
rt_kprintf("%s recv %s\r\n", pNOR->name, str);
|
||||
}
|
||||
|
||||
//rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
rt_mb_detach(&pNOR->mb);
|
||||
}
|
||||
|
||||
static int chrg_north_init (void)
|
||||
{
|
||||
rt_err_t ret;
|
||||
struct chrg_north_t *pNOR = &chrgnor;
|
||||
ret = rt_mb_init(&pNOR->mb, "mb_nor", &pNOR->mb_pool[0],
|
||||
sizeof(pNOR->mb_pool)/4, RT_IPC_FLAG_FIFO);
|
||||
if (RT_NULL != ret) {
|
||||
LOG_E("mb init failed.");
|
||||
return RT_ENOMEM;
|
||||
}
|
||||
|
||||
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_entry, pNOR,
|
||||
4096, RT_MAIN_THREAD_PRIORITY, 10);
|
||||
if (RT_NULL != pNOR->tid) {
|
||||
rt_thread_startup(pNOR->tid);
|
||||
LOG_I("start thread '%s'.", pNOR->name);
|
||||
} else {
|
||||
LOG_E("start thread '%s' failed.", pNOR->name);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INIT_APP_EXPORT(chrg_north_init);
|
||||
|
||||
|
||||
@@ -0,0 +1,21 @@
|
||||
#ifndef __CHRG_NORTH_H__
|
||||
#define __CHRG_NORTH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define THRED_NAME_NORTH "thr_nor"
|
||||
|
||||
struct chrg_north_t {
|
||||
rt_thread_t tid;
|
||||
const char *name;
|
||||
|
||||
struct rt_mailbox mb;
|
||||
rt_uint8_t mb_pool[128];
|
||||
rt_uint8_t buf[256];
|
||||
};
|
||||
|
||||
extern struct chrg_north_t chrgnor;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "chrg_south.h"
|
||||
|
||||
#define LOG_TAG "chrg.sou"
|
||||
#define DBG_ENABLE
|
||||
#define DBG_SECTION_NAME LOG_TAG
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#define DBG_COLOR
|
||||
#include <rtdbg.h>
|
||||
|
||||
struct chrg_south_t chrgsou = {
|
||||
.tid = RT_NULL,
|
||||
.name = THRED_NAME_SOUTH,
|
||||
|
||||
};
|
||||
|
||||
static void chrg_south_entry (void *data)
|
||||
{
|
||||
while (1) {
|
||||
//rt_kprintf("sou\r\n");
|
||||
rt_thread_mdelay(1000);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int chrg_south_init (void)
|
||||
{
|
||||
struct chrg_south_t *pSOU = &chrgsou;
|
||||
|
||||
pSOU->tid = rt_thread_create(pSOU->name, chrg_south_entry, pSOU,
|
||||
4096, RT_MAIN_THREAD_PRIORITY, 10);
|
||||
if (RT_NULL != pSOU->tid) {
|
||||
rt_thread_startup(pSOU->tid);
|
||||
LOG_I("start thread '%s'.", pSOU->name);
|
||||
} else {
|
||||
LOG_E("start thread '%s' failed.", pSOU->name);
|
||||
return -RT_ERROR;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
INIT_APP_EXPORT(chrg_south_init);
|
||||
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
#ifndef __CHRG_SOUTH_H__
|
||||
#define __CHRG_SOUTH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#define THRED_NAME_SOUTH "thr_sou"
|
||||
|
||||
struct chrg_south_t {
|
||||
rt_thread_t tid;
|
||||
const char *name;
|
||||
|
||||
};
|
||||
|
||||
extern struct chrg_south_t chrgsou;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user