@@ -2,4 +2,5 @@ TrainCamp_zhangcheng_PLSR/.vscode | |||||
TrainCamp_zhangcheng_PLSR/iar/Debug | TrainCamp_zhangcheng_PLSR/iar/Debug | ||||
TrainCamp_zhangcheng_PLSR/iar/settings | TrainCamp_zhangcheng_PLSR/iar/settings | ||||
TrainCamp_zhangcheng_PLSR/iar/PLSR.dep | TrainCamp_zhangcheng_PLSR/iar/PLSR.dep | ||||
TrainCamp_zhangcheng_PLSR/iar/PLSR.ewt | |||||
TrainCamp_zhangcheng_PLSR/iar/PLSR.ewt | |||||
.TMP |
@@ -12,6 +12,76 @@ | |||||
#include "../../modbus/inc/modbus.h" | #include "../../modbus/inc/modbus.h" | ||||
/** | |||||
* @brief 系统参数块 | |||||
* @details | |||||
* @note | |||||
* @attention | |||||
*/ | |||||
typedef enum { | |||||
SYSTEM_PARAM_BLOCK_0 = 0, ///< 系统参数块0,默认参数块,不可修改 | |||||
SYSTEM_PARAM_BLOCK_1, ///< 系统参数块1 | |||||
SYSTEM_PARAM_BLOCK_2, ///< 系统参数块2 | |||||
SYSTEM_PARAM_BLOCK_3, ///< 系统参数块3 | |||||
SYSTEM_PARAM_BLOCK_4 ///< 系统参数块4 | |||||
} PLSR_SYSTEM_PARAM_BLOCK; | |||||
/** | |||||
* @brief 输出端口 | |||||
* @details | |||||
* @note | |||||
* @attention | |||||
*/ | |||||
typedef enum { | |||||
OUTPUT_PORT_Y0 = 0, ///< 输出端子Y0 | |||||
OUTPUT_PORT_Y1, ///< 输出端子Y1 | |||||
OUTPUT_PORT_Y2, ///< 输出端子Y2 | |||||
OUTPUT_PORT_Y3 ///< 输出端子Y3 | |||||
} PLSR_OUTPUT_PORT; | |||||
/** | |||||
* @brief 输出模式 | |||||
* @details | |||||
* @note | |||||
* @attention | |||||
*/ | |||||
typedef enum { | |||||
RELATIVE_MODE = 0, ///< 相对模式 | |||||
ABSOLUTE_MODE ///< 绝对模式 | |||||
} PLSR_OUTPUT_MODE; | |||||
/** | |||||
* @brief 参数错误类型 | |||||
* @details | |||||
* @note | |||||
* @attention | |||||
*/ | |||||
typedef enum { | |||||
PLSR_ERROR_NONE = 0, ///< 无错误 | |||||
PLSR_FREQ_EXCE_MAX_VALUE ///< 超过最大输出频率 | |||||
} PLSR_ERROR_TYPE; | |||||
/** | |||||
* @brief PLSR指令结构类型 | |||||
* @details | |||||
* @note | |||||
* @attention | |||||
*/ | |||||
typedef struct | |||||
{ | |||||
uint16_t *dataStartAddr; ///< 起始数据地址 | |||||
uint16_t *userParamBlockAddr; ///< 用户参数块地址 | |||||
PLSR_SYSTEM_PARAM_BLOCK systemParamBlock; ///< 系统参数 | |||||
PLSR_OUTPUT_PORT outputPort; ///< 输出端子 | |||||
PLSR_OUTPUT_PORT mode; ///< 输出模式 | |||||
} PLSR_CMD; | |||||
/** | /** | ||||
* @brief PLSR功能初始化 | * @brief PLSR功能初始化 | ||||
* @details | * @details | ||||
@@ -10,6 +10,7 @@ | |||||
#include "../../system/inc/system.h" | #include "../../system/inc/system.h" | ||||
#include "../../bsp/inc/time.h" | |||||
#include "../inc/plsr.h" | #include "../inc/plsr.h" | ||||
@@ -50,12 +51,106 @@ RESUIL PLSRInit(void) | |||||
} | } | ||||
OS_EXIT_CRITICAL(); | OS_EXIT_CRITICAL(); | ||||
return MODBUS_TURE; | return MODBUS_TURE; | ||||
} | |||||
} | |||||
#include "../../bsp/inc/gpio.h" | |||||
void Callack(void *pArg) | |||||
{ | |||||
gpio_obj_t *gpio_f_6; | |||||
gpio_f_6 = get_gpio_obj("gpio_f"); | |||||
gpio_f_6->gpio_init(gpio_f_6, gpio_pin_6, "OUT_PP", "UP"); | |||||
if (*((uint8_t *)pArg) < 13) | |||||
printf("Callback tim2 count %d\r\n", (*((uint8_t *)pArg))++); | |||||
else | |||||
printf("Callback tim13 count %d\r\n", (*((uint8_t *)pArg))++); | |||||
uint16_t read_gpio_pin = 0; | |||||
read_gpio_pin = gpio_f_6->gpio_read_output(gpio_f_6); | |||||
if(gpio_f_6->gpio_pin & read_gpio_pin) | |||||
{ | |||||
gpio_f_6->gpio_set_output(gpio_f_6, gpio_f_6->gpio_pin, 0); | |||||
#ifdef USE_LED_PIN_TRACE | |||||
pDev->led_state = "on"; | |||||
#endif | |||||
} | |||||
else | |||||
{ | |||||
gpio_f_6->gpio_set_output(gpio_f_6, gpio_f_6->gpio_pin, 1); | |||||
#ifdef USE_LED_PIN_TRACE | |||||
pDev->led_state = "off"; | |||||
#endif | |||||
} | |||||
} | |||||
/** | |||||
* @brief PLSR处理任务 | |||||
* @details | |||||
* | |||||
* @param[in] *pArg 任务参数 | |||||
* | |||||
* @return RESUIL 初始化结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
*/ | |||||
void PlsrModuleTask(void *pArg) | |||||
{ | |||||
TIM_OBJ tim2; | |||||
TIM_OBJ tim10; | |||||
int8_t res; | |||||
uint8_t pArgment = 0; | |||||
int32_t pulseFreq = 0; | |||||
int32_t pulseCount = 0; | |||||
uint32_t pulseReload = 0; | |||||
res = GetTimObj("tim2", &tim2); | |||||
res = GetTimObj("tim10", &tim10); | |||||
if (res) | |||||
while (1); | |||||
tim2.init(&tim2, 8399, 9999); | |||||
tim2.open(&tim2); | |||||
tim2.registerIrq(&tim2, &Callack, &pArgment); | |||||
tim2.openIrq(&tim2); | |||||
tim10.init(&tim10, pulseFreq, pulseCount * 2); | |||||
tim10.open(&tim10); | |||||
if (pulseFreq >= 0 || pulseFreq <= 5000) | |||||
{ | |||||
pulseReload = (uint32_t)(((1.f / (float)pulseFreq) * 1000 * 1000) / 20); | |||||
tim10.init(&tim10, 1679, pulseReload); | |||||
} | |||||
else if (pulseFreq >= 5000 || pulseFreq <= 100000) | |||||
{ | |||||
pulseReload = (uint32_t)(((1.f / (float)pulseFreq) * 1000 * 1000) / 1); | |||||
tim10.init(&tim10, 83, pulseReload); | |||||
} | |||||
tim10.pwmInit(&tim10); | |||||
tim10.pwmSetPulse(&tim10, pulseReload / 2); | |||||
while (1) | |||||
{ | |||||
} | |||||
} | |||||
//1HZ | |||||
//psc 1680 | |||||
//per 50000 | |||||
//5KHZ | |||||
//psc 1680 | |||||
//per 10 | |||||
//100KHZ | |||||
//psc 84 | |||||
//per 840 | |||||
void PlsrModuleTask(void *pArg) | |||||
{ | |||||
while(1); | |||||
} | |||||
//定时器3 外部输入时钟源ETR引脚PB4,定时器11输出 | |||||
//定时器4 外部输入时钟源ETR引脚PB6,定时器14输出 | |||||
//定时器9 内部输入时钟源ITx主从模式定时器10 | |||||
//定时器12 内部输入时钟源ITx主从模式定时器13 |
@@ -44,12 +44,17 @@ typedef struct TIM | |||||
* @brief 获取定时器 | * @brief 获取定时器 | ||||
* @details | * @details | ||||
* | * | ||||
* @param[in] *timName 定时器名称 | |||||
* @param "timx" x : 10、11、13、14 | |||||
* @param[in] *timName 定时器名称 | |||||
* | |||||
* @param[out] *timObj 接收定时器参数地址 | |||||
* | * | ||||
* @return TIM 定时器结构体 | |||||
* @return int8_t 返回结果 | |||||
* @retval 0 成功 | |||||
* @retval -1 失败 | |||||
* | |||||
* @note *timName "timx" x : 10、11、13、14 | |||||
*/ | */ | ||||
TIM_OBJ GetTimObj(char *timName); | |||||
int8_t GetTimObj(char *timName, TIM_OBJ *timObj); | |||||
#endif | #endif | ||||
@@ -17,24 +17,23 @@ | |||||
typedef void (*Func)(void *pArg); | typedef void (*Func)(void *pArg); | ||||
/* 中断注册回调函数列表 */ | /* 中断注册回调函数列表 */ | ||||
static Func CallBackFuncList[3] = | |||||
static Func CallBackFuncList[] = | |||||
{ | { | ||||
NULL, ///< TIM10 | |||||
NULL, ///< TIM11 | |||||
NULL, ///< TIM2 | |||||
NULL ///< TIM13 | NULL ///< TIM13 | ||||
}; | }; | ||||
/* 中断注册回调参数列表 */ | /* 中断注册回调参数列表 */ | ||||
static void *ArgList[3] = | |||||
static void *ArgList[] = | |||||
{ | { | ||||
NULL, ///< TIM10 | |||||
NULL, ///< TIM11 | |||||
NULL, ///< TIM2 | |||||
NULL ///< TIM13 | NULL ///< TIM13 | ||||
}; | }; | ||||
/* 可用定时器列表 */ | /* 可用定时器列表 */ | ||||
static char *TimNameList[] = | static char *TimNameList[] = | ||||
{ | { | ||||
"tim2", ///< TIM2 | |||||
"tim10", ///< TIM10 | "tim10", ///< TIM10 | ||||
"tim11", ///< TIM11 | "tim11", ///< TIM11 | ||||
"tim13", ///< TIM13 | "tim13", ///< TIM13 | ||||
@@ -44,10 +43,11 @@ static char *TimNameList[] = | |||||
/* 可用定时器列表参数 */ | /* 可用定时器列表参数 */ | ||||
static TIM_TypeDef *TimType[] = | static TIM_TypeDef *TimType[] = | ||||
{ | { | ||||
TIM2, ///< TIM2 | |||||
TIM10, ///< TIM10 | TIM10, ///< TIM10 | ||||
TIM11, ///< TIM11 | TIM11, ///< TIM11 | ||||
TIM13, ///< TIM13 | TIM13, ///< TIM13 | ||||
TIM13 ///< TIM14 | |||||
TIM14 ///< TIM14 | |||||
}; | }; | ||||
@@ -67,8 +67,16 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per) | |||||
{ | { | ||||
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; | TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure; | ||||
if (tim->TIM == TIM10) | |||||
if (tim->TIM == TIM2) | |||||
{ | |||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE); | |||||
} | |||||
else if (tim->TIM == TIM10) | |||||
{ | |||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,ENABLE); | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,ENABLE); | ||||
} | |||||
else if (tim->TIM == TIM11) | else if (tim->TIM == TIM11) | ||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,ENABLE); | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,ENABLE); | ||||
else if (tim->TIM == TIM13) | else if (tim->TIM == TIM13) | ||||
@@ -85,7 +93,9 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per) | |||||
TIM_TimeBaseInitStructure.TIM_Period=per; | TIM_TimeBaseInitStructure.TIM_Period=per; | ||||
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; | TIM_TimeBaseInitStructure.TIM_Prescaler=psc; | ||||
TIM_TimeBaseInit(tim->TIM, &TIM_TimeBaseInitStructure); | TIM_TimeBaseInit(tim->TIM, &TIM_TimeBaseInitStructure); | ||||
TIM_GenerateEvent(tim->TIM, TIM_EventSource_Update); | |||||
return 0; | return 0; | ||||
} | } | ||||
@@ -100,7 +110,9 @@ int8_t TimInit(TIM_OBJ *tim, uint16_t psc, uint32_t per) | |||||
*/ | */ | ||||
void TimDeInit(TIM_OBJ *tim) | void TimDeInit(TIM_OBJ *tim) | ||||
{ | { | ||||
if (tim->TIM == TIM10) | |||||
if (tim->TIM == TIM2) | |||||
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,DISABLE); | |||||
else if (tim->TIM == TIM10) | |||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,DISABLE); | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM10,DISABLE); | ||||
else if (tim->TIM == TIM11) | else if (tim->TIM == TIM11) | ||||
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,DISABLE); | RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM11,DISABLE); | ||||
@@ -189,7 +201,12 @@ void TimOpenIrq(TIM_OBJ *tim) | |||||
TIM_ITConfig(tim->TIM, TIM_IT_Update, ENABLE); | TIM_ITConfig(tim->TIM, TIM_IT_Update, ENABLE); | ||||
TIM_ClearITPendingBit(tim->TIM, TIM_IT_Update); | TIM_ClearITPendingBit(tim->TIM, TIM_IT_Update); | ||||
NVIC_InitStructure.NVIC_IRQChannel=TIM8_UP_TIM13_IRQn; | |||||
if (tim->TIM == TIM2) | |||||
NVIC_InitStructure.NVIC_IRQChannel=TIM2_IRQn; | |||||
else if(tim->TIM == TIM13) | |||||
NVIC_InitStructure.NVIC_IRQChannel=TIM8_UP_TIM13_IRQn; | |||||
else | |||||
return; | |||||
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=7; | NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=7; | ||||
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; | NVIC_InitStructure.NVIC_IRQChannelSubPriority=0; | ||||
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; | NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE; | ||||
@@ -224,21 +241,16 @@ void TimCloseIrq(TIM_OBJ *tim) | |||||
*/ | */ | ||||
void TimRegisterIrq(TIM_OBJ *tim, void (*registerFunc)(void *pArg), void *pArg) | void TimRegisterIrq(TIM_OBJ *tim, void (*registerFunc)(void *pArg), void *pArg) | ||||
{ | { | ||||
if (tim->TIM == TIM10) | |||||
if (tim->TIM == TIM2) | |||||
{ | { | ||||
CallBackFuncList[0] = registerFunc; | CallBackFuncList[0] = registerFunc; | ||||
ArgList[0] = pArg; | ArgList[0] = pArg; | ||||
} | } | ||||
else if (tim->TIM == TIM11) | |||||
else if (tim->TIM == TIM13) | |||||
{ | { | ||||
CallBackFuncList[1] = registerFunc; | CallBackFuncList[1] = registerFunc; | ||||
ArgList[1] = pArg; | ArgList[1] = pArg; | ||||
} | } | ||||
else if (tim->TIM == TIM13) | |||||
{ | |||||
CallBackFuncList[2] = registerFunc; | |||||
ArgList[2] = pArg; | |||||
} | |||||
else | else | ||||
return; | return; | ||||
} | } | ||||
@@ -301,35 +313,40 @@ void PwmSetPulse(TIM_OBJ *tim, uint32_t pulse) | |||||
/** | /** | ||||
* @brief 定时器10、11、13、14更新中断服务函数 | |||||
* @brief 定时器2更新中断服务函数 | |||||
* @details | * @details | ||||
* | * | ||||
* @param[in] 无 | * @param[in] 无 | ||||
* | * | ||||
* @return 无 | * @return 无 | ||||
*/ | */ | ||||
void TIM8_UP_TIM13_IRQHandler(void) | |||||
void TIM2_IRQHandler(void) | |||||
{ | { | ||||
if (TIM_GetITStatus(TIM10,TIM_IT_Update) == SET) | |||||
if (TIM_GetITStatus(TIM2,TIM_IT_Update) == SET) | |||||
{ | { | ||||
if (ArgList[0] != NULL) | if (ArgList[0] != NULL) | ||||
CallBackFuncList[0](ArgList[0]); | CallBackFuncList[0](ArgList[0]); | ||||
TIM_ClearITPendingBit(TIM10, TIM_IT_Update); | |||||
TIM_ClearITPendingBit(TIM2, TIM_IT_Update); | |||||
} | } | ||||
else if (TIM_GetITStatus(TIM11,TIM_IT_Update) == SET) | |||||
} | |||||
/** | |||||
* @brief 定时器13更新中断服务函数 | |||||
* @details | |||||
* | |||||
* @param[in] 无 | |||||
* | |||||
* @return 无 | |||||
*/ | |||||
void TIM8_UP_TIM13_IRQHandler(void) | |||||
{ | |||||
if (TIM_GetITStatus(TIM13,TIM_IT_Update) == SET) | |||||
{ | { | ||||
if (ArgList[1] != NULL) | if (ArgList[1] != NULL) | ||||
CallBackFuncList[1](ArgList[1]); | CallBackFuncList[1](ArgList[1]); | ||||
TIM_ClearITPendingBit(TIM11, TIM_IT_Update); | |||||
TIM_ClearITPendingBit(TIM13, TIM_IT_Update); | |||||
} | } | ||||
else if (TIM_GetITStatus(TIM11,TIM_IT_Update) == SET) | |||||
{ | |||||
if (ArgList[2] != NULL) | |||||
CallBackFuncList[2](ArgList[2]); | |||||
TIM_ClearITPendingBit(TIM12, TIM_IT_Update); | |||||
} | |||||
else | |||||
return; | |||||
} | } | ||||
@@ -337,35 +354,46 @@ void TIM8_UP_TIM13_IRQHandler(void) | |||||
* @brief 获取定时器 | * @brief 获取定时器 | ||||
* @details | * @details | ||||
* | * | ||||
* @param[in] *timName 定时器名称 | |||||
* @param "timx" x : 10、11、13、14 | |||||
* @param[in] *timName 定时器名称 | |||||
* @note "timx" x : 10、11、13、14 | |||||
* @param[out] *timObj 接收定时器参数地址 | |||||
* | * | ||||
* @return TIM_OBJ 定时器结构体 | |||||
* @return int8_t 返回结果 | |||||
* @retval 0 成功 | |||||
* @retval -1 失败 | |||||
*/ | */ | ||||
TIM_OBJ GetTimObj(char *timName) | |||||
int8_t GetTimObj(char *timName, TIM_OBJ *timObj) | |||||
{ | { | ||||
TIM_OBJ tim; | |||||
uint8_t getTimFlag = 0; | |||||
if (!timObj) | |||||
return -1; | |||||
for (uint8_t i = 0; i < sizeof(TimNameList) / sizeof(TimNameList[0]); i++) | for (uint8_t i = 0; i < sizeof(TimNameList) / sizeof(TimNameList[0]); i++) | ||||
{ | { | ||||
if (strcmp(timName, TimNameList[i]) == 0) | if (strcmp(timName, TimNameList[i]) == 0) | ||||
{ | { | ||||
tim.TIM = TimType[i]; | |||||
timObj->TIM = TimType[i]; | |||||
getTimFlag = 1; | |||||
break; | |||||
} | } | ||||
} | } | ||||
tim.init = &TimInit; | |||||
tim.deInit = &TimDeInit; | |||||
tim.setPsc = &TimSetPsc; | |||||
tim.setPer = &TimSetPer; | |||||
tim.open = &TimOpen; | |||||
tim.close = &TimClose; | |||||
tim.openIrq = &TimOpenIrq; | |||||
tim.closeIrq = &TimCloseIrq; | |||||
tim.registerIrq = &TimRegisterIrq; | |||||
tim.pwmInit = &PwmInit; | |||||
tim.pwmDeInit = &PwmDeInit; | |||||
tim.pwmSetPulse = &PwmSetPulse; | |||||
return tim; | |||||
if (!getTimFlag) | |||||
return -1; | |||||
timObj->init = &TimInit; | |||||
timObj->deInit = &TimDeInit; | |||||
timObj->setPsc = &TimSetPsc; | |||||
timObj->setPer = &TimSetPer; | |||||
timObj->open = &TimOpen; | |||||
timObj->close = &TimClose; | |||||
timObj->openIrq = &TimOpenIrq; | |||||
timObj->closeIrq = &TimCloseIrq; | |||||
timObj->registerIrq = &TimRegisterIrq; | |||||
timObj->pwmInit = &PwmInit; | |||||
timObj->pwmDeInit = &PwmDeInit; | |||||
timObj->pwmSetPulse = &PwmSetPulse; | |||||
return 0; | |||||
} | } |
@@ -76,9 +76,7 @@ RESUIL AckProcModuleInit(void) | |||||
* | * | ||||
* @param[in] *pArg 任务参数 | * @param[in] *pArg 任务参数 | ||||
* | * | ||||
* @return RESUIL 初始化结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
* @return 无 | |||||
*/ | */ | ||||
static void AckProcModuleTask(void *pArg) | static void AckProcModuleTask(void *pArg) | ||||
{ | { | ||||
@@ -76,9 +76,7 @@ RESUIL linkCheckModuleInit(void) | |||||
* | * | ||||
* @param[in] *pArg 任务参数 | * @param[in] *pArg 任务参数 | ||||
* | * | ||||
* @return RESUIL 初始化结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
* @return 无 | |||||
*/ | */ | ||||
static void LinkCheckModuleTask(void *pArg) | static void LinkCheckModuleTask(void *pArg) | ||||
{ | { | ||||
@@ -77,9 +77,7 @@ RESUIL OperateProcModuleInit(void) | |||||
* | * | ||||
* @param[in] *pArg 任务参数 | * @param[in] *pArg 任务参数 | ||||
* | * | ||||
* @return RESUIL 初始化结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
* @return 无 | |||||
*/ | */ | ||||
static void OperateProcModuleTask(void *pArg) | static void OperateProcModuleTask(void *pArg) | ||||
{ | { | ||||
@@ -79,7 +79,19 @@ RESUIL RequestProcModuleInit(void) | |||||
RESUIL AddrIsTure(uint8_t *data, uint8_t dataLenght, ACK_FRAME *ackFrame) | |||||
/** | |||||
* @brief 判断地址是否合法 | |||||
* @details | |||||
* | |||||
* @param[in] *data 地址起始字节 | |||||
* @param[in] *dataLenght 地址长度 | |||||
* @param[out] *ackFrame 异常码输出 | |||||
* | |||||
* @return RESUIL 检测结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
*/ | |||||
static RESUIL AddrIsTure(uint8_t *data, uint8_t dataLenght, ACK_FRAME *ackFrame) | |||||
{ | { | ||||
uint32_t addr; | uint32_t addr; | ||||
if (dataLenght == 2) | if (dataLenght == 2) | ||||
@@ -114,6 +126,20 @@ RESUIL AddrIsTure(uint8_t *data, uint8_t dataLenght, ACK_FRAME *ackFrame) | |||||
return MODBUS_FALSE; | return MODBUS_FALSE; | ||||
} | } | ||||
/** | |||||
* @brief 判断数据长度是否合法 | |||||
* @details | |||||
* | |||||
* @param[in] *countLenght 计算的数据长度 | |||||
* @param[in] *buffLenght 接收到的数据长度 | |||||
* @param[out] *ackFrame 异常码输出 | |||||
* | |||||
* @return RESUIL 检测结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
*/ | |||||
RESUIL DataLenghtIsTure(uint16_t countLenght, uint16_t buffLenght, ACK_FRAME *ackFrame) | RESUIL DataLenghtIsTure(uint16_t countLenght, uint16_t buffLenght, ACK_FRAME *ackFrame) | ||||
{ | { | ||||
if (countLenght != buffLenght) | if (countLenght != buffLenght) | ||||
@@ -128,6 +154,18 @@ RESUIL DataLenghtIsTure(uint16_t countLenght, uint16_t buffLenght, ACK_FRAME *ac | |||||
} | } | ||||
} | } | ||||
/** | |||||
* @brief 判断数据长度是否为零 | |||||
* @details | |||||
* | |||||
* @param[in] *data 数据帧数据长度起始地址 | |||||
* @param[out] *ackFrame 异常码输出 | |||||
* | |||||
* @return RESUIL 检测结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
*/ | |||||
RESUIL DataCountIsZero(uint8_t *data, ACK_FRAME *ackFrame) | RESUIL DataCountIsZero(uint8_t *data, ACK_FRAME *ackFrame) | ||||
{ | { | ||||
if (((data[0] << 8) | data[1]) == 0) | if (((data[0] << 8) | data[1]) == 0) | ||||
@@ -149,9 +187,7 @@ RESUIL DataCountIsZero(uint8_t *data, ACK_FRAME *ackFrame) | |||||
* | * | ||||
* @param[in] *pArg 任务参数 | * @param[in] *pArg 任务参数 | ||||
* | * | ||||
* @return RESUIL 初始化结果 | |||||
* @retval MODBUS_TURE 成功 | |||||
* @retval MODBUS_FALSE 失败 | |||||
* @return 无 | |||||
*/ | */ | ||||
static void RequestProcModuleTask(void *pArg) | static void RequestProcModuleTask(void *pArg) | ||||
{ | { | ||||
@@ -21,7 +21,7 @@ void _sys_exit(int x) | |||||
//重定义fputc函数 | //重定义fputc函数 | ||||
int fputc(int ch, FILE *f) | int fputc(int ch, FILE *f) | ||||
{ | { | ||||
while((USART1->SR&0X40)==0);//循环发送,直到发送完毕 | |||||
while((USART1->SR&0X80)==0);//循环发送,直到发送完毕 | |||||
USART1->DR = (u8) ch; | USART1->DR = (u8) ch; | ||||
return ch; | return ch; | ||||
} | } | ||||