dps2spc3.lst

来自「使用8052单片机控制SPC3总线桥实现PROFIBUS-DP现场总线的从站部分」· LST 代码 · 共 898 行 · 第 1/4 页

LST
898
字号
 211   2                       aux_len[0] = 0;
 212   2      
 213   2                       for(i = step; i < count; i++)
 214   2                       {
 215   3                              if(aux_len[0] < lensx[i])
 216   3                              {
 217   4                                 aux_len[0] = lensx[i];
 218   4                              }
 219   3                       }
 220   2                       aux_len[0] = aux_len[0] * (count - step + 1);
 221   2                       /* determine total len for AUX-buffer 2 */
 222   2                       aux_len[1] = 0;
 223   2      
 224   2                       for(i = 0; i < step; i++)
 225   2                       {
 226   3                              if(aux_len[1] < lensx[i])
 227   3                              {
 228   4                                 aux_len[1] = lensx[i];
 229   4                              }
 230   3                       }
 231   2                       aux_len[1] = aux_len[1] * (step + 1);
 232   2      
 233   2                       if((aux_len[0] + aux_len[1]) < min_len)
 234   2                       {
 235   3                              /* neue Minimal-Laenge gefunden */
 236   3                              min_len = aux_len[0] + aux_len[1];
 237   3                              min_step = step;
 238   3                       }
 239   2                }
 240   1      
 241   1                /*  calculation of len for AUX-buffer 1 */
C51 COMPILER V7.50   DPS2SPC3                                                              10/24/2007 09:35:19 PAGE 5   

 242   1                aux_len[0] = 0;
 243   1      
 244   1                for(i = min_step; i < count; i++)
 245   1                {
 246   2                       if(aux_len[0] < lensx[i])
 247   2                       {
 248   3                              aux_len[0] = lensx[i];
 249   3                       }
 250   2                }
 251   1                /*  setup lens for AUX-buffer 1 */
 252   1                for(i = min_step; i < count; i++)
 253   1                {
 254   2                       lens[pos[i]] = aux_len[0];
 255   2                }
 256   1                /*  calculation of len for AUX-buffer 2 */
 257   1                aux_len[1] = 0;
 258   1      
 259   1                for(i = 0; i < min_step; i++)
 260   1                {
 261   2                       if(aux_len[1] < lensx[i])
 262   2                       {
 263   3                              aux_len[1] = lensx[i];
 264   3                       }
 265   2                }
 266   1                /*  setup lens for AUX-buffer 2 */
 267   1                /*  setup assignment-list */
 268   1                *assign = 0;    /* initial all buffers assigned to AUX-buffer 1 */
 269   1      
 270   1                for(i = 0; i < min_step; i++)
 271   1                {
 272   2                       lens[pos[i]] = aux_len[1];
 273   2                       *assign |= 0x1 << pos[i];
 274   2                }
 275   1                return min_len;
 276   1         }
 277             /* Ende assign_aux_buf */
 278          
 279          #ifdef _C166
                #pragma global
              #endif
 282          
 283          /*~
 284          dps2_calculate_inp_outp_len()
 285          ~*/
 286             /*
 287             +------------------------------------------------------------------------+
 288             | Funktion:  d p s 2 _ c a l c u l a t e _ i n p _ o u t p _ l e n       |
 289             +------------------------------------------------------------------------+
 290             | Description:                                                           |
 291             |  This function calculates the Input/Outputdata-lens based on the       |
 292             |  specified config-data and returns a pointer to the calculated lens.   |
 293             |  (original from DPS).                                                  |
 294             +------------------------------------------------------------------------+
 295             | parameters:                                                            |
 296             |  -cfg_ptr: pointer to config-data                                      |
 297             |  -cfg_len: config-data len                                             |
 298             |                                                                        |
 299             | returnvalue:                                                           |
 300             |  -pointer to lens                                                      |
 301             +------------------------------------------------------------------------+
 302             */
 303             DPS2_IO_DATA_LEN SPC3_DATA_ATTR *dps2_calculate_inp_outp_len(UBYTE SPC3_PTR_ATTR* cfg_ptr, UWORD cfg_le
C51 COMPILER V7.50   DPS2SPC3                                                              10/24/2007 09:35:19 PAGE 6   

             -n)  reentrant
 304             {
 305   1                UBYTE temp_inp_data_len;
 306   1                UBYTE temp_outp_data_len;
 307   1                UBYTE length;
 308   1                UBYTE count;
 309   1                UBYTE specific_data_length;
 310   1                UBYTE result_ok;
 311   1                result_ok = TRUE;
 312   1                temp_inp_data_len  = 0;
 313   1                temp_outp_data_len = 0;
 314   1      
 315   1                if ((cfg_len >  0) && (cfg_len <= dps2_binit.cfg_buf_len))
 316   1                {
 317   2                       for ( ; (cfg_len > 0) && result_ok; cfg_len -= count)
 318   2                       {
 319   3                              count = 0;
 320   3      
 321   3                              if (*cfg_ptr & DPS_CFG_IS_BYTE_FORMAT)
 322   3                              {
 323   4                                 count++;
 324   4      
 325   4                                 /* cfg_ptr points to ID-byte, CFG_BF means "CFG_IS_BYTE_FORMAT" */
 326   4                                 length = (UBYTE)( (*cfg_ptr & DPS_CFG_BF_LENGTH) + 1);
 327   4      
 328   4                                 if (*cfg_ptr & DPS_CFG_LENGTH_IS_WORD_FORMAT)
 329   4                                 {
 330   5                                        length *= 2;
 331   5                                 }
 332   4                                 if (*cfg_ptr & DPS_CFG_BF_OUTP_EXIST)
 333   4                                 {
 334   5                                        temp_outp_data_len = temp_outp_data_len + length;
 335   5                                 }
 336   4                                 if (*cfg_ptr & DPS_CFG_BF_INP_EXIST)
 337   4                                 {
 338   5                                        temp_inp_data_len = temp_inp_data_len + length;
 339   5                                 }
 340   4                                 cfg_ptr++;
 341   4                              }
 342   3                              else
 343   3                              {
 344   4                                 /* cfg_ptr points to the headerbyte of special ID-format */
 345   4                                 /* CFG_SF means "CFG_IS_SPECIAL_FORMAT" */
 346   4                                 if (*cfg_ptr & DPS_CFG_SF_OUTP_EXIST)
 347   4                                 {
 348   5                                        count++;                /* next byte contains the length of ou
 349   5                                                                                        tp_data */
 350   5                                        length = (UBYTE)((*(cfg_ptr + count) & DPS_CFG_SF_LENGTH) +1
 351   5                                        );
 352   5      
 353   5                                        if (*(cfg_ptr + count) & DPS_CFG_LENGTH_IS_WORD_FORMAT)
 354   5                                        {
 355   6                                               temp_outp_data_len = temp_outp_data_len + (UBYTE)(2*length
 356   6                                               );
 357   6                                        }
 358   5                                        else
 359   5                                        {
 360   6                                               temp_outp_data_len = temp_outp_data_len + length;
 361   6                                        }
 362   5                                 }
 363   4                                 if (*cfg_ptr & DPS_CFG_SF_INP_EXIST)
 364   4                                 {
C51 COMPILER V7.50   DPS2SPC3                                                              10/24/2007 09:35:19 PAGE 7   

 365   5                                        count++;                /* next byte contains the length of in
 366   5                                                                                        p_data */
 367   5                                        length = (UBYTE)((*(cfg_ptr + count) & DPS_CFG_SF_LENGTH) +1
 368   5                                        );
 369   5      
 370   5                                        if (*(cfg_ptr + count) & DPS_CFG_LENGTH_IS_WORD_FORMAT)
 371   5                                        {
 372   6                                               temp_inp_data_len = temp_inp_data_len + (UBYTE)(2*length);
 373   6                                        }
 374   5                                        else
 375   5                                        {
 376   6                                               temp_inp_data_len = temp_inp_data_len + length;
 377   6                                        }
 378   5                                 }
 379   4                                 specific_data_length = (UBYTE)(*cfg_ptr & DPS_CFG_BF_LENGTH);
 380   4      
 381   4                                 if (specific_data_length != 15)
 382   4                                 {
 383   5                                        count = (UBYTE)(count + 1 + specific_data_length);
 384   5                                        cfg_ptr = cfg_ptr + count;
 385   5                                 }
 386   4                                 else
 387   4                                 {
 388   5                                        result_ok = FALSE;
 389   5                                 }
 390   4                              }
 391   3                       }
 392   2      
 393   2                       if ( (cfg_len != 0) ||
 394   2                                      (
 395   2                                      (((UWORD)temp_inp_data_len + 7) & 0xfff8 +
 396   2                                      ((UWORD)temp_outp_data_len + 7) & 0xfff8)
 397   2                                      > dps2_binit.din_dout_buf_len) )
 398   2                       {
 399   3                              result_ok = FALSE;
 400   3               }
 401   2                }
 402   1                else
 403   1                {
 404   2                       result_ok = FALSE;
 405   2                }
 406   1                if (result_ok)
 407   1                {
 408   2                       io_data_len.inp_data_len  = temp_inp_data_len;
 409   2                       io_data_len.outp_data_len = temp_outp_data_len;
 410   2                       return (&io_data_len);
 411   2                }
 412   1                else
 413   1                {
 414   2                       return ((DPS2_IO_DATA_LEN *) 0);
 415   2                }
 416   1         }
 417          
 418          /*~
 419          dps2_buf_init()
 420          ~*/
 421             /*
 422             +------------------------------------------------------------------------+
 423             | Function:  d p s 2 _ b u f _ i n i t ( )                               |
 424             +------------------------------------------------------------------------+
 425             | Description:                                                           |
 426             |  The specified lens arechecked. If they are ok, the neccesarry         |
C51 COMPILER V7.50   DPS2SPC3                                                              10/24/2007 09:35:19 PAGE 8   

⌨️ 快捷键说明

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