43#define CHIP_NAME "China BPC"
44#define MANUFACTURER_NAME "China"
45#define SUPPLY_VOLTAGE_MIN 2.7f
46#define SUPPLY_VOLTAGE_MAX 5.5f
47#define MAX_CURRENT 1.5f
48#define TEMPERATURE_MIN -40.0f
49#define TEMPERATURE_MAX 125.0f
50#define DRIVER_VERSION 1000
55#define BPC_CHECK_START_FRAME_MIN (1600 * 1000)
56#define BPC_CHECK_START_FRAME_MAX (1900 * 1000)
57#define BPC_CHECK_FRAME_TIME (1000 * 1000)
58#define BPC_CHECK_DATA_0 (100 * 1000)
59#define BPC_CHECK_DATA_1 (200 * 1000)
60#define BPC_CHECK_DATA_2 (300 * 1000)
61#define BPC_CHECK_DATA_3 (400 * 1000)
72static inline uint8_t a_check_frame(uint32_t check, uint32_t t)
74 if (abs((
int)((
int)check - (
int)t)) > (
int)((
float)(t) *
BPC_MAX_RANGE))
93static inline uint8_t a_check_frame2(uint32_t check, uint32_t remain_check, uint32_t t)
97 total = check + remain_check;
104 if (abs((
int)((
int)check - (
int)t)) > (
int)((
float)(t) *
BPC_MAX_RANGE))
123static inline uint8_t a_check_start_frame(uint32_t check)
145 diff = (int64_t)((int64_t)handle->
decode[0].
t.
s -
147 (int64_t)((int64_t)handle->
decode[0].
t.
us -
149 if (a_check_start_frame((uint32_t)diff) == 0)
175 for (i = 0; i < len; i++)
179 diff = (int64_t)((int64_t)handle->
decode[i + 1].
t.
s -
180 (int64_t)handle->
decode[i].
t.
s) * 1000000 +
181 (int64_t)((int64_t)handle->
decode[i + 1].
t.
us -
184 if (a_check_start_frame((uint32_t)handle->
decode[i].
diff_us) == 0)
199static uint8_t a_bpc_data_decode(
bpc_handle_t *handle, uint32_t diff_us, uint8_t *data)
242static uint8_t a_bpc_data_decode2(
bpc_handle_t *handle, uint32_t diff_us, uint32_t remain_diff_us, uint8_t *data)
302 for (i = 0; i < len; i++)
306 diff = (int64_t)((int64_t)handle->
decode[i + 1].
t.
s -
307 (int64_t)handle->
decode[i].
t.
s) * 1000000 +
308 (int64_t)((int64_t)handle->
decode[i + 1].
t.
us -
314 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
373 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
399 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
424 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
449 data.
hour = (temp0 << 2) | temp1;
451 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
476 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
501 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
526 data.
minute = ((uint8_t)temp0 << 4) | ((uint8_t)temp1 << 2) | temp2;
528 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
553 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
578 data.
week = (temp0 << 2) | temp1;
580 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
610 count += parity & 0x1;
616 count += parity & 0x1;
622 count += parity & 0x1;
628 count += parity & 0x1;
634 count += parity & 0x1;
640 if ((count % 2) != 0)
665 if ((count % 2) == 0)
690 if ((count % 2) != 0)
716 if ((count % 2) == 0)
741 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
766 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
791 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
816 data.
day = ((uint8_t)temp0 << 4) | ((uint8_t)temp1 << 2) | temp2;
818 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
843 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
868 data.
month = (temp0 << 2) | temp1;
870 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
895 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
920 res = a_bpc_data_decode2(handle, (uint32_t)handle->
decode[ind].
diff_us,
945 data.
year = ((uint8_t)temp0 << 4) | ((uint8_t)temp1 << 2) | temp2;
947 res = a_bpc_data_decode(handle, (uint32_t)handle->
decode[ind].
diff_us, &p4);
975 count += parity & 0x1;
981 count += parity & 0x1;
987 count += parity & 0x1;
992 if ((count % 2) != 0)
1018 if ((count % 2) == 0)
1044 if ((count % 2) != 0)
1066 data.
year = ((uint16_t)1 << 6);
1071 if ((count % 2) == 0)
1093 data.
year = ((uint16_t)1 << 6);
1142 handle->
debug_print(
"bpc: timestamp read failed.\n");
1146 diff = (int64_t)((int64_t)t.
s -
1148 (int64_t)((int64_t)t.
us -
1150 if (diff - (int64_t)3000000L >= 0)
1169 a_bpc_trace_decode(handle);
1175 a_bpc_decode(handle);
1179 a_bpc_start_decode(handle);
1213 handle->
debug_print(
"bpc: timestamp_read is null.\n");
1225 handle->
debug_print(
"bpc: receive_callback is null.\n");
1233 handle->
debug_print(
"bpc: timestamp read failed.\n");
#define SUPPLY_VOLTAGE_MAX
#define BPC_CHECK_START_FRAME_MAX
#define BPC_CHECK_START_FRAME_MIN
frame check definition
#define MANUFACTURER_NAME
#define SUPPLY_VOLTAGE_MIN
#define BPC_CHECK_FRAME_TIME
#define CHIP_NAME
chip information definition
uint8_t bpc_irq_handler(bpc_handle_t *handle)
irq handler
uint8_t bpc_info(bpc_info_t *info)
get chip's information
uint8_t bpc_init(bpc_handle_t *handle)
initialize the chip
struct bpc_handle_s bpc_handle_t
bpc handle structure definition
struct bpc_s bpc_t
bpc structure definition
struct bpc_time_s bpc_time_t
bpc time structure definition
struct bpc_info_s bpc_info_t
bpc information structure definition
uint8_t bpc_deinit(bpc_handle_t *handle)
close the chip
#define BPC_MAX_RANGE
bpc max range definition
#define BPC_MAX_START_RANGE
bpc max start range definition
@ BPC_STATUS_FRAME_INVALID
void(* delay_ms)(uint32_t ms)
void(* receive_callback)(bpc_t *data)
void(* debug_print)(const char *const fmt,...)
uint8_t(* timestamp_read)(bpc_time_t *t)
float supply_voltage_max_v
char manufacturer_name[32]
float supply_voltage_min_v