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

C/C++

  1. /***********************  Filename: dp_if.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+ (dp-protocol)        */
  15. /*                                                                           */
  16. /* ------------------------------------------------------------------------- */
  17. /* history                                                                   */
  18. /* ========================================================================= */
  19. /* 08.09.2005 [V5.00]  Urversion                                             */
  20. /* 22.10.2005 [V5.01]  BugFix:                                               */
  21. /*                     Dp_cfg.h:                                             */
  22. /*                     Missing bracket:                                      */
  23. /*                     #define ASIC_USER_RAM (ASIC_RAM_LENGTH -              */
  24. /*                                              DP_ORG_LENGTH - SAP_LENGTH)  */
  25. /*                                                                           */
  26. /* ------------------------------------------------------------------------- */
  27. /*                                                                           */
  28. /*                                                                           */
  29. /* Technical support:       P. Fredehorst                                    */
  30. /*                          Tel. : ++49-9132/744-214                         */
  31. /*                          Fax. :              -204                         */
  32. /*                          eMail: pfredehorst@profichip.com                 */
  33. /*                                                                           */
  34. /*****************************************************************************/
  35. /*****************************************************************************/
  36. /* contents:
  37.   - function prototypes
  38.   - data structures
  39.   - internal functions
  40. */
  41. /*****************************************************************************/
  42. /* include hierarchy */
  43. #include "..dp_incplatform.h"
  44. #include "..dp_incdp_inc.h"
  45. //#include "E5_Inc.h"
  46. //#include <cdefBF536.h>
  47. /*---------------------------------------------------------------------------*/
  48. /* version                                                                   */
  49. /*---------------------------------------------------------------------------*/
  50. #define DP_VERSION_MAIN_INTERFACE   ((UBYTE)0x05)
  51. #define DP_VERSION_FUNCTION         ((UBYTE)0x00)
  52. #define DP_VERSION_BUGFIX           ((UBYTE)0x01)
  53. /*---------------------------------------------------------------------------*/
  54. /* function prototypes                                                       */
  55. /*---------------------------------------------------------------------------*/
  56. DP_ERROR_CODE   vpc3_set_constants  (UBYTE dev_num, UBYTE slave_address );
  57. DP_ERROR_CODE   ssc_init            (UBYTE dev_num);
  58. DP_ERROR_CODE   vpc3_buf_init       (UBYTE dev_num);
  59. UWORD           assign_aux_buf      (UBYTE dev_num, UWORD PTR_ATTR *lens, UBYTE count, UBYTE PTR_ATTR *assign, UWORD PTR_ATTR *aux_len );
  60. /*---------------------------------------------------------------------------*/
  61. /* global user data definitions                                              */
  62. /*---------------------------------------------------------------------------*/
  63. SECTION_DEF_CommuData VPC3_STRUC          VPC3_PTR    p_Vpc3[MAX_DEV_NUM];     // pointer to Vpc3 structure
  64. SECTION_DEF_CommuData VPC3_SYSTEM_STRUC               dp_sys[MAX_DEV_NUM];     // global system structure
  65. #ifdef DP_DEBUG_ENABLE
  66. SECTION_DEF_CommuData     sDP_DEBUG_BUFFER_ITEM   asDebugBuffer[MAX_DEV_NUM][ MAX_NR_OF_DEBUG ];
  67. SECTION_DEF_CommuData     UBYTE                   bDebugBufferIndex[MAX_DEV_NUM];
  68. SECTION_DEF_CommuData     UBYTE                   bDebugBufferOverlapped[MAX_DEV_NUM];
  69. #endif//#ifdef DP_DEBUG_ENABLE
  70. /*---------------------------------------------------------------------------*/
  71. /* defines                                                                   */
  72. /*---------------------------------------------------------------------------*/
  73. /* Literals */
  74. /* Lage der Bits der AUX-Puffer-Zuordnung */
  75. #define RBL_PRM                 0
  76. #define RBL_CFG                 1
  77. #define RBL_SSA                 2
  78. /*---------------------------------------------------------------------------*/
  79. /* function: DP_GetVersion                                                   */
  80. /*---------------------------------------------------------------------------*/
  81. SECTION_DEF_CommuCode void DP_GetVersion(UBYTE dev_num, psDP_VERSION pVersion )
  82. {
  83.     pVersion->wComponentsInstalled =    0x0000
  84.                             #ifdef DP_MSAC_C1
  85.                                        | DP_COMP_INSTALLED_MSAC1_IFA
  86.                                 #ifdef DP_ALARM
  87.                                        | DP_COMP_INSTALLED_SUB_AL
  88.                                      #ifdef DP_ALARM_OVER_SAP50
  89.                                        | DP_COMP_INSTALLED_SUB_AL_50
  90.                                      #endif//DP_ALARM_OVER_SAP50
  91.                                 #endif//#ifdef DP_ALARM
  92.                                 #ifdef DPV1_IM_SUPP
  93.                                        | DP_COMP_INSTALLED_IM
  94.                                 #endif//#ifdef DPV1_IM_SUPP
  95.                             #endif//#ifdef DP_MSAC_C1
  96.                             #ifdef DP_MSAC_C2
  97.                                        | DP_COMP_INSTALLED_MSAC2_IFA
  98.                                 #ifdef DPV1_IM_SUPP
  99.                                        | DP_COMP_INSTALLED_IM
  100.                                 #endif//#ifdef DPV1_IM_SUPP
  101.                             #endif//#ifdef DP_MSAC_C2
  102.                                         ;
  103.     switch(VPC3_GET_ASIC_TYPE(dev_num) )
  104.     {
  105.         case AT_VPC3B:
  106.         {
  107.             pVersion->wComponentsInstalled |= DP_COMP_INSTALLED_VPC3_B ;
  108.             break;
  109.         }
  110.         case AT_VPC3C:
  111.         {
  112.             pVersion->wComponentsInstalled |= DP_COMP_INSTALLED_VPC3_C ;
  113.             break;
  114.         }
  115.         case AT_MPI12X:
  116.         {
  117.             pVersion->wComponentsInstalled |= DP_COMP_INSTALLED_VPC3_D ;
  118.             break;
  119.         }
  120.         default:
  121.         {
  122.             //do nothing
  123.         }
  124.     }//switch(VPC3_GET_ASIC_TYPE(dev_num)
  125.     pVersion->bMainInterface = DP_VERSION_MAIN_INTERFACE;
  126.     pVersion->bFunction      = DP_VERSION_FUNCTION;
  127.     pVersion->bBugfix        = DP_VERSION_BUGFIX;
  128. }//void DP_GetVersion(UBYTE dev_num, psDP_VERSION pVersion )
  129. /*---------------------------------------------------------------------------*/
  130. /* function: DP_WriteDebugBuffer                                             */
  131. /*---------------------------------------------------------------------------*/
  132. #ifdef DP_DEBUG_ENABLE
  133. SECTION_DEF_CommuCode void DP_WriteDebugBuffer(UBYTE dev_num, DEBUG_CODE bDebugCode, UBYTE bDetail1, UBYTE bDetail2 )
  134. {
  135.     asDebugBuffer[dev_num][ bDebugBufferIndex[dev_num] ].bDebugCode = bDebugCode;
  136.     asDebugBuffer[dev_num][ bDebugBufferIndex[dev_num] ].bDetail1   = bDetail1;
  137.     asDebugBuffer[dev_num][ bDebugBufferIndex[dev_num] ].bDetail2   = bDetail2;
  138.     if( bDebugBufferIndex[dev_num] == (MAX_NR_OF_DEBUG-1) )
  139.     {
  140.         bDebugBufferOverlapped[dev_num] = TRUE;
  141.         bDebugBufferIndex[dev_num] = 0;
  142.     }
  143.     else
  144.     {
  145.         bDebugBufferIndex[dev_num]++;
  146.     }
  147. }//void DP_WriteDebugBuffer(UBYTE dev_num, DEBUG_CODE debug_code, UBYTE detail_1, UBYTE detail_2 )
  148. #endif//#ifdef DP_DEBUG_ENABLE
  149. /*---------------------------------------------------------------------------*/
  150. /* function: DP_ClearDebugBuffer                                             */
  151. /*---------------------------------------------------------------------------*/
  152. #ifdef DP_DEBUG_ENABLE
  153. SECTION_DEF_CommuCode void DP_ClearDebugBuffer(dev_num)
  154. {
  155. UWORD i;
  156.     bDebugBufferOverlapped[dev_num] = FALSE;
  157.     bDebugBufferIndex[dev_num]      = 0x00;
  158.     for(i = 0; i < MAX_NR_OF_DEBUG; i++ )
  159.     {
  160.         asDebugBuffer[dev_num][i].bDebugCode = 0x00;
  161.         asDebugBuffer[dev_num][i].bDetail1   = 0x00;
  162.         asDebugBuffer[dev_num][i].bDetail2   = 0x00;
  163.     }//for( i = 0; i < MAX_NR_OF_DEBUG; i++ )
  164. }//void DP_ClearDebugBuffer(dev_num)
  165. #endif//#ifdef DP_DEBUG_ENABLE
  166. /*--------------------------------------------------------------------------*/
  167. /*vpc3 reset function                                                       -*/
  168. /*--------------------------------------------------------------------------*/
  169. extern void ResetVPC3_0(void);
  170. SECTION_DEF_CommuCode void ResetVPC3(UBYTE dev_num)
  171. {
  172. if(dev_num == NET_A)
  173. {
  174. ResetVPC3_0();
  175. }
  176. else if(dev_num == NET_B)
  177. {
  178. }
  179. }
  180. /*---------------------------------------------------------------------------*/
  181. /*                                                                           */
  182. /*  UBYTE vpc3_initialization ()                                             */
  183. /*                                                                           */
  184. /*   function:     initializing the vpc3+ controller                         */
  185. /*                                                                           */
  186. /*   parameter:    VPC3_INIT, VPC3_DP_INIT                                   */
  187. /*   return value: errorcode (0 = no error)                                  */
  188. /*                                                                           */
  189. /*---------------------------------------------------------------------------*/
  190. SECTION_DEF_CommuCode DP_ERROR_CODE vpc3_initialization(UBYTE dev_num, UBYTE slave_address, CFG_STRUCT cfg )
  191. {
  192. DP_ERROR_CODE       error;
  193. BLACKFIN_WORDPTR  vpc3_ptr;       // pointer to vpc3 memory area
  194. unsigned char       j;
  195. UWORD               i;
  196. int nBlackfinLoop;
  197. BLACKFINDATATYPE* pBlackfinAddr;
  198.     /*-----------------------------------------------------------------------*/
  199.     /* initialize global system structure                                    */
  200.     /*-----------------------------------------------------------------------*/
  201.     memset(&dp_sys[dev_num], 0, sizeof(dp_sys[dev_num]));
  202.     #ifdef DP_DEBUG_ENABLE
  203.         DP_ClearDebugBuffer(dev_num);
  204.     #endif//#ifdef DP_DEBUG_ENABLE
  205.     /*-----------------------------------------------------------------------*/
  206.     /* init vpc3 data                                                        */
  207.     /*-----------------------------------------------------------------------*/
  208.     p_Vpc3[dev_num] = (VPC3_STRUC VPC3_PTR)VPC3_ASIC_ADDRESS(dev_num);//设置vpc的基本地址
  209.     //VPC3_CLEAR_RESET__;
  210.     //NOP__();
  211.     #ifdef MPI12x
  212.         p_Vpc3[dev_num]->int_req1 = 0x03;
  213.         NOP__();
  214.         NOP__();
  215.         NOP__();
  216.         NOP__();
  217.     #endif//#ifdef MPI12x
  218.     //neccessary, if 4Kbyte mode enabled
  219.     p_Vpc3[dev_num]->ctrl_reg.wr.mode_reg2 = INIT_VPC3_MODE_REG_2;
  220.     
  221.     
  222. //    DELAY_TICK(1);
  223.     
  224.     /*-----------------------------------------------------------------------*/
  225.     /* test and clear vpc3 ram                                               */
  226.     /*-----------------------------------------------------------------------*/
  227.     error = DP_OK;
  228.     j = 0;
  229.     vpc3_ptr = &p_Vpc3[dev_num]->slave_addr;
  230.     for(i = 0x16; i < ASIC_RAM_LENGTH;)
  231.     {
  232.         *((BLACKFINDATATYPE*)vpc3_ptr)=j;
  233.         i++;
  234.         j++;
  235.         vpc3_ptr+=1;
  236.     }
  237.     j = 0;
  238.     vpc3_ptr = &p_Vpc3[dev_num]->slave_addr;
  239.     for(i = 0x16; i < ASIC_RAM_LENGTH;)
  240.     {
  241.         if( (*((BLACKFINDATATYPE*)vpc3_ptr)&0xFF)  != (j&0xFF) )
  242.         {
  243.           error = DP_VPC3_ERROR; // ERROR
  244.           break;
  245.         }
  246.         i++;
  247.         j++;
  248.         vpc3_ptr+=1;
  249.     }
  250.     if(DP_OK == error)
  251.     {
  252.         //clear VPC3
  253.         memset(&p_Vpc3[dev_num]->slave_addr, 0, (ASIC_RAM_LENGTH-0x16)*BLACKFIN_MULTIPLER );
  254.         /*-------------------------------------------------------------------*/
  255.         /* check VPC3 is in OFFLINE                                          */
  256.         /*-------------------------------------------------------------------*/
  257.         if( !VPC3_GET_OFF_PASS(dev_num) )
  258.         {
  259.             /*---------------------------------------------------------------*/
  260.             /* set constant values                                           */
  261.             /*---------------------------------------------------------------*/
  262.             error = vpc3_set_constants(dev_num, slave_address );
  263.             if(DP_OK == error)
  264.             {
  265.                 /*-----------------------------------------------------------*/
  266.                 /* calculate length of input and output data using cfg-data  */
  267.                 /*-----------------------------------------------------------*/
  268.                 error = vpc3_calculate_inp_outp_len (dev_num, &cfg.cfg_data[0], cfg.length);
  269.                 if( DP_OK == error )
  270.                 {
  271.                     /*-------------------------------------------------------*/
  272.                     /* initialize buffer structure                           */
  273.                     /*-------------------------------------------------------*/
  274.                     error = vpc3_buf_init(dev_num);
  275.                     if (DP_OK == error)
  276.                     {
  277.                         /*---------------------------------------------------*/
  278.                         /* set real configuration data                       */
  279.                         /*---------------------------------------------------*/
  280.                         VPC3_SET_READ_CFG_LEN(dev_num,cfg.length);      // set configuration length
  281.                         //memcpy(VPC3_GET_READ_CFG_BUF_PTR(dev_num), &cfg.cfg_data[0], cfg.length );
  282. pBlackfinAddr = (BLACKFINDATATYPE*)VPC3_GET_READ_CFG_BUF_PTR(dev_num);
  283. for (nBlackfinLoop=0; nBlackfinLoop<cfg.length; nBlackfinLoop++)
  284. {
  285. pBlackfinAddr[nBlackfinLoop] = cfg.cfg_data[nBlackfinLoop];
  286. }
  287.                         // set I/O length
  288.                         vpc3_set_io_data_len(dev_num);
  289.                         /*---------------------------------------------------*/
  290.                         /* initialize subscriber                             */
  291.                         /*---------------------------------------------------*/
  292.                         #ifdef DP_SUBSCRIBER
  293.                             error = ssc_init(dev_num);
  294.                         #endif//#ifdef DP_SUBSCRIBER
  295.                         /*---------------------------------------------------*/
  296.                         /* initialize fdl_interface                          */
  297.                         /*---------------------------------------------------*/
  298.                         #ifdef DP_FDL
  299.                             if(DP_OK == error)
  300.                             {
  301.                                 error = fdl_init(dev_num);
  302.                                 if(DP_OK == error)
  303.                                 {
  304.                                     /*-----------------------------------------------*/
  305.                                     /* initialize MSAC_C1                            */
  306.                                     /*-----------------------------------------------*/
  307.                                     #ifdef DP_MSAC_C1
  308.                                         error = msac_c1_init(dev_num);
  309.                                     #endif//#ifdef DP_MSAC_C1
  310.                                     #ifdef DP_MSAC_C2
  311.                                         if(DP_OK == error)
  312.                                         {
  313.                                             /*-------------------------------------------*/
  314.                                             /* initialize MSAC_C2                        */
  315.                                             /*-------------------------------------------*/
  316.                                             error = msac_c2_init(dev_num);
  317.                                         }
  318.                                     #endif//#ifdef DP_MSAC_C2
  319.                                 }
  320.                             }
  321.                         #endif //#ifdef DP_FDL
  322.                     }//if(DP_OK == error)
  323.                 }//if(DP_OK == error)
  324.             }//if(DP_OK == error)
  325.         }//if( !VPC3_GET_OFF_PASS(dev_num) )
  326.         else
  327.         {
  328.             error = DP_NOT_OFFLINE_ERROR;
  329.         }
  330.     }//if(DP_OK == error)
  331.     return error;
  332. }
  333. /*---------------------------------------------------------------------------*/
  334. /* function: START_VPC3                                                      */
  335. /*---------------------------------------------------------------------------*/
  336. SECTION_DEF_CommuCode void START_VPC3(UBYTE dev_num)
  337. {
  338.     /*-----------------------------------------------------------------------*/
  339.     /* start vpc3                                                            */
  340.     /*-----------------------------------------------------------------------*/
  341.     START_VPC3__(dev_num);
  342.     #ifdef DP_MSAC_C2
  343.         msac_c2_open_channel(dev_num);
  344.     #endif /* DP_MSAC_C2 */
  345.     // Fetch the first diagnosis buffer
  346.     dp_sys[dev_num].diag_buf_ptr.byte_ptr = vpc3_get_diagbufptr(dev_num);
  347. }//void START_VPC3(UBYTE dev_num)
  348. /*---------------------------------------------------------------------------*/
  349. /*                                                                           */
  350. /*   function:     initializing constant vpc3 values                         */
  351. /*                                                                           */
  352. /*---------------------------------------------------------------------------*/
  353. SECTION_DEF_CommuCode DP_ERROR_CODE vpc3_set_constants(UBYTE dev_num, UBYTE slave_address )
  354. {
  355. DP_ERROR_CODE error;
  356.     error = DP_OK;
  357.     dp_sys[dev_num].din_bufsize              = DIN_BUFSIZE;
  358.     dp_sys[dev_num].dout_bufsize             = DOUT_BUFSIZE;
  359.     dp_sys[dev_num].prm_bufsize              = PRM_BUFSIZE;
  360.     dp_sys[dev_num].diag_bufsize             = DIAG_BUFSIZE;
  361.     dp_sys[dev_num].cfg_bufsize              = CFG_BUFSIZE;
  362.     dp_sys[dev_num].ssa_bufsize              = SSA_BUFSIZE;
  363.     #ifdef DP_FDL
  364.         #ifdef DP_MSAC_C2
  365.             dp_sys[dev_num].c2_num_saps      = C2_NUM_SAPS;
  366.             dp_sys[dev_num].c2_len           = DP_C2_LEN;
  367.         #endif//#ifdef DP_MSAC_C2
  368.     #endif//#ifdef DP_FDL
  369.     /*-----------------------------------------------------------------------*/
  370.     /* initialize  control logic                                             */
  371.     /*-----------------------------------------------------------------------*/
  372.     p_Vpc3[dev_num]->int_req1                = 0x00;
  373.     p_Vpc3[dev_num]->int_req2                = 0x00;
  374.     p_Vpc3[dev_num]->isreg.wr.int_ack1       = 0xFF;
  375.     p_Vpc3[dev_num]->isreg.wr.int_ack2       = 0xFF;
  376.     p_Vpc3[dev_num]->ctrl_reg.wr.mode_reg1_r = 0xFF;      // reset mode register 1
  377.    
  378. p_Vpc3[dev_num]->ctrl_reg.wr.reserved_12 = 0;  // wusenlin
  379.     /*-----------------------------------------------------------------------*/
  380.     /* set modes of vpc3                                                     */
  381.     /*-----------------------------------------------------------------------*/
  382.     p_Vpc3[dev_num]->mode_reg0_H = INIT_VPC3_MODE_REG_H;
  383.     p_Vpc3[dev_num]->mode_reg0_L = INIT_VPC3_MODE_REG_L;
  384.     p_Vpc3[dev_num]->ctrl_reg.wr.mode_reg2 = INIT_VPC3_MODE_REG_2;
  385.     /*-----------------------------------------------------------------------*/
  386.     /* set interrupt triggers                                                */
  387.     /*-----------------------------------------------------------------------*/
  388.     p_Vpc3[dev_num]->isreg.wr.int_mask_H = (UBYTE) ~(INIT_VPC3_IND_H);
  389.     p_Vpc3[dev_num]->isreg.wr.int_mask_L = (UBYTE) ~(INIT_VPC3_IND_L);
  390.     dp_sys[dev_num].ind_high = (UBYTE) ~(INIT_VPC3_IND_H);
  391.     dp_sys[dev_num].ind_low  = (UBYTE) ~(INIT_VPC3_IND_L);
  392.     /*-----------------------------------------------------------------------*/
  393.     /* set time-variables                                                    */
  394.     /*-----------------------------------------------------------------------*/
  395.     p_Vpc3[dev_num]->ctrl_reg.wr.wd_baud_ctrl = 0x10;    // WD Timeout
  396.     p_Vpc3[dev_num]->ctrl_reg.wr.mintsdr      = 0x0B;    // Min Tsdr 11 BIT (11Bit .. 255Bit)
  397.     /*-----------------------------------------------------------------------*/
  398.     /* set variables for synch-mode                                          */
  399.     /*-----------------------------------------------------------------------*/
  400.     #ifdef ISOCHRON_MODE
  401.         p_Vpc3[dev_num]->ctrl_reg.wr.sync_pw_reg = SYNCH_PULSEWIDTH;   // sync pulse width register
  402.         p_Vpc3[dev_num]->ctrl_reg.wr.sync_group = 0x80;
  403.         p_Vpc3[dev_num]->ctrl_reg.wr.sync_mode  = 0x00;
  404.     #endif//#ifdef ISOCHRON_MODE
  405.     /*-----------------------------------------------------------------------*/
  406.     /* set user watchdog (dataexchange telegram counter)                     */
  407.     /*-----------------------------------------------------------------------*/
  408.     p_Vpc3[dev_num]->user_wd_value[1] = (UBYTE)(USER_WD >> 8);
  409.     p_Vpc3[dev_num]->user_wd_value[0] = (UBYTE)(USER_WD);
  410.     /*-----------------------------------------------------------------------*/
  411.     /* set pointer to FF                                                     */
  412.     /*-----------------------------------------------------------------------*/
  413.     p_Vpc3[dev_num]->fdl_sap_list_ptr = VPC3_SAP_CTRL_LIST_START(dev_num);
  414.     p_Vpc3[dev_num]->sap_ctrl_list[0] = 0xFF;
  415.     /*-----------------------------------------------------------------------*/
  416.     /* ssa support                                                           */
  417.     /*-----------------------------------------------------------------------*/
  418.     p_Vpc3[dev_num]->real_no_add_change = (dp_sys[dev_num].ssa_bufsize == 0 ) ? 0xFF : 0x00;
  419.     /*-----------------------------------------------------------------------*/
  420.     /* set profibus ident number                                             */
  421.     /*-----------------------------------------------------------------------*/
  422.     p_Vpc3[dev_num]->ident_high = (UBYTE)(IDENT_NR >> 8);
  423.     p_Vpc3[dev_num]->ident_low  = (UBYTE)(IDENT_NR);
  424.     /*-----------------------------------------------------------------------*/
  425.     /* set and check slave address                                           */
  426.     /*-----------------------------------------------------------------------*/
  427.      if( slave_address < 126 && slave_address != 0 )
  428.     {
  429.         p_Vpc3[dev_num]->slave_addr = slave_address;
  430.     }
  431.     else
  432.     {
  433.         error = DP_ADDRESS_ERROR;
  434.     }
  435.     return error;
  436. }
  437. /*---------------------------------------------------------------------------*/
  438. /*                                                                           */
  439. /*   function:     initializing subscriber                                   */
  440. /*                                                                           */
  441. /*---------------------------------------------------------------------------*/
  442. #ifdef DP_SUBSCRIBER
  443. SECTION_DEF_CommuCode DP_ERROR_CODE ssc_init(UBYTE dev_num)
  444. {
  445. DP_ERROR_CODE       error;
  446. BLACKFIN_WORDPTR  vpc3_ptr;           // pointer to VPC3, 礐ontroller formatted
  447. UBYTE               vpc3_seg_adr;       // segment address in VPC3-ASIC
  448.     error = DP_OK;
  449.     /*-----------------------------------------------------------------------*/
  450.     /* check buffer length                                                   */
  451.     /*-----------------------------------------------------------------------*/
  452.     if (DP_MAX_DATA_PER_LINK > 244)
  453.     {
  454.         error = SSC_MAX_DATA_PER_LINK;
  455.     }
  456.     else
  457.     {
  458.         // pointer mc formatted
  459.         vpc3_ptr = &p_Vpc3[dev_num]->dpbuffer[dp_sys[dev_num].vpc3_used_dp_buf_mem];
  460.         // pointer vpc3 formatted
  461.         vpc3_seg_adr = (UBYTE)(((VPC3_ADR)vpc3_ptr-(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num)) >> BLACKFIN_SEG_MULDIV );
  462.         // length dxb_out
  463.         p_Vpc3[dev_num]->len_dxb_out_buf = (((DP_MAX_DATA_PER_LINK+2)+SEG_OFFSET) & SEG_ADDBYTE);
  464.         dp_sys[dev_num].vpc3_used_dp_buf_mem += (3* BFWORD2BYTE(p_Vpc3[dev_num]->len_dxb_out_buf) );
  465.         // length link status
  466.         p_Vpc3[dev_num]->len_dxb_link_status_buf = ((((DP_MAX_LINK_SUPPORTED*2)+4)+SEG_OFFSET) & SEG_ADDBYTE);
  467.         dp_sys[dev_num].vpc3_used_dp_buf_mem += p_Vpc3[dev_num]->len_dxb_link_status_buf;
  468.         // length link table
  469.         p_Vpc3[dev_num]->len_dxb_link_table_buf = (((DP_MAX_LINK_SUPPORTED*4)+SEG_OFFSET) & SEG_ADDBYTE);
  470.         dp_sys[dev_num].vpc3_used_dp_buf_mem += p_Vpc3[dev_num]->len_dxb_link_table_buf;
  471.         /*-------------------------------------------------------------------*/
  472.         /* check memory consumption                                          */
  473.         /*-------------------------------------------------------------------*/
  474.         if( dp_sys[dev_num].vpc3_used_dp_buf_mem > sizeof (p_Vpc3[dev_num]->dpbuffer)/BLACKFIN_MULTIPLER )
  475.         {
  476.             // Error: user needs too much memory
  477.             dp_sys[dev_num].vpc3_used_dp_buf_mem = 0;
  478.             error = DP_LESS_MEM_ERROR;
  479.         }
  480.         else
  481.         {
  482.             /*---------------------------------------------------------------*/
  483.             /* set buffer pointer                                            */
  484.             /*---------------------------------------------------------------*/
  485.             p_Vpc3[dev_num]->dxb_link_table_buf_ptr  = vpc3_seg_adr;
  486.             p_Vpc3[dev_num]->dxb_link_status_buf_ptr = p_Vpc3[dev_num]->dxb_link_table_buf_ptr  + (p_Vpc3[dev_num]->len_dxb_link_table_buf >> SEG_MULDIV);
  487.             p_Vpc3[dev_num]->dxb_out_buf_ptr1        = p_Vpc3[dev_num]->dxb_link_status_buf_ptr + (p_Vpc3[dev_num]->len_dxb_link_status_buf >> SEG_MULDIV);
  488.             p_Vpc3[dev_num]->dxb_out_buf_ptr2        = p_Vpc3[dev_num]->dxb_out_buf_ptr1        + (p_Vpc3[dev_num]->len_dxb_out_buf >> SEG_MULDIV);
  489.             p_Vpc3[dev_num]->dxb_out_buf_ptr3        = p_Vpc3[dev_num]->dxb_out_buf_ptr2        + (p_Vpc3[dev_num]->len_dxb_out_buf >> SEG_MULDIV);
  490.         }
  491.     }
  492.     return error;
  493. }
  494. #endif//#ifdef DP_SUBSCRIBER
  495. /*---------------------------------------------------------------------------*/
  496. /*                                                                           */
  497. /*  DP_ERROR_CODE vpc3_calculate_inp_outp_len (UBYTE dev_num,                */
  498. /*                                             VPC3_UNSIGNED8_PTR cfg_ptr,   */
  499. /*                                             UBYTE              cfg_len )  */
  500. /*                                                                           */
  501. /*   function:      Calculation of Inputs/Outputs.                           */
  502. /*                                                                           */
  503. /*   parameter:     cfg_ptr:  Pointer to configuration buffer.               */
  504. /*                  cfg_len:  Length of configuration data.                  */
  505. /*   return value:  -                                                        */
  506. /*                                                                           */
  507. /*---------------------------------------------------------------------------*/
  508. SECTION_DEF_CommuCode DP_ERROR_CODE vpc3_calculate_inp_outp_len (UBYTE dev_num,VPC3_UNSIGNED8_PTR cfg_ptr, UBYTE cfg_len)
  509. {
  510. DP_ERROR_CODE error;
  511. UBYTE         specific_data_length;
  512. UBYTE         temp_outp_data_len;
  513. UBYTE         temp_inp_data_len;
  514. UBYTE         length;
  515. UBYTE         count;
  516.     error = DP_OK;
  517.     temp_outp_data_len = 0;
  518.     temp_inp_data_len  = 0;
  519.     if( (cfg_len > 0)  &&  (cfg_len <= dp_sys[dev_num].cfg_bufsize) )
  520.     {
  521.         for( ; cfg_len > 0; cfg_len -= count)
  522.         {
  523.             count = 0;
  524.             if (*cfg_ptr & VPC3_CFG_IS_BYTE_FORMAT)
  525.             {
  526.                 // general identifier format
  527.                 count++;
  528.                 // cfg_ptr points to "Configurationbyte", CFG_BF means "CFG_IS_BYTE_FORMAT"
  529.                 length = (UBYTE)( (*cfg_ptr & VPC3_CFG_BF_LENGTH) + 1 );
  530.                 if(*cfg_ptr & VPC3_CFG_LENGTH_IS_WORD_FORMAT)
  531.                 {
  532.                     length *= 2;
  533.                 }
  534.                 if(*cfg_ptr & VPC3_CFG_BF_OUTP_EXIST)
  535.                 {
  536.                     temp_outp_data_len += length;
  537.                 }
  538.                 if(*cfg_ptr & VPC3_CFG_BF_INP_EXIST)
  539.                 {
  540.                     temp_inp_data_len += length;
  541.                 }
  542.                 cfg_ptr++;
  543.             }
  544.             else
  545.             {
  546.                 // cfg_ptr points to the headerbyte of "special identifier format
  547.                 // CFG_SF means "CFG_IS_SPECIAL_FORMAT"
  548.                 if(*cfg_ptr & VPC3_CFG_SF_OUTP_EXIST)
  549.                 {
  550.                     count++;    // next UBYTE contains the length of outp_data
  551.                     length = (UBYTE)((*(cfg_ptr + count) & VPC3_CFG_SF_LENGTH) +1);
  552.                     if(*(cfg_ptr + count) & VPC3_CFG_LENGTH_IS_WORD_FORMAT)
  553.                     {
  554.                         temp_outp_data_len += (2*length);
  555.                     }
  556.                     else
  557.                     {
  558.                         temp_outp_data_len += length;
  559.                     }
  560.                 }
  561.                 if(*cfg_ptr & VPC3_CFG_SF_INP_EXIST)
  562.                 {
  563.                     count++;  // next UBYTE copntains the length of inp_data
  564.                     length = (UBYTE)((*(cfg_ptr + count) & VPC3_CFG_SF_LENGTH) +1);
  565.                     if(*(cfg_ptr + count) & VPC3_CFG_LENGTH_IS_WORD_FORMAT)
  566.                     {
  567.                         temp_inp_data_len += (2*length);
  568.                     }
  569.                     else
  570.                     {
  571.                         temp_inp_data_len += length;
  572.                     }
  573.                 }
  574.                 specific_data_length = (UBYTE)(*cfg_ptr & VPC3_CFG_BF_LENGTH);
  575.                 if(specific_data_length != 15)
  576.                 {
  577.                     count = (UBYTE)(count + 1 + specific_data_length);
  578.                     cfg_ptr = cfg_ptr + count;
  579.                 }
  580.                 else
  581.                 {
  582.                     // specific data length = 15 not allowed
  583.                     dp_sys[dev_num].inp_data_len  = 0xFF;
  584.                     dp_sys[dev_num].outp_data_len = 0xFF;
  585.                     error = DP_CALCULATE_IO_ERROR;
  586.                 }
  587.             }
  588.         }//for( ; cfg_len > 0; cfg_len -= count)
  589.         if(  ( cfg_len != 0 ) || ( temp_inp_data_len > dp_sys[dev_num].din_bufsize ) || ( temp_outp_data_len > dp_sys[dev_num].dout_bufsize ) )
  590.         {
  591.             dp_sys[dev_num].inp_data_len  = 0xFF;
  592.             dp_sys[dev_num].outp_data_len = 0xFF;
  593.             error = DP_CALCULATE_IO_ERROR;
  594.         }
  595.         else
  596.         {
  597.             dp_sys[dev_num].inp_data_len  = temp_inp_data_len;
  598.             dp_sys[dev_num].outp_data_len = temp_outp_data_len;
  599.             error = DP_OK;
  600.         }
  601.     }//if( (cfg_len > 0)  &&  (cfg_len <= vpc3_dp_init.cfg_buf_len) )
  602.     else
  603.     {
  604.         dp_sys[dev_num].inp_data_len  = 0xFF;
  605.         dp_sys[dev_num].outp_data_len = 0xFF;
  606.         error = DP_CALCULATE_IO_ERROR;
  607.     }
  608. //TRACE("Dev:%d inp_data_len: %d outp_data_len:%d ", dev_num, dp_sys[dev_num].inp_data_len,dp_sys[dev_num].outp_data_len);
  609.     return error;
  610. }//vpc3_calculate_inp_outp_len (UBYTE dev_num,VPC3_UNSIGNED8_PTR cfg_ptr, UBYTE cfg_len)
  611. /*---------------------------------------------------------------------------*/
  612. /*                                                                           */
  613. /*  DP_ERROR_CODE vpc3_buf_init (UBYTE dev_num)                                       */
  614. /*                                                                           */
  615. /*   function:      Initializing VPC3 buffers.                               */
  616. /*                                                                           */
  617. /*   parameter:     none                                                     */
  618. /*   return value:  DP_OK        : Buffer length OK                          */
  619. /*                  ERROR        : defined in dp_error.h                     */
  620. /*                                                                           */
  621. /*---------------------------------------------------------------------------*/
  622. SECTION_DEF_CommuCode DP_ERROR_CODE vpc3_buf_init(UBYTE dev_num)
  623. {
  624. DP_ERROR_CODE       error;
  625. UWORD               aux_buf_len[2];      // calculated length of AUX buffer
  626. UWORD               r_din_dout_buf_len;  // calculated length of real I/O Data length
  627. UWORD               real_buf_len[3];     // real length of AUX-Buffer
  628. UBYTE               aux_ass;             // Bit array, in which the assignments of AUX1/2 are defined
  629.     error = DP_OK;
  630.     /*-----------------------------------------------------------------------*/
  631.     /* check buffer length                                                   */
  632.     /*-----------------------------------------------------------------------*/
  633.     if (dp_sys[dev_num].dout_bufsize > 244)
  634.     {
  635.         error = DP_DOUT_LEN_ERROR;
  636.     }
  637.     else if(dp_sys[dev_num].din_bufsize > 244)
  638.     {
  639.         error =  DP_DIN_LEN_ERROR;
  640.     }
  641.     else if((dp_sys[dev_num].diag_bufsize < 6) || (dp_sys[dev_num].diag_bufsize > 244))
  642.     {
  643.         error =  DP_DIAG_LEN_ERROR;
  644.     }
  645.     else if((dp_sys[dev_num].prm_bufsize < 7) || (dp_sys[dev_num].prm_bufsize > 244))
  646.     {
  647.         error =  DP_PRM_LEN_ERROR;
  648.     }
  649.     else if((dp_sys[dev_num].cfg_bufsize < 1) || (dp_sys[dev_num].cfg_bufsize > 244))
  650.     {
  651.         error =  DP_CFG_LEN_ERROR;
  652.     }
  653.     else if(dp_sys[dev_num].ssa_bufsize != 0 && ((dp_sys[dev_num].ssa_bufsize < 4) || (dp_sys[dev_num].ssa_bufsize > 244)))
  654.     {
  655.         error = DP_SSA_LEN_ERROR;
  656.     }
  657.     if(error == DP_OK)//else
  658.     {
  659.         /*-------------------------------------------------------------------*/
  660.         /* length of buffers ok, check memory consumption                    */
  661.         /*-------------------------------------------------------------------*/
  662.         if(p_Vpc3[dev_num]->mode_reg0_H & VPC3_SPEC_PRM_BUF_MODE)
  663.         {
  664.             real_buf_len[RBL_PRM] = 0; /* prm-data goes directly into prm-buffer */
  665.         }
  666.         else
  667.         {
  668.             real_buf_len[RBL_PRM] = dp_sys[dev_num].prm_bufsize; // prm-data goes over AUX-buffer
  669.         }
  670.         // length of cfg and ssa buffer
  671.         real_buf_len[RBL_CFG] = dp_sys[dev_num].cfg_bufsize;
  672.         real_buf_len[RBL_SSA] = dp_sys[dev_num].ssa_bufsize;
  673.         /*-------------------------------------------------------------------*/
  674.         /* calculate aux-buffer                                              */
  675.         /*-------------------------------------------------------------------*/
  676.         dp_sys[dev_num].vpc3_used_dp_buf_mem = assign_aux_buf(dev_num,&real_buf_len[0], 3, &aux_ass, &aux_buf_len[0]);
  677.         /*-------------------------------------------------------------------*/
  678.         /* check memory consumption                                          */
  679.         /*-------------------------------------------------------------------*/
  680.         r_din_dout_buf_len = ((dp_sys[dev_num].dout_bufsize + SEG_OFFSET) & SEG_ADDWORD) + ((dp_sys[dev_num].din_bufsize + SEG_OFFSET) & SEG_ADDWORD);
  681.         // DIn DOut buffer
  682.         dp_sys[dev_num].vpc3_used_dp_buf_mem += r_din_dout_buf_len * 3;
  683.         // add Read Config Buffer
  684.         dp_sys[dev_num].vpc3_used_dp_buf_mem += real_buf_len[RBL_CFG];
  685.         // diagnose buffer
  686.         dp_sys[dev_num].vpc3_used_dp_buf_mem += ((dp_sys[dev_num].diag_bufsize + SEG_OFFSET) & SEG_ADDBYTE) * 2;
  687.         // prm buffer
  688.         if(p_Vpc3[dev_num]->mode_reg0_H & VPC3_SPEC_PRM_BUF_MODE)
  689.         {
  690.             // spec. PRM buffer
  691.             real_buf_len[RBL_PRM] = (dp_sys[dev_num].prm_bufsize + SEG_OFFSET) & SEG_ADDBYTE;
  692.             dp_sys[dev_num].vpc3_used_dp_buf_mem += real_buf_len[RBL_PRM];
  693.             p_Vpc3[dev_num]->len_spec_prm_buf = dp_sys[dev_num].prm_bufsize;
  694.         }
  695.         else
  696.         {
  697.             p_Vpc3[dev_num]->len_spec_prm_buf = 0;
  698.         }
  699.         if( dp_sys[dev_num].vpc3_used_dp_buf_mem > sizeof (p_Vpc3[dev_num]->dpbuffer)/BLACKFIN_MULTIPLER  )
  700.         {
  701.             // Error: user needs too much memory
  702.             dp_sys[dev_num].vpc3_used_dp_buf_mem = 0;
  703.             error = DP_LESS_MEM_ERROR;
  704.         }
  705.         else
  706.         {
  707.             /*---------------------------------------------------------------*/
  708.             /* set buffer pointer                                            */
  709.             /*---------------------------------------------------------------*/
  710.             p_Vpc3[dev_num]->aux_buf_sel      = aux_ass;   // AUX-Puffer zuordnen
  711.             p_Vpc3[dev_num]->dout_buf_ptr[0]  = VPC3_DP_BUF_START(dev_num);
  712.             p_Vpc3[dev_num]->dout_buf_ptr[1]  = p_Vpc3[dev_num]->dout_buf_ptr[0]  + (((dp_sys[dev_num].dout_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  713.             p_Vpc3[dev_num]->dout_buf_ptr[2]  = p_Vpc3[dev_num]->dout_buf_ptr[1]  + (((dp_sys[dev_num].dout_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  714.             p_Vpc3[dev_num]->din_buf_ptr[0]   = p_Vpc3[dev_num]->dout_buf_ptr[2]  + (((dp_sys[dev_num].dout_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  715.             p_Vpc3[dev_num]->din_buf_ptr[1]   = p_Vpc3[dev_num]->din_buf_ptr[0]   + (((dp_sys[dev_num].din_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  716.             p_Vpc3[dev_num]->din_buf_ptr[2]   = p_Vpc3[dev_num]->din_buf_ptr[1]   + (((dp_sys[dev_num].din_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  717.             p_Vpc3[dev_num]->diag_buf_ptr[0]  = p_Vpc3[dev_num]->din_buf_ptr[2]   + (((dp_sys[dev_num].din_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  718.             p_Vpc3[dev_num]->diag_buf_ptr[1]  = p_Vpc3[dev_num]->diag_buf_ptr[0]  + (((dp_sys[dev_num].diag_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  719.             p_Vpc3[dev_num]->cfg_buf_ptr      = p_Vpc3[dev_num]->diag_buf_ptr[1]  + (((dp_sys[dev_num].diag_bufsize + SEG_OFFSET) & SEG_ADDBYTE)>>SEG_MULDIV);
  720.             p_Vpc3[dev_num]->read_cfg_buf_ptr = p_Vpc3[dev_num]->cfg_buf_ptr      + (real_buf_len[RBL_CFG]>>SEG_MULDIV);
  721.             p_Vpc3[dev_num]->prm_buf_ptr      = p_Vpc3[dev_num]->read_cfg_buf_ptr + (real_buf_len[RBL_CFG]>>SEG_MULDIV);
  722.             p_Vpc3[dev_num]->aux_buf_ptr[0]   = p_Vpc3[dev_num]->prm_buf_ptr      + (real_buf_len[RBL_PRM]>>SEG_MULDIV);
  723.             if( aux_buf_len[1] != 0 )
  724.             {
  725.                 p_Vpc3[dev_num]->aux_buf_ptr[1]   = p_Vpc3[dev_num]->aux_buf_ptr[0]   + (aux_buf_len[0]>>SEG_MULDIV);
  726.             }
  727.             else
  728.             {
  729.                 p_Vpc3[dev_num]->aux_buf_ptr[1]   = 0;
  730.             }
  731.             if (real_buf_len[RBL_SSA] == 0)
  732.             {
  733.                 // no ssa supported
  734.                 p_Vpc3[dev_num]->ssa_buf_ptr = 0;         /* Dienst sperren */
  735.             }
  736.             else
  737.             {
  738.                 // ssa supported
  739.                 if( aux_buf_len[1] != 0 )
  740.                 {
  741.                     p_Vpc3[dev_num]->ssa_buf_ptr = p_Vpc3[dev_num]->aux_buf_ptr[1] + (aux_buf_len[1]>>SEG_MULDIV);
  742.                 }
  743.                 else
  744.                 {
  745.                     p_Vpc3[dev_num]->ssa_buf_ptr = p_Vpc3[dev_num]->aux_buf_ptr[0] + (aux_buf_len[0]>>SEG_MULDIV);
  746.                 }
  747.             }
  748.             /*---------------------------------------------------------------*/
  749.             /* set buffer length                                             */
  750.             /*---------------------------------------------------------------*/
  751.             p_Vpc3[dev_num]->len_dout_buf    = dp_sys[dev_num].outp_data_len;
  752.             p_Vpc3[dev_num]->len_din_buf     = dp_sys[dev_num].inp_data_len;
  753.             p_Vpc3[dev_num]->len_diag_buf[0] = 6;                // length of Diag Buffers
  754.             p_Vpc3[dev_num]->len_diag_buf[1] = 6;
  755.             if(aux_buf_len[0] >= 244)
  756.             {
  757.                 p_Vpc3[dev_num]->len_ctrl_buf[0] = 244;      // Length AUX1-Buffer
  758.             }
  759.             else
  760.             {
  761.                 p_Vpc3[dev_num]->len_ctrl_buf[0] = aux_buf_len[0];      // Length AUX1-Buffer
  762.             }
  763.             if(aux_buf_len[1] >= 244)
  764.             {
  765.                 p_Vpc3[dev_num]->len_ctrl_buf[1] = 244;      // Length AUX1-Buffer
  766.             }
  767.             else
  768.             {
  769.                 p_Vpc3[dev_num]->len_ctrl_buf[1] = aux_buf_len[1];      // Length AUX1-Buffer
  770.             }
  771.             p_Vpc3[dev_num]->len_cfg_data    = dp_sys[dev_num].cfg_bufsize;
  772.             p_Vpc3[dev_num]->len_prm_data    = dp_sys[dev_num].prm_bufsize;
  773.             p_Vpc3[dev_num]->len_ssa_buf     = dp_sys[dev_num].ssa_bufsize;
  774.         }
  775.     }
  776.     return error;
  777. }//DP_ERROR_CODE vpc3_buf_init(UBYTE dev_num)
  778. /*---------------------------------------------------------------------------*/
  779. /*                                                                           */
  780. /*  UBYTE vpc3_cfg_data_ok(UBYTE dev_num)                                             */
  781. /*                                                                           */
  782. /*  function:      Set Configuration Data ok                                 */
  783. /*                                                                           */
  784. /*  parameter:     none                                                      */
  785. /*  return value:  VPC3_CFG_FINISHED:  The transferred configuration is OK.  */
  786. /*                 VPC3_CFG_CONFLICT:  Repeat verification of the requested  */
  787. /*                                     configuration.                        */
  788. /*                                                                           */
  789. /*---------------------------------------------------------------------------*/
  790. SECTION_DEF_CommuCode UBYTE vpc3_cfg_data_ok(UBYTE dev_num)
  791. {
  792.     return p_Vpc3[dev_num]->ctrl_reg.rd.user_cfg_data_ok;
  793. }
  794. /*---------------------------------------------------------------------------*/
  795. /*                                                                           */
  796. /*  UBYTE vpc3_cfg_data_update(UBYTE dev_num)                                         */
  797. /*                                                                           */
  798. /*  function:      Update Configuration Data                                 */
  799. /*                                                                           */
  800. /*  parameter:     none                                                      */
  801. /*  return value:  VPC3_CFG_FINISHED:  The transferred configuration is OK.  */
  802. /*                 VPC3_CFG_CONFLICT:  Repeat verification of the requested  */
  803. /*                                     configuration.                        */
  804. /*                                                                           */
  805. /*---------------------------------------------------------------------------*/
  806. SECTION_DEF_CommuCode UBYTE vpc3_cfg_data_update(UBYTE dev_num)
  807. {
  808. int nBlackfinLoop;
  809. uint16* pBlackfinAddr;
  810. uint16* pSrcAddr;
  811.     p_Vpc3[dev_num]->len_read_cfg_data = p_Vpc3[dev_num]->len_cfg_data;
  812. //    memcpy( VPC3_GET_READ_CFG_BUF_PTR(dev_num), VPC3_GET_CFG_BUF_PTR(dev_num), p_Vpc3[dev_num]->len_cfg_data);
  813. pSrcAddr = (uint16*)VPC3_GET_CFG_BUF_PTR(dev_num);
  814. pBlackfinAddr = (uint16*)VPC3_GET_READ_CFG_BUF_PTR(dev_num);
  815. for (nBlackfinLoop=0; nBlackfinLoop<BFWORD2BYTE(p_Vpc3[dev_num]->len_cfg_data); nBlackfinLoop++)
  816. {
  817. pBlackfinAddr[nBlackfinLoop] = pSrcAddr[nBlackfinLoop];
  818. }
  819. return p_Vpc3[dev_num]->ctrl_reg.rd.user_cfg_data_ok;
  820. }
  821. /*---------------------------------------------------------------------------*/
  822. /*  D e s c r i p t i o n : vpc3_cfg_data_not_ok                             */
  823. /*                                                                           */
  824. /*   function:      Set Configuration Data not ok                            */
  825. /*                                                                           */
  826. /*   parameter:     none                                                     */
  827. /*   return value:  VPC3_CFG_FINISHED:  The transferred configuration is OK. */
  828. /*                  VPC3_CFG_CONFLICT:  Repeat verification of the requested */
  829. /*                                      configuration.                       */
  830. /*---------------------------------------------------------------------------*/
  831. SECTION_DEF_CommuCode UBYTE vpc3_cfg_data_not_ok(UBYTE dev_num)
  832. {
  833.     return p_Vpc3[dev_num]->ctrl_reg.rd.user_cfg_data_nok;
  834. }
  835. /*---------------------------------------------------------------------------*/
  836. /*  D e s c r i p t i o n : vpc3_get_doutbufptr                              */
  837. /*                                                                           */
  838. /* This function fetches the pointer to the actual output buffer.            */
  839. /*---------------------------------------------------------------------------*/
  840. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_get_doutbufptr (UBYTE dev_num,UBYTE PTR_ATTR *state_ptr)
  841. {
  842. VPC3_UNSIGNED8_PTR p_doutbuf; // pointer to output buffer ( DP-Master -> VPC3+ )
  843.     *state_ptr = (p_Vpc3[dev_num]->ctrl_reg.rd.next_dout_buf_cmd & (VPC3_NEW_DOUT_BUF | VPC3_DOUT_BUF_CLEARED));
  844.     switch (p_Vpc3[dev_num]->ctrl_reg.rd.dout_buffer_sm & 0x30)    // locate user Dout Buffer
  845.     {
  846.         case 0x10:
  847.         {
  848.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dout_buf_ptr[0]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  849.             break;
  850.         }
  851.         case 0x20:
  852.         {
  853.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dout_buf_ptr[1]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  854.             break;
  855.         }
  856.         case 0x30:
  857.         {
  858.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dout_buf_ptr[2]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  859.             break;
  860.         }
  861.         default:
  862.         {
  863.             p_doutbuf = NULL_PTR;
  864.             break;
  865.         }
  866.     }//switch (p_Vpc3[dev_num]->ctrl_reg.rd.dout_buffer_sm & 0x30)    // locate user Dout Buffer
  867.     return p_doutbuf;
  868. }
  869. /*---------------------------------------------------------------------------*/
  870. /*  D e s c r i p t i o n : vpc3_get_dinbufptr                               */
  871. /*                                                                           */
  872. /* This function fetches the pointer to the actual input buffer.             */
  873. /*---------------------------------------------------------------------------*/
  874. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_get_dinbufptr (UBYTE dev_num)
  875. {
  876. VPC3_UNSIGNED8_PTR p_dinbuf; // pointer to output buffer ( VPC3 -> DP-Master )
  877.     switch (p_Vpc3[dev_num]->ctrl_reg.rd.din_buffer_sm & 0x30)         // locate user Din Buffer
  878.     {
  879.         case 0x10:
  880.         {
  881.             p_dinbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->din_buf_ptr[0]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  882.             break;
  883.         }
  884.         case 0x20:
  885.         {
  886.             p_dinbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->din_buf_ptr[1]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  887.             break;
  888.         }
  889.         case 0x30:
  890.         {
  891.             p_dinbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->din_buf_ptr[2]) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  892.             break;
  893.         }
  894.         default:
  895.         {
  896.             p_dinbuf = NULL_PTR;
  897.             break;
  898.         }
  899.     }//switch (p_Vpc3[dev_num]->ctrl_reg.rd.din_buffer_sm & 0x30)
  900.     return p_dinbuf;
  901. }
  902. /*---------------------------------------------------------------------------*/
  903. /*  D e s c r i p t i o n : vpc3_get_dxb_outbufptr                           */
  904. /*                                                                           */
  905. /* This function fetches the pointer to the actual dxb output buffer.        */
  906. /*---------------------------------------------------------------------------*/
  907. #ifdef DP_SUBSCRIBER
  908. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_get_dxb_outbufptr (UBYTE dev_num,UBYTE PTR_ATTR *state_ptr)
  909. {
  910. VPC3_UNSIGNED8_PTR p_doutbuf; // pointer to output buffer (DP-Master -> VPC3+ )
  911.     *state_ptr = (p_Vpc3[dev_num]->ctrl_reg.rd.next_dxb_buf_cmd & (VPC3_NEW_DOUT_BUF | VPC3_DOUT_BUF_CLEARED));
  912.     switch (p_Vpc3[dev_num]->ctrl_reg.rd.dxbout_buffer_sm & 0x30)    // locate user DXBout Buffer
  913.     {
  914.         case 0x10:
  915.         {
  916.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dxb_out_buf_ptr1) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  917.             break;
  918.         }
  919.         case 0x20:
  920.         {
  921.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dxb_out_buf_ptr2) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  922.             break;
  923.         }
  924.         case 0x30:
  925.         {
  926.             p_doutbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->dxb_out_buf_ptr3) << BLACKFIN_SEG_MULDIV)+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  927.             break;
  928.         }
  929.         default:
  930.         {
  931.             p_doutbuf = NULL_PTR;
  932.             break;
  933.         }
  934.     }//switch (p_Vpc3[dev_num]->ctrl_reg.rd.dxb_out_buffer_sm & 0x30)    // locate user Dout Buffer
  935.     return p_doutbuf;
  936. }
  937. /*-------------------------------------------------------------------*/
  938. /* function: dxb_subscriber_table_to_dxb_link_table                  */
  939. /*-------------------------------------------------------------------*/
  940. SECTION_DEF_CommuCode void dxb_subscriber_table_to_dxb_link_table(UBYTE dev_num, PRM_SUBSCRIBER_TABLE_PTR dxb_ptr, UBYTE NrOfLinks )
  941. {
  942. PRM_DXB_LINK_TABLE  link_table;
  943. UBYTE               i;
  944. int nBlackfinLoop;
  945. uint16* pBlackfinAddr;
  946. uint16* pSrcAddr;
  947.     memset( &link_table, 0, sizeof(PRM_DXB_LINK_TABLE));//!!! 如果V2要改...
  948.     link_table.version = dxb_ptr->version;
  949.     for(i = 0; i < NrOfLinks; i++ )
  950.     {
  951.         link_table.link_table_entry[i].publisher_addr   = dxb_ptr->subscriber_table_entry[i].publisher_addr;
  952.         link_table.link_table_entry[i].publisher_length = dxb_ptr->subscriber_table_entry[i].publisher_length;
  953.         link_table.link_table_entry[i].sample_offset    = dxb_ptr->subscriber_table_entry[i].sample_offset;
  954.         link_table.link_table_entry[i].sample_length    = dxb_ptr->subscriber_table_entry[i].sample_length;
  955.     }
  956.     VPC3_SET_DXB_LINK_TABLE_LEN(dev_num, NrOfLinks<<2);
  957.     //memcpy( VPC3_GET_DXB_LINK_TABLE_BUF_PTR(dev_num), &link_table.link_table_entry[0].publisher_addr, (NrOfLinks<<2));
  958. pBlackfinAddr = (uint16*)VPC3_GET_DXB_LINK_TABLE_BUF_PTR(dev_num);
  959. pSrcAddr = (uint16*)&link_table.link_table_entry[0].publisher_addr;
  960. for (nBlackfinLoop=0; nBlackfinLoop<(NrOfLinks<<2); nBlackfinLoop++)
  961. {
  962. pBlackfinAddr[nBlackfinLoop] = pSrcAddr[nBlackfinLoop];
  963. }
  964. }
  965. /*-------------------------------------------------------------------*/
  966. /* function: check_dxb_link_table                                    */
  967. /*-------------------------------------------------------------------*/
  968. SECTION_DEF_CommuCode UBYTE check_dxb_link_table(UBYTE dev_num)
  969. {
  970. VPC3_DXB_LINK_TABLE_PTR dxb_ptr;
  971. UBYTE                   ret_value;
  972. UBYTE                   i;
  973.     ret_value = DP_OK;
  974.     dxb_ptr = (VPC3_DXB_LINK_TABLE_PTR)VPC3_GET_DXB_LINK_TABLE_BUF_PTR(dev_num);
  975.     for(i = 0; i < (VPC3_GET_DXB_LINK_TABLE_LEN(dev_num)/4); i++)
  976.     {
  977.         if(    (dxb_ptr->link_table_entry[i].publisher_addr   > 125)
  978.             || (dxb_ptr->link_table_entry[i].publisher_length < 1  )
  979.             || (dxb_ptr->link_table_entry[i].publisher_length > 244)
  980.             || (dxb_ptr->link_table_entry[i].sample_offset    > (dxb_ptr->link_table_entry[i].publisher_length - 1))
  981.             || ((dxb_ptr->link_table_entry[i].sample_offset + dxb_ptr->link_table_entry[i].sample_length) >
  982.                                                                         (dxb_ptr->link_table_entry[i].publisher_length))
  983.             || (dxb_ptr->link_table_entry[i].sample_length > MAX_DATA_PER_LINK-2)
  984.           )
  985.         {
  986.             ret_value = DP_PRM_DXB_ERROR;
  987.             VPC3_SET_DXB_LINK_TABLE_LEN(dev_num,0);
  988.             break;
  989.         }
  990.     }
  991.     return ret_value;
  992. }
  993. /*-------------------------------------------------------------------*/
  994. /* function: build_dxb_link_status                                   */
  995. /*-------------------------------------------------------------------*/
  996. SECTION_DEF_CommuCode void build_dxb_link_status(UBYTE dev_num)
  997. {
  998. VPC3_DXB_LINK_TABLE_PTR dxb_ptr;
  999. VPC3_DXB_LINK_STATUS    link_status;
  1000. UBYTE                   i;
  1001. int nBlackfinLoop;
  1002.        uint16* pBlackfinAddr;
  1003.        uint16* pSrcAddr;
  1004.     memset( &link_status, 0, sizeof(VPC3_DXB_LINK_STATUS));//!!! 如果V2要改...
  1005.     dxb_ptr = (VPC3_DXB_LINK_TABLE_PTR)VPC3_GET_DXB_LINK_TABLE_BUF_PTR(dev_num);
  1006.     link_status.header           = 4+(VPC3_GET_DXB_LINK_TABLE_LEN(dev_num)/2);
  1007.     link_status.status_type      = 0x83;
  1008.     link_status.slot_number      = 0x00;
  1009.     link_status.status_specifier = 0x00;
  1010.     for(i = 0; i < ((link_status.header-4) / 2); i++)
  1011.     {
  1012.         link_status.link_status[i].publisher_addr = dxb_ptr->link_table_entry[i].publisher_addr;
  1013.         link_status.link_status[i].link_status    = 0x00;
  1014.     }
  1015.     VPC3_SET_DXB_LINK_STATUS_LEN(dev_num, link_status.header);
  1016.     //memcpy( VPC3_GET_DXB_LINK_STATUS_BUF_PTR(dev_num), &link_status, link_status.header);
  1017. pBlackfinAddr = (uint16*)VPC3_GET_DXB_LINK_STATUS_BUF_PTR(dev_num);
  1018. pSrcAddr = (uint16*)&link_status;
  1019. for (nBlackfinLoop=0; nBlackfinLoop<link_status.header; nBlackfinLoop++)
  1020. {
  1021. pBlackfinAddr[nBlackfinLoop] = pSrcAddr[nBlackfinLoop];
  1022. }
  1023. }
  1024. #endif//#ifdef DP_SUBSCRIBER
  1025. /*---------------------------------------------------------------------------*/
  1026. /*                                                                           */
  1027. /*  The function provides the actual prm-master by read out the diag-        */
  1028. /*  buffer in vpc3.                                                          */
  1029. /*---------------------------------------------------------------------------*/
  1030. SECTION_DEF_CommuCode UBYTE vpc3_get_master(UBYTE dev_num)
  1031. {
  1032. UBYTE  master;
  1033.     master = *((VPC3_UNSIGNED8_PTR)(((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[0]) << SEG_MULDIV)+3)*BLACKFIN_MULTIPLER+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num)))));
  1034.     if( (master&0xff) == 0xFF )//2009.11.7
  1035.     {
  1036.         master = *((VPC3_UNSIGNED8_PTR)(((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[1]) << SEG_MULDIV)+3)*BLACKFIN_MULTIPLER+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num)))));
  1037.     }
  1038.     return (master&0xff);//2009.11.7
  1039. }
  1040. /********************************************************************************
  1041. *                                                                               *
  1042. *  UWORD assign_aux_buf (UBYTE dev_num,   UWORD PTR_ATTR *lens, UBYTE count,                  *
  1043. *                           UBYTE PTR_ATTR *assign,                             *
  1044. *                           UWORD PTR_ATTR *aux_len)                            *
  1045. *                                                                              *
  1046. *   function:      Calculate length of AUX buffers.                            *
  1047. *                                                                              *
  1048. *   parameter:     lens    : pointer of list to the buffer length              *
  1049. *                  count   : length of list (2..3)                             *
  1050. *                  assign  : Bit array, in which the assignments of the        *
  1051. *                            AUX-buffers1 and 2 are defined to the control     *
  1052. *                            buffers, SSA-Buf, PRM-Buf, Cfg-Buf                *
  1053. *                  aux_len : Pointer to a 2 byte field of aux-buffer length.   *
  1054. *   return value:  count of bytes used for aux buffers.                        *
  1055. *                                                                              *
  1056. ********************************************************************************/
  1057. SECTION_DEF_CommuCode UWORD assign_aux_buf(UBYTE dev_num,UWORD PTR_ATTR *lens, UBYTE count, UBYTE PTR_ATTR *assign, UWORD PTR_ATTR *aux_len)
  1058. {
  1059. UWORD   min_len = 0xffff;     // calculated minimal length
  1060. UBYTE   min_step = 0;         // step by calculated minimal length
  1061. UBYTE   i,j;
  1062. UBYTE   pos[3];               // memory for position of length
  1063. UWORD   lensx[3];             // workarea for calculated length
  1064. UBYTE   step;                 // counter
  1065. UWORD   wtmp;                 // tmp-variable for calculated length
  1066. UBYTE   tmp;                  // tmp-variable for calculated length
  1067.                               // tmp-varaiable for sorted positions
  1068.     // check count
  1069.     if((count == 2) || (count == 3))
  1070.     {
  1071.         for(i = 0; i < count; i++)
  1072.         {
  1073.             // init memory for position of length
  1074.             pos[i] = i;
  1075.             // copy length into workarea for calculated length
  1076.             lensx[i] = lens[i];
  1077.             // put length to 8 Bit Segmentaddresses
  1078.             lensx[i] = (lensx[i] + SEG_OFFSET) & SEG_ADDWORD;
  1079.         }
  1080.         // sort length, highest length to index 0
  1081.         for(i = 0; i < count-1; i++)
  1082.         {
  1083.             for(j = i+1; j < count; j++)
  1084.             {
  1085.                 if(lensx[i] < lensx[j])
  1086.                 {
  1087.                     // found higher length
  1088.                     tmp = lensx[i];          // swap length
  1089.                     lensx[i] = lensx[j];
  1090.                     lensx[j] = tmp;
  1091.                     tmp = pos[i];            // swap position
  1092.                     pos[i] = pos[j];
  1093.                     pos[j] = tmp;
  1094.                 }
  1095.             }
  1096.         }
  1097.         // delete zero length from list lensx
  1098.         for(i = count; i > 0; i--)
  1099.         {
  1100.             if(lensx[i-1] == 0)
  1101.             {
  1102.                 count--;
  1103.             }
  1104.         }
  1105.         if( count == 0 )
  1106.         {
  1107.             min_len = 0;     // Error: no defined buffer length
  1108.         }
  1109.         // gradual length assign to aux-buffer
  1110.         for(step = 0; step < count; step++)
  1111.         {
  1112.             // get length for AUX-Buffer 1
  1113.             aux_len[0] = 0;
  1114.             for(i = step; i < count; i++)
  1115.             {
  1116.                 if(aux_len[0] < lensx[i])
  1117.                 {
  1118.                     aux_len[0] = lensx[i];
  1119.                 }
  1120.             }
  1121.             aux_len[0] = aux_len[0] * (count - step + 1);
  1122.             // get length for AUX-Buffer 2
  1123.             aux_len[1] = 0;
  1124.             for(i = 0; i < step; i++)
  1125.             {
  1126.                 if(aux_len[1] < lensx[i])
  1127.                 {
  1128.                     aux_len[1] = lensx[i];
  1129.                 }
  1130.             }
  1131.             aux_len[1] = aux_len[1] * (step + 1);
  1132.             if((aux_len[0] + aux_len[1]) < min_len)
  1133.             {
  1134.                 // new minimal length found
  1135.                 min_len = aux_len[0] + aux_len[1];
  1136.                 min_step = step;
  1137.             }
  1138.         }
  1139.         // calculate length for AUX Buffer 1
  1140.         aux_len[0] = 0;
  1141.         for(i = min_step; i < count; i++)
  1142.         {
  1143.             if(aux_len[0] < lensx[i])
  1144.             {
  1145.                 aux_len[0] = lensx[i];
  1146.             }
  1147.         }
  1148.         // put length, assigned for AUX buffer 1
  1149.         for(i = min_step; i < count; i++)
  1150.         {
  1151.             lens[pos[i]] = aux_len[0];
  1152.         }
  1153.         // calculate length of AUX-Buffer 2
  1154.         aux_len[1] = 0;
  1155.         for(i = 0; i < min_step; i++)
  1156.         {
  1157.             if (aux_len[1] < lensx[i])
  1158.             {
  1159.                 aux_len[1] = lensx[i];
  1160.             }
  1161.         }
  1162.         *assign = 0;    // put all buffer to AUX-Buffer 1
  1163.         for(i = 0; i < min_step; i++)
  1164.         {
  1165.             lens[pos[i]] = aux_len[1];
  1166.             *assign |= 0x1 << pos[i];
  1167.         }
  1168.         //check here for VPC3+/B
  1169.         //handle Cfg-telegram only over AUX-Buffer 1
  1170.         if( *assign & 0x02 )
  1171.         {
  1172.             tmp = (*assign);
  1173.             *assign = ((~tmp)&0x07);
  1174.             //*assign &= 0x07;
  1175.             wtmp = aux_len[0];
  1176.             aux_len[0] = aux_len[1];
  1177.             aux_len[1] = wtmp;
  1178.         }
  1179.     }
  1180.     else
  1181.     {
  1182.         min_len = 0; // error
  1183.     }
  1184.     return min_len;
  1185. }
  1186. /*---------------------------------------------------------------------------*/
  1187. /*  void vpc3_set_io_data_len(UBYTE dev_num)                                          */
  1188. /*---------------------------------------------------------------------------*/
  1189. SECTION_DEF_CommuCode void vpc3_set_io_data_len(UBYTE dev_num)
  1190. {
  1191.     // length of buffers OK, set real buffers
  1192.     p_Vpc3[dev_num]->len_dout_buf = dp_sys[dev_num].outp_data_len;
  1193.     p_Vpc3[dev_num]->len_din_buf  = dp_sys[dev_num].inp_data_len;
  1194. }
  1195. /*---------------------------------------------------------------------------*/
  1196. /*  D e s c r i p t i o n : vpc3_get_diagbufptr                              */
  1197. /*                                                                           */
  1198. /* This function fetches the pointer to the actual diagnosis buffer.         */
  1199. /*---------------------------------------------------------------------------*/
  1200. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_get_diagbufptr (UBYTE dev_num)
  1201. {
  1202. VPC3_UNSIGNED8_PTR p_diagbuf; // pointer to diagnosis buffer
  1203.     if((p_Vpc3[dev_num]->ctrl_reg.rd.diag_buffer_sm & 0x03) == 0x01)           // locate Diag Buffer
  1204.     {
  1205.         p_diagbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[0]) << BLACKFIN_SEG_MULDIV))+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  1206.     }
  1207.     else
  1208.     {
  1209.         if((p_Vpc3[dev_num]->ctrl_reg.rd.diag_buffer_sm & 0x0C) == 0x04)
  1210.         {
  1211.             p_diagbuf = (VPC3_UNSIGNED8_PTR)((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[1]) << BLACKFIN_SEG_MULDIV))+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));
  1212.         }
  1213.         else
  1214.         {
  1215.             p_diagbuf = NULL_PTR;
  1216.         }
  1217.     }
  1218.     return p_diagbuf;
  1219. }
  1220. /*---------------------------------------------------------------------------*/
  1221. /* function: vpc3_set_diag_update_all                                        */
  1222. /*---------------------------------------------------------------------------*/
  1223. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_set_diag_update_all(UBYTE dev_num, UBYTE diag_state, UBYTE diag_len )
  1224. {
  1225. VPC3_UNSIGNED8_PTR p_diagbuf; // pointer to diagnosis buffer
  1226.     if((p_Vpc3[dev_num]->ctrl_reg.rd.diag_buffer_sm & 0x03) == 0x01)           // locate Diag Buffer
  1227.     {
  1228.         p_Vpc3[dev_num]->len_diag_buf[0] = diag_len; // length of Diag Buffer 1
  1229.         *((VPC3_UNSIGNED8_PTR)(((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[0]) << BLACKFIN_SEG_MULDIV)+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num))))) = diag_state;
  1230.     }
  1231.     else
  1232.     {
  1233.         if((p_Vpc3[dev_num]->ctrl_reg.rd.diag_buffer_sm & 0x0C) == 0x04)
  1234.         {
  1235.             p_Vpc3[dev_num]->len_diag_buf[1] = diag_len;  // length of Diag Buffer 2
  1236.             *((VPC3_UNSIGNED8_PTR)(((VPC3_ADR)( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[1]) << BLACKFIN_SEG_MULDIV)+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num))))) = diag_state;
  1237.         }
  1238.     }
  1239.     switch( p_Vpc3[dev_num]->ctrl_reg.rd.new_diag_buf_cmd & 0x03 )
  1240.     {
  1241.         case 1:   // use buffer 1
  1242.         {
  1243.             p_diagbuf = (VPC3_UNSIGNED8_PTR)(((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[0]) << BLACKFIN_SEG_MULDIV))+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num))));
  1244.             break;
  1245.         }
  1246.         case 2:   // use buffer 2
  1247.         {
  1248.             p_diagbuf = (VPC3_UNSIGNED8_PTR)(((VPC3_ADR)(( BFWORD2BYTE(p_Vpc3[dev_num]->diag_buf_ptr[1]) << BLACKFIN_SEG_MULDIV))+((VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num))));
  1249.             break;
  1250.         }
  1251.         default:
  1252.         {
  1253.             // no buffer available
  1254.             p_diagbuf = NULL_PTR;
  1255.             break;
  1256.         }
  1257.     }
  1258.     return p_diagbuf;
  1259. }
  1260. /*---------------------------------------------------------------------------*/
  1261. /* function: reset_diagnostic_buffer                                         */
  1262. /*---------------------------------------------------------------------------*/
  1263. SECTION_DEF_CommuCode void reset_diagnostic_buffer(UBYTE dev_num)
  1264. {
  1265. VPC3_UNSIGNED8_PTR  diag_ptr;
  1266.     do
  1267.     {
  1268.         //fetch new diagnosis buffer
  1269.         diag_ptr = vpc3_get_diagbufptr(dev_num);
  1270.     }
  1271.     while(diag_ptr == NULL_PTR );
  1272.     //clear diagnostic buffer
  1273.     vpc3_set_diag_update_all(dev_num, 0, 6 );
  1274. }//void reset_diagnostic_buffer(UBYTE dev_num)
  1275. /*--------------------------------------------------------------------------*/
  1276. /* set_diagnose (called by DP, DPV1-ALARM)                                 */
  1277. /*--------------------------------------------------------------------------*/
  1278. SECTION_DEF_CommuCode DP_ERROR_CODE set_diagnosis(UBYTE dev_num, VPC3_UNION_DIAG_PTR user_diag, UBYTE user_diag_len, UBYTE diag_control, UBYTE check_diag_flag )
  1279. {
  1280. VPC3_UNION_DIAG_PTR tmp_user_diag;
  1281. DP_ERROR_CODE       ret_value;
  1282. UBYTE               tmp_user_diag_len;
  1283. UBYTE               tmp_len;
  1284. UBYTE               dp_state;
  1285. int nBlackfinLoop;
  1286. uint16* pBlackfinAddr;
  1287. //uint16* pSrcAddr;
  1288. ret_value = DP_OK;
  1289.     //check available diag buffer
  1290.     if( dp_sys[dev_num].diag_buf_ptr.byte_ptr != NULL_PTR )
  1291.     {
  1292.         tmp_user_diag     = user_diag;
  1293.         tmp_user_diag_len = user_diag_len;
  1294.         dp_state = VPC3_GET_DP_STATE(dev_num);
  1295.         if( (dp_state == DATA_EX) && (check_diag_flag == TRUE) )
  1296.         {
  1297.             if( VPC3_GET_DIAG_FLAG(dev_num) )
  1298.             {
  1299.                 //old diagnosis not send
  1300.                 ret_value = DP_DIAG_OLD_DIAG_NOT_SEND_ERROR;
  1301.             }//if( VPC3_GET_DIAG_FLAG(dev_num) )
  1302.         }//if( (dp_state == DATA_EX) && (check_diag_flag == TRUE) )
  1303.         // check user_diag_len
  1304.         if( user_diag_len > (dp_sys[dev_num].diag_bufsize-6) )
  1305.         {
  1306.             ret_value = DP_DIAG_BUFFER_LENGTH_ERROR;
  1307.         }//if( user_diag_len > (dp_sys[dev_num].diag_bufsize-6) )
  1308.         if( ret_value == DP_OK )
  1309.         {
  1310.             //check control byte
  1311.             switch(diag_control )
  1312.             {
  1313.                 case EXT_DIAG_SET:
  1314.                 {
  1315.                     if( user_diag_len == 0 )
  1316.                     {
  1317.                         ret_value = DP_DIAG_CONTROL_BYTE_ERROR;
  1318.                     }//if( user_diag_len == 0 )
  1319.                     break;
  1320.                 }//case EXT_DIAG_SET:
  1321.                 default:
  1322.                 {
  1323.                     //do nothing
  1324.                     break;
  1325.                 }//default:
  1326.             }//switch( diag_control )
  1327.             //check user diag buffer contents
  1328.             while((0 < tmp_user_diag_len) && (DP_OK == ret_value) )
  1329.             {
  1330.                 tmp_len = tmp_user_diag.struc_ptr->dev.sign_len;
  1331.                 switch(DIAG_TYPE_MASK & tmp_user_diag.struc_ptr->dev.sign_len )
  1332.                 {
  1333.                     case DIAG_TYPE_DEV:
  1334.                     {
  1335.                         if( STATUS_DIAG_HEAD_SIZE > (tmp_len = (~DIAG_TYPE_MASK) & tmp_len) )
  1336.                         {
  1337.                             ret_value = DP_DIAG_BUFFER_ERROR;
  1338.                         }//if( STATUS_DIAG_HEAD_SIZE > (tmp_len = (~DIAG_TYPE_MASK) & tmp_len) )
  1339.                         break;
  1340.                     }//case DIAG_TYPE_DEV:
  1341.                     case DIAG_TYPE_KEN:
  1342.                     {
  1343.                         if ( 0 == (tmp_len = (~DIAG_TYPE_MASK) & tmp_len) )
  1344.                         {
  1345.                             ret_value = DP_DIAG_BUFFER_ERROR;
  1346.                         }//if ( 0 == (tmp_len = (~DIAG_TYPE_MASK) & tmp_len) )
  1347.                         break;
  1348.                     }//case DIAG_TYPE_KEN:
  1349.                     case DIAG_TYPE_CHN:
  1350.                     {
  1351.                         tmp_len = DIAG_TYPE_CHN_SIZE;
  1352.                         break;
  1353.                     }//case DIAG_TYPE_CHN:
  1354.                     case DIAG_TYPE_REV:
  1355.                     {
  1356.                         tmp_len = DIAG_TYPE_REV_SIZE;
  1357.                         if( dp_state != DATA_EX )
  1358.                         {
  1359.                             // only allowed in state DATA_EX
  1360.                             ret_value = DP_DIAG_SEQUENCE_ERROR;
  1361.                         }//if( dp_state != DATA_EX )
  1362.                         break;
  1363.                     }//case DIAG_TYPE_REV:
  1364.                     default:
  1365.                     {
  1366.                         //not possible!
  1367.                         ret_value = DP_DIAG_NOT_POSSIBLE_ERROR;
  1368.                         break;
  1369.                     }//default:
  1370.                 }//switch(DIAG_TYPE_MASK & tmp_user_diag.struc_ptr->dev.sign_len )
  1371.                 tmp_user_diag_len      -= tmp_len;
  1372.                 tmp_user_diag.byte_ptr += tmp_len;
  1373.             }//while( (0 < tmp_user_diag_len) && (DP_OK == ret_value) )
  1374.             if( ret_value == DP_OK )
  1375.             {
  1376.                 //copy to diagnosis buffer
  1377.                 //memcpy( dp_sys[dev_num].diag_buf_ptr.byte_ptr+DIAG_NORM_DIAG_SIZE, user_diag.byte_ptr, user_diag_len );
  1378. pBlackfinAddr = (uint16*)dp_sys[dev_num].diag_buf_ptr.byte_ptr;
  1379. pBlackfinAddr = pBlackfinAddr + DIAG_NORM_DIAG_SIZE;
  1380. for (nBlackfinLoop=0; nBlackfinLoop<user_diag_len; nBlackfinLoop++)
  1381. {
  1382. pBlackfinAddr[nBlackfinLoop] = user_diag.byte_ptr[nBlackfinLoop];
  1383. }
  1384.                 dp_sys[dev_num].diag_buf_ptr.byte_ptr = vpc3_set_diag_update_all(dev_num, diag_control, (DIAG_NORM_DIAG_SIZE + user_diag_len) );
  1385.             }//if( ret_value == DP_OK )
  1386.         }//if( ret_value == DP_OK )
  1387.     }//if( dp_sys[dev_num].diag_buf_ptr.byte_ptr != NULL_PTR )
  1388.     else
  1389.     {
  1390. // TRACE("set_diagnosis no diagnosis buffer...");
  1391.         //Fetch new diagnosis buffer
  1392.         dp_sys[dev_num].diag_buf_ptr.byte_ptr = vpc3_get_diagbufptr(dev_num);
  1393.         //wait for next free diag_buffer
  1394.         ret_value = DP_DIAG_NO_BUFFER_ERROR;
  1395.     }//else of if( dp_sys[dev_num].diag_buf_ptr.byte_ptr != NULL_PTR )
  1396.     return ret_value;
  1397. }//DP_ERROR_CODE set_diagnosis(UBYTE dev_num, VPC3_UNION_DIAG_PTR user_diag, UBYTE user_diag_len, UBYTE diag_control, UBYTE check_diag_flag )
  1398. /*-------------------------------------------------------------------*/
  1399. /* function: vpc3_get_free_memory                                    */
  1400. /*-------------------------------------------------------------------*/
  1401. SECTION_DEF_CommuCode VPC3_UNSIGNED8_PTR vpc3_get_free_memory(UBYTE dev_num, UWORD PTR_ATTR *mem_len )
  1402. {
  1403.     //return the address and the number of bytes of unused SPC3-ram
  1404.     if( dp_sys[dev_num].vpc3_used_dp_buf_mem < ASIC_USER_RAM )
  1405.     {
  1406.         *mem_len = ASIC_USER_RAM - dp_sys[dev_num].vpc3_used_dp_buf_mem;
  1407.         return (VPC3_UNSIGNED8_PTR)((VPC3_ADR)(dp_sys[dev_num].vpc3_used_dp_buf_mem + SAP_LENGTH + DP_ORG_LENGTH)*BLACKFIN_MULTIPLER+(VPC3_ADR)VPC3_ASIC_ADDRESS(dev_num));;
  1408.     }
  1409.     else
  1410.     {
  1411.         *mem_len = 0;
  1412.         return NULL_PTR;
  1413.     }
  1414. }//VPC3_UNSIGNED8_PTR vpc3_get_free_memory(UBYTE dev_num, UWORD PTR_ATTR *mem_len )
  1415. /*-------------------------------------------------------------------*/
  1416. /* function: set_alarm                                               */
  1417. /*-------------------------------------------------------------------*/
  1418. SECTION_DEF_CommuCode UBYTE set_alarm(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback  )
  1419. {
  1420.     #ifdef DP_ALARM
  1421.         return set_alarm__(dev_num, user_alarm_ptr, callback );
  1422.     #else
  1423.         user_alarm_ptr = user_alarm_ptr;    //avoid warning
  1424.         callback       = callback;          //avoid warning
  1425.         return SET_ALARM_AL_STATE_CLOSED;
  1426.     #endif
  1427. }//UBYTE set_alarm(UBYTE dev_num, ALARM_STATUS_PDU_PTR user_alarm_ptr, UBYTE callback  )
  1428. /*-------------------------------------------------------------------*/
  1429. /* function: dpv1 statemachines                                      */
  1430. /*-------------------------------------------------------------------*/
  1431. SECTION_DEF_CommuCode void vpc3_dpv1_statemachine(UBYTE dev_num)
  1432. {
  1433.     #ifdef DP_MSAC_C1
  1434.         msac_c1_process(dev_num);    // state machine MSAC_C1
  1435.     #endif
  1436.     #ifdef DP_ALARM
  1437.         alarm_process(dev_num);      // state machine ALARM
  1438.     #endif
  1439.     #ifdef DP_MSAC_C2
  1440.         msac_c2_process(dev_num);    // state machine MSAC_C2
  1441.     #endif
  1442.     #ifdef DP_FDL
  1443.         fdl_cyclic_service(dev_num); // state machine FDL
  1444.     #endif
  1445. }//void vpc3_dpv1_statemachine(UBYTE dev_num)
  1446. /*****************************************************************************/
  1447. /*  Copyright (C) profichip GmbH 2004. Confidential.                         */
  1448. /*****************************************************************************/