From: ayer1 Date: Wed, 10 Feb 2010 20:02:38 +0000 (+0000) Subject: added mods to allow configuration of standard baudrates, moving X-Git-Tag: rc_6_tinyos_2_1_1~20 X-Git-Url: https://oss.titaniummirror.com/gitweb/?p=tinyos-2.x.git;a=commitdiff_plain;h=d3e972cf3bcc1902d0b33276e72983573fadd94f added mods to allow configuration of standard baudrates, moving setbaudrate to setrawbaudrate. setbaudrate now takes a baudrate argument (e.g. "115k") while the factor goes to setrawbaudrate (baudrate * 0.004096). also added commented instructions for changing bt uart to 230k from default 115200. added document explaining use of bt modules with this configuration. --- diff --git a/tos/platforms/shimmer/chips/bluetooth/Bluetooth.nc b/tos/platforms/shimmer/chips/bluetooth/Bluetooth.nc index f03f0a5d..6dbf75eb 100644 --- a/tos/platforms/shimmer/chips/bluetooth/Bluetooth.nc +++ b/tos/platforms/shimmer/chips/bluetooth/Bluetooth.nc @@ -71,7 +71,17 @@ interface Bluetooth { command void setServiceName(char * name); // max 16 chars command void setDeviceClass(char * class); // max 4 chars (hex word) command void disableRemoteConfig(bool disableConfig); - command void setBaudrate(char * rate_factor); // max 4 chars, must be integer + /* + * rate_factor is baudrate * 0.004096, e.g. to set 115200, pass in "472" + */ + command void setRawBaudrate(char * rate_factor); // max 4 chars, must be integer + + /* + * provide one of the following as a string argument: + * { 1200, 2400, 4800, 9600, 19.2, 38.4, 57.6, 115K, 230K, 460K, 921K } + */ + command void setBaudrate(char * new_baud); + /* save power by minimising time Inquiry/Page scanning, call these commands from */ /* your StdControl.init() - module reset necessary for changes to take effect */ command void setPagingTime(char * hexval_time); // max 4 chars (hex word) diff --git a/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc b/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc index 7f0b6b49..b6d7a55f 100644 --- a/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc +++ b/tos/platforms/shimmer/chips/bluetooth/RovingNetworksP.nc @@ -65,11 +65,11 @@ implementation { uint8_t radioMode, charsSent, setupStep; bool discoverable, authenticate, encrypt, setNameRequest, setPINRequest, runDiscoveryRequest, resetDefaultsRequest, - setSvcClassRequest, setDevClassRequest, setSvcNameRequest, setCustomBaudrate, disableRemoteConfig, newMode, + setSvcClassRequest, setDevClassRequest, setSvcNameRequest, setRawBaudrate, setBaudrate, disableRemoteConfig, newMode, setCustomInquiryTime, setCustomPagingTime; norace bool transmissionOverflow, messageInProgress; - char expectedCommandResponse[8], newName[17], newPIN[17], newSvcClass[5], newDevClass[5], newSvcName[17], newBaudrate[5], - newInquiryTime[5], newPagingTime[5]; + char expectedCommandResponse[8], newName[17], newPIN[17], newSvcClass[5], newDevClass[5], newSvcName[17], newRawBaudrate[5], + newBaudrate[5], newInquiryTime[5], newPagingTime[5]; norace struct Message outgoingMsg; norace struct Message incomingMsg; @@ -134,12 +134,23 @@ implementation { ssel: 0x02, pena: 0, pev: 0, spb: 0, clen: 1,listen: 0, mm: 0, ckpl: 0, urxse: 0, urxeie: 0, urxwie: 0, utxe : 1, urxe :1} }; + call UARTControl.setModeUart(&RN_uart_config); // set to UART mode #ifdef USE_8MHZ_CRYSTAL // we need exact divisors, else the thing acts unpredictably call UARTControl.setUbr(0x08); call UARTControl.setUmctl(0xee); #endif - call UARTControl.setModeUart(&RN_uart_config); // set to UART mode + /* + * to run the bt module at 230k, first the application must configure it + * using its default uart speed of 115200, then reset the uart to 230k here + * see accompanying bluetoothBaudrateConfiguration.pdf doc for details + * yes, doc is written for tos-1.x, but setClockRate() is just broken into + * two calls here in tos-2.x + * + call UARTControl.setUbr(0x04); + call UARTControl.setUmctl(0x82); + */ + call UARTControl.enableTxIntr(); call UARTControl.enableRxIntr(); } @@ -209,9 +220,22 @@ implementation { * the supplied "rate_factor" is the baudrate * 0.004096 * this factor must be an integer value... */ - command void Bluetooth.setBaudrate(char * rate_factor){ - setCustomBaudrate = TRUE; - snprintf(newBaudrate, 5, "%s", rate_factor); + command void Bluetooth.setRawBaudrate(char * rate_factor){ + setRawBaudrate = TRUE; + snprintf(newRawBaudrate, 5, "%s", rate_factor); + } + + /* + * to set the baudrate of the BT to MSP serial interface + * as per RovingNetworks command spec EG "SU,96" or "SU,230" + * SU, - Baudrate, {1200, 2400, 4800, 9600, 19.2, + * 38.4, 57.6, 115K, 230K, 460K, 921K }, + * BUT, the MSP USARTS will not run at > 230K in UART mode, + * see MSP user guide + */ + command void Bluetooth.setBaudrate(char * new_baud){ + setBaudrate = TRUE; + snprintf(newBaudrate, 5, "%s", new_baud); } command void Bluetooth.setPIN(char * PIN){ @@ -334,9 +358,9 @@ implementation { } case 11: setupStep++; - if(setCustomBaudrate){ + if(setRawBaudrate){ // set the baudrate to suit the MSP430 running at 8Mhz - sprintf(commandbuf, "SZ,%s\r", newBaudrate); + sprintf(commandbuf, "SZ,%s\r", newRawBaudrate); writeCommand(commandbuf, "AOK"); break; } @@ -374,6 +398,15 @@ implementation { } break; case 15: + setupStep++; + if(setBaudrate){ + // set the baudrate to suit the MSP430 running at 8Mhz + sprintf(commandbuf, "SU,%s\r", newBaudrate); + writeCommand(commandbuf, "AOK"); + break; + } + + case 16: setupStep++; // exit command mode writeCommand("---\r", "END"); @@ -407,11 +440,12 @@ implementation { setSvcClassRequest = FALSE; setSvcNameRequest = FALSE; setDevClassRequest = FALSE; - setCustomBaudrate = FALSE; + setRawBaudrate = FALSE; disableRemoteConfig = FALSE; setCustomInquiryTime = FALSE; setCustomPagingTime = FALSE; - + setBaudrate = FALSE; + setupStep = 0; atomic *expectedCommandResponse = 0; // NULL pointer transmissionOverflow = FALSE, messageInProgress = FALSE; diff --git a/tos/platforms/shimmer/chips/bluetooth/bluetoothBaudrateConversion.pdf b/tos/platforms/shimmer/chips/bluetooth/bluetoothBaudrateConversion.pdf new file mode 100644 index 00000000..f029e149 Binary files /dev/null and b/tos/platforms/shimmer/chips/bluetooth/bluetoothBaudrateConversion.pdf differ