📄 sci_transmitter.c
字号:
/* File : sci_transmitter.c
* Author : Li Lan
* Date : June 6th, 2007
* Abstract : This project is a test transmitter. (for MC13213-NCB)
* The Zigbee channel is set to 2.460GHz, so the receiver
* has to work on the same frequency. Connect the board
* and the PC with a serial cable(COM1, 38400, 8, n, 1, n)
*
* It has following performance:
* 1. When the system restart, LED1 will be ON.
* 2. On the PC screen (Hyper Terminal), there will be
* a line of welcome message "--- My SARD test (by Li Lan) ---"
* 2. When pressing SW4, the board will transmit a data
* packet "ABCD", and the packet length is 4.
* 3. If the packet is send 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_transmitter.h"
#include "freescale_radio_hardware.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;
INT8 gi8AppStatus = INITIAL_STATE; // Current mode of this board.
/**************************************************************
* Prototypes
**************************************************************/
void MCPSDataIndication(tRxPacket *);
/**************************************************************
* Main Program
**************************************************************/
void main(void)
{
tRxPacket sRxPacket;
tTxPacket gsTxPacket;
byte au8RxDataBuffer[26];
UINT8 gau8TxDataBuffer[26];
char App_String[11]; // My string to show results on PC
/* Initialize the packet.*/
gsTxPacket.u8DataLength = 0;
gsTxPacket.pu8Data = &gau8TxDataBuffer[0];
sRxPacket.pu8Data = &au8RxDataBuffer[0];
sRxPacket.u8MaxDataLength = 30;
sRxPacket.u8Status = 0;
/********** Begin initialization **********/
//EnableInterrupts; /* enable interrupts */
MCUInit(); // initialize MCU
RadioInit(); // initialize MC13192
/* initialize the switches */
SW1PU = PULL_UP_ON;
SW1DIR = DDIR_INPUT;
SW2PU = PULL_UP_ON;
SW2DIR = DDIR_INPUT;
SW3PU = PULL_UP_ON;
SW3DIR = DDIR_INPUT;
SW4PU = PULL_UP_ON;
SW4DIR = DDIR_INPUT;
/* 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 */
TPM1SC = 0x0F; /* Timer divide by 128. (16uS timebase for 8MHz bus clock). */
/* SCI initialization */
SCIInitGeneric(8000000, 38400, 1);
SCITransmitStr("\r\r--- My SARD 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
*/
/* Set MC13192 to idle mode */
//PLMESetTrxStateRequest(IDLE_MODE);
gu8RTxMode = IDLE_MODE;
gi8AppStatus = IDLE_STATE;
/* Enable the keyboard interrput for SW5 */
KBI1PE_KBI1PE5 = 1;
KBI1SC_KBI1E = 1;
/* Define data */
gau8TxDataBuffer[0] = 'A';
gau8TxDataBuffer[1] = 'B';
gau8TxDataBuffer[2] = 'C';
gau8TxDataBuffer[3] = 'D';
gsTxPacket.u8DataLength = 4;
/**************************************************************
* Main Loop, repeated now forever
**************************************************************/
for(;;)
{
__RESET_WATCHDOG(); /* feeds the dog */
LED1 = LED_ON; // A flag to show the system is working.
switch (gi8AppStatus)
{
case IDLE_STATE:
break;
case TRANSMIT_DATA:
if(MCPSDataRequest(&gsTxPacket) == SUCCESS)
{
LED4 = LED_ON; // A flag to show the packet has been sent successfully.
MCUDelay(ONE_SECOND);
LED4 = LED_OFF;
}
gi8AppStatus = IDLE_STATE;
break;
}
} /* loop forever */
/* please make sure that you never leave main */
}/*--------------- The End of the Main Function-------------- */
/**************************************************************
* Interrupt functions
**************************************************************/
/* Interrupt function when pressing the SW5 button */
interrupt void intSW4()
{
gi8AppStatus = TRANSMIT_DATA;
KBI1SC_KBACK = 1; // Acknowledge interrupt
}
/**************************************************************
* 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();
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -