📄 temper.c
字号:
/******************************************************************************* * CONFIDENTIAL - PHILIPS APM * * This is unpublished work is a trade secret. Philips APM owns all rights * to this work and intends to maintain it in confidence to preserve its * trade secret status. Philips Automotive Playback Modules reserves the * right to protect this work as an unpublished copyrighted work in the * event of an inadvertent Automotive Systems also reserves its right. * Those having access to this work mayor deliberate unauthorized publication. * Do not copy it, use it, or disclose the information contained in it * without the written authorization of Philips Automotive Playback Modules. ******************************************************************************//******************************************************************************//*! \file * * Project Scope: CDM M8 * * Organization: Philips APM-DS * * Version Control: * \source sources\main\temper.c * \version 0.1 * \author Bernard Bosnjak * \date 26.04.2004 * * Target Hardware: Accordo ******************************************************************************* * \brief Temperature management * * \par Change History: * * - BB050117 Added mean temperature value calculation * ******************************************************************************/#include "gendef.h"#if (HAVE_TEMP_SENSOR==1)#define S_ONE_TEMPER#include "hwreg.h"#include "temper.h"#include "srvinc.h"#include "player.h"#include "hostif_low.h"#define TEMPERATURE_COLD_dC 0#define TEMPERATURE_FNCT_dC 50#define TEMPERATURE_SPONT_DC 65#define TEMPERATURE_SPEC_dC 90/* 1V = 0x200 = 250sC */#define _MAX_ADC 512#ifdef S_ONE_TEMPER#define _TEMP_dC_AT_MAX_ADC 112 //for EPCOS NTC #else#define _TEMP_dC_AT_MAX_ADC 127#endif#define TEMPERATURE_ADC_2_dC(x) ((x)*_TEMP_dC_AT_MAX_ADC/_MAX_ADC+4)#define TEMPERATURE_dC_2_ADC(x) ((x)*_MAX_ADC/_TEMP_dC_AT_MAX_ADC)#define TEMPERATURE_CHECK T2s#define TEMPERATURE_TIMEOUT T60s#if (TEMPERATURE_SPEC_dC < TEMPERATURE_FNCT_dC)#error "TEMPERATURE_SPEC_dC must be >= TEMPERATURE_FNCT_dC"#endif#define COLD_STATE 0#define HOT_STATE 1typedef struct{ UInt state : 1; UInt ready : 1;} TEMP_CTRL_STRUCT;typedef union{ uint8 all; TEMP_CTRL_STRUCT field;} TEMP_CTRL_UNION;static int8 temperature;static TEMP_CTRL_UNION temp_ctrl;static uint16 adc_sum;static uint8 adc_cnt;static int8 temp_mean;#define MAX_ADC_SAMPLE 64#define TEMPERATURE_MSG_REQUEST() do{ \ send_hostif_inevent(HOSTIF_SPONTANEOUS_SEND_MSG); \}while(0)/******************************************************************************//* Function: calc_temperature *//* *//*! \brief * \param void * \return void * \remark *//******************************************************************************/static void calc_temperature(void){ adc_sum += AUX1L; adc_sum += ((AUX1H & 0x07) << 8); if (0 == --adc_cnt) { temp_mean = (int8) TEMPERATURE_ADC_2_dC(adc_sum / MAX_ADC_SAMPLE); adc_cnt = MAX_ADC_SAMPLE; adc_sum = 0; temp_ctrl.field.ready = 1; }}/******************************************************************************//* Function: temperature_init *//* *//*! \brief * \param void * \return void * \remark *//******************************************************************************/void temperature_init(void){ temp_ctrl.all = 0; temperature = 0; temp_mean = 0; adc_sum = 0; adc_cnt = MAX_ADC_SAMPLE;#if (HAVE_CD_MECHA == 1) afe_init();#endif start_timer(TEMPERATURE_TIMER,T30s); stop_timer(TEMPERATURE_SPONT_SEND_TIMER);}/******************************************************************************//* Function: temperature_fsm *//* *//*! \brief * \param void * \return void * \remark *//******************************************************************************/void temperature_fsm(void){ calc_temperature(); if (!timer_in_progress(TEMPERATURE_TIMER) && temp_ctrl.field.ready) { start_timer(TEMPERATURE_TIMER, TEMPERATURE_CHECK); temp_ctrl.field.ready = 0; temperature = temp_mean; if (COLD_STATE == temp_ctrl.field.state) { if (temperature > TEMPERATURE_FNCT_dC) { temp_ctrl.field.state = HOT_STATE; } else { temperature = TEMPERATURE_COLD_dC; } } if (HOT_STATE == temp_ctrl.field.state) { if (temperature <= TEMPERATURE_FNCT_dC) { temp_ctrl.field.state = COLD_STATE; temperature = TEMPERATURE_COLD_dC; } else { if (temperature >= TEMPERATURE_SPONT_DC) { if (temperature > TEMPERATURE_SPEC_dC) { temperature = TEMPERATURE_SPEC_dC; } if (!timer_in_progress(TEMPERATURE_SPONT_SEND_TIMER)) { start_timer(TEMPERATURE_SPONT_SEND_TIMER, TEMPERATURE_TIMEOUT); TEMPERATURE_MSG_REQUEST(); } } } } }}/******************************************************************************//* Function: temperature_get *//* *//*! \brief * \param void * \return int8 * \remark *//******************************************************************************/int8 temperature_get(void){ return temperature;}#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -