📄 srvopu.c
字号:
/**************************************************
*
* srvopu.c
*
* CVS ID: $Id: srvopu.c,v 1.22 2007/10/30 17:11:56 dellorto Exp $
* Author: Fabio Dell'Orto [FD] - STM
* Date: $Date: 2007/10/30 17:11:56 $
* Revision: $Revision: 1.22 $
*
* Description:
*
*
***************************************************
*
* COPYRIGHT (C) ST Microelectronics 2005
* All Rights Reserved
*
*******************************************************************************
* \brief Optical Pick-Up management procedures
*
* \par Change History:
*
* - BB040426 Enabled ADC for temperature measurement
*
* - PH040601a Modified profile handling. Introduced profile union
* and pointer to it. So it can be switched ROM/RAM
*
* - ST040628 Changes:
* - Introduced check_substrate(), stop_check_substrate()
* and a different version of check_media() for simplified
* media detection (only substrate is detected)
* - Copleted hf_recover()
* - Hardware AGC algorithm already disabled in te_adjust()
* - Introduced erased_cd_rw_recover()
*
* - MR040603- Corrected setting of RATE_CTRL1.agc_dis
*
* - PH040728a Changes:
* - HF check moved from start_ttm() over focus_on() to te_adjust()
* - Declared local functions "static"
* - Introduced uint8, int8, int16, uint16, int32, uint32
* - Usage of doxygen headers
*
* - PH040819a Changes:
* - Modified CHECK_MEDIA: Don't execute switch case if
* startup_report says check_media is done
* - Modified FE_ADJUST: Don't execute switch case if
* startup_report says fe_adjust is done
* - Modified TE_ADJUST: Don't execute switch case if
* startup_report says te_adjust is done
*
* - BB040928a Code rom and ram size optimisation:
* - Optimised check_servo() and evaluation of check_servo() result
*
* - BB041012b Force execution of all calibrations (fe adjust, hf found, te adjust,
* agc focus, agc tracking) if one at new startup if one failed
*
* - BB041013a Fixed te_adjust() min max measurements
*
* - BB050303a channel_offset_calibration() made more robust (added timeout)
* and code size optimizations
*
* - BB050815g Added difference between UNWRITTEN_DISC error if hf problem
* or erased cdrw ()
* - BB051101a Code optimisation
* - Optimised channel_gain_calibration() to work without pointer
*
***************************************************
*
* STM CVS Log:
*
* $Log: srvopu.c,v $ * Revision 1.22 2007/10/30 17:11:56 dellorto * modified roundings and dark level removal in the calculation of AFE amplitudes, * in order to improve the behavior in case of low reflective discs * * Revision 1.21 2007/09/26 15:14:54 dellorto * modified initialisation for new hf detection handling * * Revision 1.20 2007/04/11 14:21:05 belardi * Integration of HAVE_CD_MECHA modification by [GP] *
* Revision 1.19 2007/03/16 14:19:42 dellorto
* used new profiles
*
* Revision 1.18 2006/10/31 11:11:18 marcucci
* No more static functions for Jump Table
*
* Revision 1.17 2006/10/09 15:14:03 dellorto
* no message
*
* Revision 1.16 2006/09/18 09:55:25 belardi
* Corrected CVS keyword usage
*
* Revision 1.15 2006/09/18 09:25:38 belardi
* AddeLogg$ CVS keyword into file header
*
*
******************************************************************************/
#include "gendef.h"
#include "hwreg.h"
#include "osal.h"
#include "srvinc.h"
#include "pdebug.h"
#define enable_max_min_measurement() RA_ADDR = (uint8)0x08
#define start_max_measurement(x) RA_DATA = (x)
#define stop_max_measurement(x) RA_DATA = (x)
#define start_min_measurement(x) RA_DATA = (uint8)((x) - 1)
#define stop_min_measurement(x) RA_DATA = (uint8)((x) - 1)
#define read_measurement() (uint8)(RA_DATA >> 2)
#define CHANNEL_AC (uint8)0x05
#define CHANNEL_BD (uint8)0x07
#define CHANNEL_E (uint8)0x01
#define CHANNEL_F (uint8)0x03
#if (HAVE_CD_MECHA == 1)
uint8 ac_amp;
uint8 bd_amp;
uint8 e_amp;
uint8 f_amp;
uint8 ac_acc;
uint8 bd_acc;
uint8 e_acc;
uint8 f_acc;
uint8 ac_dark_level;
uint8 bd_dark_level;
uint8 e_dark_level;
uint8 f_dark_level;
uint16 error_amp;
sint16 starting_gain;
sint16 fe_gain;
uint8 abcd_amp;
uint8 reflectivity;
sint16 te_mean;
sint16 te_gain;
static uint8 const gain_2_amplitude_vector[0x0C] =
{
0xF2, 0xE4, 0xD7, 0xCB, 0xC0, 0xB5, 0xAB, 0xA1, 0x98, 0x90, 0x88, 0x80
};
static uint8 const amplitude_2_gain_vector[0x20] =
{
0x0C, 0x0B, 0x0B, 0x0A, 0x0A, 0x09, 0x09, 0x08,
0x08, 0x07, 0x07, 0x07, 0x06, 0x06, 0x05, 0x05,
0x05, 0x04, 0x04, 0x04, 0x03, 0x03, 0x03, 0x02,
0x02, 0x02, 0x01, 0x01, 0x01, 0x01, 0x00, 0x00
};
/******************************************************************************/
/* Function: find_level_shift_increment */
/* */
/*! \brief level shift increment calculation
* \param uint8 offset_level
* uint8 scaling_factor
* uint8 gain (from 0x00 to 0x3F, linear in dB, 0x0C = 6dB)
* \return uint8 level shift increment
* \remark
*/
/******************************************************************************/
uint8 find_level_shift_increment(uint8 offset, uint8 scaling_factor, uint8 gain)
{
uint8 shift;
uint8 amplitude;
shift = 0;
if (gain == 0)
{
amplitude = 0xFF;
}
else
{
while (gain > 0x0C)
{
gain -= 0x0C;
shift ++;
}
amplitude = (uint8)(gain_2_amplitude_vector[gain - 1]);
}
return (uint8)((((offset * amplitude) >> shift) + (scaling_factor >> 1)) / scaling_factor);
}
/******************************************************************************/
/* Function: amplitude_2_gain */
/* */
/*! \brief amplitude to gain conversion
* \param uint8 amplitude (from 0x00 to 0x3F, linear)
* \return uint8 gain (from 0x00 to 0x3F, linear in dB, 0x0C = 6dB)
* \remark
*/
/******************************************************************************/
uint8 amplitude_2_gain(uint8 amplitude)
{
uint8 gain;
if (amplitude < 0x02)
{
return 0x3F;
}
else
{
gain = 0;
while (amplitude < 0x20)
{
amplitude <<= 1;
gain += 0x0C;
}
return (uint8)(gain + amplitude_2_gain_vector[amplitude - 0x20]);
}
}
/******************************************************************************/
/* Function: read_measurement_sat_dlr */
/* */
/*! \brief reading of channel measurement with checking of saturation (sat)
* and dark level removal (dlr)
* \param void
* \return read value (from 0x00 to 0x3F)
* \remark the considered channel and the type of measure must be specified,
* before reading, using start/stop_max/min_measurement()
*/
/******************************************************************************/
uint8 read_measurement_sat_dlr(uint8 dark_level)
{
uint8 value;
value = (uint8)(RA_DATA >> 2);
if (value == 0x3F)
{
servo_misc_flags.field.channel_saturated = 1;
}
if (value > dark_level)
{
value = (uint8)(value - dark_level);
}
else
{
value = 0;
}
return value;
}
#define read_measurement_ac() read_measurement_sat_dlr(ac_dark_level)
#define read_measurement_bd() read_measurement_sat_dlr(bd_dark_level)
#define read_measurement_e() read_measurement_sat_dlr(e_dark_level)
#define read_measurement_f() read_measurement_sat_dlr(f_dark_level)
/******************************************************************************/
/* Function: afe_init */
/* */
/*! \brief analog front-end initialisation
* \param void
* \return void
* \remark
*/
/******************************************************************************/
void afe_init(void)
{
ANA_TST_CTRL_TOP.all = 0x1D;
laser_off();
abcdef_off();
}
/******************************************************************************/
/* Function: laser_on */
/* */
/*! \brief switch on laser-diode circuit
* \param void
* \return void
* \remark
*/
/******************************************************************************/
void laser_on(void)
{
ANA_LAS_DAC.all = OPU_PRO_LASER_POWER; /* laser on */
DEBUG_SERVO(("Laser_On", 4, 0));
wait_T100us();
}
/******************************************************************************/
/* Function: laser_off */
/* */
/*! \brief switch off laser-diode circuit
* \param void
* \return void
* \remark
*/
/******************************************************************************/
void laser_off(void)
{
ANA_LAS_DAC.all = 0x00; /* laser off */
DEBUG_SERVO(("Laser_Off", 4, 0));
wait_T100us();
}
/******************************************************************************/
/* Function: abcdef_on */
/* */
/*! \brief switch on photodiode channels
* \param void
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -