///////////////////////////////////////////////////////////////////////////////
//
// IAR C/C++ Compiler V2.10.4.157 for STM8                10/Aug/2020  13:50:20
// Copyright 2010-2015 IAR Systems AB.
//
//    Source file  =  F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\user.c
//    Command line =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\user.c -e -Ol --no_cse
//        --no_unroll --no_inline --no_code_motion --no_tbaa --no_cross_call
//        --debug --code_model small --data_model medium -o
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\Obj\ --dlib_config
//        E:\IAR\stm8\LIB\dlstm8smf.h -lB
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\inc\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\FWLIB\src\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\radio\ -I
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\SX1278\ --vregs 16
//    List file    =  F:\2-Lora\Code\stm8l151K6T6-WLAN\Debug\List\user.s
//
///////////////////////////////////////////////////////////////////////////////

        EXTERN ?b0
        EXTERN ?b1
        EXTERN ?b14
        EXTERN ?b8
        EXTERN ?b9
        EXTERN ?dec32_l0_l0
        EXTERN ?epilogue_l2_w6
        EXTERN ?inc32_l0_l0
        EXTERN ?load32_0x_l0
        EXTERN ?load32_l0_0x
        EXTERN ?mov_w1_w0
        EXTERN ?mov_w5_w0
        EXTERN ?push_l2
        EXTERN ?push_w6
        EXTERN ?sdiv16_x_x_y
        EXTERN ?w0
        EXTERN ?w1
        EXTERN ?w2
        EXTERN ?w3
        EXTERN ?w4
        EXTERN ?w5
        EXTERN ?w6
        EXTERN BeepCheck
        EXTERN CadDecTime
        EXTERN CycleDetectionTime
        EXTERN DelayMs
        EXTERN DelayTime
        EXTERN DelayTime4s
        EXTERN Delay_2s
        EXTERN FeedWatchDog
        EXTERN HostPCSend
        EXTERN LedStr
        EXTERN LedTest
        EXTERN MotorStr
        EXTERN SX78Str
        EXTERN SX7xTest
        EXTERN Sx1278RxTimeout
        EXTERN Sx1278SleepTime
        EXTERN UartRecLen
        EXTERN UartStr
        EXTERN UartTimeOut
        EXTERN toupper
        EXTERN wireless_init

        PUBLIC ByteToHexStr
        PUBLIC HexStrToByte
        PUBLIC Timer4Deal
        PUBLIC UserTest
        PUBLIC count
        PUBLIC ddd
        PUBLIC test

// F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\user.c
//    1 #include "user.h"

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    2 u8 count = 0;
count:
        DS8 1

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    3 u8 test = 0;
test:
        DS8 1
//    4 

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    5 u8 ddd = 0;
ddd:
        DS8 1

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//    6 void Timer4Deal(void)
//    7 {
//    8     static uint32_t s_1=0,s_2=0,s_4=0,ms_10;
//    9     if(1){if(LedStr.Cnt)LedStr.Cnt--;};
Timer4Deal:
        LDW       X, #LedStr + 1
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_0
        LDW       X, S:?w1
        CPW       X, #0x0
??Timer4Deal_0:
        JREQ      L:??Timer4Deal_1
        LDW       X, #LedStr + 1
        CALL      L:?load32_l0_0x
        CALL      L:?dec32_l0_l0
        LDW       X, #LedStr + 1
        CALL      L:?load32_0x_l0
//   10     if(UARTTEST){if(UartStr.Cnt)UartStr.Cnt--;};
??Timer4Deal_1:
        LDW       X, #UartStr + 1
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_2
        LDW       X, S:?w1
        CPW       X, #0x0
??Timer4Deal_2:
        JREQ      L:??Timer4Deal_3
        LDW       X, #UartStr + 1
        CALL      L:?load32_l0_0x
        CALL      L:?dec32_l0_l0
        LDW       X, #UartStr + 1
        CALL      L:?load32_0x_l0
//   11     if(wireless_init.InitDelay)wireless_init.InitDelay--;
??Timer4Deal_3:
        LDW       X, #wireless_init + 5
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_4
        LDW       X, S:?w1
        CPW       X, #0x0
??Timer4Deal_4:
        JREQ      L:??Timer4Deal_5
        LDW       X, #wireless_init + 5
        CALL      L:?load32_l0_0x
        CALL      L:?dec32_l0_l0
        LDW       X, #wireless_init + 5
        CALL      L:?load32_0x_l0
//   12     if(wireless_init.SendDelay)wireless_init.SendDelay--;
??Timer4Deal_5:
        LDW       X, #wireless_init + 1
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_6
        LDW       X, S:?w1
        CPW       X, #0x0
??Timer4Deal_6:
        JREQ      L:??Timer4Deal_7
        LDW       X, #wireless_init + 1
        CALL      L:?load32_l0_0x
        CALL      L:?dec32_l0_l0
        LDW       X, #wireless_init + 1
        CALL      L:?load32_0x_l0
//   13     if(UartTimeOut)UartTimeOut--;
??Timer4Deal_7:
        LD        A, L:UartTimeOut
        CP        A, #0x0
        JREQ      L:??Timer4Deal_8
        LD        A, L:UartTimeOut
        ADD       A, #0xff
        LD        L:UartTimeOut, A
//   14     if(DelayMs)DelayMs--;
??Timer4Deal_8:
        LDW       X, L:DelayMs
        TNZW      X
        JREQ      L:??Timer4Deal_9
        LDW       X, L:DelayMs
        DECW      X
        LDW       L:DelayMs, X
//   15     s_1++;s_2++;s_4++;ms_10++;
??Timer4Deal_9:
        LDW       X, #??s_1
        CALL      L:?load32_l0_0x
        CALL      L:?inc32_l0_l0
        LDW       X, #??s_1
        CALL      L:?load32_0x_l0
        LDW       X, #??s_2
        CALL      L:?load32_l0_0x
        CALL      L:?inc32_l0_l0
        LDW       X, #??s_2
        CALL      L:?load32_0x_l0
        LDW       X, #??s_4
        CALL      L:?load32_l0_0x
        CALL      L:?inc32_l0_l0
        LDW       X, #??s_4
        CALL      L:?load32_0x_l0
        LDW       X, #??ms_10
        CALL      L:?load32_l0_0x
        CALL      L:?inc32_l0_l0
        LDW       X, #??ms_10
        CALL      L:?load32_0x_l0
//   16     
//   17     if(ms_10>=10)
        LDW       X, #??ms_10
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_10
        LDW       X, S:?w1
        CPW       X, #0xa
??Timer4Deal_10:
        JRC       L:??Timer4Deal_11
//   18     {
//   19          if(UartRecLen)FeedWatchDog();
        LD        A, L:UartRecLen
        CP        A, #0x0
        JREQ      L:??Timer4Deal_12
        CALL      L:FeedWatchDog
//   20          if(CadDecTime)CadDecTime--;
??Timer4Deal_12:
        LD        A, L:CadDecTime
        CP        A, #0x0
        JREQ      L:??Timer4Deal_13
        LD        A, L:CadDecTime
        ADD       A, #0xff
        LD        L:CadDecTime, A
//   21          if(Sx1278RxTimeout)Sx1278RxTimeout--;
??Timer4Deal_13:
        LD        A, L:Sx1278RxTimeout
        CP        A, #0x0
        JREQ      L:??Timer4Deal_14
        LD        A, L:Sx1278RxTimeout
        ADD       A, #0xff
        LD        L:Sx1278RxTimeout, A
//   22          if(Sx1278SleepTime)Sx1278SleepTime--;
??Timer4Deal_14:
        LD        A, L:Sx1278SleepTime
        CP        A, #0x0
        JREQ      L:??Timer4Deal_15
        LD        A, L:Sx1278SleepTime
        ADD       A, #0xff
        LD        L:Sx1278SleepTime, A
//   23          BeepCheck();
??Timer4Deal_15:
        CALL      L:BeepCheck
//   24          if(CycleDetectionTime)CycleDetectionTime--;
        LD        A, L:CycleDetectionTime
        CP        A, #0x0
        JREQ      L:??Timer4Deal_16
        LD        A, L:CycleDetectionTime
        ADD       A, #0xff
        LD        L:CycleDetectionTime, A
//   25          if(MotorStr.delay_ms200)MotorStr.delay_ms200--;
??Timer4Deal_16:
        LD        A, L:MotorStr + 1
        CP        A, #0x0
        JREQ      L:??Timer4Deal_17
        LD        A, L:MotorStr + 1
        ADD       A, #0xff
        LD        L:MotorStr + 1, A
//   26           if(MotorStr.delay_ms500)MotorStr.delay_ms500--;
??Timer4Deal_17:
        LD        A, L:MotorStr + 2
        CP        A, #0x0
        JREQ      L:??Timer4Deal_18
        LD        A, L:MotorStr + 2
        ADD       A, #0xff
        LD        L:MotorStr + 2, A
//   27          SX78Str.SX7xDelay = TRUE;
??Timer4Deal_18:
        MOV       L:SX78Str + 7, #0x1
//   28          ms_10=0;
        LDW       X, #0x0
        LDW       L:??ms_10, X
        LDW       X, #0x0
        LDW       L:??ms_10 + 2, X
//   29     }
//   30     if(s_1>=1000)
??Timer4Deal_11:
        LDW       X, #??s_1
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_19
        LDW       X, S:?w1
        CPW       X, #0x3e8
??Timer4Deal_19:
        JRC       L:??Timer4Deal_20
//   31     {
//   32          if(Delay_2s--);
        LD        A, L:Delay_2s
        ADD       A, #0xff
        LD        L:Delay_2s, A
//   33          if(ddd)ddd--;
        LD        A, L:ddd
        CP        A, #0x0
        JREQ      L:??Timer4Deal_21
        LD        A, L:ddd
        ADD       A, #0xff
        LD        L:ddd, A
//   34          if(DelayTime4s)DelayTime4s--;
??Timer4Deal_21:
        LD        A, L:DelayTime4s
        CP        A, #0x0
        JREQ      L:??Timer4Deal_22
        LD        A, L:DelayTime4s
        ADD       A, #0xff
        LD        L:DelayTime4s, A
//   35          if(MotorStr.motor_delay)MotorStr.motor_delay--;
??Timer4Deal_22:
        LD        A, L:MotorStr
        CP        A, #0x0
        JREQ      L:??Timer4Deal_23
        LD        A, L:MotorStr
        ADD       A, #0xff
        LD        L:MotorStr, A
//   36          s_1=0;if(DelayTime)DelayTime--;
??Timer4Deal_23:
        LDW       X, #0x0
        LDW       L:??s_1, X
        LDW       X, #0x0
        LDW       L:??s_1 + 2, X
        LD        A, L:DelayTime
        CP        A, #0x0
        JREQ      L:??Timer4Deal_20
        LD        A, L:DelayTime
        ADD       A, #0xff
        LD        L:DelayTime, A
//   37     }
//   38     if(s_2>=1000*2)
??Timer4Deal_20:
        LDW       X, #??s_2
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_24
        LDW       X, S:?w1
        CPW       X, #0x7d0
??Timer4Deal_24:
        JRC       L:??Timer4Deal_25
//   39     {
//   40          s_2 = 0;
        LDW       X, #0x0
        LDW       L:??s_2, X
        LDW       X, #0x0
        LDW       L:??s_2 + 2, X
//   41     }
//   42     if(s_4>=1000*4)
??Timer4Deal_25:
        LDW       X, #??s_4
        CALL      L:?load32_l0_0x
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??Timer4Deal_26
        LDW       X, S:?w1
        CPW       X, #0xfa0
??Timer4Deal_26:
        JRC       L:??Timer4Deal_27
//   43     {
//   44          static uint8_t TxSecond60Cnt = 0;
//   45          s_4 = 0;
        LDW       X, #0x0
        LDW       L:??s_4, X
        LDW       X, #0x0
        LDW       L:??s_4 + 2, X
//   46 //                if((TxModel)&&(TxSecond60Cnt++>=2))
//   47 //		{
//   48 //                  static int i = 0;
//   49 //                  GPIO_ToggleBits(GPIOA,GPIO_Pin_5);
//   50 //                  TxSecond60Cnt = 0;
//   51 //                  //uint8_t BUFF[2][25] = {{0x35,0x19,0x13,0x7B,0x05,0x35,0x19,0x06,0x02,0x00,0x56,0x7D},{0x35,0x19,0x13,0x7B,0x05,0x35,0x19,0x06,0x02,0x01,0x57,0x7D}};
//   52 //                  uint8_t BUFF[2][25] = {{0x35,0x19,0x13,0x7B,0x04,0x35,0x19,0x03,0xFF,0x50,0x7D},{0x35,0x19,0x13,0x7B,0x04,0x35,0x19,0x03,0xFF,0x50,0x7D}};
//   53 //				SX78Str.SX7xTxFlag = TRUE;
//   54 //				SX78Str.SX7xCmd = CmdTX;
//   55 //				memcpy(SX78Str.SX7xTxStr,BUFF[i++],SX78Str.SX7xTxlen = 11*sizeof(uint8_t));
//   56 //                                if(i>=2)i=0;
//   57 //		}
//   58     }
//   59 }
??Timer4Deal_27:
        RET

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??s_1:
        DS8 4

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??s_2:
        DS8 4

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??s_4:
        DS8 4

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
??ms_10:
        DS8 4
//   60 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   61 void UserTest(void)
//   62 {
//   63      FeedWatchDog();
UserTest:
        CALL      L:FeedWatchDog
//   64      SX7xTest(&SX78Str.SX7xCmd);
        LDW       X, #SX78Str + 8
        CALL      L:SX7xTest
//   65      LedTest();
        CALL      L:LedTest
//   66      HostPCSend();
        JP        L:HostPCSend
//   67 }
//   68 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   69 void ByteToHexStr(const unsigned char* source, char* dest, int sourceLen)
//   70 {
ByteToHexStr:
        LDW       S:?w3, X
        LDW       S:?w2, Y
        CALL      L:?mov_w1_w0
//   71 	short i;
//   72 	unsigned char highByte, lowByte;
//   73 	for (i = 0; i < sourceLen; i++)
        CLRW      Y
        JRA       L:??ByteToHexStr_0
//   74 	{
//   75 		highByte = source[i] >> 4;
//   76 		lowByte = source[i] & 0x0f;
//   77 
//   78 		highByte += 0x30;
//   79 
//   80 		if (highByte > 0x39)
//   81 			dest[i * 2] = highByte + 0x07;
//   82 		else
//   83 			dest[i * 2] = highByte;
//   84 
//   85 		lowByte += 0x30;
//   86 		if (lowByte > 0x39)
//   87 			dest[i * 2 + 1] = lowByte + 0x07;
//   88 		else
//   89 			dest[i * 2 + 1] = lowByte;
??ByteToHexStr_1:
        LDW       X, Y
        SLLW      X
        ADDW      X, S:?w2
        INCW      X
        LD        A, S:?b0
        LD        (X), A
??ByteToHexStr_2:
        LDW       X, Y
        INCW      X
        LDW       Y, X
??ByteToHexStr_0:
        CPW       Y, S:?w1
        JRSGE     L:??ByteToHexStr_3
        LDW       X, Y
        ADDW      X, S:?w3
        LD        A, (X)
        SWAP      A
        AND       A, #0xf
        LD        S:?b1, A
        LDW       X, Y
        ADDW      X, S:?w3
        LD        A, (X)
        AND       A, #0xf
        LD        S:?b0, A
        LD        A, S:?b1
        ADD       A, #0x30
        LD        S:?b1, A
        LD        A, S:?b1
        CP        A, #0x3a
        JRC       L:??ByteToHexStr_4
        LDW       X, Y
        SLLW      X
        ADDW      X, S:?w2
        LD        A, S:?b1
        ADD       A, #0x7
        LD        (X), A
        JRA       L:??ByteToHexStr_5
??ByteToHexStr_4:
        LDW       X, Y
        SLLW      X
        ADDW      X, S:?w2
        LD        A, S:?b1
        LD        (X), A
??ByteToHexStr_5:
        LD        A, S:?b0
        ADD       A, #0x30
        LD        S:?b0, A
        LD        A, S:?b0
        CP        A, #0x3a
        JRC       L:??ByteToHexStr_1
        LDW       X, Y
        SLLW      X
        ADDW      X, S:?w2
        INCW      X
        LD        A, S:?b0
        ADD       A, #0x7
        LD        (X), A
        JRA       L:??ByteToHexStr_2
//   90 	}
//   91 	return;
??ByteToHexStr_3:
        RET
//   92 }

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   93 void HexStrToByte(const char* source, unsigned char* dest, int sourceLen)
//   94 {
HexStrToByte:
        CALL      L:?push_l2
        CALL      L:?push_w6
        PUSH      S:?b14
        PUSHW     X
        LDW       S:?w6, Y
        CALL      L:?mov_w5_w0
//   95 	short i;
//   96 	unsigned char highByte, lowByte;
//   97 	for (i = 0; i < sourceLen; i += 2)
        CLR       S:?b9
        CLR       S:?b8
        JRA       L:??HexStrToByte_0
//   98 	{
//   99 		highByte = toupper(source[i]);
//  100 		lowByte = toupper(source[i + 1]);
//  101 
//  102 		if (highByte > 0x39)
//  103 			highByte -= 0x37;
//  104 		else
//  105 			highByte -= 0x30;
//  106 
//  107 		if (lowByte > 0x39)
//  108 			lowByte -= 0x37;
//  109 		else
//  110 			lowByte -= 0x30;
??HexStrToByte_1:
        LD        A, S:?b0
        ADD       A, #0xd0
        LD        S:?b0, A
//  111 
//  112 		dest[i / 2] = (highByte << 4) | lowByte;
??HexStrToByte_2:
        LD        A, S:?b14
        SWAP      A
        AND       A, #0xf0
        OR        A, S:?b0
        LDW       Y, #0x2
        LDW       X, S:?w4
        CALL      L:?sdiv16_x_x_y
        ADDW      X, S:?w6
        LD        (X), A
        LDW       X, S:?w4
        ADDW      X, #0x2
        LDW       S:?w4, X
??HexStrToByte_0:
        LDW       X, S:?w4
        CPW       X, S:?w5
        JRSGE     L:??HexStrToByte_3
        LDW       X, S:?w4
        ADDW      X, (0x1,SP)
        LD        A, (X)
        CLRW      X
        LD        XL, A
        CALL      L:toupper
        EXG       A, XL
        LD        S:?b14, A
        EXG       A, XL
        LDW       X, S:?w4
        ADDW      X, (0x1,SP)
        INCW      X
        LD        A, (X)
        CLRW      X
        LD        XL, A
        CALL      L:toupper
        EXG       A, XL
        LD        S:?b0, A
        EXG       A, XL
        LD        A, S:?b14
        CP        A, #0x3a
        JRC       L:??HexStrToByte_4
        LD        A, S:?b14
        ADD       A, #0xc9
        LD        S:?b14, A
        JRA       L:??HexStrToByte_5
??HexStrToByte_4:
        LD        A, S:?b14
        ADD       A, #0xd0
        LD        S:?b14, A
??HexStrToByte_5:
        LD        A, S:?b0
        CP        A, #0x3a
        JRC       L:??HexStrToByte_1
        LD        A, S:?b0
        ADD       A, #0xc9
        LD        S:?b0, A
        JRA       L:??HexStrToByte_2
//  113 	}
//  114 	return;
??HexStrToByte_3:
        ADD       SP, #0x2
        POP       S:?b14
        JP        L:?epilogue_l2_w6
//  115 }

        SECTION VREGS:DATA:REORDER:NOROOT(0)

        END
// 
//  19 bytes in section .near.bss
// 795 bytes in section .near_func.text
// 
// 795 bytes of CODE memory
//  19 bytes of DATA memory
//
//Errors: none
//Warnings: 2
