i2c_tx_check(每300ms檢查一次) -> send_rf_cmd() ->
=============================================================
infoManager.c
static timer g_sendi2c_timer;
TAILQ_HEAD(i2c_tx_queue, i2c_tx_message);
struct i2c_tx_queue *tx_q = NULL;
#define RF_WKUP_MAIN 129//ENET0_MDIO bank4 pin1
int send_rf_cmd(struct i2c_tx_message *msg)
{
int ret = 1;
switch(msg->id)
{
.....中間略過......
}
return ret;
}
.................中間略過.................
void* i2c_tx_check(void* unused)
{
int ret = 0;
uint32_t fob_status;
struct i2c_tx_message *m2 = NULL;
ret = gpio_get_value(RF_WKUP_MAIN, &fob_status);
//printf("[Gerald] RF_WKUP_MAIN = %d\n", fob_status);
if(ret > 0)//errno
{
IM_DBG_ERROR("read RF_WKUP_MAIN failed, ret = %d", ret);
return;
}
if((!TAILQ_EMPTY(tx_q)) && (fob_status == 1))//high: ready; low: busy
{
m2 = TAILQ_FIRST(tx_q);
ret = send_rf_cmd(m2);
TAILQ_REMOVE(tx_q, m2, node);
free(m2);
}
}
void start_checker_timer()
{
.................中間略過.................
timer_setup(&g_sendi2c_timer);
.................中間略過.................
g_sendi2c_timer.set_timer(&g_sendi2c_timer, 300, true, i2c_tx_check, NULL);
}
void stop_checker_timer()
{
.................中間略過.................
g_sendi2c_timer.cancel(&g_sendi2c_timer);
}
void init_i2c_tx_queue()
{
tx_q = malloc(sizeof(*tx_q));
TAILQ_INIT(tx_q);
gpio_export(RF_WKUP_MAIN);
gpio_dir_in(RF_WKUP_MAIN);
}
void uninit_i2c_tx_queue()
{
free(tx_q);
}
void make_i2c_message(enum rf_command_table id, char *cmd)
{
struct i2c_tx_message *m1 = NULL;
m1 = calloc(1, sizeof(*m1));
if(m1 == NULL)
{
IM_DBG_ERROR("Can not allocate i2c cmd\n");
}
else
{
m1->id = id;
m1->cmd = cmd;
TAILQ_INSERT_TAIL(tx_q, m1, node);
DKEY_BMW_PROFILE_LOG("cmd_id = %d, value = %s", m1->id, m1->cmd);
}
}
void initInfoManager() {
.................中間略過.................
infoMgr->make_i2c_message = make_i2c_message;
.................中間略過.................
init_i2c_tx_queue();
}
void uninitInfoManager() {
.................中間略過.................
uninit_i2c_tx_queue();
.................中間略過.................
}
==============================================================
infoManager.h
#include <sys/queue.h>
enum rf_command_table {
MASTER_STATE = 1,
ACCESS = 2,
WINDOW = 3,
MISCELLANEOUS = 4,
AUTO_DRIVING = 5,
VEHICLE_FACILITY_CONTROL = 6,
};
struct i2c_tx_message
{
enum rf_command_table id;
char *cmd;
TAILQ_ENTRY(i2c_tx_message) node;
};
typedef struct infoManager_s {
.................中間略過.................
void (*make_i2c_message)();
} infoManager;
void add_language_change_event_notify(enum im_evnet_category_t category, int eve
.................中間略過.................
int send_rf_cmd(struct i2c_tx_message *msg);
========================================================
結論 :
==============================================================
沒有留言:
張貼留言