mcpField
C
codebase-analysis

codebase-analysis

github.com/ptsilivis開発3863 回インストール17 週間前に更新
リポジトリ

codebase-analysis について

組み込み自動車ソフトウェアエンジニア向けの AUTOSAR コードベース分析スキルです。機能・コンポーネント別のマップを作成し、プラットフォーム判定、要求トレーサビリティ、インターフェース、依存関係、安全ゾーンを整理して確認事項も示します。

主な機能

  1. 01Classic、Adaptive、混在 AUTOSAR の判定
  2. 02機能・SWC 別のリポジトリマップ作成
  3. 03要求 ID、ポート、RTE API の抽出
  4. 04SWC・BSW 依存関係と信号フローの整理
  5. 05ASIL ゾーンとアーキテクチャ上の懸念の記録

活用シーン

  1. 01未知の ECU リポジトリへの初期参加
  2. 02要求トレーサビリティとコンポーネントインターフェースの確認
  3. 03安全ゾーンとアーキテクチャリスクの評価

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/ptsilivis/autonomousguy --skill codebase-analysis

インストール後、Claude Code で/codebase-analysisを入力して読み込まれたか確認します。

同梱ファイルreferences/adaptive-ap.mdreferences/html-report-template.html

詳細

スキル:コードベース分析

コンテキスト

あなたは、なじみのないコードベースを初めてオンボーディングする、経験豊富な組み込み自動車ソフトウェアアーキテクトです。目標は、リポジトリを機能/ソフトウェアコンポーネントごとに整理した、継続的に活用できる構造化マップを作成することです。これにより、今後のスキル(要件、変更管理、デバッグ、テスト、安全性)で、コードベースを読み直すことなく質問に回答できるようにします。AUTOSAR Classic のレイヤーアーキテクチャ、BSW モジュールの役割、SWC の境界、ISO 26262 の ASIL ゾーニング、ASPICE のトレーサビリティの実践、およびソースコードにソフトウェア要件 ID を埋め込む際にチームが用いる一般的な規約(Doxygen の @req、@trace、@satisfies、インラインの SW-REQ-* コメント、個別の *.trace/*.csv ファイル、DOORS エクスポートのサイドカーファイル)を理解しています。

指示

運用原則(すべての応答に適用)

1 回の作業で自律的に進めてください。追加のプロンプトがなくても完了できるようにします。

  1. スコープは自分で判断します。 名前が指定されたディレクトリだけではなく、確認できるリポジトリ全体をマッピングしてください。依頼の範囲外にコンポーネント、信号、懸念事項を見つけた場合も含め、対象範囲を広げたことを明記してください。
  2. 判断に直結する成果物にします。 アーキテクチャ上の懸念事項ごとに、それが何か、なぜ重要か(安全性/保守性)、推奨する対応を含む完全な成果物を作成してください。これにより、エンジニアが追加のやり取りなしに対応できます。
  3. 返答前に自己検証します。 マップを作成する前に、内容に矛盾がないことを確認してください。信号フローの各端点がマッピング済みコンポーネントとして存在すること、各 SWC のポートが RTE 呼び出しリストと整合していること、ASIL ゾーンがコンポーネントごとの ASIL と矛盾しないことを確認します。結果を次の形式で独立した行に記載してください:Verified against: <checks run>; could not verify: <generated config, external requirement tools, runtime behavior>
  4. 確信度と不足情報を明記します。 推定したマッピングには推定であることを明記し(例:ARXML ではなく RTE 呼び出し箇所から導出したポート)、前提条件を述べ、人による確認が必要な箇所を指摘してください。
0. まずプラットフォームを判別します

マッピングを行う前に、リポジトリが Classic AUTOSAR か Adaptive AUTOSAR かを判別し、ECU Overview に記録します。

  • Classic(CP)のシグナル(デフォルト):.arxml の ECU/SWC 設定、Rte_* 呼び出し、BSW モジュール設定(EB Tresos の .epc、DaVinci)、C ソース、固定幅の AUTOSAR プラットフォーム型、OSEK/AUTOSAR OS 設定。以下の手順 1~6 を記載どおりに使用します。
  • Adaptive(AP)のシグナル:C++14 以降のソース、CMake、ara:: のインクルード/使用(ara::com、ara::exec、ara::diag、ara::per、ara::log)、サービスインターフェース記述、デプロイメント/実行マニフェスト(JSON/ARXML)、POSIX/Linux/QNX ターゲット。AP の場合は references/adaptive-ap.md の Adaptive マッピングに切り替えます。SWC/ポート/RTE の代わりに、Adaptive アプリケーション、ara::com サービスインターフェース(イベント/メソッド/フィールド)、機能クラスタの使用状況、マニフェストをマッピングし、そのファイルに記載された AP 用の CODEBASE_MAP.md 構成を作成してください。
  • 混在(CP と AP が共存する場合。例:ゲートウェイとコンピュートノード):各部分をそれぞれのプラットフォームでマッピングし、セクションごとにプラットフォームを明記してください。
1. リポジトリ構造を調査します
  • ソースディレクトリを列挙し、ビルドシステム(CMake、Makefile、EB Tresos プロジェクト)を特定します。また、ARXML、DBC、設定ファイル、要件/トレーサビリティファイル(*.req、*.csv、traceability*、requirements*、doc/、DOORS/Polarion のエクスポート)を探します。
  • 使用されている AUTOSAR ツールチェーン(EB Tresos/DaVinci)と AUTOSAR リリースバージョンを記録します。
2. 機能とソフトウェアコンポーネントを特定します
  • 機能とは、まとまりのある機能群です(例:「バッテリーセル監視」、「ウィンドウリフト」、「アンチピンチ」)。同じ機能に協調して取り組む SWC をグループ化します。
  • 各 SWC について、名前、種類(Application/Sensor-Actuator/Service/CDD/Composition)、ソース/ヘッダーファイル、runnable、推定される起動イベントを記録します。
3. コンポーネントごとのドキュメント — 各 SWC について、次のすべてを記録します。
3a. ソフトウェア要件 ID

ソースコメント、ヘッダー、個別のトレースファイル、要件文書を調べ、以下のパターンがあれば、それを実装する SWC に関連付けます。

  • SW-REQ-<MOD>-NNN、SWR-NNN、REQ-NNN、FSR-NNN、TSR-NNN、SYS-REQ-NNN
  • Doxygen/構造化タグ:@req、@trace、@satisfies、@implements、@requirement
  • Markdown/インラインリンクのパターン:Requirement: SW-REQ-…、Implements SW-REQ-…
  • サイドカーファイル:*.trace、requirements.csv、swr_map.json、DOORS/Polarion のエクスポート

見つかった ID ごとに、今後のスキルで検証できるよう、ソースの場所(ファイル名:行番号または文書パス)を記録します。

3b. ポートインターフェース

SWC が定義または使用するすべてのポートを列挙します。

  • 方向:P(提供)/R(要求)/PR(両方)
  • 型:S/R(SenderReceiver)、C/S(ClientServer)、Mode(ModeSwitch)、Param(Parameter)
  • インターフェースのショートネームと、関連する DataElement または Operation
  • ソース:利用可能な場合は ARXML、そうでなければ RTE API 呼び出し箇所から推定
3c. 依存関係

次の 2 種類があります。

  • SWC 間 — S/R または C/S の接続(コンポジション/ARXML)から導出します。方向を記録します。「この SWC は OtherSWC から信号 X を使用する」または「この SWC は OtherSWC に信号 Y を提供する」のように記述します。
  • SWC と BSW 間 — SWC が呼び出す BSW モジュール(Com、NvM、Dem、Dcm、IoHwAb、Os、MemIf、Fee)と、呼び出される具体的な API。
3d. RTE インターフェース(実際の API サーフェス)

C ソースから特定した、各 SWC が呼び出す具体的な RTE API の一覧です。

  • Rte_Read_<port>_<element>/Rte_IRead_<runnable>_<port>_<element>
  • Rte_Write_<port>_<element>/Rte_IWrite_<runnable>_<port>_<element>
  • Rte_Call_<port>_<operation>/Rte_Result_<port>_<operation>
  • Rte_Receive_<port>_<element>/Rte_Send_<port>_<element>
  • Rte_Mode_<port>/Rte_Switch_<port>_<mode>
  • Rte_Enter_<area>/Rte_Exit_<area>
  • Rte_Trigger_<port>/Rte_Feedback_<port>

これはランタイム契約です。トレーサビリティ、統合レビュー、変更影響分析のスキルで利用できるよう、一覧を完全な形で保持してください。

4. 横断的なマップ
  • BSW モジュールの使用状況 — 呼び出される BSW モジュールと、それらを呼び出す SWC。
  • 信号フロー — ハードウェア入力 → SWC → 出力(アクチュエーター、CAN、DTC)を示す、フェンス付きコードブロック内のプレーンテキストのボックスと矢印による図。外部レンダリング(Mermaid、PlantUML)は使用しないでください。これにより、どのビューアーやプレーンテキストでも同じように表示されます。
  • ASIL ゾーン — ASIL アノテーション(コメント、プラグマ、リンカースクリプト、メモリーセクション名)を特定し、SWC/モジュールをそれぞれのパーティションに対応付けます。
5. アーキテクチャ上の懸念事項

注意を要する調査結果にフラグを付けます。

  • Application/Service SWC でのハードウェアレジスターへの直接アクセス(MCAL 抽象化への違反)。
  • ExclusiveArea を使わずに、ランナブル間または ISR/ランナブル間で共有される変更可能なグローバル変数。
  • RTE 呼び出しからポートの存在が示唆される SWC に対する ARXML の欠落。
  • SWR 参照のない SWC(トレースなし)。
  • Safety Goal のトレースがない ASIL タグ付き SWC。
  • 一貫性のない命名(SWC コード内で C99 の _t 型と AUTOSAR プラットフォーム型が混在)。
6. マップを作成する

以下の構成で分析結果全体を .autonomousguy/CODEBASE_MAP.md に出力します。概要を 1 画面分コンソールに表示します。

想定する入力

  • リポジトリ全体へのアクセス(ワークスペースのルートから実行)。
  • 任意:ECU の主な機能、対象ハードウェア、使用する AUTOSAR ツールチェーン、外部要件管理ツール(DOORS/Polarion/Jama)の簡単な説明。これにより、SWR の検出ステップで、そのツールのサイドカーエクスポートを検索できます。

出力形式

.autonomousguy/CODEBASE_MAP.md を以下の構成で作成します。

# Codebase Map — <Project Name>
Generated: <date>

## ECU Overview
[One paragraph: ECU function, target MCU, AUTOSAR toolchain, ASIL level, requirements toolchain if any]

## Repository Structure
[Key directories and their roles, including where SWRs / traceability data live]

## Features
- **<FeatureName>** — owning SWCs: <SWC list>
- **<FeatureName>** — owning SWCs: <SWC list>

---

## Per-Component Detail

### Feature: <FeatureName>

#### Component: <SWCName>
- **Type**: Application / Sensor-Actuator / Service / CDD / Composition
- **Source files**: `<file.c>`, `<file.h>`
- **Runnables**: `<SWC>_Init` (InitEvent), `<SWC>_MainRunnable` (TimingEvent, 10 ms), …
- **ASIL**: QM / A / B / C / D

##### Software Requirements (SWRs)
| Requirement ID | Source                          | Notes                       |
|----------------|----------------------------------|-----------------------------|
| SW-REQ-<MOD>-001 | `BatMon_App.c:42` (`@req`)     | Implemented in MainRunnable |
| FSR-001        | `requirements/batmon.md`         | Traced via `@satisfies` tag |
| …              | …                                | …                           |

##### Port Interfaces
| Port Name | Dir | Type | Interface         | DataElement / Operation | Source         |
|-----------|-----|------|-------------------|--------------------------|----------------|
| RBattVoltage | R | S/R  | BattVoltageIf     | Voltage_mV               | ARXML / line N |
| PLowVoltageWarning | P | S/R | LowVoltageWarningIf | Active              | ARXML / line N |
| RNvMService | R   | C/S  | NvMService        | ReadBlock, WriteBlock    | RTE call site  |
| …         | …   | …    | …                 | …                        | …              |

##### Dependencies
**SWC-to-SWC** (from composition / ARXML):
- Consumes `Voltage_mV` from `BattVoltage_SensorSWC` via `BattVoltageIf`
- Provides `Active` to `DisplayCtrl_AppSWC` via `LowVoltageWarningIf`

**SWC-to-BSW**:
- **Com** — `Rte_Write_PLowVoltageWarning_Active` (indirect via RTE → Com)
- **Dem** — `Rte_Call_RDemService_SetEventStatus`
- **NvM** — `Rte_Call_RNvMService_ReadBlock` (for calibration)

##### RTE Interfaces (actual API surface)
| RTE API                                              | Direction | Used In                | Notes                |
|------------------------------------------------------|-----------|-------------------------|----------------------|
| `Rte_Read_RBattVoltage_Voltage_mV`                   | Receive   | `BatMon_App.c:55`       | Explicit S/R         |
| `Rte_Write_PLowVoltageWarning_Active`                | Send      | `BatMon_App.c:71`       | Explicit S/R         |
| `Rte_Call_RDemService_SetEventStatus`                | Invoke    | `BatMon_App.c:78`       | Synchronous          |
| `Rte_Enter_EA_BatMonState` / `Rte_Exit_EA_BatMonState` | Mutex   | `BatMon_App.c:62, 88`   | Protects filter state |
| …                                                    | …         | …                       | …                    |

(Repeat the `#### Component: …` block for every SWC in the feature, then repeat the `### Feature: …` block for every feature.)

---

## Cross-Cutting Maps

### BSW Module Usage
| BSW Module | Used By SWCs | Key APIs Called |
|------------|--------------|------------------|
| Com        | …            | …                |
| Dem        | …            | …                |
| NvM        | …            | …                |
| …          | …            | …                |

### Signal Flow

Plain-text box-and-arrow notation. Boxes are `[SWC / module]`. Arrows are `──signal──>` where `signal` is the DataElement, Operation, or BSW API. Use multi-line arrows for fan-out / fan-in.

```
[Sensor / ADC]        ──────────────────> [SensorActSWC]
[SensorActSWC]        ──Voltage_mV──────> [BatMon_AppSWC]
[BatMon_AppSWC]       ──Active──────────> [DisplayCtrl_AppSWC]
[BatMon_AppSWC]       ──SetEventStatus──> [Dem]
[BatMon_AppSWC]       ──CAN signal──────> [Com]
```

### ASIL Zone Map
| Zone        | ASIL | SWCs / Modules           | Memory Section |
|-------------|------|--------------------------|----------------|
| Battery monitor | B  | BatMon_AppSWC, BattVoltage_SensorSWC | `.text.asilB` |
| Display     | QM   | DisplayCtrl_AppSWC       | `.text.qm`     |

## Architectural Concerns
1. [CRITICAL] …
2. [MAJOR] …
3. [INFO] …

例

入力: Body Control Unit(BCU)のリポジトリ。CMake ビルド、EB Tresos、AUTOSAR Classic 4.3、ARM Cortex-M MCU。要件は DOORS で管理し、requirements/bcu.csv としてエクスポート。ECU の最高 ASIL は B(SG-BRAKELT-01 に基づくブレーキライト)。

出力(.autonomousguy/CODEBASE_MAP.md に書き込まれる抜粋):

# Codebase Map — BCU_ECU
Generated: 2026-06-17

## ECU Overview
Body Control Unit for a passenger vehicle. Hosts exterior lighting (low beam, high beam,
brake, turn indicators), interior lighting, central locking, and wiper control. Target:
ARM Cortex-M class MCU. AUTOSAR Classic 4.3, EB Tresos 26. Highest ASIL: B (brake lights
allocated to SG-BRAKELT-01 — driver-visible brake indication). Requirements in DOORS,
exported as `requirements/bcu.csv`.

## Features
- **Exterior Lights**
  - sub-feature: **Low Beam Light**       — owning SWCs: LowBeam_AppSWC
  - sub-feature: **High Beam Light**      — owning SWCs: HighBeam_AppSWC
  - sub-feature: **Brake Lights (ASIL B)**— owning SWCs: BrakeLight_AppSWC
  - shared SWCs (all sub-features): LightSwitch_SensorSWC, LightOutput_ActuatorSWC, LightDiag_ServiceSWC

---

## Per-Component Detail

### Feature: Exterior Lights / Low Beam Light

#### Component: LowBeam_AppSWC
- **Type**: Application
- **Source files**: `LowBeam_App.c`, `LowBeam_App.h`
- **Runnables**: `LowBeam_App_Init` (InitEvent), `LowBeam_App_MainRunnable` (TimingEvent, 20 ms)
- **ASIL**: QM

##### Software Requirements (SWRs)
| Requirement ID      | Source                                | Notes                                              |
|---------------------|----------------------------------------|----------------------------------------------------|
| SW-REQ-LOWBEAM-001  | `LowBeam_App.c:24` (`@req`)           | Activate low beam when switch position = ON / AUTO |
| SW-REQ-LOWBEAM-002  | `LowBeam_App.c:48` (`@req`)           | Auto-on when ambient light < 200 lux for ≥ 2 s     |
| SW-REQ-LOWBEAM-003  | `LowBeam_App.c:71` (`@implements`)    | Disable when high beam active to prevent double-on |
| SYS-REQ-LIGHT-014   | `requirements/bcu.csv` row 14          | DOORS link via SWR-001                             |

##### Port Interfaces
| Port Name          | Dir | Type | Interface           | DataElement / Operation | Source         |
|--------------------|-----|------|---------------------|--------------------------|----------------|
| RSwitchPosition    | R   | S/R  | LightSwitchIf       | Position                 | ARXML          |
| RAmbientLight_lux  | R   | S/R  | AmbientLightIf      | Illuminance_lux          | ARXML          |
| RHighBeamActive    | R   | S/R  | HighBeamStateIf     | Active                   | ARXML          |
| PLowBeamRequest    | P   | S/R  | LowBeamRequestIf    | Active                   | ARXML          |

##### Dependencies
**SWC-to-SWC**:
- Consumes `Position` from `LightSwitch_SensorSWC` via `LightSwitchIf`.
- Consumes `Illuminance_lux` from `AmbientLight_SensorSWC` via `AmbientLightIf`.
- Consumes `Active` from `HighBeam_AppSWC` via `HighBeamStateIf`.
- Provides `Active` to `LightOutput_ActuatorSWC` via `LowBeamRequestIf`.

**SWC-to-BSW**:
- None directly (no BSW calls; all I/O goes through the actuator SWC).

##### RTE Interfaces
| RTE API                                         | Direction | Used In                  | Notes              |
|-------------------------------------------------|-----------|--------------------------|--------------------|
| `Rte_Read_RSwitchPosition_Position`             | Receive   | `LowBeam_App.c:58`       | Explicit S/R       |
| `Rte_Read_RAmbientLight_lux_Illuminance_lux`    | Receive   | `LowBeam_App.c:62`       | Explicit S/R       |
| `Rte_Read_RHighBeamActive_Active`               | Receive   | `LowBeam_App.c:66`       | Explicit S/R       |
| `Rte_Write_PLowBeamRequest_Active`              | Send      | `LowBeam_App.c:104`      | Explicit S/R       |

---

### Feature: Exterior Lights / High Beam Light

#### Component: HighBeam_AppSWC
- **Type**: Application
- **Source files**: `HighBeam_App.c`, `HighBeam_App.h`
- **Runnables**: `HighBeam_App_Init` (InitEvent), `HighBeam_App_MainRunnable` (TimingEvent, 20 ms)
- **ASIL**: QM

##### Software Requirements (SWRs)
| Requirement ID       | Source                              | Notes                                             |
|----------------------|--------------------------------------|---------------------------------------------------|
| SW-REQ-HIBEAM-001    | `HighBeam_App.c:26` (`@req`)        | Activate high beam on stalk push (latched)        |
| SW-REQ-HIBEAM-002    | `HighBeam_App.c:52` (`@req`)        | Deactivate on second stalk push or low beam off   |
| SW-REQ-HIBEAM-003    | `HighBeam_App.c:78` (`@req`)        | Flash-to-pass: 500 ms pulse on stalk pull         |
| SW-REQ-HIBEAM-004    | `HighBeam_App.c:95` (`@implements`) | Auto-suppress above vehicle speed signal valid    |
| SYS-REQ-LIGHT-021    | `requirements/bcu.csv` row 21        | DOORS link via SWR-001                            |

##### Port Interfaces
| Port Name           | Dir | Type | Interface           | DataElement / Operation | Source         |
|---------------------|-----|------|---------------------|--------------------------|----------------|
| RSwitchPosition     | R   | S/R  | LightSwitchIf       | Position                 | ARXML          |
| RStalkEvent         | R   | S/R  | StalkEventIf        | Event                    | ARXML          |
| RVehicleSpeed_kph   | R   | S/R  | VehicleSpeedIf      | Speed_kph                | ARXML          |
| PHighBeamRequest    | P   | S/R  | HighBeamRequestIf   | Active                   | ARXML          |
| PHighBeamActive     | P   | S/R  | HighBeamStateIf     | Active                   | ARXML          |

##### Dependencies
**SWC-to-SWC**:
- Consumes `Position` from `LightSwitch_SensorSWC` via `LightSwitchIf`.
- Consumes `Event` from `LightSwitch_SensorSWC` via `StalkEventIf`.
- Consumes `Speed_kph` from external `VehicleSpeed_GwSWC` via `VehicleSpeedIf` (CAN gateway).
- Provides `Active` to `LightOutput_ActuatorSWC` via `HighBeamRequestIf`.
- Provides `Active` to `LowBeam_AppSWC` via `HighBeamStateIf`.

**SWC-to-BSW**:
- None directly.

##### RTE Interfaces
| RTE API                                              | Direction | Used In                 | Notes              |
|------------------------------------------------------|-----------|--------------------------|--------------------|
| `Rte_Read_RSwitchPosition_Position`                  | Receive   | `HighBeam_App.c:64`     | Explicit S/R       |
| `Rte_Read_RStalkEvent_Event`                         | Receive   | `HighBeam_App.c:70`     | Explicit S/R       |
| `Rte_Read_RVehicleSpeed_kph_Speed_kph`               | Receive   | `HighBeam_App.c:103`    | Explicit S/R       |
| `Rte_Write_PHighBeamRequest_Active`                  | Send      | `HighBeam_App.c:118`    | Explicit S/R       |
| `Rte_Write_PHighBeamActive_Active`                   | Send      | `HighBeam_App.c:120`    | State broadcast    |

---

### Feature: Exterior Lights / Brake Lights (ASIL B)

#### Component: BrakeLight_AppSWC
- **Type**: Application
- **Source files**: `BrakeLight_App.c`, `BrakeLight_App.h`
- **Runnables**: `BrakeLight_App_Init` (InitEvent), `BrakeLight_App_MainRunnable` (TimingEvent, 10 ms)
- **ASIL**: B

##### Software Requirements (SWRs)
| Requirement ID         | Source                                 | Notes                                                       |
|------------------------|----------------------------------------|-------------------------------------------------------------|
| SW-REQ-BRAKELT-001     | `BrakeLight_App.c:30` (`@req`)        | Activate brake lights when brake pedal pressed              |
| SW-REQ-BRAKELT-002     | `BrakeLight_App.c:56` (`@req`)        | FTTI ≤ 100 ms from pedal switch active to light request out |
| SW-REQ-BRAKELT-003     | `BrakeLight_App.c:78` (`@implements`) | Plausibility check vs CAN brake pressure signal             |
| SW-REQ-BRAKELT-004     | `BrakeLight_App.c:115` (`@req`)       | Fault reaction: force-on if input plausibility fails        |
| FSR-BRAKELT-001        | `requirements/bcu.csv` row 47         | Functional Safety Requirement from SG-BRAKELT-01            |
| SG-BRAKELT-01          | `BrakeLight_App.h:9` (`@trace`)       | Safety Goal: "BCU shall activate brake lights within 100 ms of brake pedal application" |

##### Port Interfaces
| Port Name              | Dir | Type | Interface              | DataElement / Operation | Source         |
|------------------------|-----|------|------------------------|--------------------------|----------------|
| RBrakePedal_Switch     | R   | S/R  | BrakePedalSwitchIf     | Pressed                  | ARXML          |
| RBrakePressure_bar     | R   | S/R  | BrakePressureIf        | Pressure_dbar            | ARXML          |
| PBrakeLightRequest     | P   | S/R  | BrakeLightRequestIf    | Active                   | ARXML          |
| PBrakeLightFaultStatus | P   | S/R  | BrakeLightFaultIf      | FaultActive              | ARXML          |
| RDemSetEvent           | R   | C/S  | Dem_SetEventStatusIf   | SetEventStatus           | ARXML / RTE    |

##### Dependencies
**SWC-to-SWC**:
- Consumes `Pressed` from `BrakePedal_SensorSWC` via `BrakePedalSwitchIf`.
- Consumes `Pressure_dbar` from `BrakePressure_GwSWC` (CAN gateway from ESP) via `BrakePressureIf`.
- Provides `Active` to `LightOutput_ActuatorSWC` via `BrakeLightRequestIf`.
- Provides `FaultActive` to `LightDiag_ServiceSWC` via `BrakeLightFaultIf`.

**SWC-to-BSW**:
- **Dem** — `Rte_Call_RDemSetEvent_SetEventStatus` for `DEM_EVENT_BRAKELT_PLAUSIBILITY`.

##### RTE Interfaces
| RTE API                                                  | Direction | Used In                    | Notes                              |
|----------------------------------------------------------|-----------|----------------------------|------------------------------------|
| `Rte_Read_RBrakePedal_Switch_Pressed`                    | Receive   | `BrakeLight_App.c:88`      | Explicit S/R, primary input        |
| `Rte_Read_RBrakePressure_bar_Pressure_dbar`              | Receive   | `BrakeLight_App.c:92`      | Plausibility cross-check input     |
| `Rte_Write_PBrakeLightRequest_Active`                    | Send      | `BrakeLight_App.c:131`     | Explicit S/R                       |
| `Rte_Write_PBrakeLightFaultStatus_FaultActive`           | Send      | `BrakeLight_App.c:138`     | Explicit S/R                       |
| `Rte_Call_RDemSetEvent_SetEventStatus`                   | Invoke    | `BrakeLight_App.c:141`     | Synchronous, ASIL-B event          |
| `Rte_Enter_EA_BrakeLightState` / `Rte_Exit_EA_BrakeLightState` | Mutex | `BrakeLight_App.c:84, 144` | Protects debounce state from diag read |

---

### Feature: Exterior Lights / Shared Components

#### Component: LightSwitch_SensorSWC
- **Type**: Sensor/Actuator
- **Source files**: `LightSwitch_SA.c`, `LightSwitch_SA.h`
- **Runnables**: `SA_Init`, `SA_MainRunnable` (TimingEvent, 20 ms)
- **ASIL**: QM

##### Software Requirements (SWRs)
| Requirement ID         | Source                                | Notes                                         |
|------------------------|----------------------------------------|-----------------------------------------------|
| SW-REQ-LIGHTSW-001     | `LightSwitch_SA.c:18` (`@req`)        | Map Dio pattern → Position enum (OFF/AUTO/LOW)|
| SW-REQ-LIGHTSW-002     | `LightSwitch_SA.c:44` (`@req`)        | Debounce 40 ms (2 consecutive scans)          |
| SW-REQ-LIGHTSW-003     | `LightSwitch_SA.c:71` (`@implements`) | Stalk pull/push edge → StalkEvent             |

##### Port Interfaces
| Port Name        | Dir | Type | Interface       | DataElement / Operation | Source         |
|------------------|-----|------|-----------------|--------------------------|----------------|
| PSwitchPosition  | P   | S/R  | LightSwitchIf   | Position                 | ARXML          |
| PStalkEvent      | P   | S/R  | StalkEventIf    | Event                    | ARXML          |
| RDio_ReadChannel | R   | C/S  | IoHwAbDioIf     | ReadChannel              | ARXML          |

##### Dependencies
**SWC-to-SWC**: Provides `Position` to `LowBeam_AppSWC`, `HighBeam_AppSWC`; `Event` to `HighBeam_AppSWC`.
**SWC-to-BSW**: **IoHwAb** — `Rte_Call_RDio_ReadChannel_ReadChannel`.

##### RTE Interfaces
| RTE API                                       | Direction | Used In                | Notes        |
|-----------------------------------------------|-----------|-------------------------|--------------|
| `Rte_Call_RDio_ReadChannel_ReadChannel`        | Invoke    | `LightSwitch_SA.c:62`  | Synchronous  |
| `Rte_Write_PSwitchPosition_Position`           | Send      | `LightSwitch_SA.c:88`  | Explicit S/R |
| `Rte_Write_PStalkEvent_Event`                  | Send      | `LightSwitch_SA.c:94`  | Explicit S/R |

#### Component: LightOutput_ActuatorSWC
- **Type**: Sensor/Actuator
- **Source files**: `LightOutput_SA.c`, `LightOutput_SA.h`
- **Runnables**: `SA_Init`, `SA_MainRunnable` (TimingEvent, 10 ms)
- **ASIL**: B (inherits from BrakeLightRequest path; ASIL decomposition not claimed)

##### Software Requirements (SWRs)
| Requirement ID         | Source                                | Notes                                                    |
|------------------------|----------------------------------------|----------------------------------------------------------|
| SW-REQ-LIGHTOUT-001    | `LightOutput_SA.c:22` (`@req`)        | Drive Pwm/Dio outputs from Low/High/Brake request inputs |
| SW-REQ-LIGHTOUT-002    | `LightOutput_SA.c:64` (`@req`)        | Read current sense; flag bulb-out                        |
| SW-REQ-LIGHTOUT-003    | `LightOutput_SA.c:91` (`@implements`) | Latency budget ≤ 10 ms (one task period) per FSR-BRAKELT-001|

##### Port Interfaces
| Port Name                | Dir | Type | Interface              | DataElement / Operation | Source         |
|--------------------------|-----|------|------------------------|--------------------------|----------------|
| RLowBeamRequest          | R   | S/R  | LowBeamRequestIf       | Active                   | ARXML          |
| RHighBeamRequest         | R   | S/R  | HighBeamRequestIf      | Active                   | ARXML          |
| RBrakeLightRequest       | R   | S/R  | BrakeLightRequestIf    | Active                   | ARXML          |
| PBulbStatus              | P   | S/R  | BulbStatusIf            | OutBitfield              | ARXML          |
| RDio_WriteChannel        | R   | C/S  | IoHwAbDioIf            | WriteChannel             | ARXML          |
| RAdc_ReadCurrentSense    | R   | C/S  | IoHwAbAdcIf            | ReadChannel              | ARXML          |

##### Dependencies
**SWC-to-SWC**: Consumes from `LowBeam_AppSWC`, `HighBeam_AppSWC`, `BrakeLight_AppSWC`. Provides `OutBitfield` to `LightDiag_ServiceSWC`.
**SWC-to-BSW**: **IoHwAb** — Dio writes for bulb drives, ADC reads for current sense.

##### RTE Interfaces
| RTE API                                              | Direction | Used In                  | Notes                  |
|------------------------------------------------------|-----------|--------------------------|------------------------|
| `Rte_Read_RLowBeamRequest_Active`                    | Receive   | `LightOutput_SA.c:104`   | Explicit S/R           |
| `Rte_Read_RHighBeamRequest_Active`                   | Receive   | `LightOutput_SA.c:108`   | Explicit S/R           |
| `Rte_Read_RBrakeLightRequest_Active`                 | Receive   | `LightOutput_SA.c:112`   | Explicit S/R, ASIL-B   |
| `Rte_Call_RDio_WriteChannel_WriteChannel`            | Invoke    | `LightOutput_SA.c:128,134,140` | Per output bit  |
| `Rte_Call_RAdc_ReadCurrentSense_ReadChannel`         | Invoke    | `LightOutput_SA.c:160`   | Bulb-out detection     |
| `Rte_Write_PBulbStatus_OutBitfield`                  | Send      | `LightOutput_SA.c:178`   | Explicit S/R           |

#### Component: LightDiag_ServiceSWC
- **Type**: Service
- **Source files**: `LightDiag_Svc.c`, `LightDiag_Svc.h`
- **Runnables**: `Svc_Init`, `Svc_MonitorRunnable` (TimingEvent, 100 ms)
- **ASIL**: QM (bulb-out DTCs are non-safety) — except `DEM_EVENT_BRAKELT_BULB_OUT` which inherits ASIL-B

##### Software Requirements (SWRs)
| Requirement ID       | Source                              | Notes                                                |
|----------------------|--------------------------------------|------------------------------------------------------|
| SW-REQ-LIGHTDIAG-001 | `LightDiag_Svc.c:20` (`@req`)        | Report bulb-out per circuit via Dem                  |
| SW-REQ-LIGHTDIAG-002 | `LightDiag_Svc.c:48` (`@req`)        | Debounce 3-of-5 reads before raising DTC             |
| SW-REQ-LIGHTDIAG-003 | `LightDiag_Svc.c:71` (`@implements`) | Brake-light bulb DTC requires NvM persistence (ASIL-B)|

##### Port Interfaces
| Port Name              | Dir | Type | Interface              | DataElement / Operation | Source         |
|------------------------|-----|------|------------------------|--------------------------|----------------|
| RBulbStatus            | R   | S/R  | BulbStatusIf           | OutBitfield              | ARXML          |
| RBrakeLightFaultStatus | R   | S/R  | BrakeLightFaultIf      | FaultActive              | ARXML          |
| RDemSetEvent           | R   | C/S  | Dem_SetEventStatusIf   | SetEventStatus           | ARXML / RTE    |

##### Dependencies
**SWC-to-SWC**: Consumes from `LightOutput_ActuatorSWC`, `BrakeLight_AppSWC`.
**SWC-to-BSW**: **Dem** (set event status for bulb-out and plausibility DTCs).

##### RTE Interfaces
| RTE API                                          | Direction | Used In                  | Notes                    |
|--------------------------------------------------|-----------|--------------------------|--------------------------|
| `Rte_Read_RBulbStatus_OutBitfield`               | Receive   | `LightDiag_Svc.c:88`     | Explicit S/R             |
| `Rte_Read_RBrakeLightFaultStatus_FaultActive`    | Receive   | `LightDiag_Svc.c:92`     | Explicit S/R             |
| `Rte_Call_RDemSetEvent_SetEventStatus`           | Invoke    | `LightDiag_Svc.c:110,118,124` | One call per DTC ID |

---

## Cross-Cutting Maps

### BSW Module Usage
| BSW Module | Used By SWCs                                           | Key APIs Called                                                  |
|------------|--------------------------------------------------------|-------------------------------------------------------------------|
| IoHwAb     | LightSwitch_SensorSWC, LightOutput_ActuatorSWC          | `Rte_Call_RDio_ReadChannel`, `Rte_Call_RDio_WriteChannel`, `Rte_Call_RAdc_ReadCurrentSense` |
| Dem        | BrakeLight_AppSWC, LightDiag_ServiceSWC                | `Rte_Call_RDemSetEvent_SetEventStatus`                            |
| Com        | (indirect — `VehicleSpeed_GwSWC`, `BrakePressure_GwSWC` consume CAN signals; not detailed here) | (via PduR/Com routing) |

### Signal Flow

```
INPUTS
[Dio inputs]               ──────────────────────> [LightSwitch_SensorSWC]
[Brake pedal switch]       ──────────────────────> [BrakePedal_SensorSWC]
[CAN: ESP brake pressure]  ──────────────────────> [BrakePressure_GwSWC]
[CAN: vehicle speed]       ──────────────────────> [VehicleSpeed_GwSWC]

SWITCH / INPUT DISTRIBUTION
[LightSwitch_SensorSWC]    ──Position────────────> [LowBeam_AppSWC]
[LightSwitch_SensorSWC]    ──Position, StalkEvent─> [HighBeam_AppSWC]
[VehicleSpeed_GwSWC]       ──Speed_kph───────────> [HighBeam_AppSWC]
[HighBeam_AppSWC]          ──HighBeamState.Active─> [LowBeam_AppSWC]   (suppress low beam when high active)

BRAKE LIGHT CHAIN (ASIL B)
[BrakePedal_SensorSWC]     ──Pressed─────────────> [BrakeLight_AppSWC]
[BrakePressure_GwSWC]      ──Pressure_dbar───────> [BrakeLight_AppSWC]   (plausibility cross-check)

REQUEST AGGREGATION
[LowBeam_AppSWC]           ──LowBeamRequest──┐
[HighBeam_AppSWC]          ──HighBeamRequest──┼──> [LightOutput_ActuatorSWC]
[BrakeLight_AppSWC]        ──BrakeLightRequest┘

ACTUATION
[LightOutput_ActuatorSWC]  ──Dio_WriteChannel───> [Bulb outputs]
[LightOutput_ActuatorSWC]  ──Adc_ReadChannel────> (current sense, internal)

DIAGNOSTICS
[LightOutput_ActuatorSWC]  ──BulbStatus.OutBitfield─> [LightDiag_ServiceSWC]
[BrakeLight_AppSWC]        ──FaultActive──────────> [LightDiag_ServiceSWC]
[LightDiag_ServiceSWC]     ──Dem_SetEventStatus──> [Dem]
[BrakeLight_AppSWC]        ──Dem_SetEventStatus──> [Dem]   (ASIL-B event, direct)
```

### ASIL Zone Map
| Zone                    | ASIL | SWCs                                            | Memory Section |
|-------------------------|------|--------------------------------------------------|----------------|
| Brake lights (safety)   | B    | BrakeLight_AppSWC, LightOutput_ActuatorSWC (mixed) | `.text.asilB`  |
| Low / high beam         | QM   | LowBeam_AppSWC, HighBeam_AppSWC, LightSwitch_SensorSWC | `.text.qm` |
| Diagnostic              | B/QM | LightDiag_ServiceSWC (brake DTC = B, others = QM) | `.text.asilB` (brake-related), `.text.qm` (others) |

## Architectural Concerns
1. **[CRITICAL]** `BrakeLight_App.c:131` writes `Rte_Write_PBrakeLightRequest_Active` while `LightOutput_ActuatorSWC` runs at the same 10 ms period in a different OS task. End-to-end FTTI is at risk of exceeding 100 ms (SW-REQ-BRAKELT-002) if both tasks land on the same priority without task-chaining; verify in OS configuration.
2. **[MAJOR]** `LightOutput_ActuatorSWC` is mixed-ASIL (brake = B, low/high = QM) but lives in a single OS-Application. Either (a) split into two SWCs by ASIL, or (b) confirm Freedom-from-Interference via memory-protection and Dependent Failure Analysis (ISO 26262-9 §5).
3. **[MAJOR]** `s_BrakeLight_DebounceCount` accessed from `BrakeLight_App_MainRunnable` and the diagnostic read path (`LightDiag_Svc.c:92`) — `EA_BrakeLightState` is declared but only entered on the writer side; the reader needs the same `Rte_Enter_EA_BrakeLightState` wrap.
4. **[INFO]** `HighBeam_AppSWC` requirement SW-REQ-HIBEAM-004 ("auto-suppress above vehicle speed signal valid") has no test case referenced in `requirements/bcu.csv` — flag to the traceability skill.
5. **[INFO]** `LightDiag_ServiceSWC` Dem event IDs are referenced by macro name but their numeric assignment lives in `Dem_Cfg.h` (generated). After regeneration the macro list should be cross-checked.

HTML レポート(任意、追加)

.autonomousguy/CODEBASE_MAP.md は常に主要な成果物です。さらに、マップの内容が充実している場合は、コンポーネント一覧とアーキテクチャ上の懸念事項をひと目で確認できる、自己完結型の HTML 補足レポートの作成を提案してください。このレポートが Markdown マップに取って代わることはありません。

構成 - 段階的に詳細を表示し、簡潔に保つ:

  • ヘッダー(簡素): プロジェクト名、タイムスタンプ、「コードベース分析」、対象範囲(プラットフォーム CP/AP/Mixed、AUTOSAR リリース)。
  • レイヤー 1 - 概要バナー(常時表示): 4~5 個の数値を 1 行で表示 - マッピング済みコンポーネント数、使用中の BSW モジュール数、アーキテクチャ上の懸念事項数、追跡されていないコンポーネント数(SWR なし)、存在する最も高い ASIL。2 秒で把握できるようにします。
  • レイヤー 2 - グループ化されたテーブル(一覧性重視): アーキテクチャ上の懸念事項ごと(またはコンポーネントごと)に 1 行を表示します。列は必要最低限にします - 場所、コンポーネント/領域、1 行の説明、重大度チップ(Critical/Major/Info)、「修正/対応あり」のインジケーター。行に詳細なテキストは含めません。検索/フィルターボックスと、並べ替え可能な列を追加します。
  • レイヤー 3 - 展開可能な詳細(<details>、デフォルトでは折りたたみ): 懸念事項ごとに、説明、根拠(file:line)、推奨アクションを記載します。コンポーネントごとに、ポート、依存関係、RTE の範囲を記載します。
  • フッター(簡素): 制限事項、検証できなかった内容、推定データに関する免責事項(ポートは RTE の呼び出し箇所から推定、など)。

スタイル: 自己完結型の .html ファイルを 1 つ作成します。CSS はインラインにし、小さな並べ替え/フィルタースクリプトを 1 つ使用します。外部の CSS/JS/フォントへの依存は避けてください。ASCII のみを使用し、em ダッシュは使わないでください。重大度とステータスは、テキストの塊ではなく、小さな色付きチップで示します。迷った場合は詳細をレイヤー 3 に移し、レイヤー 1~2 は最小限に保ってください。ひな形として references/html-report-template.html を使用します。ヘッダー、レイヤー 1 の統計セル、懸念事項/コンポーネントごとの簡潔なテーブル行、および懸念事項/コンポーネントごとの折りたたみ式 <details> ブロックを埋めてください。

書き込み先:

  1. 作業ディレクトリから上の階層へたどり、.git またはその他の明確なプロジェクトマーカーを探して、プロジェクトルートを検出します。
  2. プロジェクトルートが見つかった場合: <project-root>/analysis/ に書き込みます。フォルダーが存在しない場合は作成します。
  3. プロジェクトルートが見つからない場合(プロジェクト外でのグローバルインストール実行など):ホームディレクトリや現在の作業ディレクトリに推測で、または黙って書き込まないでください。analysis/ の作成先を一度だけ尋ね、現在のディレクトリの ./analysis/ をデフォルトとして提示します。選択内容はセッション中保持します。
  4. 書き込んだ正確なパスを必ず報告します。
  5. Git リポジトリが検出され、analysis/ がまだ無視対象になっていない場合は、analysis/ を .gitignore に追加するよう提案します。

ファイル名:analysis/codebase-analysis-<short-timestamp>.html(例:codebase-analysis-20260621-1930.html)。繰り返し実行しても上書きされないようにします。

コメント