TX Complete Feature

From Texas Instruments Wiki
Jump to: navigation, search

Description:

One of the most important considerations in a wireless device is power consumption.

In order to improve the power consumption as much as possible, CC3000 needs to be shutdown whenever possible.

The TX complete feature's main functionality is to indicate the host whenever it is safe to shutdown CC3000.

Note: it is safe to shutdown CC3000 when all transmitted packets have been acknowledged, at all levels. It is important to distinguish between TCP and UDP.

Since TCP is a reliable protocol by nature, a transmitted packet is considered successful when an ACK frame is received at the transport layer and the MAC layer.

Unlike TCP, UDP requires an ACK only at the MAC layer. For clarification, whenever the number of packets sent by the application is equal to the actual number of acknowledged packets, the HCI_EVENT_CC3000_CAN_SHUT_DOWN event is sent to the application.


API:

This feature is enabled by default. It may be disabled by applying the following API:


wlan_set_event_mask (HCI_EVNT_WLAN_TX_COMPLETE)


Note: It is also possible to enable/disable this feature in runtime.

The event identification is done using the following API:


CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)

Example:

From basic WiFi App:

// this is a diluted version of the unsolicited event handler to demonstrate the EVENT generation
hci_unsol_event_handler(char *event_hdr)
{
 if (event_type & HCI_EVNT_UNSOL_BASE)
 {
 switch(event_type)
 {
 case HCI_EVNT_DATA_UNSOL_FREE_BUFF:
 {
 hci_event_unsol_flowcontrol_handler(event_hdr);
 if (tSLInformation.NumberOfReleasedPackets==tSLInformation.NumberOfSentPackets)
 {
 if (tSLInformation.InformHostOnTxComplete)
 {
 // generating the event to application
 tSLInformation.sWlanCB(HCI_EVENT_CC3000_CAN_SHUT_DOWN, NULL, 0);
 }
 }
 return 1;
 }
 }
 }


// this is the application callback function to handle unsolicited event
void CC3000_UsynchCallback(long lEventType, char * data, unsigned char length)
{
 if (lEventType == HCI_EVENT_CC3000_CAN_SHUT_DOWN)
 {
 // signaling it is OK to shutdown
 OkToDoShutDown = 1;
 }
}


void main(void)
{
 // connect to an AP
 wlan_connect(0, "TP-LINK",7,0,0,0);
 // wait for a DHCP process to finish
 while ((ulCC3000DHCP==0) || (ulCC3000Connected == 0))
 {
 hci_unsolicited_event_handler();
 SysCtlDelay(1000);
 }
 // open a UDP socket for sending data and send 100 packets
 ulSocket = socket(2,2,17);
 for (count=0; count < 100; count++)
 {
 sendto(ulSocket, udpdata, 100, 0, &destAddr, sizeof(destAddr));
 }
 // the application has finished transmission and waiting for a signal
 while (OkToShutDown == 0) ;
 // now it is OK to shutdown
}