Compare commits
3 Commits
05e1755a53
...
d3bed70160
| Author | SHA1 | Date | |
|---|---|---|---|
| d3bed70160 | |||
| 9cc338c122 | |||
| d0b4af0a92 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,10 +1,14 @@
|
||||
{
|
||||
"Version": 1,
|
||||
"WorkspaceRootPath": "C:\\Work\\3_Src\\0_Tool\\PMIC_Tool\\",
|
||||
"WorkspaceRootPath": "C:\\Work\\Src\\0_Tool\\PMIC_Tool\\",
|
||||
"Documents": [
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|C:\\Work\\3_Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|solutionrelative:PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
"AbsoluteMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|C:\\WORK\\SRC\\0_TOOL\\PMIC_TOOL\\PMIC_CMD_TOOL\\EXTERNAL\\FT4222\\INCLUDE\\FTD2XX.H||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|solutionrelative:PMIC_CMD_TOOL\\EXTERNAL\\FT4222\\INCLUDE\\FTD2XX.H||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
},
|
||||
{
|
||||
"AbsoluteMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|C:\\Work\\Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}",
|
||||
"RelativeMoniker": "D:0:0:{C5541CC8-518C-4E1A-A6A8-CB37F56E9558}|PMIC_Cmd_Tool\\PMIC_Cmd_Tool.vcxproj|solutionrelative:PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp||{D0E1A5C6-B359-4E41-9B60-3365922C2A22}"
|
||||
}
|
||||
],
|
||||
"DocumentGroupContainers": [
|
||||
@@ -19,19 +23,28 @@
|
||||
{
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 0,
|
||||
"Title": "PMIC_Cmd_Tool.cpp",
|
||||
"DocumentMoniker": "C:\\Work\\3_Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp",
|
||||
"RelativeDocumentMoniker": "PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp",
|
||||
"ToolTip": "C:\\Work\\3_Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp",
|
||||
"RelativeToolTip": "PMIC_Cmd_Tool\\PMIC_Cmd_Tool.cpp",
|
||||
"ViewState": "AgIAAK4AAAAAAAAAAAAAALQAAAAKAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2025-12-19T05:26:16.228Z",
|
||||
"Title": "ftd2xx.h",
|
||||
"DocumentMoniker": "C:\\Work\\Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\external\\FT4222\\include\\ftd2xx.h",
|
||||
"RelativeDocumentMoniker": "PMIC_Cmd_Tool\\external\\FT4222\\include\\ftd2xx.h",
|
||||
"ToolTip": "C:\\Work\\Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\external\\FT4222\\include\\ftd2xx.h",
|
||||
"RelativeToolTip": "PMIC_Cmd_Tool\\external\\FT4222\\include\\ftd2xx.h",
|
||||
"ViewState": "AgIAACoAAAAAAAAAAAAAAHQBAAAdAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000680|",
|
||||
"WhenOpened": "2026-01-16T02:48:28.794Z",
|
||||
"EditorCaption": ""
|
||||
},
|
||||
{
|
||||
"$type": "Bookmark",
|
||||
"Name": "ST:0:0:{cce594b6-0c39-4442-ba28-10c64ac7e89f}"
|
||||
"$type": "Document",
|
||||
"DocumentIndex": 1,
|
||||
"Title": "PMIC_Cmd_Tool.cpp",
|
||||
"DocumentMoniker": "C:\\Work\\Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp",
|
||||
"RelativeDocumentMoniker": "PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp",
|
||||
"ToolTip": "C:\\Work\\Src\\0_Tool\\PMIC_Tool\\PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp",
|
||||
"RelativeToolTip": "PMIC_Cmd_Tool\\src\\PMIC_Cmd_Tool.cpp",
|
||||
"ViewState": "AgIAAAwAAAAAAAAAAAAhwCEAAAAGAAAAAAAAAA==",
|
||||
"Icon": "ae27a6b0-e345-4288-96df-5eaf394ee369.000677|",
|
||||
"WhenOpened": "2026-01-16T02:11:14.724Z",
|
||||
"EditorCaption": ""
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
@@ -116,21 +116,26 @@
|
||||
<SDLCheck>true</SDLCheck>
|
||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<AdditionalIncludeDirectories>.\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<AdditionalIncludeDirectories>$(ProjectDir)include;$(ProjectDir)external\FT4222\include;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
</ClCompile>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||
<AdditionalLibraryDirectories>.\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);ftd2xx.lib;LibFT4222-64.lib</AdditionalDependencies>
|
||||
<AdditionalLibraryDirectories>$(ProjectDir)external\FT4222\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
|
||||
<AdditionalDependencies>$(CoreLibraryDependencies);%(AdditionalDependencies);LibFT4222-64.lib;ftd2xx.lib</AdditionalDependencies>
|
||||
<DelayLoadDLLs>LibFT4222-64.dll;%(DelayLoadDLLs)</DelayLoadDLLs>
|
||||
</Link>
|
||||
<PostBuildEvent>
|
||||
<Command>copy "$(ProjectDir)dll\ftd2xx.dll" "$(OutDir)"
|
||||
copy "$(ProjectDir)dll\LibFT4222-64.dll" "$(OutDir)"</Command>
|
||||
<Command>if not exist "$(OutDir)dll" mkdir "$(OutDir)dll"
|
||||
xcopy /y "$(ProjectDir)external\FT4222\dll\*.dll" "$(OutDir)dll\"
|
||||
</Command>
|
||||
</PostBuildEvent>
|
||||
</ItemDefinitionGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="PMIC_Cmd_Tool.cpp" />
|
||||
<ClInclude Include="include\PMIC_Reg_Map.h" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\PMIC_Cmd_Tool.cpp" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
|
||||
<ImportGroup Label="ExtensionTargets">
|
||||
|
||||
@@ -15,7 +15,12 @@
|
||||
</Filter>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="PMIC_Cmd_Tool.cpp">
|
||||
<ClInclude Include="include\PMIC_Reg_Map.h">
|
||||
<Filter>헤더 파일</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="src\PMIC_Cmd_Tool.cpp">
|
||||
<Filter>소스 파일</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
|
||||
192
Src/0_Tool/PMIC_Tool/PMIC_Cmd_Tool/include/PMIC_Reg_Map.h
Normal file
192
Src/0_Tool/PMIC_Tool/PMIC_Cmd_Tool/include/PMIC_Reg_Map.h
Normal file
@@ -0,0 +1,192 @@
|
||||
#pragma once
|
||||
#ifndef PMIC_REG_MAP_H // Header Guard: <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20>ߺ<EFBFBD> include <20>Ǵ<EFBFBD> <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>
|
||||
#define PMIC_REG_MAP_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/* ============================================================================
|
||||
PMIC I2C Slave Addresses
|
||||
============================================================================ */
|
||||
#define PMIC_ADDR_REGU (0x54) // Regulation Register I2C Slave Address
|
||||
#define PMIC_ADDR_PROT (0x55) // Protection Register I2C Slave Address
|
||||
|
||||
/* ============================================================================
|
||||
PMIC Register Map - Regulation (Slave: 0x54)
|
||||
============================================================================ */
|
||||
#define IO_PAGE_REGU ((uint8_t)0x000)
|
||||
#define IO_CHIPNAME_REGU ((uint8_t)0x001)
|
||||
#define IO_CHIPVERSION_REGU ((uint8_t)0x002)
|
||||
#define IO_DIEID3_REGU ((uint8_t)0x003)
|
||||
#define IO_DIEID2_REGUB ((uint8_t)0x004)
|
||||
#define IO_DIEID1_REGU ((uint8_t)0x005)
|
||||
#define IO_DIEID0_REGU7 ((uint8_t)0x006)
|
||||
#define OTP_VERSION_REGU ((uint8_t)0x00A)
|
||||
#define IO_MODECTRL_REGU ((uint8_t)0x022)
|
||||
#define IO_MODECTRL2_REGU ((uint8_t)0x023)
|
||||
#define CHIPTSTATE_BUCK_PGOOD ((uint8_t)0x02D)
|
||||
#define CHIPTSTATE_LDO_PGOOD ((uint8_t)0x02E)
|
||||
#define FLT_MASK_OTP ((uint8_t)0x030)
|
||||
#define FLT_MASK_TEMP ((uint8_t)0x031)
|
||||
#define FLT_MASK_BUCK1 ((uint8_t)0x032)
|
||||
#define FLT_MASK_BUCK2 ((uint8_t)0x033)
|
||||
#define FLT_MASK_BUCK3 ((uint8_t)0x034)
|
||||
#define FLT_MASK_BUCK4 ((uint8_t)0x035)
|
||||
#define FLT_MASK_BUCK5 ((uint8_t)0x036)
|
||||
#define FLT_MASK_LDO ((uint8_t)0x037)
|
||||
#define FLT_MASK_IF ((uint8_t)0x038)
|
||||
#define FLT_RECORD_OTP ((uint8_t)0x040)
|
||||
#define FLT_RECORD_TEMP ((uint8_t)0x041)
|
||||
#define FLT_RECORD_BUCK1 ((uint8_t)0x042)
|
||||
#define FLT_RECORD_BUCK2 ((uint8_t)0x043)
|
||||
#define FLT_RECORD_BUCK3 ((uint8_t)0x044)
|
||||
#define FLT_RECORD_BUCK4 ((uint8_t)0x045)
|
||||
#define FLT_RECORD_BUCK5 ((uint8_t)0x046)
|
||||
#define FLT_RECORD_LDO ((uint8_t)0x047)
|
||||
#define FLT_RECORD_IF ((uint8_t)0x048)
|
||||
#define FLT_RECORD_LDO_DISC_DET ((uint8_t)0x049)
|
||||
#define IO_GP3CFGMSB ((uint8_t)0x04C)
|
||||
#define IO_GP3CFGLSB ((uint8_t)0x04D)
|
||||
#define IO_GPIO_DATAIN ((uint8_t)0x056)
|
||||
#define IO_GPIO_DATAOUT ((uint8_t)0x057)
|
||||
#define IO_GPIO_0_DATAOUT_UP_DLY ((uint8_t)0x05C)
|
||||
#define IO_GPIO_0_DATAOUT_DN_DLY ((uint8_t)0x05D)
|
||||
#define IO_GPIO_1_DATAOUT_UP_DLY ((uint8_t)0x05E)
|
||||
#define IO_GPIO_1_DATAOUT_DN_DLY ((uint8_t)0x05F)
|
||||
#define IO_GPIO_2_DATAOUT_UP_DLY ((uint8_t)0x060)
|
||||
#define IO_GPIO_2_DATAOUT_DN_DLY ((uint8_t)0x061)
|
||||
#define IO_GPIO_3_DATAOUT_UP_DLY ((uint8_t)0x062)
|
||||
#define IO_GPIO_3_DATAOUT_DN_DLY ((uint8_t)0x063)
|
||||
#define LOCK_OUT_CFG ((uint8_t)0x06F)
|
||||
#define BUCK1_DVS0CFG1 ((uint8_t)0x070)
|
||||
#define BUCK1_DVS0CFG0 ((uint8_t)0x071)
|
||||
#define BUCK1_DVS1CFG1 ((uint8_t)0x072)
|
||||
#define BUCK1_DVS1CFG0 ((uint8_t)0x073)
|
||||
#define BUCK1_DVSSEL ((uint8_t)0x075)
|
||||
#define BUCK1_EN_DLY ((uint8_t)0x076)
|
||||
#define BUCK1_SHUTDN_DLY ((uint8_t)0x077)
|
||||
#define BUCK2_DVS0CFG1 ((uint8_t)0x080)
|
||||
#define BUCK2_DVS0CFG0 ((uint8_t)0x081)
|
||||
#define BUCK2_EN_DLY ((uint8_t)0x086)
|
||||
#define BUCK2_SHUTDN_DLY ((uint8_t)0x087)
|
||||
#define BUCK3_DVS0CFG1 ((uint8_t)0x090)
|
||||
#define BUCK3_DVS0CFG0 ((uint8_t)0x091)
|
||||
#define BUCK3_EN_DLY ((uint8_t)0x096)
|
||||
#define BUCK3_SHUTDN_DLY ((uint8_t)0x097)
|
||||
#define BUCK4_DVS0CFG1 ((uint8_t)0x0A0)
|
||||
#define BUCK4_DVS0CFG0 ((uint8_t)0x0A1)
|
||||
#define BUCK4_EN_DLY ((uint8_t)0x0A6)
|
||||
#define BUCK4_SHUTDN_DLY ((uint8_t)0x0A7)
|
||||
#define BUCK5_DVS0CFG1 ((uint8_t)0x0B0)
|
||||
#define BUCK5_DVS0CFG0 ((uint8_t)0x0B1)
|
||||
#define BUCK5_EN_DLY ((uint8_t)0x0B6)
|
||||
#define BUCK5_SHUTDN_DLY ((uint8_t)0x0B7)
|
||||
#define LDO1_EN_DLY ((uint8_t)0x0C3)
|
||||
#define LDO1_SHUTDN_DLY ((uint8_t)0x0C4)
|
||||
#define LDO2_EN_DLY ((uint8_t)0x0C5)
|
||||
#define LDO2_SHUTDN_DLY ((uint8_t)0x0C6)
|
||||
#define LDO3_EN_DLY ((uint8_t)0x0C7)
|
||||
#define LDO3_SHUTDN_DLY ((uint8_t)0x0C8)
|
||||
#define LDO4_EN_DLY ((uint8_t)0x0C9)
|
||||
#define LDO4_SHUTDN_DLY ((uint8_t)0x0CA)
|
||||
#define LDO5_EN_DLY ((uint8_t)0x0CB)
|
||||
#define LDO5_SHUTDN_DLY ((uint8_t)0x0CC)
|
||||
#define LDO6_EN_DLY ((uint8_t)0x0CD)
|
||||
#define LDO6_SHUTDN_DLY ((uint8_t)0x0CE)
|
||||
#define HICCUP_RESTRT_DLY ((uint8_t)0x0CF)
|
||||
#define HICCUP_CNT_LIM ((uint8_t)0x0D0)
|
||||
#define DISC_DET_CFG ((uint8_t)0x0D1)
|
||||
#define BUCK_DISC_VTH0 ((uint8_t)0x0D2)
|
||||
#define BUCK_DISC_VTH1 ((uint8_t)0x0D3)
|
||||
#define LDO_DISC_VTH0 ((uint8_t)0x0D4)
|
||||
#define LDO_DISC_VTH1 ((uint8_t)0x0D5)
|
||||
#define MISC_CTRL_REGU ((uint8_t)0x0D6)
|
||||
#define IO_PD ((uint8_t)0x125)
|
||||
#define BACKUP_CFG ((uint8_t)0x176)
|
||||
#define I_IO_INTERNALVERSION_REGU ((uint8_t)0x223)
|
||||
|
||||
/* ============================================================================
|
||||
PMIC Register Map - Protection (Slave: 0x55)
|
||||
============================================================================ */
|
||||
#define IO_PAGE ((uint8_t)0x00)
|
||||
#define IO_CHIPNAME ((uint8_t)0x01)
|
||||
#define IO_CHIPVERSION ((uint8_t)0x02)
|
||||
#define IO_DIEID3 ((uint8_t)0x03)
|
||||
#define IO_DIEID2 ((uint8_t)0x04)
|
||||
#define IO_DIEID1 ((uint8_t)0x05)
|
||||
#define IO_DIEID0 ((uint8_t)0x06)
|
||||
#define IO_CHIPSTATE ((uint8_t)0x07)
|
||||
#define FUSA_CTRL_1_A ((uint8_t)0x08)
|
||||
#define FUSA_CTRL_2 ((uint8_t)0x09)
|
||||
#define FUSA_CTRL_3 ((uint8_t)0x0A)
|
||||
#define FUSA_CTRL_4 ((uint8_t)0x0B)
|
||||
#define FUSA_CTRL_5 ((uint8_t)0x0C)
|
||||
#define FUSA_CHK_CVM1 ((uint8_t)0x0D)
|
||||
#define FUSA_STATUS_CVM1 ((uint8_t)0x0E)
|
||||
#define FUSA_STATUS_CVM2 ((uint8_t)0x0F)
|
||||
#define FUSA_STATUS_1 ((uint8_t)0x10)
|
||||
#define FUSA_STATUS_2 ((uint8_t)0x11)
|
||||
#define FUSA_STATUS_2A ((uint8_t)0x12)
|
||||
#define FUSA_STATUS_3 ((uint8_t)0x13)
|
||||
#define FUSA_STATUS_4 ((uint8_t)0x14)
|
||||
#define FUSA_SOC_CHK_1 ((uint8_t)0x15)
|
||||
#define IO_HOST_MSGCNT ((uint8_t)0x16)
|
||||
#define CLK_CNT_1 ((uint8_t)0x17)
|
||||
#define CLK_CNT_2 ((uint8_t)0x18)
|
||||
#define FLT_RECORD_A ((uint8_t)0x19)
|
||||
#define FLT_RECORD_B ((uint8_t)0x1A)
|
||||
#define FLT_RECORD_GND_AVIN ((uint8_t)0x1B)
|
||||
#define FLT_RECORD_BG_Temp ((uint8_t)0x1C)
|
||||
#define FLT_RECORD_IntLDOs ((uint8_t)0x1D)
|
||||
#define FLT_RECORD_ExtLDOs ((uint8_t)0x1E)
|
||||
#define FLT_RECORD_BUCKS_B ((uint8_t)0x1F)
|
||||
#define FLT_RECORD_BUCKS_A ((uint8_t)0x20)
|
||||
#define FLT_RECORD_ExtINPs_7_0 ((uint8_t)0x21)
|
||||
#define OTP_RWADDR ((uint8_t)0x28)
|
||||
#define OTP_FLT_RECORD ((uint8_t)0x2A)
|
||||
#define ADCMON_COPY_SAMPLE ((uint8_t)0x2D)
|
||||
#define ADCMON_COPY_DATA_MSB ((uint8_t)0x2E)
|
||||
#define ADCMON_COPY_DATA_LSB ((uint8_t)0x2F)
|
||||
#define ADCMON_DATAMSB_Offset ((uint8_t)0x30)
|
||||
#define ADCMON_DATALSB_Offset ((uint8_t)0x31)
|
||||
#define ADCMON_DATAMSB_Temp2 ((uint8_t)0x32)
|
||||
#define ADCMON_DATALSB_Temp2 ((uint8_t)0x33)
|
||||
#define ADCMON_DATAMSB_Temp3 ((uint8_t)0x34)
|
||||
#define ADCMON_DATALSB_Temp3 ((uint8_t)0x35)
|
||||
|
||||
/* ADC Monitoring Data Registers */
|
||||
#define ADCMON_DATAMSB_BGR ((uint8_t)0x36)
|
||||
#define ADCMON_DATALSB_BGR ((uint8_t)0x37)
|
||||
#define ADCMON_DATAMSB_PGNDR ((uint8_t)0x38)
|
||||
#define ADCMON_DATALSB_PGNDR ((uint8_t)0x39)
|
||||
#define IntLDORegu_0_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x3A)
|
||||
#define IntLDORegu_0_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x3B)
|
||||
#define IntLDORegu_1_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x3C)
|
||||
#define IntLDORegu_1_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x3D)
|
||||
#define IntLDORegu_2_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x3E)
|
||||
#define IntLDORegu_2_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x3F)
|
||||
#define IntLDORegu_3_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x40)
|
||||
#define IntLDORegu_3_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x41)
|
||||
#define IntLDORegu_4_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x42)
|
||||
#define IntLDORegu_4_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x43)
|
||||
#define IntLDORegu_5_ADCMON_DATAMSB_IntLDORegu ((uint8_t)0x44)
|
||||
#define IntLDORegu_5_ADCMON_DATALSB_IntLDORegu ((uint8_t)0x45)
|
||||
#define IntLDOProt_0_ADCMON_DATAMSB_IntLDOProt ((uint8_t)0x46)
|
||||
#define IntLDOProt_0_ADCMON_DATALSB_IntLDOProt ((uint8_t)0x47)
|
||||
#define IntLDOProt_1_ADCMON_DATAMSB_IntLDOProt ((uint8_t)0x48)
|
||||
#define IntLDOProt_1_ADCMON_DATALSB_IntLDOProt ((uint8_t)0x49)
|
||||
|
||||
/* ADC Monitoring Data Registers (AVIN, PVIN, VOUT) */
|
||||
#define ADCMON_DATAMSB_AVIN1 ((uint8_t)0x04A)
|
||||
#define ADCMON_DATALSB_AVIN1 ((uint8_t)0x04B)
|
||||
#define ADCMON_DATAMSB_AVIN2 ((uint8_t)0x04C)
|
||||
#define ADCMON_DATALSB_AVIN2 ((uint8_t)0x04D)
|
||||
|
||||
#define extLDO_0_ADCMON_DATAMSB_ExtLDO ((uint8_t)0x04E)
|
||||
#define extLDO_0_ADCMON_DATALSB_ExtLDO ((uint8_t)0x04F)
|
||||
#define extLDO_1_ADCMON_DATAMSB_ExtLDO ((uint8_t)0x050)
|
||||
#define extLDO_1_ADCMON_DATALSB_ExtLDO ((uint8_t)0x051)
|
||||
#define extLDO_2_ADCMON_DATAMSB_ExtLDO ((uint8_t)0x052)
|
||||
#define extLDO_2_ADCMON_DATALSB_ExtLDO ((uint8_t)0x053)
|
||||
#define extLDO_3_ADCMON_DATAMSB_ExtLDO ((uint8_t)0x054)
|
||||
|
||||
#endif // PMIC_REG_MAP_H
|
||||
@@ -9,12 +9,428 @@
|
||||
//Sleep(1); // 1ms 딜레이
|
||||
//Sleep(10); // 10ms 딜레이
|
||||
//Sleep(100); // 100ms 딜레이
|
||||
//Sleep(1000); // 1s 딜레이
|
||||
//Sleep(10000); // 10s 딜레이
|
||||
|
||||
// FT4222 헤더
|
||||
#include "ftd2xx.h"
|
||||
#include "LibFT4222.h"
|
||||
|
||||
uint8_t PMIC_I2C_SLAVE_ADDR = 0x55;
|
||||
// PMIC Register Map
|
||||
#include "PMIC_Reg_Map.h"
|
||||
|
||||
// Function Prototypes
|
||||
FT_HANDLE InitializeFT4222();
|
||||
void currentTime(char* buf, size_t len);
|
||||
void logPacket(const char* dir, uint8_t* data, int size, int hasCrc);
|
||||
uint8_t calcCRC8(uint8_t addrWithRw, uint8_t* data, int len);
|
||||
int parseCommand(const char* dir);
|
||||
void PMIC_I2C_Write(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr, uint8_t value);
|
||||
void PMIC_I2C_Read(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr);
|
||||
|
||||
int main()
|
||||
{
|
||||
FT4222_STATUS ft4222Status;
|
||||
//char addrInput[16];
|
||||
unsigned int tempAddr = 0;
|
||||
uint8_t I2C_SLAVE_ADDR = 0;
|
||||
unsigned long log_counter = 0;
|
||||
|
||||
char timeStr[16]; // 시간을 저장할 버퍼 (HH:MM:SS면 9바이트면 충분)
|
||||
|
||||
currentTime(timeStr, sizeof(timeStr));
|
||||
|
||||
//printf("현재 시간: %s\n", timeStr);
|
||||
|
||||
// 1. DLL 탐색 경로에 하위 폴더 'dll' 추가
|
||||
// 이 설정은 이 함수 호출 이후에 로드되는 모든 DLL에 적용됩니다.
|
||||
if (!SetDllDirectoryA("./dll")) {
|
||||
printf("DLL 경로 설정 실패 (에러 코드: %lu)\n", GetLastError());
|
||||
return -1;
|
||||
}
|
||||
|
||||
// 2. FT4222 장치 연결 및 초기화
|
||||
FT_HANDLE ftHandle = InitializeFT4222();
|
||||
if (!ftHandle) {
|
||||
return -1; // 초기화 실패 시 프로그램 종료
|
||||
}
|
||||
|
||||
printf("PMIC I2C Packet Logger with FT4222\n \n");
|
||||
|
||||
#if 0
|
||||
printf("I2C Address\n Regulation Register is 0x54\n Protection Register is 0x55\n \nEnter 7-bit I2C Slave Address (hex): ");
|
||||
if (scanf_s("%15s", addrInput, (unsigned)_countof(addrInput)) != 1) {
|
||||
printf("입력 오류\n");
|
||||
return -1;
|
||||
}
|
||||
if (sscanf_s(addrInput, "%x", &tempAddr) != 1) {
|
||||
printf("잘못된 주소 입력\n");
|
||||
return -1;
|
||||
}
|
||||
I2C_SLAVE_ADDR = (uint8_t)tempAddr;
|
||||
|
||||
printf("슬레이브 주소 설정됨: 0x%02X\n", I2C_SLAVE_ADDR);
|
||||
|
||||
getchar(); // 버퍼 클리어
|
||||
|
||||
printf("사용법: I2C_WRITE <data...> 또는 w <data...>\n");
|
||||
printf(" I2C_READ (항상 2바이트 읽음) 또는 r\n");
|
||||
printf("exit 또틑 e 입력 시 종료\n");
|
||||
#endif
|
||||
|
||||
printf("Read Regulation 0x54, Page 0x02, Address 0x23 : 0x66 이면 OK\n ");
|
||||
|
||||
#if 0
|
||||
FT_HANDLE ftHandle = NULL;
|
||||
FT_STATUS ftStatus;
|
||||
DWORD numDevs = 0;
|
||||
|
||||
ftStatus = FT_CreateDeviceInfoList(&numDevs);
|
||||
if (ftStatus != FT_OK || numDevs == 0) {
|
||||
printf("FT4222 장치를 찾을 수 없습니다.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ftStatus = FT_Open(0, &ftHandle);
|
||||
if (ftStatus != FT_OK) {
|
||||
printf("FT4222 장치 열기 실패\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, 400); // 400kHz
|
||||
if (ft4222Status != FT4222_OK) {
|
||||
printf("I2C Master 초기화 실패\n");
|
||||
FT_Close(ftHandle);
|
||||
return -1;
|
||||
}
|
||||
#endif
|
||||
|
||||
/* Fault register data: Protection Register, Address 0x010 ~0x014, 0x019 ~0x021
|
||||
0x010 - FUSA_STATUS_1
|
||||
0x011 - FUSA_STATUS_2
|
||||
0x012 - FUSA_STATUS_2A
|
||||
0x013 - FUSA_STATUS_3
|
||||
0x014 - FUSA_STATUS_4
|
||||
0x019 - FLT_RECORD_A
|
||||
0x01A - FLT_RECORD_B
|
||||
0x01B - FLT_RECORD_GND_AVIN
|
||||
0x01C - FLT_RECORD_BG_Temp
|
||||
0x01D - FLT_RECORD_IntLDOs
|
||||
0x01E - FLT_RECORD_ExtLDOs
|
||||
0x01F - FLT_RECORD_BUCKS_B
|
||||
0x020 - FLT_RECORD_BUCKS_A
|
||||
0x021 - FLT_RECORD_ExtINPs_7_0
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x10); //0x010 - FUSA_STATUS_1
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x11); //0x011 - FUSA_STATUS_2
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x12); //0x012 - FUSA_STATUS_2A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x13); //0x013 - FUSA_STATUS_3
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x14); //0x014 - FUSA_STATUS_4
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x19); //0x019 - FLT_RECORD_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1A); //0x01A - FLT_RECORD_B
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1B); //0x01B - FLT_RECORD_GND_AVIN
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1C); //0x01C - FLT_RECORD_BG_Temp
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1D); //0x01D - FLT_RECORD_IntLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1E); //0x01E - FLT_RECORD_ExtLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1F); //0x01F - FLT_RECORD_BUCKS_B
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x20); //0x01E - FLT_RECORD_BUCKS_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x21); //0x01F - FLT_RECORD_ExtINPs_7_0
|
||||
*/
|
||||
|
||||
//printf("=================================================================================\n");
|
||||
/********************************************************************************************
|
||||
I2C Write
|
||||
PMIC_I2C_Write(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr, uint8_t value)
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0xAA, 0xBB);
|
||||
********************************************************************************************/
|
||||
//printf("=================================================================================\n");
|
||||
/********************************************************************************************
|
||||
I2C Read
|
||||
PMIC_I2C_Read(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0xAA);
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
//for (int i = 0; i < 10000000; i++) {
|
||||
//while (1) {
|
||||
//}
|
||||
|
||||
//for (int i = 0; i < 10000000; i++) {
|
||||
//while (log_counter < 10 ){
|
||||
|
||||
// 예: 10번 while에 한 번만 실행
|
||||
//if (log_counter % 10 == 0) {
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
printf("실행하려면 Enter 키를 누르세요...\n");
|
||||
(void)getchar();
|
||||
|
||||
//Regulation Register
|
||||
// Page00
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x00);
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x00);
|
||||
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x00); //0x000 - IO_PAGE_REGU
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x01); //0x001 - IO_CHIPNAME_REGU
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x02); //0x002 - IO_CHIPVERSION_REGU
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x03); //0x003 - IO_DIEID3_REGU
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x04); //0x004
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x05); //0x005
|
||||
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x23);
|
||||
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
// Page02
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x20);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x21);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x22); //0x222 - I_OTP_VERSION
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x23); //0x223 - I_OTP_INTERNALVERSION
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x24);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x25);
|
||||
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
//Protection Register
|
||||
|
||||
// Read FLT Register
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x10); //0x010 - FUSA_STATUS_1
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x11); //0x011 - FUSA_STATUS_2
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x12); //0x012 - FUSA_STATUS_2A
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x13); //0x013 - FUSA_STATUS_3
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x14); //0x014 - FUSA_STATUS_4
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x19); //0x019 - FLT_RECORD_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1A); //0x01A - FLT_RECORD_B
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1B); //0x01B - FLT_RECORD_GND_AVIN
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1C); //0x01C - FLT_RECORD_BG_Temp
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1D); //0x01D - FLT_RECORD_IntLDOs
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1E); //0x01E - FLT_RECORD_ExtLDOs
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1F); //0x01F - FLT_RECORD_BUCKS_B
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x20); //0x01E - FLT_RECORD_BUCKS_A
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x21); //0x01F - FLT_RECORD_ExtINPs_7_0
|
||||
|
||||
|
||||
// PMIC Debug Mode
|
||||
// Page01
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_PROT, 0x00, 0x01);
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_PROT, 0x00, 0x01);
|
||||
//PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x02); //0x102 - IO_MODECTRL Read시 디폴트 0x65
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_PROT, 0x02, 0x25); //0x102 - IO_MODECTRL
|
||||
|
||||
// 10s 딜레이
|
||||
//Sleep(10000);
|
||||
|
||||
//PMIC_I2C_Write(ftHandle, PMIC_ADDR_PROT, 0x02, 0x65); //0x102 - IO_MODECTRL
|
||||
|
||||
//}
|
||||
//log_counter++;
|
||||
//}
|
||||
|
||||
#if 0
|
||||
//Regulation Register
|
||||
printf("[Page-0]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x00);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x00);
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x00); //0x000 - IO_PAGE_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x01); //0x001 - IO_CHIPNAME_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x02); //0x002 - IO_CHIPVERSION_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x03); //0x003 - IO_DIEID3_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x04); //0x004 - IO_DIEID2_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x05); //0x005 - IO_DIEID1_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x06); //0x006 - IO_DIEID0_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x0A); //0x00A - OTP_VERSION_REGU
|
||||
|
||||
//Fault register data: Protection Register, Address 0x010 ~0x014, 0x019 ~0x021
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x10); //0x010 - FUSA_STATUS_1
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x11); //0x011 - FUSA_STATUS_2
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x12); //0x012 - FUSA_STATUS_2A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x13); //0x013 - FUSA_STATUS_3
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x14); //0x014 - FUSA_STATUS_4
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x19); //0x019 - FLT_RECORD_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1A); //0x01A - FLT_RECORD_B
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1B); //0x01B - FLT_RECORD_GND_AVIN
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1C); //0x01C - FLT_RECORD_BG_Temp
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1D); //0x01D - FLT_RECORD_IntLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1E); //0x01E - FLT_RECORD_ExtLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_PROT, 0x1F); //0x01F - FLT_RECORD_BUCKS_B
|
||||
|
||||
|
||||
printf("[Page-1]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x01);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x01);
|
||||
|
||||
|
||||
printf("[Page-2]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x02);
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x20); //0x020 - FLT_RECORD_BUCKS_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x21); //0x021 - FLT_RECORD_ExtINPs_7_0
|
||||
|
||||
|
||||
printf("[PMIC_RAA271005_INIT]====================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x01);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_ADDR_REGU, 0x00, 0x01);
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x07); //0x107 - WDT_CFG0 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x08); //0x108 - WDT_CFG1 (OTP) //WDT_ULCNT, WDT_LLCNT
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x09); //0x109 - WDT_CFG2 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x16); //0x116 - FUSA_TIMER_1 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x17); //0x117 - FUSA_TIMER_2 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_ADDR_REGU, 0x2C); //0x12C - FLT_MASK_B (OTP)
|
||||
|
||||
//Protection Register
|
||||
|
||||
#endif
|
||||
char line[256];
|
||||
while (1) {
|
||||
printf("> ");
|
||||
if (!fgets(line, sizeof(line), stdin)) break;
|
||||
|
||||
line[strcspn(line, "\r\n")] = 0; // 개행 제거
|
||||
if (strcmp(line, "exit") == 0) break;
|
||||
if (strcmp(line, "e") == 0) break;
|
||||
if (strlen(line) == 0) continue;
|
||||
|
||||
char* context = NULL;
|
||||
char* token = strtok_s(line, " ", &context);
|
||||
if (!token) continue;
|
||||
|
||||
for (char* p = token; *p; p++) *p = toupper(*p);
|
||||
|
||||
int command = parseCommand(token);
|
||||
|
||||
if (command == 1) { // I2C_WRITE
|
||||
uint8_t bytes[256];
|
||||
int len = 0;
|
||||
|
||||
while ((token = strtok_s(NULL, " ", &context)) != NULL) {
|
||||
unsigned int val;
|
||||
if (sscanf_s(token, "%x", &val) == 1) {
|
||||
bytes[len++] = (uint8_t)val;
|
||||
}
|
||||
else {
|
||||
printf("잘못된 HEX 값: %s\n", token);
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
printf("전송할 데이터가 없습니다.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t addrWithRw = (I2C_SLAVE_ADDR << 1) | 0x00;
|
||||
uint8_t crc = calcCRC8(addrWithRw, bytes, len);
|
||||
bytes[len++] = crc;
|
||||
|
||||
uint16 transferred = 0;
|
||||
ft4222Status = FT4222_I2CMaster_Write(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
bytes,
|
||||
(uint16)len,
|
||||
&transferred);
|
||||
|
||||
if (ft4222Status != FT4222_OK) {
|
||||
printf("I2C Write 실패\n");
|
||||
}
|
||||
else {
|
||||
logPacket("I2C_WRITE", bytes, len, 1);
|
||||
}
|
||||
}
|
||||
else if (command == 2) { // I2C_READ
|
||||
uint8_t bytes[256];
|
||||
uint16 transferred = 0;
|
||||
FT4222_STATUS st;
|
||||
int len = 0;
|
||||
|
||||
while ((token = strtok_s(NULL, " ", &context)) != NULL) {
|
||||
unsigned int val;
|
||||
if (sscanf_s(token, "%x", &val) == 1) {
|
||||
bytes[len++] = (uint8_t)val;
|
||||
}
|
||||
else {
|
||||
printf("잘못된 HEX 값: %s\n", token);
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
printf("전송할 데이터가 없습니다.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t addrWithRw = (I2C_SLAVE_ADDR << 1) | 0x00;
|
||||
uint8_t crc = calcCRC8(addrWithRw, bytes, len);
|
||||
bytes[len++] = crc;
|
||||
|
||||
st = FT4222_I2CMaster_Write(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
bytes,
|
||||
(uint16)len,
|
||||
&transferred);
|
||||
|
||||
if (st != FT4222_OK) {
|
||||
printf("Read용 Address Write 실패\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 🔹 Register Address에서 2바이트 Read (Value + CRC)
|
||||
uint8_t rx[2] = { 0 };
|
||||
st = FT4222_I2CMaster_Read(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
rx,
|
||||
2,
|
||||
&transferred);
|
||||
|
||||
if (st != FT4222_OK) {
|
||||
printf("I2C Read 실패\n");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
printf("Read 결과: [Address = 0x%02X], [Value = 0x%02X], [CRC = 0x%02X]\n",
|
||||
bytes[0], rx[0], rx[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("첫 단어는 I2C_WRITE(w) 또는 I2C_READ(r) 여야 합니다.\n");
|
||||
}
|
||||
}
|
||||
|
||||
FT_Close(ftHandle);
|
||||
return 0;
|
||||
}
|
||||
|
||||
FT_HANDLE InitializeFT4222() {
|
||||
FT_HANDLE handle = NULL;
|
||||
DWORD numDevs = 0;
|
||||
|
||||
// 연결된 장치 리스트 확인
|
||||
if (FT_CreateDeviceInfoList(&numDevs) != FT_OK || numDevs == 0) {
|
||||
printf("오류: 연결된 FT4222 장치를 찾을 수 없습니다.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// 0번 인덱스 장치 열기
|
||||
if (FT_Open(0, &handle) != FT_OK) {
|
||||
printf("오류: 장치를 열 수 없습니다.\n");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
// I2C 마스터 모드 초기화 (400kHz 주파수 설정)
|
||||
if (FT4222_I2CMaster_Init(handle, 400) != FT4222_OK) {
|
||||
printf("오류: I2C 마스터 초기화 실패.\n");
|
||||
FT_Close(handle);
|
||||
return NULL;
|
||||
}
|
||||
return handle;
|
||||
}
|
||||
|
||||
// 현재 시간을 "HH:MM:SS" 형식으로 buf에 저장
|
||||
void currentTime(char* buf, size_t len)
|
||||
@@ -202,330 +618,4 @@ void PMIC_I2C_Read(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr)
|
||||
printf("Read 결과: [Address = 0x%02X], [Value = 0x%02X], [CRC = 0x%02X]\n",
|
||||
regAddr, rx[0], rx[1]);
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("PMIC I2C Packet Logger with FT4222\n \n");
|
||||
|
||||
char addrInput[16];
|
||||
unsigned int tempAddr = 0;
|
||||
uint8_t I2C_SLAVE_ADDR = 0;
|
||||
unsigned long log_counter = 0;
|
||||
|
||||
char timeStr[16]; // 시간을 저장할 버퍼 (HH:MM:SS면 9바이트면 충분)
|
||||
|
||||
currentTime(timeStr, sizeof(timeStr));
|
||||
|
||||
//printf("현재 시간: %s\n", timeStr);
|
||||
|
||||
|
||||
#if 0
|
||||
printf("I2C Address\n Regulation Register is 0x54\n Protection Register is 0x55\n \nEnter 7-bit I2C Slave Address (hex): ");
|
||||
if (scanf_s("%15s", addrInput, (unsigned)_countof(addrInput)) != 1) {
|
||||
printf("입력 오류\n");
|
||||
return -1;
|
||||
}
|
||||
if (sscanf_s(addrInput, "%x", &tempAddr) != 1) {
|
||||
printf("잘못된 주소 입력\n");
|
||||
return -1;
|
||||
}
|
||||
I2C_SLAVE_ADDR = (uint8_t)tempAddr;
|
||||
|
||||
printf("슬레이브 주소 설정됨: 0x%02X\n", I2C_SLAVE_ADDR);
|
||||
|
||||
getchar(); // 버퍼 클리어
|
||||
|
||||
printf("사용법: I2C_WRITE <data...> 또는 w <data...>\n");
|
||||
printf(" I2C_READ (항상 2바이트 읽음) 또는 r\n");
|
||||
printf("exit 또틑 e 입력 시 종료\n");
|
||||
#endif
|
||||
|
||||
printf("Read Regulation 0x54, Page 0x02, Address 0x23 : 0x66 이면 OK\n ");
|
||||
|
||||
FT_HANDLE ftHandle = NULL;
|
||||
FT_STATUS ftStatus;
|
||||
DWORD numDevs = 0;
|
||||
|
||||
ftStatus = FT_CreateDeviceInfoList(&numDevs);
|
||||
if (ftStatus != FT_OK || numDevs == 0) {
|
||||
printf("FT4222 장치를 찾을 수 없습니다.\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
ftStatus = FT_Open(0, &ftHandle);
|
||||
if (ftStatus != FT_OK) {
|
||||
printf("FT4222 장치 열기 실패\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
FT4222_STATUS ft4222Status = FT4222_I2CMaster_Init(ftHandle, 400); // 400kHz
|
||||
if (ft4222Status != FT4222_OK) {
|
||||
printf("I2C Master 초기화 실패\n");
|
||||
FT_Close(ftHandle);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Fault register data: 0x010 ~0x014, 0x019 ~0x021
|
||||
//0x010 - FUSA_STATUS_1
|
||||
//0x011 - FUSA_STATUS_2
|
||||
//0x012 - FUSA_STATUS_2A
|
||||
//0x013 - FUSA_STATUS_3
|
||||
//0x014 - FUSA_STATUS_4
|
||||
//0x019 - FLT_RECORD_A
|
||||
//0x01A - FLT_RECORD_B
|
||||
//0x01B - FLT_RECORD_GND_AVIN
|
||||
//0x01C - FLT_RECORD_BG_Temp
|
||||
//0x01D - FLT_RECORD_IntLDOs
|
||||
//0x01E - FLT_RECORD_ExtLDOs
|
||||
//0x01F - FLT_RECORD_BUCKS_B
|
||||
//0x020 - FLT_RECORD_BUCKS_A
|
||||
//0x021 - FLT_RECORD_ExtINPs_7_0
|
||||
|
||||
//printf("=================================================================================\n");
|
||||
/********************************************************************************************
|
||||
I2C Write
|
||||
PMIC_I2C_Write(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr, uint8_t value)
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0xAA, 0xBB);
|
||||
********************************************************************************************/
|
||||
//printf("=================================================================================\n");
|
||||
/********************************************************************************************
|
||||
I2C Read
|
||||
PMIC_I2C_Read(FT_HANDLE ftHandle, uint8_t slaveAddr, uint8_t regAddr)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0xAA);
|
||||
********************************************************************************************/
|
||||
|
||||
|
||||
|
||||
//for (int i = 0; i < 10000000; i++) {
|
||||
//while (1) {
|
||||
//}
|
||||
|
||||
//for (int i = 0; i < 10000000; i++) {
|
||||
//while (log_counter < 10 ){
|
||||
|
||||
// 예: 10번 while에 한 번만 실행
|
||||
//if (log_counter % 10 == 0) {
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
printf("실행하려면 Enter 키를 누르세요...\n");
|
||||
getchar();
|
||||
|
||||
//Regulation Register
|
||||
// Page00
|
||||
PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x00);
|
||||
PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x00);
|
||||
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x00); //0x000 - IO_PAGE_REGU
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x01); //0x001 - IO_CHIPNAME_REGU
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x02); //0x002 - IO_CHIPVERSION_REGU
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x03); //0x003 - IO_DIEID3_REGU
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x04); //0x004
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x05); //0x005
|
||||
|
||||
//PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x02);
|
||||
//PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x02);
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x23);
|
||||
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
// Page02
|
||||
PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x02);
|
||||
PMIC_I2C_Write(ftHandle, 0x54, 0x00, 0x02);
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x20);
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x21);
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x22); //0x222 - I_OTP_VERSION
|
||||
PMIC_I2C_Read(ftHandle, 0x54, 0x23); //0x223 - I_OTP_INTERNALVERSION
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x24);
|
||||
//PMIC_I2C_Read(ftHandle, 0x54, 0x25);
|
||||
|
||||
// 30ms 딜레이
|
||||
//Sleep(30);
|
||||
|
||||
//Protection Register
|
||||
// Page01
|
||||
PMIC_I2C_Write(ftHandle, 0x55, 0x00, 0x01);
|
||||
PMIC_I2C_Write(ftHandle, 0x55, 0x00, 0x01);
|
||||
PMIC_I2C_Read(ftHandle, 0x55, 0x02); //0x102 - IO_MODECTRL Read시 디폴트 0x65
|
||||
PMIC_I2C_Write(ftHandle, 0x55, 0x02, 0x25); //0x102 - IO_MODECTRL
|
||||
|
||||
// 10s 딜레이
|
||||
Sleep(10000);
|
||||
|
||||
PMIC_I2C_Write(ftHandle, 0x55, 0x02, 0x65); //0x102 - IO_MODECTRL
|
||||
|
||||
//}
|
||||
//log_counter++;
|
||||
//}
|
||||
|
||||
#if 0
|
||||
//Protection Register
|
||||
//Regulation Register
|
||||
printf("[Page-0]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x00);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x00);
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00); //0x000 - IO_PAGE_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x01); //0x001 - IO_CHIPNAME_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x02); //0x002 - IO_CHIPVERSION_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x03); //0x003 - IO_DIEID3_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x04); //0x004 - IO_DIEID2_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x05); //0x005 - IO_DIEID1_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x06); //0x006 - IO_DIEID0_REGU
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x0A); //0x00A - OTP_VERSION_REGU
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x10); //0x010 - FUSA_STATUS_1
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x11); //0x011 - FUSA_STATUS_2
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x12); //0x012 - FUSA_STATUS_2A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x13); //0x013 - FUSA_STATUS_3
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x14); //0x014 - FUSA_STATUS_4
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x19); //0x019 - FLT_RECORD_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1A); //0x01A - FLT_RECORD_B
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1B); //0x01B - FLT_RECORD_GND_AVIN
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1C); //0x01C - FLT_RECORD_BG_Temp
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1D); //0x01D - FLT_RECORD_IntLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1E); //0x01E - FLT_RECORD_ExtLDOs
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x1F); //0x01F - FLT_RECORD_BUCKS_B
|
||||
|
||||
|
||||
printf("[Page-1]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x01);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x01);
|
||||
|
||||
|
||||
printf("[Page-2]=================================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x02);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x02);
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x20); //0x020 - FLT_RECORD_BUCKS_A
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x21); //0x021 - FLT_RECORD_ExtINPs_7_0
|
||||
|
||||
|
||||
printf("[PMIC_RAA271005_INIT]====================================================================\n");
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x01);
|
||||
PMIC_I2C_Write(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x00, 0x01);
|
||||
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x07); //0x107 - WDT_CFG0 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x08); //0x108 - WDT_CFG1 (OTP) //WDT_ULCNT, WDT_LLCNT
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x09); //0x109 - WDT_CFG2 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x16); //0x116 - FUSA_TIMER_1 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x17); //0x117 - FUSA_TIMER_2 (OTP)
|
||||
PMIC_I2C_Read(ftHandle, PMIC_I2C_SLAVE_ADDR, 0x2C); //0x12C - FLT_MASK_B (OTP)
|
||||
#endif
|
||||
char line[256];
|
||||
while (1) {
|
||||
printf("> ");
|
||||
if (!fgets(line, sizeof(line), stdin)) break;
|
||||
|
||||
line[strcspn(line, "\r\n")] = 0; // 개행 제거
|
||||
if (strcmp(line, "exit") == 0) break;
|
||||
if (strcmp(line, "e") == 0) break;
|
||||
if (strlen(line) == 0) continue;
|
||||
|
||||
char* context = NULL;
|
||||
char* token = strtok_s(line, " ", &context);
|
||||
if (!token) continue;
|
||||
|
||||
for (char* p = token; *p; p++) *p = toupper(*p);
|
||||
|
||||
int command = parseCommand(token);
|
||||
|
||||
if (command == 1) { // I2C_WRITE
|
||||
uint8_t bytes[256];
|
||||
int len = 0;
|
||||
|
||||
while ((token = strtok_s(NULL, " ", &context)) != NULL) {
|
||||
unsigned int val;
|
||||
if (sscanf_s(token, "%x", &val) == 1) {
|
||||
bytes[len++] = (uint8_t)val;
|
||||
}
|
||||
else {
|
||||
printf("잘못된 HEX 값: %s\n", token);
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
printf("전송할 데이터가 없습니다.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t addrWithRw = (I2C_SLAVE_ADDR << 1) | 0x00;
|
||||
uint8_t crc = calcCRC8(addrWithRw, bytes, len);
|
||||
bytes[len++] = crc;
|
||||
|
||||
uint16 transferred = 0;
|
||||
ft4222Status = FT4222_I2CMaster_Write(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
bytes,
|
||||
(uint16)len,
|
||||
&transferred);
|
||||
|
||||
if (ft4222Status != FT4222_OK) {
|
||||
printf("I2C Write 실패\n");
|
||||
}
|
||||
else {
|
||||
logPacket("I2C_WRITE", bytes, len, 1);
|
||||
}
|
||||
}
|
||||
else if (command == 2) { // I2C_READ
|
||||
uint8_t bytes[256];
|
||||
uint16 transferred = 0;
|
||||
FT4222_STATUS st;
|
||||
int len = 0;
|
||||
|
||||
while ((token = strtok_s(NULL, " ", &context)) != NULL) {
|
||||
unsigned int val;
|
||||
if (sscanf_s(token, "%x", &val) == 1) {
|
||||
bytes[len++] = (uint8_t)val;
|
||||
}
|
||||
else {
|
||||
printf("잘못된 HEX 값: %s\n", token);
|
||||
}
|
||||
}
|
||||
|
||||
if (len == 0) {
|
||||
printf("전송할 데이터가 없습니다.\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t addrWithRw = (I2C_SLAVE_ADDR << 1) | 0x00;
|
||||
uint8_t crc = calcCRC8(addrWithRw, bytes, len);
|
||||
bytes[len++] = crc;
|
||||
|
||||
st = FT4222_I2CMaster_Write(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
bytes,
|
||||
(uint16)len,
|
||||
&transferred);
|
||||
|
||||
if (st != FT4222_OK) {
|
||||
printf("Read용 Address Write 실패\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 🔹 Register Address에서 2바이트 Read (Value + CRC)
|
||||
uint8_t rx[2] = { 0 };
|
||||
st = FT4222_I2CMaster_Read(ftHandle,
|
||||
I2C_SLAVE_ADDR,
|
||||
rx,
|
||||
2,
|
||||
&transferred);
|
||||
|
||||
if (st != FT4222_OK) {
|
||||
printf("I2C Read 실패\n");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
printf("Read 결과: [Address = 0x%02X], [Value = 0x%02X], [CRC = 0x%02X]\n",
|
||||
bytes[0], rx[0], rx[1]);
|
||||
}
|
||||
}
|
||||
else {
|
||||
printf("첫 단어는 I2C_WRITE(w) 또는 I2C_READ(r) 여야 합니다.\n");
|
||||
}
|
||||
}
|
||||
|
||||
FT_Close(ftHandle);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user