RocketLogger  1.1.6
pru.h File Reference
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <math.h>
#include <pruss_intc_mapping.h>
#include <prussdrv.h>
#include <pthread.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ipc.h>
#include <sys/mman.h>
#include <sys/select.h>
#include <sys/shm.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <termios.h>
#include <time.h>
#include <unistd.h>
#include "ambient.h"
#include "calibration.h"
#include "file_handling.h"
#include "log.h"
#include "meter.h"
#include "sem.h"
#include "types.h"
#include "util.h"
#include "web.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_data_struct
 

Macros

#define WAKEUP   0x02000000
 
#define STANDBY   0x04000000
 
#define RESET   0x06000000
 
#define START   0x08000000
 
#define STOP   0x0A000000
 
#define OFFSETCAL   0x1A000000
 
#define RDATAC   0x10000000
 
#define SDATAC   0x11000000
 
#define RDATA   0x12000000
 
#define RREG   0x20000000
 
#define WREG   0x40000000
 
#define ID   0x00000000
 
#define CONFIG1   0x01000000
 
#define CONFIG2   0x02000000
 
#define CONFIG3   0x03000000
 
#define CH1SET   0x05000000
 
#define CH2SET   0x06000000
 
#define CH3SET   0x07000000
 
#define CH4SET   0x08000000
 
#define CH5SET   0x09000000
 
#define CH6SET   0x0A000000
 
#define CH7SET   0x0B000000
 
#define CH8SET   0x0C000000
 
#define GAIN1   0x1000
 
#define GAIN2   0x2000
 
#define GAIN12   0x6000
 
#define K1   0x0600
 
#define K2   0x0500
 
#define K4   0x0400
 
#define K8   0x0300
 
#define K16   0x0200
 
#define K32   0x0100
 
#define K64   0x0000
 
#define CONFIG1DEFAULT   0x9000
 
#define CONFIG2DEFAULT   0xE000
 
#define CONFIG3DEFAULT   0xE800
 
#define MMAP_FILE   "/sys/class/uio/uio0/maps/map1/"
 Memory map file. More...
 
#define PRU_CODE   "/lib/firmware/rocketlogger_spi.bin"
 PRU binary file location. More...
 
#define PRECISION_HIGH   24
 
#define PRECISION_LOW   16
 
#define SIZE_HIGH   4
 
#define SIZE_LOW   2
 
#define VALID_MASK   0x1
 Mask for valid bit read from PRU. More...
 
#define BINARY_MASK   0xE
 Mask for binary inputs read from PRU. More...
 
#define PRU_TIMEOUT   3
 PRU time out in seconds. More...
 
#define NUMBER_ADC_COMMANDS   12
 Number of ADC commands. More...
 

Typedefs

typedef enum pru_state rl_pru_state
 

Enumerations

enum  pru_state { PRU_OFF = 0, PRU_LIMIT = 1, PRU_CONTINUOUS = 3 }
 

Functions

void * pru_wait_event (void *voidEvent)
 
int pru_wait_event_timeout (unsigned int event, unsigned int timeout)
 
void pru_set_state (rl_pru_state state)
 
int pru_init (void)
 
int pru_data_setup (struct pru_data_struct *pru, struct rl_conf *conf, uint32_t avg_factor)
 
int pru_sample (FILE *data, FILE *ambient_file, struct rl_conf *conf, char *file_comment)
 
void pru_stop (void)
 
void pru_close (void)
 

Macro Definition Documentation

#define BINARY_MASK   0xE

Mask for binary inputs read from PRU.

Definition at line 150 of file pru.h.

Referenced by file_handle_data(), and web_handle_data().

#define CH1SET   0x05000000

Definition at line 91 of file pru.h.

Referenced by pru_data_setup().

#define CH2SET   0x06000000

Definition at line 92 of file pru.h.

Referenced by pru_data_setup().

#define CH3SET   0x07000000

Definition at line 93 of file pru.h.

Referenced by pru_data_setup().

#define CH4SET   0x08000000

Definition at line 94 of file pru.h.

Referenced by pru_data_setup().

#define CH5SET   0x09000000

Definition at line 95 of file pru.h.

Referenced by pru_data_setup().

#define CH6SET   0x0A000000

Definition at line 96 of file pru.h.

Referenced by pru_data_setup().

#define CH7SET   0x0B000000

Definition at line 97 of file pru.h.

Referenced by pru_data_setup().

#define CH8SET   0x0C000000

Definition at line 98 of file pru.h.

#define CONFIG1   0x01000000

Definition at line 88 of file pru.h.

Referenced by pru_data_setup().

#define CONFIG1DEFAULT   0x9000

ADS131E08S configuration default value defines

Definition at line 121 of file pru.h.

Referenced by pru_data_setup().

#define CONFIG2   0x02000000

Definition at line 89 of file pru.h.

#define CONFIG2DEFAULT   0xE000

Definition at line 122 of file pru.h.

#define CONFIG3   0x03000000

Definition at line 90 of file pru.h.

Referenced by pru_data_setup().

#define CONFIG3DEFAULT   0xE800

Definition at line 123 of file pru.h.

Referenced by pru_data_setup().

#define GAIN1   0x1000

ADS131E08S gain settings

Definition at line 103 of file pru.h.

Referenced by pru_data_setup().

#define GAIN12   0x6000

Definition at line 105 of file pru.h.

#define GAIN2   0x2000

Definition at line 104 of file pru.h.

Referenced by pru_data_setup().

#define ID   0x00000000

ADS131E08S register definitions

Definition at line 87 of file pru.h.

#define K1   0x0600

ADS131E08S sampling rates

Definition at line 110 of file pru.h.

Referenced by pru_data_setup().

#define K16   0x0200

Definition at line 114 of file pru.h.

Referenced by pru_data_setup().

#define K2   0x0500

Definition at line 111 of file pru.h.

Referenced by pru_data_setup().

#define K32   0x0100

Definition at line 115 of file pru.h.

Referenced by pru_data_setup().

#define K4   0x0400

Definition at line 112 of file pru.h.

Referenced by pru_data_setup().

#define K64   0x0000

Definition at line 116 of file pru.h.

Referenced by pru_data_setup().

#define K8   0x0300

Definition at line 113 of file pru.h.

Referenced by pru_data_setup().

#define MMAP_FILE   "/sys/class/uio/uio0/maps/map1/"

Memory map file.

Definition at line 128 of file pru.h.

Referenced by pru_data_setup(), pru_map_memory(), pru_sample(), and pru_unmap_memory().

#define NUMBER_ADC_COMMANDS   12

Number of ADC commands.

Definition at line 165 of file pru.h.

Referenced by pru_data_setup().

#define OFFSETCAL   0x1A000000

Definition at line 77 of file pru.h.

#define PRECISION_HIGH   24

ADS131E08S precision defines(PRECISION_HIGH for low sampling rates, PRECISION_LOW for high ones)

Definition at line 138 of file pru.h.

Referenced by pru_data_setup().

#define PRECISION_LOW   16

Definition at line 139 of file pru.h.

Referenced by pru_data_setup().

#define PRU_CODE   "/lib/firmware/rocketlogger_spi.bin"

PRU binary file location.

Definition at line 130 of file pru.h.

Referenced by pru_sample().

#define PRU_TIMEOUT   3

PRU time out in seconds.

Definition at line 153 of file pru.h.

Referenced by pru_sample(), and pru_stop().

#define RDATA   0x12000000

Definition at line 80 of file pru.h.

#define RDATAC   0x10000000

Definition at line 78 of file pru.h.

Referenced by pru_data_setup().

#define RESET   0x06000000

Definition at line 74 of file pru.h.

Referenced by pru_data_setup().

#define RREG   0x20000000

Definition at line 81 of file pru.h.

#define SDATAC   0x11000000

Definition at line 79 of file pru.h.

Referenced by pru_data_setup().

#define SIZE_HIGH   4

Sample size definitions

Definition at line 144 of file pru.h.

Referenced by pru_data_setup().

#define SIZE_LOW   2

Definition at line 145 of file pru.h.

#define STANDBY   0x04000000

Definition at line 73 of file pru.h.

#define START   0x08000000

Definition at line 75 of file pru.h.

#define STOP   0x0A000000

Definition at line 76 of file pru.h.

#define VALID_MASK   0x1

Mask for valid bit read from PRU.

Definition at line 148 of file pru.h.

Referenced by file_handle_data(), and web_handle_data().

#define WAKEUP   0x02000000

Copyright (c) 2016-2019, Swiss Federal Institute of Technology (ETH Zurich) 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. ADS131E08S command (extended to 32 bits for PRU use) definitions

Definition at line 72 of file pru.h.

#define WREG   0x40000000

Definition at line 82 of file pru.h.

Referenced by pru_data_setup().

Typedef Documentation

typedef enum pru_state rl_pru_state

PRU state definition

Enumeration Type Documentation

enum pru_state

PRU state definition

Enumerator
PRU_OFF 

PRU off.

PRU_LIMIT 

Limited sampling mode.

PRU_CONTINUOUS 

Continuous sampling mode.

Definition at line 158 of file pru.h.

Function Documentation

void pru_close ( void  )

Disable PRU

Definition at line 725 of file pru.c.

Referenced by hw_close().

int pru_data_setup ( struct pru_data_struct pru,
struct rl_conf conf,
uint32_t  avg_factor 
)
int pru_init ( void  )

PRU initiation

Returns
SUCCESS on success, FAILURE otherwise

Definition at line 167 of file pru.c.

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

Referenced by hw_init().

+ Here is the call graph for this function:

int pru_sample ( FILE *  data_file,
FILE *  ambient_file,
struct rl_conf conf,
char *  file_comment 
)

Main PRU sampling function

Parameters
data_fileFile pointer to data file
ambient_fileFile pointer to ambient file
confPointer to current rl_conf configuration
file_commentComment to store in the file header
Returns
SUCCESS on success, FAILURE otherwise

Definition at line 296 of file pru.c.

References rl_conf::ambient, AMBIENT_DATA_BLOCK_SIZE, AMBIENT_ENABLED, ambient_setup_header(), ambient_setup_lead_in(), ambient_store_data(), BIN, web_shm::buffer, BUFFER100_SIZE, BUFFER10_SIZE, BUFFER1_SIZE, rl_status::buffer_number, pru_data_struct::buffer_size, buffer_sizes, ceil_div(), rl_file_header::channel, rl_file_lead_in::channel_bin_count, rl_file_lead_in::channel_count, CHANNEL_ENABLED, rl_conf::channels, count_channels(), create_sem(), create_time_stamp(), CSV, rl_file_lead_in::data_block_count, DATA_SEM, rl_conf::digital_inputs, DIGITAL_INPUTS_ENABLED, rl_conf::enable_web_server, rl_ambient::enabled, ERROR, FAILURE, rl_conf::file_format, file_handle_data(), rl_ambient::file_name, rl_conf::file_name, file_setup_header(), file_setup_lead_in(), file_store_header_bin(), file_store_header_csv(), file_update_header_bin(), file_update_header_csv(), I1H_INDEX, I1L_INDEX, I2H_INDEX, I2L_INDEX, INFO, rl_file_header::lead_in, LIMIT, rl_conf::max_file_size, MAX_PATH_LENGTH, METER, meter_init(), meter_print_buffer(), meter_stop(), MIN_ADC_RATE, MMAP_FILE, rl_conf::mode, NO_FILE, time_stamp::nsec, web_shm::num_channels, NUM_CHANNELS, NUM_DIGITAL_INPUTS, NUM_SEMS, NUM_WEB_POINTS, PRU_BUFFER_STATUS_SIZE, PRU_CODE, pru_data_setup(), PRU_DIG_SIZE, pru_map_memory(), PRU_OFF, PRU_TIMEOUT, pru_unmap_memory(), pru_wait_event_timeout(), read_file_value(), remove_sem(), RL_ERROR, rl_log(), RL_RUNNING, rl_file_lead_in::sample_count, pru_data_struct::sample_limit, rl_conf::sample_limit, rl_conf::sample_rate, pru_data_struct::sample_size, rl_status::samples_taken, rl_status::sampling, SAMPLING_ON, time_stamp::sec, sem_id, SEM_KEY, rl_ambient::sensor_count, set_sem(), pru_data_struct::state, rl_status::state, status, SUCCESS, rl_conf::update_rate, WAIT_SEM, WARNING, web_buffer_reset(), web_create_shm(), web_data, web_handle_data(), WEB_RING_BUFFER_COUNT, and write_status().

Referenced by hw_sample().

+ Here is the call graph for this function:

void pru_set_state ( rl_pru_state  state)

Write state to PRU

Parameters
statePRU state to write

Definition at line 157 of file pru.c.

Referenced by pru_stop().

void pru_stop ( void  )

Stop and shut down PRU operation.

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

Definition at line 710 of file pru.c.

References PRU_OFF, pru_set_state(), PRU_TIMEOUT, pru_wait_event_timeout(), RL_ERROR, rl_status::state, and status.

Referenced by hw_close().

+ Here is the call graph for this function:

void* pru_wait_event ( void *  voidEvent)

Wait on PRU event

Parameters
voidEventPRU event to wait on

Definition at line 56 of file pru.c.

References done.

Referenced by pru_wait_event_timeout().

int pru_wait_event_timeout ( unsigned int  event,
unsigned int  timeout 
)

Wrapper for PRU event waiting with time out

Parameters
eventPRU event to wait on
timeoutTime out in seconds
Returns
error code of pthread timedwait function

Definition at line 79 of file pru.c.

References done, pru_wait_event(), and waiting.

Referenced by pru_sample(), and pru_stop().

+ Here is the call graph for this function: