📄 demoboard.c
字号:
/* Execution time for entire TX operation is 1.5ms */
gauTxDataBuffer[0] = 0xE1; /* Code bytes non-ZigBee */
gauTxDataBuffer[1] = 0xCC;
gauTxDataBuffer[2] = SECURITY; /* Generic security number */
gauTxDataBuffer[3] = u8DeviceLed; /* Target device */
gauTxDataBuffer[4] = u8LightLed; /* Targeted device's LED. Position contains result on RX */
gauTxDataBuffer[5] = u8Dsn; /* Current data sequence number */
gauTxDataBuffer[6] = 0x00; /* Target device's receive u16Count */
gsTxPacket.u8DataLength = 8;
gauTxDataBuffer[7] = TOGGLECMD;
u8AppStatus = 4; /* Waiting for the u8Toggle ack */
MCPSDataRequest(&gsTxPacket); /* Transmit the packet */
/* Total dwell time is 44ms */
/* We need to wait for all possible devices to repeat plus a 2mS margin */
u16NewTime = MCUReadTmr1 ();
u16RTXOldTime = u16NewTime;
LedDrive(0x00); /* LEDs off */
/* Dwell for a possible repeat cycle. */
while ((u16NewTime-u16RTXOldTime) < DWELLTIME)
{
u16NewTime = MCUReadTmr1 ();
}
/* Total max RX time is 135-44ms */
/* This allows time for the longest routing solution both ways, plus the end device delay plus margin */
MLMERXEnableRequest(&gsRxPacket, RXTIMEOUT); /* Wait for target device response or timeout */
if (u8AppStatus == 4)
{
while (gu8RTxMode != IDLE_MODE) /* Wait until RX is done */
{
LOW_POWER_WHILE(); /* Conserve MCU power */
}
/* Check for timeout. */
if ((gsRxPacket.u8Status == SUCCESS)) /* Good packet received */
{
/* Check to see if the response is intended for this unit */
if ((gauRxDataBuffer[0] == 0xE1) && (gauRxDataBuffer[1] == 0xCC) && (gauRxDataBuffer[2] == SECURITY) && (gauRxDataBuffer[3] == u8DeviceLed) && (gauRxDataBuffer[5] == u8Dsn))
{
/* Check for ACKBACK. */
if ((u8AppStatus == 4) && (*(gsRxPacket.pu8Data + 7) == ACKBACK))
{
LedDrive(0x0f); /* All LEDs on */
u8AppStatus = 0; /* Now that LEDs indicate info, glow for a short */
u8LinkQuality = MLMELinkQuality (); /* Unused but available */
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < LONGFLASHON)
{
u16NewTime = MCUReadTmr1 ();
}
LedDrive(0x00); /* LEDs off */
}
}
else
/* Good packet but not for us. Conflict with another group or 802.15.4 device */
{
u16Count = 0;
while (u16Count < SHORTFLASHCOUNT) /* Flash all LEDs on/off a few times to indicate failure */
{
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHON)
{
u16NewTime = MCUReadTmr1 ();
}
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHOFF)
{
u16NewTime = MCUReadTmr1 ();
}
u16Count ++;
}
}
}
}
if (u8AppStatus != 0) /* Not a valid RX. */
{
u8RetryCount++; /* Times to retry */
if (u8RetryCount == MAXTRY)
{
u8AppStatus = 0; /* Retry over with */
u16Count = 0;
while (u16Count < SHORTFLASHCOUNT) /* Flash all LEDs on/off a few times to indicate failure */
{
LedDrive(0x0f);
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHON)
{
u16NewTime = MCUReadTmr1 ();
}
LedDrive(0x00);
u16OldTime = MCUReadTmr1 ();
u16NewTime = u16OldTime;
while ((u16NewTime-u16OldTime) < SHORTFLASHOFF)
{
u16NewTime = MCUReadTmr1 ();
}
u16Count ++;
}
}
else
/* RX timeout so we need to retry */
{
if (u8AppStatus == 4) /* Retry u8Toggle */
{
u8AppStatus = 2;
}
}
}
}
}
}
/**************************************************************
* Interrupt: MC13192 initiated interrupt handler
* Parameters: none
* Return: none
* Actions: Disables the pushbutton interrupt
**************************************************************/
interrupt void KBD_ISR()
{
/* Disable the PB0 IRQ. Not needed until a new STOP. */
KBI1SC_KBI1E = 0;
PB0IE =0;
PB1IE =0;
PB2IE =0;
PB3IE =0;
KBI1SC_KBACK = 1;
}
/**************************************************************
* Function: LED driver
* Parameters: state. 1-4 is light only that LED.
* 5 is turn all off. 6 is all on.
* Return: none
**************************************************************/
void LedDrive (UINT8 state)
{
switch (state)
{
case 0x00:
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 1;
break;
case 0x01:
LED1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 1;
break;
case 0x02:
LED1 = 1;
LED2 = 0;
LED3 = 1;
LED4 = 1;
break;
case 0x03:
LED1 = 0;
LED2 = 0;
LED3 = 1;
LED4 = 1;
break;
case 0x04:
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 1;
break;
case 0x05:
LED1 = 0;
LED2 = 1;
LED3 = 0;
LED4 = 1;
break;
case 0x06:
LED1 = 1;
LED2 = 0;
LED3 = 0;
LED4 = 1;
break;
case 0x07:
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 1;
break;
case 0x08:
LED1 = 1;
LED2 = 1;
LED3 = 1;
LED4 = 0;
break;
case 0x09:
LED1 = 0;
LED2 = 1;
LED3 = 1;
LED4 = 0;
break;
case 0x0a:
LED1 = 1;
LED2 = 0;
LED3 = 1;
LED4 = 0;
break;
case 0x0b:
LED1 = 0;
LED2 = 0;
LED3 = 1;
LED4 = 0;
break;
case 0x0c:
LED1 = 1;
LED2 = 1;
LED3 = 0;
LED4 = 0;
break;
case 0x0d:
LED1 = 0;
LED2 = 1;
LED3 = 0;
LED4 = 0;
break;
case 0x0e:
LED1 = 1;
LED2 = 0;
LED3 = 0;
LED4 = 0;
break;
case 0x0f:
LED1 = 0;
LED2 = 0;
LED3 = 0;
LED4 = 0;
break;
}
return;
}
/**************************************************************
* Function: Received data handler
* Parameters: rx_packet_t
**************************************************************/
void MCPSDataIndication(tRxPacket *gsRxPacket)
/* Just a direct return. Main loop will handle it. */
{
}
/**************************************************************
* Function: MC13192 reset handler
* Parameters: none
**************************************************************/
void MLMEMC13192ResetIndication (void)
/* Not implemented. */
{
}
/**************************************************************
* 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 + -