add more comments
This commit is contained in:
@@ -1,76 +0,0 @@
|
||||
|
||||
#include <stdio.h>
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
#include "chrg_clk.h"
|
||||
|
||||
#define LOG_TAG "chrg.clk"
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
struct chrg_clk_t chrgclk = {
|
||||
.name = TMR_NAME_CLOCK,
|
||||
.timer_fd = RT_NULL,
|
||||
.cnt = 0,
|
||||
};
|
||||
|
||||
static void chrg_clk_callback (void *args)
|
||||
{
|
||||
struct chrg_clk_t *pCLK = (struct chrg_clk_t *)args;
|
||||
|
||||
pCLK->cnt++;
|
||||
|
||||
if (pCLK->cnt % 60 == 0) {
|
||||
//rt_kprintf("R : %d mins\r\n", pCLK->cnt/60);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
static int chrg_clk_init (void)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
struct chrg_clk_t *pCLK = &chrgclk;
|
||||
|
||||
pCLK->timer_fd = rt_timer_create(pCLK->name, chrg_clk_callback,
|
||||
pCLK, RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC);
|
||||
if (pCLK->timer_fd == RT_NULL) {
|
||||
LOG_E("create '%s' failed.", pCLK->name);
|
||||
return -1;
|
||||
} else {
|
||||
ret = rt_timer_start(pCLK->timer_fd);
|
||||
if (ret != RT_EOK) {
|
||||
LOG_E("start '%s' failed.", pCLK->name);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
INIT_ENV_EXPORT(chrg_clk_init);
|
||||
|
||||
|
||||
int uptime (void)
|
||||
{
|
||||
struct chrg_clk_t *pCLK = &chrgclk;
|
||||
|
||||
if (pCLK != RT_NULL) {
|
||||
int day = pCLK->cnt/86400;
|
||||
int hour = (pCLK->cnt%86400)/3600;
|
||||
int minute = ((pCLK->cnt%86400)%3600)/60;
|
||||
int second = ((pCLK->cnt%86400)%3600)%60;
|
||||
rt_tick_t tick = rt_tick_get();
|
||||
|
||||
rt_kprintf("up %d days, %02d:%02d:%02d.%03d \r\n",
|
||||
day, hour, minute, second, tick%1000);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(uptime, System running time.);
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +0,0 @@
|
||||
#ifndef __CHRG_CLK_H__
|
||||
#define __CHRG_CLK_H__
|
||||
|
||||
#define TMR_NAME_CLOCK "tmr.clk"
|
||||
|
||||
struct chrg_clk_t {
|
||||
const char *name;
|
||||
rt_timer_t timer_fd;
|
||||
rt_uint32_t cnt;
|
||||
|
||||
};
|
||||
|
||||
extern struct chrg_clk_t chrgclk;
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,10 +1,133 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_fal.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 初始化片上FLASH存储驱动,参数读/写FLASH接口实现;
|
||||
升级数据包写入实现;日志写入FLASH实现。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "fal.h"
|
||||
|
||||
#include "chrg_fal.h"
|
||||
|
||||
#ifdef FAL_PART_HAS_TABLE_CFG
|
||||
|
||||
#define LOG_TAG "chrg.fal"
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_read
|
||||
函数描述: 从 FALSH 分区读取数据
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度 *buf:数据缓冲区
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_fal_read (const char *name, rt_uint32_t offset, rt_size_t length, rt_uint8_t *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_partition *part_dev = RT_NULL;
|
||||
if ((RT_NULL == buf)||(length <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
part_dev = fal_partition_find(name);
|
||||
if (RT_NULL == part_dev) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fal_partition_read(part_dev, offset, buf, length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_write
|
||||
函数描述: 将数据写入 FALSH 分区
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度 *buf:数据缓冲区
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_fal_write (const char *name, rt_uint32_t offset, rt_size_t length, rt_uint8_t *buf)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_partition *part_dev = RT_NULL;
|
||||
if ((RT_NULL == buf)||(length <= 0)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
part_dev = fal_partition_find(name);
|
||||
if (RT_NULL == part_dev) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fal_partition_write(part_dev, offset, buf, length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_erase
|
||||
函数描述: 从 FALSH 分区擦除数据
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_fal_erase (const char *name, rt_uint32_t offset, rt_size_t length)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_partition *part_dev = RT_NULL;
|
||||
if (length <= 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
part_dev = fal_partition_find(name);
|
||||
if (RT_NULL == part_dev) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fal_partition_erase(part_dev, offset, length);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_erase_part
|
||||
函数描述: 擦除整个分区数据
|
||||
输入参数: *name: 分区名 offset: 起始地址 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_fal_erase_all (const char *name)
|
||||
{
|
||||
int ret = 0;
|
||||
const struct fal_partition *part_dev = RT_NULL;
|
||||
|
||||
part_dev = fal_partition_find(name);
|
||||
if (RT_NULL == part_dev) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ret = fal_partition_erase_all(part_dev);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_init
|
||||
函数描述: 将 FALSH 分区抽象为设备
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_fal_init (void)
|
||||
{
|
||||
rt_int32_t ret = 0;
|
||||
@@ -25,3 +148,7 @@ static int chrg_fal_init (void)
|
||||
INIT_ENV_EXPORT(chrg_fal_init);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_fal.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 提供参数读/写FLASH接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_FAL_H__
|
||||
#define __CHRG_FAL_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
#ifdef FAL_PART_HAS_TABLE_CFG
|
||||
|
||||
// 以下定义与 fal_cfg.h 中 FAL_PART_TABLE 同步。
|
||||
#define PART_BOOT "boot"
|
||||
#define PART_PARAM "param"
|
||||
#define PART_LOG "log"
|
||||
#define PART_APPLICATION "app"
|
||||
#define PART_DOWNLOAD "download"
|
||||
#define PART_FACTORY "factory"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_read
|
||||
函数描述: 从 FALSH 分区读取数据
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度 *buf:数据缓冲区
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_fal_read (const char *name, rt_uint32_t offset, rt_size_t length, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_write
|
||||
函数描述: 将数据写入 FALSH 分区
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度 *buf:数据缓冲区
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_fal_write (const char *name, rt_uint32_t offset, rt_size_t length, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_erase
|
||||
函数描述: 从 FALSH 分区擦除数据
|
||||
输入参数: *name: 分区名 offset: 偏移地址 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_fal_erase (const char *name, rt_uint32_t offset, rt_size_t length);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_fal_erase_part
|
||||
函数描述: 擦除整个分区数据
|
||||
输入参数: *name: 分区名 offset: 起始地址 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_fal_erase_all (const char *name);
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_gpio.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 一般性 GPIO 读写操作: 管脚设置,读取等
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
@@ -34,7 +42,94 @@ struct chrg_io_t chrgios[TOTAL_IOS] = {
|
||||
[IDX_GPO_SOU_SW_LV2_B2] = {GPO_PIN_SOU_SW_LV2_B2, PIN_MODE_OUTPUT, PIN_LOW}
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_mode_set
|
||||
函数描述: 修改 PIN 引脚方向。
|
||||
输入参数: idx 引脚索引, mode : 输出/输入
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_gpio_mode_set (eIDX_IO idx, rt_uint8_t mode)
|
||||
{
|
||||
if (idx >= TOTAL_IOS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct chrg_io_t *pIO = &chrgios[idx];
|
||||
|
||||
if (PIN_MODE_INPUT == mode) {
|
||||
rt_pin_mode(pIO->base, PIN_MODE_INPUT);
|
||||
pIO->mode = PIN_MODE_INPUT;
|
||||
} else if (PIN_MODE_OUTPUT == mode) {
|
||||
rt_pin_mode(pIO->base, PIN_MODE_OUTPUT);
|
||||
pIO->mode = PIN_MODE_OUTPUT;
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_get
|
||||
函数描述: 读取引脚当前值。
|
||||
输入参数: idx 引脚索引
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 低电平, =1: 高电平
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_gpio_get (eIDX_IO idx)
|
||||
{
|
||||
rt_ssize_t value = 0;
|
||||
if (idx >= TOTAL_IOS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct chrg_io_t *pIO = &chrgios[idx];
|
||||
|
||||
value = rt_pin_read(pIO->base);
|
||||
if (PIN_LOW == value) {
|
||||
pIO->value = PIN_LOW;
|
||||
} else {
|
||||
pIO->value = PIN_HIGH;
|
||||
}
|
||||
|
||||
return pIO->value;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_set
|
||||
函数描述: 设置输出引脚高低电平。
|
||||
输入参数: idx 引脚索引, value 高/低电平
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_gpio_set (eIDX_IO idx, rt_uint8_t value)
|
||||
{
|
||||
if (idx >= TOTAL_IOS) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
struct chrg_io_t *pIO = &chrgios[idx];
|
||||
|
||||
if (PIN_MODE_OUTPUT == pIO->mode) {
|
||||
rt_pin_write(pIO->base, value);
|
||||
pIO->value = value;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpios_init
|
||||
函数描述: 初始化pin脚
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_gpios_init (void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -1,3 +1,13 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_gpio.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 :
|
||||
GPIO口宏定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_GPIO_H__
|
||||
#define __CHRG_GPIO_H__
|
||||
|
||||
@@ -100,6 +110,37 @@ struct chrg_io_t {
|
||||
|
||||
extern struct chrg_io_t chrgios[TOTAL_IOS];
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_mode_set
|
||||
函数描述: 修改 PIN 引脚方向。
|
||||
输入参数: idx 引脚索引, mode : 输出/输入
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_gpio_mode_set (eIDX_IO idx, rt_uint8_t mode);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_get
|
||||
函数描述: 读取引脚当前值。
|
||||
输入参数: idx 引脚索引
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 低电平, =1: 高电平
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_gpio_get (eIDX_IO idx);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_gpio_set
|
||||
函数描述: 设置输出引脚高低电平。
|
||||
输入参数: idx 引脚索引, value 高/低电平
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_gpio_set (eIDX_IO idx, rt_uint8_t value);
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_led.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 采用系统软件定时器驱动多路GPIO
|
||||
LED灯,实现LED等工作模式初始化,闪烁方式等的功能。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_led.h"
|
||||
@@ -51,6 +60,14 @@ struct chrg_led_t chrgleds[TOTAL_LEDS] = {
|
||||
}
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_get
|
||||
函数描述: 读取led pin管脚状态值。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,>=0: 状态值
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_get (eIDX_LED index)
|
||||
{
|
||||
if (index >= TOTAL_LEDS) {
|
||||
@@ -63,6 +80,14 @@ rt_int32_t chrg_led_get (eIDX_LED index)
|
||||
return pLED->pin_value;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_set
|
||||
函数描述: 设置led pin管脚状态值。
|
||||
输入参数: *pLED: led pin定时器信息 value: 值
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_set (struct chrg_led_t *pLED, rt_uint8_t value)
|
||||
{
|
||||
pLED->pin_value = value;
|
||||
@@ -71,6 +96,14 @@ rt_int32_t chrg_led_set (struct chrg_led_t *pLED, rt_uint8_t value)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_toggle
|
||||
函数描述: led pin管脚翻转。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_toggle (eIDX_LED index)
|
||||
{
|
||||
if (index >= TOTAL_LEDS) {
|
||||
@@ -85,16 +118,40 @@ rt_int32_t chrg_led_toggle (eIDX_LED index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_timer_set_on
|
||||
函数描述: 设定状态高的延时。
|
||||
输入参数: *pLED: led pin定时器信息
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_int32_t chrg_led_timer_set_on (struct chrg_led_t *pLED)
|
||||
{
|
||||
return rt_timer_control(pLED->tmr_fd, RT_TIMER_CTRL_SET_TIME, (void *)&pLED->tmr_millis_on);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_timer_set_off
|
||||
函数描述: 设定状态低的延时。
|
||||
输入参数: *pLED: led pin定时器信息
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_int32_t chrg_led_timer_set_off (struct chrg_led_t *pLED)
|
||||
{
|
||||
return rt_timer_control(pLED->tmr_fd, RT_TIMER_CTRL_SET_TIME, (void *)&pLED->tmr_millis_off);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_pulsing
|
||||
函数描述: led pin定时器执行管脚状态设置。
|
||||
输入参数: *pLED: led pin定时器信息, state: 流转状态
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_pulsing (struct chrg_led_t *pLED, rt_uint8_t state)
|
||||
{
|
||||
rt_int32_t ret = 0;
|
||||
@@ -123,6 +180,14 @@ rt_int32_t chrg_led_pulsing (struct chrg_led_t *pLED, rt_uint8_t state)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_timer_timeout_callback
|
||||
函数描述: led pin定时器回调操作。
|
||||
输入参数: *parameter:led pin定时器信息。
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static void chrg_led_timer_timeout_callback (void* parameter)
|
||||
{
|
||||
struct chrg_led_t *pLED = (struct chrg_led_t *)parameter;
|
||||
@@ -155,6 +220,14 @@ static void chrg_led_timer_timeout_callback (void* parameter)
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_timer_start
|
||||
函数描述: 启动led pin定时器。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_int32_t chrg_led_timer_start (eIDX_LED index)
|
||||
{
|
||||
if (index >= TOTAL_LEDS) {
|
||||
@@ -176,6 +249,14 @@ static rt_int32_t chrg_led_timer_start (eIDX_LED index)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_timer_delete
|
||||
函数描述: 删除led pin定时器。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_timer_delete (eIDX_LED index)
|
||||
{
|
||||
if (index >= TOTAL_LEDS) {
|
||||
@@ -185,6 +266,14 @@ rt_int32_t chrg_led_timer_delete (eIDX_LED index)
|
||||
return rt_timer_delete(chrgleds[index].tmr_fd);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_show
|
||||
函数描述: 控制指定灯的工作模式。
|
||||
输入参数: index:灯编号, times:单次/循环, on:亮延时 off:灭延时
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_int32_t chrg_led_show (struct chrg_led_t *pLED, rt_uint32_t times, rt_uint32_t on, rt_uint32_t off)
|
||||
{
|
||||
rt_int32_t ret = 0;
|
||||
@@ -203,6 +292,14 @@ static rt_int32_t chrg_led_show (struct chrg_led_t *pLED, rt_uint32_t times, rt_
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_flashing
|
||||
函数描述: 控制指定灯的工作模式。
|
||||
输入参数: index:灯编号, times:单次/循环, on:亮延时 off:灭延时
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_int32_t chrg_led_flashing (eIDX_LED index, rt_uint32_t times, rt_uint32_t on, rt_uint32_t off)
|
||||
{
|
||||
rt_int32_t ret = -1;
|
||||
@@ -216,6 +313,14 @@ rt_int32_t chrg_led_flashing (eIDX_LED index, rt_uint32_t times, rt_uint32_t on,
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_leds_init
|
||||
函数描述: 启动多个软件定时,用于管理LED灯工作模式。
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_leds_init (void)
|
||||
{
|
||||
rt_uint8_t i = 0;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_led.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 控制LED灯工作模式。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_LED_H__
|
||||
#define __CHRG_LED_H__
|
||||
|
||||
@@ -63,12 +72,54 @@ struct chrg_led_t {
|
||||
|
||||
extern struct chrg_led_t chrgleds[TOTAL_LEDS];
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_pin_get
|
||||
函数描述: 读取led pin管脚状态值。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,>=0: 状态值
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_int32_t chrg_led_get (eIDX_LED index);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_pin_set
|
||||
函数描述: 设置led pin管脚状态值。
|
||||
输入参数: *pLED: led定时器信息 value: 值
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_int32_t chrg_led_set (struct chrg_led_t *pPIN, rt_uint8_t value);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_toggle
|
||||
函数描述: led pin管脚翻转。
|
||||
输入参数: index:灯编号
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_int32_t chrg_led_toggle (eIDX_LED index);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_pulsing
|
||||
函数描述: led pin定时器执行管脚状态设置。
|
||||
输入参数: *pLED: led pin定时器信息, state: 流转状态
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_int32_t chrg_led_pulsing (struct chrg_led_t *pPIN, rt_uint8_t state);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_led_flashing
|
||||
函数描述: 控制指定灯的工作模式。
|
||||
输入参数: index:灯编号, times:单次/循环, on:亮延时 off:灭延时
|
||||
输出参数: -
|
||||
返回说明: <0: 异常,=0: 正常操作
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_int32_t chrg_led_flashing (eIDX_LED index, rt_uint32_t times, rt_uint32_t on, rt_uint32_t off);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_rel.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : sink/source 切换继电器操作。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -13,7 +22,14 @@ struct chrg_rel_t chrgrel[TOTAL_NOR_CHS] = {
|
||||
[IDX_NOR_CH4] = {GPO_PIN_CH4_P0, GPO_PIN_CH4_P1, GPO_PIN_CH4_P2}
|
||||
};
|
||||
|
||||
// 北向继电器组 组合切换
|
||||
/*****************************************************************
|
||||
函数名称: chrg_nor_sw_rel
|
||||
函数描述: 北向继电器组 组合切换。
|
||||
输入参数: ch: 通道索引 id: sink/source
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_nor_sw_rel (eIDX_NOR_CH ch, eIDX_ID id)
|
||||
{
|
||||
if (ch >= TOTAL_NOR_CHS) {
|
||||
@@ -36,6 +52,14 @@ void chrg_nor_sw_rel (eIDX_NOR_CH ch, eIDX_ID id)
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_nor_rel_init
|
||||
函数描述: 北向继电器组 初始化。
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_nor_rel_init (void)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -52,7 +76,7 @@ static int chrg_nor_rel_init (void)
|
||||
|
||||
INIT_DEVICE_EXPORT(chrg_nor_rel_init);
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
int rel_test (int argc, char **argv)
|
||||
{
|
||||
if (argc < 3) {
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_rel.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : sink/source 切换继电器操作。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_REL_H__
|
||||
#define __CHRG_REL_H__
|
||||
|
||||
@@ -14,6 +23,14 @@ struct chrg_rel_t {
|
||||
|
||||
extern struct chrg_rel_t chrgrel[TOTAL_NOR_CHS];
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_nor_sw_rel
|
||||
函数描述: 北向继电器组 组合切换。
|
||||
输入参数: ch: 通道索引 id: sink/source
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_nor_sw_rel (eIDX_NOR_CH ch, eIDX_ID id);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_switch.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : SN74LV4052APW 选通操作接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
|
||||
@@ -12,6 +21,15 @@ L H L 1Y2, 2Y2
|
||||
L H H 1Y3, 2Y3
|
||||
H X X None
|
||||
*/
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_switch_ch
|
||||
函数描述: 控制选通通道。
|
||||
输入参数: inA:管脚号A inB:管脚号B ch:通路
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_switch_ch (rt_base_t inA, rt_base_t inB, eIDX_CH ch)
|
||||
{
|
||||
rt_uint8_t a,b;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_switch.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : SN74LV4052APW 选通操作接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SWITCH_H__
|
||||
#define __CHRG_SWITCH_H__
|
||||
|
||||
@@ -5,6 +14,14 @@
|
||||
|
||||
#include "chrg_def.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_switch_ch
|
||||
函数描述: 控制选通通道。
|
||||
输入参数: inA:管脚号A inB:管脚号B ch:通路
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_switch_ch (rt_base_t inA, rt_base_t inB, eIDX_CH ch);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_tmr.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 芯片内支持的高精度(us级)硬件定时器操作实现:启动、停止、回调等接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -13,18 +21,141 @@ struct chrg_tmr_t chrgtmr[TOTAL_TMRS] = {
|
||||
.dev = RT_NULL,
|
||||
.name = DEV_NAME_HWTIMER_1S,
|
||||
.mode = HWTIMER_MODE_PERIOD,
|
||||
.timeout = 1000000, // 10ms
|
||||
}
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmr_us_callback
|
||||
函数描述: us 计时回调函数
|
||||
输入参数: dev:设备节点,size:数据长度
|
||||
输出参数: -
|
||||
返回说明: =0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_err_t chrg_tmr_1s_callback(rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
rt_kprintf(".");
|
||||
struct chrg_tmr_t *pTMR = (struct chrg_tmr_t *)&chrgtmr[IDX_TMR_1S];
|
||||
pTMR->times++;
|
||||
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
int chrg_tmr_init (eIDX_TMR index)
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_get_count
|
||||
函数描述: 获取指定编号定时器的当前时刻,单位us
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: >=0: 定时器已运转微秒数 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint32_t chrg_tmr_get_count (eIDX_TMR index)
|
||||
{
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
rt_uint32_t cnt = 0;
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
rt_device_control(pTMR->dev, HWTIMER_CTRL_COUNT_GET, &cnt);
|
||||
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_start
|
||||
函数描述: 启动指定编号的定时器
|
||||
输入参数: index: 定时器编号,timeo: 微秒定时
|
||||
输出参数: -
|
||||
返回说明: 0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_err_t chrg_tmr_start (eIDX_TMR index, uint32_t timeo)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return RT_EINVAL;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL == pTMR->dev) {
|
||||
LOG_E("dev '%s' not opened.", pTMR->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTMR->timeout.sec = timeo/1000000;
|
||||
pTMR->timeout.usec = timeo%1000000;
|
||||
|
||||
if (rt_device_write(pTMR->dev, 0, &pTMR->timeout,
|
||||
sizeof(rt_hwtimerval_t)) != sizeof(rt_hwtimerval_t)) {
|
||||
LOG_E("set timer '%s' timeout failed.", pTMR->name);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_stop
|
||||
函数描述: 停止指定编号的定时器
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: 0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_err_t chrg_tmr_stop (eIDX_TMR index)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return RT_EINVAL;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL == pTMR->dev) {
|
||||
LOG_E("dev '%s' not opened.", pTMR->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = rt_device_control(pTMR->dev, HWTIMER_CTRL_STOP, RT_NULL);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("set '%s' stop failed. %d", pTMR->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmr_release
|
||||
函数描述: 释放指定编号的定时器
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: 0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_tmr_release (eIDX_TMR index)
|
||||
{
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return ;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL != pTMR->dev) {
|
||||
rt_device_close(pTMR->dev);
|
||||
pTMR->dev = RT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_open
|
||||
函数描述: 打开指定编号的硬件定时器设备
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: =0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tmr_open (eIDX_TMR index)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
rt_uint32_t freq = 1000000;
|
||||
@@ -67,77 +198,27 @@ int chrg_tmr_init (eIDX_TMR index)
|
||||
return -1;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
rt_err_t chrg_tmr_start (eIDX_TMR index, uint32_t timeo)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return RT_EINVAL;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL == pTMR->dev) {
|
||||
LOG_E("dev '%s' not opened.", pTMR->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
pTMR->timeout.sec = timeo/1000000;
|
||||
pTMR->timeout.usec = timeo%1000000;
|
||||
|
||||
if (rt_device_write(pTMR->dev, 0, &pTMR->timeout,
|
||||
sizeof(rt_hwtimerval_t)) != sizeof(rt_hwtimerval_t)) {
|
||||
LOG_E("set timer '%s' timeout failed.", pTMR->name);
|
||||
return ret;
|
||||
if (IDX_TMR_1S == pTMR->index) {
|
||||
chrg_tmr_start(pTMR->index, TIME_TRIGGER_SECOND);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
rt_err_t chrg_tmr_stop (eIDX_TMR index)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return RT_EINVAL;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL == pTMR->dev) {
|
||||
LOG_E("dev '%s' not opened.", pTMR->name);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ret = rt_device_control(pTMR->dev, HWTIMER_CTRL_STOP, RT_NULL);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("set '%s' stop failed. %d", pTMR->name, ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
void chrg_tmr_release (eIDX_TMR index)
|
||||
{
|
||||
if (index >= TOTAL_TMRS) {
|
||||
return ;
|
||||
}
|
||||
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[index];
|
||||
if (RT_NULL != pTMR->dev) {
|
||||
rt_device_close(pTMR->dev);
|
||||
pTMR->dev = RT_NULL;
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_init
|
||||
函数描述: 初始化多个硬件高精度定时器
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: 0: 正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tmrs_init (void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (i = 0; i < TOTAL_TMRS; i++) {
|
||||
chrg_tmr_init((eIDX_TMR)i);
|
||||
chrg_tmr_open((eIDX_TMR)i);
|
||||
}
|
||||
|
||||
return 0;
|
||||
@@ -146,6 +227,25 @@ int chrg_tmrs_init (void)
|
||||
|
||||
INIT_ENV_EXPORT(chrg_tmrs_init);
|
||||
|
||||
static int uptime (int argc, char **argv)
|
||||
{
|
||||
struct chrg_tmr_t *pTMR = &chrgtmr[IDX_TMR_1S];
|
||||
|
||||
int day = pTMR->times/86400;
|
||||
int hour = (pTMR->times%86400)/3600;
|
||||
int minute = ((pTMR->times%86400)%3600)/60;
|
||||
int second = ((pTMR->times%86400)%3600)%60;
|
||||
|
||||
rt_uint32_t us = chrg_tmr_get_count(IDX_TMR_1S);
|
||||
rt_kprintf("up %d days, %02d:%02d:%02d.%06d \r\n",
|
||||
day, hour, minute, second, us%1000000);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(uptime, system running life.)
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
static int sec_tmr(int argc, char **argv)
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_tmr.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 高精度(us级)硬件定时器调用接口:启动、停止、读取时刻等接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_TMR_H__
|
||||
#define __CHRG_TMR_H__
|
||||
|
||||
@@ -5,8 +14,9 @@
|
||||
#include <rtdevice.h>
|
||||
|
||||
|
||||
#define DEV_NAME_HWTIMER_1S "timer2"
|
||||
#define DEV_NAME_HWTIMER_1S "timer2" // 32bits
|
||||
|
||||
#define TIME_TRIGGER_SECOND (1000000) // 1s
|
||||
|
||||
typedef enum {
|
||||
IDX_TMR_1S = 0, // 1s 周期
|
||||
@@ -21,16 +31,40 @@ struct chrg_tmr_t {
|
||||
rt_hwtimerval_t timeout; // 周期 us
|
||||
eIDX_TMR index; // 定时器编号
|
||||
|
||||
rt_uint32_t times; // 定时器触发计数
|
||||
};
|
||||
|
||||
extern struct chrg_tmr_t chrgtmr[TOTAL_TMRS];
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_start
|
||||
函数描述: 启动指定编号的定时器
|
||||
输入参数: index: 定时器编号,timeo: 微秒定时
|
||||
输出参数: -
|
||||
返回说明: 0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_err_t chrg_tmr_start (eIDX_TMR index, uint32_t timeo);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_stop
|
||||
函数描述: 停止指定编号的定时器
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: 0: 正常 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_err_t chrg_tmr_stop (eIDX_TMR index);
|
||||
|
||||
extern void chrg_tmr_release (eIDX_TMR index);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tmrs_get_count
|
||||
函数描述: 获取指定编号定时器的当前时刻,单位us
|
||||
输入参数: index: 定时器编号
|
||||
输出参数: -
|
||||
返回说明: >=0: 定时器已运转微秒数 <0 :异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint32_t chrg_tmr_get_count (eIDX_TMR index);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_tty.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现串口设备创建、销毁、配置、读取数据、发送数据等接口函数。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
@@ -12,6 +20,14 @@
|
||||
|
||||
|
||||
#ifdef TTY_USING_DMA_TX
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_send_comp_hook
|
||||
函数描述: 串口DMA方式接收回调。
|
||||
输入参数: dev: 设备信息, *buffer:数据缓冲
|
||||
输出参数: -
|
||||
返回说明: 0:正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_err_t chrg_tty_send_comp_hook (rt_device_t dev, void *buffer)
|
||||
{
|
||||
struct chrg_tty_t *pTTY = (struct chrg_tty_t *)(dev->user_data);
|
||||
@@ -21,6 +37,14 @@ static rt_err_t chrg_tty_send_comp_hook (rt_device_t dev, void *buffer)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_recv_ind_hook
|
||||
函数描述: 串口接收回调。
|
||||
输入参数: dev: 设备信息, size:数据长度
|
||||
输出参数: -
|
||||
返回说明: 0:正常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static rt_err_t chrg_tty_recv_ind_hook (rt_device_t dev, rt_size_t size)
|
||||
{
|
||||
struct chrg_tty_t *pTTY = (struct chrg_tty_t *)(dev->user_data);
|
||||
@@ -31,6 +55,14 @@ static rt_err_t chrg_tty_recv_ind_hook (rt_device_t dev, rt_size_t size)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_cal_byte_tmo
|
||||
函数描述: 根据波特率计算字节通信超时。
|
||||
输入参数: baudrate: 波特率
|
||||
输出参数: -
|
||||
返回说明: 超时时间
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_tty_cal_byte_tmo (int baudrate)
|
||||
{
|
||||
int tmo = (40 * 1000) / baudrate;
|
||||
@@ -44,7 +76,14 @@ static int chrg_tty_cal_byte_tmo (int baudrate)
|
||||
return (tmo);
|
||||
}
|
||||
|
||||
// mode : 0--receive mode, 1--send mode
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_mode_set
|
||||
函数描述: 设置流向控制脚。
|
||||
输入参数: *pTTY: tty设备信息, mode: 流控引脚初始值
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: mode : 0--receive mode, 1--send mode
|
||||
*****************************************************************/
|
||||
void chrg_tty_mode_set (struct chrg_tty_t *pTTY, int mode)
|
||||
{
|
||||
if (pTTY->pin < 0) {
|
||||
@@ -70,6 +109,14 @@ void chrg_tty_mode_set (struct chrg_tty_t *pTTY, int mode)
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_dev_open
|
||||
函数描述: 打开系统已注册的串口设备。
|
||||
输入参数: *pTTY: tty设备信息
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_tty_dev_open (struct chrg_tty_t *pTTY)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
@@ -119,15 +166,15 @@ static int chrg_tty_dev_open (struct chrg_tty_t *pTTY)
|
||||
return (-RT_ERROR);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief create tty instance dynamically
|
||||
* @param name - serial device name
|
||||
* @param baudrate - serial baud rate
|
||||
* @param parity - serial parity mode
|
||||
* @param pin - mode contrle pin
|
||||
* @param level - send mode level
|
||||
* @retval instance handle
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_create
|
||||
函数描述: 创建串口设备实例,并做初始化。
|
||||
输入参数: *devname: 设备名,baudrate: 波特率 parity: 奇偶校验
|
||||
pin: 流向控制脚(RS485必填,RS232时为-1),level: 流向控制初始值
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
struct chrg_tty_t *chrg_tty_create (const char *devname, int baudrate, int parity, int pin, int level)
|
||||
{
|
||||
struct chrg_tty_t *pTTY = RT_NULL;
|
||||
@@ -183,11 +230,14 @@ struct chrg_tty_t *chrg_tty_create (const char *devname, int baudrate, int parit
|
||||
return pTTY;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief destory tty instance created dynamically
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_destory
|
||||
函数描述: 释放串口设备实例。
|
||||
输入参数: *pTTY: tty设备信息
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_destory (struct chrg_tty_t *pTTY)
|
||||
{
|
||||
if (RT_NULL == pTTY) {
|
||||
@@ -212,15 +262,18 @@ int chrg_tty_destory (struct chrg_tty_t *pTTY)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief config tty params
|
||||
* @param pTTY - instance handle
|
||||
* @param baudrate - baudrate of communication
|
||||
* @param databits - data bits, 5~8
|
||||
* @param parity - parity bit, 0~2, 0 - none, 1 - odd, 2 - even
|
||||
* @param stopbits - stop bits, 0~1, 0 - 1 stop bit, 1 - 2 stop bits
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_config
|
||||
函数描述: 配置串口设备通信参数。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
baudrate:波特率
|
||||
databits:数据位数 5~8
|
||||
parity:奇偶校验 0-none 1-odd 2-even
|
||||
stopbits:停止位数 0: 1 stop bit 1: 2 stop bits
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_config (struct chrg_tty_t *pTTY,
|
||||
int baudrate, int databits, int parity, int stopbits)
|
||||
{
|
||||
@@ -246,12 +299,15 @@ int chrg_tty_config (struct chrg_tty_t *pTTY,
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief set wait datas timeout for receiving
|
||||
* @param pTTY - instance handle
|
||||
* @param tmo_ms - receive wait timeout, 0--no wait, <0--wait forever, >0--wait timeout, default = 0
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_set_recv_tmo
|
||||
函数描述: 设置数据块间接收超时时间。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
tmo_ms:超时时间 ms 0:no wait <0: wait forever >0: wait timeout, default=0
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_set_recv_tmo (struct chrg_tty_t *pTTY, int tmo_ms)
|
||||
{
|
||||
if (RT_NULL == pTTY) {
|
||||
@@ -264,12 +320,15 @@ int chrg_tty_set_recv_tmo (struct chrg_tty_t *pTTY, int tmo_ms)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief set byte interval timeout for receiving
|
||||
* @param pTTY - instance handle
|
||||
* @param tmo_ms - byte interval timeout, default is calculated from baudrate
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_set_byte_tmo
|
||||
函数描述: 设置字节间接收超时时间。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
tmo_ms:超时时间 ms ,默认由波特率计算得到。
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_set_byte_tmo (struct chrg_tty_t *pTTY, int tmo_ms)
|
||||
{
|
||||
if (RT_NULL == pTTY) {
|
||||
@@ -288,11 +347,14 @@ int chrg_tty_set_byte_tmo (struct chrg_tty_t *pTTY, int tmo_ms)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief open tty connect
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_connect
|
||||
函数描述: 连接串口实例,并初始化。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_connect (struct chrg_tty_t * pTTY)
|
||||
{
|
||||
if (RT_NULL == pTTY) {
|
||||
@@ -327,11 +389,14 @@ int chrg_tty_connect (struct chrg_tty_t * pTTY)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief close tty connect
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_disconnect
|
||||
函数描述: 断开串口实例,并释放资源。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_disconn (struct chrg_tty_t *pTTY)
|
||||
{
|
||||
if (RT_NULL == pTTY) {
|
||||
@@ -366,13 +431,14 @@ int chrg_tty_disconn (struct chrg_tty_t *pTTY)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief receive datas from tty
|
||||
* @param pTTY - instance handle
|
||||
* @param buf - buffer addr
|
||||
* @param size - maximum length of received datas
|
||||
* @retval >=0 - length of received datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_recv
|
||||
函数描述: 接收串口数据。
|
||||
输入参数: *pTTY: tty设备信息,size: 待接收数据长度。
|
||||
输出参数: *buf: 接收数据缓冲
|
||||
返回说明: <0:异常 =0:中止 >0:已接收数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_recv (struct chrg_tty_t *pTTY, void *buf, int size)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
@@ -430,13 +496,14 @@ int chrg_tty_recv (struct chrg_tty_t *pTTY, void *buf, int size)
|
||||
return recv_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief send datas to tty
|
||||
* @param pTTY - instance handle
|
||||
* @param buf - buffer addr
|
||||
* @param size - length of send datas
|
||||
* @retval >=0 - length of sent datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_send
|
||||
函数描述: 发送串口数据。
|
||||
输入参数: *pTTY: tty设备信息,*buf: 发送数据缓冲,size: 待发送数据长度。
|
||||
输出参数:
|
||||
返回说明: <0:异常 >0:已发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_send (struct chrg_tty_t *pTTY, void *buf, int size)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
@@ -467,11 +534,14 @@ int chrg_tty_send (struct chrg_tty_t *pTTY, void *buf, int size)
|
||||
return send_len;
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief break tty receive wait
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_break_recv
|
||||
函数描述: 中止数据接收。
|
||||
输入参数: *pTTY: tty设备信息。
|
||||
输出参数:
|
||||
返回说明: <0:异常 0:正常中止
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_break_recv (struct chrg_tty_t *pTTY)
|
||||
{
|
||||
if ((pTTY == RT_NULL) || (pTTY->evt == RT_NULL)) {
|
||||
@@ -483,15 +553,16 @@ int chrg_tty_break_recv (struct chrg_tty_t *pTTY)
|
||||
return (RT_EOK);
|
||||
}
|
||||
|
||||
/*
|
||||
* @brief send data to tty and then receive response data from tty
|
||||
* @param pTTY - instance handle
|
||||
* @param send_buf - send buffer addr
|
||||
* @param send_len - length of send datas
|
||||
* @param recv_buf - recv buffer addr
|
||||
* @param recv_size - maximum length of received datas
|
||||
* @retval >=0 - length of received datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_send_then_recv
|
||||
函数描述: 串口发送数据后接收数据。
|
||||
输入参数: *pTTY: tty设备信息,*send_buf:发送数据区,
|
||||
send_len:发送数据长度,*recv_buf:接收数据区,
|
||||
recv_size:待接收数据长度
|
||||
输出参数:
|
||||
返回说明: <0:异常 >=0:已接收数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_tty_send_then_recv (struct chrg_tty_t *pTTY,
|
||||
void *send_buf, int send_len, void *recv_buf, int recv_size)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_tty.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 串口设备调用接口:创建、销毁、配置、读取数据、发送数据等接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_TTY_H__
|
||||
#define __CHRG_TTY_H__
|
||||
|
||||
@@ -51,102 +60,134 @@ struct chrg_tty_t {
|
||||
#endif
|
||||
};
|
||||
|
||||
/*
|
||||
* @brief create tty instance dynamically
|
||||
* @param serial - serial device name
|
||||
* @param baudrate - serial baud rate
|
||||
* @param parity - serial parity mode
|
||||
* @param pin - mode contrle pin
|
||||
* @param level - send mode level
|
||||
* @retval instance handle
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_create
|
||||
函数描述: 创建串口设备实例,并做初始化。
|
||||
输入参数: *devname: 设备名,baudrate: 波特率 parity: 奇偶校验
|
||||
pin: 流向控制脚(RS485必填,RS232时为-1),level: 流向控制初始值
|
||||
输出参数: -
|
||||
返回说明: 0: 正确 <0: 异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
struct chrg_tty_t *chrg_tty_create (const char *name, int baudrate, int parity, int pin, int level);
|
||||
|
||||
/*
|
||||
* @brief destory tty instance created dynamically
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_destory
|
||||
函数描述: 释放串口设备实例。
|
||||
输入参数: *pTTY: tty设备信息
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_destory (struct chrg_tty_t *pTTY);
|
||||
|
||||
/*
|
||||
* @brief config tty params
|
||||
* @param pTTY - instance handle
|
||||
* @param baudrate - baudrate of communication
|
||||
* @param databits - data bits, 5~8
|
||||
* @param parity - parity bit, 0~2, 0 - none, 1 - odd, 2 - even
|
||||
* @param stopbits - stop bits, 0~1, 0 - 1 stop bit, 1 - 2 stop bits
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_config
|
||||
函数描述: 配置串口设备通信参数。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
baudrate:波特率
|
||||
databits:数据位数 5~8
|
||||
parity:奇偶校验 0-none 1-odd 2-even
|
||||
stopbits:停止位数 0: 1 stop bit 1: 2 stop bits
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_config (struct chrg_tty_t *pTTY,
|
||||
int baudrate, int databits, int parity, int stopbits);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_mode_set
|
||||
函数描述: 设置流向控制脚。
|
||||
输入参数: *pTTY: tty设备信息, mode: 流控引脚初始值
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: mode : 0--receive mode, 1--send mode
|
||||
*****************************************************************/
|
||||
extern void chrg_tty_mode_set (struct chrg_tty_t *pTTY, int mode);
|
||||
|
||||
/*
|
||||
* @brief set wait datas timeout for receiving
|
||||
* @param pTTY - instance handle
|
||||
* @param tmo_ms - receive wait timeout, 0--no wait, <0--wait forever, >0--wait timeout, default = 0
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_set_recv_tmo
|
||||
函数描述: 设置数据块间接收超时时间。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
tmo_ms:超时时间 ms 0:no wait <0: wait forever >0: wait timeout, default=0
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_set_recv_tmo (struct chrg_tty_t *pTTY, int tmo_ms);
|
||||
|
||||
/*
|
||||
* @brief set byte interval timeout for receiving
|
||||
* @param pTTY - instance handle
|
||||
* @param tmo_ms - byte interval timeout, default is calculated from baudrate
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_set_byte_tmo
|
||||
函数描述: 设置字节间接收超时时间。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
tmo_ms:超时时间 ms ,默认由波特率计算得到。
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_set_byte_tmo (struct chrg_tty_t *pTTY, int tmo_ms);
|
||||
|
||||
/*
|
||||
* @brief open tty connect
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_connect
|
||||
函数描述: 连接串口实例,并初始化。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_connect (struct chrg_tty_t *pTTY);
|
||||
|
||||
/*
|
||||
* @brief close tty connect
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_disconnect
|
||||
函数描述: 断开串口实例,并释放资源。
|
||||
输入参数: *pTTY: tty设备信息,
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_disconn (struct chrg_tty_t *pTTY);
|
||||
|
||||
/*
|
||||
* @brief receive datas from tty
|
||||
* @param pTTY - instance handle
|
||||
* @param buf - buffer addr
|
||||
* @param size - maximum length of received datas
|
||||
* @retval >=0 - length of received datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_recv
|
||||
函数描述: 接收串口数据。
|
||||
输入参数: *pTTY: tty设备信息,size: 待接收数据长度。
|
||||
输出参数: *buf: 接收数据缓冲
|
||||
返回说明: <0:异常 =0:中止 >0:已接收数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_recv (struct chrg_tty_t *pTTY, void *buf, int size);
|
||||
|
||||
/*
|
||||
* @brief send datas to tty
|
||||
* @param pTTY - instance handle
|
||||
* @param buf - buffer addr
|
||||
* @param size - length of send datas
|
||||
* @retval >=0 - length of sent datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_send
|
||||
函数描述: 发送串口数据。
|
||||
输入参数: *pTTY: tty设备信息,*buf: 发送数据缓冲,size: 待发送数据长度。
|
||||
输出参数:
|
||||
返回说明: <0:异常 >0:已发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_send (struct chrg_tty_t *pTTY, void *buf, int size);
|
||||
|
||||
/*
|
||||
* @brief break tty receive wait
|
||||
* @param pTTY - instance handle
|
||||
* @retval 0 - success, other - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_break_recv
|
||||
函数描述: 中止数据接收。
|
||||
输入参数: *pTTY: tty设备信息。
|
||||
输出参数:
|
||||
返回说明: <0:异常 0:正常中止
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_break_recv (struct chrg_tty_t *pTTY);
|
||||
|
||||
/*
|
||||
* @brief send data to tty and then receive response data from tty
|
||||
* @param pTTY - instance handle
|
||||
* @param send_buf - send buffer addr
|
||||
* @param send_len - length of send datas
|
||||
* @param recv_buf - recv buffer addr
|
||||
* @param recv_size - maximum length of received datas
|
||||
* @retval >=0 - length of received datas, <0 - error
|
||||
*/
|
||||
/*****************************************************************
|
||||
函数名称: chrg_tty_send_then_recv
|
||||
函数描述: 串口发送数据后接收数据。
|
||||
输入参数: *pTTY: tty设备信息,*send_buf:发送数据区,
|
||||
send_len:发送数据长度,*recv_buf:接收数据区,
|
||||
recv_size:待接收数据长度
|
||||
输出参数:
|
||||
返回说明: <0:异常 >=0:已接收数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_tty_send_then_recv (struct chrg_tty_t *pTTY,
|
||||
void *send_buf, int send_len, void *recv_buf, int recv_size);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_vcom.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现USB虚拟串口作为控制终端。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <board.h>
|
||||
@@ -31,6 +39,14 @@ int chrg_vcom_init (void)
|
||||
}
|
||||
#endif
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_vcom_console_init
|
||||
函数描述: 配置控制台为虚拟串口。
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: 0
|
||||
其它说明: 需要作为环境配置启动。
|
||||
*****************************************************************/
|
||||
int chrg_vcom_console_init (void)
|
||||
{
|
||||
rt_console_set_device(DEV_NAME_VCOM);
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_vcom.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现USB虚拟串口作为控制终端。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_VCOM_H__
|
||||
#define __CHRG_VCOM_H__
|
||||
|
||||
@@ -9,3 +18,4 @@
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_wdt.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现芯片内部看门狗初始化以及喂狗函数。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include <rtdevice.h>
|
||||
@@ -14,11 +22,27 @@ struct chrg_wdt_t chrgwdt = {
|
||||
.feed = 3,
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_wdt_feed
|
||||
函数描述: 喂内部硬件狗函数
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_wdt_feed (void)
|
||||
{
|
||||
rt_device_control(chrgwdt.dev, RT_DEVICE_CTRL_WDT_KEEPALIVE, RT_NULL);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_wdt_init
|
||||
函数描述: 芯片内部硬件狗设备初始化打开
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: 0:正常 <0:异常
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_wdt_init (void)
|
||||
{
|
||||
rt_err_t ret;
|
||||
@@ -50,3 +74,5 @@ static int chrg_wdt_init (void)
|
||||
INIT_PREV_EXPORT(chrg_wdt_init);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_wdt.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现芯片内部看门狗初始化以及喂狗函数。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_WDT_H__
|
||||
#define __CHRG_WDT_H__
|
||||
|
||||
@@ -17,6 +26,14 @@ struct chrg_wdt_t {
|
||||
|
||||
extern struct chrg_wdt_t chrgwdt;
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_wdt_feed
|
||||
函数描述: 喂内部硬件狗函数
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_wdt_feed (void);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_comm.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现对外通讯协议 MODBUS 服务端,以独立线程等待处理响应请求数据。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -327,6 +335,14 @@ eMBErrorCode mb_reg_discrete_cb (rt_uint8_t *pucRegBuffer, rt_uint16_t usAddress
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcReadCoils
|
||||
函数描述: 读多个继电器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcReadCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -360,6 +376,14 @@ eMBException funcReadCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcReadDiscreteInputs
|
||||
函数描述: 读离散输入
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcReadDiscreteInputs (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -393,6 +417,14 @@ eMBException funcReadDiscreteInputs (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcReadHoldingRegister
|
||||
函数描述: 读保持寄存器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcReadHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -425,6 +457,14 @@ eMBException funcReadHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcReadInputRegister
|
||||
函数描述: 读输入寄存器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -457,6 +497,14 @@ eMBException funcReadInputRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcWriteCoil
|
||||
函数描述: 写单个保持继电器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcWriteCoil (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -494,6 +542,14 @@ eMBException funcWriteCoil (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcWriteHoldingRegister
|
||||
函数描述: 写多个保持继电器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcWriteHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -519,6 +575,14 @@ eMBException funcWriteHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcWriteMultipleCoils
|
||||
函数描述: 写多个继电器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcWriteMultipleCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -555,6 +619,14 @@ eMBException funcWriteMultipleCoils (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
return eStatus;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: funcWriteMultipleHoldingRegister
|
||||
函数描述: 写多个寄存器
|
||||
输入参数: reqFrame: 请求数据 reqLen: 请求长度 resFrame:响应数据 resLen:响应长度
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
eMBException funcWriteMultipleHoldingRegister (rt_uint8_t *reqFrame, rt_uint16_t reqLen,
|
||||
rt_uint8_t *resFrame, rt_uint16_t *resLen)
|
||||
{
|
||||
@@ -602,7 +674,14 @@ static struct code_func_t funcHandlers[MB_HANDLERS_MAX] = {
|
||||
{MB_WRITE_MULTIPLE_REGISTERS, funcWriteMultipleHoldingRegister},
|
||||
};
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_comm_parse_msg
|
||||
函数描述: 解析请求的消息
|
||||
输入参数: pCOMM: 消息结构
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: 分命令处理对应消息。地址为广播时不应答
|
||||
*****************************************************************/
|
||||
static int chrg_comm_parse_msg (struct chrg_comm_t *pCOMM)
|
||||
{
|
||||
if (RT_NULL == pCOMM) {
|
||||
@@ -661,6 +740,14 @@ static int chrg_comm_parse_msg (struct chrg_comm_t *pCOMM)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_comm_thread_entry
|
||||
函数描述: 对外RS485通信线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_comm_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_comm.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现对外通讯协议 MODBUS 服务端,以独立线程等待处理响应请求数据。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_COMM_H__
|
||||
#define __CHRG_COMM_H__
|
||||
|
||||
@@ -151,6 +160,14 @@ struct chrg_comm_t {
|
||||
|
||||
extern struct chrg_comm_t chrgcomm;
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_comm_thread_entry
|
||||
函数描述: 对外RS485通信线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_comm_thread_entry (void *data);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_lcd.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现与显示屏交互,向屏更新数据与接收屏控制数据,以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,13 +17,14 @@
|
||||
#include "chrg_south.h"
|
||||
#include "chrg_roll_sou.h"
|
||||
#include "chrg_eload.h"
|
||||
|
||||
#include "chrg_utils.h"
|
||||
#include "chrg_lcd.h"
|
||||
|
||||
#define LOG_TAG "chrg.lcd"
|
||||
#define DBG_LEVEL DBG_LOG
|
||||
#include <rtdbg.h>
|
||||
|
||||
int Flag_R1=0,Flag_R2=0,Flag_R3=0,Flag_R4=0;
|
||||
struct chrg_lcd_t chrglcd = {
|
||||
.devname = DEV_NAME_LCD,
|
||||
.tty = RT_NULL,
|
||||
@@ -28,8 +38,18 @@ struct chrg_lcd_t chrglcd = {
|
||||
// 55 41 00 0D 0A 停止
|
||||
// 55 41 01 0D 0A 运行
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_lcd_parse
|
||||
函数描述: 接收显示屏的控制消息
|
||||
输入参数: *recv: 接收数据 len:长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: 本部分为 HMI 文件自定义命令,需要统一规划管理
|
||||
*****************************************************************/
|
||||
static int chrg_lcd_parse (rt_uint8_t *recv, rt_uint16_t len)
|
||||
{
|
||||
rt_uint16_t Recv_Data;
|
||||
|
||||
if (len < 5) {
|
||||
return -1;
|
||||
}
|
||||
@@ -49,11 +69,17 @@ static int chrg_lcd_parse (rt_uint8_t *recv, rt_uint16_t len)
|
||||
case 0x23:
|
||||
case 0x24: { // 电源/负载
|
||||
ch = recv[LCD_IDX_CMD] - 0x21;
|
||||
if (Flag_R1 == 1 && ch == 0) return 0;
|
||||
if (Flag_R2 == 1 && ch == 1) return 0;
|
||||
if (Flag_R3 == 1 && ch == 2) return 0;
|
||||
if (Flag_R4 == 1 && ch == 3) return 0;
|
||||
pSW = &pNOR->sw[ch];
|
||||
if (1 == recv[LCD_IDX_VAL]) {
|
||||
pSW->id = ID_SOURCE;
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_ELOAD, ELOAD_SOURCE);
|
||||
} else {
|
||||
pSW->id = ID_SINK;
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_ELOAD, ELOAD_LOAD);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -63,10 +89,14 @@ static int chrg_lcd_parse (rt_uint8_t *recv, rt_uint16_t len)
|
||||
case 0x33:
|
||||
case 0x34: { // 恒压/恒流
|
||||
ch = recv[LCD_IDX_CMD] - 0x31;
|
||||
if (Flag_R1 == 1 && ch == 0) return 0;
|
||||
if (Flag_R2 == 1 && ch == 1) return 0;
|
||||
if (Flag_R3 == 1 && ch == 2) return 0;
|
||||
if (Flag_R4 == 1 && ch == 3) return 0;
|
||||
if (1 == recv[LCD_IDX_VAL]) {
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, MODE_CONSTANT_VOLTAGE);
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_MODE, MODE_CONSTANT_VOLTAGE);
|
||||
} else {
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, MODE_CONSTANT_CURRENT);
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_MODE, MODE_CONSTANT_CURRENT);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -77,23 +107,64 @@ static int chrg_lcd_parse (rt_uint8_t *recv, rt_uint16_t len)
|
||||
case 0x44: { // 运行/停止
|
||||
ch = recv[LCD_IDX_CMD] - 0x41;
|
||||
if (1 == recv[LCD_IDX_VAL]) {
|
||||
pNOR->enable[ch] = 0;
|
||||
pSOU->enable[ch] = 0;
|
||||
//pNOR->enable[ch] = 0;
|
||||
//pSOU->enable[ch] = 0;
|
||||
switch(ch) {
|
||||
case 0: Flag_R1 = 1; break;
|
||||
case 1: Flag_R2 = 1; break;
|
||||
case 2: Flag_R3 = 1; break;
|
||||
case 3: Flag_R4 = 1; break;
|
||||
}
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_WORK,WORK_START);
|
||||
} else {
|
||||
pNOR->enable[ch] = 1;
|
||||
pSOU->enable[ch] = 1;
|
||||
//pNOR->enable[ch] = 1;
|
||||
//pSOU->enable[ch] = 1;
|
||||
switch(ch) {
|
||||
case 0: Flag_R1 = 0; break;
|
||||
case 1: Flag_R2 = 0; break;
|
||||
case 2: Flag_R3 = 0; break;
|
||||
case 3: Flag_R4 = 0; break;
|
||||
}
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_WORK,WORK_STOP);
|
||||
}
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
case 0x51:
|
||||
case 0x52:
|
||||
case 0x53:
|
||||
case 0x54: { //CV电压值设定
|
||||
ch = recv[LCD_IDX_CMD] - 0x51;
|
||||
Recv_Data = recv[LCD_IDX_VAL+1]<<8|recv[LCD_IDX_VAL];//get lower Reg_Data
|
||||
//Recv_Data = swap_u16(Recv_Data);
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_VOLTAGE_OUT+1,Recv_Data);//plus 1,set voltage lower REG
|
||||
}
|
||||
break;
|
||||
case 0x61:
|
||||
case 0x62:
|
||||
case 0x63:
|
||||
case 0x64:{ //CC电流值设定
|
||||
ch = recv[LCD_IDX_CMD] - 0x61;
|
||||
Recv_Data = recv[LCD_IDX_VAL+1]<<8|recv[LCD_IDX_VAL];//get lower Reg_Data
|
||||
//Recv_Data = swap_u16(Recv_Data);
|
||||
chrg_set_sou_mode((eIDX_SOU_CH)ch, REG_CURRENT_OUT+1,Recv_Data);//plus 1,set current lower REG
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_lcd_send
|
||||
函数描述: 向显示屏发送控制消息
|
||||
输入参数: *cmd: 控制命令,自动补齐3个FF
|
||||
输出参数: -
|
||||
返回说明: 0:发送完成 <0: 发送失败
|
||||
其它说明: 参考《淘晶驰串口屏开发手册》http://wiki.tjc1688.com/
|
||||
*****************************************************************/
|
||||
int chrg_lcd_send (char *cmd)
|
||||
{
|
||||
rt_ssize_t ret = -1;
|
||||
@@ -122,14 +193,20 @@ int chrg_lcd_send (char *cmd)
|
||||
data = RT_NULL;
|
||||
}
|
||||
|
||||
rt_thread_mdelay(10);
|
||||
rt_thread_mdelay(20);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_lcd_thread_entry
|
||||
函数描述: 接收LCD数据线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_lcd_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_lcd.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现与显示屏交互,向屏更新数据与接收屏控制数据。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_LCD_H__
|
||||
#define __CHRG_LCD_H__
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_north.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现北向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
@@ -35,7 +44,14 @@ struct chrg_north_t chrgnorth = {
|
||||
.manual = MANU_AUTO,
|
||||
};
|
||||
|
||||
// 北向通道选择
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_switch
|
||||
函数描述: 北向通道选择
|
||||
输入参数: ch: 北向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_switch (eIDX_NOR_CH ch)
|
||||
{
|
||||
if (ch >= TOTAL_NOR_CHS) {
|
||||
@@ -46,6 +62,14 @@ int chrg_north_switch (eIDX_NOR_CH ch)
|
||||
chrgios[IDX_GPO_NOR_SW_B].base, (eIDX_CH)ch);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_send
|
||||
函数描述: 北向通道数据发送
|
||||
输入参数: *data: 数据 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_send (rt_uint8_t *data, rt_size_t length)
|
||||
{
|
||||
rt_ssize_t ret = -1;
|
||||
@@ -59,7 +83,14 @@ int chrg_north_send (rt_uint8_t *data, rt_size_t length)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 提取3字节帧头
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_frame_head
|
||||
函数描述: 北向通道数据帧头提取
|
||||
输入参数: *rb: 缓冲区 *head: 帧头 id:编号
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: 提取3字节帧头
|
||||
*****************************************************************/
|
||||
static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eIDX_ID id)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -123,6 +154,14 @@ static int chrg_north_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pickup_frame
|
||||
函数描述: 北向通道数据帧提取
|
||||
输入参数: *rb: 缓冲区 *pFrame: 数据帧 idx:通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
struct pickup_info_t *pFrame, eIDX_NOR_CH idx)
|
||||
{
|
||||
@@ -208,6 +247,14 @@ static int chrg_north_pickup_frame (struct rt_ringbuffer *rb,
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_thread_entry
|
||||
函数描述: 北向通道数据接收线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_north_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_north.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现北向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_NORTH_H__
|
||||
#define __CHRG_NORTH_H__
|
||||
|
||||
@@ -48,11 +57,34 @@ struct chrg_north_t {
|
||||
|
||||
extern struct chrg_north_t chrgnorth;
|
||||
|
||||
// 北向通道选择
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_switch
|
||||
函数描述: 北向通道选择
|
||||
输入参数: ch: 北向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_switch (eIDX_NOR_CH ch);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_send
|
||||
函数描述: 北向通道数据发送
|
||||
输入参数: *data: 数据 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_send (rt_uint8_t *data, rt_size_t length);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_thread_entry
|
||||
函数描述: 北向通道数据接收线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_north_thread_entry (void *data);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_roll_nor.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现北向通信轮巡请求命令。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -25,6 +34,14 @@ const rt_base_t sw_uart[TOTAL_NOR_CHS] = {
|
||||
IDX_GPO_UART_SW4
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_roll_nor_sw_uart
|
||||
函数描述: 北向通道切换 sink/source 串口
|
||||
输入参数: ch: 通道 id: sink/source
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static void chrg_roll_nor_sw_uart (eIDX_NOR_CH ch, eIDX_ID id)
|
||||
{
|
||||
if (ch >= TOTAL_NOR_CHS) {
|
||||
@@ -39,6 +56,14 @@ static void chrg_roll_nor_sw_uart (eIDX_NOR_CH ch, eIDX_ID id)
|
||||
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_roll_nor_thread_entry
|
||||
函数描述: 北向通道轮巡请求数据线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_roll_nor_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
@@ -122,7 +147,7 @@ void chrg_roll_nor_thread_entry (void *data)
|
||||
pMB_R = RT_NULL;
|
||||
}
|
||||
|
||||
rt_thread_mdelay(50); // 间隔 50ms
|
||||
rt_thread_mdelay(200); // 间隔 200ms
|
||||
} else {
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
pNOR->manual = MANU_AUTO;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_roll_nor.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现北向通信轮巡请求命令。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_ROLL_NOR_H__
|
||||
#define __CHRG_ROLL_NOR_H__
|
||||
|
||||
@@ -8,6 +17,14 @@
|
||||
extern rt_uint8_t nor_run;
|
||||
extern rt_uint8_t nor_ch;
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_roll_nor_thread_entry
|
||||
函数描述: 北向通道轮巡请求数据线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_roll_nor_thread_entry (void *data);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_roll_sou.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现南向通信轮巡请求命令。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -15,19 +24,38 @@ rt_uint8_t sou_run = 1;
|
||||
rt_uint8_t sou_ch = IDX_SOU_CH1;
|
||||
rt_uint8_t sou_pt = MB_R_PART1;
|
||||
rt_uint8_t sou_mode = 0;
|
||||
rt_uint8_t sou_reg = 0;
|
||||
rt_uint16_t sou_mode_value = 0;
|
||||
|
||||
void chrg_set_sou_mode (eIDX_SOU_CH idx, rt_uint8_t mode)
|
||||
/*****************************************************************
|
||||
函数名称: chrg_set_sou_mode
|
||||
函数描述: 南向通道插入设置请求命令
|
||||
输入参数: idx:通道 mode:设置模式
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_set_sou_mode (eIDX_SOU_CH idx,rt_uint8_t reg, rt_uint16_t mode_value)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = &chrgthr[IDX_THR_ROLL_SOU];
|
||||
struct chrg_south_t *pSOU = &chrgsouth;
|
||||
sou_run = 0;
|
||||
sou_ch = idx;
|
||||
sou_mode = mode;
|
||||
sou_reg = reg;
|
||||
sou_mode_value = mode_value;
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
pSOU->manual = MANU_INSERT;
|
||||
rt_mutex_release(pTHR->mutex);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_roll_sou_thread_entry
|
||||
函数描述: 南向通道轮巡请求数据线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_roll_sou_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
@@ -53,7 +81,7 @@ void chrg_roll_sou_thread_entry (void *data)
|
||||
chrg_eload_refresh(ID_ELOAD, sou_pt);
|
||||
} else if (MANU_INSERT == manu) {
|
||||
chrg_south_switch((eIDX_SOU_CH)sou_ch);
|
||||
chrg_eload_write_reg(ID_ELOAD, REG_MODE, sou_mode);
|
||||
chrg_eload_write_reg(ID_ELOAD, sou_reg, sou_mode_value);
|
||||
|
||||
} else { // 轮巡4个通道
|
||||
if (0 == sou_run) {
|
||||
@@ -107,7 +135,7 @@ void chrg_roll_sou_thread_entry (void *data)
|
||||
pMB_R = RT_NULL;
|
||||
}
|
||||
|
||||
rt_thread_mdelay(50); // 间隔 50ms
|
||||
rt_thread_mdelay(200); // 间隔 200ms
|
||||
} else {
|
||||
if (MANU_AUTO != manu) {
|
||||
rt_mutex_take(pTHR->mutex, RT_WAITING_FOREVER);
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_roll_sou.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现南向通信轮巡请求命令。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_ROLL_SOU_H__
|
||||
#define __CHRG_ROLL_SOU_H__
|
||||
|
||||
@@ -9,8 +18,24 @@
|
||||
extern rt_uint8_t sou_run;
|
||||
extern rt_uint8_t sou_ch;
|
||||
|
||||
extern void chrg_set_sou_mode (eIDX_SOU_CH idx, rt_uint8_t mode);
|
||||
/*****************************************************************
|
||||
函数名称: chrg_set_sou_mode
|
||||
函数描述: 南向通道插入设置请求命令
|
||||
输入参数: idx:通道 mode:设置模式
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_set_sou_mode (eIDX_SOU_CH idx,rt_uint8_t reg, rt_uint16_t mode_value);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_roll_sou_thread_entry
|
||||
函数描述: 南向通道轮巡请求数据线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_roll_sou_thread_entry (void *data);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_south.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现南向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include <rtthread.h>
|
||||
|
||||
@@ -24,18 +33,32 @@ struct chrg_south_t chrgsouth = {
|
||||
.manual = MANU_AUTO,
|
||||
};
|
||||
|
||||
// 南向1级选通
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_switch_lv1
|
||||
函数描述: 南向通道选择1级
|
||||
输入参数: ch: 南向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: 南向1级选通
|
||||
*****************************************************************/
|
||||
static int chrg_south_switch_lv1 (eIDX_CH ch)
|
||||
{
|
||||
if (ch >= 2) {
|
||||
return -1;
|
||||
}
|
||||
// if (ch >= 2) {
|
||||
// return -1;
|
||||
// }
|
||||
|
||||
return chrg_switch_ch(chrgios[IDX_GPO_SOU_SW_LV1_A].base,
|
||||
chrgios[IDX_GPO_SOU_SW_LV1_B].base, ch);
|
||||
}
|
||||
|
||||
// 南向2级左半
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_switch_lv2_1
|
||||
函数描述: 南向通道选择2级,左半部分
|
||||
输入参数: ch: 南向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_south_switch_lv2_1 (eIDX_CH ch)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -51,7 +74,14 @@ static int chrg_south_switch_lv2_1 (eIDX_CH ch)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 南向2级右半
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_switch_lv2_2
|
||||
函数描述: 南向通道选择2级,右半部分
|
||||
输入参数: ch: 南向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_south_switch_lv2_2 (eIDX_CH ch)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -69,7 +99,14 @@ static int chrg_south_switch_lv2_2 (eIDX_CH ch)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 南向通道选择
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_switch
|
||||
函数描述: 南向通道选择
|
||||
输入参数: ch: 南向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_south_switch (eIDX_SOU_CH ch)
|
||||
{
|
||||
int ret = -1;
|
||||
@@ -77,6 +114,7 @@ int chrg_south_switch (eIDX_SOU_CH ch)
|
||||
return -1;
|
||||
}
|
||||
|
||||
#if 0
|
||||
// 1级/2级通道顺序反向
|
||||
if ((IDX_SOU_CH1 == ch)||(IDX_SOU_CH2 == ch)) {
|
||||
ret = chrg_south_switch_lv1(IDX_CH2);
|
||||
@@ -87,10 +125,32 @@ int chrg_south_switch (eIDX_SOU_CH ch)
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
//新版注释上面的旧版切换,只要PC8-A和PC9-B控制切换
|
||||
if (IDX_SOU_CH1 == ch) {
|
||||
ret = chrg_south_switch_lv1(IDX_CH1);
|
||||
} else if (IDX_SOU_CH2 == ch){
|
||||
ret = chrg_south_switch_lv1(IDX_CH2);
|
||||
} else if (IDX_SOU_CH3 == ch){
|
||||
ret = chrg_south_switch_lv1(IDX_CH3);
|
||||
} else if (IDX_SOU_CH4 == ch){
|
||||
ret = chrg_south_switch_lv1(IDX_CH4);
|
||||
} else {
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_send
|
||||
函数描述: 南向数据发送
|
||||
输入参数: *data: 数据 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_south_send (rt_uint8_t *data, rt_size_t length)
|
||||
{
|
||||
rt_ssize_t ret = -1;
|
||||
@@ -104,7 +164,14 @@ int chrg_south_send (rt_uint8_t *data, rt_size_t length)
|
||||
return ret;
|
||||
}
|
||||
|
||||
// 读取 modbus 前3个字节。2个(设置)或3个字节(查询)
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_frame_head
|
||||
函数描述: 南向数据帧头提取
|
||||
输入参数: *rb: 缓冲区 *head: 帧头 id:编号
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: MODBUS协议。读取 modbus 前3个字节。2个(设置)或3个字节(查询)
|
||||
*****************************************************************/
|
||||
static int chrg_south_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eIDX_ID id)
|
||||
{
|
||||
int i = 0;
|
||||
@@ -175,6 +242,14 @@ static int chrg_south_frame_head (struct rt_ringbuffer *rb, rt_uint8_t *head, eI
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_pickup_frame
|
||||
函数描述: 南向通道数据帧提取
|
||||
输入参数: *rb: 缓冲区 *pFrame: 数据帧
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_south_pickup_frame (struct rt_ringbuffer *rb,
|
||||
struct pickup_info_t *pFrame)
|
||||
{
|
||||
@@ -256,6 +331,14 @@ static int chrg_south_pickup_frame (struct rt_ringbuffer *rb,
|
||||
return cnt;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_thread_entry
|
||||
函数描述: 南向通道数据接收线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
void chrg_south_thread_entry (void *data)
|
||||
{
|
||||
struct chrg_thread_t *pTHR = (struct chrg_thread_t *)data;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_south.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 实现南向通信交互,包括接收命令解析,发送请求命令,切换通路。以独立线程处理。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SOUTH_H__
|
||||
#define __CHRG_SOUTH_H__
|
||||
|
||||
@@ -39,11 +48,34 @@ struct chrg_south_t {
|
||||
|
||||
extern struct chrg_south_t chrgsouth;
|
||||
|
||||
// 南向通道选择
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_switch
|
||||
函数描述: 南向通道选择
|
||||
输入参数: ch: 南向通道
|
||||
输出参数: -
|
||||
返回说明: <0: 错误
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_south_switch (eIDX_SOU_CH ch);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_send
|
||||
函数描述: 南向数据发送
|
||||
输入参数: *data: 数据 length: 数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_south_send (rt_uint8_t *data, rt_size_t length);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_south_thread_entry
|
||||
函数描述: 南向通道数据接收线程体
|
||||
输入参数: *data: 本线程信息
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern void chrg_south_thread_entry (void *data);
|
||||
|
||||
|
||||
|
||||
@@ -1,4 +1,11 @@
|
||||
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_thread.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 启动多个业务线程
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
#include <rtthread.h>
|
||||
|
||||
#include "chrg_thread.h"
|
||||
@@ -106,6 +113,39 @@ struct chrg_thread_t chrgthr[TOTAL_THRS] = {
|
||||
}
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_evt_send
|
||||
函数描述: 向指定线程发送事件编号
|
||||
输入参数: idx: 目的线程编号, data: 事件编号
|
||||
输出参数: -
|
||||
返回说明: 0: OK , !=0 : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_err_t chrg_thread_evt_send (eIDX_THRS idx, rt_uint32_t data)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (idx >= TOTAL_THRS) {
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
struct chrg_thread_t *pTHR = &chrgthr[idx];
|
||||
|
||||
if (RT_NULL != pTHR->ev) {
|
||||
rt_event_send(pTHR->ev, data);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_mb_send
|
||||
函数描述: 向指定线程发送邮件
|
||||
输入参数: idx: 目的线程编号, *data: 邮件指针
|
||||
输出参数: -
|
||||
返回说明: 0: OK , !=0 : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_err_t chrg_thread_mb_send (eIDX_THRS idx, void *data)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
@@ -126,6 +166,42 @@ rt_err_t chrg_thread_mb_send (eIDX_THRS idx, void *data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_mq_send
|
||||
函数描述: 向指定线程发送消息队列
|
||||
输入参数: idx: 目的线程编号, *data: 消息队列指针, len:消息长度
|
||||
输出参数: -
|
||||
返回说明: 0: OK , !=0 : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_err_t chrg_thread_mq_send (eIDX_THRS idx, void *data, rt_size_t len)
|
||||
{
|
||||
rt_err_t ret = RT_EOK;
|
||||
|
||||
if (idx >= TOTAL_THRS) {
|
||||
return RT_ERROR;
|
||||
}
|
||||
|
||||
struct chrg_thread_t *pTHR = &chrgthr[idx];
|
||||
|
||||
if (RT_NULL != pTHR->mq) {
|
||||
ret = rt_mq_send(pTHR->mq, data, len);
|
||||
if (RT_EOK != ret) {
|
||||
LOG_E("mq send failed. [%d]", ret);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_create
|
||||
函数描述: 创建单个线程
|
||||
输入参数: idx: 线程编号
|
||||
输出参数: -
|
||||
返回说明: RT_EOK: OK , RT_ERROR : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_thread_create (eIDX_THRS idx)
|
||||
{
|
||||
if (idx >= TOTAL_THRS) {
|
||||
@@ -186,6 +262,14 @@ int chrg_thread_create (eIDX_THRS idx)
|
||||
return RT_EOK;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_init
|
||||
函数描述: 所有常驻业务线程初始化
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: 0: OK
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
static int chrg_thread_init (void)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_thread.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 统一管理业务线程,业务线程信息定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_THREAD_H__
|
||||
#define __CHRG_THREAD_H__
|
||||
@@ -61,8 +69,44 @@ struct chrg_thread_t {
|
||||
|
||||
extern struct chrg_thread_t chrgthr[TOTAL_THRS];
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_evt_send
|
||||
函数描述: 向指定线程发送事件编号
|
||||
输入参数: idx: 目的线程编号, data: 事件编号
|
||||
输出参数: -
|
||||
返回说明: 0: OK , !=0 : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_err_t chrg_thread_evt_send (eIDX_THRS idx, rt_uint32_t data);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_mb_send
|
||||
函数描述: 向指定线程发送邮件
|
||||
输入参数: idx: 目的线程编号, *data: 邮件指针
|
||||
输出参数: -
|
||||
返回说明: RT_EOK: OK , RT_ERROR : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_err_t chrg_thread_mb_send (eIDX_THRS idx, void *data);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_mq_send
|
||||
函数描述: 向指定线程发送消息队列
|
||||
输入参数: idx: 目的线程编号, *data: 消息队列指针, len:消息长度
|
||||
输出参数: -
|
||||
返回说明: 0: OK , !=0 : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_err_t chrg_thread_mq_send (eIDX_THRS idx, void *data, rt_size_t len);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_thread_create
|
||||
函数描述: 创建单个线程
|
||||
输入参数: idx: 线程编号
|
||||
输出参数: -
|
||||
返回说明: RT_EOK: OK , RT_ERROR : FAILED
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_thread_create (eIDX_THRS idx);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_def.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 全局宏定义,常量,及结构体。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_DEF_H__
|
||||
#define __CHRG_DEF_H__
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_eload.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 源载命令数据解析,封装,读写请求。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -8,6 +17,14 @@
|
||||
#include "chrg_lcd.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_read_regs
|
||||
函数描述: 向南向发送读取寄存器
|
||||
输入参数: addr:地址 reg:寄存器起始地址 len:寄存器个数
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len)
|
||||
{
|
||||
rt_uint8_t buf[8] = {0};
|
||||
@@ -23,6 +40,14 @@ int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len)
|
||||
return chrg_south_send(buf, 8);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_write_reg
|
||||
函数描述: 向南向发送写单个寄存器
|
||||
输入参数: addr:地址 reg:寄存器地址 value:写入值
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value)
|
||||
{
|
||||
rt_uint8_t buf[8] = {0};
|
||||
@@ -38,6 +63,14 @@ int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value)
|
||||
return chrg_south_send(buf, 8);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_refresh
|
||||
函数描述: 分段请求读取寄存器表
|
||||
输入参数: addr:地址 part:分段
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: 实际运行过程只需要读取前13个寄存器即可,即分段0
|
||||
*****************************************************************/
|
||||
int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part)
|
||||
{
|
||||
int ret = 0;
|
||||
@@ -51,6 +84,14 @@ int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_parse
|
||||
函数描述: 解析源载返回数据
|
||||
输入参数: idx:通道 pt:分段0 *data:数据区 len:数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16_t len)
|
||||
{
|
||||
if (idx >= TOTAL_SOU_CHS) {
|
||||
@@ -71,26 +112,49 @@ int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16
|
||||
pLOAD->status2 = pP1->status2;
|
||||
pLOAD->fault1 = pP1->fault1;
|
||||
pLOAD->fault2 = (rt_uint8_t)pP1->fault2;
|
||||
pLOAD->eload = (rt_uint8_t)pP1->eload;
|
||||
pLOAD->eload = swap_u16(pP1->eload);
|
||||
pLOAD->work = (rt_uint8_t)pP1->work_cmd;
|
||||
pLOAD->mode = (rt_uint8_t)pP1->work_mode;
|
||||
pLOAD->voltage = pP1->voltage;
|
||||
pLOAD->current = pP1->current;
|
||||
pLOAD->voltage = swap_u32(pP1->voltage);
|
||||
pLOAD->current = swap_u32(pP1->current);
|
||||
pLOAD->temperatue = pP1->temperature;
|
||||
pLOAD->version = pP1->version;
|
||||
pLOAD->address = (rt_uint8_t)pP1->addr;
|
||||
rt_kprintf("vol %d, cur %d\r\n", pLOAD->voltage, pLOAD->current);
|
||||
|
||||
char tmp[36] = {0};
|
||||
snprintf(tmp, 36, "main.CH%d_Volt_Show.val=%d",
|
||||
idx+1, pLOAD->voltage);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "status.CH%d_Volt_Sta.txt=\"%d.%03d\"",
|
||||
idx+1, pLOAD->voltage/1000, pLOAD->voltage%1000);
|
||||
chrg_lcd_send(tmp);
|
||||
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "main.CH%d_Curr_Show.val=%d",
|
||||
idx+1, pLOAD->current);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
snprintf(tmp, 36, "status.CH%d_Curr_Sta.txt=\"%d.%03d\"",
|
||||
idx+1, pLOAD->current/1000, pLOAD->current%1000);
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
if (pP1->work_cmd == 0x100){
|
||||
if (pP1->work_mode == MODE_CONSTANT_VOLTAGE){
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"恒压\"", idx+1);
|
||||
} else {
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"恒流\"", idx+1);
|
||||
}
|
||||
} else {
|
||||
snprintf(tmp, 36, "main.CH%d_Status.txt=\"停止\"", idx+1);
|
||||
}
|
||||
chrg_lcd_send(tmp);
|
||||
rt_memset(tmp, 0, 36);
|
||||
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_eload.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 源载命令数据解析,封装,读写请求,寄存器定义,数据结构定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_ELOAD_H__
|
||||
#define __CHRG_ELOAD_H__
|
||||
|
||||
@@ -104,6 +113,7 @@ typedef enum {
|
||||
#define SIZE_P1_RD 13 // 读13个寄存器
|
||||
#define SIZE_P2_RD 28 // 读28个寄存器
|
||||
|
||||
#pragma pack(push,1)
|
||||
struct eload_p1_t {
|
||||
rt_uint16_t status1; // reg0
|
||||
rt_uint16_t status2; // reg1
|
||||
@@ -153,13 +163,46 @@ struct chrg_eload_t {
|
||||
rt_uint16_t version; // 版本
|
||||
rt_uint8_t address; // 地址
|
||||
};
|
||||
#pragma pack(pop)
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_read_regs
|
||||
函数描述: 向南向发送读取寄存器
|
||||
输入参数: addr:地址 reg:寄存器起始地址 len:寄存器个数
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_read_regs (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t len);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_write_reg
|
||||
函数描述: 向南向发送写单个寄存器
|
||||
输入参数: addr:地址 reg:寄存器地址 value:写入值
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_write_reg (rt_uint8_t addr, rt_uint16_t reg, rt_uint16_t value);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_refresh
|
||||
函数描述: 分段请求读取寄存器表
|
||||
输入参数: addr:地址 part:分段
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送数据长度
|
||||
其它说明: 实际运行过程只需要读取前13个寄存器即可,即分段0
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_refresh (rt_uint8_t addr, rt_uint8_t part);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_eload_parse
|
||||
函数描述: 解析源载返回数据
|
||||
输入参数: idx:通道 pt:分段0 *data:数据区 len:数据长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_eload_parse (rt_uint8_t idx, rt_uint8_t pt, rt_uint8_t *data, rt_uint16_t len);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_north_pkg.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据编码、解码。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <string.h>
|
||||
#include <rtthread.h>
|
||||
@@ -6,6 +14,15 @@
|
||||
#include "chrg_north_pkg.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_encode
|
||||
函数描述: 北向数据帧编码
|
||||
输入参数: id: sink/source cmd:指令 *data_in:数据 len_in:数据长度
|
||||
*data_out:数据帧 len_out:数据帧长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
rt_uint8_t len_in, rt_uint8_t *data_out, rt_uint16_t *len_out)
|
||||
{
|
||||
@@ -33,7 +50,14 @@ int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_decode
|
||||
函数描述: 北向数据帧解码
|
||||
输入参数: *data:数据 length:数据长度 *pSW:源载数据结构
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int chrg_north_pkg_decode (rt_uint8_t *data, rt_uint16_t length, struct chrg_switch_t *pSW)
|
||||
{
|
||||
if ((RT_NULL == data)||(RT_NULL == pSW)||(length < 5)) {
|
||||
|
||||
@@ -7,9 +7,26 @@
|
||||
#include "chrg_def.h"
|
||||
#include "chrg_north.h"
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_encode
|
||||
函数描述: 北向数据帧编码
|
||||
输入参数: id: sink/source cmd:指令 *data_in:数据 len_in:数据长度
|
||||
*data_out:数据帧 len_out:数据帧长度
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:帧长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_pkg_encode (eIDX_ID id, rt_uint8_t cmd, rt_uint8_t *data_in,
|
||||
rt_uint8_t len_in, rt_uint8_t *data_out, rt_uint16_t *len_out);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: chrg_north_pkg_decode
|
||||
函数描述: 北向数据帧解码
|
||||
输入参数: *data:数据 length:数据长度 *pSW:源载数据结构
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 0:正确
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int chrg_north_pkg_decode (rt_uint8_t *data, rt_uint16_t length, struct chrg_switch_t *pSW);
|
||||
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_sink.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据sink请求数据填充及发送。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_sink.h"
|
||||
@@ -6,7 +14,14 @@
|
||||
#include "chrg_north_pkg.h"
|
||||
#include "chrg_utils.h"
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: sink_get_vc
|
||||
函数描述: sink电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int sink_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_sink.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据sink请求数据填充及发送,命令字定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SINK_H__
|
||||
#define __CHRG_SINK_H__
|
||||
|
||||
@@ -142,6 +151,14 @@ struct chrg_sink_t {
|
||||
rt_uint8_t cc_lvl; // 设置CC线电平等级(0-10,默认7)
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: sink_get_vc
|
||||
函数描述: sink电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int sink_get_vc (rt_uint16_t vol, rt_uint16_t cur);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_source.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据source请求数据填充及发送。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
#include "chrg_source.h"
|
||||
@@ -7,7 +15,14 @@
|
||||
#include "chrg_utils.h"
|
||||
|
||||
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_vc
|
||||
函数描述: source电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -24,6 +39,14 @@ int source_get_vc (rt_uint16_t vol, rt_uint16_t cur)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_pd
|
||||
函数描述: source pd 协议查询请求
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_get_pd (void)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -34,6 +57,14 @@ int source_get_pd (void)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_cc_lvl
|
||||
函数描述: source 设置 cc 等级
|
||||
输入参数: lvl:等级
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_set_cc_lvl (rt_uint8_t lvl)
|
||||
{
|
||||
rt_uint16_t len = 0;
|
||||
@@ -47,6 +78,14 @@ int source_set_cc_lvl (rt_uint8_t lvl)
|
||||
return chrg_north_send(frame, len);
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_pd
|
||||
函数描述: source 设置PD协议
|
||||
输入参数: pro:协议 src:源 pps: PPS vmax:最大电压 vmin:最小电压 max_cur:最大电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
int source_set_pd (rt_uint8_t pro, rt_uint8_t src, rt_uint8_t pps,
|
||||
rt_uint16_t vmax, rt_uint16_t vmin, rt_int16_t max_cur)
|
||||
{
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_source.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 北向数据source请求数据填充及发送,命令字定义。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_SOURCE_H__
|
||||
#define __CHRG_SOURCE_H__
|
||||
|
||||
@@ -128,12 +137,44 @@ struct chrg_src_t {
|
||||
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_vc
|
||||
函数描述: source电压电流查询请求
|
||||
输入参数: vol:电压 cur:电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_get_vc (rt_uint16_t vol, rt_uint16_t cur);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_get_pd
|
||||
函数描述: source pd 协议查询请求
|
||||
输入参数: -
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_get_pd (void);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_cc_lvl
|
||||
函数描述: source 设置 cc 等级
|
||||
输入参数: lvl:等级
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_set_cc_lvl (rt_uint8_t lvl);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: source_set_pd
|
||||
函数描述: source 设置PD协议
|
||||
输入参数: pro:协议 src:源 pps: PPS vmax:最大电压 vmin:最小电压 max_cur:最大电流
|
||||
输出参数: -
|
||||
返回说明: <0: 错误 >0:发送长度
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern int source_set_pd (rt_uint8_t pro, rt_uint8_t src, rt_uint8_t pps,
|
||||
rt_uint16_t vmax, rt_uint16_t vmin, rt_int16_t max_cur);
|
||||
|
||||
|
||||
@@ -1,3 +1,11 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_utils.c
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 一些通用数据封装,功能接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
@@ -53,6 +61,14 @@ static const rt_uint8_t aucCRCLo[] = {
|
||||
0x41, 0x81, 0x80, 0x40
|
||||
};
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: mb_crc16
|
||||
函数描述: 查表法计算 MODBUS CRC16校验
|
||||
输入参数: *pucFrame:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t mb_crc16 (rt_uint8_t *pucFrame, rt_uint16_t usLen)
|
||||
{
|
||||
rt_uint8_t ucCRCHi = 0xFF;
|
||||
@@ -88,6 +104,14 @@ rt_uint8_t _crc8 (rt_uint8_t res, rt_uint8_t data)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: calc_crc8
|
||||
函数描述: 计算 crc8
|
||||
输入参数: *data:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length)
|
||||
{
|
||||
rt_uint8_t i = 0, res = 0x55;
|
||||
@@ -99,6 +123,14 @@ rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u16_to_u8v
|
||||
函数描述: u16 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
@@ -110,6 +142,14 @@ rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u16
|
||||
函数描述: 字节流转 u16
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t u8v_to_u16 (rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
@@ -119,14 +159,67 @@ rt_uint16_t u8v_to_u16 (rt_uint8_t *buf)
|
||||
return 0;
|
||||
}
|
||||
|
||||
// rt_uint16_t 高低位互换
|
||||
/*****************************************************************
|
||||
函数名称: u32_to_u8v
|
||||
函数描述: u32 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint8_t u32_to_u8v (rt_uint32_t value, rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
buf[0] = (value>>24)&0xFF;
|
||||
buf[1] = (value>>16)&0xFF;
|
||||
buf[2] = (value>>8)&0xFF;
|
||||
buf[3] = value&0xFF;
|
||||
return 4;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u32
|
||||
函数描述: 字节流转 u32
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint32_t u8v_to_u32 (rt_uint8_t *buf)
|
||||
{
|
||||
if (RT_NULL != buf) {
|
||||
return (((rt_uint32_t)buf[0]<<24) + ((rt_uint32_t)buf[1]<<16)
|
||||
+((rt_uint32_t)buf[2]<<8) + buf[3]);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u16
|
||||
函数描述: u16高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint16_t swap_u16 (rt_uint16_t x)
|
||||
{
|
||||
return ((x & 0x00FF) << 8) |
|
||||
((x & 0xFF00) >> 8);
|
||||
}
|
||||
|
||||
// rt_uint32_t 高低位互换
|
||||
/*****************************************************************
|
||||
函数名称: swap_u32
|
||||
函数描述: u32高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
rt_uint32_t swap_u32 (rt_uint32_t x)
|
||||
{
|
||||
return ((x & 0x000000FF) << 24) |
|
||||
|
||||
@@ -1,18 +1,95 @@
|
||||
/****************************************************************************
|
||||
文件名称 : chrg_utils.h
|
||||
完成日期 :
|
||||
当前版本号 : V1.0
|
||||
主要功能 : 一些通用数据封装,功能接口。
|
||||
版本历史 : 创建原始版本
|
||||
说明 :
|
||||
******************************************************************************/
|
||||
|
||||
#ifndef __CHRG_UTILS_H__
|
||||
#define __CHRG_UTILS_H__
|
||||
|
||||
#include <rtthread.h>
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: mb_crc16
|
||||
函数描述: 查表法计算 MODBUS CRC16校验
|
||||
输入参数: *pucFrame:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t mb_crc16 (rt_uint8_t * pucFrame, rt_uint16_t usLen);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: calc_crc8
|
||||
函数描述: 计算 crc8
|
||||
输入参数: *data:数据 usLen:长度
|
||||
输出参数: 校验码
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t calc_crc8 (rt_uint8_t *data, rt_uint8_t length);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u16_to_u8v
|
||||
函数描述: u16 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t u16_to_u8v (rt_uint16_t value, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u16
|
||||
函数描述: 字节流转 u16
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t u8v_to_u16 (rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u32_to_u8v
|
||||
函数描述: u32 转字节流
|
||||
输入参数: value:数据 *buf:字节流
|
||||
输出参数: -
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint8_t u32_to_u8v (rt_uint32_t value, rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: u8v_to_u32
|
||||
函数描述: 字节流转 u32
|
||||
输入参数: *buf:字节流
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint32_t u8v_to_u32 (rt_uint8_t *buf);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u16
|
||||
函数描述: u16高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint16_t swap_u16 (rt_uint16_t x);
|
||||
|
||||
/*****************************************************************
|
||||
函数名称: swap_u32
|
||||
函数描述: u32高低位互换
|
||||
输入参数: x:数值
|
||||
输出参数: value:数据
|
||||
返回说明: -
|
||||
其它说明: -
|
||||
*****************************************************************/
|
||||
extern rt_uint32_t swap_u32 (rt_uint32_t x);
|
||||
|
||||
#endif
|
||||
|
||||
+142
-147
@@ -337,9 +337,9 @@
|
||||
<v6Rtti>0</v6Rtti>
|
||||
<VariousControls>
|
||||
<MiscControls></MiscControls>
|
||||
<Define>RT_USING_ARMLIBC, __CLK_TCK=RT_TICK_PER_SECOND, USE_HAL_DRIVER, __RTTHREAD__, RT_USING_LIBC, __STDC_LIMIT_MACROS, STM32F405xx</Define>
|
||||
<Define>__STDC_LIMIT_MACROS, USE_HAL_DRIVER, RT_USING_LIBC, RT_USING_ARMLIBC, __RTTHREAD__, __CLK_TCK=RT_TICK_PER_SECOND, STM32F405xx</Define>
|
||||
<Undefine></Undefine>
|
||||
<IncludePath>..\..\rt-thread\libcpu\arm\common;..\..\rt-thread\components\libc\posix\ipc;..\..\rt-thread\components\drivers\include;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;..\..\rt-thread\components\finsh;..\..\rt-thread\components\libc\posix\io\eventfd;.;..\..\libs\cmsis-core\Include;..\..\rt-thread\components\drivers\include;board;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\drv_flash;..\..\rt-thread\components\drivers\phy;..\..\rt-thread\include;board\ports;..\..\libs\stm32f4\STM32F4_HAL\Inc;board\CubeMX_Config\Inc;..\..\libs\stm32f4\STM32F4_CMSIS\Include;..\..\rt-thread\components\utilities\ulog;..\..\rt-thread\components\drivers\include;..\..\libs\stm32f4\STM32F4_HAL\Inc\Legacy;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\components\libc\posix\io\poll;..\..\rt-thread\components\drivers\smp_call;..\..\rt-thread\components\drivers\include;applications\bsp;..\..\rt-thread\components\drivers\include;applications\thread;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;applications;..\..\rt-thread\components\libc\compilers\common\extension;..\..\rt-thread\components\fal\inc;..\..\rt-thread\components\drivers\include;..\..\rt-thread\libcpu\arm\cortex-m4;..\..\rt-thread\components\libc\posix\io\epoll;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;applications\utils;..\..\rt-thread\components\legacy\usb\usbdevice;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config</IncludePath>
|
||||
<IncludePath>..\..\libs\cmsis-core\Include;..\..\rt-thread\components\drivers\include;applications\thread;..\..\rt-thread\components\drivers\include;applications\utils;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\config;..\..\libs\stm32f4\STM32F4_HAL\Inc;..\..\rt-thread\components\drivers\smp_call;..\..\rt-thread\components\utilities\ulog;..\..\rt-thread\components\libc\posix\io\epoll;..\..\rt-thread\components\libc\compilers\common\extension\fcntl\octal;..\..\rt-thread\components\drivers\include;..\..\rt-thread\components\libc\compilers\common\include;..\..\rt-thread\components\drivers\include;..\..\rt-thread\libcpu\arm\common;..\..\rt-thread\components\finsh;..\..\rt-thread\components\libc\posix\ipc;board\ports;..\..\rt-thread\components\fal\inc;board\CubeMX_Config\Inc;..\..\rt-thread\components\libc\compilers\common\extension;..\..\rt-thread\components\legacy\usb\usbdevice;..\..\rt-thread\libcpu\arm\cortex-m4;..\..\libs\stm32f4\STM32F4_HAL\Inc\Legacy;..\..\rt-thread\components\drivers\phy;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers\drivers\drv_flash;..\..\rt-thread\components\libc\posix\io\poll;..\..\rt-thread\include;board;..\..\rt-thread\components\libc\posix\io\eventfd;..\..\rt-thread\components\drivers\include;.;..\..\libs\stm32f4\STM32F4_CMSIS\Include;applications;..\..\rt-thread\bsp\stm32\libraries\HAL_Drivers;..\..\rt-thread\components\drivers\include;applications\bsp;..\..\rt-thread\components\drivers\include</IncludePath>
|
||||
</VariousControls>
|
||||
</Cads>
|
||||
<Aads>
|
||||
@@ -393,16 +393,21 @@
|
||||
<Group>
|
||||
<GroupName>Applications/bsp</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>chrg_switch.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_switch.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_wdt.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_wdt.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_tty.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_tty.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_tmr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -414,14 +419,9 @@
|
||||
<FilePath>applications\bsp\chrg_fal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_switch.c</FileName>
|
||||
<FileName>chrg_tty.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_switch.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_vcom.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_vcom.c</FilePath>
|
||||
<FilePath>applications\bsp\chrg_tty.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_led.c</FileName>
|
||||
@@ -429,44 +429,44 @@
|
||||
<FilePath>applications\bsp\chrg_led.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_wdt.c</FileName>
|
||||
<FileName>chrg_vcom.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_wdt.c</FilePath>
|
||||
<FilePath>applications\bsp\chrg_vcom.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_rel.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_rel.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_clk.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\bsp\chrg_clk.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Applications/thread</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>chrg_north.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_north.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_roll_nor.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_roll_nor.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_south.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_south.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_comm.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_comm.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_lcd.c</FileName>
|
||||
<FileName>chrg_roll_sou.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_lcd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_north.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_north.c</FilePath>
|
||||
<FilePath>applications\thread\chrg_roll_sou.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_thread.c</FileName>
|
||||
@@ -474,20 +474,20 @@
|
||||
<FilePath>applications\thread\chrg_thread.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_roll_sou.c</FileName>
|
||||
<FileName>chrg_lcd.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_roll_sou.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_south.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\thread\chrg_south.c</FilePath>
|
||||
<FilePath>applications\thread\chrg_lcd.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Applications/utils</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>chrg_source.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_source.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_sink.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -498,11 +498,6 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_eload.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_source.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>applications\utils\chrg_source.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>chrg_north_pkg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -1403,25 +1398,25 @@
|
||||
<GroupName>Fal</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>fal_partition.c</FileName>
|
||||
<FileName>fal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_partition.c</FilePath>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal_flash.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_flash.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal_partition.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_partition.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal_rtt.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal_rtt.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>fal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\fal\src\fal.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -2297,16 +2292,6 @@
|
||||
<Group>
|
||||
<GroupName>klibc</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>kstdio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstdio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>rt_vsscanf.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\rt_vsscanf.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>rt_vsnprintf_tiny.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -2322,6 +2307,16 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstring.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>rt_vsscanf.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\rt_vsscanf.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>kstdio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\src\klibc\kstdio.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
@@ -2357,6 +2352,11 @@
|
||||
<Group>
|
||||
<GroupName>rt_usbd</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>usbdevice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\legacy\usb\usbdevice\core\usbdevice.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>cdc_vcom.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
@@ -2367,40 +2367,30 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\legacy\usb\usbdevice\core\usbdevice_core.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>usbdevice.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\legacy\usb\usbdevice\core\usbdevice.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>STM32F4-CMSIS</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>system_stm32f4xx.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\system_stm32f4xx.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>startup_stm32f405xx.s</FileName>
|
||||
<FileType>2</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\arm\startup_stm32f405xx.s</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>system_stm32f4xx.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_CMSIS\Source\Templates\system_stm32f4xx.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>STM32F4-HAL</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pccard.c</FileName>
|
||||
<FileName>stm32f4xx_hal_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pccard.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash.c</FileName>
|
||||
@@ -2408,64 +2398,39 @@
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp_ex.c</FileName>
|
||||
<FileName>stm32f4xx_hal_usart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp_ex.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ramfunc.c</FileName>
|
||||
<FileName>stm32f4xx_hal_rng.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ramfunc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pcd_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pcd_ex.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rng.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_uart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_uart.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cec.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cec.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pcd.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pcd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_lptim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_lptim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_wwdg.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_wwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_ll_usb.c</FileName>
|
||||
<FileName>stm32f4xx_hal_tim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_ll_usb.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_crc.c</FileName>
|
||||
<FileName>stm32f4xx_hal_cryp_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_crc.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rcc.c</FileName>
|
||||
@@ -2477,20 +2442,40 @@
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_hcd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_ll_usb.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_ll_usb.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pccard.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pccard.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_flash_ramfunc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_flash_ramfunc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_tim_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cortex.c</FileName>
|
||||
<FileName>stm32f4xx_hal_lptim.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_lptim.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr.c</FileName>
|
||||
<FileName>stm32f4xx_hal_cec.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cec.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cryp.c</FileName>
|
||||
@@ -2498,29 +2483,9 @@
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cryp.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr_ex.c</FileName>
|
||||
<FileName>stm32f4xx_hal.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_gpio.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_gpio.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rcc_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_usart.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_usart.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_iwdg.c</FileName>
|
||||
@@ -2528,30 +2493,60 @@
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_iwdg.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rng.c</FileName>
|
||||
<FileName>stm32f4xx_hal_pcd_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rng.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pcd_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_tim.c</FileName>
|
||||
<FileName>stm32f4xx_hal_pcd.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_tim.c</FilePath>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pcd.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_crc.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_crc.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_cortex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_cortex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_dma.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_dma.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_rcc_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_rcc_ex.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>stm32f4xx_hal_pwr_ex.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\libs\stm32f4\STM32F4_HAL\Src\stm32f4xx_hal_pwr_ex.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
<Group>
|
||||
<GroupName>Utilities</GroupName>
|
||||
<Files>
|
||||
<File>
|
||||
<FileName>console_be.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\utilities\ulog\backend\console_be.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>ulog.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\utilities\ulog\ulog.c</FilePath>
|
||||
</File>
|
||||
<File>
|
||||
<FileName>console_be.c</FileName>
|
||||
<FileType>1</FileType>
|
||||
<FilePath>..\..\rt-thread\components\utilities\ulog\backend\console_be.c</FilePath>
|
||||
</File>
|
||||
</Files>
|
||||
</Group>
|
||||
</Groups>
|
||||
|
||||
@@ -318,6 +318,14 @@ static rt_err_t rt_hwtimer_control(struct rt_device *dev, int cmd, void *args)
|
||||
rt_hw_interrupt_enable(level);
|
||||
}
|
||||
break;
|
||||
case HWTIMER_CTRL_COUNT_GET:
|
||||
{
|
||||
if (timer->ops->count_get != RT_NULL) {
|
||||
rt_uint32_t cnt = timer->ops->count_get(timer);
|
||||
*(rt_uint32_t *)args = cnt;
|
||||
}
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
if (timer->ops->control != RT_NULL)
|
||||
|
||||
@@ -21,7 +21,8 @@ typedef enum
|
||||
HWTIMER_CTRL_FREQ_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x01, /* set the count frequency */
|
||||
HWTIMER_CTRL_STOP = RT_DEVICE_CTRL_BASE(Timer) + 0x02, /* stop timer */
|
||||
HWTIMER_CTRL_INFO_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x03, /* get a timer feature information */
|
||||
HWTIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04 /* Setting the timing mode(oneshot/period) */
|
||||
HWTIMER_CTRL_MODE_SET = RT_DEVICE_CTRL_BASE(Timer) + 0x04, /* Setting the timing mode(oneshot/period) */
|
||||
HWTIMER_CTRL_COUNT_GET = RT_DEVICE_CTRL_BASE(Timer) + 0x05 /* get hwtimer count */
|
||||
} rt_hwtimer_ctrl_t;
|
||||
|
||||
/* Timing Mode */
|
||||
|
||||
Reference in New Issue
Block a user