///////////////////////////////////////////////////////////////////////////////
//
// IAR C/C++ Compiler V2.10.4.157 for STM8                10/Aug/2020  13:50:19
// Copyright 2010-2015 IAR Systems AB.
//
//    Source file  =  F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\parameter.c
//    Command line =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\USER\parameter.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\parameter.s
//
///////////////////////////////////////////////////////////////////////////////

        EXTERN ?b0
        EXTERN ?b12
        EXTERN ?b13
        EXTERN ?b3
        EXTERN ?epilogue_l2
        EXTERN ?epilogue_l2_l3
        EXTERN ?epilogue_l2_w6
        EXTERN ?inc32_l2_l2
        EXTERN ?load32_0x_l0
        EXTERN ?load32_l0_0x
        EXTERN ?mov_l0_l2
        EXTERN ?mov_l2_l0
        EXTERN ?mov_w0_w5
        EXTERN ?move1616_v_x_y_a
        EXTERN ?mul32_l0_l0_0x
        EXTERN ?push_l2
        EXTERN ?push_l3
        EXTERN ?push_w6
        EXTERN ?sext32_l0_x
        EXTERN ?srl32_l0_l0_db
        EXTERN ?sub32_l0_l0_dl
        EXTERN ?w0
        EXTERN ?w1
        EXTERN ?w4
        EXTERN ?w5
        EXTERN ?w6
        EXTERN ?w7
        EXTERN FLASH_EraseByte
        EXTERN FLASH_Lock
        EXTERN FLASH_ProgramByte
        EXTERN FLASH_ReadByte
        EXTERN FLASH_Unlock
        EXTERN FLASH_WaitForLastOperation
        EXTERN LoraPara
        EXTERN memcpy

        PUBLIC EEPROM_Erase
        PUBLIC EEPROM_ReadByte
        PUBLIC EEPROM_WriteByte
        PUBLIC FixedParaChange
        PUBLIC FixedParaDeal
        PUBLIC LoraChannel
        PUBLIC LoraParaRead
        PUBLIC SystemPara
        PUBLIC temp4

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

        SECTION `.near.data`:DATA:REORDER:NOROOT(0)
//    2 PARAMETER SystemPara = PARA_DEFAULT;
SystemPara:
        DC8 1, 53, 25, 19, 7, 0, 249, 19, 7, 0, 0, 1, 0, 0, 0, 0, 0, 1, 3, 4
        DC8 112, 0, 10, 10, 0, 0, 0, 0, 0, 0, 1, 116, 1, 116, 2, 0, 7, 101, 3
        DC8 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
//    3 

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//    4 uint32_t LoraChannel = 0;
LoraChannel:
        DS8 4
//    5 void LoraParaRead(void)
//    6 {
//    7 
//    8     LoraPara.RxSF = SystemPara.LockID[3]/10 + 0x07;
//    9     LoraPara.RxBW = SystemPara.LockID[3]%10;
//   10 
//   11     if(LoraPara.RxSF>12)LoraPara.RxSF = 0x07;
//   12     if(LoraPara.RxBW>9)LoraPara.RxBW = 0x07;
//   13 
//   14     if(SystemPara.LockID[2]>83)SystemPara.LockID[2] = 23;
//   15     LoraChannel = SystemPara.LockID[2] + 410;
//   16     LoraChannel *= 1024*16;
//   17     LoraPara.RxChannel[0] = (uint8_t)(LoraChannel);
//   18     LoraPara.RxChannel[1] = (uint8_t)(LoraChannel>>8);
//   19     LoraChannel = LoraChannel>>8;
//   20     LoraPara.RxChannel[2] = (uint8_t)(LoraChannel>>8);
//   21 
//   22     LoraPara.TxSF = SystemPara.PcID[3]/10 + 0x07;
//   23     LoraPara.TxBW = SystemPara.PcID[3]%10;
//   24     if(LoraPara.TxSF>12)LoraPara.TxSF = 0x07;
//   25     if(LoraPara.TxBW>9)LoraPara.TxBW = 0x07;
//   26 
//   27     
//   28     /*********************************************/
//   29     //设置为固定值SF=11,BW=125K
//   30     LoraPara.RxSF = 0x08;
//   31     LoraPara.RxBW = 0x07;
//   32     LoraPara.TxSF = 0x08;
//   33     LoraPara.TxBW = 0x07;
//   34      /*********************************************/
//   35     
//   36     if(SystemPara.PcID[2]>93)SystemPara.PcID[2] = 89;
//   37     LoraChannel = SystemPara.PcID[2] + 410;
//   38     LoraChannel *= 1024*16;
//   39     LoraPara.TxChannel[0] = (uint8_t)(LoraChannel);
//   40     LoraPara.TxChannel[1] = (uint8_t)(LoraChannel>>8);
//   41     LoraChannel = LoraChannel>>8;
//   42     LoraPara.TxChannel[2] = (uint8_t)(LoraChannel>>8);
//   43     
//   44     //由于是网关，所以需要交换一下值
//   45     uint8_t temp[3] = 0;
//   46     memcpy(temp,LoraPara.TxChannel,3*sizeof(uint8_t));
//   47     memcpy(LoraPara.TxChannel,LoraPara.RxChannel,3*sizeof(uint8_t));
//   48     memcpy(LoraPara.RxChannel,temp,3*sizeof(uint8_t));
//   49 
//   50 }

        SECTION `.near.data`:DATA:REORDER:NOROOT(0)
//   51 PARAMETER temp4 = PARA_DEFAULT;
temp4:
        DC8 1, 53, 25, 19, 7, 0, 249, 19, 7, 0, 0, 1, 0, 0, 0, 0, 0, 1, 3, 4
        DC8 112, 0, 10, 10, 0, 0, 0, 0, 0, 0, 1, 116, 1, 116, 2, 0, 7, 101, 3
        DC8 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0

        SECTION `.near_func.text`:CODE:NOROOT(0)
        CODE
FixedParaDeal:
        LDW       Y, L:??n
        LDW       X, #SystemPara
        PUSHW     X
        LDW       X, #0x1000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        POPW      X
        CALL      L:EEPROM_ReadByte
        LD        A, L:SystemPara
        CP        A, #0x0
        JRNE      L:??FixedParaDeal_0
        LDW       Y, L:??n
        LDW       X, #temp4
        PUSHW     X
        LDW       X, #0x1000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        POPW      X
        CALL      L:EEPROM_WriteByte
        JP        L:LoraParaRead
??FixedParaDeal_0:
        LDW       X, #0xd
        LDW       S:?w0, X
        LDW       Y, #SystemPara
        LDW       X, #temp4
        CALL      L:memcpy
        MOV       L:temp4, #0x1
        REQUIRE LoraParaRead
        ;               // Fall through to label LoraParaRead

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
LoraParaRead:
        SUB       SP, #0x3
        LD        A, L:SystemPara + 4
        MOV       S:?b0, #0xa
        CLRW      X
        LD        XL, A
        LD        A, S:?b0
        DIV       X, A
        LD        A, XL
        ADD       A, #0x7
        LD        L:LoraPara, A
        LD        A, L:SystemPara + 4
        MOV       S:?b0, #0xa
        CLRW      X
        LD        XL, A
        LD        A, S:?b0
        DIV       X, A
        LD        L:LoraPara + 1, A
        LD        A, L:LoraPara
        CP        A, #0xd
        JRC       L:??LoraParaRead_0
        MOV       L:LoraPara, #0x7
??LoraParaRead_0:
        LD        A, L:LoraPara + 1
        CP        A, #0xa
        JRC       L:??LoraParaRead_1
        MOV       L:LoraPara + 1, #0x7
??LoraParaRead_1:
        LD        A, L:SystemPara + 3
        CP        A, #0x54
        JRC       L:??LoraParaRead_2
        MOV       L:SystemPara + 3, #0x17
??LoraParaRead_2:
        LD        A, L:SystemPara + 3
        CLRW      X
        LD        XL, A
        ADDW      X, #0x19a
        CALL      L:?sext32_l0_x
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #0x4000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        LDW       X, #LoraChannel
        CALL      L:?mul32_l0_l0_0x
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LD        A, S:?b3
        LD        L:LoraPara + 3, A
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LDW       X, S:?w1
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        L:LoraPara + 4, A
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        CALL      L:?srl32_l0_l0_db
        DATA
        DC8       0x8
        CODE
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LDW       X, S:?w1
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        L:LoraPara + 5, A
        LD        A, L:SystemPara + 8
        MOV       S:?b0, #0xa
        CLRW      X
        LD        XL, A
        LD        A, S:?b0
        DIV       X, A
        LD        A, XL
        ADD       A, #0x7
        LD        L:LoraPara + 6, A
        LD        A, L:SystemPara + 8
        MOV       S:?b0, #0xa
        CLRW      X
        LD        XL, A
        LD        A, S:?b0
        DIV       X, A
        LD        L:LoraPara + 7, A
        LD        A, L:LoraPara + 6
        CP        A, #0xd
        JRC       L:??LoraParaRead_3
        MOV       L:LoraPara + 6, #0x7
??LoraParaRead_3:
        LD        A, L:LoraPara + 7
        CP        A, #0xa
        JRC       L:??LoraParaRead_4
        MOV       L:LoraPara + 7, #0x7
??LoraParaRead_4:
        MOV       L:LoraPara, #0x8
        MOV       L:LoraPara + 1, #0x7
        MOV       L:LoraPara + 6, #0x8
        MOV       L:LoraPara + 7, #0x7
        LD        A, L:SystemPara + 7
        CP        A, #0x5e
        JRC       L:??LoraParaRead_5
        MOV       L:SystemPara + 7, #0x59
??LoraParaRead_5:
        LD        A, L:SystemPara + 7
        CLRW      X
        LD        XL, A
        ADDW      X, #0x19a
        CALL      L:?sext32_l0_x
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #0x4000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        LDW       X, #LoraChannel
        CALL      L:?mul32_l0_l0_0x
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LD        A, S:?b3
        LD        L:LoraPara + 9, A
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LDW       X, S:?w1
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        L:LoraPara + 10, A
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        CALL      L:?srl32_l0_l0_db
        DATA
        DC8       0x8
        CODE
        LDW       X, #LoraChannel
        CALL      L:?load32_0x_l0
        LDW       X, #LoraChannel
        CALL      L:?load32_l0_0x
        LDW       X, S:?w1
        CLR       A
        RRWA      X, A
        LD        A, XL
        LD        L:LoraPara + 11, A
        LDW       Y, #?_0
        LDW       X, SP
        ADDW      X, #0x1
        PUSHW     X
        LD        A, #0x3
        CALL      L:?move1616_v_x_y_a
        POPW      X
        LDW       X, #0x3
        LDW       S:?w0, X
        LDW       Y, #LoraPara + 9
        LDW       X, SP
        ADDW      X, #0x1
        CALL      L:memcpy
        LDW       X, #0x3
        LDW       S:?w0, X
        LDW       Y, #LoraPara + 3
        LDW       X, #LoraPara + 9
        CALL      L:memcpy
        LDW       X, #0x3
        LDW       S:?w0, X
        LDW       Y, SP
        ADDW      Y, #0x1
        LDW       X, #LoraPara + 3
        CALL      L:memcpy
        ADD       SP, #0x3
        RET
//   52 void FixedParaDeal(void)
//   53 {

        SECTION `.near.data`:DATA:REORDER:NOROOT(0)
//   54     static int n = sizeof(PARAMETER);
??n:
        DC16 59
//   55 
//   56     EEPROM_ReadByte(PARAM_ADDR,(uint8_t *)(&SystemPara),n);
//   57     if(SystemPara.FixedPara==0)
//   58     {
//   59         EEPROM_WriteByte(PARAM_ADDR,(uint8_t *)(&temp4),n);
//   60     }
//   61     else
//   62     {
//   63         memcpy(&temp4,&SystemPara,13*sizeof(uint8_t));
//   64         temp4.FixedPara = 1;
//   65         //EEPROM_WriteByte(PARAM_ADDR,(uint8_t *)(&temp4),n);
//   66     }
//   67     LoraParaRead();
//   68 
//   69 }
//   70 
//   71 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   72 void FixedParaChange(bool State)//State=1 修改参数,修改完毕后读出，State=0 不变
//   73 {
FixedParaChange:
        CALL      L:?push_l2
        SUB       SP, #0x3b
//   74     if(State!=TRUE)return;
        CP        A, #0x1
        JRNE      L:??FixedParaChange_0
//   75     int n = sizeof(PARAMETER),t = (&SystemPara.PhoResBase[3]-&SystemPara.VariablePara);
        LDW       X, #0x3b
        LDW       S:?w4, X
        LDW       X, #0x29
        LDW       S:?w5, X
//   76     PARAMETER temp2;
//   77     EEPROM_ReadByte(PARAM_ADDR,(uint8_t *)(&temp2),n);
        LDW       Y, S:?w4
        LDW       X, SP
        ADDW      X, #0x1
        PUSHW     X
        LDW       X, #0x1000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        POPW      X
        CALL      L:EEPROM_ReadByte
//   78     //if((memcmp(&SystemPara.VariablePara,&temp2.VariablePara,t*sizeof(uint8_t)))!=NULL)
//   79     {
//   80         memcpy(&SystemPara.VariablePara,&temp2.VariablePara,t*sizeof(uint8_t));
        CALL      L:?mov_w0_w5
        LDW       Y, SP
        ADDW      Y, #0x12
        LDW       X, #SystemPara + 17
        CALL      L:memcpy
//   81         EEPROM_WriteByte(PARAM_ADDR,(uint8_t *)(&SystemPara),n);
        LDW       Y, S:?w4
        LDW       X, #SystemPara
        PUSHW     X
        LDW       X, #0x1000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        POPW      X
        CALL      L:EEPROM_WriteByte
//   82     }
//   83     EEPROM_ReadByte(PARAM_ADDR,(uint8_t *)(&SystemPara),n);
        LDW       Y, S:?w4
        LDW       X, #SystemPara
        PUSHW     X
        LDW       X, #0x1000
        LDW       S:?w1, X
        CLRW      X
        LDW       S:?w0, X
        POPW      X
        CALL      L:EEPROM_ReadByte
//   84     LoraParaRead();
        CALL      L:LoraParaRead
//   85 }
??FixedParaChange_0:
        ADD       SP, #0x3b
        JP        L:?epilogue_l2
//   86 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   87 void EEPROM_ReadByte(u32 addr, u8 *buf, u16 len)
//   88 {
EEPROM_ReadByte:
        CALL      L:?push_l2
        CALL      L:?push_l3
        PUSHW     X
        CALL      L:?mov_l2_l0
        LDW       S:?w7, Y
//   89     u16 i;
//   90     if (addr<0x00001000 || addr>0x000013FF)
        CALL      L:?mov_l0_l2
        CALL      L:?sub32_l0_l0_dl
        DATA
        DC32      0x1000
        CODE
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??EEPROM_ReadByte_0
        LDW       X, S:?w1
        CPW       X, #0x400
??EEPROM_ReadByte_0:
        JRNC      L:??EEPROM_ReadByte_1
//   91     {
//   92         return;
//   93     }
//   94     for (i=0; i<len; i++, addr++)
        CLR       S:?b13
        CLR       S:?b12
        JRA       L:??EEPROM_ReadByte_2
//   95     {
//   96         buf[i] = FLASH_ReadByte(addr);
??EEPROM_ReadByte_3:
        CALL      L:?mov_l0_l2
        CALL      L:FLASH_ReadByte
        LDW       X, S:?w6
        ADDW      X, (0x1,SP)
        LD        (X), A
//   97     }
        LDW       X, S:?w6
        INCW      X
        LDW       S:?w6, X
        CALL      L:?inc32_l2_l2
??EEPROM_ReadByte_2:
        LDW       X, S:?w6
        CPW       X, S:?w7
        JRC       L:??EEPROM_ReadByte_3
//   98 }
??EEPROM_ReadByte_1:
        ADD       SP, #0x2
        JP        L:?epilogue_l2_l3
//   99 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  100 void EEPROM_WriteByte(u32 addr, u8 *buf, u16 len)
//  101 {
EEPROM_WriteByte:
        CALL      L:?push_l2
        CALL      L:?push_l3
        PUSHW     X
        CALL      L:?mov_l2_l0
        LDW       S:?w7, Y
//  102     u16 i;
//  103     if (addr<0x00001000 || addr>0x000013FF)
        CALL      L:?mov_l0_l2
        CALL      L:?sub32_l0_l0_dl
        DATA
        DC32      0x1000
        CODE
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??EEPROM_WriteByte_0
        LDW       X, S:?w1
        CPW       X, #0x400
??EEPROM_WriteByte_0:
        JRNC      L:??EEPROM_WriteByte_1
//  104     {
//  105         return;
//  106     }
//  107     FLASH_Unlock(FLASH_MemType_Data);
        LD        A, #0xf7
        CALL      L:FLASH_Unlock
//  108     while (!(FLASH->IAPSR & FLASH_IAPSR_DUL))
??EEPROM_WriteByte_2:
        BTJF      L:0x5054, #0x3, L:??EEPROM_WriteByte_2
//  109     {
//  110         ;
//  111     }
//  112     for (i=0; i<len; i++, addr++)
        CLR       S:?b13
        CLR       S:?b12
        JRA       L:??EEPROM_WriteByte_3
//  113     {
//  114         FLASH_ProgramByte(addr, buf[i]);
??EEPROM_WriteByte_4:
        LDW       X, S:?w6
        ADDW      X, (0x1,SP)
        LD        A, (X)
        CALL      L:?mov_l0_l2
        CALL      L:FLASH_ProgramByte
//  115          FLASH_WaitForLastOperation(FLASH_MemType_Program);
        LD        A, #0xfd
        CALL      L:FLASH_WaitForLastOperation
//  116     }
        LDW       X, S:?w6
        INCW      X
        LDW       S:?w6, X
        CALL      L:?inc32_l2_l2
??EEPROM_WriteByte_3:
        LDW       X, S:?w6
        CPW       X, S:?w7
        JRC       L:??EEPROM_WriteByte_4
//  117     FLASH_Lock(FLASH_MemType_Data);
        LD        A, #0xf7
        CALL      L:FLASH_Lock
//  118 }
??EEPROM_WriteByte_1:
        ADD       SP, #0x2
        JP        L:?epilogue_l2_l3
//  119 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//  120 void EEPROM_Erase(u32 addr, u16 len)
//  121 {
EEPROM_Erase:
        CALL      L:?push_l2
        CALL      L:?push_w6
        CALL      L:?mov_l2_l0
        LDW       S:?w6, X
//  122     if (addr<0x00001000 || addr>0x000013FF)
        CALL      L:?mov_l0_l2
        CALL      L:?sub32_l0_l0_dl
        DATA
        DC32      0x1000
        CODE
        LDW       X, S:?w0
        CPW       X, #0x0
        JRNE      L:??EEPROM_Erase_0
        LDW       X, S:?w1
        CPW       X, #0x400
??EEPROM_Erase_0:
        JRNC      L:??EEPROM_Erase_1
//  123     {
//  124         return;
//  125     }
//  126     FLASH_Unlock(FLASH_MemType_Data);
        LD        A, #0xf7
        CALL      L:FLASH_Unlock
//  127     while (!(FLASH->IAPSR & FLASH_IAPSR_DUL))
??EEPROM_Erase_2:
        BTJF      L:0x5054, #0x3, L:??EEPROM_Erase_2
//  128     {
//  129         ;
//  130     }
//  131     for (; len>0; len--, addr++)
??EEPROM_Erase_3:
        LDW       X, S:?w6
        TNZW      X
        JREQ      L:??EEPROM_Erase_4
//  132     {
//  133         FLASH_EraseByte(addr);
        CALL      L:?mov_l0_l2
        CALL      L:FLASH_EraseByte
//  134     }
        LDW       X, S:?w6
        DECW      X
        LDW       S:?w6, X
        CALL      L:?inc32_l2_l2
        JRA       L:??EEPROM_Erase_3
//  135     FLASH_Lock(FLASH_MemType_Data);
??EEPROM_Erase_4:
        LD        A, #0xf7
        CALL      L:FLASH_Lock
//  136 }
??EEPROM_Erase_1:
        JP        L:?epilogue_l2_w6

        SECTION VREGS:DATA:REORDER:NOROOT(0)

        SECTION `.near.rodata`:CONST:REORDER:NOROOT(0)
?_0:
        DC8 0, 0, 0

        END
//  137 
//  138 
// 
//   4 bytes in section .near.bss
// 120 bytes in section .near.data
//   3 bytes in section .near.rodata
// 811 bytes in section .near_func.text
// 
// 811 bytes of CODE  memory
//   3 bytes of CONST memory
// 124 bytes of DATA  memory
//
//Errors: none
//Warnings: 1
