C51 COMPILER V9.01   SH_IEC60730B_8051F_DIO                                                10/11/2023 14:22:17 PAGE 1   


C51 COMPILER V9.01, COMPILATION OF MODULE SH_IEC60730B_8051F_DIO
OBJECT MODULE PLACED IN .\output\sh_iec60730b_8051f_dio.obj
COMPILER INVOKED BY: C:\Keil_v5\C51\BIN\C51.EXE code_classb\iec60730_lib\sh_iec60730b_8051f_dio.c LARGE OPTIMIZE(7,SIZE)
                    - REGFILE(.\output\McuFlash_ISP.ORC) BROWSE INTVECTOR(0X1000) INCDIR(.\header_app;.\header_drv;.\code_gasguage) DEBUG OBJ
                    -ECTEXTEND PRINT(.\output\sh_iec60730b_8051f_dio.lst) OBJECT(.\output\sh_iec60730b_8051f_dio.obj)

line level    source

   1          /*
   2           * IEC60730 Class B Library for SINOWEALTH 8051 based ICs.
   3           * File:    sh_iec60730b_8051f_dio.c
   4           * Version: 1.0
   5           * Author:  Robin.zhang Chaoming.luo
   6           * Date:    04/21/2023
   7           * SINOWEALTH IS SUPPLYING THIS SOFTWARE FOR USE EXCLUSIVELY ON SINOWEALTH'S 
   8           * MICROCONTROLLER PRODUCTS. IT IS PROTECTED UNDER APPLICABLE COPYRIGHT LAWS. 
   9           * THIS SOFTWARE IS FOR GUIDANCE IN ORDER TO SAVE TIME. AS A RESULT, SINOWEALTH 
  10           * SHALL NOT BE HELD LIABLE FOR ANY DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES 
  11           * WITH RESPECT TO ANY CLAIMS ARISING FROM THE CONTENT OF SUCH FIRMWARE AND/OR
  12           * THE USE MADE BY CUSTOMERS OF THE CODING INFORMATION CONTAINED HEREIN IN 
  13           * CONNECTION WITH THEIR PRODUCTS.
  14           *
  15          */
  16          
  17          #include "sh_iec60730b_8051f_cfg.h"
*** WARNING C318 IN LINE 17 OF code_classb\iec60730_lib\sh_iec60730b_8051f_dio.c: can't open file 'sh_iec60730b_8051f_cf
             -g.h'
  18          
  19          
  20          #if SH_CHK_DIO_TEST_EN == 1
*** WARNING C322 IN LINE 20 OF code_classb\iec60730_lib\sh_iec60730b_8051f_dio.c: unknown identifier
              /*******************************************************************************
               *
               * @brief    Checks whether the tested pin has the expected input value.
               *
               * @param    *pTestedPin   - pointer to tested pin struct.
               * @param    expectedValue - expected input value.
               *
               * @return   SH_CHK_PASS
               *           SH_CHK_FAIL_DIO
               *
               ******************************************************************************/
              SHT_RESULT sh_8051f_dio_input(SHT_GPIO_ID pin, SHT_BOOL expectedValue)
              {
                  SHT_BOOL readv = sh_8051f_dio_read_port_val(pin);
                  readv >>= (pin&0xF);
                  readv &= 1;    
                  if(readv != expectedValue)
                      return SH_CHK_FAIL_DIO;
                  else
                      return SH_CHK_PASS;
              }
              
              /*******************************************************************************
               *
               * @brief    Function tests whether the tested pin, that is configured as the input one, has the expected 
             -value.
               *           It is adapted to be used as a "get" function for the sh_8051f_dio_short_to_supply_set() and 
                           the sh_8051f_dio_short_to_adjacent_set() function.
               *           If the Adjacent pin is not involved in test, then tested pin parameters can be entered instea
             -d the adjacent pin parameters.
C51 COMPILER V9.01   SH_IEC60730B_8051F_DIO                                                10/11/2023 14:22:17 PAGE 2   

               *           Both tested pin and adjacent pin must be configured as GPIO before the call of the function!!
             -!
               *
               * @param    *pTestedPin    - pointer to tested pin struct.
               * @param    *pAdjPin       - pointer to adjacent pin struct.
               * @param    testedPinValue - expected value of the tested pin (logical 0 or logical 1).
               * @param    backupEnable   - flag. if non-zero, backup functionality is enable/active.
               *
               * @return   SH_CHK_PASS
               *           SH_CHK_FAIL_DIO
               *
               ******************************************************************************/
              SHT_RESULT sh_8051f_dio_input_ext(SHT_IEC60730B_DIO_TEST *pTestedPin,SHT_IEC60730B_DIO_TEST *pAdjPin, SHT_
             -BOOL expectedValue,SHT_BOOL backupEnable)
              {
                  SHT_RESULT checkResult = SH_CHK_PASS;
                  SHT_BOOL   readv = sh_8051f_dio_read_port_cr(pTestedPin->gpio); 
                  
                  if(((readv >>(pTestedPin->gpio&0xF))&1) != SH_DIO_MODE_IN )
                      checkResult = SH_CHK_FAIL_DIO;
                  else
                  {
                      readv = sh_8051f_dio_read_port_val(pTestedPin->gpio);
                      readv >>= (pTestedPin->gpio&0xF);
                      readv &= 1;    
                      if(expectedValue != readv)
                          checkResult = SH_CHK_FAIL_DIO;
                  }
                  
                  if(backupEnable)
                  {//restore pins;
                     sh_8051f_dio_write_port_cr(pTestedPin->gpio,pTestedPin->bkCR);
                     sh_8051f_dio_write_port_pcr(pTestedPin->gpio,pTestedPin->bkPCR);
                     sh_8051f_dio_write_port_val(pTestedPin->gpio,pTestedPin->bkVAL);
                     
                     if(pAdjPin != pTestedPin)
                     {
                         sh_8051f_dio_write_port_cr(pAdjPin->gpio,pTestedPin->bkCR);
                         sh_8051f_dio_write_port_pcr(pAdjPin->gpio,pTestedPin->bkPCR);
                         sh_8051f_dio_write_port_val(pAdjPin->gpio,pTestedPin->bkVAL);
                     }
                  }    
                  return checkResult;
              }
              
              /*******************************************************************************
               *
               * @brief    Function sets the tested pin as GPIO input with pull-up enable to test the pin against the sh
             -ort to GND.
               *           For getting the result of the test, call the "sh_8051f_dio_input_ext()" function with 
               *           the expected "testedPinValue" sets to 1 for GND.
               *           Tested pin must be configured as GPIO before the call of the function!
               *
               * @param    *pTestedPin    - pointer to tested pin struct.
               * @param    backupEnable   - flag. If non-zero, backup functionality is enable/active.
               *
               * @return   SH_CHK_PASS
               *           SH_CHK_FAIL_DIO
               *
               ******************************************************************************/
              SHT_RESULT sh_8051f_dio_short_to_supply_set(SHT_IEC60730B_DIO_TEST *pTestedPin, SHT_BOOL backupEnable)
              {
C51 COMPILER V9.01   SH_IEC60730B_8051F_DIO                                                10/11/2023 14:22:17 PAGE 3   

                  SHT_RESULT checkResult = SH_CHK_PASS;
                  SHT_BOOL   readv = sh_8051f_dio_read_port_cr(pTestedPin->gpio);     
                  if(backupEnable)
                  {
                     pTestedPin->bkCR  = readv;
                     pTestedPin->bkVAL = sh_8051f_dio_read_port_val(pTestedPin->gpio);
                     pTestedPin->bkPCR = sh_8051f_dio_read_port_pcr(pTestedPin->gpio);        
                  }
                  if(((readv >>(pTestedPin->gpio&0xF))&1) != SH_DIO_MODE_IN )
                      return SH_CHK_FAIL_DIO;
                  
                  readv =  sh_8051f_dio_read_port_pcr(pTestedPin->gpio);
                  readv |= (1<<(pTestedPin->gpio&0xF));
                  sh_8051f_dio_write_port_pcr(pTestedPin->gpio,readv);
                  
                  return checkResult;    
              }
              
              /*******************************************************************************
               *
               * @brief    Function sets the tested pin as GPIO input with "testedPinValue". 
               *           And the adjacent pin as GPIO output with opposite output value as for the tested pin.
               *           For getting the result of the test, call the "sh_8051f_dio_input()" function with the expecte
             -d "testedPinValue".   
               *           Both tested pin and adjacent pin must be configured as GPIO before the call of the function!
               *
               * @param    *pTestedPin    - pointer to tested pin struct.
               * @param    *pAdjPin       - pointer to adjacent pin struct.
               * @param    testedPinValue - value that will be set on the tested pin.
               * @param    backupEnable   - flag. If non-zero, backup functionality is enable/active.
               *
               * @return   SH_CHK_PASS
               *           SH_CHK_FAIL_DIO
               *
               ******************************************************************************/
              SHT_RESULT sh_8051f_dio_short_to_adjacent_set(SHT_IEC60730B_DIO_TEST *pTestedPin, SHT_IEC60730B_DIO_TEST *
             -pAdjPin, SHT_BOOL backupEnable)
              {
                  SHT_RESULT checkResult = SH_CHK_PASS;
                  SHT_BOOL   readv = sh_8051f_dio_read_port_cr(pTestedPin->gpio);         
                  if(backupEnable)
                  {
                     pTestedPin->bkCR  = readv;
                     pTestedPin->bkVAL = sh_8051f_dio_read_port_val(pTestedPin->gpio);
                     pTestedPin->bkPCR = sh_8051f_dio_read_port_pcr(pTestedPin->gpio);        
                      
                     pAdjPin->bkCR  = sh_8051f_dio_read_port_cr(pAdjPin->gpio);
                     pAdjPin->bkVAL = sh_8051f_dio_read_port_val(pAdjPin->gpio);
                     pAdjPin->bkPCR = sh_8051f_dio_read_port_pcr(pAdjPin->gpio);              
                  }
                  
                  if(((readv >>(pTestedPin->gpio&0xF))&1) != SH_DIO_MODE_IN )
                      return SH_CHK_FAIL_DIO;
               
                  /* pull up */
                  readv = sh_8051f_dio_read_port_pcr(pTestedPin->gpio);
                  readv |= (1<<(pTestedPin->gpio&0xF));
                  sh_8051f_dio_write_port_pcr(pTestedPin->gpio,readv);
                  
                  /*adjacent pin output 0*/
                  readv = sh_8051f_dio_read_port_cr(pAdjPin->gpio);
                  readv |= (1<<(pAdjPin->gpio&0xF));
C51 COMPILER V9.01   SH_IEC60730B_8051F_DIO                                                10/11/2023 14:22:17 PAGE 4   

                  sh_8051f_dio_write_port_cr(pAdjPin->gpio,readv); /*set output mode*/
                  sh_8051f_dio_write_pin(pAdjPin->gpio,SH_DIO_PINV_0); /*out 0*/
                  
                  return checkResult;        
              }
              
              
              /*******************************************************************************
               *
               * @brief    This function executes the digital output test. 
               *           The test is focused only to test one digital pin.
               *
               * @param    *pTestedPin - pointer to tested pin struct.
               * @param    delay       - the delay needed to recognize the value change on tested pin.
               *
               * @return   SH_CHK_PASS
               *           SH_CHK_FAIL_DIO
               *
               ******************************************************************************/
              SHT_RESULT sh_8051f_dio_output(SHT_GPIO_ID pin, SHT_U8 delay)
              {
                  SHT_RESULT shResult = SH_CHK_PASS;
                  SHT_U8 readv = sh_8051f_dio_read_port_cr(pin);    
                  if(((readv >>(pin&0xF))&1) != SH_DIO_MODE_OUT )
                      shResult = SH_CHK_FAIL_DIO;
                  else
                  {
                      SHT_U8 bkVAL = sh_8051f_dio_read_port_val(pin);   
                      
                      sh_8051f_dio_write_pin(pin,SH_DIO_PINV_0);
                      readv = delay;
                      while(readv){readv--;}
                      readv = sh_8051f_dio_read_port_val(pin);        
                      if(((readv >>(pin&0xF))&1) !=  SH_DIO_PINV_0)
                          shResult = SH_CHK_FAIL_DIO;
                      else
                      {
                          sh_8051f_dio_write_pin(pin,SH_DIO_PINV_1);
                          readv = readv;
                          while(readv){readv--;}
                          readv = sh_8051f_dio_read_port_val(pin);
                          if(((readv >>(pin&0xF))&1) !=  SH_DIO_PINV_1)
                              shResult = SH_CHK_FAIL_DIO;            
                      }
                    
                      sh_8051f_dio_write_port_val(pin,bkVAL);        
                  }
                  
                  return shResult;
              }
              #endif


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   ----    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =   ----    ----
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.

C51 COMPILER V9.01   SH_IEC60730B_8051F_DIO                                                10/11/2023 14:22:17 PAGE 5   


C51 COMPILATION COMPLETE.  2 WARNING(S),  0 ERROR(S)
