📄 userspc3 0810.lst
字号:
430 5 /* Write the external diagnosis data to the SPC3 */
431 5 build_diag_data_blk((struct diag_data_blk *)user_diag_buffer_ptr);
432 5 /*build_diag_data_blk函数见本文件尾*/
433 5 /* Set the service code;设置诊断服务码 */
434 5 /* 0x01 External diagnosis */
435 5 /* 0x02 Static diagnosis */
436 5 /* 0x04 External diagnosis Overflow;后三位表征/*
437 5 DPS2_SET_DIAG_STATE(diag_service_code);
438 5 /* Trigger the diagnosis update in the SPC3*/
439 5 DPS2_DIAG_UPDATE(); /*$ 漏了一段?*/
440 5 /*#define DPS2_DIAG_UPDATE() dps2_diag_update() 见.CP14*/
441 5 /* Store "no diagnosis buffer available" */
442 5 user_diag_flag = FALSE;/* Set the Notice "Diag. buffer NOT availble*/
443 5
444 5 }
445 4
446 4 dps_chg_diag_srvc_byte_old = dps_chg_diag_srvc_byte_new;
447 4
448 4 }
449 3 }
450 2
451 2
452 2 /*================ Check the buffers and the state =================*/
453 2
454 2 /* Is a new diagnosis buffer available */
455 2 if (DPS2_POLL_IND_DIAG_BUFFER_CHANGED()) /* 见.Hp8 */
456 2 {
457 3 DPS2_CON_IND_DIAG_BUFFER_CHANGED(); /* Confirm the indication;.Hp8 */
458 3 user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR(); /* Fetch the pointer;.Hp9*/
459 3 user_diag_flag = TRUE; /* Set the Notice "Diag. buffer availble */
460 3 }
461 2
462 2 } /*=== endless loop ===*/
463 1
464 1 return;
465 1
466 1 }
467
468 /* #pragma public */
469
470 /************************************************************************/
471 /* D e s c r i p t i o n : */
472 /* */
473 /* Reset the USER and DPS */
474 /************************************************************************/
475
476
477 void user_dps_reset (void)
478 {
479 1 enum SPC3_INIT_RET dps2_init_result; /* result of the initial. */
480 1 /*见 .Hp3 有SPC3_INIT_RET枚举类型的定义;表征*/
481 1
482 1 DPS2_SET_IDENT_NUMBER_HIGH(ident_numb_high); /* Set the Identnumber */
483 1 DPS2_SET_IDENT_NUMBER_LOW(ident_numb_low);
484 1
485 1 SPC3_SET_STATION_ADDRESS(this_station); /* Set the station address .Hp8 */
486 1
487 1 SPC3_SET_HW_MODE(SYNC_SUPPORTED | FREEZE_SUPPORTED | INT_POL_LOW | USER_TIMEBASE_10m);
C51 COMPILER V7.02b USERSPC3_0810 11/01/2004 20:51:05 PAGE 9
488 1 /*设置HW_MODE ;Set div. modes of the;PDF19 */
489 1 /*Mode-Register 0的各位 ; SPC3 见PDF68和.Hp7 */
490 1 if (!real_no_add_chg) /*real_no_add_chg; 站地址可变设置 */
491 1 {
492 2 DPS2_SET_ADD_CHG_ENABLE(); /* Allow or allow not the */
493 2 } /* address change;站地址可变性设置 */
494 1 else
495 1 {
496 2 DPS2_SET_ADD_CHG_DISABLE();
497 2 }
498 1
499 1
500 1 /* initialize the length of the buffers for DPS2_INIT() */
501 1 /*-- 见 DPS2-Buffer-Initialization 结构体定义 .Hp4*/
502 1 dps2_buf.din_dout_buf_len = 244;
503 1 dps2_buf.diag_buf_len = sizeof(struct diag_data_blk);
504 1 dps2_buf.prm_buf_len = 20;
505 1 dps2_buf.cfg_buf_len = 10;
506 1
507 1 dps2_buf.ssa_buf_len = 5; /* reserve buffer if address change is possible $*可选/
508 1 /* dps2_buf.ssa_buf_len = 0; Suspend 中止the address change service */
509 1 /* No storage in the IM183 is possible */
510 1
511 1 /* initialize the buffers in the SPC3;初始化SPC3的BUF */
512 1 /*dps2_buf是DPS2_BUFINIT结构体, .Hp*/
513 1 dps2_init_result = SPC3_INIT(&dps2_buf);
514 1 /*dps2_init_result是SPC3_INIT_RET枚举类型 .Hp3 ; */
515 1 /*SPC3_INIT()函数见.Hp8及 .Cp8;即调用dps_buf_init */
516 1
517 1 if(dps2_init_result != SPC3_INIT_OK) /* buf初始化成功? */
518 1 { /* Failure */
519 2 for(;;)
520 2 {
521 3 error_code = INIT_ERROR;
522 3 user_error_function(error_code); /* 见本.U */
523 3
524 3 }
525 2 }
526 1
527 1 /* 组态数据初始化:Get a buffer for the first configuration;为首次组态获得一个buf */
528 1 real_config_data_ptr = (UBYTE SPC3_PTR_ATTR*) DPS2_GET_READ_CFG_BUF_PTR();/* 见.Hp9 */
529 1
530 1 /* Set the length of the configuration data;设置组态数据长度 见.Hp9 */
531 1 DPS2_SET_READ_CFG_LEN(CFG_LEN);
532 1
533 1 /* Write the configuration bytes in the buffer;往buf写组态数据 */
534 1 *(real_config_data_ptr) = CONFIG_DATA_INP; /* $ Example 0x15 */
535 1 *(real_config_data_ptr + 1) = CONFIG_DATA_OUTP; /* $ Example 0x25 */
536 1
537 1 /* Store the actuall configuration in RAM for the check in the check_configuration
538 1 sequence (see the modul intspc3.c);存组态以备检查 */
539 1 cfg_akt[0] = CONFIG_DATA_INP;
540 1 cfg_akt[1] = CONFIG_DATA_OUTP;
541 1 cfg_len_akt = 2;
542 1
543 1 /*根据特定组态数据计算I/O数据长度,(不是IO buf长度)算出长度指针#*/
544 1 /* Calculate the length of the input and output using the configuration bytes*/
545 1 user_io_data_len_ptr=dps2_calculate_inp_outp_len(real_config_data_ptr,(UWORD)CFG_LEN);/*.Cp5;user_io_data_
-len_ptr 已定义全局变量*/
546 1 if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0) /* 返回指针不为零吗?*/
547 1 { /* 非零 */
548 2
C51 COMPILER V7.02b USERSPC3_0810 11/01/2004 20:51:05 PAGE 10
549 2 /* Write the IO data length in the init block */
550 2
551 2 DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);/* 见.CP12 */
552 2 }
553 1 else /* I/O数据长度出错处理 */
554 1 {
555 2 for(;;)
556 2 {
557 3 error_code =IO_LENGTH_ERROR;
558 3 user_error_function(error_code);
559 3 }
560 2 }
561 1
562 1 /* 初始化输入buf指、针诊断buf指针、诊断服务字节*/
563 1 /* Fetch the first input buffer;取第一个输入buf指针 */
564 1 user_input_buffer_ptr = DPS2_GET_DIN_BUF_PTR();/* .HP10 */
565 1
566 1 /* Fetch the first diagnosis buffer, initialize service bytes;取第一个诊断buf,初始化服务字节 */
567 1 dps_chg_diag_srvc_byte_new = dps_chg_diag_srvc_byte_old = 0;
568 1 user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR(); /* 见.Hp9 */
569 1 user_diag_flag = TRUE;
570 1
571 1 /* for info: get the baudrate;得到波特率 */
572 1 user_baud_value = SPC3_GET_BAUD();/*.P1 */
573 1
574 1 /* Set the Watchdog for the baudrate control;为波特率控制设定看门狗
575 1 SPC3_SET_BAUD_CNTRL(0x1E); /*.P1 */
576 1
577 1 /* and finally, at last, los geht's start the SPC3;启动SPC3 */
578 1 SPC3_START();/* .Hp8 */
579 1
580 1 }
581
582
583 /************************************************************************/
584 /* D e s c r i p t i o n : */
585 /* */
586 /* user_error_function */
587 /************************************************************************/
588 void user_error_function(enum ERRORCODES errors)
589 {
590 1 char ch;
591 1 /* An error has occured -> user defined actions */
592 1 /* you can check the error_code */
593 1 ch=errors;
594 1 while (1);
595 1
596 1 }
597
598
599 /************************************************************************/
600 /* D e s c r i p t i o n : */
601 /* */
602 /* build diagnostics datablock */
603 /* 建立诊断数据; 本例中把用户参数复制到用户诊断数据 */
604 /* In this EXAMPLE the received user parameter data are copied to */
605 /* the user diagnosis data! */
606 /************************************************************************/
607
608 void build_diag_data_blk (struct diag_data_blk * diag_ptr)
609 {
610 1 diag_ptr -> header = (diag_len - 6); /* subtract the fixed */
C51 COMPILER V7.02b USERSPC3_0810 11/01/2004 20:51:05 PAGE 11
611 1 diag_ptr -> ext_diag_0 = prm_tst_buf[0]; /* DP diagnosis */
612 1 diag_ptr -> ext_diag_1 = prm_tst_buf[1];
613 1 diag_ptr -> ext_diag_2 = prm_tst_buf[2];
614 1 diag_ptr -> ext_diag_3 = prm_tst_buf[3];
615 1 diag_ptr -> ext_diag_4 = prm_tst_buf[4];
616 1 diag_ptr -> ext_diag_5 = prm_tst_buf[5];
617 1 diag_ptr -> ext_diag_6 = prm_tst_buf[6];
618 1 diag_ptr -> ext_diag_7 = prm_tst_buf[7];
619 1 diag_ptr -> ext_diag_8 = prm_tst_buf[8];
620 1 diag_ptr -> ext_diag_9 = prm_tst_buf[9];
621 1 diag_ptr -> ext_diag_10 = prm_tst_buf[10];
622 1 diag_ptr -> ext_diag_11 = prm_tst_buf[11];
623 1 diag_ptr -> ext_diag_12 = prm_tst_buf[12];
624 1 diag_ptr -> ext_diag_13 = 0;
625 1 diag_ptr -> ext_diag_14 = 0;
626 1 diag_ptr -> ext_diag_15 = 0;
627 1 diag_ptr -> ext_diag_16 = 0;
628 1 diag_ptr -> ext_diag_17 = 0;
629 1 }
630
631
632
633
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1398 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 95 1
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -