RocketLogger  2.0.1
pru.h File Reference
#include <stdint.h>
#include <stdio.h>
#include "rl.h"
+ Include dependency graph for pru.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  pru_control
 
struct  pru_data
 
struct  pru_buffer
 

Macros

#define PRU_BINARY_FILE   "/lib/firmware/rocketlogger.bin"
 PRU binary file location. More...
 
#define PRU_DIGITAL_SIZE   4
 Overall size of FRU digital channels in bytes. More...
 
#define PRU_SAMPLE_SIZE   4
 Size of PRU channel data in bytes. More...
 
#define PRU_BUFFER_STATUS_SIZE   4
 Size of PRU buffer status in bytes. More...
 
#define PRU_DIGITAL_INPUT_MASK   0x3F
 
#define PRU_DIGITAL_INPUT1_MASK   0x01
 
#define PRU_DIGITAL_INPUT2_MASK   0x02
 
#define PRU_DIGITAL_INPUT3_MASK   0x04
 
#define PRU_DIGITAL_INPUT4_MASK   0x08
 
#define PRU_DIGITAL_INPUT5_MASK   0x10
 
#define PRU_DIGITAL_INPUT6_MASK   0x20
 
#define PRU_DIGITAL_I1L_VALID_MASK   0x40
 
#define PRU_DIGITAL_I2L_VALID_MASK   0x80
 
#define PRU_TIMEOUT_US   2000000
 PRU time out in micro seconds. More...
 

Typedefs

typedef enum pru_state pru_state_t
 
typedef struct pru_control pru_control_t
 
typedef struct pru_data pru_data_t
 
typedef struct pru_buffer pru_buffer_t
 

Enumerations

enum  pru_state { PRU_STATE_OFF = 0x00 , PRU_STATE_SAMPLE_FINITE = 0x01 , PRU_STATE_SAMPLE_CONTINUOUS = 0x03 }
 

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)
 

Macro Definition Documentation

◆ PRU_BINARY_FILE

#define PRU_BINARY_FILE   "/lib/firmware/rocketlogger.bin"

PRU binary file location.

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 41 of file pru.h.

◆ PRU_BUFFER_STATUS_SIZE

#define PRU_BUFFER_STATUS_SIZE   4

Size of PRU buffer status in bytes.

Definition at line 48 of file pru.h.

◆ PRU_DIGITAL_I1L_VALID_MASK

#define PRU_DIGITAL_I1L_VALID_MASK   0x40

Definition at line 60 of file pru.h.

◆ PRU_DIGITAL_I2L_VALID_MASK

#define PRU_DIGITAL_I2L_VALID_MASK   0x80

Definition at line 61 of file pru.h.

◆ PRU_DIGITAL_INPUT1_MASK

#define PRU_DIGITAL_INPUT1_MASK   0x01

Definition at line 54 of file pru.h.

◆ PRU_DIGITAL_INPUT2_MASK

#define PRU_DIGITAL_INPUT2_MASK   0x02

Definition at line 55 of file pru.h.

◆ PRU_DIGITAL_INPUT3_MASK

#define PRU_DIGITAL_INPUT3_MASK   0x04

Definition at line 56 of file pru.h.

◆ PRU_DIGITAL_INPUT4_MASK

#define PRU_DIGITAL_INPUT4_MASK   0x08

Definition at line 57 of file pru.h.

◆ PRU_DIGITAL_INPUT5_MASK

#define PRU_DIGITAL_INPUT5_MASK   0x10

Definition at line 58 of file pru.h.

◆ PRU_DIGITAL_INPUT6_MASK

#define PRU_DIGITAL_INPUT6_MASK   0x20

Definition at line 59 of file pru.h.

◆ PRU_DIGITAL_INPUT_MASK

#define PRU_DIGITAL_INPUT_MASK   0x3F

Digital channel bit position in PRU digital information

Definition at line 53 of file pru.h.

◆ PRU_DIGITAL_SIZE

#define PRU_DIGITAL_SIZE   4

Overall size of FRU digital channels in bytes.

Definition at line 44 of file pru.h.

◆ PRU_SAMPLE_SIZE

#define PRU_SAMPLE_SIZE   4

Size of PRU channel data in bytes.

Definition at line 46 of file pru.h.

◆ PRU_TIMEOUT_US

#define PRU_TIMEOUT_US   2000000

PRU time out in micro seconds.

Definition at line 64 of file pru.h.

Typedef Documentation

◆ pru_buffer_t

typedef struct pru_buffer pru_buffer_t

Typedef for PRU data buffer structure

Definition at line 1 of file pru.h.

◆ pru_control_t

typedef struct pru_control pru_control_t

Typedef for PRU control data structure

Definition at line 1 of file pru.h.

◆ pru_data_t

typedef struct pru_data pru_data_t

Typedef for PRU channel data block structure

Definition at line 1 of file pru.h.

◆ pru_state_t

typedef enum pru_state pru_state_t

Typedef for PRU state

Definition at line 1 of file pru.h.

Enumeration Type Documentation

◆ pru_state

enum pru_state

PRU state definition

Enumerator
PRU_STATE_OFF 
PRU_STATE_SAMPLE_FINITE 

PRU off.

PRU_STATE_SAMPLE_CONTINUOUS 

PRU sampling in finite mode.

Definition at line 69 of file pru.h.

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  )

Initialize PRU driver.

Map PRU shared memory and enable PRU interrupts.

Returns
SUCCESS on success, FAILURE otherwise

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 615 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: