📄 dsa.c.bak
字号:
#include "global.h"
#include "util.h"
#include "dsa.h"
#include "mb90092.h"
#define LOW_BYTE 1
#define HIGH_BYTE 0
#define PARAMETER LOW_BYTE
#define CMD HIGH_BYTE
DSA_CMD idata dsa_recieve;
extern unsigned char idata DSA_timer;
extern unsigned char xdata gps_recieve_buf[];
extern unsigned int dsa_task;
extern unsigned char dsa_state;
extern unsigned char main_row;
extern unsigned char main_column;
extern unsigned char character_color;
extern unsigned char line_color;
unsigned int display_char;
unsigned char dsa_send_count=0;
void DSA_servo(void)
{
if(DSA_recieve(0)==SUCCESS)
{
#if 0
//clear_main_screen();
OSD_ASCII_output(7,5,(dsa_recieve.Word>>8)&0xff);
OSD_ASCII_output(4,5,dsa_recieve.Word&0xff);
#endif
switch((dsa_recieve.Word >>8)&0xff)
{
case 0x70:
main_row =dsa_recieve.Word&0xff;
break;
case 0x71:
main_column =dsa_recieve.Word&0xff;
break;
case 0x72:
character_color=dsa_recieve.Word&0xff;
break;
case 0x73:
line_color=dsa_recieve.Word&0xff;
break;
case 0x74:
display_char = (dsa_recieve.Word<<8)&0xff00;
//OSD_ASCII_output(1,5,(dsa_recieve.Word>>8)&0xff);
//OSD_ASCII_output(3,5,dsa_recieve.Word&0xff);
break;
case 0x75:
display_char |= (dsa_recieve.Word&0xff);
//OSD_ASCII_output(1,7,(dsa_recieve.Word>>8)&0xff);
//OSD_ASCII_output(3,7,dsa_recieve.Word&0xff);
OSD_ASCII_output(8,9,(display_char>>8)&0xff);
OSD_ASCII_output(9,9,display_char&0xff);
//OSD_main_symbol(main_row,main_column,character_color,line_color,display_char>>8);
//OSD_main_symbol(main_row,main_column,character_color,line_color,display_char);
break;
}
}
else {
//if(DSA_send(dsa_task>>8,dsa_task)==SUCCESS)
//dsa_task =0;
#if 1
switch(dsa_state)
{
case 0:
break;
case 1:
if(dsa_task==DSA_send_gps){
ES0 =0;ES1 =0;
dsa_send_count=0;
dsa_state++;
}
else
if(dsa_task==DSA_send_gsm){
dsa_send_count=0;
dsa_state = 3;
}
break;
case 2:
if(DSA_send(dsa_task>>8,gps_recieve_buf[dsa_send_count])==SUCCESS)
{
dsa_send_count++;
}
if(dsa_send_count==(GPS_MAX_MESSAGE) /*GPS_send_over*/){
ES0 = 1; ES1 = 1;
dsa_send_count = 0;
dsa_task = 0;
dsa_state = 0;
//GPS_valid = 1; //gwm adjust
}
break;
case 3:
if(DSA_send(dsa_task>>8,gps_recieve_buf[dsa_send_count])==SUCCESS)
{
dsa_send_count++;
}
if(dsa_send_count==300/*GSM_send_over*/){
dsa_send_count = 0;
dsa_task = 0;
dsa_state = 0;
}
break;
case 4:
if(DSA_send(dsa_task>>8,dsa_task)==SUCCESS)
dsa_task = 0;
dsa_state = 0;
break;
}
#endif
}
}
/***************************************************************************
* Function : DSA_send
* Description : 1. Transfer command and parameter to control DSA interface
* 2. DSA timing includes 3 phases :
* sync, data transfer, comm ack
* 3. Use 3 bus lines : DATA, STB, ACK
* 4. Process as a transmitter
* Arguments : bCmd ==> DSA command to processor(Opcode)
* bParameter==> for DSA command parameter
* Return : SUCCESS, FAIL
*****************************************************************************/
bit DSA_send(unsigned char bCmd,unsigned char bParameter)
{
char btRCVResponse;
unsigned char i,bRetry;
DSA_DAT = LOW; /* transfer request */
DSA_DAT = LOW; /*delay */
DSA_DAT = LOW; /*delay */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && DSA_ACK );
if(!DSA_timer) goto dsa_snd_restore;
DSA_DAT = HIGH;
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && !DSA_ACK );
if(!DSA_timer) goto dsa_snd_restore;
/*---------- Data transmission --------- */
/*8 bits for command, 8 bits for parameter */
/* transmitter : transmit 1 bit==>let stb=0 ==> wait until ack=0*/
/* ==> let stb=1 ==> wait until ack=1 ==> next bit*/
dsa_recieve.Byte[CMD]=bCmd;
dsa_recieve.Byte[PARAMETER]=bParameter;
for( i=0;i<16;i++ ) /* to transfer 16 bits */
{
DSA_DAT = MSB(dsa_recieve.Word); /* send msb */
DSA_STB = LOW; /* data valid */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && DSA_ACK );
if(!DSA_timer) goto dsa_snd_restore;
DSA_STB = HIGH;
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && !DSA_ACK );
if(!DSA_timer) goto dsa_snd_restore;
dsa_recieve.Word <<= 1; /* shift left 1 bit */
}
DSA_DAT = HIGH;
//for(i = 0; i < 0x20;i++);
/*---------- Communication acknowledge --------
// set ack=0 ==> wait until stb=0==>read reply=>set ack=1
// ==>wait until stb=1 and data=1
*/
DSA_ACK = LOW;
/* wait for rcv clearing STB, timeout~250ms
// the receiver lower the STB
// indicate the status of transmission is on the DATA line
*/
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && DSA_STB );
if(!DSA_timer) goto dsa_snd_restore;
btRCVResponse = (char)DSA_DAT; /* read receiver's reply */
/* the transmitter raise the ACK line */
/* indicate the transmitter know the status of transmission */
DSA_ACK = HIGH;
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && !DSA_STB );
if(!DSA_timer) goto dsa_snd_restore;
goto dsa_snd_ok;
dsa_snd_restore:
btRCVResponse = 0;
dsa_snd_ok:
DSA_DAT = HIGH;
DSA_STB = HIGH;
DSA_ACK = HIGH;
dsa_recieve.Byte[0] = 0;
dsa_recieve.Byte[1] = 0;
if(btRCVResponse)
return SUCCESS;
else
return FAIL;
}
/*************************************************************************
* Function : DSA_recieve
* Description : 1. Receive command and parameter from DSA interface
* 2. Process as a receiver
* 3. Use 3 bus lines : DATA, STB, ACK
* 4. Count the received data--> 16 bit
* Arguments : bRCVCmd : expected response command from dsa interface
* wWaitTime : wait for response timeout
* Return : if bRCVCmd == DSA_DUMMY(0x00) ==> return SUCCESS
* if (bRCVCmd == received command from servo)
* && (bit count == 16)
* ==> return data (from servo)
* else return recieve_restore(0xff)
************************************************************************/
unsigned char DSA_recieve(unsigned char bRCVCmd)
{
unsigned char i;
char btDataOK;
/* commands from servo processor
*--------- Starting sychronization -----------
* wait until data=0 ==> set ack=0 ==> wait until data=1 ==>
* set ack=1 ==>ready
* wait the transmitter pull down the DATA line
*/
if( DSA_DAT ) goto recieve_restore;
/* the DATA line is low, the receiver then clears the ACK line */
DSA_ACK = LOW; /* recognized the data transfer request */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && !DSA_DAT );
if(!DSA_timer) goto recieve_restore;
DSA_ACK = HIGH;
/*---------- Data transmission ---------
// 8 bits for command, 8 bits for parameter
// wait until stb=0 ==> receive 1 bit ==> set ack=0
// ==> wait until stb=1 ==> set ack=1 ==> next bit
*/
for(i=0;i<16;i++)
{
dsa_recieve.Word <<= 1; /* shift 1 bit to the left */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && DSA_STB );
if(!DSA_timer) goto recieve_restore;
/* receiver read the data, update the bit 0 each time */
dsa_recieve.Word |= DSA_DAT;
/* then lower the ACK */
DSA_ACK=LOW; /* data received */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && !DSA_STB );
if(!DSA_timer) goto recieve_restore;
/* receiver raise the ACK line, 1 bit transmitted */
DSA_ACK = HIGH;
}
/*---------- Communication acknowledge --------
// wait until ack=0 ==> reply transmission status ==> set stb=0 ==>
// wait until ack=1 ==>set stb=1 and data=1
*/
/* assume the transmission is OK */
DSA_DAT = 1;
/* the transmitter will clear the ACK line for checking the transmitting status */
DSA_timer = DSA_SYS_250ms;
while( (DSA_timer > 0) && DSA_ACK );
if(!DSA_timer) goto recieve_restore;
/* instead of checking the bit counter, we check the command received
* for if the program achieve this phase, the bit counter is always 16.
* the receiver lower the DATA line means data error
* but even data transmission error, still need to complete the acknowledge phase
*/
#if 0
if( (bRCVCmd==DSA_DUMMY) || (dsa_recieve.Byte[CMD]==bRCVCmd) )
{
btDataOK =(char) TRUE;
DSA_DAT = 1; /* data ok */
}
else
{
btDataOK =(char) FALSE;
DSA_DAT = 0; /* data error */
}
#endif
DSA_DAT = 1; /* data ok */
/*
after setting the transmission status, the receiver then clear the STB line
*/
DSA_STB = LOW;
/*
wait for transmitter setting ACK
*/
DSA_timer = DSA_SYS_250ms; //250 ms
while( (DSA_timer > 0) && !DSA_ACK );
if(!DSA_timer) goto recieve_restore;
/*
the receiver raise the STB line and DATA line to end the transmission cycle.
*/
DSA_STB = HIGH;
DSA_DAT = HIGH;
DSA_ACK = HIGH;
/*---------- Communication complete --------*/
/*
some command do not need check response command
*/
//if( bRCVCmd == DSA_DUMMY )
return SUCCESS; /* always return successful*/
recieve_restore:
DSA_STB = HIGH;
DSA_DAT = HIGH;
DSA_ACK = HIGH;
return DSA_ERR_RESPONSE;
#if 0
/* the response command are correct */
else
if( btDataOK )
return dsa_recieve.Byte[PARAMETER]; /* return response parameter */
return DSA_ERR_RESPONSE;
#endif
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -