📄 srvfsm.c
字号:
/************************************************** * * srvfsm.c * * CVS ID: $Id: srvfsm.c,v 1.48 2007/09/26 15:14:23 dellorto Exp $ * Author: Fabio Dell'Orto [FD] - STM * Date: $Date: 2007/09/26 15:14:23 $ * Revision: $Revision: 1.48 $ * * Description: * * *************************************************** * * COPYRIGHT (C) ST Microelectronics 2005 * All Rights Reserved * ******************************************************************************* * \brief TOP LEVEL Servo State Machine function * * \par Change History: * * - PH040601a Modified profile handling. Introduced profile union * and pointer to it. So it can be switched ROM/RAM * * - ST040628 Added ERASED_CD_RW_RECOVER state * * - PH040728a - Changed Order FOCUS_ON->START_TTM to START_TTM->FOCUS_ON * - Declared local functions "static" * - Introduced uint8, int8, int16, uint16, int32, uint32 * - Usage of doxygen headers * - BB040928d Fixed synchronisation between acquisition interrupt and * servo state machine * - BB041109c Fixed noise during jump from data track * - BB041110a Fixed seek to target time * - If jump backward is executed very fast (small jump) it was * possible that last_T get T_actual value before jump * and recovery will be executed: jump last_t + 1 sec * - It was possible that cd_flags.new_T is set but T_actual is * not updated * - BB050114c Modified servo_init_for_new_disc_cmd() to not fail if called * during servo_init_cmd() is executing * - BB050221b Fixed forced request for execution of read TOC * - BB050304 Fixed output interface when configured for 2.1168MHz * (audio_init() made more robust) * - BB050719a Fixed access to variables with flags which are written in ISR * - BB050809b Fixed muting when shockproof controller is off * - BB050810j Code optimizations: optimised servo state execution * - BB050810k Fixed servo pause event generating and handling * - BB060929a Improved no TOC and Copyprotected CD support * - FD060929b Added descriptive READY * *************************************************** * * STM CVS Log: * * $Log: srvfsm.c,v $ * Revision 1.48 2007/09/26 15:14:23 dellorto * modified initialisation for new hf detection handling * * Revision 1.47 2007/08/14 15:30:15 dellorto * multiple mechanisms * * Revision 1.46 2007/04/11 14:21:04 belardi * Integration of HAVE_CD_MECHA modification by [GP] * * Revision 1.45 2007/04/06 06:37:22 hara * Add T_actual handling for more robust TOC reading. * * Revision 1.44 2006/11/25 08:15:26 belardi * Ununsed function removal to free code space * * Revision 1.43 2006/11/21 13:58:43 dellorto * improved hostif reporting of servo parameters in case of restart * * Revision 1.42 2006/11/10 16:35:01 dellorto * introduced configurable compiling options for servo error variables * * Revision 1.41 2006/10/31 11:10:49 marcucci * No more static functions for Jump Table * * Revision 1.40 2006/10/26 10:20:39 dellorto * removal of servo_cmd_result * * Revision 1.39 2006/10/09 15:13:04 dellorto * improved TTM recover for DC TTM motor * different start-up transition for DC TTM motor * * Revision 1.38 2006/09/19 10:29:20 belardi * Comments * * Revision 1.37 2006/09/18 09:55:25 belardi * Corrected CVS keyword usage * * Revision 1.36 2006/09/18 09:25:37 belardi * Added Log CVS keyword into file header * * ******************************************************************************/#include "gendef.h"#include "hwreg.h"#include "osal.h"#include "srvinc.h"#include "pdebug.h"#include "debug.h"#include "capture.h"#ifdef APM_PICKUP #include "service.h"#else #include "hostif_high.h"#endif#if (HAVE_CD_MECHA == 1)uint16 servo_function_counter;uint16 servo_function_counter_2;uint8 tmp_cmd; /* FD060929b */uint8 sm_state_0;uint8 sm_state_1;uint8 sm_state_2;static uint8 prev_sm_state_0;uint8 prev_sm_state_1;static uint8 prev_sm_state_2;#define prev_servo_fsm_state prev_sm_state_0static uint8 servo_retries;SERVO_ACQ_FLAGS_UNION servo_acq_flags;SERVO_STARTUP_FLAGS_UNION servo_startup_flags;SERVO_RECOVER_FLAGS_UNION servo_recover_flags;SERVO_SEEK_FLAGS_UNION servo_seek_flags;SERVO_ACTIVE_FLAGS_UNION servo_active_flags;SERVO_MISC_FLAGS_UNION servo_misc_flags;static RETVAL error_reason;#ifdef HAVE_DEBUG_SERVO_ERRORSstatic RETVAL first_error_reason; // debug variablestatic uint8 state_with_error; // debug variablestatic uint8 state_with_first_error; // debug variable#endifuint8 max_servo_retries;RETVAL servo_fsm_result;RETVAL servo_command_result;// OS20 stuffvoid ServoTask(void *unused);tQsubcode_event servo_subcode_event[EVENT_MAX_STAGES];void *get_servo_subcode_event_data(t_event_stage i){ return (void *)&servo_subcode_event[i];}/******************************************************************************//* Function: servo_set_max_retries *//* *//*! \brief Setter function for setting the maximum number of retries. * \param uint8 - The new number of maximum reties. If 0xFF then the maxi- * mum number of retries is set to the default value. * \return void * \remark *//******************************************************************************/#if 0 // [RB] unusedvoid servo_set_max_retries(uint8 max){ if (0xFF == max) { max_servo_retries = MAX_SERVO_RETRIES; } else { max_servo_retries = max; }}#endif////////////////////////////////////////////////////////////////////////////////// MUTE DETECTOR/////////////////////////////////////////////////////////////////////////////////******************************************************************************//* Function: oif_mute_detect *//* *//*! \brief Checks whether mute/unmute condition had effect * \param void * \return void * \remark *//******************************************************************************/#ifdef APM_PICKUP // BBTODO mute (oif) handling must to be moved to decoder [RB] commented out to reduce ROM code spacevoid oif_mute_detect(void){ if (1 == oif_mute_control.mute_start) { oif_mute_control.mute_start = 0; start_timer(MUTE_TIMER, T30ms); }#ifdef APM_PICKUP if ((0 == timer_in_progress(MUTE_TIMER)) || (!(((0 != oif_mode.i2s) && ((OIF_AP_MUTE_CTRL.all & MUTE_I2S_FORCE) != MUTE_I2S_FORCE)) || ((0 != oif_mode.spdif) && ((OIF_AP_MUTE_CTRL.all & MUTE_SPDIF_FORCE) != MUTE_SPDIF_FORCE)) || (0 != oif_mode.analog)))) { oif_mute_control.ad_mute_status = 1; } else { oif_mute_control.ad_mute_status = 0; }#else // [RB] not really used in non-APM code if (!timer_in_progress(MUTE_TIMER)) { OIF_SPDIF_CONTROL.field.i2s_spdif_mux = 1; oif_mute_control.ad_mute_status = OIF_I2S_SPDIF_REG_2.mux_1_field.ad_mute; OIF_SPDIF_CONTROL.field.i2s_spdif_mux = 0; }#endif}#endif // #if 0////////////////////////////////////////////////////////////////////////////////// Management of Errors and Requests/////////////////////////////////////////////////////////////////////////////////******************************************************************************//* Function: reset_servo_errors *//* *//*! \brief Initialize error variables. Interface * \param void * \return void * \remark *//******************************************************************************/void reset_servo_errors(void){ error_reason = NO_ERROR_REASON;#ifdef HAVE_DEBUG_SERVO_ERRORS first_error_reason = NO_ERROR_REASON; state_with_error = NO_STATE; state_with_first_error = NO_STATE;#endif servo_retries = max_servo_retries; dsp_error_flags.all = 0;}/******************************************************************************//* Function: report_servo_error *//* *//*! \brief save error_reason and state_with_error * \param uint8 error * \return void * \remark In case of first occurence, store first_error_reason * and state_with_first_error *//******************************************************************************/void report_servo_error(RETVAL error){ error_reason = error;#ifdef HAVE_DEBUG_SERVO_ERRORS state_with_error = servo_fsm_state; if (servo_retries == max_servo_retries) { first_error_reason = error; state_with_first_error = servo_fsm_state; }#endif}/******************************************************************************//* Function: servo_fsm_transition_handling *//* *//*! \brief Error and request handler of servo state machine * \param void * \return void * \remark Decides if error is recoverable or not and executes * appropriate actions *//******************************************************************************/RETVAL servo_fsm_transition_handling(RETVAL transition_reason){ if ((IN_PROGRESS != transition_reason) && (OK != transition_reason)) { DEBUG_SERVO(("servo_fsm trans_reason ", 1, 1, transition_reason)); stop_timer(SERVO_SAFETY_TIMER); if (IS_SERVO_ERROR(transition_reason)) { report_servo_error(transition_reason); if (IS_SERVO_RECOVERABLE_ERROR(transition_reason)) {#if (1 == HAVE_SHOCK_MEMORY) if ((servo_retries != 0) || (cap_config.esp && (cap_esp_margin > CAP_ESP_EXTEND_SERVO_RETRIES_THRS))) { if (servo_retries != 0) { servo_retries--; }#else if (servo_retries != 0) { servo_retries--;#endif if ((TTM_STOPPED != transition_reason) && (!servo_recover_flags.field.ttm_recover_active)) { set_disc_control(DISC_CONTROL_RECOVER); } else { prepare_ttm_for_recover(); } switch (transition_reason) { case PLL_UNLOCKED: servo_fsm_state = JUMP_TTM_CHECK; break; case TTM_STOPPED: servo_fsm_state = TTM_RECOVER; break; case FOCUS_NOT_FOUND: case FOCUS_LOST: servo_fsm_state = FOCUS_RECOVER; break; case TRACKING_NOT_FOUND: case TRACKING_LOST: servo_fsm_state = TRACKING_RECOVER; break; case HF_NOT_FOUND: sm_state_1 = STATE_1; case HF_LOST: servo_fsm_state = HF_RECOVER; break; case ERASED_CD_RW: servo_fsm_state = ERASED_CD_RW_RECOVER; break; //case PLL_ERROR: default: servo_fsm_state = PLL_RECOVER; break; } } else /* (servo_retries == 0) && (shock margin exhausted) */ { //error_reason = MAX_SERVO_RETRIES_ERROR; servo_fsm_state = ERROR_STATE; } } else /* (IS_SERVO_UNRECOVERABLE_ERROR(transition_reason)) */ { if (IS_SERVO_FATAL_ERROR(transition_reason)) { /* LOAD_DSP_ERROR */ servo_fsm_state = FATAL_ERROR; } else /* other UNRECOVERABLE errors */ { /* SLEDGE_ERROR */ /* CALIBRATION_ERROR */ /* MEDIA_NOT_FOUND */ /* FE_ADJUST_ERROR */ /* TTM_SPEED_ERROR */ /* UNWRITTEN_DISC */ /* TE_ADJUST_ERROR */ /* AGC_FOCUS_ERROR */ /* AGC_TRACKING_ERROR */ /* SEEK_ERROR */ /* one of TIMEOUT_ERROR */#if (1 == HAVE_SHOCK_MEMORY) if ((TTM_SPEED_ERROR == transition_reason) && (cap_config.esp && (cap_esp_margin > CAP_ESP_EXTEND_SERVO_RETRIES_THRS))) { servo_fsm_state = TTM_RECOVER; } else#endif { servo_fsm_state = ERROR_STATE; } } } } else if (IS_SERVO_REQUEST(transition_reason)) { switch (transition_reason) { case INIT_REQUEST: servo_fsm_state = SERVO_INIT; reset_servo_errors(); break; case INIT_FOR_NEW_DISC_REQUEST: servo_fsm_state = SERVO_INIT_FOR_NEW_DISC; reset_servo_errors(); break; case START_REQUEST: servo_fsm_state = SERVO_START; reset_servo_errors(); break; case SET_SPEED_REQUEST: servo_fsm_state = JUMP_TTM_CHECK; break; case JUMP_REQUEST: servo_fsm_state = START_JUMP; break; case FE_ADJUST_REQUEST: servo_fsm_state = FE_ADJUST; break; case START_TTM_REQUEST: servo_fsm_state = START_TTM; break; case HF_SEARCH_AFTER_HF_NOT_FOUND: servo_fsm_state = HF_RECOVER; sm_state_1 = STATE_1; break; case SKIP_TO_ACCESS_CHECK: servo_fsm_state = ACCESS_CHECK; break; //case FE_ADJUST_RETRY: //case HF_SEARCH_AFTER_FOCUS_LOST: //case MODE1_SEARCH_AFTER_FOCUS_LOST: default: servo_fsm_state = FOCUS_RECOVER; break; } } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -