RocketLogger  2.0.2
pru.c File Reference
#include <errno.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <linux/limits.h>
#include <pruss_intc_mapping.h>
#include <prussdrv.h>
#include <sys/types.h>
#include <unistd.h>
#include "calibration.h"
#include "log.h"
#include "meter.h"
#include "rl.h"
#include "rl_file.h"
#include "rl_socket.h"
#include "sem.h"
#include "sensor/sensor.h"
#include "util.h"
#include "pru.h"
+ Include dependency graph for pru.c:

Go to the source code of this file.

Functions

int pru_init (void)
 
void pru_deinit (void)
 
int pru_control_init (pru_control_t *const pru_control, rl_config_t const *const config, uint32_t aggregates)
 
int pru_set_state (pru_state_t state)
 
int pru_sample (FILE *data_file, FILE *ambient_file, rl_config_t const *const config)
 
void pru_stop (void)
 

Function Documentation

◆ pru_control_init()

int pru_control_init ( pru_control_t *const  pru_control,
rl_config_t const *const  config,
uint32_t  aggregates 
)

PRU data structure initialization.

Parameters
pru_controlPRU data structure to initialize
configCurrent measurement configuration
aggregatesNumber of samples to aggregate for sampling rates smaller than the minimal ADC rate (set 1 for no aggregates)
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 80 of file pru.c.

References pru_control::buffer0_addr, pru_control::buffer1_addr, pru_control::buffer_length, PRU_BUFFER_STATUS_SIZE, PRU_DIGITAL_SIZE, PRU_SAMPLE_SIZE, PRU_STATE_SAMPLE_CONTINUOUS, PRU_STATE_SAMPLE_FINITE, RL_CHANNEL_COUNT, RL_SAMPLE_RATE_MIN, pru_control::sample_limit, rl_config::sample_limit, pru_control::sample_rate, rl_config::sample_rate, pru_control::state, SUCCESS, and rl_config::update_rate.

Referenced by pru_sample().

◆ pru_deinit()

void pru_deinit ( void  )

Shutdown PRU and deinitialize PRU driver.

Halt the PRU, unmap PRU shared memory and disable PRU interrupts.

Definition at line 74 of file pru.c.

Referenced by hw_deinit().

◆ pru_init()

int pru_init ( void  )

Copyright (c) 2016-2020, ETH Zurich, Computer Engineering Group All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
  • Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Definition at line 57 of file pru.c.

References ERROR, rl_log(), RL_LOG_ERROR, and SUCCESS.

Referenced by hw_init().

+ Here is the call graph for this function:

◆ pru_sample()

int pru_sample ( FILE *  data_file,
FILE *  ambient_file,
rl_config_t const *const  config 
)

Main PRU sampling routine.

Configures and runs the actual RocketLogger measurements.

Parameters
data_fileData file to write to
ambient_fileAmbient file to write to
configCurrent measurement configuration
Returns
Returns 0 on success, negative on failure with errno set accordingly

Definition at line 130 of file pru.c.

References rl_config::ambient_enable, rl_config::background_enable, pru_control::buffer0_addr, pru_control::buffer1_addr, rl_status::buffer_count, pru_control::buffer_length, rl_file_header::channel, pru_data::channel_analog, rl_file_lead_in::channel_bin_count, rl_file_lead_in::channel_count, pru_data::channel_digital, create_time_stamp(), pru_buffer::data, rl_file_lead_in::data_block_count, rl_status::disk_use_rate, div_ceil(), ERROR, rl_status::error, rl_config::file_enable, rl_config::file_format, rl_config::file_name, rl_config::file_size, pru_buffer::index, rl_config::interactive_enable, rl_file_header::lead_in, meter_deinit(), meter_init(), meter_print_buffer(), rl_timestamp::nsec, rl_calibration::offsets, PRU_BINARY_FILE, PRU_BUFFER_STATUS_SIZE, pru_control_init(), PRU_DIGITAL_SIZE, PRU_SAMPLE_SIZE, PRU_STATE_OFF, pru_stop(), PRU_TIMEOUT_US, RL_CHANNEL_COUNT, rl_file_add_ambient_block(), rl_file_add_data_block(), RL_FILE_AMBIENT_DATA_BLOCK_SIZE, RL_FILE_FORMAT_CSV, RL_FILE_FORMAT_RLD, rl_file_get_ambient_file_name(), rl_file_setup_ambient_header(), rl_file_setup_ambient_lead_in(), rl_file_setup_data_header(), rl_file_setup_data_lead_in(), rl_file_store_header_bin(), rl_file_store_header_csv(), rl_file_update_header_bin(), rl_file_update_header_csv(), rl_log(), RL_LOG_ERROR, RL_LOG_INFO, RL_LOG_WARNING, rl_pid_set(), RL_SAMPLE_RATE_MIN, RL_SENSOR_SAMPLE_RATE, rl_socket_handle_data(), rl_status_write(), rl_status::sample_count, rl_file_lead_in::sample_count, pru_control::sample_limit, rl_config::sample_limit, rl_config::sample_rate, rl_status::sampling, rl_calibration::scales, rl_timestamp::sec, rl_status::sensor_available, rl_status::sensor_count, SENSOR_REGISTRY_SIZE, sensors_read(), pru_control::state, SUCCESS, rl_config::update_rate, and rl_config::web_enable.

Referenced by hw_sample().

+ Here is the call graph for this function:

◆ pru_set_state()

int pru_set_state ( pru_state_t  state)

Write a new state to the PRU shared memory.

Parameters
stateThe PRU state to write
Returns
Returns number of bytes written, negative on failure with errno set accordingly

Definition at line 122 of file pru.c.

Referenced by pru_stop().

◆ pru_stop()

void pru_stop ( void  )

Stop running PRU measurements.

Note
When sampling in continuous mode, this has to be called before {}.

Definition at line 619 of file pru.c.

References rl_status::error, pru_set_state(), PRU_STATE_OFF, and PRU_TIMEOUT_US.

Referenced by hw_deinit(), and pru_sample().

+ Here is the call graph for this function: