linux应用层直接获取3536芯片温度


根据一下文档,编写单次CPU内部温度测量



/*********************************************
 *	blue star test sample...
 *
 ********************************************/
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 

#define MAP_SIZE	4096
#define MAP_MASK (MAP_SIZE - 1)

#define PERI_PMC68 		0x120e0110
#define V_PERI_PMC68	0x40000000

#define PERI_PMC70		0x120e0118


static int dev_fd; 
int main()
{
	void* p_PERI_PMC68  = NULL;
	void* p_PERI_PMC70  = NULL;
	unsigned int tmp = 0;
	double temprature=0;
	
	dev_fd = open("/dev/mem", O_RDWR | O_NDELAY);        
  
    if (dev_fd < 0)    
    {  
        printf("open(/dev/mem) failed.");      
        return 0;  
    }  
	
	unsigned int *map_base=(void * )mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, dev_fd, PERI_PMC68 & ~MAP_MASK );  
	

	if (NULL == map_base)
	{
		printf("Memory Map error.");
		return 0;
	}
	
	
	p_PERI_PMC68 = map_base+0x110/4;
	p_PERI_PMC70 = map_base+0x118/4;
	
		
#if 1	
	while(1)
	{
		*(unsigned int*)p_PERI_PMC68 = V_PERI_PMC68;
		sleep(1);
		*(unsigned int*)p_PERI_PMC68 = 0x0;
		
		tmp = *(unsigned int*)p_PERI_PMC70 & 0x3ff;
		temprature = 1.0*(tmp-125)/806*165-40;
		//printf("PERI_PMC70:%x\n",*(unsigned int*)p_PERI_PMC70);
		
		sleep(1);
		printf("Temprature:%0.2f 0C\n",temprature);
		//sleep(1);
		
	}
#endif

	
}	 




















你可能感兴趣的:(笔记)