📄 sci_receiver_ver2.c
字号:
/* File : sci_receiver.c (for MC13213-NCB)
* Author : Li Lan
* Date : June 6th, 2007
* Abstract : This project is a test receiver, which can show LED
* answer to another Zigbee Module, and the packet data
* received will be shown on PC through SCI port.
* The Zigbee channel is set to 2.460GHz, so the transmitter
* has to work on the same frequency.
*
* It has following performance:
* 1. After system resets, LED1 is ON, The other LEDs are OFF.
* The PC HyperTerminal will show a welcome massage:
* "--- My 13213-NCB receiver test (by Li Lan) ---"
* COM setting should be: 38400, 8, none, 1, none.
* 2. When another Zigbee module transmits a packet, our
* board catches it. The packet length and data will
* be shown on the PC HyperTerminal..
* 4. After receiving a packet successfully, the LED4 will
* be ON for about 1sec, and then turn OFF
**********************************************************************/
/**************************************************************
* Includes
**************************************************************/
#include <hidef.h> /* for EnableInterrupts macro */
#include "pub_def.h"
#include "simple_mac.h"
#include "SCI.h"
#include "mc13192_hw_config.h"
#include "bootloader user api.h"
#include "sci_receiver.h"
#include "freescale_radio_hardware.h"
#include "MC13192_regs.h"
#include "drivers.h"
/**************************************************************
* Data definitions
**************************************************************/
UINT8 gu8RTxMode; /* Current mode of the MC13192 XCVR */
tRxPacket *psDrvRxPacket;
extern tPhyOptions gsPhyOptions;
typedef void(*tIsrFunc)(void); /* define a type pointing to a function
* that is for making a interrupt table
*/
extern UINT8 gu8SCIData[128];
extern UINT8 gu8SCIDataFlag;
/**************************************************************
* Prototypes
**************************************************************/
void MCPSDataIndication(tRxPacket *);
/**************************************************************
* Main Program
**************************************************************/
void main(void)
{
tRxPacket sRxPacket;
byte au8RxDataBuffer[26];
char App_String[11]; // My string to show results on PC
sRxPacket.pu8Data = &au8RxDataBuffer[0];
sRxPacket.u8MaxDataLength = 30;
sRxPacket.u8Status = 0;
/********** Begin initialization **********/
//EnableInterrupts; /* enable interrupts */
MCUInit(); // initialize MCU
RadioInit(); // initialize MC13192
/* initialize the leds */
LED1DIR = DDIR_OUTPUT; // initialize as output
LED2DIR = DDIR_OUTPUT;
LED3DIR = DDIR_OUTPUT;
LED4DIR = DDIR_OUTPUT;
LED5DIR = DDIR_OUTPUT;
LED1 = LED_OFF; // All lights off
LED2 = LED_OFF;
LED3 = LED_OFF;
LED4 = LED_OFF;
LED5 = LED_OFF;
/* Set initial Clk speed */
PLMESetMC13192ClockRate(0); // 16MHz CLKo, 8MHz bus clock
/* Freq Output Frequency
* 0 16MHz (Recommended default)
* 1 8MHz
* 2 4MHz
* 3 2MHz
* 4 1MHz
* 5 62.5kHz
* 6 32.786kHz
* 7 16.393kHz */
/******************************************************************
To adjust output power call the PLME_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)
******************************************************************/
//PLMEMC13192PAOutputAdjust(MAX_POWER); //Set MAX power setting
//PLMEMC13192PAOutputAdjust(MIN_POWER); //Set MIN power setting
PLMEMC13192PAOutputAdjust(NOMINAL_POWER); //Set Nominal power setting
UseExternalClock(); /* switch clock sources */
//LEDSInit(); // initialize the leds.(turn off DS2 and DS3)
TPM1SC = 0x0F; /* Timer divide by 128. (16uS timebase for 8MHz bus clock). */
/* SCI initialization */
//SCIInitGeneric(8000000, 38400, 1);
//SCITransmitStr("\r\r--- My 13213-NCB receiver test (by Li Lan) ---\r\r");
/* Enable all interrupts and ready to go */
MC13192_IRQ_IE_BIT = 1;
EnableInterrupts;
/* Set the MC13192 RF channel */
PLMESetChannelRequest(11); /* 0 : 2.405GHz
* 1 : 2.410GHz
* 2 : 2.415GHz
* 3 : 2.420GHz
* 4 : 2.425GHz
* 5 : 2.430GHz
* 6 : 2.435GHz
* 7 : 2.440GHz
* 8 : 2.445GHz
* 9 : 2.450GHz
* 10: 2.455GHz
* 11: 2.460GHz
* 12: 2.465GHz
* 13: 2.470GHz
* 14: 2.475GHz
* 15: 2.480GHz
*/
MLMERXEnableRequest(&sRxPacket, 0x); /* Activate the receiver */
/**************************************************************
* Main Loop, repeated now forever
**************************************************************/
for(;;)
{
__RESET_WATCHDOG(); /* feeds the dog */
LED1 = LED_ON;
//LED_DS2_ON();
if (gu8RTxMode == IDLE_MODE) /* RX is now done */
{
if (sRxPacket.u8Status == SUCCESS)
{
/* Print the packet length on PC screen */
/*SCITransmitStr(" Received Packet Length = ");
int2string((UINT32) sRxPacket.u8DataLength, App_String);
trimWhiteSpace(App_String);
SCITransmitStr(App_String);
SCITransmitStr("\r");
SCITransmitStr(" Packet Data = ");
SCITransmitFormattedArray(sRxPacket.pu8Data, sRxPacket.u8DataLength);
SCITransmitStr("\r"); */
// blink the light
//LED_DS3_ON(); // A flag to show the packet has been sent successfully.
LED4 = LED_ON;
MCUDelay(HALF_SECOND);
//LED_DS3_OFF();
LED4 = LED_OFF;
}
MLMERXEnableRequest(&sRxPacket, 0x); /* back to receiver on */
}
} /* loop forever */
/* please make sure that you never leave main */
}/*--------------- The End of the Main Function-------------- */
/**************************************************************
* Function: Received data handler
* Parameters: tRxPacket
**************************************************************/
void MCPSDataIndication(tRxPacket *sRxPacket)
/* Just a direct return. Main loop will handle it. */
{
;
}
void MLMEMC13192ResetIndication(void)
{
//Notifies you that the MC13192 has been reset.
//Application must handle this here.
}
/**************************************************************
* Function: Read MCU timer.
* Parameters: none
* Return: 16-bit timer value.
**************************************************************/
UINT16 MCUReadTmr1(void)
{
UINT16 w; /* w[0] is MSB, w[1] is LSB */
((UINT8*)&w)[0] = TPM1CNTH; /* MSB */
((UINT8*)&w)[1] = TPM1CNTL; /* LSB */
return w;
}
/**************************************************************
* Function: Delay.
* Parameters: Delay u16Count
* Return: none.
**************************************************************/
void MCUDelay (UINT16 delay_t)
{
UINT16 u16MCUOldTime;
UINT16 u16MCUNewTime;
u16MCUOldTime = MCUReadTmr1();
u16MCUNewTime = u16MCUOldTime;
while ((u16MCUNewTime-u16MCUOldTime) < delay_t)
{
u16MCUNewTime = MCUReadTmr1();
}
}
/**************************************************************
* Function: Initiate leds (DS2 and DS3).
* Parameters: none
* Return: none.
**************************************************************/
void LEDSInit(void)
{
UINT16 u16SpiReg = 0; // a variable to restore the content of the SPI register.
// define the GPIO[7:6](LED: DS2 and DS3) as output only.
u16SpiReg = SPIDrvRead(GPIO_CONFIG);
u16SpiReg |= 0x3000; // GPIO[7:6](LED: DS2 and DS3) output enable.
u16SpiReg &= 0xFF9F; // GPIO[7:6] input disable.
SPIDrvWrite(GPIO_CONFIG, u16SpiReg);
// set the output drive strength of GPIO[7:6]
u16SpiReg = SPIDrvRead(GPIO_DATA);
u16SpiReg |= 0xC000;
SPIDrvWrite(GPIO_DATA, u16SpiReg);
// turn off the LED DS2 and DS3
LED_DS2_OFF();
LED_DS3_OFF();
}
/**************************************************************
* Function: Turn ON the led of DS2.
* Parameters: none
* Return: none.
**************************************************************/
void LED_DS2_ON(void)
{
UINT16 u16SpiReg; // a variable to restore the content of the SPI register.
u16SpiReg = SPIDrvRead(GPIO_DATA);
u16SpiReg |= 0x0020;
SPIDrvWrite(GPIO_DATA, u16SpiReg);
}
/**************************************************************
* Function: Turn ON the led of DS3.
* Parameters: none
* Return: none.
**************************************************************/
void LED_DS3_ON(void)
{
UINT16 u16SpiReg; // a variable to restore the content of the SPI register.
u16SpiReg = SPIDrvRead(GPIO_DATA);
u16SpiReg |= 0x0040;
SPIDrvWrite(GPIO_DATA, u16SpiReg);
}
/**************************************************************
* Function: Turn OFF the led of DS2.
* Parameters: none
* Return: none.
**************************************************************/
void LED_DS2_OFF(void)
{
UINT16 u16SpiReg; // a variable to restore the content of the SPI register.
u16SpiReg = SPIDrvRead(GPIO_DATA);
u16SpiReg &= 0xFFDF;
SPIDrvWrite(GPIO_DATA, u16SpiReg);
}
/**************************************************************
* Function: Turn OFF the led of DS3.
* Parameters: none
* Return: none.
**************************************************************/
void LED_DS3_OFF(void)
{
UINT16 u16SpiReg; // a variable to restore the content of the SPI register.
u16SpiReg = SPIDrvRead(GPIO_DATA);
u16SpiReg |= 0xFFBF;
SPIDrvWrite(GPIO_DATA, u16SpiReg);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -