From: andreaskoepke Date: Wed, 5 Mar 2008 11:14:00 +0000 (+0000) Subject: baudrates revisited X-Git-Tag: release_tinyos_2_1_0_0~494 X-Git-Url: https://oss.titaniummirror.com/gitweb/?a=commitdiff_plain;ds=sidebyside;h=83aea03cb5781e0594fa6586d644f5cb90c3073d;p=tinyos-2.x.git baudrates revisited --- diff --git a/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyC.nc b/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyC.nc index fe2fb3be..4e794f3e 100644 --- a/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyC.nc +++ b/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyC.nc @@ -64,4 +64,10 @@ implementation UartPhyControl = Uart4b6bPhyP; Uart4b6bPhyP.RxByteTimer -> RxByteTimer; + +#ifdef UART_DEBUG + components new SerialDebugC() as SD; + Uart4b6bPhyP.SerialDebug -> SD; +#endif + } diff --git a/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyP.nc b/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyP.nc index 4b830dfe..dce79576 100644 --- a/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyP.nc +++ b/tos/platforms/eyesIFX/byte_radio/Uart4b6bPhyP.nc @@ -47,10 +47,21 @@ module Uart4b6bPhyP { uses { interface RadioByteComm; interface Alarm as RxByteTimer; +#ifdef UART_DEBUG + interface SerialDebug; +#endif } } implementation { +#ifdef UART_DEBUG + void sdDebug(uint16_t p) { + call SerialDebug.putPlace(p); + } +#else + void sdDebug(uint16_t p) {}; +#endif + /* Module Definitions */ typedef enum { STATE_PREAMBLE, @@ -72,7 +83,7 @@ implementation /* constants */ enum { PREAMBLE_LENGTH=2, - BYTE_TIME=21, + BYTE_TIME=ENCODED_32KHZ_BYTE_TIME+3, PREAMBLE_BYTE=0x55, SYNC_BYTE=0xFF, SFD_BYTE=0x83, @@ -96,6 +107,9 @@ implementation numPreambles = PREAMBLE_LENGTH; byteTime = BYTE_TIME; } +#ifdef UART_DEBUG + call SerialDebug.putShortDesc("U4b6bP"); +#endif return SUCCESS; } @@ -123,8 +137,9 @@ implementation call RxByteTimer.stop(); if(phyState >= STATE_DATA_HIGH) { signal PhyPacketRx.recvFooterDone(FAIL); + sdDebug(10); } - phyState = STATE_PREAMBLE; + phyState = STATE_PREAMBLE; } async event void RxByteTimer.fired() { @@ -182,6 +197,7 @@ implementation phyState = STATE_PREAMBLE; call RxByteTimer.stop(); signal PhyPacketRx.recvFooterDone(SUCCESS); + sdDebug(20); } diff --git a/tos/platforms/eyesIFX/byte_radio/UartManchPhyP.nc b/tos/platforms/eyesIFX/byte_radio/UartManchPhyP.nc index 0b39150e..c52a9f5c 100644 --- a/tos/platforms/eyesIFX/byte_radio/UartManchPhyP.nc +++ b/tos/platforms/eyesIFX/byte_radio/UartManchPhyP.nc @@ -75,7 +75,7 @@ implementation } phyState_t; #define PREAMBLE_LENGTH 2 -#define BYTE_TIME 21 +#define BYTE_TIME TDA5250_32KHZ_BYTE_TIME #define PREAMBLE_BYTE 0x55 #define SYNC_BYTE 0xFF #define SFD_BYTE 0x50 diff --git a/tos/platforms/eyesIFX/byte_radio/code4b6b.h b/tos/platforms/eyesIFX/byte_radio/code4b6b.h index f376f86b..d504f829 100644 --- a/tos/platforms/eyesIFX/byte_radio/code4b6b.h +++ b/tos/platforms/eyesIFX/byte_radio/code4b6b.h @@ -38,7 +38,8 @@ #define CODE_4B_6B_H enum { - ILLEGAL_CODE = 0xff + ILLEGAL_CODE = 0xff, + ENCODED_32KHZ_BYTE_TIME = 3*TDA5250_32KHZ_BYTE_TIME/2 }; const uint8_t nibbleToSixBit[] = { diff --git a/tos/platforms/eyesIFX/byte_radio/manchester.h b/tos/platforms/eyesIFX/byte_radio/manchester.h new file mode 100644 index 00000000..2585ff1d --- /dev/null +++ b/tos/platforms/eyesIFX/byte_radio/manchester.h @@ -0,0 +1,170 @@ +/* -*- mode:c++; indent-tabs-mode: nil -*- + * Copyright (c) 2006, Technische Universitaet Berlin + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * - Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * - Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * - Neither the name of the Technische Universitaet Berlin nor the names + * of its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED + * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, + * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY + * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE + * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * - Description --------------------------------------------------------- + * provide functions to encode/decode a manchester stream + * - Revision ------------------------------------------------------------- + * $Revision$ + * $Date$ + * @author Andreas Koepke + * ======================================================================== + */ + +enum { + ILLEGAL_CODE = 0xff, + ENCODED_32KHZ_BYTE_TIME = 2*TDA5250_32KHZ_BYTE_TIME +}; + +const uint8_t nibbleToManchesterByte[] = { + 0x55, + 0x56, + 0x59, + 0x5a, + 0x65, + 0x66, + 0x69, + 0x6a, + 0x95, + 0x96, + 0x99, + 0x9a, + 0xa5, + 0xa6, + 0xa9, + 0xaa +}; + +const uint8_t manchesterByteToNibble[] = { + 0x0, + 0x1, + 0xff, + 0xff, + 0x2, + 0x3, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0x4, + 0x5, + 0xff, + 0xff, + 0x6, + 0x7, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0x8, + 0x9, + 0xff, + 0xff, + 0xa, + 0xb, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xff, + 0xc, + 0xd, + 0xff, + 0xff, + 0xe, + 0xf +}; + +uint8_t manchesterEncodeNibble(uint8_t nib) +{ + return nibbleToManchesterByte[nib]; +} + +uint8_t manchesterDecodeByte(uint8_t b) +{ + uint8_t dec; + + if(b < 0x55) { + dec = 0xff; + } + else if(b > 0xaa) { + dec = 0xff; + } + else { + dec = manchesterByteToNibble[b - 0x55]; + } + return dec; +} diff --git a/tos/platforms/eyesIFX/chips/msp430/Msp430DcoSpec.h b/tos/platforms/eyesIFX/chips/msp430/Msp430DcoSpec.h index ae6c97c8..54f17cc0 100644 --- a/tos/platforms/eyesIFX/chips/msp430/Msp430DcoSpec.h +++ b/tos/platforms/eyesIFX/chips/msp430/Msp430DcoSpec.h @@ -40,6 +40,6 @@ #ifndef MS430DCOSPEC_H #define MS430DCOSPEC_H -#define TARGET_DCO_KHZ 3906 // the target MCLK clock rate in binary kHz (4 000 000 Hz) +#define TARGET_DCO_KHZ 3926 // the target MCLK clock rate in binary kHz (4 020 000 Hz) #define ACLK_KHZ 32 // the ACLK rate in binary kHz #endif diff --git a/tos/platforms/eyesIFX/chips/tda5250/eyesIFXBaudrates.h b/tos/platforms/eyesIFX/chips/tda5250/eyesIFXBaudrates.h new file mode 100644 index 00000000..2863240e --- /dev/null +++ b/tos/platforms/eyesIFX/chips/tda5250/eyesIFXBaudrates.h @@ -0,0 +1,68 @@ +/* auto generated from tda5250BusResourceSettings.h using the following perl script: + +#!/usr/bin/perl -w +use strict; +my $state = "START"; +my $br; +while(<>) { + if(/UBR_1MHZ_/) { + ($br) = /UBR_1MHZ_(\d+)/; + if($state eq "START") { + print '#if '; + $state = "MIDDLE"; + } + else { + print '#elif '; + } + print 'TDA5250_UART_BAUDRATE == ', $br,"\n"; + print '#define TDA5250_UART_UBR UBR_1MHZ_', $br, "\n"; + print '#define TDA5250_UART_UMCTL UMCTL_1MHZ_', $br, "\n"; + } +} +print '#endif',"\n" + +*/ + +#if TDA5250_UART_BAUDRATE == 35108 +#define TDA5250_UART_UBR UBR_1MHZ_35108 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_35108 +#elif TDA5250_UART_BAUDRATE == 10240 +#define TDA5250_UART_UBR UBR_1MHZ_10240 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_10240 +#elif TDA5250_UART_BAUDRATE == 10922 +#define TDA5250_UART_UBR UBR_1MHZ_10922 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_10922 +#elif TDA5250_UART_BAUDRATE == 11702 +#define TDA5250_UART_UBR UBR_1MHZ_11702 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_11702 +#elif TDA5250_UART_BAUDRATE == 12603 +#define TDA5250_UART_UBR UBR_1MHZ_12603 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_12603 +#elif TDA5250_UART_BAUDRATE == 13653 +#define TDA5250_UART_UBR UBR_1MHZ_13653 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_13653 +#elif TDA5250_UART_BAUDRATE == 14894 +#define TDA5250_UART_UBR UBR_1MHZ_14894 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_14894 +#elif TDA5250_UART_BAUDRATE == 16384 +#define TDA5250_UART_UBR UBR_1MHZ_16384 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_16384 +#elif TDA5250_UART_BAUDRATE == 18204 +#define TDA5250_UART_UBR UBR_1MHZ_18204 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_18204 +#elif TDA5250_UART_BAUDRATE == 20480 +#define TDA5250_UART_UBR UBR_1MHZ_20480 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_20480 +#elif TDA5250_UART_BAUDRATE == 23405 +#define TDA5250_UART_UBR UBR_1MHZ_23405 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_23405 +#elif TDA5250_UART_BAUDRATE == 27306 +#define TDA5250_UART_UBR UBR_1MHZ_27306 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_27306 +#elif TDA5250_UART_BAUDRATE == 32768 +#define TDA5250_UART_UBR UBR_1MHZ_32768 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_32768 +#elif TDA5250_UART_BAUDRATE == 40960 +#define TDA5250_UART_UBR UBR_1MHZ_40960 +#define TDA5250_UART_UMCTL UMCTL_1MHZ_40960 +#endif diff --git a/tos/platforms/eyesIFX/chips/tda5250/tda5250BusResourceSettings.h b/tos/platforms/eyesIFX/chips/tda5250/tda5250BusResourceSettings.h index a4ab9cc1..9093ba4b 100644 --- a/tos/platforms/eyesIFX/chips/tda5250/tda5250BusResourceSettings.h +++ b/tos/platforms/eyesIFX/chips/tda5250/tda5250BusResourceSettings.h @@ -40,12 +40,39 @@ enum { TDA5250_UART_BUS_ID = unique(MSP430_UARTO_BUS) }; +/* frequency of crystal: 18089580 Hz, + divide by 18 -> 1004976 Hz */ + +#ifndef TDA5250_UART_BAUDRATE +#define TDA5250_UART_BAUDRATE 40960U +#endif + enum { - // real milli seconds - UBR_1MHZ_23405=0x002A, UMCTL_1MHZ_23405=0xDD, // 23405 bit/s - UBR_1MHZ_35108=0x001C, UMCTL_1MHZ_35108=0xAA, // 35108 bit/s + /** for reference, not recommended for new experiments */ + UBR_1MHZ_35108=0x001C, UMCTL_1MHZ_35108=0xAA, // 35108 bit/s + + /** use real frequency, use only settings that result in an even byte time */ + UBR_1MHZ_10240=0x0062, UMCTL_1MHZ_10240=0x08, // 10240 bit/s + UBR_1MHZ_10922=0x005C, UMCTL_1MHZ_10922=0x00, // 10922 bit/s + UBR_1MHZ_11702=0x0055, UMCTL_1MHZ_11702=0xEF, // 11702 bit/s + UBR_1MHZ_12603=0x004F, UMCTL_1MHZ_12603=0xDD, // 12603 bit/s + UBR_1MHZ_13653=0x0049, UMCTL_1MHZ_13653=0xB5, // 13653 bit/s + UBR_1MHZ_14894=0x0043, UMCTL_1MHZ_14894=0xAA, // 14894 bit/s + UBR_1MHZ_16384=0x003D, UMCTL_1MHZ_16384=0x92, // 16384 bit/s + UBR_1MHZ_18204=0x0037, UMCTL_1MHZ_18204=0x84, // 18204 bit/s + UBR_1MHZ_20480=0x0031, UMCTL_1MHZ_20480=0x80, // 20480 bit/s + UBR_1MHZ_23405=0x002A, UMCTL_1MHZ_23405=0x7F, // 23405 bit/s + UBR_1MHZ_27306=0x0024, UMCTL_1MHZ_27306=0x7B, // 27306 bit/s + UBR_1MHZ_32768=0x001E, UMCTL_1MHZ_32768=0x5B, // 32768 bit/s + UBR_1MHZ_40960=0x0018, UMCTL_1MHZ_40960=0x55, // 40960 bit/s }; -msp430_uart_union_config_t tda5250_uart_config = { {ubr: UBR_1MHZ_35108, umctl: UMCTL_1MHZ_35108, ssel: 0x02, pena: 0, pev: 0, spb: 0, clen: 1, listen: 0, mm: 0, ckpl: 0, urxse: 0, urxeie:0, urxwie: 0, urxe: 1, utxe: 0} }; +#include "eyesIFXBaudrates.h" + +msp430_uart_union_config_t tda5250_uart_config = { {ubr: TDA5250_UART_UBR, umctl: TDA5250_UART_UMCTL, ssel: 0x02, pena: 0, pev: 0, spb: 0, clen: 1, listen: 0, mm: 0, ckpl: 0, urxse: 0, urxeie:0, urxwie: 0, urxe: 1, utxe: 0} }; + +enum { + TDA5250_32KHZ_BYTE_TIME = (32768UL*10)/TDA5250_UART_BAUDRATE +}; #endif diff --git a/tos/platforms/eyesIFX/chips/tda5250/tda5250RegDefaultSettings.h b/tos/platforms/eyesIFX/chips/tda5250/tda5250RegDefaultSettings.h index 561ecb5c..b15f3a51 100644 --- a/tos/platforms/eyesIFX/chips/tda5250/tda5250RegDefaultSettings.h +++ b/tos/platforms/eyesIFX/chips/tda5250/tda5250RegDefaultSettings.h @@ -71,7 +71,7 @@ // choose one #define INITIAL_RF_POWER RF_HITX_DAMPING_0dB -#define TDA5250_REG_DEFAULT_SETTING_CONFIG FULL_RANGE +#define TDA5250_REG_DEFAULT_SETTING_CONFIG MED_RANGE_LP #define TDA5250_REG_DEFAULT_SETTING_FSK 0x0A0C #define TDA5250_REG_DEFAULT_SETTING_XTAL_TUNING 0x0012 #define TDA5250_REG_DEFAULT_SETTING_LPF 0x98 diff --git a/tos/platforms/eyesIFX/eyesIFXSerialP.nc b/tos/platforms/eyesIFX/eyesIFXSerialP.nc index 933b288e..4d946689 100644 --- a/tos/platforms/eyesIFX/eyesIFXSerialP.nc +++ b/tos/platforms/eyesIFX/eyesIFXSerialP.nc @@ -5,8 +5,7 @@ module eyesIFXSerialP { } implementation { enum { - // true mega hertz - UBR_1MHZ_57601=0x0011, UMCTL_1MHZ_57601=0x52 // 57600 bit/s + UBR_1MHZ_57601=0x0011, UMCTL_1MHZ_57601=0xAA // 57600 bit/s }; msp430_uart_union_config_t msp430_uart_eyes_config = { {ubr: UBR_1MHZ_57601, umctl: UMCTL_1MHZ_57601, ssel: 0x02, pena: 0, pev: 0, spb: 0, clen: 1, listen: 0, mm: 0, ckpl: 0, urxse: 0, urxeie: 1, urxwie: 0, urxe: 1, utxe: 1} };