@@ -274,7 +274,8 @@ int detect_chip(int chip_n) {
ms3_compute(&atrvec[0]);
ms3_compute(&atrvec[20]);
ms3_compute(&atrvec[40]);
- spi_init();
+ if (!spi_init())
+ return 0;
spi_clear_buf();
@@ -21,6 +21,8 @@
*/
#include "spidevc.h"
+
+#include <stdbool.h>
#include <sys/mman.h>
#include <stdint.h>
#include <unistd.h>
@@ -42,14 +44,23 @@
static volatile unsigned *gpio;
-void spi_init(void)
+bool spi_init(void)
{
int fd;
fd = open("/dev/mem",O_RDWR|O_SYNC);
- if (fd < 0) { perror("/dev/mem trouble"); exit(1); }
+ if (fd < 0)
+ {
+ perror("/dev/mem trouble");
+ return false;
+ }
gpio = mmap(0,4096,PROT_READ|PROT_WRITE,MAP_SHARED,fd,0x20200000);
- if (gpio == MAP_FAILED) { perror("gpio mmap trouble"); exit(1); }
+ if (gpio == MAP_FAILED)
+ perror("gpio mmap trouble");
close(fd);
+ return true;
}
#define INP_GPIO(g) *(gpio+((g)/10)) &= ~(7<<(((g)%10)*3))
@@ -1,8 +1,10 @@
#ifndef SPIDEVC_H
#define SPIDEVC_H
/* Initialize SPI using this function */
-void spi_init(void);
+bool spi_init(void);
/* TX-RX single frame */
int spi_txrx(const char *wrbuf, char *rdbuf, int bufsz);