/*
* Copyright 2001 by Texas Instruments Incorporated.
* All rights reserved. Property of Texas Instruments Incorporated.
* Restricted rights to use, duplicate or disclose this code are
* granted through contract.
* U.S. Patent Nos. 5,283,900 5,392,448
*/
/* "@(#) DSP/BIOS 4.51.0 05-23-01 (barracuda-i10)" */
/***************************************************************************/
/* */
/* H E L L O . C */
/* */
/* Basic C standard I/O from main. */
/* */
/* */
/***************************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include "type.h"
#include "mcbsp54.h"
#include "system.h"
#include "tvp5150.h"
#include "comm.h"
#include "motiondetect.h"
typedef struct _UartFrame{
u8 Head;
u8 Type;
u8 Experiment;
u8 Operation;
u8 Method;
u8 Parameter;
}UartFrame, *PuartFrame;
u8 lsrstatus;
extern u8 rece[8];
PuartFrame preceive=0;
int i,parameter,method,exp_flag=0,image_num=-1,image_num1=0,com_mode=0;
extern unsigned int rdv_int,fifoempty_int,rerror_int,timeout_int;
u8 sendsingal1[8]={0x55,0x00,0xff,0x00,0x00,0x00,0x00,0x00};
u8 senddatahead1[8] = {0x55,0x00,0x99,0xff,0x88,0x00,0x00,0x00};
#pragma DATA_SECTION(e_buffer,".e_buffer")
unsigned char e_buffer[25344];
#pragma DATA_SECTION(y_buffer,".y_buffer")
unsigned char y_buffer[25344];
#pragma DATA_SECTION(u_buffer,".u_buffer")
unsigned char u_buffer[6336];
/* ======== main ========*/
void main()
{
tvp5150_init(CIF); //图象采集芯片的初始化
ch375_Init(); //USB芯片的初始化
uart_setup(BAUDRATE_115200, //设置uart的工作参数
WORDLENGTH_8,
STOPBIT_1,
NO_PARITY,
(FIFO_ENABLE+FIFO_DIP_8));
uart_interrupt_control((RDAV_INT+RLS_INT)); //打开uart的数据接收中断和接收状态中断
rece_reset(); //接收数组清零
int_flag_reset(); //中断标志位清零
dsp_interrupt_set(INT_2); //开DSP的INT2中断
dsp_interrupt_set(INT_3); //开DSP的INT3中断
for(;;)
{
if((timeout_int==0x01)) //若是time out中断,则执行以下代码
{
timeout_int=0x00; //超时中断标志清零
UART_FCR_REG = 0x0083; //复位receiver FIFO
asm(" nop ");
asm(" nop ");
uart_sendsingal(TIMEOUTERR,NO_IMAGE_NUM); //通知上位机发生超时错误
}
else if((rerror_int==0x01)) //若是接收错误中断,则执行以下代码
{
rerror_int=0x00; //uart接收错误中断标志清零
UART_FCR_REG = 0x0083; //复位receiver FIFO
asm(" nop ");
asm(" nop ");
uart_sendsingal(RECEIVEERR,NO_IMAGE_NUM); //通知上位机发生接收错误(如接收FIFO溢出错误)
}
else if((rdv_int==0x01)) //若是数据有效中断则判断接收到的数据
{
rdv_int=0x00; //数据有效中断标志清零
preceive = (PuartFrame)(&rece[0]); //将接收数组的首地址赋给结构体指针preceive
if(preceive->Head!=HEAD&&preceive->Head!=0x00)//若数据头有错则通知上位机重发
{
rece_reset(); //接收数组清零
sendsingal(com_mode,HEADERR,NO_IMAGE_NUM); //通知上位机数据头错误
}
else if(preceive->Head==HEAD) //若数据头没错则依据命令操作
{
if(preceive->Type == IMAGE1) //如果上位机进入的是image界面,则报实验选择错
{
Delay50ms();
sendsingal(com_mode,EXP_ERROR,NO_IMAGE_NUM);
}
if(preceive->Type == TEST) //若是测试串口则应答
{
rece_reset(); //接收数组清零
if(com_mode==UART_COM)
{
sendsingal(com_mode,READY,NO_IMAGE_NUM); //测试应答
}
image_num = -1;
}
if(preceive->Type == INIT) //上位机切换实验标签时下位机图像标志重新初始化
{
image_num = -1;
}
switch(preceive->Operation)
{
case START: //若是开始实验命令则采集图象
exp_flag = (int)(preceive->Experiment);
rece_reset();
if(exp_flag!=MOTIONDETECT) //若和上位机实验类型不对则通知上位机
{
sendsingal(com_mode,EXP_ERROR,NO_IMAGE_NUM);
}
else //若实验类型对则开始采集
{
startcapG();
ramselect(FIRST_32K);
ReadbufG(y_buffer,72,CIF,RstReadP);
ramselect(SECOND_32K);
ReadbufG(y_buffer,72,CIF,NoRstReadP);
ramselect(THIRD_32K);
ReadbufG(y_buffer,72,CIF,NoRstReadP);
ramselect(FOURTH_32K);
ReadbufG(y_buffer,72,CIF,NoRstReadP);
image_num++;
image_num1=(image_num%2);
sendsingal(com_mode,ORI_IMAGEREADY,((u8)image_num1));
}
break;
case ORI_IMAGE: //若是传输原图象命令则传原图象
rece_reset();
image_num=(image_num%2);
ramselect(FIRST_32K); //传第一幅图象
senddata(com_mode,LENGTH_Y_QCIF,y_buffer,FIRSTTIME_SEND);
ramselect(SECOND_32K);
senddata(com_mode,LENGTH_Y_QCIF,y_buffer,NOT_FIRSTTIME_SEND);
ramselect(THIRD_32K);
senddata(com_mode,LENGTH_Y_QCIF,y_buffer,NOT_FIRSTTIME_SEND);
ramselect(FOURTH_32K);
senddata(com_mode,LENGTH_Y_QCIF,y_buffer,NOT_FIRSTTIME_SEND);
break;
case START_SEC_IMAGE: //开始采集第二幅命令
parameter = (int)(preceive->Parameter);
rece_reset();
startcapG();
ramselect(FIRST_32K);
ReadbufG(e_buffer,72,CIF,RstReadP);
motiondetect(e_buffer,y_buffer,y_buffer,XSIZE,YSIZE>>2,parameter);
image_num1=image_num+2;
sendsingal(com_mode,SEC_IMAGEREADY,((u8)image_num1));
break;
case SEC_IMAGE: //传送第二幅图像命令
rece_reset();
ramselect(FIRST_32K); //传送第二幅图像
senddata(com_mode,LENGTH_Y_QCIF,e_buffer,FIRSTTIME_SEND);
ramselect(SECOND_32K);
ReadbufG(e_buffer,72,CIF,NoRstReadP);