# WBT Overview

## Description

WM block transfer protocol (WBT) is a buffer control library especially for transferring data to be used under MP communications.
Data is distributed efficiently to multiple children without worrying about the data size.
Transfer from children to the parent is also possible.

Using WBT

The WBT library only functions as a protocol for splitting data into block units and is not used to perform any actual wireless transmissions. For this reason, it is necessary to use the WM library when exchanging data and to implement MP communications ahead of time using the application. The WBT library is implemented using all or part of the send/receive buffer used for MP communications.
In order to link WBT to MP communications, it is necessary to accept a send buffer from the WBT and notify the WBT of the receive buffer either before or after sending or receiving MP communications, separately fom the flow of a series of WBT library function calls.
Specifically, call the following WBT functions inside the WM callback 1) when an MP comunication connection is established (when calling a WM_StartMP complete callback), 2) when MP data has been sent (when calling the WM_SetMPData complete callback), and 3) when MP data has been received (when calling the callback specified by WM_SetPortCallback).

- WBT_MpParentSendHook (when calling a WM_StartMP or WM_SetMPData completion callback in the case of a parent)
- WBT_MpChildSendHook (when calling a WM_StartMP or WM_SetMPData completion callback in the case of a child)
- WBT_MpParentRecvHook (when calling the callback specified by WM_SetPortCallback in the case of a parent)
- WBT_MpChildRecvHook (when calling the callback specified by WM_SetPortCallback in the case of a child)

For example, on the MP communicaton parent device, the WM_SetMPData complete callback function calls WBT_MpParentSendHook with the buffer for the next MP communication as an argument, and the buffer will be set by WM_SetMPData.
`data_size = WBT_MpParentSendHook(SendBuf, DATA_SIZE_MAX);
WM_SetMPData(callback, SendBuf, data_size, 0, 0xffff);
`
Since these functions essentially only read and write data to an send/receive buffer used for MP communications, they do not strictly need to be called in the scenes specified here, but rather may be called even up until the next MP communication.

Furthermore, since the length of the WBT command wait receive queue is only one, only one WBT command can be registered at a time. (WBT_RequestSync, WBT_GetBlockInfo, WBT_GetBlock and WBT_PutUserData functions)
Care must be taken so that even if the next WBT command is issued before the currently executing WBT command terminates, that new command cannot be registered.

Basic Flow of WBT API Calls

The following figure illustrates the process flow for a series of API calls from startup to termination when using WBT.

As described in the section on how to use WBT, WBT really only provides a protocol. Functions such as WM_SetMPData must actually be called for parts with arrows connecting parent and child devices in the figure above. In addition, it is necessary to get a send buffer by calling WBT_MpParentSendHook or WBT_MpChildSendHook before sending MP data, and also necessary to notify WBT of the contents of the recevied buffer by calling WBT_MpParentRecvHook or WBT_MpChildRecvHook after MP data has been received.

Parent Device Process Flow

1. Call WBT_InitParent and specify the packet size for the parent and child device and a callback.
2. Call WBT_RegisterBlock and register a block of data.
3. MP communications start. (Carried out until WM_StartMP completes.)
4. The following processes are performed each send cycle.
   1. WBT_MpParentSendHook is called and a buffer to be sent to the other party is obtained.
   2. Sets the buffer previously obtained by WM-SetMPData.
5. Once the MP receive callback has been called, software calls WBT_MpParentRecvHook and the receive buffer is sent to WBT.
   Depending on the contents of the receive buffer and the status of WBT, this function is called along with command information received by the callback set by WBT_InitParent.
   However, there is no processing that needs to be performed during this callback in the case of a parent device (the side with data to be downloaded).
   If the callback has been called by the WBT_CMD_REQ_GET_BLOCK_DONE, it indicates that one block transfer has completed.
6. Processing proceeds by repeating steps 4 and 5.

Child Device Process Flow

1. WBT_InitChild is called and a callback specified.
2. MP communications start. (Connection is made to the parent and this process is performed until WM_StartMP completes.)
3. WBT_SetOwnAid is called and the child's AID number is sent to WBT.
4. WBT_RequestSync is called and a callback specified.
5. The following processes are performed each send cycle.
   1. WBT_MpChildSendHook is called and a buffer to be sent to the other party is obtained.
   2. Sets the buffer previously obtained by WM-SetMPData.
6. Once the MP receive callback has been called, WBT_MpChildRecvHook is called and the send buffer is sent to the WBT.
   Depending on the contents of the receive buffer and the status of WBT, this function is called along with command information received by the callback set by WBT_InitChild.
   However, in the case of a child device (download side), processing proceeds inside callbacks specified by various WBT functions such as WBT_RequestSync rather than within this callback.
7. The next WBT function is called when a callback specified by any of a variety of WBT functions has been called.
   1. In the case of the WBT_RequestSync complete callback, WBT_GetBlockInfo is called and the block information number wanted by the child is specified.
   2. In the case of the WBT_GetBlockInfo complete callback, WBT_GetBlock is called and the block ID obtained using WBT_GetBlockInfo is specified.
   3. In the case of a WBT_GetBlock complete callback, block transfer has completed.
8. Processing proceeds by repeating steps 5, 6, and 7.

## See Also

`WBT Function List
`

## Revision History

03/13/2006 Initial version.

CONFIDENTIAL