Exemplo n.º 1
0
/*************************************************************************//**
*  @brief Tx Module task handler
*****************************************************************************/
void nwkTxTaskHandler(void)
{
	NwkFrame_t *frame = NULL;

	while (NULL != (frame = nwkFrameNext(frame))) {
		switch (frame->state) {
#ifdef NWK_ENABLE_SECURITY
		case NWK_TX_STATE_ENCRYPT:
		{
			nwkSecurityProcess(frame, true);
		}
		break;
#endif

		case NWK_TX_STATE_DELAY:
		{
			if (frame->tx.timeout > 0) {
				frame->state = NWK_TX_STATE_WAIT_DELAY;
				SYS_TimerStart(&nwkTxDelayTimer);
			} else {
				frame->state = NWK_TX_STATE_SEND;
			}
		}
		break;

		case NWK_TX_STATE_SEND:
		{
			if (NULL == nwkTxPhyActiveFrame) {
				nwkTxPhyActiveFrame = frame;
				frame->state = NWK_TX_STATE_WAIT_CONF;
				PHY_DataReq(&(frame->size));
				nwkIb.lock++;
			}
		}
		break;

		case NWK_TX_STATE_WAIT_CONF:
			break;

		case NWK_TX_STATE_SENT:
		{
			if (NWK_SUCCESS_STATUS == frame->tx.status) {
				if (frame->header.nwkSrcAddr == nwkIb.addr &&
						frame->header.nwkFcf.
						ackRequest) {
					frame->state = NWK_TX_STATE_WAIT_ACK;
					frame->tx.timeout = NWK_ACK_WAIT_TIME /
							NWK_TX_ACK_WAIT_TIMER_INTERVAL
							+ 1;
					SYS_TimerStart(&nwkTxAckWaitTimer);
				} else {
					frame->state = NWK_TX_STATE_CONFIRM;
				}
			} else {
				frame->state = NWK_TX_STATE_CONFIRM;
			}
		}
		break;

		case NWK_TX_STATE_WAIT_ACK:
			break;

		case NWK_TX_STATE_CONFIRM:
		{
#ifdef NWK_ENABLE_ROUTING
			nwkRouteFrameSent(frame);
#endif
			if (NULL == frame->tx.confirm) {
				nwkFrameFree(frame);
			} else {
				frame->tx.confirm(frame);
			}
		}
		break;

		default:
			break;
		}
	}
}
Exemplo n.º 2
0
void nwkTxTaskHandler(void)
{
    if (0 == nwkTxActiveFrames)
        return;

    for (int i = 0; i < NWK_BUFFERS_AMOUNT; i++)
    {
        NwkFrame_t *frame = nwkFrameByIndex(i);

        switch (frame->state)
        {
#ifdef NWK_ENABLE_SECURITY
        case NWK_TX_STATE_ENCRYPT:
        {
            nwkSecurityProcess(frame, true);
        }
        break;
#endif

        case NWK_TX_STATE_SEND:
        {
            if (!PHY_Busy())
            {
                nwkTxPhyActiveFrame = frame;
                frame->state = NWK_TX_STATE_WAIT_CONF;
                PHY_DataReq((uint8_t *)&frame->data, frame->size);
            }
        }
        break;

        case NWK_TX_STATE_WAIT_CONF:
            break;

        case NWK_TX_STATE_SENT:
        {
            if (NWK_SUCCESS_STATUS == frame->tx.status)
            {
                if (frame->data.header.nwkSrcAddr == nwkIb.addr &&
                        frame->data.header.nwkFcf.ackRequest)
                {
                    frame->state = NWK_TX_STATE_WAIT_ACK;
                    frame->tx.timeout = NWK_ACK_WAIT_TIME / NWK_TX_ACK_WAIT_TIMER_INTERVAL + 1;
                    SYS_TimerStart(&nwkTxAckWaitTimer);
                }
                else
                {
                    frame->state = NWK_TX_STATE_CONFIRM;
                }
            }
            else
            {
                frame->state = NWK_TX_STATE_CONFIRM;
            }
        }
        break;

        case NWK_TX_STATE_WAIT_ACK:
            break;

        case NWK_TX_STATE_CONFIRM:
        {
#ifdef NWK_ENABLE_ROUTING
            nwkRouteFrameSent(frame);
#endif
            frame->tx.confirm(frame);
            --nwkTxActiveFrames;
        }
        break;

        default:
            break;
        };
    }
}