/* Works for both CAN and FDCAN frame lengths. If length is invalid value, then returns 0xFF. */
uint32_t fdcan_length_to_dlc(uint8_t length)
/* Works for both CAN and FDCAN frame lengths. If length is invalid value, then returns 0xFF. */
uint32_t fdcan_length_to_dlc(uint8_t length)
{
	if (length <= 8) {
		return length;
	} else if (length <= 24) {
		if ((length % 4) != 0) {
			return 0xFF;
		}
		return 8 + ((length - 8) / 4);
	} else {
		if ((length % 16) != 0) {
			return 0xFF;
		}
		return 11 + (length / 16);
	}
}