dp_fdl.c
上传用户:hualang
上传日期:2022-04-11
资源大小:104k
文件大小:51k
开发平台:

C/C++

  1. /***********************  Filename: dp_fdl[dev_num].c  ********************************/
  2. /* ========================================================================= */
  3. /*                                                                           */
  4. /* 0000  000   000  00000 0  000  0   0 0 0000                               */
  5. /* 0   0 0  0 0   0 0     0 0   0 0   0 0 0   0                              */
  6. /* 0   0 0  0 0   0 0     0 0     0   0 0 0   0      Einsteinstra遝 6        */
  7. /* 0000  000  0   0 000   0 0     00000 0 0000       91074 Herzogenaurach    */
  8. /* 0     00   0   0 0     0 0     0   0 0 0                                  */
  9. /* 0     0 0  0   0 0     0 0   0 0   0 0 0          Tel: ++49-9132-744-200  */
  10. /* 0     0  0  000  0     0  000  0   0 0 0    GmbH  Fax: ++49-9132-744-204  */
  11. /*                                                                           */
  12. /* ========================================================================= */
  13. /*                                                                           */
  14. /* Function:       interface service routines for VPC3+ (DPV1 services)      */
  15. /*                                                                           */
  16. /* ------------------------------------------------------------------------- */
  17. /*                                                                           */
  18. /* Technical support:       P. Fredehorst                                    */
  19. /*                          Tel. : ++49-9132/744-214                         */
  20. /*                          Fax. :              -204                         */
  21. /*                          eMail: pfredehorst@profichip.com                 */
  22. /*                                                                           */
  23. /*****************************************************************************/
  24. /*****************************************************************************/
  25. /* contents:
  26.   - function prototypes
  27.   - data structures
  28.   - internal functions
  29. */
  30. /*****************************************************************************/
  31. /* include hierarchy */
  32. //#include "E5_Inc.h"
  33. #include "..dp_incplatform.h"
  34. #include "..dp_incdp_inc.h"
  35. #if defined (DP_FDL) //compile only, if fdl-application is selected
  36. /*---------------------------------------------------------------------------*/
  37. /* function prototypes                                                       */
  38. /*---------------------------------------------------------------------------*/
  39. /*---------------------------------------------------------------------------*/
  40. /* global fdl definitions                                                    */
  41. /*---------------------------------------------------------------------------*/
  42. SECTION_DEF_CommuData static FDL_STRUC fdl[MAX_DEV_NUM];
  43. /*---------------------------------------------------------------------------*/
  44. /*                                                                           */
  45. /*  DP_ERROR_CODE fdl_init (UBYTE dev_num)                                            */
  46. /*                                                                           */
  47. /*   function:      Initializing FDL-Interface.                              */
  48. /*                                                                           */
  49. /*   parameter:     none                                                     */
  50. /*   return value:  DP_OK        : Buffer length OK                          */
  51. /*                  ERROR        : defined in dp_error.h                     */
  52. /*                                                                           */
  53. /*---------------------------------------------------------------------------*/
  54. SECTION_DEF_CommuCode DP_ERROR_CODE fdl_init(UBYTE dev_num)
  55. {
  56. DP_ERROR_CODE           error;              // system error code
  57. BLACKFIN_WORDPTR        vpc3_ptr;           // pointer to VPC3, 礐ontroller formatted
  58. UBYTE                   vpc3_seg_adr;       // segment address in VPC3-ASIC
  59. UWORD                   resp_buf_len;       // response buffer
  60. UWORD                   ind_buf_len;        // first indication buffer
  61. UWORD                   sec_buf_len;        // secind indication buffer
  62. UWORD                   fdl_used_mem = 0;   // memory used by fdl
  63. UBYTE                   i;
  64. FDL_SAP_HEADER_PTR fdl_h_ptr = &fdl[dev_num].sap_header[0];
  65.     error = DP_OK;
  66.     memset(&fdl[dev_num], 0, sizeof(fdl[dev_num]));
  67.     memset(&fdl[dev_num].search_key[0], 0xFF, sizeof(fdl[dev_num].search_key));
  68.     //on error: empty sap-list - first byte of sap-list becomes end-criterion
  69.     p_Vpc3[dev_num]->sap_ctrl_list[0] = 0xFF;
  70.     fdl[dev_num].rm_state  = RM_LOCKED;
  71.     fdl[dev_num].dpv2_open = FALSE;
  72.     fdl[dev_num].reset_ctr = 0;
  73.     //Adresse 17: sap_list_ptr vpc3.sap_list / 8
  74.     p_Vpc3[dev_num]->fdl_sap_list_ptr = VPC3_SAP_CTRL_LIST_START(dev_num);
  75.     //pointer mc formatted
  76.     vpc3_ptr = &p_Vpc3[dev_num]->dpbuffer[dp_sys[dev_num].vpc3_used_dp_buf_mem ];//已经是word变量不需要×2
  77.     //pointer vpc3 formatted
  78.     vpc3_seg_adr = (UBYTE)(((VPC3_ADR)vpc3_ptr-(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num)) >> BLACKFIN_SEG_MULDIV );
  79.     #ifdef DP_MSAC_C2
  80.         //describe the MSAC_C2-space
  81.         fdl_h_ptr->sap_nr       = 49;
  82.         fdl_h_ptr->req_ssap     = SAP_ALL;
  83.         fdl_h_ptr->sap_type     = FDL_RM_SAP;
  84.         fdl_h_ptr->ind_buf_len  = 0;                                      //ind-pointer with no length - only buf-header
  85.         fdl_h_ptr->resp_buf_len = FDL_RM_BUF_LENGTH;
  86.         fdl_h_ptr->serv_sup     = SS_SRD_LH;
  87.         fdl_h_ptr->req_sa       = VPC3_GET_STATION_ADDRESS(dev_num);             //lock saps for all masters by setting own address
  88.         fdl_h_ptr++;
  89.         for(i = 0; i < DP_C2_NUM_SAPS; i++)
  90.         {
  91.             fdl_h_ptr->sap_nr       = MSAC_C2_SAP_NR_HIGH - i;
  92.             fdl_h_ptr->req_ssap     = SAP_ALL;
  93.             fdl_h_ptr->sap_type     = FDL_MSAC_C2_SAP;
  94.             fdl_h_ptr->ind_buf_len  = DP_C2_LEN;
  95.             fdl_h_ptr->resp_buf_len = DP_C2_LEN;
  96.             fdl_h_ptr->serv_sup     = SS_SRD_LH;
  97.             fdl_h_ptr->req_sa       = VPC3_GET_STATION_ADDRESS(dev_num);
  98.             fdl_h_ptr++;
  99.         }//for(i = 0; i < DP_C2_NUM_SAPS; i++)
  100.     #endif//#ifdef DP_MSAC_C2
  101.     #ifdef DP_MSAC_C1
  102.         #if(DP_C1_SAPS & DP_C1_USE_ALARM_SAP)
  103.             fdl_h_ptr->sap_nr       = DP_C1_ALARM_SAP_NR;
  104.             fdl_h_ptr->req_ssap     = SAP_ALL;
  105.             fdl_h_ptr->sap_type     = FDL_MSAC_C1_SAP;
  106.             fdl_h_ptr->ind_buf_len  = 4;
  107.             fdl_h_ptr->resp_buf_len = 4;
  108.             fdl_h_ptr->serv_sup     = SS_SRD_LH;
  109.             fdl_h_ptr->req_sa       = (UBYTE) VPC3_GET_STATION_ADDRESS(dev_num); //lock saps for all masters by setting own address
  110.             fdl_h_ptr++;
  111.         #endif//#if(DP_C1_SAPS & DP_C1_USE_ALARM_SAP)
  112.         #if(DP_C1_SAPS & DP_C1_USE_RD_WR_SAP)
  113.             fdl_h_ptr->sap_nr       = DP_C1_RD_WR_SAP_NR;
  114.             fdl_h_ptr->req_ssap     = SAP_ALL;
  115.             fdl_h_ptr->sap_type     = FDL_MSAC_C1_SAP;
  116.             fdl_h_ptr->ind_buf_len  = DP_C1_LEN;
  117.             fdl_h_ptr->resp_buf_len = DP_C1_LEN;
  118.             fdl_h_ptr->serv_sup     = SS_SRD_LH;
  119.             fdl_h_ptr->req_sa       = (UBYTE) VPC3_GET_STATION_ADDRESS(dev_num); //lock saps for all masters by setting own address
  120.             fdl_h_ptr++;
  121.         #endif//#if(DP_C1_SAPS & DP_C1_USE_RD_WR_SAP)
  122.     #endif//#ifdef DP_MSAC_C1
  123.     fdl_h_ptr = &fdl[dev_num].sap_header[0];
  124.     for(i = 0; i < FDL_SAP_MAX; i++)
  125.     {
  126.         fdl[dev_num].search_key[fdl_h_ptr->sap_nr] = i;
  127.         sec_buf_len = 0;
  128.         fdl_h_ptr->state = DISABLED;
  129.         switch(BFWORD2BYTE(fdl_h_ptr->sap_type))
  130.         {
  131.             case FDL_RM_SAP:
  132.             {
  133.                 //the rm-sap has an ind-buffer with length #0
  134.                 ind_buf_len = ((UWORD) 0 + sizeof_FDL_BUF_HEAD + SEG_OFFSET) & SEG_ADDWORD;
  135.                 //one response-buffer
  136.                 resp_buf_len = ((UWORD) FDL_RM_BUF_LENGTH + sizeof_FDL_BUF_HEAD + SEG_OFFSET) & SEG_ADDWORD;
  137.                 break;
  138.             }//case FDL_RM_SAP:
  139.             case FDL_MSAC_C1_SAP:
  140.             case FDL_MSAC_C2_SAP:
  141.             {
  142.                 //one indication/response-buffer
  143.                 if(BFWORD2BYTE(fdl_h_ptr->ind_buf_len) > BFWORD2BYTE(fdl_h_ptr->resp_buf_len))
  144.                 {
  145.                     ind_buf_len = ((UWORD)BFWORD2BYTE(fdl_h_ptr->ind_buf_len) + sizeof_FDL_BUF_HEAD + SEG_OFFSET) & SEG_ADDWORD;
  146.                 }
  147.                 else
  148.                 {
  149.                     ind_buf_len = ((UWORD)BFWORD2BYTE(fdl_h_ptr->resp_buf_len) + sizeof_FDL_BUF_HEAD + SEG_OFFSET) & SEG_ADDWORD;
  150.                 }
  151.                 resp_buf_len = 0;
  152.                 if (BFWORD2BYTE(fdl_h_ptr->sap_type) == FDL_MSAC_C2_SAP )
  153.                 {
  154.                     sec_buf_len = ((UWORD)FDL_DPV2_SEC_BUF_LENGTH + sizeof_FDL_BUF_HEAD + SEG_OFFSET) & SEG_ADDWORD;
  155.                 }
  156.                 break;
  157.             }//case FDL_MSAC_C1_SAP:
  158.             default:
  159.             {
  160.                 break;
  161.             }//default:
  162.         }//switch(fdl_h_ptr->sap_type)
  163.         fdl_used_mem += ind_buf_len + resp_buf_len + sec_buf_len;
  164.         if( (dp_sys[dev_num].vpc3_used_dp_buf_mem + fdl_used_mem) > ASIC_USER_RAM )
  165.         {
  166.             memset(&fdl[dev_num].search_key[0], 0xFF, sizeof(fdl[dev_num].search_key));
  167.             //on error: empty sap-list - first byte of sap-list becomes end-criterion
  168.             p_Vpc3[dev_num]->sap_ctrl_list[0] = 0xFF;
  169.             return DP_LESS_MEM_FDL_ERROR;
  170.         }//if( (dp_sys[dev_num].vpc3_used_dp_buf_mem + fdl_used_mem) > ASIC_USER_RAM )
  171.         fdl_h_ptr->sap_ptr = (FDL_SAP_CNTRL PTR_ATTR *) &( p_Vpc3[dev_num]->sap_ctrl_list[7*i] );//不需要×2
  172.         fdl_h_ptr->sap.resp_s__sap_nr = BFWORD2BYTE(fdl_h_ptr->sap_nr);
  173.         fdl_h_ptr->sap.req_sa         = BFWORD2BYTE(fdl_h_ptr->req_sa);
  174.         // req_ssap any sap but not default-sap or ALL_SSAP
  175.         if( (fdl_h_ptr->req_ssap&0xff) < DEFAULT_SAP )//2009.11.7
  176.         {
  177.             fdl_h_ptr->sap.req_sa |= 0x80;
  178.         }//if( fdl_h_ptr->req_ssap < DEFAULT_SAP )
  179.         fdl_h_ptr->sap.access__req_ssap = fdl_h_ptr->req_ssap;
  180.         fdl_h_ptr->sap.event__serv_sup  = fdl_h_ptr->serv_sup;
  181.         fdl_h_ptr->sap.ind_ptr[0]  = fdl_h_ptr->sap.ind_ptr[1]  = vpc3_seg_adr;
  182.         fdl_h_ptr->sap.resp_ptr    = vpc3_seg_adr;
  183.         fdl_h_ptr->vpc3_ind_ptr[0] = fdl_h_ptr->vpc3_ind_ptr[1] = vpc3_seg_adr;
  184.         _INIT_FDL_BUF_HEAD((FDL_BUF_HEAD_PTR) vpc3_ptr, fdl_h_ptr->ind_buf_len);
  185.         fdl_h_ptr->ind_ptr[0] = fdl_h_ptr->ind_ptr[1] = (FDL_BUF_HEAD_PTR) vpc3_ptr;
  186.         fdl_h_ptr->resp_ptr     = (FDL_BUF_HEAD_PTR) vpc3_ptr;
  187.         incr_vpc3_up_ptr__(ind_buf_len);
  188.         //dpv2-saps with wait-buffer
  189.         if( sec_buf_len )
  190.         {
  191.             fdl_h_ptr->ind_ptr[1]        = (FDL_BUF_HEAD_PTR) vpc3_ptr;
  192.             fdl_h_ptr->vpc3_ind_ptr[1]   = vpc3_seg_adr;
  193.             fdl_h_ptr->sap.ind_ptr[1]    = vpc3_seg_adr;
  194.             _INIT_FDL_BUF_HEAD((FDL_BUF_HEAD_PTR) vpc3_ptr, FDL_DPV2_SEC_BUF_LENGTH);
  195.             incr_vpc3_up_ptr__(sec_buf_len);
  196.         }//if( sec_buf_len )
  197.         //rm-sap with response-buffer
  198.         if(resp_buf_len)
  199.         {
  200.             fdl_h_ptr->sap.resp_ptr = vpc3_seg_adr;
  201.             fdl_h_ptr->resp_ptr     = (FDL_BUF_HEAD_PTR) vpc3_ptr;
  202.             //the rm-sap has one response-buffer that will be initialized now
  203.             ((FDL_BUF_HEAD_PTR) vpc3_ptr)->cntrl   = 0;
  204.             ((FDL_BUF_HEAD_PTR) vpc3_ptr)->len     = FDL_RM_BUF_LENGTH;
  205.             ((FDL_BUF_HEAD_PTR) vpc3_ptr)->fc      = FC_RESP_L;
  206.             ((FDL_BUF_HEAD_PTR) vpc3_ptr)->max_len = FDL_RM_BUF_LENGTH;
  207.             fdl[dev_num].rm_buffer = (rm_answer PTR_ATTR *) &vpc3_ptr[sizeof_FDL_BUF_HEAD]; //WORD型指针,不需要×2
  208.             fdl[dev_num].rm_buffer->opcode       = 0x56; //dpv2 opcode for rm
  209.             fdl[dev_num].rm_buffer->poll_to_high = (MSAC_C2_TIMEOUT_1_5MBAUD >> 8) & 0x00ff;
  210.             fdl[dev_num].rm_buffer->poll_to_low  = MSAC_C2_TIMEOUT_1_5MBAUD & 0x00ff;
  211.             incr_vpc3_up_ptr__(resp_buf_len);
  212.         }//if(resp_buf_len)
  213.         //sap-parameters are copied in vpc3
  214.         copy_sap_parameter__(fdl_h_ptr->sap_ptr, & fdl_h_ptr->sap);
  215.         fdl_h_ptr++;
  216.     }//for(i = 0; i < FDL_SAP_MAX; i++)
  217.     //initialisation o.k. set sap-list-end-criterion and determine the new vpc3-space left
  218.     p_Vpc3[dev_num]->sap_ctrl_list[7*FDL_SAP_MAX] = 0xFF;//已经是word不需要乘BLACKFIN_MULTIPLER
  219.     dp_sys[dev_num].vpc3_used_dp_buf_mem += fdl_used_mem;
  220.     return error;
  221. }//DP_ERROR_CODE fdl_init(UBYTE dev_num)
  222. /*---------------------------------------------------------------------------*/
  223. /* function: fdl_set_poll_timeout                                            */
  224. /*---------------------------------------------------------------------------*/
  225. SECTION_DEF_CommuCode void fdl_set_poll_timeout(UBYTE dev_num, UWORD poll_timeout )
  226. {
  227.     fdl[dev_num].rm_buffer->poll_to_high = (poll_timeout >> 8) & 0x00ff;
  228.     fdl[dev_num].rm_buffer->poll_to_low  = poll_timeout & 0x00ff;
  229. }//void fdl_set_poll_timeout(UBYTE dev_num, UWORD poll_timeout )
  230. /*---------------------------------------------------------------------------*/
  231. /*                                                                           */
  232. /* void fdl_mac_indication (UBYTE dev_num)                                            */
  233. /*                                                                           */
  234. /* function: fdl-state-machine - treat an mac-indication - REQ-PDU-IND       */
  235. /*                                                                           */
  236. /*---------------------------------------------------------------------------*/
  237. SECTION_DEF_CommuCode void fdl_mac_indication(UBYTE dev_num)//总FDL结构有n个sap header每个header里包括了sap list指针和内容
  238. {
  239. FDL_SAP_HEADER_PTR  fdl_h_ptr;
  240. UBYTE               sap_ctr;
  241. UBYTE               help_byte;
  242.     fdl_h_ptr = &fdl[dev_num].sap_header[0];//判断sap缓冲区内哪一个sap被调用
  243.     for(sap_ctr = 0; sap_ctr < FDL_SAP_MAX; sap_ctr++)
  244.     {
  245.         if(    ((fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_IND) || (fdl_h_ptr->ind_ptr[1]->cntrl & PCNTRL_IND))
  246.             && (BFWORD2BYTE(fdl_h_ptr->state) == ENABLED) )
  247.         {
  248. //logMsg("fdl_mac_indication-----step1,dev_num=%d,sap_type=%d!n",dev_num,fdl_h_ptr->sap_type,0,0,0,0);
  249.             if( BFWORD2BYTE(fdl_h_ptr->sap_type) == FDL_RM_SAP )//masc2
  250.             {
  251.                 #ifdef DP_MSAC_C2
  252.                     FDL_SAP_HEADER_PTR  fdl_h_ptr_rm;
  253.                     // set the dpv2-sap to it's new master
  254.                     fdl_h_ptr_rm = fdl_get_sap_header_ptr(dev_num,(UBYTE) fdl[dev_num].rm_buffer->sap_nr);
  255.                     // allow access to the sap from the detected master and it's source-sap
  256.                     fdl_set_sa_ssap (dev_num,fdl_h_ptr_rm->sap_nr, (UBYTE) (fdl_h_ptr->sap_ptr->req_sa),
  257.                                      (UBYTE) (fdl_h_ptr->sap_ptr->access__req_ssap & 0x7f) );
  258.                     //try to reload the rm-sap
  259.                     fdl[dev_num].rm_state = RM_LOADABLE;
  260.                     //reset several control-values of sap 49 in vpc3-sap_list
  261.                     fdl_h_ptr->sap_ptr->resp_s__sap_nr   = 49;
  262.                     fdl_h_ptr->sap_ptr->req_sa           = SA_ALL;
  263.                     fdl_h_ptr->sap_ptr->access__req_ssap = SAP_ALL;
  264.                     //preset the rm-sap with it's own ind-pointer (length == 0)
  265.                     //fdl_h_ptr->sap_ptr->ind_ptr[1] = fdl_h_ptr->sap_ptr->ind_ptr[0] = fdl_h_ptr->sap.ind_ptr[0];
  266.                     //preset the rm-sap to cause RS mm, 24-Feb-1998
  267.                     fdl_h_ptr->sap_ptr->ind_ptr[0] = 0;
  268.                     //dpv2-saps start from index #1 (index #0 is always the rm-sap)
  269.                     fdl_h_ptr_rm = & fdl[dev_num].sap_header[1];
  270.                     help_byte = DP_C2_NUM_SAPS;
  271.                     while(help_byte--)
  272.                     {
  273.                         //if ( fdl_h_ptr_rm->state == DISABLED_FOR_RM )
  274.                         if( (BFWORD2BYTE(fdl_h_ptr_rm->state) == DISABLED_FOR_RM ) || ( BFWORD2BYTE(fdl_h_ptr_rm->state) == DISABLED ))
  275.                         {
  276.                             fdl[dev_num].rm_state = RM_LOADED;
  277.                             fdl_h_ptr_rm->state = DISABLED_IN_RM;
  278.                             //force rs of rm-sap by storing #0 in vpc3-sap-list
  279.                             fdl_h_ptr->sap_ptr->ind_ptr[0] = 0;
  280.                             //store the uP-addresses of the ind-buffers of the desired dpv2-sap
  281.                             fdl_h_ptr->ind_ptr[0] = fdl_h_ptr->ind_ptr[1] = fdl_h_ptr_rm->ind_ptr[0];
  282.                             //reset the control-byte of the ind-buffer of the desired dpv2-sap
  283.                             fdl_h_ptr_rm->ind_ptr[0]->cntrl = 0;
  284.                             fdl_h_ptr_rm->ind_ptr[1]->cntrl = 0;
  285.                             fdl_h_ptr_rm->resp_ptr->cntrl = 0;
  286.                             //take the vpc3-address of the ind-buffer of the desired dpv2-sap
  287.                             help_byte = fdl_h_ptr_rm->vpc3_ind_ptr[0];
  288.                             //store the new sap-number in the immediate-response-buffer
  289.                             fdl[dev_num].rm_buffer->sap_nr = fdl_h_ptr_rm->sap_nr;
  290.                             msac_c2_open_channel_sap(dev_num,fdl[dev_num].rm_buffer->sap_nr);
  291.                             //preset the control-byte of the immediate-response-buffer for sending
  292.                             fdl_h_ptr->resp_ptr->cntrl = PCNTRL_RESP + PCNTRL_USER;
  293.                             //store the vpc3-address the ind-buffer of the desired dpv2-sap in vpc3-sap-list (ind_ptr 1)
  294.                             fdl_h_ptr->sap_ptr->ind_ptr[1] = help_byte;
  295.                             //do the same in vpc3-sap-list with ind_ptr 0  that means: sap 49 is enabled now
  296.                             fdl_h_ptr->sap_ptr->ind_ptr[0] = help_byte;
  297.                             break;
  298.                         }//if( (fdl_h_ptr_rm->state == DISABLED_FOR_RM ) || (fdl_h_ptr_rm->state == DISABLED ))
  299.                         else
  300.                         {
  301.                             fdl_h_ptr_rm++;
  302.                         }//else of if( ( fdl_h_ptr_rm->state == DISABLED_FOR_RM ) || ( fdl_h_ptr_rm->state == DISABLED ))
  303.                     }//while(help_byte--)
  304.                 #endif//#ifdef DP_MSAC_C2
  305.             }//if( fdl_h_ptr->sap_type == FDL_RM_SAP )
  306.             else
  307.             {
  308. //logMsg("fdl_mac_indication-----step2!n",dev_num,0,0,0,0,0);
  309.                 help_byte = ( fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_IND ) ? 0 : 1;
  310.                 if( BFWORD2BYTE(fdl_h_ptr-> state) == ENABLED )
  311.                 {
  312.                     //indication-buffer for user
  313.                     fdl_h_ptr->ind_ptr[help_byte]->cntrl &= ~PCNTRL_IND;
  314.                     //fdl_h_ptr->ind_ptr[help_byte]->cntrl |= PCNTRL_USER;
  315.                     switch(BFWORD2BYTE(fdl_h_ptr->sap_type))
  316.                     {
  317.                         #ifdef DP_MSAC_C1
  318.                             case FDL_MSAC_C1_SAP:
  319.                             {
  320. //logMsg("fdl_mac_indication-----step3!n",dev_num,0,0,0,0,0);
  321.                                 msac_c1_pdu_received(dev_num, fdl_h_ptr->sap_nr,
  322.                                                       (IND_RESP_BUF_PTR) &(fdl_h_ptr->ind_ptr[help_byte]->len) ,
  323.                                                       (fdl_h_ptr->sap_ptr->req_sa & 0x7F)   );//req_sa请求的原地址
  324.                                 break;
  325.                             }//case FDL_MSAC_C1_SAP:
  326.                         #endif//#ifdef DP_MSAC_C1
  327.                         #ifdef DP_MSAC_C2
  328.                             case FDL_MSAC_C2_SAP:
  329.                             {
  330.                                 msac_c2_input_queue(dev_num, (MSAC_C2_DATA_BUF_PTR) &(fdl_h_ptr->ind_ptr[help_byte]->len) , FDL_OK,fdl_h_ptr->sap_nr, MSAC_C2_IND_RECV);
  331.                                 break;
  332.                             }//case FDL_MSAC_C2_SAP:
  333.                         #endif//#ifdef DP_MSAC_C2
  334.                             default:
  335.                             {
  336.                                 break;
  337.                             }//default:
  338.                     }//switch(fdl_h_ptr->sap_type)
  339.                 }//if( fdl_h_ptr-> state == ENABLED )
  340.             }//else of if( fdl_h_ptr->sap_type == FDL_RM_SAP )
  341.         }//if(    ((fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_IND) || ....
  342.         fdl_h_ptr++;
  343.     }//for(sap_ctr = 0; sap_ctr < FDL_SAP_MAX; sap_ctr++)
  344. }//void fdl_mac_indication(UBYTE dev_num)
  345. /*---------------------------------------------------------------------------*/
  346. /*                                                                           */
  347. /* void fdl_flc_indication (UBYTE dev_num)                                            */
  348. /*                                                                           */
  349. /* function: fdl-state-machine - treat a flc-indication - POLL-END-IND       */
  350. /*                                                                           */
  351. /*---------------------------------------------------------------------------*/
  352. SECTION_DEF_CommuCode void fdl_flc_indication(UBYTE dev_num)
  353. {
  354. FDL_SAP_HEADER_PTR  fdl_h_ptr = &fdl[dev_num].sap_header[0];
  355. UBYTE               sap_ctr;
  356.     for(sap_ctr = 0; sap_ctr < FDL_SAP_MAX; sap_ctr++)
  357.     {
  358.         if( fdl_h_ptr->sap_ptr->resp_s__sap_nr & 0x80 )
  359.         {
  360.             //fdl_h_ptr->sap_ptr->resp_s__sap_nr &= 0x7f;
  361.             if( BFWORD2BYTE(fdl_h_ptr-> state) == ENABLED )
  362.             {
  363.                 switch(BFWORD2BYTE(fdl_h_ptr->sap_type))
  364.                 {
  365.                     #ifdef DP_MSAC_C2
  366.                         case FDL_RM_SAP:
  367.                         {
  368.                             // do nothing here
  369.                             break;
  370.                         }
  371.                         case FDL_MSAC_C2_SAP:
  372.                         {
  373.                             msac_c2_input_queue(dev_num,NULL_PTR, FDL_OK, fdl_h_ptr->sap_nr, MSAC_C2_RESP_SENT);
  374.                             break;
  375.                         }
  376.                     #endif//#ifdef DP_MSAC_C2
  377.                         default:
  378.                         {
  379.                             break;
  380.                         }//default:
  381.                 }//switch(fdl_h_ptr->sap_type)
  382.             }//if( fdl_h_ptr-> state == ENABLED )
  383.         }//if( fdl_h_ptr->sap_ptr->resp_s__sap_nr & 0x80 )
  384.         fdl_h_ptr++;
  385.     }//for(sap_ctr = 0; sap_ctr < FDL_SAP_MAX; sap_ctr++)
  386. }//void fdl_flc_indication(UBYTE dev_num)
  387. /*---------------------------------------------------------------------------*/
  388. /*                                                                           */
  389. /* void fdl_cyclic_service (UBYTE dev_num)                                            */
  390. /*                                                                           */
  391. /* function: fdl-state-machine - treat a sap to be reset but actually in use */
  392. /*                                                                           */
  393. /*---------------------------------------------------------------------------*/
  394. SECTION_DEF_CommuCode void fdl_cyclic_service (UBYTE dev_num)
  395. {
  396. #ifdef NOTUSED
  397. FDL_SAP_HEADER_PTR  fdl_h_ptr;
  398. UBYTE               ctr;
  399.     if( fdl[dev_num].reset_ctr )
  400.     {
  401.         fdl_h_ptr = & fdl[dev_num].sap_header[0];
  402.         ctr = FDL_SAP_MAX;
  403.         while(ctr--)
  404.         {
  405.             if( BFWORD2BYTE(fdl_h_ptr->state) == DIS_RUNNING )
  406.             {
  407.                 if(    !(fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE)
  408.                     && !(fdl_h_ptr->ind_ptr[1]->cntrl & PCNTRL_INUSE)
  409.                     && !(fdl_h_ptr->resp_ptr->cntrl   & PCNTRL_INUSE)
  410.                   )
  411.                 {
  412.                     fdl_h_ptr->state = DISABLED;
  413.                     fdl[dev_num].reset_ctr--;
  414.                     //perform sap-reset
  415.                     //set indication-buffer to vpc3
  416.                     copy_sap_parameter__(fdl_h_ptr->sap_ptr, &fdl_h_ptr->sap);
  417.                     fdl_h_ptr->ind_ptr[0]->cntrl = 0;
  418.                     //fdl_h_ptr->ind_ptr[1]->cntrl = 0;
  419.                     fdl_h_ptr->resp_ptr->cntrl = 0;
  420.                     switch( fdl_h_ptr->sap_type )
  421.                     {
  422.                       #ifdef DP_MSAC_C2
  423.                         case FDL_MSAC_C2_SAP:
  424.                         {
  425.                             msac_c2_input_queue(dev_num,NULL_PTR, FDL_OK, fdl_h_ptr->sap_nr, MSAC_C2_IND_DISABLE_DONE );
  426.                             break;
  427.                         }
  428.                       #endif//#ifdef DP_MSAC_C2
  429.                       #ifdef DP_MSAC_C1
  430.                         case FDL_MSAC_C1_SAP:
  431.                         {
  432.                             msac_c1_ind_disable_done(dev_num,fdl_h_ptr->sap_nr, FDL_OK );
  433.                             break;
  434.                         }
  435.                       #endif//#ifdef DP_MSAC_C1
  436.                     }
  437.                 }
  438.             }
  439.             fdl_h_ptr++;
  440.         }
  441.     }
  442. #endif
  443. }
  444. /*---------------------------------------------------------------------------*/
  445. /*                                                                           */
  446. /* void fdl_set_sa_ssap(UBYTE dev_num,UBYTE sap_nr, UBYTE req_sa, UBYTE req_ssap)          */
  447. /*                                                                           */
  448. /*   function: This function sets temporary sa and ssap of the desired sap.  */
  449. /*                                                                           */
  450. /*---------------------------------------------------------------------------*/
  451. SECTION_DEF_CommuCode void fdl_set_sa_ssap(UBYTE dev_num,   UBYTE sap_nr, UBYTE req_sa, UBYTE req_ssap )
  452. {
  453. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  454. UBYTE               req_sa_loc = req_sa & 0x7f;
  455.     //perform service only, if req_ssap is in a valid range
  456.     if( ( (req_ssap&0xff) <= DEFAULT_SAP) || ( (req_ssap&0xff) == SAP_ALL) )////2009.11.7
  457.     {
  458.         if( (sap_nr&0xff) != DEFAULT_SAP)//2009.11.7
  459.         {
  460.             if ( (req_sa&0xff) != SA_ALL )//2009.11.7
  461.             {
  462.                 req_sa_loc |= 0x80;
  463.             }//if ( req_sa != SA_ALL )
  464.         }//if(sap_nr != DEFAULT_SAP)
  465.         fdl_h_ptr->state = ENABLED;
  466.         //set sap-parameters
  467.         fdl_h_ptr->sap_ptr->access__req_ssap = req_ssap;
  468.         fdl_h_ptr->sap_ptr->req_sa = req_sa_loc;
  469.     }//if( (req_ssap <= DEFAULT_SAP) || (req_ssap == SAP_ALL) )
  470. }//void fdl_set_sa_ssap(UBYTE dev_num,    UBYTE sap_nr, UBYTE req_sa, UBYTE req_ssap )
  471. /*---------------------------------------------------------------------------*/
  472. /*                                                                           */
  473. /* FDL_SAP_HEADER_PTR fdl_get_sap_header_ptr(UBYTE dev_num, UBYTE sap )                    */
  474. /*                                                                           */
  475. /*   function: return 0 or the pointer to the desired fdl-sap-structure      */
  476. /*                                                                           */
  477. /*---------------------------------------------------------------------------*/
  478. SECTION_DEF_CommuCode FDL_SAP_HEADER_PTR  fdl_get_sap_header_ptr(UBYTE dev_num, UBYTE sap )
  479. {
  480. UBYTE  index;
  481.     if( ( (sap&0xff) >= sizeof(fdl[dev_num].search_key) ) || ((index = fdl[dev_num].search_key[sap&0xff]) == 0xFF ) )//2009.11.7
  482.     {
  483.         // error function
  484.     }//if( (sap >= sizeof(fdl[dev_num].search_key) ) || ((index = fdl[dev_num].search_key[sap]) == 0xFF ) )
  485.     return (&fdl[dev_num].sap_header[index]);
  486. }//FDL_SAP_HEADER_PTR   fdl_get_sap_header_ptr(UBYTE dev_num, UBYTE sap )
  487. /*---------------------------------------------------------------------------*/
  488. /*                                                                           */
  489. /* void fdl_ind_provide (UBYTE dev_num,UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr)             */
  490. /*                                                                           */
  491. /*   function: The function prepares the indication-provide of a desired SAP */
  492. /*                                                                           */
  493. /*---------------------------------------------------------------------------*/
  494. SECTION_DEF_CommuCode void fdl_ind_provide(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr )
  495. {
  496. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  497. UBYTE               ret_value = FDL_OK;
  498. UBYTE               i;
  499.     DP_LOCK_IND(dev_num);
  500.     i = (fdl_h_ptr->sap_type == FDL_MSAC_C2_SAP) ? 0 : 1;
  501.     for(; i < 2; i++)
  502.     {
  503.         //search for pointer
  504.         if( ind_ptr == (IND_RESP_BUF_PTR) &(fdl_h_ptr->ind_ptr[i]->len) )
  505.         {
  506.             //pointer belongs to sap
  507.             if( fdl_h_ptr->ind_ptr[i]->cntrl & PCNTRL_USER )
  508.             {
  509.                 //indication-buffer belongs to user, return to vpc3
  510.                 fdl_h_ptr->ind_ptr[i]->cntrl = 0;
  511.                 ret_value = FDL_OK;
  512.                 break;
  513.             }//if( fdl_h_ptr->ind_ptr[i]->cntrl & PCNTRL_USER )
  514.             else
  515.             {
  516.                 //buffer not occupied by user
  517.                 ret_value = FDL_NUIB;
  518.                 break;
  519.             }//else of if( fdl_h_ptr->ind_ptr[i]->cntrl & PCNTRL_USER )
  520.         }//if( ind_ptr == (IND_RESP_BUF_PTR) &(fdl_h_ptr->ind_ptr[i]->len) )
  521.         else
  522.         {
  523.             //no buffer was found */
  524.             ret_value = FDL_FPTR;
  525.         }//else of if( ind_ptr == (IND_RESP_BUF_PTR) &(fdl_h_ptr->ind_ptr[i]->len) )
  526.     }//for(; i < 2; i++)
  527.     DP_UNLOCK_IND(dev_num);
  528. }//void fdl_ind_provide(UBYTE dev_num, UBYTE sap_nr, IND_RESP_BUF_PTR ind_ptr )
  529. /*---------------------------------------------------------------------------*/
  530. /*                                                                           */
  531. /* void fdl_resp_provide (UBYTE dev_num,UBYTE sap_nr, UBYTE prim_sec)                      */
  532. /*                                                                           */
  533. /*   function: The function prepares the response-provide of a desired SAP   */
  534. /*                                                                           */
  535. /*---------------------------------------------------------------------------*/
  536. SECTION_DEF_CommuCode void fdl_resp_provide(UBYTE dev_num, UBYTE sap_nr, UBYTE prim_sec )
  537. {
  538.    int i,j;
  539. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  540. IND_RESP_BUF_PTR    usr_ptr;
  541. FDL_BUF_HEAD_PTR    resp_ptr;
  542. UBYTE               ret_value = FDL_OK;
  543. UBYTE               help_byte;
  544.     DP_LOCK_IND(dev_num);
  545.                             
  546.     if( (BFWORD2BYTE(fdl_h_ptr->sap_type) != FDL_MSAC_C2_SAP) && (prim_sec == FDL_SECONDARY_BUF) )
  547.     {
  548.         //no buffer available
  549.         ret_value = FDL_NURB;
  550.     }//if( (fdl_h_ptr->sap_type != FDL_MSAC_C2_SAP) && (prim_sec == FDL_SECONDARY_BUF) )
  551.     if( ret_value == FDL_OK )
  552.     {
  553.         switch( prim_sec )
  554.         {
  555.             case FDL_PRIMARY_BUF:
  556.             {
  557.                 resp_ptr  = fdl_h_ptr->resp_ptr;
  558.                 help_byte = fdl_h_ptr->resp_buf_len;
  559.                 break;
  560.             }//case FDL_PRIMARY_BUF:
  561.             case FDL_SECONDARY_BUF:
  562.             {
  563.                 resp_ptr  = fdl_h_ptr->ind_ptr[1];
  564.                 help_byte = FDL_DPV2_SEC_BUF_LENGTH;
  565.                 break;
  566.             }//case FDL_SECONDARY_BUF:
  567.             default:
  568.             {
  569.                 resp_ptr = (FDL_BUF_HEAD_PTR)0;// NIL;
  570.                 help_byte = 0;
  571.                 break;
  572.             }//default:
  573.         }//switch( prim_sec )
  574.         if( !(resp_ptr) || (resp_ptr->cntrl & PCNTRL_RESP) )
  575.         {
  576.             //no buffer available
  577.             ret_value = FDL_NURB;
  578.         }//if( !(resp_ptr) || (resp_ptr->cntrl & PCNTRL_RESP) )
  579.         else
  580.         {
  581.             usr_ptr = (IND_RESP_BUF_PTR) &resp_ptr->len;
  582.             if( BFWORD2BYTE(usr_ptr->data_len) <= help_byte )
  583.             {
  584.                 //length fits into buffer
  585.                 help_byte = BFWORD2BYTE(usr_ptr->fc);
  586.                 if( (help_byte == FC_RESP_L) || (help_byte == FC_RESP_H) )
  587.                 {
  588.                     if( (BFWORD2BYTE(fdl_h_ptr->sap_type) == FDL_MSAC_C1_SAP) || ( BFWORD2BYTE(fdl_h_ptr->sap_type) == FDL_MSAC_C2_SAP))
  589.                     {
  590.                         help_byte = (prim_sec == FDL_PRIMARY_BUF) ? fdl_h_ptr->vpc3_ind_ptr[0] : fdl_h_ptr->vpc3_ind_ptr[1];
  591.                         fdl_h_ptr->sap_ptr->ind_ptr[0] = (UBYTE) help_byte;
  592.                         //changed V301, profichip 19.09.2002
  593.                         //the VPC3+ can receive the ABORT message over indication buffer 2
  594.                         //fdl_h_ptr->sap_ptr->ind_ptr[1] = (UBYTE) help_byte;
  595.                         fdl_h_ptr->sap_ptr->resp_ptr   = (UBYTE) help_byte;
  596.                     }
  597.                     resp_ptr->cntrl &= ~PCNTRL_RESP;
  598.                     //taskDelay( 1 );
  599. for(i=0 ;i<300 ;i++)//硬延时一段时间 100000
  600. {
  601. j=0;
  602. }
  603.                     resp_ptr->cntrl |= PCNTRL_RESP;
  604.                 }//if( (help_byte == FC_RESP_L) || (help_byte == FC_RESP_H) )
  605.                 else
  606.                 {
  607.                     ret_value = FDL_IVP;
  608.                 }//else of if( (help_byte == FC_RESP_L) || (help_byte == FC_RESP_H) )
  609.             }//if( usr_ptr->data_len <= help_byte )
  610.             else
  611.             {
  612.                 //length exceeds buffer
  613.                 ret_value = FDL_RLEN;
  614.             }//else of if( usr_ptr->data_len <= help_byte )
  615.         }//else of if( !(resp_ptr) || (resp_ptr->cntrl & PCNTRL_RESP) )
  616.     }//if( ret_value == FDL_OK )
  617.     DP_UNLOCK_IND(dev_num);
  618.     if( ret_value != FDL_OK )
  619.     {
  620.         switch( BFWORD2BYTE(fdl_h_ptr->sap_type) )
  621.         {
  622.             #ifdef DP_MSAC_C2
  623.                 case FDL_MSAC_C2_SAP:
  624.                 {
  625.                     msac_c2_input_queue(dev_num,NULL_PTR, ret_value, fdl_h_ptr->sap_nr, MSAC_C2_RESP_SENT);
  626.                     break;
  627.                 }//case FDL_MSAC_C2_SAP:
  628.             #endif//#ifdef DP_MSAC_C2
  629.                 default:
  630.                 {
  631.                     break;
  632.                 }//default:
  633.         }//switch( fdl_h_ptr->sap_type )
  634.     }//if( ret_value != FDL_OK )
  635. }//void fdl_resp_provide(UBYTE dev_num, UBYTE sap_nr, UBYTE prim_sec )
  636. /*---------------------------------------------------------------------------*/
  637. /*                                                                           */
  638. /* void fdl_reset_pcntrl_resp_bit (UBYTE dev_num,UBYTE sap_nr, UBYTE prim_sec)             */
  639. /*                                                                           */
  640. /*   function: The function reset the PCNTRL_RESP bit in the buffer          */
  641. /*                                                                           */
  642. /*---------------------------------------------------------------------------*/
  643. SECTION_DEF_CommuCode void fdl_reset_pcntrl_resp_bit(UBYTE dev_num, UBYTE sap_nr, UBYTE prim_sec )
  644. {
  645. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  646. FDL_BUF_HEAD_PTR    resp_ptr;
  647. UBYTE               ret_value = FDL_OK;
  648.     DP_LOCK_IND(dev_num);
  649.     if( (BFWORD2BYTE(fdl_h_ptr->sap_type) != FDL_MSAC_C2_SAP) && (prim_sec == FDL_SECONDARY_BUF) )
  650.     {
  651.         //no buffer available
  652.         ret_value = FDL_NURB;
  653.     }//if( (fdl_h_ptr->sap_type != FDL_MSAC_C2_SAP) && (prim_sec == FDL_SECONDARY_BUF) )
  654.     if( ret_value == FDL_OK )
  655.     {
  656.         switch( prim_sec )
  657.         {
  658.             case FDL_PRIMARY_BUF:
  659.             {
  660.                 resp_ptr  = fdl_h_ptr->resp_ptr;
  661.                 break;
  662.             }//case FDL_PRIMARY_BUF:
  663.             case FDL_SECONDARY_BUF:
  664.             {
  665.                 resp_ptr  = fdl_h_ptr->ind_ptr[1];
  666.                 break;
  667.             }//case FDL_SECONDARY_BUF:
  668.             default:
  669.             {
  670.                 resp_ptr = (FDL_BUF_HEAD_PTR)0;// NIL;
  671.                 break;
  672.             }//default:
  673.         }//switch( prim_sec )
  674.         if( resp_ptr )
  675.         {
  676.             resp_ptr->cntrl &= ~PCNTRL_RESP;
  677.         }//if( resp_ptr )
  678.     }//if( ret_value == FDL_OK )
  679.     DP_UNLOCK_IND(dev_num);
  680. }//void fdl_reset_pcntrl_resp_bit(UBYTE dev_num, UBYTE sap_nr, UBYTE prim_sec )
  681. /*---------------------------------------------------------------------------*/
  682. /*                                                                           */
  683. /* void fdl_ind_disable(UBYTE dev_num,UBYTE sap_nr)                                        */
  684. /*                                                                           */
  685. /*   function: The function resets the sap to its initial value              */
  686. /*                                                                           */
  687. /*---------------------------------------------------------------------------*/
  688. SECTION_DEF_CommuCode void fdl_ind_disable(UBYTE dev_num, UBYTE sap_nr )
  689. {
  690. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  691.     DP_LOCK_IND(dev_num);
  692.     //DP_UNLOCK_IND(dev_num) done in following function
  693.     fdl_perform_ind_disable(dev_num,fdl_h_ptr);
  694. }//void fdl_ind_disable(UBYTE dev_num, UBYTE sap_nr )
  695. /*---------------------------------------------------------------------------*/
  696. /*                                                                           */
  697. /* void fdl_ind_disable(UBYTE dev_num,UBYTE sap_nr)                                        */
  698. /*                                                                           */
  699. /*   function: The function resets the sap to its initial value              */
  700. /*                                                                           */
  701. /*---------------------------------------------------------------------------*/
  702. SECTION_DEF_CommuCode void fdl_ind_disable_SAP50(UBYTE dev_num)
  703. {
  704. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,DP_C1_ALARM_SAP_NR);
  705.     DP_LOCK_IND(dev_num);
  706.     //DP_UNLOCK_IND(dev_num) done in following function
  707.     fdl_perform_ind_disable_SAP50(dev_num,fdl_h_ptr);
  708. }//void fdl_ind_disable_SAP50(UBYTE dev_num)
  709. /*---------------------------------------------------------------------------*/
  710. /*                                                                           */
  711. /* UBYTE fdl_ind_await(UBYTE dev_num,UBYTE sap_nr)                                         */
  712. /*                                                                           */
  713. /*   function: The function the rm for a connection at the desired sap s     */
  714. /*                                                                           */
  715. /*---------------------------------------------------------------------------*/
  716. SECTION_DEF_CommuCode UBYTE fdl_ind_await(UBYTE dev_num, UBYTE sap_nr )
  717. {
  718. FDL_SAP_HEADER_PTR  fdl_h_ptr = fdl_get_sap_header_ptr(dev_num,sap_nr);
  719. UBYTE               ret_value = FDL_OK;
  720. #ifdef DP_MSAC_C2
  721. UBYTE               help_byte;
  722. #endif//#ifdef DP_MSAC_C2
  723.     DP_LOCK_IND(dev_num);
  724.     switch( BFWORD2BYTE(fdl_h_ptr->sap_type) )
  725.     {
  726.         #ifdef DP_MSAC_C1
  727.             case FDL_MSAC_C1_SAP:
  728.             {
  729.                 fdl_set_sa_ssap(dev_num,sap_nr, SA_ALL, SAP_ALL);
  730.                 break;
  731.             }//case FDL_MSAC_C1_SAP:
  732.         #endif//#ifdef DP_MSAC_C1
  733.         #ifdef DP_MSAC_C2
  734.             case FDL_MSAC_C2_SAP:
  735.             {
  736.                 if( fdl[dev_num].dpv2_open != FALSE )
  737.                 {
  738.                     if( fdl_h_ptr->state == DISABLED )
  739.                     {
  740.                         fdl_h_ptr->state = DISABLED_FOR_RM;
  741.                         if( fdl[dev_num].rm_state == RM_LOADABLE )
  742.                         {
  743.                             fdl[dev_num].rm_state = RM_LOADED;
  744.                             fdl_h_ptr->state = DISABLED_IN_RM;
  745.                             //force rs of rm-sap by storing #0 in vpc3-sap-list
  746.                             fdl[dev_num].sap_header[0].sap_ptr->ind_ptr[0] = 0;
  747.                             //store the uP-addresses of the ind-buffers of the desired dpv2-sap
  748.                             fdl[dev_num].sap_header[0].ind_ptr[0] = fdl[dev_num].sap_header[0].ind_ptr[1] = fdl_h_ptr->ind_ptr[0];
  749.                             //reset several control-values of sap 49 in vpc3-sap_list/
  750.                             fdl[dev_num].sap_header[0].sap_ptr->resp_s__sap_nr   = 49;
  751.                             fdl[dev_num].sap_header[0].sap_ptr->req_sa           = SA_ALL;
  752.                             fdl[dev_num].sap_header[0].sap_ptr->access__req_ssap = SAP_ALL;
  753.                             //reset the control-byte of the ind-buffer of the desired dpv2-sap
  754.                             fdl_h_ptr->ind_ptr[0]->cntrl = 0;
  755.                             fdl_h_ptr->ind_ptr[1]->cntrl = 0;
  756.                             fdl_h_ptr->resp_ptr->cntrl = 0;
  757.                             //take the vpc3-address of the ind-buffer of the desired dpv2-sap
  758.                             help_byte = fdl_h_ptr->vpc3_ind_ptr[0];
  759.                             //store the new sap-number in the immediate-response-buffer
  760.                             fdl[dev_num].rm_buffer->sap_nr = fdl_h_ptr->sap_nr;
  761.                             //preset the control-byte of the immediate-response-buffer for sending
  762.                             fdl[dev_num].sap_header[0].resp_ptr->cntrl = PCNTRL_RESP + PCNTRL_USER;
  763.                             //store the vpc3-address the ind-buffer of the desired dpv2-sap in vpc3-sap-list (ind_ptr 1)
  764.                             fdl[dev_num].sap_header[0].sap_ptr->ind_ptr[1] = help_byte;
  765.                             //do the same in vpc3-sap-list with ind_ptr 0  that means: sap 49 is enabled now
  766.                             fdl[dev_num].sap_header[0].sap_ptr->ind_ptr[0] = help_byte;
  767.                         }//if( fdl[dev_num].rm_state == RM_LOADABLE )
  768.                     }//if( fdl_h_ptr->state == DISABLED )
  769.                     else
  770.                     {
  771.                         ret_value = FDL_IUSE;
  772.                     }//else of if( fdl_h_ptr->state == DISABLED )
  773.                 }//if( fdl[dev_num].dpv2_open != FALSE )
  774.                 else
  775.                 {
  776.                     ret_value = FDL_OPEN_ERR;
  777.                 }//else of if( fdl[dev_num].dpv2_open != FALSE )
  778.                 break;
  779.             }//case FDL_MSAC_C2_SAP:
  780.         #endif//#ifdef DP_MSAC_C2
  781.             default:
  782.             {
  783.                 break;
  784.             }
  785.     }//switch( fdl_h_ptr->sap_type )
  786.     DP_UNLOCK_IND(dev_num);
  787.     return(ret_value );
  788. }//UBYTE fdl_ind_await(UBYTE dev_num, UBYTE sap_nr )
  789. /*---------------------------------------------------------------------------*/
  790. /*                                                                           */
  791. /* void fdl_perform_ind_disable(UBYTE dev_num,FDL_SAP_HEADER_PTR  fdl_h_ptr)               */
  792. /*                                                                           */
  793. /*   function: The function resets the sap to its initial value, unlocks     */
  794. /*             interrupt and if due: performs the user-callback-function     */
  795. /*                                                                           */
  796. /*---------------------------------------------------------------------------*/
  797. SECTION_DEF_CommuCode void fdl_perform_ind_disable(UBYTE dev_num, FDL_SAP_HEADER_PTR fdl_h_ptr )
  798. {
  799. UBYTE ret_value;
  800.     ret_value = FDL_OPEN_ERR;
  801.     if( (fdl_h_ptr->state&0xff) == ENABLED )//2009.11.7
  802.     {
  803.         fdl_h_ptr->state = DISABLED;
  804.         fdl_h_ptr->sap_ptr->ind_ptr[0] = 0;
  805.         if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE)
  806.             || (fdl_h_ptr->ind_ptr[1]->cntrl & PCNTRL_INUSE)
  807.             || (fdl_h_ptr->resp_ptr->cntrl   & PCNTRL_INUSE)
  808.           )
  809.         {
  810.             fdl_h_ptr->state = DIS_RUNNING;
  811.             fdl[dev_num].reset_ctr++;
  812.         }//if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE) ...
  813.         else
  814.         {
  815.             //perform sap-reset
  816.             //set indication-buffer to vpc3
  817.             copy_sap_parameter__(fdl_h_ptr->sap_ptr, & fdl_h_ptr->sap);
  818.             fdl_h_ptr->ind_ptr[0]->cntrl = 0;
  819.             fdl_h_ptr->ind_ptr[1]->cntrl = 0;
  820.             fdl_h_ptr->resp_ptr->cntrl = 0;
  821.             ret_value = FDL_OK;
  822.         }//else of if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE) ...
  823.     }//if(fdl_h_ptr->state == ENABLED )
  824.     else
  825.     {
  826.         ret_value = FDL_IUSE;
  827.     }//else of if(fdl_h_ptr->state == ENABLED )
  828.     DP_UNLOCK_IND(dev_num);
  829.     if( ret_value != FDL_OPEN_ERR )
  830.     {
  831.         switch( fdl_h_ptr->sap_type&0xff )//2009.11.7
  832.         {
  833.             #ifdef DP_MSAC_C2
  834.                 case FDL_MSAC_C2_SAP:
  835.                 {
  836.                     msac_c2_input_queue(dev_num,NULL_PTR, ret_value, fdl_h_ptr->sap_nr, MSAC_C2_IND_DISABLE_DONE );
  837.                     break;
  838.                 }//case FDL_MSAC_C2_SAP:
  839.             #endif//#ifdef DP_MSAC_C2
  840.             #ifdef DP_MSAC_C1
  841.                 case FDL_MSAC_C1_SAP:
  842.                 {
  843.                     msac_c1_ind_disable_done(dev_num,fdl_h_ptr->sap_nr, ret_value);
  844.                     break;
  845.                 }//case FDL_MSAC_C1_SAP:
  846.             #endif//#ifdef DP_MSAC_C1
  847.                 default:
  848.                 {
  849.                     break;
  850.                 }//default:
  851.         }//switch( fdl_h_ptr->sap_type )
  852.     }//if( ret_value != FDL_OPEN_ERR )
  853. }//void fdl_perform_ind_disable(UBYTE dev_num, FDL_SAP_HEADER_PTR fdl_h_ptr )
  854. /*---------------------------------------------------------------------------*/
  855. /*                                                                           */
  856. /* void fdl_perform_ind_disable_SAP50(UBYTE dev_num,FDL_SAP_HEADER_PTR    fdl_h_ptr)       */
  857. /*                                                                           */
  858. /*   function: The function resets the sap 50 to its initial value, unlocks  */
  859. /*             interrupt and if due: performs the user-callback-function     */
  860. /*                                                                           */
  861. /*---------------------------------------------------------------------------*/
  862. SECTION_DEF_CommuCode void fdl_perform_ind_disable_SAP50(UBYTE dev_num, FDL_SAP_HEADER_PTR fdl_h_ptr )
  863. {
  864. UBYTE  ret_value = FDL_OPEN_ERR; //preset with non-generated return-value
  865.     fdl_h_ptr->state = DISABLED;
  866.     fdl_h_ptr->sap_ptr->ind_ptr[0] = 0;
  867.     if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE)
  868.         || (fdl_h_ptr->ind_ptr[1]->cntrl & PCNTRL_INUSE)
  869.         || (fdl_h_ptr->resp_ptr->cntrl   & PCNTRL_INUSE)
  870.       )
  871.     {
  872.         fdl_h_ptr->state = DIS_RUNNING;
  873.         fdl[dev_num].reset_ctr++;
  874.     }//if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE) ...
  875.     else
  876.     {
  877.         //perform sap-reset
  878.         //set indication-buffer to vpc3
  879.         copy_sap_parameter__(fdl_h_ptr->sap_ptr, & fdl_h_ptr->sap);
  880.         fdl_h_ptr->ind_ptr[0]->cntrl = 0;
  881.         fdl_h_ptr->ind_ptr[1]->cntrl = 0;
  882.         fdl_h_ptr->resp_ptr->cntrl = 0;
  883.         ret_value = FDL_OK;
  884.     }//else of if(    (fdl_h_ptr->ind_ptr[0]->cntrl & PCNTRL_INUSE) ...
  885.     DP_UNLOCK_IND(dev_num);
  886. }//void fdl_perform_ind_disable_SAP50(UBYTE dev_num, FDL_SAP_HEADER_PTR fdl_h_ptr )
  887. /*---------------------------------------------------------------------------*/
  888. /*                                                                           */
  889. /*   void fdl_open_channel (UBYTE dev_num)                                            */
  890. /*                                                                           */
  891. /*   function: open channel                                                  */
  892. /*                                                                           */
  893. /*---------------------------------------------------------------------------*/
  894. #ifdef DP_MSAC_C2
  895. SECTION_DEF_CommuCode UBYTE fdl_open_channel(UBYTE dev_num)
  896. {
  897. UBYTE  ret_value;
  898.     DP_LOCK_IND(dev_num);
  899.     if( fdl[dev_num].dpv2_open == FALSE )
  900.     {
  901.         fdl[dev_num].dpv2_open = TRUE;
  902.         fdl[dev_num].rm_state = RM_LOADABLE;
  903.         fdl_set_sa_ssap (dev_num,49, SA_ALL, SAP_ALL);
  904.         ret_value = FDL_OK;
  905.     }//if( fdl[dev_num].dpv2_open == FALSE )
  906.     else
  907.     {
  908.         ret_value = FDL_OPEN_ERR;
  909.     }//else of if( fdl[dev_num].dpv2_open == FALSE )
  910.     DP_UNLOCK_IND(dev_num);
  911.     return ret_value;
  912. }//UBYTE fdl_open_channel(UBYTE dev_num)
  913. #endif //#ifdef DP_MSAC_C2
  914. /*---------------------------------------------------------------------------*/
  915. /*                                                                           */
  916. /*   void fdl_close_channel (UBYTE dev_num,UBYTE chan_ident)                               */
  917. /*                                                                           */
  918. /*   function: close channel                                                 */
  919. /*                                                                           */
  920. /*---------------------------------------------------------------------------*/
  921. #ifdef DP_MSAC_C2
  922. SECTION_DEF_CommuCode void fdl_close_channel(UBYTE dev_num, UBYTE chan_ident )
  923. {
  924. FDL_SAP_HEADER_PTR  fdl_h_ptr;
  925. UBYTE               ret_value;
  926.     DP_LOCK_IND(dev_num);
  927.     switch( chan_ident )
  928.     {
  929.         case FDL_MSAC_C2_SAP:
  930.         {
  931.             if( fdl[dev_num].dpv2_open != FALSE )
  932.             {
  933.                 // force rs but do not touch the pointers yet
  934.                 fdl[dev_num].sap_header[0].sap_ptr->req_sa = (UBYTE) VPC3_GET_STATION_ADDRESS(dev_num);
  935.                 fdl[dev_num].dpv2_open = FALSE;
  936.                 fdl[dev_num].rm_state = RM_LOCKED;
  937.                 // set all msac_c2-saps DISABLED
  938.                 fdl_h_ptr = &fdl[dev_num].sap_header[1]; // MSAC_C2-saps start at index #1
  939.                 ret_value = DP_C2_NUM_SAPS;
  940.                 while( ret_value-- )
  941.                 {
  942.                     switch( fdl_h_ptr->state )
  943.                     {
  944.                         case  ENABLED:
  945.                         case  DIS_RUNNING:
  946.                         {
  947.                             //let old connections run
  948.                             break;
  949.                         }//case  ENABLED:
  950.                         case  DISABLED:
  951.                         {
  952.                             break;
  953.                         }//case  DISABLED:
  954.                         case  DISABLED_FOR_RM:
  955.                         case  DISABLED_IN_RM:
  956.                         {
  957.                             fdl_h_ptr->state = DISABLED;
  958.                             break;
  959.                         }//case  DISABLED_FOR_RM:
  960.                         default:
  961.                         {
  962.                             break;
  963.                         }//default:
  964.                     }//switch( fdl_h_ptr->state )
  965.                 }//while( ret_value-- )
  966.                 fdl_perform_ind_disable(dev_num, &fdl[dev_num].sap_header[0] );
  967.             }//if( fdl[dev_num].dpv2_open != FALSE )
  968.             else
  969.             {
  970.                 DP_UNLOCK_IND(dev_num);
  971.             }
  972.             break;
  973.         }//case FDL_MSAC_C2_SAP:
  974.         default:
  975.         {
  976.             break;
  977.         }//default
  978.     }//switch( chan_ident )
  979. }//void fdl_close_channel(UBYTE dev_num, UBYTE chan_ident )
  980. #endif //#ifdef DP_MSAC_C2
  981. #endif//#if defined (DP_FDL) // compile only, if fdl-application is selected
  982. /*****************************************************************************/
  983. /*  Copyright (C) profichip GmbH 2004. Confidential.                         */
  984. /*****************************************************************************/