mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Revision:
530:2939f5396008
Parent:
227:7bd0639b8911
--- 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];