From 2d9b230be1ec6264e35688a168fb6915154dba92 Mon Sep 17 00:00:00 2001 From: mirkix Date: Mon, 18 Jan 2016 20:54:43 +0100 Subject: [PATCH] AP_RangeFinder: Load .data section for HC-SR04 PRU driver used by BBBMINI This adds .data section loading to the HC-SR04 range finder driver used by BBBMINI. The firmware is running inside a PRU. It is necessary to develop more complex driver software inside the PRU. --- .../AP_RangeFinder/AP_RangeFinder_BBB_PRU.cpp | 20 ++++++++++++++++++- .../AP_RangeFinder/AP_RangeFinder_BBB_PRU.h | 1 + 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.cpp b/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.cpp index 7b11b94e9a..f6867ca6f6 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.cpp +++ b/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.cpp @@ -63,7 +63,7 @@ bool AP_RangeFinder_BBB_PRU::detect(RangeFinder &_ranger, uint8_t instance) *ctrl = 0; hal.scheduler->delay(1); - // Load firmware + // Load firmware (.text) FILE *file = fopen("/lib/firmware/rangefinderprutext.bin", "rb"); if(file == NULL) { @@ -79,6 +79,24 @@ bool AP_RangeFinder_BBB_PRU::detect(RangeFinder &_ranger, uint8_t instance) munmap(ram, PRU0_IRAM_SIZE); + ram = mmap(0, PRU0_DRAM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, PRU0_DRAM_BASE); + + // Load firmware (.data) + file = fopen("/lib/firmware/rangefinderprudata.bin", "rb"); + if(file == NULL) + { + result = false; + } + + if(fread(ram, PRU0_DRAM_SIZE, 1, file) != 1) + { + result = false; + } + + fclose(file); + + munmap(ram, PRU0_DRAM_SIZE); + // Map PRU RAM ram = mmap(0, 0x1000, PROT_READ | PROT_WRITE, MAP_SHARED, mem_fd, PRU0_DRAM_BASE); close(mem_fd); diff --git a/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.h b/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.h index c1a381c511..00370a0f08 100644 --- a/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.h +++ b/libraries/AP_RangeFinder/AP_RangeFinder_BBB_PRU.h @@ -11,6 +11,7 @@ #define PRU0_IRAM_SIZE 0x2000 #define PRU0_DRAM_BASE 0x4a300000 +#define PRU0_DRAM_SIZE 0x2000 struct range { uint32_t distance;