Revision fa35b710
| b/host/apps/omap_debug/fpga-downloader.cc | ||
|---|---|---|
| 1 |
/* -*- c++ -*- */ |
|
| 2 |
/* |
|
| 3 |
* Copyright 2003,2004,2008,2009 Free Software Foundation, Inc. |
|
| 4 |
* |
|
| 5 |
* This file is part of GNU Radio |
|
| 6 |
* |
|
| 7 |
* GNU Radio is free software; you can redistribute it and/or modify |
|
| 8 |
* it under the terms of the GNU General Public License as published by |
|
| 9 |
* the Free Software Foundation; either version 3, or (at your option) |
|
| 10 |
* any later version. |
|
| 11 |
* |
|
| 12 |
* GNU Radio is distributed in the hope that it will be useful, |
|
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 15 |
* GNU General Public License for more details. |
|
| 16 |
* |
|
| 17 |
* You should have received a copy of the GNU General Public License |
|
| 18 |
* along with GNU Radio; see the file COPYING. If not, write to |
|
| 19 |
* the Free Software Foundation, Inc., 51 Franklin Street, |
|
| 20 |
* Boston, MA 02110-1301, USA. |
|
| 21 |
*/ |
|
| 22 |
|
|
| 23 |
#include <iostream> |
|
| 24 |
#include <sstream> |
|
| 25 |
#include <fstream> |
|
| 26 |
#include <string> |
|
| 27 |
#include <cstdlib> |
|
| 28 |
|
|
| 29 |
#include <fcntl.h> |
|
| 30 |
#include <sys/types.h> |
|
| 31 |
#include <sys/stat.h> |
|
| 32 |
#include <sys/ioctl.h> |
|
| 33 |
|
|
| 34 |
#include <linux/spi/spidev.h> |
|
| 35 |
|
|
| 36 |
/* |
|
| 37 |
* Configuration connections |
|
| 38 |
* |
|
| 39 |
* CCK - MCSPI1_CLK |
|
| 40 |
* DIN - MCSPI1_MOSI |
|
| 41 |
* PROG_B - GPIO_175 - output (change mux) |
|
| 42 |
* DONE - GPIO_173 - input (change mux) |
|
| 43 |
* INIT_B - GPIO_114 - input (change mux) |
|
| 44 |
* |
|
| 45 |
*/ |
|
| 46 |
|
|
| 47 |
const unsigned int PROG_B = 175; |
|
| 48 |
const unsigned int DONE = 173; |
|
| 49 |
const unsigned int INIT_B = 114; |
|
| 50 |
|
|
| 51 |
static std::string bit_file = "safe_u1e.bin"; |
|
| 52 |
|
|
| 53 |
const int BUF_SIZE = 4096; |
|
| 54 |
|
|
| 55 |
enum gpio_direction {IN, OUT};
|
|
| 56 |
|
|
| 57 |
class gpio {
|
|
| 58 |
public: |
|
| 59 |
|
|
| 60 |
gpio(unsigned int gpio_num, gpio_direction pin_direction); |
|
| 61 |
|
|
| 62 |
bool get_value(); |
|
| 63 |
void set_value(bool state); |
|
| 64 |
|
|
| 65 |
private: |
|
| 66 |
|
|
| 67 |
std::stringstream base_path; |
|
| 68 |
std::fstream value_file; |
|
| 69 |
}; |
|
| 70 |
|
|
| 71 |
class spidev {
|
|
| 72 |
public: |
|
| 73 |
|
|
| 74 |
spidev(std::string dev_name); |
|
| 75 |
~spidev(); |
|
| 76 |
|
|
| 77 |
void send(char *wbuf, char *rbuf, unsigned int nbytes); |
|
| 78 |
|
|
| 79 |
private: |
|
| 80 |
|
|
| 81 |
int fd; |
|
| 82 |
|
|
| 83 |
}; |
|
| 84 |
|
|
| 85 |
gpio::gpio(unsigned int gpio_num, gpio_direction pin_direction) |
|
| 86 |
{
|
|
| 87 |
std::fstream export_file; |
|
| 88 |
|
|
| 89 |
export_file.open("/sys/class/gpio/export", std::ios::out);
|
|
| 90 |
if (!export_file.is_open()) ///\todo Poor error handling |
|
| 91 |
std::cout << "Failed to open gpio export file." << std::endl; |
|
| 92 |
|
|
| 93 |
export_file << gpio_num << std::endl; |
|
| 94 |
|
|
| 95 |
base_path << "/sys/class/gpio/gpio" << gpio_num << std::flush; |
|
| 96 |
|
|
| 97 |
std::fstream direction_file; |
|
| 98 |
std::string direction_file_name; |
|
| 99 |
|
|
| 100 |
direction_file_name = base_path.str() + "/direction"; |
|
| 101 |
|
|
| 102 |
direction_file.open(direction_file_name.c_str()); |
|
| 103 |
if (!direction_file.is_open()) |
|
| 104 |
std::cout << "Failed to open direction file." << std::endl; |
|
| 105 |
if (pin_direction == OUT) |
|
| 106 |
direction_file << "out" << std::endl; |
|
| 107 |
else |
|
| 108 |
direction_file << "in" << std::endl; |
|
| 109 |
|
|
| 110 |
std::string value_file_name; |
|
| 111 |
|
|
| 112 |
value_file_name = base_path.str() + "/value"; |
|
| 113 |
|
|
| 114 |
value_file.open(value_file_name.c_str(), std::ios_base::in | std::ios_base::out); |
|
| 115 |
if (!value_file.is_open()) |
|
| 116 |
std::cout << "Failed to open value file." << std::endl; |
|
| 117 |
} |
|
| 118 |
|
|
| 119 |
bool gpio::get_value() |
|
| 120 |
{
|
|
| 121 |
|
|
| 122 |
std::string val; |
|
| 123 |
|
|
| 124 |
std::getline(value_file, val); |
|
| 125 |
value_file.seekg(0); |
|
| 126 |
|
|
| 127 |
if (val == "0") |
|
| 128 |
return false; |
|
| 129 |
else if (val == "1") |
|
| 130 |
return true; |
|
| 131 |
else |
|
| 132 |
std::cout << "Data read from value file|" << val << "|" << std::endl; |
|
| 133 |
|
|
| 134 |
return false; |
|
| 135 |
} |
|
| 136 |
|
|
| 137 |
void gpio::set_value(bool state) |
|
| 138 |
{
|
|
| 139 |
|
|
| 140 |
if (state) |
|
| 141 |
value_file << "1" << std::endl; |
|
| 142 |
else |
|
| 143 |
value_file << "0" << std::endl; |
|
| 144 |
} |
|
| 145 |
|
|
| 146 |
static void prepare_fpga_for_configuration(gpio &prog, gpio &init) |
|
| 147 |
{
|
|
| 148 |
|
|
| 149 |
prog.set_value(true); |
|
| 150 |
prog.set_value(false); |
|
| 151 |
prog.set_value(true); |
|
| 152 |
|
|
| 153 |
#if 0 |
|
| 154 |
bool ready_to_program(false); |
|
| 155 |
unsigned int count(0); |
|
| 156 |
do {
|
|
| 157 |
ready_to_program = init.get_value(); |
|
| 158 |
count++; |
|
| 159 |
|
|
| 160 |
sleep(1); |
|
| 161 |
} while (count < 10 && !ready_to_program); |
|
| 162 |
|
|
| 163 |
if (count == 10) {
|
|
| 164 |
std::cout << "FPGA not ready for programming." << std::endl; |
|
| 165 |
exit(-1); |
|
| 166 |
} |
|
| 167 |
#endif |
|
| 168 |
} |
|
| 169 |
|
|
| 170 |
spidev::spidev(std::string fname) |
|
| 171 |
{
|
|
| 172 |
int ret; |
|
| 173 |
int mode = 0; |
|
| 174 |
int speed = 12000000; |
|
| 175 |
int bits = 8; |
|
| 176 |
|
|
| 177 |
fd = open(fname.c_str(), O_RDWR); |
|
| 178 |
|
|
| 179 |
ret = ioctl(fd, SPI_IOC_WR_MODE, &mode); |
|
| 180 |
ret = ioctl(fd, SPI_IOC_WR_MAX_SPEED_HZ, &speed); |
|
| 181 |
ret = ioctl(fd, SPI_IOC_WR_BITS_PER_WORD, &bits); |
|
| 182 |
} |
|
| 183 |
|
|
| 184 |
|
|
| 185 |
spidev::~spidev() |
|
| 186 |
{
|
|
| 187 |
close(fd); |
|
| 188 |
} |
|
| 189 |
|
|
| 190 |
void spidev::send(char *buf, char *rbuf, unsigned int nbytes) |
|
| 191 |
{
|
|
| 192 |
int ret; |
|
| 193 |
|
|
| 194 |
struct spi_ioc_transfer tr; |
|
| 195 |
tr.tx_buf = (unsigned long) buf; |
|
| 196 |
tr.rx_buf = (unsigned long) rbuf; |
|
| 197 |
tr.len = nbytes; |
|
| 198 |
tr.delay_usecs = 0; |
|
| 199 |
tr.speed_hz = 48000000; |
|
| 200 |
tr.bits_per_word = 8; |
|
| 201 |
|
|
| 202 |
ret = ioctl(fd, SPI_IOC_MESSAGE(1), &tr); |
|
| 203 |
|
|
| 204 |
} |
|
| 205 |
|
|
| 206 |
static void send_file_to_fpga(std::string &file_name, gpio &error, gpio &done) |
|
| 207 |
{
|
|
| 208 |
std::ifstream bitstream; |
|
| 209 |
|
|
| 210 |
std::cout << "File name - " << file_name.c_str() << std::endl; |
|
| 211 |
|
|
| 212 |
bitstream.open(file_name.c_str(), std::ios::binary); |
|
| 213 |
if (!bitstream.is_open()) |
|
| 214 |
std::cout << "File " << file_name << " not opened succesfully." << std::endl; |
|
| 215 |
|
|
| 216 |
spidev spi("/dev/spidev1.0");
|
|
| 217 |
char buf[BUF_SIZE]; |
|
| 218 |
char rbuf[BUF_SIZE]; |
|
| 219 |
|
|
| 220 |
do {
|
|
| 221 |
bitstream.read(buf, BUF_SIZE); |
|
| 222 |
spi.send(buf, rbuf, bitstream.gcount()); |
|
| 223 |
|
|
| 224 |
if (error.get_value()) |
|
| 225 |
std::cout << "INIT_B went high, error occured." << std::endl; |
|
| 226 |
|
|
| 227 |
if (!done.get_value()) |
|
| 228 |
std::cout << "Configuration complete." << std::endl; |
|
| 229 |
|
|
| 230 |
} while (bitstream.gcount() == BUF_SIZE); |
|
| 231 |
} |
|
| 232 |
|
|
| 233 |
int main(int argc, char *argv[]) |
|
| 234 |
{
|
|
| 235 |
|
|
| 236 |
gpio gpio_prog_b(PROG_B, OUT); |
|
| 237 |
gpio gpio_init_b(INIT_B, IN); |
|
| 238 |
gpio gpio_done (DONE, IN); |
|
| 239 |
|
|
| 240 |
if (argc == 2) |
|
| 241 |
bit_file = argv[1]; |
|
| 242 |
|
|
| 243 |
std::cout << "FPGA config file: " << bit_file << std::endl; |
|
| 244 |
|
|
| 245 |
prepare_fpga_for_configuration(gpio_prog_b, gpio_init_b); |
|
| 246 |
|
|
| 247 |
std::cout << "Done = " << gpio_done.get_value() << std::endl; |
|
| 248 |
|
|
| 249 |
send_file_to_fpga(bit_file, gpio_init_b, gpio_done); |
|
| 250 |
} |
|
| 251 |
|
|
| b/host/apps/omap_debug/test.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
|
|
| 3 |
void |
|
| 4 |
main() |
|
| 5 |
{
|
|
| 6 |
int x; |
|
| 7 |
char *y; |
|
| 8 |
long long z; |
|
| 9 |
|
|
| 10 |
x = 0x01020304; |
|
| 11 |
z = 0x0102030405060708LL; |
|
| 12 |
|
|
| 13 |
printf("%x\n",x);
|
|
| 14 |
y = (char *)&x; |
|
| 15 |
printf("%x\n",y[0]);
|
|
| 16 |
printf("%x\n",y[1]);
|
|
| 17 |
printf("%x\n",y[2]);
|
|
| 18 |
printf("%x\n",y[3]);
|
|
| 19 |
|
|
| 20 |
printf("Printing z ...\n");
|
|
| 21 |
printf("%llx\n",z);
|
|
| 22 |
printf("Printing z done\n");
|
|
| 23 |
|
|
| 24 |
y = (char *)&z; |
|
| 25 |
printf("%x\n",y[0]);
|
|
| 26 |
printf("%x\n",y[1]);
|
|
| 27 |
printf("%x\n",y[2]);
|
|
| 28 |
printf("%x\n",y[3]);
|
|
| 29 |
printf("%x\n",y[4]);
|
|
| 30 |
printf("%x\n",y[5]);
|
|
| 31 |
printf("%x\n",y[6]);
|
|
| 32 |
printf("%x\n",y[7]);
|
|
| 33 |
} |
|
| 34 |
|
|
| b/host/apps/omap_debug/u1e-read-stream.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <sys/types.h> |
|
| 3 |
#include <fcntl.h> |
|
| 4 |
|
|
| 5 |
int main(int rgc, char *argv[]) |
|
| 6 |
{
|
|
| 7 |
int fp, cnt, n; |
|
| 8 |
short buf[1024]; |
|
| 9 |
|
|
| 10 |
n = 0; |
|
| 11 |
|
|
| 12 |
fp = open("/dev/usrp1_e0", O_RDONLY);
|
|
| 13 |
printf("fp = %d\n", fp);
|
|
| 14 |
|
|
| 15 |
do {
|
|
| 16 |
cnt = read(fp, buf, 2048); |
|
| 17 |
n++; |
|
| 18 |
// printf("Bytes read - %d\n", cnt);
|
|
| 19 |
} while(n < 10*512); |
|
| 20 |
printf("Data - %hX\n", buf[0]);
|
|
| 21 |
} |
|
| b/host/apps/omap_debug/usrp1-e-ctl.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <stdlib.h> |
|
| 3 |
#include <sys/types.h> |
|
| 4 |
#include <fcntl.h> |
|
| 5 |
#include <linux/ioctl.h> |
|
| 6 |
|
|
| 7 |
#include "usrp1_e.h" |
|
| 8 |
|
|
| 9 |
// Usage: usrp1_e_ctl w|r offset number_of_values val1 val2 .... |
|
| 10 |
|
|
| 11 |
int main(int argc, char *argv[]) |
|
| 12 |
{
|
|
| 13 |
int fp, i, cnt, ret; |
|
| 14 |
struct usrp1_e_ctl *ctl_data; |
|
| 15 |
|
|
| 16 |
if (argc < 4) {
|
|
| 17 |
printf("Usage: usrp1_e_ctl w|r offset number_of_values val1 val2 ....\n");
|
|
| 18 |
exit(-1); |
|
| 19 |
} |
|
| 20 |
|
|
| 21 |
cnt = atoi(argv[3]); |
|
| 22 |
|
|
| 23 |
ctl_data = malloc(sizeof(struct usrp1_e_ctl) + cnt*2); |
|
| 24 |
|
|
| 25 |
ctl_data->offset = atoi(argv[2]); |
|
| 26 |
ctl_data->count = cnt; |
|
| 27 |
|
|
| 28 |
printf("Sizeof usrp1_e_ctl struct = %d\n", sizeof(struct usrp1_e_ctl));
|
|
| 29 |
|
|
| 30 |
fp = open("/dev/usrp1_e0", O_RDWR);
|
|
| 31 |
printf("fp = %d\n", fp);
|
|
| 32 |
|
|
| 33 |
if (*argv[1] == 'w') {
|
|
| 34 |
for (i=0; i<cnt; i++) |
|
| 35 |
ctl_data->buf[i] = atoi(argv[4+i]); |
|
| 36 |
|
|
| 37 |
ret = ioctl(fp, USRP1_E_WRITE_CTL, ctl_data); |
|
| 38 |
printf("Return value from write ioctl = %d\n", ret);
|
|
| 39 |
} |
|
| 40 |
|
|
| 41 |
if (*argv[1] == 'r') {
|
|
| 42 |
ret = ioctl(fp, USRP1_E_READ_CTL, ctl_data); |
|
| 43 |
printf("Return value from write ioctl = %d\n", ret);
|
|
| 44 |
|
|
| 45 |
for (i=0; i<ctl_data->count; i++) {
|
|
| 46 |
if (!(i%8)) |
|
| 47 |
printf("\nData at %4d :", i);
|
|
| 48 |
printf(" %5d", ctl_data->buf[i]);
|
|
| 49 |
} |
|
| 50 |
printf("\n");
|
|
| 51 |
} |
|
| 52 |
} |
|
| b/host/apps/omap_debug/usrp1-e-ram.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <sys/types.h> |
|
| 3 |
#include <fcntl.h> |
|
| 4 |
|
|
| 5 |
int main(int rgc, char *argv[]) |
|
| 6 |
{
|
|
| 7 |
int fp, i, cnt; |
|
| 8 |
unsigned short buf[1024]; |
|
| 9 |
unsigned short buf_rb[1024]; |
|
| 10 |
|
|
| 11 |
fp = open("/dev/usrp1_e0", O_RDWR);
|
|
| 12 |
printf("fp = %d\n", fp);
|
|
| 13 |
|
|
| 14 |
for (i=0; i<1024; i++) |
|
| 15 |
buf[i] = i*256; |
|
| 16 |
write(fp, buf, 2048); |
|
| 17 |
read(fp, buf_rb, 2048); |
|
| 18 |
|
|
| 19 |
printf("Read back %hX %hX\n", buf_rb[0], buf_rb[1]);
|
|
| 20 |
|
|
| 21 |
for (i=0; i<1024; i++) {
|
|
| 22 |
if (buf[i] != buf_rb[i]) |
|
| 23 |
printf("Read - %hX, expected - %hX\n", buf_rb[i], buf[i]);
|
|
| 24 |
} |
|
| 25 |
} |
|
| b/host/apps/omap_debug/usrp1-e-read.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <sys/types.h> |
|
| 3 |
#include <fcntl.h> |
|
| 4 |
|
|
| 5 |
int main(int rgc, char *argv[]) |
|
| 6 |
{
|
|
| 7 |
int fp, cnt; |
|
| 8 |
short buf[1024]; |
|
| 9 |
|
|
| 10 |
fp = open("/dev/usrp1_e0", O_RDONLY);
|
|
| 11 |
printf("fp = %d\n", fp);
|
|
| 12 |
|
|
| 13 |
do {
|
|
| 14 |
cnt = read(fp, buf, 2048); |
|
| 15 |
// printf("Bytes read - %d\n", cnt);
|
|
| 16 |
} while(1); |
|
| 17 |
printf("Data - %hX\n", buf[0]);
|
|
| 18 |
} |
|
| b/host/apps/omap_debug/usrp1-e-write.c | ||
|---|---|---|
| 1 |
#include <stdio.h> |
|
| 2 |
#include <sys/types.h> |
|
| 3 |
#include <fcntl.h> |
|
| 4 |
|
|
| 5 |
int main(int rgc, char *argv[]) |
|
| 6 |
{
|
|
| 7 |
int fp, i, cnt; |
|
| 8 |
short buf[1024]; |
|
| 9 |
|
|
| 10 |
fp = open("/dev/usrp1_e0", O_WRONLY);
|
|
| 11 |
printf("fp = %d\n", fp);
|
|
| 12 |
|
|
| 13 |
for (i=0; i<1024; i++) {
|
|
| 14 |
buf[i] = i; |
|
| 15 |
} |
|
| 16 |
|
|
| 17 |
do {
|
|
| 18 |
cnt = write(fp, buf, 2048); |
|
| 19 |
printf("Bytes written - %d\n", cnt);
|
|
| 20 |
} while (1); |
|
| 21 |
} |
|
Also available in: Unified diff