Skip to content

MouchenHung/PROJ_Q_YV3p5_I2C_SLAVE

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 

Repository files navigation

PROJ_Q_YV3p5_I2C_SLAVE

I2C slave device relative code.

==================================================================================

OVERLOOK - LATEST

==================================================================================
PHASE1. DEVICE CODE v1.4.1 2021.12.02
PHASE2. PLATFORM CODE v1.3 2021.12.06
==================================================================================

COMMIT CONTEXT

==================================================================================

{ PHASE1. DEVICE CODE }

NAME: I2C SLAVE DEVICE
FILE: hal_i2c_slave.c
DESCRIPTION: There is 1 callback function "i2c_slave_cb" for I2C slave ISR handle and user APIs "q_*" for user access.
AUTHOR: MouchenHung
DATE/VERSION: 2021.12.02 - v1.4.1
Note:
(1) Shall not modify code in this file!!!

(2) "hal_i2c_slave.h" must be included!

(3) User APIs follow check-rule before doing task

          [api]                               [.is_init] [.is_register]
        * i2c_slave_control                   X          X
        * i2c_slave_read                      O          X
        * i2c_slave_status_get                X          X
        * i2c_slave_status_print              X          X
        * i2c_slave_cfg_get                   O          X
                                              (O: must equal 1, X: no need to check)

(4) I2C slave function/api usage recommend
[ACTIVATE]
Use "i2c_slave_control()" to register/modify/unregister slave bus
[READ]
Use "i2c_slave_read()" to read slave queue message

(5) Slave queue method: Zephyr api, unregister the bus while full msgq, register back while msgq get space.

HISTORY_________________________________________________________________

v1.0 - 2021.11.23 - First commit
v1.1 - 2021.11.24 - Code modify1
* Simplify code
* Remove".is_msg_full" from struct "i2c_slave_device"
* Modify "MAX_I2C_SLAVE_BUFF" from 255 to 512
* Remove first byte (slave address) from buffer in slave callback function
* Add new input arg from "util_init_I2C_slave()", to control whether need to do slave register after init
* Add "util_register_I2C_slave()" to user api
v1.2 - 2021.11.25 - Code modify2
* Solve message queue memory free issue
* Add platform code to exclude modifiable code from previous "hal_i2c_slave.c"
* Remove init and register action in function "util_init_I2C_slave()", which means additional action is needed in main function
* Move i2c slave table "I2C_SLAVE_CFG_TABLE[]" and "util_init_I2C_slave()" to "plat_i2c_slave.c" as platform file
v1.4 - 2021.12.01 - Code modify3
* Bug fixed
* Simplify code
v1.4.1 - 2021.12.01 - Code modify4
* Bug fixed
* Simplify code


{ PHASE2. PLATFORM CODE }

NAME: I2C SLAVE INIT
FILE: plat_i2c_slave.c
DESCRIPTION: Provide i2c slave config table "I2C_SLAVE_CFG_TABLE[]" for init slave config.
AUTHOR: MouchenHung
DATE/VERSION: 2021.12.06 - v1.2
Note:
(1) "plat_i2c_slave.h" is included by "hal_i2c_slave.h"

HISTORY_________________________________________________________________

v1.0 - 2021.11.25 - First commit
v1.1 - 2021.12.02 - Modify code
v1.2 - 2021.12.06 - Add util_init function
v1.3 - 2021.12.06 - Modify code

==================================================================================

USAGE

==================================================================================
[STEP1. Set bus and address main.c]
	static mctp_smbus_port smbus_port[MCTP_SMBUS_NUM] = {
		{.conf.smbus_conf.addr = 0x60, .conf.smbus_conf.bus = 0x00},
		{.conf.smbus_conf.addr = 0x40, .conf.smbus_conf.bus = 0x01}
	};
[STEP2. Add init function to main.c "main()"]
	util_init_I2C_slave();

	uint32_t i;
	for (i = 0; i < MCTP_SMBUS_NUM; i++) {
[STEP3. Add read api to "mctp_smbus_read"]
	uint8_t ret = i2c_slave_read(mctp_inst->medium_conf.smbus_conf.bus, rdata, ARRAY_SIZE(rdata), &rlen);
	if (ret){
	printk("Error occur: couse of errorcode[%d]\n", ret);
	}

About

I2C slave device relative code.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages