📄 lap.c
字号:
frame[11]=0x01; /* 6 slots */
break;
}
if (cr&0x02) /* check if conflict bit is set */
frame[11]|=4; /* or in address conflict bit*/
frame[12]=slotcount; /* pass the slotcount */
frame[13]=IRLAP_VERSION; /*0*/
if (cr&0x04)/* check if this is the final XID command */
{
extern kal_uint8 *irda_get_device_info(void);
extern kal_uint16 irda_get_device_info_size(void);
#if 0
/* under construction !*/
/* under construction !*/
#else
xmemcpy (&frame[14],(kal_uint8*)irda_get_device_info(),irda_get_device_info_size());
fsize = 14+irda_get_device_info_size();
#endif
}
else
fsize = 14;
}
else if ( ( type == SNRM_COMMAND ) ||
( type == UA_RESPONSE && irlap_state==IRLAP_CONN ) )
{
tmplong= Swap_long_order(dev_address);
xmemcpy ((kal_uint8 *)&frame[2],(kal_uint8 *)&tmplong,4);
xmemcpy ((kal_uint8 *)&frame[6],(kal_uint8 *)&destination_address,4);
if (type==UA_RESPONSE )
{
extern kal_uint8 result_params[CONNECT_PARAMS_SIZE];
/*22*/
//xmemcpy (&frame[10],tx_lap_frame,sizeof(connect_params));
xmemcpy (&frame[10],tx_lap_frame,sizeof(result_params));
fsize = 11+sizeof(connect_params);/*22-21=1*/
}
if (type==SNRM_COMMAND)
{
frame[10]=connection_address;
xmemcpy (&frame[11],connect_params,sizeof(connect_params));
fsize = 11+sizeof(connect_params);
}
}
else
{
fsize = 2;
}
tmpptr1->size=fsize;
return(tmpptr1);
}
/*************************************************************************
* FUNCTION
* Send_S_Packet
*
* DESCRIPTION
* This function is used to send an S type packet response
*
* PARAMETERS
* kal_uint8 type:Command or Response
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Send_S_Packet( kal_uint8 type )/* globals: Vr */
{
if(local_busy)
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG5);
#endif
Com_write(Format_packet (type,(kal_uint8)(RNR_RESPONSE|(type<<4)|(Vr<<5))));
}
else
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG6);
#endif
Com_write(Format_packet (type,(kal_uint8)(RR_RESPONSE|(type<<4)|(Vr<<5))));
}
}
/*************************************************************************
* FUNCTION
* Getbuf
*
* DESCRIPTION
* This function is used to gets a buffer from the buffer pool
*
* PARAMETERS
*
* RETURNS
* Pointer to next available buffer
0 if no more buffers
*
* GLOBALS AFFECTED
*
*************************************************************************/
FBUF * Getbuf( void )
/* returns 0 if out of buffers, or error */
{
FBUF * tmpbuf;
kal_uint32 savedMask;
savedMask = SaveAndSetIRQMask();
ASSERT(CurBuf!=0);
ASSERT(CurBuf->stat==B_FREE);
tmpbuf = CurBuf;
CurBuf = CurBuf->next;
tmpbuf->stat=B_ALLOC;
tmpbuf->size=0;
tmpbuf->type=NO_TYPE;
tgbuf--;
RestoreIRQMask(savedMask);
return((FBUF *)tmpbuf);
}
FBUF * IR_Getbuf(void)
/* returns 0 if out of buffers, or error */
{
FBUF * tmpbuf;
ASSERT(CurBuf!=0);
ASSERT(CurBuf->stat==B_FREE);
tmpbuf = CurBuf;
CurBuf = CurBuf->next;
tmpbuf->stat=B_ALLOC;
tmpbuf->size=0;
tmpbuf->type=NO_TYPE;
tgbuf--;
return((FBUF *)tmpbuf);
}
/*************************************************************************
* FUNCTION
* Freebuf
*
* DESCRIPTION
* This function is used to free an allocated buffer
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Freebuf ( FBUF * buf )
{
kal_uint32 savedMask;
savedMask = SaveAndSetIRQMask();
ASSERT(buf!=0);
ASSERT(buf->stat==B_ALLOC);
buf->next=(FBUF *)CurBuf;
CurBuf = (FBUF *)buf;
CurBuf->stat=B_FREE;
CurBuf->size=0;
CurBuf->type=CONTROL_TYPE;
buf=0;
tgbuf++;
RestoreIRQMask(savedMask);
}
void IR_Freebuf ( FBUF * buf )
{
ASSERT(buf!=0);
ASSERT(buf->stat==B_ALLOC);
buf->next=(FBUF *)CurBuf;
CurBuf = (FBUF *)buf;
CurBuf->stat=B_FREE;
CurBuf->size=0;
CurBuf->type=CONTROL_TYPE;
buf=0;
tgbuf++;
}
/*************************************************************************
* FUNCTION
* InitBuf
*
* DESCRIPTION
* This function is used to initialize the buffer pool
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/* buffer area, used with Getbuf and Freebuf */
//#pragma arm section rwdata = "INTERNRW" , rodata = "INTERNCONST" , zidata = "INTERNZI"
static kal_int32 databuf[((NBUFFS)*BSIZE+3)/4];
//#pragma arm section
FBUF* debug_ptr = (FBUF *)databuf;
void InitBuf ( void )
{
kal_uint16 i;
kal_uint8 * tmpptr1;
FBUF * tmpptr2;
FBUF * prevptr;
unsigned long addr;
kal_uint32 savedMask;
savedMask = SaveAndSetIRQMask();
tmpptr1 = (kal_uint8 *)databuf;
addr = (unsigned long)tmpptr1;
tmpptr1 = (kal_uint8 *)addr;
CurBuf = (FBUF *)tmpptr1;
tmpptr2 = (FBUF *)tmpptr1;
tgbuf=0;
for ( i=0;i<NBUFFS;i++)
{
prevptr=(FBUF *)tmpptr2;
tmpptr2->type=CONTROL_TYPE;
tmpptr2->stat=B_FREE;
tmpptr2->size=0;
tmpptr2 = (FBUF *)((kal_uint8 *)tmpptr2 + BSIZE);
prevptr->next=(FBUF *)tmpptr2;
tgbuf++;
}
prevptr->next=0;
RestoreIRQMask(savedMask);
}
/*************************************************************************
* FUNCTION
* Cleanbufs
*
* DESCRIPTION
* This function is used to Clean buffer pool
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void Cleanbufs( void )
{
kal_int16 i;
kal_uint8 * tmpptr1=0;
FBUF * tmpptr2;
unsigned long addr;
addr = (unsigned long)databuf;
addr += (unsigned long)((4 - (kal_int16)addr) & 3);
tmpptr2 = (FBUF *)tmpptr1;
tmpptr1 = (kal_uint8 *)addr;
for ( i=0;i<NBUFFS;i++)
{
if ((tmpptr2->stat!=B_FREE)&&(tmpptr2->stat!=B_ALLOC))
{
}
else
{
if (tmpptr2->stat!=B_FREE)
{
/* free the buffer */
if ( ((tmpptr2->type&0x7f)==TX_TYPE)||
((tmpptr2->type&0x7f)==RX_TYPE) )
{
Freebuf((FBUF*)tmpptr2);
}
}
}
tmpptr2 = (FBUF *)((kal_uint8 *)tmpptr2 + BSIZE);
}
}
/*************************************************************************
* FUNCTION
* IrLAP_DATA_request
*
* DESCRIPTION
* This function is used to do LAP data request
*
* PARAMETERS
* FBUF * buf
* RETURNS
* 0=success
* 1=bad irlap_state
*
* GLOBALS AFFECTED
* User data must be offset in buffer for I_PACKET_OFFSET
buf points to head of alloced FBUF
. Contents and size of buffer are previously set using Getbuf()
. Sets LAPDESC state so buffer can be sent
. Current IRLAP state must be NRMS,XMIT, or NRMP
. Updates descriptor ptrs
. Q's data if request if valid and will free buffer automatically
. User must free buffer is request returns a non zero value
*************************************************************************/
kal_uint8 IrLAP_DATA_request ( FBUF * buf )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG7);
#endif
if ((irlap_state!=IRLAP_NRMS&&
irlap_state!=IRLAP_XMIT&&
irlap_state!=IRLAP_NRMP ) )
{
Freebuf(buf);
return(1);
}
QUEUE_ADD(lap_request_q,buf,MAX_REQUEST);
return(0);
}
/*************************************************************************
* FUNCTION
* IrDA_Task
*
* DESCRIPTION
* This function is used to decode receive frames
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void IrDA_Task(void)
{
FBUF * fptr;
if ( FRAME_IN_QUEUE(decode_q) )
{
QUEUE_REMOVE(decode_q,fptr,MAX_DECODE_FRAMES);
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG8);
#endif
IRLAP_frame_decode (fptr);
}
else
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_WARNING, IRDA_MSG9);
#endif
}
}
/*************************************************************************
* FUNCTION
* Format_T_packet
*
* DESCRIPTION
* This function is used to format the test frame
*
* PARAMETERS
* kal_uint8 addr : connect address flag
0 = use broadcast address
1 = use station's connect address
kal_uint8 cr : command response bit
FBUF * dframe : frame
kal_uint8 flag : signals a zero sized i field
* RETURNS
* Pointer to the formatted frame packet
*
* GLOBALS AFFECTED
*
*************************************************************************/
FBUF * Format_T_packet ( kal_uint8 addr,
kal_uint8 cr,
FBUF * dframe,
kal_uint8 flag )
{
kal_uint8 * frame;
kal_uint16 size;
frame=(kal_uint8 *)dframe+FBUF_HEAD;
#if 0
/* under construction !*/
/* under construction !*/
/* under construction !*/
/* under construction !*/
#endif
frame[0]=(connection_address&0xfe)|cr;
frame[1]=TEST_COMMAND;
/* include connection address, command, dest and src address */
if (flag)
size=10;
else
size=dframe->size;
dframe->size=size;
return((FBUF*)dframe);
}
/*************************************************************************
* FUNCTION
* LAP_disconnect_reset
*
* DESCRIPTION
* This function is used to do a LAP disconnect reset
*
* PARAMETERS
* None
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void LAP_disconnect_reset ( kal_uint8 reason )
{
Com_ioctl( IOCTL_BAUD, CONTENTION_BAUD );
irp_connect= DISCONNECT_INDICATION;
LINK_DISCONNECT_CALLBACK(reason);
}
/*************************************************************************
* FUNCTION
* LAP_user_disconnect_cb
*
* DESCRIPTION
* This function implements LAP user disconnect callback function
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void LAP_user_disconnect_cb( void )
{
kal_uint8 result;
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG10);
#endif
STOP_WD_TIMER();
STOP_F_TIMER();
//IR_SW_Init();
result=IrLAP_LINK_init();
Init_IAS_p();
Init_IAS_s();
}
/*************************************************************************
* FUNCTION
* IrLAP_DISCONNECT_request
*
* DESCRIPTION
* This function implements LAP Disconnect request
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void IrLAP_DISCONNECT_request( void )
{
#ifdef IRDA_KAL_TRACE
kal_trace(TRACE_FUNC, IRDA_MSG11);
#endif
if((irlap_state!=IRLAP_SCLOSE)||(irlap_state!=IRLAP_PCLOSE)||(irlap_state!=IRLAP_NDM))
{
lap_disconnect_flag =1;
}
}
/*************************************************************************
* FUNCTION
* random32
*
* DESCRIPTION
* This function is used to generate a ramdom number
*
* PARAMETERS
* None
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
/*to generate ramdom number from RTC*/
kal_uint32 random32(void)
{
kal_uint32 temp;
/*use RTC_TC_SEC to generate a random number*/
temp = *(kal_uint16 *)(0x80210014) & 0x003f;
temp ^= ( (*(kal_uint16 *)(0x80210014) & 0x003f) << (*(kal_uint16 *)(0x80210014)&0x001f));
return temp;
}
/*************************************************************************
* FUNCTION
* I_timer_expired
*
* DESCRIPTION
* There is no data tranfer and disconnect the link
*
* PARAMETERS
*
* RETURNS
* None
*
* GLOBALS AFFECTED
*
*************************************************************************/
void IrLAP_I_frame_timeout(void )
{
kal_prompt_trace(MOD_LAP,"I frame timeout");
LAP_disconnect_reset(LOST_LAP_CON);
irda_lmp_flag=MSG_ID_LAP_DISCONNECT_INDICATION;
Reset_Baudrate();
}
void IrLAP_I_frame_timer_enable(kal_bool enable)
{
if(enable==KAL_TRUE)
{
if(local_lsap_sel==OBEX_LSAP_SEL||local_lsap_sel==OBEX_IRXFER_LSAP_SEL)
{
kal_prompt_trace(MOD_LAP,"enable I frame time");
stack_start_timer(&irda_context.i_frame_timer, IRDA_I_FRMAE_TIMER_INDEX,2000);
}
}
else
{
kal_prompt_trace(MOD_LAP,"disable I frame time");
stack_stop_timer(&irda_context.i_frame_timer);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -