📄 userspc3.lst
字号:
400 5 user_diag_flag = FALSE;
401 5
402 5 }
403 4
404 4 dps_chg_diag_srvc_byte_old = dps_chg_diag_srvc_byte_new;
405 4
406 4 }
407 3 }
408 2
409 2
410 2 /*================ Check the buffers and the state =================*/
411 2
412 2 /* Is a new diagnosis buffer available */
413 2 if (DPS2_POLL_IND_DIAG_BUFFER_CHANGED())
414 2 {
415 3 DPS2_CON_IND_DIAG_BUFFER_CHANGED(); /* Confirm the indication */
416 3 user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR(); /* Fetch the pointer */
417 3 user_diag_flag = TRUE; /* Set the Notice "Diag. buffer availble */
418 3 }
419 2
420 2 } /*=== endless loop ===*/
421 1
422 1 return;
423 1
424 1 }
425
426 /* #pragma public */
427
C51 COMPILER V7.50 USERSPC3 10/24/2007 09:35:20 PAGE 8
428
429 /************************************************************************/
430 /* D e s c r i p t i o n : */
431 /* */
432 /* Reset the USER and DPS */
433 /************************************************************************/
434
435
436 void user_dps_reset (void)
437 {
438 1 enum SPC3_INIT_RET dps2_init_result; /* result of the initial. */
439 1
440 1
441 1 DPS2_SET_IDENT_NUMBER_HIGH(ident_numb_high); /* Set the Identnumber */
442 1 DPS2_SET_IDENT_NUMBER_LOW(ident_numb_low);
443 1
444 1 SPC3_SET_STATION_ADDRESS(this_station); /* Set the station address*/
445 1
446 1 SPC3_SET_HW_MODE(SYNC_SUPPORTED | FREEZE_SUPPORTED | INT_POL_LOW | USER_TIMEBASE_10m);
447 1 /* Set div. modes of the */
448 1 /* SPC3 */
449 1 if (!real_no_add_chg)
450 1 {
451 2 DPS2_SET_ADD_CHG_ENABLE(); /* Allow or allow not the */
452 2 } /* address change */
453 1 else
454 1 {
455 2 DPS2_SET_ADD_CHG_DISABLE();
456 2 }
457 1
458 1
459 1 /* initialize the length of the buffers for DPS2_INIT() */
460 1 dps2_buf.din_dout_buf_len = 244;
461 1 dps2_buf.diag_buf_len = sizeof(struct diag_data_blk);
462 1 dps2_buf.prm_buf_len = 20;
463 1 dps2_buf.cfg_buf_len = 10;
464 1
465 1 /* dps2_buf.ssa_buf_len = 5; reserve buffer if address change is possible */
466 1 dps2_buf.ssa_buf_len = 0; /* Suspend the address change service */
467 1 /* No storage in the IM183 is possible */
468 1
469 1
470 1 /* initialize the buffers in the SPC3 */
471 1 dps2_init_result = SPC3_INIT(&dps2_buf);
472 1 if(dps2_init_result != SPC3_INIT_OK)
473 1 { /* Failure */
474 2 for(;;)
475 2 {
476 3 error_code = INIT_ERROR;
477 3 user_error_function(error_code);
478 3 }
479 2 }
480 1
481 1 /* Get a buffer for the first configuration */
482 1 real_config_data_ptr = (UBYTE SPC3_PTR_ATTR*) DPS2_GET_READ_CFG_BUF_PTR();
483 1
484 1 /* Set the length of the configuration data */
485 1 DPS2_SET_READ_CFG_LEN(CFG_LEN);
486 1
487 1 /* Write the configuration bytes in the buffer */
488 1 *(real_config_data_ptr) = CONFIG_DATA_INP; /* Example 0x13 */
489 1 *(real_config_data_ptr + 1) = CONFIG_DATA_OUTP; /* Example 0x23 */
C51 COMPILER V7.50 USERSPC3 10/24/2007 09:35:20 PAGE 9
490 1
491 1 /* Store the actuall configuration in RAM for the check in the
492 1 check_configuration sequence (see the modul intspc3.c) */
493 1 cfg_akt[0] = CONFIG_DATA_INP;
494 1 cfg_akt[1] = CONFIG_DATA_OUTP;
495 1 cfg_len_akt = 2;
496 1
497 1
498 1 /* Calculate the length of the input and output using the configuration bytes*/
499 1 user_io_data_len_ptr = dps2_calculate_inp_outp_len (real_config_data_ptr,(UWORD)CFG_LEN);
500 1 if (user_io_data_len_ptr != (DPS2_IO_DATA_LEN *)0)
501 1 {
502 2 /* Write the IO data length in the init block */
503 2 DPS2_SET_IO_DATA_LEN(user_io_data_len_ptr);
504 2 }
505 1 else
506 1 {
507 2 for(;;)
508 2 {
509 3 error_code =IO_LENGTH_ERROR;
510 3 user_error_function(error_code);
511 3 }
512 2 }
513 1
514 1
515 1 /* Fetch the first input buffer */
516 1 user_input_buffer_ptr = DPS2_GET_DIN_BUF_PTR();
517 1
518 1 /* Fetch the first diagnosis buffer, initialize service bytes */
519 1 dps_chg_diag_srvc_byte_new = dps_chg_diag_srvc_byte_old = 0;
520 1 user_diag_buffer_ptr = DPS2_GET_DIAG_BUF_PTR();
521 1 user_diag_flag = TRUE;
522 1
523 1 /* for info: get the baudrate */
524 1 user_baud_value = SPC3_GET_BAUD();
525 1
526 1 /* Set the Watchdog for the baudrate control */
527 1 SPC3_SET_BAUD_CNTRL(0x1E);
528 1
529 1 /* and finally, at last, los geht's start the SPC3 */
530 1 SPC3_START();
531 1
532 1 }
533
534
535
536
537 /************************************************************************/
538 /* D e s c r i p t i o n : */
539 /* */
540 /* user_error_function */
541 /************************************************************************/
542 void user_error_function(enum ERRORCODES errors)
543 {
544 1 char ch;
545 1 /* An error has occured -> user defined actions */
546 1 /* you can check the error_code */
547 1 ch=errors;
548 1 while (1);
549 1
550 1 }
551
C51 COMPILER V7.50 USERSPC3 10/24/2007 09:35:20 PAGE 10
552
553 /************************************************************************/
554 /* D e s c r i p t i o n : */
555 /* */
556 /* build diagnostics datablock */
557 /* */
558 /* In this EXAMPLE the received user parameter data are copied to */
559 /* the user diagnosis data! */
560 /************************************************************************/
561
562 void build_diag_data_blk (struct diag_data_blk * diag_ptr)
563 {
564 1 diag_ptr -> header = (diag_len - 6); /* subtract the fixed */
565 1 diag_ptr -> ext_diag_0 = prm_tst_buf[0]; /* DP diagnosis */
566 1 diag_ptr -> ext_diag_1 = prm_tst_buf[1];
567 1 diag_ptr -> ext_diag_2 = prm_tst_buf[2];
568 1 diag_ptr -> ext_diag_3 = prm_tst_buf[3];
569 1 diag_ptr -> ext_diag_4 = prm_tst_buf[4];
570 1 diag_ptr -> ext_diag_5 = prm_tst_buf[5];
571 1 diag_ptr -> ext_diag_6 = prm_tst_buf[6];
572 1 diag_ptr -> ext_diag_7 = prm_tst_buf[7];
573 1 diag_ptr -> ext_diag_8 = prm_tst_buf[8];
574 1 diag_ptr -> ext_diag_9 = prm_tst_buf[9];
575 1 diag_ptr -> ext_diag_10 = prm_tst_buf[10];
576 1 diag_ptr -> ext_diag_11 = prm_tst_buf[11];
577 1 diag_ptr -> ext_diag_12 = prm_tst_buf[12];
578 1 diag_ptr -> ext_diag_13 = 0;
579 1 diag_ptr -> ext_diag_14 = 0;
580 1 diag_ptr -> ext_diag_15 = 0;
581 1 diag_ptr -> ext_diag_16 = 0;
582 1 diag_ptr -> ext_diag_17 = 0;
583 1 }
584
585
586
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 1285 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 90 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 + -