/* CAN Init Initialize the selected CAN peripheral block.  */
void can_init(uint32_t canport, bool listen_only, uint32_t sjw, uint32_t tseg1, uint32_t tseg2, bool sam3, uint32_t brp)
/* CAN Init Initialize the selected CAN peripheral block.  */
void can_init(uint32_t canport, bool listen_only, uint32_t sjw, uint32_t tseg1, uint32_t tseg2, bool sam3, uint32_t brp)
{
	CAN_ISR_SR_CMR_MR(canport) = CAN_MR_RM;
	CAN_ISR_SR_CMR_MR_SET(canport, CAN_MR_AFM);
	if (listen_only) {
		CAN_ISR_SR_CMR_MR_SET(canport, CAN_MR_LOM);
	}
	CAN_BTR1_BTR0_RMC_IMR(canport) = CAN_BTR0_BRP(brp) | CAN_BTR0_SJW(sjw)
		| CAN_BTR1_TSEG1(tseg1) | CAN_BTR1_TSEG2(tseg2);
	if (sam3) {
		CAN_BTR1_BTR0_RMC_IMR(canport) |= CAN_BTR1_SAM;
	}
	CAN_ACR(canport) = 0;
	CAN_AMR(canport) = 0xFFFFFFFFu;
}