Example #1
0
/****************************************************************************
 *
 * NAME: clientOtaFinishing
 *
 * DESCRIPTION:
 * OTA download finishing routine, check the crc of total downloaded image
 * at the external flash
 *
 * PARAMETERS: Name         RW  Usage
 *             None
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
void clientOtaFinishing()
{
#ifdef OTA_CLIENT
    DBG_vPrintf(TRACE_EP, "OtaFinishing: get all %d blocks \r\n", g_sDevice.otaCurBlock);
    g_sDevice.otaDownloading = 0;
    PDM_vSaveRecord(&g_sDevicePDDesc);

    //verify the external flash image
    uint8 au8Values[OTA_MAGIC_NUM_LEN];
    uint32 u32TotalImage = 0;
    bool valid = true;

    //first, check external flash to detect image header
    APP_vOtaFlashLockRead(OTA_MAGIC_OFFSET, OTA_MAGIC_NUM_LEN, au8Values);

    if (memcmp(magicNum, au8Values, OTA_MAGIC_NUM_LEN) == 0)
    {
        DBG_vPrintf(TRACE_EP, "OtaFinishing: found image magic num. \r\n");

        //read the image length out
        APP_vOtaFlashLockRead(OTA_IMAGE_LEN_OFFSET, 4, (uint8 *)(&u32TotalImage));

        if (u32TotalImage != g_sDevice.otaTotalBytes)
        {
            DBG_vPrintf(TRACE_EP, "OtaFinishing: total length not match. \r\n");
            valid = false;
        }
    }
    else
    {
        DBG_vPrintf(TRACE_EP, "OtaFinishing: not find magic num. \r\n");
        valid = false;
    }

    //second, check crc
    uint32 crc = imageCrc(u32TotalImage);
    DBG_vPrintf(TRACE_EP, "OtaFinishing: verify crc: 0x%x \r\n", crc);
    if (crc != g_sDevice.otaCrc)
    {
        DBG_vPrintf(TRACE_EP, "OtaFinishing: crc not match \r\n");
        valid = false;
    }

    if (valid)
    {
        //send upgrade request to ota server
        g_sDevice.otaDownloading = 2;
        PDM_vSaveRecord(&g_sDevicePDDesc);
        //OS_eActivateTask(APP_taskOTAReq);
        vResetATimer(APP_OTAReqTimer, APP_TIME_MS(1000));
        //APP_vOtaKillInternalReboot();
    }
    else
    {
        clientOtaRestartDownload();
    }
#endif
}
Example #2
0
/****************************************************************************
 *
 * NAME: aupsSendApiFrm
 *
 * DESCRIPTION:
 * send a api frame into the stream processor
 *
 * PARAMETERS: Name         RW  Usage
 *             dst          W   Pointer to destination of the buffer
 *             len          R   number of the bytes you want to read
 * RETURNS:
 * uint8: real number of bytes you read
 *
 ****************************************************************************/
PUBLIC uint8 aupsSendApiFrm(void *data, int len)
{
    uint32 avlb_cnt = SPM_u32PushData(data, len);
    if (avlb_cnt >= THRESHOLD_READ)
    {
        OS_eActivateTask(APP_taskHandleUartRx);             //Activate SPM immediately
    } else
    {
        vResetATimer(APP_tmrHandleUartRx, APP_TIME_MS(5));  //Activate SPM 5ms later
    }
}
/****************************************************************************
 *
 * NAME: SPM_vProcStream
 *
 * DESCRIPTION:
 * Stream Processing Machine(SPM) process stream
 * If receive a valid frame, unpack and execute callback
 * else discard it.
 *
 * RETURNS:
 * void
 *
 ****************************************************************************/
PRIVATE void SPM_vProcStream(uint32 dataCnt)
{
	uint8 tmp[RXFIFOLEN] = {0};
	/* calc the minimal */
	uint32 readCnt = MIN(dataCnt, RXFIFOLEN);

	OS_eEnterCriticalSection(mutexRxRb);
	ringbuffer_read(&rb_rx_spm, tmp, readCnt);
	OS_eExitCriticalSection(mutexRxRb);

	/* Instance an apiSpec */
	tsApiSpec apiSpec;
	bool bValid = FALSE;
	memset(&apiSpec, 0, sizeof(tsApiSpec));

	/* Deassemble apiSpec frame */
	uint16 procSize =  u16DecodeApiSpec(tmp, readCnt, &apiSpec, &bValid);
	if(!bValid)
	{
	/*
	  Invalid frame,discard from ringbuffer
	  Any data received prior to the start delimiter will be discarded.
	  If the frame is not received correctly or if the checksum fails,
	  discard too.And Re-Activate Task 1ms later.
	*/
		vResetATimer(APP_tmrHandleUartRx, APP_TIME_MS(1));
	}
	else
	{
		/* Process API frame using API support layer's api */
		API_i32ApiFrmCmdProc(&apiSpec);
	}
	/* Discard already processed part */
	OS_eEnterCriticalSection(mutexRxRb);
	ringbuffer_pop(&rb_rx_spm, tmp, procSize);
	OS_eExitCriticalSection(mutexRxRb);
}