Revision d54d2f07 Host/Source/SerialBoot/xcpmaster.c
Host/Source/SerialBoot/xcpmaster.c | ||
---|---|---|
23 | 23 |
* You should have received a copy of the GNU General Public License along with OpenBLT. |
24 | 24 |
* If not, see <http://www.gnu.org/licenses/>. |
25 | 25 |
* |
26 |
* A special exception to the GPL is included to allow you to distribute a combined work
|
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any
|
|
26 |
* A special exception to the GPL is included to allow you to distribute a combined work |
|
27 |
* that includes OpenBLT without being obliged to provide the source code for any |
|
28 | 28 |
* proprietary components. The exception text is included at the bottom of the license |
29 | 29 |
* file <license.html>. |
30 |
*
|
|
30 |
* |
|
31 | 31 |
* \endinternal |
32 | 32 |
****************************************************************************************/ |
33 | 33 |
|
... | ... | |
91 | 91 |
/**************************************************************************************** |
92 | 92 |
* Function prototypes |
93 | 93 |
****************************************************************************************/ |
94 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID);
|
|
94 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID);
|
|
95 | 95 |
static sb_uint8 XcpMasterSendCmdSetMta(sb_uint32 address); |
96 | 96 |
static sb_uint8 XcpMasterSendCmdUpload(sb_uint8 data[], sb_uint8 length); |
97 | 97 |
static sb_uint8 XcpMasterSendCmdProgramStart(void); |
... | ... | |
155 | 155 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
156 | 156 |
** |
157 | 157 |
****************************************************************************************/ |
158 |
sb_uint8 XcpMasterConnect(sb_uint8 flashingTargetID)
|
|
158 |
sb_uint8 XcpMasterConnect(sb_uint32 flashingTargetID)
|
|
159 | 159 |
{ |
160 | 160 |
sb_uint8 cnt; |
161 | 161 |
sb_uint8 retries = 1; |
162 | 162 |
if (flashingTargetID <= 0) { |
163 | 163 |
retries = XCP_MASTER_CONNECT_RETRIES; |
164 | 164 |
} |
165 |
|
|
165 |
|
|
166 | 166 |
/* try to connect with a finite amount of retries */ |
167 | 167 |
for (cnt=0; cnt<retries; cnt++) |
168 | 168 |
{ |
... | ... | |
357 | 357 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
358 | 358 |
** |
359 | 359 |
****************************************************************************************/ |
360 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint8 flashingTargetID)
|
|
360 |
static sb_uint8 XcpMasterSendCmdConnect(sb_uint32 flashingTargetID)
|
|
361 | 361 |
{ |
362 |
sb_uint8 packetData[2];
|
|
362 |
sb_uint8 packetData[1+4];
|
|
363 | 363 |
tXcpTransportResponsePacket *responsePacketPtr; |
364 |
|
|
364 |
|
|
365 | 365 |
/* prepare the command packet */ |
366 | 366 |
packetData[0] = XCP_MASTER_CMD_CONNECT; |
367 |
packetData[1] = flashingTargetID; /* normal mode */ |
|
368 |
|
|
369 |
/* send the packet */ |
|
370 |
if (XcpTransportSendPacket(packetData, 2, XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE) |
|
367 |
packetData[1] = (sb_uint8)(0xFF & flashingTargetID >> 0); |
|
368 |
packetData[2] = (sb_uint8)(0xFF & flashingTargetID >> 8); |
|
369 |
packetData[3] = (sb_uint8)(0xFF & flashingTargetID >> 16); |
|
370 |
packetData[4] = (sb_uint8)(0xFF & flashingTargetID >> 24); |
|
371 |
|
|
372 |
/* send the packet |
|
373 |
* NOTE: For legacy support the following code depends on the MSB if the flashingTargetID. |
|
374 |
* If the MSB (packData[4]) is zero (i.e. 0x00??????) the system switches to legacy mode. |
|
375 |
* In legacy mode, the flashingTargetID was only one byte - the LSB (packingData[1]). |
|
376 |
*/ |
|
377 |
if (XcpTransportSendPacket(packetData, 1 + ((packetData[4] != 0) ? 4 : 1), XCP_MASTER_CONNECT_TIMEOUT_MS) == SB_FALSE) |
|
371 | 378 |
{ |
372 | 379 |
/* cound not set packet or receive response within the specified timeout */ |
373 | 380 |
return SB_FALSE; |
374 | 381 |
} |
375 | 382 |
/* still here so a response was received */ |
376 | 383 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
377 |
|
|
384 |
|
|
378 | 385 |
/* check if the reponse was valid */ |
379 | 386 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
380 | 387 |
{ |
381 | 388 |
/* not a valid or positive response */ |
382 | 389 |
return SB_FALSE; |
383 | 390 |
} |
384 |
|
|
391 |
|
|
385 | 392 |
/* process response data */ |
386 | 393 |
if ((responsePacketPtr->data[2] & 0x01) == 0) |
387 | 394 |
{ |
... | ... | |
400 | 407 |
{ |
401 | 408 |
xcpMaxDto = responsePacketPtr->data[5] + (responsePacketPtr->data[4] << 8); |
402 | 409 |
} |
403 |
|
|
410 |
|
|
404 | 411 |
/* double check size configuration of the master */ |
405 | 412 |
assert(XCP_MASTER_TX_MAX_DATA >= xcpMaxCto); |
406 | 413 |
assert(XCP_MASTER_RX_MAX_DATA >= xcpMaxDto); |
407 |
|
|
408 |
/* still here so all went well */
|
|
414 |
|
|
415 |
/* still here so all went well */ |
|
409 | 416 |
return SB_TRUE; |
410 | 417 |
} /*** end of XcpMasterSendCmdConnect ***/ |
411 | 418 |
|
... | ... | |
420 | 427 |
{ |
421 | 428 |
sb_uint8 packetData[8]; |
422 | 429 |
tXcpTransportResponsePacket *responsePacketPtr; |
423 |
|
|
430 |
|
|
424 | 431 |
/* prepare the command packet */ |
425 | 432 |
packetData[0] = XCP_MASTER_CMD_SET_MTA; |
426 | 433 |
packetData[1] = 0; /* reserved */ |
427 | 434 |
packetData[2] = 0; /* reserved */ |
428 | 435 |
packetData[3] = 0; /* address extension not supported */ |
429 |
|
|
436 |
|
|
430 | 437 |
/* set the address taking into account byte ordering */ |
431 | 438 |
XcpMasterSetOrderedLong(address, &packetData[4]); |
432 |
|
|
439 |
|
|
433 | 440 |
/* send the packet */ |
434 | 441 |
if (XcpTransportSendPacket(packetData, 8, XCP_MASTER_TIMEOUT_T4_MS) == SB_FALSE) //XCP_MASTER_TIMEOUT_T1_MS |
435 | 442 |
{ |
... | ... | |
439 | 446 |
} |
440 | 447 |
/* still here so a response was received */ |
441 | 448 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
442 |
|
|
449 |
|
|
443 | 450 |
/* check if the reponse was valid */ |
444 | 451 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
445 | 452 |
{ |
... | ... | |
452 | 459 |
printf(" (set MTA)\n"); |
453 | 460 |
return SB_FALSE; |
454 | 461 |
} |
455 |
|
|
456 |
/* still here so all went well */
|
|
462 |
|
|
463 |
/* still here so all went well */ |
|
457 | 464 |
return SB_TRUE; |
458 | 465 |
} /*** end of XcpMasterSendCmdSetMta ***/ |
459 | 466 |
|
... | ... | |
470 | 477 |
sb_uint8 packetData[2]; |
471 | 478 |
tXcpTransportResponsePacket *responsePacketPtr; |
472 | 479 |
sb_uint8 data_index; |
473 |
|
|
480 |
|
|
474 | 481 |
/* cannot request more data then the max rx data - 1 */ |
475 | 482 |
assert(length < XCP_MASTER_RX_MAX_DATA); |
476 |
|
|
483 |
|
|
477 | 484 |
/* prepare the command packet */ |
478 | 485 |
packetData[0] = XCP_MASTER_CMD_UPLOAD; |
479 | 486 |
packetData[1] = length; |
... | ... | |
487 | 494 |
} |
488 | 495 |
/* still here so a response was received */ |
489 | 496 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
490 |
|
|
497 |
|
|
491 | 498 |
/* check if the reponse was valid */ |
492 | 499 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
493 | 500 |
{ |
... | ... | |
500 | 507 |
printf(" (upload)\n"); |
501 | 508 |
return SB_FALSE; |
502 | 509 |
} |
503 |
|
|
510 |
|
|
504 | 511 |
/* now store the uploaded data */ |
505 | 512 |
for (data_index=0; data_index<length; data_index++) |
506 | 513 |
{ |
507 | 514 |
data[data_index] = responsePacketPtr->data[data_index+1]; |
508 | 515 |
} |
509 |
|
|
510 |
/* still here so all went well */
|
|
516 |
|
|
517 |
/* still here so all went well */ |
|
511 | 518 |
return SB_TRUE; |
512 | 519 |
} /*** end of XcpMasterSendCmdUpload ***/ |
513 | 520 |
|
... | ... | |
534 | 541 |
} |
535 | 542 |
/* still here so a response was received */ |
536 | 543 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
537 |
|
|
544 |
|
|
538 | 545 |
/* check if the reponse was valid */ |
539 | 546 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
540 | 547 |
{ |
... | ... | |
547 | 554 |
printf(" (program start)\n"); |
548 | 555 |
return SB_FALSE; |
549 | 556 |
} |
550 |
|
|
557 |
|
|
551 | 558 |
/* store max number of bytes the slave allows for master->slave packets during the |
552 | 559 |
* programming session |
553 | 560 |
*/ |
554 | 561 |
xcpMaxProgCto = responsePacketPtr->data[3]; |
555 |
|
|
556 |
/* still here so all went well */
|
|
562 |
|
|
563 |
/* still here so all went well */ |
|
557 | 564 |
return SB_TRUE; |
558 | 565 |
} /*** end of XcpMasterSendCmdProgramStart ***/ |
559 | 566 |
|
... | ... | |
579 | 586 |
} |
580 | 587 |
/* still here so a response was received */ |
581 | 588 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
582 |
|
|
589 |
|
|
583 | 590 |
/* check if the reponse was valid */ |
584 | 591 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
585 | 592 |
{ |
586 | 593 |
/* not a valid or positive response */ |
587 | 594 |
return SB_FALSE; |
588 | 595 |
} |
589 |
|
|
590 |
/* still here so all went well */
|
|
596 |
|
|
597 |
/* still here so all went well */ |
|
591 | 598 |
return SB_TRUE; |
592 | 599 |
} /*** end of XcpMasterSendCmdProgramStart ***/ |
593 | 600 |
|
594 | 601 |
|
595 | 602 |
/************************************************************************************//** |
596 |
** \brief Sends the XCP PROGRAM RESET command. Note that this command is a bit
|
|
603 |
** \brief Sends the XCP PROGRAM RESET command. Note that this command is a bit |
|
597 | 604 |
** different as in it does not require a response. |
598 | 605 |
** \return SB_TRUE is successfull, SB_FALSE otherwise. |
599 | 606 |
** |
... | ... | |
626 | 633 |
|
627 | 634 |
// /* still here so a response was received */ |
628 | 635 |
// responsePacketPtr = XcpTransportReadResponsePacket(); |
629 |
//
|
|
636 |
// |
|
630 | 637 |
// /* check if the reponse was valid */ |
631 | 638 |
// printf("response not valid\nlength: %u\nresponse: %i", responsePacketPtr->len, *(responsePacketPtr->data)); |
632 | 639 |
// if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
... | ... | |
635 | 642 |
// return SB_FALSE; |
636 | 643 |
// } |
637 | 644 |
|
638 |
|
|
639 |
/* still here so all went well */
|
|
645 |
|
|
646 |
/* still here so all went well */ |
|
640 | 647 |
return SB_TRUE; |
641 | 648 |
} /*** end of XcpMasterSendCmdProgramReset ***/ |
642 | 649 |
|
... | ... | |
653 | 660 |
sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA]; |
654 | 661 |
tXcpTransportResponsePacket *responsePacketPtr; |
655 | 662 |
sb_uint8 cnt; |
656 |
|
|
663 |
|
|
657 | 664 |
/* verify that this number of bytes actually first in this command */ |
658 | 665 |
assert(length <= (xcpMaxProgCto-2) && (xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA)); |
659 |
|
|
666 |
|
|
660 | 667 |
/* prepare the command packet */ |
661 | 668 |
packetData[0] = XCP_MASTER_CMD_PROGRAM; |
662 | 669 |
packetData[1] = length; |
... | ... | |
674 | 681 |
} |
675 | 682 |
/* still here so a response was received */ |
676 | 683 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
677 |
|
|
684 |
|
|
678 | 685 |
/* check if the reponse was valid */ |
679 | 686 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
680 | 687 |
{ |
... | ... | |
687 | 694 |
printf(" (program)\n"); |
688 | 695 |
return SB_FALSE; |
689 | 696 |
} |
690 |
|
|
691 |
/* still here so all went well */
|
|
697 |
|
|
698 |
/* still here so all went well */ |
|
692 | 699 |
return SB_TRUE; |
693 | 700 |
} /*** end of XcpMasterSendCmdProgram ***/ |
694 | 701 |
|
... | ... | |
704 | 711 |
sb_uint8 packetData[XCP_MASTER_TX_MAX_DATA]; |
705 | 712 |
tXcpTransportResponsePacket *responsePacketPtr; |
706 | 713 |
sb_uint8 cnt; |
707 |
|
|
714 |
|
|
708 | 715 |
/* verify that this number of bytes actually first in this command */ |
709 | 716 |
assert(xcpMaxProgCto <= XCP_MASTER_TX_MAX_DATA); |
710 |
|
|
717 |
|
|
711 | 718 |
/* prepare the command packet */ |
712 | 719 |
packetData[0] = XCP_MASTER_CMD_PROGRAM_MAX; |
713 | 720 |
for (cnt=0; cnt<(xcpMaxProgCto-1); cnt++) |
... | ... | |
724 | 731 |
} |
725 | 732 |
/* still here so a response was received */ |
726 | 733 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
727 |
|
|
734 |
|
|
728 | 735 |
/* check if the reponse was valid */ |
729 | 736 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
730 | 737 |
{ |
... | ... | |
737 | 744 |
printf(" (program max)\n"); |
738 | 745 |
return SB_FALSE; |
739 | 746 |
} |
740 |
|
|
741 |
/* still here so all went well */
|
|
747 |
|
|
748 |
/* still here so all went well */ |
|
742 | 749 |
return SB_TRUE; |
743 | 750 |
} /*** end of XcpMasterSendCmdProgramMax ***/ |
744 | 751 |
|
... | ... | |
772 | 779 |
} |
773 | 780 |
/* still here so a response was received */ |
774 | 781 |
responsePacketPtr = XcpTransportReadResponsePacket(); |
775 |
|
|
782 |
|
|
776 | 783 |
/* check if the reponse was valid */ |
777 | 784 |
if ( (responsePacketPtr->len == 0) || (responsePacketPtr->data[0] != XCP_MASTER_CMD_PID_RES) ) |
778 | 785 |
{ |
... | ... | |
785 | 792 |
printf(" (program clear)\n"); |
786 | 793 |
return SB_FALSE; |
787 | 794 |
} |
788 |
|
|
789 |
/* still here so all went well */
|
|
795 |
|
|
796 |
/* still here so all went well */ |
|
790 | 797 |
return SB_TRUE; |
791 | 798 |
} /*** end of XcpMasterSendCmdProgramClear ***/ |
792 | 799 |
|
Also available in: Unified diff