1. remove the unnecessary debug message

2. simplize and optimize the code.

Signed-off-by: hans <hans.tseng@deltaww.com>
This commit is contained in:
hans
2018-11-07 15:33:58 +08:00
parent 403a9d4b26
commit 93b1205e34
3 changed files with 61 additions and 104 deletions

View File

@@ -105,7 +105,7 @@ dni_fani_info_get_fan(int local_id, onlp_fan_info_t* info)
{
int rpm = 0;
char fullpath[100] = {0};
uint8_t present_bit=0x00, bit=0x00;
uint8_t present_bit=0x00;
mux_info_t mux_info;
mux_info.offset = SWPLD_PSU_FAN_I2C_MUX_REG;
@@ -135,35 +135,35 @@ dni_fani_info_get_fan(int local_id, onlp_fan_info_t* info)
{
case FAN_1_ON_FAN_BOARD:
case FAN_6_ON_FAN_BOARD:
if((present_bit & (bit+1)) == 0)
if((present_bit & 1) == 0)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;
break;
case FAN_2_ON_FAN_BOARD:
case FAN_7_ON_FAN_BOARD:
if((present_bit & ((bit+1)<<1)) == 0)
if((present_bit & (1<<1)) == 0)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;
break;
case FAN_3_ON_FAN_BOARD:
case FAN_8_ON_FAN_BOARD:
if((present_bit & ((bit+1)<<2)) == 0)
if((present_bit & (1<<2)) == 0)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;
break;
case FAN_4_ON_FAN_BOARD:
case FAN_9_ON_FAN_BOARD:
if((present_bit & ((bit+1)<<3)) == 0)
if((present_bit & (1<<3)) == 0)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;
break;
case FAN_5_ON_FAN_BOARD:
case FAN_10_ON_FAN_BOARD:
if((present_bit & ((bit+1)<<4)) == 0)
if((present_bit & (1<<4)) == 0)
info->status |= ONLP_FAN_STATUS_PRESENT;
else
info->status |= ONLP_FAN_STATUS_FAILED;

View File

@@ -173,54 +173,42 @@ int dni_i2c_lock_write( mux_info_t * mux_info, dev_info_t * dev_info)
int dni_i2c_lock_read_attribute(mux_info_t * mux_info, char * fullpath)
{
int fd, len, nbytes = 10;
int fd, len, nbytes = 10,rv = -1;
char r_data[10] = {0};
DNI_BUS_LOCK();
if(mux_info != NULL)
dni_swpld_write_attribute(mux_info->offset, mux_info->channel,BUS_LOCKED);
if ((fd = open(fullpath, O_RDONLY)) == -1)
if ((fd = open(fullpath, O_RDONLY)) >= 0)
{
goto ERROR;
}
if ((len = read(fd, r_data, nbytes)) <= 0)
{
goto ERROR;
if ((len = read(fd, r_data, nbytes)) > 0)
{
rv=atoi(r_data);
}
}
close(fd);
DNI_BUS_UNLOCK();
return atoi(r_data);
ERROR:
close(fd);
DNI_BUS_UNLOCK();
return -1;
return rv;
}
int dni_i2c_lock_write_attribute(mux_info_t * mux_info, char * data,char * fullpath)
{
int fd, len, nbytes = 10;
int fd, nbytes = 10, rv = -1;
DNI_BUS_LOCK();
if(mux_info!=NULL)
dni_swpld_write_attribute(mux_info->offset, mux_info->channel,BUS_LOCKED);
/* Create output file descriptor */
fd = open(fullpath, O_WRONLY, 0644);
if (fd == -1)
if((fd = open(fullpath, O_WRONLY, 0644)) >= 0)
{
goto ERROR;
if(write(fd, data, (ssize_t) nbytes) > 0)
{
fsync(fd);
rv = 0;
}
}
len = write (fd, data, (ssize_t) nbytes);
if (len != nbytes)
{
goto ERROR;
}
fsync(fd);
close(fd);
DNI_BUS_UNLOCK();
return 0;
ERROR:
close(fd);
DNI_BUS_UNLOCK();
return -1;
return rv;
}
@@ -228,86 +216,63 @@ ERROR:
Use this function to select address & read the data. */
int dni_lock_swpld_read_attribute(int addr)
{
int fd, len, nbytes = 10,data = 0;
int fd , fd1, nbytes = 10,data = 0, rv=-1;
char r_data[10] = {0};
char address[10] = {0};
sprintf(address, "%02x", addr);
DNI_BUS_LOCK();
/* Create output file descriptor */
fd = open(SWPLD_ADDR_PATH, O_WRONLY, 0644);
if (fd == -1)
if((fd = open(SWPLD_ADDR_PATH, O_WRONLY, 0644)) >=0)
{
goto ERROR;
if(write (fd, address, 2) >0)
{
fsync(fd);
if ((fd1 = open(SWPLD_DATA_PATH, O_RDONLY,0644)) >= 0)
{
if ((read(fd1, r_data, nbytes)) > 0)
{
sscanf( r_data, "%x", &data);
rv=data;
}
}
close(fd1);
}
}
len = write (fd, address, 2);
if(len <= 0)
{
goto ERROR;
}
close(fd);
if ((fd = open(SWPLD_DATA_PATH, O_RDONLY,0644)) == -1)
{
goto ERROR;
}
if ((len = read(fd, r_data, nbytes)) <= 0)
{
goto ERROR;
}
sscanf( r_data, "%x", & data);
close(fd);
DNI_BUS_UNLOCK();
return data;
ERROR:
close(fd);
DNI_BUS_UNLOCK();
return -1;
return rv;
}
/* SWPLD modulize in AG9032v1 platform at bus 6 on address 0x31.
Use this function to select address the & write the data. */
int dni_swpld_write_attribute(int addr, int data,int bus_lock)
{
int fd, len;
int fd,fd1,rv = -1;
char address[10] = {0};
sprintf(address, "%02x", addr);
if(bus_lock == BUS_LOCK)
DNI_BUS_LOCK();
/* Create output file descriptor */
fd = open(SWPLD_ADDR_PATH, O_WRONLY, 0644);
if (fd == -1)
if((fd= open(SWPLD_ADDR_PATH, O_WRONLY, 0644)) >= 0)
{
goto ERROR;
if( write(fd, address, 2) > 0)
{
fsync(fd);
if((fd1 = open(SWPLD_DATA_PATH, O_WRONLY, 0644)) >= 0)
{
sprintf(address, "%02x", data);
if( write (fd1, address, 2) >0 )
{
rv=0;
fsync(fd1);
}
}
close(fd1);
}
}
len = write(fd, address, 2);
if(len <= 0)
{
goto ERROR;
}
fsync(fd);
close(fd);
fd = open(SWPLD_DATA_PATH, O_WRONLY, 0644);
if (fd == -1)
{
goto ERROR;
}
sprintf(address, "%02x", data);
len = write (fd, address, 2);
if(len <= 0)
{
goto ERROR;
}
fsync(fd);
close(fd);
if(bus_lock == BUS_LOCK)
DNI_BUS_UNLOCK();
return 0;
ERROR:
close(fd);
if(bus_lock == BUS_LOCK)
DNI_BUS_UNLOCK();
return -1;
return rv;
}

View File

@@ -212,7 +212,7 @@ onlp_sysi_platform_manage_leds(void)
/* Set front lights: fan, power supply 1, 2
*/
int rpm, rpm1,i=0,count=0, state;
uint8_t present_bit = 0x00, bit=0x00;
uint8_t present_bit = 0x00;
uint8_t power_state;
mux_info_t mux_info;
dev_info_t dev_info;
@@ -228,13 +228,10 @@ onlp_sysi_platform_manage_leds(void)
dev_info.size = 1;
present_bit = dni_i2c_lock_read(&mux_info, &dev_info);
char echoDebug[50]={0};
sprintf(echoDebug, "echo \"[DEBUG ] present_bit=0x%x \" > /dev/console",present_bit);
system(echoDebug);
/* Fan tray 1 */
rpm = dni_i2c_lock_read_attribute(NULL, FAN5_FRONT);
rpm1 = dni_i2c_lock_read_attribute(NULL, FAN5_REAR);
if((present_bit & ((bit+1) << 4)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
if((present_bit & (1 << 4)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
{/* Green light */
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_1),ONLP_LED_MODE_GREEN);
@@ -246,10 +243,9 @@ onlp_sysi_platform_manage_leds(void)
}
/* Fan tray 2 */
bit=0x00;
rpm = dni_i2c_lock_read_attribute(NULL, FAN4_FRONT);
rpm1 = dni_i2c_lock_read_attribute(NULL, FAN4_REAR);
if((present_bit & ((bit+1) << 3)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
if((present_bit & (1 << 3)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
{/* Green light */
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_2),ONLP_LED_MODE_GREEN);
@@ -261,10 +257,9 @@ onlp_sysi_platform_manage_leds(void)
}
/* Fan tray 3 */
bit=0x00;
rpm = dni_i2c_lock_read_attribute(NULL, FAN3_FRONT);
rpm1 = dni_i2c_lock_read_attribute(NULL, FAN3_REAR);
if((present_bit & ((bit+1) << 2)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
if((present_bit & (1 << 2)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
{/* Green light */
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_3),ONLP_LED_MODE_GREEN);
@@ -276,10 +271,9 @@ onlp_sysi_platform_manage_leds(void)
}
/* Fan tray 4 */
bit=0x00;
rpm = dni_i2c_lock_read_attribute(NULL, FAN2_FRONT);
rpm1 = dni_i2c_lock_read_attribute(NULL, FAN2_REAR);
if((present_bit & ((bit+1) << 1)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
if((present_bit & (1 << 1)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
{/* Green light */
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_4),ONLP_LED_MODE_GREEN);
@@ -291,10 +285,9 @@ onlp_sysi_platform_manage_leds(void)
}
/* Fan tray 5 */
bit=0x00;
rpm = dni_i2c_lock_read_attribute(NULL, FAN1_FRONT);
rpm1 = dni_i2c_lock_read_attribute(NULL, FAN1_REAR);
if((present_bit & (bit+1)) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
if((present_bit & 1) == 0 && rpm != 960 && rpm != 0 && rpm1 != 960 && rpm1 != 0 )
{/* Green light */
onlp_ledi_mode_set(ONLP_LED_ID_CREATE(LED_REAR_FAN_TRAY_5),ONLP_LED_MODE_GREEN);
@@ -312,9 +305,8 @@ onlp_sysi_platform_manage_leds(void)
//dev_info.addr = FAN_TRAY_1 + i;
//fantray_present = dni_i2c_lock_read(&mux_info, &dev_info);
// if( fantray_present >= 0)
bit=0x00;
present_bit = dni_i2c_lock_read(&mux_info, &dev_info);
if( (present_bit & (bit+1) << i) == 0)
if( (present_bit & (1 << i)) == 0)
count++;
}
/* Set front light of FAN */