///////////////////////////////////////////////////////////////////////////////
//                                                                            /
// IAR ANSI C/C++ Compiler V6.30.1.53127/W32 for ARM    08/Mar/2012  18:18:26 /
// Copyright 1999-2011 IAR Systems AB.                                        /
//                                                                            /
//    Cpu mode     =  thumb                                                   /
//    Endian       =  little                                                  /
//    Source file  =  D:\Profiles\b01252\My Documents\Freescale\P0\software\s /
//                    ample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_ /
//                    sc\src\projects\TWRK20D50M_Demo\I2C\hal_i2c.c           /
//    Command line =  "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\src\projects\TWRK20D50M_Demo\I2C\hal_i2c.c" -D IAR  /
//                    -D TOWER -D TWR_K20D50M -lCN "D:\Profiles\b01252\My     /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\FLASH_128KB_PFLASH\List\" -lB         /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\FLASH_128KB_PFLASH\List\" /
//                     -o "D:\Profiles\b01252\My                              /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\FLASH_128KB_PFLASH\Obj\" --no_cse     /
//                    --no_unroll --no_inline --no_code_motion --no_tbaa      /
//                    --no_clustering --no_scheduling --debug                 /
//                    --endian=little --cpu=Cortex-M4 -e --fpu=None           /
//                    --dlib_config "C:\Program Files\IAR Systems\Embedded    /
//                    Workbench 6.0_5\arm\INC\c\DLib_Config_Normal.h" -I      /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\common\" -I  /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\cpu\" -I     /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\cpu\headers\ /
//                    " -I "D:\Profiles\b01252\My                             /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\drivers\uart\" -I        /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\drivers\mcg\ /
//                    " -I "D:\Profiles\b01252\My                             /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\drivers\wdog\" -I        /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\drivers\rcm\ /
//                    " -I "D:\Profiles\b01252\My                             /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\drivers\lptmr\" -I       /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\platforms\"  /
//                    -I "D:\Profiles\b01252\My Documents\Freescale\P0\softwa /
//                    re\sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50 /
//                    MHz_sc\build\iar\TWRK20D50M_Demo\..\" -I                /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\projects\TWR /
//                    K20D50M_Demo\" -I "D:\Profiles\b01252\My                /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \dma\" -I "D:\Profiles\b01252\My                        /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \adc16\" -I "D:\Profiles\b01252\My                      /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \i2c\" -I "D:\Profiles\b01252\My                        /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \tsi\" -I "D:\Profiles\b01252\My                        /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \adc_test\" -I "D:\Profiles\b01252\My                   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \angle_calculation\" -I "D:\Profiles\b01252\My          /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \buzzer\" -I "D:\Profiles\b01252\My                     /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \fft_test\" -I "D:\Profiles\b01252\My                   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \irda_test\" -I "D:\Profiles\b01252\My                  /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \cmt_test\" -I "D:\Profiles\b01252\My                   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \protocol\" -I "D:\Profiles\b01252\My                   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \task_mgr\" -I "D:\Profiles\b01252\My                   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \TWRK20_specific\" -I "D:\Profiles\b01252\My            /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\projects\TWRK20D50M_Demo /
//                    \rtc\" -I "D:\Profiles\b01252\My                        /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\CMSIS\DSP_Lib\Lib\interm /
//                    ediateFiles\" -I "D:\Profiles\b01252\My                 /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\CMSIS\DSP_Lib\Include\"  /
//                    -I "D:\Profiles\b01252\My Documents\Freescale\P0\softwa /
//                    re\sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50 /
//                    MHz_sc\build\iar\TWRK20D50M_Demo\..\..\..\src\CMSIS\CM4 /
//                    \DeviceSupport\ARM\ARMCM4\" -I "D:\Profiles\b01252\My   /
//                    Documents\Freescale\P0\software\sample code             /
//                    cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\build\ia /
//                    r\TWRK20D50M_Demo\..\..\..\src\CMSIS\CM4\CoreSupport\"  /
//                    -I "D:\Profiles\b01252\My Documents\Freescale\P0\softwa /
//                    re\sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50 /
//                    MHz_sc\build\iar\TWRK20D50M_Demo\..\..\..\src\CMSIS\CM4 /
//                    \CoreSupportLiker Options-Library\" -I                  /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\src\CMSIS\DSP_Li /
//                    b\Lib\intermediateFiles\arm_cortexM4_math.lib\" -I      /
//                    "D:\Profiles\b01252\My Documents\Freescale\P0\software\ /
//                    sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz /
//                    _sc\build\iar\TWRK20D50M_Demo\..\..\..\build\" -Ol      /
//                    --use_c++_inline -I "C:\Program Files\IAR               /
//                    Systems\Embedded Workbench 6.0_5\arm\CMSIS\Include\"    /
//                    -D ARM_MATH_CM4                                         /
//    List file    =  D:\Profiles\b01252\My Documents\Freescale\P0\software\s /
//                    ample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_ /
//                    sc\build\iar\TWRK20D50M_Demo\FLASH_128KB_PFLASH\List\ha /
//                    l_i2c.s                                                 /
//                                                                            /
//                                                                            /
///////////////////////////////////////////////////////////////////////////////

        NAME hal_i2c

        #define SHT_PROGBITS 0x1

        PUBLIC hal_i2c_deinit
        PUBLIC hal_i2c_init
        PUBLIC i2c_get_ack
        PUBLIC i2c_give_ack
        PUBLIC i2c_give_nack
        PUBLIC i2c_read_byte
        PUBLIC i2c_repeated_start
        PUBLIC i2c_set_master_mode
        PUBLIC i2c_set_rx_mode
        PUBLIC i2c_set_slave_mode
        PUBLIC i2c_set_tx_mode
        PUBLIC i2c_start
        PUBLIC i2c_stop
        PUBLIC i2c_wait
        PUBLIC i2c_write_byte

// D:\Profiles\b01252\My Documents\Freescale\P0\software\sample code cesar\TWR-K20D50M_LABS_AND_CE\kinetis_50MHz_sc\src\projects\TWRK20D50M_Demo\I2C\hal_i2c.c
//    1 
//    2 #include "common.h"
//    3 
//    4 

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//    5 void i2c_set_tx_mode(I2C_MemMapPtr p)
//    6 {
//    7     p->C1 |= I2C_C1_TX_MASK;
i2c_set_tx_mode:
        LDRB     R1,[R0, #+2]
        ORRS     R1,R1,#0x10
        STRB     R1,[R0, #+2]
//    8 
//    9 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   10 void i2c_set_rx_mode(I2C_MemMapPtr p)
//   11 {
//   12     p->C1 &= ~I2C_C1_TX_MASK;
i2c_set_rx_mode:
        LDRB     R1,[R0, #+2]
        ANDS     R1,R1,#0xEF
        STRB     R1,[R0, #+2]
//   13 }
        BX       LR               ;; return
//   14 

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   15 void i2c_set_slave_mode(I2C_MemMapPtr p)
//   16 {
//   17     p->C1  &= ~I2C_C1_MST_MASK;
i2c_set_slave_mode:
        LDRB     R1,[R0, #+2]
        ANDS     R1,R1,#0xDF
        STRB     R1,[R0, #+2]
//   18 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   19 void i2c_set_master_mode(I2C_MemMapPtr p)
//   20 {
//   21     p->C1  |=  I2C_C1_MST_MASK;
i2c_set_master_mode:
        LDRB     R1,[R0, #+2]
        ORRS     R1,R1,#0x20
        STRB     R1,[R0, #+2]
//   22 }
        BX       LR               ;; return
//   23 
//   24 // i2c general
//   25 

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   26 void i2c_give_nack(I2C_MemMapPtr p)
//   27 {
//   28     p->C1 |= I2C_C1_TXAK_MASK;
i2c_give_nack:
        LDRB     R1,[R0, #+2]
        ORRS     R1,R1,#0x8
        STRB     R1,[R0, #+2]
//   29 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   30 void i2c_give_ack(I2C_MemMapPtr p)
//   31 {
//   32     p->C1 &= ~I2C_C1_TXAK_MASK;
i2c_give_ack:
        LDRB     R1,[R0, #+2]
        ANDS     R1,R1,#0xF7
        STRB     R1,[R0, #+2]
//   33 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   34 void i2c_repeated_start(I2C_MemMapPtr p)
//   35 {
//   36     p->C1     |= 0x04;
i2c_repeated_start:
        LDRB     R1,[R0, #+2]
        ORRS     R1,R1,#0x4
        STRB     R1,[R0, #+2]
//   37 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   38 void i2c_write_byte(I2C_MemMapPtr p, uint8 data)
//   39 {
//   40     p->D = data;
i2c_write_byte:
        STRB     R1,[R0, #+4]
//   41 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   42 uint8 i2c_read_byte(I2C_MemMapPtr p)
//   43 {
//   44     return p->D;
i2c_read_byte:
        LDRB     R0,[R0, #+4]
        BX       LR               ;; return
//   45 }

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   46 void i2c_start(I2C_MemMapPtr p)
//   47 {
i2c_start:
        PUSH     {R4,LR}
        MOVS     R4,R0
//   48     i2c_set_master_mode(p);
        MOVS     R0,R4
        BL       i2c_set_master_mode
//   49     i2c_set_tx_mode(p);
        MOVS     R0,R4
        BL       i2c_set_tx_mode
//   50 }
        POP      {R4,PC}          ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   51 void i2c_stop(I2C_MemMapPtr p)
//   52 {
i2c_stop:
        PUSH     {R4,LR}
        MOVS     R4,R0
//   53     i2c_set_slave_mode(p);
        MOVS     R0,R4
        BL       i2c_set_slave_mode
//   54     i2c_set_rx_mode(p);
        MOVS     R0,R4
        BL       i2c_set_rx_mode
//   55 }
        POP      {R4,PC}          ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   56 void i2c_wait(I2C_MemMapPtr p)
//   57 {
//   58     // wait flag
//   59     while((p->S & I2C_S_IICIF_MASK)==0)
i2c_wait:
??i2c_wait_0:
        LDRB     R1,[R0, #+3]
        LSLS     R1,R1,#+30
        BPL.N    ??i2c_wait_0
//   60         ;
//   61     // clear flag
//   62     p->S |= I2C_S_IICIF_MASK;
        LDRB     R1,[R0, #+3]
        ORRS     R1,R1,#0x2
        STRB     R1,[R0, #+3]
//   63 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   64 uint16 i2c_get_ack(I2C_MemMapPtr p)
//   65 {
//   66     if((p->S & I2C_S_RXAK_MASK) == 0)
i2c_get_ack:
        LDRB     R0,[R0, #+3]
        LSLS     R0,R0,#+31
        BMI.N    ??i2c_get_ack_0
//   67         return TRUE;
        MOVS     R0,#+1
        B.N      ??i2c_get_ack_1
//   68     else
//   69         return FALSE;
??i2c_get_ack_0:
        MOVS     R0,#+0
??i2c_get_ack_1:
        BX       LR               ;; return
//   70 }
//   71 
//   72 // -------------------------------------------------

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   73 void hal_i2c_init(void)
//   74 {
//   75     SIM_SCGC4 |= SIM_SCGC4_I2C0_MASK;
hal_i2c_init:
        LDR.N    R0,??DataTable1  ;; 0x40048034
        LDR      R0,[R0, #+0]
        ORRS     R0,R0,#0x40
        LDR.N    R1,??DataTable1  ;; 0x40048034
        STR      R0,[R1, #+0]
//   76 
//   77     // configure GPIO for I2C function
//   78     PORTB_PCR2 = PORT_PCR_MUX(2);
        LDR.N    R0,??DataTable1_1  ;; 0x4004a008
        MOV      R1,#+512
        STR      R1,[R0, #+0]
//   79     PORTB_PCR3 = PORT_PCR_MUX(2);
        LDR.N    R0,??DataTable1_2  ;; 0x4004a00c
        MOV      R1,#+512
        STR      R1,[R0, #+0]
//   80 
//   81     I2C0_F  = 0x14; // baudrate
        LDR.N    R0,??DataTable1_3  ;; 0x40066001
        MOVS     R1,#+20
        STRB     R1,[R0, #+0]
//   82     I2C0_C1 = 0x80; // enable IIC
        LDR.N    R0,??DataTable1_4  ;; 0x40066002
        MOVS     R1,#+128
        STRB     R1,[R0, #+0]
//   83 }
        BX       LR               ;; return
//   84 

        SECTION `.text`:CODE:NOROOT(1)
        THUMB
//   85 void hal_i2c_deinit(void)
//   86 {
//   87     I2C0_C1 = 0x00;
hal_i2c_deinit:
        LDR.N    R0,??DataTable1_4  ;; 0x40066002
        MOVS     R1,#+0
        STRB     R1,[R0, #+0]
//   88     SIM_SCGC4 &= ~SIM_SCGC4_I2C0_MASK;
        LDR.N    R0,??DataTable1  ;; 0x40048034
        LDR      R0,[R0, #+0]
        BICS     R0,R0,#0x40
        LDR.N    R1,??DataTable1  ;; 0x40048034
        STR      R0,[R1, #+0]
//   89 }
        BX       LR               ;; return

        SECTION `.text`:CODE:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
??DataTable1:
        DC32     0x40048034

        SECTION `.text`:CODE:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
??DataTable1_1:
        DC32     0x4004a008

        SECTION `.text`:CODE:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
??DataTable1_2:
        DC32     0x4004a00c

        SECTION `.text`:CODE:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
??DataTable1_3:
        DC32     0x40066001

        SECTION `.text`:CODE:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
??DataTable1_4:
        DC32     0x40066002

        SECTION `.iar_vfe_header`:DATA:REORDER:NOALLOC:NOROOT(2)
        SECTION_TYPE SHT_PROGBITS, 0
        DATA
        DC32 0

        SECTION __DLIB_PERTHREAD:DATA:REORDER:NOROOT(0)
        SECTION_TYPE SHT_PROGBITS, 0

        SECTION __DLIB_PERTHREAD_init:DATA:REORDER:NOROOT(0)
        SECTION_TYPE SHT_PROGBITS, 0

        END
//   90 
//   91 
//   92 
// 
// 226 bytes in section .text
// 
// 226 bytes of CODE memory
//
//Errors: none
//Warnings: none
