alarmer.c 添加基本函数
main.c 添加自动运行 hex_file 增加线程堆栈 uart_dma_sample.c 添加485测试函数及发送函数 board.h 添加485对应的uart6
This commit is contained in:
parent
8f9f601e26
commit
f041c0ea08
12
.config
12
.config
@ -340,7 +340,7 @@ CONFIG_ULOG_LINE_BUF_SIZE=256
|
||||
#
|
||||
# log format
|
||||
#
|
||||
# CONFIG_ULOG_OUTPUT_FLOAT is not set
|
||||
CONFIG_ULOG_OUTPUT_FLOAT=y
|
||||
CONFIG_ULOG_USING_COLOR=y
|
||||
CONFIG_ULOG_OUTPUT_TIME=y
|
||||
CONFIG_ULOG_TIME_USING_TIMESTAMP=y
|
||||
@ -635,7 +635,15 @@ CONFIG_PKG_CJSON_VER="v1.7.15"
|
||||
#
|
||||
# CONFIG_PKG_USING_RT_MEMCPY_CM is not set
|
||||
# CONFIG_PKG_USING_RT_KPRINTF_THREADSAFE is not set
|
||||
# CONFIG_PKG_USING_RT_VSNPRINTF_FULL is not set
|
||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL=y
|
||||
CONFIG_PKG_RT_VSNPRINTF_FULL_PATH="/packages/system/enhanced-kservice/rt_vsnprintf_full"
|
||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SPRINTF is not set
|
||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_SNPRINTF is not set
|
||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_PRINTF is not set
|
||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSPRINTF is not set
|
||||
# CONFIG_RT_VSNPRINTF_FULL_REPLACING_VSNPRINTF is not set
|
||||
CONFIG_PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION=y
|
||||
CONFIG_PKG_RT_VSNPRINTF_FULL_VER="latest"
|
||||
# end of enhanced kernel services
|
||||
|
||||
#
|
||||
|
@ -51,6 +51,7 @@ void alarm_sample(int argc, char *argv[])
|
||||
setup.wktime.tm_sec = 0;//p_tm.tm_sec;
|
||||
|
||||
alarm = rt_alarm_create(user_alarm_callback, &setup);
|
||||
|
||||
if(RT_NULL != alarm)
|
||||
{
|
||||
rt_alarm_start(alarm);
|
||||
@ -59,3 +60,171 @@ void alarm_sample(int argc, char *argv[])
|
||||
}
|
||||
/* export msh cmd */
|
||||
MSH_CMD_EXPORT(alarm_sample,alarm sample);
|
||||
|
||||
|
||||
void poTT_callback(rt_alarm_t alarm, time_t timestamp)
|
||||
{
|
||||
LOG_D("power UP TT.");
|
||||
}
|
||||
void pdTT_callback(rt_alarm_t alarm, time_t timestamp)
|
||||
{
|
||||
LOG_D("power DOWN TT.");
|
||||
}
|
||||
//每个开窗设置对应两个rtc闹钟,一个上电一个下电
|
||||
//更新开窗设置前需要先清空闹钟设置。可改为调用rt_alarm_control()修改。
|
||||
static struct rt_alarm *alarm[4];//支持2组开窗共4个闹钟
|
||||
|
||||
void InitAlarm()
|
||||
{
|
||||
struct rt_alarm_setup setup;
|
||||
static time_t now;
|
||||
struct tm p_tm;
|
||||
/* 获取当前时间戳,并把下一秒时间设置为闹钟时间 */
|
||||
now = time(NULL);
|
||||
gmtime_r(&now, &p_tm);
|
||||
|
||||
setup.flag = RT_ALARM_DAILY;//天重复
|
||||
setup.wktime.tm_year = p_tm.tm_year;
|
||||
setup.wktime.tm_mon = p_tm.tm_mon;
|
||||
setup.wktime.tm_mday = p_tm.tm_mday;
|
||||
setup.wktime.tm_wday = p_tm.tm_wday;
|
||||
setup.wktime.tm_hour = 1; //整点
|
||||
setup.wktime.tm_min = 0; //p_tm.tm_min;
|
||||
setup.wktime.tm_sec = 0; //p_tm.tm_sec;
|
||||
|
||||
if (RT_NULL != alarm[0])
|
||||
{
|
||||
rt_alarm_delete(alarm[0]); //
|
||||
}
|
||||
alarm[0] = rt_alarm_create(poTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = 2; //开窗1闭合点
|
||||
if (RT_NULL != alarm[1])
|
||||
{
|
||||
rt_alarm_delete(alarm[1]); //
|
||||
}
|
||||
alarm[1] = rt_alarm_create(pdTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = 7; //开窗2开启点
|
||||
if (RT_NULL != alarm[2])
|
||||
{
|
||||
rt_alarm_delete(alarm[2]); //
|
||||
}
|
||||
alarm[2] = rt_alarm_create(poTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = 8; //开窗2闭合点
|
||||
if (RT_NULL != alarm[3])
|
||||
{
|
||||
rt_alarm_delete(alarm[3]); //
|
||||
}
|
||||
alarm[3] = rt_alarm_create(pdTT_callback, &setup);
|
||||
|
||||
|
||||
for (size_t var = 0; var < 4; var++) {
|
||||
if (alarm[var] != RT_NULL) {
|
||||
rt_alarm_start(alarm[var]);
|
||||
// LOG_D("alarm %d started.",var+1);
|
||||
LOG_D("alarm %d(%02d) started.",var+1,alarm[var]->wktime.tm_hour+8);
|
||||
}
|
||||
else {
|
||||
LOG_E("Failed to start alarm %d.",var+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
INIT_APP_EXPORT(InitAlarm);
|
||||
/**
|
||||
* 更新rtc闹钟
|
||||
* @param t 每个rtc时刻组成的数组,依次对应开窗时段的开始和结束
|
||||
*/
|
||||
void updateAlarm(int *t)
|
||||
{
|
||||
struct rt_alarm_setup setup;
|
||||
|
||||
static time_t now;
|
||||
struct tm p_tm;
|
||||
/* 获取当前时间戳,并把下一秒时间设置为闹钟时间 */
|
||||
now = time(NULL);
|
||||
gmtime_r(&now, &p_tm);
|
||||
|
||||
setup.flag = RT_ALARM_DAILY;//天重复
|
||||
setup.wktime.tm_year = p_tm.tm_year;
|
||||
setup.wktime.tm_mon = p_tm.tm_mon;
|
||||
setup.wktime.tm_mday = p_tm.tm_mday;
|
||||
setup.wktime.tm_wday = p_tm.tm_wday;
|
||||
// setup.wktime.tm_hour = 1; //整点
|
||||
setup.wktime.tm_min = 0; //p_tm.tm_min;
|
||||
setup.wktime.tm_sec = 0; //p_tm.tm_sec;
|
||||
|
||||
setup.wktime.tm_hour = t[0]; //开窗1开启点
|
||||
if (RT_NULL != alarm[0])
|
||||
{
|
||||
rt_alarm_delete(alarm[0]); //
|
||||
}
|
||||
alarm[0] = rt_alarm_create(poTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = t[1]; //开窗1闭合点
|
||||
if (RT_NULL != alarm[1])
|
||||
{
|
||||
rt_alarm_delete(alarm[1]); //
|
||||
}
|
||||
alarm[1] = rt_alarm_create(pdTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = t[2]; //开窗2开启点
|
||||
if (RT_NULL != alarm[2])
|
||||
{
|
||||
rt_alarm_delete(alarm[2]); //
|
||||
}
|
||||
alarm[2] = rt_alarm_create(poTT_callback, &setup);
|
||||
|
||||
setup.wktime.tm_hour = t[3]; //开窗2闭合点
|
||||
if (RT_NULL != alarm[3])
|
||||
{
|
||||
rt_alarm_delete(alarm[3]); //
|
||||
}
|
||||
alarm[3] = rt_alarm_create(pdTT_callback, &setup);
|
||||
|
||||
|
||||
for (size_t var = 0; var < 4; var++) {
|
||||
if (alarm[var] != RT_NULL) {
|
||||
rt_alarm_start(alarm[var]);
|
||||
LOG_D("alarm %d started.",var+1);
|
||||
}
|
||||
else {
|
||||
LOG_E("Failed to start alarm %d.",var+1);
|
||||
}
|
||||
}
|
||||
// rt_alarm_control(alarm[0],RT_ALARM_CTRL_MODIFY,&setup);
|
||||
|
||||
}
|
||||
/**
|
||||
* 关闭rtc闹钟,
|
||||
*/
|
||||
void stopAlarm()
|
||||
{
|
||||
for (size_t var = 0; var < 4; var++) {
|
||||
if (alarm[var] != RT_NULL) {
|
||||
rt_alarm_stop(alarm[var]);
|
||||
LOG_D("alarm %d stopped.",var+1);
|
||||
}
|
||||
else {
|
||||
LOG_E("Failed to stop alarm %d.",var+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 恢复rtc闹钟,
|
||||
*/
|
||||
void startAlarm()
|
||||
{
|
||||
for (size_t var = 0; var < 4; var++) {
|
||||
if (alarm[var] != RT_NULL) {
|
||||
rt_alarm_start(alarm[var]);
|
||||
LOG_D("alarm %d started.",var+1);
|
||||
}
|
||||
else {
|
||||
LOG_E("Failed to start alarm %d.",var+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
//MSH_CMD_EXPORT(stopAlarm,stop);
|
||||
//MSH_CMD_EXPORT(startAlarm,start);
|
||||
|
@ -69,4 +69,4 @@ void sys_log_file_backend_init(void)
|
||||
ulog_file_backend_enable(file_be); //必须使能才能有效
|
||||
}
|
||||
MSH_CMD_EXPORT(sys_log_file_backend_init,log2file);
|
||||
INIT_APP_EXPORT(sys_log_file_backend_init);
|
||||
//INIT_COMPONENT_EXPORT(sys_log_file_backend_init);
|
||||
|
@ -35,6 +35,8 @@ int main(void)
|
||||
|
||||
rt_pin_mode(TT_EN, PIN_MODE_OUTPUT);
|
||||
|
||||
rt_pin_mode(TR485_RE, PIN_MODE_OUTPUT);
|
||||
rt_pin_write(TR485_RE, PIN_LOW);
|
||||
// rt_pin_write(ETH_RESET_PIN, PIN_LOW);//关闭ETH
|
||||
// rt_pin_write(TT_EN, PIN_HIGH);//关闭TT
|
||||
|
||||
@ -118,12 +120,14 @@ void pp(int argc, char **argv)
|
||||
MSH_CMD_EXPORT(pp, 打包文件。);
|
||||
#endif
|
||||
|
||||
|
||||
INIT_APP_EXPORT(main);
|
||||
extern int rt_hw_stm32_eth_init(void);
|
||||
MSH_CMD_EXPORT(rt_hw_stm32_eth_init, 初始化网络。);
|
||||
|
||||
void show_version(void)
|
||||
{
|
||||
rt_kprintf("SW Version: %s\n","1.0");
|
||||
rt_kprintf("SW Version: %s\n","1.3");
|
||||
}
|
||||
|
||||
MSH_CMD_EXPORT(show_version,显示版本号);
|
||||
|
@ -109,7 +109,7 @@ void hexFile(int argc, char **argv)
|
||||
static char f[30];
|
||||
rt_strcpy(f,argv[1]);
|
||||
/* 创建线程 */
|
||||
rt_thread_t thread = rt_thread_create("hex_file", hexFile_thread_entry, (void *) f, 1024 * 1, 25, 10);
|
||||
rt_thread_t thread = rt_thread_create("hex_file", hexFile_thread_entry, (void *) f, 1024 * 2, 25, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
|
@ -18,6 +18,7 @@
|
||||
#include <rtthread.h>
|
||||
#include <dfs_file.h>
|
||||
#include <usrcfg.h>
|
||||
#include <board.h>
|
||||
|
||||
#define LOG_TAG "uart"
|
||||
#define LOG_LVL LOG_LVL_DBG
|
||||
@ -101,19 +102,19 @@ static void serial_thread_entry(void *parameter)
|
||||
{
|
||||
|
||||
/* 从串口读取数据*/
|
||||
rx_length = rt_device_read(msg.dev, 0, rx_buffer+rx_length, msg.size);
|
||||
rx_length = rt_device_read(msg.dev, 0, rx_buffer, msg.size);
|
||||
currLen += rx_length;
|
||||
/* 启动定时器1 */
|
||||
if (timer1 != RT_NULL)
|
||||
rt_timer_start(timer1);
|
||||
|
||||
LOG_D("rec cnt=%d",rx_length);
|
||||
LOG_HEX("rx:",16,rx_buffer,rx_length);//print what received.
|
||||
|
||||
#ifdef TR_ACK
|
||||
/* 回传收到的消息 */
|
||||
rt_device_write(serial, 0, rx_buffer+rx_length, rx_length);
|
||||
#endif
|
||||
if (currLen > 1024) //大于1k则存盘
|
||||
if (0 && currLen > 1024) //大于1k则存盘
|
||||
{
|
||||
|
||||
int fd =open(f,O_WRONLY | O_CREAT|O_APPEND);
|
||||
@ -139,7 +140,7 @@ static int uart_dma_sample(int argc, char *argv[])
|
||||
rt_err_t ret = RT_EOK;
|
||||
char uart_name[RT_NAME_MAX];
|
||||
static char msg_pool[256];
|
||||
// char str[] = "hello RT-Thread!\r\n";
|
||||
char str[] = {0x01,0x03,0x00,0x00,0x00,0x1d,0x85,0xc3};
|
||||
|
||||
if (argc == 2)
|
||||
{
|
||||
@ -164,14 +165,27 @@ static int uart_dma_sample(int argc, char *argv[])
|
||||
sizeof(struct rx_msg), /* 一条消息的最大长度 */
|
||||
sizeof(msg_pool), /* 存放消息的缓冲区大小 */
|
||||
RT_IPC_FLAG_FIFO); /* 如果有多个线程等待,按照先来先得到的方法分配消息 */
|
||||
|
||||
#ifdef TR485
|
||||
struct serial_configure config = RT_SERIAL_CONFIG_DEFAULT; /* 初 始 化 配 置 参 数 */
|
||||
/* step2: 修 改 串 口 配 置 参 数 */
|
||||
config.baud_rate = BAUD_RATE_9600; //修 改 波 特 率 为 9600
|
||||
config.data_bits = DATA_BITS_8; //数 据 位 8
|
||||
config.stop_bits = STOP_BITS_1; //停 止 位 1
|
||||
config.bufsz = 128; //修 改 缓 冲 区 buff size 为 128
|
||||
config.parity = PARITY_NONE; //无 奇 偶 校 验 位
|
||||
/* step3: 控 制 串 口 设 备。 通 过 控 制 接 口 传 入 命 令 控 制 字, 与 控 制 参 数 */
|
||||
rt_device_control(serial, RT_DEVICE_CTRL_CONFIG, &config);
|
||||
#endif
|
||||
/* 以 DMA 接收及轮询发送方式打开串口设备 */
|
||||
rt_device_open(serial, RT_DEVICE_FLAG_DMA_RX);
|
||||
/* 设置接收回调函数 */
|
||||
rt_device_set_rx_indicate(serial, uart_input);
|
||||
/* 发送字符串 */
|
||||
// rt_device_write(serial, 0, str, (sizeof(str) - 1));
|
||||
|
||||
#ifdef TR485
|
||||
rt_pin_write(TR485_RE, PIN_HIGH);
|
||||
rt_device_write(serial, 0, str, sizeof(str));
|
||||
rt_pin_write(TR485_RE, PIN_LOW);
|
||||
#endif
|
||||
/* 创建定时器1 周期定时器 */
|
||||
timer1 = rt_timer_create("rxtimer", timeout1,
|
||||
RT_NULL, rt_tick_from_millisecond(40*1000),
|
||||
@ -179,7 +193,7 @@ static int uart_dma_sample(int argc, char *argv[])
|
||||
|
||||
|
||||
/* 创建 serial 线程 */
|
||||
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024*1, 25+1, 10);
|
||||
rt_thread_t thread = rt_thread_create("serial", serial_thread_entry, RT_NULL, 1024*2, 25+1, 10);
|
||||
/* 创建成功则启动线程 */
|
||||
if (thread != RT_NULL)
|
||||
{
|
||||
@ -195,3 +209,26 @@ static int uart_dma_sample(int argc, char *argv[])
|
||||
/* 导出到 msh 命令列表中 */
|
||||
MSH_CMD_EXPORT(uart_dma_sample, uart device dma sample);
|
||||
INIT_COMPONENT_EXPORT(uart_dma_sample);
|
||||
|
||||
|
||||
|
||||
void sendData(int argc, char *argv[])
|
||||
{
|
||||
//待发数据
|
||||
char str[][50] =
|
||||
{
|
||||
{0x01,0x03,0x00,0x00,0x00,0x1d,0x85,0xc3},
|
||||
"hello",
|
||||
{0x5A,0xA5, 0x31, 0x32, 0x19, 0x06, 0x00, 0x01, 0x01, 0x1C, 0xED }
|
||||
};
|
||||
|
||||
size_t size[]={8,strlen(str[1]),11};//对应每一维数据长度
|
||||
|
||||
size_t index = 0;
|
||||
if (argc == 2) {
|
||||
index = atoi(argv[1]);
|
||||
}
|
||||
size_t rst = rt_device_write(serial, 0, str[index], size[index]);
|
||||
LOG_D("send %d Bytes ok.",rst);
|
||||
}
|
||||
MSH_CMD_EXPORT(sendData,3所串口发送数据,参数为第几组数据)
|
||||
|
@ -76,6 +76,12 @@ extern "C"
|
||||
#define BSP_UART3_TX_PIN "PB10"
|
||||
#define BSP_UART3_RX_PIN "PB11"
|
||||
#define BSP_UART3_RX_USING_DMA
|
||||
|
||||
#define BSP_USING_UART6
|
||||
#define BSP_UART6_TX_PIN "PC6"
|
||||
#define BSP_UART6_RX_PIN "PC7"
|
||||
#define BSP_UART6_RX_USING_DMA
|
||||
|
||||
#else
|
||||
#define BSP_USING_UART1
|
||||
#define BSP_UART1_TX_PIN "PA9"
|
||||
@ -385,6 +391,7 @@ extern "C"
|
||||
#define LED_HEART_DEBUG GET_PIN(B,3)
|
||||
#define TT_EN GET_PIN(B,0)
|
||||
#define ETH_RESET_PIN GET_PIN(A, 4)//E-7
|
||||
#define TR485_RE GET_PIN(C,3)
|
||||
#else
|
||||
#define LED_HEART GET_PIN(E,3)
|
||||
// #define LED_HEART_DEBUG GET_PIN(B,3)
|
||||
|
@ -207,6 +207,7 @@
|
||||
|
||||
/* log format */
|
||||
|
||||
#define ULOG_OUTPUT_FLOAT
|
||||
#define ULOG_USING_COLOR
|
||||
#define ULOG_OUTPUT_TIME
|
||||
#define ULOG_TIME_USING_TIMESTAMP
|
||||
@ -283,6 +284,8 @@
|
||||
|
||||
/* enhanced kernel services */
|
||||
|
||||
#define PKG_USING_RT_VSNPRINTF_FULL
|
||||
#define PKG_USING_RT_VSNPRINTF_FULL_LATEST_VERSION
|
||||
/* end of enhanced kernel services */
|
||||
|
||||
/* acceleration: Assembly language or algorithmic acceleration packages */
|
||||
|
Loading…
Reference in New Issue
Block a user