drivers: can: take minimum supported bitrate into consideration
Take the minimum supported bitrate into consideration when validating the bitrate. Signed-off-by: Henrik Brix Andersen <hebad@vestas.com>
This commit is contained in:
parent
810eaf1fb0
commit
019fde0437
@ -351,10 +351,13 @@ int z_impl_can_set_timing(const struct device *dev,
|
||||
int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
|
||||
{
|
||||
struct can_timing timing = { 0 };
|
||||
uint32_t min_bitrate;
|
||||
uint32_t max_bitrate;
|
||||
uint16_t sample_pnt;
|
||||
int ret;
|
||||
|
||||
(void)can_get_min_bitrate(dev, &min_bitrate);
|
||||
|
||||
ret = can_get_max_bitrate(dev, &max_bitrate);
|
||||
if (ret == -ENOSYS) {
|
||||
/* Maximum bitrate unknown */
|
||||
@ -363,7 +366,7 @@ int z_impl_can_set_bitrate(const struct device *dev, uint32_t bitrate)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((max_bitrate > 0) && (bitrate > max_bitrate)) {
|
||||
if ((bitrate < min_bitrate) || (((max_bitrate > 0) && (bitrate > max_bitrate)))) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
@ -404,10 +407,13 @@ int z_impl_can_set_timing_data(const struct device *dev,
|
||||
int z_impl_can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data)
|
||||
{
|
||||
struct can_timing timing_data = { 0 };
|
||||
uint32_t min_bitrate;
|
||||
uint32_t max_bitrate;
|
||||
uint16_t sample_pnt;
|
||||
int ret;
|
||||
|
||||
(void)can_get_min_bitrate(dev, &min_bitrate);
|
||||
|
||||
ret = can_get_max_bitrate(dev, &max_bitrate);
|
||||
if (ret == -ENOSYS) {
|
||||
/* Maximum bitrate unknown */
|
||||
@ -416,7 +422,7 @@ int z_impl_can_set_bitrate_data(const struct device *dev, uint32_t bitrate_data)
|
||||
return ret;
|
||||
}
|
||||
|
||||
if ((max_bitrate > 0) && (bitrate_data > max_bitrate)) {
|
||||
if ((bitrate_data < min_bitrate) || ((max_bitrate > 0) && (bitrate_data > max_bitrate))) {
|
||||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user