diff --git a/.vscode/settings.json b/.vscode/settings.json index 1d72d42..4e8548f 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -6,6 +6,17 @@ "asp_oid.h": "c", "msp_uart2.h": "c", "task_w600.h": "c", - "UART2.C": "cpp" + "UART2.C": "cpp", + "main.h": "c", + "msp_uart0.h": "c", + "UART4.C": "cpp", + "w600.h": "c", + "bsp_config.h": "c", + "rs485.h": "c", + "chipid.h": "c", + "eeprom.h": "c", + "uart2.h": "c", + "clib.h": "c", + "uart0.h": "c" } } \ No newline at end of file diff --git a/source/app/app_task_speech.c b/source/app/app_task_speech.c index 074e9a9..ac9b910 100644 --- a/source/app/app_task_speech.c +++ b/source/app/app_task_speech.c @@ -1,130 +1,131 @@ -#include "app_task_speech.h" -#include "app_task_tcp.h" -#include "../msp/msp_uart3.h" -#include "../msp/msp_uart0.h" - - - -#define START_CODE 0x7E -#define END_CODE 0xEF - - -TS_TASK_SPEECH ts_speech; - - -void L3_task_speech_init(void) -{ - //U8 music[6] = {0x7E,0x04,0xAE,0x1E,0x30,0xEF}; - //L0_uart0_sendArray((U8 *)&open,9); - //U8 code open[9] = {0x7E,0x07,0xA3,0x43,0x30,0x30,0x39,0x86,0xEF}; - //L0_uart3_sendArray((U8 *)&open , 9); - L1_task_init(&ts_speech.task); - L3_task_s_go(ts_speech,D_task_init); -} - -#define D_task_wait_tcp_order 0x61 -#define D_task_speech_send 0x62 - -void L3_task_speech_handle(TS_TASK_SPEECH *s) -{ - TTSS_Task_init() - L2_task_go(D_task_wait_tcp_order); - TTSS_Task_step(D_task_wait_tcp_order) - if(s_uart2_tcp_rec.ok && (ts_tcp.slaverIndex != 0)) - //if(s_uart2_tcp_rec.ok) - { - s_uart2_tcp_rec.ok = 0; - s->pkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); - if(s->pkg->slaver == SERVER_ID) - { - L3_ccmodbus_slaver_ack(s->pkg,s->ack); - s->ccmd_speech_info[0].start = START_CODE; - s->ccmd_speech_info[0].num = 0x07; - s->ccmd_speech_info[0].oper = SPEECH_NAME_PLAY; - s->ccmd_speech_info[0].title = 0x43; - //ts_speech.ccmd_speech_info[0].buf = (U8*)&R.spee_order; - s->ccmd_speech_info[0].end = END_CODE; - //Lc_buf_copy_uc((U8 *)&s->ccmd_speech_info[0].buf,(U8 *)&R.spee_order,(U16)2); - //L0_uart0_sendArray((U8 *)&R.spee_order,2); //00 04 - s->slaverIndex = 0; - s->pkglen = L3_pack_speech(&s->speech_pkg , &s->ccmd_speech_info + s->slaverIndex); - L2_task_go(D_task_speech_send); - } - } - else - { - L2_task_go(D_task_wait_tcp_order); - } - TTSS_Task_step(D_task_speech_send) - { - L0_uart3_sendArray((U8 *)&s->speech_pkg, s->pkglen); - //L0_uart0_sendArray((U8*)&s->speech_pkg,s->pkglen); - } - L2_task_go(D_task_wait_tcp_order); - TTSS_Task_end(); -} - -U8 ascTable[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; - -U8 *hexBytes2AsciiBytes(U8 asciiBytes[],U8 hexBytes[],U8 hexBytesLen) -{ - U8 i = 0; - for(i=0;i> 4 & 0x0F]; - asciiBytes[i*2 + 1] = ascTable[hexBytes[i] >> 0 & 0x0F]; - - } - return asciiBytes; -} - - U8 Fun_SC_Check(U8 *p1, unsigned short int len) -{ - U8 sum = 0; - for(;len > 0; len--) - { - sum += *p1++; - } - - return sum; -} - - - -U8 L3_pack_speech_A3(TS_SPEECH *pspeech , U8 start ,U8 num ,U8 title ,U8 end)//tcp传来的buf -{ - int name; - U8 tcp_buf[6]; - U8 str_buf[6]; - U8 bufsize = 9; - pspeech->start = start; - pspeech->num = num; - pspeech->oper = SPEECH_NAME_PLAY; - pspeech->title = title; - Lc_buf_copy_uc((U8 *)&tcp_buf,(U8 *)&R.spee_order,(U16)2); - hexBytes2AsciiBytes(str_buf,tcp_buf,2); - name = getIndexOfSigns(str_buf[2])*16+getIndexOfSigns(str_buf[3])*1; - pspeech->buf[0] = (U8)(name/100) ; - pspeech->buf[1] = (U8)((name%100)/10); - pspeech->buf[2] = (U8)(name%10); - //L0_uart0_sendArray((U8*)&tcp_buf,3); - Lc_hex2ascii((U8 *)&pspeech->buf,(U8 *)&pspeech->buf,3); - pspeech->crc = Fun_SC_Check(&pspeech->num,6); //累加和校验 - pspeech->end = end; - return bufsize; -} - -U8 L3_pack_speech(TS_SPEECH *pspeech, CCMD_SPEECH_INFO *speech_info) +#include "app_task_speech.h" +#include "app_task_tcp.h" +#include "../msp/uart3.h" +#include "../msp/uart2.h" +#include "../msp/uart0.h" + + + +#define START_CODE 0x7E +#define END_CODE 0xEF + + +TS_TASK_SPEECH ts_speech; + + +void L3_task_speech_init(void) { - U16 pkglen = 0; - switch(speech_info->oper) + //U8 music[6] = {0x7E,0x04,0xAE,0x1E,0x30,0xEF}; + //L0_uart0_sendArray((U8 *)&open,9); + //U8 code open[9] = {0x7E,0x07,0xA3,0x43,0x30,0x30,0x39,0x86,0xEF}; + //L0_uart3_sendArray((U8 *)&open , 9); + L1_task_init(&ts_speech.task); + L3_task_s_go(ts_speech,D_task_init); +} + +#define D_task_wait_tcp_order 0x61 +#define D_task_speech_send 0x62 + +void L3_task_speech_handle(TS_TASK_SPEECH *s) +{ + TTSS_Task_init() + L2_task_go(D_task_wait_tcp_order); + TTSS_Task_step(D_task_wait_tcp_order) +// if(s_uart2_tcp_rec.ok && (ts_tcp.slaverIndex != 0)) + //if(s_uart2_tcp_rec.ok) + { +// s_uart2_tcp_rec.ok = 0; +// s->pkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); + if(s->pkg->slaver == SERVER_ID) + { + L3_ccmodbus_slaver_ack(s->pkg,s->ack); + s->ccmd_speech_info[0].start = START_CODE; + s->ccmd_speech_info[0].num = 0x07; + s->ccmd_speech_info[0].oper = SPEECH_NAME_PLAY; + s->ccmd_speech_info[0].title = 0x43; + //ts_speech.ccmd_speech_info[0].buf = (U8*)&R.spee_order; + s->ccmd_speech_info[0].end = END_CODE; + //Lc_buf_copy_uc((U8 *)&s->ccmd_speech_info[0].buf,(U8 *)&R.spee_order,(U16)2); + //L0_uart0_sendArray((U8 *)&R.spee_order,2); //00 04 + s->slaverIndex = 0; + s->pkglen = L3_pack_speech(&s->speech_pkg , &s->ccmd_speech_info + s->slaverIndex); + L2_task_go(D_task_speech_send); + } + } + { + L2_task_go(D_task_wait_tcp_order); + } + TTSS_Task_step(D_task_speech_send) + { + L0_uart3_sendArray((U8 *)&s->speech_pkg, s->pkglen); + //L0_uart0_sendArray((U8*)&s->speech_pkg,s->pkglen); + } + L2_task_go(D_task_wait_tcp_order); + TTSS_Task_end(); +} + +U8 ascTable[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + +U8 *hexBytes2AsciiBytes(U8 asciiBytes[],U8 hexBytes[],U8 hexBytesLen) +{ + U8 i = 0; + for(i=0;i> 4 & 0x0F]; + asciiBytes[i*2 + 1] = ascTable[hexBytes[i] >> 0 & 0x0F]; + + } + return asciiBytes; +} + + U8 Fun_SC_Check(U8 *p1, unsigned short int len) +{ + U8 sum = 0; + for(;len > 0; len--) + { + sum += *p1++; + } + + return sum; +} + + + +U8 L3_pack_speech_A3(TS_SPEECH *pspeech , U8 start ,U8 num ,U8 title ,U8 end)//tcp传来的buf +{ + int name; + U8 tcp_buf[6]; + U8 str_buf[6]; + U8 bufsize = 9; + pspeech->start = start; + pspeech->num = num; + pspeech->oper = SPEECH_NAME_PLAY; + pspeech->title = title; + Lc_buf_copy_uc((U8 *)&tcp_buf,(U8 *)&R.spee_order,(U16)2); + hexBytes2AsciiBytes(str_buf,tcp_buf,2); + name = getIndexOfSigns(str_buf[2])*16+getIndexOfSigns(str_buf[3])*1; + pspeech->buf[0] = (U8)(name/100) ; + pspeech->buf[1] = (U8)((name%100)/10); + pspeech->buf[2] = (U8)(name%10); + //L0_uart0_sendArray((U8*)&tcp_buf,3); + Lc_hex2ascii((U8 *)&pspeech->buf,(U8 *)&pspeech->buf,3); + pspeech->crc = Fun_SC_Check(&pspeech->num,6); //累加和校验 + pspeech->end = end; + return bufsize; +} + +U8 L3_pack_speech(TS_SPEECH *pspeech, CCMD_SPEECH_INFO +*speech_info) +{ + U16 pkglen = 0; + switch(speech_info->oper) { - case SPEECH_NAME_PLAY: - pkglen = L3_pack_speech_A3(pspeech,speech_info->start,speech_info->num,speech_info->title,speech_info->end); - break; - default: - break; - } - return pkglen; -} - + case SPEECH_NAME_PLAY: + pkglen = L3_pack_speech_A3(pspeech,speech_info->start,speech_info->num,speech_info->title,speech_info->end); + break; + default: + break; + } + return pkglen; +} + diff --git a/source/app/app_task_tcp.c b/source/app/app_task_tcp.c index 9244831..169a171 100644 --- a/source/app/app_task_tcp.c +++ b/source/app/app_task_tcp.c @@ -1,6 +1,6 @@ #include "app_task_tcp.h" -#include "../msp/msp_uart0.h" -#include "../msp/msp_uart2.h" +#include "../msp/uart0.h" +#include "../msp/uart2.h" #include "../app/task_w600.h" #include "../app/app_config.h" @@ -54,11 +54,11 @@ void L3_task_tcp_handle(TS_tcp *s) switch(s->slaverIndex) { case 0: - if(s_uart2_tcp_rec.ok) +// if(s_uart2_tcp_rec.ok) { - s_uart2_tcp_rec.ok = 0; +// s_uart2_tcp_rec.ok = 0; s_task_gm35_flow.tcp_last_recv_stmp = s_nos_tick.t_1s; - s->pAckPkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); +// s->pAckPkg = (TS_PH3_ccmodbus*)(s_uart2_tcp_rec.sp); //L3_gm35_rcv_data((U8*)s->pAckPkg,s->pAckPkg->num); if(s->pAckPkg->slaver == G.ccmd_slaver_info[s->slaverIndex].slaver) { @@ -82,7 +82,7 @@ void L3_task_tcp_handle(TS_tcp *s) L2_task_go(D_task_tcp_switch_next_slaver); } //#if 0 - else if(s_nos_tick.t_1s - s->sendStamp >= 5) //重发 + if(s_nos_tick.t_1s - s->sendStamp >= 5) //重发 { if(++s->retryTimes < 3) { diff --git a/source/app/main.c b/source/app/main.c index 3844e4b..51a9a95 100644 --- a/source/app/main.c +++ b/source/app/main.c @@ -109,9 +109,9 @@ void L0_main_init(void) //w600任务初始化 // L3_task_gm35_flow_init(W600_ST); //按键任务初始化 - L0_key_init(); + // L0_key_init(); //笔头任务初始化 - L1_oid_init(); + // L1_oid_init(); //语音模块初始化 // L3_task_speech_init(); //tcp轮询任务初始化 @@ -134,9 +134,11 @@ void main(void) L0_id_get_rom(G.mcu_id); //打印版本信息 L0_uart0_sendArray("v1.0",4); - + L0_uart0_sendstr("KEY1-TEST"); + + Lc_delay_ms(3000); L0_uart3_sendArray((U8 *)&open , 9); // L0_uart3_sendArray((U8 *)&buletooth , 7); @@ -155,7 +157,6 @@ void main(void) #endif while(1) { - L1_Oid_readoid(); @@ -166,15 +167,15 @@ void main(void) D_print_heartbeat() {///这个地方可以放置心跳的打印信息 ///如果其他的打印存在,并且关闭了这个打印的话,这个打印会临时被关闭,下一次打开 - // L0_uart0_uc('.'); + L0_uart0_uc('.'); // L0_uart2_sendArray((U8 *)&buletooth , 7); } } - if(L3_tick_interval(100L))/////10ms - {L2_tick_stamp(); - D_print_heartbeat_close(); + // if(L3_tick_interval(100L))/////10ms + // {L2_tick_stamp(); + // D_print_heartbeat_close(); /// L1_as_readA(0);//读取倾角传感器数据 /// Lc_buf_copy_uc(s_uart1_rec.buf,s_as[0].d,8); @@ -209,7 +210,7 @@ void main(void) #endif //笔头数据采集 - //L3_task_oid_handle(&ts_task_oid); + L3_task_oid_handle(&ts_task_oid); //WIFI // L3_uart2_exp_protocol(&s_uart2_at); @@ -223,7 +224,7 @@ void main(void) //语音模块 - // L3_task_speech_handle(&ts_speech); + L3_task_speech_handle(&ts_speech); //按键处理 @@ -238,7 +239,6 @@ void main(void) // L3_task_tcp_control_handle(&ts_tcp_control); #endif } -} //end main diff --git a/source/app/main.h b/source/app/main.h index 5a54ca1..c6b704e 100644 --- a/source/app/main.h +++ b/source/app/main.h @@ -37,9 +37,14 @@ #ifndef _MAIN_H #define _MAIN_H -#include "../msp/msp_uart0.h" -#include "../msp/msp_uart2.h" -#include "../msp/msp_uart3.h" +//#include "../msp/msp_uart0.h" +//#include "../msp/msp_uart2.h" +//#include "../msp/msp_uart3.h" + +#include "../msp/uart0.h" +#include "../msp/uart2.h" +#include "../msp/uart3.h" +#include "../msp/uart4.h" #include "../msp/eeprom.h" diff --git a/source/app/task_key.h b/source/app/task_key.h index 3782c09..0f011a5 100644 --- a/source/app/task_key.h +++ b/source/app/task_key.h @@ -14,8 +14,8 @@ #define _app_task_key_H #include "../bsp/bsp_config.h" #include "../ctask/task.h" -#include "../msp/msp_uart0.h" -#include "../msp/msp_uart3.h" +//#include "../msp/msp_uart0.h" +//#include "../msp/msp_uart3.h" #include "../app/task_w600.h" #include "../clib/type.h" struct _s_task_key_ diff --git a/source/app/task_register.c b/source/app/task_register.c index 7abb600..1499c64 100644 --- a/source/app/task_register.c +++ b/source/app/task_register.c @@ -13,7 +13,7 @@ #include "task_register.h" #include "../app/app_config.h" #include "../bsp/bsp_config.h" -#include "../msp/msp_uart0.h" +#include "../msp/uart0.h" #include "task_w600.h" //============================================= diff --git a/source/app/task_w600.c b/source/app/task_w600.c index 4269361..8f67708 100644 --- a/source/app/task_w600.c +++ b/source/app/task_w600.c @@ -13,8 +13,8 @@ #include "task_w600.h" #include "app_config.h" -#include "../msp/msp_uart2.h" -#include "../msp/msp_uart0.h" +//#include "../msp/msp_uart2.h" +//#include "../msp/msp_uart0.h" #include "../asp/asp_oid.h" struct _s_task_gm35_gprs_ s_task_gm35_flow; @@ -39,7 +39,7 @@ U8 * _cipsend_hex(U8 len) void L3_gm35_send_str(U8 *str) { - L0_uart2_sendstr(str); + // L0_uart2_sendstr(str); if(G.debug) { L0_uart0_sendstr(str); @@ -50,7 +50,7 @@ void L3_gm35_send_str(U8 *str) void L3_gm35_send_data(U8 *buf , U16 len) { //L3_gm35_send_str(_cipsend_hex(len)); - L0_uart2_sendArray(buf,len); +// L0_uart2_sendArray(buf,len); if(G.debug) { L0_uart0_sendArray(buf,len); diff --git a/source/asp/asp_oid.h b/source/asp/asp_oid.h index 54043bc..2649790 100644 --- a/source/asp/asp_oid.h +++ b/source/asp/asp_oid.h @@ -7,7 +7,8 @@ #include "../bsp/bsp_oid.h" -#include "msp_uart0.h" +//#include "msp_uart0.h" +#include "uart0.h" #include "../ctask/task.h" #include "../app/app_config.h" diff --git a/source/bsp/bsp_config.h b/source/bsp/bsp_config.h index 1572bde..50059dd 100644 --- a/source/bsp/bsp_config.h +++ b/source/bsp/bsp_config.h @@ -269,7 +269,7 @@ #define D_Cdelay_200us 20 #define D_Cdelay_1us 1 ////while p21翻转时测定 500k 2us 一个指令 #define L0_delay_1us() Lc_delay_nop(0) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us -#define L0_delay_10us() Lc_delay_nop(4) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us +// #define L0_delay_10us() Lc_delay_nop(4) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us #define L0_delay_40us() Lc_delay_nop(18) // 5个nop() 100ns 50个nop() 1us (20)=10us (2)1.5us //xx #endif//D_sys_MainFre) @@ -304,7 +304,7 @@ L1_tick_tick #endif //STEP 5 <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< #include "../ctask/task.h" #include "../ctask/tick.h" diff --git a/source/bsp/chipid.h b/source/bsp/chipid.h index ca448c3..3effe82 100644 --- a/source/bsp/chipid.h +++ b/source/bsp/chipid.h @@ -26,7 +26,8 @@ ///>>>端口位定义,可修改!!!!!!>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> #include "../bsp/bsp_config.h" -#include "../msp/msp_uart0.h" +//#include "../msp/msp_uart0.h" +#include "../msp/uart0.h" extern void L0_id_get(U8 *id); extern void L0_id_get_rom(U8 *id); diff --git a/source/bsp/rs485.h b/source/bsp/rs485.h index 3383d38..291f19b 100644 --- a/source/bsp/rs485.h +++ b/source/bsp/rs485.h @@ -2,7 +2,8 @@ #define BSP_485_H #include "../bsp/bsp_config.h" -#include "../msp/msp_uart0.h" +//#include "../msp/msp_uart0.h" +#include "../msp/uart0.h" //485_RE P33 //485_DE P32 diff --git a/source/clib/clib.c b/source/clib/clib.c index bd2ed3d..8e7de00 100644 --- a/source/clib/clib.c +++ b/source/clib/clib.c @@ -12,7 +12,7 @@ #include "type.h" #include "clib.h" -#include "../msp/msp_uart0.h" +#include "../msp/uart0.h" #include "../msp/time.h" diff --git a/source/ctask/task.h b/source/ctask/task.h index 0b9f100..f322066 100644 --- a/source/ctask/task.h +++ b/source/ctask/task.h @@ -20,7 +20,7 @@ #ifndef _TASK_H_ #define _TASK_H_ #include "../clib/type.h" -#include "../msp/time.h" +#include "../ctask/time.h" #include "task.h" #include "tick.h" diff --git a/source/ctask/tick.h b/source/ctask/tick.h index e37e9c8..532b0bc 100644 --- a/source/ctask/tick.h +++ b/source/ctask/tick.h @@ -11,7 +11,7 @@ #ifndef __tick_H #define __tick_H #include "../clib/Type.h" -#include "../msp/time.h" +#include "../ctask/time.h" struct _s_nos_tick_ { diff --git a/source/msp/time.c b/source/ctask/time.c similarity index 96% rename from source/msp/time.c rename to source/ctask/time.c index aa9b262..6fbf309 100644 --- a/source/msp/time.c +++ b/source/ctask/time.c @@ -1,4 +1,6 @@ #include "time.h" +#include "../msp/uartx.h" + #define D_TIMER_COUNT(t,clk,timeInUs) (U16)(65536 - 1.0 * (clk) / 1000 * (1.0 * timeInUs / 1000) / t) //#define D_TIMER_COUNT(t,clk,timeInUs) (U16)(65536 - (clk) / 1000 * timeInUs / 1000 / t) @@ -23,7 +25,8 @@ void L0_timer0_Init(void) /// 和 L0_timer0_Init 关联,需要配置 bsp_config.h中的 D_sys_MainFre /// 默认10ms 作为TTSS系统的定时引擎 void timer0_isrHandle (void) D_SERVE_TIMER0 -{// +{ + U8 i = 0; NOP(); NOP(); NOP(); TF0 = 0; #if 0 @@ -36,6 +39,15 @@ void timer0_isrHandle (void) D_SERVE_TIMER0 L1_tick_tick(); ///系统中的1sflag 和以10ms为颗粒的延时使用 为tdelay服务 + //串口回调 + for(i=0; i< SERIAL_MAX_NUM; i++) + { + if(ts_uart[i].tp_handler != NULL) + { + ts_uart[i].tp_handler(ts_uart[i].uartx); + } + } + #endif /// BITN_1(DR_who_wakeup, DRB_who_wakeup_timer0); NOP(); NOP(); NOP(); diff --git a/source/msp/time.h b/source/ctask/time.h similarity index 100% rename from source/msp/time.h rename to source/ctask/time.h diff --git a/source/msp/UART0.C b/source/msp/UART0.C new file mode 100644 index 0000000..a3b9ef6 --- /dev/null +++ b/source/msp/UART0.C @@ -0,0 +1,78 @@ + +#include "uart0.h" +#include "uartx.h" + + +void L0_uart0_init(void) +{ + U16 val = D_BRT_COUNT(12, D_sys_MainFre, D_uart0_BRT); + SCON = 0x50; // 8位数据,可变波特率 + AUXR &= 0xBF; //定时器时钟12T模式 + AUXR &= 0xFE; //串口1选择定时器1为波特率发生器 + TMOD &= 0x0F; //设置定时器模式 + TL1 = val; //设置定时初始值 + TH1 = val >> 8; //设置定时初始值 + ET1 = 0; //禁止定时器中断 + TR1 = 1; //定时器1开始计时 +} + +void L0_uart0_buf_init(void) +{ + //定义发送缓冲区 + ts_uart[uNum0].s.buf = ts_send_buf.s1; + ts_uart[uNum0].s.bufmax = D_send1_max; + ts_uart[uNum0].s.max = ts_uart[uNum0].s.now = 0; + ts_uart[uNum0].s.ok = D_ready; + + //定义接收缓冲区 + ts_uart[uNum0].r.buf = ts_recv_buf.r1; + ts_uart[uNum0].r.bufmax = D_recv1_max; + ts_uart[uNum0].r.head = 0; + ts_uart[uNum0].r.ok = 0; + ts_uart[uNum0].r.idle = 1; + ts_uart[uNum0].r.overtime_t = 0; + + //定义接收处理协议 + ts_uart[uNum0].tp_handler = L0_uartN_overtime_callback; + ts_uart[uNum0].uartx = uNum0; + + //串口初始化 + L0_uart0_init(); + + //打开串口中断 + D_uart0_ES_INT(1); + + //默认处于接收状态 + D_UART0_485_RX() +} + +/************************************************* +UART 中断 +*************************************************/ +void INTERRUPT_UART(void) D_SERVE_UART +{ + // NOP(); NOP(); NOP(); + if (L0_uart0_IntRI()) //如果是U0接收中断 + { + L0_uart0_IntRIClear(); //清除接收中断标志 + ts_uart[uNum0].r.reg = SBUF; //获取当前数据 + L0_uartN_s2b(uNum0); //接收数据至缓冲区 + } + if (L0_uart0_IntTI()) //如果是U0发送中断 + { + L0_uart0_IntTIClear(); //清除发送中断标志 + if (ts_uart[uNum0].s.max > ts_uart[uNum0].s.now) + { + SBUF = ts_uart[uNum0].s.p[ts_uart[uNum0].s.now]; + ts_uart[uNum0].s.now++; + } + else + { + ts_uart[uNum0].s.ok = D_ready; + ts_uart[uNum0].s.max = 0; + ts_uart[uNum0].s.now = 0; //可以发送下一个数据 + // D_UART0_485_RX() //切换到接收状态 + } + } + // NOP(); NOP(); NOP(); +} diff --git a/source/msp/msp_uart2.h b/source/msp/UART0.h similarity index 65% rename from source/msp/msp_uart2.h rename to source/msp/UART0.h index d3bb23c..890fb72 100644 --- a/source/msp/msp_uart2.h +++ b/source/msp/UART0.h @@ -43,52 +43,42 @@ uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中 void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 -------------------------------------------------------------------------------------------- msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 - L0_uart2_Init - uart2_IRQHandler + L0_UART0_Init + UART0_IRQHandler L0_Usend_uc------UserDef ----------------------------------------------------------------------------------------- ********************************************************************************/ -#ifndef _uart2_H -#define _uart2_H - +#ifndef _uart0_H +#define _uart0_H #include "../bsp/bsp_config.h" +#include "uartx.h" -#include "../tpc/at0d0a.h" -#include "../tpc/modbus.h" -#include "msp_uart_x.h" -#include "../tpc/ccmodbus.h" +//#include "../tpc/tpc_x.h" -#define uNum2 1 +#define uNum0 0 -#define D_uart2_ES_INT(x) (x) ? (BITN_1(IE2,ES2)) : (BITN_0(IE2,ES2)) -#define L0_uart2_IntRI() (S2CON & S2RI)//BITN_G(SCON,U0RI) -#define L0_uart2_IntTI() (S2CON & S2TI)//BITN_G(SCON,U0TI) -#define L0_uart2_IntRIClear(); BITN_0(S2CON,S2RI) -#define L0_uart2_IntTIClear(); BITN_0(S2CON,S2TI) -#define L0_uart2_get() (S2BUF) +#define D_uart0_ES_INT(x) ES = (x) +#define L0_uart0_IntRI() (RI)//BITN_G(SCON,U0RI) +#define L0_uart0_IntTI() (TI)//BITN_G(SCON,U0TI) +#define L0_uart0_IntRIClear(); RI = 0;//BITN_0(SCON,U0RI) +#define L0_uart0_IntTIClear(); TI = 0;//BITN_0(SCON,U0TI) //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< -void L0_uart2_buf_init(void); -void L0_uart2_sendArray(U8 * buf, U16 len); -void uart2_Handdle(void); -#define L0_uart2_uc(X) L0_uartN_uc(uNum2,X) -#define L0_uart2_us(X) L0_uartN_us(uNum2,X) -#define L0_uart2_ul(X) L0_uartN_ul(uNum2,X) -#define L0_uart2_0d0a() L0_uartN_0d0a(0) -#define L0_uart2_uchex(X) L0_uartN_uchex(uNum2,X) -#define L0_uart2_ushex(X) L0_uartN_ushex(uNum2,X) -#define L0_uart2_ulhex(X) L0_uartN_ulhex(uNum2,X) -#define L0_uart2_sendstr(buf) L0_uartN_sendstr(uNum2,buf) -//extern TP_Handler_X s_uart2_rec; -//extern TS_PH4_modbus s_uart2_ack; -extern TS_Handle_0d0a s_uart2_at; -extern TS_Handle_PH3 s_uart2_tcp_rec; -extern void (*Lp0_uart2_fun)(unsigned char sbufreg); +void L0_uart0_buf_init(void); -extern void L1_uart_tpc_config(void); +#define L0_uart0_uc(X) L0_uartN_uc(uNum0,X) +#define L0_uart0_us(X) L0_uartN_us(uNum0,X) +#define L0_uart0_ul(X) L0_uartN_ul(uNum0,X) +#define L0_uart0_0d0a() L0_uartN_0d0a(0) +#define L0_uart0_uchex(X) L0_uartN_uchex(uNum0,X) +#define L0_uart0_ushex(X) L0_uartN_ushex(uNum0,X) +#define L0_uart0_ulhex(X) L0_uartN_ulhex(uNum0,X) +#define L0_uart0_sendstr(buf) L0_uartN_sendstr(uNum0,buf) +#define L0_uart0_sendArray(buf, n) L0_uartN_sendArray(uNum0,buf,n) +#define L0_uart0_sendArrayHex(buf, n) L0_uartN_sendArrayHex(uNum0,buf,n) -#endif //#ifndef _uart2_H +#endif //#ifndef _uart0_H diff --git a/source/msp/UART2.c b/source/msp/UART2.c new file mode 100644 index 0000000..44de2ef --- /dev/null +++ b/source/msp/UART2.c @@ -0,0 +1,84 @@ +#include "uart2.h" +//#include "uartx.h" + +//TS_Handle_PH3 s_uart2_tcp_rec; + +void L0_uart2_init(void) +{ +#if (MainFre_11M == D_sys_MainFre) // 115200bps@11.0592MHz + S2CON = 0x50; + AUXR |= 0x04; + T2L = 0xE8; + T2H = 0xFF; + AUXR |= 0x10; + +#elif (MainFre_22M == D_sys_MainFre) //115200bps@22.1184MHz + S2CON = 0x50; //8???,????? + AUXR |= 0x04; //?????1T?? + T2L = 0xD0; //??????? + T2H = 0xFF; //??????? + AUXR |= 0x10; //???2???? +#endif +} + +void L0_uart2_buf_init(void) +{ + //定义发送缓冲区 + ts_uart[uNum2].s.buf = ts_send_buf.s2; + ts_uart[uNum2].s.bufmax = D_send2_max; + ts_uart[uNum2].s.max = ts_uart[uNum2].s.now = 0; + ts_uart[uNum2].s.ok = D_ready; + + //定义接收缓冲区 + ts_uart[uNum2].r.buf = ts_recv_buf.r2; + ts_uart[uNum2].r.bufmax = D_recv2_max; + ts_uart[uNum2].r.head = 0; + ts_uart[uNum2].r.ok = 0; + ts_uart[uNum2].r.idle = 1; + ts_uart[uNum2].r.overtime_t = 0; + + //定义接收处理协议 + ts_uart[uNum2].tp_handler = L0_uartN_overtime_callback; + ts_uart[uNum2].uartx = uNum2; + + //串口初始化 + L0_uart2_init(); + + //打开串口中断 + D_uart2_ES_INT(1); + + //默认处于接收状态 + // D_UART2_485_RX() +} + +/************************************************* +UART 中断 +*************************************************/ +#define D_SERVE_uart2 interrupt 8 +void INTERRUPT_uart2(void) D_SERVE_uart2 // using 2 +{ + NOP();NOP();NOP(); + if (L0_uart2_IntRI()) //如果是U2接收中断 + { + L0_uart2_IntRIClear(); //清除接收中断标志 + ts_uart[uNum2].r.reg = S2BUF; //获取当前数据 + L0_uartN_s2b(uNum2); //接收数据至缓冲区 + } + if (L0_uart2_IntTI()) //如果是U0发送中断 + { + L0_uart2_IntTIClear(); //清除发送中断标 + if (ts_uart[uNum2].s.max != ts_uart[uNum2].s.now) + { + S2BUF = ts_uart[uNum2].s.p[ts_uart[uNum2].s.now]; + ts_uart[uNum2].s.now++; + } + else + { + ts_uart[uNum2].s.ok = D_ready; + ts_uart[uNum2].s.max = 0; + ts_uart[uNum2].s.now = 0; //可以发送下一个数据 +// D_UART2_485_RX() //切换到接收状态 + } + } + NOP();NOP();NOP(); +} diff --git a/source/msp/mcu support/UART2.h b/source/msp/UART2.h similarity index 87% rename from source/msp/mcu support/UART2.h rename to source/msp/UART2.h index d3bb23c..32ddaae 100644 --- a/source/msp/mcu support/UART2.h +++ b/source/msp/UART2.h @@ -54,26 +54,26 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 #define _uart2_H #include "../bsp/bsp_config.h" - -#include "../tpc/at0d0a.h" -#include "../tpc/modbus.h" -#include "msp_uart_x.h" #include "../tpc/ccmodbus.h" +#include "uartx.h" + #define uNum2 1 +// TS_Handle_PH3 s_uart2_tcp_rec; + #define D_uart2_ES_INT(x) (x) ? (BITN_1(IE2,ES2)) : (BITN_0(IE2,ES2)) #define L0_uart2_IntRI() (S2CON & S2RI)//BITN_G(SCON,U0RI) #define L0_uart2_IntTI() (S2CON & S2TI)//BITN_G(SCON,U0TI) #define L0_uart2_IntRIClear(); BITN_0(S2CON,S2RI) #define L0_uart2_IntTIClear(); BITN_0(S2CON,S2TI) -#define L0_uart2_get() (S2BUF) + + //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< void L0_uart2_buf_init(void); -void L0_uart2_sendArray(U8 * buf, U16 len); -void uart2_Handdle(void); + #define L0_uart2_uc(X) L0_uartN_uc(uNum2,X) #define L0_uart2_us(X) L0_uartN_us(uNum2,X) #define L0_uart2_ul(X) L0_uartN_ul(uNum2,X) @@ -81,14 +81,9 @@ void uart2_Handdle(void); #define L0_uart2_uchex(X) L0_uartN_uchex(uNum2,X) #define L0_uart2_ushex(X) L0_uartN_ushex(uNum2,X) #define L0_uart2_ulhex(X) L0_uartN_ulhex(uNum2,X) -#define L0_uart2_sendstr(buf) L0_uartN_sendstr(uNum2,buf) -//extern TP_Handler_X s_uart2_rec; -//extern TS_PH4_modbus s_uart2_ack; -extern TS_Handle_0d0a s_uart2_at; -extern TS_Handle_PH3 s_uart2_tcp_rec; -extern void (*Lp0_uart2_fun)(unsigned char sbufreg); - -extern void L1_uart_tpc_config(void); +#define L0_uart2_sendstr(buf) L0_uartN_sendstr(uNum2,buf) +#define L0_uart2_sendArray(buf, n) L0_uartN_sendArray(uNum2,buf,n) +#define L0_uart2_sendArrayHex(buf, n) L0_uartN_sendArrayHex(uNum2,buf,n) #endif //#ifndef _uart2_H diff --git a/source/msp/UART3.c b/source/msp/UART3.c new file mode 100644 index 0000000..d6bea23 --- /dev/null +++ b/source/msp/UART3.c @@ -0,0 +1,88 @@ +#include "uart3.h" +#include "uartx.h" + +void L0_uart3_init(void) +{ +#if (MainFre_11M == D_sys_MainFre) //115200bps@11.0592MHz + S3CON = 0x10; //8位数据,可变波特率 + S3CON |= 0x40; //串口3选择定时器3为波特率发生器 + T4T3M |= 0x02; //定时器3时钟为Fosc,即1T + T3L = 0xE8; //设定定时初值 + T3H = 0xFF; //设定定时初值 + T4T3M |= 0x08; //启动定时器3 + +#elif (MainFre_22M == D_sys_MainFre) //115200bps@22.1184MHz + S3CON = 0x10; //8位数据,可变波特率 + S3CON |= 0x40; //串口3选择定时器3为波特率发生器 + T4T3M &= 0xFD; //定时器时钟12T模式 + T3L = 0xFC; //设置定时初始值 + T3H = 0xFF; //设置定时初始值 + T4T3M |= 0x08; //定时器3开始计时 + +#endif + +} + +void L0_uart3_buf_init(void) +{ + //定义发送缓冲区 + ts_uart[uNum3].s.buf = ts_send_buf.s3; + ts_uart[uNum3].s.bufmax = D_send3_max; + ts_uart[uNum3].s.max = ts_uart[uNum3].s.now = 0; + ts_uart[uNum3].s.ok = D_ready; + + //定义接收缓冲区 + ts_uart[uNum3].r.buf = ts_recv_buf.r3; + ts_uart[uNum3].r.bufmax = D_recv3_max; + ts_uart[uNum3].r.head = 0; + ts_uart[uNum3].r.ok = 0; + ts_uart[uNum3].r.idle = 1; + ts_uart[uNum3].r.overtime_t = 0; + + //串口协议解析专用字段 + ts_uart[uNum3].tp_handler = L0_uartN_overtime_callback; + ts_uart[uNum3].uartx = uNum3; + + //串口初始化 + L0_uart3_init(); + + //打开串口中断 + D_uart3_ES_INT(1); + + //默认处于接收状态 + //D_UART3_485_RX() +} + +/************************************************* +UART 中断 +*************************************************/ +#define D_SERVE_UART3 interrupt 17 +void INTERRUPT_UART3(void) D_SERVE_UART3// using 3 +{ + NOP(); NOP(); NOP(); + if(L0_uart3_IntRI()) //如果是U3接收中断 + { + L0_uart3_IntRIClear(); //清除接收中断标志 + ts_uart[uNum3].r.reg = S3BUF; //获取当前数据 + L0_uartN_s2b(uNum3); //接收数据至缓冲区 + } + if(L0_uart3_IntTI()) //如果是U0发送中断 + { + L0_uart3_IntTIClear(); //清除发送中断标志 + if(ts_uart[uNum3].s.max != ts_uart[uNum3].s.now) + { + S3BUF = ts_uart[uNum3].s.p[ts_uart[uNum3].s.now]; + ts_uart[uNum3].s.now ++; + } + else + { + ts_uart[uNum3].s.ok = D_ready; + ts_uart[uNum3].s.max = 0; + ts_uart[uNum3].s.now = 0;//可以发送下一个数据 + //D_UART3_485_RX() //切换到接收状态 + } + } + NOP(); NOP(); NOP(); +} + + diff --git a/source/msp/UART3.h b/source/msp/UART3.h new file mode 100644 index 0000000..4389bac --- /dev/null +++ b/source/msp/UART3.h @@ -0,0 +1,39 @@ +#ifndef _uart3_H +#define _uart3_H + +#include "../bsp/bsp_config.h" +#include "uartx.h" + +#define uNum3 2 + +//#define S4SM0 BITN7 +#define D_uart3_ES_INT(x) (x) ? (BITN_1(IE2,ES3)) : (BITN_0(IE2,ES3)) +//#define D_uart3_ES_INT_CLOSE() BITN_0(IE2,ES3) +//#define D_uart3_ES_INT_OPEN() BITN_1(IE2,ES3) +#define L0_uart3_IntRI() (S3CON & S3RI)//BITN_G(SCON,U0RI) +#define L0_uart3_IntTI() (S3CON & S3TI)//BITN_G(SCON,U0TI) +#define L0_uart3_IntRIClear(); BITN_0(S3CON,S3RI) +#define L0_uart3_IntTIClear(); BITN_0(S3CON,S3TI) +#define L0_uart3_set(x) S3BUF = (x); +#define L0_uart3_get() (S3BUF) + + +//<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< + +void L0_uart3_buf_init(void); + +void FOUR_G_ATEST(void); + +#define L0_uart3_uc(X) L0_uartN_uc(uNum3,X) +#define L0_uart3_us(X) L0_uartN_us(uNum3,X) +#define L0_uart3_ul(X) L0_uartN_ul(uNum3,X) +#define L0_uart3_0d0a() L0_uartN_0d0a(uNum3) +#define L0_uart3_uchex(X) L0_uartN_uchex(uNum3,X) +#define L0_uart3_ushex(X) L0_uartN_ushex(uNum3,X) +#define L0_uart3_ulhex(X) L0_uartN_ulhex(uNum3,X) +#define L0_uart3_sendstr(buf) L0_uartN_sendstr(uNum3,buf) +#define L0_uart3_sendArray(buf, n) L0_uartN_sendArray(uNum3,buf,n) +#define L0_uart3_sendArrayHex(buf, n) L0_uartN_sendArrayHex(uNum3,buf,n) + +#endif //#ifndef _uart3_H + diff --git a/source/msp/UART4.C b/source/msp/UART4.C new file mode 100644 index 0000000..b6549f4 --- /dev/null +++ b/source/msp/UART4.C @@ -0,0 +1,98 @@ + +#include "uart4.h" + +//#define FOSC 11059200L //系统频率 +//#define BAUD4 115200 //串口波特率 +void L0_uart4_init(void)//115200bps@11.0592MHz +{ + #if(MainFre_11M == D_sys_MainFre) +#if 0 + S4CON = 0x50; //8位可变波特率 + T4L = (65536 - (FOSC/4/BAUD4)); //设置波特率重装值 + T4H = (65536 - (FOSC/4/BAUD4))>>8; + T4T3M |= 0x20; //定时器4为1T模式 + T4T3M |= 0x80; //定时器4开始计时 +#else + S4CON = 0x10; //8位数据,可变波特率 + S4CON |= 0x40; //串口4选择定时器4为波特率发生器 + T4T3M |= 0x20; //定时器4时钟为Fosc,即1T + T4L = 0xE8; //设定定时初值 + T4H = 0xFF; //设定定时初值 + T4T3M |= 0x80; //启动定时器4 +#endif + + +#elif (MainFre_22M == D_sys_MainFre) //115200bps@22.1184MHz + S4CON = 0x10; //8位数据,可变波特率 + S4CON |= 0x40; //串口4选择定时器4为波特率发生器 + T4T3M |= 0x20; //定时器4时钟为Fosc,即1T + T4L = 0xD0; //设定定时初值 + T4H = 0xFF; //设定定时初值 + T4T3M |= 0x80; //启动定时器4 +#endif +} + +void L0_uart4_buf_init(void) +{ + //定义发送缓冲区 + ts_uart[uNum4].s.buf = ts_send_buf.s4; + ts_uart[uNum4].s.bufmax = D_send4_max; + ts_uart[uNum4].s.max = ts_uart[uNum4].s.now = 0; + ts_uart[uNum4].s.ok = D_ready; + + //定义接收缓冲区 + ts_uart[uNum4].r.buf = ts_recv_buf.r4; + ts_uart[uNum4].r.bufmax = D_recv4_max; + ts_uart[uNum4].r.head = 0; + ts_uart[uNum4].r.ok = 0; + ts_uart[uNum4].r.idle = 1; + ts_uart[uNum4].r.overtime_t = 0; + + //串口协议解析专用字段 + ts_uart[uNum4].tp_handler = L0_uartN_overtime_callback; + ts_uart[uNum4].uartx = uNum4; + + //串口初始化 + L0_uart4_init(); + + //打开串口中断 + D_uart4_ES_INT(1); + + //默认处于接收状态 + //D_UART4_485_RX() +} + +/************************************************* +UART 中断 +*************************************************/ + +// #define D_SERVE_uart4 interrupt 18 +// void INTERRUPT_uart4(void) D_SERVE_uart4// using 2 +// { +// //NOP(); NOP(); NOP(); +// if(L0_uart4_IntRI()) //如果是U0接收中断 +// { +// L0_uart4_IntRIClear(); //清除接收中断标志 +// ts_uart[uNum4].r.reg = S4BUF; //获取当前数据 +// L0_uartN_s2b(uNum4); //接收数据至缓冲区 +// } +// if(L0_uart4_IntTI()) //如果是U0发送中断 +// { +// L0_uart4_IntTIClear(); //清除发送中断标志 +// if(ts_uart[uNum4].s.max != ts_uart[uNum4].s.now) +// { +// S4BUF = ts_uart[uNum4].s.p[ts_uart[uNum4].s.now]; +// ts_uart[uNum4].s.now ++; +// } +// else +// { +// ts_uart[uNum4].s.ok = D_ready; +// ts_uart[uNum4].s.max = 0; +// ts_uart[uNum4].s.now = 0;//可以发送下一个数据 +// D_UART4_485_RX() //切换到接收状态 +// } +// } +// //NOP(); NOP(); NOP(); +// } + + diff --git a/source/msp/mcu support/UART4.h b/source/msp/UART4.h similarity index 93% rename from source/msp/mcu support/UART4.h rename to source/msp/UART4.h index b70da6c..78a3c9b 100644 --- a/source/msp/mcu support/UART4.h +++ b/source/msp/UART4.h @@ -54,8 +54,7 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 #define _uart4_H #include "../bsp/bsp_config.h" -#include "../tpc/tpc_ccmodbus.h" -#include "uartN.h" +#include "uartx.h" #define uNum4 3 @@ -69,7 +68,6 @@ msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 //<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< void L0_uart4_buf_init(void); -void L0_uart4_sendArray(U8 * buf, U16 len); #define L0_uart4_uc(X) L0_uartN_uc(uNum4,X) #define L0_uart4_us(X) L0_uartN_us(uNum4,X) @@ -79,10 +77,8 @@ void L0_uart4_sendArray(U8 * buf, U16 len); #define L0_uart4_ushex(X) L0_uartN_ushex(uNum4,X) #define L0_uart4_ulhex(X) L0_uartN_ulhex(uNum4,X) #define L0_uart4_sendstr(buf) L0_uartN_sendstr(uNum4,buf) -#define L1_uart4_uchexArray(buf) L1_uartN_uchexArray(uNum4,buf) - -extern TP_Handler_X s_uart4_rec; -extern TS_PH3_ccmodbus s_uart4_ack; +#define L0_uart4_sendArray(buf, n) L0_uartN_sendArray(uNum4,buf,n) +#define L0_uart4_sendArrayHex(buf, n) L0_uartN_sendArrayHex(uNum4,buf,n) #endif //#ifndef _uart4_H diff --git a/source/msp/UARTX.c b/source/msp/UARTX.c new file mode 100644 index 0000000..41e12a5 --- /dev/null +++ b/source/msp/UARTX.c @@ -0,0 +1,240 @@ + +#include "uartx.h" + +TS_uart_reg ts_uart[SERIAL_MAX_NUM] = {0}; +TS_send_buf ts_send_buf; +TS_recv_buf ts_recv_buf; + +void L0_uartN_set(U8 uartx, U8 x) /*reentrant*/ +{ + switch (uartx) + { + case 0: + SBUF = (x); + break; + case 1: + S2BUF = (x); + break; + case 2: + S3BUF = (x); + break; + case 3: + S4BUF = (x); + break; + default: + break; + } +} + +U8 L0_uartN_get(U8 uartx) +{ + U8 x = 0; + switch (uartx) + { + case 0: + x = SBUF; + break; + case 1: + x = S2BUF; + break; + case 2: + x = S3BUF; + break; + case 3: + x = S4BUF; + break; + default: + break; + } + return x; +} + +void L0_uartN_485(U8 uartx) +{ + switch(uartx) + { + // case 0: D_UART0_485_TX(); break; + // case 1: D_UART2_485_TX(); break; + // case 2: D_UART3_485_TX(); break; + // case 3: D_UART4_485_TX(); break; + default: break; + } +} + +void L0_waitFree_uartN(U8 uartx) +{ + ts_uart[uartx].s.over = 0; + while (ts_uart[uartx].s.ok != D_ready) + { +#if 1 //发送数据特别快时,某些情况下会导致数据发送出错 + ts_uart[uartx].s.over++; + if (ts_uart[uartx].s.over > 20000) + { + ts_uart[uartx].s.max = 0; + ts_uart[uartx].s.now = 0; + ts_uart[uartx].s.ok = D_ready; + break; + } +#endif + } +} + +void L0_uartN_sendArray(U8 uartx, void *buf, U16 len) +{ + U16 i; + if (len == 0) + { + return; + } + L0_waitFree_uartN(uartx); + + L0_uartN_485(uartx); + ts_uart[uartx].s.ok = D_clear; + ts_uart[uartx].s.over = 0; + ts_uart[uartx].s.max = len; + ts_uart[uartx].s.now = 1; + if (len <= ts_uart[uartx].s.bufmax) + { + //将参数buf拷贝至内部buf + for (i = 0; i < len; i++) + { + ts_uart[uartx].s.buf[i] = ((U8 *)buf)[i]; + } + ts_uart[uartx].s.p = ts_uart[uartx].s.buf; + } + else + { + //不使用内部buf,如果再发送完毕之前,参数buf被回收,发送会出错 + ts_uart[uartx].s.p = (U8 *)buf; + } + L0_uartN_set(uartx, ts_uart[uartx].s.p[0]); +} + +void L0_uartN_uc(U8 uartx, U8 ww) +{ + L0_uartN_sendArray(uartx, &ww, 1); +} + +void L0_uartN_us(U8 uartx, vU16 ww) +{ + U_U16 uStemp; + uStemp.word = ww; + ts_uart[uartx].s.buf3[0] = uStemp.BYTE2.h; + ts_uart[uartx].s.buf3[1] = uStemp.BYTE2.l; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 2); +} + +void L0_uartN_ul(U8 uartx, vU32 ww) +{ + U_U32 uStemp; + L0_waitFree_uartN(uartx); + uStemp.dWord = ww; + ts_uart[uartx].s.buf3[0] = uStemp.BYTE4.byte0; + ts_uart[uartx].s.buf3[1] = uStemp.BYTE4.byte1; + ts_uart[uartx].s.buf3[2] = uStemp.BYTE4.byte2; + ts_uart[uartx].s.buf3[3] = uStemp.BYTE4.byte3; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 4); +} + +void L0_uartN_0d0a(U8 uartx) +{ + L0_waitFree_uartN(uartx); + ts_uart[uartx].s.buf3[0] = 0x0d; + ts_uart[uartx].s.buf3[1] = 0x0a; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 2); +} + +void L0_uartN_uchex(U8 uartx, U8 ww) +{ + L0_waitFree_uartN(uartx); + ts_uart[uartx].s.buf3[0] = cguHex2Char[D_uc_high(ww)][1]; + ts_uart[uartx].s.buf3[1] = cguHex2Char[D_uc_low(ww)][1]; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 2); +} + +void L0_uartN_ushex(U8 uartx, vU16 ww) +{ + U_F16 k; + L0_waitFree_uartN(uartx); + k.us = ww; + ts_uart[uartx].s.buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; + ts_uart[uartx].s.buf3[1] = cguHex2Char[D_uc_low(k.BYTE2.H)][1]; + ts_uart[uartx].s.buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; + ts_uart[uartx].s.buf3[3] = cguHex2Char[D_uc_low(k.BYTE2.L)][1]; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 4); +} + +void L0_uartN_ulhex(U8 uartx, U32 ww) +{ + U_U32 k; + L0_waitFree_uartN(uartx); + k.dWord = ww; + ts_uart[uartx].s.buf3[0] = cguHex2Char[D_uc_high(k.BYTE4.byte0)][1]; + ts_uart[uartx].s.buf3[1] = cguHex2Char[D_uc_low(k.BYTE4.byte0)][1]; + ts_uart[uartx].s.buf3[2] = cguHex2Char[D_uc_high(k.BYTE4.byte1)][1]; + ts_uart[uartx].s.buf3[3] = cguHex2Char[D_uc_low(k.BYTE4.byte1)][1]; + ts_uart[uartx].s.buf3[4] = cguHex2Char[D_uc_high(k.BYTE4.byte2)][1]; + ts_uart[uartx].s.buf3[5] = cguHex2Char[D_uc_low(k.BYTE4.byte2)][1]; + ts_uart[uartx].s.buf3[6] = cguHex2Char[D_uc_high(k.BYTE4.byte3)][1]; + ts_uart[uartx].s.buf3[7] = cguHex2Char[D_uc_low(k.BYTE4.byte3)][1]; + L0_uartN_sendArray(uartx, ts_uart[uartx].s.buf3, 8); +} + +void L0_uartN_sendstr(U8 uartx, U8 *str) +{ + L0_uartN_sendArray(uartx, str, Lc_strlen(str)); +} + +void L0_uartN_sendArrayHex(U8 uartx, vU8 *buf, U16 n) +{ + U16 i; + for (i = 0; i < n; i++) + { + L0_uartN_uchex(uartx, buf[i]); + L0_uartN_uc(uartx, ' '); + } +} + +void L0_uartN_s2b(U8 uartx) +{ + if(ts_uart[uartx].r.head == 0) + { + ts_uart[uartx].r.head = 1; + ts_uart[uartx].r.ok = 0; + ts_uart[uartx].r.num = 0; + } + else + { + if(ts_uart[uartx].r.num >= ts_uart[uartx].r.bufmax) + { + ts_uart[uartx].r.num = 0; + } + } + ts_uart[uartx].r.buf[ ts_uart[uartx].r.num ] = ts_uart[uartx].r.reg; + ts_uart[uartx].r.num++; + ts_uart[uartx].r.idle = 0; + ts_uart[uartx].r.overtime_t = 0; +} + +void L0_uartN_overtime_callback(U8 uartx) +{ + if(0 == ts_uart[uartx].r.idle) + { + if(ts_uart[uartx].r.overtime_t >= 2) + { + //设置总线空闲 + ts_uart[uartx].r.idle = 1; + ts_uart[uartx].r.head = 0; + ts_uart[uartx].r.overtime_t = 0; + + //数据不为空 + if(ts_uart[uartx].r.num > 0) + { + /// 接收到的数据结束: 总线空闲+buf非空 + // ts_uart[uartx].r.num = 0; + ts_uart[uartx].r.ok = 1; + } + } + ts_uart[uartx].r.overtime_t ++; + } +} \ No newline at end of file diff --git a/source/msp/UARTX.h b/source/msp/UARTX.h new file mode 100644 index 0000000..c2bcf67 --- /dev/null +++ b/source/msp/UARTX.h @@ -0,0 +1,97 @@ + +#ifndef _uartN_H +#define _uartN_H +#include "../clib/clib.h" +#include "../tpc/tpc_x.h" +#include "../bsp/bsp_config.h" + +#define SERIAL_MAX_NUM 4 +#define D_UART_send_buf2_max 8 //此处改动会影响L0_uartN_ulhex函数 + +#define D_uartN_free() (0 == ts_uart_send_buf[uartx].max) +#define D_uartN_busy() (0 != ts_uart_send_buf[uartx].max) +#define D_BRT_COUNT(t,clk,uartBRT) (U16)(65536- (clk / (4 * uartBRT * t))) + +/////可以依据实际使用独立定制 +#define D_send1_max 64 +#define D_send2_max 64 +#define D_send3_max 128 +#define D_send4_max 64 + +/////可以依据实际使用独立定制 +#define D_recv1_max 64 +#define D_recv2_max 64 +#define D_recv3_max 128 +#define D_recv4_max 64 + +typedef struct +{ + U8 r1[D_recv1_max]; + U8 r2[D_recv2_max]; + U8 r3[D_recv3_max]; + U8 r4[D_recv4_max]; +}TS_recv_buf; + +typedef struct +{ + U8 s1[D_send1_max]; + U8 s2[D_send2_max]; + U8 s3[D_send3_max]; + U8 s4[D_send4_max]; +}TS_send_buf; + +typedef struct _TS_uart_reg +{ + struct + { + vU8 num; //接收到的数目注意数据长度的范围 + vU8 *p; + vU16 now; /// 当前buf所在的位置 0------(max-1) + vU16 max; /// 当前buf中数据长度,也就是需要发送的长度 + vU32 over; /// 结束等待标志,over累加到某个值时,结束等待 + vU8 ok; /// 发送完成标志 + vU8 *buf; + vU8 buf3[D_UART_send_buf2_max]; + U16 bufmax; ///buf的最大长度 + }s; + + struct + { + vU8 reg; + vU8 ok; //接收协议ok标志,串口初始化设置为0 + vU8 idle; //空闲标志 + vU8 overtime_t; //超时溢出的计数器 + vU8 head; //接收标志头标志,串口初始化设置0 + vU8 num; //协议实际长度 + vU8 *buf; ////协议缓冲,由每个串口根据需要的缓冲区大小自己定义 + U16 bufmax; ///buf的最大长度 + }r; + + void (*tp_handler)(U8 uartx); + U8 uartx; + +}TS_uart_reg; + +extern TS_uart_reg ts_uart[SERIAL_MAX_NUM]; +extern TS_send_buf ts_send_buf; +extern TS_recv_buf ts_recv_buf; + +extern void L0_uartN_init(U8 uartx); +extern void L0_uartN_set(U8 uartx,U8 x); +extern U8 L0_uartN_get(U8 uartx); +extern void L0_uartN_sendArray(U8 uartx,void *buf,U16 len); +extern void L0_uartN_uc(U8 uartx,U8 ww); +extern void L0_uartN_us(U8 uartx,vU16 ww); +extern void L0_uartN_ul(U8 uartx,vU32 ww); +extern void L0_uartN_0d0a(U8 uartx); +extern void L0_uartN_uchex(U8 uartx, U8 ww); +extern void L0_uartN_ushex(U8 uartx, U16 ww); +extern void L0_uartN_ulhex(U8 uartx, U32 ww); +extern void L0_uartN_sendstr(U8 uartx,U8 *buf); +extern void L0_uartN_sendArrayHex(U8 uartx,vU8 *buf,U16 n); +extern void L0_uartN_s2b(U8 uartx); +extern void L0_uartN_overtime_callback(U8 uartx); + + +#endif //#ifndef _uartN_H + diff --git a/source/msp/eeprom.h b/source/msp/eeprom.h index c2310cb..e1e7f40 100644 --- a/source/msp/eeprom.h +++ b/source/msp/eeprom.h @@ -21,7 +21,7 @@ #include "../clib/type.h" #include "../clib/clib.h" #include "../ctask/tick.h" -#include "msp_uart0.h" +#include "../msp/uart0.h" /** * EEPROM 存储结构 diff --git a/source/msp/mcu support/.keep b/source/msp/mcu support/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/source/msp/mcu support/UART0.C b/source/msp/mcu support/UART0.C deleted file mode 100644 index 9bea919..0000000 --- a/source/msp/mcu support/UART0.C +++ /dev/null @@ -1,180 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -/// COPYRIGHT NOTICE -/// Copyright (c) 2015, 传控科技 -/// All rights reserved. -/// -/// @file main.c -/// @brief main app -/// -///(本文件实现的功能的详述) -/// -/// @version 1.1 CCsens technology -/// @author CC -/// @date 20150102 -/// -/// -/// 修订说明:最初版本 -/// Modified by: -/// Modified date: -/// Version: -/// Descriptions: -// 20160413 CC-ACC-VH02 -// 连接至 J22 RXD0 TXD0 -//P5_DIR &= ~BITN1; //p5.1输出TXD -//P5_DIR |= BITN0; //p5.0输入RXD -//P5_SEL0 &= ~(BITN0 +BITN1); //设置P5.0 P5.1为UART0 RXD TXD -//P5_SEL1 |= BITN0 +BITN1; - -/***************************************************************************** -update by cc @201700110 -针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 -个需要平衡的事情. - -clib/clib.c: -公用的函数 和硬件无关 -放置串行模式(串口等其他通讯总线类的输出)输出的函数, -一些覆盖模式输出的(lcd等固屏输出的)的也可使用 - void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) ------------------------------------------------------------------------------------------ -uartcom/Uprotocol2app - 协议到应用 - 为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 - -typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ - L3_UARTcom0_exp_protocol 解析应用协议 ------------------------------------------------------------------------------------------ -uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 -公用的串口通讯定义 - struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ - void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 --------------------------------------------------------------------------------------------- -msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 - L0_UART0_Init - UART0_IRQHandler - L0_Usend_uc------UserDef ------------------------------------------------------------------------------------------ -********************************************************************************/ -#include "msp_uart0.h" -#include "../msp/time.h" -//#define _USE_485 - -static volatile Ts_uart_send_buf idata ts_uart_send_shop; - -TP_Handler_X s_uart0_rec; -TS_PH4_modbus s_uart0_ack; - -void L0_uart0_init(void) -{ -// U16 val1= D_BRT_COUNT(12,D_sys_MainFre,D_uart0_BRT); -// SCON = 0x50; //8位数据,可变波特率 -// AUXR |= 0x01; //串口1选择定时器2为波特率发生器 -// AUXR &= 0xFB; //定时器2时钟为Fosc/12,即12T -// T2L = val1; -// T2H = val1 >> 8; -// AUXR |= 0x10; //启动定时器2 - SCON = 0x50; //8位数据,可变波特率 - AUXR &= 0xBF; //定时器时钟12T模式 - AUXR &= 0xFE; //串口1选择定时器1为波特率发生器 - TMOD &= 0x0F; //设置定时器模式 - TL1 = 0xFC; //设置定时初始值 - TH1 = 0xFF; //设置定时初始值 -//// TL1 = val1; //设置定时初始值 -//// TH1 = val1 >> 8; //设置定时初始值 - ET1 = 0; //禁止定时器%d中断 - TR1 = 1; //定时器1开始计时 -// SCON = 0x50; //8位数据,可变波特率 -// AUXR |= 0x01; //串口1选择定时器2为波特率发生器 -// AUXR &= 0xFB; //定时器时钟12T模式 -// T2L = 0xE8; //设置定时初始值 -// T2H = 0xFF; //设置定时初始值 -// AUXR |= 0x10; //定时器2开始计时 -} - -void L0_uart0_buf_init(void) -{ - ts_uart[uNum0].p = &ts_uart_send_shop; - ts_uart[uNum0].p->max = ts_uart[uNum0].p->now = 0; - ts_uart[uNum0].p->ok = D_ready; - ts_uart[uNum0].t = &s_uart0_rec; - ts_uart[uNum0].t->head = 0; - ts_uart[uNum0].t->ok = 0; - //ts_uart[uNum0].tp_handler = L1_s2b_PH4; - ts_uart[uNum0].tp_handler = NULL; //使用函数指针导致错误 - ts_uart[uNum0].ack = (U8*)&s_uart0_ack; - L0_uart0_init(); - D_uart0_ES_INT(1); //打开串口中断 - -#if (D_UART0_485_TYPE != TYPE_485_NONE) - D_UART0_485_RX() //默认处于接收状态 -#endif -} - -void L0_uart0_sendArray(U8 * buf, U16 len) -{ -#if (D_UART0_485_TYPE != TYPE_485_NONE) - D_UART0_485_TX() //切换到输出状态 -#endif - L0_uartN_sendArray(uNum0,buf,len); -} - -/************************************************* -UART 中断 -*************************************************/ -void INTERRUPT_UART(void) D_SERVE_UART -{ - //NOP(); NOP(); NOP(); - if(L0_uart0_IntRI()) //如果是U0接收中断 - { - // LED0 ^= 1; - L0_uart0_IntRIClear(); //清除接收中断标志 - ts_uart[uNum0].t->reg = SBUF; - //ts_uart[uNum0].tp_handler(ts_uart[uNum0].t); - L1_s2b_PH4(ts_uart[uNum0].t); - L0_timer3_restart(); - } - if(L0_uart0_IntTI()) //如果是U0发送中断 - { - //LED0 ^= 1; - L0_uart0_IntTIClear(); //清除发送中断标志 - if(ts_uart[uNum0].p->max != ts_uart[uNum0].p->now) - { - SBUF = ts_uart[uNum0].p->p[ts_uart[uNum0].p->now]; - //L0_uartN_set(uNum0,ts_uart[uNum0].p->p[ts_uart[uNum0].p->now]); - ts_uart[uNum0].p->now ++; - } - else - { - ts_uart[uNum0].p->ok = D_ready; - ts_uart[uNum0].p->max = 0; - ts_uart[uNum0].p->now = 0;//可以发送下一个数据 -#if (D_UART0_485_TYPE != TYPE_485_NONE) - D_UART0_485_RX() //切换到接收状态 -#endif - } - } - //NOP(); NOP(); NOP(); -} -#if 0 -void timer3_isrHanddle(void) D_SERVE_TIMER3 -{ - struct _tp_handler_x *p1 = &s_uart0_rec; - if((p1->head == 1) && (p1->num >= D_s_modbus_min)) - { - p1->head = 0; - crc16_irq(p1->crc,p1->buf,p1->num - 2); //校验CRC - if(p1->crc[0] == p1->buf[p1->num-2] && p1->crc[1] == p1->buf[p1->num-1]) - { - p1->ok = 1; -// LED0 ^= 1; - } - else - { - p1->yes = 1; - } - } - - L0_timer3_stop(); -} -#endif - - diff --git a/source/msp/mcu support/uart_x.c b/source/msp/mcu support/uart_x.c deleted file mode 100644 index 57210d8..0000000 --- a/source/msp/mcu support/uart_x.c +++ /dev/null @@ -1,211 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -/// COPYRIGHT NOTICE -/// Copyright (c) 2015, 传控科技 -/// All rights reserved. -/// -/// @file main.c -/// @brief main app -/// -///(本文件实现的功能的详述) -/// -/// @version 1.1 CCsens technology -/// @author CC -/// @date 20150102 -/// -/// -/// 修订说明:最初版本 -/// Modified by: -/// Modified date: -/// Version: -/// Descriptions: -// 20160413 CC-ACC-VH02 -// 连接至 J22 RXD0 TXD0 -//P5_DIR &= ~BITN1; //p5.1输出TXD -//P5_DIR |= BITN0; //p5.0输入RXD -//P5_SEL0 &= ~(BITN0 +BITN1); //设置P5.0 P5.1为UART0 RXD TXD -//P5_SEL1 |= BITN0 +BITN1; - -/***************************************************************************** -update by cc @201700110 -针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 -个需要平衡的事情. - -clib/clib.c: -公用的函数 和硬件无关 -放置串行模式(串口等其他通讯总线类的输出)输出的函数, -一些覆盖模式输出的(lcd等固屏输出的)的也可使用 - void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) ------------------------------------------------------------------------------------------ -uartcom/Uprotocol2app - 协议到应用 - 为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 - -typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ - L3_UARTcom0_exp_protocol 解析应用协议 ------------------------------------------------------------------------------------------ -uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 -公用的串口通讯定义 - struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ - void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 --------------------------------------------------------------------------------------------- -msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 - L0_UART0_Init - UART0_IRQHandler - L0_Usend_uc------UserDef ------------------------------------------------------------------------------------------ -********************************************************************************/ -#include "msp_uart_x.h" - -TS_uart_reg idata ts_uart[SERIAL_MAX_NUM] = {0}; - -void L0_uartN_set(U8 uartx,U8 x) -{ - switch(uartx) - { - case 0:SBUF = (x);break; - case 1:S2BUF = (x);break; - case 2:S3BUF = (x);break; - case 3:S4BUF = (x);break; - default:break; - } -} - -U8 L0_uartN_get(U8 uartx) -{ - U8 x = 0; - switch(uartx) - { - case 0:x = SBUF; break; - case 1:x = S2BUF;break; - case 2:x = S3BUF;break; - case 3:x = S4BUF;break; - default:break; - } - return x; -} - -void L0_waitFree_uartN(U8 uartx) -{ - ts_uart[uartx].p->over = 0; - while(ts_uart[uartx].p->ok != D_ready) - { - #if 0 //发送数据特别快时,某些情况下会导致数据发送出错 - if(ts_uart[uartx].p->over ++ > 600000) - { - break; - } - #endif - } -} - -void L0_uartN_sendArray(U8 uartx,void *buf,U16 len) -{ - L0_waitFree_uartN(uartx); - ts_uart[uartx].p->ok = D_clear; - ts_uart[uartx].p->over = 0; - ts_uart[uartx].p->max = len; - ts_uart[uartx].p->now = 1; - if(len <= D_UART_send_buf_max) - { - //将参数buf拷贝至内部buf - for(ts_uart[uartx].p->num = 0;ts_uart[uartx].p->num < len;ts_uart[uartx].p->num ++) - { - ts_uart[uartx].p->buf[ts_uart[uartx].p->num] = ((U8*)buf)[ts_uart[uartx].p->num]; - } - ts_uart[uartx].p->p = ts_uart[uartx].p->buf; - } - else - { - //不使用内部buf,如果再发送完毕之前,参数buf被回收,发送会出错 - ts_uart[uartx].p->p = (U8 *)buf; - } - L0_uartN_set(uartx,ts_uart[uartx].p->p[0]); -} - -void L0_uartN_uc(U8 uartx,U8 ww) -{ - L0_uartN_sendArray(uartx,&ww,1); -} - -void L0_uartN_us(U8 uartx,vU16 ww) -{ - U_U16 uStemp; - uStemp.word = ww; - ts_uart[uartx].p->buf3[0] = uStemp.BYTE2.h; - ts_uart[uartx].p->buf3[1] = uStemp.BYTE2.l; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,2); -} - -void L0_uartN_ul(U8 uartx,vU32 ww) -{ - U_U32 uStemp; - L0_waitFree_uartN(uartx); - uStemp.dWord = ww; - ts_uart[uartx].p->buf3[0] = uStemp.BYTE4.byte0; - ts_uart[uartx].p->buf3[1] = uStemp.BYTE4.byte1; - ts_uart[uartx].p->buf3[2] = uStemp.BYTE4.byte2; - ts_uart[uartx].p->buf3[3] = uStemp.BYTE4.byte3; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,4); -} - -void L0_uartN_0d0a(U8 uartx) -{ - L0_waitFree_uartN(uartx); - ts_uart[uartx].p->buf3[0] = 0x0d; - ts_uart[uartx].p->buf3[1] = 0x0a; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,2); -} - -void L0_uartN_uchex(U8 uartx,U8 ww) -{ - L0_waitFree_uartN(uartx); - ts_uart[uartx].p->buf3[0] = cguHex2Char[D_uc_high(ww)][1]; - ts_uart[uartx].p->buf3[1] = cguHex2Char[D_uc_low (ww)][1]; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,2); -} - -void L0_uartN_ushex(U8 uartx,vU16 ww) -{ - U_F16 k; - L0_waitFree_uartN(uartx); - k.us = ww; - ts_uart[uartx].p->buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; - ts_uart[uartx].p->buf3[1] = cguHex2Char[D_uc_low (k.BYTE2.H)][1]; - ts_uart[uartx].p->buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; - ts_uart[uartx].p->buf3[3] = cguHex2Char[D_uc_low (k.BYTE2.L)][1]; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,4); -} - -void L0_uartN_ulhex(U8 uartx,U32 ww) -{ - U_U32 k; - L0_waitFree_uartN(uartx); - k.dWord = ww; - ts_uart[uartx].p->buf3[0] = cguHex2Char[D_uc_high(k.BYTE4.byte0)][1]; - ts_uart[uartx].p->buf3[1] = cguHex2Char[D_uc_low (k.BYTE4.byte0)][1]; - ts_uart[uartx].p->buf3[2] = cguHex2Char[D_uc_high(k.BYTE4.byte1)][1]; - ts_uart[uartx].p->buf3[3] = cguHex2Char[D_uc_low (k.BYTE4.byte1)][1]; - ts_uart[uartx].p->buf3[4] = cguHex2Char[D_uc_high(k.BYTE4.byte2)][1]; - ts_uart[uartx].p->buf3[5] = cguHex2Char[D_uc_low (k.BYTE4.byte2)][1]; - ts_uart[uartx].p->buf3[6] = cguHex2Char[D_uc_high(k.BYTE4.byte3)][1]; - ts_uart[uartx].p->buf3[7] = cguHex2Char[D_uc_low (k.BYTE4.byte3)][1]; - L0_uartN_sendArray(uartx,ts_uart[uartx].p->buf3,8); -} - -void L0_uartN_sendstr(U8 uartx,U8 *str) -{ - L0_uartN_sendArray(uartx,str,Lc_strlen(str)); -} - -void L0_uartN_uchexArray(U8 uartx,vU8 *buf,U16 n) -{ - int i; - for(i=0;inow = 0; ts_uart[uNum2].p->ok = D_ready; //ts_uart[uNum2].t = &s_uart2_rec; @@ -136,10 +136,7 @@ void L1_uart_tpc_config(void) UART 中断 *************************************************/ ///#define D_SERVE_uart2 interrupt 8 -// using 2 -#define D_SERVE_UART2 interrupt 8 -///void INTERRUPT_uart2(void) D_SERVE_uart2 -void INTERRUPT_uart2(void) interrupt 8 +void INTERRUPT_uart2(void) interrupt 8 ///D_SERVE_uart2// using 2 { //NOP(); NOP(); NOP(); if(L0_uart2_IntRI()) //如果是U2接收中断 @@ -152,7 +149,7 @@ void INTERRUPT_uart2(void) interrupt 8 //L1_s2b_0d0a(&s_uart2_at); L1_s2b_gm35(L0_uart2_get()); } - if(L0_uart2_IntTI()) //如果是U0发送中断 + if(L0_uart2_IntTI()) //如果是U2发送中断 { L0_uart2_IntTIClear(); //清除发送中断标志 if(ts_uart[uNum2].p->max != ts_uart[uNum2].p->now) diff --git a/source/msp/msp_uart3.c b/source/msp/msp/msp_uart3.c similarity index 100% rename from source/msp/msp_uart3.c rename to source/msp/msp/msp_uart3.c diff --git a/source/msp/msp_uart3.h b/source/msp/msp/msp_uart3.h similarity index 100% rename from source/msp/msp_uart3.h rename to source/msp/msp/msp_uart3.h diff --git a/source/msp/msp_uart_x.c b/source/msp/msp/msp_uart_x.c similarity index 100% rename from source/msp/msp_uart_x.c rename to source/msp/msp/msp_uart_x.c diff --git a/source/msp/msp_uart_x.h b/source/msp/msp/msp_uart_x.h similarity index 100% rename from source/msp/msp_uart_x.h rename to source/msp/msp/msp_uart_x.h diff --git a/source/msp/nouse/msp_uart4.C b/source/msp/nouse/msp_uart4.C deleted file mode 100644 index 9184f55..0000000 --- a/source/msp/nouse/msp_uart4.C +++ /dev/null @@ -1,169 +0,0 @@ -////////////////////////////////////////////////////////////////////////// -/// COPYRIGHT NOTICE -/// Copyright (c) 2015, 传控科技 -/// All rights reserved. -/// -/// @file main.c -/// @brief main app -/// -///(本文件实现的功能的详述) -/// -/// @version 1.1 CCsens technology -/// @author CC -/// @date 20150102 -/// -/// -/// 修订说明:最初版本 -/// Modified by: -/// Modified date: -/// Version: -/// Descriptions: -// 20160413 CC-ACC-VH02 -// 连接至 J22 RXD0 TXD0 -//P5_DIR &= ~BITN1; //p5.1输出TXD -//P5_DIR |= BITN0; //p5.0输入RXD -//P5_SEL0 &= ~(BITN0 +BITN1); //设置P5.0 P5.1为uart4 RXD TXD -//P5_SEL1 |= BITN0 +BITN1; - -/***************************************************************************** -update by cc @201700110 -针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复杂的还是软件应用简单是 -个需要平衡的事情. - -clib/clib.c: -公用的函数 和硬件无关 -放置串行模式(串口等其他通讯总线类的输出)输出的函数, -一些覆盖模式输出的(lcd等固屏输出的)的也可使用 - void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) ------------------------------------------------------------------------------------------ -uartcom/Uprotocol2app - 协议到应用 - 为了适应不同的通讯协议需要不同的uart口来对应 和应用相关 - -typedef struct _ts_lcm_pro_; 应用协议包的定义? LCM的协议------------ - L3_UARTcom0_exp_protocol 解析应用协议 ------------------------------------------------------------------------------------------ -uartcom/urec2protocol: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 标头式或者标尾式 -公用的串口通讯定义 - struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ - void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 --------------------------------------------------------------------------------------------- -msp/uartx.c 底层代码 和cpu相关 缓存发送也放在里面 - L0_uart4_Init - uart4_IRQHandler - L0_Usend_uc------UserDef ------------------------------------------------------------------------------------------ -********************************************************************************/ -#include "uart4.h" - -//#define _USE_485 - -static volatile Ts_uart_send_buf idata ts_uart_send_shop; -//TP_Handler_X s_uart4_at_rec; -//TP_Handler_X s_uart4_tcp_rec; -TP_Handler_X s_uart4_rec; -TS_PH3_ccmodbus s_uart4_ack; - -//#define FOSC 11059200L //系统频率 -//#define BAUD4 115200 //串口波特率 -void L0_uart4_init(void)//115200bps@11.0592MHz -{ - #if(MainFre_11M == D_sys_MainFre) -#if 0 - S4CON = 0x50; //8位可变波特率 - T4L = (65536 - (FOSC/4/BAUD4)); //设置波特率重装值 - T4H = (65536 - (FOSC/4/BAUD4))>>8; - T4T3M |= 0x20; //定时器4为1T模式 - T4T3M |= 0x80; //定时器4开始计时 -#else - S4CON = 0x10; //8位数据,可变波特率 - S4CON |= 0x40; //串口4选择定时器4为波特率发生器 - T4T3M |= 0x20; //定时器4时钟为Fosc,即1T - T4L = 0xE8; //设定定时初值 - T4H = 0xFF; //设定定时初值 - T4T3M |= 0x80; //启动定时器4 -#endif - - -#elif (MainFre_22M == D_sys_MainFre) //115200bps@22.1184MHz - S4CON = 0x10; //8位数据,可变波特率 - S4CON |= 0x40; //串口4选择定时器4为波特率发生器 - T4T3M |= 0x20; //定时器4时钟为Fosc,即1T - T4L = 0xD0; //设定定时初值 - T4H = 0xFF; //设定定时初值 - T4T3M |= 0x80; //启动定时器4 -#endif -} - -void L0_uart4_buf_init(void) -{ - ts_uart[uNum4].p = &ts_uart_send_shop; - ts_uart[uNum4].p->now = 0; - ts_uart[uNum4].p->ok = D_ready; - ts_uart[uNum4].t = &s_uart4_rec; - ts_uart[uNum4].t->head_0 = D_CMD_Filter1_ff; - ts_uart[uNum4].t->head_1 = D_CMD_Filter2_fe; - ts_uart[uNum4].t->head = 0; - ts_uart[uNum4].t->ok = 0; - ts_uart[uNum4].tp_handler = L1_s2b_PH3; - ts_uart[uNum4].ack = (U8*)&s_uart4_ack; - - //s_uart4_tcp_rec.head_0 = D_CMD_Filter1_ff; - //s_uart4_tcp_rec.head_1 = D_CMD_Filter2_fe; - //s_uart4_tcp_rec.head = 0; - //s_uart4_tcp_rec.ok = 0; - L0_uart4_init(); - D_uart4_ES_INT(1); //打开串口中断 - -#if (D_UART4_485_TYPE != TYPE_485_NONE) - D_UART4_485_RX() //默认处于接收状态 -#endif -} - -void L0_uart4_sendArray(U8 * buf, U16 len) -{ -#if (D_UART4_485_TYPE != TYPE_485_NONE) - D_UART4_485_TX() //切换到输出状态 -#endif - L0_uartN_sendArray(uNum4,buf,len); -} - -/************************************************* -UART 中断 -*************************************************/ - -#define D_SERVE_uart4 interrupt 18 -void INTERRUPT_uart4(void) D_SERVE_uart4// using 2 -{ -#if 1 - //NOP(); NOP(); NOP(); - if(L0_uart4_IntRI()) //如果是U0接收中断 - { - L0_uart4_IntRIClear(); //清除接收中断标志 - ts_uart[uNum4].t->reg = L0_uartN_get(uNum4); - ts_uart[uNum4].tp_handler(ts_uart[uNum4].t); - } - if(L0_uart4_IntTI()) //如果是U0发送中断 - { - L0_uart4_IntTIClear(); //清除发送中断标志 - if(ts_uart[uNum4].p->max != ts_uart[uNum4].p->now) - { - L0_uartN_set(uNum4,ts_uart[uNum4].p->p[ts_uart[uNum4].p->now]); - ts_uart[uNum4].p->now ++; - } - else - { - ts_uart[uNum4].p->ok = D_ready; - ts_uart[uNum4].p->max = 0; - ts_uart[uNum4].p->now = 0;//可以发送下一个数据 -#if (D_UART4_485_TYPE != TYPE_485_NONE) - D_UART4_485_RX() //切换到接收状态 -#endif - - } - } - //NOP(); NOP(); NOP(); -#endif -} - -