Lines Matching +full:max +full:- +full:x
4 * SPDX-License-Identifier: Apache-2.0
30 ctx->status = error; in can_tx_default_cb()
31 k_sem_give(&ctx->done); in can_tx_default_cb()
38 const struct can_driver_api *api = (const struct can_driver_api *)dev->api; in z_impl_can_send()
42 return -EINVAL; in z_impl_can_send()
45 if ((frame->flags & CAN_FRAME_IDE) != 0U) { in z_impl_can_send()
51 CHECKIF((frame->id & ~(id_mask)) != 0U) { in z_impl_can_send()
52 LOG_ERR("invalid frame with %s (%d-bit) CAN ID 0x%0*x", in z_impl_can_send()
53 (frame->flags & CAN_FRAME_IDE) != 0 ? "extended" : "standard", in z_impl_can_send()
54 (frame->flags & CAN_FRAME_IDE) != 0 ? 29 : 11, in z_impl_can_send()
55 (frame->flags & CAN_FRAME_IDE) != 0 ? 8 : 3, frame->id); in z_impl_can_send()
56 return -EINVAL; in z_impl_can_send()
65 err = api->send(dev, frame, timeout, can_tx_default_cb, &ctx); in z_impl_can_send()
75 return api->send(dev, frame, timeout, callback, user_data); in z_impl_can_send()
81 const struct can_driver_api *api = (const struct can_driver_api *)dev->api; in can_add_rx_filter()
85 return -EINVAL; in can_add_rx_filter()
88 if ((filter->flags & CAN_FILTER_IDE) != 0U) { in can_add_rx_filter()
94 CHECKIF(((filter->id & ~(id_mask)) != 0U) || ((filter->mask & ~(id_mask)) != 0U)) { in can_add_rx_filter()
95 LOG_ERR("invalid filter with %s (%d-bit) CAN ID 0x%0*x, CAN ID mask 0x%0*x", in can_add_rx_filter()
96 (filter->flags & CAN_FILTER_IDE) != 0 ? "extended" : "standard", in can_add_rx_filter()
97 (filter->flags & CAN_FILTER_IDE) != 0 ? 29 : 11, in can_add_rx_filter()
98 (filter->flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter->id, in can_add_rx_filter()
99 (filter->flags & CAN_FILTER_IDE) != 0 ? 8 : 3, filter->mask); in can_add_rx_filter()
100 return -EINVAL; in can_add_rx_filter()
103 return api->add_rx_filter(dev, callback, user_data, filter); in can_add_rx_filter()
117 LOG_ERR("Msgq %p overflowed. Frame ID: 0x%x", msgq, frame->id); in can_msgq_put()
124 const struct can_driver_api *api = dev->api; in z_impl_can_add_rx_filter_msgq()
126 return api->add_rx_filter(dev, can_msgq_put, msgq, filter); in z_impl_can_add_rx_filter_msgq()
134 * +---------------------------------------------------+
136 * +--------------+----------+------------+------------+
138 * +--------------+----------+------------+------------+
140 * +--------------+-----------------------+------------+
151 * @param max Pointer to the maximum supported timing parameter values.
153 * @retval -ENOTSUP if the requested sample point cannot be met.
156 const struct can_timing *min, const struct can_timing *max) in update_sample_pnt() argument
158 uint16_t tseg1_max = max->phase_seg1 + max->prop_seg; in update_sample_pnt()
159 uint16_t tseg1_min = min->phase_seg1 + min->prop_seg; in update_sample_pnt()
164 tseg2 = total_tq - (total_tq * sample_pnt) / 1000; in update_sample_pnt()
165 tseg2 = CLAMP(tseg2, min->phase_seg2, max->phase_seg2); in update_sample_pnt()
168 tseg1 = total_tq - CAN_SYNC_SEG - tseg2; in update_sample_pnt()
172 tseg2 = total_tq - CAN_SYNC_SEG - tseg1; in update_sample_pnt()
174 if (tseg2 > max->phase_seg2) { in update_sample_pnt()
175 return -ENOTSUP; in update_sample_pnt()
180 tseg2 = total_tq - CAN_SYNC_SEG - tseg1; in update_sample_pnt()
182 if (tseg2 < min->phase_seg2) { in update_sample_pnt()
183 return -ENOTSUP; in update_sample_pnt()
187 res->phase_seg2 = tseg2; in update_sample_pnt()
190 res->prop_seg = CLAMP(tseg1 / 2, min->prop_seg, max->prop_seg); in update_sample_pnt()
191 res->phase_seg1 = tseg1 - res->prop_seg; in update_sample_pnt()
193 if (res->phase_seg1 > max->phase_seg1) { in update_sample_pnt()
195 res->phase_seg1 = max->phase_seg1; in update_sample_pnt()
196 res->prop_seg = tseg1 - res->phase_seg1; in update_sample_pnt()
197 } else if (res->phase_seg1 < min->phase_seg1) { in update_sample_pnt()
199 res->phase_seg1 = min->phase_seg1; in update_sample_pnt()
200 res->prop_seg = tseg1 - res->phase_seg1; in update_sample_pnt()
208 sample_pnt_res - sample_pnt : in update_sample_pnt()
209 sample_pnt - sample_pnt_res; in update_sample_pnt()
242 * @param max Pointer to the maximum supported timing parameter values.
247 * @retval -EINVAL if the requested bitrate or sample point is out of range.
248 * @retval -ENOTSUP if the requested bitrate is not supported.
249 * @retval -EIO if @a can_get_core_clock() is not available.
252 const struct can_timing *min, const struct can_timing *max, in can_calc_timing_internal() argument
255 uint32_t total_tq = CAN_SYNC_SEG + max->prop_seg + max->phase_seg1 + max->phase_seg2; in can_calc_timing_internal()
263 return -EINVAL; in can_calc_timing_internal()
268 return -EIO; in can_calc_timing_internal()
275 for (prescaler = MAX(core_clock / (total_tq * bitrate), min->prescaler); in can_calc_timing_internal()
276 prescaler <= max->prescaler; in can_calc_timing_internal()
286 err = update_sample_pnt(total_tq, sample_pnt, &tmp_res, min, max); in can_calc_timing_internal()
295 res->prop_seg = tmp_res.prop_seg; in can_calc_timing_internal()
296 res->phase_seg1 = tmp_res.phase_seg1; in can_calc_timing_internal()
297 res->phase_seg2 = tmp_res.phase_seg2; in can_calc_timing_internal()
298 res->prescaler = (uint16_t)prescaler; in can_calc_timing_internal()
312 res->sjw = MIN(res->phase_seg1, res->phase_seg2 / 2); in can_calc_timing_internal()
313 res->sjw = CLAMP(res->sjw, min->sjw, max->sjw); in can_calc_timing_internal()
315 return err_min == INT_MAX ? -ENOTSUP : err_min; in can_calc_timing_internal()
322 const struct can_timing *max = can_get_timing_max(dev); in z_impl_can_calc_timing() local
325 return -EINVAL; in z_impl_can_calc_timing()
328 return can_calc_timing_internal(dev, res, min, max, bitrate, sample_pnt); in z_impl_can_calc_timing()
336 const struct can_timing *max = can_get_timing_data_max(dev); in z_impl_can_calc_timing_data() local
339 return -EINVAL; in z_impl_can_calc_timing_data()
342 return can_calc_timing_internal(dev, res, min, max, bitrate, sample_pnt); in z_impl_can_calc_timing_data()
348 const struct can_timing *max) in check_timing_in_range() argument
350 if (!IN_RANGE(timing->sjw, min->sjw, max->sjw) || in check_timing_in_range()
351 !IN_RANGE(timing->prop_seg, min->prop_seg, max->prop_seg) || in check_timing_in_range()
352 !IN_RANGE(timing->phase_seg1, min->phase_seg1, max->phase_seg1) || in check_timing_in_range()
353 !IN_RANGE(timing->phase_seg2, min->phase_seg2, max->phase_seg2) || in check_timing_in_range()
354 !IN_RANGE(timing->prescaler, min->prescaler, max->prescaler)) { in check_timing_in_range()
355 return -ENOTSUP; in check_timing_in_range()
358 if ((timing->sjw > timing->phase_seg1) || (timing->sjw > timing->phase_seg2)) { in check_timing_in_range()
359 return -ENOTSUP; in check_timing_in_range()
368 const struct can_driver_api *api = (const struct can_driver_api *)dev->api; in z_impl_can_set_timing()
370 const struct can_timing *max = can_get_timing_max(dev); in z_impl_can_set_timing() local
373 err = check_timing_in_range(timing, min, max); in z_impl_can_set_timing()
378 return api->set_timing(dev, timing); in z_impl_can_set_timing()
385 uint32_t max = can_get_bitrate_max(dev); in z_impl_can_set_bitrate() local
389 if ((bitrate < min) || (bitrate > max)) { in z_impl_can_set_bitrate()
390 return -ENOTSUP; in z_impl_can_set_bitrate()
400 return -ERANGE; in z_impl_can_set_bitrate()
410 const struct can_driver_api *api = (const struct can_driver_api *)dev->api; in z_impl_can_set_timing_data()
412 const struct can_timing *max = can_get_timing_data_max(dev); in z_impl_can_set_timing_data() local
415 if (api->set_timing_data == NULL) { in z_impl_can_set_timing_data()
416 return -ENOSYS; in z_impl_can_set_timing_data()
419 err = check_timing_in_range(timing_data, min, max); in z_impl_can_set_timing_data()
424 return api->set_timing_data(dev, timing_data); in z_impl_can_set_timing_data()
431 uint32_t max = can_get_bitrate_max(dev); in z_impl_can_set_bitrate_data() local
435 if ((bitrate_data < min) || (bitrate_data > max)) { in z_impl_can_set_bitrate_data()
436 return -ENOTSUP; in z_impl_can_set_bitrate_data()
446 return -ERANGE; in z_impl_can_set_bitrate_data()