///////////////////////////////////////////////////////////////////////////////
//
// 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\BSP\SPI.c
//    Command line =  
//        F:\2-Lora\Code\stm8l151K6T6-WLAN\BSP\SPI.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\SPI.s
//
///////////////////////////////////////////////////////////////////////////////

        EXTERN ?b0
        EXTERN ?b1
        EXTERN ?b10
        EXTERN ?b2
        EXTERN ?b3
        EXTERN ?b4
        EXTERN ?b5
        EXTERN ?b6
        EXTERN ?b8
        EXTERN ?b9
        EXTERN ?epilogue_w4
        EXTERN ?push_w4
        EXTERN CLK_PeripheralClockConfig
        EXTERN DelayTime
        EXTERN GPIO_Init
        EXTERN GPIO_WriteBit
        EXTERN SPI_Cmd
        EXTERN SPI_DeInit
        EXTERN SPI_Init

        PUBLIC SpiInOut
        PUBLIC SpiInit1
        PUBLIC dataTemp
        PUBLIC regTemp
        PUBLIC spi0ReadWrite
        PUBLIC spiTest
        PUBLIC temp2
        PUBLIC temp3

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

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//    2 void SpiInit1( void )
//    3 {
//    4     CLK_PeripheralClockConfig(CLK_Peripheral_SPI1,ENABLE);
SpiInit1:
        MOV       S:?b0, #0x1
        LD        A, #0x4
        CALL      L:CLK_PeripheralClockConfig
//    5     SPI_IO_INIT;
        MOV       S:?b0, #0xf0
        LD        A, #0x8
        LDW       X, #0x5005
        CALL      L:GPIO_Init
        MOV       S:?b0, #0x1
        LD        A, #0x8
        LDW       X, #0x5005
        CALL      L:GPIO_WriteBit
        MOV       S:?b0, #0xf0
        LD        A, #0x20
        LDW       X, #0x5005
        CALL      L:GPIO_Init
        MOV       S:?b0, #0xf0
        LD        A, #0x40
        LDW       X, #0x5005
        CALL      L:GPIO_Init
        MOV       S:?b0, #0x40
        LD        A, #0x80
        LDW       X, #0x5005
        CALL      L:GPIO_Init
//    6     SPI_DeInit(SPI1);
        LDW       X, #0x5200
        CALL      L:SPI_DeInit
//    7     SPI0_DELAY;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
//    8     SPI_Init(SPI1,SPI_FirstBit_MSB,SPI_BaudRatePrescaler_16,SPI_Mode_Master,SPI_CPOL_Low,SPI_CPHA_1Edge,SPI_Direction_2Lines_FullDuplex,SPI_NSS_Soft,0);
        CLR       S:?b6
        MOV       S:?b5, #0x2
        CLR       S:?b4
        CLR       S:?b3
        CLR       S:?b2
        MOV       S:?b1, #0x4
        MOV       S:?b0, #0x18
        CLR       A
        LDW       X, #0x5200
        CALL      L:SPI_Init
//    9     SPI_Cmd(SPI1,ENABLE);
        LD        A, #0x1
        LDW       X, #0x5200
        JP        L:SPI_Cmd
//   10 //    SPI1->CR2 = 0x01;
//   11 //    SPI1->CR1 = 0x5C;
//   12 //    SPI1->CR1 |= 0x40;
//   13 }
//   14 

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   15 uint8_t SpiInOut( uint8_t outData )
//   16 {
//   17   u8 cc=0;
SpiInOut:
        CLR       S:?b0
//   18     /* Send SPIy data */
//   19     //SPI_SendData( SPI1, outData );
//   20     SPI1->DR = outData;
        LD        L:0x5204, A
//   21     while(!(SPI1->SR&0x02));
??SpiInOut_0:
        BTJF      L:0x5203, #0x1, L:??SpiInOut_0
//   22     while(!(SPI1->SR&0x01));
??SpiInOut_1:
        BTJF      L:0x5203, #0x0, L:??SpiInOut_1
//   23     cc= SPI1->DR;//SPI_ReceiveData( SPI1 );
        LD        A, L:0x5204
        LD        S:?b0, A
//   24     SPI1->SR &= ~0x01;
        BRES      L:0x5203, #0x0
//   25     return cc;
        LD        A, S:?b0
        RET
//   26 }

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//   27 uint8_t regTemp=0,dataTemp=0,temp3=0;
regTemp:
        DS8 1

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
dataTemp:
        DS8 1

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
temp3:
        DS8 1

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   28 uint8_t spi0ReadWrite(uint8_t reg,uint8_t data,enum DataDeal deal)
//   29 {
spi0ReadWrite:
        CALL      L:?push_w4
        PUSH      S:?b10
        LD        S:?b8, A
        MOV       S:?b9, S:?b0
        MOV       S:?b10, S:?b1
//   30 		SPI0_SCS_L;
        CLR       S:?b0
        LD        A, #0x8
        LDW       X, #0x5005
        CALL      L:GPIO_WriteBit
//   31 		SPI0_DELAY;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
//   32 		dataTemp = data;
        LD        A, S:?b9
        LD        L:dataTemp, A
//   33 		regTemp = reg;
        LD        A, S:?b8
        LD        L:regTemp, A
//   34 		if(deal==write)
        LD        A, S:?b10
        CP        A, #0x1
        JRNE      L:??spi0ReadWrite_0
//   35 		{
//   36 				regTemp |= 0x80;
        BSET      L:regTemp, #0x7
        JRA       L:??spi0ReadWrite_1
//   37 		}
//   38 		else if(deal==read)
??spi0ReadWrite_0:
        TNZ       S:?b10
        JRNE      L:??spi0ReadWrite_1
//   39 		{
//   40 				regTemp &= 0x7F;
        BRES      L:regTemp, #0x7
//   41 				dataTemp = 0xff;
        MOV       L:dataTemp, #0xff
//   42 		}
//   43 		SpiInOut(regTemp);
??spi0ReadWrite_1:
        LD        A, L:regTemp
        CALL      L:SpiInOut
//   44 		temp3 =  SpiInOut(dataTemp);
        LD        A, L:dataTemp
        CALL      L:SpiInOut
        LD        L:temp3, A
//   45 		SPI0_SCS_H;
        MOV       S:?b0, #0x1
        LD        A, #0x8
        LDW       X, #0x5005
        CALL      L:GPIO_WriteBit
//   46 		return temp3;
        LD        A, L:temp3
        POP       S:?b10
        JP        L:?epilogue_w4
//   47 }

        SECTION `.near.bss`:DATA:REORDER:NOROOT(0)
//   48 uint8_t temp2;
temp2:
        DS8 1

        SECTION `.near_func.text`:CODE:REORDER:NOROOT(0)
        CODE
//   49 void spiTest(void)
//   50 {
//   51       if(DelayTime)return;
spiTest:
        LD        A, L:DelayTime
        CP        A, #0x0
        JRNE      L:??spiTest_0
//   52       DelayTime = 1;
        MOV       L:DelayTime, #0x1
//   53       temp2 = spi0ReadWrite(REG_LR_VERSION,0xff,read);;//SpiInOut(0xa5);
        CLR       S:?b1
        MOV       S:?b0, #0xff
        LD        A, #0x42
        CALL      L:spi0ReadWrite
        LD        L:temp2, A
//   54       SPI0_DELAY;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
        NOP;
//   55       //UsartPrint(&temp2,1);
//   56 }
??spiTest_0:
        RET

        SECTION VREGS:DATA:REORDER:NOROOT(0)

        END
//   57 
// 
//   4 bytes in section .near.bss
// 449 bytes in section .near_func.text
// 
// 449 bytes of CODE memory
//   4 bytes of DATA memory
//
//Errors: none
//Warnings: 1
