[Tinyos-help] Serial Baudrate
Eric Decker
cire831 at gmail.com
Thu Jul 3 11:35:39 PDT 2008
I haven't looked at the ATMega stuff in a number of years and don't remember
how that hardware controls the baud rate on its usart.
I could tell you almost off the top of my head if you were using a MSP430
based mote. But that doesn't help you.
Here is what I would do...
Can you get a slower baud rate to work? 57600?
1) Investigate how the ATMega does the working baud rate. You'll have to
look at the low level platform code that does the actual programming of the
control registers for the uart. Will probably also have to look at the h/w
manual for the ATMega.
2) Understand what parameters/registers to change to get say 115200 (for
Linux) and 128000 (for Cygwin). Program the mote up with those parameters
and see what works.
3) When you understand how to generate the register values. Try generating
the values for a known working baud (like 57600) and check to see if that is
what is being programed on the ATMega mote. (check your work).
That is how I would proceed.
hope that helps,
eric
On Wed, Jul 2, 2008 at 11:10 PM, Varun Jain <varun at spiderbox.com.au> wrote:
> I tried doing the 230400 baud rate as well on Cygwin, I think there is
> something either wrong in m_byte_time value that I am defining or something
> else I am missing, I am running Tinyos-2.0.2 under Cygwin, so I do not think
> I can go with the linux code.
>
>
>
> I do not know how to solve this problem.
>
>
>
>
>
> Varun Jain
>
>
>
> *From:* Eric Decker [mailto:cire831 at gmail.com]
> *Sent:* Thursday, July 03, 2008 4:08 PM
> *To:* Varun Jain
> *Subject:* Re: [Tinyos-help] Serial Baudrate
>
>
>
> I haven't ever seen the speeds that the Cygwin code uses. I have seen what
> the Linux code uses, namely 57600, 115200, and 230400.
>
> The Cygwin may work but it depends on what the underlying hardware
> supports. Given that Cygwin/Windows and Linux runs on the same hardware
> it is very interesting the difference.
>
> The easiest thing to do is try it. I personally would go with the Linux
> code.
>
> The telosb (msp430) h/w will support either mechanism by tweaking the
> divider and modulator registers.
>
> eric
>
> On Wed, Jul 2, 2008 at 10:51 PM, Varun Jain <varun at spiderbox.com.au>
> wrote:
>
> By 'differently', I am referring to the code at
> /tools/tinyos/java/serial ----à here we can see two files, namely
> NativeSerial_win32 AND NativeSerial_linux
>
>
>
> For Windows (Cygwin) machines, I believe it gets the code for Baudrate from
> In NativeSerial_win32 as below:
>
>
>
> int getBaudRate()
>
> {
>
> int baud_rate = get_comm_state().BaudRate;
>
> switch( baud_rate )
>
> {
>
> case CBR_110: return 110;
>
> case CBR_300: return 300;
>
> case CBR_600: return 600;
>
> case CBR_1200: return 1200;
>
> case CBR_2400: return 2400;
>
> case CBR_4800: return 4800;
>
> case CBR_9600: return 9600;
>
> case CBR_14400: return 14400;
>
> case CBR_19200: return 19200;
>
> case CBR_38400: return 38400;
>
> case CBR_56000: return 56000;
>
> case CBR_57600: return 57600;
>
> case CBR_115200: return 115200;
>
> case CBR_128000: return 128000;
>
> case CBR_256000: return 256000;
>
> }
>
> return baud_rate;
>
> }
>
>
>
> AND IN Linux machines, we get Baudrates from NativeSerial_linux file as
> below:
>
> int baud_to_enum( int baud )
>
> {
>
> switch( baud )
>
> {
>
> case 0: return B0;
>
> case 50: return B50;
>
> case 75: return B75;
>
> case 110: return B110;
>
> case 134: return B134;
>
> case 150: return B150;
>
> case 200: return B200;
>
> case 300: return B300;
>
> case 600: return B600;
>
> case 1200: return B1200;
>
> case 1800: return B1800;
>
> case 2400: return B2400;
>
> case 4800: return B4800;
>
> case 9600: return B9600;
>
> case 19200: return B19200;
>
> case 38400: return B38400;
>
> case 57600: return B57600;
>
> case 115200: return B115200;
>
> case 230400: return B230400;
>
> }
>
> throw comm_port_error("baud_to_enum, bad baud rate");
>
> }
>
>
>
> int enum_to_baud( int baudenum )
>
> {
>
> switch( baudenum )
>
> {
>
> case B0: return 0;
>
> case B50: return 50;
>
> case B75: return 75;
>
> case B110: return 110;
>
> case B134: return 134;
>
> case B150: return 150;
>
> case B200: return 200;
>
> case B300: return 300;
>
> case B600: return 600;
>
> case B1200: return 1200;
>
> case B1800: return 1800;
>
> case B2400: return 2400;
>
> case B4800: return 4800;
>
> case B9600: return 9600;
>
> case B19200: return 19200;
>
> case B38400: return 38400;
>
> case B57600: return 57600;
>
> case B115200: return 115200;
>
> case B230400: return 230400;
>
> }
>
> throw comm_port_error("enum_to_baud, bad baud rate");
>
> }
>
>
>
> All my discussion is based on my belief that when we use Java tools like
> "Listen, MsgReader, etc.", these files are used… if not then I am wrong but
> if I am right, then we can see that after the baudrate of 115200bps, Linux
> machines can have only 230400bps whereas Windows can have 128000 and
> 256000bps.
>
>
>
> Secondly, my problem is that my platform has an atmel atmega128 processor,
> and all the platforms having this processor can either have 19200 or
> 57600bps BECAUSE in the UART code for atmega128 located at
> /tos/chips/atm128/Atm128UartP.nc, it defines the following:
>
>
>
> command error_t Init.init() {
>
> if (PLATFORM_BAUDRATE == 19200UL)
>
> m_byte_time = 200; // 1 TMicor ~= 2.12 us, one byte = 417us ~= 200
>
> else if (PLATFORM_BAUDRATE == 57600UL)
>
> m_byte_time = 68; // 1 TMicor ~= 2.12 us, one byte = 138us ~= 65
>
>
>
> return SUCCESS;
>
> }
>
>
>
> So, I tried to add the code here and define the following:
>
>
>
> else if (PLATFORM_BAUDRATE == 115200UL)
>
> m_byte_time = 33; // 1 TMicor ~= 2.12 us, one byte = 69us ~= 33 -à1 byte takes 69 us so 69/2.12 gives 33 (POINT ME IF I AM WRONG)
>
> else if (PLATFORM_BAUDRATE == 230400UL)
>
> m_byte_time = 17; // 1 TMicor ~= 2.12 us, one byte = 35us ~= 17
>
> else if (PLATFORM_BAUDRATE == 256000UL)
>
> m_byte_time = 15; // 1 TMicor ~= 2.12 us, one byte = 31us ~= 15
>
>
>
>
>
> I think either I have a fault in m_byte_time value because for 57600bps
> baudrate, it comes out 65, but a value of 68 is given in the basic code, I
> do not know why??
>
>
>
> THIS IS WHY I ASKED if the higher baudrates are handled differently in
> Linux and Windows???
>
>
>
> I need higher baudrate as the BaseStationw ill be receiving number of
> packets per second, so it needs to send it out of serial faster otherwise
> there will be a bottleneck.
>
>
>
> I hope my question is more clearer now….
>
>
>
> Cheers,
>
>
>
> Varun Jain
>
>
>
> *From:* Eric Decker [mailto:cire831 at gmail.com]
> *Sent:* Thursday, July 03, 2008 7:28 AM
> *To:* Varun Jain
> *Subject:* Re: [Tinyos-help] Serial Baudrate
>
>
>
> What do you mean "differently for Linux and Windows"?
>
> On Tue, Jul 1, 2008 at 7:37 PM, Varun Jain <varun at spiderbox.com.au> wrote:
>
> Hi,
>
> Does anyone knows if Baudrate over 115200 bps is handed differently in
> Tinyos-2.x for Linux and Windows(Cygwin). What are the maximum speeds I can
> set up for them? I currently have Atmega-128 controller
>
>
>
> Cheers,
>
>
>
> Varun Jain
>
>
>
>
> _______________________________________________
> Tinyos-help mailing list
> Tinyos-help at millennium.berkeley.edu
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
>
>
>
>
> --
> Eric B. Decker
> Senior (over 50 :-) Researcher
> Autonomous Systems Lab
> Jack Baskin School of Engineering
> UCSC
>
>
>
>
> --
> Eric B. Decker
> Senior (over 50 :-) Researcher
> Autonomous Systems Lab
> Jack Baskin School of Engineering
> UCSC
>
--
Eric B. Decker
Senior (over 50 :-) Researcher
Autonomous Systems Lab
Jack Baskin School of Engineering
UCSC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://www.millennium.berkeley.edu/pipermail/tinyos-help/attachments/20080703/acc123d1/attachment-0001.htm
More information about the Tinyos-help
mailing list