blob: a2ee41774688c8f82c3131c7611183bd2d1101e2 [file] [log] [blame]
/*******************************************************************/
/************************* File Description ************************/
/*******************************************************************/
/* File Name: $Workfile: hmx_uprade.c $
* Version: $Revision: 1.0 $
* Original Author: Yang Hyun Uk $
* Current Author: $Author: huyang@humaxdigital.com $
* Date: $Date: 2011.09.30
* File Description: HTTP Live Streaming
* Module:
* Remarks:
*/
/**
*
* @defgroup UPGRADE Upgrade APIs
*
*/
/**
* @author Hyunuk Yang(huyang@humaxdigital.com)
* @date 30 Sept 2011
*/
/**
* @note
* Copyright (C) 2011 Humax Corporation. All Rights Reserved. <br>
* This software is the confidential and proprietary information
* of Humax Corporation. You may not use or distribute this software
* except in compliance with the terms and conditions of any applicable license
* agreement in writing between Humax Corporation and you.
*/
/*@{*/
/**
* @file hmx_upgrade.c
*/
/*******************************************************************/
/**************************** Header Files *************************/
/*******************************************************************/
/* Start Including Header Files */
#include <stdio.h>
#include "hmx_upgrade.h"
#include "util.h"
/* End Including Headers */
/*******************************************************************/
/****************************** define *****************************/
/*******************************************************************/
#define HMX_UPGRADE_NUMBER_OF_QUEUE 64
#define HMX_UPGRADE_TASK_PRIORITY 10
#define HMX_UPGRADE_TASK_STACK_SIZE (1024*128)
/* End #define */
/*******************************************************************/
/****************************** typedef ****************************/
/*******************************************************************/
/* Start typedef */
/* End typedef */
/*******************************************************************/
/************************ global variables *************************/
/*******************************************************************/
/* Start global variable */
/**
* Upgrade Status Callback notifies status to APP
*/
HMX_UpgradeEventCallback g_fUpgradeStatusCallback = NULL;
HMX_UPGRADE_COMMAND_t g_tUpgradeCommand;
/* End global variable */
/*******************************************************************/
/************************ static variables *************************/
/*******************************************************************/
/* Start static variable */
static unsigned long s_ulUpgradeTaskId = 0;
static unsigned long s_ulUpgradeMessgseId=0;
/* End static variable */
static void P_HMX_Upgrade_Task(void* param);
/**
* @b Function @b Description <br>
* Start Humax Upgrade Module. it creates a thread for Upgrading. <br>
*
* @param[in] callback : specify a callback to get Upgrade Status. if NULL, Upgrade Module can't be started.
* @param[in] file : specify a file path. also http address will be possible. if NULL, Upgrade Module can't be started.
*
* @return # 0 : success <br>
* # 1 : failed <br>
*
*/
int HMX_UPGRADE_Start( HMX_UpgradeEventCallback callback, unsigned char * file)
{
int err;
HMX_UPGRADE_COMMAND_t upgrade_msg;
/* Add Callback */
if( callback == NULL )
{
printf("[%s] ERROR callback porinter is NULL \n", __FUNCTION__);
return 1;
}
g_fUpgradeStatusCallback = callback;
if ( file == NULL )
{
printf("[%s] ERROR file path is nULL\n", __FUNCTION__);
return 1;
}
err = HMX_MSG_Create(HMX_UPGRADE_NUMBER_OF_QUEUE, sizeof(HMX_UPGRADE_COMMAND_t), "UpgradeMsgQ", &s_ulUpgradeMessgseId, HMX_SUSPENDTYPE_FIFO);
if(err != HMX_OK)
{
printf("[%s] [%d] Error(0x%x) \n\r",__FUNCTION__,__LINE__, err);
return HMX_ERROR;
}
err = HMX_TASK_Create( P_HMX_Upgrade_Task, HMX_UPGRADE_TASK_PRIORITY, HMX_UPGRADE_TASK_STACK_SIZE, "UpgradeTask", NULL, &s_ulUpgradeTaskId, 0);
if( err != HMX_OK )
{
printf("[%s] [%d] Error(0x%x) \n\r",__FUNCTION__,__LINE__, err);
return HMX_ERROR;
}
HMX_TASK_Start(s_ulUpgradeTaskId);
upgrade_msg.command = HMX_UPGRADE_FETCH;
/* this should be freed at Reciever */
upgrade_msg.file_path = strdup(file);
err = HMX_MSG_Send(s_ulUpgradeMessgseId, &upgrade_msg, sizeof(HMX_UPGRADE_COMMAND_t),0);
if(err != HMX_OK)
{
printf( "[HMX_UPGRADE_Start] HMX_MSG_Send error : err is 0x%x\n", err);
return HMX_ERROR;
}
return HMX_OK;
}
/**
* @b Function @b Description <br>
* Stop Humax Upgrade Module. even it can be stoped while it is Reading or Flashing. <br>
*
* @return # 0 : success <br>
* # 1 : failed <br>
*
*/
int HMX_UPGRADE_Stop(void)
{
int err;
HMX_UPGRADE_COMMAND_t upgrade_msg;
upgrade_msg.command = HMX_UPGRADE_STOP;
err = HMX_MSG_SendUrgent(s_ulUpgradeMessgseId, &upgrade_msg, sizeof(HMX_UPGRADE_COMMAND_t),0);
if(err != HMX_OK)
{
printf( "[HMX_UPGRADE_Stop] HMX_MSG_Send error : err is 0x%x\n", err);
return HMX_ERROR;
}
HMX_TASK_Stop(s_ulUpgradeTaskId);
err = HMX_TASK_Destroy(s_ulUpgradeTaskId);
if( err != HMX_OK )
{
printf("[%s] [%d] Error(0x%x) \n\r",__FUNCTION__,__LINE__, err);
return HMX_ERROR;
}
err = HMX_MSG_Destroy(s_ulUpgradeMessgseId);
if(err != HMX_OK)
{
printf("[%s] [%d] Error(0x%x) \n\r",__FUNCTION__,__LINE__, err);
return HMX_ERROR;
}
return HMX_OK;
}
#if 0
/**
* @b Function @b Description <br>
* Specify a file to upgrade <br>
*
* @param[in] file : specify full file path.
*
* @return # 0 : success <br>
* # 1 : failed <br>
*
*/
int HMX_UPGRADE_FetchFileToUpgrade(unsigned char * file)
{
int nErr;
HMX_UPGRADE_COMMAND_t upgrade_msg;
if ( file == NULL )
{
printf("[%s] file path is nULL\n", __FUNCTION__);
}
upgrade_msg.command = HMX_UPGRADE_FETCH;
/* this should be freed at Reciever */
upgrade_msg.file_path = strdup(file);
printf("[%s] file path is %s\n", __FUNCTION__, upgrade_msg.file_path);
nErr = HMX_MSG_SendTimeout(s_ulUpgradeMessgseId, &upgrade_msg, sizeof(HMX_UPGRADE_COMMAND_t),0);
if(nErr != HMX_OK)
{
printf( "[HMX_UPGRADE_FetchFileToUpgrade] HMX_MSG_Send error : err is 0x%x\n", nErr);
return HMX_ERR;
}
return HMX_OK;
}
#endif
void HMX_UPGRADE_Call_Callback(HMX_UPGRADE_STATUS_Msg_t * upgrade_status_msg )
{
if ( g_fUpgradeStatusCallback != NULL )
{
g_fUpgradeStatusCallback(upgrade_status_msg);
}
}
/*******************************************************************/
/************************ static funtions **************************/
/*******************************************************************/
static HMX_UPGRADE_EVENT_e P_HMX_UPGRADE_FILE(unsigned char * path)
{
HMX_UPGRADE_STATUS_Msg_t * upgrade_status_msg;
int ret;
upgrade_status_msg = malloc(sizeof(HMX_UPGRADE_STATUS_Msg_t));
printf ("[%s] \n", __FUNCTION__ );
ret = HMX_UPGRADE_HDF_Do_Flash( path );
if ( ret != HMX_OK )
{
printf ("[%s] HMX_UPGRADE_HDF_Do_Flash ret %d\n", __FUNCTION__, ret );
upgrade_status_msg->event = ret;
HMX_UPGRADE_Call_Callback(upgrade_status_msg);
return HMX_UPGRADE_FILE_NOT_EXIST;
}
free(upgrade_status_msg);
return HMX_UPGRADE_DONE;
}
static void P_HMX_Upgrade_Task(void* param)
{
HMX_UPGRADE_EVENT_e nErr;
int upgrade_is_done = 0;
HMX_UPGRADE_COMMAND_t recieved_command;
unsigned char * file_path=NULL;
HMX_UPGRADE_COMMAND_t send_command;
HMX_UPGRADE_STATUS_Msg_t * upgrade_status_msg;
upgrade_status_msg = malloc(sizeof(upgrade_status_msg));
while(1)
{
nErr = HMX_MSG_Receive(s_ulUpgradeMessgseId, &recieved_command, sizeof(HMX_UPGRADE_COMMAND_t));
if(nErr != HMX_OK)
{
printf ("%s (%d) Error> Error VK_MSG_ReceiveTimeout\n",__FUNCTION__,__LINE__);
}
else
{
switch( recieved_command.command)
{
case HMX_UPGRADE_START:
{
printf("[%s] Receive HMX_UPGRADE_START command \n",__FUNCTION__);
/* DO Upgrade ........ here */
nErr = P_HMX_UPGRADE_FILE(file_path);
send_command.command = HMX_UPGRADE_STOP;
(void)HMX_MSG_Send(s_ulUpgradeMessgseId, &send_command, sizeof(HMX_UPGRADE_COMMAND_t),0);
break;
}
case HMX_UPGRADE_STOP:
{
printf("[%s] HMX_UPGRADE_STOP \r\n",__FUNCTION__);
free(upgrade_status_msg);
free(file_path);
/* Notify to app, UPgreade is done. */
upgrade_status_msg->event = HMX_UPGRADE_DONE;
HMX_UPGRADE_Call_Callback(upgrade_status_msg);
/* TASK kills itself. */
return 0;
}
case HMX_UPGRADE_FETCH:
{
printf("[%s] HMX_UPGRADE_FETCH \r\n",__FUNCTION__);
file_path = strdup(recieved_command.file_path);
printf("[%s] file path = %s \r\n",__FUNCTION__, file_path);
/* command file_path free */
free(recieved_command.file_path);
send_command.command = HMX_UPGRADE_START;
(void)HMX_MSG_Send(s_ulUpgradeMessgseId, &send_command, sizeof(HMX_UPGRADE_COMMAND_t),0);
break;
}
default:
printf("[%s] Receive Unknown Command \r\n",__FUNCTION__);
break;
}
}
}
}
/*@}*/