CANfestival - an open source CANopen framework

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Mon May 30 09:56:35 2011 +0000
Parent:
1:285c99dcbb25
Child:
3:1f91c44b482f
Child:
4:a0557653428b
Commit message:
done for the night 5-30-11

Changed in this revision

framework/driver/mbed/can_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
framework/driver/mbed/timer_mbed.cpp Show annotated file Show diff for this revision Revisions of this file
framework/include/mbed/applicfg.h Show annotated file Show diff for this revision Revisions of this file
framework/include/mbed/canfestival.h Show annotated file Show diff for this revision Revisions of this file
--- a/framework/driver/mbed/can_mbed.cpp	Mon May 30 08:26:03 2011 +0000
+++ b/framework/driver/mbed/can_mbed.cpp	Mon May 30 09:56:35 2011 +0000
@@ -55,7 +55,7 @@
 ******************************************************************************/
 {
     // convert the message from a CANopen object to a mbed object
-    CANMessage msg(m->cob_id, (char*)m->data, m->len, static_cast<CANType>(m->rtr), CANStandard);
+    CANMessage msg(m->cob_id, (uint8_t*)m->data, m->len, static_cast<CANType>(m->rtr), CANStandard);
     // make sure the message was sent
     if (CANopen.write(msg) == 0){
         return 0;                               
@@ -82,20 +82,20 @@
     m->len = msg.len;
     m->rtr = static_cast<UNS8>(msg.type);
     // clear erroneous data from the last use
-	for (int i=0; i<=7; i++){
-		if (i <= (msg.len-1))
-			m->data[i] = msg.data[i];
-		else
-			m->data[i] = 0;
-	}
-	// messge processed
+    for (int i=0; i<=7; i++){
+        if (i <= (msg.len-1))
+            m->data[i] = msg.data[i];
+        else
+            m->data[i] = 0;
+    }
+    // messge processed
     return 1;
 }
 
 /***************************************************************************/
 unsigned char canChangeBaudRate_driver( CAN_HANDLE fd, char* baud)
 {
-	// not sure how baud is passed as a char* yet
+    // not sure how baud is passed as a char* yet
     return 0;
 }
 
--- a/framework/driver/mbed/timer_mbed.cpp	Mon May 30 08:26:03 2011 +0000
+++ b/framework/driver/mbed/timer_mbed.cpp	Mon May 30 09:56:35 2011 +0000
@@ -30,8 +30,8 @@
 extern uint32_t SystemCoreClock;
 
 // Define the timer registers
-#define TimerAlarm        LPC_TIM1->MR0	// compare register to genterate an interrupt
-#define TimerCounter      LPC_TIM1->TC	// free running timer counter register
+#define TimerAlarm        LPC_TIM1->MR0    // compare register to genterate an interrupt
+#define TimerCounter      LPC_TIM1->TC     // free running timer counter register
 
 /************************** Module variables **********************************/
 // Store the last timer value to calculate the elapsed time
@@ -44,27 +44,27 @@
 OUTPUT    void
 ******************************************************************************/
 {
-	float prescaler = 0;
-	TimerAlarm = 0;
-	// power up the timer (if not already done)
-	LPC_SC->PCONP |= (0x1 << 0x2);
-	// reset the timer
-	LPC_TIM1->TCR = 0x2;
-	// set up the prescaler to create an 8us incrementing tick using Timer1
-	switch ((LPC_SC->PCLKSEL0 >> 0x4) & 0x3){
-			case 0x00:	prescaler = 0.000008 / (1.0 / (SystemCoreClock / 4.0));	break;
-			case 0x01:	prescaler = 0.000008 / (1.0 / SystemCoreClock);	 		break;
-			case 0x02:	prescaler = 0.000008 / (1.0 / (SystemCoreClock / 2.0));	break;
-			case 0x03:	prescaler = 0.000008 / (1.0 / (SystemCoreClock / 8.0));	break;
-	}
-	LPC_TIM1->PR = static_cast<uint32_t>(prescaler);
-	// MR0 is used as a match event to trigger an interrupt - managed through TimerAlarm
-	LPC_TIM1->MCR |= (0x1 << 0);
-	NVIC_EnableIRQ(TIMER1_IRQn);
-	// start the timer
-	LPC_TIM1->TCR = 0x1; 
+    float prescaler = 0;
+    TimerAlarm = 0;
+    // power up the timer (if not already done)
+    LPC_SC->PCONP |= (0x1 << 0x2);
+    // reset the timer
+    LPC_TIM1->TCR = 0x2;
+    // set up the prescaler to create an 8us incrementing tick using Timer1
+    switch ((LPC_SC->PCLKSEL0 >> 0x4) & 0x3){
+            case 0x00:    prescaler = 0.000008 / (1.0 / (SystemCoreClock / 4.0));    break;
+            case 0x01:    prescaler = 0.000008 / (1.0 / SystemCoreClock);            break;
+            case 0x02:    prescaler = 0.000008 / (1.0 / (SystemCoreClock / 2.0));    break;
+            case 0x03:    prescaler = 0.000008 / (1.0 / (SystemCoreClock / 8.0));    break;
+    }
+    LPC_TIM1->PR = static_cast<uint32_t>(prescaler);
+    // MR0 is used as a match event to trigger an interrupt - managed through TimerAlarm
+    LPC_TIM1->MCR |= (0x1 << 0);
+    NVIC_EnableIRQ(TIMER1_IRQn);
+    // start the timer
+    LPC_TIM1->TCR = 0x1; 
     // Set timer for CANopen operation tick 8us , max time is 9+ hrs
-	TimeDispatch();
+    TimeDispatch();
 }
 
 void setTimer(TIMEVAL value)
@@ -84,9 +84,9 @@
 OUTPUT    value TIMEVAL (unsigned long) the elapsed time
 ******************************************************************************/
 {
-	uint32_t timer = TimerCounter;	// Copy the value of the running timer
-  	// Calculate the time difference and return it
-  	return timer > last_time_set ? timer - last_time_set : last_time_set - timer;
+    uint32_t timer = TimerCounter;    // Copy the value of the running timer
+    // Calculate the time difference and return it
+    return timer > last_time_set ? timer - last_time_set : last_time_set - timer;
 }
 
 ///******************************************************************************
@@ -95,11 +95,11 @@
 
 extern "C" void TIMER1_IRQHandler()
 {
-	// clear all pending interrupts
-	LPC_TIM1->IR = 0x3F;
-	// store the time of the last interrupt occurance
-	last_time_set = TimerCounter;
-	// Call the time handler of the stack to adapt the elapsed time
-	TimeDispatch();                          
+    // clear all pending interrupts
+    LPC_TIM1->IR = 0x3F;
+    // store the time of the last interrupt occurance
+    last_time_set = TimerCounter;
+    // Call the time handler of the stack to adapt the elapsed time
+    TimeDispatch();                          
 }
 
--- a/framework/include/mbed/applicfg.h	Mon May 30 08:26:03 2011 +0000
+++ b/framework/include/mbed/applicfg.h	Mon May 30 09:56:35 2011 +0000
@@ -42,7 +42,7 @@
 // Unsigned integers
 #define UNS8        unsigned char
 #define UNS16       unsigned short int
-#define UNS32     	unsigned int
+#define UNS32         unsigned int
 /*
 #define UNS24
 #define UNS40
@@ -53,8 +53,8 @@
 
 
 // Reals
-#define REAL32  	float
-#define REAL64    	double
+#define REAL32      float
+#define REAL64        double
 
 #include "canopen_can.h"
 
@@ -64,10 +64,10 @@
 /// Definition of MSG_ERR
 // ---------------------
 #ifdef DEBUG_ERR_CONSOLE_ON
-#define MSG_ERR(num, str, val)	\
-          printf(num, ' ');   	\
-          printf(str);       	\
-          printf(val);       	\
+#define MSG_ERR(num, str, val)    \
+          printf(num, ' ');       \
+          printf(str);           \
+          printf(val);           \
           printf('\n');
 #else
 #    define MSG_ERR(num, str, val)
@@ -76,10 +76,10 @@
 /// Definition of MSG_WAR
 // ---------------------
 #ifdef DEBUG_WAR_CONSOLE_ON
-#define MSG_WAR(num, str, val)	\
-          printf(num, ' ');    	\
-          printf(str);        	\
-          printf(val);        	\
+#define MSG_WAR(num, str, val)    \
+          printf(num, ' ');        \
+          printf(str);            \
+          printf(val);            \
           printf('\n');
 #else
 #    define MSG_WAR(num, str, val)
--- a/framework/include/mbed/canfestival.h	Mon May 30 08:26:03 2011 +0000
+++ b/framework/include/mbed/canfestival.h	Mon May 30 09:56:35 2011 +0000
@@ -1,45 +1,45 @@
-/*
-This file is part of CanFestival, a library implementing CanOpen Stack.
-
+/*
+This file is part of CanFestival, a library implementing CanOpen Stack.
+
 Copyright (C): Edouard TISSERANT and Francis DUPIN
-mbed port: sgrove
-
-See COPYING file for copyrights details.
-
-This library is free software; you can redistribute it and/or
-modify it under the terms of the GNU Lesser General Public
-License as published by the Free Software Foundation; either
-version 2.1 of the License, or (at your option) any later version.
-
-This library is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
-Lesser General Public License for more details.
-
-You should have received a copy of the GNU Lesser General Public
-License along with this library; if not, write to the Free Software
-Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-*/
-
-
-#ifndef __CAN_CANFESTIVAL__
-#define __CAN_CANFESTIVAL__
-
-#include "applicfg.h"
-#include "data.h"
-
-/************************* To be called by user app ***************************/
-
+mbed port: sgrove
+
+See COPYING file for copyrights details.
+
+This library is free software; you can redistribute it and/or
+modify it under the terms of the GNU Lesser General Public
+License as published by the Free Software Foundation; either
+version 2.1 of the License, or (at your option) any later version.
+
+This library is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+Lesser General Public License for more details.
+
+You should have received a copy of the GNU Lesser General Public
+License along with this library; if not, write to the Free Software
+Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+*/
+
+
+#ifndef __CAN_CANFESTIVAL__
+#define __CAN_CANFESTIVAL__
+
+#include "applicfg.h"
+#include "data.h"
+
+/************************* To be called by user app ***************************/
+
 #ifdef __cplusplus
 extern "C"{
 #endif
-
-extern void initTimer(void);
-extern UNS8 canSend(CAN_PORT notused, Message *m);
+
+extern void initTimer(void);
+extern UNS8 canSend(CAN_PORT notused, Message *m);
 extern UNS8 canChangeBaudRate(CAN_PORT port, char* baud);
 
 #ifdef __cplusplus
 }
-#endif
-
-#endif
+#endif
+
+#endif