# Network Co-Processor

# Network Co-Processor

This module includes functions that control the Thread stack's execution.

## Summary

| ### Typedefs ||
|---|---|
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga01f212cdeb9c9b21b856f85944ef1b21)(uint32_t aAddress, uint16_t aCount)` | typedef `bool(*` Defines delegate (function pointer) type to control behavior of peek/poke operation. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga2057e09412b7908052cebdaf430f930b)(const uint8_t *aBuf, uint16_t aBufLength)` | typedef `int(*` Pointer is called to send HDLC encoded NCP data. |

| ### Functions ||
|---|---|
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1gafca9a76c9b88f3d1126aa08e7d099ab3(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance, https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga2057e09412b7908052cebdaf430f930b aSendCallback)` | `void` Initialize the NCP based on HDLC framing. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1gaa291c538f21bd37a07f01aede62c6a98(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 **aInstance, uint8_t aCount, https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga2057e09412b7908052cebdaf430f930b aSendCallback)` | `void` Initialize the NCP based on HDLC framing. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1gae9f0f710cfefd72bff753447041180a2(const uint8_t *aBuf, uint16_t aBufLength)` | `void` Is called after HDLC encoded NCP data received. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga23be4509cf2a598fc9dd96d2ee188599(void)` | `void` Is called after NCP send finished. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga3d4f98dd4bee3918767db0db9d5bb1cf(https://openthread.io/reference/group/plat-logging#group__plat-logging_1ga6ac756046db5c24c6c068139b689dbdb aLogLevel, https://openthread.io/reference/group/plat-logging#group__plat-logging_1gaee25d56d067df60b93f75b2ff587668c aLogRegion, const char *aFormat, va_list aArgs)` | `void` Writes OpenThread Log using `otNcpStreamWrite`. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga0e92286242539c3073f364af71bbc10a(https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga01f212cdeb9c9b21b856f85944ef1b21 aAllowPeekDelegate, https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga01f212cdeb9c9b21b856f85944ef1b21 aAllowPokeDelegate)` | `void` Registers peek/poke delegate functions with NCP module. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1gaa14454761f0888f88f14d732039400ef(https://openthread.io/reference/group/api-instance#group__api-instance_1ga25440551213fb5b40869725378584960 *aInstance)` | `void` Initialize the NCP based on SPI framing. |
| `https://openthread.io/reference/group/api-ncp#group__api-ncp_1ga5bf9c9fcc1d94d1b53dcd3bf4e5f85ae(int aStreamId, const uint8_t *aDataPtr, int aDataLen)` | `https://openthread.io/reference/group/api-error#group__api-error_1gabaaa90aaa35da8f9d394a227a23a6a49` Send data to the host via a specific stream. |

## Typedefs

### otNcpDelegateAllowPeekPoke

```
bool(* otNcpDelegateAllowPeekPoke)(uint32_t aAddress, uint16_t aCount)
```
Defines delegate (function pointer) type to control behavior of peek/poke operation.

This delegate function is called to decide whether to allow peek or poke of a specific memory region. It is used if NCP support for peek/poke commands is enabled.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aAddress` | Start address of memory region. | | `[in] aCount` | Number of bytes to peek or poke. | |
| **Returns** | TRUE to allow peek/poke of the given memory region, FALSE otherwise. |

### otNcpHdlcSendCallback

```
int(* otNcpHdlcSendCallback)(const uint8_t *aBuf, uint16_t aBufLength)
```
Pointer is called to send HDLC encoded NCP data.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aBuf` | A pointer to a buffer with an output. | | `[in] aBufLength` | A length of the output data stored in the buffer. | |
| **Returns** | Number of bytes processed by the callback. |

## Functions

### otNcpHdlcInit

```
void otNcpHdlcInit(
  otInstance *aInstance,
  otNcpHdlcSendCallback aSendCallback
)
```
Initialize the NCP based on HDLC framing.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | The OpenThread instance structure. | | `[in] aSendCallback` | The function pointer used to send NCP data. | |

### otNcpHdlcInitMulti

```
void otNcpHdlcInitMulti(
  otInstance **aInstance,
  uint8_t aCount,
  otNcpHdlcSendCallback aSendCallback
)
```
Initialize the NCP based on HDLC framing.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstances` | The OpenThread instance pointers array. | | `[in] aCount` | Number of elements in the array. | | `[in] aSendCallback` | The function pointer used to send NCP data. | |

### otNcpHdlcReceive

```
void otNcpHdlcReceive(
  const uint8_t *aBuf,
  uint16_t aBufLength
)
```
Is called after HDLC encoded NCP data received.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aBuf` | A pointer to a buffer. | | `[in] aBufLength` | The length of the data stored in the buffer. | |

### otNcpHdlcSendDone

```
void otNcpHdlcSendDone(
  void
)
```
Is called after NCP send finished.

### otNcpPlatLogv

```
void otNcpPlatLogv(
  otLogLevel aLogLevel,
  otLogRegion aLogRegion,
  const char *aFormat,
  va_list aArgs
)
```
Writes OpenThread Log using `otNcpStreamWrite`.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aLogLevel` | The log level. | | `[in] aLogRegion` | The log region. | | `[in] aFormat` | A pointer to the format string. | | `[in] aArgs` | va_list matching aFormat. | |

### otNcpRegisterPeekPokeDelegates

```
void otNcpRegisterPeekPokeDelegates(
  otNcpDelegateAllowPeekPoke aAllowPeekDelegate,
  otNcpDelegateAllowPeekPoke aAllowPokeDelegate
)
```
Registers peek/poke delegate functions with NCP module.

The delegate functions are called by NCP module to decide whether to allow peek or poke of a specific memory region. If the delegate pointer is set to NULL, it allows peek/poke operation for any address.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aAllowPeekDelegate` | Delegate function pointer for peek operation. | | `[in] aAllowPokeDelegate` | Delegate function pointer for poke operation. | |

### otNcpSpiInit

```
void otNcpSpiInit(
  otInstance *aInstance
)
```
Initialize the NCP based on SPI framing.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aInstance` | The OpenThread instance structure. | |

### otNcpStreamWrite

```
otError otNcpStreamWrite(
  int aStreamId,
  const uint8_t *aDataPtr,
  int aDataLen
)
```
Send data to the host via a specific stream.

Attempts to send the given data to the host using the given aStreamId. This is useful for reporting error messages, implementing debug/diagnostic consoles, and potentially other types of datastreams.

The write either is accepted in its entirety or rejected. Partial writes are not attempted.

<br />

| Details ||
|---|---|
| Parameters | |---|---| | `[in] aStreamId` | A numeric identifier for the stream to write to. If set to '0', will default to the debug stream. | | `[in] aDataPtr` | A pointer to the data to send on the stream. If aDataLen is non-zero, this param MUST NOT be NULL. | | `[in] aDataLen` | The number of bytes of data from aDataPtr to send. | |
| Return Values | |---|---| | `OT_ERROR_NONE` | The data was queued for delivery to the host. | | `OT_ERROR_BUSY` | There are not enough resources to complete this request. This is usually a temporary condition. | | `OT_ERROR_INVALID_ARGS` | The given aStreamId was invalid. | |

## Resources

OpenThread API Reference topics originate from the source code, available
on [GitHub](https://github.com/openthread/openthread/tree/main/include/openthread).
For more information, or to contribute to our documentation, refer to
[Resources](https://openthread.io/resources).