135 uint32_t aggregates = 1;
151 uint32_t pru_extmem_size = (uint32_t)prussdrv_extmem_size();
152 uint32_t pru_extmem_size_demand =
156 if (pru_extmem_size_demand > pru_extmem_size) {
158 "insufficient PRU memory allocated/available.\n"
159 "update uio_pruss configuration:"
160 "options uio_pruss extram_pool_sz=0x%06x",
161 pru_extmem_size_demand);
166 void const *buffer0 = prussdrv_get_virt_addr(pru.
buffer0_addr);
167 void const *buffer1 = prussdrv_get_virt_addr(pru.
buffer1_addr);
216 prussdrv_pru_write_memory(PRUSS0_PRU0_DATARAM, 0, (
unsigned int *)&pru,
220 __sync_synchronize();
230 res = prussdrv_pru_wait_event_timeout(PRU_EVTOUT_0,
PRU_TIMEOUT_US);
234 errno, strerror(errno));
236 }
else if (res == 0) {
249 if (daemon(1, 1) < 0) {
251 "failed to create background process; %d message: %s", errno,
258 pid_t pid = getpid();
262 prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
265 int32_t *
const analog_buffer = (int32_t *)malloc(
267 uint32_t *
const digital_buffer =
273 size_t sensor_buffer_size = 0;
274 uint32_t sensor_rate_counter = 0;
277 uint32_t buffers_lost = 0;
278 uint32_t num_files = 1;
279 bool web_failure_disable =
false;
282 uint32_t buffer_read_count =
301 uint64_t file_size = (uint64_t)ftello(data_file);
309 char file_name[PATH_MAX];
310 char new_file_ending[PATH_MAX];
315 char *file_ending = file_name;
316 while (strchr(file_ending, target) != NULL) {
317 file_ending = strchr(file_ending, target);
324 sprintf(new_file_ending,
"_p%d", num_files);
325 strcat(new_file_ending, file_ending);
326 strcpy(file_ending, new_file_ending);
329 data_file = fopen64(file_name,
"w+");
347 fclose(ambient_file);
350 char *ambient_file_name =
352 strcpy(file_name, ambient_file_name);
355 file_ending = file_name;
356 while (strchr(file_ending, target) != NULL) {
357 file_ending = strchr(file_ending, target);
364 sprintf(new_file_ending,
"_p%d", num_files);
365 strcat(new_file_ending, file_ending);
366 strcpy(file_ending, new_file_ending);
369 ambient_file = fopen64(file_name,
"w+");
377 &ambient_file_header);
394 if (i < buffer_read_count - 1 ||
403 sensor_buffer_size = 0;
412 sensor_rate_counter =
420 res = prussdrv_pru_wait_event_timeout(PRU_EVTOUT_0,
PRU_TIMEOUT_US);
423 }
while (res < 0 && errno == EINTR);
427 "Failed waiting for PRU interrupt; %d message: %s", errno,
431 }
else if (res == 0) {
440 timestamp_realtime.
nsec -= (int64_t)2048e3 * 490 / config->
update_rate;
441 if (timestamp_realtime.
nsec < 0) {
442 timestamp_realtime.
sec -= 1;
443 timestamp_realtime.
nsec += (int64_t)1e9;
445 timestamp_monotonic.
nsec -= (int64_t)2048e3 * 490 / config->
update_rate;
446 if (timestamp_monotonic.
nsec < 0) {
447 timestamp_monotonic.
sec -= 1;
448 timestamp_monotonic.
nsec += (int64_t)1e9;
452 prussdrv_pru_clear_event(PRU_EVTOUT_0, PRU0_ARM_INTERRUPT);
455 __sync_synchronize();
461 "overrun: %d samples (%d buffer) lost (%d in total)",
468 for (
size_t i = 0; i < buffer_size; i++) {
474 uint32_t *
const digital_data = digital_buffer + i;
493 errno, strerror(errno));
497 if (config->
web_enable && !web_failure_disable) {
499 sensor_buffer, buffer_size,
500 sensor_buffer_size, ×tamp_realtime,
501 ×tamp_monotonic, config);
504 web_failure_disable =
true;
506 "Web server connection failed; %d message: %s", errno,
509 "Disabling web interface and continue sampling.");
517 data_file, analog_buffer, digital_buffer, buffer_size,
518 ×tamp_realtime, ×tamp_monotonic, config);
521 if (block_count < 0) {
523 "Adding data block to data file failed; %d message: %s",
524 errno, strerror(errno));
532 block_count * (buffer_size / aggregates);
545 ambient_file, sensor_buffer, sensor_buffer_size,
546 ×tamp_realtime, ×tamp_monotonic, config);
549 if (block_count < 0) {
552 "Adding data block to ambient file failed; %d message: %s",
553 errno, strerror(errno));
568 ×tamp_realtime, ×tamp_monotonic,
586 free(digital_buffer);
597 free(data_file_header.
channel);
601 fflush(ambient_file);
602 free(ambient_file_header.
channel);