📄 aud_vr_sd.c
字号:
/*****************************************************************************
* Copyright Statement:
* --------------------
* This software is protected by Copyright and the information contained
* herein is confidential. The software may not be copied and the information
* contained herein may not be used or disclosed except with the written
* permission of MediaTek Inc. (C) 2005
*
* BY OPENING THIS FILE, BUYER HEREBY UNEQUIVOCALLY ACKNOWLEDGES AND AGREES
* THAT THE SOFTWARE/FIRMWARE AND ITS DOCUMENTATIONS ("MEDIATEK SOFTWARE")
* RECEIVED FROM MEDIATEK AND/OR ITS REPRESENTATIVES ARE PROVIDED TO BUYER ON
* AN "AS-IS" BASIS ONLY. MEDIATEK EXPRESSLY DISCLAIMS ANY AND ALL WARRANTIES,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE IMPLIED WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT.
* NEITHER DOES MEDIATEK PROVIDE ANY WARRANTY WHATSOEVER WITH RESPECT TO THE
* SOFTWARE OF ANY THIRD PARTY WHICH MAY BE USED BY, INCORPORATED IN, OR
* SUPPLIED WITH THE MEDIATEK SOFTWARE, AND BUYER AGREES TO LOOK ONLY TO SUCH
* THIRD PARTY FOR ANY WARRANTY CLAIM RELATING THERETO. MEDIATEK SHALL ALSO
* NOT BE RESPONSIBLE FOR ANY MEDIATEK SOFTWARE RELEASES MADE TO BUYER'S
* SPECIFICATION OR TO CONFORM TO A PARTICULAR STANDARD OR OPEN FORUM.
*
* BUYER'S SOLE AND EXCLUSIVE REMEDY AND MEDIATEK'S ENTIRE AND CUMULATIVE
* LIABILITY WITH RESPECT TO THE MEDIATEK SOFTWARE RELEASED HEREUNDER WILL BE,
* AT MEDIATEK'S OPTION, TO REVISE OR REPLACE THE MEDIATEK SOFTWARE AT ISSUE,
* OR REFUND ANY SOFTWARE LICENSE FEES OR SERVICE CHARGE PAID BY BUYER TO
* MEDIATEK FOR SUCH MEDIATEK SOFTWARE AT ISSUE.
*
* THE TRANSACTION CONTEMPLATED HEREUNDER SHALL BE CONSTRUED IN ACCORDANCE
* WITH THE LAWS OF THE STATE OF CALIFORNIA, USA, EXCLUDING ITS CONFLICT OF
* LAWS PRINCIPLES. ANY DISPUTES, CONTROVERSIES OR CLAIMS ARISING THEREOF AND
* RELATED THERETO SHALL BE SETTLED BY ARBITRATION IN SAN FRANCISCO, CA, UNDER
* THE RULES OF THE INTERNATIONAL CHAMBER OF COMMERCE (ICC).
*
*****************************************************************************/
/*******************************************************************************
* Filename:
* ---------
* aud_vr_sd.c
*
* Project:
* --------
* Maui
*
* Description:
* ------------
* This file includes vr sd service functions
*
* Author:
* -------
* -------
*
*==============================================================================
* HISTORY
* Below this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*------------------------------------------------------------------------------
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
* removed!
* removed!
* removed!
*
*------------------------------------------------------------------------------
* Upper this line, this part is controlled by PVCS VM. DO NOT MODIFY!!
*==============================================================================
*******************************************************************************/
#ifndef MED_NOT_PRESENT
/*==== INCLUDES =========*/
#include "kal_release.h"
#include "kal_trace.h"
#include "stack_common.h"
#include "stack_msgs.h"
#include "app_ltlcom.h" /* Task message communiction */
#include "syscomp_config.h"
#include "task_config.h" /* Task creation */
#include "stacklib.h" /* Basic type for dll, evshed, stacktimer */
#include "event_shed.h" /* Event scheduler */
#include "stack_timer.h" /* Stack timer */
/* global includes */
#include "l1audio.h"
#include "device.h"
#include "resource_audio.h"
#include "fat_fs.h"
#include "nvram_enums.h"
#include "nvram_struct.h"
#include "nvram_user_defs.h"
#include "nvram_data_items.h"
#include "custom_nvram_editor_data_item.h"
#include "custom_equipment.h"
/* local includes */
#include "med_global.h"
#include "aud_defs.h"
#include "med_struct.h"
#include "med_api.h"
#include "med_context.h"
#include "med_main.h"
#include "aud_main.h"
#include "med_utility.h"
#ifdef __AUD_TRACE_ON__
#include "med_trc.h"
#endif
#ifdef __MED_VR_MOD__
static const kal_uint16 *hex_0_9_digits = L"0123456789";
static const kal_uint16 *hex_a_f_digits = L"abcdef";
static const kal_uint16 *hex_A_F_digits = L"ABCDEF";
aud_vr_sd_context_struct vr_sd_ctx;
extern aud_vr_context_struct vr_ctx;
/*****************************************************************************
* FUNCTION
* aud_vr_sd_find_word_id
* DESCRIPTION
* vr sd find the index of a word id
* PARAMETERS
* group_id [IN]
* word_id [IN]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_find_word_id(kal_uint16 group_id, kal_uint16 word_id)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 id_length = vr_sd_ctx.id_length[group_id];
kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
kal_int32 i;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
for (i = 0; i < id_length; i++)
{
if (id_array[i] == word_id)
{
return i;
}
}
return -1;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_extract_group_id
* DESCRIPTION
* vr sd parse and extract the group id (a decimal integer) from the assigned folder name (without path)
* PARAMETERS
* filename [?]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_extract_group_id(kal_uint16 *filename)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 *p;
kal_uint16 digit_char;
kal_int32 result;
kal_int32 filename_len = kal_wstrlen(filename);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (filename_len < 1)
{
return -1;
}
for (result = 0; *filename; filename++)
{
digit_char = *filename;
if ((p = kal_wstrchr(hex_0_9_digits, (int)digit_char)) != NULL)
{
result = (result * 10) + (p - hex_0_9_digits);
}
else
{
return -1;
}
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_extract_word_id
* DESCRIPTION
* vr sd parse and extract the word id (a hexadecimal integer) from the assigned folder name (without path)
* PARAMETERS
* filename [?]
* RETURNS
* kal_int32
*****************************************************************************/
kal_int32 aud_vr_sd_extract_word_id(kal_uint16 *filename)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 *p;
kal_uint16 digit_char, i, j;
kal_int32 result;
kal_int32 filename_len = kal_wstrlen(filename);
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
if (filename_len < 8)
{
return -1;
}
for (result = 0, i = 0, j = filename_len - 8; i < 4; i++, j++)
{
digit_char = filename[j];
if ((p = kal_wstrchr(hex_0_9_digits, (int)digit_char)) != NULL)
{
result = (result << 4) + (p - hex_0_9_digits);
}
else if ((p = kal_wstrchr(hex_a_f_digits, (int)digit_char)) != NULL)
{
result = (result << 4) + (p - hex_a_f_digits + 10);
}
else if ((p = kal_wstrchr(hex_A_F_digits, (int)digit_char)) != NULL)
{
result = (result << 4) + (p - hex_A_F_digits + 10);
}
else
{
return -1;
}
}
return result;
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_scan_tags_in_group_folder
* DESCRIPTION
* vr sd scan all tags in a group folder
* PARAMETERS
* group_id [IN]
* path [?]
* RETURNS
* void
*****************************************************************************/
void aud_vr_sd_scan_tags_in_group_folder(kal_uint16 group_id, kal_uint16 *path)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 filename[VR_MAX_DB_PATH_LEN + 1];
kal_uint16 filename_expr[VR_MAX_DB_PATH_LEN + 1];
kal_int32 word_id;
FS_HANDLE fd_cursor;
FS_DOSDirEntry file_info;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
vr_sd_ctx.id_length[group_id] = 0;
kal_wsprintf(filename_expr, "%wMTKVR_????.vrd", path);
if ((fd_cursor = FS_FindFirst(filename_expr, 0, 0, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1)) >= 0)
{
/* loop through all vrd files in a group folder */
do
{
/* filter out folder results */
if (!(file_info.Attributes & FS_ATTR_DIR))
{
/* parse word id and add to id array and increment id length */
if ((word_id = aud_vr_sd_extract_word_id(filename)) >= 0)
{
vr_sd_ctx.id_array[group_id][vr_sd_ctx.id_length[group_id]++] = word_id;
}
}
} while (FS_FindNext(fd_cursor, &file_info, filename, (VR_MAX_DB_PATH_LEN + 1) << 1) == FS_NO_ERROR);
FS_FindClose(fd_cursor);
}
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_filter_out_not_exist_tags
* DESCRIPTION
* vr sd scan all tags in a group id array and remove non-existing tag ids from the array
* PARAMETERS
* group_id [IN]
* RETURNS
* void
*****************************************************************************/
void aud_vr_sd_filter_out_not_exist_tags(kal_uint16 group_id)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
FS_HANDLE file_handle;
kal_wchar file_name[VR_MAX_DB_PATH_LEN + 1];
kal_uint32 i, count;
kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
kal_uint16 id_len = vr_sd_ctx.id_length[group_id];
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* loop through id array */
for (i = count = 0; i < id_len; i++)
{
/* check does each tag file exist */
kal_wsprintf(file_name, "%wMTKVR_%04x.vrd", vr_ctx.db_path, id_array[i]);
if ((file_handle = FS_Open(file_name, FS_READ_ONLY)) >= 0)
{
FS_Close(file_handle);
id_array[count++] = id_array[i];
}
}
/* update id length to the number of exisiting tag files in id array */
if (count != id_len)
{
vr_sd_ctx.id_length[group_id] = count;
}
}
/*****************************************************************************
* FUNCTION
* aud_vr_sd_delete_one_tag
* DESCRIPTION
* vr sd delete a tag id with its file and its id in the array
* PARAMETERS
* group_id [IN]
* word_id [IN]
* RETURNS
* kal_bool
*****************************************************************************/
kal_bool aud_vr_sd_delete_one_tag(kal_uint16 group_id, kal_uint16 word_id)
{
/*----------------------------------------------------------------*/
/* Local Variables */
/*----------------------------------------------------------------*/
kal_uint16 *id_length_p = &vr_sd_ctx.id_length[group_id];
kal_uint16 *id_array = vr_sd_ctx.id_array[group_id];
kal_int32 i, j;
kal_wchar filename[VR_MAX_DB_PATH_LEN + 1];
kal_bool result;
/*----------------------------------------------------------------*/
/* Code Body */
/*----------------------------------------------------------------*/
/* find the index of word id in id array */
if ((j = aud_vr_sd_find_word_id(group_id, word_id)) >= 0)
{
/* delete tag file */
kal_wsprintf(filename, "%c:\\VRDB\\ISD\\%d\\MTKVR_%04x.vrd", (kal_uint8) vr_ctx.db_drive, group_id, word_id);
if (FS_Delete(filename) == FS_NO_ERROR)
{
/* left shift rest word ids in id array */
(*id_length_p)--;
for (i = j; i < *id_length_p; i++)
{
id_array[i] = id_array[i + 1];
}
result = KAL_TRUE;
}
else
{
result = KAL_FALSE;
}
}
else
{
result = KAL_TRUE;
}
return result;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -