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

📄 socrat_b.c

📁 Infineon公司有一款实现SHDSL协议(ADSL协议的变种)的芯片
💻 C
📖 第 1 页 / 共 4 页
字号:
/*******************************************************************************
       Copyright (c) 2000, Infineon Technologies.  All rights reserved.
  
                               No Warranty                                                 
   Because the program is licensed free of charge, there is no warranty for 
   the program, to the extent permitted by applicable law.  Except when     
   otherwise stated in writing the copyright holders and/or other parties   
   provide the program "as is" without warranty of any kind, either         
   expressed or implied, including, but not limited to, the implied         
   warranties of merchantability and fitness for a particular purpose. The  
   entire risk as to the quality and performance of the program is with     
   you.  should the program prove defective, you assume the cost of all     
   necessary servicing, repair or correction.                               
                                                                            
   In no event unless required by applicable law or agreed to in writing    
   will any copyright holder, or any other party who may modify and/or      
   redistribute the program as permitted above, be liable to you for        
   damages, including any general, special, incidental or consequential     
   damages arising out of the use or inability to use the program           
   (including but not limited to loss of data or data being rendered        
   inaccurate or losses sustained by you or third parties or a failure of   
   the program to operate with any other programs), even if such holder or  
   other party has been advised of the possibility of such damages. 
 *******************************************************************************       
   
   Module:        SOCRAT_B                                                                   
   Product ID:    22622.1.0.1
   Description:   Contains proceedings for handling of SOCRATES. 

 ******************************************************************************/

// Group=SOCRAT_B 

/* ============================= */
/* Includes                      */
/* ============================= */

#include <stdio.h>
#include <absacc.h>
#include <stdlib.h>
#include <string.h>

#include "sysdef.h"            
#include "dds.h"          
#include "sysvar.h"
#include "sysfunc.h"

#include "modid.h"

/* ============================= */
/* Local Macros & Definitions    */
/* ============================= */




                                       /* Message ID's                        */
#define MSG_ID_SOCRATES_SET_TRANSFER                0
#define MSG_ID_SOCRATES_SET_EPIC_SWITCH             1
#define MSG_ID_SOCRATES_HDLC_BZ_RESET               2   
#define MSG_ID_SOCRATES_HDLC_BZ_TRANSMIT            3
                                        /* not longer supported, error is printed */
#define MSG_ID_SOCRATES_GHS_GENERAL_CONFIGURATION   6
#define MSG_ID_SOCRATES_GHS_DATA_RATES              7
#define MSG_ID_SOCRATES_GHS_TRANSMISSION_MODE       8

#define MSG_ID_SOCRATES_GHS_SET_STATE               9
#define MSG_ID_SOCRATES_GHS_INDICATE_STATE          10
#define MSG_ID_SOCRATES_GHS_ACTIVATE                11
#define MSG_ID_SOCRATES_CL_BASIC                    12
#define MSG_ID_SOCRATES_CL_PARAM                    13
#define MSG_ID_SOCRATES_CL_STD_INFO                 14
#ifdef DEBUG
   #define MSG_ID_SOCRATES_CL_TRAIN_RATES_DN        15
   #define MSG_ID_SOCRATES_CL_TRAIN_RATES_UP        29
#else
   #define MSG_ID_SOCRATES_CL_TRAIN_RATES           15
#endif
#define MSG_ID_SOCRATES_CL_PROBE_RATES_DN           16
#define MSG_ID_SOCRATES_CL_PROBE_RATES_UP           28
#define MSG_ID_SOCRATES_CL_FRAMING                  17
#define MSG_ID_SOCRATES_CL_TPS_A                    18
#define MSG_ID_SOCRATES_CL_TPS_B                    19

#define MSG_ID_SOCRATES_HDLC_E_RESET                20   
#define MSG_ID_SOCRATES_HDLC_E_TRANSMIT             21
#define MSG_ID_SOCRATES_HDLC_E_TRANSMIT_BLOCK       22

#define MSG_ID_SOCRATES_STATE_TIME                  25
#define MSG_ID_SOCRATES_INDICATE_STATE_TIME         26

#define MSG_ID_SOCRATES_INTERRUPT                   27

                                       /* first part of error message         */
static const WORD8 Error_Text_Start[]  = "Invalid";

                                       /* end of error message                */
static const WORD8 Error_Text_End[]    = "parameter specified";

/* ============================= */
/* Global variable definition    */
/* ============================= */

WORD8 G_Epic_Switch_Src_Prt;
WORD8 G_Epic_Switch_Src_Slt;
WORD8 G_Epic_Switch_Dst_Prt;
WORD8 G_Epic_Switch_Dst_Slt;
WORD8 G_Epic_Switch_Slt_Num;

WORD8 G_Ghsstate_Indication = 0x01;
//WORD8  G_Eeprom[LAST_EEPROM_INDEX];
WORD8 G_Ghs_Capability_List [CAPLIST_LENGTH];
BOOL G_Processing_Cl;


/* ============================= */
/* Local function declaration    */
/* ============================= */

static void Msg_Soc_Set_Transfer (P_DDS_MSG pMsg);
static void Msg_Soc_Set_Epic_Switch (P_DDS_MSG pMsg);
static void Msg_Soc_Hdlc_Transmit (P_DDS_MSG pMsg);
static void Msg_Soc_Hdlc_Reset (P_DDS_MSG pMsg);
static void Msg_Soc_Ghs_Set_State (P_DDS_MSG pMsg);
static void Msg_Soc_Ghs_Indicate_State (P_DDS_MSG pMsg);
static void Msg_Soc_Ghs_Activate (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Basic_Settings (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Parameter (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Std_Info (P_DDS_MSG pMsg);
#ifdef DEBUG
static void Msg_Soc_Cl_Train_Rates_Dn (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Train_Rates_Up (P_DDS_MSG pMsg);
#else
static void Msg_Soc_Cl_Train_Rates (P_DDS_MSG pMsg);
#endif
static void Msg_Soc_Cl_Probe_Rates_Up (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Probe_Rates_Dn (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_Framing (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_TPS_A (P_DDS_MSG pMsg);
static void Msg_Soc_Cl_TPS_B (P_DDS_MSG pMsg);
static void Msg_Soc_Eoc_Transmit (P_DDS_MSG pMsg);
static void Msg_Soc_Eoc_Transmit_Block (P_DDS_MSG pMsg);
static void Msg_Soc_Eoc_Reset (P_DDS_MSG pMsg);
static void Msg_Soc_State_Time (P_DDS_MSG pMsg);

static void Soc_Set_Bitrate (WORD8 standard_rate);
static void Socrates_Msg_Entry (P_DDS_MSG pMsg);
static void Soc_Cl_Download (void);

/* ============================= */
/* Global function definition    */
/* ============================= */
void Msg_Soc_Indicate_State_Time (void);
void Msg_Soc_Interrupt (T_INT_TYPE type, WORD8 nr, const WORD8 *data);       


/*******************************************************************************
Description:
   Inititialization function, which calls the message entry function of 
   this module.
Arguments:
   NONE.
Return:
   NONE.
Remarks:
   NONE.
 ******************************************************************************/
void Socrates_Module_Init (void)
{
   printf ("\nModule SOCRAT_B.C: Initialization done");
   DdsSetMsgEntry (Socrates_Msg_Entry, MOD_ID_SOCRATES_MODULE);
}

/* ============================= */
/* Local function definition     */
/* ============================= */

/*******************************************************************************
Description:
   Receive message to initialize data transfer settings of SOCRATES.
Arguments:
   pMsg  -  Pointer to received message.
Return:
   NONE.
Remarks:
   Transfer settings are done with function Soc_Set_Bitrate.
 ******************************************************************************/
static void Msg_Soc_Set_Transfer (P_DDS_MSG pMsg)
{
   WORD8  rate;
   WORD8  tdm_off;
   const WORD8 *error_text = NULL;

                                       /* Read parameters of received    
                                          message.                            */
   G_V24    = MsgReadWord8 (pMsg, 0);
   tdm_off  = MsgReadWord8 (pMsg, 1);
   rate     = MsgReadWord8 (pMsg, 2);
                                         
                                       /* Set error text dependent on   
                                          the received parameters.            */
   if (rate > 0x09) 
      error_text = "RATE";

                                       /* Start processing if all       
                                          parameters are correct.             */
   if (error_text == NULL)
   {
      V24_PRINT (("\nSocrates_Set_Transfer: TDM_OFF=0x%02X, RATE=0x%02X", tdm_off, rate));

      Out ( SOCRATES_TDM_OFF, tdm_off );
      Out ( SOCRATES_BYTE_BOFF, tdm_off );/* has always to be the same as TDM_OFF */
      Soc_Set_Bitrate (rate);

   }
  
                                       /* V24 control message:          
                                          When error.                         */
   if (error_text != NULL)
   {
      V24_PRINT (("\nSocrates_Set_Transfer: %s ", Error_Text_Start));
      V24_PRINT (("%s ", error_text));     
      V24_PRINT (("%s", Error_Text_End));     
   }
                                       /* Free received message         
                                          because no message is         
                                          returned to the user.               */
   DdsMsgFree (pMsg);
}

/*******************************************************************************
Description:
   Receive message to set switching of time slots done by EPIC.
Arguments:
   pMsg  -  Pointer to received message.
Return:
   NONE.
Remarks:
   Switching of time slots done by function Epic_Update_Connections.
 ******************************************************************************/
static void Msg_Soc_Set_Epic_Switch (P_DDS_MSG pMsg)
{
   WORD8  sr_prt;
   WORD8  sr_slt;
   WORD8  ds_prt;
   WORD8  ds_slt;
   WORD8  slt_nm;
   const WORD8 *error_text = NULL;

                                       /* Read parameters of received    
                                          message.                            */
   G_V24   = MsgReadWord8 (pMsg, 0);
   sr_prt  = MsgReadWord8 (pMsg, 1);
   sr_slt  = MsgReadWord8 (pMsg, 2);
   ds_prt  = MsgReadWord8 (pMsg, 3);
   ds_slt  = MsgReadWord8 (pMsg, 4);
   slt_nm  = MsgReadWord8 (pMsg, 5);
                                         
                                       /* V24 control message:          
                                          When entering.                      */
   V24_PRINT (("\nSocrates_Set_Epic_Switch: SR_PRT=0x%02X, SR_SLT=0x%02X, ", sr_prt, sr_slt));
   V24_PRINT (("DS_PRT=0x%02X, DS_SLT=0x%02X, SLT_NM=0x%02X", ds_prt, ds_slt, slt_nm));  
      
                                       /* Set error text dependent on   
                                          the received parameters.            */
   if ( G_Eeprom [CONFIG_P_CLK] == P_CLK_2MHZ )
   {
      if (sr_slt > 0x1F)              
         error_text = "SR_SLT"; 
      if (ds_slt > 0x1F)              
         error_text = "DS_SLT";
   } 
   if (G_Eeprom [CONFIG_P_CLK] == P_CLK_4MHZ)
   {
      if ((sr_slt > 0x3F) || ((sr_slt > 0x1F) && ((sr_prt&0x03) == 0x10)))                
         error_text = "SR_SLT"; 
      if ((ds_slt > 0x3F) || ((ds_slt > 0x1F) && ((ds_prt&0x03) == 0x10)))                
         error_text = "DS_SLT";
   } 
                   
                                       /* Start processing if all       
                                          parameters are correct.             */
   if (error_text == NULL)
   {
                                       /* Set global switching          
                                          variables.                          */
      G_Epic_Switch_Src_Prt = sr_prt;
      G_Epic_Switch_Src_Slt = sr_slt;
      G_Epic_Switch_Dst_Prt = ds_prt;
      G_Epic_Switch_Dst_Slt = ds_slt;
      G_Epic_Switch_Slt_Num = slt_nm;

                                       /* Update all switching          
                                          connections.                        */
      Epic_Update_Connections ();
   }
  
                                       /* V24 control message:          
                                          When error.                         */
   if (error_text != NULL)
   {
      V24_PRINT (("\nSocrates_Set_Epic_Switch: %s ", Error_Text_Start));
      V24_PRINT (("%s ", error_text));     
      V24_PRINT (("%s", Error_Text_End));     
   }

                                       /* Free received message         
                                          because no message is         
                                          returned to the user.               */
   DdsMsgFree (pMsg);
}


/*******************************************************************************
Description:
   Receive message for writing HDLC BZ data via SOCRATES.
Arguments:
   pMsg - pointer to received message
Return Value:
   none
Remarks:
   HDLC transmission done by function Soc_Hdlc_Transmit.
*******************************************************************************/
static void Msg_Soc_Hdlc_Transmit (P_DDS_MSG pMsg)
{
   WORD8 nr, i;
   WORD8 *data_array;            
   const WORD8  *error_text = NULL;
   int ret;

                                       /* Read parameters of received   
                                          message.                            */
   G_V24      = MsgReadWord8 (pMsg,0);
   nr         = MsgReadWord8 (pMsg,1);
   data_array = (WORD8 *) malloc (nr);

   if (G_V24 > 0x01) 
      error_text = "V24";
      
   if (data_array == NULL) 
   {
      printf ("\nSOCRAT_B.C: Memory overflow, ignore data");
      DdsMsgFree (pMsg);
      return;
   }
                                       /* Start processing if all       
                                          parameters are correct.             */
   if (error_text == NULL)
   {
                                       /* V24 control message:          
                                          When processing.                    */
      V24_PRINT(("\n(SLOT %d) Soc_Hdlc_Bz_Transmit:data=", SLOT_NR));
      for (i = 0;i < nr; i++)
      {
         data_array[i] = MsgReadWord8 (pMsg, i+2);
         V24_PRINT(("0x%02X,", data_array[i]));
      }

      ret = Soc_Hdlc_Transmit (nr, data_array);
      switch (ret)
      {
      case -1:
         V24_PRINT(("\n(SLOT %d) HDLC BZ Transceiver not ready!", SLOT_NR));
         free (data_array);
         data_array = NULL;
         break;
      case -2:
         V24_PRINT(("\n(SLOT %d) HDLC BZ Transceiver still busy!", SLOT_NR));
         free (data_array);
         data_array = NULL;
         break;
      }
   }

                                       /* V24 control message:          
                                          When error.                         */
   if (error_text != NULL)
   {
      V24_PRINT (("\n(SLOT %d) Soc_Hdlc_Bz_Transmit: %s ", SLOT_NR, Error_Text_Start));
      V24_PRINT (("%s ", error_text));     
      V24_PRINT (("%s", Error_Text_End));     
   } 
                                       /* Free received message         
                                          because no message is         
                                          returned to the user.               */
   DdsMsgFree (pMsg);
}

/*******************************************************************************
Description:
   Receive message for resetting HDLC BZ part of SOCRATES.
Arguments:
   pMsg - pointer to received message
Return Value:
   none
Remarks:
   HDLC reset done by function Soc_Hdlc_Reset.
*******************************************************************************/

⌨️ 快捷键说明

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