commit
39dfef0eee
|
@ -8,15 +8,15 @@ extern int Image$$RW_IRAM1$$ZI$$Limit;
|
||||||
extern int __bss_end;
|
extern int __bss_end;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
uint8_t CpuUsageMajor, CpuUsageMinor; //CPU使用率
|
uint8_t CpuUsageMajor, CpuUsageMinor; //CPU使用率
|
||||||
USHORT usModbusUserData[MB_PDU_SIZE_MAX];
|
USHORT usModbusUserData[MB_PDU_SIZE_MAX];
|
||||||
UCHAR ucModbusUserData[MB_PDU_SIZE_MAX];
|
UCHAR ucModbusUserData[MB_PDU_SIZE_MAX];
|
||||||
//====================操作系统各线程优先级==================================
|
//====================操作系统各线程优先级==================================
|
||||||
#define thread_SysMonitor_Prio 11
|
#define thread_SysMonitor_Prio 11
|
||||||
#define thread_ModbusSlavePoll_Prio 10
|
#define thread_ModbusSlavePoll_Prio 10
|
||||||
#define thread_ModbusMasterPoll_Prio 9
|
#define thread_ModbusMasterPoll_Prio 9
|
||||||
ALIGN(RT_ALIGN_SIZE)
|
ALIGN(RT_ALIGN_SIZE)
|
||||||
//====================操作系统各线程堆栈====================================
|
//====================操作系统各线程堆栈====================================
|
||||||
static rt_uint8_t thread_SysMonitor_stack[256];
|
static rt_uint8_t thread_SysMonitor_stack[256];
|
||||||
static rt_uint8_t thread_ModbusSlavePoll_stack[512];
|
static rt_uint8_t thread_ModbusSlavePoll_stack[512];
|
||||||
static rt_uint8_t thread_ModbusMasterPoll_stack[512];
|
static rt_uint8_t thread_ModbusMasterPoll_stack[512];
|
||||||
|
@ -25,11 +25,11 @@ struct rt_thread thread_SysMonitor;
|
||||||
struct rt_thread thread_ModbusSlavePoll;
|
struct rt_thread thread_ModbusSlavePoll;
|
||||||
struct rt_thread thread_ModbusMasterPoll;
|
struct rt_thread thread_ModbusMasterPoll;
|
||||||
|
|
||||||
//***************************系统监控线程***************************
|
//***************************系统监控线程***************************
|
||||||
//函数定义: void thread_entry_SysRunLed(void* parameter)
|
//函数定义: void thread_entry_SysRunLed(void* parameter)
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Armink 2013-08-02 Company: BXXJS
|
//备 注:Editor:Armink 2013-08-02 Company: BXXJS
|
||||||
//******************************************************************
|
//******************************************************************
|
||||||
void thread_entry_SysMonitor(void* parameter)
|
void thread_entry_SysMonitor(void* parameter)
|
||||||
{
|
{
|
||||||
|
@ -60,18 +60,18 @@ void thread_entry_SysMonitor(void* parameter)
|
||||||
// errorCode = eMBMasterReqWriteMultipleHoldingRegister(1,3,2,usModbusUserData,RT_WAITING_FOREVER);
|
// errorCode = eMBMasterReqWriteMultipleHoldingRegister(1,3,2,usModbusUserData,RT_WAITING_FOREVER);
|
||||||
// errorCode = eMBMasterReqReadHoldingRegister(1,3,2,RT_WAITING_FOREVER);
|
// errorCode = eMBMasterReqReadHoldingRegister(1,3,2,RT_WAITING_FOREVER);
|
||||||
// errorCode = eMBMasterReqReadWriteMultipleHoldingRegister(1,3,2,usModbusUserData,5,2,RT_WAITING_FOREVER);
|
// errorCode = eMBMasterReqReadWriteMultipleHoldingRegister(1,3,2,usModbusUserData,5,2,RT_WAITING_FOREVER);
|
||||||
//记录出错次数
|
//记录出错次数
|
||||||
if (errorCode != MB_MRE_NO_ERR) {
|
if (errorCode != MB_MRE_NO_ERR) {
|
||||||
errorCount++;
|
errorCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************ Modbus从机轮训线程***************************
|
//************************ Modbus从机轮训线程***************************
|
||||||
//函数定义: void thread_entry_ModbusSlavePoll(void* parameter)
|
//函数定义: void thread_entry_ModbusSlavePoll(void* parameter)
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Armink 2013-08-02 Company: BXXJS
|
//备 注:Editor:Armink 2013-08-02 Company: BXXJS
|
||||||
//******************************************************************
|
//******************************************************************
|
||||||
void thread_entry_ModbusSlavePoll(void* parameter)
|
void thread_entry_ModbusSlavePoll(void* parameter)
|
||||||
{
|
{
|
||||||
|
@ -83,11 +83,11 @@ void thread_entry_ModbusSlavePoll(void* parameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//************************ Modbus主机轮训线程***************************
|
//************************ Modbus主机轮训线程***************************
|
||||||
//函数定义: void thread_entry_ModbusMasterPoll(void* parameter)
|
//函数定义: void thread_entry_ModbusMasterPoll(void* parameter)
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Armink 2013-08-28 Company: BXXJS
|
//备 注:Editor:Armink 2013-08-28 Company: BXXJS
|
||||||
//******************************************************************
|
//******************************************************************
|
||||||
void thread_entry_ModbusMasterPoll(void* parameter)
|
void thread_entry_ModbusMasterPoll(void* parameter)
|
||||||
{
|
{
|
||||||
|
@ -99,11 +99,11 @@ void thread_entry_ModbusMasterPoll(void* parameter)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//**********************系统初始化函数********************************
|
//**********************系统初始化函数********************************
|
||||||
//函数定义: int rt_application_init(void)
|
//函数定义: int rt_application_init(void)
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Liuqiuhu 2013-1-31 Company: BXXJS
|
//备 注:Editor:Liuqiuhu 2013-1-31 Company: BXXJS
|
||||||
//********************************************************************
|
//********************************************************************
|
||||||
int rt_application_init(void)
|
int rt_application_init(void)
|
||||||
{
|
{
|
||||||
|
@ -127,11 +127,11 @@ int rt_application_init(void)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//**************************初始化RT-Thread函数*************************************
|
//**************************初始化RT-Thread函数*************************************
|
||||||
//函数定义: void rtthread_startup(void)
|
//函数定义: void rtthread_startup(void)
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Armink 2011-04-04 Company: BXXJS
|
//备 注:Editor:Armink 2011-04-04 Company: BXXJS
|
||||||
//**********************************************************************************
|
//**********************************************************************************
|
||||||
void rtthread_startup(void)
|
void rtthread_startup(void)
|
||||||
{
|
{
|
||||||
|
|
|
@ -78,7 +78,7 @@ void IWDG_Feed(void);
|
||||||
/***********************************************************************************************************/
|
/***********************************************************************************************************/
|
||||||
|
|
||||||
|
|
||||||
//软、硬件版本号定义
|
//软、硬件版本号定义
|
||||||
#define VERSION_SOFTWARE_MAJOR 1
|
#define VERSION_SOFTWARE_MAJOR 1
|
||||||
#define VERSION_SOFTWARE_MINOR 0
|
#define VERSION_SOFTWARE_MINOR 0
|
||||||
#define VERSION_HARDWARE_MAJOR 1
|
#define VERSION_HARDWARE_MAJOR 1
|
||||||
|
|
|
@ -60,18 +60,18 @@ void rt_hw_board_init()
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
static void RCC_Configuration(void)
|
static void RCC_Configuration(void)
|
||||||
{
|
{
|
||||||
//下面是给各模块开启时钟
|
//下面是给各模块开启时钟
|
||||||
//启动GPIO
|
//启动GPIO
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | \
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB | \
|
||||||
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | \
|
RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | \
|
||||||
RCC_APB2Periph_GPIOE ,
|
RCC_APB2Periph_GPIOE ,
|
||||||
ENABLE);
|
ENABLE);
|
||||||
//启动AFIO
|
//启动AFIO
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO, ENABLE);
|
||||||
//配置ADC转换时钟
|
//配置ADC转换时钟
|
||||||
RCC_ADCCLKConfig(RCC_PCLK2_Div8); //9M
|
RCC_ADCCLKConfig(RCC_PCLK2_Div8); //9M
|
||||||
//启动DMA时钟
|
//启动DMA时钟
|
||||||
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA时钟
|
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);//使能DMA时钟
|
||||||
/* Enable ADC1 and GPIOC clock */
|
/* Enable ADC1 and GPIOC clock */
|
||||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC1 , ENABLE);
|
||||||
}
|
}
|
||||||
|
@ -106,17 +106,17 @@ static void GPIO_Configuration(void)
|
||||||
{
|
{
|
||||||
GPIO_InitTypeDef GPIO_InitStructure;
|
GPIO_InitTypeDef GPIO_InitStructure;
|
||||||
|
|
||||||
/***************数字输出IO初始化*********************/
|
/***************数字输出IO初始化*********************/
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12; //继电器1 LED1 LED2
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_8 | GPIO_Pin_11 | GPIO_Pin_12; //继电器1 LED1 LED2
|
||||||
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
GPIO_Init(GPIOA, &GPIO_InitStructure);
|
||||||
|
|
||||||
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_14 | GPIO_Pin_15; //蜂鸣器 继电器3 继电器2
|
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_0 | GPIO_Pin_14 | GPIO_Pin_15; //蜂鸣器 继电器3 继电器2
|
||||||
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
GPIO_Init(GPIOB, &GPIO_InitStructure);
|
||||||
|
|
||||||
/*************数字输入IO初始化*********************/
|
/*************数字输入IO初始化*********************/
|
||||||
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
|
||||||
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
|
||||||
|
|
||||||
|
@ -125,29 +125,29 @@ static void GPIO_Configuration(void)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//*******************初始化独立看门狗*************************************
|
//*******************初始化独立看门狗*************************************
|
||||||
//函数定义: void IWDG_Configuration(void)
|
//函数定义: void IWDG_Configuration(void)
|
||||||
//描 述:初始化独立看门狗
|
//描 述:初始化独立看门狗
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:分频因子=4*2^prer.但最大值只能是256!时间计算(大概):Tout=40K/((4*2^prer)*rlr)值 2S超时
|
//备 注:分频因子=4*2^prer.但最大值只能是256!时间计算(大概):Tout=40K/((4*2^prer)*rlr)值 2S超时
|
||||||
//Editor:liuqh 2013-1-16 Company: BXXJS
|
//Editor:liuqh 2013-1-16 Company: BXXJS
|
||||||
//*******************************************************************
|
//*******************************************************************
|
||||||
static void IWDG_Configuration(void)
|
static void IWDG_Configuration(void)
|
||||||
{
|
{
|
||||||
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);//使能对IWDG->PR和IWDG->RLR的写
|
IWDG_WriteAccessCmd(IWDG_WriteAccess_Enable);//使能对IWDG->PR和IWDG->RLR的写
|
||||||
IWDG_SetPrescaler(IWDG_Prescaler_64);//64分频
|
IWDG_SetPrescaler(IWDG_Prescaler_64);//64分频
|
||||||
IWDG_SetReload(1300);
|
IWDG_SetReload(1300);
|
||||||
IWDG_ReloadCounter();
|
IWDG_ReloadCounter();
|
||||||
IWDG_Enable();
|
IWDG_Enable();
|
||||||
}
|
}
|
||||||
//*******************喂独立看门狗*************************************
|
//*******************喂独立看门狗*************************************
|
||||||
//函数定义: void IWDG_Feed(void)
|
//函数定义: void IWDG_Feed(void)
|
||||||
//描 述:初始化独立看门狗
|
//描 述:初始化独立看门狗
|
||||||
//入口参数:无
|
//入口参数:无
|
||||||
//出口参数:prer:分频数:0~7(只有低3位有效!),rlr:重装载寄存器值:低11位有效.
|
//出口参数:prer:分频数:0~7(只有低3位有效!),rlr:重装载寄存器值:低11位有效.
|
||||||
//备 注:分频因子=4*2^prer.但最大值只能是256!时间计算(大概):Tout=40K/((4*2^prer)*rlr)值
|
//备 注:分频因子=4*2^prer.但最大值只能是256!时间计算(大概):Tout=40K/((4*2^prer)*rlr)值
|
||||||
//Editor:liuqh 2013-1-16 Company: BXXJS
|
//Editor:liuqh 2013-1-16 Company: BXXJS
|
||||||
//*******************************************************************
|
//*******************************************************************
|
||||||
|
|
||||||
void IWDG_Feed(void)
|
void IWDG_Feed(void)
|
||||||
|
@ -219,19 +219,19 @@ void BSP_Init (void)
|
||||||
NVIC_Configuration();
|
NVIC_Configuration();
|
||||||
SysTick_Configuration();
|
SysTick_Configuration();
|
||||||
GPIO_Configuration();
|
GPIO_Configuration();
|
||||||
// TODO 方便调试,暂时注释看门狗,正式发布时需要打开
|
// TODO 方便调试,暂时注释看门狗,正式发布时需要打开
|
||||||
// IWDG_Configuration();
|
// IWDG_Configuration();
|
||||||
}
|
}
|
||||||
//****************************防超时程序********************************
|
//****************************防超时程序********************************
|
||||||
//函数定义: uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)())
|
//函数定义: uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)())
|
||||||
//描 述:在TimeOfTimeout时间内,每Period时间检测一次DetectCondition()返回的值是否有效
|
//描 述:在TimeOfTimeout时间内,每Period时间检测一次DetectCondition()返回的值是否有效
|
||||||
//入口参数:TimeOfTimeout:防超时总时间(单位:systick)
|
//入口参数:TimeOfTimeout:防超时总时间(单位:systick)
|
||||||
// Period :每Period时间检测一次,即时间因子(单位:systick)
|
// Period :每Period时间检测一次,即时间因子(单位:systick)
|
||||||
// (*DetectCondition)():检测条件,等于ConditionValue则条件满足,检测结束,否则延时Period时间继续检测
|
// (*DetectCondition)():检测条件,等于ConditionValue则条件满足,检测结束,否则延时Period时间继续检测
|
||||||
// ConditionValue ;条件成立的值
|
// ConditionValue ;条件成立的值
|
||||||
//出口参数:0:在TimeOfTimeout时间内,检测到条件成立
|
//出口参数:0:在TimeOfTimeout时间内,检测到条件成立
|
||||||
// 1:在TimeOfTimeout时间内,没有检测到条件成立
|
// 1:在TimeOfTimeout时间内,没有检测到条件成立
|
||||||
//备 注:Editor:Armink 2012-03-09 Company: BXXJS
|
//备 注:Editor:Armink 2012-03-09 Company: BXXJS
|
||||||
//**********************************************************************
|
//**********************************************************************
|
||||||
uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)(),uint8_t ConditionValue)
|
uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCondition)(),uint8_t ConditionValue)
|
||||||
{
|
{
|
||||||
|
@ -250,11 +250,11 @@ uint8_t AvoidTimeout(uint32_t TimeOfTimeout,uint32_t Period,uint8_t (*DetectCond
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
//************************************延时函数**************************************
|
//************************************延时函数**************************************
|
||||||
//函数定义: void Delay(vu32 nCount)
|
//函数定义: void Delay(vu32 nCount)
|
||||||
//入口参数:nCount :延时函数中,循环的次数
|
//入口参数:nCount :延时函数中,循环的次数
|
||||||
//出口参数:无
|
//出口参数:无
|
||||||
//备 注:Editor:Armink 2011-03-18 Company: BXXJS
|
//备 注:Editor:Armink 2011-03-18 Company: BXXJS
|
||||||
//**********************************************************************************
|
//**********************************************************************************
|
||||||
void Delay(vu32 nCount)
|
void Delay(vu32 nCount)
|
||||||
{
|
{
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* File : usart.c
|
* File : usart.c
|
||||||
* This file is part of RT-Thread RTOS
|
* This file is part of RT-Thread RTOS
|
||||||
* COPYRIGHT (C) 2006-2013, RT-Thread Development Team
|
* COPYRIGHT (C) 2006-2021, RT-Thread Development Team
|
||||||
*
|
*
|
||||||
* The license and distribution terms for this file may be
|
* The license and distribution terms for this file may be
|
||||||
* found in the file LICENSE in this distribution or at
|
* found in the file LICENSE in this distribution or at
|
||||||
|
|
|
@ -390,7 +390,7 @@ eMBMasterFuncReadDiscreteInputs( UCHAR * pucFrame, USHORT * usLen );
|
||||||
eMBException
|
eMBException
|
||||||
eMBMasterFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
|
eMBMasterFuncReadWriteMultipleHoldingRegister( UCHAR * pucFrame, USHORT * usLen );
|
||||||
|
|
||||||
/*! \ingroup modbus
|
/*! \ingroup modbus
|
||||||
*\brief These functions are interface for Modbus Master
|
*\brief These functions are interface for Modbus Master
|
||||||
*/
|
*/
|
||||||
void vMBMasterGetPDUSndBuf( UCHAR ** pucFrame );
|
void vMBMasterGetPDUSndBuf( UCHAR ** pucFrame );
|
||||||
|
|
Loading…
Reference in New Issue