IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Git Source Tree
Root/
Source at commit c2dd23840ce5875deca09673fcb8abb8dc3a8e7a created 13 years 7 months ago. By Werner Almesberger, Moved fw/ and tools/ into atrf/ as well. | |
---|---|
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 | |
31 | static int error; |
32 | |
33 | |
34 | int atspi_error(void) |
35 | { |
36 | return error; |
37 | } |
38 | |
39 | |
40 | int 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 | |
53 | usb_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 | |
68 | void atspi_close(usb_dev_handle *dev) |
69 | { |
70 | /* to do */ |
71 | } |
72 | |
73 | |
74 | /* ----- device mode ------------------------------------------------------- */ |
75 | |
76 | |
77 | void atspi_reset(usb_dev_handle *dev) |
78 | { |
79 | int res; |
80 | |
81 | if (error) |
82 | return; |
83 | |
84 | res = |
85 | usb_control_msg(dev, TO_DEV, ATSPI_RESET, 0, 0, NULL, 0, 1000); |
86 | if (res < 0) { |
87 | fprintf(stderr, "ATSPI_RESET: %d\n", res); |
88 | error = 1; |
89 | } |
90 | } |
91 | |
92 | |
93 | void atspi_reset_rf(usb_dev_handle *dev) |
94 | { |
95 | int res; |
96 | |
97 | if (error) |
98 | return; |
99 | |
100 | res = |
101 | usb_control_msg(dev, TO_DEV, ATSPI_RF_RESET, 0, 0, NULL, 0, 1000); |
102 | if (res < 0) { |
103 | fprintf(stderr, "ATSPI_RF_RESET: %d\n", res); |
104 | error = 1; |
105 | } |
106 | } |
107 | |
108 | |
109 | /* ----- register access --------------------------------------------------- */ |
110 | |
111 | |
112 | void atspi_reg_write(usb_dev_handle *dev, uint8_t reg, uint8_t value) |
113 | { |
114 | int res; |
115 | |
116 | if (error) |
117 | return; |
118 | |
119 | res = usb_control_msg(dev, TO_DEV, ATSPI_REG_WRITE, value, reg, |
120 | NULL, 0, 1000); |
121 | if (res < 0) { |
122 | fprintf(stderr, "ATSPI_REG_WRITE: %d\n", res); |
123 | error = 1; |
124 | } |
125 | } |
126 | |
127 | |
128 | uint8_t atspi_reg_read(usb_dev_handle *dev, uint8_t reg) |
129 | { |
130 | uint8_t value = 0; |
131 | int res; |
132 | |
133 | if (error) |
134 | return 0; |
135 | |
136 | res = usb_control_msg(dev, FROM_DEV, ATSPI_REG_READ, 0, reg, |
137 | (void *) &value, 1, 1000); |
138 | if (res < 0) { |
139 | fprintf(stderr, "ATSPI_REG_READ: %d\n", res); |
140 | error = 1; |
141 | } |
142 | return value; |
143 | } |
144 |