mbed library sources
Fork of mbed-src by
Diff: targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c
- Revision:
- 530:2939f5396008
- Parent:
- 227:7bd0639b8911
- Child:
- 637:ed69428d4850
diff -r dcb248af6296 -r 2939f5396008 targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c --- a/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c Thu Apr 30 07:45:07 2015 +0100 +++ b/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c Thu Apr 30 09:15:06 2015 +0100 @@ -79,7 +79,45 @@ } int can_mode(can_t *obj, CanMode mode) { - return 0; // not implemented + int success = 0; + switch (mode) { + case MODE_RESET: + // Clear all special modes + can_reset(obj); + obj->dev->MOD &=~ 0x06; + success = 1; + break; + case MODE_NORMAL: + // Clear all special modes + can_disable(obj); + obj->dev->MOD &=~ 0x06; + can_enable(obj); + success = 1; + break; + case MODE_SILENT: + // Set listen-only mode and clear self-test mode + can_disable(obj); + obj->dev->MOD |= 0x02; + obj->dev->MOD &=~ 0x04; + can_enable(obj); + success = 1; + break; + case MODE_TEST_LOCAL: + // Set self-test mode and clear listen-only mode + can_disable(obj); + obj->dev->MOD |= 0x04; + obj->dev->MOD &=~ 0x02; + can_enable(obj); + success = 1; + break; + case MODE_TEST_SILENT: + case MODE_TEST_GLOBAL: + default: + success = 0; + break; + } + + return success; } int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { @@ -316,6 +354,12 @@ const unsigned int *buf = (const unsigned int *)&m; CANStatus = obj->dev->SR; + + // Send the message to ourself if in a test mode + if (obj->dev->MOD & 0x04) { + cc = 1; + } + if (CANStatus & 0x00000004) { obj->dev->TFI1 = buf[0] & 0xC00F0000; obj->dev->TID1 = buf[1];