LibDriver BPC
Loading...
Searching...
No Matches
driver_bpc_receive_test.c
Go to the documentation of this file.
1
36
38
39static bpc_handle_t gs_handle;
40static volatile uint8_t gs_flag;
41
50{
51 if (bpc_irq_handler(&gs_handle) != 0)
52 {
53 return 1;
54 }
55
56 return 0;
57}
58
64static void a_receive_callback(bpc_t *data)
65{
66 const char week[][10] =
67 {
68 "Sunday",
69 "Monday",
70 "Tuesday",
71 "Wednesday",
72 "Thursday",
73 "Friday",
74 "Saturday",
75 "Invalid",
76 };
77
78 switch (data->status)
79 {
80 case BPC_STATUS_OK :
81 {
82 bpc_interface_debug_print("bpc: irq ok.\n");
83 bpc_interface_debug_print("bpc: time is %04d-%02d-%02d %02d:%02d:%02d %s.\n",
84 data->year, data->month, data->day,
85 data->hour, data->minute, data->second,
86 week[data->week > 7 ? 7 : data->week]);
87 gs_flag = 1;
88
89 break;
90 }
92 {
93 bpc_interface_debug_print("bpc: irq parity error.\n");
94
95 break;
96 }
98 {
99 bpc_interface_debug_print("bpc: irq frame invalid.\n");
100
101 break;
102 }
103 default :
104 {
105 bpc_interface_debug_print("bpc: irq unknown status.\n");
106
107 break;
108 }
109 }
110}
111
120uint8_t bpc_receive_test(uint32_t times)
121{
122 uint8_t res;
123 uint16_t timeout;
124 uint32_t i;
125 bpc_info_t info;
126
127 /* link interface function */
132 DRIVER_BPC_LINK_RECEIVE_CALLBACK(&gs_handle, a_receive_callback);
133
134 /* get information */
135 res = bpc_info(&info);
136 if (res != 0)
137 {
138 bpc_interface_debug_print("bpc: get info failed.\n");
139
140 return 1;
141 }
142 else
143 {
144 /* print chip info */
145 bpc_interface_debug_print("bpc: chip is %s.\n", info.chip_name);
146 bpc_interface_debug_print("bpc: manufacturer is %s.\n", info.manufacturer_name);
147 bpc_interface_debug_print("bpc: interface is %s.\n", info.interface);
148 bpc_interface_debug_print("bpc: driver version is %d.%d.\n", info.driver_version / 1000, (info.driver_version % 1000) / 100);
149 bpc_interface_debug_print("bpc: min supply voltage is %0.1fV.\n", info.supply_voltage_min_v);
150 bpc_interface_debug_print("bpc: max supply voltage is %0.1fV.\n", info.supply_voltage_max_v);
151 bpc_interface_debug_print("bpc: max current is %0.2fmA.\n", info.max_current_ma);
152 bpc_interface_debug_print("bpc: max temperature is %0.1fC.\n", info.temperature_max);
153 bpc_interface_debug_print("bpc: min temperature is %0.1fC.\n", info.temperature_min);
154 }
155
156 /* init */
157 res = bpc_init(&gs_handle);
158 if (res != 0)
159 {
160 bpc_interface_debug_print("bpc: init failed.\n");
161
162 return 1;
163 }
164
165 /* start receive test */
166 bpc_interface_debug_print("bpc: start receive test.\n");
167
168 /* loop */
169 for (i = 0; i < times; i++)
170 {
171 /* 60s timeout */
172 timeout = 6000;
173
174 /* init 0 */
175 gs_flag = 0;
176
177 /* check timeout */
178 while (timeout != 0)
179 {
180 /* check the flag */
181 if (gs_flag != 0)
182 {
183 break;
184 }
185
186 /* timeout -- */
187 timeout--;
188
189 /* delay 10ms */
191 }
192
193 /* check the timeout */
194 if (timeout == 0)
195 {
196 /* receive timeout */
197 bpc_interface_debug_print("bpc: receive timeout.\n");
198 (void)bpc_deinit(&gs_handle);
199
200 return 1;
201 }
202 }
203
204 /* finish receive test */
205 bpc_interface_debug_print("bpc: finish receive test.\n");
206 (void)bpc_deinit(&gs_handle);
207
208 return 0;
209}
driver bpc receive test header file
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_info_s bpc_info_t
bpc information structure definition
uint8_t bpc_deinit(bpc_handle_t *handle)
close the chip
@ BPC_STATUS_FRAME_INVALID
Definition driver_bpc.h:80
@ BPC_STATUS_OK
Definition driver_bpc.h:78
@ BPC_STATUS_PARITY_ERR
Definition driver_bpc.h:79
uint8_t bpc_interface_timestamp_read(bpc_time_t *t)
interface timestamp read
void bpc_interface_delay_ms(uint32_t ms)
interface delay ms
void bpc_interface_debug_print(const char *const fmt,...)
interface print format data
uint8_t bpc_receive_test_irq_handler(void)
receive test irq
uint8_t bpc_receive_test(uint32_t times)
receive test
float temperature_max
Definition driver_bpc.h:146
float supply_voltage_max_v
Definition driver_bpc.h:143
uint32_t driver_version
Definition driver_bpc.h:147
float temperature_min
Definition driver_bpc.h:145
float max_current_ma
Definition driver_bpc.h:144
char manufacturer_name[32]
Definition driver_bpc.h:140
float supply_voltage_min_v
Definition driver_bpc.h:142
char interface[8]
Definition driver_bpc.h:141
char chip_name[32]
Definition driver_bpc.h:139
uint8_t month
Definition driver_bpc.h:90
uint8_t week
Definition driver_bpc.h:92
uint16_t year
Definition driver_bpc.h:89
uint8_t day
Definition driver_bpc.h:91
uint8_t second
Definition driver_bpc.h:95
uint8_t minute
Definition driver_bpc.h:94
uint8_t status
Definition driver_bpc.h:88
uint8_t hour
Definition driver_bpc.h:93