📄 capture.c
字号:
void cap_esp_buf_estim_last(void){ /* update next target */ cap_esp_buf.target.lba = cap_esp_buf.last.lba + 1; if (CAP_INPUT_BUFFER_SIZE - 1 == cap_esp_buf.last.pos) { cap_esp_buf.target.pos = 0; } else { cap_esp_buf.target.pos = cap_esp_buf.last.pos + 1; } cap_esp_buf.last.lba = cap_esp_buf.first.lba + CAP_INPUT_BUFFER_SIZE - 1; if (0 == cap_esp_buf.first.pos) { cap_esp_buf.last.pos = CAP_INPUT_BUFFER_SIZE - 1; } else { cap_esp_buf.last.pos = cap_esp_buf.first.pos - 1; }}/******************************************************************************//* Function: cap_esp_buf_update_curr *//* *//*! \brief update current block * \param * \return * \remark *//******************************************************************************/void cap_esp_buf_update_curr(uint32 req_lba, uint16 pos, uint16 offset){ cap_esp_buf.curr.lba = req_lba; cap_esp_buf.curr.pos = pos; cap_esp_buf.curr.first_byte = offset; if (1 == cap_esp_buf.fill) { cap_esp_buf.dist = 0; } else if (cap_esp_buf.curr.pos > cap_esp_buf.last.pos) { cap_esp_buf.dist = CAP_INPUT_BUFFER_SIZE - cap_esp_buf.curr.pos + cap_esp_buf.last.pos; } else { cap_esp_buf.dist = cap_esp_buf.last.pos - cap_esp_buf.curr.pos; } if (cap_esp_buf.dist < CAP_BUFFER_THRS) { cap_esp_buf_update_first(); cap_esp_buf_estim_last(); cap_esp_buf.fill = 1; }}#endif/******************************************************************************//* Function: cap_esp_check_margin *//* *//*! \brief Processing ESP buffer margin * \param * \return * \remark *//******************************************************************************/void cap_esp_check_margin(void){ cap_esp_margin = (cap_status.write.xfer_pointer - cap_status.read.xfer_pointer); if (cap_esp_margin < CAP_ESP_MIN_ADDR_PTR) { cap_esp_margin += (CAP_ESP_STOP_ADDR_PTR); }#ifdef APM_PICKUP /* Report ESP status. */ service_report_esp_status(CAP_INPUT_BUFFER_SIZE_SDRAM, /* ESP buffer size in sectors of 2856 bytes. */ cap_esp_margin >> ((ADPCM_ON == cap_config.adpcm) ? 2 : 0)); /* ESP buffer filling in sectors of 2856 bytes. */#endif DEBUG_ESP_MARGIN();}/******************************************************************************//* Function: cap_esp_search_buffer *//* *//*! \brief Search current buffer contents * \param * \return * \remark *//******************************************************************************/uint16 cap_esp_search_buffer(void){ uint32 req_sector_count; uint32 buf_sector_count; uint32 read_ptr_pos; /* When enter this function, Start sector is in buffer !!! */ /* caculate requested number of sectors */ req_sector_count = local_cap_cmd_event.command_params.xfer_params.sector_stop - local_cap_cmd_event.command_params.xfer_params.sector_start + 1; /* calculte number of setors in buffer */ buf_sector_count = cap_esp_buf.last.lba - local_cap_cmd_event.command_params.xfer_params.sector_start; /* Calculate next read pointer for the case if force_execution bit == '1' */ read_ptr_pos = local_cap_cmd_event.command_params.xfer_params.sector_start - cap_esp_buf.first.lba + cap_esp_buf.first.pos; if (read_ptr_pos >= CAP_INPUT_BUFFER_SIZE) { read_ptr_pos -= CAP_INPUT_BUFFER_SIZE; } if ((local_cap_cmd_event.command_params.xfer_params.force_execution) || (local_cap_cmd_event.command_params.xfer_params.Play_Mode == 0))//DR060912 check for ROM mode { if (req_sector_count > buf_sector_count) { /* Needs to capture remaining sectors */ cap_esp_buf.fill = 1; local_cap_cmd_event.command_params.xfer_params.sector_start = cap_esp_buf.last.lba; cap_status.write.xfer_pointer = cap_esp_buf.last.pos; if (!(cap_status.write.xfer_condition & CAP_ESP_CURR_EVENT_READY_DONE)) { /* Set EVENT_READY flag, it's done with current transition */ cap_status.write.xfer_condition |= CAP_ESP_CURR_EVENT_READY_DONE; /* prepare the status event for controller */ cap_update_fsm_result(NO_ERROR_REASON); event_set_capture(READY); } } else { /* Don't need to capture, just control read controller */ cap_esp_buf.fill = 0; cap_status.write.xfer_pointer = read_ptr_pos + req_sector_count; if (cap_status.write.xfer_pointer >= CAP_INPUT_BUFFER_SIZE) { cap_status.write.xfer_pointer -= CAP_INPUT_BUFFER_SIZE; } } } else { /* Needs to capture remaining sectors */ cap_esp_buf.fill = 1; if (cap_status.write.xfer_condition & CAP_ESP_WAKEUP_TO_RESTART) { int16 local_back_ptr; uint8 *cap_input_buffer; /* Copy restart target sector by BD_START to cap_esp_buf.last. */ if (cap_config.esp && (cap_esp_buf.last.lba > local_bd_event.last_good_lba)) /* tbd */ { if (local_bd_event.last_block_cnt < local_bd_event.last_valid_block_cnt) { local_bd_event.last_block_cnt += 0xFF; }#if (1 == HAVE_SHOCK_MEMORY) if ((ADPCM_ON == cap_config.adpcm) && (DATA_TYPE_CDDA == local_cap_cmd_event.command_params.xfer_params.data_type)) { local_bd_event.last_block_cnt--; /* ADPCM ON: last_block_cnt == "actual count + 1". */ }#endif local_back_ptr = local_bd_event.last_block_cnt - local_bd_event.last_valid_block_cnt; local_bd_event.last_block_cnt = local_bd_event.last_valid_block_cnt = 0; /* Reset block count */ // [FH] 29/Mar/2007 if((cap_esp_buf.last.lba - (uint16)local_back_ptr) < cap_esp_buf.first.lba) { /* Protect wrong local_bd_event.last_good_lba. After Non valid sector transfer, BD shows N-1 address. */ cap_esp_buf.last.pos = cap_esp_buf.first.pos; cap_esp_buf.last.lba = cap_esp_buf.first.lba; } else { if (cap_esp_buf.last.pos >= local_back_ptr) { cap_esp_buf.last.pos -= local_back_ptr; } else { cap_esp_buf.last.pos = CAP_INPUT_BUFFER_SIZE + cap_esp_buf.last.pos - local_back_ptr; } cap_esp_buf.last.lba = local_bd_event.last_good_lba; } /* Shoould delete the following copy in the future. */ cap_status.write.last_good_lba = cap_esp_buf.last.lba; cap_status.write.last_good_ptr = cap_esp_buf.last.pos; } if (DATA_TYPE_CDDA == local_cap_cmd_event.command_params.xfer_params.data_type) {#if (1 == HAVE_SHOCK_MEMORY) if (ADPCM_ON == cap_config.adpcm) { /* For re-start sequence with ADPCM compression ON, it needs extra pre-capturing for ADPCM encode. Last_good_lba--; Last_good_ptr--; */ if (!(cap_status.write.xfer_condition & CAP_ESP_WRITE_PTR_KEEP)) { cap_status.write.last_good_lba--; if (cap_status.write.last_good_ptr) { cap_status.write.last_good_ptr--; } else { cap_status.write.last_good_ptr = CAP_INPUT_BUFFER_SIZE - 1; } } }#endif if ((cap_status.write.last_good_lba - cap_esp_buf.first.lba) > 2) /* Available sectors in buffer. */ { /* Check "target N - 2" sector & "target N - 1" sector doesn't have LEADIN flag */ if (cap_status.write.last_good_ptr >= 2) { cap_input_buffer = CAP_INPUT_BUFFER + ((cap_status.write.last_good_ptr - 2) * CAP_INPUT_SECTOR_SIZE); } else { cap_input_buffer = CAP_INPUT_BUFFER + ((CAP_INPUT_BUFFER_SIZE + cap_status.write.last_good_ptr - 2) * CAP_INPUT_SECTOR_SIZE); } local_back_ptr = 0;#if (1 == HAVE_SHOCK_MEMORY) if (((*(cap_input_buffer + 705) & 0x80) && (ADPCM_ON == cap_config.adpcm)) || ((*(cap_input_buffer + 2469) & 0x80) && (ADPCM_OFF == cap_config.adpcm)))#else if ((*(cap_input_buffer + 2469) & 0x80))#endif { /* "Target N - 2" sector has LEADIN flag. */ local_back_ptr = 2; /* Exclude the N - 2 sector from BD consistensy check window. */ } else { if (cap_status.write.last_good_ptr) { cap_input_buffer = CAP_INPUT_BUFFER + ((cap_status.write.last_good_ptr - 1) * CAP_INPUT_SECTOR_SIZE); } else { cap_input_buffer = CAP_INPUT_BUFFER + ((CAP_INPUT_BUFFER_SIZE + cap_status.write.last_good_ptr - 1) * CAP_INPUT_SECTOR_SIZE); }#if (1 == HAVE_SHOCK_MEMORY) if (((*(cap_input_buffer + 705) & 0x80) && (ADPCM_ON == cap_config.adpcm)) || ((*(cap_input_buffer + 2469) & 0x80) && (ADPCM_OFF == cap_config.adpcm)))#else if ((*(cap_input_buffer + 2469) & 0x80))#endif { /* "Target N - 1" sector has LEADIN flag. */ local_back_ptr = 1; /* Exculde the N - 1 sector from BD consistensy check window. */ } } cap_status.write.last_good_lba -= local_back_ptr; if (cap_status.write.last_good_ptr >= local_back_ptr) { cap_status.write.last_good_ptr -= local_back_ptr; } else { cap_status.write.last_good_ptr = CAP_INPUT_BUFFER_SIZE + cap_status.write.last_good_ptr - local_back_ptr; } } /* if((cap_status.write.last_good_lba - cap_esp_buf.first.lba) > 2) */#if (1 == HAVE_SHOCK_MEMORY) if (ADPCM_ON == cap_config.adpcm) { /* Move back (increment) last_good_ptr for origianl position. */ if (!(cap_status.write.xfer_condition & CAP_ESP_WRITE_PTR_KEEP)) { cap_status.write.xfer_condition |= CAP_ESP_WRITE_PTR_KEEP; cap_status.write.last_good_ptr++; if (cap_status.write.last_good_ptr >= CAP_INPUT_BUFFER_SIZE) { cap_status.write.last_good_ptr = 0; } } }#endif } cap_esp_buf.last.lba = cap_status.write.last_good_lba; cap_esp_buf.last.pos = cap_status.write.last_good_ptr; /***** Should be replaced by cap_esp_buf.last.pos instead of cap_status.write.last_good_ptr in the following program. */ /* Should check write poiner over-lap read pointer */ if (cap_status.write.xfer_pointer >= cap_status.read.xfer_pointer) { if (cap_status.write.last_good_ptr < cap_status.read.xfer_pointer) { /* Now, it happen uderflow..., and it should avoid only pointer over-lap. */ cap_status.read.xfer_pointer = cap_status.write.last_good_ptr; } } else /* cap_status.write.xfer_ponter < cap_status.read.xfer_pointer */ { if ((cap_status.read.xfer_pointer >= cap_status.write.last_good_ptr) && (cap_status.write.xfer_pointer < cap_status.write.last_good_ptr)) { /* Now, it happen uderflow..., and it should avoid only pointer over-lap. */ cap_status.read.xfer_pointer = cap_status.write.last_good_ptr; } } cap_status.write.xfer_pointer = cap_status.write.last_good_ptr; /***** Should be replaced by cap_esp_buf.last.pos instead of cap_status.write.last_good_ptr in the following program. */ cap_esp_check_margin(); /* Copy last.lba to sector_start only when CAP_ESP_WAKEUP_TO_RESTART bit is set. */ local_cap_cmd_event.command_params.xfer_params.sector_start = cap_esp_buf.last.lba; } else /* if(!cap_status.write.xfer_condition & CAP_ESP_WAKEUP_TO_RESTART) */ { /* Reset cap_esp_buf.first/last information */ cap_esp_buf.first.lba = local_cap_cmd_event.command_params.xfer_params.sector_start; cap_esp_buf.first.pos = cap_status.write.xfer_pointer; /* cap_esp_buf.last information show next lba/position to capture. */ cap_esp_buf.last.lba = local_cap_cmd_event.command_params.xfer_params.sector_start; cap_esp_buf.last.pos = cap_status.write.xfer_pointer; } } return read_ptr_pos;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -