📄 aduc812.c
字号:
/*modification history--------------------01a,08apr02,lagarwal written*//*DESCRIPTIONThis module contains the routines for temp. voltage monitoring device (ADuC812 microcontroller)This file has routines to get/set temp/voltage high/low limits.*/#include "ixdp2400.h"#include "aduc812.h"#include "ixdp2400I2c.h"/******************************************************************************** int readVolt(volt_id, which_limit)** This routine reads the voltage monitor field for the specified voltage level* and returns current voltage in uV.* This function can only be called on master NPU.** RETURNS: current voltage in uV.*/int readVolt(volt_id identifier, which_limit limit){ int regOff = 0; int resolution = 0; /* check for master */ if(!isNPUMaster()) { return 0; } switch(identifier) { case ADUC_3_3V_M_ID: regOff = 0x1; resolution = ADUC_5V_REF_RES; break; case ADUC_2_5V_M_ID: regOff = 0x3; resolution = ADUC_5V_REF_RES; break; case ADUC_3_3V_ID: regOff = 0x5 + (limit * 2); resolution = ADUC_5V_REF_RES; break; case ADUC_2_5V_ID: regOff = 0xB + (limit * 2); resolution = ADUC_5V_REF_RES; break; case ADUC_1_8V_ID: regOff = 0x11 + (limit * 2); resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_5V_ID: regOff = 0x17 + (limit * 2); resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_3V_ID: regOff = 0x1D + (limit * 2); resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_2_5V_ID: regOff = 0x23 + (limit * 2); resolution = ADUC_2_5V_REF_RES; break; default: printf("readVolt: illegal voltage identifier\n"); break; } /* read the register */ if(regOff) { char devId; unsigned short monitorRegVal = 0; i2c_read(SLAVE_ADDR_5, ADUC812_DEV_ID_OFF, &devId); if(devId == ADUC812_DEV_ID) { i2c_seq_read(SLAVE_ADDR_5, regOff, (unsigned char *)&monitorRegVal, 2); return (monitorRegVal * resolution); } } return 0;}/******************************************************************************** STATUS voltLimitSet(volt_id, int, which_limit)** This routine sets the high/low limit for the specified voltage level* and returns the status of operation. value should be in uV* This function can only be called on master NPU.** RETURNS: status of operation.*/STATUS voltLimitSet(volt_id identifier, int value, which_limit limit){ int regOff = 0; int resolution = 0; if(limit == MONITOR) return ERROR; /* check for master */ if(!isNPUMaster()) { return ERROR; } switch(identifier) { case ADUC_3_3V_M_ID: printf("voltLimitSet: Setting limit for 3.3 V Main voltage level is not supported\n"); break; case ADUC_2_5V_M_ID: printf("voltLimitSet: Setting limit for 2.5 V Main voltage level is not supported\n"); break; case ADUC_3_3V_ID: regOff = 0x7; resolution = ADUC_5V_REF_RES; break; case ADUC_2_5V_ID: regOff = 0xD; resolution = ADUC_5V_REF_RES; break; case ADUC_1_8V_ID: regOff = 0x13; resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_5V_ID: regOff = 0x19; resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_3V_ID: regOff = 0x1F; resolution = ADUC_2_5V_REF_RES; break; case ADUC_1_2_5V_ID: regOff = 0x25; resolution = ADUC_2_5V_REF_RES; break; default: printf("voltLimitSet: illegal voltage identifier\n"); break; } /* write the register */ if(regOff) { char devId; unsigned short limitRegVal = 0; i2c_read(SLAVE_ADDR_5, ADUC812_DEV_ID_OFF, &devId); if(devId == ADUC812_DEV_ID) { limitRegVal = value / resolution; /* add the offset depending on which limit needs to be set */ regOff = regOff + (limit * 2); i2c_page_write(SLAVE_ADDR_5, regOff, (unsigned char *)&limitRegVal, 2); return OK; } } return ERROR;}/******************************************************************************** int readTemp(temp_id, which_limit)** This routine reads the temp. monitor field for the specified NPU* and returns current temp. in Celcius.* This function can only be called on master NPU.** RETURNS: current temp.*/int readTemp(temp_id identifier, which_limit limit){ int regOff = 0; /* check for master */ if(!isNPUMaster()) { return 0; } switch(identifier) { case M_NPU_ID: regOff = 0x2A + limit; break; case S_NPU_ID: regOff = 0x2D + limit; break; default: printf("readTemp: illegal tempreature identifier\n"); break; } /* read the register */ if(regOff) { char devId; unsigned char monitorRegVal = 0; i2c_read(SLAVE_ADDR_5, TEMP_DEV_ID_OFF, &devId); if(devId == TEMP_DEV_ID) { i2c_read(SLAVE_ADDR_5, regOff, (unsigned char *)&monitorRegVal); return ((int)monitorRegVal); } } return 0;}/******************************************************************************** STATUS tempLimitSet(temp_id, int, which_limit)** This routine sets the high/low temp. limit for the specified NPU* and returns the status of operation. value should be in Celcius.* This function can only be called on master NPU.** RETURNS: status of operation.*/STATUS tempLimitSet(temp_id identifier, int value, which_limit limit){ int regOff = 0; if(limit == MONITOR) return ERROR; /* check for master */ if(!isNPUMaster()) { return ERROR; } switch(identifier) { case M_NPU_ID: regOff = 0x2B; break; case S_NPU_ID: regOff = 0x2E; break; default: printf("tempLimitSet: illegal voltage identifier\n"); break; } /* write the register */ if(regOff) { char devId; char limitRegVal = 0; i2c_read(SLAVE_ADDR_5, TEMP_DEV_ID_OFF, &devId); if(devId == TEMP_DEV_ID) { limitRegVal = value; /* add the offset depending on which limit needs to be set */ regOff = regOff + limit; i2c_write(SLAVE_ADDR_5, regOff, (unsigned char)limitRegVal); return OK; } } return ERROR;}/******************************************************************************** void aduc812ISR(void)** This routine is interrupt service routine for ADuC812 interrupt.* This function can only be called on master NPU.** RETURNS: nothing*/void aduc812ISR(void){ int aducISRReg, i; /* check for master */ if(!isNPUMaster()) { return; } i2c_seq_read(SLAVE_ADDR_5, INT_OFF, (unsigned char *)&aducISRReg, 4); /* decode source of interrupt */ for(i = 0; i < 20; i++) { if((1 << i) & aducISRReg) { switch(1 << i) { case ADUC_3_3V_M_HIGH: break; case ADUC_3_3V_M_LOW: break; case ADUC_3_3V_HIGH: break; case ADUC_3_3V_LOW: break; case ADUC_2_5V_M_HIGH: break; case ADUC_2_5V_M_LOW: break; case ADUC_2_5V_HIGH: break; case ADUC_2_5V_LOW: break; case ADUC_1_8V_HIGH: break; case ADUC_1_8V_LOW: break; case ADUC_1_5V_HIGH: break; case ADUC_1_5V_LOW: break; case ADUC_1_3V_HIGH: break; case ADUC_1_3V_LOW: break; case ADUC_1_2_5V_HIGH: break; case ADUC_1_2_5V_LOW: break; case ADUC_MASTER_TEMP_HIGH: break; case ADUC_MASTER_TEMP_LOW: break; case ADUC_SLAVE_TEMP_HIGH: break; case ADUC_SLAVE_TEMP_LOW: break; default: break; } } } /* send the shutdown command */ i2c_write(SLAVE_ADDR_5, ADUC812_COMMAND, SHUTDOWN_COMMAND); return;}/******************************************************************************** void aduc812Init(void)** This routine sets up the ISR.* This function can only be called on master NPU.** RETURNS: status of operation.*/void aduc812Init(void){ /* connect the ISR */ pciIntConnect((void *)CPLD_ADUC_INT, aduc812ISR, 0); pciIntEnable(CPLD_ADUC_INT); return;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -