/**************************************************************************************************
* FILENAME
* flash.c
*
* VERSION
* 1.0
*
* DESCRIPTION
* This file contains the timer initial routine and timer ISR.
*
* DATA STRUCTURES
* None
*
* FUNCTIONS
* 1.
* 2.
*
* HISTORY
* 10/28/2003 Ver 1.0 Created by Hank Ji
*
* REMARK
* None
*
*************************************************************************************************/
#include <stdio.h>
#include "740defs.h"
#define C_communication
#include "ist.h"
/************************************************/
/* Name: Fun_pc_com */
/* In: None */
/* Out: None */
/* Description: */
/* communication with pc */
/************************************************/
bool Fun_pc_com(void)
{
uint16 temp1;
//get head char
pcdata.head = Fun_UART_getchar();
RevData[0] = pcdata.head;
//get other ascii and end char
temp1 = Fun_UART_getdata(RevData);
if(temp1 == 0)
{
nops;
return False; //receive fail
}
pcdata.command = RevData[1];
pcdata.size = (RevData[2]*256) + RevData[3];
pcdata.error = RevData[temp1 - 2];
pcdata.parity = RevData[temp1 - 1];
pcdata.end = RevData[temp1];
if(pcdata.size != (temp1-6))
{
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_SIZE;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return False;
}
if(pcdata.error != 0)
{
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_ERR;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return False;
}
if(pcdata.parity != check_sum(RevData,(temp1-2)))
{
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_PARITY;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return False;
}
switch(pcdata.command)
{
case CMD_TEST:
Fun_pccom_test();
break;
case CMD_GET_IMAGE:
Fun_pccom_getimage();
break;
case CMD_GET_SYS:
Fun_pccom_getsys();
break;
case CMD_GET_IO:
Fun_pccom_getio();
break;
case CMD_SET_IO:
Fun_pccom_setio();
break;
case CMD_POWER_OFF:
Fun_pccom_poweroff();
break;
case CMD_SEND_IMG_BEGIN:
Fun_SEND_IMG_BEGIN();
break;
case CMD_SEND_IMG_NEXT:
Fun_SEND_IMG_NEXT();
break;
case CMD_SEND_IMG_AGAIN:
Fun_SEND_IMG_AGAIN();
break;
case CMD_SEND_IMG_END:
Fun_SEND_IMG_END();
break;
case CMD_TEST_SYSTEM:
Fun_test_system();
break;
case CMD_TEST_IMAGE:
Fun_test_image();
break;
default:
break;
}
return True;
}
/************************************************/
/* Name: Fun_test_system */
/* In: None */
/* Out: None */
/* Description: */
/* Read Image and transfer to pc */
/************************************************/
void Fun_test_system(void)
{
RevData[4] = ERR_NONE;
if(Fun_test_flash())
{
RevData[4] |= ERR_FLASH;
}
RevData[2] = 0;
RevData[3] = 0;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
}
bool Fun_test_flash(void)
{
uint8 chs = 0;
uint8 chs1 = 0;
uint32 i;
//check boot
for(i=0;i<0xfff;i++)
{
chs = chs + VPchar(Flash_baseaddr+i);
}
if(chs != VPchar(Flash_baseaddr+0xfff))return False;
//check download
chs = 0;
for(i=0x1000;i<0x2fff;i++)
{
chs = chs + VPchar(Flash_baseaddr+i);
}
if(chs != VPchar(Flash_baseaddr+0x2fff))return False;
//check main
chs = 0;
for(i=0x3000;i<0x2afff;i++)
{
chs = chs + VPchar(Flash_baseaddr+i);
}
if(chs != VPchar(Flash_baseaddr+0x2afff))return False;
//check parameter page
chs = 0;
for(i=0x2ff00;i<0x2ff7f;i++)
{
chs = chs + VPchar(Flash_baseaddr+i);
}
for(i=0x2ff80;i<0x2ffff;i++)
{
chs1 = chs1 + VPchar(Flash_baseaddr+i);
}
if(chs != VPchar(Flash_baseaddr+0x2ff7f))
{
if(chs1 != VPchar(Flash_baseaddr+0x2ffff))return False;
}
return True;
}
/************************************************/
/* Name: Fun_test_image */
/* In: None */
/* Out: None */
/* Description: */
/* Read Image and transfer to pc */
/************************************************/
void Fun_test_image(void)
{
uint32 i;
uint8 dat = RevData[4];
if(Fun_Sensor_init())
{
Led_greenoff;
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_TEST_IMAGE;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return;
}
if(Fun_capture_image(ImageBuffer)==True)
{
for(i=0;i<MIN_IMAGE_SIZE;i++)
{
if(ImageBuffer[i] != dat)
{
RevData[4] = ERR_TEST_IMAGE;
break;
}
}
RevData[4] = ERR_NONE;
}
else
{
RevData[4] = ERR_TEST_IMAGE;
}
RevData[2] = 0;
RevData[3] = 0;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
}
/************************************************/
/* Name: Fun_SEND_IMG */
/* In: None */
/* Out: None */
/* Description: */
/* Read Image and transfer to pc */
/************************************************/
void Fun_SEND_IMG_BEGIN(void)
{
uint8 i;
Led_greenon;
if(Fun_Sensor_init())
{
Led_greenoff;
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_RDIMG_ERR;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return;
}
if(Fun_capture_image(ImageBuffer))
{
Led_greenoff;
RevData[2] = 0;
RevData[3] = 0;
RevData[4] = ERR_RDIMG_ERR;
RevData[5] = check_sum(RevData,4);
RevData[6] = PCCOM_END;
Fun_UART_senddata(RevData,6,0);
return;
}
Led_greenoff;
Imag_data_size = 0;
RevData[2] = 0;
RevData[3] = 0x80;
for(i=0;i<128;i++)
{
RevData[i+4] = ImageBuffer[Imag_data_size +i];
}
RevData[132] = 0;
RevData[133] = check_sum(RevData,131);
RevData[134] = PCCOM_END;
Fun_UART_senddata(RevData,134,0);
return;
}
void Fun_SEND_IMG_NEXT(void)
{
uint8 i;
Imag_data_size = Imag_data_size + 128;
RevData[2] = 0;
RevData[3] = 0x80;
for(i=0;i<128;i++)
{
RevData[i+4] = ImageBuffer[Imag_data_size + i];
}
RevData[132] = 0;
RevData[133] = check_sum(RevData,131);
RevData[134] = PCCOM_END;
Fun_UART_senddata(RevData,134,0);
}
void Fun_SEND_IMG_AGAIN(void)
{
uint8 i;
RevData[2] = 0;
RevData[3] = 0x80;
for(i=0;i<128;i++)
{
RevData[i+4] = ImageBuffer[Imag_data_size +i];
}
RevData[132] = 0;
RevData[133] = check_sum(RevData,131);
RevData[134] = PCCOM_END;
Fun_UART_senddata(RevData,134,0);
}
void Fun_SEND_IMG_END(void)
{
uint8 i;
Imag_data_size = Imag_data_size + 128;
RevData[2] = 0;
RevData[3] = 0x80;
for(i=0;i<128;i++)
{
RevData[i+4] = ImageBuffer[Imag_data_size +i];
}
RevData[132] = 0;
RevData[133] = check_sum(RevData,131);
RevData[134] = PCCOM_END;
Fun_UART_senddata(RevData,134,0);
Flag_get_image = True;
}
/************************************************/
/* Name: Fun_pccom_test */
/* In: None */
/* Out: None */
/* Description: */
/* communication with pc */
/************************************************/
void Fun_pccom_test(void)
{
Fun_UART_senddata(RevData,6,0);
}
/*********************
评论0