Doxy-style comments and various cleanup in unix.c
authoretisserant
Mon, 21 Apr 2008 16:34:51 +0200
changeset 442 010c26b9ba89
parent 441 968697561674
child 443 994c99afb344
Doxy-style comments and various cleanup in unix.c
drivers/unix/unix.c
--- a/drivers/unix/unix.c	Mon Apr 21 16:34:12 2008 +0200
+++ b/drivers/unix/unix.c	Mon Apr 21 16:34:51 2008 +0200
@@ -52,11 +52,12 @@
 
 #define MAX_NB_CAN_PORTS 16
 
+/** CAN port structure */
 typedef struct {
-  char used;
-  CAN_HANDLE fd;
-  TASK_HANDLE receiveTask;
-  CO_Data* d;
+  char used;  /**< flag indicating CAN port usage, will be used to abort Receiver task*/
+  CAN_HANDLE fd; /**< CAN port file descriptor*/
+  TASK_HANDLE receiveTask; /**< CAN Receiver task*/
+  CO_Data* d; /**< CAN object data*/
 } CANPort;
 
 #include "can_driver.h"
@@ -84,7 +85,12 @@
 	return -1;
 }
 
-/*Loads the dll and get funcs ptr*/
+/**
+ * Loads the dll and get funcs ptr
+ *
+ * @param driver_name String containing driver's dynamic library name
+ * @return Library handle
+ */
 LIB_HANDLE LoadCanDriver(char* driver_name)
 {
 	LIB_HANDLE handle = NULL;
@@ -122,6 +128,12 @@
 }
 */
 
+/**
+ * CAN send routine
+ * @param port CAN port
+ * @param m CAN message
+ * @return success or error
+ */
 UNS8 canSend(CAN_PORT port, Message *m)
 {
 	if(port){
@@ -134,11 +146,15 @@
 	return 1; // NOT OK
 }
 
+/**
+ * CAN Receiver Task
+ * @param port CAN port
+ */
 void canReceiveLoop(CAN_PORT port)
 {
        Message m;
 
-       while (1) {
+       while (((CANPort*)port)->used) {
                if (DLL_CALL(canReceive)(((CANPort*)port)->fd, &m) != 0)
                        break;
 
@@ -147,6 +163,13 @@
                LeaveMutex();
        }
 }
+
+/**
+ * CAN open routine
+ * @param board device name and baudrate
+ * @param d CAN object data
+ * @return valid CAN_PORT pointer or NULL
+ */
 CAN_PORT canOpen(s_BOARD *board, CO_Data * d)
 {
 	int i;
@@ -180,21 +203,37 @@
 	}
 }
 
+/**
+ * CAN close routine
+ * @param d CAN object data
+ * @return success or error
+ */
 int canClose(CO_Data * d)
 {
+	UNS8 res;
+
 	EnterMutex();
 	((CANPort*)d->canHandle)->used = 0;
 	CANPort* tmp = (CANPort*)d->canHandle;
 	d->canHandle = NULL;
 	LeaveMutex();
 	
-	int res = DLL_CALL(canClose)(tmp->fd);
-	
+	// close CAN port
+	res = DLL_CALL(canClose)(tmp->fd);
+
+	// kill receiver task
 	WaitReceiveTaskEnd(&tmp->receiveTask);
+	
 	return res;
 }
 
 
+/**
+ * CAN change baudrate routine
+ * @param port CAN port
+ * @param baud baudrate
+ * @return success or error
+ */
 UNS8 canChangeBaudRate(CAN_PORT port, char* baud)
 {
    if(port){