📄 drivers.c
字号:
/**
* Copyright (c) 2004, Freescale Semiconductor
* Freescale Confidential Proprietary
*
* File name : drivers.c
* Project name: SMAC (Simple Media Access Controller)
*
* Department : Freescale Radio Products Division
*
* Description : This is the SMAC C source driver file for the HC(S)08 MCU and
* MC13192 transceiver.
* The driver controls all interfaces to/from the MC13192 by the SPI, selected
* interrupt source and MCU GPIO's assigned to other MC13192 pins.
* The SMAC driver is the lowest layer of C code.
* Actual hardware interconnects from the MCU to the MC13192 are defined in the
* MC13192_hw_config.h header file.
*
* $Author: a20639 $
* $Date: 2005/03/10 15:40:04 $
* $Name: $
*/
#include "device_header.h"
#include "pub_def.h"
#include "drivers.h"
#include "MC13192_regs.h"
#include "MC13192_hw_config.h"
#include "mcu_hw_config.h"
#include "simple_phy.h"
/*Defines*/
#define AssertCE() MCF_GPIO_PORTQS = (MCF_GPIO_PORTQS & 0xDF);
#define DeAssertCE() MCF_GPIO_PORTQS = (MCF_GPIO_PORTQS | 0x20);
/* Globals */
tRxPacket *psDrvRxPacket;
tCCAMeasurement sDrvCCAReading; /* NOT USED */
UINT8 gu8IRQValue = 0;
extern UINT8 gu8RTxMode;
/*
* IRQIsr : MC13192 initiated IRQ interrupt handler
*
* Parameters : None
*
* Return : The interrupt will RTI unless valid data is recvd.
* In this case a PDDataIndication function call-back will be executed first,
* followed by a RTI.
*/
__interrupt__
void irq_isr(void)
{
/* The vector is defined in vectortable.c */
volatile UINT16 u16StatusContent, u16Reg, u16Temp; /*
* Result of the status register
* read
*/
UINT8 u8DataLength = 0; /* Data length for the RX packet */
//for debug
//printf("enter zigbee isr\n");
CLEAR_IRQ_FLAG; /* Acknowledge the interrupt. MC13192 IRQ pin still low. */
u16StatusContent = SPIDrvRead(STATUS_ADDR); /*
* Read the MC13192 status
* register.
*/
/* Test for IRQ glitch or possible fast double IRQ. */
if(MCF_EPORT_EPFR == 0x02){ //__isflag_int_enabled
/* IRQ is low. Re-read status. */
CLEAR_IRQ_FLAG; /* Acknowledge the interrupt. MC13192 IRQ pin still low. */
u16Reg = SPIDrvRead(STATUS_ADDR); /* Read the MC13192 status register. */
u16StatusContent = u16StatusContent | u16Reg; /*
* Actual status is the OR
* of both.
*/
}
u16StatusContent &= TX_IRQ_MASK | RX_IRQ_MASK | ATTN_IRQ_MASK | \
CRC_VALID_MASK | TIMER1_IRQ_MASK | CCA_IRQ_MASK | \
LO_LOCK_IRQ_MASK;
if (gu8RTxMode != RX_MODE_WTO) {
/* If timeout not being used, mask out timer. */
u16StatusContent &= ~(TIMER1_IRQ_MASK);
}
if ((u16StatusContent & ~(CRC_VALID_MASK)) == 0) {
/* If no status bits are set just return. */
return;
}
/* DOZE Complete Interrupt */
if ((u16StatusContent & DOZE_IRQ_MASK) != 0) {
SPIDrvWrite(T2_HI_ADDR, 0x8000); /* disable the timer2 */
u16Temp= SPIDrvRead(MODE2_ADDR);
u16Temp &= 0xFFFC;
SPIDrvWrite(MODE2_ADDR, u16Temp);
}
/* ATTN IRQ Handler*/
if ((u16StatusContent & ATTN_IRQ_MASK) != 0) {
/*
* If attn interrupt, set the rtx_state mirror.
* For MC13192 V2.x devices, read the reset indication in R25/7 first.
* If a reset is indicated, call back to a reset handler.
*/
u16StatusContent = SPIDrvRead(RESIND_ADDR); /*
* Read the MC13192 reset
* indicator register.
*/
u16StatusContent &= RESET_BIT_MASK;
if (u16StatusContent == 0) { /* Reset */
gu8RTxMode = MC13192_RESET_MODE; /*
* Set the rtx_state mirror to
* idle with attn.
*/
PLMEMC13192ResetIndication();
return;
}
else {
gu8RTxMode = IDLE_MODE_ATTN; /*
* Set the rtx_state mirror to idle
* with attn.
*/
return;
}
}
/* TIMER1 IRQ Handler (Used for receiver timeout notification) */
if ((u16StatusContent & TIMER1_IRQ_MASK) != 0) {
/* If timeout ocurs (and timeout enabled), update mode mirror state. */
if (gu8RTxMode == RX_MODE_WTO) {
/* Clear Timer1 if in RX_MODE_WTO */
SPIDrvWrite(T1_HI_ADDR, 0x8000); /* Disables TC1 and clears IRQ */
SPIDrvWrite(T1_LO_ADDR, 0x0000);
psDrvRxPacket->u8Status = TIMEOUT;
RTXENDeAssert(); /* Forces the MC13192 to idle. */
gu8RTxMode = IDLE_MODE;
PDDataIndication(); /* TIMEOUT notification */
return;
}
}
/* LO LOCK IRQ - Occurs when MC13192 loses LOCK */
/* For receive cycles, re-enable. For transmit/CCA, abort. */
if ((u16StatusContent & LO_LOCK_IRQ_MASK) != 0) {
RTXENDeAssert(); /* Forces the MC13192 to idle. */
/* Unlock from receive cycles */
if ((gu8RTxMode == RX_MODE) || (gu8RTxMode == RX_MODE_WTO) || \
(gu8RTxMode == CCA_MODE)) {
/* Read the MC13192 trx register. Timer trigger off. */
u16StatusContent = (SPIDrvRead(MODE_ADDR) & 0xFF7F);
SPIDrvWrite(MODE_ADDR, u16StatusContent); /*
* Re-write the trx
* register.
*/
RTXENAssert(); /* Re-start the sequence. */
}
else {
gu8RTxMode = IDLE_MODE;
}
return;
}
if ((gu8RTxMode == IDLE_MODE) || ((u16StatusContent & CCA_IRQ_MASK) != 0) || \
((u16StatusContent & TX_IRQ_MASK) != 0)) {
/* If in idle mode already or if CCA or TX is done, just return. */
RTXENDeAssert(); /* Forces the MC13192 to idle. */
/* Check for Pulse TX Mode for PRBS9 Test mode sequence */
if (gu8RTxMode == PULSE_TX_MODE) {
u16StatusContent = (SPIDrvRead(MODE_ADDR) & 0xFF7F); /* Read the MC13192 trx register. Timer trigger off. */
SPIDrvWrite(MODE_ADDR, u16StatusContent); /* Re-write the trx register. */
RTXENAssert(); /* Re-start the sequence. */
#if defined (PA)
MC13192_PA_CTRL = PA_OFF; //Turn off the PA when TX is complete
#endif
return;
}
gu8RTxMode = IDLE_MODE;
return;
}
/* If rx is done */
if ((u16StatusContent & RX_IRQ_MASK) != 0)
{
RTXENDeAssert(); /* Forces the MC13192 to idle. */
if ((u16StatusContent & CRC_VALID_MASK) == 0)
{
/* If an invalid CRC, restart receiver. */
/* Read the MC13192 trx register. Timer trigger off. */
u16StatusContent = (SPIDrvRead(MODE_ADDR) & 0xFF7F);
/* Update the trx register */
SPIDrvWrite(MODE_ADDR, u16StatusContent);
RTXENAssert(); /* Forces the MC13192 to enter the receive mode. */
return;
}
else {
/* Read received packet length register and mask off length bits */
u8DataLength = (UINT8) (SPIDrvRead(RX_PKT_LEN) & 0x7F);
if (u8DataLength < 3) /* Rx_pkt_length is bad when <5 because of CRC and byte codes. */
{
/* Read the MC13192 trx register. Timer trigger off. */
u16StatusContent = (SPIDrvRead(MODE_ADDR) & 0xFF7F);
/* Update the trx register. */
SPIDrvWrite(MODE_ADDR, u16StatusContent);
/* Forces the MC13192 to enter the receive mode. */
RTXENAssert();
return;
}
/* Test the Byte Codes */
//u16Temp = SPIDrvRead2(RX_PKT); /* Get the code bytes */
//if (u16Temp != 0xFF7E)
//{
/* Read the MC13192 trx register. Timer trigger off. */
// u16StatusContent = (SPIDrvRead(MODE_ADDR) & 0xFF7F);
/* Update the trx register. */
// SPIDrvWrite(MODE_ADDR, u16StatusContent);
/* Forces the MC13192 to enter the receive mode. */
// RTXENAssert();
// return;
// }
/* A valid packet has been received. */
gu8RTxMode = IDLE_MODE; /* Set the rtx_state to idle */
SPIDrvWrite(T1_HI_ADDR, 0x8000); /*
* Disables TC1 and clears the
* IRQ.
*/
SPIDrvWrite(T1_LO_ADDR, 0x0000);
psDrvRxPacket->u8DataLength = u8DataLength;
psDrvRxPacket->u8Status = SUCCESS;
PDDataIndication(); /* Notify PHY that there is data available. */
return;
}
}
}
/*
* MC13192Wake : Wake the MC13192 from Hibernate/Doze mode
*
* Parameters : None
*
* Return : None
*/
void MC13192Wake (void)
{
AssertATTN();
DeAssertATTN();
}
/*
* RTXENDeAssert : Deassert the MC13192 RTXEN pin (forces IC to idle)
*
* Parameters : None
*
* Return : None
*/
void RTXENDeAssert(void)
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -