test

Fork of CANnucleo by Zoltan Hudak

Revision:
21:bcd8161f8f6c
Parent:
14:0344705e6fb8
--- a/CAN.cpp	Sat Mar 19 21:16:10 2016 +0000
+++ b/CAN.cpp	Thu May 19 17:16:59 2016 +0000
@@ -31,10 +31,9 @@
  * @retval
  */
 CAN::CAN(PinName rxPin, PinName txPin, FunctionalState abom /* = ENABLE */) :
-    _can(),
     _irq() {
-    can_init(&_can, rxPin, txPin, abom);
-    can_irq_init(&_can, (&CAN::_irq_handler), (uint32_t)this);
+    can_init(rxPin, txPin, abom);
+    can_irq_init((uint32_t)this, (&CAN::_irq_handler));
 }
 
 /**
@@ -44,8 +43,8 @@
  * @retval
  */
 CAN::~CAN(void) {
-    can_irq_free(&_can);
-    can_free(&_can);
+    can_irq_free();
+    can_free();
 }
 
 /**
@@ -55,7 +54,7 @@
  * @retval
  */
 int CAN::frequency(int f) {
-    return can_frequency(&_can, f);
+    return can_frequency(f);
 }
 
 /**
@@ -65,7 +64,7 @@
  * @retval
  */
 int CAN::write(CANMessage msg) {
-    return can_write(&_can, msg, 0);
+    return can_write(msg, 0);
 }
 
 /**
@@ -75,7 +74,7 @@
  * @retval
  */
 int CAN::read(CANMessage& msg, int handle) {
-    return can_read(&_can, &msg, handle);
+    return can_read(&msg, handle);
 }
 
 /**
@@ -85,7 +84,7 @@
  * @retval
  */
 void CAN::reset(void) {
-    can_reset(&_can);
+    can_reset();
 }
 
 /**
@@ -95,7 +94,7 @@
  * @retval
  */
 unsigned char CAN::rderror(void) {
-    return can_rderror(&_can);
+    return can_rderror();
 }
 
 /**
@@ -105,7 +104,7 @@
  * @retval
  */
 unsigned char CAN::tderror(void) {
-    return can_tderror(&_can);
+    return can_tderror();
 }
 
 /**
@@ -115,7 +114,7 @@
  * @retval
  */
 void CAN::monitor(bool silent) {
-    can_monitor(&_can, (silent) ? 1 : 0);
+    can_monitor((silent) ? 1 : 0);
 }
 
 /**
@@ -125,7 +124,7 @@
  * @retval
  */
 int CAN::mode(Mode mode) {
-    return can_mode(&_can, (CanMode) mode);
+    return can_mode((CanMode) mode);
 }
 
 /**
@@ -182,14 +181,14 @@
  *                   |     |                     |
  *            STID[10:3]  STID[2:0]             IDE   
  *
- * Keep in mind that filter #0 was already set up in the constructor to receive all CAN messages by default.
+ * Recall that filter #0 has been set up in the constructor to receive all CAN messages by default.
  * So we have to reconfigure it. If we were set up filter #1 here then filter #0 would receive all the messages
  * and no message would reach filter #1!
  *
- * To set up filter #0 we call:
+ * To reconfigure (set up) filter #0 we call:
  *     can.filter(0x0207 << 21, 0xFFE00004, CANAny, 0);
  *
- *             Only these bits (set to 1) of filter id are compared with the corresponding
+ *             Only these bits of 'Filter id' (set to 1 here in 'Filter mask') are compared with the corresponding
  *             bits of received message (the others are disregarded)
  *                                |
  *                 ---------------------------------
@@ -209,20 +208,20 @@
  *                             ||||| |||||||| ||||| ||
  *                             -----------------------
  *                                         |
- *                          These bits (set to 0 in filter mask) are disregarded (masked).
+ *                          These bits (set to 0 in 'Filter mask') are disregarded (masked).
  *                          They can have arbitrary values.
  *
  * NOTE: For the meaning of individual bits see the mapping of 32-bits explained above.
  *
  * @param   format: This parameter must be CANAny
  * @param   handle: Selects the filter. This parameter must be a number between 0 and 13.
- * @param   retval: 0 - successful
- *                  1 - error
- *                  2 - busy
- *                  3 - time out  
+ * @retval  0 - successful
+ *          1 - error
+ *          2 - busy
+ *          3 - time out  
  */
 int CAN::filter(unsigned int id, unsigned int mask, CANFormat format /* = CANAny */, int handle /* = 0 */) {
-    return can_filter(&_can, id, mask, format, handle);
+    return can_filter(id, mask, format, handle);
 }
 
 /**
@@ -234,10 +233,8 @@
  */
 void CAN::attach(void (*fptr) (void), IrqType type) {
     HAL_NVIC_DisableIRQ(CAN_IRQ);
-    if(fptr) {
-        can_irq_set(fptr);
-    }
-    can_irq_init(&_can, &CAN::_irq_handler, (uint32_t) this);
+    if(fptr)
+        _irq[(CanIrqType)type].attach(fptr);
     HAL_NVIC_EnableIRQ(CAN_IRQ);
 }
 
@@ -259,3 +256,5 @@
 
 
 
+
+