* Helper function - scan for 32 bits of LSS address, one by one */
| 713 | * Helper function - scan for 32 bits of LSS address, one by one |
| 714 | */ |
| 715 | static CO_LSSmaster_return_t |
| 716 | CO_LSSmaster_FsScanWait(CO_LSSmaster_t* LSSmaster, uint32_t timeDifference_us, CO_LSSmaster_scantype_t scan) { |
| 717 | CO_LSSmaster_return_t ret; |
| 718 | |
| 719 | switch (scan) { |
| 720 | case CO_LSSmaster_FS_SCAN: break; |
| 721 | case CO_LSSmaster_FS_MATCH: |
| 722 | /* No scanning requested */ |
| 723 | return CO_LSSmaster_SCAN_FINISHED; |
| 724 | break; |
| 725 | case CO_LSSmaster_FS_SKIP: |
| 726 | default: return CO_LSSmaster_SCAN_FAILED; break; |
| 727 | } |
| 728 | |
| 729 | ret = CO_LSSmaster_check_timeout(LSSmaster, timeDifference_us); |
| 730 | if (ret == CO_LSSmaster_TIMEOUT) { |
| 731 | |
| 732 | ret = CO_LSSmaster_WAIT_SLAVE; |
| 733 | |
| 734 | if (CO_FLAG_READ(LSSmaster->CANrxNew)) { |
| 735 | uint8_t cs = LSSmaster->CANrxData[0]; |
| 736 | CO_FLAG_CLEAR(LSSmaster->CANrxNew); |
| 737 | |
| 738 | if (cs != CO_LSS_IDENT_SLAVE) { |
| 739 | /* wrong response received. Can not continue */ |
| 740 | return CO_LSSmaster_SCAN_FAILED; |
| 741 | } |
| 742 | } else { |
| 743 | /* no response received, assumption is wrong */ |
| 744 | LSSmaster->fsIdNumber |= 1UL << LSSmaster->fsBitChecked; |
| 745 | } |
| 746 | |
| 747 | if (LSSmaster->fsBitChecked == CO_LSS_FASTSCAN_BIT0) { |
| 748 | /* Scanning cycle is finished, we now have 32 bit address data */ |
| 749 | ret = CO_LSSmaster_SCAN_FINISHED; |
| 750 | } else { |
| 751 | LSSmaster->fsBitChecked--; |
| 752 | |
| 753 | CO_LSSmaster_FsSendMsg(LSSmaster, LSSmaster->fsIdNumber, LSSmaster->fsBitChecked, LSSmaster->fsLssSub, |
| 754 | LSSmaster->fsLssSub); |
| 755 | } |
| 756 | } |
| 757 | |
| 758 | return ret; |
| 759 | } |
| 760 | |
| 761 | /* |
| 762 | * Helper function - initiate check for 32 bit part of LSS address |
no test coverage detected