> For the complete documentation index, see [llms.txt](https://sdk.twelite.info/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sdk.twelite.info/twelite-net-api-ref/krubakku/cbappcoldstart.md).

# cbAppColdStart()

## 解説

`cbAppColdStart(bool_t bStart)` は、`bStart == FALSE` で最初に呼び出され、その後 `bStart == TRUE` で呼び出されます。`bStart == TRUE` の節でアプリケーションの初期化処理を行います。

ここで TWELITE NET の重要な初期化 ([`sToCoNet_AppContext`](broken://pages/-LB-iFVz_Ov3iZzxfW1U) 構造体) を行う必要が有ります。一部の機能はここでしか設定できません。

[`ToCoNet_Event_Register_State_Machine()`](/twelite-net-api-ref/yzaibento/toconet_event-api/toconet_event_register_state_machine.md) 関数にて、ユーザ定義イベント処理関数を登録しています。

この処理の最後で [`ToCoNet_vMacStart()`](/twelite-net-api-ref/twelite-net-guan-shu/toconet_vmacstart.md) 関数を呼び出します。

API の手続きとして MAC 層の開始を明示しています。

## 引数

| 型        | 名前       | 詳細                                    |
| -------- | -------- | ------------------------------------- |
| `bool_t` | `bStart` | 起動時に２回呼び出され、最初が`FALSE`、2回目が`TRUE`となる。 |

#### bStart

`FALSE`：マイコンの起動直後で、ペリフェラル等の初期化も行われていない。ここでモジュール登録の [`ToCoNet_REG_MOD_ALL()`](broken://pages/-LB-k-KjxdeixZFXN5c7)マクロを呼び出す。

`TRUE`：TWELITE NET ライブラリやハードウェアAPIの初期化が行わた後、ライブラリの初期化前で呼び出される。ここでは以下の手続きを記述する。

* [`sToCoNet_AppContext`](broken://pages/-LB-iFVz_Ov3iZzxfW1U) 構造体に初期パラメータの設定
* [`ToCoNet_Event_Register_State_Machine()`](/twelite-net-api-ref/yzaibento/toconet_event-api/toconet_event_register_state_machine.md) によりステートマシンの登録
* アプリケーション独自のメモリ領域等の初期化
* ハードウェアの初期化
* [`ToCoNet_vMacStart()`](/twelite-net-api-ref/twelite-net-guan-shu/toconet_vmacstart.md) によるMAC 層の開始

## 戻り値

なし

## サンプル

```c
void cbAppColdStart(bool_t bAfterAhiInit)
{
	if (!bAfterAhiInit) {
		// before AHI init, very first of code.

		// Register modules
		ToCoNet_REG_MOD_ALL();

	} else {
		// disable brown out detect
		vAHI_BrownOutConfigure(0,//0:2.0V 1:2.3V
				FALSE,
				FALSE,
				FALSE,
				FALSE);

		// clear application context
		memset (&sAppData, 0x00, sizeof(sAppData));
		sAppData.u8channel = CHANNEL;

		// ToCoNet configuration
		sToCoNet_AppContext.u32AppId = APP_ID;
		sToCoNet_AppContext.u8Channel = CHANNEL;

		sToCoNet_AppContext.bRxOnIdle = TRUE;

		// others
		SPRINTF_vInit128();

		// Register
		ToCoNet_Event_Register_State_Machine(vProcessEvCore);

		// Others
		vInitHardware(FALSE);

		// MAC start
		ToCoNet_vMacStart();
	}
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://sdk.twelite.info/twelite-net-api-ref/krubakku/cbappcoldstart.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
