?? slavemain.c
字號:
/*****************************************************************************
* *
* ********** *
* ************ *
* *** *** *
* *** +++ *** *
* *** + + *** *
* *** + CHIPCON CC1010 Wireless audio project *
* *** + + *** *
* *** +++ *** SlaveMain *
* *** *** *
* *********** *
* ********* *
* *
*****************************************************************************
* This source file is part of a software project for Full Duplex, *
* single-chip, wireless intercom, written for the CC1010 chip *
* (RF-transceiver chip with integrated 8051 micro-controller). *
*****************************************************************************
* Author: OAE *
*****************************************************************************
* Revision history: *
* *
* $Log: SlaveMain.c,v $
* Revision 1.2 2003/08/18 12:20:11 tos
* Synchronisation with library update (reentry issue).
*
* Revision 1.1 2003/08/04 12:33:16 tos
* Initial version in CVS.
*
* *
* *
****************************************************************************/
#include <Common/Main.h>
// Define preamble constants
#define PREAMBLE_BYTE_COUNT 18
#define PREAMBLE_BITS_SENSE_INIT 81
#define PREAMBLE_BITS_SENSE 16
// Variables
ulong adcperiod = 125;// The ADC sample period in us
ulong pwmperiod = 17;// The PWM-timer period in us
word wait = 5000;// A variable used to pause the program excetcution
word xdata tCounter; // Reload variable used by interrupt routine
// External constants
extern const byte xdata *transmit_buffer_start_ptr0;
extern const byte xdata *transmit_buffer_start_ptr1;
extern const byte xdata *receive_buffer_start_ptr0;
extern const byte xdata *receive_buffer_start_ptr1;
extern bit currenttransmitbuffer;
extern bit currentreceivebuffer;
// Slave specific prototypes
void PacketAssembler(byte sample);
void AverageFilterUpdate(byte numpreamblebitsense,
RF_RXTXPAIR_SETTINGS* RF_SETTINGS);
/**************************************************************************
* main() - Main function *
***************************************************************************
* Description: *
* Initiation and system control. This is where the program execution *
* starts. *
***************************************************************************
* Input arguments: *
* None. *
* Return value: *
* None.
**************************************************************************/
void main()
{
// Perform calibration
halRFCalib(&RF_SETTINGS_INIT, &RF_CALDATA);
// Select RF bytemode
RFCON |= 0x01;
// Set suitable synch byte
RF_SET_SYNC_BYTE(RF_SUITABLE_SYNC_BYTE);
// Disable watchdog timer
WDT_ENABLE(FALSE);
// Set optimum settings for speed and low power consumption
MEM_NO_WAIT_STATES();
FLASH_SET_POWER_MODE(FLASH_STANDBY_BETWEEN_READS);
// Initialize DES key at absolute address
memcpy(DES_KEY, DES_KEY_TEMP, 7);
// Initialize The leds
BLED_OE(TRUE); BLED = LED_OFF;
RLED_OE(TRUE); RLED = LED_OFF;
//GLED_OE(TRUE); GLED = LED_OFF;
// Turn on interrupt
INT_ENABLE(INUM_TIMER0, INT_ON);
INT_GLOBAL_ENABLE(INT_ON);
// Setup ADC, select AD0 as input
halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_VDD, CLK_FREQ, 0);
ADC_SELECT_INPUT(ADC_INPUT_AD0);
// Set the ADC clock divider to its lowest possible value
ADCON2=0;
// Power up the ADC from sleep mode
ADC_POWER(TRUE);
/**********************************************************************
* RF-initiation - average filter update *
**********************************************************************/
// Start reception of preambles to update average filter
AverageFilterUpdate(PREAMBLE_BITS_SENSE_INIT, &RF_SETTINGS_INIT);
// Wait before preamble transmission
while (wait--);
// Start transmission of preambles to update the masters average filter
PacketSend(PREAMBLE_BYTE_COUNT, NULL, 0, &RF_SETTINGS_ACTIVE);
// Turn on red led to indicate successful initiation
RLED = LED_ON;
/*********************************************************************/
// Configure timer 3 as PWM timer for DA-conversion
halConfigTimer23(TIMER3 | TIMER23_PWM, pwmperiod, CLK_FREQ);
TIMER3_RUN(TRUE);
// Configure timer 0 to generate repeated interrups for ADC and DAC
halConfigTimer01(TIMER0 | TIMER01_INT_TIMER, adcperiod, CLK_FREQ, &tCounter);
TIMER0_RUN(TRUE);
/**********************************************************************
* Main loop - normal operation *
**********************************************************************/
while (TRUE)
{
// Wait for synch then receive and buffer packet in correct buffer
if (currentreceivebuffer == BUFFER0)
PacketReceive(PREAMBLE_BITS_SENSE, receive_buffer_start_ptr1,
PACKET_SIZE, &RF_SETTINGS_ACTIVE);
else
PacketReceive(PREAMBLE_BITS_SENSE, receive_buffer_start_ptr0,
PACKET_SIZE, &RF_SETTINGS_ACTIVE);
// Toggle blue led to indicate packet transmission
BLED = !BLED;
// Read packet from the correct buffer and send
if (currenttransmitbuffer == BUFFER0)
PacketSend(PREAMBLE_BYTE_COUNT, transmit_buffer_start_ptr0,
PACKET_SIZE, &RF_SETTINGS_ACTIVE);
else
PacketSend(PREAMBLE_BYTE_COUNT, transmit_buffer_start_ptr1,
PACKET_SIZE, &RF_SETTINGS_ACTIVE);
}// End while
/*********************************************************************/
}//End main
/**************************************************************************
* Timer 0 interrupt service routine *
**************************************************************************/
void TIMER0_ISR() interrupt INUM_TIMER0
{
// Reset the timer to generate another interrupt
INT_SETFLAG (INUM_TIMER0, INT_CLR);
ISR_TIMER0_ADJUST(tCounter);
// Sample the ADC input
ADCON|=0x04;
// Continue without waiting for completion
// Send the previous sampled value to the packet assembler
PacketAssembler(ADC_GET_SAMPLE_8BIT());
// Read and decode the received and buffered data, update output
PWM3_SET_DUTY_CYCLE(PacketDisassembler());
}// End ISR
/*************************************************************************/
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -