Browse Source

v1.1 485轮询测试ok

master
zhangsan 5 years ago
parent
commit
bb87816a05
  1. BIN
      si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym
  2. BIN
      si4/soft_gsm_main.si4project/soft_gsm_main.sip_xm
  3. BIN
      si4/soft_gsm_main.si4project/soft_gsm_main.siwork
  4. 2
      source/app/app_common.c
  5. 4
      source/app/app_common.h
  6. 7
      source/app/app_task_485.c
  7. 8
      source/app/app_task_485_control.c
  8. 2
      source/app/app_task_485_control.h
  9. 5
      source/app/main.c
  10. 6
      source/ctask/task.h
  11. 17
      source/ctask/tick.c
  12. 5
      source/ctask/tick.h
  13. 58
      source/msp/UART2.c
  14. 12
      source/msp/time.c
  15. 2
      source/tpc/tpc_modbus.c

BIN
si4/soft_gsm_main.si4project/soft_gsm_main.sip_sym

Binary file not shown.

BIN
si4/soft_gsm_main.si4project/soft_gsm_main.sip_xm

Binary file not shown.

BIN
si4/soft_gsm_main.si4project/soft_gsm_main.siwork

Binary file not shown.

2
source/app/app_common.c

@ -63,6 +63,8 @@ void Lu_register_init()
G.slaver_info[4].bytes = 2;
G.slaver_info[4].buf = (U8*)&G.rfid;
G.slaver_info[4].mask = 0;
G.modbusstmp = 0;
#if 0
for(i = 0; i < PAPER_BOX_NUM; i++)
{

4
source/app/app_common.h

@ -162,11 +162,13 @@ typedef struct
typedef struct printer_maintenance_global
{
U16 reserved;
U32 total_weight;
S32 total_weight;
U16 rfid;
MD_SLAVER_INFO slaver_info[MD_SLAVER_INFO_MAX];
vU32 modbusstmp;
#if 1
TS_PaperCalib paperCalibs[PAPER_BOX_NUM];
U16 currentSensorVal[PAPER_BOX_NUM]; //当前纸张传感输出

7
source/app/app_task_485.c

@ -47,11 +47,11 @@ void L3_task_485_handle(TS_485 *s)
//L0_uart2_uc(s->pkglen);
//Lc_delay_ms(70);
L0_uart2_sendArray((U8*)&s->loopPkg,s->pkglen);
s->sendStamp = s_nos_tick.t_50ms;
s->sendStamp = s_nos_tick.t_5ms;
L2_task_go(D_task_485_wait_modbus_ack);
TTSS_Task_step(D_task_485_wait_modbus_ack)
if(s_nos_tick.t_50ms - s->sendStamp >= 2)
if(s_nos_tick.t_5ms - s->sendStamp >= 20)
{
if(s_uart2_rec.ok)
{
@ -63,7 +63,8 @@ void L3_task_485_handle(TS_485 *s)
if(s->pAckPkg->salver == G.slaver_info[0].slaver && s->pAckPkg->oper == MODBUS_OPER_READ)
{
G.total_weight =
s->pAckPkg->buf[1] >> 24 | s->pAckPkg->buf[2] >> 16 | s->pAckPkg->buf[3] >> 8 | s->pAckPkg->buf[4];
(S32)(s->pAckPkg->buf[1]) << 24 | (S32)(s->pAckPkg->buf[2]) << 16 | (S32)(s->pAckPkg->buf[3]) << 8
| (S32)(s->pAckPkg->buf[4]);
}
}
}

8
source/app/app_task_485_control.c

@ -24,6 +24,12 @@ void L3_task_485_control_handle(TS_485_control *s)
L2_task_go(D_task_485_control_01);
TTSS_Task_step(D_task_485_control_01)
//L0_uart0_ulhex(s->total_weight_pool);
//Lc_delay_ms(70);// 2000--7s
//L0_uart0_uc(' ');L0_uart0_uc(' ');L0_uart0_uc(' ');
//Lc_delay_ms(70);// 2000--7s
//L0_uart0_0d0a();
//L0_uart0_ulhex(G.total_weight);
if(s->total_weight_pool != G.total_weight)
{
G.slaver_info[1].mask = 1;
@ -35,7 +41,7 @@ void L3_task_485_control_handle(TS_485_control *s)
{
G.slaver_info[2].mask = 1;
//G.slaver_info[4].mask = 1;
s->total_weight_pool = G.total_weight;
s->rfid_pool = G.rfid;
}
L2_task_go(D_task_485_control_01);

2
source/app/app_task_485_control.h

@ -9,7 +9,7 @@ typedef struct
{
TS_task task;
S32 total_weight_pool;
S32 rfid_pool;
U16 rfid_pool;
}TS_485_control;
extern TS_485_control ts_485_control;

5
source/app/main.c

@ -118,6 +118,7 @@ void main(void)
//-----------------------------------------------
//系统主循环
//-----------------------------------------------
while(9)
{
if(1 == s_nos_tick.t1s_heatbeart)
@ -125,6 +126,10 @@ void main(void)
s_nos_tick.t1s_heatbeart = 0;
//L0_uart0_uc('.');
L0_uart0_sendArray("abcdefg", 7);
D_P03_REV();
D_P04_REV();
D_P05_REV();
D_P06_REV();
}
//串口3 RFID接收
L3_UARTcom3_exp_protocol(&s_uart3_rec);

6
source/ctask/task.h

@ -68,7 +68,7 @@ typedef struct _ts_task
/// Delay_cycle适用于 时间短的,其一次循环取决于主循环的时间,和Tdelay比,Cdelay长时间计时误差大
#define L2_task_switch_default_idelay(); \
case D_task_Tdelay:\
if (s_nos_tick.t_50ms >= s->task.n)\
if (s_nos_tick.t_5ms >= s->task.n)\
{\
L2_task_delay_over();\
}\
@ -172,7 +172,7 @@ typedef struct _ts_task
//>>L2_task_delay一定要放在L2_task_go之后
#define L1_task_Tdelay(delay_n) s->task.sh_next = s->task.sh;\
s->task.sh = D_task_Tdelay;\
s->task.n = delay_n + s_nos_tick.t_50ms;
s->task.n = delay_n + s_nos_tick.t_5ms;
//>>L2_task_delay一定要放在L2_task_go之后
@ -223,7 +223,7 @@ extern void L1_task_init(TS_task *s);
{ \
s->task.sh_next = next;\
s->task.sh = D_task_Tdelay;\
s->task.n = (delay_n) + s_nos_tick.t_50ms; \
s->task.n = (delay_n) + s_nos_tick.t_5ms; \
} \
else \
{ \

17
source/ctask/tick.c

@ -30,12 +30,12 @@ void L1_tick_init(void)
s_nos_tick.t1s_heatbeart= 0;
s_nos_tick.flag_50ms = 0;
s_nos_tick.t_50ms = 0;
s_nos_tick.t_5ms = 0;
//s_nos_tick.t_50ms = 0;
s_nos_tick.t_100ms = 0;
s_nos_tick.t_1s = 0;
s_nos_tick.flag_1s = 0;
s_nos_tick.t_n = 0;
}
#if 0
@ -71,14 +71,15 @@ void L1_tick_tick (void)
void L1_tick_tick (void)
{
/// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms
///锟洁当锟斤拷1.39锟斤拷锟絫_10ms 锟斤拷锟斤拷锟斤拷锟斤拷诘锟截癸拷锟斤拷锟较低筹拷锟斤拷锟?锟斤拷全锟斤拷锟斤拷锟斤拷锟斤拷
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000锟斤拷/锟斤拷
///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
s_nos_tick.tp_count++;
s_nos_tick.t_50ms ++;//D_led_D1_REV(); 20160522 锟斤拷证
if(s_nos_tick.t_50ms % D_TIMER0_1S_COUNT == 0)
//s_nos_tick.t_50ms ++;//D_led_D1_REV(); 20160522验证
s_nos_tick.t_5ms ++;
if(s_nos_tick.t_5ms % D_TIMER0_1S_COUNT == 0)
{
// 65535*65535/24/60/60/356/10 =12.7锟斤拷
s_nos_tick.t_1s ++;//// 65535*65535/24/60/60/356/10 =12.7锟斤拷
// 65535*65535/24/60/60/356/10 =12.7
s_nos_tick.t_1s ++;
s_nos_tick.flag_1s2 = 1;
s_nos_tick.t1s_heatbeart = 1;
}

5
source/ctask/tick.h

@ -20,8 +20,9 @@ struct _s_nos_tick_
vU8 flag_50ms;
vU32 sys_clock;
vU32 t_n; // noos系统定时器最小技术单元
vU32 t_50ms; // noos 系统定时器10m技术
//vU32 t_50ms; // noos 系统定时器10m技术
vU32 t_100ms;
vU32 t_5ms;
vU32 t_1s;
vU8 flag_1s;
vU8 flag_1s2;
@ -55,7 +56,7 @@ extern struct _s_nos_tick_ s_nos_tick;
#define D_Tdelay_10min (D_Tdelay_1s*60 * 10)
#define D_Tdelay_1h (D_Tdelay_1min*60)
#define D_Tdelay_1day (D_Tdelay_1h*24)
#define D_TIMER0_1S_COUNT 20
#define D_TIMER0_1S_COUNT 200
//#define D_10mS 1//D_TIMER0_10MS_COUNT
//#define D_100mS (D_10mS*10)
//#define D_1S (D_10mS*100)

58
source/msp/UART2.c

@ -56,6 +56,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面
********************************************************************************/
#include "uart2.h"
#include "../bsp/bsp_485.h"
#include "../app/app_common.h"
struct _s_uart2_send_buf_ s_uart2_send_shop;
struct _s_uart2_send_buf_ s_uart2_send_depot;
@ -165,6 +166,7 @@ void INTERRUPT_uart2(void) D_SERVE_uart2// using 2
/// output: 对应的结构体变量中携带 缓存buf和协议ok的标志
//s_uart2_rec.reg = L0_uart2_get();
//s_uart2_rec.ok = 1;
G.modbusstmp = s_nos_tick.t_5ms;
(*Lp0_uart2_fun)(L0_uart2_get());
//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
@ -194,44 +196,40 @@ void INTERRUPT_uart2(void) D_SERVE_uart2// using 2
D_uart2_ES_INT_OPEN();
}
#if 0
void timer0_isrHanddle (void) interrupt 1
{
NOP();
TF0 = 0;
void L0_uart2_0d0a(void)
//modbus协议处理
if(s_uart2_rec.head == 1 && G.modbusstmp - s_nos_tick.t_5ms >= 1) //收到一条协议
{
s_uart2_send_depot.max = 2;
s_uart2_send_depot.buf[0] = 0x0d;
s_uart2_send_depot.buf[1] = 0x0a;
s_uart2_send_depot.p = s_uart2_send_depot.buf;
L0_uart2_sendbuf();
}
// L0_uart2_uc(cguHex2Char[D_uc_low(s->sec)][0]);
void L0_uart2_uchex(U8 ww)
s_uart2_rec.head = 0;
crc16_irq(s_uart2_rec.crc,s_uart2_rec.buf,s_uart2_rec.num - 2);
if(s_uart2_rec.crc[0] == s_uart2_rec.buf[s_uart2_rec.num-2] && s_uart2_rec.crc[1] == s_uart2_rec.buf[s_uart2_rec.num-1])
{
s_uart2_send_depot.max = 2;
s_uart2_send_depot.buf[0] = cguHex2Char[D_uc_low(ww)][1];
s_uart2_send_depot.buf[1] = cguHex2Char[D_uc_high(ww)][1];
s_uart2_send_depot.p = s_uart2_send_depot.buf;
L0_uart2_sendbuf();
}
void L0_uart2_ulhex(vU32 ww)
if(s_uart2_rec.ok == 0)
{
U_U32 ultemp;
ultemp.dWord = ww;
L0_uart2_uchex(ultemp.BYTE4.byte0);
L0_uart2_uchex(ultemp.BYTE4.byte1);
L0_uart2_uchex(ultemp.BYTE4.byte2);
L0_uart2_uchex(ultemp.BYTE4.byte3);
s_uart2_rec.ok = 1;
}
//D_P32_REV();
}
void L0_uart2_sendstr(U8 *str)
{
//L0_uart2_sendbuf(str,strlen(str));
s_uart2_send_depot.max = strlen(str);
s_uart2_send_depot.p = str;
L0_uart2_sendbuf();
}
//tick处理
#if 0
/// 65535*65535 /3600/24/365=139nian/s=1.39nian/10ms
///相当于1.39年后t_10ms 溢出,对于电池供电的系统而言 完全可以满足
// 4,294,836,225 = 65535*65535 ;3600*24*60*60 = 31,536,000秒/年
s_nos_tick.t_10ms ++;//D_led_D1_REV(); 20160522 验证
#else
L1_tick_tick(); ///系统中的1sflag 和以10ms为颗粒的延时使用 为tdelay服务
#endif
NOP();
}

12
source/msp/time.c

@ -5,17 +5,26 @@
/*************************初始化定时器0*****************************/
void L0_timer0_Init(void) //50毫秒@11.0592MHz
{
#if 0 //50ms@11.0592MHz
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初值
TH0 = 0x4C; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
#else //5ms@11.0592MHz
AUXR &= 0x7F; //定时器时钟12T模式
TMOD &= 0xF0; //设置定时器模式
TL0 = 0x00; //设置定时初值
TH0 = 0xEE; //设置定时初值
TF0 = 0; //清除TF0标志
TR0 = 1; //定时器0开始计时
#endif
ET0 = 1; //add by cc
}
/********************** Timer0中断函数************************/
#if 0 //该函数移入uart2.c
void timer0 (void) interrupt 1
{
NOP(); NOP(); NOP();
@ -24,6 +33,7 @@ void timer0 (void) interrupt 1
/// BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0);
NOP(); NOP(); NOP();
}
#endif
/******************************END*********************************/

2
source/tpc/tpc_modbus.c

@ -81,7 +81,7 @@ U8 L3_pack_modbus_10(TS_PH4_modbus *pmodbus ,U8 slaverId, U16 reg, U16 num, U8 b
}
crc16(pmodbus->crc,&pmodbus->salver,2 + bufsize + bytes);
pmodbus->buf[bufsize + bytes] = pmodbus->crc[0];
pmodbus->buf[bufsize + bytes] = pmodbus->crc[1];
pmodbus->buf[bufsize + bytes + 1] = pmodbus->crc[1];
return bufsize + bytes + 2 + 2;
}

Loading…
Cancel
Save