C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 1 C51 COMPILER V9.54, COMPILATION OF MODULE MSP_UARTN OBJECT MODULE PLACED IN ..\out\msp_uartN.obj COMPILER INVOKED BY: E:\KeilC51\C51\BIN\C51.EXE ..\source\msp\uart\msp_uartN.c LARGE OMF2 OPTIMIZE(0,SIZE) BROWSE ORDER -NOINTPROMOTE INCDIR(..\source\bsp;..\source\msp;..\source\app;..\source\clib;..\source\cpu;..\source\ctask;..\source\tpc -;..\source\asp;..\source\debug;..\source\msp\uart;..\source\msp\simiic;..\source\bsp\oled;..\source\bsp\TTSSbsp) DEBUG P -RINT(..\out\msp_uartN.lst) TABS(2) OBJECT(..\out\msp_uartN.obj) line level source 1 ////////////////////////////////////////////////////////////////////////// 2 /// COPYRIGHT NOTICE 3 /// Copyright (c) 2023 CCSENS 4 /// All rights reserved. 5 /// 6 /// @file main.c 7 /// @brief main app 8 /// 9 ///(本文件实现的功能的详述) 10 /// 11 /// @version 1.1 CCsens technology 12 /// @author CC 13 /// @date 20150102 14 /// 15 /// 16 /// 修订说明:最初版本 17 /// Modified by: 18 /// Modified date: 19 /// Version: 20 /// Descriptions: 21 // 20160413 CC-ACC-VH02 22 23 /***************************************************************************** 24 update by cc @20220305 25 26 27 28 针对多串口 和 单一串口 有区别 每个串口是独立的还是分开的有讲究 程序是复 -的还是软件应用简单是 29 个需要平衡的事情. 30 31 clib/clib.c: 32 公用的函数 和硬件无关 33 放置串行模式(串口等其他通讯总线类的输出)输出的函数, 34 一些覆盖模式输出的(lcd等固屏输出的)的也可使用 35 void Lc_print(void (*L0pf_send_uc)(char ww), char *dat,...) 36 ----------------------------------------------------------------------------------------- 37 38 app 39 asp 40 bsp 41 42 debug 选择哪个串口作为debug协议的通讯 43 44 ----------------------------------------------------------------------------------------- 45 46 ----------------------------------------------------------------------------------------- 47 tpc/: 接收到的数据放入到指向特定协议的缓存中,和协议的格式有关 一般分为 -头式或者标尾式 48 公用的串口通讯定义 49 struct _s_uart_rec_ 的公共协议包(关键的结构体)的声明------struct _s_uart_rec_ 50 void L1_uart_2buf(struct _s_uart_rec_ *p)串行数据保存到指向特定协议的缓冲中 C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 2 51 52 -------------------------------------------------------------------------------------------- 53 msp/msp_uartx.c 54 55 56 57 58 59 -------------------------------------------------------------------------------------------- 60 msp/msp_uart0.c 底层代码 和cpu相关 缓存发送也放在里面 61 L0_UART0_Init 62 UART0_IRQHandler 63 L0_Usend_uc------UserDef 64 ----------------------------------------------------------------------------------------- 65 ********************************************************************************/ 66 67 #include "msp_uartN.h" *** WARNING C320 IN LINE 51 OF ..\source\bsp\TTSSbsp\bsp_config.h: "MainFre_22M" 68 69 TS_Uart_Send_ ts_Usend[SERIAL_MAX_NUM]= {0}; 70 TS_send_buf_ ts_Usendbuf; 71 72 TS_rec_road_ ts_Urec[SERIAL_MAX_NUM]= {0}; 73 TS_rec_buf_ ts_Urecbuf; 74 code vU16 S_send_max[4]= 75 { 76 D_send1_max, 77 D_send2_max, 78 D_send3_max, 79 D_send4_max 80 }; 81 82 void L0_uartN_set(U8 uartx,U8 x) 83 { 84 1 switch(uartx) 85 1 { 86 2 case 0: 87 2 SBUF = (x); 88 2 break; 89 2 case 1: 90 2 S2BUF = (x);/// 91 2 break; 92 2 case 2: 93 2 S3BUF = (x); 94 2 break; 95 2 case 3: 96 2 S4BUF = (x); 97 2 break; 98 2 default:break; 99 2 } 100 1 } 101 /* 102 void L0_waitFree_uartN888(U8 uartx) 103 { 104 ts_Usend[uartx].over = 0; 105 while(ts_Usend[uartx].now != 0) 106 { 107 #if 10 //发送数据特别快时,某些情况下会导致数据发送出错 108 if(ts_Usend[uartx].over ++ > 600000)///这样写居然出错 109 110 {////ts_uart[uartx].p->ok = D_ready; 111 C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 3 112 ts_Usend[uartx].now = 0; 113 break; 114 } 115 #endif 116 } 117 } 118 */ 119 120 void L0_waitFree_uartN(U8 uartx) 121 { 122 1 ts_Usend[uartx].over = 0; 123 1 while(ts_Usend[uartx].now != 0) 124 1 { 125 2 #if 10 //发送数据特别快时,某些情况下会导致数据发送出错 126 2 /// if(ts_uart[uartx].p->over ++ > 600000)///这样写居然出错(vU32) 127 2 ts_Usend[uartx].over ++; 128 2 if(ts_Usend[uartx].over > 20000)////600 000--4s 129 2 {////ts_uart[uartx].p->ok = D_ready; 130 3 ts_Usend[uartx].max = ts_Usend[uartx].now; 131 3 ts_Usend[uartx].ok = D_ready; 132 3 // ts_Usend[uartx].over = 0; 133 3 // ts_Usend[uartx].now = 1; 134 3 ts_Usend[uartx].now = 0; 135 3 break; 136 3 } 137 2 #endif 138 2 } 139 1 } 140 141 #define D_485R 0 142 #define D_485S 1 143 144 145 void L0_uartN_485(U8 uartx,U8 x) 146 { 147 1 if (D_485R == x) 148 1 { 149 2 switch(uartx) 150 2 { 151 3 case 0: 152 3 // D_UART1_485_RX(); 153 3 break; 154 3 case 1: 155 3 break; 156 3 case 2: 157 3 break; 158 3 case 3: 159 3 //// D_UART4_485_RX(); 160 3 break; 161 3 default:break; 162 3 } 163 2 }else 164 1 { 165 2 switch(uartx) 166 2 { 167 3 case 0: 168 3 // D_UART1_485_TX(); 169 3 break; 170 3 case 1: 171 3 break; 172 3 case 2: 173 3 break; C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 4 174 3 case 3: 175 3 //// D_UART4_485_TX(); 176 3 break; 177 3 default:break; 178 3 } 179 2 } 180 1 181 1 } 182 183 void L0_uartN_Array(U8 uartx,void *buf,U16 len) 184 { 185 1 u16 i; 186 1 187 1 L0_waitFree_uartN(uartx); 188 1 189 1 L0_uartN_485(uartx,D_485S); 190 1 ts_Usend[uartx].ok = D_ready; 191 1 ts_Usend[uartx].over = 0; 192 1 ts_Usend[uartx].now = 1; 193 1 if (len > ts_Usend[uartx].max_def) 194 1 { 195 2 len = ts_Usend[uartx].max_def - 1; 196 2 } 197 1 ts_Usend[uartx].max = len; 198 1 //将参数buf拷贝至内部buf 199 1 for(i = 0;i < len;i ++) 200 1 { 201 2 ts_Usend[uartx].sbuf[i] = ((U8*)buf)[i]; 202 2 } 203 1 L0_uartN_set(uartx,ts_Usend[uartx].sbuf[0]); 204 1 } 205 206 207 void L0_uartN_Arraylong(U8 uartx,U8 *buf,U16 usStart,U16 usEnd) 208 { 209 1 //L0_uart0_sendbuf(str,strlen(str)); 210 1 U16 t; 211 1 t = usEnd-usStart; 212 1 t ++; 213 1 L0_uartN_Array(uartx,&buf[usStart],t); 214 1 } 215 216 217 void L0_uartN_uc(U8 uartx,U8 ww) 218 { 219 1 L0_uartN_Array(uartx,&ww,1); 220 1 } 221 222 void L0_uartN_us(U8 uartx,vU16 ww) 223 { 224 1 U_U16 uStemp; 225 1 uStemp.word = ww; 226 1 ts_Usend[uartx].buf3[0] = uStemp.BYTE2.h; 227 1 ts_Usend[uartx].buf3[1] = uStemp.BYTE2.l; 228 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2); 229 1 } 230 231 void L0_uartN_ul(U8 uartx,vU32 ww) 232 { 233 1 U_U32 uStemp; 234 1 L0_waitFree_uartN(uartx); 235 1 uStemp.dWord = ww; C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 5 236 1 ts_Usend[uartx].buf3[0] = uStemp.BYTE4.byte0; 237 1 ts_Usend[uartx].buf3[1] = uStemp.BYTE4.byte1; 238 1 ts_Usend[uartx].buf3[2] = uStemp.BYTE4.byte2; 239 1 ts_Usend[uartx].buf3[3] = uStemp.BYTE4.byte3; 240 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,4); 241 1 } 242 243 void L0_uartN_0d0a(U8 uartx) 244 { 245 1 L0_waitFree_uartN(uartx); 246 1 ts_Usend[uartx].buf3[0] = 0x0d; 247 1 ts_Usend[uartx].buf3[1] = 0x0a; 248 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2); 249 1 } 250 251 void L0_uartN_uchex(U8 uartx,U8 ww) 252 { 253 1 L0_waitFree_uartN(uartx); 254 1 ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(ww)][1]; 255 1 ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (ww)][1]; 256 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,2); 257 1 } 258 259 void L0_uartN_ushex(U8 uartx,vU16 ww) 260 { 261 1 U_F16 k; 262 1 L0_waitFree_uartN(uartx); 263 1 k.us = ww; 264 1 ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(k.BYTE2.H)][1]; 265 1 ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (k.BYTE2.H)][1]; 266 1 ts_Usend[uartx].buf3[2] = cguHex2Char[D_uc_high(k.BYTE2.L)][1]; 267 1 ts_Usend[uartx].buf3[3] = cguHex2Char[D_uc_low (k.BYTE2.L)][1]; 268 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,4); 269 1 } 270 271 void L0_uartN_ulhex(U8 uartx,U32 ww) 272 { 273 1 U_U32 k; 274 1 L0_waitFree_uartN(uartx); 275 1 k.dWord = ww; 276 1 ts_Usend[uartx].buf3[0] = cguHex2Char[D_uc_high(k.BYTE4.byte0)][1]; 277 1 ts_Usend[uartx].buf3[1] = cguHex2Char[D_uc_low (k.BYTE4.byte0)][1]; 278 1 ts_Usend[uartx].buf3[2] = cguHex2Char[D_uc_high(k.BYTE4.byte1)][1]; 279 1 ts_Usend[uartx].buf3[3] = cguHex2Char[D_uc_low (k.BYTE4.byte1)][1]; 280 1 ts_Usend[uartx].buf3[4] = cguHex2Char[D_uc_high(k.BYTE4.byte2)][1]; 281 1 ts_Usend[uartx].buf3[5] = cguHex2Char[D_uc_low (k.BYTE4.byte2)][1]; 282 1 ts_Usend[uartx].buf3[6] = cguHex2Char[D_uc_high(k.BYTE4.byte3)][1]; 283 1 ts_Usend[uartx].buf3[7] = cguHex2Char[D_uc_low (k.BYTE4.byte3)][1]; 284 1 L0_uartN_Array(uartx,ts_Usend[uartx].buf3,8); 285 1 } 286 287 void L0_uartN_str(U8 uartx,U8 *str) 288 { 289 1 L0_uartN_Array(uartx,str,Lc_strlen(str)); 290 1 } 291 292 void L0_uartN_uchexArray(U8 uartx,vU8 *buf,U16 n) 293 { 294 1 int i; 295 1 for(i=0;i>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>//withoutbuf>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> 319 320 void L0_uartN_sbuf(U8 uartx)/////cc 2023/04/23--4:23:19 修正bug 调用时放到ts_Usend[uartx].max 复 -的前面 321 { 322 1 ts_Usend[uartx].max = 0; 323 1 ts_Usend[uartx].now = 0; 324 1 ts_Usend[uartx].ok = D_ready; 325 1 ts_Usend[uartx].max_def = S_send_max[uartx]; 326 1 switch(uartx) 327 1 { 328 2 case 0: 329 2 ts_Usend[uartx].sbuf = ts_Usendbuf.s1; 330 2 break; 331 2 case 1: 332 2 ts_Usend[uartx].sbuf = ts_Usendbuf.s2; 333 2 break; 334 2 case 2: 335 2 ts_Usend[uartx].sbuf = ts_Usendbuf.s3; 336 2 break; 337 2 case 3: 338 2 ts_Usend[uartx].sbuf = ts_Usendbuf.s4; 339 2 break; 340 2 default:break; 341 2 } 342 1 } 343 344 ////使用内置的usend buf的发送 cc 2023/04/23--4:25:8 调用的时候不可使用本通道的缓 - 345 void L0_uartN_Array_withoutbuf(U8 uartx,U16 len) 346 { 347 1 /// u16 i; 348 1 L0_waitFree_uartN(uartx); 349 1 350 1 L0_uartN_485(uartx,D_485S); 351 1 L0_uartN_sbuf(uartx); 352 1 353 1 if (len > ts_Usend[uartx].max_def) 354 1 { 355 2 len = ts_Usend[uartx].max_def - 1; 356 2 } 357 1 ts_Usend[uartx].max = len; C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 7 358 1 ts_Usend[uartx].now = 1; 359 1 L0_uartN_set(uartx,ts_Usend[uartx].sbuf[0]); 360 1 } 361 362 ///cc 2023/04/23--4:25:8 调用的时候不可使用本通道的缓存 363 void L0_uartN_Arrayhex_withoutbuf(U8 uartx,vU8 *buf,U16 len) 364 { 365 1 vU16 i;vU16 t; 366 1 367 1 L0_waitFree_uartN(uartx); 368 1 L0_uartN_sbuf(uartx); 369 1 if (len > (ts_Usend[uartx].max_def/3)) 370 1 { 371 2 len = ts_Usend[uartx].max_def/3 - 1; 372 2 } 373 1 for(i = 0;i < len;i ++) 374 1 { 375 2 376 2 t = i * 3; 377 2 ts_Usend[uartx].sbuf[t] = cguHex2Char[D_uc_high(buf[i])][1];/// 34 '3'--33 378 2 t ++; 379 2 ts_Usend[uartx].sbuf[t] = cguHex2Char[D_uc_low (buf[i])][1];/// 34 '3'--33 380 2 t ++; 381 2 ts_Usend[uartx].sbuf[t] = ' '; 382 2 t ++; 383 2 384 2 } 385 1 // len 2 11x 22x \0 386 1 ts_Usend[uartx].sbuf[t] = ' '; 387 1 t++; 388 1 ts_Usend[uartx].sbuf[t] = 0x00; 389 1 L0_uartN_Array_withoutbuf(uartx,t-1); 390 1 391 1 } 392 393 394 395 396 397 398 399 400 401 402 403 404 405 MODULE INFORMATION: STATIC OVERLAYABLE CODE SIZE = 3362 ---- CONSTANT SIZE = 8 ---- XDATA SIZE = 392 ---- PDATA SIZE = ---- ---- DATA SIZE = ---- ---- IDATA SIZE = ---- ---- BIT SIZE = ---- ---- EDATA SIZE = ---- ---- HDATA SIZE = ---- ---- XDATA CONST SIZE = ---- ---- FAR CONST SIZE = ---- ---- C51 COMPILER V9.54 MSP_UARTN 09/06/2024 14:32:50 PAGE 8 END OF MODULE INFORMATION. C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)