#include "pinctrl_porting.h"
#include "hx3508_hal.h"
#include "custom_runtime.h"
+#include "errcode.h"
+#include "thread_init.h"
// #include "tyhx_hrs_custom.h"
//平台头文件包含定义
#ifdef NORDIC_SDK
static osTimerId_t g_hx3508_timer = NULL;
+/* 表冠自己的消息队列与线程,用于处理 ROTARY_OPEN */
+#define ROTARY_MSG_OPEN 1
+#define ROTARY_QUEUE_MSG_COUNT 10
+#define ROTARY_TASK_STACK_SIZE 0x400
+#define ROTARY_BOARD_TASK_PRIO 7
+typedef struct {
+ uint8_t cmd;
+ uint8_t data[5];
+} rotary_cmd_t;
+static unsigned long g_rotary_queue = 0xFFFFFFFF;
+static bool g_rotary_queue_created = false;
+static bool g_rotary_service_inited = false;
+
extern encoder_callback g_encoder_callback;
static uint8_t ost_init = 0;
/**
- * OTS 定时器创建函数
- * @param NULL
+ * 表冠消息队列创建(由 uapi_create_osThread_custom 内 create_queue_handle 调用)
+ */
+static void create_rotary_queue(void)
+{
+ if (osal_msg_queue_create("rotary_service_queue", ROTARY_QUEUE_MSG_COUNT, &g_rotary_queue,
+ 0, sizeof(rotary_cmd_t)) != ERRCODE_SUCC) {
+ TYHX_LOG("rotary create queue fail\n");
+ g_rotary_queue_created = false;
+ } else {
+ g_rotary_queue_created = true;
+ }
+}
+
+/**
+ * 表冠线程:从队列取消息并执行,与 custom_fileoperate_service 同风格
+ */
+static void rotary_task_func(void const *arg)
+{
+ (void)arg;
+ int32_t ret;
+ rotary_cmd_t mail;
+ uint32_t msgsize = (uint32_t)sizeof(rotary_cmd_t);
+
+ while (1) {
+ ret = osal_msg_queue_read_copy(g_rotary_queue, (void *)&mail, &msgsize,
+ OSAL_MSGQ_WAIT_FOREVER);
+ if (ret != OSAL_SUCCESS) {
+ continue;
+ }
+ switch (mail.cmd) {
+ case ROTARY_MSG_OPEN:
+ hx3508_open();
+ break;
+ default:
+ break;
+ }
+ }
+}
+
+/**
+ * OTS 定时器创建函数;同时按 custom_fileoperate_service 方式创建表冠队列与线程
*/
void ots_timer_creat(void)
{
- // app_timer_create(&g_hx3508_timer, APP_TIMER_MODE_REPEATED, ots_timer_handler);
- if(g_hx3508_timer == NULL)
+ if (g_hx3508_timer == NULL)
g_hx3508_timer = osTimerNew((osTimerFunc_t)ots_timer_handler, osTimerPeriodic, NULL, NULL);
+
+ if (!g_rotary_service_inited) {
+ app_task_definition_t taskcfg = {0};
+ taskcfg.create_queue_handle = create_rotary_queue;
+ taskcfg.attr.name = "rotary_service";
+ taskcfg.attr.priority = osPriorityNormal;
+ taskcfg.attr.stack_size = ROTARY_TASK_STACK_SIZE;
+ taskcfg.func = (osThreadFunc_t)rotary_task_func;
+ taskcfg.use_mem = USE_EXTEND_MEM;
+
+ if (uapi_create_osThread_custom(&taskcfg) == ERRCODE_SUCC) {
+ g_rotary_service_inited = true;
+ }
+ }
}
/**
void hx3508_int_callback(pin_t pin, uintptr_t param)
{
- // printf("hx3508_int_callback %d 0x%X\n",pin,param);
+ (void)param;
uapi_gpio_clear_interrupt(pin);
- if(!uapi_dev_runtime_get_train_status())
- do_custom_cmd_service_check_msg(CUSTOM_CMD_MSG_ROTARY_OPEN,NULL,0);
+ if (!uapi_dev_runtime_get_train_status() && g_rotary_queue_created && g_rotary_queue != 0xFFFFFFFF) {
+ rotary_cmd_t mail = {0};
+ mail.cmd = ROTARY_MSG_OPEN;
+ (void)osal_msg_queue_write_copy(g_rotary_queue, (void *)&mail, sizeof(rotary_cmd_t), 0);
+ }
}
void hx3508_open(void)