mbed library sources. Supersedes mbed-src.

Fork of mbed-dev by mbed official

Revision:
150:02e0a0aed4ec
Parent:
149:156823d33999
--- a/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_can.c	Fri Oct 28 11:17:30 2016 +0100
+++ b/targets/TARGET_NUVOTON/TARGET_NUC472/device/StdDriver/nuc472_can.c	Tue Nov 08 17:45:16 2016 +0000
@@ -419,6 +419,7 @@
 
     SystemCoreClockUpdate();
 
+#if 0   // original implementation got 5% inaccuracy.
     u32Value = SystemCoreClock;
 
     if(u32BaudRate * 8 < (u32Value/2)) {
@@ -428,7 +429,26 @@
         u8Tseg1 = 2;
         u8Tseg2 = 1;
     }
+#else
+    u32Value = SystemCoreClock / u32BaudRate;
+    /* Fix for most standard baud rates, include 125K */
 
+    u8Tseg1 = 3;
+    u8Tseg2 = 2;
+    while(1)
+    {
+        if(((u32Value % (u8Tseg1 + u8Tseg2 + 3)) == 0) | (u8Tseg1 >= 15))
+            break;
+
+        u8Tseg1++;
+
+        if((u32Value % (u8Tseg1 + u8Tseg2 + 3)) == 0)
+            break;
+
+        if(u8Tseg2 < 7)
+            u8Tseg2++;
+    }
+#endif
     u32Brp  = SystemCoreClock/(u32BaudRate) / (u8Tseg1 + u8Tseg2 + 3) -1;
 
     u32Value = ((uint32_t)u8Tseg2 << CAN_BTIME_TSEG2_Pos) | ((uint32_t)u8Tseg1 << CAN_BTIME_TSEG1_Pos) |