Transmitting a Packet
This figure shows a simplified task model of µC/TCP-IP when packets are transmitted through the device.
Figure - µC/TCP-IP Sending a Packet
- A task (assuming an application task) that wants to send data interfaces to µC/TCP-IP through the BSD socket API.
- A function within µC/TCP-IP acquires the binary semaphore (i.e., the global lock) in order to place the data to send into µC/TCP-IP’s data structures.
- The appropriate µC/TCP-IP layer processes the data, preparing it for transmission.
- The task (via the IF layer) then waits on a counting semaphore, which is used to indicate that the transmitter in the device is available to send a packet. If the device is not able to send the packet, the task blocks until the semaphore is signaled by the device. Note that during device initialization, the semaphore is initialized with a value corresponding to the number of packets that can be sent at one time through the device. If the device has sufficient buffer space to be able to queue up four packets, then the counting semaphore is initialized with a count of 4. For DMA-based devices, the value of the semaphore is initialized to the number of available transmit descriptors.
- When the device is ready, the driver either copies the data to the device internal memory space or configures the DMA transmit descriptor. When the device is fully configured, the device driver issues a transmit command.
- After placing the packet into the device, the task releases the global data lock and continues execution.
- When the device finishes sending the data, the device generates an interrupt.
- The Tx ISR signals the Tx Available semaphore indicating that the device is able to send another packet. Additionally, the Tx ISR handler passes the address of the buffer that completed transmission to the Transmit De-allocation task via a queue which is encapsulated by an OS port function call.
- The Transmit De-allocation task wakes up when a device driver posts a transmit buffer address to its queue.
- The global data lock is acquired. If the global data lock is held by another task, the Transmit De-allocation task must wait to acquire the global data lock. Since it is recommended that the Transmit De-allocation task be configured as the highest priority µC/TCP-IP task, it will run following the release of the global data lock, assuming the queue has at least one entry present.
- The lock is released when transmit buffer de-allocation is finished. Further transmission and reception of additional data by application and µC/TCP-IP tasks may resume.