📄 echoslave.c
字号:
/* Interface an Atmel AVR MCU with Freescales MC1319x ZigBee chip */
/*
* Author: johan@anteeo.se
*
* Copyright (C) 2005 by Anteeo Systems HB, Sweden
*
* 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, or
* (at your option) any later version.
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*
* Created: Fri May 13 22:46:58 2005, johan@anteeo.se
*
*/
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdio.h>
#include <mc1319x.h>
#include <ledfeedback.h>
// This assumes the default prescaler (250kHz) in the MC13192 is used
// Timeout in 0.5s
#define RCV_DEFAULT_TIMEOUT (0xFFFFFF/67)*0.5
// Clear Channel Assessment callback
void CCAdoneCallback(char bBusy, char iPower)
{
}
void packetSentCallback(void)
{
// Do not log to USART here because we need to be quick about starting to
// wait for packets, otherwise we might miss some!
// Wait for reply tgm
MC13192_receivePacket(RCV_DEFAULT_TIMEOUT);
}
void packetReceivedCallback(void)
{
// If we are not the master, bounce back packet!
if( packetSize==0)
{
// Received corrupt tgm, resume waiting
MC13192_receivePacket(RCV_DEFAULT_TIMEOUT);
return;
}
else if(packetSize==0xff )
{
// Receive timeout, resume waiting
MC13192_receivePacket(RCV_DEFAULT_TIMEOUT);
return;
}
else
{
// Got a packet, increment sequence and reply
packetBuf[0]++;
MC13192_sendPacket(10);
}
}
void rcvAbortedCallback(void)
{
MC13192_sendPacket(10);
}
int main (void)
{
// Setup registers to control the LED
LED_Init();
// Setup registers to interface the AVR with MC1319x
MC1319x_MCU_Init();
// Init MC13192
MC13192Init();
// Flash led to show we are alive
blinkLED(LED_GREEN);
MC1319x_MCUenableInterrupts();
MC13192_receivePacket(RCV_DEFAULT_TIMEOUT);
while (1)
{
// Drive the LED loop
tickLEDs();
}
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -