Connect Serial Protocol#

The Connect Serial Protocol (CSP) is used by a Host application processor to interact with the Connect stack running on an NCP. CSP messages are sent between the Host and the NCP over a CPC endpoint. CSP is a binary protocol encapsulated within the CPC protocol. For details on the CPC protocol, see the documentation of the CPCd github project.

Every API call from the application translates into a CSP message. The file csp-command-app.c contains the Host API implementation that converts API calls into serial commands, while csp-command-callbacks.c converts incoming serial commands into calls to the application callback functions. There is also a table that maps serial command IDs to handlers. All API calls are referenced by an identifier that must match on both the Host and the NCP side. The file csp-api-enum-gen.h contains these identifiers for both the host and the NCP project.

The csp-command-vncp.c is the NCP code that corresponds to csp-command-app.c. For every API in csp-command-app.c, a corresponding handler exists in csp-command-vncp.c. The csp-command-callbacks.c file exists both on host and NCP, but they are not the same. On the host side, sli_connect_ncp_handle_indication() should be called to deserialize CSP into callbacks, while on the NCP side, every supported callback is implemented and serialized into CSP frames.

Note: Bear in mind that the files csp-command-app.c, csp-command-vncp.c, csp-command-callbacks.c, and csp-api-enum-gen.h are automatically generated so they are subject to change without notice.

In general, the CSP works as follows:

  1. An API call at the Host generates a serial message that gets sent to the NCP.

  2. The Host spins waiting for a response from the NCP.

  3. The NCP, upon receiving a message from the Host, decodes the message and invokes the actual stack API.

  4. The NCP gets a return status from the API, packages it into a response, and sends it to the Host.

  5. The Host, which was waiting for the response, gets the response, which is the return value of the API call.

  6. Finally, the stack API call at the Host returns the actual return value. The following figure illustrates the typical CSP data flow.

The following figure illustrates the typical CSP data flow.

CSP data flowCSP data flow

In the case when data is generated on the NCP side, e.g., by receiving from the network, the NCP sends the message, and the corresponding callback function is invoked on the Host side as shown in the following figure.

CSP data flow - function callbackCSP data flow - function callback

CSP Format#

Byte 0 Byte 1 Byte 2 (Bytes > 2)
Command identifier Arguments

The CSP message consists of a 16-bit command identifier and the packed arguments. This is generated/decoded on both sides using csp-format.c..