⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 l3cmain.c

📁 phs 源代码 小灵通协议源代码 phs source code
💻 C
📖 第 1 页 / 共 2 页
字号:
/************************************************************************/
/*                                                                      */
/*		NAME		l3cmain.c				*/
/*		FUNC						        */
/*                                                                      */
/************************************************************************/
#ifndef PM_ONPC

#ifdef __cplusplus
extern "C"{
#endif

#include "phs_def.h"
#include "l3c_def.h"
#include "l3_ext.h"
#include "l3c_ext.h"
#include "sysdef.h"

#ifdef SIMU_ON_PC
#include <string.h>
#endif

extern L3C_SYSWRK	l3c_syswork;

#ifdef EXT_IO
#include  "mn80sts.h"
extern MN_STATE Mn_state;
#endif

/************************************************************************/
/*                                                                      */
/*		NUMBER		2				        */
/*		CALL		U1 L3cMain()                           */
/*		PARAM						        */
/*		FUNC		l3c main entry point                    */
/*		RETURN		0                   */
/*		GLOBAL      Sys_work	 :				*/
/*                 L3_dl[2]	 :   channel state            */
/*                 L3c_all_tbl	 :  state machine used in all state      */
/*		   L3c_l2_tbl[4]:event from L2 layer state machine table */
/*		   L3c_l3_tbl[4]:event from high layer state machine table*/
/*		   L3c_l2_cnt[4]:event count from L2 layer in state machine table*/
/*		   L3c_l3_cnt[4]:event count from high layer in state machine table*/
/*                                                                      */
/************************************************************************/
#ifdef _ON_SANYO_
U1 L3cMain(void)
#else
U1 L3cMain(void* mbox)
#endif
{
	U1	count;
	U1	re_flg;
#ifndef _ON_SANYO_
	memcpy ((void *) l3c_syswork.in_evt, (const void *)(((EV_BUF_ST *)mbox)->event), sizeof (l3c_syswork.in_evt));
#endif
	re_flg = OFF;
	set_up_b((U1 *)SYS_WORK->out_evt, 0, sizeof(SYS_WORK->out_evt));

	switch ( (U2)((U1)IN_DLDEVT->evt_cod & EVT_IMSK) )
	{
		case EVT_L3	:	/* event code from high layer */
			if ( IN_DLDEVT->evt_cod == EINITL3 )/* L3 initial	*/
			{						/*状态表*/
				SYS_WORK->sts_ptr = L3c_all_tbl;/* used in all state(state mschine)*/
				SYS_WORK->sts_cnt = L3C_ALL_CNT;/* used in all state(event count)*/
			}
			else
			{/*other event code from high layer*/
				if ( IN_DLDEVT->add_dat[1] == SFACCH )  /* sacch and facch channel */
				{						/*状态表*/
					SYS_WORK->sts_ptr = L3c_l3_tbl[L3_dl[FACCH_ST]];	 /* sacch channel  state machine table*/
					SYS_WORK->sts_cnt = L3c_l3_cnt[L3_dl[FACCH_ST]];        /* sacch event count table */

					L3_lnkreq = FACCH;			/* sacch link request */
					re_flg = ON;			/* research again  in state machine table*/
				}
				else	/* SACCH or FACCH 		*/
				{
					SYS_WORK->sts_ptr =L3c_l3_tbl[L3_dl[IN_DLDEVT->add_dat[1]-1]];  /* sacch or facch state machine table */

					SYS_WORK->sts_cnt =L3c_l3_cnt[L3_dl[IN_DLDEVT->add_dat[1]-1]]; /* event count */

				}
			}
			break;

		case EVT_L2	:	/* event code from L2	*/
          //   ProtocolTrace(2,"!!L3c_main(l2) state=%d %d\n",L3_dl[IN_DLDEVT->dl_typ-1],((U1)IN_DLDEVT->evt_cod & EVT_IMSK));
			SYS_WORK->sts_ptr = L3c_l2_tbl[L3_dl[IN_DLDEVT->dl_typ-1]];  /* sacch or facch state machine table */

			SYS_WORK->sts_cnt = L3c_l2_cnt[L3_dl[IN_DLDEVT->dl_typ-1]];	/* event count */

			break;

		case EVT_L1	:/* event code from L1 layer*/
			SYS_WORK->sts_ptr = L3c_all_tbl;	/* used in all state(state mschine)*/
			SYS_WORK->sts_cnt = L3C_ALL_CNT;	/* used in all state(event count)*/
			break;
	}

	/* search message type in state machine */
	for ( count=0; count<SYS_WORK->sts_cnt; count++, SYS_WORK->sts_ptr++ )
 	{
		if ( SYS_WORK->sts_ptr->evt_cod == IN_DLDEVT->evt_cod )
		{/* if found	*/
			SYS_WORK->sts_ptr->fnc_adr();	/* execute function*/
			break;
		}
	}
	if ( count >= SYS_WORK->sts_cnt )	/* if not found	*/
	{
#ifdef _ON_SANYO_
		L3dMain();
#else
		L3dMain(mbox);	/* received unknown message type 	*/
#endif
	}

	if ( re_flg == OFF )
		return ( 0 );

	set_up_b((U1 *)SYS_WORK->out_evt, 0, sizeof(SYS_WORK->out_evt));

	SYS_WORK->sts_ptr = L3c_l3_tbl[L3_dl[SACCH_ST]];   /* sacch channel  state machine table*/
	SYS_WORK->sts_cnt = L3c_l3_cnt[L3_dl[SACCH_ST]];  /* sacch event count table */

	L3_lnkreq = SACCH;   /* sacch link request */
	/* serach message type again in state  machine-------------------------------------------*/
	for ( count=0; count<SYS_WORK->sts_cnt; count++, SYS_WORK->sts_ptr++ )
	{
		if ( IN_DLDEVT->evt_cod == SYS_WORK->sts_ptr->evt_cod )
		{/* if found 	*/
			SYS_WORK->sts_ptr->fnc_adr();/*执行状态表中事件对应的函数*/
			break;
		}
	}
	if ( count >= SYS_WORK->sts_cnt )/* if not found	*/
	{
#ifdef _ON_SANYO_
		L3dMain();
#else
		L3dMain(mbox);	/* received unknown message type 	*/
#endif
	}

	return ( 0 );
}

/************************************************************************/
/*                                                                      */
/*		NUMBER		3				        */
/*		CALL		void L3cDataLinkReq()                       */
/*		PARAM						        */
/*		FUNC		handle data link establishment request  */
/*		RETURN		void                  */
/*		GLOBAL      Sys_work	 :	input and output message pointer						*/
/*                  L3_dl[2]	 :  channel id state            */
/*                  L3c_lnkreq	 :  channel id link request	        */
/*                                                                      */
/************************************************************************/
void L3cDataLinkReq(void)
{
	/* sending request (MNG -> L3 -> L2) ----------------------------*/

	SYS_WORK->tsk_id = TASKL2;			/* set task id	*/
	OUT_DLDEVT->evt_cod = EDLSETRQ;			/* set event code 	*/
	OUT_DLDEVT->dl_typ = IN_DLDEVT->add_dat[1];	/*set channel id	*/
	if ( IN_DLDEVT->add_dat[1] == SFACCH )		/* sacch and facch	*/
	{
		OUT_DLDEVT->dl_typ = L3_lnkreq;		/* channel id link request	*/
	}
	OUT_DLDEVT->dl_id = SLOT1;			/* time slot	*/
	m_excreq( (WORD*)&SYS_WORK->tsk_id );			/* send out*/

	L3_dl[OUT_DLDEVT->dl_typ-1] = ST_SET_WT;	/*  channel id state change to P1 state	*/
}

/************************************************************************/
/*                                                                      */
/*		NUMBER		4				        */
/*		CALL		void L3cDataLinkFreeReq()                       */
/*		PARAM						        */
/*		FUNC		handle free data link request message   */
/*		RETURN		void                          */
/*		GLOBAL      Sys_work	 :input and output message pointer*/
/*                  L3_dl[2]	 :  channel id state         */
/*                  L3c_lnkreq	 :  channel id link request	        */
/*                                                                      */
/************************************************************************/
void L3cDataLinkFreeReq(void)
{
	/* 俢俴亅send free request (MNG -> L3 -> L2) ----------------------------*/

	SYS_WORK->tsk_id = TASKL2;			/* set task id	*/
	OUT_DLDEVT->evt_cod = EDLFRERQ;                 /* set event code 	*/
	OUT_DLDEVT->dl_typ = IN_DLDEVT->add_dat[1];     /*set channel id	*/
	if ( IN_DLDEVT->add_dat[1] == SFACCH )          /* sacch and facch	*/
	{
		OUT_DLDEVT->dl_typ = L3_lnkreq;         /* channel id link request	*/
	}
	OUT_DLDEVT->dl_id = SLOT1;			/* time slot	*/
	m_excreq( (WORD*)&SYS_WORK->tsk_id );                  /* send out*/

	L3_dl[OUT_DLDEVT->dl_typ-1] = ST_FRE_WT;        /*  channel id state change to P3 state	*/
}

/************************************************************************/
/*                                                                      */
/*		NUMBER		5				        */
/*		CALL		void L3cDataLinkFreeReqAtP0()                      */
/*		PARAM						        */
/*		FUNC		handle free data link request message at P0 state*/
/*		RETURN		void                          */
/*		GLOBAL      Sys_work	 :input and output message pointer*/
/*                                                                      */
/************************************************************************/
void L3cDataLinkFreeReqAtP0(void)
{
	/* 俢俴亅send free request  (MNG -> L3 -> MNG) --------------------------*/

	SYS_WORK->tsk_id = TASKMNG;				/* set task id 	*/
	OUT_DLDEVT->evt_cod = EL3FRERS;				/* set event code	*/
	OUT_DLDEVT->dl_typ = 0;					/* channel id	*/
	OUT_DLDEVT->add_dat[0] = IN_DLDEVT->add_dat[0];
	OUT_DLDEVT->add_dat[1] = IN_DLDEVT->add_dat[1];
	m_excreq( (WORD*)&SYS_WORK->tsk_id );				/* send out	*/
}

/************************************************************************/
/*                                                                      */
/*		NUMBER		6				        */
/*		CALL		void L3cDataLinkInd()                       */
/*		PARAM						        */
/*		FUNC		handle data link indication message   */
/*		RETURN		void                  */
/*		GLOBAL      Sys_work	 :input and output message pointer*/
/*                  Sys_ccsinf   :  cs info                     	*/
/*                  L3_dl[2]	 :  channel id state            	*/
/*                                                                      */
/************************************************************************/
void L3cDataLinkInd(void)
{
	/* send data link indication message (MNG <- L3 <- L2) ---------------------------*/

	SYS_WORK->tsk_id = TASKMNG;				/* set task id		*/
	OUT_DLDEVT->evt_cod = EL3SETRS;				/* set event code	*/
	OUT_DLDEVT->add_dat[0] = (U2)Sys_ccsinf[2];
	OUT_DLDEVT->add_dat[1] = IN_DLDEVT->dl_typ;	/* channel id */
	m_excreq( (WORD*)&SYS_WORK->tsk_id );				/* send out */
#ifdef SIMU_ON_PC
     ProtocolTrace(2,"!!L3c_dlstrs dl_typ=%d\n",OUT_DLDEVT->add_dat[1]);
#endif
	L3_dl[OUT_DLDEVT->add_dat[1]-1] = ST_SET;	/*  channel id state change to P2 state		*/
}

/************************************************************************/
/*                                                                      */
/*		NUMBER		7				        */
/*		CALL		void L3cDataLinkFreeInd()                       */
/*		PARAM						        */
/*		FUNC		handle free data link indication message*/
/*		RETURN		void                            */
/*		GLOBAL      Sys_work	 :	input and output message pointer*/
/*                  Sys_ccsinf   :  cs info                		*/
/*                  L3_dl[2]	 :  channel id state            	*/
/*                                                                      */
/************************************************************************/
void L3cDataLinkFreeInd(void)
{
	/* send free data link indication (MNG <- L3 <- L2) ---------------------------*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -