diff --git a/examples/makefile b/examples/makefile index 085d41f99..6a6a9fe1b 100644 --- a/examples/makefile +++ b/examples/makefile @@ -3,7 +3,7 @@ include ../imports.mak SUBDIRS := \ custom_frequency_generator empty empty_c \ fft/split_radix_fft_4k_single_core fft/split_radix_fft_post_processing \ - LCD_interface logic_scope pru_emif pru_eqep pru_i2s spi_loopback \ + LCD_interface logic_scope pru_emif pru_eqep pru_i2c pru_i2s spi_loopback \ fir multicore_scheduler rpmsg_echo_linux # "make" or "make all" builds projects that match $(DEVICE) set in imports.mak diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/example.projectspec b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/example.projectspec new file mode 100644 index 000000000..bc4cac089 --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/example.projectspec @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/linker.cmd b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/linker.cmd new file mode 100644 index 000000000..13fdcb5e9 --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/linker.cmd @@ -0,0 +1,43 @@ +/* + * AM261x_PRU0.cmd + * + * Example Linker command file for linking assembly programs built with the TI-PRU-CGT + * on AM261x PRU0 cores + */ + +/* Specify the System Memory Map */ +MEMORY +{ + PAGE 0: + /* 16 KB PRU Instruction RAM */ + PRU_IMEM : org = 0x00000000 len = 0x00004000 + + PAGE 1: + /* Data RAMs */ + /* 8 KB PRU Data RAM 0 */ + PRU0_DMEM_0 : org = 0x00000000 len = 0x00002000 + /* 8 KB PRU Data RAM 1 */ + PRU1_DMEM_1 : org = 0x00002000 len = 0x00002000 + + PAGE 2: + /* C28 needs to be programmed to point to SHAREDMEM, default is 0 */ + /* 32 KB PRU Shared RAM */ + PRU_SHAREDMEM : org = 0x00010000 len = 0x00008000 +} + +/* Specify the sections allocation into memory */ +SECTIONS { + + .text > PRU_IMEM, PAGE 0 + .stack > PRU0_DMEM_0, PAGE 1 + .bss > PRU0_DMEM_0, PAGE 1 + .cio > PRU0_DMEM_0, PAGE 1 + .data > PRU0_DMEM_0, PAGE 1 + .switch > PRU0_DMEM_0, PAGE 1 + .sysmem > PRU0_DMEM_0, PAGE 1 + .cinit > PRU0_DMEM_0, PAGE 1 + .rodata > PRU0_DMEM_0, PAGE 1 + .rofardata > PRU0_DMEM_0, PAGE 1 + .farbss > PRU0_DMEM_0, PAGE 1 + .fardata > PRU0_DMEM_0, PAGE 1 +} diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/makefile b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/makefile new file mode 100644 index 000000000..00993d53b --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt/makefile @@ -0,0 +1,48 @@ +export OPEN_PRU_PATH?=$(abspath ../../../../../..) +include $(OPEN_PRU_PATH)/imports.mak + +# Define build outputs +OUTPUT_NAME := pru_i2c_am261x-lp_icss_m0_pru0_fw + +# MCU+ projects: rename & move hex array output +MCU_HEX_NAME := pru0_load_bin.h +HEX_ARRAY_PREFIX := PRU0Firmware +MCU_HEX_PATH := $(OPEN_PRU_PATH)/examples/pru_i2c/firmware/am261x-lp/$(MCU_HEX_NAME) + +# which directories to search for assembly & C source files? +FILES_PATH := .. ../../.. . + +# Linker command file +COMMAND_FILES := linker.cmd + +# Silicon version (3: PRUSS, PRU-ICSS; 4: PRU_ICSSG) +PRU_VERSION := 3 +EXPECTED_DEVICE := am261x + +# Default values are defined in pru_rules.mak: +# - include paths (INCLUDE) +# - compiler flags (CFLAGS) +# - linker flags (LFLAGS) + +# Optional: +# Pre-define here to override default value +# OPT_LEVEL, STACK_SIZE, HEAP_SIZE, or ENTRY_POINT + +# pru_rules.mak has shared settings for all PRU/RTU/TX_PRU core makefiles +include $(OPEN_PRU_PATH)/pru_rules.mak + +# Optional: +# Append values to INCLUDE, CFLAGS, or LFLAGS here. +# Values can be appended like this: +# INCLUDE += --include_path= + +# Defines (pass instance specific definitions to the program) +# see --define or -D in 'PRU Optimizing C/C++ Compiler User's Guide' +# For example, to define PRU0, ICSSG1, SOC_AM243X, and set _DEBUG_=1: +# -DPRU0 -DICSSG1 --define=SOC_AM243X -D_DEBUG_=1 +DFLAGS := -DPRU0 -DSLICE0 -DSOC_AM261X + +# Libraries +# see --library in 'PRU Optimizing C/C++ Compiler User's Guide' +LIBS := + diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/example.projectspec b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/example.projectspec new file mode 100644 index 000000000..afbcb22bd --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/example.projectspec @@ -0,0 +1,81 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/linker.cmd b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/linker.cmd new file mode 100644 index 000000000..2c780dcff --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/linker.cmd @@ -0,0 +1,43 @@ +/* + * AM261x_PRU1.cmd + * + * Example Linker command file for linking assembly programs built with the TI-PRU-CGT + * on AM261x PRU1 cores + */ + +/* Specify the System Memory Map */ +MEMORY +{ + PAGE 0: + /* 16 KB PRU Instruction RAM */ + PRU_IMEM : org = 0x00000000 len = 0x00004000 + + PAGE 1: + /* Data RAMs */ + /* 8 KB PRU Data RAM 0 */ + PRU0_DMEM_0 : org = 0x00000000 len = 0x00002000 + /* 8 KB PRU Data RAM 1 */ + PRU1_DMEM_1 : org = 0x00002000 len = 0x00002000 + + PAGE 2: + /* C28 needs to be programmed to point to SHAREDMEM, default is 0 */ + /* 32 KB PRU Shared RAM */ + PRU_SHAREDMEM : org = 0x00010000 len = 0x00008000 +} + +/* Specify the sections allocation into memory */ +SECTIONS { + + .text > PRU_IMEM, PAGE 0 + .stack > PRU1_DMEM_1, PAGE 1 + .bss > PRU1_DMEM_1, PAGE 1 + .cio > PRU1_DMEM_1, PAGE 1 + .data > PRU1_DMEM_1, PAGE 1 + .switch > PRU1_DMEM_1, PAGE 1 + .sysmem > PRU1_DMEM_1, PAGE 1 + .cinit > PRU1_DMEM_1, PAGE 1 + .rodata > PRU1_DMEM_1, PAGE 1 + .rofardata > PRU1_DMEM_1, PAGE 1 + .farbss > PRU1_DMEM_1, PAGE 1 + .fardata > PRU1_DMEM_1, PAGE 1 +} diff --git a/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/makefile b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/makefile new file mode 100644 index 000000000..35f940ca4 --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt/makefile @@ -0,0 +1,48 @@ +export OPEN_PRU_PATH?=$(abspath ../../../../../..) +include $(OPEN_PRU_PATH)/imports.mak + +# Define build outputs +OUTPUT_NAME := pru_i2c_am261x-lp_icss_m0_pru1_fw + +# MCU+ projects: rename & move hex array output +MCU_HEX_NAME := pru1_load_bin.h +HEX_ARRAY_PREFIX := PRU1Firmware +MCU_HEX_PATH := $(OPEN_PRU_PATH)/examples/pru_i2c/firmware/am261x-lp/$(MCU_HEX_NAME) + +# which directories to search for assembly & C source files? +FILES_PATH := .. ../../.. . + +# Linker command file +COMMAND_FILES := linker.cmd + +# Silicon version (3: PRUSS, PRU-ICSS; 4: PRU_ICSSG) +PRU_VERSION := 3 +EXPECTED_DEVICE := am261x + +# Default values are defined in pru_rules.mak: +# - include paths (INCLUDE) +# - compiler flags (CFLAGS) +# - linker flags (LFLAGS) + +# Optional: +# Pre-define here to override default value +# OPT_LEVEL, STACK_SIZE, HEAP_SIZE, or ENTRY_POINT + +# pru_rules.mak has shared settings for all PRU/RTU/TX_PRU core makefiles +include $(OPEN_PRU_PATH)/pru_rules.mak + +# Optional: +# Append values to INCLUDE, CFLAGS, or LFLAGS here. +# Values can be appended like this: +# INCLUDE += --include_path= + +# Defines (pass instance specific definitions to the program) +# see --define or -D in 'PRU Optimizing C/C++ Compiler User's Guide' +# For example, to define PRU0, ICSSG1, SOC_AM243X, and set _DEBUG_=1: +# -DPRU0 -DICSSG1 --define=SOC_AM243X -D_DEBUG_=1 +DFLAGS := -DPRU1 -DSLICE1 -DSOC_AM261X + +# Libraries +# see --library in 'PRU Optimizing C/C++ Compiler User's Guide' +LIBS := + diff --git a/examples/pru_i2c/firmware/am261x-lp/pru0_load_bin.h b/examples/pru_i2c/firmware/am261x-lp/pru0_load_bin.h new file mode 100644 index 000000000..8f08572f1 --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/pru0_load_bin.h @@ -0,0 +1,951 @@ +/* + * Copyright (C) 2026 Texas Instruments Incorporated + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +const uint32_t PRU0Firmware_0[] = { +0x2effbb80, +0x91342481, +0x13020101, +0x81342481, +0x2401008a, +0x240000ca, +0x2402008b, +0x240000cb, +0x2403008c, +0x240000cc, +0x2400818d, +0x240000cd, +0x240000ce, +0x2400008e, +0x240000cf, +0x2400008f, +0x240000d0, +0x24000090, +0x240000d1, +0x24000091, +0x240000d2, +0x24000092, +0x240000d3, +0x24000093, +0x24000000, +0x2f05138a, +0x2effbd80, +0x24000081, +0x010c8181, +0x90813896, +0x6900d607, +0x69039602, +0x2409c4d6, +0x69029602, +0x2402a8d6, +0x69019602, +0x240140d6, +0x91003a81, +0xd100e110, +0x91107a81, +0x24ffffc1, +0x24ffff81, +0x24ffffc2, +0x24ffff82, +0x81107a81, +0x91043a81, +0x1f00e1e1, +0x81043a81, +0x91743a81, +0x24ffff81, +0x81743a81, +0x91003a81, +0x1f00e1e1, +0x81003a81, +0x91107a94, +0x00d6f4f4, +0x0300f5f5, +0x81787a94, +0x91703a81, +0x1f01e1e1, +0x81703a81, +0x51039608, +0x5102961b, +0x5101962e, +0x24020085, +0x240040c6, +0x24000086, +0x80852086, +0x7f0000fc, +0x91743a81, +0xcf00e1ff, +0x91743a81, +0xd100e102, +0x21004500, +0x240000e1, +0x1f00e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81787a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85138a, +0x228d0083, +0x24000000, +0x2f05138a, +0x7f0000ed, +0x91743a81, +0xcf00e1ff, +0x91743a81, +0xd100e102, +0x21005900, +0x240000e1, +0x1f00e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81787a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85138a, +0x228d0083, +0x24000000, +0x2f05138a, +0x7f0000ed, +0x91743a81, +0xcf00e1ff, +0x91743a81, +0xd100e102, +0x21006d00, +0x240000e1, +0x1f00e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81787a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85138a, +0x228d0083, +0x24000000, +0x2f05138a, +0x7f0000ed, +0xf1a42a84, +0xc90fe402, +0x2400858d, +0x20830000, +0xf1082a84, +0x5100c408, +0x6911c403, +0x24008f8d, +0x20830000, +0x2400d48d, +0x24050c84, +0xe1080a84, +0x20830000, +0x20830000, +0xf1d82a8e, +0x2400006e, +0x2400938d, +0x20830000, +0xf1e40a6e, +0x2400968d, +0x20830000, +0x2450d0da, +0x2408109a, +0xf1003a97, +0x1c0efefe, +0x1c2efefe, +0x1e0ef7f7, +0x1e2ef7f7, +0xe1003a97, +0x2400a08d, +0x20830000, +0xf1940a50, +0x2400a38d, +0x20830000, +0xf1950a70, +0x2400a68d, +0x20830000, +0xf1a42a84, +0xc90ae403, +0x2400ae8d, +0x20830000, +0x2400d48d, +0x24050a84, +0xe1080a84, +0x20830000, +0xf1a42a84, +0xd108e403, +0x1d08f0f0, +0x2100b300, +0x1f08f0f0, +0x2400b58d, +0x20830000, +0xf1a42a84, +0xc900e403, +0x1f00f0f0, +0x2100ba00, +0x1d00f0f0, +0x2400bc8d, +0x20830000, +0xf1a42a84, +0xc901e403, +0x1f01f0f0, +0x2100c100, +0x1d01f0f0, +0x2400c38d, +0x20830000, +0xf1a42a84, +0xc904e403, +0x1f04f0f0, +0x2100c800, +0x1d04f0f0, +0x2400ca8d, +0x20830000, +0xf1a42a84, +0x1d06f0f0, +0xc906e402, +0x1f06f0f0, +0xf1e80ad2, +0x24000092, +0x2400ed8d, +0x24050084, +0xe1080a84, +0x20830000, +0x24000084, +0xe10a0a84, +0x24000085, +0x01088585, +0x006e8585, +0x24000104, +0x80851804, +0x2400dd8d, +0x20830000, +0x24020085, +0x240010c6, +0x24000086, +0x80852086, +0x2400e38d, +0x20830000, +0x24000085, +0x01088585, +0x006e8585, +0x90851804, +0x51000402, +0x2100eb00, +0x2400818d, +0x20830000, +0x2400dd8d, +0x20830000, +0x24000084, +0xe10a0a84, +0x24000085, +0x01088585, +0x006e8585, +0x24000104, +0x80851804, +0x2400f68d, +0x20830000, +0x24020085, +0x240010c6, +0x24000086, +0x80852086, +0x2400fc8d, +0x20830000, +0x24000085, +0x01088585, +0x006e8585, +0x90851804, +0x51000402, +0x21010400, +0x2401068d, +0x20830000, +0x2400f68d, +0x20830000, +0xf1082a84, +0x5100c402, +0x24010a8d, +0x20830000, +0xf1082a84, +0x6910c405, +0x2401128d, +0x24050084, +0xe1080a84, +0x20830000, +0x2401188d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x2400d48d, +0x20830000, +0xf1082a84, +0x6911c403, +0x2400818d, +0x20830000, +0x24011e8d, +0x20830000, +0xf1082a84, +0x6912c403, +0x24014e8d, +0x20830000, +0x2401248d, +0x20830000, +0xf1082a84, +0x6913c403, +0x2401478d, +0x20830000, +0x24012a8d, +0x20830000, +0xf1082a84, +0x491cc404, +0x6114c403, +0x2401558d, +0x20830000, +0x2401318d, +0x20830000, +0xf1082a84, +0x691dc403, +0x2403538d, +0x20830000, +0x2401378d, +0x20830000, +0xf1082a84, +0x691ec403, +0x2403668d, +0x20830000, +0x24013d8d, +0x20830000, +0xf1082a84, +0x691fc403, +0x2403808d, +0x20830000, +0x2401438d, +0x20830000, +0x2400ed8d, +0x24050c84, +0xe1080a84, +0x20830000, +0x1d02f0f0, +0x240000f3, +0x24000092, +0x2402008b, +0x24023991, +0x24019a8d, +0x20830000, +0x1f02f0f0, +0x240000f3, +0x24000092, +0x2402008b, +0x2402ba91, +0x24019a8d, +0x20830000, +0xf1082a84, +0xd108f040, +0x240000f3, +0x24000092, +0x2402008b, +0x1f047373, +0xf1e00a33, +0x1d02f0f0, +0x24023991, +0x5114c42e, +0xc906f002, +0x1f007373, +0x5116c424, +0x2401ffe5, +0xe1000533, +0x2401ff8b, +0x2400016f, +0x5115c41b, +0x2400026f, +0x5117c419, +0x2400036f, +0x5119c417, +0x511bc40b, +0x2400016f, +0x1f027373, +0x24000151, +0x5118c404, +0x24000251, +0x511ac402, +0x1f037373, +0xc900731d, +0x1f057373, +0x21019000, +0xf1980a84, +0x5100841b, +0x2400fd86, +0xc9007302, +0x2400fc86, +0x48868417, +0x2401fee5, +0xe1000533, +0xe1010504, +0x2401fe8b, +0x0102046f, +0xc900730f, +0x1f017373, +0x01016f6f, +0x21019000, +0x1f02f0f0, +0x2402ba91, +0x2400016f, +0xc9007308, +0x1f057373, +0x2400026f, +0x21019000, +0xc9003302, +0x1f02f0f0, +0x2400006f, +0x24031e91, +0x24019a8d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x24050b84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x2401a08d, +0x20830000, +0xd108f003, +0x24007f84, +0x2101a400, +0x2403ff84, +0xf1ac0acd, +0x1084cdcd, +0x2401a88d, +0x20830000, +0xd108f007, +0x0909cdcd, +0xc902f003, +0x1f08cdcd, +0x2101ae00, +0x1d08cdcd, +0x2101b600, +0x09016d6d, +0xc902f003, +0x1f006d6d, +0x2101b400, +0x1d006d6d, +0x11076d6d, +0x13f06d6d, +0x11000f0f, +0x11004f4f, +0x2401ba8d, +0x20830000, +0xd1047309, +0xf1980a84, +0x49ff8411, +0x61018410, +0x11ff046f, +0x11004f4f, +0xf04f0b2f, +0x2401d18d, +0x20830000, +0xd102f008, +0x51006f07, +0xc9017305, +0x05016f04, +0x68044f03, +0x1013132f, +0x2101cb00, +0xf04f0b2f, +0x2401d18d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd1047302, +0xc900f003, +0x1c2ef7f7, +0xe1003a97, +0x2401e08d, +0x20830000, +0x2401e28d, +0x20830000, +0xd1047302, +0xc900f003, +0x1c0ef7f7, +0xe1003a97, +0x2401e88d, +0x20830000, +0x0d0f0f05, +0xc805cd04, +0x1e2ef7f7, +0xe1003a97, +0x2101ef00, +0x1c2ef7f7, +0xe1003a97, +0xc9007307, +0x0b071306, +0xc805cd02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x01010f0f, +0x2401f98d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2401fd8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402088d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f05, +0x1e2ef7f7, +0xe1003a97, +0x2402118d, +0x20830000, +0x2401e88d, +0x20830000, +0x2402138d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x11000f0f, +0x2402188d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x1d03f0f0, +0x21022500, +0x1f03f0f0, +0x2402278d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0xd103f009, +0xc908f005, +0x51014f04, +0x01014f4f, +0x2401e88d, +0x20830000, +0x11004f4f, +0x1091918d, +0x20830000, +0x2402348d, +0x20830000, +0x24050884, +0xe1080a84, +0x1f067373, +0x24031e8d, +0x20830000, +0xc9072f04, +0x1e2ef7f7, +0xe1003a97, +0x21023f00, +0x1c2ef7f7, +0xe1003a97, +0xc9007307, +0x0b071306, +0xc9072f02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x09012f2f, +0x01010f0f, +0x24024a8d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24024e8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402598d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f05, +0x1e2ef7f7, +0xe1003a97, +0x2402628d, +0x20830000, +0x2402398d, +0x20830000, +0x2402648d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2402688d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x1d03f0f0, +0x21027500, +0x1f03f0f0, +0x2402778d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0xd103f00f, +0x01014f4f, +0x2400000f, +0x606f4f04, +0x2400004f, +0x24028c8d, +0x20830000, +0xc9017305, +0x05016f04, +0x68044f03, +0x1013132f, +0x21028600, +0xf04f0b2f, +0x2402398d, +0x20830000, +0x24050984, +0xe1080a84, +0x2402918d, +0x20830000, +0xd1027303, +0x24031e8d, +0x20830000, +0x2402948d, +0x20830000, +0x1f067373, +0x24031e8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402988d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24029c8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402a78d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0x1d027373, +0x1f02f0f0, +0x1f08cdcd, +0x2400008f, +0x1051516f, +0xc9057302, +0x01016f6f, +0x2400004f, +0x2402ba91, +0x2402b48d, +0x20830000, +0x2402b68d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2401e88d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402be8d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x09012f2f, +0x2402c38d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x11fe2f2f, +0x2102d000, +0x13012f2f, +0xc9007307, +0x0b071306, +0xc9002f02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x01010f0f, +0x2402da8d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f1b, +0xc9037312, +0x1d037373, +0x51002f0a, +0x102f2f6f, +0xc9057303, +0x51ff2f07, +0x01016f6f, +0x24000084, +0x102f2f04, +0xe1980a84, +0x2402f98d, +0x20830000, +0x24050d84, +0xe1080a84, +0x1f067373, +0x240101cf, +0x2402fd8d, +0x20830000, +0x01014f4f, +0x606f4f05, +0xd1047302, +0xc904f003, +0x2402fd8d, +0x20830000, +0x2402f98d, +0x20830000, +0x2402bc8d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0x2403018d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2403018d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2403058d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2403108d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2400000f, +0x51004f07, +0x05014f04, +0xe0040c2f, +0x606f4f04, +0x2400004f, +0x24031e8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402bc8d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0xd1047303, +0xd1067302, +0xc901f003, +0x2403278d, +0x20830000, +0x2403408d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24032b8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2403368d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2400ed8d, +0xd1067306, +0x24050084, +0xc9057303, +0x51001302, +0x24050f84, +0xe1080a84, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2403448d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24050084, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x24000092, +0x24050e84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x2400008f, +0x240a00cf, +0x2403578d, +0x20830000, +0x01010f0f, +0xd00eff02, +0x01014f4f, +0x606f0f02, +0x24035d8d, +0x20830000, +0x2400ed8d, +0x504f0f03, +0x24050584, +0x21036200, +0x24050684, +0x2400008f, +0x240000cf, +0xe1080a84, +0x20830000, +0x2400008f, +0x240900cf, +0x1e2ef7f7, +0xe1003a97, +0x2403738d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x01010f0f, +0x2403778d, +0x20830000, +0x24036c8d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2403718d, +0x20830000, +0x606f0f03, +0x24037c8d, +0x20830000, +0x2403738d, +0x20830000, +0x2400ed8d, +0x24050784, +0xe1080a84, +0x20830000, +0xf1980a84, +0x49ff8406, +0x61018405, +0x11ff046f, +0x11004f4f, +0x24038b8d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0xf04f0b2f, +0xe04f0c2f, +0x01014f4f, +0x704f6f02, +0x20830000, +0x2400ed8d, +0x24050084, +0xe1080a84, +0x20830000, +0x2a000000}; + diff --git a/examples/pru_i2c/firmware/am261x-lp/pru1_load_bin.h b/examples/pru_i2c/firmware/am261x-lp/pru1_load_bin.h new file mode 100644 index 000000000..3798b4de0 --- /dev/null +++ b/examples/pru_i2c/firmware/am261x-lp/pru1_load_bin.h @@ -0,0 +1,951 @@ +/* + * Copyright (C) 2026 Texas Instruments Incorporated + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +const uint32_t PRU1Firmware_0[] = { +0x2effbb80, +0x91342481, +0x13020101, +0x81342481, +0x2401008a, +0x240000ca, +0x2402008b, +0x240000cb, +0x2403008c, +0x240000cc, +0x2400818d, +0x240000cd, +0x240000ce, +0x2400008e, +0x240000cf, +0x2400008f, +0x240000d0, +0x24000090, +0x240000d1, +0x24000091, +0x240000d2, +0x24000092, +0x240000d3, +0x24000093, +0x24000000, +0x2f05938a, +0x2effbd80, +0x24000081, +0x010c8181, +0x90813996, +0x6900d607, +0x69039602, +0x2409c4d6, +0x69029602, +0x2402a8d6, +0x69019602, +0x240140d6, +0x91003a81, +0xd100e110, +0x91107a81, +0x24ffffc1, +0x24ffff81, +0x24ffffc2, +0x24ffff82, +0x81107a81, +0x91043a81, +0x1f00e1e1, +0x81043a81, +0x91743a81, +0x24ffff81, +0x81743a81, +0x91003a81, +0x1f00e1e1, +0x81003a81, +0x91107a94, +0x00d6f4f4, +0x0300f5f5, +0x81807a94, +0x91703a81, +0x1f02e1e1, +0x81703a81, +0x51039608, +0x5102961b, +0x5101962e, +0x24020085, +0x240040c6, +0x24000086, +0x80852086, +0x7f0000fc, +0x91743a81, +0xcf01e1ff, +0x91743a81, +0xd101e102, +0x21004500, +0x240000e1, +0x1f01e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81807a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85938a, +0x228d0083, +0x24000000, +0x2f05938a, +0x7f0000ed, +0x91743a81, +0xcf01e1ff, +0x91743a81, +0xd101e102, +0x21005900, +0x240000e1, +0x1f01e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81807a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85938a, +0x228d0083, +0x24000000, +0x2f05938a, +0x7f0000ed, +0x91743a81, +0xcf01e1ff, +0x91743a81, +0xd101e102, +0x21006d00, +0x240000e1, +0x1f01e1e1, +0x81743a81, +0x00d6f4f4, +0x0300f5f5, +0x81807a94, +0x24008081, +0x24028082, +0x80822081, +0x24000000, +0x2e85938a, +0x228d0083, +0x24000000, +0x2f05938a, +0x7f0000ed, +0xf1a42a84, +0xc90fe402, +0x2400858d, +0x20830000, +0xf1082a84, +0x5100c408, +0x6911c403, +0x24008f8d, +0x20830000, +0x2400d48d, +0x24050c84, +0xe1080a84, +0x20830000, +0x20830000, +0xf1d82a8e, +0x2400006e, +0x2400938d, +0x20830000, +0xf1e40a6e, +0x2400968d, +0x20830000, +0x2450d0da, +0x2408149a, +0xf1003a97, +0x1c0efefe, +0x1c2efefe, +0x1e0ef7f7, +0x1e2ef7f7, +0xe1003a97, +0x2400a08d, +0x20830000, +0xf1940a50, +0x2400a38d, +0x20830000, +0xf1950a70, +0x2400a68d, +0x20830000, +0xf1a42a84, +0xc90ae403, +0x2400ae8d, +0x20830000, +0x2400d48d, +0x24050a84, +0xe1080a84, +0x20830000, +0xf1a42a84, +0xd108e403, +0x1d08f0f0, +0x2100b300, +0x1f08f0f0, +0x2400b58d, +0x20830000, +0xf1a42a84, +0xc900e403, +0x1f00f0f0, +0x2100ba00, +0x1d00f0f0, +0x2400bc8d, +0x20830000, +0xf1a42a84, +0xc901e403, +0x1f01f0f0, +0x2100c100, +0x1d01f0f0, +0x2400c38d, +0x20830000, +0xf1a42a84, +0xc904e403, +0x1f04f0f0, +0x2100c800, +0x1d04f0f0, +0x2400ca8d, +0x20830000, +0xf1a42a84, +0x1d06f0f0, +0xc906e402, +0x1f06f0f0, +0xf1e80ad2, +0x24000092, +0x2400ed8d, +0x24050084, +0xe1080a84, +0x20830000, +0x24000084, +0xe10a0a84, +0x24000085, +0x01088585, +0x006e8585, +0x24000104, +0x80851904, +0x2400dd8d, +0x20830000, +0x24020085, +0x240020c6, +0x24000086, +0x80852086, +0x2400e38d, +0x20830000, +0x24000085, +0x01088585, +0x006e8585, +0x90851904, +0x51000402, +0x2100eb00, +0x2400818d, +0x20830000, +0x2400dd8d, +0x20830000, +0x24000084, +0xe10a0a84, +0x24000085, +0x01088585, +0x006e8585, +0x24000104, +0x80851904, +0x2400f68d, +0x20830000, +0x24020085, +0x240020c6, +0x24000086, +0x80852086, +0x2400fc8d, +0x20830000, +0x24000085, +0x01088585, +0x006e8585, +0x90851904, +0x51000402, +0x21010400, +0x2401068d, +0x20830000, +0x2400f68d, +0x20830000, +0xf1082a84, +0x5100c402, +0x24010a8d, +0x20830000, +0xf1082a84, +0x6910c405, +0x2401128d, +0x24050084, +0xe1080a84, +0x20830000, +0x2401188d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x2400d48d, +0x20830000, +0xf1082a84, +0x6911c403, +0x2400818d, +0x20830000, +0x24011e8d, +0x20830000, +0xf1082a84, +0x6912c403, +0x24014e8d, +0x20830000, +0x2401248d, +0x20830000, +0xf1082a84, +0x6913c403, +0x2401478d, +0x20830000, +0x24012a8d, +0x20830000, +0xf1082a84, +0x491cc404, +0x6114c403, +0x2401558d, +0x20830000, +0x2401318d, +0x20830000, +0xf1082a84, +0x691dc403, +0x2403538d, +0x20830000, +0x2401378d, +0x20830000, +0xf1082a84, +0x691ec403, +0x2403668d, +0x20830000, +0x24013d8d, +0x20830000, +0xf1082a84, +0x691fc403, +0x2403808d, +0x20830000, +0x2401438d, +0x20830000, +0x2400ed8d, +0x24050c84, +0xe1080a84, +0x20830000, +0x1d02f0f0, +0x240000f3, +0x24000092, +0x2402008b, +0x24023991, +0x24019a8d, +0x20830000, +0x1f02f0f0, +0x240000f3, +0x24000092, +0x2402008b, +0x2402ba91, +0x24019a8d, +0x20830000, +0xf1082a84, +0xd108f040, +0x240000f3, +0x24000092, +0x2402008b, +0x1f047373, +0xf1e00a33, +0x1d02f0f0, +0x24023991, +0x5114c42e, +0xc906f002, +0x1f007373, +0x5116c424, +0x2401ffe5, +0xe1000533, +0x2401ff8b, +0x2400016f, +0x5115c41b, +0x2400026f, +0x5117c419, +0x2400036f, +0x5119c417, +0x511bc40b, +0x2400016f, +0x1f027373, +0x24000151, +0x5118c404, +0x24000251, +0x511ac402, +0x1f037373, +0xc900731d, +0x1f057373, +0x21019000, +0xf1980a84, +0x5100841b, +0x2400fd86, +0xc9007302, +0x2400fc86, +0x48868417, +0x2401fee5, +0xe1000533, +0xe1010504, +0x2401fe8b, +0x0102046f, +0xc900730f, +0x1f017373, +0x01016f6f, +0x21019000, +0x1f02f0f0, +0x2402ba91, +0x2400016f, +0xc9007308, +0x1f057373, +0x2400026f, +0x21019000, +0xc9003302, +0x1f02f0f0, +0x2400006f, +0x24031e91, +0x24019a8d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x24050b84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x2401a08d, +0x20830000, +0xd108f003, +0x24007f84, +0x2101a400, +0x2403ff84, +0xf1ac0acd, +0x1084cdcd, +0x2401a88d, +0x20830000, +0xd108f007, +0x0909cdcd, +0xc902f003, +0x1f08cdcd, +0x2101ae00, +0x1d08cdcd, +0x2101b600, +0x09016d6d, +0xc902f003, +0x1f006d6d, +0x2101b400, +0x1d006d6d, +0x11076d6d, +0x13f06d6d, +0x11000f0f, +0x11004f4f, +0x2401ba8d, +0x20830000, +0xd1047309, +0xf1980a84, +0x49ff8411, +0x61018410, +0x11ff046f, +0x11004f4f, +0xf04f0b2f, +0x2401d18d, +0x20830000, +0xd102f008, +0x51006f07, +0xc9017305, +0x05016f04, +0x68044f03, +0x1013132f, +0x2101cb00, +0xf04f0b2f, +0x2401d18d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd1047302, +0xc900f003, +0x1c2ef7f7, +0xe1003a97, +0x2401e08d, +0x20830000, +0x2401e28d, +0x20830000, +0xd1047302, +0xc900f003, +0x1c0ef7f7, +0xe1003a97, +0x2401e88d, +0x20830000, +0x0d0f0f05, +0xc805cd04, +0x1e2ef7f7, +0xe1003a97, +0x2101ef00, +0x1c2ef7f7, +0xe1003a97, +0xc9007307, +0x0b071306, +0xc805cd02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x01010f0f, +0x2401f98d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2401fd8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402088d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f05, +0x1e2ef7f7, +0xe1003a97, +0x2402118d, +0x20830000, +0x2401e88d, +0x20830000, +0x2402138d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x11000f0f, +0x2402188d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x1d03f0f0, +0x21022500, +0x1f03f0f0, +0x2402278d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0xd103f009, +0xc908f005, +0x51014f04, +0x01014f4f, +0x2401e88d, +0x20830000, +0x11004f4f, +0x1091918d, +0x20830000, +0x2402348d, +0x20830000, +0x24050884, +0xe1080a84, +0x1f067373, +0x24031e8d, +0x20830000, +0xc9072f04, +0x1e2ef7f7, +0xe1003a97, +0x21023f00, +0x1c2ef7f7, +0xe1003a97, +0xc9007307, +0x0b071306, +0xc9072f02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x09012f2f, +0x01010f0f, +0x24024a8d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24024e8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402598d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f05, +0x1e2ef7f7, +0xe1003a97, +0x2402628d, +0x20830000, +0x2402398d, +0x20830000, +0x2402648d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2402688d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x1d03f0f0, +0x21027500, +0x1f03f0f0, +0x2402778d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0xd103f00f, +0x01014f4f, +0x2400000f, +0x606f4f04, +0x2400004f, +0x24028c8d, +0x20830000, +0xc9017305, +0x05016f04, +0x68044f03, +0x1013132f, +0x21028600, +0xf04f0b2f, +0x2402398d, +0x20830000, +0x24050984, +0xe1080a84, +0x2402918d, +0x20830000, +0xd1027303, +0x24031e8d, +0x20830000, +0x2402948d, +0x20830000, +0x1f067373, +0x24031e8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402988d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24029c8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2402a78d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0x1d027373, +0x1f02f0f0, +0x1f08cdcd, +0x2400008f, +0x1051516f, +0xc9057302, +0x01016f6f, +0x2400004f, +0x2402ba91, +0x2402b48d, +0x20830000, +0x2402b68d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2401e88d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402be8d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x09012f2f, +0x2402c38d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0xd02eff03, +0x11fe2f2f, +0x2102d000, +0x13012f2f, +0xc9007307, +0x0b071306, +0xc9002f02, +0x15010606, +0x09011313, +0x51000602, +0x15071313, +0x01010f0f, +0x2402da8d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x61080f1b, +0xc9037312, +0x1d037373, +0x51002f0a, +0x102f2f6f, +0xc9057303, +0x51ff2f07, +0x01016f6f, +0x24000084, +0x102f2f04, +0xe1980a84, +0x2402f98d, +0x20830000, +0x24050d84, +0xe1080a84, +0x1f067373, +0x240101cf, +0x2402fd8d, +0x20830000, +0x01014f4f, +0x606f4f05, +0xd1047302, +0xc904f003, +0x2402fd8d, +0x20830000, +0x2402f98d, +0x20830000, +0x2402bc8d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0x2403018d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2403018d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x2403058d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2403108d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2400000f, +0x51004f07, +0x05014f04, +0xe0040c2f, +0x606f4f04, +0x2400004f, +0x24031e8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2402bc8d, +0x20830000, +0x1c2ef7f7, +0xe1003a97, +0xd1047303, +0xd1067302, +0xc901f003, +0x2403278d, +0x20830000, +0x2403408d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24032b8d, +0x20830000, +0xd00eff06, +0x01019292, +0x5100d203, +0x4892d202, +0x24034a8d, +0x20830000, +0x51009203, +0x24000092, +0x20830000, +0x2403368d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2400ed8d, +0xd1067306, +0x24050084, +0xc9057303, +0x51001302, +0x24050f84, +0xe1080a84, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x2403448d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x24050084, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x1e2ef7f7, +0xe1003a97, +0x1e0ef7f7, +0xe1003a97, +0x24000092, +0x24050e84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0x2400008f, +0x240a00cf, +0x2403578d, +0x20830000, +0x01010f0f, +0xd00eff02, +0x01014f4f, +0x606f0f02, +0x24035d8d, +0x20830000, +0x2400ed8d, +0x504f0f03, +0x24050584, +0x21036200, +0x24050684, +0x2400008f, +0x240000cf, +0xe1080a84, +0x20830000, +0x2400008f, +0x240900cf, +0x1e2ef7f7, +0xe1003a97, +0x2403738d, +0x20830000, +0x1e0ef7f7, +0xe1003a97, +0x01010f0f, +0x2403778d, +0x20830000, +0x24036c8d, +0x20830000, +0x1c0ef7f7, +0xe1003a97, +0x2403718d, +0x20830000, +0x606f0f03, +0x24037c8d, +0x20830000, +0x2403738d, +0x20830000, +0x2400ed8d, +0x24050784, +0xe1080a84, +0x20830000, +0xf1980a84, +0x49ff8406, +0x61018405, +0x11ff046f, +0x11004f4f, +0x24038b8d, +0x20830000, +0x24050d84, +0xe1080a84, +0x2400ed8d, +0x20830000, +0xf04f0b2f, +0xe04f0c2f, +0x01014f4f, +0x704f6f02, +0x20830000, +0x2400ed8d, +0x24050084, +0xe1080a84, +0x20830000, +0x2a000000}; + diff --git a/examples/pru_i2c/firmware/pru_i2c_firmware_version.h b/examples/pru_i2c/firmware/pru_i2c_firmware_version.h new file mode 100644 index 000000000..652ff8867 --- /dev/null +++ b/examples/pru_i2c/firmware/pru_i2c_firmware_version.h @@ -0,0 +1,54 @@ +; Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/ +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; +; Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the +; distribution. +; +; Neither the name of Texas Instruments Incorporated nor the names of +; its contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +;************************************************************************************ +; File: pru_i2c_firmware_version.h +; +; Brief: ICSS I2C Firmware version control file +;************************************************************************************ + + .if !$defined("__firmware_version_h") +__firmware_version_h .set 1 + +; bit31 release or internal version +FIRMWARE_VERSION_INTERNAL .set 1 +FIRMWARE_VERSION_RELEASE .set 1 +; bit30..24 major version number ;For major IP changes. +FIRMWARE_VERSION_MAJOR .set 0x00 +; bit23..16 minor version number ;For feature additions to firmware. +FIRMWARE_VERSION_MINOR .set 0x00 +; bit15..0 build number ;For all other minor changes. +FIRMWARE_VERSION_BUILD .set 0x00 + +; macro for indicating version of firmware +I2C_FIRMWARE_VERSION .set ((FIRMWARE_VERSION_RELEASE << 31) | (FIRMWARE_VERSION_MAJOR << 24) | (FIRMWARE_VERSION_MINOR << 16) | (FIRMWARE_VERSION_BUILD << 0)) + + + .endif ;__firmware_version_h \ No newline at end of file diff --git a/examples/pru_i2c/firmware/pru_i2c_interface.h b/examples/pru_i2c/firmware/pru_i2c_interface.h new file mode 100644 index 000000000..4ffe83587 --- /dev/null +++ b/examples/pru_i2c/firmware/pru_i2c_interface.h @@ -0,0 +1,236 @@ +/* Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/ +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions +* are met: +* +* Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the +* distribution. +* +* Neither the name of Texas Instruments Incorporated nor the names of +* its contributors may be used to endorse or promote products derived +* from this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +************************************************************************************* +* File: pru_i2c_interface.h +* +* Brief: This is a common header file with all memory map configuration. +************************************************************************************* +*/ +#ifndef ICSS_I2C_H +#define ICSS_I2C_H + +#define PRUICSS_MAX_INSTANCE (2U) + +typedef enum PRUICSS_PruCores_e +{ + PRUICCSS_PRU0, + PRUICCSS_PRU1 +}PRUICSS_PruCores; + +/* The Memory Size of I2C Instance */ +#define ICSS_I2C_INSTANCE_SIZE (0x0300) +/* The Memory offset of I2C Tx Buffer */ +#define ICSS_I2C_INSTANCE_TX_OFFSET (0x0100) +/* The Memory offset of I2C Rx Buffer */ +#define ICSS_I2C_INSTANCE_RX_OFFSET (0x0200) + +#define ICSS_I2C_CONFIG_MEMORY (0x0000) + +/* The Memory region of I2C INSTANCE0 MMap */ +#define ICSS_I2C_INSTANCE0_ADDR (ICSS_I2C_CONFIG_MEMORY + 0x100 ) + +/* The Memory region of I2C INSTANCE0 Tx buffer */ +#define ICSS_I2C_INSTANCE0_TX_MEM (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_INSTANCE_TX_OFFSET) + +/* The Memory region of I2C INSTANCE0 Rx buffer */ +#define ICSS_I2C_INSTANCE0_RX_MEM (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_INSTANCE_RX_OFFSET) + +/* The Memory offset of I2C Revision Register low value */ +#define ICSS_I2C_REVNB_LO_OFFSET (0x00) +/* The Memory offset of I2C Revision Register high value */ +#define ICSS_I2C_REVNB_HI_OFFSET (0x04) +/* The Memory offset of I2C command value register */ +#define ICSS_I2C_COMMAND_OFFSET (0x08) +/* The Memory offset of I2C IRQ status register */ +#define ICSS_I2C_IRQSTATUS_OFFSET (0x28) +/* The Memory offset of I2C Fifo size register */ +#define ICSS_I2C_BUF_OFFSET (0x94) +/* The Memory offset of I2C data count register */ +#define ICSS_I2C_CNT_OFFSET (0x98) +/* The Memory offset of I2C configuration register */ +#define ICSS_I2C_CON_OFFSET (0xA4) +/* The Memory offset of I2C slave address register */ +#define ICSS_I2C_SA_OFFSET (0xAC) +/* The Memory offset of I2C input output pin value */ +#define ICSS_I2C_PRU_PIN_OFFSET (0xD8) +/* The Memory offset of I2C clock value register */ +#define ICSS_I2C_PRU_CLK_VAL_OFFSET (0xDC) +/* The Memory offset of I2C smbus command code register (u8). For + * ICSS_SMBUS_QUICK_CMD, bit 0 is the R/W bit sent with the address. */ +#define ICSS_I2C_PRU_CMD_CODE_OFFSET (0xE0) +/* The Memory offset of I2C instance id register */ +#define ICSS_I2C_PRU_INST_ID_OFFSET (0xE4) +/* The Memory offset of the SCL low timeout (u16): number of state machine + * ticks (4 per SCL period) a target may hold SCL low (clock stretching) + * before the transfer ends with TIME_OUT_ERROR. 0 = wait indefinitely. + * SMBus requires 25 ms (tTIMEOUT,MIN). Latched by ICSS_I2C_SETUP_CMD. */ +#define ICSS_I2C_SCL_TIMEOUT_OFFSET (0xE8) +/* Instance offsets 0xFE and 0xFF are used by the firmware to stage the + * SMBus command code and block count in front of the Tx buffer. */ + +/* The register bit for enabling i2c instance */ +#define ICSS_I2C_MODULE_ENABLE_BIT (15) +/* The register bit for selecting master or slave */ +#define ICSS_I2C_MASTER_SLAVE_MODE_BIT (10) +/* The register bit for selecting address mode */ +#define ICSS_I2C_ADDRESSING_MODE_BIT (8) +/* Reserved (was: SMBus burst mode, never implemented) */ +#define ICSS_I2C_SMBUS_BURST_BIT (5) +/* The register bit for enabling SMBus Packet Error Checking (CRC-8) */ +#define ICSS_I2C_PEC_BIT (6) +/* The register bit for deciding NACK recieve */ +#define ICSS_I2C_RECIEVE_NACK_BIT (4) +/* The register bit for deciding ACK recieve */ +#define ICSS_I2C_ACK_RECIEVED_BIT (3) +/* The register bit for selecting between read/write */ +#define ICSS_I2C_READ_WRITE_BIT (2) +/* The register bit for enabling start bit */ +#define ICSS_I2C_START_BIT (0) +/* The register bit for enabling stop bit */ +#define ICSS_I2C_STOP_BIT (1) + +/* The command value for resetting I2C instance */ +#define ICSS_I2C_RESET_CMD (0x10U) +/* The command value for setting up I2C instance */ +#define ICSS_I2C_SETUP_CMD (0x11U) +/* The command value for start Rx for I2C instance */ +#define ICSS_I2C_RX_CMD (0x12U) +/* The command value for start Tx for I2C instance */ +#define ICSS_I2C_TX_CMD (0x13U) +/* The command value for start quick cmd for I2C instance */ +#define ICSS_SMBUS_QUICK_CMD (0x14U) +/* The command value for start send byte cmd for I2C instance */ +#define ICSS_SMBUS_SEND_BYTE_CMD (0x15U) +/* The command value for start recieve byte cmd for I2C instance */ +#define ICSS_SMBUS_RECEIVE_BYTE_CMD (0x16U) +/* The command value for start write byte cmd for I2C instance */ +#define ICSS_SMBUS_WRITE_BYTE_CMD (0x17U) +/* The command value for start read byte cmd for I2C instance */ +#define ICSS_SMBUS_READ_BYTE_CMD (0x18U) +/* The command value for start write word cmd for I2C instance */ +#define ICSS_SMBUS_WRITE_WORD_CMD (0x19U) +/* The command value for start read word for I2C instance */ +#define ICSS_SMBUS_READ_WORD_CMD (0x1AU) +/* The command value for start block write for I2C instance */ +#define ICSS_SMBUS_BLOCK_WRITE_CMD (0x1BU) +/* The command value for start block read for I2C instance */ +#define ICSS_SMBUS_BLOCK_READ_CMD (0x1CU) +/* The command value for start read scl cmd for I2C instance */ +#define ICSS_I2C_READ_SCL_CMD (0x1DU) +/* The command value for start reset slave cmd for I2C instance */ +#define ICSS_I2C_RESET_SLAVE_CMD (0x1EU) +/* The command value for loopback mode */ +#define ICSS_I2C_LOOPBACK_CMD (0x1FU) + +/* The response for command successful */ +#define COMMAND_SUCCESS (0x0500U) +/* The response for reset command failure */ +#define RESET_COMMAND_FAILED (0x0501U) +/* The response for setup command failure */ +#define SETUP_COMMAND_FAILED (0x0502U) +/* The response for tx command failure */ +#define TX_COMMAND_FAILED (0x0503U) +/* The response for rx command failure */ +#define RX_COMMAND_FAILED (0x0504U) +/* The response for if SCL value high */ +#define SCL_VALUE_HIGH (0x0505U) +/* The response for if SCL value low */ +#define SCL_VALUE_LOW (0x0506U) +/* The response for sucessfull reset command */ +#define RESET_SLAVE_DONE (0x0507U) +/* The response for NACK for address transmission */ +#define ADDRESS_ACKNOWLDEGE_FAILED (0x0508U) +/* The response for NACK for data transmission */ +#define DATA_ACKNOWLDEGE_FAILED (0x0509U) +/* The response for wrong master slave configuration */ +#define MASTER_SLAVE_MODE_FAILED (0x050AU) +/* The response for wrong addressing mode configuration */ +#define ADDRESSING_MODE_FAILED (0x050BU) +/* The response for invalid command passed configuration */ +#define INVALID_COMMAND (0x050CU) +/* The response for incorrect data count configuration */ +#define INVALID_DATA_COUNT (0x050DU) +/* The time out for the response to come */ +#define TIME_OUT_ERROR (0x050EU) +/* The response for an SMBus read whose PEC byte did not match */ +#define PEC_ERROR (0x050FU) + + +/* The iep counter increment value for 400KHz value */ +// The IEP counts DEFAULT_INC = 5 per 200 MHz clock, so every increment +// must be a multiple of 5 to land exactly on a counter value. +// A bit is 4 ticks with SCL low for 2 of them. Fast-mode needs +// tLOW >= 1.3 us, and the SCL edges move by a few cycles with the work +// done in each state, so the tick is 0.68 us: time-slice 136 (680/5) +// cycles, giving tLOW >= 1.33 us. +// => bus clock time is 136*4/200e6 = 2.72 usec. +// => bus clock speed is 1/2.72e-6 = 367.6 kHz (400 kHz with 1.25 us +// tLOW would be out of spec) +#define IEP_CMP_INCREMENT_VAL_400KHZ (0x000002A8U) // 367.6 kHz +#define IEP_CMP_INCREMENT_HALF_VAL_400KHZ (0x00000138U) + +/* The iep counter increment value for 100KHz value */ +// 4 I2C instances, time-slice 125 (625/5) cycles. +// => bus clock time is 125*4*4/200e6 = 10 usec. +// => bus clock speed is 1/10e-6 = 100 kHz +#define IEP_CMP_INCREMENT_VAL_100KHZ (0x000009C4U) // 100 kHz, 1x instances +#define IEP_CMP_INCREMENT_HALF_VAL_100KHZ (0x000004e1U) // + +// 1 I2C instance, time-slice 64 (320/5) cycles. +// => bus clock time is 64*4/200e6 = 1.28 usec. +// => bus clock speed is 1/1.28e-6 = 781.25 kHz +#define IEP_CMP_INCREMENT_VAL_1MHZ (0x00000140U) // 781.25 kHz, 1x instance +#define IEP_CMP_INCREMENT_HALF_VAL_1MHZ (0x000000A0U) + +/* The register offset of IRQ status for host to read. One u8 flag per + * instance at IRQ_COMMON_REGISTER_OFFSET + instance id (0..3): the PRU sets + * it to 1 when a response is ready and the host writes 0 to acknowledge it. + * Each side only writes the byte of its own instance, so no read-modify-write + * is needed. */ +#define IRQ_COMMON_REGISTER_OFFSET (0x0008U) +/* The register offset of global frequency set */ +#define I2C_BUS_FREQUENCY_OFFSET (0x000CU) + +/* The frequency configuration for I2C FW */ +#define ICSS_I2C_NO_FREQ (0x00U) +/* The frequency configuration for I2C FW @ 1MHZ */ +#define ICSS_I2C_1MHZ_FREQ (0x01U) +/* The frequency configuration for I2C FW @ 400KHZ */ +#define ICSS_I2C_400KHZ_FREQ (0x02U) +/* The frequency configuration for I2C FW @ 100KHZ */ +#define ICSS_I2C_100KHZ_FREQ (0x03U) + +/* The interrupt line used for host for PRU0*/ +#define ICSS_I2C_INTC_PRU0_BIT_VAL (0x00100000U) +/* The interrupt line used for host for PRU1*/ +#define ICSS_I2C_INTC_PRU1_BIT_VAL (0x00200000U) + +#endif diff --git a/examples/pru_i2c/firmware/pru_i2c_macro.h b/examples/pru_i2c/firmware/pru_i2c_macro.h new file mode 100644 index 000000000..8f9ea615a --- /dev/null +++ b/examples/pru_i2c/firmware/pru_i2c_macro.h @@ -0,0 +1,1009 @@ +; Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/ +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; +; Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the +; distribution. +; +; Neither the name of Texas Instruments Incorporated nor the names of +; its contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +;************************************************************************************ +; File: pru_i2c_macro.h +; +; Brief: This file contains ICSS I2C macros definations +;************************************************************************************ + + .if !$defined("__icss_i2c_macros_h") +__icss_i2c_macros_h .set 1 + +;************************************* includes ************************************* + + ;;.include "icss_constant_defines.inc" + ;;.include "icss_cfg_regs.h" + ;;.include "icss_iep_regs.h" + ;;.include "icss_intc_regs.inc" + ;;;.include "endat_icss_reg_defs.h" + .cdecls C,NOLIST +%{ +#include "pru_i2c_interface.h" +%} + +;--------------------------------------------------------------------------------------- + +;************************************************************************************ +; +; Macro: ENABLE_XIN_XOUT_SHITFTING +; +; Enable support of shifting during XIN/XOUT operation +; +; PEAK cycles: +; 3 cycles +; Pseudo code: +; ICSS_CFG_SPPC[0-7] |= 0x02 +; +; Parameters: +; None +; +; Returns: +; None +; +ENABLE_XIN_XOUT_SHITFTING .macro + LBCO &TEMP_REG1, ICSS_CFG_CONST, ICSS_CFG_SPPC, 4 + OR TEMP_REG1.b0, TEMP_REG1.b0, 0x02 + SBCO &TEMP_REG1, ICSS_CFG_CONST, ICSS_CFG_SPPC, 4 + .endm + + +;************************************************************************************ +; +; Macro: I2C_WAIT_FOR_IEP_CMP +; +; wait until this core's IEP compare event (I2C_IEP_CMP_STATUS_BIT) is set +; +; PEAK cycles: +; Unbounded by design: this is the scheduler tick. It returns at most +; one IEP compare period after the previous tick. The compare is armed +; by I2C_SETUP_IEP_COUNTER and re-armed by I2C_IEP_INTC_CLEAR_EVENT, and +; the shared IEP counter is never stopped by this firmware, so the wait +; always terminates. There is no other time base to time it out against. +; Pseudo code: +; while(IEP_CMP_STATUS_REG.I2C_IEP_CMP_STATUS_BIT == 0) +; +; Parameters: +; None +; +; Returns: +; None +; +; Registers modified: +; TEMP_REG1 +; +;************************************************************************************ +I2C_WAIT_FOR_IEP_CMP .macro + + ; INTENTIONALLY_UNBOUNDED_LOOP: scheduler tick, see the notes above +WAIT_FOR_INT?: + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_STATUS_REG, 4 + QBBC WAIT_FOR_INT?, TEMP_REG1, I2C_IEP_CMP_STATUS_BIT + + .endm + + +;************************************************************************************ +; +; Macro: I2C_IEP_INTC_CLEAR_EVENT +; +; Clear the iep cmp event and intc event +; +; PEAK cycles: +; +; Pseudo code: +; status = IEP_CMP_STATUS_REG +; if(status.I2C_IEP_CMP_STATUS_BIT == 0) +; goto arg1 ; no tick pending for this core +; IEP_CMP_STATUS_REG = 1 << I2C_IEP_CMP_STATUS_BIT ; write-1-to-clear +; next_compare += I2C_GLOBAL_FREQ_REG.w2 ; 64-bit add +; I2C_IEP_CMP_REG = next_compare ; re-arm this core +; ICSS_INTC_SECR1 = 0x0080 ; clear the INTC event +; +; Parameters: +; arg1 - required, a label in the caller that is jumped to when no compare +; event is pending for this core (the "no tick yet" continuation) +; +; Returns: +; None +; +; Registers modified: +; TEMP_REG1, TEMP_REG2.w0 (scratch) +; IEP_COUNTER_NEXT_VAL1, IEP_COUNTER_NEXT_VAL2 (next compare value) +; +;************************************************************************************ +I2C_IEP_INTC_CLEAR_EVENT .macro arg1 + + ; clear the IEP compare event happened + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_STATUS_REG, 4 + QBBS IEP_INTC_CLEAR?, TEMP_REG1, I2C_IEP_CMP_STATUS_BIT + JMP arg1 +IEP_INTC_CLEAR?: + + ; write-1-to-clear only this core's bit: the other PRU shares the register + LDI TEMP_REG1, 0 + SET TEMP_REG1, TEMP_REG1, I2C_IEP_CMP_STATUS_BIT + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_STATUS_REG, 4 + + ;Set compare values + ADD IEP_COUNTER_NEXT_VAL1, IEP_COUNTER_NEXT_VAL1, I2C_GLOBAL_FREQ_REG.w2 + ADC IEP_COUNTER_NEXT_VAL2, IEP_COUNTER_NEXT_VAL2, 0x00 + SBCO &IEP_COUNTER_NEXT_VAL1, ICSS_IEP_CONST, I2C_IEP_CMP_REG, 8 + + ; Clear the intc interrupt event flag + LDI TEMP_REG1.w0, 0x0080 + LDI TEMP_REG2.w0, ICSS_INTC_SECR1 + SBCO &TEMP_REG1, ICSS_INTC_CONST, TEMP_REG2.w0, 4 + + .endm + +;************************************************************************************ +; +; Macro: I2C_WAVE_FUNCTION0 +; +; jump to the next state of i2c function +; +; PEAK cycles: +; +; Pseudo code: +; restore R10..R19 from I2C_CONTEXT_BANK ; this core's scratchpad bank +; call the state at R13.w0 ; return address in TEMP_REG3.w0 +; save R10..R19 to I2C_CONTEXT_BANK +; +; Parameters: +; None +; +; Returns: +; None +; +; Registers modified: +; R0.b0 (XIN/XOUT offset), TEMP_REG3.w0 (state return address) +; R10..R19 (context: loaded from the bank, then written back to it) +; plus whatever the called state writes: states use TEMP_REG1..8 and +; R27..R29 as scratch, update the context registers, and update R23 (the +; GPIO_OUT_CTRL shadow) through the open-drain pin macros. The +; SETUP_I2C_SCL_SDA_HIGH state also loads R26 (GPIO_OUT_CTRL address) and +; clears the SCL and SDA bits of R30. R20..R22 (scheduler: compare value, +; frequency word) are not written by the states. +; +;************************************************************************************ +I2C_WAVE_FUNCTION0 .macro + + ;Restore I2C instance context + LDI R0.b0, 0x00 + XIN I2C_CONTEXT_BANK, &R10, 40 + + ;Jump and link to the next task function + JAL TEMP_REG3.w0, R13.w0 ;R13 store RESET MODE + + ;Save context to SPAD + LDI R0.b0, 0x00 + XOUT I2C_CONTEXT_BANK, &R10, 40 + + .endm + + +;************************************************************************************ +; +; Macro: UPDATE_NEXT_LOCAL_STATE +; +; update next state in state keep register +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label of next state +; +; Returns: +; None +; +;************************************************************************************ +UPDATE_NEXT_LOCAL_STATE .macro arg1 + LDI R13.w0, $CODE(arg1) + .endm + + +;************************************************************************************ +; +; Macro: STATE_TASK_OVER +; +; Return to the scheduler as state task is over. +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label of next state +; +; Returns: +; None +; +;************************************************************************************ +STATE_TASK_OVER .macro + JMP TEMP_REG3.w0 + .endm + +;************************************************************************************ +; +; Open-drain bus pins +; +; SCL and SDA are never driven high. R30 keeps both pin bits at 0 and the +; line is controlled through the pin's OUTDISABLE bit in this core's +; ICSSMx_PRUy_GPIO_OUT_CTRL register (I2C_GPIO_OUT_CTRL): +; OUTDISABLE = 1 -> released, the external pull-up takes the line high +; OUTDISABLE = 0 -> driven low +; R23 is a shadow copy of that register and R26 holds its address, both +; set up in SETUP_I2C_SCL_SDA_HIGH, so a pin change is a single store. +; A target can therefore hold SCL low (clock stretching, see +; WAIT_SCL_HIGH) and the master never fights a target on SDA. +; +; PEAK cycles: +; 2 + store +; +; Registers modified: +; R23 +; +;************************************************************************************ +SET_SCL_PIN_HIGH .macro + SET R23, R23, R14.b0 + SBBO &R23, R26, 0, 4 + .endm + +SET_SCL_PIN_LOW .macro + CLR R23, R23, R14.b0 + SBBO &R23, R26, 0, 4 + .endm + +SET_SDA_PIN_HIGH .macro + SET R23, R23, R14.b1 + SBBO &R23, R26, 0, 4 + .endm + +SET_SDA_PIN_LOW .macro + CLR R23, R23, R14.b1 + SBBO &R23, R26, 0, 4 + .endm + +;************************************************************************************ +; +; Macro: WAIT_SCL_HIGH +; +; Clock stretching. Put at the top of every state that runs one tick after +; SCL was released. If a target still holds SCL low, return without +; advancing the state, so the same state runs again on the next tick. +; R18.w0 counts the ticks SCL has been held low; when it reaches the limit +; in R18.w2 (ICSS_I2C_SCL_TIMEOUT_OFFSET, 0 = no limit) the transfer is +; abandoned with TIME_OUT_ERROR (SCL_LOW_TIMEOUT). +; When SCL comes up after being held, wait one more tick before going on, +; so the high period is counted from the moment SCL actually rose and is +; never shorter than without stretching (tHIGH). +; +; Registers modified: +; R18.w0, R13.w0 (on timeout) +; +;************************************************************************************ +WAIT_SCL_HIGH .macro + QBBS scl_high?, R31, R14.b0 + ADD R18.w0, R18.w0, 1 + QBEQ scl_wait?, R18.w2, 0 + QBLT scl_wait?, R18.w2, R18.w0 + LDI R13.w0, $CODE(SCL_LOW_TIMEOUT) +scl_wait?: + STATE_TASK_OVER +scl_high?: + QBEQ scl_ok?, R18.w0, 0 + LDI R18.w0, 0 + STATE_TASK_OVER +scl_ok?: + .endm + +;************************************************************************************ +; +; Macro: PEC_UPDATE +; +; SMBus Packet Error Code: CRC-8, x^8 + x^2 + x + 1, initial value 0, +; updated one bit at a time as bits go out or come in, MSB first. Runs +; only when SMB_F_PEC is set for the current transfer. +; +; Parameters: +; src, bitn: the bit (register, bit number) just sent or received +; +; Registers modified: +; R19.b0 (CRC), TEMP_REG6.b0 +; +;************************************************************************************ +PEC_UPDATE .macro src, bitn + QBBC pec_done?, R19.b3, SMB_F_PEC + LSR TEMP_REG6.b0, R19.b0, 7 + QBBC pec_bit0?, src, bitn + XOR TEMP_REG6.b0, TEMP_REG6.b0, 1 +pec_bit0?: + LSL R19.b0, R19.b0, 1 + QBEQ pec_done?, TEMP_REG6.b0, 0 + XOR R19.b0, R19.b0, 0x07 +pec_done?: + .endm + +;************************************************************************************ +; +; Macro: TX_FETCH_BYTE +; +; Load byte R15.b2 of the transmit stream into dest. The stream starts at +; R11: the Tx buffer for I2C, or up to two SMBus prefix bytes (command +; code, block count) staged just in front of it. When SMB_F_PECTX is set +; the last byte of the stream is the PEC, taken from R19.b0, which by then +; covers every bit sent before it. +; +; Registers modified: +; dest, TEMP_REG4.b0 +; +;************************************************************************************ +TX_FETCH_BYTE .macro dest + QBBC fetch_buf?, R19.b3, SMB_F_PECTX + SUB TEMP_REG4.b0, R15.b3, 1 + QBNE fetch_buf?, R15.b2, TEMP_REG4.b0 + MOV dest, R19.b0 + JMP fetch_done? +fetch_buf?: + LBBO &dest, R11, R15.b2, 1 +fetch_done?: + .endm + +;---------------------------------------------------------------------- +; Macro Name: READ_SDA_PIN_ACK +; Description: Set high value on SCL pin +; Input Parameters: none +; Output Parameters: none +;---------------------------------------------------------------------- +READ_SDA_PIN_ACK .macro + QBBS ACK_RECIEVED?, R31, R14.b1 + CLR R16, R16, ICSS_I2C_ACK_RECIEVED_BIT + JMP NO_ACK_RECIEVED? +ACK_RECIEVED?: + SET R16, R16, ICSS_I2C_ACK_RECIEVED_BIT +NO_ACK_RECIEVED?: + .endm + +;---------------------------------------------------------------------- +; Macro Name: COPY_LOCAL_TO_GLOBAL_STATE +; Description: copy next state from global state register. +; Input Parameters: none +; Output Parameters: none +;---------------------------------------------------------------------- +COPY_LOCAL_TO_GLOBAL_STATE .macro + AND R13.w0, R17.w0, R17.w0 + .endm + + +;************************************************************************************ +; +; Macro: RAISE_INTERRUPT_MEM_FOR_HOST +; +; raise the interrupt memory for telling host which instance raise the interrupt. +; Each instance owns one byte of the shared IRQ word (IRQ_COMMON_REGISTER_OFFSET +; + instance id) and writes it with a single byte store, so two instances +; cannot overwrite each other's flag. +; +; PEAK cycles: +; +; Pseudo code: +; command word (R10 + ICSS_I2C_COMMAND_OFFSET + 2) = 0 +; DMEM0[ICSS_I2C_CONFIG_MEMORY + IRQ_COMMON_REGISTER_OFFSET + R14.b3] = 1 +; next state = arg1; return to the scheduler +; +; Parameters: +; arg1 - required, the state to run on the next tick +; +; Returns: +; None +; +; Registers modified: +; TEMP_REG4.w0, TEMP_REG5.w0 (scratch) +; R13.w0 (next state) +; +; Registers read: +; R10 (instance memory base), R14.b3 (instance id), +; TEMP_REG3.w0 (scheduler return address) +; +;************************************************************************************ +RAISE_INTERRUPT_MEM_FOR_HOST .macro arg1 + LDI TEMP_REG4.w0, 0x0000 + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET+2, 2 + + LDI TEMP_REG5.w0, ICSS_I2C_CONFIG_MEMORY + ADD TEMP_REG5.w0, TEMP_REG5.w0, IRQ_COMMON_REGISTER_OFFSET + ADD TEMP_REG5.w0, TEMP_REG5.w0, R14.b3 + LDI TEMP_REG4.b0, 1 + SBCO &TEMP_REG4.b0, ICSS_DMEM0_CONST, TEMP_REG5.w0, 1 + UPDATE_NEXT_LOCAL_STATE arg1 + STATE_TASK_OVER + .endm + + +;************************************************************************************ +; +; Macro: RAISE_INTERRUPT_FOR_HOST +; +; raise the interrupt memory for telling host which instance raise the interrupt. +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; None: +; +; Returns: +; None +; +; Registers modified: +; TEMP_REG5.w0, TEMP_REG6 (scratch) +; R13.w0 (next state) +; +; Registers read: +; TEMP_REG3.w0 (scheduler return address) +; +;************************************************************************************ +RAISE_INTERRUPT_FOR_HOST .macro arg1 + LDI TEMP_REG5.w0, ICSS_INTC_SRSR1 + .if $defined("PRU0") + LDI32 TEMP_REG6, ICSS_I2C_INTC_PRU0_BIT_VAL + .else + LDI32 TEMP_REG6, ICSS_I2C_INTC_PRU1_BIT_VAL + .endif + SBCO &TEMP_REG6, ICSS_INTC_CONST, TEMP_REG5.w0, 4 + UPDATE_NEXT_LOCAL_STATE arg1 + STATE_TASK_OVER + .endm + +;************************************************************************************ +; +; Macro: CHECK_INTERRUPT_RECEIVED +; +; check whether the host has acknowledged this instance's interrupt, that is, +; cleared its byte of the shared IRQ word. +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label on new memory location if interrupt is ACKed +; arg2: Label on new memory location if interrupt is not ACKed +; +; Returns: +; None +; +; Registers modified: +; TEMP_REG4.b0, TEMP_REG5.w0 (scratch) +; R13.w0 (next state) +; +; Registers read: +; R14.b3 (instance id), TEMP_REG3.w0 (scheduler return address) +; +;************************************************************************************ +CHECK_INTERRUPT_RECEIVED .macro arg1, arg2 + LDI TEMP_REG5.w0, ICSS_I2C_CONFIG_MEMORY + ADD TEMP_REG5.w0, TEMP_REG5.w0, IRQ_COMMON_REGISTER_OFFSET + ADD TEMP_REG5.w0, TEMP_REG5.w0, R14.b3 + LBCO &TEMP_REG4.b0, ICSS_DMEM0_CONST, TEMP_REG5.w0, 1 + QBEQ INTERRUPT_RECEIVED_JMP_STATE?, TEMP_REG4.b0, 0 + JMP INTERRUPT_RECEIVED_REPEAT_STATE? + +INTERRUPT_RECEIVED_JMP_STATE?: + UPDATE_NEXT_LOCAL_STATE arg1 + STATE_TASK_OVER + +INTERRUPT_RECEIVED_REPEAT_STATE?: + UPDATE_NEXT_LOCAL_STATE arg2 + STATE_TASK_OVER + .endm + + +;************************************************************************************ +; +; Macro: UPDATE_NEXT_GLOBAL_STATE +; +; update next state in state keep register +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label on next memory location +; +; +; Returns: +; None +; +;************************************************************************************ +UPDATE_NEXT_GLOBAL_STATE .macro arg1 + LDI R17.w0, $CODE(arg1) + .endm + +;************************************************************************************ +; +; Macro: READ_ADDRESS_REGISTER +; +; Read the address register for slave address +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label on next memory location +; +; +; Returns: +; None +; +;************************************************************************************ +READ_ADDRESS_REGISTER .macro arg1 + QBBS read_address_register_10bits?, R16, ICSS_I2C_ADDRESSING_MODE_BIT + LDI TEMP_REG4.w0, 0x007F + JMP read_address_register_done? + +read_address_register_10bits?: + LDI TEMP_REG4.w0, 0x03FF + +read_address_register_done?: + LBBO &R13.w2, R10, ICSS_I2C_SA_OFFSET, 2 + + ;debug code + .if $defined("DEBUG_CODE") + LDI R13.w2, 0x53 + .endif + + AND R13.w2, R13.w2, TEMP_REG4.w0 + UPDATE_NEXT_LOCAL_STATE arg1 + STATE_TASK_OVER + .endm + +;************************************************************************************ +; +; Macro: READ_RW_REGISTER_BIT +; +; Read the RW bit to find read or write operation +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1: Label on new memory location +; +; +; Returns: +; None +; +;************************************************************************************ +READ_RW_REGISTER_BIT .macro arg1 + QBBS read_rw_register_bit_10bits?, R16, ICSS_I2C_ADDRESSING_MODE_BIT + LSL R13.w2, R13.w2, 9 + QBBC slave_address_w_setup?, R16, ICSS_I2C_READ_WRITE_BIT + SET R13.w2, R13.w2, 8 + JMP slave_address_rw_setup_return? +slave_address_w_setup?: + CLR R13.w2, R13.w2, 8 +slave_address_rw_setup_return?: + JMP read_rw_register_bit_done? + +read_rw_register_bit_10bits?: + LSL R13.b3, R13.b3, 1 + QBBC slave_address_w_setup_10bits?, R16, ICSS_I2C_READ_WRITE_BIT + SET R13.b3, R13.b3, 0 + JMP slave_address_rw_setup_return_10bits? +slave_address_w_setup_10bits?: + CLR R13.b3, R13.b3, 0 +slave_address_rw_setup_return_10bits?: + AND R13.b3, R13.b3, 0x07 + OR R13.b3, R13.b3, 0xF0 + +read_rw_register_bit_done?: + AND R15.b0, R15.b0, 0x00 + AND R15.b2, R15.b2, 0x00 + UPDATE_NEXT_LOCAL_STATE arg1 + STATE_TASK_OVER + .endm + + +;************************************************************************************ +; +; Macro: SEND_TX_DATA_CHECK_FOR_ACK +; +; Description: send 8 bits of Tx data +; check if ACK is recieved from slave or not. +; keep on sending until all data is sent. +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; arg1 is register to be used for reading that data. +; arg2 is Label on new memory location for TX DATA complete +; arg3 is Label on new memory location for No ACK +; Returns: +; None +; +;************************************************************************************ +SEND_TX_DATA_CHECK_FOR_ACK .macro arg1, arg2, arg3 +; +; put the most significant bit of the data byte on SDA (SCL is low) +; +tx_data_sda_begin?: + QBBC tx_data_sda_low?, arg1, 7 + SET_SDA_PIN_HIGH + JMP tx_data_sda_continue? +tx_data_sda_low?: + SET_SDA_PIN_LOW +tx_data_sda_continue?: + PEC_UPDATE arg1, 7 + LSL arg1, arg1, 1 + ADD R15.b0, R15.b0, 0x01 + LDI R13.w0, $CODE(tx_data_scl_begin?) + STATE_TASK_OVER + +; +; release SCL +; +tx_data_scl_begin?: + SET_SCL_PIN_HIGH + LDI R13.w0, $CODE(tx_data_sda_read?) + STATE_TASK_OVER + +; +; SCL high period (waits here while a target stretches the clock) +; +tx_data_sda_read?: + WAIT_SCL_HIGH + LDI R13.w0, $CODE(tx_data_scl_end?) + STATE_TASK_OVER + +; +; pull SCL low; after the 8th bit release SDA on this same edge, so the +; target can drive its ACK +; +tx_data_scl_end?: + SET_SCL_PIN_LOW + QBGT tx_sda_next_bit?, R15.b0, 0x08 + SET_SDA_PIN_HIGH + LDI R13.w0, $CODE(tx_data_ack_begin?) + STATE_TASK_OVER + +tx_sda_next_bit?: + LDI R13.w0, $CODE(tx_data_sda_begin?) + STATE_TASK_OVER + +; +; SDA was released in tx_data_scl_end; this tick keeps the 4-tick bit timing +; +tx_data_ack_begin?: + LDI R13.w0, $CODE(tx_data_ack_scl_begin?) + STATE_TASK_OVER + +; +; release SCL for the ACK bit +; +tx_data_ack_scl_begin?: + SET_SCL_PIN_HIGH + LDI R13.w0, $CODE(tx_data_ack_read?) + STATE_TASK_OVER + +; +; sample the ACK bit once SCL is high +; +tx_data_ack_read?: + WAIT_SCL_HIGH + READ_SDA_PIN_ACK + LDI R13.w0, $CODE(tx_data_ack_scl_end?) + STATE_TASK_OVER + +; +; pull SCL low; on ACK send the next byte or finish +; +tx_data_ack_scl_end?: + SET_SCL_PIN_LOW + QBBS tx_data_ack_not_recieved?, R16, ICSS_I2C_ACK_RECIEVED_BIT + ADD R15.b2, R15.b2, 0x01 + LDI R15.b0, 0x00 + QBGT tx_mode_continue?, R15.b2, R15.b3 + LDI R15.b2, 0x00 + LDI R13.w0, $CODE(arg2) + STATE_TASK_OVER +tx_mode_continue?: + TX_FETCH_BYTE arg1 + LDI R13.w0, $CODE(tx_data_sda_begin?) + STATE_TASK_OVER + +; +; the target did not acknowledge a data byte +; +tx_data_ack_not_recieved?: + LDI TEMP_REG4.w0, DATA_ACKNOWLDEGE_FAILED + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + LDI R13.w0, $CODE(arg3) + STATE_TASK_OVER + + .endm + + + + + +;************************************************************************************ +; +; Macro: I2C_SETUP_IEP_COUNTER +; +; Description: Setup the IEP timer counter for periodic interrupt. +; +; The IEP counter and IEP_CMP_CFG_REG are shared by PRU0 and PRU1 and there is +; no hardware lock around them. The first core to run this macro resets and +; starts the counter; the second only joins it. The read-modify-write of +; IEP_CMP_CFG_REG (enable bit) and the "counter already enabled" test are not +; atomic across the two cores, so the two PRUs must not run this macro at the +; same time: release PRU0 and PRU1 from reset one after the other, with the +; first core past its init before the second starts. Two cores starting +; together can lose an enable bit (that core then waits forever in +; I2C_WAIT_FOR_IEP_CMP) or reset the counter under the other core. +; +; PEAK cycles: +; +; Pseudo code: +; +; +; Parameters: +; None +; Returns: +; None +; +; Registers modified: +; TEMP_REG1, TEMP_REG2 (scratch) +; IEP_COUNTER_NEXT_VAL1, IEP_COUNTER_NEXT_VAL2 (first compare value) +; +; Registers read: +; I2C_GLOBAL_FREQ_REG.w2 (IEP compare increment) +; +;************************************************************************************ + +I2C_SETUP_IEP_COUNTER .macro + ;read IEP Timer enabled or not + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_GLOBAL_CFG_REG, 4 + QBBS iep_counter_setup_done?, TEMP_REG1 , 0 + + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_COUNT_REG, 8 + LDI32 TEMP_REG1 , 0xFFFFFFFF + LDI32 TEMP_REG2 , 0xFFFFFFFF + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_COUNT_REG, 8 + + ;Clear overflow status register + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_GLOBAL_STATUS_REG, 4 + SET TEMP_REG1 , TEMP_REG1 , 0 + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_GLOBAL_STATUS_REG, 4 + + ;Clear compare status + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_STATUS_REG, 4 + LDI TEMP_REG1.w0 , 0xFFFF + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_STATUS_REG, 4 + + ;Enable IEP counter + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_GLOBAL_CFG_REG, 4 + SET TEMP_REG1 , TEMP_REG1 , 0 + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_GLOBAL_CFG_REG, 4 + +iep_counter_setup_done?: + ; First compare = current count + one tick. Starting from the live count + ; (rather than a constant) is what lets the second PRU join a counter the + ; first PRU already started. + LBCO &IEP_COUNTER_NEXT_VAL1, ICSS_IEP_CONST, ICSS_IEP_COUNT_REG, 8 + ADD IEP_COUNTER_NEXT_VAL1, IEP_COUNTER_NEXT_VAL1, I2C_GLOBAL_FREQ_REG.w2 + ADC IEP_COUNTER_NEXT_VAL2, IEP_COUNTER_NEXT_VAL2, 0x00 + SBCO &IEP_COUNTER_NEXT_VAL1, ICSS_IEP_CONST, I2C_IEP_CMP_REG, 8 + + ; Enable this core's compare event without disabling the other core's + LBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_CFG_REG, 4 + SET TEMP_REG1, TEMP_REG1, I2C_IEP_CMP_ENABLE_BIT + SBCO &TEMP_REG1, ICSS_IEP_CONST, ICSS_IEP_CMP_CFG_REG, 4 + + .endm + + + +;------------------------------------------------------------------------------------------------------------------------------- +; Macro Name: READ_RX_DATA_AND_SEND_ACK +; Description: read 8 bits of Rx data then send ack +; keep on sending until all data is read. +; Input Parameters: arg1 is register to be used for reading data. +; Input Parameters: arg2 is Label on new memory location for DATA complete +; Output Parameters: none +;---------------------------------------------------------------------------------------------------------------------------- +READ_RX_DATA_AND_SEND_ACK .macro arg1, arg2 +; +; release SDA so the target can drive it +; + SET_SDA_PIN_HIGH +rx_data_sda_begin?: + LDI R13.w0, $CODE(rx_data_scl_begin?) + STATE_TASK_OVER + +; +; release SCL for the data bit +; +rx_data_scl_begin?: + SET_SCL_PIN_HIGH + LSL arg1, arg1, 1 + LDI R13.w0, $CODE(rx_data_sda_read?) + STATE_TASK_OVER + +; +; sample SDA into the LSB once SCL is high +; +rx_data_sda_read?: + WAIT_SCL_HIGH + QBBS rx_data_sda_high?, R31, R14.b1 + AND arg1, arg1, 0xFE + JMP rx_data_sda_read_continue? +rx_data_sda_high?: + OR arg1, arg1, 0x01 +rx_data_sda_read_continue?: + PEC_UPDATE arg1, 0 + ADD R15.b0, R15.b0, 0x01 + LDI R13.w0, $CODE(rx_data_scl_end?) + STATE_TASK_OVER + +; +; pull SCL low; after the 8th bit decide between ACK and NACK +; +rx_data_scl_end?: + SET_SCL_PIN_LOW + QBGT rx_sda_next_bit?, R15.b0, 0x08 + QBBC rx_data_not_count?, R19.b3, SMB_F_BLKRD + ; SMBus block read: this byte is the block count. It is reported in the + ; count register and not stored. The count plus an optional PEC byte must + ; fit the 8-bit byte index. + CLR R19.b3, R19.b3, SMB_F_BLKRD + QBEQ rx_count_bad?, arg1, 0x00 + MOV R15.b3, arg1 + QBBC rx_count_ok?, R19.b3, SMB_F_PECRX + QBEQ rx_count_bad?, arg1, 0xFF + ADD R15.b3, R15.b3, 0x01 +rx_count_ok?: + LDI TEMP_REG4.w0, 0x0000 + MOV TEMP_REG4.b0, arg1 + SBBO &TEMP_REG4, R10, ICSS_I2C_CNT_OFFSET, 2 + LDI R13.w0, $CODE(rx_data_ack_begin?) + STATE_TASK_OVER +rx_count_bad?: + LDI TEMP_REG4.w0, INVALID_DATA_COUNT + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + SET R19.b3, R19.b3, SMB_F_ERR + LDI R15.w2, 0x0101 + LDI R13.w0, $CODE(rx_data_nack_begin?) + STATE_TASK_OVER +rx_data_not_count?: + ADD R15.b2, R15.b2, 0x01 + QBGT rx_data_next_state?, R15.b2, R15.b3 + QBBS rx_data_nack?, R19.b3, SMB_F_SMB + QBBC rx_data_next_state?, R16, ICSS_I2C_RECIEVE_NACK_BIT +rx_data_nack?: + LDI R13.w0, $CODE(rx_data_nack_begin?) + STATE_TASK_OVER + +rx_data_next_state?: + LDI R13.w0, $CODE(rx_data_ack_begin?) + STATE_TASK_OVER + +rx_sda_next_bit?: + LDI R13.w0, $CODE(rx_data_sda_begin?) + STATE_TASK_OVER + +; +; pull SDA low to ACK the byte +; +rx_data_ack_begin?: + SET_SDA_PIN_LOW + LDI R13.w0, $CODE(rx_data_ack_scl_begin?) + STATE_TASK_OVER + +; +; leave SDA released to NACK the byte +; +rx_data_nack_begin?: + SET_SDA_PIN_HIGH + LDI R13.w0, $CODE(rx_data_ack_scl_begin?) + STATE_TASK_OVER + +; +; release SCL for the ACK/NACK bit +; +rx_data_ack_scl_begin?: + SET_SCL_PIN_HIGH + LDI R13.w0, $CODE(rx_data_ack_read?) + STATE_TASK_OVER + +; +; ACK/NACK high period (waits here while a target stretches the clock) +; +rx_data_ack_read?: + WAIT_SCL_HIGH + LDI R13.w0, $CODE(rx_data_ack_scl_end?) + STATE_TASK_OVER + +; +; pull SCL low, store the byte, then read the next one or finish. The +; block count byte (byte index still 0) is not stored. +; +rx_data_ack_scl_end?: + SET_SCL_PIN_LOW + LDI R15.b0, 0x00 + QBEQ rx_mode_continue?, R15.b2, 0x00 + SUB TEMP_REG4.b0, R15.b2, 1 + SBBO &arg1, R12, TEMP_REG4.b0, 1 + QBGT rx_mode_continue?, R15.b2, R15.b3 + LDI R15.b2, 0x00 + LDI R13.w0, $CODE(arg2) + STATE_TASK_OVER + +rx_mode_continue?: + SET_SDA_PIN_HIGH + LDI R13.w0, $CODE(rx_data_sda_begin?) + STATE_TASK_OVER + + .endm + + +;************************************************************************************ +; +; Macro: I2C_TRANSFER_INIT +; +; Reset the per-transfer state: PEC, command code, flags (R19), the +; SCL-low counter and the transmit stream base (R11 = Tx buffer). +; +;************************************************************************************ +I2C_TRANSFER_INIT .macro + LDI R19, 0 + LDI R18.w0, 0 + LDI R11.w0, ICSS_I2C_INSTANCE0_TX_MEM + .endm + + .endif ; __icss_i2c_macros_h diff --git a/examples/pru_i2c/firmware/pru_i2c_main.asm b/examples/pru_i2c/firmware/pru_i2c_main.asm new file mode 100644 index 000000000..d369731d3 --- /dev/null +++ b/examples/pru_i2c/firmware/pru_i2c_main.asm @@ -0,0 +1,1395 @@ +; Copyright (C) 2026 Texas Instruments Incorporated - http://www.ti.com/ +; +; Redistribution and use in source and binary forms, with or without +; modification, are permitted provided that the following conditions +; are met: +; +; Redistributions of source code must retain the above copyright +; notice, this list of conditions and the following disclaimer. +; +; Redistributions in binary form must reproduce the above copyright +; notice, this list of conditions and the following disclaimer in the +; documentation and/or other materials provided with the +; distribution. +; +; Neither the name of Texas Instruments Incorporated nor the names of +; its contributors may be used to endorse or promote products derived +; from this software without specific prior written permission. +; +; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +; LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR +; A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT +; OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, +; SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT +; LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, +; DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY +; THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT +; (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +; OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + +;-------------------------------------------------------------------------------------- +; File: pru_i2c_main.asm +; +; Brief: Firmware for ICSS PRU +;-------------------------------------------------------------------------------------- + +; CCS/makefile specific settings + .retain ; Required for building .out with assembly file + .retainrefs ; Required for building .out with assembly file + + .global main + .sect ".text" + +;----------------------------------Includes---------------------------------------------------- + + .include "pru_i2c_firmware_version.h" + .include "pru_i2c_macro.h" + .include "icss_constant_defines.inc" + .include "icss_cfg_regs.inc" + .include "icss_iep_regs.inc" + .include "icss_intc_regs.inc" +;-------------------------------------------------------------------------------------- + +; +; symbols +; + + .asg R1, TEMP_REG1 ; temporary register 1 + .asg R2, TEMP_REG2 ; temporary register 2 + .asg R3, TEMP_REG3 ; temporary register 3 + .asg R4, TEMP_REG4 ; temporary register 4 + .asg R5, TEMP_REG5 ; temporary register 5 + .asg R6, TEMP_REG6 ; temporary register 6 + .asg R7, TEMP_REG7 ; temporary register 7 + .asg R8, TEMP_REG8 ; temporary register 8 + + .asg R20, IEP_COUNTER_NEXT_VAL1 + .asg R21, IEP_COUNTER_NEXT_VAL2 + .asg R22, I2C_GLOBAL_FREQ_REG + + + + +PRU0_IEP_CMP_REG .set ICSS_IEP_CMP0_REG +PRU1_IEP_CMP_REG .set ICSS_IEP_CMP1_REG +PRU0_IEP_CMP_ENABLE_BIT .set 1 +PRU1_IEP_CMP_ENABLE_BIT .set 2 +PRU0_IEP_CMP_STATUS_BIT .set 0 +PRU1_IEP_CMP_STATUS_BIT .set 1 + +; Bank ids for Xfer instructions +BANK0 .set 10 +BANK1 .set 11 +BANK2 .set 12 + +; MSS_CTRL ICSSMx_PRUy_GPIO_OUT_CTRL (AM261x, cslr_mss_ctrl.h). Setting a bit +; disables the output driver of that PRU GPO pin, which releases the line to +; the external pull-up. Used to hand SDA to the target for ACK and read data. +ICSSM0_PRU0_GPIO_OUT_CTRL .set 0x50D00810 +ICSSM0_PRU1_GPIO_OUT_CTRL .set 0x50D00814 +ICSSM1_PRU0_GPIO_OUT_CTRL .set 0x50D00818 +ICSSM1_PRU1_GPIO_OUT_CTRL .set 0x50D0081C + +; Per-core resources. The IEP and the scratchpad banks are shared by both +; PRUs, so each core must use its own compare register, status bit, enable +; bit and context bank. The build must define exactly one of PRU0 / PRU1 +; (projectspec -DPRU0/-DPRU1, makefile DFLAGS); icss_constant_defines.inc +; also relies on it to select the DMEM constants. + .if $defined("PRU0") +I2C_IEP_CMP_REG .set PRU0_IEP_CMP_REG +I2C_IEP_CMP_ENABLE_BIT .set PRU0_IEP_CMP_ENABLE_BIT +I2C_IEP_CMP_STATUS_BIT .set PRU0_IEP_CMP_STATUS_BIT +I2C_CONTEXT_BANK .set BANK0 + .if $defined("ICSSM1") +I2C_GPIO_OUT_CTRL .set ICSSM1_PRU0_GPIO_OUT_CTRL + .else +I2C_GPIO_OUT_CTRL .set ICSSM0_PRU0_GPIO_OUT_CTRL + .endif + .elseif $defined("PRU1") +I2C_IEP_CMP_REG .set PRU1_IEP_CMP_REG +I2C_IEP_CMP_ENABLE_BIT .set PRU1_IEP_CMP_ENABLE_BIT +I2C_IEP_CMP_STATUS_BIT .set PRU1_IEP_CMP_STATUS_BIT +I2C_CONTEXT_BANK .set BANK1 + .if $defined("ICSSM1") +I2C_GPIO_OUT_CTRL .set ICSSM1_PRU1_GPIO_OUT_CTRL + .else +I2C_GPIO_OUT_CTRL .set ICSSM0_PRU1_GPIO_OUT_CTRL + .endif + .else + .emsg "pru_i2c: define PRU0 or PRU1 for the core this firmware runs on" + .endif + +; Register usage: +; R1-R8 TEMP_REG1..8, scratch. TEMP_REG3.w0 holds the state return +; address while a state runs (JAL in I2C_WAVE_FUNCTION0). +; R10-R19 I2C instance context, saved/restored with XIN/XOUT on +; I2C_CONTEXT_BANK: +; R10 instance base, R11 Tx buffer, R12 Rx buffer, +; R13.w0 next state, R13.w2 slave address shift register, +; R14 b0 SCL pin, b1 SDA pin, b3 instance id, +; R15 b0 bit count, b1 data byte, b2 byte index, b3 byte count, +; R16 control flags (ICSS_I2C_*_BIT), R17.w0 post-address state, +; R17.b2 SMBus read phase length. +; R18 w0 SCL-low tick counter, w2 SCL-low timeout (ticks, 0 = off). +; R19 b0 PEC CRC, b1 SMBus command code, b3 transfer flags SMB_F_*. +; R20-R21 next IEP compare value (64-bit), R22 frequency word. +; R23 shadow of I2C_GPIO_OUT_CTRL (open-drain SCL/SDA), R26 its address. + +; Transfer flags in R19.b3 (cleared at the start of every transfer) +SMB_F_PEC .set 0 ; update the PEC CRC +SMB_F_PECTX .set 1 ; last write-phase byte is the PEC +SMB_F_RDPHASE .set 2 ; repeated START + read after writing +SMB_F_BLKRD .set 3 ; next byte read is the block count +SMB_F_SMB .set 4 ; SMBus: always START/STOP, NACK last byte +SMB_F_PECRX .set 5 ; the read ends with the target's PEC +SMB_F_ERR .set 6 ; error already reported, end with STOP + +; SMBus block write data count limits, in bytes. The stream (command code, +; count, data and the optional PEC byte) has to fit the 8-bit stream index, +; so the PEC byte takes one byte off the limit. +SMBUS_BLOCK_MAX_LEN .set 253 +SMBUS_BLOCK_MAX_LEN_PEC .set 252 + + +;-------------------------------------------------------------------------------------- + +;******** +;* MAIN * +;******** + +main: + +init: +;---------------------------------------------------------------------------- +; Clear the register space +; Before begining with the application, make sure all the registers are set +; to 0. PRU has 32 - 4 byte registers: R0 to R31, with R30 and R31 being special +; registers for output and input respectively. +;---------------------------------------------------------------------------- + +; Give the starting address and number of bytes to clear. + ZERO &R0, 120 + + + ;need to add section to store firmware version in memory' + ;///// + + ; Enable support of shifting during XIN/XOUT operation + ENABLE_XIN_XOUT_SHITFTING + + ;Initialize I2C instance 0 registers + LDI R10.w0 , ICSS_I2C_INSTANCE0_ADDR + LDI R10.w2 , 0x0000 + LDI R11.w0 , ICSS_I2C_INSTANCE0_TX_MEM + LDI R11.w2 , 0x0000 + LDI R12.w0 , ICSS_I2C_INSTANCE0_RX_MEM + LDI R12.w2 , 0x0000 + LDI R13.w0 , $CODE(RESET_MODE) + LDI R13.w2 , 0x0000 + LDI32 R14 , 0x00000000 + LDI32 R15 , 0x00000000 + LDI32 R16 , 0x00000000 + LDI32 R17 , 0x00000000 + LDI32 R18 , 0x00000000 + LDI32 R19 , 0x00000000 + + LDI R0.b0, 0x00 + XOUT I2C_CONTEXT_BANK, &R10, 40 + + ;add a variable delay for N cyles to avoid contention + ;between PRU0 and PRU1 if both out of reset at the same time. + ;;DELAY DELAY_CYCLE + + ZERO &R0, 124 ;Zero all registers + + ;decide the global working frequency for I2C FW + ;Load frequency from DMEM + LDI TEMP_REG1.w0, ICSS_I2C_CONFIG_MEMORY + ADD TEMP_REG1.w0, TEMP_REG1.w0, I2C_BUS_FREQUENCY_OFFSET + LBCO &I2C_GLOBAL_FREQ_REG.w0, ICSS_DMEM0_CONST, TEMP_REG1.w0, 4 + + ; The configuration only has to carry the frequency selector (w0). If the + ; host left the IEP compare increment (w2) at 0, derive it from the + ; selector here so that a selector-only configuration gets a nonzero tick + ; period. A nonzero w2 written by the host is kept as an override. An + ; unsupported selector ends in ERROR_LOOP below. + QBNE FREQ_NOT_1MHZ, I2C_GLOBAL_FREQ_REG.w2, 0 + QBNE FREQ_NOT_100KHZ, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_100KHZ_FREQ + LDI I2C_GLOBAL_FREQ_REG.w2, IEP_CMP_INCREMENT_VAL_100KHZ +FREQ_NOT_100KHZ: + QBNE FREQ_NOT_400KHZ, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_400KHZ_FREQ + LDI I2C_GLOBAL_FREQ_REG.w2, IEP_CMP_INCREMENT_VAL_400KHZ +FREQ_NOT_400KHZ: + QBNE FREQ_NOT_1MHZ, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_1MHZ_FREQ + LDI I2C_GLOBAL_FREQ_REG.w2, IEP_CMP_INCREMENT_VAL_1MHZ +FREQ_NOT_1MHZ: + + ;Debug code for testing + .if $defined("DEBUG_CODE") + LDI TEMP_REG1.w0, ICSS_I2C_400KHZ_FREQ + LDI TEMP_REG1.w2, IEP_CMP_INCREMENT_VAL_400KHZ + MOV I2C_GLOBAL_FREQ_REG, TEMP_REG1 + .endif + + ; Setup the IEP Timer Counter + I2C_SETUP_IEP_COUNTER + + ; jump to task_loop based on global frequency + QBEQ TASK_LOOP_100Khz, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_100KHZ_FREQ + QBEQ TASK_LOOP_400Khz, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_400KHZ_FREQ + QBEQ TASK_LOOP_1Mhz, I2C_GLOBAL_FREQ_REG.w0, ICSS_I2C_1MHZ_FREQ + +; Unsupported frequency selector. Do not stop the IEP counter here: it is +; shared with the other PRU, whose I2C instance may already be running. +ERROR_LOOP: + LDI TEMP_REG5.w0, ICSS_INTC_SRSR1 + LDI32 TEMP_REG6, 0x00400000 + SBCO &TEMP_REG6, ICSS_INTC_CONST, TEMP_REG5.w0, 4 + QBA ERROR_LOOP + + +;---------------------------------------------------------- +; Task for 100Khz mode +; 1) Waiting for cmp event +; 2) Clear the event +; 3) Perform the i2c wave transition +;---------------------------------------------------------- +TASK_LOOP_100Khz: + ;wait for the IEP CMP event 1 to happen +IEP_CHECK_EVENT0: + I2C_WAIT_FOR_IEP_CMP + + ; clear IEP CMP event and interrupt associated with it. + I2C_IEP_INTC_CLEAR_EVENT IEP_CHECK_EVENT0 + + ;perform the i2c wave transition + I2C_WAVE_FUNCTION0 + + QBA TASK_LOOP_100Khz + + +;---------------------------------------------------------- +; Task for 400Khz mode +; 1) Waiting for cmp event +; 2) Clear the event +; 3) Perform the i2c wave transition +;---------------------------------------------------------- +TASK_LOOP_400Khz: + ;wait for the IEP CMP event 1 to happen +IEP_CHECK_EVENT1: + I2C_WAIT_FOR_IEP_CMP + + ; clear IEP CMP event and interrupt associated with it. + I2C_IEP_INTC_CLEAR_EVENT IEP_CHECK_EVENT1 + + ;perform the i2c wave transition + I2C_WAVE_FUNCTION0 + + QBA TASK_LOOP_400Khz + + +;---------------------------------------------------------- +; Task for 1MHz mode +; 1) Waiting for cmp event +; 2) Clear the event +; 3) Perform the i2c wave transition +;---------------------------------------------------------- + +TASK_LOOP_1Mhz: + ;wait for the IEP CMP event 1 to happen +IEP_CHECK_EVENT2: + I2C_WAIT_FOR_IEP_CMP + + ; clear IEP CMP event and interrupt associated with it. + I2C_IEP_INTC_CLEAR_EVENT IEP_CHECK_EVENT2 + + ;perform the i2c wave transition + I2C_WAVE_FUNCTION0 + + QBA TASK_LOOP_1Mhz + + + + +;-----------------------------------------------------------I2C states---------------------------------------------------------------------------------- +; +; +; In all state, the processing is broken into multiple state we have a tight budget of +; 20 cycles per state. +; +;----------------------------------------------------------- + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This is the initial mode in which comes out of reset +; It checks if the enabled bit is set or not. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_MODE: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + + ;Debug Code + .if $defined("DEBUG_CODE") + SET TEMP_REG4, TEMP_REG4, ICSS_I2C_MODULE_ENABLE_BIT + .endif + + QBBC RESET_MODE_RETURN, TEMP_REG4, ICSS_I2C_MODULE_ENABLE_BIT + UPDATE_NEXT_LOCAL_STATE CHECK_SETUP_COMMAND + +RESET_MODE_RETURN: + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; In this state, firmware is only out of reset +; The only command it can accept in the state is setup command. +; if any other command is passed it will send invalid command response back +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +CHECK_SETUP_COMMAND: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + LDI TEMP_REG4, 0 + LDI TEMP_REG4.w2, ICSS_I2C_SETUP_CMD + .endif + + QBEQ CHECK_SETUP_COMMAND_RETURN, TEMP_REG4.w2, 0x00 + QBNE CHECK_SETUP_COMMAND_ERROR, TEMP_REG4.w2, ICSS_I2C_SETUP_CMD + + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_PRU_PIN_NUM + STATE_TASK_OVER + +CHECK_SETUP_COMMAND_ERROR: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_ERROR + LDI TEMP_REG4.w0, INVALID_COMMAND + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +CHECK_SETUP_COMMAND_RETURN: + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This state load the PRU pins no. for the instance. +; SCL -> PRU GPO and SDA -> PRU GPI pins numbers +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_PRU_PIN_NUM: + LBBO &R14, R10, ICSS_I2C_PRU_PIN_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + LDI R14.b0, 1 + LDI R14.b1, 2 + .endif + + LDI R14.b3, 0x00 + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_INST_ID + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This instance id of the FW is being loaded into the register. +; This id helps the FW to decide which bit to raise high when raising an interrupt. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_INST_ID: + LBBO &R14.b3, R10, ICSS_I2C_PRU_INST_ID_OFFSET, 1 + + ;debug code + .if $defined("DEBUG_CODE") + LDI R14.b3, 0 + .endif + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_SCL_SDA_HIGH + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This set the SCL clk line and SDA data line high. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_SCL_SDA_HIGH: + ; Open-drain bus: R30 keeps the SCL and SDA bits at 0 and the lines are + ; switched with their OUTDISABLE bits (see SET_SCL_PIN_HIGH). Start with + ; both lines released, which is also the idle state of the bus. + LDI32 R26, I2C_GPIO_OUT_CTRL + LBBO &R23, R26, 0, 4 + CLR R30, R30, R14.b0 + CLR R30, R30, R14.b1 + SET R23, R23, R14.b0 + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_TX_FIFO_SIZE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the Tx fifo size of the firmware +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_TX_FIFO_SIZE: + LBBO &R16.b2, R10, ICSS_I2C_BUF_OFFSET, 1 + + ;debug code + .if $defined("DEBUG_CODE") + LDI R16.b2, 12 + .endif + + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_RX_FIFO_SIZE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the Rx fifo size of the firmware +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_RX_FIFO_SIZE: + LBBO &R16.b3, R10, ICSS_I2C_BUF_OFFSET+1, 1 + + ;debug code + .if $defined("DEBUG_CODE") + LDI R16.b3, 12 + .endif + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_MASTER_SLAVE_MODE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the firmware into master or slave mode +; currently only master mode is supported. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_MASTER_SLAVE_MODE: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + SET TEMP_REG4, TEMP_REG4, ICSS_I2C_MASTER_SLAVE_MODE_BIT + .endif + + QBBC SETUP_I2C_MASTER_SLAVE_ERROR, TEMP_REG4, ICSS_I2C_MASTER_SLAVE_MODE_BIT + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_ADDRESSING_MODE + STATE_TASK_OVER + +SETUP_I2C_MASTER_SLAVE_ERROR: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_ERROR + LDI TEMP_REG4.w0, MASTER_SLAVE_MODE_FAILED + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the firmware for 10 bits or 8 bits addressing mode +; currently only 7 bits mode is supported. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_ADDRESSING_MODE: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + QBBS SETUP_I2C_ADDRESSING_10BIT, TEMP_REG4, ICSS_I2C_ADDRESSING_MODE_BIT + CLR R16, R16, ICSS_I2C_ADDRESSING_MODE_BIT + JMP SETUP_I2C_ADDRESSING_DONE + +SETUP_I2C_ADDRESSING_10BIT: + SET R16, R16, ICSS_I2C_ADDRESSING_MODE_BIT + +SETUP_I2C_ADDRESSING_DONE: + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_START_CTRL + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the firmware for sending start bit at beginning or not +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_START_CTRL: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + SET TEMP_REG4, TEMP_REG4, ICSS_I2C_START_BIT + .endif + + QBBC SETUP_I2C_NO_START_CTRL, TEMP_REG4, ICSS_I2C_START_BIT + SET R16, R16, ICSS_I2C_START_BIT + JMP SETUP_I2C_START_DONE + +SETUP_I2C_NO_START_CTRL: + CLR R16, R16, ICSS_I2C_START_BIT + +SETUP_I2C_START_DONE: + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_STOP_CTRL + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the firmware for sending stop bit at end of data transfer +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_STOP_CTRL: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + SET TEMP_REG4, TEMP_REG4, ICSS_I2C_STOP_BIT + .endif + + QBBC SETUP_I2C_NO_STOP_CTRL, TEMP_REG4, ICSS_I2C_STOP_BIT + SET R16, R16, ICSS_I2C_STOP_BIT + JMP SETUP_I2C_STOP_DONE + +SETUP_I2C_NO_STOP_CTRL: + CLR R16, R16, ICSS_I2C_STOP_BIT + +SETUP_I2C_STOP_DONE: + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_NACK_CTRL + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; This configures the firmware for ending the read operation with NACK or not +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_NACK_CTRL: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + SET TEMP_REG4, TEMP_REG4, ICSS_I2C_RECIEVE_NACK_BIT + .endif + + QBBC SETUP_I2C_NO_NACK_CTRL, TEMP_REG4, ICSS_I2C_RECIEVE_NACK_BIT + SET R16, R16, ICSS_I2C_RECIEVE_NACK_BIT + JMP SETUP_I2C_NACK_DONE + + + +SETUP_I2C_NO_NACK_CTRL: + CLR R16, R16, ICSS_I2C_RECIEVE_NACK_BIT + +SETUP_I2C_NACK_DONE: + UPDATE_NEXT_LOCAL_STATE SETUP_I2C_SMBUS_CTRL + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; SMBus PEC enable and the SCL-low (clock stretching) timeout +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SETUP_I2C_SMBUS_CTRL: + LBBO &TEMP_REG4, R10, ICSS_I2C_CON_OFFSET, 4 + CLR R16, R16, ICSS_I2C_PEC_BIT + QBBC SETUP_I2C_NO_PEC, TEMP_REG4, ICSS_I2C_PEC_BIT + SET R16, R16, ICSS_I2C_PEC_BIT +SETUP_I2C_NO_PEC: + LBBO &R18.w2, R10, ICSS_I2C_SCL_TIMEOUT_OFFSET, 2 + LDI R18.w0, 0 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + + ;debug code + .if $defined("DEBUG_CODE") + UPDATE_NEXT_LOCAL_STATE FIRMWARE_READY + .endif + + LDI TEMP_REG4.w0, COMMAND_SUCCESS + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Set the MMap for host to find out which instance raised the interrupt. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RAISE_HOST_INTERRUPT_MEM_FOR_ERROR: + RAISE_INTERRUPT_MEM_FOR_HOST RAISE_HOST_INTERRUPT_FOR_ERROR + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Raise interrupt for Host while the firmware was trying to configure +; setup procedures. +; after raising the interrupt wait for host to respond. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RAISE_HOST_INTERRUPT_FOR_ERROR: + RAISE_INTERRUPT_FOR_HOST CHECK_HOST_INTERRUPT_ERROR_RECEIVED + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; check for host to receive the command response +; then jump to "reset" mode again for reconfiguration +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +CHECK_HOST_INTERRUPT_ERROR_RECEIVED: + CHECK_INTERRUPT_RECEIVED RESET_MODE, RAISE_HOST_INTERRUPT_FOR_ERROR + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Set the MMap for host to find out which instance raised the interrupt. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RAISE_HOST_INTERRUPT_MEM_FOR_READY: + RAISE_INTERRUPT_MEM_FOR_HOST RAISE_HOST_INTERRUPT_FOR_READY + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Raise interrupt for Host while the firmware succesfully does setup configuration +; but fails to any transaction i.e. read or write. +; after raising the interrupt wait for host to respond. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RAISE_HOST_INTERRUPT_FOR_READY: + RAISE_INTERRUPT_FOR_HOST CHECK_HOST_INTERRUPT_READY_RECEIVED + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; check for host to receive the command response +; then jump to "firmware ready" mode again to do a transaction again +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +CHECK_HOST_INTERRUPT_READY_RECEIVED: + CHECK_INTERRUPT_RECEIVED FIRMWARE_READY, RAISE_HOST_INTERRUPT_FOR_READY + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; In this state, firmware is out of reset succesfully +; firmware is ready to accept any command and check if the command word is not "0x0000" +; then start to check which command is passed. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +FIRMWARE_READY: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + LDI TEMP_REG4.w2, ICSS_I2C_TX_CMD + .endif + + QBEQ FIRMWARE_READY_RETURN, TEMP_REG4.w2, 0x00 + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_RESET_CMD_CHECK + +FIRMWARE_READY_RETURN: + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the reset command has been passed. +; if reset command is passed then resets the firmware else check for another command +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_RESET_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + ;;LDI TEMP_REG4.w2, ICSS_I2C_TX_CMD + LDI TEMP_REG4.w2, ICSS_I2C_RX_CMD + .endif + + QBNE ICSS_I2C_RESET_CMD_CHECK_RETURN, TEMP_REG4.w2, ICSS_I2C_RESET_CMD + UPDATE_NEXT_LOCAL_STATE RESET_SCL_SDA_HIGH + LDI TEMP_REG4.w0, COMMAND_SUCCESS + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +ICSS_I2C_RESET_CMD_CHECK_RETURN: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_SETUP_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; set the value on iep gpo enable register to high value +; this will pull the line to high impedence and open drain will keep the line high +; set the value on iep gpo to low value for pulling the line +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SCL_SDA_HIGH: + SET_SDA_PIN_HIGH + SET_SCL_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_ERROR + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the setup command has been passed. +; if setup command is passed then redo the firmware setup procedure +; else check for another command +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_SETUP_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + ;;LDI TEMP_REG4.w2, ICSS_I2C_TX_CMD + LDI TEMP_REG4.w2, ICSS_I2C_RX_CMD + .endif + + QBNE ICSS_I2C_SETUP_CMD_CHECK_RETURN, TEMP_REG4.w2, ICSS_I2C_SETUP_CMD + UPDATE_NEXT_LOCAL_STATE RESET_MODE + STATE_TASK_OVER + +ICSS_I2C_SETUP_CMD_CHECK_RETURN: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_RX_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the Rx command has been passed. +; if Rx command is passed then start receive data procedure +; else check for another command +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_RX_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + ;;LDI TEMP_REG4.w2, ICSS_I2C_TX_CMD + LDI TEMP_REG4.w2, ICSS_I2C_RX_CMD + .endif + + QBNE ICSS_I2C_RX_CMD_CHECK_RETURN, TEMP_REG4.w2, ICSS_I2C_RX_CMD + UPDATE_NEXT_LOCAL_STATE RX_MODE + STATE_TASK_OVER + +ICSS_I2C_RX_CMD_CHECK_RETURN: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_TX_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the Tx command has been passed. +; if Tx command is passed then start transmit data procedure +; else check for another command +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_TX_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + + ;debug code + .if $defined("DEBUG_CODE") + LDI TEMP_REG4.w2, ICSS_I2C_TX_CMD + .endif + + QBNE ICSS_I2C_TX_CMD_CHECK_RETURN, TEMP_REG4.w2, ICSS_I2C_TX_CMD + UPDATE_NEXT_LOCAL_STATE TX_MODE + STATE_TASK_OVER + +ICSS_I2C_TX_CMD_CHECK_RETURN: + UPDATE_NEXT_LOCAL_STATE ICSS_SMBUS_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; SMBus commands (ICSS_SMBUS_QUICK_CMD .. ICSS_SMBUS_BLOCK_READ_CMD) start an +; SMBus transfer. Every other command is passed on to the next check. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_SMBUS_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + QBLT ICSS_SMBUS_CMD_CHECK_NEXT, TEMP_REG4.w2, ICSS_SMBUS_BLOCK_READ_CMD + QBGT ICSS_SMBUS_CMD_CHECK_NEXT, TEMP_REG4.w2, ICSS_SMBUS_QUICK_CMD + UPDATE_NEXT_LOCAL_STATE SMBUS_MODE + STATE_TASK_OVER + +ICSS_SMBUS_CMD_CHECK_NEXT: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_READ_SCL_CMD_CHECK + STATE_TASK_OVER + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the I2C read SCL command has been passed. +; if this command requires the host to change the pinmux to input for SCL pin +; else no matching command has been found +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_READ_SCL_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + QBNE ICSS_I2C_READ_SCL_CMD_CHECK_NEXT, TEMP_REG4.w2, ICSS_I2C_READ_SCL_CMD + UPDATE_NEXT_LOCAL_STATE READ_SCL_PIN_SETUP + STATE_TASK_OVER + +ICSS_I2C_READ_SCL_CMD_CHECK_NEXT: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_RESET_SLAVE_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the I2C reset slave command has been passed. +; if this command will send 9 clock pulse to device for reseting it. +; else no matching command has been found +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_RESET_SLAVE_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + QBNE ICSS_I2C_RESET_SLAVE_CMD_CHECK_NEXT, TEMP_REG4.w2, ICSS_I2C_RESET_SLAVE_CMD + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_BEGIN + STATE_TASK_OVER + +ICSS_I2C_RESET_SLAVE_CMD_CHECK_NEXT: + UPDATE_NEXT_LOCAL_STATE ICSS_I2C_LOOPBACK_CMD_CHECK + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; checks if the I2C reset slave command has been passed. +; if this command will send 9 clock pulse to device for reseting it. +; else no matching command has been found +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ICSS_I2C_LOOPBACK_CMD_CHECK: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + QBNE ICSS_I2C_LOOPBACK_CMD_CHECK_NEXT, TEMP_REG4.w2, ICSS_I2C_LOOPBACK_CMD + UPDATE_NEXT_LOCAL_STATE LOOPBACK_DATA_COUNT + STATE_TASK_OVER + +ICSS_I2C_LOOPBACK_CMD_CHECK_NEXT: + UPDATE_NEXT_LOCAL_STATE FIRMWARE_READY_COMMAND_ERROR + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; no known command has been matched with passed cmd +; raise an interrupt and respond with error reponse word +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +FIRMWARE_READY_COMMAND_ERROR: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + LDI TEMP_REG4.w0, INVALID_COMMAND + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; I2C write: send the Tx buffer to the target +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +TX_MODE: + CLR R16, R16, ICSS_I2C_READ_WRITE_BIT + I2C_TRANSFER_INIT + UPDATE_NEXT_GLOBAL_STATE TX_DATA_SDA_BEGIN + UPDATE_NEXT_LOCAL_STATE SET_SCL_SDA_HIGH + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; I2C read: read the data count from the target into the Rx buffer +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RX_MODE: + SET R16, R16, ICSS_I2C_READ_WRITE_BIT + I2C_TRANSFER_INIT + UPDATE_NEXT_GLOBAL_STATE RX_DATA_SDA_BEGIN + UPDATE_NEXT_LOCAL_STATE SET_SCL_SDA_HIGH + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; SMBus command: decode the protocol and describe the transfer. +; +; A transfer is a write phase (the "stream": optional command code and +; block count prefix bytes, the Tx buffer, optional PEC) followed, for the +; read protocols, by a repeated START and a read phase into the Rx buffer. +; The prefix bytes are staged at the two bytes just below the Tx buffer +; (instance offsets 0xFE/0xFF), so the stream is contiguous from R11. +; +; protocol write phase read phase +; quick (address only, R/W = command code bit 0) +; send byte cmd +; receive byte 1 byte +; write byte cmd, Tx[0] +; write word cmd, Tx[0] (low), Tx[1] (high) +; block write cmd, N = count, Tx[0..N-1] +; read byte cmd Sr, 1 byte +; read word cmd Sr, 2 bytes (low first) +; block read cmd Sr, N, N bytes (N -> count) +; +; With PEC enabled (CON ICSS_I2C_PEC_BIT) a write-only transfer ends with +; the PEC byte and a read phase reads one more byte, the target's PEC, +; which is checked. Quick command has no PEC. 10-bit addressing is not +; supported for SMBus. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SMBUS_MODE: + LBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 4 + QBBS SMBUS_MODE_10BIT, R16, ICSS_I2C_ADDRESSING_MODE_BIT + I2C_TRANSFER_INIT + SET R19.b3, R19.b3, SMB_F_SMB + LBBO &R19.b1, R10, ICSS_I2C_PRU_CMD_CODE_OFFSET, 1 + CLR R16, R16, ICSS_I2C_READ_WRITE_BIT + UPDATE_NEXT_GLOBAL_STATE TX_DATA_SDA_BEGIN + QBEQ SMBUS_MODE_QUICK, TEMP_REG4.w2, ICSS_SMBUS_QUICK_CMD + QBBC SMBUS_MODE_NO_PEC, R16, ICSS_I2C_PEC_BIT + SET R19.b3, R19.b3, SMB_F_PEC +SMBUS_MODE_NO_PEC: + QBEQ SMBUS_MODE_RECEIVE_BYTE, TEMP_REG4.w2, ICSS_SMBUS_RECEIVE_BYTE_CMD + ; every other protocol starts with the command code + LDI TEMP_REG5, ICSS_I2C_INSTANCE0_TX_MEM - 1 + SBBO &R19.b1, TEMP_REG5, 0, 1 + LDI R11.w0, ICSS_I2C_INSTANCE0_TX_MEM - 1 + LDI R15.b3, 1 + QBEQ SMBUS_MODE_WRITE, TEMP_REG4.w2, ICSS_SMBUS_SEND_BYTE_CMD + LDI R15.b3, 2 + QBEQ SMBUS_MODE_WRITE, TEMP_REG4.w2, ICSS_SMBUS_WRITE_BYTE_CMD + LDI R15.b3, 3 + QBEQ SMBUS_MODE_WRITE, TEMP_REG4.w2, ICSS_SMBUS_WRITE_WORD_CMD + QBEQ SMBUS_MODE_BLOCK_WRITE, TEMP_REG4.w2, ICSS_SMBUS_BLOCK_WRITE_CMD + ; read byte / read word / block read: write the command code, then read + LDI R15.b3, 1 + SET R19.b3, R19.b3, SMB_F_RDPHASE + LDI R17.b2, 1 + QBEQ SMBUS_MODE_READ, TEMP_REG4.w2, ICSS_SMBUS_READ_BYTE_CMD + LDI R17.b2, 2 + QBEQ SMBUS_MODE_READ, TEMP_REG4.w2, ICSS_SMBUS_READ_WORD_CMD + SET R19.b3, R19.b3, SMB_F_BLKRD +SMBUS_MODE_READ: + QBBC SMBUS_MODE_START, R19.b3, SMB_F_PEC + SET R19.b3, R19.b3, SMB_F_PECRX + JMP SMBUS_MODE_START + +SMBUS_MODE_BLOCK_WRITE: + ; N = data count, 1..SMBUS_BLOCK_MAX_LEN (SMBUS_BLOCK_MAX_LEN_PEC with + ; PEC) so that cmd, N, data and PEC fit the 8-bit stream index + LBBO &TEMP_REG4.w0, R10, ICSS_I2C_CNT_OFFSET, 2 + QBEQ SMBUS_MODE_COUNT_ERROR, TEMP_REG4.w0, 0 + LDI TEMP_REG6.w0, SMBUS_BLOCK_MAX_LEN + QBBC SMBUS_MODE_BLOCK_MAX, R19.b3, SMB_F_PEC + LDI TEMP_REG6.w0, SMBUS_BLOCK_MAX_LEN_PEC +SMBUS_MODE_BLOCK_MAX: + QBLT SMBUS_MODE_COUNT_ERROR, TEMP_REG4.w0, TEMP_REG6.w0 + LDI TEMP_REG5, ICSS_I2C_INSTANCE0_TX_MEM - 2 + SBBO &R19.b1, TEMP_REG5, 0, 1 + SBBO &TEMP_REG4.b0, TEMP_REG5, 1, 1 + LDI R11.w0, ICSS_I2C_INSTANCE0_TX_MEM - 2 + ADD R15.b3, TEMP_REG4.b0, 2 +SMBUS_MODE_WRITE: + QBBC SMBUS_MODE_START, R19.b3, SMB_F_PEC + SET R19.b3, R19.b3, SMB_F_PECTX + ADD R15.b3, R15.b3, 1 + JMP SMBUS_MODE_START + +SMBUS_MODE_RECEIVE_BYTE: + SET R16, R16, ICSS_I2C_READ_WRITE_BIT + UPDATE_NEXT_GLOBAL_STATE RX_DATA_SDA_BEGIN + LDI R15.b3, 1 + QBBC SMBUS_MODE_START, R19.b3, SMB_F_PEC + SET R19.b3, R19.b3, SMB_F_PECRX + LDI R15.b3, 2 + JMP SMBUS_MODE_START + +SMBUS_MODE_QUICK: + ; address only; the R/W bit is bit 0 of the command code + QBBC SMBUS_MODE_QUICK_W, R19.b1, 0 + SET R16, R16, ICSS_I2C_READ_WRITE_BIT +SMBUS_MODE_QUICK_W: + LDI R15.b3, 0 + UPDATE_NEXT_GLOBAL_STATE DATA_PROCESSING_COMPLETE + +SMBUS_MODE_START: + UPDATE_NEXT_LOCAL_STATE SET_SCL_SDA_HIGH + STATE_TASK_OVER + +SMBUS_MODE_COUNT_ERROR: + LDI TEMP_REG4.w0, INVALID_DATA_COUNT + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +SMBUS_MODE_10BIT: + LDI TEMP_REG4.w0, ADDRESSING_MODE_FAILED + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; release both lines before the START condition +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SET_SCL_SDA_HIGH: + SET_SDA_PIN_HIGH + SET_SCL_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE SLAVE_ADDRESS_SETUP + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; read the slave address from configuration registers. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SLAVE_ADDRESS_SETUP: + READ_ADDRESS_REGISTER SLAVE_ADDRESS_RW_SETUP + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; configure the read/write bit in the slave address register for transmission +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SLAVE_ADDRESS_RW_SETUP: + READ_RW_REGISTER_BIT DATA_COUNT + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; I2C: read the number of bytes to read or write and load the first byte. +; SMBus: the length was set by SMBUS_MODE, only load the first byte. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +DATA_COUNT: + QBBS DATA_COUNT_SMBUS, R19.b3, SMB_F_SMB + LBBO &TEMP_REG4.w0, R10, ICSS_I2C_CNT_OFFSET, 2 + + ;debug code + .if $defined("DEBUG_CODE") + ; fif count + LDI TEMP_REG4.w0, 1 + .endif + + QBLT DATA_COUNT_ERROR, TEMP_REG4.w0, 0xFF + QBGT DATA_COUNT_ERROR, TEMP_REG4.w0, 0x01 + + AND R15.b3, TEMP_REG4.b0, 0xFF + AND R15.b2, R15.b2, 0x00 + LBBO &R15.b1, R11, R15.b2, 1 + + UPDATE_NEXT_LOCAL_STATE START_CONDITION_SDA_LOW + STATE_TASK_OVER + +DATA_COUNT_SMBUS: + QBBS DATA_COUNT_SMBUS_DONE, R16, ICSS_I2C_READ_WRITE_BIT + QBEQ DATA_COUNT_SMBUS_DONE, R15.b3, 0 + TX_FETCH_BYTE R15.b1 +DATA_COUNT_SMBUS_DONE: + UPDATE_NEXT_LOCAL_STATE START_CONDITION_SDA_LOW + STATE_TASK_OVER + +DATA_COUNT_ERROR: + LDI TEMP_REG4.w0, INVALID_DATA_COUNT + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; START condition: SDA low while SCL is high. SMBus always sends START. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +START_CONDITION_SDA_LOW: + WAIT_SCL_HIGH + QBBS START_CONDITION_SDA_LOW_DO, R19.b3, SMB_F_SMB + QBBC START_CONDITION_SDA_LOW_RETURN, R16, ICSS_I2C_START_BIT +START_CONDITION_SDA_LOW_DO: + SET_SDA_PIN_LOW +START_CONDITION_SDA_LOW_RETURN: + UPDATE_NEXT_LOCAL_STATE START_CONDITION_HOLD + STATE_TASK_OVER + +; START hold time (tHD;STA): one more tick with SDA low and SCL high, so it +; is two ticks long (5 us at 100 kHz, Standard-mode/SMBus needs 4.0 us) +START_CONDITION_HOLD: + UPDATE_NEXT_LOCAL_STATE START_CONDITION_SCL_LOW + STATE_TASK_OVER + +START_CONDITION_SCL_LOW: + QBBS START_CONDITION_SCL_LOW_DO, R19.b3, SMB_F_SMB + QBBC START_CONDITION_SCL_LOW_RETURN, R16, ICSS_I2C_START_BIT +START_CONDITION_SCL_LOW_DO: + SET_SCL_PIN_LOW +START_CONDITION_SCL_LOW_RETURN: + UPDATE_NEXT_LOCAL_STATE ADDRESS_SDA_BEGIN + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; address byte(s): put the next address bit on SDA (SCL is low) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +ADDRESS_SDA_BEGIN: + RSB TEMP_REG5.b0, R15.b0, 15 + QBBC ADDRESS_SDA_LOW, R13.w2, TEMP_REG5.b0 + SET_SDA_PIN_HIGH + JMP ADDRESS_SDA_CONTINUE +ADDRESS_SDA_LOW: + SET_SDA_PIN_LOW +ADDRESS_SDA_CONTINUE: + PEC_UPDATE R13.w2, TEMP_REG5.b0 + ADD R15.b0, R15.b0, 0x01 + UPDATE_NEXT_LOCAL_STATE ADDRESS_SCL_BEGIN + STATE_TASK_OVER + +ADDRESS_SCL_BEGIN: + SET_SCL_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE ADDRESS_SDA_READ + STATE_TASK_OVER + +ADDRESS_SDA_READ: + WAIT_SCL_HIGH + UPDATE_NEXT_LOCAL_STATE ADDRESS_SCL_END + STATE_TASK_OVER + +; pull SCL low; after the 8th bit release SDA on this same edge, so the +; target can drive its ACK (SCL is already low, so this is not a STOP) +ADDRESS_SCL_END: + SET_SCL_PIN_LOW + QBGT SDA_NEXT_BIT, R15.b0, 0x08 + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE ADDRESS_ACK_BEGIN + STATE_TASK_OVER + +SDA_NEXT_BIT: + UPDATE_NEXT_LOCAL_STATE ADDRESS_SDA_BEGIN + STATE_TASK_OVER + +; SDA was released in ADDRESS_SCL_END; this tick keeps the 4-tick bit timing +ADDRESS_ACK_BEGIN: + UPDATE_NEXT_LOCAL_STATE ADDRESS_ACK_SCL_BEGIN + STATE_TASK_OVER + +ADDRESS_ACK_SCL_BEGIN: + SET_SCL_PIN_HIGH + AND R15.b0, R15.b0, 0x00 + UPDATE_NEXT_LOCAL_STATE ADDRESS_ACK_READ + STATE_TASK_OVER + +ADDRESS_ACK_READ: + WAIT_SCL_HIGH + READ_SDA_PIN_ACK + UPDATE_NEXT_LOCAL_STATE ADDRESS_ACK_SCL_END + STATE_TASK_OVER + +; pull SCL low; on ACK continue with the second address byte (10-bit) or +; the data phase in R17.w0, on NACK abandon the transfer +ADDRESS_ACK_SCL_END: + SET_SCL_PIN_LOW + QBBS ADDRESS_ACK_NOT_RECIEVED, R16, ICSS_I2C_ACK_RECIEVED_BIT + QBBC ADDRESS_ACK_SCL_END_DONE, R16, ICSS_I2C_ADDRESSING_MODE_BIT + QBEQ ADDRESS_ACK_SCL_END_DONE, R15.b2, 0x01 + ADD R15.b2, R15.b2, 0x01 + UPDATE_NEXT_LOCAL_STATE ADDRESS_SDA_BEGIN + STATE_TASK_OVER + +ADDRESS_ACK_SCL_END_DONE: + AND R15.b2, R15.b2, 0x00 + COPY_LOCAL_TO_GLOBAL_STATE + STATE_TASK_OVER + +ADDRESS_ACK_NOT_RECIEVED: + UPDATE_NEXT_LOCAL_STATE NO_ADDRESS_ACK_RECIEVED + STATE_TASK_OVER + +; no ACK for the address: report it and end the transfer with a STOP +NO_ADDRESS_ACK_RECIEVED: + LDI TEMP_REG4.w0, ADDRESS_ACKNOWLDEGE_FAILED + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + SET R19.b3, R19.b3, SMB_F_ERR + UPDATE_NEXT_LOCAL_STATE DATA_PROCESSING_COMPLETE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; write phase: send the stream and check each ACK +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +TX_DATA_SDA_BEGIN: + SEND_TX_DATA_CHECK_FOR_ACK R15.b1, TX_PHASE_DONE, TX_DATA_NACK + +; the stream is sent: SMBus reads continue with a repeated START +TX_PHASE_DONE: + QBBS TX_PHASE_DONE_READ, R19.b3, SMB_F_RDPHASE + UPDATE_NEXT_LOCAL_STATE DATA_PROCESSING_COMPLETE + STATE_TASK_OVER +TX_PHASE_DONE_READ: + UPDATE_NEXT_LOCAL_STATE RSTART_SDA_HIGH + STATE_TASK_OVER + +; no ACK for a data byte (DATA_ACKNOWLDEGE_FAILED is already reported): +; end the transfer with a STOP +TX_DATA_NACK: + SET R19.b3, R19.b3, SMB_F_ERR + UPDATE_NEXT_LOCAL_STATE DATA_PROCESSING_COMPLETE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; repeated START (Sr) for the read phase of an SMBus read: release SDA and +; SCL, then SDA low while SCL is high, then the address byte with R/W = 1 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RSTART_SDA_HIGH: + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE RSTART_SCL_HIGH + STATE_TASK_OVER + +RSTART_SCL_HIGH: + SET_SCL_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE RSTART_SETUP + STATE_TASK_OVER + +; repeated START setup time (tSU;STA): SCL high for two ticks before SDA falls +RSTART_SETUP: + WAIT_SCL_HIGH + UPDATE_NEXT_LOCAL_STATE RSTART_SDA_LOW + STATE_TASK_OVER + +RSTART_SDA_LOW: + SET_SDA_PIN_LOW + CLR R19.b3, R19.b3, SMB_F_RDPHASE + SET R16, R16, ICSS_I2C_READ_WRITE_BIT + SET R13.w2, R13.w2, 8 + LDI R15.w0, 0x0000 + MOV R15.b3, R17.b2 + QBBC RSTART_SDA_LOW_NO_PEC, R19.b3, SMB_F_PECRX + ADD R15.b3, R15.b3, 1 +RSTART_SDA_LOW_NO_PEC: + LDI R15.b2, 0x00 + UPDATE_NEXT_GLOBAL_STATE RX_DATA_SDA_BEGIN + UPDATE_NEXT_LOCAL_STATE RSTART_HOLD + STATE_TASK_OVER + +; repeated START hold time (tHD;STA) +RSTART_HOLD: + UPDATE_NEXT_LOCAL_STATE RSTART_SCL_LOW + STATE_TASK_OVER + +RSTART_SCL_LOW: + SET_SCL_PIN_LOW + UPDATE_NEXT_LOCAL_STATE ADDRESS_SDA_BEGIN + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; read phase: read bytes into the Rx buffer, ACK all but the last +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RX_DATA_SDA_BEGIN: + READ_RX_DATA_AND_SEND_ACK R15.b1, DATA_PROCESSING_COMPLETE + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; end of the transfer (SCL is low). Send STOP if CON asks for it, and always +; for SMBus and after an error. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +DATA_PROCESSING_COMPLETE: + SET_SDA_PIN_LOW + QBBS COMPLETE_WITH_STOP, R19.b3, SMB_F_SMB + QBBS COMPLETE_WITH_STOP, R19.b3, SMB_F_ERR + QBBC COMPLETE_WITH_NO_STOP, R16, ICSS_I2C_STOP_BIT +COMPLETE_WITH_STOP: + UPDATE_NEXT_LOCAL_STATE STOP_CONDITION_SCL_HIGH + STATE_TASK_OVER + +COMPLETE_WITH_NO_STOP: + UPDATE_NEXT_LOCAL_STATE NO_STOP_CONDITION_SDA_HIGH + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; STOP condition: release SCL, then release SDA while SCL is high. The bus +; is then idle with both lines released. Report the result unless an error +; was already reported; an SMBus read with PEC must end with a zero CRC. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +STOP_CONDITION_SCL_HIGH: + SET_SCL_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE STOP_CONDITION_SETUP + STATE_TASK_OVER + +; STOP setup time (tSU;STO): SCL high for two ticks before SDA rises +STOP_CONDITION_SETUP: + WAIT_SCL_HIGH + UPDATE_NEXT_LOCAL_STATE STOP_CONDITION_SDA_HIGH + STATE_TASK_OVER + +STOP_CONDITION_SDA_HIGH: + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + QBBS STOP_CONDITION_REPORTED, R19.b3, SMB_F_ERR + LDI TEMP_REG4.w0, COMMAND_SUCCESS + QBBC STOP_CONDITION_REPORT, R19.b3, SMB_F_PECRX + QBEQ STOP_CONDITION_REPORT, R19.b0, 0 + LDI TEMP_REG4.w0, PEC_ERROR +STOP_CONDITION_REPORT: + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 +STOP_CONDITION_REPORTED: + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; no STOP (I2C with CON STOP clear): release SDA, then SCL +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +NO_STOP_CONDITION_SDA_HIGH: + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE NO_STOP_CONDITION_SCL_HIGH + STATE_TASK_OVER + +NO_STOP_CONDITION_SCL_HIGH: + SET_SCL_PIN_HIGH + LDI TEMP_REG4.w0, COMMAND_SUCCESS + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; a target held SCL low for longer than the configured timeout: release +; both lines and report TIME_OUT_ERROR (no STOP is possible while SCL is +; held low) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +SCL_LOW_TIMEOUT: + SET_SDA_PIN_HIGH + SET_SCL_PIN_HIGH + LDI R18.w0, 0 + LDI TEMP_REG4.w0, TIME_OUT_ERROR + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; prepare to read clk value for 10 clk cycles +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +READ_SCL_PIN_SETUP: + LDI R15.w0, 0x0000 + LDI R15.w2, 0x0A00 + UPDATE_NEXT_LOCAL_STATE READ_SCL_PIN_VALUE + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; read the scl clk value for 10 clk cycles +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +READ_SCL_PIN_VALUE: + ADD R15.b0, R15.b0, 0x01 + QBBS SCL_PIN_VALUE_HIGH, R31, R14.b0 + ADD R15.b2, R15.b2, 0x01 + +SCL_PIN_VALUE_HIGH: + QBGT READ_SCL_PIN_VALUE_REPEAT, R15.b0, R15.b3 + UPDATE_NEXT_LOCAL_STATE READ_SCL_PIN_DONE + +READ_SCL_PIN_VALUE_REPEAT: + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; read scl pins for 10 cycles is done. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +READ_SCL_PIN_DONE: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + QBEQ SCL_PIN_READ_VALUE_LOW, R15.b0, R15.b2 + LDI TEMP_REG4.w0, SCL_VALUE_HIGH + JMP READ_SCL_PIN_DONE_RETURN + +SCL_PIN_READ_VALUE_LOW: + LDI TEMP_REG4.w0, SCL_VALUE_LOW + +READ_SCL_PIN_DONE_RETURN: + LDI R15.w0, 0x0000 + LDI R15.w2, 0x0000 + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; setup for reseting the slave +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_SCL_BEGIN: + LDI R15.w0, 0x0000 + LDI R15.w2, 0x0900 + ; Bus recovery: make sure SDA is released so a target that holds it low + ; can let go, then clock SCL until it does. SDA stays released afterwards, + ; as on an idle bus. + SET_SDA_PIN_HIGH + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_LOW + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; make SCL high, counting one clock pulse per rising edge +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_SCL_HIGH: + SET_SCL_PIN_HIGH + ADD R15.b0, R15.b0, 0x01 + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_WAIT2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; wait to match the timing parameters +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_SCL_WAIT1: + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_HIGH + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; make SCL low +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_SCL_LOW: + SET_SCL_PIN_LOW + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_WAIT1 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; wait to match the timing parameters; after 9 pulses SCL is left high +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_SCL_WAIT2: + QBGT RESET_SLAVE_SCL_RETURN, R15.b0, R15.b3 + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_RETURN + STATE_TASK_OVER + +RESET_SLAVE_SCL_RETURN: + UPDATE_NEXT_LOCAL_STATE RESET_SLAVE_SCL_LOW + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Finish reseting slave +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +RESET_SLAVE_RETURN: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + LDI TEMP_REG4.w0, RESET_SLAVE_DONE + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; Read the number of 8 bits data need to be copied over +; also initialize the data count and bit count register to 0 +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +LOOPBACK_DATA_COUNT: + LBBO &TEMP_REG4.w0, R10, ICSS_I2C_CNT_OFFSET, 2 + QBLT LOOPBACK_DATA_COUNT_ERROR, TEMP_REG4.w0, 0xFF + QBGT LOOPBACK_DATA_COUNT_ERROR, TEMP_REG4.w0, 0x01 + AND R15.b3, TEMP_REG4.b0, 0xFF + AND R15.b2, R15.b2, 0x00 + UPDATE_NEXT_LOCAL_STATE LOOPBACK_COPY_DATA + STATE_TASK_OVER + +LOOPBACK_DATA_COUNT_ERROR: + LDI TEMP_REG4.w0, INVALID_DATA_COUNT + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + STATE_TASK_OVER + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; copy data from Tx to Rx buffer. +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +LOOPBACK_COPY_DATA: + LBBO &R15.b1, R11, R15.b2, 1 + SBBO &R15.b1, R12, R15.b2, 1 + ADD R15.b2, R15.b2, 1 + QBGE LOOPBACK_COPY_DATA_RETURN, R15.b3, R15.b2 + STATE_TASK_OVER + +LOOPBACK_COPY_DATA_RETURN: + UPDATE_NEXT_LOCAL_STATE RAISE_HOST_INTERRUPT_MEM_FOR_READY + LDI TEMP_REG4.w0, COMMAND_SUCCESS + SBBO &TEMP_REG4, R10, ICSS_I2C_COMMAND_OFFSET, 2 + STATE_TASK_OVER + + + halt ; end of program diff --git a/examples/pru_i2c/makefile b/examples/pru_i2c/makefile new file mode 100644 index 000000000..800821250 --- /dev/null +++ b/examples/pru_i2c/makefile @@ -0,0 +1,98 @@ +include ../../imports.mak + +####################### +# project information # +####################### + +PROJECT_NAME := pru_i2c +SUPPORTED_PROCESSORS := am261x +# Does the PRU code have dependencies outside of the open-pru repo? +PRU_DEPENDENCIES := +# Use NON_PRU_DEPENDENCIES to select which makefiles to call for non-PRU cores +NON_PRU_DEPENDENCIES := mcuplus + +################### +# Prebuild checks # +################### +BUILD_PROJECT := y +DEVICE_NON_PRU := + +# Only build project if $(DEVICE) is in $(SUPPORTED_PROCESSORS) +ifeq (,$(findstring $(DEVICE),$(SUPPORTED_PROCESSORS))) +BUILD_PROJECT := n +MESSAGE := Project $(PROJECT_NAME) does not have a build option for $(DEVICE) +endif + +# Only build project if PRU dependencies exist +ifneq (,$(PRU_DEPENDENCIES)) +# MCU+ SDK dependency? +ifeq (mcuplus,$(findstring mcuplus,$(PRU_DEPENDENCIES))) +ifneq ($(BUILD_MCUPLUS),y) +BUILD_PROJECT := n +MESSAGE ?= Project $(PROJECT_NAME) depends on MCU+ SDK, but BUILD_MCUPLUS != y. +endif +endif +endif + +# Only build non-PRU code if the non-PRU code is enabled in imports.mak +ifeq ($(BUILD_MCUPLUS),y) +ifeq (mcuplus,$(findstring mcuplus,$(NON_PRU_DEPENDENCIES))) +DEVICE_NON_PRU += $(DEVICE)_mcuplus +endif +endif +ifeq ($(BUILD_LINUX),y) +ifeq (linux,$(findstring linux,$(NON_PRU_DEPENDENCIES))) +DEVICE_NON_PRU += $(DEVICE)_linux +endif +endif + +########################### +# Make and clean commands # +########################### + +ifeq ($(BUILD_PROJECT),y) +# "make" or "make all" builds projects that match $(DEVICE) set in imports.mak +# "make" builds PRU firmware first, then host (non-PRU) code +all: MESSAGE = "Building $(PROJECT_NAME) for $(DEVICE)" +all: pre_build_message + $(MAKE) pru + $(MAKE) host + +# "make pru" builds only PRU firmware for $(DEVICE) +pru: ARGUMENTS_PRU = all +pru: $(DEVICE) + +# "make host" builds only host (non-PRU) code for $(DEVICE) +host: ARGUMENTS_MCUPLUS = all +host: $(DEVICE_NON_PRU) + +# "make clean" cleans projects that match $(DEVICE) set in imports.mak +clean: ARGUMENTS_PRU = clean +clean: ARGUMENTS_MCUPLUS = scrub +clean: MESSAGE = "Cleaning $(PROJECT_NAME) for $(DEVICE)" +clean: pre_build_message $(DEVICE) $(DEVICE_NON_PRU) + +else +# if a prebuild check failed, print message and exit +all clean pru host: pre_build_message +endif + +pre_build_message: + @echo $(MESSAGE) + +###################### +# Target definitions # +###################### + +# provide target definitions for each supported processor +# PRU firmware should be built before any RTOS code that includes it +am261x: +# am261x-lp + $(MAKE) -C firmware/am261x-lp/icss_m0_pru0_fw/ti-pru-cgt $(ARGUMENTS_PRU) + $(MAKE) -C firmware/am261x-lp/icss_m0_pru1_fw/ti-pru-cgt $(ARGUMENTS_PRU) + +am261x_mcuplus: +# am261x-lp + $(MAKE) -C mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang $(ARGUMENTS_MCUPLUS) + +.PHONY: all clean pru host pre_build_message $(DEVICE) $(DEVICE_NON_PRU) $(SUPPORTED_PROCESSORS) diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/example.syscfg b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/example.syscfg new file mode 100644 index 000000000..0b7b84894 --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/example.syscfg @@ -0,0 +1,296 @@ +/** + * These arguments were used when this file was generated. They will be automatically applied on subsequent loads + * via the GUI or CLI. Run CLI with '--help' for additional information on how to override these arguments. + * @cliArgs --device "AM261x_ZFG" --part "AM2612" --package "ZFG" --context "r5fss0-0" --product "MCU_PLUS_SDK@07.03.01" + * @v2CliArgs --device "AM2612" --package "NFBGA (ZFG)" --context "r5fss0-0" --product "MCU_PLUS_SDK@07.03.01" + * @versions {"tool":"1.22.0+3893"} + */ + +/** + * Import the modules used in this configuration. + */ +const pruicss = scripting.addModule("/drivers/pruicss/pruicss", {}, false); +const pruicss1 = pruicss.addInstance(); +const debug_log = scripting.addModule("/kernel/dpl/debug_log"); +const dpl_cfg = scripting.addModule("/kernel/dpl/dpl_cfg"); +const mpu_armv7 = scripting.addModule("/kernel/dpl/mpu_armv7", {}, false); +const mpu_armv71 = mpu_armv7.addInstance(); +const mpu_armv72 = mpu_armv7.addInstance(); +const mpu_armv73 = mpu_armv7.addInstance(); +const mpu_armv74 = mpu_armv7.addInstance(); +const mpu_armv75 = mpu_armv7.addInstance(); +const mpu_armv76 = mpu_armv7.addInstance(); +const default_linker = scripting.addModule("/memory_configurator/default_linker", {}, false); +const default_linker1 = default_linker.addInstance(); +const general = scripting.addModule("/memory_configurator/general", {}, false); +const general1 = general.addInstance(); +const region = scripting.addModule("/memory_configurator/region", {}, false); +const region1 = region.addInstance(); +const section = scripting.addModule("/memory_configurator/section", {}, false); +const section1 = section.addInstance(); +const section2 = section.addInstance(); +const section3 = section.addInstance(); +const section4 = section.addInstance(); +const section5 = section.addInstance(); +const section6 = section.addInstance(); +const section7 = section.addInstance(); +const section8 = section.addInstance(); +const section9 = section.addInstance(); +const section10 = section.addInstance(); +const section11 = section.addInstance(); +const section12 = section.addInstance(); + +/** + * Write custom configuration values to the imported modules. + */ +pruicss1.$name = "CONFIG_PRU_ICSS0"; +pruicss1.instance = "ICSSM0"; +pruicss1.AdditionalICSSSettings[0].$name = "CONFIG_PRU_ICSS_IO0"; +pruicss1.AdditionalICSSSettings[0].PruGPIO.create(1); +pruicss1.AdditionalICSSSettings[0].PruGPIO[0].$name = "CONFIG_PRU_ICSS_GPIO0"; +/* I2C SCL: PR0_PRU1_GPIO18, open-drain, read back for clock stretching, + * internal pull-up (BoosterPack J1.4) */ +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO18.$assign = "GPIO120"; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO18.$used = true; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO18.rx = true; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO18.pu_pd = "pu"; +/* I2C SDA: PR0_PRU1_GPIO19, open-drain, internal pull-up (BoosterPack J1.3) */ +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO19.$assign = "GPIO119"; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO19.$used = true; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO19.rx = true; +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].PR0_PRU1_GPIO19.pu_pd = "pu"; + +debug_log.enableUartLog = true; +debug_log.uartLog.$name = "CONFIG_UART0"; +debug_log.uartLog.UART.$assign = "UART0"; +debug_log.uartLog.UART.RXD.$assign = "GPIO27"; +debug_log.uartLog.UART.TXD.$assign = "GPIO28"; +debug_log.uartLog.child.$name = "drivers_uart_v2_uart_v2_template0"; + +mpu_armv71.$name = "CONFIG_MPU_REGION0"; +mpu_armv71.size = 31; +mpu_armv71.attributes = "Device"; +mpu_armv71.accessPermissions = "Supervisor RD+WR, User RD"; +mpu_armv71.allowExecute = false; + +mpu_armv72.$name = "CONFIG_MPU_REGION1"; +mpu_armv72.size = 15; +mpu_armv72.accessPermissions = "Supervisor RD+WR, User RD"; + +mpu_armv73.$name = "CONFIG_MPU_REGION2"; +mpu_armv73.baseAddr = 0x80000; +mpu_armv73.size = 15; +mpu_armv73.accessPermissions = "Supervisor RD+WR, User RD"; + +mpu_armv74.$name = "CONFIG_MPU_REGION3"; +mpu_armv74.accessPermissions = "Supervisor RD+WR, User RD"; +mpu_armv74.baseAddr = 0x70000000; +mpu_armv74.size = 21; + +mpu_armv75.$name = "CONFIG_MPU_REGION4"; +mpu_armv75.size = 14; +mpu_armv75.baseAddr = 0x50D00000; +mpu_armv75.allowExecute = false; +mpu_armv75.attributes = "Device"; + +mpu_armv76.$name = "CONFIG_MPU_REGION5"; +mpu_armv76.size = 14; +mpu_armv76.allowExecute = false; +mpu_armv76.attributes = "NonCached"; +mpu_armv76.baseAddr = 0x72000000; + +default_linker1.$name = "memory_configurator_default_linker0"; + +general1.$name = "CONFIG_GENERAL0"; +general1.linker.$name = "TIARMCLANG0"; + +region1.$name = "MEMORY_REGION_CONFIGURATION0"; +region1.memory_region.create(11); +region1.memory_region[0].type = "TCMA"; +region1.memory_region[0].$name = "R5F_VECS"; +region1.memory_region[0].size = 0x40; +region1.memory_region[0].auto = false; +region1.memory_region[1].type = "TCMA"; +region1.memory_region[1].$name = "R5F_TCMA"; +region1.memory_region[1].size = 0x7FC0; +region1.memory_region[2].type = "TCMB"; +region1.memory_region[2].size = 0x8000; +region1.memory_region[2].$name = "R5F_TCMB"; +region1.memory_region[3].$name = "SBL"; +region1.memory_region[3].auto = false; +region1.memory_region[3].size = 0x40000; +region1.memory_region[4].$name = "OCRAM"; +region1.memory_region[4].auto = false; +region1.memory_region[4].manualStartAddress = 0x70040000; +region1.memory_region[4].size = 0x40000; +region1.memory_region[5].type = "FLASH"; +region1.memory_region[5].auto = false; +region1.memory_region[5].manualStartAddress = 0x60100000; +region1.memory_region[5].size = 0x80000; +region1.memory_region[5].$name = "FLASH"; +region1.memory_region[6].$name = "USER_SHM_MEM"; +region1.memory_region[6].auto = false; +region1.memory_region[6].manualStartAddress = 0x70150000; +region1.memory_region[6].size = 0x4000; +region1.memory_region[6].isShared = true; +region1.memory_region[6].shared_cores = ["r5fss0-1"]; +region1.memory_region[7].$name = "LOG_SHM_MEM"; +region1.memory_region[7].auto = false; +region1.memory_region[7].manualStartAddress = 0x70154000; +region1.memory_region[7].size = 0x4000; +region1.memory_region[7].isShared = true; +region1.memory_region[7].shared_cores = ["r5fss0-1"]; +region1.memory_region[8].type = "CUSTOM"; +region1.memory_region[8].$name = "RTOS_NORTOS_IPC_SHM_MEM"; +region1.memory_region[8].auto = false; +region1.memory_region[8].manualStartAddress = 0x72000000; +region1.memory_region[8].size = 0x3E80; +region1.memory_region[8].isShared = true; +region1.memory_region[8].shared_cores = ["r5fss0-1"]; +region1.memory_region[9].type = "CUSTOM"; +region1.memory_region[9].$name = "MAILBOX_HSM"; +region1.memory_region[9].auto = false; +region1.memory_region[9].manualStartAddress = 0x44000000; +region1.memory_region[9].size = 0x3CE; +region1.memory_region[9].isShared = true; +region1.memory_region[9].shared_cores = ["r5fss0-1"]; +region1.memory_region[10].type = "CUSTOM"; +region1.memory_region[10].$name = "MAILBOX_R5F"; +region1.memory_region[10].auto = false; +region1.memory_region[10].manualStartAddress = 0x44000400; +region1.memory_region[10].size = 0x3CE; +region1.memory_region[10].isShared = true; +region1.memory_region[10].shared_cores = ["r5fss0-1"]; + +section1.load_memory = "R5F_VECS"; +section1.group = false; +section1.$name = "Vector Table"; +section1.output_section.create(1); +section1.output_section[0].$name = ".vectors"; +section1.output_section[0].palignment = true; + +section2.load_memory = "OCRAM"; +section2.$name = "Text Segments"; +section2.output_section.create(5); +section2.output_section[0].$name = ".text.hwi"; +section2.output_section[0].palignment = true; +section2.output_section[1].$name = ".text.cache"; +section2.output_section[1].palignment = true; +section2.output_section[2].$name = ".text.mpu"; +section2.output_section[2].palignment = true; +section2.output_section[3].$name = ".text.boot"; +section2.output_section[3].palignment = true; +section2.output_section[4].$name = ".text:abort"; +section2.output_section[4].palignment = true; + +section3.load_memory = "OCRAM"; +section3.$name = "Code and Read-Only Data"; +section3.output_section.create(2); +section3.output_section[0].$name = ".text"; +section3.output_section[0].palignment = true; +section3.output_section[1].$name = ".rodata"; +section3.output_section[1].palignment = true; + +section4.load_memory = "OCRAM"; +section4.$name = "Data Segment"; +section4.output_section.create(1); +section4.output_section[0].$name = ".data"; +section4.output_section[0].palignment = true; + +section5.load_memory = "OCRAM"; +section5.$name = "Memory Segments"; +section5.output_section.create(3); +section5.output_section[0].$name = ".bss"; +section5.output_section[0].output_sections_start = "__BSS_START"; +section5.output_section[0].output_sections_end = "__BSS_END"; +section5.output_section[0].palignment = true; +section5.output_section[1].$name = ".sysmem"; +section5.output_section[1].palignment = true; +section5.output_section[2].$name = ".stack"; +section5.output_section[2].palignment = true; + +section6.load_memory = "OCRAM"; +section6.$name = "Stack Segments"; +section6.output_section.create(5); +section6.output_section[0].$name = ".irqstack"; +section6.output_section[0].output_sections_start = "__IRQ_STACK_START"; +section6.output_section[0].output_sections_end = "__IRQ_STACK_END"; +section6.output_section[0].input_section.create(1); +section6.output_section[0].input_section[0].$name = ". = . + __IRQ_STACK_SIZE;"; +section6.output_section[1].$name = ".fiqstack"; +section6.output_section[1].output_sections_start = "__FIQ_STACK_START"; +section6.output_section[1].output_sections_end = "__FIQ_STACK_END"; +section6.output_section[1].input_section.create(1); +section6.output_section[1].input_section[0].$name = ". = . + __FIQ_STACK_SIZE;"; +section6.output_section[2].$name = ".svcstack"; +section6.output_section[2].output_sections_start = "__SVC_STACK_START"; +section6.output_section[2].output_sections_end = "__SVC_STACK_END"; +section6.output_section[2].input_section.create(1); +section6.output_section[2].input_section[0].$name = ". = . + __SVC_STACK_SIZE;"; +section6.output_section[3].$name = ".abortstack"; +section6.output_section[3].output_sections_start = "__ABORT_STACK_START"; +section6.output_section[3].output_sections_end = "__ABORT_STACK_END"; +section6.output_section[3].input_section.create(1); +section6.output_section[3].input_section[0].$name = ". = . + __ABORT_STACK_SIZE;"; +section6.output_section[4].$name = ".undefinedstack"; +section6.output_section[4].output_sections_start = "__UNDEFINED_STACK_START"; +section6.output_section[4].output_sections_end = "__UNDEFINED_STACK_END"; +section6.output_section[4].input_section.create(1); +section6.output_section[4].input_section[0].$name = ". = . + __UNDEFINED_STACK_SIZE;"; + +section7.load_memory = "OCRAM"; +section7.$name = "Initialization and Exception Handling"; +section7.output_section.create(3); +section7.output_section[0].$name = ".ARM.exidx"; +section7.output_section[0].palignment = true; +section7.output_section[1].$name = ".init_array"; +section7.output_section[1].palignment = true; +section7.output_section[2].$name = ".fini_array"; +section7.output_section[2].palignment = true; + +section8.load_memory = "USER_SHM_MEM"; +section8.type = "NOLOAD"; +section8.$name = "User Shared Memory"; +section8.group = false; +section8.output_section.create(1); +section8.output_section[0].$name = ".bss.user_shared_mem"; +section8.output_section[0].alignment = 0; + +section9.load_memory = "LOG_SHM_MEM"; +section9.$name = "Log Shared Memory"; +section9.group = false; +section9.type = "NOLOAD"; +section9.output_section.create(1); +section9.output_section[0].$name = ".bss.log_shared_mem"; +section9.output_section[0].alignment = 0; + +section10.load_memory = "RTOS_NORTOS_IPC_SHM_MEM"; +section10.type = "NOLOAD"; +section10.$name = "IPC Shared Memory"; +section10.group = false; +section10.output_section.create(1); +section10.output_section[0].$name = ".bss.ipc_vring_mem"; +section10.output_section[0].alignment = 0; + +section11.load_memory = "MAILBOX_HSM"; +section11.type = "NOLOAD"; +section11.$name = "SIPC HSM Queue Memory"; +section11.group = false; +section11.output_section.create(1); +section11.output_section[0].$name = ".bss.sipc_hsm_queue_mem"; +section11.output_section[0].alignment = 0; + +section12.load_memory = "MAILBOX_R5F"; +section12.$name = "SIPC R5F Queue Memory"; +section12.group = false; +section12.type = "NOLOAD"; +section12.output_section.create(1); +section12.output_section[0].$name = ".bss.sipc_secure_host_queue_mem"; +section12.output_section[0].alignment = 0; + +/** + * Pinmux solution for unlocked pins/peripherals. This ensures that minor changes to the automatic solver in a future + * version of the tool will not impact the pinmux you originally saw. These lines can be completely deleted in order to + * re-solve from scratch. + */ +pruicss1.AdditionalICSSSettings[0].PruGPIO[0]["PRU-ICSS0"].$suggestSolution = "PRU-ICSS0"; diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/main.c b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/main.c new file mode 100644 index 000000000..58db51ec3 --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/main.c @@ -0,0 +1,51 @@ +/* File: main.c */ +/* + * Copyright (C) 2026 Texas Instruments Incorporated + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include "ti_drivers_config.h" +#include "ti_board_config.h" + +void pru_i2c_example_main(void *args); + +int main(void) +{ + System_init(); + Board_init(); + + pru_i2c_example_main(NULL); + + Board_deinit(); + System_deinit(); + + return 0; +} diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/example.projectspec b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/example.projectspec new file mode 100644 index 000000000..55a4a9d75 --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/example.projectspec @@ -0,0 +1,115 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile new file mode 100644 index 000000000..4942274d2 --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile @@ -0,0 +1,350 @@ +# +# Auto generated makefile +# + +export OPEN_PRU_PATH?=$(abspath ../../../../../..) +include $(OPEN_PRU_PATH)/imports.mak +include $(MCU_PLUS_SDK_PATH)/devconfig/devconfig.mak + + +CG_TOOL_ROOT=$(CGT_TI_ARM_CLANG_PATH) + +CC=$(CG_TOOL_ROOT)/bin/tiarmclang +LNK=$(CG_TOOL_ROOT)/bin/tiarmclang +STRIP=$(CG_TOOL_ROOT)/bin/tiarmstrip +OBJCOPY=$(CG_TOOL_ROOT)/bin/tiarmobjcopy +COV=$(CG_TOOL_ROOT)/bin/tiarmcov +PROFDATA=$(CG_TOOL_ROOT)/bin/tiarmprofdata +COVERAGE_PATH=$(abspath .) +ifeq ($(OS), Windows_NT) + PYTHON=python +else + PYTHON=python3 +endif + +PROFILE?=release +ConfigName:=$(PROFILE) + +OUTNAME:=pru_i2c.$(PROFILE).out + +BOOTIMAGE_PATH=$(abspath .) +oeconfig?=None +BOOTIMAGE_NAME:=pru_i2c.$(PROFILE).appimage +BOOTIMAGE_NAME_XIP:=pru_i2c.$(PROFILE).appimage_xip +BOOTIMAGE_NAME_SIGNED:=pru_i2c.$(PROFILE).appimage.signed +BOOTIMAGE_NAME_MCELF:=pru_i2c.$(PROFILE).mcelf +BOOTIMAGE_NAME_MCELF_HS:=pru_i2c.$(PROFILE).mcelf.hs +BOOTIMAGE_RPRC_NAME:=pru_i2c.$(PROFILE).rprc +BOOTIMAGE_RPRC_NAME_XIP:=pru_i2c.$(PROFILE).rprc_xip +BOOTIMAGE_RPRC_NAME_TMP:=pru_i2c.$(PROFILE).rprc_tmp +BOOTIMAGE_NAME_HS:=pru_i2c.$(PROFILE).appimage.hs +BOOTIMAGE_NAME_HS_FS:=pru_i2c.$(PROFILE).appimage.hs_fs +TARGETS := $(BOOTIMAGE_NAME_MCELF) + +ifeq ($(DEVICE_TYPE), HS) + TARGETS += $(BOOTIMAGE_NAME_MCELF_HS) +endif + +FILES_common := \ + main.c \ + pru_i2c_example.c \ + ti_drivers_config.c \ + ti_drivers_open_close.c \ + ti_board_config.c \ + ti_board_open_close.c \ + ti_dpl_config.c \ + ti_pinmux_config.c \ + ti_power_clock_config.c \ + +FILES_PATH_common = \ + .. \ + ../../.. \ + generated \ + +INCLUDES_common := \ + -I${CG_TOOL_ROOT}/include/c \ + -I${MCU_PLUS_SDK_PATH}/source \ + -I${OPEN_PRU_PATH}/source \ + -I${MCU_PLUS_SDK_PATH}/source/pru_io/driver \ + -I${OPEN_PRU_PATH}/examples/pru_i2c/firmware/am261x-lp \ + -I${OPEN_PRU_PATH}/examples/pru_i2c/firmware \ + -Igenerated \ + +DEFINES_common := \ + -DSOC_AM261X \ + -DOS_NORTOS \ + +CFLAGS_common := \ + -mcpu=cortex-r5 \ + -mfloat-abi=hard \ + -mfpu=vfpv3-d16 \ + -mthumb \ + -Wall \ + -Werror \ + -g \ + -Wno-gnu-variable-sized-type-not-at-end \ + -Wno-unused-function \ + +CFLAGS_cpp_common := \ + -Wno-c99-designator \ + -Wno-extern-c-compat \ + -Wno-c++11-narrowing \ + -Wno-reorder-init-list \ + -Wno-register \ + -Wno-writable-strings \ + -Wno-enum-compare \ + -Wno-reserved-user-defined-literal \ + -Wno-unused-const-variable \ + -Wno-vla-cxx-extension \ + -x c++ \ + +CFLAGS_debug := \ + -D_DEBUG_=1 \ + +CFLAGS_release := \ + -Os \ + +LNK_FILES_common = \ + generated/linker.cmd \ + +LIBS_PATH_common = \ + -Wl,-i${MCU_PLUS_SDK_PATH}/source/kernel/nortos/lib \ + -Wl,-i${MCU_PLUS_SDK_PATH}/source/drivers/lib \ + -Wl,-i${MCU_PLUS_SDK_PATH}/source/board/lib \ + -Wl,-i${MCU_PLUS_SDK_PATH}/source/pru_io/lib \ + -Wl,-i${CG_TOOL_ROOT}/lib \ + +LIBS_common = \ + -lnortos.am261x.r5f.ti-arm-clang.${ConfigName}.lib \ + -ldrivers.am261x.r5f.ti-arm-clang.nortos.${ConfigName}.lib \ + -lboard.am261x.r5f.ti-arm-clang.nortos.${ConfigName}.lib \ + -llibc.a \ + -llibsysbm.a \ + +LFLAGS_common = \ + -Wl,--diag_suppress=10063 \ + -Wl,--ram_model \ + -Wl,--reread_libs \ + -Wl,--gen_xml_func_hash \ + + +LIBS_NAME = \ + nortos.am261x.r5f.ti-arm-clang.${ConfigName}.lib \ + drivers.am261x.r5f.ti-arm-clang.nortos.${ConfigName}.lib \ + board.am261x.r5f.ti-arm-clang.nortos.${ConfigName}.lib \ + libc.a \ + libsysbm.a \ + +LIBS_PATH_NAME = \ + ${MCU_PLUS_SDK_PATH}/source/kernel/nortos/lib \ + ${MCU_PLUS_SDK_PATH}/source/drivers/lib \ + ${MCU_PLUS_SDK_PATH}/source/board/lib \ + ${MCU_PLUS_SDK_PATH}/source/pru_io/lib \ + ${CG_TOOL_ROOT}/lib \ + +FILES := $(FILES_common) $(FILES_$(PROFILE)) +ASMFILES := $(ASMFILES_common) $(ASMFILES_$(PROFILE)) +FILES_PATH := $(FILES_PATH_common) $(FILES_PATH_$(PROFILE)) +CFLAGS := $(CFLAGS_common) $(CFLAGS_$(PROFILE)) +ifeq ($(INSTRUMENTATION_MODE), yes) +CFLAGS += -fprofile-instr-generate -fcoverage-mapping +endif +DEFINES := $(DEFINES_common) $(DEFINES_$(PROFILE)) +INCLUDES := $(INCLUDES_common) $(INCLUDE_$(PROFILE)) +LIBS := $(LIBS_common) $(LIBS_$(PROFILE)) +LIBS_PATH := $(LIBS_PATH_common) $(LIBS_PATH_$(PROFILE)) +LFLAGS := $(LFLAGS_common) $(LFLAGS_$(PROFILE)) +LNKOPTFLAGS := $(LNKOPTFLAGS_common) $(LNKOPTFLAGS_$(PROFILE)) +LNK_FILES := $(LNK_FILES_common) $(LNK_FILES_$(PROFILE)) + +OBJDIR := obj/$(PROFILE)/ +OBJS := $(FILES:%.c=%.obj) +OBJS += $(ASMFILES:%.S=%.obj) +DEPS := $(FILES:%.c=%.d) + +vpath %.obj $(OBJDIR) +vpath %.c $(FILES_PATH) +vpath %.S $(FILES_PATH) +vpath %.lib $(LIBS_PATH_NAME) +vpath %.a $(LIBS_PATH_NAME) + +$(OBJDIR)/%.obj %.obj: %.c + @echo Compiling: am261x:r5fss0-0:nortos:ti-arm-clang $(OUTNAME): $< + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) -MMD -o $(OBJDIR)/$@ $< + +$(OBJDIR)/%.obj %.obj: %.S + @echo Compiling: am261x:r5fss0-0:nortos:ti-arm-clang $(LIBNAME): $< + $(CC) -c $(CFLAGS) $(INCLUDES) $(DEFINES) -o $(OBJDIR)/$@ $< + +all: $(TARGETS) + +SYSCFG_GEN_FILES=generated/ti_drivers_config.c generated/ti_drivers_config.h +SYSCFG_GEN_FILES+=generated/ti_drivers_open_close.c generated/ti_drivers_open_close.h +SYSCFG_GEN_FILES+=generated/ti_dpl_config.c generated/ti_dpl_config.h +SYSCFG_GEN_FILES+=generated/ti_pinmux_config.c generated/ti_power_clock_config.c +SYSCFG_GEN_FILES+=generated/ti_board_config.c generated/ti_board_config.h +SYSCFG_GEN_FILES+=generated/ti_board_open_close.c generated/ti_board_open_close.h + +SYSTEM_FLAG ?= false + +ifeq ($(SYSTEM_FLAG), false) + SYSTEM_COMMAND := syscfg $(SYSCFG_GEN_FILES) $(OBJS) $(LNK_FILES) $(LIBS_NAME) +else + SYSTEM_COMMAND := $(OBJS) $(LNK_FILES) $(LIBS_NAME) +endif + +$(OUTNAME): $(SYSTEM_COMMAND) + @echo . + @echo Linking: am261x:r5fss0-0:nortos:ti-arm-clang $@ ... + $(LNK) $(LNKOPTFLAGS) $(LFLAGS) $(LIBS_PATH) -Wl,-m=$(basename $@).map -o $@ $(addprefix $(OBJDIR), $(OBJS)) $(LIBS) $(LNK_FILES) -Wl,--xml_link_info=$(basename $@).lnkxml + @echo Linking: am261x:r5fss0-0:nortos:ti-arm-clang $@ Done !!! + @echo . + +clean: + @echo Cleaning: am261x:r5fss0-0:nortos:ti-arm-clang $(OUTNAME) ... + $(RMDIR) $(OBJDIR) + $(RM) $(OUTNAME) + $(RM) $(BOOTIMAGE_NAME) + $(RM) $(BOOTIMAGE_NAME_XIP) + $(RM) $(BOOTIMAGE_NAME_SIGNED) + $(RM) $(BOOTIMAGE_RPRC_NAME) + $(RM) $(BOOTIMAGE_RPRC_NAME_XIP) + $(RM) $(BOOTIMAGE_NAME_MCELF) + $(RMDIR) generated/ + +scrub: + @echo Scrubing: am261x:r5fss0-0:nortos:ti-arm-clang pru_i2c ... + $(RMDIR) obj +ifeq ($(OS),Windows_NT) + $(RM) \*.out + $(RM) \*.map + $(RM) \*.appimage* + $(RM) \*.rprc* + $(RM) \*.tiimage* + $(RM) \*.bin + $(RM) \*.lnkxml + $(RM) \*.mcelf + $(RM) \*.mcelf_xip + $(RM) \*.mcelf-enc + $(RM) \*.mcelf.hs +else + $(RM) *.out + $(RM) *.map + $(RM) *.appimage* + $(RM) *.rprc* + $(RM) *.tiimage* + $(RM) *.bin + $(RM) *.lnkxml + $(RM) *.mcelf + $(RM) *.mcelf_xip + $(RM) *.mcelf-enc + $(RM) *.mcelf.hs +endif + $(RMDIR) generated + +$(OBJS): | $(OBJDIR) + +$(OBJDIR): + $(MKDIR) $@ + + +.NOTPARALLEL: + +.INTERMEDIATE: syscfg +$(SYSCFG_GEN_FILES): syscfg + +ifeq ($(SYSTEM_FLAG), false) +syscfg: ../example.syscfg + @echo Generating SysConfig files ... + $(SYSCFG_NODE) $(SYSCFG_CLI_PATH)/dist/cli.js --product $(SYSCFG_SDKPRODUCT) --product $(SYSCFG_MCU_PLUS_SDK_PRODUCT) --context r5fss0-0 --part AM2612 --package ZFG --output generated/ ../example.syscfg +endif + +syscfg-gui: + $(SYSCFG_NWJS) $(SYSCFG_PATH) --product $(SYSCFG_SDKPRODUCT) --product $(SYSCFG_MCU_PLUS_SDK_PRODUCT) --device AM261x_ZFG --context r5fss0-0 --part AM2612 --package ZFG --output generated/ ../example.syscfg + +# +# Generation of boot image which can be loaded by Secondary Boot Loader (SBL) +# +ifeq ($(OS),Windows_NT) +EXE_EXT=.exe +endif +ifeq ($(OS),Windows_NT) + BOOTIMAGE_CERT_GEN_CMD=powershell -executionpolicy unrestricted -command $(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/x509CertificateGen.ps1 +else + BOOTIMAGE_CERT_GEN_CMD=$(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/x509CertificateGen.sh +endif +BOOTIMAGE_TEMP_OUT_FILE=temp_stdout_$(PROFILE).txt + + +BOOTIMAGE_CORE_ID_r5fss0-0 = 0 +BOOTIMAGE_CORE_ID_r5fss0-1 = 1 +BOOTIMAGE_CORE_ID_r5fss1-0 = 2 +BOOTIMAGE_CORE_ID_r5fss1-1 = 3 +SBL_RUN_ADDRESS=0x70002000 +SBL_DEV_ID=55 + +APP_IMAGE_SIGN_CMD = $(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/mcu_appimage_x509_cert_gen.py +MCELF_IMAGE_GEN = $(MCU_PLUS_SDK_PATH)/tools/boot/multicore-elf/genimage.py + +ifeq ($(OS),Windows_NT) + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.exe +else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S), Darwin) + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.out.mac + else + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.out +endif +endif + +MULTI_CORE_IMAGE_PARAMS = \ + $(BOOTIMAGE_RPRC_NAME)@$(BOOTIMAGE_CORE_ID_r5fss0-0) \ + +MULTI_CORE_IMAGE_PARAMS_XIP = \ + $(BOOTIMAGE_RPRC_NAME_XIP)@$(BOOTIMAGE_CORE_ID_r5fss0-0) \ + +$(BOOTIMAGE_NAME_MCELF): $(OUTNAME) + @echo Boot MulticoreELF image: $(BOOTIMAGE_PATH)/$(BOOTIMAGE_NAME_MCELF) ... + $(PYTHON) $(MCELF_IMAGE_GEN) --core-img=$(BOOTIMAGE_CORE_ID_r5fss0-0):$(OUTNAME) --output=$(BOOTIMAGE_NAME_MCELF) --merge-segments=$(MCELF_MERGE_SEGMENTS_FLAG) --tolerance-limit=$(MCELF_MERGE_SEGMENTS_TOLERANCE_LIMIT) --ignore-context=$(MCELF_IGNORE_CONTEXT_FLAG) --xip=$(MCELF_XIP_RANGE) --xlat=$(MCELF_ADDR_TRANSLATION_PATH) --max-segment-size=$(MCELF_MAX_SEGMENT_SIZE) --otfaConfigFile=$(oeconfig) + @echo Boot MulticoreELF ELF image: $(BOOTIMAGE_PATH)/$(BOOTIMAGE_NAME_MCELF) Done !!! + @echo . + +$(BOOTIMAGE_NAME_MCELF_HS): $(BOOTIMAGE_NAME_MCELF) +ifeq ($(DEVICE_TYPE), HS) +# Sign the appimage using appimage signing script +ifeq ($(ENC_ENABLED),no) +ifeq ($(RSASSAPSS_ENABLED),no) + @echo Boot image signing: Encryption is disabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --output $(BOOTIMAGE_NAME_MCELF_HS) +else + @echo Boot image signing: Encryption is disabled. RSASSAPSS is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --pss_saltlen $(APP_SIGNING_SALT_LENGTH) --output $(BOOTIMAGE_NAME_MCELF_HS) --rsassa_pss +endif +else +ifeq ($(RSASSAPSS_ENABLED),no) + @echo Boot image signing: Encryption is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --enc y --enckey $(APP_ENCRYPTION_KEY) --kd-salt $(KD_SALT) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --enc_key_id $(APP_ENCRYPTION_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --output $(BOOTIMAGE_NAME_MCELF_HS) + $(RM) $(BOOTIMAGE_NAME_MCELF)-enc +else + @echo Boot image signing: Encryption is enabled. RSASSAPSS is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --enc y --enckey $(APP_ENCRYPTION_KEY) --kd-salt $(KD_SALT) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --enc_key_id $(APP_ENCRYPTION_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --pss_saltlen $(APP_SIGNING_SALT_LENGTH) --output $(BOOTIMAGE_NAME_MCELF_HS) --rsassa_pss + $(RM) $(BOOTIMAGE_NAME_MCELF)-enc +endif +endif + @echo Boot image: am261x:r5fss0-0:nortos:ti-arm-clang $(BOOTIMAGE_PATH)/$(BOOTIMAGE_NAME_MCELF_HS) Done !!! + @echo . +endif + + + +.PHONY: coverage +coverage: + @echo Creating Coverage Report for pru_i2c.$(PROFILE) ... + $(MKDIR) coverage + $(PROFDATA) merge -sparse -obj-file=$(OUTNAME) $(OUTNAME).cnt -o pru_i2c.$(PROFILE).profdata + $(COV) show --format=html --show-expansions --show-instantiations --show-branches=count --object=$(OUTNAME) -instr-profile=pru_i2c.$(PROFILE).profdata --output-dir=$(COVERAGE_PATH)/coverage --ignore-filename-regex=build_jenkins + $(COV) export --format=text --object=$(OUTNAME) --instr-profile=pru_i2c.$(PROFILE).profdata > coverage/pru_i2c.$(PROFILE).profdata.json + node $(MCU_PLUS_SDK_PATH)/tools/smart_placement/clang_coverage_analyse.js --input=coverage/pru_i2c.$(PROFILE).profdata.json --output-json=coverage/pru_i2c.$(PROFILE).analysis.json --output=../pru_i2c.annotations.$(PROFILE).S --top-function-count=500 + @echo Coverage Report Generated at $(COVERAGE_PATH)/coverage folder !!! + +-include $(addprefix $(OBJDIR)/, $(DEPS)) diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_ccs_bootimage_gen b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_ccs_bootimage_gen new file mode 100644 index 000000000..a08ec99ce --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_ccs_bootimage_gen @@ -0,0 +1,112 @@ +# +# Auto generated makefile +# + +# Below variables need to be defined outside this file or via command line +# - OPEN_PRU_PATH +# - MCU_PLUS_SDK_PATH +# - PROFILE +# - CG_TOOL_ROOT +# - OUTNAME +# - CCS_INSTALL_DIR +# - CCS_IDE_MODE + +CCS_PATH=$(CCS_INSTALL_DIR) +include $(OPEN_PRU_PATH)/imports.mak +include $(MCU_PLUS_SDK_PATH)/devconfig/devconfig.mak + +STRIP=$(CG_TOOL_ROOT)/bin/tiarmstrip +OBJCOPY=$(CG_TOOL_ROOT)/bin/tiarmobjcopy +ifeq ($(OS), Windows_NT) + PYTHON=python +else + PYTHON=python3 +endif + +OUTFILE=$(PROFILE)/$(OUTNAME).out +BOOTIMAGE_PATH=$(abspath ${PROFILE}) +BOOTIMAGE_NAME_MCELF:=$(BOOTIMAGE_PATH)/$(OUTNAME).mcelf +BOOTIMAGE_NAME_MCELF_HS:=$(BOOTIMAGE_PATH)/$(OUTNAME).mcelf.hs +TARGETS += $(BOOTIMAGE_NAME_MCELF) +TARGETS += $(BOOTIMAGE_NAME_MCELF_HS) +ifeq ($(DEVICE_TYPE), HS) + TARGETS += $(BOOTIMAGE_NAME_MCELF_HS) +endif + +# +# Generation of boot image which can be loaded by Secondary Boot Loader (SBL) +# +ifeq ($(OS),Windows_NT) +EXE_EXT=.exe +endif +ifeq ($(OS),Windows_NT) + BOOTIMAGE_CERT_GEN_CMD=powershell -executionpolicy unrestricted -command $(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/x509CertificateGen.ps1 +else + BOOTIMAGE_CERT_GEN_CMD=$(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/x509CertificateGen.sh +endif +BOOTIMAGE_TEMP_OUT_FILE=$(PROFILE)/temp_stdout_$(PROFILE).txt + +BOOTIMAGE_CORE_ID_r5fss0-0 = 0 +BOOTIMAGE_CORE_ID_r5fss0-1 = 1 +BOOTIMAGE_CORE_ID_r5fss1-0 = 2 +BOOTIMAGE_CORE_ID_r5fss1-1 = 3 +SBL_RUN_ADDRESS=0x70002000 +SBL_DEV_ID=55 + +APP_IMAGE_SIGN_CMD = $(MCU_PLUS_SDK_PATH)/source/security/security_common/tools/boot/signing/mcu_appimage_x509_cert_gen.py +MCELF_IMAGE_GEN = $(MCU_PLUS_SDK_PATH)/tools/boot/multicore-elf/genimage.py + +ifeq ($(OS),Windows_NT) + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.exe +else + UNAME_S = $(shell uname -s) + ifeq ($(UNAME_S), Darwin) + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.out.mac + else + XIPGEN_CMD=$(MCU_PLUS_SDK_PATH)/tools/boot/xipGen/xipGen.out +endif +endif + +MULTI_CORE_IMAGE_PARAMS = \ + $(BOOTIMAGE_RPRC_NAME)@$(BOOTIMAGE_CORE_ID_r5fss0-0) \ + +MULTI_CORE_IMAGE_PARAMS_XIP = \ + $(BOOTIMAGE_RPRC_NAME_XIP)@$(BOOTIMAGE_CORE_ID_r5fss0-0) \ + +all: +ifeq ($(CCS_IDE_MODE),cloud) +# No post build steps +else + + @echo Boot multi-core ELF image: am261x:r5fss0-0:nortos:ti-arm-clang $(BOOTIMAGE_NAME_MCELF) ... + + $(PYTHON) $(MCELF_IMAGE_GEN) --core-img=$(BOOTIMAGE_CORE_ID_r5fss0-0):$(OUTFILE) --output=$(BOOTIMAGE_NAME_MCELF) --merge-segments=$(MCELF_MERGE_SEGMENTS_FLAG) --tolerance-limit=$(MCELF_MERGE_SEGMENTS_TOLERANCE_LIMIT) --ignore-context=$(MCELF_IGNORE_CONTEXT_FLAG) --xip=$(MCELF_XIP_RANGE) --xlat=$(MCELF_ADDR_TRANSLATION_PATH) --max-segment-size=$(MCELF_MAX_SEGMENT_SIZE) + + @echo Boot multi-core ELF image: $(BOOTIMAGE_NAME_MCELF) Done !!! + @echo . + +ifeq ($(DEVICE_TYPE), HS) +# Sign the appimage using appimage signing script +ifeq ($(ENC_ENABLED),no) +ifeq ($(RSASSAPSS_ENABLED),no) + @echo Boot image signing: Encryption is disabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --output $(BOOTIMAGE_NAME_MCELF_HS) +else + @echo Boot image signing: Encryption is disabled. RSASSA-PSS is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --pss_saltlen $(APP_SIGNING_SALT_LENGTH) --output $(BOOTIMAGE_NAME_MCELF_HS) --rsassa_pss +endif +else +ifeq ($(RSASSAPSS_ENABLED),no) + @echo Boot image signing: Encryption is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --enc y --enckey $(APP_ENCRYPTION_KEY) --kd-salt $(KD_SALT) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --enc_key_id $(APP_ENCRYPTION_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --output $(BOOTIMAGE_NAME_MCELF_HS) + $(RM) $(BOOTIMAGE_NAME_MCELF)-enc +else + @echo Boot image signing: Encryption is enabled. RSASSA-PSS is enabled. + $(PYTHON) $(APP_IMAGE_SIGN_CMD) --bin $(BOOTIMAGE_NAME_MCELF) --key $(APP_SIGNING_KEY) --enc y --enckey $(APP_ENCRYPTION_KEY) --kd-salt $(KD_SALT) --sign_key_id $(APP_SIGNING_KEY_KEYRING_ID) --enc_key_id $(APP_ENCRYPTION_KEY_KEYRING_ID) --hash_algo $(APP_SIGNING_HASH_ALGO) --pss_saltlen $(APP_SIGNING_SALT_LENGTH) --output $(BOOTIMAGE_NAME_MCELF_HS) --rsassa_pss + $(RM) $(BOOTIMAGE_NAME_MCELF)-enc +endif +endif + @echo Boot image: am261x:r5fss0-0:nortos:ti-arm-clang $(BOOTIMAGE_PATH)/$(BOOTIMAGE_NAME_MCELF_HS) Done !!! + @echo . +endif +endif diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_projectspec b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_projectspec new file mode 100644 index 000000000..a483afd8d --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/makefile_projectspec @@ -0,0 +1,16 @@ +export OPEN_PRU_PATH?=$(abspath ../../../../../..) +include $(OPEN_PRU_PATH)/imports.mak + +PROFILE?=Release + +PROJECT_NAME=pru_i2c_am261x-lp_r5fss0-0_nortos_ti-arm-clang + +all: + $(CCS_ECLIPSE) -noSplash -data $(OPEN_PRU_PATH)/ccs_projects -application com.ti.ccstudio.apps.projectBuild -ccs.projects $(PROJECT_NAME) -ccs.configuration $(PROFILE) + +clean: + $(CCS_ECLIPSE) -noSplash -data $(OPEN_PRU_PATH)/ccs_projects -application com.ti.ccstudio.apps.projectBuild -ccs.projects $(PROJECT_NAME) -ccs.configuration $(PROFILE) -ccs.clean + +export: + $(MKDIR) $(OPEN_PRU_PATH)/ccs_projects + $(CCS_ECLIPSE) -noSplash -data $(OPEN_PRU_PATH)/ccs_projects -application com.ti.ccstudio.apps.projectCreate -ccs.projectSpec example.projectspec -ccs.overwrite full diff --git a/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/syscfg_c.rov.xs b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/syscfg_c.rov.xs new file mode 100644 index 000000000..f716f8e9d --- /dev/null +++ b/examples/pru_i2c/mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/syscfg_c.rov.xs @@ -0,0 +1,12 @@ +/* + * ======== syscfg_c.rov.xs ======== + * This file contains the information needed by the Runtime Object + * View (ROV) tool. + */ +var crovFiles = [ + "kernel/freertos/rov/FreeRTOS.rov.js", +]; + +var objectViewerFiles = [ + "kernel/freertos/rov_theia/FreeRTOS_Theia.rov.js", +]; diff --git a/examples/pru_i2c/mcuplus/pru_i2c_example.c b/examples/pru_i2c/mcuplus/pru_i2c_example.c new file mode 100644 index 000000000..72031bd01 --- /dev/null +++ b/examples/pru_i2c/mcuplus/pru_i2c_example.c @@ -0,0 +1,514 @@ +/* File: pru_i2c_example.c */ +/* + * Copyright (C) 2026 Texas Instruments Incorporated + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the + * distribution. + * + * Neither the name of Texas Instruments Incorporated nor the names of + * its contributors may be used to endorse or promote products derived + * from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include +#include "ti_drivers_config.h" +#include "ti_drivers_open_close.h" +#include "ti_board_config.h" +#include "ti_board_open_close.h" +#include +#include +#include + +/* PRU <-> host memory map and command/response codes (shared with the PRU + * firmware, do not duplicate the values here) */ +#include "pru_i2c_interface.h" + +/* + * This example shows an R5F core (NORTOS) using the PRU I2C master firmware + * from examples/pru_i2c/firmware to talk to an I2C target: + * 1. the I2C configuration is written into the PRU data RAM + * 2. the PRU firmware is loaded and started + * 3. the R5F sends commands to the PRU through the data RAM and waits for + * the PRU to report completion + * + * The demo transfers are written for a generic EEPROM-style target (for + * example an AT24C02 / 24LC02) that takes a one byte register pointer + * followed by data bytes: + * - write: [pointer, data0 ... dataN-1] + * - read back: write [pointer], then read N bytes + */ + +/* ========================================================================== */ +/* User configurable settings */ +/* ========================================================================== */ + +/* PRU core that runs the I2C firmware: 0 = ICSSM0 PRU0, 1 = ICSSM0 PRU1. + * + * AM261x-LP: the BoosterPack headers carry PR0_PRU1_GPIO17..19 but none of the + * PR0_PRU0_GPIOx signals (those are used by the on-board Ethernet PHY), so + * the default is PRU1. If you change this, update the pinmux in example.syscfg + * to the matching PR0_PRUx_GPIOy pins as well. */ +#define PRU_I2C_PRU_CORE (1U) + +/* PRU GPIO numbers used for the bus. The firmware uses one number per signal + * for both the output (R30[n]) and the input (R31[n]) register bit, so the + * pad has to be PR0_PRUx_GPIO in example.syscfg. You can change these two + * numbers, but keep them in sync with example.syscfg. + * SCL: PR0_PRU1_GPIO18 (pad GPIO120, BoosterPack J1.4) + * SDA: PR0_PRU1_GPIO19 (pad GPIO119, BoosterPack J1.3) */ +#define PRU_I2C_SCL_PIN (18U) +#define PRU_I2C_SDA_PIN (19U) + +/* I2C bus frequency. PRU_I2C_BUS_FREQ is the firmware's frequency selector + * (ICSS_I2C_100KHZ_FREQ, ICSS_I2C_400KHZ_FREQ or ICSS_I2C_1MHZ_FREQ). The + * actual SCL rate is set by the IEP compare increment below. */ +#define PRU_I2C_BUS_FREQ (ICSS_I2C_400KHZ_FREQ) +#define PRU_I2C_BUS_HZ (400000U) + +/* The firmware advances its state machine once per IEP compare event and + * needs 4 ticks per SCL period, with SCL low for 2 of them. The IEP counts + * PRU_I2C_IEP_DEFAULT_INC per IEP clock, and its clock comes from SysConfig + * (250 MHz by default on AM261x, while the IEP_CMP_INCREMENT_VAL_* constants + * in pru_i2c_interface.h assume 200 MHz). So derive the increment from the + * configured IEP clock: the tick is at least 1/(4 * PRU_I2C_BUS_HZ), and at + * least PRU_I2C_MIN_TICK_NS so that SCL low meets the Fast-mode + * tLOW >= 1.3 us (with margin for the few cycles the edges move by). At + * 400 kHz the second limit wins: about 368 kHz. */ +#define PRU_I2C_IEP_DEFAULT_INC (5U) +#define PRU_I2C_MIN_TICK_NS (680U) +#define PRU_I2C_IEP_CLKS_BUS \ + ((CONFIG_PRU_ICSS0_IEP_CLK_FREQ_HZ + (4U * PRU_I2C_BUS_HZ) - 1U) / (4U * PRU_I2C_BUS_HZ)) +#define PRU_I2C_IEP_CLKS_TLOW \ + (((CONFIG_PRU_ICSS0_IEP_CLK_FREQ_HZ / 1000U) * PRU_I2C_MIN_TICK_NS + 999999U) / 1000000U) +#define PRU_I2C_IEP_CLKS_PER_TICK \ + ((PRU_I2C_IEP_CLKS_BUS > PRU_I2C_IEP_CLKS_TLOW) ? PRU_I2C_IEP_CLKS_BUS : PRU_I2C_IEP_CLKS_TLOW) +#define PRU_I2C_IEP_INCREMENT (PRU_I2C_IEP_CLKS_PER_TICK * PRU_I2C_IEP_DEFAULT_INC) + +/* How long a target may hold SCL low (clock stretching) before the transfer + * ends with TIME_OUT_ERROR, in state machine ticks: the SMBus tTIMEOUT of + * 25 ms. */ +#define PRU_I2C_SCL_TIMEOUT_TICKS \ + ((25000U * 1000U) / ((PRU_I2C_IEP_CLKS_PER_TICK * 1000000U) / (CONFIG_PRU_ICSS0_IEP_CLK_FREQ_HZ / 1000U))) + +/* 7-bit address of the I2C target used for the demo transfers */ +#define PRU_I2C_TARGET_ADDR (0x50U) +/* Register pointer (first byte of every demo transfer) */ +#define PRU_I2C_TARGET_REG (0x00U) +/* Number of data bytes written and read back */ +#define PRU_I2C_TEST_LEN (4U) +/* Time to wait after a write before the target responds again. EEPROMs hold + * off for the internal write cycle (typically 5 ms max). */ +#define PRU_I2C_WRITE_CYCLE_US (10000U) + +/* How long the R5F waits for the PRU to report a response */ +#define PRU_I2C_TIMEOUT_US (100000U) + +/* ========================================================================== */ +/* Local macros */ +/* ========================================================================== */ + +/* PRU firmware image array. The header is generated by the PRU firmware build + * into examples/pru_i2c/firmware/am261x-lp/ */ +#if (PRU_I2C_PRU_CORE == 0U) +#include +#define PRU_I2C_FIRMWARE PRU0Firmware_0 +#define PRU_I2C_OUT_CTRL_REG (CSL_MSS_CTRL_U_BASE + CSL_MSS_CTRL_ICSSM0_PRU0_GPIO_OUT_CTRL) +#else +#include +#define PRU_I2C_FIRMWARE PRU1Firmware_0 +#define PRU_I2C_OUT_CTRL_REG (CSL_MSS_CTRL_U_BASE + CSL_MSS_CTRL_ICSSM0_PRU1_GPIO_OUT_CTRL) +#endif + +/* Global words, shared by both PRU cores. The firmware reads them through + * ICSS_DMEM0_CONST, which is DMEM0 on PRU0 and on PRU1 alike, so they always + * live in PRU0's data RAM. The layout is defined by pru_i2c_interface.h. */ +#define PRU_I2C_IRQ_REG (IRQ_COMMON_REGISTER_OFFSET) /* u8 per instance: set by PRU, cleared by R5F */ +#define PRU_I2C_FREQ_REG (I2C_BUS_FREQUENCY_OFFSET) /* u16: frequency selection */ +#define PRU_I2C_IEP_INC_REG (I2C_BUS_FREQUENCY_OFFSET + 2U) /* u16: IEP compare increment */ + +/* Instance 0 registers, in the data RAM of the core that runs the firmware + * (PRU0 -> DMEM0, PRU1 -> DMEM1). ICSS_I2C_COMMAND_OFFSET is a 32-bit word: the low + * half is the response of the PRU, the high half is the command from the R5F. */ +#define PRU_I2C_RESPONSE_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_COMMAND_OFFSET) +#define PRU_I2C_COMMAND_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_COMMAND_OFFSET + 2U) +#define PRU_I2C_TX_FIFO_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_BUF_OFFSET) /* u8 */ +#define PRU_I2C_RX_FIFO_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_BUF_OFFSET + 1U) /* u8 */ +#define PRU_I2C_COUNT_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_CNT_OFFSET) /* u16 */ +#define PRU_I2C_CON_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_CON_OFFSET) /* u32 */ +#define PRU_I2C_SA_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_SA_OFFSET) /* u16 */ +#define PRU_I2C_SCL_PIN_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_PRU_PIN_OFFSET) /* u8 */ +#define PRU_I2C_SDA_PIN_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_PRU_PIN_OFFSET + 1U) /* u8 */ +#define PRU_I2C_INST_ID_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_PRU_INST_ID_OFFSET) /* u8 */ +#define PRU_I2C_SCL_TIMEOUT_REG (ICSS_I2C_INSTANCE0_ADDR + ICSS_I2C_SCL_TIMEOUT_OFFSET) /* u16 */ + +/* Instance id: selects this instance's byte in the shared IRQ register. Use + * the core number so a PRU0 and a PRU1 instance can run side by side. */ +#define PRU_I2C_INST_ID (PRU_I2C_PRU_CORE) + +/* The firmware accepts a data count of 1..255 */ +#define PRU_I2C_MAX_COUNT (255U) + +/* ========================================================================== */ +/* Global variables */ +/* ========================================================================== */ + +PRUICSS_Handle gPruIcss0Handle; + +/* Base address of the data RAM of the PRU that runs the I2C firmware */ +static uintptr_t gPruDmemBase; +/* Base address of DMEM0, which holds the global IRQ and frequency words */ +static uintptr_t gPruGlobalBase; + +/* ========================================================================== */ +/* Local function definitions */ +/* ========================================================================== */ + +static const char *PruI2c_responseToString(uint16_t response) +{ + const char *str; + + switch (response) + { + case COMMAND_SUCCESS: str = "COMMAND_SUCCESS"; break; + case RESET_COMMAND_FAILED: str = "RESET_COMMAND_FAILED"; break; + case SETUP_COMMAND_FAILED: str = "SETUP_COMMAND_FAILED"; break; + case TX_COMMAND_FAILED: str = "TX_COMMAND_FAILED"; break; + case RX_COMMAND_FAILED: str = "RX_COMMAND_FAILED"; break; + case ADDRESS_ACKNOWLDEGE_FAILED: str = "ADDRESS_ACKNOWLDEGE_FAILED (no ACK from target)"; break; + case DATA_ACKNOWLDEGE_FAILED: str = "DATA_ACKNOWLDEGE_FAILED"; break; + case MASTER_SLAVE_MODE_FAILED: str = "MASTER_SLAVE_MODE_FAILED"; break; + case ADDRESSING_MODE_FAILED: str = "ADDRESSING_MODE_FAILED"; break; + case INVALID_COMMAND: str = "INVALID_COMMAND"; break; + case INVALID_DATA_COUNT: str = "INVALID_DATA_COUNT"; break; + case TIME_OUT_ERROR: str = "TIME_OUT_ERROR (SCL held low too long)"; break; + default: str = "unknown response"; break; + } + return str; +} + +/* Wait until the PRU sets this instance's flag in the IRQ register. + * The PRU also raises INTC system event SRSR1 bit 20 (PRU0) / 21 (PRU1) at + * the same time (ICSS_I2C_INTC_PRU0_BIT_VAL / ICSS_I2C_INTC_PRU1_BIT_VAL). + * This example does not use the interrupt, it polls the data RAM flag. */ +static int32_t PruI2c_waitForPru(uint32_t timeoutUs) +{ + uint64_t start = ClockP_getTimeUsec(); + + while (HW_RD_REG8(gPruGlobalBase + PRU_I2C_IRQ_REG + PRU_I2C_INST_ID) == 0U) + { + if ((ClockP_getTimeUsec() - start) > timeoutUs) + { + return SystemP_TIMEOUT; + } + } + return SystemP_SUCCESS; +} + +/* Acknowledge the PRU response. The PRU waits for the flag to be cleared + * before it accepts the next command. Only this instance's byte is written, + * so the other core's flag cannot be lost. */ +static void PruI2c_ackPru(void) +{ + HW_WR_REG8(gPruGlobalBase + PRU_I2C_IRQ_REG + PRU_I2C_INST_ID, 0U); +} + +/* Send a command to the PRU, wait for its response and acknowledge it. */ +static int32_t PruI2c_sendCommand(uint16_t command, uint16_t *response) +{ + int32_t status; + + /* Make sure the configuration and the TX data written by the caller are + * visible to the PRU before it sees the command. */ + __sync_synchronize(); + HW_WR_REG16(gPruDmemBase + PRU_I2C_COMMAND_REG, command); + + status = PruI2c_waitForPru(PRU_I2C_TIMEOUT_US); + if (status == SystemP_SUCCESS) + { + *response = HW_RD_REG16(gPruDmemBase + PRU_I2C_RESPONSE_REG); + PruI2c_ackPru(); + } + else + { + /* Not a firmware response: the PRU did not report anything in time */ + DebugP_log("PRU I2C: no response from PRU within %u us\r\n", PRU_I2C_TIMEOUT_US); + *response = TIME_OUT_ERROR; + } + return status; +} + +/* Write the I2C configuration into the PRU data RAM, load the firmware and + * run the setup command. */ +static int32_t PruI2c_init(void) +{ + const PRUICSS_HwAttrs *hwAttrs; + uint16_t response = 0U; + uint32_t reg; + int32_t status; + + hwAttrs = PRUICSS_getAttrs(CONFIG_PRU_ICSS0); + DebugP_assert(hwAttrs != NULL); + gPruDmemBase = (PRU_I2C_PRU_CORE == 0U) ? hwAttrs->pru0DramBase : hwAttrs->pru1DramBase; + gPruGlobalBase = hwAttrs->pru0DramBase; + + /* PRUICSS_loadFirmware() enables the PRU core right away, and the + * firmware reads the frequency settings once while it boots. So stop the + * core, clear the data RAM and write the whole configuration before the + * firmware is loaded. */ + status = PRUICSS_disableCore(gPruIcss0Handle, PRU_I2C_PRU_CORE); + if (status != SystemP_SUCCESS) + { + return status; + } + if (PRUICSS_initMemory(gPruIcss0Handle, PRUICSS_DATARAM(PRU_I2C_PRU_CORE)) == 0U) + { + return SystemP_FAILURE; + } + + /* Bus frequency (u16) and IEP compare increment (u16), shared by both + * cores. Clear only this instance's IRQ flag: the other core's instance + * may be using the same register. */ + HW_WR_REG16(gPruGlobalBase + PRU_I2C_FREQ_REG, PRU_I2C_BUS_FREQ); + HW_WR_REG16(gPruGlobalBase + PRU_I2C_IEP_INC_REG, PRU_I2C_IEP_INCREMENT); + PruI2c_ackPru(); + + /* Instance 0 configuration */ + /* TX and RX buffers are 256 bytes each */ + HW_WR_REG8(gPruDmemBase + PRU_I2C_TX_FIFO_REG, 0xFFU); + HW_WR_REG8(gPruDmemBase + PRU_I2C_RX_FIFO_REG, 0xFFU); + HW_WR_REG8(gPruDmemBase + PRU_I2C_SCL_PIN_REG, PRU_I2C_SCL_PIN); + HW_WR_REG8(gPruDmemBase + PRU_I2C_SDA_PIN_REG, PRU_I2C_SDA_PIN); + HW_WR_REG8(gPruDmemBase + PRU_I2C_INST_ID_REG, PRU_I2C_INST_ID); + HW_WR_REG16(gPruDmemBase + PRU_I2C_SCL_TIMEOUT_REG, PRU_I2C_SCL_TIMEOUT_TICKS); + /* Module enabled, master mode, 7-bit addressing, START and STOP around + * every transfer, NACK the last byte of a read */ + reg = (1U << ICSS_I2C_MODULE_ENABLE_BIT) | + (1U << ICSS_I2C_MASTER_SLAVE_MODE_BIT) | + (1U << ICSS_I2C_START_BIT) | + (1U << ICSS_I2C_STOP_BIT) | + (1U << ICSS_I2C_RECIEVE_NACK_BIT); + HW_WR_REG32(gPruDmemBase + PRU_I2C_CON_REG, reg); + + /* The bus is open-drain: the firmware keeps the R30 bits at 0 and drives + * a line low by clearing its bit in ICSSM0_PRUx_GPIO_OUT_CTRL + * (1 = output disabled = released). Start with both lines released, so + * the PRU does not pull the bus low between reset and its setup. + * SysConfig already sets these bits for pins configured with "rx". */ + reg = HW_RD_REG32(PRU_I2C_OUT_CTRL_REG); + reg |= (1U << PRU_I2C_SCL_PIN) | (1U << PRU_I2C_SDA_PIN); + HW_WR_REG32(PRU_I2C_OUT_CTRL_REG, reg); + + /* Load the firmware, this also starts the PRU core */ + status = PRUICSS_loadFirmware(gPruIcss0Handle, PRU_I2C_PRU_CORE, + PRU_I2C_FIRMWARE, sizeof(PRU_I2C_FIRMWARE)); + if (status != SystemP_SUCCESS) + { + return status; + } + + /* Latch the configuration inside the firmware */ + status = PruI2c_sendCommand(ICSS_I2C_SETUP_CMD, &response); + if ((status != SystemP_SUCCESS) || (response != COMMAND_SUCCESS)) + { + DebugP_log("PRU I2C setup failed, response 0x%04X (%s)\r\n", + response, PruI2c_responseToString(response)); + return SystemP_FAILURE; + } + return SystemP_SUCCESS; +} + +/* Write tx[0..len-1] to the target. */ +static int32_t PruI2c_write(uint8_t targetAddr, const uint8_t *tx, uint32_t len, uint16_t *response) +{ + uint32_t i; + int32_t status; + + if ((len == 0U) || (len > PRU_I2C_MAX_COUNT)) + { + *response = INVALID_DATA_COUNT; + return SystemP_FAILURE; + } + + HW_WR_REG16(gPruDmemBase + PRU_I2C_SA_REG, targetAddr); + HW_WR_REG16(gPruDmemBase + PRU_I2C_COUNT_REG, len); + for (i = 0U; i < len; i++) + { + HW_WR_REG8(gPruDmemBase + ICSS_I2C_INSTANCE0_TX_MEM + i, tx[i]); + } + + status = PruI2c_sendCommand(ICSS_I2C_TX_CMD, response); + if ((status == SystemP_SUCCESS) && (*response != COMMAND_SUCCESS)) + { + status = SystemP_FAILURE; + } + return status; +} + +/* Read len bytes from the target into rx. */ +static int32_t PruI2c_read(uint8_t targetAddr, uint8_t *rx, uint32_t len, uint16_t *response) +{ + uint32_t i; + int32_t status; + + if ((len == 0U) || (len > PRU_I2C_MAX_COUNT)) + { + *response = INVALID_DATA_COUNT; + return SystemP_FAILURE; + } + + HW_WR_REG16(gPruDmemBase + PRU_I2C_SA_REG, targetAddr); + HW_WR_REG16(gPruDmemBase + PRU_I2C_COUNT_REG, len); + + status = PruI2c_sendCommand(ICSS_I2C_RX_CMD, response); + if (status == SystemP_SUCCESS) + { + if (*response == COMMAND_SUCCESS) + { + for (i = 0U; i < len; i++) + { + rx[i] = HW_RD_REG8(gPruDmemBase + ICSS_I2C_INSTANCE0_RX_MEM + i); + } + } + else + { + status = SystemP_FAILURE; + } + } + return status; +} + +/* ========================================================================== */ +/* Example */ +/* ========================================================================== */ + +void pru_i2c_example_main(void *args) +{ + uint8_t txBuf[PRU_I2C_TEST_LEN + 1U]; + uint8_t rxBuf[PRU_I2C_TEST_LEN]; + uint16_t response; + uint32_t i; + int32_t status; + int32_t testStatus = SystemP_SUCCESS; + + Drivers_open(); + + status = Board_driversOpen(); + DebugP_assert(SystemP_SUCCESS == status); + + gPruIcss0Handle = PRUICSS_open(CONFIG_PRU_ICSS0); + DebugP_assert(gPruIcss0Handle != NULL); + + DebugP_log("PRU I2C master example started\r\n"); + DebugP_log("PRU core %u, SCL = PR0_PRU%u_GPIO%u, SDA = PR0_PRU%u_GPIO%u, target 0x%02X\r\n", + PRU_I2C_PRU_CORE, PRU_I2C_PRU_CORE, PRU_I2C_SCL_PIN, + PRU_I2C_PRU_CORE, PRU_I2C_SDA_PIN, PRU_I2C_TARGET_ADDR); + + status = PruI2c_init(); + if (status != SystemP_SUCCESS) + { + DebugP_log("FAIL: PRU I2C init (status %d)\r\n", status); + testStatus = SystemP_FAILURE; + } + + if (testStatus == SystemP_SUCCESS) + { + /* 1. write pointer + data bytes */ + txBuf[0] = PRU_I2C_TARGET_REG; + for (i = 0U; i < PRU_I2C_TEST_LEN; i++) + { + txBuf[1U + i] = (uint8_t)(0xA5U ^ (i * 0x11U)); + } + status = PruI2c_write(PRU_I2C_TARGET_ADDR, txBuf, PRU_I2C_TEST_LEN + 1U, &response); + DebugP_log("Write %u bytes at pointer 0x%02X: response 0x%04X (%s)\r\n", + PRU_I2C_TEST_LEN, PRU_I2C_TARGET_REG, response, PruI2c_responseToString(response)); + if (status != SystemP_SUCCESS) + { + testStatus = SystemP_FAILURE; + } + } + + if (testStatus == SystemP_SUCCESS) + { + /* wait for the internal write cycle of the target */ + ClockP_usleep(PRU_I2C_WRITE_CYCLE_US); + + /* 2. set the pointer ... */ + status = PruI2c_write(PRU_I2C_TARGET_ADDR, txBuf, 1U, &response); + DebugP_log("Write pointer 0x%02X: response 0x%04X (%s)\r\n", + PRU_I2C_TARGET_REG, response, PruI2c_responseToString(response)); + if (status != SystemP_SUCCESS) + { + testStatus = SystemP_FAILURE; + } + } + + if (testStatus == SystemP_SUCCESS) + { + /* 3. ... and read the data back */ + memset(rxBuf, 0, sizeof(rxBuf)); + status = PruI2c_read(PRU_I2C_TARGET_ADDR, rxBuf, PRU_I2C_TEST_LEN, &response); + DebugP_log("Read %u bytes: response 0x%04X (%s)\r\n", + PRU_I2C_TEST_LEN, response, PruI2c_responseToString(response)); + if (status != SystemP_SUCCESS) + { + testStatus = SystemP_FAILURE; + } + } + + if (testStatus == SystemP_SUCCESS) + { + /* 4. compare */ + for (i = 0U; i < PRU_I2C_TEST_LEN; i++) + { + DebugP_log(" byte %u: wrote 0x%02X, read 0x%02X\r\n", i, txBuf[1U + i], rxBuf[i]); + if (txBuf[1U + i] != rxBuf[i]) + { + testStatus = SystemP_FAILURE; + } + } + if (testStatus != SystemP_SUCCESS) + { + DebugP_log("FAIL: read back data does not match\r\n"); + } + } + + if (testStatus == SystemP_SUCCESS) + { + DebugP_log("PASS: PRU I2C write/read back\r\n"); + DebugP_log("All tests have passed!!\r\n"); + } + else + { + DebugP_log("Some tests have failed!!\r\n"); + } + + PRUICSS_disableCore(gPruIcss0Handle, PRU_I2C_PRU_CORE); + PRUICSS_close(gPruIcss0Handle); + Board_driversClose(); + Drivers_close(); +} diff --git a/examples/pru_i2c/readme.md b/examples/pru_i2c/readme.md new file mode 100644 index 000000000..6eb8b9c89 --- /dev/null +++ b/examples/pru_i2c/readme.md @@ -0,0 +1,271 @@ +# PRU I2C Master + +## Introduction + +This project implements an I2C master (controller) in PRU firmware. A PRU core +bit-bangs SCL and SDA with an IEP-timed state machine, and a host core (here an +R5F core running NORTOS) controls the bus through commands and data buffers in +the PRU data RAM. The R5F example in `mcuplus/` loads the firmware, writes a +few bytes to an I2C target, reads them back and prints PASS or FAIL together +with the response code of the PRU firmware for every transfer. + +The project contains: + +* `firmware/`: PRU assembly firmware (`pru_i2c_main.asm`), the memory interface + header (`pru_i2c_interface.h`) and a CCS/makefile project for PRU0 and PRU1 + of ICSSM0. +* `mcuplus/`: R5F host code. `pru_i2c_example.c` is the common host logic, + `mcuplus/am261x-lp/r5fss0-0_nortos/` holds `main.c`, `example.syscfg` and + the CCS/makefile project. + +# Supported Combinations + + Parameter | Value + ---------------|----------- + ICSSM | ICSSM0 - PRU0, PRU1 (firmware). The R5F example runs the firmware on ICSSM0 PRU1 + Toolchain | pru-cgt (PRU firmware), ti-arm-clang (R5F) + Board | am261x-lp + Example folder | examples/pru_i2c/ + +For all other devices and boards see the section "Supported processors +per-project" in the [examples readme](../readme.md). Only the AM261x-LP has +build infrastructure for this project; building for any other device prints +"does not have a build option" and builds nothing. + +# Validated HW & SW + +The AM261x-LP build in this project has **not been run on an AM261x-LP**. The +PRU firmware has run on an LP-AM263 (AM263x) board, see below. + + Item | Version + ---------------------------|----------- + Build: MCU+ SDK | AM261x MCU+ SDK 11.00.00.29 + Build: PRU compiler | ti-cgt-pru 2.3.3 + Build: R5F compiler | ti-cgt-armllvm 4.0.4.LTS + Build: SysConfig | 1.26.0 + Hardware run (AM261x-LP) | not done + Hardware run (LP-AM263) | PRU1 firmware, AM263x MCU+ SDK 26.01.00.08, ti-cgt-armllvm 4.0.4.LTS, SysConfig 1.28 + +LP-AM263 run: the PRU firmware at commit 8f4c1c2c ran at 100 kHz and at the +"400 kHz" setting (367.6 kHz with the 200 MHz IEP clock and the 0.68 us tick +floor). It passed these tests against the on-board CAT23M01 EEPROM and TPIC2810 +LED driver, with the MCU I2C1 controller reading back every PRU transfer: + +* address probe: ACK at 0x61/0x52/0x53, NACK at 0x10/0x21 +* a 16-byte EEPROM read that matches the MCU I2C1 read +* TPIC2810 register writes, read back by the MCU +* an 8-byte EEPROM write and restore, each read back by the MCU + +Later commits only add the selector-to-increment fallback, which the R5F +application does not use because it always writes the IEP increment. + +The only firmware change for that board was the AM263x `ICSSM_PRUx_GPIO_OUT_CTRL` +addresses (MSS_CTRL `0x50D00824`/`0x50D00828`). That change and the AM263x +projects are not part of this project yet. No waveforms were captured, and only +one PRU instance ran at a time. + +# How it works + +## PRU <-> host memory interface + +The host core talks to the firmware through PRU data RAM. The two global +words (IRQ register and frequency) are always in DMEM0, for PRU0 and PRU1 +alike: the firmware reads them through `ICSS_DMEM0_CONST`. The instance block +and the TX/RX buffers are in the data RAM of the core that runs the firmware +(PRU0 -> DMEM0, PRU1 -> DMEM1), at local address 0x100. All offsets and bit +definitions are in +[firmware/pru_i2c_interface.h](firmware/pru_i2c_interface.h), the host code +includes that header instead of repeating the values. + + Offset | Size | Name | Description + ------------------|------|----------------------------------------|------------- + DMEM0 0x0008 | u8[4]| `IRQ_COMMON_REGISTER_OFFSET` | Shared by both cores. One u8 flag per instance at `IRQ_COMMON_REGISTER_OFFSET + ` (0..3): **set to 1 by the PRU** when a response is ready and **cleared to 0 by the host** to acknowledge it. Each side writes only its own byte, so two instances cannot lose each other's flag. The PRU does not accept the next command until the flag is cleared. + DMEM0 0x000C | u16 | `I2C_BUS_FREQUENCY_OFFSET` | Shared by both cores. Bus frequency selector: `ICSS_I2C_100KHZ_FREQ` (3), `ICSS_I2C_400KHZ_FREQ` (2), `ICSS_I2C_1MHZ_FREQ` (1). Any other value sends the firmware into an error loop. + DMEM0 0x000E | u16 | `I2C_BUS_FREQUENCY_OFFSET` + 2 | IEP compare increment per state tick (4 ticks per SCL period), a multiple of the IEP DEFAULT_INC (5). See "Bus frequency" below. + own DMEM 0x0100 | | `ICSS_I2C_INSTANCE0_ADDR` | Start of the instance 0 block (offsets below are relative to it) + + 0x08 | u16 | `ICSS_I2C_COMMAND_OFFSET` | Response of the PRU (`COMMAND_SUCCESS` 0x0500, `ADDRESS_ACKNOWLDEGE_FAILED`, `DATA_ACKNOWLDEGE_FAILED`, `INVALID_DATA_COUNT`, `TIME_OUT_ERROR` (SCL held low too long), `PEC_ERROR`, `INVALID_COMMAND`, ...) + + 0x0A | u16 | `ICSS_I2C_COMMAND_OFFSET` + 2 | Command from the host (`ICSS_I2C_SETUP_CMD`, `ICSS_I2C_TX_CMD`, `ICSS_I2C_RX_CMD`, `ICSS_SMBUS_*_CMD`, ...). The PRU clears it when it raises the response. + + 0x94 / + 0x95 | u8 | `ICSS_I2C_BUF_OFFSET` | TX / RX FIFO size + + 0x98 | u16 | `ICSS_I2C_CNT_OFFSET` | Number of bytes to transfer, 1..255 (I2C) or the block write length; after an SMBus block read, the byte count the target sent + + 0xA4 | u32 | `ICSS_I2C_CON_OFFSET` | Configuration: bit 15 module enable, bit 10 master (must be 1), bit 8 10-bit addressing, bit 6 SMBus PEC, bit 5 reserved, bit 4 NACK the last read byte, bit 1 send STOP, bit 0 send START (bits 4, 1 and 0 apply to I2C transfers; SMBus always sends START/STOP and NACKs the last byte) + + 0xAC | u16 | `ICSS_I2C_SA_OFFSET` | 7-bit target address + + 0xD8 / + 0xD9 | u8 | `ICSS_I2C_PRU_PIN_OFFSET` | SCL / SDA pin: the bit number in R30 (output) and R31 (input) + + 0xE0 | u8 | `ICSS_I2C_PRU_CMD_CODE_OFFSET` | SMBus command code (for quick command, bit 0 is the R/W bit) + + 0xE4 | u8 | `ICSS_I2C_PRU_INST_ID_OFFSET` | Instance id, the byte used in the shared IRQ register. The example uses the core number, so a PRU0 and a PRU1 instance do not collide. + + 0xE8 | u16 | `ICSS_I2C_SCL_TIMEOUT_OFFSET` | Clock stretching limit in state machine ticks (4 per SCL period); 0 = wait indefinitely. The example uses the SMBus 25 ms. + + 0xFE / + 0xFF | | (reserved) | Used by the firmware to stage the SMBus command code and block count + + 0x100 (0x0200) | 256 B| `ICSS_I2C_INSTANCE0_TX_MEM` | TX buffer + + 0x200 (0x0300) | 256 B| `ICSS_I2C_INSTANCE0_RX_MEM` | RX buffer + +The PRU also raises INTC system event SRSR1 bit 20 (PRU0) or bit 21 (PRU1) +(`ICSS_I2C_INTC_PRU0_BIT_VAL`, `ICSS_I2C_INTC_PRU1_BIT_VAL`) when it sets the +IRQ flag. The R5F example does not use this interrupt, it polls the IRQ flag +in the data RAM with a timeout. An interrupt can be added with the +`PRUICSS_intcInit()` / `PRUICSS_registerIrqHandler()` APIs. + +## Sequence + +1. **Configure, then start the PRU.** The firmware reads the frequency words + (0x0C) once while it boots, and `PRUICSS_loadFirmware()` starts the core. + So the host stops the core, clears the data RAM, writes the frequency words + and the instance 0 block (pins, instance id, FIFO sizes, `CON` with module + enable, master, START, STOP and NACK), and only then loads the firmware. +2. **Setup.** Write `ICSS_I2C_SETUP_CMD`, wait for the IRQ flag, check that the + response is `COMMAND_SUCCESS`, clear the IRQ flag. +3. **Transfers.** For each transfer write the target address and the byte + count (and the data into the TX buffer for a write), then write + `ICSS_I2C_TX_CMD` or `ICSS_I2C_RX_CMD`. Wait for the IRQ flag, read the + response (and the RX buffer for a read), clear the IRQ flag. + +The demo uses a generic EEPROM-style target (default address 0x50) that +takes a one byte pointer followed by data: + +1. write `[pointer, d0, d1, d2, d3]` +2. wait 10 ms for the internal write cycle of the target +3. write `[pointer]` (STOP is sent, the target keeps its pointer) +4. read 4 bytes and compare them with what was written + +## SMBus + +The SMBus commands use the same buffers. Write the target address (`SA`), the +command code (+0xE0) and, for writes, the data into the TX buffer, then write +the command: + + Command | On the bus | Host input | Result + -------------------------------|-----------------------------------------|-------------------------|-------- + `ICSS_SMBUS_QUICK_CMD` | S addr+R/W P | R/W = command code bit 0 | - + `ICSS_SMBUS_SEND_BYTE_CMD` | S addr+W cmd P | cmd | - + `ICSS_SMBUS_RECEIVE_BYTE_CMD` | S addr+R data P | - | RX[0] + `ICSS_SMBUS_WRITE_BYTE_CMD` | S addr+W cmd TX[0] P | cmd, TX[0] | - + `ICSS_SMBUS_READ_BYTE_CMD` | S addr+W cmd Sr addr+R data P | cmd | RX[0] + `ICSS_SMBUS_WRITE_WORD_CMD` | S addr+W cmd low high P | cmd, TX[0] low, TX[1] high | - + `ICSS_SMBUS_READ_WORD_CMD` | S addr+W cmd Sr addr+R low high P | cmd | RX[0] low, RX[1] high + `ICSS_SMBUS_BLOCK_WRITE_CMD` | S addr+W cmd N TX[0..N-1] P | cmd, count = N (1..253, 252 with PEC) | - + `ICSS_SMBUS_BLOCK_READ_CMD` | S addr+W cmd Sr addr+R N data[N] P | cmd | count = N, RX[0..N-1] + +With PEC enabled (`CON` bit 6), writes end with the PEC byte and reads check +the target's PEC (`PEC_ERROR` if it does not match). Quick command has no PEC. +SMBus uses 7-bit addresses only. + +## Open-drain bus and clock stretching + +The firmware never drives SCL or SDA high. It keeps both R30 bits at 0 and +switches each line with its bit in the `ICSSM0_PRUx_GPIO_OUT_CTRL` register of +MSS_CTRL (PRU0 at 0x50D00810, PRU1 at 0x50D00814): 1 = output disabled, so the +pull-up takes the line high, 0 = driven low. After releasing SCL it waits +until SCL reads high, so targets can stretch the clock (up to +`ICSS_I2C_SCL_TIMEOUT_OFFSET`). Both pads therefore need the input path +("rx" in SysConfig) and a pull-up. The R5F example sets both +`OUTDISABLE` bits (released) before it starts the PRU. The firmware selects +the register of the core it is built for (`-DPRU0` / `-DPRU1`, and `-DICSSM1` +for ICSSM1). + +# Pin assignment (AM261x-LP) + + Signal | PRU GPIO (R30/R31 bit) | SoC pad | BoosterPack | Direction + -------|------------------------|--------------------|-------------|---------- + SCL | PR0_PRU1_GPIO18 (18) | GPIO120 (ball C19) | J1.4 | open-drain (rx enabled), internal pull-up enabled + SDA | PR0_PRU1_GPIO19 (19) | GPIO119 (ball C18) | J1.3 | open-drain (rx enabled), internal pull-up enabled + +The bit numbers are set with `PRU_I2C_SCL_PIN` and `PRU_I2C_SDA_PIN` in +`mcuplus/pru_i2c_example.c`. The pads are configured in +`mcuplus/am261x-lp/r5fss0-0_nortos/example.syscfg`. The firmware uses one +number per signal for both the R30 output bit and the R31 input bit, so the +GPO and GPI have to be the same `PR0_PRU1_GPIO` pin. If you change a pin, +change it in both files. + +Why PRU1: on the AM261x-LP none of the `PR0_PRU0_GPIOx` (ICSSM0 PRU0) signals +is routed to the BoosterPack headers, they are used by the on-board Ethernet +PHY 0 (RGMII2). `PR0_PRU1_GPIO17`, `GPIO18` and `GPIO19` are routed to +J2.17, J1.4 and J1.3. The firmware itself is built for both PRU0 and PRU1. +To run it on PRU0 set `PRU_I2C_PRU_CORE` to 0 and change the pinmux to pins +that are available on your board. + +How the routing was checked: in the *AM261x LaunchPad User's Guide* +(SPRUJF1D, section 2.12 "Pinmux Mapping", table "Pinmux Options for J1"), +`PR0_PRU1_GPIO19` is the mode 0 function of J1.3 and `PR0_PRU1_GPIO18` the mode +0 function of J1.4. SysConfig 1.26.2 resolves them to GPIO119 and GPIO120. The +SDK Ethernet pinmux for the LP (`icss_dual_emac/am261x-lp/pruicss_pinmux.h`) +does not use these two PRU GPIOs. This was a document and tool check only. It +was **not** checked against the LP schematic or on a board. In the standard +BoosterPack mux mode (BP_MUX_SW_S1:S0 = 00) J1.3 and J1.4 are the BoosterPack +UART3 RX and TX lines, so do not plug in a BoosterPack that drives them. + +# Steps to run the example + +Generic build, load and run steps are not repeated here, see the +[Getting Started](../../docs/getting_started.md) documents. The project +specific steps are: + +1. **Wire the target.** Connect an I2C target to J1.4 (SCL), J1.3 (SDA) and + GND, and power it from 3.3 V. SCL and SDA both need a pull-up resistor + (for example 2.2 k to 4.7 k to 3.3 V). The example also enables the + internal pull-ups of both pads, but they are weak, use external resistors. + The default target is an EEPROM-style device (for example a 24C02) + at address 0x50. Change `PRU_I2C_TARGET_ADDR` (and, if needed, + `PRU_I2C_TARGET_REG`, `PRU_I2C_TEST_LEN`) in `mcuplus/pru_i2c_example.c` + for another device. +2. **Build.** From the repository root (with `DEVICE`, `BUILD_MCUPLUS` and the + tool paths set in `imports.mak`) run + `make DEVICE=am261x BUILD_MCUPLUS=y`, or build only this project with + `make -C examples/pru_i2c all DEVICE=am261x BUILD_MCUPLUS=y`. The PRU + firmware is built first, the R5F build includes the generated + `pru1_load_bin.h`. The R5F image is + `mcuplus/am261x-lp/r5fss0-0_nortos/ti-arm-clang/pru_i2c.release.out` + (the `.mcelf` boot image is generated next to it). With CCS, import the + PRU0/PRU1 firmware projects and the R5F project from `examples/pru_i2c`, + build the PRU projects first. +3. **Run on the R5F core** (r5fss0-0) and open the UART0 console (the log + output of the example goes to UART0, like in the other AM261x examples). + +## Expected output + +With a responding target: + +``` +PRU I2C master example started +PRU core 1, SCL = PR0_PRU1_GPIO18, SDA = PR0_PRU1_GPIO19, target 0x50 +Write 4 bytes at pointer 0x00: response 0x0500 (COMMAND_SUCCESS) +Write pointer 0x00: response 0x0500 (COMMAND_SUCCESS) +Read 4 bytes: response 0x0500 (COMMAND_SUCCESS) + byte 0: wrote 0xA5, read 0xA5 + byte 1: wrote 0xB4, read 0xB4 + byte 2: wrote 0x87, read 0x87 + byte 3: wrote 0x96, read 0x96 +PASS: PRU I2C write/read back +All tests have passed!! +``` + +With no target on the bus the first transfer fails with +`response 0x0508 (ADDRESS_ACKNOWLDEGE_FAILED (no ACK from target))` and the +example prints `Some tests have failed!!`. +A `TIME_OUT_ERROR (no response from PRU)` means the PRU did not answer within +100 ms, for example because the firmware is not running or the setup command +was not accepted. + +# Known limitations + +* Master mode only, one instance (instance 0) per PRU core, no multi-master + arbitration, 7-bit addressing in the example (the `CON` bit for 10-bit + addressing exists in the firmware interface but is not used here; SMBus is + 7-bit only). +* The demo uses plain I2C writes and reads; the SMBus commands are described + above but not exercised by the example code. +* The START and STOP bits of `CON` are latched by the setup command. The + example sets both, so each transfer is a complete START ... STOP transaction. + The pointer-then-read sequence of the demo therefore uses two separate + transactions and works only with targets that keep their pointer across a + STOP (EEPROM-like). Targets that need a repeated START are not covered. +* **Bus frequency.** The `IEP_CMP_INCREMENT_VAL_*` constants in + `pru_i2c_interface.h` assume a 200 MHz IEP clock. With the default SysConfig + settings of this example the IEP clock is 250 MHz + (`CONFIG_PRU_ICSS0_IEP_CLK_FREQ_HZ` in the generated `ti_drivers_config.h`; + 200 MHz needs the R5F at 400 MHz), so the example derives the increment from + that define instead (`PRU_I2C_IEP_INCREMENT`). The tick is the larger of + 1/(4 x `PRU_I2C_BUS_HZ`) and 0.68 us, so that SCL low meets the Fast-mode + minimum of 1.3 us. At 250 MHz and 400 kHz that is 170 IEP clocks per tick, + about 368 kHz. The same floor gave 367.6 kHz on an LP-AM263 (200 MHz IEP + clock), computed from the IEP settings, not measured with a scope. +* The example polls the IRQ flag instead of using the PRU interrupt. +* The example is built for NORTOS on the r5fss0-0 core of the AM261x-LP only. +* Not yet run on an AM261x-LP, see "Validated HW & SW". diff --git a/examples/readme.md b/examples/readme.md index 6bb74c6f3..21f4bbb76 100644 --- a/examples/readme.md +++ b/examples/readme.md @@ -41,6 +41,10 @@ pru_emif * Emulate an Extended Memory Interface (EMIF) client 16-bit/32-bit asynchronous parallel interface to interface with C2K F28379D +pru_i2c +* I2C/SMBus master emulated on PRU GPIOs, with an R5F NORTOS example that + drives it through a shared-memory command interface + pru_i2s * Emulate I2S/TDM protocol using PRU, both Rx and Tx supported @@ -95,6 +99,7 @@ For more information about the PRU features on each processor, refer to app note | logic_scope | Y | Yport | Yport | Yport | Yport | Yport | | pru_eqep | Y | Yport | Yport | Yport | N-sw | Yport | | pru_emif | Y | Yport | Yport | Yport | N-sw | Yport | +| pru_i2c | Yport | Y | Yport | Yport | N-sw | Yport | | pru_i2s | Yport | Y | Yport | Y | N-sw | Yport | | spi_loopback | Y | Yport | Yport | Yport | N-sw | Yport | | fir | Y | Yport | Yport | Yport | Yport | Yport |