| 137 | } |
| 138 | |
| 139 | OD_entry_t* |
| 140 | OD_find(OD_t* od, uint16_t index) { |
| 141 | if ((od == NULL) || (od->size == 0U)) { |
| 142 | return NULL; |
| 143 | } |
| 144 | |
| 145 | uint16_t min = 0; |
| 146 | uint16_t max = od->size - 1U; |
| 147 | |
| 148 | /* Fast search in ordered Object Dictionary. If indexes are mixed, this won't work. If Object |
| 149 | * Dictionary has up to N entries, then the max number of loop passes is log2(N) */ |
| 150 | while (min < max) { |
| 151 | /* get entry between min and max */ |
| 152 | uint16_t cur = (min + max) >> 1; |
| 153 | OD_entry_t* entry = &od->list[cur]; |
| 154 | |
| 155 | if (index == entry->index) { |
| 156 | return entry; |
| 157 | } |
| 158 | |
| 159 | if (index < entry->index) { |
| 160 | max = (cur > 0U) ? (cur - 1U) : cur; |
| 161 | } else { |
| 162 | min = cur + 1U; |
| 163 | } |
| 164 | } |
| 165 | |
| 166 | if (min == max) { |
| 167 | OD_entry_t* entry = &od->list[min]; |
| 168 | if (index == entry->index) { |
| 169 | return entry; |
| 170 | } |
| 171 | } |
| 172 | |
| 173 | return NULL; /* entry does not exist in OD */ |
| 174 | } |
| 175 | |
| 176 | ODR_t |
| 177 | OD_getSub(const OD_entry_t* entry, uint8_t subIndex, OD_IO_t* io, bool_t odOrig) { |
no outgoing calls
no test coverage detected