Subversion Repositories Projects

Compare Revisions

Ignore whitespace Rev 1914 → Rev 1920

/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Text File
0,0 → 1,177
// wi232.c:
//
// Call fopen_wi232() to set up the wi232 as an input output data stream.
// If fopen_wi232() is the first fopen command called, then the wi232
// becomes stdin and stdout and stderr.
// The
//
// Uses Interupts to handle data streaming. The wi232 uses USART0, which uses:
// Rx = PORTE0 = pin 2
// Tx = PORTE1 = pin 3
// CTS = PORTE2 = pin 4
#include <inttypes.h>
#include <stdio.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/signal.h>
 
#include "wi232.h"
#include "circularqueue.h"
#include "usart.h"
 
const int _baud_rate_c = 38400;
const int _tx_buffer_size_c = 256;
const int _rx_buffer_size_c = 256;
const uint8_t _cts_pin_c = _BV( PINE2 );
 
volatile char wi232_tx_buffer[ _tx_buffer_size_c ];
volatile char wi232_rx_buffer[ _rx_buffer_size_c ];
 
// circular queues used for the USART
CircularQueue< volatile char > wi232_tx_q( wi232_tx_buffer, _tx_buffer_size_c );
CircularQueue< volatile char > wi232_rx_q( wi232_rx_buffer, _rx_buffer_size_c );
 
// prototype
int wi232_putchar( char );
int wi232_getchar();
void initialize_baud_rate();
void command( bool enable );
void write_register( uint8_t reg, uint8_t value );
bool _cts();
 
// use BAUD_RATE baud 8N1 RX & TX on USART0
// to transmit to the wi232
FILE* fopen_wi232()
{
// enable Rx, Tx & Rx interupt
// (Tx buffer empty interupt is enabled when we actually send something)
UCSR0B = _BV( RXEN0 ) |
_BV( TXEN0 ) |
_BV( RXCIE0 );
// UCSC00 = 1 & UCSC01 = 1 -> 8-bit data
UCSR0C = _BV( UCSZ00 ) | _BV( UCSZ01 );
initialize_baud_rate();
wi232_tx_q.clear();
wi232_rx_q.clear();
 
// set wi232_putchar as the stdout stream character Tx-er
// set wi232_getchar as the stdin stream chacacter Rx-er
return fdevopen( wi232_putchar, wi232_getchar, 0 );
}
 
inline void initialize_baud_rate()
{
// enable command pin as output
DDRE |= _BV( PORTE3 );
command( true );
usart0_set_baud_rate( 2400 );
sei();
write_register( 78, 3 ); // set baud rate to 38400
wait(100);
cli();
usart0_set_baud_rate( 38400 );
command( false );
}
 
inline void command( bool enable )
{
if ( enable )
PORTE &= ~_BV( PORTE3 );
else
PORTE |= _BV( PORTE3 );
}
 
inline void write_register( uint8_t reg, uint8_t value )
{
if ( value < 0x80 )
{
// data = [ 0xFF, 2, reg, value ]
wi232_putchar( 0xFF );
wi232_putchar( 2 );
wi232_putchar( reg );
wi232_putchar( value );
}
else // value >= 0x80
{
// data = [ 0xFF, 3, reg, 0xFE, (value - 0x80) ]
wi232_putchar( 0xFF );
wi232_putchar( 3 );
wi232_putchar( reg );
wi232_putchar( 0xFE );
wi232_putchar( value - 0x80 );
}
}
 
int wi232_putchar( char x )
{
wi232_tx_q.put( x );
// enable the "data register empty" interupt
// (it may already be enabled in which case no harm is done)
UCSR0B |= _BV( UDRIE0 );
 
// return -1 if overflow is true, otherwise return 0
// return wi232_tx_q.overflow() ? -1 : 0;
return 0; // for now, screw overflow - just ignore it
}
 
int wi232_getchar()
{
// wait until the queue is no longer empty
while ( wi232_rx_q.is_empty() );
 
char x = wi232_rx_q.get();
return x;
}
 
uint16_t wi232_data_available()
{
return wi232_rx_q.length();
}
 
bool wi232_is_empty()
{
return wi232_rx_q.is_empty();
}
 
// returns true when CTS is low,
// i.e. it is true when it is okay to send data
inline bool _cts()
{
return !(PINE & _cts_pin_c);
}
 
// we received some data on USART0
// put this data into the received data queue
SIGNAL( SIG_UART0_RECV )
{
wi232_rx_q.put( UDR0 );
}
 
// the USART is ready to queue another byte to send
SIGNAL( SIG_UART0_DATA )
{
if ( !wi232_tx_q.is_empty() )
{
if ( !_cts() )
{
sei();
// wait until CTS is true
while ( !_cts() );
}
 
// if the queue is not empty, put the next character in the buffer
// this also resets the interupt flag automatically
UDR0 = wi232_tx_q.get();
}
else
{
// disable the interupt
UCSR0B &= ~_BV( UDRIE0 );
}
}
 
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Wi232.c
0,0 → 1,621
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* 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; either 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
 
 
#include "../cpu.h"
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <util/delay.h>
#include <stdlib.h>
#include <string.h>
#include "../lcd/lcd.h"
#include "../uart/usart.h"
#include "../uart/uart1.h"
#include "../main.h"
#include "../wi232/Wi232.h"
#include "../timer/timer.h"
#include "../eeprom/eeprom.h"
#include "../setup/setup.h"
 
 
 
 
 
#if defined HWVERSION1_3W || defined HWVERSION3_9 || defined HWVERSION1_2W
 
uint8_t Wi232_hardware = 0;
uint8_t InitErr=0;
uint8_t Wi232_Baudrate = 0; //Merkzelle für aktuelle Baudrate
uint8_t Wi232_New_Baudrate = 0; //Merkzelle für zu setzende Baudrate
 
 
uint16_t SearchWi232(uint8_t Baudrate) // Suche Wi232 mit entsprechender Baudrate
 
// Return = 0, Wi232 not found
 
{
int16_t RegisterWi232;
 
SetBaudUart0(Baudrate);
lcd_printpns_at (0, 1, PSTR(" with Baud"),0);
switch (Baudrate)
{
case Baud_2400: lcd_printpns_at (6, 1, PSTR(" 2400"),0);break;
case Baud_9600: lcd_printpns_at (6, 1, PSTR(" 9600"),0);break;
case Baud_19200: lcd_printpns_at (6, 1, PSTR(" 19200"),0);break;
case Baud_38400: lcd_printpns_at (6, 1, PSTR(" 38400"),0);break;
case Baud_57600: lcd_printpns_at (6, 1, PSTR(" 57600"),0);break;
case Baud_115200:lcd_printpns_at (6, 1, PSTR("115200"),0);break;
break;
}
 
RegisterWi232 = ReadWi232(regDiscover);
lcd_print_hex_at(0,2,RegisterWi232,0);
if (RegisterWi232 > 0 && RegisterWi232 < 0xFF)
{ Wi232_hardware = 2;
Wi232_Baudrate = Baudrate;
}
return RegisterWi232;
}
 
 
/*************************************************************************
Function: discoverWI232()
Purpose: check if Wi232 available
Returns: Version or 0 = timeout
 
**************************************************************************/
void discoverWi232(uint8_t DiscBaudrate)
 
{
 
int16_t RegisterWi232=0;
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
set_WI232CMD();
_delay_ms(200);
lcd_cls();
SetBaudUart0( DiscBaudrate);
 
lcd_printpns_at (0, 0, PSTR("search Wi.232 Modul"),0);
 
{
while (RegisterWi232==0)
{
RegisterWi232=SearchWi232(DiscBaudrate); if (RegisterWi232 !=0) {Wi232_hardware = 1; continue;}
RegisterWi232=SearchWi232(Baud_2400); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_9600); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_19200); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_38400); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_57600); if (RegisterWi232 !=0) continue;
RegisterWi232=SearchWi232(Baud_115200); if (RegisterWi232 !=0) continue;
break;
}
// _delay_ms(1000);
 
}
 
if (RegisterWi232 == 0)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("no Wi.232 found"),0);
Wi232_hardware = 0;
_delay_ms(2000);
}
 
if (RegisterWi232 == 0xFF)
{
lcd_cls();
lcd_printpns_at (0, 0, PSTR("Wi.232 Sytaxerror "),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
RegisterWi232 = 0;
}
 
if (RegisterWi232 > 0 && RegisterWi232 < 0xFF)
{
lcd_cls();
SetBaudUart0(Wi232_Baudrate);
 
if (Wi232_hardware ==1) // alles ok , Baudrate Wi232 passt
lcd_printpns_at (0, 0, PSTR("Wi.232 found "),0);
 
if (Wi232_hardware ==2) // Wi232 gefunden, aber falsche Baudrate
{
Config.WiIsSet= false; //wenn hier 2400 gefunden wurde, ist Wi232 nicht initialisiert
lcd_printpns_at (0, 0, PSTR("Wi.232 wrong Baudrate"),0);
if (WriteWi232(regNVDATARATE,Config.PKT_Baudrate)!=0) /* NV-Ram auf PKT-Baudrate setzen*/
{
lcd_printpns_at (0, 1, PSTR("Error set NV-RAM"),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
// else
// {
//// _delay_ms(1000);
// lcd_printpns_at (0, 1, PSTR("NV-RAM is set to "),0);
// lcd_printpns_at (0, 2, PSTR("given Baudrate"),0);
// _delay_ms(2000);
// }
 
if (WriteWi232(regDATARATE,Config.PKT_Baudrate)!=0) /* Ram auf PKT_Baudrate setzen*/
{
lcd_printpns_at (0, 3, PSTR("Error set RAM "),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
// else
// {
//// _delay_ms(1000);
// lcd_printpns_at (0, 1, PSTR("RAM is set to "),0);
// lcd_printpns_at (0, 2, PSTR("given Baudrate"),0);
// _delay_ms(2000);
// }
 
SetBaudUart0(Config.PKT_Baudrate);
Old_Baudrate = Config.PKT_Baudrate;
 
}
lcd_cls_line (0,1,21);
lcd_printpns_at (0, 1, PSTR("Version:"),0);
lcd_print_hex_at(9,1,RegisterWi232,0);
}
clr_WI232CMD();
}
 
 
/*************************************************************************
Function: InitWI232()
Purpose: set Wi232Register for Mikrokopter
Returns: 0 = ACK, FF = NAK
 
**************************************************************************/
void InitWi232(uint8_t InitBaudrate)
{
 
uint8_t i = 0;
#ifdef HWVERSION3_9
Change_Output(Uart02Wi); // Verbindung zu Wi232 herstellen
#endif
 
discoverWi232(Old_Baudrate); // Check if Wi232 available
 
if (Wi232_hardware != 0)
{
lcd_printpns_at (0, 2, PSTR("Init Wi232 wait...."),0);
set_WI232CMD();
_delay_ms(200);
SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
if (WriteWi232(regNETGRP,126)!=0) /*damit Wi232 nix mehr vom Kopter schickt erstmal Networkgroup ins Nirwana setzen */
lcd_printpns_at (i++,4,PSTR("."),0);
// InitErr =12;
// Grund:
//If RF packets are received while the CMD line is active,
//they are still processed and presented to the module’s UART for transmission.
 
// wenn sich ein EEPROM-Wert ändert wird auch das Ram beschrieben damit die Änderung sofort wirksam wird
if (WriteWi232(regNVTXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(1); /*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(2);/*TX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVRXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(3);/* RX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regRXCHANNEL,Config.WiTXRXChannel)!=0)
InitErrorWi232(4);/* RX Channel*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVSLPMODE ,Sleep_Awake)!=0)
InitErrorWi232(5);/* Sleepmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVPWRMODE,WbModeP15)!=0)
InitErrorWi232(6);/* Transceiver Mode/Powermode */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVTXTO,Config.WiTXTO)!=0)
InitErrorWi232(7);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regTXTO,Config.WiTXTO)!=0)
InitErrorWi232(8);/* UART Timeout */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVUARTMTU,Config.WiUartMTU)!=0)
InitErrorWi232(9);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regUARTMTU,Config.WiUartMTU)!=0)
InitErrorWi232(10);/* UART Buffer*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETMODE,Config.WiNetworkMode)!=0)
InitErrorWi232(11);/* Networkmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETMODE,Config.WiNetworkMode)!=0)
InitErrorWi232(12);/* Networkmode*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVUSECRC ,CRC_Enable)!=0)
InitErrorWi232(13);/* CRC*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVCSMAMODE,CSMA_En)!=0)
InitErrorWi232(14);/* CSMA*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVNETGRP,Config.WiNetworkGroup)!=0)
InitErrorWi232(15);/* Networkgroup */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNETGRP,Config.WiNetworkGroup)!=0)
InitErrorWi232(15);/* Networkgroup */
lcd_printpns_at (i++,4,PSTR("."),0);
 
if (WriteWi232(regNVDATARATE,InitBaudrate)!=0)
InitErrorWi232(16);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
_delay_ms(200);
 
if (WriteWi232(regDATARATE,InitBaudrate)!=0)
InitErrorWi232(17);/* Baudrate*/
lcd_printpns_at (i++,4,PSTR("."),0);
 
 
clr_WI232CMD();
 
if (InitErr !=0)
{
lcd_printpns_at (0, 2, PSTR("Wi232 InitError "),0);
lcd_print_hex(InitErr,0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
}
else
{
lcd_printpns_at (0, 2, PSTR("Wi232 Init ok...."),0);
WriteWiInitFlag(); // Init merken
lcd_print_hex(InitBaudrate,0);
}
SetBaudUart0(InitBaudrate);
_delay_ms(2000);
}
}
 
/*************************************************************************
Function: InitErrorWI232()
Purpose: Show Wi232 Error, Value
Returns:
**************************************************************************/
void InitErrorWi232(uint8_t Error)
{
 
lcd_printpns_at (0, 3, PSTR("Wi232 InitError "),0);
lcd_print_hex(Error,0);
InitErr=Error;
set_beep ( 500, 0x0040, BeepNormal);
_delay_ms(500);
 
}
 
 
 
 
/*************************************************************************
Function: WriteWI232()
Purpose: set Register to Wi232, Register, Value
Returns: 0 = ACK, FF = NAK
ACHTUNG nur für Value <0x80
**************************************************************************/
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue)
 
{
uint8_t timeout=10;
uint8_t tc=0;
unsigned int v;
 
if ( RegisterValue < 0x80 )
{
USART_putc(0xff);
USART_putc(0x02);
USART_putc(Wi232Register);
USART_putc(RegisterValue);
}
else // RegisterValue >= 0x80
{
USART_putc(0xff);
USART_putc(0x03);
USART_putc(Wi232Register);
USART_putc(0xfe);
USART_putc(RegisterValue - 0x80);
}
 
 
do
{
v = USART_getc(); /*ACK erwartet*/
_delay_ms(100);
tc ++;
}
while (v==0 && tc!=timeout);
 
// lcd_print_hex(v,0);
if (v != 0x06)
{
lcd_printpns_at (0, 2, PSTR("Wi.232 NAK"),0);
set_beep ( 1000, 0x0040, BeepNormal);
_delay_ms(2000);
return 0xFF;
}
 
if (v==0x06)
return 0;
 
return 0xFF;
}
 
 
/*************************************************************************
Function: ReadWI232()
Purpose: send Readcommand to Wi232,
Returns: Registervalue, 0 = timeout 0xFF = Syntaxerror
 
**************************************************************************/
int16_t ReadWi232(uint16_t Wi232Register)
 
{
uint8_t timeout=10;
uint8_t tc=0;
 
 
unsigned int v;
 
v = USART_getc(); /*Zeichen löschen*/
USART_putc(0xff);
USART_putc(0x02);
USART_putc(0xfe);
USART_putc(Wi232Register);
_delay_ms(50);
// lcd_printpns_at (0, 2, PSTR("read Wi232"),0);
 
 
do
{
v = USART_getc(); /*ACK erwartet*/
_delay_ms(100);
tc ++;
}
while (v==0 && tc!=timeout);
 
if (tc == timeout)
return 0; /* Timeout*/
 
if (v != 0x06)
return 0xFF; /* Syntaxerror*/
 
// lcd_print_hex(v,0);
// v = USART_getc(); /*Register*/
// lcd_print_hex(v,0);
// v = USART_getc(); /*Value*/
// lcd_print_hex(v,0);
 
return v;
 
}
 
 
 
///*************************************************************************
//Function: EscapeString()
//Purpose:
//Returns:
//Quelle: Radiotronix Wi.232 Manual
//**************************************************************************/
//
//
//int EscapeString(char *src, char src_len, char *dest)
//{
// // The following function copies and encodes the first
// // src_len characters from *src into *dest. This
// // encoding is necessary for Wi.232 command formats.
// // The resulting string is null terminated. The size
// // of this string is the function return value.
// // ---------------------------------------------------
// uint8_t src_idx, dest_idx;
// // Save space for the command header and size bytes
// // ------------------------------------------------
// dest_idx = 2;
// // Loop through source string and copy/encode
// // ------------------------------------------
// for (src_idx = 0; src_idx < src_len; src_idx++)
// {
// if (src[src_idx] > 127)
// {
// dest[dest_idx++] = 0xFE;
// }
// dest[dest_idx++] = (src[src_idx] & 0x7F);
// }
// // Add null terminator
// // -------------------
// dest[dest_idx] = 0;
// // Add command header
// // ------------------
// dest[0] = 0xFF;
// dest[1] = dest_idx-2;
//
// // Return escape string size
// // -------------------------
// return dest_idx;
//}
 
 
//#if defined HWVERSION1_3W || defined HWVERSION3_9
///*************************************************************************
//Function: Wi232USB()
//Purpose: Connect Wi232 Programmmode to PKT USB,
//Returns:
//
//**************************************************************************/
//void Wi232_USB(void)
//
//
//{
// unsigned int c0,c1;
//
// if (Wi232_hardware==1)
// {
//// USART_Init (UART_BAUD_SELECT(57600,F_CPU));
//// uart1_init( UART_BAUD_SELECT(57600,F_CPU) );
//// USART_Init (UART_BAUD_SELECT(2400,F_CPU));
//// uart1_init( UART_BAUD_SELECT(2400,F_CPU) );
// }
//
// if (Wi232_hardware==2)
// {
// USART_Init (UART_BAUD_SELECT(2400,F_CPU));
// uart1_init( UART_BAUD_SELECT(2400,F_CPU) );
// }
//
// lcd_cls ();
//// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
//
// set_WI232CMD();
//
// lcd_printpns_at (0, 0, PSTR("Wi.232 Konfiguration "),0);
// lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0);
// lcd_printpns_at (0, 2, PSTR("Wi.232"),0);
// lcd_printpns_at (0, 3, PSTR("Programm starten"),0);
// lcd_printpns_at (17, 7, PSTR("Exit"),0);
//
// c1 = 0;
//
// for(;;)
// {
// c0 = uart1_getc(); /* from USB*/
// if ( c0 & UART_NO_DATA )
// {
// c1 = USART_getc();
//
// if (c1 == 0)
// {}
// else
// {
//// lcd_print_hex(c1,0);
// uart1_putc (c1); /*to USB*/;
// }
// }
// else
// {
// USART_putc(c0 ); /* to Wi232*/
//// lcd_print_hex(c0,0);
//// _delay_ms(1);
// }
//
// if ((get_key_press (1 << KEY_ENTER)))
// {
// clr_WI232CMD();
//// uart1_init( UART_BAUD_SELECT(57600,F_CPU) );
//// USART_Init( UART_BAUD_SELECT(57600,F_CPU) );
//// SwitchToFC();
// return;
// }
//
// }
//}
///*************************************************************************
//Function: Wi232_FC()
//Purpose: Connect Wi232 to PKT USB, Transparent
//Returns:
//
//**************************************************************************/
//void Wi232_FC(void)
//
//
//{
// unsigned int c0,c1;
//
//
//// USART_Init (UART_BAUD_SELECT(PKT_Baudrate,F_CPU));
//// uart1_init( UART_BAUD_SELECT(PKT_Baudrate,F_CPU) );
// SetBaudUart0(Config.PKT_Baudrate);
// SetBaudUart1(Config.PKT_Baudrate);
//
//
// lcd_cls ();
//// SwitchToWi232(); /* Serielle Kanäle Wi232 mit USB verbinden*/
//
//
// lcd_printpns_at (0, 0, PSTR("Wi.232 to FC "),0);
// lcd_printpns_at (0, 1, PSTR("PC mit USB verbinden"),0);
// lcd_printpns_at (0, 2, PSTR("und Mikrokoptertool"),0);
// lcd_printpns_at (0, 3, PSTR("starten"),0);
// lcd_printpns_at (17, 7, PSTR("Exit"),0);
//
// c1 = 0;
//
// for(;;)
// {
// c0 = uart1_getc(); /* from USB*/
// if ( c0 & UART_NO_DATA )
// {
// c1 = USART_getc();
// if (c1 == 0)
// {}
// else
// {
//// lcd_print_hex(c1,0);
// uart1_putc (c1); /*to USB*/;
//
// }
// }
// else
// {
// USART_putc(c0 ); /* to Wi232*/
//// lcd_print_hex(c0,0);
//// _delay_ms(1);
// }
//
// if ((get_key_press (1 << KEY_ENTER)))
// {
// return;
// }
// }
//}
 
 
#endif
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property
/Transportables_Koptertool/branch/test2/GPL_PKT_V3_6_7f_FC090b/wi232/Wi232.h
0,0 → 1,178
/*****************************************************************************
* Copyright (C) 2008 Thomas Kaiser, thomas@ft-fanpage.de *
* Copyright (C) 2009 Peter "woggle" Mack, mac@denich.net *
* Copyright (C) 2011 Christian "Cebra" Brandtner, brandtner@brandtner.net *
* Copyright (C) 2011 Harald Bongartz *
* *
* 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; either 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. *
* *
* You should have received a copy of the GNU General Public License *
* along with this program; if not, write to the *
* Free Software Foundation, Inc., *
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
* *
* *
* Credits to: *
* Holger Buss & Ingo Busker from mikrokopter.de for the MK project + SVN *
* http://www.mikrokopter.de *
* Gregor "killagreg" Stobrawa for his version of the MK code *
* Thomas Kaiser "thkais" for the original project. See *
* http://www.ft-fanpage.de/mikrokopter/ *
* http://forum.mikrokopter.de/topic-4061-1.html *
* Claas Anders "CaScAdE" Rathje for providing the font and his C-OSD code *
* http://www.mylifesucks.de/oss/c-osd/ *
* Harald Bongartz "HaraldB" for providing his Ideas and Code for usibility*
*****************************************************************************/
 
#ifndef WI232_H_
#define WI232_H_
 
 
void discoverWi232(uint8_t Baudrate);
void InitWi232(uint8_t Baudrate);
int16_t WriteWi232(uint8_t Wi232Register, uint8_t RegisterValue);
int16_t ReadWi232(uint16_t Wi232Register);
void InitErrorWi232(uint8_t Error);
extern uint8_t Wi232_hardware;
extern uint8_t Wi232_New_Baudrate; //Merkzelle für zu setzende Baudrate
 
 
// Non-volatile Registers
// Name Address Description Default
#define regNVTXCHANNEL 0x00 // Transmit channel setting ## 0 ##
#define regNVRXCHANNEL 0x01 // Receive channel setting ## 0 ##
#define regNVPWRMODE 0x02 // Operating mode settings ## +13 dBm widebandmode ##
#define regNVDATARATE 0x03 // UART data rate ## 2400bps ##
#define regNVNETMODE 0x04 // Network mode (Normal/Slave) ## Normal ##
#define regNVTXTO 0x05 // Transmit wait timeout ## ~16ms ##
#define regNVNETGRP 0x06 // Network group ID ## 0x00 ##
#define regNVUSECRC 0x08 // Enable/Disable CRC ## Enabled ##
#define regNVUARTMTU 0x09 // Minimum transmission unit. ## 64 bytes ##
#define regNVSHOWVER 0x0A // Enable/Disable start-up message ## Enabled ##
#define regNVCSMAMODE 0x0B // Enable/Disable CSMA ## Enabled ##
#define regNVSLPMODE 0x0D // Power state of module ## Awake ##
#define regNVACKONWAKE 0x0E // Send ACK character to host on wake
 
 
// Non-volatile Read Only Registers
// Name Address Description
#define regMAC0 0x22 // These registers form the unique 48-bit MAC address.
#define regMAC1 0x23 // MAC
#define regMAC2 0x24 // MAC
#define regOUI0 0x25 // MAC
#define regOUI1 0x26 // MAC
#define regOUI2 0x27 // MAC
 
#define regDiscover 0x78 // Versionsregister
 
 
// Volatile Read/Write Registers
// Name Address Description
#define regTXCHANNEL 0x4B // Transmit channel setting
#define regRXCHANNEL 0x4C // Receive channel setting
#define regPWRMODE 0x4D // Operating mode settings
#define regDATARATE 0x4E // UART data rate
#define regNETMODE 0x4F // Network mode (Normal or Slave)
#define regTXTO 0x50 // Transmit wait timeout
#define regNETGRP 0x51 // Network group ID
#define regUSECRC 0x53 // Enable/Disable CRC
#define regUARTMTU 0x54 // Minimum transmission unit.
#define regSHOWVER 0x55 // Enable/Disable start-up message
#define regCSMAMODE 0x56 // Enable/disable CSMA
#define regSLPMODE 0x58 // Power state of module
#define regACKONWAKE 0x59 // Send ACK character to host on wake
 
 
// Wideband Channels
// regNVTXCHAN (0x00) regTXCHAN (0x4B)
// Channel Number Frequency
#define wChan0 0x00 // 868.300 MHz
#define wChan1 0x01 // 868.95 MHz ## MK ##
 
// Narrowband Channels
// regNVRXCHAN (0x01) regRXCHAN (0x4C)
// Channel Number Frequency
#define nChan0 0x00 // 868.225 MHz
#define nChan1 0x01 // 868.375 MHz ## MK ##
#define nChan2 0x02 // 868.850 MHz
#define nChan3 0x03 // 869.050 MHz
#define nChan4 0x04 // 869.525 MHz
#define nChan5 0x05 // 869.850 MHz
 
// Power Mode
// regNVPWRMODE (0x02) regPWRMODE (0x4D)
// PM1 PM1 PM0 Mode
#define NbModeN0 0x00 // 0 0 0 Narrowband Mode 0dBm power setting (typical)
#define WbModeP5 0x01 // 0 0 1 Wideband Mode +5dBm power setting (typical)
#define WbModeP10 0x02 // 0 1 0 Wideband Mode +10dBm power setting (typical)
#define WbModeP15 0x03 // 0 1 1 Wideband Mode +15dBm power setting (typical) ## MK ##
#define WbModeN0 0x04 // 1 0 0 Wideband Mode 0dBm power setting (typical)
#define NbModeP5 0x05 // 1 0 1 Narrowband Mode +5dBm power setting (typical)
#define NbModeP10 0x06 // 1 1 0 Narrowband Mode +10dBm power setting (typical)
#define NbModeP15 0x07 // 1 1 1 Narrowband Mode +15dBm power setting (typical)
 
// Wi232 UART Baudrate
// regNVDATARATE (0x03) regDATARATE (0x4E)
// Baud Rate BR2 BR1 BR0
#define Wi232_2400 Baud_2400 // 0 0 0* (default 2400)
#define Wi232_9600 Baud_9600 // 0 0 1
#define Wi232_19200 Baud_19200 // 0 1 0
#define Wi232_38400 Baud_38400 // 0 1 1
#define Wi232_57600 Baud_57600 // 1 0 0 ## MK ##
#define Wi232_115200 Baud_115200 // 1 0 1
#define Wi232_10400 0x06 // 1 1 0
#define Wi232_31250 0x07 // 1 1 1
 
// NetworkMode
// regNVNETMODE (0x04) regNETMODE (0x4F)
#define NetMode_Slave 0x00 // Slavemode
#define NetMode_Normal 0x01 // Normalmode (default)
 
// Transmit Wait Timeout
// regNVTXTO (0x05) regTXTO (0x50)
#define TWaitTimeFull 0x00 // full Buffer required
#define TWaitTime16 0x10 // 16 ms Delay (default)
 
// Network Group
// regNVNETGRP (0x06) regNETGRP (0x51)
#define NetWorkGroup 66 // default = 0, valid 0-127 ## MK = 66 ##
 
// CRC Control
// regNVUSECRC (0x08) regUSECRC (0x53)
#define CRC_Disable 0x00 // no CRC check
#define CRC_Enable 0x01 // CRC check (default)
 
// UART minimum transmission unit
// regNVUARTMTU (0x09) regUARTMTU (0x54)
#define UartMTU64 64 // default=64, valid 1-144
 
// Verbose mode
// regNVSHOWVER (0x0A)
#define ShowVers_Dis 0x00 // do not show Startupmessage ## MK = 66 ##
#define ShowVers_En 0x01 // show Startupmessage (default)
 
// CSMA enable
// regNVCSMAMODE (0x0B) regCSMAMODE (0x56)
#define CSMA_Dis 0x00 // disable CSMA Carrier-sense multiple access
#define CSMA_En 0x01 // enable CSMA (default)
 
// Sleep control
// regNVSLPMODE (0x0D) regSLPMODE (0x58)
#define Sleep_Awake 0x00 // Sleepmode = Awake (default)
#define Sleep 0x01 // Sleepmode = Sleep
#define Sleep_Stby 0x02 // Sleepmode = Standby
 
// ACK on Wake
// regNVACKONWAKE (0x0D) regACKONWAKE (0x59)
#define ACKwake_Dis 0x00 // disable ACK on Wake
#define ACKwake_En 0x01 // enable ACK on Wake (default)
 
 
#endif // WI232_H_
Property changes:
Added: svn:mime-type
+text/plain
\ No newline at end of property