⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 med_utility.c

📁 最新MTK手机软件源码
💻 C
📖 第 1 页 / 共 3 页
字号:
    if (req_p->location == 0)
    {
        *(req_p->buffer_p) = med_alloc_int_mem(req_p->buffer_size);
    }
    else
    {
        *(req_p->buffer_p) = med_alloc_ext_mem(req_p->buffer_size);
    }

    MED_SET_EVENT(MED_EVT_GET_BUFFER);
}


/*****************************************************************************
 * FUNCTION
 *  med_free_buffer_req_hdlr
 * DESCRIPTION
 *  
 * PARAMETERS
 *  ilm_ptr     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void med_free_buffer_req_hdlr(ilm_struct *ilm_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    media_free_buffer_req_struct *req_p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    req_p = (media_free_buffer_req_struct*) ilm_ptr->local_para_ptr;
    if (req_p->location == 0)
    {
        med_free_int_mem(req_p->buffer_p);
    }
    else
    {
        med_free_ext_mem(req_p->buffer_p);
    }

    MED_SET_EVENT(MED_EVT_FREE_BUFFER);
}


/*****************************************************************************
 * FUNCTION
 *  med_start_base_timer
 * DESCRIPTION
 *  
 * PARAMETERS
 *  base_timer_ptr      [?]         
 *  time_out            [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void med_start_base_timer(void *base_timer_ptr, kal_uint32 time_out)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    stack_start_timer((stack_timer_struct*) base_timer_ptr, MED_BASE_TIMER_ID, time_out);
    return;
}


/*****************************************************************************
 * FUNCTION
 *  med_stop_base_timer
 * DESCRIPTION
 *  
 * PARAMETERS
 *  base_timer_ptr      [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void med_stop_base_timer(void *base_timer_ptr)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    stack_stop_timer((stack_timer_struct*) base_timer_ptr);
    return;
}


/*****************************************************************************
 * FUNCTION
 *  med_timer_expiry_callback
 * DESCRIPTION
 *  
 * PARAMETERS
 *  arg     [?]     
 * RETURNS
 *  void
 *****************************************************************************/
void med_timer_expiry_callback(void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint8 *timer_id = (kal_uint8*) arg;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if ((kal_uint32) timer_id < (kal_uint32) MAX_NUM_OF_MED_TIMER)
    {
        med_timer_table[(kal_uint32) (timer_id)].event_id = NULL;
        (med_timer_table[(kal_uint32) (timer_id)].callback_func) (med_timer_table[(kal_uint32) (timer_id)].arg);
    }
}


/*****************************************************************************
 * FUNCTION
 *  med_start_timer
 * DESCRIPTION
 *  
 * PARAMETERS
 *  timer_id            [IN]        
 *  period              [IN]        
 *  timer_expiry        [IN]        
 *  arg                 [?]         
 * RETURNS
 *  void
 *****************************************************************************/
void med_start_timer(kal_uint8 timer_id, kal_uint32 period, kal_timer_func_ptr timer_expiry, void *arg)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_uint16 temp = (period * 7) >> 5;    /* ~= x 1/4.615 */

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (temp == 0)
    {
        temp = 1;
    }
    med_timer_table[timer_id].callback_func = timer_expiry;
    med_timer_table[timer_id].arg = arg;
    med_timer_table[timer_id].event_id = evshed_set_event(
                                            med_context_p->event_scheduler_ptr,
                                            (kal_timer_func_ptr) med_timer_expiry_callback,
                                            (void*)timer_id,
                                            temp /** KAL_TICKS_10_MSEC */ );
}


/*****************************************************************************
 * FUNCTION
 *  med_stop_timer
 * DESCRIPTION
 *  
 * PARAMETERS
 *  timer_id        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void med_stop_timer(kal_uint8 timer_id)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (med_timer_table[timer_id].event_id != NULL)
    {
        evshed_cancel_event(med_context_p->event_scheduler_ptr, &(med_timer_table[timer_id].event_id));
        med_timer_table[timer_id].event_id = NULL;
    }

}


/*****************************************************************************
 * FUNCTION
 *  med_alloc_int_mem
 * DESCRIPTION
 *  
 * PARAMETERS
 *  size        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void *med_alloc_int_mem(kal_int32 size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    void *p ;

    kal_take_mutex(med_mem_mutex);
    p = (void*)med_int_smalloc((size_type) size);
    kal_give_mutex(med_mem_mutex);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (p == NULL)
    {
        ASSERT(p != NULL);
    }
    return p;
}


/*****************************************************************************
 * FUNCTION
 *  med_free_int_mem
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pointer     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void med_free_int_mem(void **pointer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_take_mutex(med_mem_mutex);
    med_int_sfree((address_t) * pointer);
    *pointer = NULL;
    kal_give_mutex(med_mem_mutex);
}


/*****************************************************************************
 * FUNCTION
 *  med_alloc_ext_mem
 * DESCRIPTION
 *  
 * PARAMETERS
 *  size        [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void *med_alloc_ext_mem(kal_int32 size)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    void *p;

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    if (size == 0)
    {
        return NULL;
    }
    kal_take_mutex(med_mem_mutex);
    p = (void*)med_ext_smalloc((size_type) size);
    kal_give_mutex(med_mem_mutex);
    //if(p==NULL)
    //{
    //ASSERT(p!=NULL);
    //}
    return p;
}


/*****************************************************************************
 * FUNCTION
 *  med_free_ext_mem
 * DESCRIPTION
 *  
 * PARAMETERS
 *  pointer     [IN]        
 * RETURNS
 *  void
 *****************************************************************************/
void med_free_ext_mem(void **pointer)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_take_mutex(med_mem_mutex);
    med_ext_sfree((address_t) * pointer);
    kal_give_mutex(med_mem_mutex);
    *pointer = NULL;
}


/*****************************************************************************
 * FUNCTION
 *  med_check_disc_space
 * DESCRIPTION
 *  
 * PARAMETERS
 *  dir_name        [?]         
 *  free_byte       [IN]        
 * RETURNS
 *  
 *****************************************************************************/
kal_int32 med_check_disc_space(kal_wchar *dir_name, kal_int32 free_byte)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
    kal_int32 result;
    FS_DiskInfo disc_info;
    kal_wchar dir[3];

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    kal_mem_set(dir, 0, 6);
    kal_mem_cpy(dir, dir_name, 4);
    /* check the available free space */
    result = FS_GetDiskInfo((kal_wchar*) dir, &disc_info, FS_DI_BASIC_INFO | FS_DI_FREE_SPACE);

    if (result & (FS_DI_BASIC_INFO | FS_DI_FREE_SPACE))
    {
        if ((disc_info.FreeClusters * disc_info.SectorsPerCluster * disc_info.BytesPerSector) < free_byte)
        {
            return MED_RES_DISC_FULL;
        }
        else
        {
            return MED_RES_OK;
        }
    }
    else
    {
        return MED_RES_NO_DISC;
    }
}


/*****************************************************************************
 * FUNCTION
 *  med_get_media_type
 * DESCRIPTION
 *  
 * PARAMETERS
 *  file_name       [?]     
 * RETURNS
 *  

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -