?? des_mc33696.c
字號(hào):
ECHO_TIE |= ECHO_TIMER_INT; /* Interrupt enable */
ECHO_TCTL = ECHO_CLEAR_ON_COMPARE; /* Output compare action select */
/* ECHO_TIMER_PIN_OFF replaced by ECHO_CLEAR_ON_COMPARE */
/* on the line above because of use of the pin by BCD */
/* DOOR_LOCK1_IN2 line */
ECHO_TC7H = ECHO_MODH; /* Main timer terminal count = a bit */
ECHO_TC7L = ECHO_MODL; /* time */
ECHO_TCxH = ECHO_MODH; /* Compare = full bit-time */
ECHO_TCxL = ECHO_MODL;
ECHO_TSCR1 |= ECHO_TIMER_ON; /* Start the timer */
/*--- Enable interrupts */
asm cli;
}
/******************************************************************************
* Put Echo into Standby/low power mode. Messages already received can be
* retrieved from the driver buffer using Echo_DriverStatus as before but no new
* messages will be received and nothing can be transmitted.
*
* !!Only Echo_Enable and Echo_DriverStatus
* are safe to be called when Echo is disabled!!
******************************************************************************/
void Echo_Disable(void) {
/*--- Turn off timer channel and SPI interrupts */
ECHO_TCTL &= ~ECHO_TIMER_PIN_OFF; /* Pin disconnected */
ECHO_TIE &= ~ECHO_TIMER_INT; /* Interrupts disable */
ECHO_SPIxC1 &= ~ECHO_SPIxC1_SPIE;
/*--- Turn off SPI module and timer */
ECHO_SPIxC1 &= ~ECHO_SPIxC1_SPE;
#if ECHO_TIMER_DISABLE == 1
ECHO_TSCR1 &= ECHO_TIMER_OFF; /* Disable timer */
#endif
/*--- Reset the driver status */
status.Word = 0;
/*--- Turn off the PA and LNA */
#ifdef ECHO_ENABLELNA
ECHO_ENABLELNA = 0;
#endif
#ifdef ECHO_ENABLEPA
ECHO_ENABLEPA = 0;
#endif
/*--- Turn off RSSI module and Echo transceiver */
echoRegisters[ECHO_COMMAND_REG] &= ~ECHO_BIT_RSSIE;
echoRegisters[ECHO_CONFIG2_REG] &= ~ECHO_BIT_TRXE;
Echo_EnterConfig();
WaitN(ITERATIONS_1200uS);
Echo_Config(BUILDCMD(CMD_ONE, ECHO_COMMAND_REG, 1), &echoRegisters\
[ECHO_COMMAND_REG], 1);
Echo_Config(BUILDCMD(CMD_ONE, ECHO_CONFIG2_REG, 1), &echoRegisters\
[ECHO_CONFIG2_REG], 1);
Echo_ExitConfig();
/* Echo_ExitConfig leaves SEB=1, digital interface disabled */
/*--- Turn off the STROBE */
/* After SPI stuff in case we're in Rx mode - STROBE=0 would turn Echo */
/* off before ^ */
#ifdef ECHO_STROBE
ECHO_STROBE = 0;
#endif
}
/******************************************************************************
* Set up timer registers and start it going. Require to setup
* echoDriverNextState variable before starting timer interrupts!
* Also, SPI should be disabled while the timer is generating a waveform.
******************************************************************************/
void Echo_KickOffTimer(void) {
/* Set up the timer */
ECHO_TIOS |= ECHO_IC_OC; /* Select OC on used timer channel */
ECHO_TSCR2 |= ECHO_TCRE; /* Timer counter reset enable */
ECHO_TFLG1 |= ECHO_TIMER_INT; /* Clear any old interrupt pending */
ECHO_TIE |= ECHO_TIMER_INT; /* Interrupt enable */
ECHO_TCTL &= ~ECHO_TIMER_PIN_OFF; /* Pin disconnceted */
ECHO_TC7H = ECHO_MODH; /* Main timer terminal count */
ECHO_TC7L = ECHO_MODL;
ECHO_TCxH = ECHO_COMH; /* Compare = half bit-time */
ECHO_TCxL = ECHO_COML;
ECHO_TSCR1 |= ECHO_TIMER_ON; /* Start the timer */
/*--- Enable interrupts */
asm cli;
}
/******************************************************************************
* Send a single preamble/ID sequence.
* Switches to Tx mode and initiates the sending. While the Preamble/ID sequence
* is being send, the Busy and Tx flags will be set. Note: does not return from
* Tx mode! Must be used in combination with Echo_SendData to complete the
* message telegram and return Echo to Rx mode.
******************************************************************************/
void Echo_SendPreambleID(void) {
status.Bits.Busy = 1;
if (status.Bits.Mode == 0) {
/* If we're in Rx mode, need to switch to Tx */
Echo_EnterConfig();
bitCounter = ECHO_1200uS_DELAY;
echoDriverNextState = ECHO_STARTUP;
}
else {
/* Jump straight to the preamble */
#if ECHO_MODE_VALUE == ECHO_OOK
bitCounter = ECHO_PREAMBLE_200uS;
echoDriverNextState = ECHO_PREAMBLE_1;
#else
// bitCounter = 4;
halfbitCounter = 8;
echoDriverNextState = ECHO_PREAMBLE_2;
#endif
}
/* Configure the Tx state machine for ID only */
tx_config.Bits.IDHeaderSelect = 0;
tx_config.Bits.CompleteSend = 0;
/* Buffer to pick up ID from */
echoTxDataPtr = echoTransmitBuffer;
Echo_KickOffTimer();
}
/******************************************************************************
* Send a preamble+Header+Data+EOM sequence.
* Requires driver to be in Tx mode (by calling Send_PreambleID previously).
******************************************************************************/
void Echo_SendData(void) {
/* Must be in Tx mode already (by calling Send_PreambleID) */
if (status.Bits.Mode != 1) {
status.Bits.Error = 1;
return;
}
/* Status bit set to indicate transmitting */
status.Bits.Busy = 1;
status.Bits.Tx = 1;
/* Configure the Tx state machine for P+Header+Data */
tx_config.Bits.IDHeaderSelect = 1;
/* Set up data, length, checksum etc */
echoTransmitBuffer[3] |= ECHO_BUFFER_FULL; /* Mark buf full while we're */
/* using it */
echoTxDataPtr = echoTransmitBuffer;
byteCounter = echoTransmitBuffer[3] & ~ECHO_BUFFER_FULL;
echoChecksum = echoTxDataPtr[2]; /* Start with ID */
/* Set up driver next state */
#if ECHO_MODE_VALUE == ECHO_OOK
echoDriverNextState = ECHO_PREAMBLE_1;
bitCounter = ECHO_PREAMBLE_200uS;
#else
echoDriverNextState = ECHO_PREAMBLE_2;
// bitCounter = 4;
halfbitCounter = 8;
#endif
Echo_KickOffTimer();
}
/******************************************************************************
* Send a complete telegram consisting of number of Preamble+ID sequences spaced
* by a number of bit-times. The spaceing and repeat count are defined in the Tx
* buffer. This sequence is followed by a Header, Data and EOM. Switches to Tx
* mode and initiates the sending. While the sequence is being sent, the Busy
* and Tx flags will be set. The full flag on the Tx buffer will remain set for
* the duration of its use by the driver. The buffer may be copied internally,
* so even though the Tx buffer is empty, it might still be sending!! Use the
* status flags to check.
******************************************************************************/
void Echo_SendMessage(void) {
echoTransmitBuffer[3] |= ECHO_BUFFER_FULL; /* Mark buf full while we're */
/*using it */
/* The internal buffer is only full when transmitting a complete */
/* telegram. In that case, the ISR will pick up the new message when */
/* it's finished, so just leave it. */
if ((echoInternalTxBuffer[3] & ECHO_BUFFER_FULL) != 0) return;
status.Bits.Busy = 1;
/* Set up driver next state: Startup switches to Tx mode before preamble */
Echo_EnterConfig();
bitCounter = ECHO_1200uS_DELAY;
echoDriverNextState = ECHO_STARTUP;
/* Configure the Tx state machine for P+ID repeat */
tx_config.Bits.IDHeaderSelect = 0;
tx_config.Bits.CompleteSend = 1;
tx_config.Bits.IDRepeat = 0;
/* Set up data, length, checksum etc */
EchoCopyTxBuf();
echoTxDataPtr = echoInternalTxBuffer;
byteCounter = echoTxDataPtr[3] & ~ECHO_BUFFER_FULL;
echoChecksum = echoTxDataPtr[2]; /* Start with ID */
IDCounter = echoTxDataPtr[0]; /* Number of P+ID repeats */
Echo_KickOffTimer();
}
/******************************************************************************
* Send a complete message consisting of Preamble followed my a continuous
* stream of ID's then a Header, Data and EOM. Switches to Tx mode and initiates
* the sending. While the sequence is being sent, the Busy and Tx flags will be
* set. Always sends at least one ID; repeatCount is number of extra ID's to
* send.
******************************************************************************/
void Echo_SendIDRepeat(unsigned char repeatCount) {
status.Bits.Busy = 1;
/* Set up driver next state: Startup switches to Tx mode before preamble */
Echo_EnterConfig();
bitCounter = ECHO_1200uS_DELAY;
echoDriverNextState = ECHO_STARTUP;
/* Configure the Tx state machine for ID repeat */
tx_config.Bits.IDHeaderSelect = 0;
tx_config.Bits.CompleteSend = 1;
tx_config.Bits.IDRepeat = 1;
/* Set up data, length, checksum etc */
echoTransmitBuffer[3] |= ECHO_BUFFER_FULL; /* Mark buf full while we're */
/* using it */
echoTxDataPtr = echoTransmitBuffer;
byteCounter = echoTransmitBuffer[3] & ~ECHO_BUFFER_FULL;
echoChecksum = echoTxDataPtr[2]; /* Start with ID */
IDCounter = repeatCount;
Echo_KickOffTimer();
}
/******************************************************************************
* Timer interrupt used for (transmitting bits) and other timing.
* Essentially a big function implementing a state machine which transitions on
* interrupts. See the Echo Device Driver Design document for a fuller
* description.
******************************************************************************/
#pragma CODE_SEG __NEAR_SEG NON_BANKED
interrupt void Echo_TxTimer_Interrupt(void) {
switch (echoDriverNextState) {
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* 2ms delay when Echo starts up */
case ECHO_ENABLE_DELAY:
bitCounter--;
if (bitCounter == 0) {
status.Bits.EnableDelay = 0;
status.Bits.Busy = 0;
ECHO_TIE &= ~ECHO_TIMER_INT; /* Turn off channel ints.*/
ECHO_TCTL &= ~ECHO_TIMER_PIN_OFF; /* Turn off channel pin */
#if ECHO_TIMER_DISABLE == 1
ECHO_TSCR1 &= ECHO_TIMER_OFF;
#endif
ECHO_SPIxC1 |= ECHO_SPIxC1_SPIE; /* Enable SPI interrupts */
ECHO_SPIxC1 |= ECHO_SPIxC1_SPE; /* Turn on the SPI */
ECHO_SEB = 0; /* Enable Echo digital interface */
/* to receive msg's on the SPI */
ECHO_SEB_DDR = 1;
echoDriverNextState = ECHO_READY;
}
else { /* Still more delay to come so go round again */
ECHO_TCTL = ECHO_CLEAR_ON_COMPARE;
ECHO_TFLG1 |= ECHO_TIMER_INT;
/* ECHO_TIMER_PIN_OFF replaced by ECHO_CLEAR_ON_COMPARE */
/* on the line above because of use of the pin by BCD */
/* DOOR_LOCK1_IN2 line */
}
break;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Startup: 1.2ms delay when Echo enters config mode to switch to Tx */
/* mode. Enter with bitCounter = # of bit-times in 1.2ms */
/* Echo_EnterConfig should be called prior to entering this state */
case ECHO_STARTUP:
ECHO_TCTL &= ~ECHO_TIMER_PIN_OFF;
ECHO_TFLG1 |= ECHO_TIMER_INT;
if (--bitCounter == 0) {
echoDriverNextState = ECHO_RXTX_SWITCH;
}
break;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* RxTxSwitch: Switch to Tx mode before sending Preamble */
case ECHO_RXTX_SWITCH:
ECHO_TCTL &= ~ECHO_TIMER_PIN_OFF;
ECHO_TFLG1 |= ECHO_TIMER_INT;
/* Status bits set to Tx mode */
status.Bits.Mode = 1;
status.Bits.Rx = 0;
status.Bits.Tx = 1;
/* Turn on the PA and turn off the LNA */
#ifdef ECHO_ENABLELNA
ECHO_ENABLELNA = 0;
#endif
#ifdef ECHO_ENABLEPA
ECHO_ENABLEPA = 1;
#endif
/* Switch to Tx mode */
echoRegisters[ECHO_COMMAND_REG] |= ECHO_BIT_MODE;
Echo_Config(BUILDCMD(CMD_ONE, ECHO_COMMAND_REG, 1), \
&echoRegisters[ECHO_COMMAND_REG], 1);
Echo_ExitConfig();
ECHO_SPIxC1 &= ~ECHO_SPIxC1_SPE; /* Disable MOSI so timer can */
/* drive it */
ECHO_SEB = 0; /* Enable Echo's interface */
/* Set up driver next state */
#if ECHO_MODE_VALUE == ECHO_OOK
bitCounter = ECHO_PREAMBLE_200uS;
echoDriverNextState = ECHO_PREAMBLE_1;
#else
// bitCounter = 4;
halfbitCounter = 8;
echoDriverNextState = ECHO_PREAMBLE_2;
#endif
break;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Preamble 1: '1' NRZ > 200 uSec, enter with bitCounter set to # of */
/* bits in 200uS */
case ECHO_PREAMBLE_1:
ECHO_TCTL = ECHO_SET_ON_COMPARE;
ECHO_TFLG1 |= ECHO_TIMER_INT;
if (--bitCounter == 0) {
echoDriverNextState = ECHO_PREAMBLE_2;
#if ECHO_MODE_OOKREF == 0
// bitCounter = 1;
halfbitCounter = 2; // 1 bit NRZ = 2 symbols RZ
#else
// bitCounter = 4;
halfbitCounter = 8; // 4 bits NRZ = 8 symbols RZ
#endif
}
break;
/*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/
/* Preamble 2: 0's (Manchester) to settle data slicer reference */
/* Enter with bitCounter set to # 0's to send */
case ECHO_PREAMBLE_2:
if (halfbit == 0){
ECHO_TCTL = ECHO_CLEAR_ON_COMPARE;
ECHO_TCxH = ECHO_COMH;
ECHO_TCxL = ECHO_COML;
ECHO_TFLG1 |= ECHO_TIMER_INT;
halfbit = 1;
}
else {
ECHO_TCTL = ECHO_SET_ON_COMPARE;
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -