📄 wireless_uart.c
字号:
/****************************************************************************
Wireless_UART.c
Application Note: This simple application forms a point to point wireless uart with ACKs.
Power either the 13192SARD or GB60 EVB with a MC13192 2.2 IC and connect the UART1 on the EVB and
Uart1 for 13192SARD. If you have legacy ARD boards this by default must use UART2.
UNZIP this in the apps directory with other app demos.
Download the same code to 2 boards.
Set the Hyperterms for 38400 No flow control.
Type a character on one of the hyperterms. It will send the character via MC13192 to
the other board and display it on its respective Hyperterm. It will be displayed and the rx
board will send back "ACK". The TX board will be listening for the ACK. On every timeout
the TX will retransmit the character. The number of successive tries is reflected
on the LEDs. 1 light is one retry. 2 is two retries. 3 is three retries etc.
If the ack is received the LEDs are reset.
If the ack is not received by the 5th retry the character is dropped and the
LEDs are reset.
The timeout period is controlled by TIMEOUT_PERIOD
The number of retries is kept in RETRY_COUNT. Note retries past 5 will reset
Also, on the GB60EVBs COM_SW 4 must be on to allow the RX on the UART2 to work.
$Author: a20639 $
$Date: 2006/07/31 17:21:59 $
$Name: $
****************************************************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "pub_def.h"
#include "simple_mac.h"
#include "LCD.h"
#include "SCI.h"
#include "mc13192_hw_config.h"
#include "bootloader user api.h"
#include "wireless_uart.h"
#include "freescale_radio_hardware.h"
/////////////////////////////
/* note: Buad Rate = 38400 */
/////////////////////////////
/*Defines*/
/*Global Variables*/
UINT8 gu8RTxMode;
extern UINT8 gu8SCIDataFlag;
extern UINT8 gu8SCIData[128];
UINT8 SCI_TestTx = 0;
INT8 gi8AppStatus = 0;
#ifdef BOOTLOADER_ENABLED
#define TIMEOUT_PERIOD 0x2000 /*Changed to 0x2000 due to lower UART baud rate. 28.09.04 MVC*/
#else
#define TIMEOUT_PERIOD 0x1000
#endif BOOTLOADER_ENABLED
#define RETRY_COUNT 4
void main(void)
{
tRxPacket gsRxPacket;
tTxPacket gsTxPacket;
UINT8 gau8RxDataBuffer[128];
UINT8 gau8TxDataBuffer[128];
UINT8 u8RetryNo = 0;
UINT16 u16Count = 0;
/* Initialize the packet.*/
gsTxPacket.u8DataLength = 0;
gsTxPacket.pu8Data = &gau8TxDataBuffer[0];
gsRxPacket.u8DataLength = 0;
gsRxPacket.pu8Data = &gau8RxDataBuffer[0];
gsRxPacket.u8MaxDataLength = 128;
gsRxPacket.u8Status = 0;
MCUInit();
RadioInit();
/******************************************************************
* To adjust output power call the MLME_MC13192_PA_output_adjust() with:
*
* MAX_POWER (+3 to +5dBm)
* NOMINAL_POWER (0 dBm)
* MIN_POWER ~(-16dBm)
*
* or somewhere custom ? (0-15, 11 (NOMINAL_POWER) being Default power)
*
*****************************************************************
*/
MLMEMC13192PAOutputAdjust(MAX_POWER); //Set MAX power setting
/* MLMEMC13192PAOutputAdjust(MIN_POWER); //Set MIN power setting */
/* MLMEMC13192PAOutputAdjust(NOMINAL_POWER); //Set Nominal power setting */
/* Init LED's */
LED1 = 1; /* Default is off */
LED2 = 1;
LED3 = 1;
LED4 = 1;
LED1DIR = 1; /*Output*/
LED2DIR = 1;
LED3DIR = 1;
LED4DIR = 1;
PB0PU = 1; /* Pushbutton directions and pull-ups for bootloader*/
PB0DIR = 0;
PB1PU = 1;
PB1DIR = 0;
PB2PU = 1;
PB2DIR = 0;
PB3PU = 1;
PB3DIR = 0;
MLMESetMC13192ClockRate(0); /* Set initial Clk speed */
UseExternalClock(); /* switch clock sources */
#if LCD_ENABLED
LCDInit();
#endif
SCIInitGeneric(8000000, 38400, DEFAULT_SCI_PORT);
#ifdef BOOTLOADER_ENABLED
boot_init(); /*Initialize the bootloader.*/
#endif BOOTLOADER_ENABLED
#ifdef BOOTLOADER_ENABLED
boot_call(); /*Check for user request to run bootloader.*/
/*App will not return, if Bootloader is requested.*/
#endif BOOTLOADER_ENABLED
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
LED1DIR = 1;
LED2DIR = 1;
LED3DIR = 1;
LED4DIR = 1;
SCITransmitStr("\r\rWireless Typematic Demo\r\r");
EnableInterrupts;
gi8AppStatus = INITIAL_STATE; /* Initial Mode */
if (MLMESetChannelRequest(15) == SUCCESS)
{
gi8AppStatus= RECEIVER_ALWAYS_ON;
}
for(;;) {
switch (gi8AppStatus) {
case IDLE_STATE:
/* Switch to RECEIVER_ALWAYS_ON */
gi8AppStatus= RECEIVER_ALWAYS_ON;
break;
case RECEIVER_ALWAYS_ON:
u8RetryNo = 0;
MLMERXEnableRequest(&gsRxPacket, 0);
LOW_POWER_WHILE();
break;
case WAITING_FOR_ACK:
/* Do nothing. Go to sleep waiting for TO or RX_IRQ */
break;
case TRANSMIT_DATA:
gi8AppStatus= IDLE_STATE;
if (MLMERXDisableRequest() != SUCCESS) { /* Turn off the RX forever mode. */
gi8AppStatus= TRANSMIT_DATA;
break;
}
gau8TxDataBuffer[0] = gu8SCIData[0]; /* Load the SCI data into gsTxPacket */
gau8TxDataBuffer[1] = '\0'; /* Sending String */
gsTxPacket.u8DataLength = 2;
if ((MCPSDataRequest(&gsTxPacket) == SUCCESS)) /* transmit data */
{
gi8AppStatus = WAITING_FOR_ACK;
MLMERXEnableRequest(&gsRxPacket, TIMEOUT_PERIOD);
u16Count = 0;
}
gu8SCIDataFlag = 0;
break;
case TRANSMIT_ACK:
gi8AppStatus= RECEIVER_ALWAYS_ON;
gau8TxDataBuffer[0] = 'A';
gau8TxDataBuffer[1] = 'C';
gau8TxDataBuffer[2] = 'K';
gsTxPacket.u8DataLength = 3;
MCPSDataRequest(&gsTxPacket); /* transmit data */
break;
case TIMEOUT_STATE:
if (u8RetryNo < RETRY_COUNT)
{
gi8AppStatus= TRANSMIT_DATA; /* Retransmit. */
switch (u8RetryNo % 4)
{
case 0x00:
LED1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 1;
u8RetryNo++;
break;
case 0x01:
LED1 = 1;
LED2 = 0;
LED3 = 1;
LED4 = 1;
u8RetryNo++;
break;
case 0x02:
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 1;
u8RetryNo++;
break;
case 0x03:
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 0;
u8RetryNo++;
break;
}
} else
{
/* Give up on packet. */
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
gi8AppStatus= RECEIVER_ALWAYS_ON;
u8RetryNo = 0;
}
}
if (gu8SCIDataFlag == 1)
{
gi8AppStatus= TRANSMIT_DATA;
}
}
}
void MCPSDataIndication(tRxPacket *gsRxPacket)
{
/*
* Place your code here to handle a mac layer data indication.
* RX packet is in the global structure
* gsRxPacket.dataLength and gsRxPacket.data
*/
if (gsRxPacket->u8Status == SUCCESS)
{
/* Packet received */
if (gsRxPacket->pu8Data[0] == 'A' && gsRxPacket->pu8Data[1] == 'C' && gsRxPacket->pu8Data[2] == 'K')
{
if (gi8AppStatus== WAITING_FOR_ACK)
{
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
gi8AppStatus= RECEIVER_ALWAYS_ON; /* go back to rx_mode. */
}
} else /* Not an ACK */
{
#if LCD_ENABLED
LCDWriteString(1, &gsRxPacket->pu8Data[0]);
#endif
SCITransmitStr(&gsRxPacket->pu8Data[0]);
gi8AppStatus = TRANSMIT_ACK;
}
}
if (gsRxPacket->u8Status == TIMEOUT)
{
/* Received TIMEOUT */
gi8AppStatus = TIMEOUT_STATE;
}
}
void MLMEMC13192ResetIndication(void)
{
//Notifies you that the MC13192 has been reset.
//Application must handle this here.
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -