aboutsummaryrefslogtreecommitdiff
path: root/simplemotion.c
diff options
context:
space:
mode:
Diffstat (limited to 'simplemotion.c')
-rw-r--r--simplemotion.c47
1 files changed, 30 insertions, 17 deletions
diff --git a/simplemotion.c b/simplemotion.c
index cea0238..78059ab 100644
--- a/simplemotion.c
+++ b/simplemotion.c
@@ -1,16 +1,5 @@
//Copyright (c) Granite Devices Oy
-/*
- This program is free software; you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation; version 2 of the License.
-
- This program 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 General Public License for more details.
-*/
-
#include <stdio.h>
#include <string.h>
@@ -92,7 +81,10 @@ void smDebug( smbus handle, smVerbosityLevel verbositylevel, char *format, ...)
va_start(fmtargs,format);
vsnprintf(buffer,sizeof(buffer)-1,format,fmtargs);
va_end(fmtargs);
- fprintf(smDebugOut,"%s: %s",smBus[handle].busDeviceName, buffer);
+ if(handle>=0)
+ fprintf(smDebugOut,"%s: %s",smBus[handle].busDeviceName, buffer);
+ else
+ fprintf(smDebugOut,"SMLib: %s",buffer);//no handle given
}
}
#else
@@ -222,6 +214,27 @@ smbus smOpenBus( const char * devicename )
return handle;
}
+/** Change baudrate of SM communication port. This does not affect already opened ports but the next smOpenBus will be opened at the new speed.
+ Calling this is optional. By default SM bus and all slave devices operates at 460800 BPS speed.
+ Parameters:
+ -bps: bus speed in bits per second. for possible choices, see rs232.c (but note that all speeds are not necessarily supported by SM devices)
+ Typical usage is:
+ - first call smSetParameter(handle,0,SMP_BUS_SPEED,N) to change speed of all connected slaves to N PBS
+ - then close port with smCloseBus
+ - then call smSetBaudrate(N)
+ - then open bus again with smOpenBus
+
+ Note that in upcoming SM device firmware versions, bitrate will be reset to default (460800) if device side SM bus watchdog timer has been enabled, and it timeouts.
+ This allows re-establishing connection at defautl speed if connection breaks up and SM bus watchdog timeout gets exceeded. To identify is device supports this,
+ read parameter SMP_SM_VERSION. Values above 25 support this feature. Value 25 and below will not reset baudrate.
+
+ Note also that SMP_BUS_SPEED will not be saved in device flash memory - it will reset to default at every reset & power on.
+ */
+LIB void smSetBaudrate( unsigned long pbs )
+{
+ SMBusBaudrate=pbs;
+}
+
/** Close connection to given bus handle number. This frees communication link therefore makes it available for other apps for opening.
-return value: a SM_STATUS value, i.e. SM_OK if command succeed
*/
@@ -558,7 +571,7 @@ SM_STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retV
if(smBus[bushandle].cmd_recv_queue_bytes>=smBus[bushandle].recv_payloadsize)
{
- smDebug(Trace,bushandle,"Packet receive error, return data coudn't be parsed\n");
+ smDebug(bushandle,Trace, "Packet receive error, return data coudn't be parsed\n");
//return 0
if(retValue!=NULL) *retValue=0;//check every time if retValue is set NULL by caller -> don't store anything to it if its NULL
@@ -579,7 +592,7 @@ SM_STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retV
smuint8 *readBuf=(smuint8*)&read;
readBuf[1]=rxbyte;
readBuf[0]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
- smDebug(Trace,bushandle,"RET16B: %d\n",read.retData);
+ smDebug(bushandle,Trace,"RET16B: %d\n",read.retData);
if(retValue!=NULL) *retValue=read.retData;
return recordStatus(bushandle,SM_OK);
@@ -592,7 +605,7 @@ SM_STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retV
readBuf[2]=rxbyte;
readBuf[1]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
readBuf[0]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
- smDebug(Trace,bushandle,"RET24B: %d\n",read.retData);
+ smDebug(bushandle,Trace,"RET24B: %d\n",read.retData);
if(retValue!=NULL) *retValue=read.retData;
return recordStatus(bushandle,SM_OK);
@@ -606,7 +619,7 @@ SM_STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retV
readBuf[2]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
readBuf[1]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
readBuf[0]=bufget8bit(smBus[bushandle].recv_rsbuf, smBus[bushandle].cmd_recv_queue_bytes++);
- smDebug(Trace,bushandle,"RET32B: %d\n",read.retData);
+ smDebug(bushandle,Trace,"RET32B: %d\n",read.retData);
if(retValue!=NULL) *retValue=read.retData;
return recordStatus(bushandle,SM_OK);
@@ -617,7 +630,7 @@ SM_STATUS smGetQueuedSMCommandReturnValue( const smbus bushandle, smint32 *retV
SMPayloadCommandRet8 read;
smuint8 *readBuf=(smuint8*)&read;
readBuf[0]=rxbyte;
- smDebug(Trace,bushandle,"RET_OTHER: %d\n",read.retData);
+ smDebug(bushandle,Trace,"RET_OTHER: %d\n",read.retData);
if(retValue!=NULL) *retValue=read.retData;
return recordStatus(bushandle,SM_OK);