Date:2010-08-20 21:27:24 (9 years 4 months ago)
Author:Werner Almesberger
Commit:ac349b0bc0340d47c7764e60fde7a13bd930e53a
Message: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
Files: fw/atspi/at86rf230.h (1 diff)
fw/atspi/ep0.c (1 diff)
fw/include/at86rf230.h (1 diff)
tools/atspi-id/Makefile (1 diff)
tools/atspi-id/atspi-id.c (2 diffs)
tools/include/atspi.h (1 diff)
tools/lib/Makefile (1 diff)
tools/lib/atspi.c (1 diff)

Change Details

fw/atspi/at86rf230.h
1/*
2 * atspi/at86rf230.h - AT86RF230 protocol and register definitions
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program 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 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef AT86RF230_H
15#define AT86RF230_H
16
17enum at86rf230_spi_cmd {
18    AT86RF230_REG_WRITE = 0xc0, /* 11... */
19    AT86RF230_REG_READ = 0x80, /* 10... */
20    AT86RF230_BUF_WRITE = 0x60, /* 011... */
21    AT86RF230_BUF_READ = 0x20, /* 001... */
22    AT86RF230_SRAM_WRITE = 0x40, /* 010... */
23    AT86RF230_SRAM_READ = 0x00 /* 000... */
24};
25
26#define MAX_PSDU 127 /* octets, see AT86RF230 manual section 8.1 */
27#define SRAM_SIZE 128
28
29#endif /* !AT86RF230_H */
fw/atspi/ep0.c
211211        nSS = 1;
212212        usb_send(&ep0, buf, size, NULL, NULL);
213213        return 1;
214#endif
215214
216215    default:
217216        error("Unrecognized SETUP: 0x%02x 0x%02x ...\n",
fw/include/at86rf230.h
1/*
2 * atspi/at86rf230.h - AT86RF230 protocol and register definitions
3 *
4 * Written 2008-2010 by Werner Almesberger
5 * Copyright 2008-2010 Werner Almesberger
6 *
7 * This program 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 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#ifndef AT86RF230_H
15#define AT86RF230_H
16
17enum at86rf230_spi_cmd {
18    AT86RF230_REG_WRITE = 0xc0, /* 11... */
19    AT86RF230_REG_READ = 0x80, /* 10... */
20    AT86RF230_BUF_WRITE = 0x60, /* 011... */
21    AT86RF230_BUF_READ = 0x20, /* 001... */
22    AT86RF230_SRAM_WRITE = 0x40, /* 010... */
23    AT86RF230_SRAM_READ = 0x00 /* 000... */
24};
25
26#define MAX_PSDU 127 /* octets, see AT86RF230 manual section 8.1 */
27#define SRAM_SIZE 128
28
29enum at86rf230_regs {
30    AT86RF230_REG_PART_NUM = 0x1c,
31    AT86RF230_REG_VERSION_NUM = 0x1d,
32    AT86RF230_REG_MAN_ID_0 = 0x1e,
33    AT86RF230_REG_MAN_ID_1 = 0x1f,
34};
35
36#endif /* !AT86RF230_H */
tools/atspi-id/Makefile
1414F32XBASE = ../../../f32xbase
1515
1616MAIN = atspi-id
17OBJS = $(F32XBASE)/lib/usb.o
1817
1918include $(F32XBASE)/lib/Makefile.common
2019
21CFLAGS += -I$(F32XBASE)/include -I../../fw/include
20CFLAGS += -I../../fw/include -I../include
21LDLIBS += -L../lib -latspi
tools/atspi-id/atspi-id.c
1313
1414#include <stdlib.h>
1515#include <stdio.h>
16#include <usb.h>
1617
17#include "f32xbase/usb.h"
1818#include "atspi/ep0.h"
19#include "atspi/usb-ids.h"
19#include "atspi.h"
2020
2121
2222#define FROM_DEV ATSPI_FROM_DEV(0)
...... 
101101
102102    if (argc != 1)
103103        usage(*argv);
104    dev = open_usb(USB_VENDOR, USB_PRODUCT);
105    if (!dev) {
106        fprintf(stderr, ":-(\n");
104    dev = atspi_open();
105    if (!dev)
107106        return 1;
108    }
109107
110108    show_info(dev);
111109
tools/include/atspi.h
1#ifndef ATSPI_H
2#define ATSPI_H
3
4
5#include <stdint.h>
6#include <usb.h>
7
8
9int atspi_error(void);
10int atspi_clear_error(void);
11
12usb_dev_handle *atspi_open(void);
13void atspi_close(usb_dev_handle *dev);
14
15void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value);
16uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg);
17
18#endif /* !ATSPI_H */
tools/lib/Makefile
1#
2# lib/Makefile - Build the ATSPI library
3#
4# Written 2010 by Werner Almesberger
5# Copyright 2010 Werner Almesberger
6#
7# This program 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 2 of the License, or
10# (at your option) any later version.
11#
12
13
14F32XBASE = ../../../f32xbase
15
16LIB = libatspi.a
17
18CFLAGS = -Wall -I$(F32XBASE)/include -I../../fw/include -I../include
19OBJS = $(F32XBASE)/lib/usb.o atspi.o
20
21.PHONY: all clean spotless
22
23all: $(LIB)
24
25$(LIB): $(OBJS)
26        $(AR) cr $@ $^
27
28clean:
29        rm -f $(OBJS)
30
31spotless: clean
32        rm -f $(LIB)
tools/lib/atspi.c
1/*
2 * lib/atspi.c - ATSPI access functions library
3 *
4 * Written 2010 by Werner Almesberger
5 * Copyright 2010 Werner Almesberger
6 *
7 * This program 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 2 of the License, or
10 * (at your option) any later version.
11 */
12
13
14#include <stdio.h>
15#include <usb.h>
16
17#include "f32xbase/usb.h"
18#include "atspi/ep0.h"
19#include "atspi/usb-ids.h"
20
21#include "atspi.h"
22
23
24#define FROM_DEV ATSPI_FROM_DEV(0)
25#define TO_DEV ATSPI_TO_DEV(0)
26
27
28/* ----- error handling ---------------------------------------------------- */
29
30
31static int error;
32
33
34int atspi_error(void)
35{
36    return error;
37}
38
39
40int atspi_clear_error(void)
41{
42    int ret;
43
44    ret = error;
45    error = 0;
46    return ret;
47}
48
49
50/* ----- open/close -------------------------------------------------------- */
51
52
53usb_dev_handle *atspi_open(void)
54{
55    usb_dev_handle *dev;
56
57    dev = open_usb(USB_VENDOR, USB_PRODUCT);
58    if (dev) {
59        error = 0;
60    } else {
61        fprintf(stderr, ":-(\n");
62        error = 1;
63    }
64    return dev;
65}
66
67
68void atspi_close(usb_dev_handle *dev)
69{
70    /* to do */
71}
72
73
74/* ----- register access --------------------------------------------------- */
75
76
77void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value)
78{
79    int res;
80
81    if (error)
82        return;
83
84    res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg,
85        NULL, 0, 1000);
86    if (res < 0) {
87        fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res);
88        error = 1;
89    }
90}
91
92
93uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg)
94{
95    uint8_t value = 0;
96    int res;
97
98    if (error)
99        return 0;
100
101    res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg,
102        (void *) &value, 1, 1000);
103    if (res < 0) {
104        fprintf(stderr, "ATSPI_REG_READ: %d\n", res);
105        error = 1;
106    }
107    return value;
108}

Archive Download the corresponding diff file



interactive