1
0
mirror of git://projects.qi-hardware.com/ben-wpan.git synced 2024-11-22 18:50:37 +02:00

Introduce library with ATSPI access functions (largely untested)

- tools/include/atspi.h, tools/lib/Makefile, tools/lib/atspi.c: library
  with ATSPI access functions
- tools/atspi-id/Makefile: use libatspi
- tools/atspi-id/atspi-id.c (main) use atspi_open instead of open_usb
- fw/atspi/at86rf230.h: moved to fw/include/
- fw/include/at86rf230.h: added ID registers
- fw/atspi/ep0.c: removed stray #endif
This commit is contained in:
Werner Almesberger 2010-08-20 16:27:24 -03:00
parent bf74a0348b
commit ac349b0bc0
7 changed files with 171 additions and 9 deletions

View File

@ -211,7 +211,6 @@ static __bit my_setup(struct setup_request *setup) __reentrant
nSS = 1; nSS = 1;
usb_send(&ep0, buf, size, NULL, NULL); usb_send(&ep0, buf, size, NULL, NULL);
return 1; return 1;
#endif
default: default:
error("Unrecognized SETUP: 0x%02x 0x%02x ...\n", error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",

View File

@ -26,4 +26,11 @@ enum at86rf230_spi_cmd {
#define MAX_PSDU 127 /* octets, see AT86RF230 manual section 8.1 */ #define MAX_PSDU 127 /* octets, see AT86RF230 manual section 8.1 */
#define SRAM_SIZE 128 #define SRAM_SIZE 128
enum at86rf230_regs {
AT86RF230_REG_PART_NUM = 0x1c,
AT86RF230_REG_VERSION_NUM = 0x1d,
AT86RF230_REG_MAN_ID_0 = 0x1e,
AT86RF230_REG_MAN_ID_1 = 0x1f,
};
#endif /* !AT86RF230_H */ #endif /* !AT86RF230_H */

View File

@ -14,8 +14,8 @@
F32XBASE = ../../../f32xbase F32XBASE = ../../../f32xbase
MAIN = atspi-id MAIN = atspi-id
OBJS = $(F32XBASE)/lib/usb.o
include $(F32XBASE)/lib/Makefile.common include $(F32XBASE)/lib/Makefile.common
CFLAGS += -I$(F32XBASE)/include -I../../fw/include CFLAGS += -I../../fw/include -I../include
LDLIBS += -L../lib -latspi

View File

@ -13,10 +13,10 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <usb.h>
#include "f32xbase/usb.h"
#include "atspi/ep0.h" #include "atspi/ep0.h"
#include "atspi/usb-ids.h" #include "atspi.h"
#define FROM_DEV ATSPI_FROM_DEV(0) #define FROM_DEV ATSPI_FROM_DEV(0)
@ -101,11 +101,9 @@ int main(int argc, const char **argv)
if (argc != 1) if (argc != 1)
usage(*argv); usage(*argv);
dev = open_usb(USB_VENDOR, USB_PRODUCT); dev = atspi_open();
if (!dev) { if (!dev)
fprintf(stderr, ":-(\n");
return 1; return 1;
}
show_info(dev); show_info(dev);

18
tools/include/atspi.h Normal file
View File

@ -0,0 +1,18 @@
#ifndef ATSPI_H
#define ATSPI_H
#include <stdint.h>
#include <usb.h>
int atspi_error(void);
int atspi_clear_error(void);
usb_dev_handle *atspi_open(void);
void atspi_close(usb_dev_handle *dev);
void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value);
uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg);
#endif /* !ATSPI_H */

32
tools/lib/Makefile Normal file
View File

@ -0,0 +1,32 @@
#
# lib/Makefile - Build the ATSPI library
#
# Written 2010 by Werner Almesberger
# Copyright 2010 Werner Almesberger
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
F32XBASE = ../../../f32xbase
LIB = libatspi.a
CFLAGS = -Wall -I$(F32XBASE)/include -I../../fw/include -I../include
OBJS = $(F32XBASE)/lib/usb.o atspi.o
.PHONY: all clean spotless
all: $(LIB)
$(LIB): $(OBJS)
$(AR) cr $@ $^
clean:
rm -f $(OBJS)
spotless: clean
rm -f $(LIB)

108
tools/lib/atspi.c Normal file
View File

@ -0,0 +1,108 @@
/*
* lib/atspi.c - ATSPI access functions library
*
* Written 2010 by Werner Almesberger
* Copyright 2010 Werner Almesberger
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <stdio.h>
#include <usb.h>
#include "f32xbase/usb.h"
#include "atspi/ep0.h"
#include "atspi/usb-ids.h"
#include "atspi.h"
#define FROM_DEV ATSPI_FROM_DEV(0)
#define TO_DEV ATSPI_TO_DEV(0)
/* ----- error handling ---------------------------------------------------- */
static int error;
int atspi_error(void)
{
return error;
}
int atspi_clear_error(void)
{
int ret;
ret = error;
error = 0;
return ret;
}
/* ----- open/close -------------------------------------------------------- */
usb_dev_handle *atspi_open(void)
{
usb_dev_handle *dev;
dev = open_usb(USB_VENDOR, USB_PRODUCT);
if (dev) {
error = 0;
} else {
fprintf(stderr, ":-(\n");
error = 1;
}
return dev;
}
void atspi_close(usb_dev_handle *dev)
{
/* to do */
}
/* ----- register access --------------------------------------------------- */
void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value)
{
int res;
if (error)
return;
res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg,
NULL, 0, 1000);
if (res < 0) {
fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res);
error = 1;
}
}
uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg)
{
uint8_t value = 0;
int res;
if (error)
return 0;
res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg,
(void *) &value, 1, 1000);
if (res < 0) {
fprintf(stderr, "ATSPI_REG_READ: %d\n", res);
error = 1;
}
return value;
}