Skip to content

Commit

Permalink
Acquire blocks of SAMPLES_PER_BLOCK forever, in circular buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
haunma committed Feb 14, 2016
1 parent fa28771 commit 30b299b
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 40 deletions.
41 changes: 20 additions & 21 deletions seiscape.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,13 @@

#include <prussdrv.h>
#include <pruss_intc_mapping.h>


#include "seiscape_common.h"


#define PRU0 0
#define MMAP0_LOC "/sys/class/uio/uio0/maps/map0/"
#define MMAP1_LOC "/sys/class/uio/uio0/maps/map1/"
//#define MMAP0_LOC "/sys/class/uio/uio0/maps/map0/"
//#define MMAP1_LOC "/sys/class/uio/uio0/maps/map1/"

// Register access sequences for the AD7175-2 are encoded as a series
// of variable-length blocks of the form
Expand All @@ -39,15 +42,15 @@ const uint8_t init_seq[] = { 3, 0x47, 0x00, 0x00, // ID


// Short function to load a single unsigned int from a sysfs entry
unsigned int readFileValue(char filename[])
{
FILE* fp;
unsigned int value = 0;
fp = fopen(filename, "rt");
fscanf(fp, "%x", &value);
fclose(fp);
return value;
}
//unsigned int readFileValue(char filename[])
//{
// FILE* fp;
// unsigned int value = 0;
// fp = fopen(filename, "rt");
// fscanf(fp, "%x", &value);
// fclose(fp);
// return value;
//}


int main()
Expand All @@ -66,12 +69,12 @@ int main()

// Read in the location and address of the shared memory. This value changes
// each time a new block of memory is allocated.
unsigned int PRU_data_addr = readFileValue(MMAP0_LOC "addr");
printf("-> the PRU memory is mapped at the base address: %x\n", (PRU_data_addr + 0x2000));
// unsigned int PRU_data_addr = readFileValue(MMAP0_LOC "addr");
// printf("-> the PRU memory is mapped at the base address: %x\n", (PRU_data_addr + 0x2000));

uint32_t ddr_addr = readFileValue(MMAP1_LOC "addr");
uint32_t ddr_size = readFileValue(MMAP1_LOC "size");
printf("The DDR External Memory pool has location: 0x%x and size: 0x%x bytes\n", ddr_addr, ddr_size);
// uint32_t ddr_addr = readFileValue(MMAP1_LOC "addr");
// uint32_t ddr_size = readFileValue(MMAP1_LOC "size");
// printf("The DDR External Memory pool has location: 0x%x and size: 0x%x bytes\n", ddr_addr, ddr_size);

// Allocate and initialize memory
prussdrv_init();
Expand All @@ -85,10 +88,6 @@ int main()
}

// Write the AD7175-2 initialization sequence into PRU0 Data RAM0.
// You can edit the value to PRUSS0_PRU1_DATARAM if you wish to
// write to PRU1.
// unsigned int *tmp = (unsigned int *) init_seq;
// prussdrv_pru_write_memory(PRUSS0_PRU0_DATARAM, 0, tmp, sizeof(init_seq));
memcpy(pru_dataram0, init_seq, sizeof(init_seq));

// Map the PRU's interrupts
Expand Down
47 changes: 28 additions & 19 deletions seiscape.p
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,27 @@
//

.setcallreg r29.w0
.origin 0 // start of program in PRU memory
.origin 0 // start of program in PRU memory
.entrypoint start

#define PRU0_R31_VEC_VALID 32 // allows notification of program completion
#define PRU_EVTOUT_0 3 // the event number that is sent back

#define SCLK_COUNT 500 // Loop count for SCLK half-cycle

#include "seiscape_common.h"

#define PRU0_R31_VEC_VALID 32 // allows notification of program completion
#define PRU_EVTOUT_0 3 // the event number that is sent back

#define SCLK_COUNT 500 // Loop count for SCLK half-cycle


start:

// Enable the OCP master port -- allows transfer of data to Linux userspace
LBCO r0, c4, 4, 4 // load SYSCFG reg into r0 (use c4 const addr)
CLR r0, r0, 4 // clear bit 4 (STANDBY_INIT)
SBCO r0, c4, 4, 4 // store the modified r0 back at the load addr

MOV r1, 0x0 // PRU RAM base address

// TEST TEST TEST TEST
//
// Reset the AD7175-2 with 64 SCLKS while DIN=1, then wait ~ 1 ms
//
// TEST TEST TEST TEST
SET r30.t2
MOV r18, 64
next_reset_clk:
Expand All @@ -46,7 +45,7 @@ QBNE waitloop, r20, 0

next_transaction:
LBBO r9.b0, r1, 0, 1 // Number of bytes in SPI transaction => r9
QBEQ init_done, r9.b0, 0 // Done if this is the terminating null
QBEQ start_sampling, r9.b0, 0 // Done if this is the terminating null
LBBO r10.b0, r1, 1, 1 // Comms register => r10
ADD r1, r1, 2

Expand Down Expand Up @@ -115,9 +114,12 @@ ADD r1, r1, 1 // Advance PRU RAM ptr
QBA writes // Go write next byte


init_done:
// Initialization is complete; now collect ADC samples.
MOV r11, 0x400 // How many samples to read
start_sampling:
// Initialization is complete; now collect ADC samples
MOV r1, BUFFER_START

get_new_block:
MOV r11, SAMPLES_PER_BLOCK // How many samples per EVTOUT signal

sample_wait:
// Wait for READY signal
Expand Down Expand Up @@ -158,14 +160,21 @@ QBNE next_bit_rs2, r18, 0
SBBO r17, r1, 0, 4 // Store r17 result into RAM
ADD r1, r1, 4 // Advance PRU RAM ptr

// Wait for next sample.
// Decrement counter and loop until zero
SUB r11, r11, 1
QBNE sample_wait, r11, 0

done:
// Program complete; signal host.
// Done with this block; tell host
MOV r2, BUFFER_PTR_SAVE
SBBO r1, r2, 0, 4 // Pass dataram ptr to host at special addr
MOV r31.b0, PRU0_R31_VEC_VALID | PRU_EVTOUT_0
HALT

// If dataram ptr has reached the end of the buffer, loop back to
// "start_sampling" to reset it, otherwise just start the next block.
MOV r2, BUFFER_END
QBLT get_new_block, r2, r1
QBA start_sampling




Expand Down
10 changes: 10 additions & 0 deletions seiscape_common.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// Common definitions for the seiscape host- and PRU-side code

#define SAMPLES_PER_BLOCK 600
#define BLOCKS_IN_BUFFER 3

// These are pointers into the 8-kB PRU data RAM:
#define BUFFER_PTR_SAVE 255 // Where to store dataram ptr for host
#define BUFFER_START 256
#define BUFFER_END BUFFER_START + 4*SAMPLES_PER_BLOCK*BLOCKS_IN_BUFFER

0 comments on commit 30b299b

Please sign in to comment.