2024-02-23 22:25:47 +08:00
|
|
|
#include "by_tiny_frame_master_write.h"
|
2024-02-15 22:50:20 +08:00
|
|
|
|
2024-02-24 18:32:52 +08:00
|
|
|
#if defined(BY_TF_DEVICE_MASTER)
|
|
|
|
|
|
|
|
|
|
#include "by_tiny_frame_pack.h"
|
|
|
|
|
#include "by_tiny_frame_parse.h"
|
|
|
|
|
|
2024-02-23 22:25:47 +08:00
|
|
|
void by_tiny_frame_write_run(void)
|
|
|
|
|
{
|
2024-02-24 18:32:52 +08:00
|
|
|
// nothing
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void by_tiny_frame_write(uint8_t slave_id, uint16_t reg_addr, uint32_t data)
|
|
|
|
|
{
|
2024-03-02 16:02:22 +08:00
|
|
|
if(by_tiny_frame_pack_lock){
|
|
|
|
|
//写入忙处理
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-02-24 18:32:52 +08:00
|
|
|
// 填充数据
|
|
|
|
|
by_tf_pack_frame_t frame_s;
|
|
|
|
|
frame_s.slave_id = slave_id;
|
|
|
|
|
frame_s.cmd = BY_TINY_FRAME_WRITE_CMD_CODE;
|
|
|
|
|
frame_s.reg_addr = reg_addr;
|
|
|
|
|
frame_s.data = data;
|
|
|
|
|
|
|
|
|
|
// 发送写请求
|
|
|
|
|
by_tiny_frame_pack_send(&frame_s);
|
|
|
|
|
// 设置响应监听 id
|
|
|
|
|
by_tiny_frame_parse_set_listen_slave_id(slave_id);
|
|
|
|
|
// 注册响应监听回调
|
|
|
|
|
by_tiny_frame_parse_handle_register(by_tiny_frame_write_handle);
|
|
|
|
|
// 开启响应监听
|
|
|
|
|
by_tiny_frame_parse_start_listen();
|
|
|
|
|
|
2024-03-02 16:02:22 +08:00
|
|
|
by_tiny_frame_pack_lock = 1;
|
2024-02-24 18:32:52 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void by_tiny_frame_write_handle(by_tf_parse_frame_t frame_s, uint8_t status)
|
|
|
|
|
{
|
2024-03-02 16:02:22 +08:00
|
|
|
by_tiny_frame_pack_lock = 0;
|
2024-02-24 18:32:52 +08:00
|
|
|
|
|
|
|
|
#if (BY_TF_DEBUG)
|
|
|
|
|
printf("****** WRITE REGISTER DONE ******\r\n");
|
|
|
|
|
printf("SLAVE ID: 0x%0.2X\r\n", frame_s.frame[0]);
|
|
|
|
|
printf("\t--cmd: %0.2X\n\t--reg_addr: 0x%0.4X\n\t--data: 0x%0.8X\r\n", frame_s.cmd, frame_s.reg_addr, frame_s.data);
|
|
|
|
|
if (status) {
|
|
|
|
|
printf("write operation failed!!!\r\n");
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
printf("write operation successful!!!\r\n");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif
|