Files
2024-09-28 14:24:04 +08:00

133 lines
3.8 KiB
Plaintext
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

diff --git a/iotelic/kunlun/Mainline/startup/misc/main.c b/iotelic/kunlun/Mainline/startup/misc/main.c
index 8b90072..44f5f07 100644
--- a/iotelic/kunlun/Mainline/startup/misc/main.c
+++ b/iotelic/kunlun/Mainline/startup/misc/main.c
@@ -57,13 +57,127 @@ static void startup_ftm_init()
proto_ftm_init();
#endif
}
+extern void iot_wdg_feed_dog();
+uint32_t iot_rtc_init(void);
+
+#include "iot_i2c_slave_api.h"
+#include "iot_i2c_api.h"
+
+
+uint8_t v = 0;
+void int_test(int t)
+{
+ //iot_printf("\r\n%d\r\n", __LINE__);
+ iot_gpio_value_set(44, v%2);
+ v++;
+ iot_gpio_interrupt_enable(t, 1);
+}
+#define IRAM_FUNC(x) __attribute__((section(".iram."#x))) x
+
+uint8_t IRAM_ATTR send_buf[100] = {0x10, 0x20, 0x30, 0x40, 0x50,0x60,0x70,0x80,0x90};
+uint8_t IRAM_ATTR recv_buf[100] = {0xa0, 0xb0, 0xc0, 0xd0};
+
+
+uint8_t IRAM_ATTR memory_buf[256] = {0};
+uint8_t IRAM_ATTR memory_addr=0;
+
+int IRAM_ATTR times = 0;
+void IRAM_FUNC(iot_i2c_slave_callback)(bool_t t);
+
+void iot_i2c_slave_callback(bool_t t)
+{
+ if(true == t) { // master 读数据这里是slaver 所以需要发送数据
+ iot_i2c_s_write_data(IOT_I2C_S_PORT_0, send_buf, 1);
+ } else { // master 写数据这里是slaver 所以需要接收数据
+ int num = iot_i2c_s_get_data_num(IOT_I2C_S_PORT_0);
+ uint8_t device_addr = iot_i2c_s_fifo_read_byte(IOT_I2C_S_PORT_0); //第一个字节为device地址
+ device_addr = device_addr;
+ times = 0;
+ memory_addr = iot_i2c_s_fifo_read_byte(IOT_I2C_S_PORT_0); //第二个字节为要写入的存储器首地址
+
+ //如果后面还有则为data
+ for(int i = 0; i < num - 2; i++) {
+ memory_buf[memory_addr + i] = iot_i2c_s_fifo_read_byte(IOT_I2C_S_PORT_0);
+ //iot_printf("recv_buf[%d]=%02x\r\n", i, recv_buf[i] & 0xff );
+ }
+ //iot_printf("\r\n\r\n");
+ }
+
+}
+
+
+
void iot_startup_init_task(void *arg)
{
uint8_t gpio_3v3;
+ //int gpio1 = 43;
for (;;) {
+
/* sub system init */
iot_sub_system_init();
+ iot_gpio_open_as_output(40);
+
+ //iot_gpio_open_as_interrupt(gpio1);
+ //iot_gpio_interrupt_config(gpio1, GPIO_INT_EDGE_BOTH, int_test, gpio1, 0);
+ //iot_gpio_interrupt_enable(gpio1, 1);
+
+
+
+ iot_printf("task 22 entry....\n");
+
+
+ iot_i2c_slave_cfg_t slave_cfg;
+
+
+
+ slave_cfg.port = IOT_I2C_S_PORT_0;
+ slave_cfg.addr = 0x0d;
+ slave_cfg.gpio.scl = 43;
+ slave_cfg.gpio.sda = 44;
+ slave_cfg.callback = iot_i2c_slave_callback;
+ iot_i2c_slave_init(&slave_cfg);
+
+//
+ // i2c master init
+ int gpio1 = 18;
+ int gpio2 = 19;
+
+ iot_i2c_module_cfg_t g_cfg = {0};
+ g_cfg.port = IOT_I2C_PORT_0;
+ g_cfg.nack_wait_num = 10;
+ g_cfg.baud = 20;
+ g_cfg.gpio.scl = gpio1;
+ g_cfg.gpio.sda = gpio2;
+ iot_i2c_module_init(&g_cfg);
+
+
+ //iot_gpio_open_as_output(gpio1);
+ //iot_gpio_open_as_output(gpio2);
+ for(;;) {
+
+ //iot_gpio_value_set(gpio1, 0);
+ //iot_gpio_value_set(gpio1, 1);
+
+ //iot_gpio_value_set(gpio2, 0);
+ //iot_gpio_value_set(gpio2, 1);
+
+ iot_printf("task 1 entry....\n");
+ if(0) {
+ if (0 != iot_i2c_write(g_cfg.port, 0x0d, (char *)recv_buf, 4)) {
+ iot_printf("i2c_write err\r\n");
+ }
+ }
+
+ if (0 != iot_i2c_read(g_cfg.port, 0x0d, (char *)recv_buf, 1)) {
+
+ }
+
+ os_delay(1000);
+ iot_wdg_feed_dog();
+
+ }
+//----------------------------------------------------------------------------------
/* open the 3v3 power for bluetooth, wifi, rtc and em_ext module */
gpio_3v3 = iot_board_get_gpio(GPIO_P3V3_EN);