Skip to content

[LPC15xx] CAN implementation improvements #3504

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 9, 2017
Merged

Conversation

ducky64
Copy link
Contributor

@ducky64 ducky64 commented Dec 26, 2016

  • Add support for TX interrupts.
  • Allocates dedicated TX messageboxes (instead of runtime-allocating a messagebox when requested).
  • Change RX and TX interrupt style from messagebox-based to controller based.
    • This is the simplest implementation - both irq_set and filter modify the messagebox control registers, and both can be called at any time, in any order. However, this could be implemented with a more complex read-modify-write of messagebox control registers.
  • Add support for error-warning, error-passive, and bus-off status change interrupts.
    • Since the controller hardware only provides a general error status change interrupt flag, it isn't possible to differentiate between which one caused the interrupt. Therefore, it is possible to have error-warning interrupts fire multiple times (once going into error-warning, again going into error-passive, and again when going into bus-off; possibly also with any TX/RX interrupt while in an error state). There should never be "incorrect" interrupts, only extraneous interrupts.
  • can_reset now also clears a bus-off error.
    • Possibly undesirably, it seems CAN read and CAN write also does the same, though since the API is so vague about it, I'm not changing the implementation.

@0xc0170
Copy link
Contributor

0xc0170 commented Dec 30, 2016

cc @toyowata

Copy link
Contributor

@toyowata toyowata left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and added a comment.
@ducky64 Please can you provide any test result of this PR, if you have.

// Put CAN in Reset Mode and enable interrupt
can_disable(obj);
if (enable == 0) {
LPC_C_CAN0->CANCNTL &= ~(1UL << 1 | 1UL << 2);
if (!(enabled_irqs && IRQ_ENABLE_ANY)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this operator && (logical AND) intentional here? I think this should be operator & (Bitwise AND).

@ducky64
Copy link
Contributor Author

ducky64 commented Jan 2, 2017

That was a typo; fixed (along with two more instances of the same; derp...).

I tested this on a CAN network with 3 LPC1549 devices. The tests involved attaching interrupts to RxIrq, TxIrq, EwIrq, EpIrq, and BeIrq that toggle different LEDs.
RxIrq toggles a LED when a message is received from another node
TxIrq blinks a LED when a message is transmitted successfully
EwIrq and EpIrq rapidly toggles a LED when attempting to transmit from a bus with the other nodes held in reset (and hence unable to ACK). The rapid toggling is probably a consequence of automatic retransmit combined with the read operations in the main loop that reset the controller. For whatever reason, it never goes into bus-off.
BeIrq rapidly toggles a LED when attempting to transmit when the RXD line is disconnected. Since a mismatch is detected earlier in the message, this probably increments the error counters faster than the above scenario and is able to trigger bus-off mode.

So basically the requested interrupts do get triggered. I don't really have the resources to generate exactly enough errors to trip error-warning or error-passive, but the results smell sane...

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 3, 2017

/morph test-nightly

@mbed-bot
Copy link

mbed-bot commented Jan 3, 2017

Result: SUCCESS

Your command has finished executing! Here's what you wrote!

/morph test-nightly

Output

mbed Build Number: 1347

All builds and test passed!

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 3, 2017

@toyowata Happy with this patch?

@toyowata
Copy link
Contributor

toyowata commented Jan 4, 2017

@0xc0170 Yes, LGTM.

@sg- sg- merged commit 10b6dbf into ARMmbed:master Jan 9, 2017
aisair pushed a commit to aisair/mbed that referenced this pull request Apr 30, 2024
Ports for Upcoming Targets


Fixes and Changes

3488: Dev stm i2c v2 unitary functions ARMmbed/mbed-os#3488
3492: Fix #3463 CAN read() return value ARMmbed/mbed-os#3492
3503: [LPC15xx] Ensure that PWM=1 is resolved correctly ARMmbed/mbed-os#3503
3504: [LPC15xx] CAN implementation improvements ARMmbed/mbed-os#3504
3539: NUCLEO_F412ZG - Add support of TRNG peripheral ARMmbed/mbed-os#3539
3540: STM: SPI: Initialize Rx in spi_master_write ARMmbed/mbed-os#3540
3438: K64F: Add support for SERIAL ASYNCH API ARMmbed/mbed-os#3438
3519: MCUXpresso: Fix ENET driver to enable interrupts after interrupt handler is set ARMmbed/mbed-os#3519
3544: STM32L4 deepsleep improvement ARMmbed/mbed-os#3544
3546: NUCLEO-F412ZG - Add CAN peripheral ARMmbed/mbed-os#3546
3551: Fix I2C driver for RZ/A1H ARMmbed/mbed-os#3551
3558: K64F UART Asynch API: Fix synchronization issue ARMmbed/mbed-os#3558
3563: LPC4088 - Fix vector checksum ARMmbed/mbed-os#3563
3567: Dev stm32 F0 v1.7.0 ARMmbed/mbed-os#3567
3577: Fixes linking errors when building with debug profile ARMmbed/mbed-os#3577
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants