add more files
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
from building import *
|
||||
import os
|
||||
|
||||
cwd = GetCurrentDir()
|
||||
src = Glob('*.c')
|
||||
|
||||
path = [cwd]
|
||||
|
||||
group = DefineGroup('Applications/thread', src, depend = [''], CPPPATH = path)
|
||||
|
||||
list = os.listdir(cwd)
|
||||
for item in list:
|
||||
if os.path.isfile(os.path.join(cwd, item, 'SConscript')):
|
||||
group = group + SConscript(os.path.join(item, 'SConscript'))
|
||||
|
||||
Return('group')
|
||||
@@ -0,0 +1,7 @@
|
||||
|
||||
#include "chrg_comm.h"
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#ifndef __CHRG_COMM_H__
|
||||
#define __CHRG_COMM_H__
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
|
||||
#include "chrg_lcd.h"
|
||||
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
#ifndef __CHRG_LCD_H__
|
||||
#define __CHRG_LCD_H__
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -4,58 +4,68 @@
|
||||
#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 = {
|
||||
.name = THR_NAME_NORTH,
|
||||
.tid = RT_NULL,
|
||||
.name = THRED_NAME_NORTH,
|
||||
|
||||
.tty = RT_NULL,
|
||||
.rx_len = 0,
|
||||
};
|
||||
|
||||
static void chrg_north_entry (void *data)
|
||||
static void chrg_north_thread_entry (void *data)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
struct chrg_north_t *pNOR = (struct chrg_north_t *)data;
|
||||
|
||||
if (RT_NULL == pNOR) {
|
||||
if ((RT_NULL == pNOR)||(RT_NULL == pNOR->tty)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
char *str = RT_NULL;
|
||||
rt_uint8_t ch;
|
||||
struct chrg_tty_t *pTTY = pNOR->tty;
|
||||
|
||||
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);
|
||||
ret = rt_sem_take(&pTTY->sem_rx, RT_WAITING_FOREVER);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("sem take failed. %d", ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
//rt_thread_mdelay(1000);
|
||||
rt_ringbuffer_getchar(pTTY->rb, &ch);
|
||||
if (pNOR->rx_len < SIZE_BUF_UART) {
|
||||
pNOR->rx_buf[pNOR->rx_len++] = ch;
|
||||
rt_kprintf("%c", ch);
|
||||
}
|
||||
|
||||
if (pNOR->rx_len >= 32) {
|
||||
pNOR->rx_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
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->tty = &chrgtty[IDX_TTY_NORTH];
|
||||
rt_memset(pNOR->rx_buf, 0, SIZE_BUF_UART);
|
||||
|
||||
ret = rt_mutex_init(&pNOR->lock, pNOR->name, RT_IPC_FLAG_FIFO);
|
||||
if (ret != RT_EOK) {
|
||||
LOG_E("init mutex '%s' failed.", pNOR->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_entry, pNOR,
|
||||
4096, RT_MAIN_THREAD_PRIORITY, 10);
|
||||
pNOR->tid = rt_thread_create(pNOR->name, chrg_north_thread_entry, pNOR, 4096,
|
||||
RT_MAIN_THREAD_PRIORITY, 20);
|
||||
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;
|
||||
LOG_E("create thread '%s' failed.", pNOR->name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -65,3 +75,21 @@ static int chrg_north_init (void)
|
||||
INIT_APP_EXPORT(chrg_north_init);
|
||||
|
||||
|
||||
static int north_send(rt_uint8_t argc, char **argv)
|
||||
{
|
||||
rt_ssize_t ret = 0;
|
||||
struct chrg_north_t *pNOR = &chrgnor;
|
||||
struct chrg_tty_t *pTTY = pNOR->tty;
|
||||
|
||||
if (RT_NULL != pTTY->dev) {
|
||||
ret = rt_device_write(pTTY->dev, 0, "1234567890abcdef", 16);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
MSH_CMD_EXPORT(north_send, north send test);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,16 +2,18 @@
|
||||
#define __CHRG_NORTH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_tty.h"
|
||||
|
||||
#define THRED_NAME_NORTH "thr_nor"
|
||||
#define THR_NAME_NORTH "thr_nor"
|
||||
|
||||
struct chrg_north_t {
|
||||
rt_thread_t tid;
|
||||
const char *name;
|
||||
const char *name;
|
||||
struct rt_thread *tid;
|
||||
struct rt_mutex lock;
|
||||
|
||||
struct rt_mailbox mb;
|
||||
rt_uint8_t mb_pool[128];
|
||||
rt_uint8_t buf[256];
|
||||
struct chrg_tty_t *tty;
|
||||
rt_uint16_t rx_len;
|
||||
rt_uint8_t rx_buf[SIZE_BUF_UART];
|
||||
};
|
||||
|
||||
extern struct chrg_north_t chrgnor;
|
||||
|
||||
@@ -4,39 +4,68 @@
|
||||
#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 = {
|
||||
.name = THR_NAME_SOUTH,
|
||||
.tid = RT_NULL,
|
||||
.name = THRED_NAME_SOUTH,
|
||||
|
||||
.tty = RT_NULL,
|
||||
.rx_len = 0,
|
||||
};
|
||||
|
||||
static void chrg_south_entry (void *data)
|
||||
static void chrg_south_thread_entry (void *data)
|
||||
{
|
||||
while (1) {
|
||||
//rt_kprintf("sou\r\n");
|
||||
rt_thread_mdelay(1000);
|
||||
rt_err_t ret = RT_EOK;
|
||||
struct chrg_south_t *pSOU = (struct chrg_south_t *)data;
|
||||
|
||||
if ((RT_NULL == pSOU)||(RT_NULL == pSOU->tty)) {
|
||||
return ;
|
||||
}
|
||||
|
||||
|
||||
rt_uint8_t ch;
|
||||
struct chrg_tty_t *pTTY = pSOU->tty;
|
||||
|
||||
while (1) {
|
||||
ret = rt_sem_take(&pTTY->sem_rx, RT_WAITING_FOREVER);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("sem take failed. %d", ret);
|
||||
continue;
|
||||
}
|
||||
|
||||
rt_ringbuffer_getchar(pTTY->rb, &ch);
|
||||
if (pSOU->rx_len < SIZE_BUF_UART) {
|
||||
pSOU->rx_buf[pSOU->rx_len++] = ch;
|
||||
rt_kprintf("%c", ch);
|
||||
}
|
||||
|
||||
if (pSOU->rx_len >= 32) {
|
||||
pSOU->rx_len = 0;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static int chrg_south_init (void)
|
||||
{
|
||||
rt_err_t ret;
|
||||
struct chrg_south_t *pSOU = &chrgsou;
|
||||
|
||||
pSOU->tid = rt_thread_create(pSOU->name, chrg_south_entry, pSOU,
|
||||
4096, RT_MAIN_THREAD_PRIORITY, 10);
|
||||
|
||||
pSOU->tty = &chrgtty[IDX_TTY_NORTH];
|
||||
rt_memset(pSOU->rx_buf, 0, SIZE_BUF_UART);
|
||||
|
||||
ret = rt_mutex_init(&pSOU->lock, pSOU->name, RT_IPC_FLAG_FIFO);
|
||||
if (ret != RT_EOK) {
|
||||
LOG_E("init mutex '%s' failed.", pSOU->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
pSOU->tid = rt_thread_create(pSOU->name, chrg_south_thread_entry, pSOU, 4096,
|
||||
RT_MAIN_THREAD_PRIORITY, 20);
|
||||
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;
|
||||
LOG_E("create thread '%s' failed.", pSOU->name);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -45,4 +74,21 @@ static int chrg_south_init (void)
|
||||
|
||||
INIT_APP_EXPORT(chrg_south_init);
|
||||
|
||||
static int south_send(rt_uint8_t argc, char **argv)
|
||||
{
|
||||
rt_err_t ret;
|
||||
struct chrg_south_t *pSOU = &chrgsou;
|
||||
struct chrg_tty_t *pTTY = pSOU->tty;
|
||||
|
||||
if (RT_NULL != pTTY->dev) {
|
||||
ret = rt_device_write(pTTY->dev, 0, "1234567890abcdef", 16);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
MSH_CMD_EXPORT(south_send, south send test);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,13 +2,18 @@
|
||||
#define __CHRG_SOUTH_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_tty.h"
|
||||
|
||||
#define THRED_NAME_SOUTH "thr_sou"
|
||||
#define THR_NAME_SOUTH "thr_sou"
|
||||
|
||||
struct chrg_south_t {
|
||||
rt_thread_t tid;
|
||||
const char *name;
|
||||
|
||||
const char *name;
|
||||
struct rt_thread *tid;
|
||||
struct rt_mutex lock;
|
||||
|
||||
struct chrg_tty_t *tty;
|
||||
rt_uint16_t rx_len;
|
||||
rt_uint8_t rx_buf[SIZE_BUF_UART];
|
||||
};
|
||||
|
||||
extern struct chrg_south_t chrgsou;
|
||||
|
||||
Reference in New Issue
Block a user