141 lines
3.1 KiB
C
141 lines
3.1 KiB
C
|
|
#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-><3E><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> ; 1-><3E><><EFBFBD>չ<EFBFBD>Լ ; 2~7-><3E><><EFBFBD><EFBFBD>
|
|||
|
|
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; // <20><>ʱ<EFBFBD><CAB1>2<EFBFBD>ij<EFBFBD>ʼֵ
|
|||
|
|
U16 zc_intv_tmr_us; // <20>ϴι<CFB4><CEB9><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
|
|
|||
|
|
U16 cur_cnt; // <20><><EFBFBD><EFBFBD>buffer<65><72>cnt
|
|||
|
|
U16 diff_buf[TWACS_ZC_INTR_DIFF_BUF_SIZE]; // <20><><EFBFBD><EFBFBD>n<EFBFBD>εIJ<CEB5>ֵ
|
|||
|
|
|
|||
|
|
U16 avg_diff; // <20><><EFBFBD><EFBFBD>n<EFBFBD>ε<EFBFBD>ƽ<EFBFBD><C6BD>ֵ<EFBFBD><D6B5><EFBFBD><EFBFBD>̨һֱ<D2BB>ڼ<EFBFBD><DABC><EFBFBD>
|
|||
|
|
U16 thrd; // <20><><EFBFBD><EFBFBD>ֵ
|
|||
|
|
|
|||
|
|
U8 sync_cnt; // ÿ<><C3BF>PEAK֮<4B><D6AE><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
U8 state; // ״̬<D7B4><CCAC>״̬
|
|||
|
|
|
|||
|
|
U8 max_idx; // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʱ<EFBFBD>õı<C3B5><C4B1><EFBFBD>
|
|||
|
|
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
|
|||
|
|
|