kopia lustrzana https://github.com/cariboulabs/cariboulite
testing smi device
rodzic
6079cd4855
commit
31958d6a5c
|
@ -8,12 +8,8 @@
|
|||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static void fail(const char *msg) {
|
||||
perror(msg);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
static void print_smi_settings(struct smi_settings *settings) {
|
||||
static void print_smi_settings(struct smi_settings *settings)
|
||||
{
|
||||
printf("width: %d\n", settings->data_width);
|
||||
printf("pack: %c\n", settings->pack_data ? 'Y' : 'N');
|
||||
printf("read setup: %d, strobe: %d, hold: %d, pace: %d\n", settings->read_setup_time, settings->read_strobe_time, settings->read_hold_time, settings->read_pace_time);
|
||||
|
@ -23,65 +19,86 @@ static void print_smi_settings(struct smi_settings *settings) {
|
|||
printf("dma panic threshold read: %d, write: %d\n", settings->dma_panic_read_thresh, settings->dma_panic_write_thresh);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int count = 8;
|
||||
int opt;
|
||||
int fd = open("/dev/smi", O_RDWR);
|
||||
if (fd < 0) fail("cant open");
|
||||
struct smi_settings settings;
|
||||
int ret = ioctl(fd, BCM2835_SMI_IOC_GET_SETTINGS, &settings);
|
||||
if (ret != 0) fail("ioctl 1");
|
||||
settings.read_setup_time = 10;
|
||||
settings.read_strobe_time = 20;
|
||||
settings.read_hold_time = 40;
|
||||
settings.read_pace_time = 80;
|
||||
bool writeMode = false;
|
||||
static void setup_settings (struct smi_settings *settings)
|
||||
{
|
||||
settings->read_setup_time = 1;
|
||||
settings->read_strobe_time = 1;
|
||||
settings->read_hold_time = 1;
|
||||
settings->read_pace_time = 1;
|
||||
settings->write_setup_time = 1;
|
||||
settings->write_hold_time = 1;
|
||||
settings->write_pace_time = 1;
|
||||
settings->write_strobe_time = 1;
|
||||
settings->data_width = SMI_WIDTH_8BIT;
|
||||
settings->dma_enable = 1;
|
||||
settings->pack_data = 1;
|
||||
settings->dma_passthrough_enable = 1;
|
||||
}
|
||||
|
||||
while ((opt = getopt(argc, argv, "b:e:s:h:p:wE:S:H:P:")) != -1) {
|
||||
switch (opt) {
|
||||
case 'b':
|
||||
count = atoi(optarg);
|
||||
break;
|
||||
case 'e':
|
||||
settings.read_setup_time = atoi(optarg);
|
||||
break;
|
||||
case 's':
|
||||
settings.read_strobe_time = atoi(optarg);
|
||||
break;
|
||||
case 'h':
|
||||
settings.read_hold_time = atoi(optarg);
|
||||
break;
|
||||
case 'p':
|
||||
settings.read_pace_time = atoi(optarg);
|
||||
break;
|
||||
case 'E':
|
||||
settings.write_setup_time = atoi(optarg);
|
||||
break;
|
||||
case 'S':
|
||||
settings.write_strobe_time = atoi(optarg);
|
||||
break;
|
||||
case 'H':
|
||||
settings.write_hold_time = atoi(optarg);
|
||||
break;
|
||||
case 'P':
|
||||
settings.write_pace_time = atoi(optarg);
|
||||
break;
|
||||
case 'w':
|
||||
writeMode = true;
|
||||
break;
|
||||
}
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int fd = open("/dev/smi", O_RDWR);
|
||||
if (fd < 0)
|
||||
{
|
||||
perror("cant open");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
struct smi_settings settings;
|
||||
|
||||
int ret = ioctl(fd, BCM2835_SMI_IOC_GET_SETTINGS, &settings);
|
||||
if (ret != 0)
|
||||
{
|
||||
perror("ioctl 1");
|
||||
close (fd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("Current settings:\n");
|
||||
print_smi_settings(&settings);
|
||||
|
||||
setup_settings(&settings);
|
||||
|
||||
ret = ioctl(fd, BCM2835_SMI_IOC_WRITE_SETTINGS, &settings);
|
||||
if (ret != 0) fail("ioctl 2");
|
||||
if (ret != 0)
|
||||
{
|
||||
perror("ioctl 1");
|
||||
close (fd);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
printf("\n\nNEW settings:\n");
|
||||
print_smi_settings(&settings);
|
||||
uint16_t buffer[count];
|
||||
if (writeMode) {
|
||||
for (int i=0; i<count; i++) buffer[i] = i;
|
||||
write(fd, buffer, count*2);
|
||||
} else {
|
||||
read(fd, buffer, count*2);
|
||||
for (int i=0; i<count; i++) printf("%02x ", buffer[i]);
|
||||
|
||||
|
||||
bool writeMode = false;
|
||||
// writeMode = true;
|
||||
|
||||
int count = 512;
|
||||
uint32_t buffer[512]; // 512 samples
|
||||
if (writeMode)
|
||||
{
|
||||
for (int i=0; i<count; i++)
|
||||
{
|
||||
buffer[i] = i;
|
||||
}
|
||||
|
||||
write(fd, buffer, count*sizeof(uint32_t));
|
||||
}
|
||||
else
|
||||
{
|
||||
read(fd, buffer, count*sizeof(uint32_t));
|
||||
|
||||
printf("\n\nread words:\n");
|
||||
for (int i=0; i<count; i++)
|
||||
{
|
||||
printf("%02x ", buffer[i]);
|
||||
}
|
||||
puts("\n");
|
||||
}
|
||||
|
||||
|
||||
close (fd);
|
||||
return 0;
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue