Files
kunlun/import/sby/inc/lib_twacs_zc.h
2024-09-28 14:24:04 +08:00

141 lines
3.1 KiB
C
Executable File
Raw 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.

#ifndef _LIB_TWACS_ZC_H_
#define _LIB_TWACS_ZC_H_
#include <string.h>
#include "typedef.h"
//#define DEBUG_UART
#ifdef DEBUG_UART
void example_send_char_via_com(U8 ch);
#endif
#define TWACS_ZC_INTR_DIFF_BUF_SIZE 20
#define TWACS_ZC_THRD_OFFSET 60
#define TWACS_INTV_CNT_BUF_SIZE 32
#define TWACS_INTV_CNT_MIN 21
#define TWACS_INTV_CNT_MAX 32
#define TWACS_VAILED_DIFF_MAX_VAL (40)
#define JFG_MODE_MIN_VALUE 21
#define JFG_MODE_MAX_VALUE 29
#define JQ_MODE_MIN_VALUE 25
#define JQ_MODE_MAX_VALUE 32
#define AUTO_MODE (0)
#define JFG_MODE (1)
#define JQ_MODE (2)
#define TWACS_MODE AUTO_MODE
typedef enum{
SSTATE_DET_PEAK,
SSTATE_DET_MAX_PEAK,
SSTATE_UPDATE_PEAK,
} twacs_zc_state_t;
typedef struct
{
U8 key_bytes_ver; //must be 0xFD
U8 rsv0;
U8 pkt_num_lo;
U8 code_type :4;
U8 chip_type :4;
U8 acode_type;
U8 checksum_lo;
U8 checksum_hi;
U8 pkt_num_hi;
U16 mcu_version;
U8 rsv1[5];
U8 hid_num; //must be 1
U16 hid[1];
U8 rev2[14];
U8 phy_cfg[12];
U8 dll_cfg[4];
// app config
U16 sw_ver;
U8 firm[4];
U8 date;
U8 month;
U8 year;
U8 std_376p2 :1; //0->std_13 ; 1->std_09
U8 dst_addr_mod :1; //0->from 376.2 ; 1->from 645
U8 cjq_ii_mod :3; //0->¹úÍø±ê×¼ ; 1->°²»Õ¹æÔ¼ ; 2~7->±£Áô
U8 cjq_i_fixed :1; //0->uart_test ; 1->fixed
U8 auto_search_ena :1;
U8 panid_ena :1;
U8 gwd_ena :1;
U8 rev3 :7;
U8 app_rev[5];
} lib_mcu_key_bytes_t;
typedef struct
{
U8 sec_20ms_cnt;
U8 sec_chg_flag;
U8 sec_cnt;
U8 min_cnt;
U8 hor_cnt;
}auto_thrd_t;
typedef struct
{
U8 rx_finish_flag;
U8 rx_mode;
U16 rx_finish_val;
U8 zc_inter;
U16 time2_reload_val; // ¶¨Ê±Æ÷2µÄ³õʼֵ
U16 zc_intv_tmr_us; // ÉϴιýÁãµÄʱ¼ä
U16 cur_cnt; // ÏÂÃæbufferµÄcnt
U16 diff_buf[TWACS_ZC_INTR_DIFF_BUF_SIZE]; // ×î½ün´ÎµÄ²îÖµ
U16 avg_diff; // ×î½ün´ÎµÄƽ¾ùÖµ£¬ºǫ́һֱÔÚ¼ÆËã
U16 thrd; // ÃÅÏÞÖµ
U8 sync_cnt; // ÿ¸öPEAKÖ®¼äµÄ¹ýÁãÖÜÆÚÊý
U8 state; // ״̬»ú״̬
U8 max_idx; // ÒëÂëÊý¾ÝʱÓõıäÁ¿
U8 intv_idx;
U8 intv_info[TWACS_INTV_CNT_BUF_SIZE];
U16 thrd_info[TWACS_INTV_CNT_BUF_SIZE];
U8 get_one_byte_flag;
U8 bak_intv_idx;
U8 bak_intv_info[TWACS_INTV_CNT_BUF_SIZE];
U16 bak_thrd_info[TWACS_INTV_CNT_BUF_SIZE];
U16 zc_timer;
auto_thrd_t auto_thrd;
} twacs_zc_vars_t;
U16 twacs_get_zc_intv_us(U16 zc_timer);
U16 calc_diff_avg(void);
void twacs_zc_sync(void);
void twacs_background_decode (void);
void jfg_zc_decode (void);
void jq_zc_decode (void);
void twacs_zc_background_rx_data(void);
void row_timer_calc(void);
void print_char(U8 ch);
void twacs_zc_datapro(void);
U8 zc_cs_get (U8 * dat, U16 datlen);
#endif