Compare commits

...

61 Commits
v0.1 ... master

Author SHA1 Message Date
Denis 'GNUtoo' Carikli dc2983d907 firmware: Makefiles: enable changing toolchain
Without that the user was expected to either patch
the Makefiles or to get a toolchain with the arm-elf-
prefix.

Change-Id: I0c362cde7afd6de025e8fe2c1e9abe3d3a1e04a6
Signed-off-by: Denis 'GNUtoo' Carikli <GNUtoo@no-log.org>
2017-10-05 09:27:29 +08:00
Harald Welte 5176342acf add README.md
Change-Id: Ib2c4fc8b20812f698c75041f75cd0076f5354af2
2017-03-17 22:20:06 +01:00
Harald Welte 373c172ab8 convert from u_int*_t to uint*_t
Change-Id: I33f6383535c5860b833f7ccb9bea122d38f28e3f
2017-03-17 22:20:04 +01:00
Harald Welte 5a40e2fed1 Merge branch 'minxu-fixes' 2014-11-11 22:31:27 +01:00
Min Xu b6caca4b64 improve handling of spurious IRQs
rather than printing directly from the interrupt handler, just increment
the number and print it from the main loop function instead.
2014-11-11 22:30:55 +01:00
Min Xu 478c2332b7 Allow some USB interrupts to be handled during dbgu_append 2014-11-11 22:30:55 +01:00
Min Xu 8701086cac Retrieve + print previous PC from stack to debug wdog/spurious IRQ
Retrive previous PC from the stack before entering specific interrupt
handler routines.  Allow user to trace where interrupt occured: e.g.
WatchDog and Spurious interrupt

Prior to this change, spurious interrupt would occur so much (observed
via gdb/remote debug) so it appears that the board stalled.  Once a
custom spurious interrupt installed, the code continues after the
interrupt instead of re-entering the interrupt.
2014-11-11 22:30:55 +01:00
Min Xu 6bafd0cfb4 Don't split req_ctx with ATR payload
The codnition for flushing a req_ctx on UART idle is fixed to flush only
if
1) There has been no new data since last check, and
2) There are no req_ctx currently pending to be transmitted to USB, and
3) We did NOT just got a reset and waiting for ATR

I saw an ATR split in two different req_ctx prior, presumably flush
decided to send req_ctx after ATR but got a new character just before
sent).  If we did get a RESET, let original logic decide to send the
req_ctx -- presumably when ATR data is fully received.
2014-11-11 22:30:55 +01:00
Min Xu 7e3c9959e1 iso_uart: Print more errors, not just overruns 2014-11-11 22:30:54 +01:00
Min Xu 9662f2830a change number + qty of small/large req_ctx 2014-11-11 22:30:54 +01:00
Min Xu 4b98ba5d1c pcd_enumerate: More complete USB endpoint resetting 2014-11-11 22:30:54 +01:00
Min Xu 3cd467a8ef req_ctx: Keep statistic about number of req_ctx in given state
... and print this from a debug statement.
2014-11-11 22:30:54 +01:00
Min Xu ab325fc295 Ensure to transmit current req_ctx on RESET/VCC events
When any of the following events occur:
* VCC_PHONE off
* nRST
* RST

we tranmsit the current req_ctx, if there is data pending.

This ensures that for any successive data, the ATR flag in the next
req_ctx containing the data, not in the previous req_ctx.  It also
ensures that the ATR is aligned at 0 offset in the new req_ctx, which is
an assumption the host software makes but the previous code didn't
ensure.

Furthermore, we introduce a periodic flushing of any pending but
incomplete req_ctx.
2014-11-11 22:30:54 +01:00
Min Xu 9bd1b003a6 iso7816_uart.h: add missing #ifdef/endif to avoid multiple inclusion 2014-11-11 22:30:54 +01:00
Min Xu 04403a7c8b usbcmd_generic: Add missing \r to DEBUGP() 2014-11-11 22:30:54 +01:00
Min Xu 82cb631bf9 watchdog: print watchdog expiration even in non-debug builds 2014-11-11 22:30:54 +01:00
Min Xu e39637e1b8 pcd_enumerate: Avoid disabling interrupt during endpoint refill
The old implementation has a big local_irq_save() / restore() around the
endpoint re-fill routine.  This disables interrupts for a long time,
psossibly causing lost interrupts.

The new implementation works around this by disabling the USB (UDP)
interrupt only, rather than disabling all interrupts on the system.
2014-11-11 22:30:54 +01:00
Min Xu 7fcc62940d simtrace: Add heartbeat message to debug console 2014-11-11 22:30:54 +01:00
Min Xu ca4e80551b dbgu: make debug routines re-entrant 2014-11-11 22:30:54 +01:00
Min Xu ec975220d0 req_ctx: Change number of small / large req_ctx 2014-11-11 22:30:54 +01:00
Min Xu b6b2c7d482 req_ctx: avoid loop iterations by introducing per-state queues
In order to speed up the lookup of req_ctx, we keep per-state queues
rather than iterating over all the request contexts that exist again and
again.
2014-11-11 22:30:54 +01:00
Min Xu 40def0ab1a change req_ctx sizes large 2048->1000; small 128->270 2014-11-11 22:30:53 +01:00
Min Xu 3b7035dcd9 req_ctx: Use consistent numeric range for REQ_CTX_STATE
... which will allow us to check for invalid states by a simple
'greater than' check later on.
2014-11-11 22:30:53 +01:00
Harald Welte 3c85f8de8d update main_factory to write version 1,4,0 instead of 1,3,0 to OTP 2014-11-11 22:26:45 +01:00
Harald Welte bb28e090cd simtrace: main_factory: Program OTP area with simtrace version 2013-11-17 20:13:13 +01:00
Harald Welte 54c248f97a simtrace: Add OTP data containing production data 2013-11-17 20:12:58 +01:00
Harald Welte 1e8df4869c spi_flash: add code for OTP read/write 2013-11-17 20:12:39 +01:00
Harald Welte 6ea973b79e iso7816_uart: Make sure ATR is separated from normal APDU in all cases
Prior to this patch, the ATR was not send in a separate USB message for
cards that are T=0 only.
2012-05-18 21:52:32 +02:00
Harald Welte 5aae62cb7b 7816_uart: add comment about f/d calculation 2012-05-18 08:41:08 +02:00
Holger Freyther f0fb308984 eabi: Remove EABI functions to fix building with EABI toolchains
These symbols are not referenced on an arm-elf gcc 4.7, they are
used when building with an arm-eabi gcc 4.7 and then cause linking
issues. The linking to libgcc can not be omitted as the irq code is
using ffs. Remove the EABI symbols. The alternative would be to
declare the EABI as weak inside the lib1funcs.

Link error:
multiple definition of `__udivsi3'
multiple definition of `__aeabi_uidiv'

Exported symbols:
nm lib/lib1funcs.o
00000000 t Ldiv0
00000010 T __div0
2012-04-08 10:01:04 +02:00
Harald Welte 868b6d0c68 simtrace: introduce statistics
the statistics count various events like overruns, parity errors,
missing rctx and can dump those stats via USB as well as on the serial
console.
2012-03-23 00:03:45 +01:00
Harald Welte 4c0cf591b0 wdt: make sure WDT doesn't fire inadvertently
We have to set WDD and WDV to the same value to avoid watchdog errors
2012-03-22 23:33:07 +01:00
Harald Welte 4086f4cf46 simtrace: implement SIM power switching API
there is now a high-level command by which we can swithc the VCC
supply of the SIM cards.

For some reason, the _PASS variant (passing through the voltage from the
phone) doesn't seem to work reliably.  It might be that we are draining
reverse current throught the LDO once we supply SIM power that way.
2012-03-22 22:55:14 +01:00
Harald Welte 559fc68583 make VCC / card detect more reliable 2012-03-22 15:20:54 +01:00
Harald Welte 94143382bf disable logging of PIO status in PIO interrupt routine 2012-03-22 15:03:10 +01:00
Harald Welte 4f7ca20bf4 simtrace: Inform host of Fi/Di values (and flag change due to PPS) 2012-02-12 15:34:41 +01:00
Sylvain Munaut f233812722 simtrace: 7816 UART: Add missing entry in Di table
Add missing entry in Fi_table. It's apparently used as '64' in some
reader and 'unsupported' in some other. For simtrace I guess we should
consider it 64.
2012-01-26 00:53:15 +01:00
Kevin Redon 2a3d3624be Make sure we don't forward power _and_ supply SIM power at the same time
The FPF2005 has no reverse voltage blocker, this is why the 3.3V from
the LDO flows back into VCC_PHONE. It even damages the chip (so says the
datasheet) I corrected the double power source problem by disabling the
LDO (see patch), but still 1.8V does not work and 3.0-3.3V is used. I
have to look for other reasons.
2011-12-18 08:35:20 +01:00
Holger Hans Peter Freyther ebf16b4ddf usb: Do not send ZLP when we have filled the window
Only send the ZLP if we send less data than was required/asked for
by the host and it is a multiple of the bMaxPacketSize0 (which is
hardcoded to 8 right now).

This is completing the change done in fe88b83e80 to
fix SIMtrace attached to OSX and not regress on windows.

Introduce another parameter to udp_ep0_send_data to specify the window
size (wLength) or if not available the default from USB 2.0 specification.
2011-12-14 15:16:54 +01:00
Holger Hans Peter Freyther ebc2088382 dfu: Remove unused variable, mark method as not retuning 2011-11-10 07:33:56 +01:00
Holger Hans Peter Freyther 7db9f66c8b dfu: Use {} for possible empty if statement (in case debug is off)
src/dfu/dfu.c:853:23: warning: suggest braces around empty body in an ‘if’ statement [-Wempty-body]
2011-11-10 07:33:55 +01:00
Holger Hans Peter Freyther 1532eb49f4 dfu: Mark unsued variables as __unused for now 2011-11-10 07:33:55 +01:00
Holger Hans Peter Freyther c6f26629d2 dfu: udp_ep0_recv_clean is static and is not called anywhere 2011-11-10 07:33:53 +01:00
Holger Hans Peter Freyther 7ab4135217 dfu: The i variable to disable interrupts shadows the outer index
In case ram_app_entry() returns do not reset i to 32, otherwise we
will never reset the watchdog.

src/dfu/dfu.c:1077:7: warning: declaration of ‘i’ shadows a previous local [-Wshadow]
src/dfu/dfu.c:1068:6: warning: shadowed declaration is here [-Wshadow]
2011-11-10 07:33:53 +01:00
Bjoern Kerler 3d60f2e042 fix linking issue with latest binutils versions 2011-10-21 20:02:12 +02:00
Bjoern Kerler 427688677e Fix fi/di calculation for certain mobiles like GT-S770 or HTC Raphael
There were some mistakes while copying the tables from ISO 7816-3,
and also a quite old version of 7816-3 was used.
2011-10-21 20:01:01 +02:00
Harald Welte 4b27294faf Update TODO file 2011-08-16 11:49:22 +02:00
Harald Welte 9dbedc6587 SIMTRACE: ISO7816: Deal with ATR that don't have historical bytes
In case there are no historical bytes, we immediately transition from
the last TD byte into the WAIT_TCK or WAIT_APDU state.
2011-08-16 10:22:01 +02:00
Harald Welte d9930d60aa ISO7816: Properly handle T=0 only cards without TCK in ATR 2011-08-16 10:10:39 +02:00
Harald Welte fa7297b93f SIMTRACE UART: Reset error status on error related IRQ
This prevents an IRQ-flood after a parity or overrun error, which
in turn would cause a watchdog reset.
2011-08-15 22:59:24 +02:00
Harald Welte a6d972c23d simtrace UART: set INACK flag to make sure we ignore any parity error
As a SIM card tracer, we want to remain completely passive and thus not
signal back parity errors with the ISO 7816 NACK.

The UART INACK flag does exactly that...
2011-08-15 21:42:03 +02:00
Harald Welte ea85282e09 DBGU: Print Reset controller Status Register on boot
This helps us to discover _why_ the CPU has been rebooted.
2011-08-15 21:40:35 +02:00
Harald Welte 7d31d475b6 USB: Add support for the 3rd DFU interface (RAM) 2011-08-15 21:40:09 +02:00
Harald Welte 48029c2bf3 add simtrace README file 2011-07-30 19:07:04 +02:00
Harald Welte a3de0a4ac2 Merge branch 'simtrace' 2011-07-30 19:04:55 +02:00
Harald Welte ffbce3ea2c update mkcompile_h to work with git repository 2011-07-30 19:01:57 +02:00
Harald Welte dd88fde8d2 USB driver: use the DFU-provided function to send EP0 data
There is no point in replicating the functionality that already
exists in the DFU section of the flash
2011-07-07 17:57:01 +02:00
Harald Welte 8cc090e310 dfu: fix EP0 IN trasnfers that are even multiple of 8
We have to send a ZLP at the end of such transfers, otherwise the host
will time out at the end of the transfer.  This resulted in multi-second
delays for recognizing the SIMtrace hardware by the USB host.
2011-07-07 17:56:55 +02:00
Holger Hans Peter Freyther 8ac31009df typo: Fix typo, transform reqyests to requests. 2011-01-31 18:15:42 +03:00
Harald Welte 1e04258b8d ausb: fix interrupt URB callback 2010-11-18 23:08:29 +01:00
Harald Welte 6506db78c1 ausb: make ausb_test compile again 2010-11-18 23:08:23 +01:00
86 changed files with 1948 additions and 1001 deletions

58
README.md Normal file
View File

@ -0,0 +1,58 @@
OpenPCD, OpenPICC and SIMtrace device firmware
==============================================
This repository contains the C-language firmware of a couple of
different USB devices that share nothing in common but the fact that
they contain and Atmel AT91SAM7S microcontroller and that Harald Welte
was involved in their development.
The OpenPCD 1.x and OpenPICC 1.x devices are pretty much obsolete these
days, so SAM7S based SIMtrace 1.x is the only relevant platform these
days.
[Osmocom](https://osmocom.org/)
[SIMtrace](https://osmocom.org/projects/simtrace) is a USB-attached
peripheral device that is primarily used to sniff the traffic between a
SIM/USIM card and a Phone or cellular modem.
Homepage
--------
The official homepage of the project is
<https://osmocom.org/projects/simtrace/wiki/>
GIT Repository
--------------
You can clone from the official openpcd.git repository using
git clone git://git.osmocom.org/openpcd.git
There is a cgit interface at <http://git.osmocom.org/openpcd/>
Documentation
-------------
Ther homepage (see above) contains a wiki with information as well as
the SIMtrace user manual.
Mailing List
------------
Discussions related to SIMtrace are happening on the
simtrace@lists.osmocom.org mailing list, please see
<https://lists.osmocom.org/mailman/listinfo/simtrace> for subscription
options and the list archive.
Please observe the [Osmocom Mailing List
Rules](https://osmocom.org/projects/cellular-infrastructure/wiki/Mailing_List_Rules)
when posting.
Contributing
------------
Our coding standards are described at
<https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards>
We use accept code/patch submissions via e-mail to the above-mentioned
mailing list.

View File

@ -116,7 +116,8 @@ ifeq ($(BOARD), SIMTRACE)
SUBMDL = AT91SAM7S128
TARGET := main_simtrace
SRCARM += src/simtrace/iso7816_uart.c src/simtrace/tc_etu.c \
src/simtrace/sim_switch.c src/simtrace/spi_flash.c
src/simtrace/sim_switch.c src/simtrace/spi_flash.c \
src/simtrace/prod_info.c
SRCARM += src/simtrace/$(TARGET).c
endif
@ -351,12 +352,13 @@ LPC21ISP_CONTROL = -control
# Define programs and commands.
SHELL = sh
CC = arm-elf-gcc
CPP = arm-elf-g++
OBJCOPY = arm-elf-objcopy
OBJDUMP = arm-elf-objdump
SIZE = arm-elf-size
NM = arm-elf-nm
CROSS_COMPILE ?= arm-elf-
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
SIZE = $(CROSS_COMPILE)size
NM = $(CROSS_COMPILE)nm
REMOVE = rm -f
COPY = cp

View File

@ -303,12 +303,13 @@ LPC21ISP_CONTROL = -control
# Define programs and commands.
SHELL = sh
CC = arm-elf-gcc
CPP = arm-elf-g++
OBJCOPY = arm-elf-objcopy
OBJDUMP = arm-elf-objdump
SIZE = arm-elf-size
NM = arm-elf-nm
CROSS_COMPILE ?= arm-elf-
CC = $(CROSS_COMPILE)gcc
CPP = $(CROSS_COMPILE)g++
OBJCOPY = $(CROSS_COMPILE)objcopy
OBJDUMP = $(CROSS_COMPILE)objdump
SIZE = $(CROSS_COMPILE)size
NM = $(CROSS_COMPILE)nm
REMOVE = rm -f
COPY = cp

9
firmware/README.simtrace Normal file
View File

@ -0,0 +1,9 @@
You will probably need the followign commants:
make -f Makefile.dfu BOARD=SIMTRACE
make BOARD=SIMTRACE DEBUG=1 TARGET=main_simtrace
as well as possibly
cat dfu.bin main_simtrace.bin > main_simtrace.samba

View File

@ -10,14 +10,9 @@ USB:
- Make sure we don't eat a lot of power before entering the configured state
DFU:
- fix DFU download (usb control write / zlp at end)
- add capability to flash DFU itself
- add a header to the application program, checksum and size
- checksum application image. If wrong, enter DFU recovery mode
- Get rid of lots of constant values and replace them by proper defines
Generic:
- why is watchdog apparently not working?
Way Later, for librfid:
- Implement parts (or all of) 14443 in firmware as alternative configuration

View File

@ -4,4 +4,7 @@
#define likely(x) __builtin_expect(!!(x), 1)
#define unlikely(x) __builtin_expect(!!(x), 0)
#define __unused __attribute__((unused))
#define __noreturn __attribute__((noreturn))
#endif

View File

@ -6,12 +6,12 @@
#include <sys/types.h>
struct openpcd_hdr {
u_int8_t cmd; /* command. high nibble: class,
uint8_t cmd; /* command. high nibble: class,
* low nibble: cmd */
u_int8_t flags;
u_int8_t reg; /* register */
u_int8_t val; /* value (in case of write *) */
u_int8_t data[0];
uint8_t flags;
uint8_t reg; /* register */
uint8_t val; /* value (in case of write *) */
uint8_t data[0];
} __attribute__ ((packed));
#define OPCD_REV_LEN 16

View File

@ -5,20 +5,33 @@
/* this is kept compatible with OpenPCD protocol */
struct simtrace_hdr {
u_int8_t cmd;
u_int8_t flags;
u_int8_t res[2];
u_int8_t data[0];
uint8_t cmd;
uint8_t flags;
uint8_t res[2];
uint8_t data[0];
} __attribute__ ((packed));
enum simtrace_usb_msgt {
SIMTRACE_MSGT_NULL,
SIMTRACE_MSGT_DATA,
SIMTRACE_MSGT_RESET, /* reset was asserted, no more data */
SIMTRACE_MSGT_STATS, /* statistics */
};
/* flags for MSGT_DATA */
#define SIMTRACE_FLAG_ATR 0x01 /* ATR immediately after reset */
#define SIMTRACE_FLAG_WTIME_EXP 0x04 /* work waiting time expired */
#define SIMTRACE_FLAG_PPS_FIDI 0x08 /* Fi/Di values in res[2] */
struct simtrace_stats {
uint32_t no_rctx;
uint32_t rctx_sent;
uint32_t rst;
uint32_t pps;
uint32_t bytes;
uint32_t parity_err;
uint32_t frame_err;
uint32_t overrun;
} stats;
#endif /* SIMTRACE_USB_H */

View File

@ -119,11 +119,11 @@
* such requests may be made at any time.
*/
struct usb_ctrlrequest {
u_int8_t bRequestType;
u_int8_t bRequest;
u_int16_t wValue;
u_int16_t wIndex;
u_int16_t wLength;
uint8_t bRequestType;
uint8_t bRequest;
uint16_t wValue;
uint16_t wIndex;
uint16_t wLength;
} __attribute__ ((packed));
/*-------------------------------------------------------------------------*/
@ -169,8 +169,8 @@ struct usb_ctrlrequest {
/* All standard descriptors have these 2 fields at the beginning */
struct usb_descriptor_header {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
} __attribute__ ((packed));
@ -178,21 +178,21 @@ struct usb_descriptor_header {
/* USB_DT_DEVICE: Device descriptor */
struct usb_device_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t bcdUSB;
u_int8_t bDeviceClass;
u_int8_t bDeviceSubClass;
u_int8_t bDeviceProtocol;
u_int8_t bMaxPacketSize0;
u_int16_t idVendor;
u_int16_t idProduct;
u_int16_t bcdDevice;
u_int8_t iManufacturer;
u_int8_t iProduct;
u_int8_t iSerialNumber;
u_int8_t bNumConfigurations;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint16_t idVendor;
uint16_t idProduct;
uint16_t bcdDevice;
uint8_t iManufacturer;
uint8_t iProduct;
uint8_t iSerialNumber;
uint8_t bNumConfigurations;
} __attribute__ ((packed));
#define USB_DT_DEVICE_SIZE 18
@ -231,15 +231,15 @@ struct usb_device_descriptor {
* descriptors.
*/
struct usb_config_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t wTotalLength;
u_int8_t bNumInterfaces;
u_int8_t bConfigurationValue;
u_int8_t iConfiguration;
u_int8_t bmAttributes;
u_int8_t bMaxPower;
uint16_t wTotalLength;
uint8_t bNumInterfaces;
uint8_t bConfigurationValue;
uint8_t iConfiguration;
uint8_t bmAttributes;
uint8_t bMaxPower;
} __attribute__ ((packed));
#define USB_DT_CONFIG_SIZE 9
@ -254,10 +254,10 @@ struct usb_config_descriptor {
/* USB_DT_STRING: String descriptor */
struct usb_string_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t wData[0]; /* UTF-16LE encoded */
uint16_t wData[0]; /* UTF-16LE encoded */
} __attribute__ ((packed));
/* note that "string" zero is special, it holds language codes that
@ -268,16 +268,16 @@ struct usb_string_descriptor {
/* USB_DT_INTERFACE: Interface descriptor */
struct usb_interface_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bInterfaceNumber;
u_int8_t bAlternateSetting;
u_int8_t bNumEndpoints;
u_int8_t bInterfaceClass;
u_int8_t bInterfaceSubClass;
u_int8_t bInterfaceProtocol;
u_int8_t iInterface;
uint8_t bInterfaceNumber;
uint8_t bAlternateSetting;
uint8_t bNumEndpoints;
uint8_t bInterfaceClass;
uint8_t bInterfaceSubClass;
uint8_t bInterfaceProtocol;
uint8_t iInterface;
} __attribute__ ((packed));
#define USB_DT_INTERFACE_SIZE 9
@ -286,13 +286,13 @@ struct usb_interface_descriptor {
/* USB_DT_ENDPOINT: Endpoint descriptor */
struct usb_endpoint_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bEndpointAddress;
u_int8_t bmAttributes;
u_int16_t wMaxPacketSize;
u_int8_t bInterval;
uint8_t bEndpointAddress;
uint8_t bmAttributes;
uint16_t wMaxPacketSize;
uint8_t bInterval;
} __attribute__ ((packed));
#define USB_DT_ENDPOINT_SIZE 7
@ -317,16 +317,16 @@ struct usb_endpoint_descriptor {
/* USB_DT_DEVICE_QUALIFIER: Device Qualifier descriptor */
struct usb_qualifier_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t bcdUSB;
u_int8_t bDeviceClass;
u_int8_t bDeviceSubClass;
u_int8_t bDeviceProtocol;
u_int8_t bMaxPacketSize0;
u_int8_t bNumConfigurations;
u_int8_t bRESERVED;
uint16_t bcdUSB;
uint8_t bDeviceClass;
uint8_t bDeviceSubClass;
uint8_t bDeviceProtocol;
uint8_t bMaxPacketSize0;
uint8_t bNumConfigurations;
uint8_t bRESERVED;
} __attribute__ ((packed));
@ -334,10 +334,10 @@ struct usb_qualifier_descriptor {
/* USB_DT_OTG (from OTG 1.0a supplement) */
struct usb_otg_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bmAttributes; /* support for HNP, SRP, etc */
uint8_t bmAttributes; /* support for HNP, SRP, etc */
} __attribute__ ((packed));
/* from usb_otg_descriptor.bmAttributes */
@ -348,27 +348,27 @@ struct usb_otg_descriptor {
/* USB_DT_DEBUG: for special highspeed devices, replacing serial console */
struct usb_debug_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
/* bulk endpoints with 8 byte maxpacket */
u_int8_t bDebugInEndpoint;
u_int8_t bDebugOutEndpoint;
uint8_t bDebugInEndpoint;
uint8_t bDebugOutEndpoint;
};
/*-------------------------------------------------------------------------*/
/* USB_DT_INTERFACE_ASSOCIATION: groups interfaces */
struct usb_interface_assoc_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bFirstInterface;
u_int8_t bInterfaceCount;
u_int8_t bFunctionClass;
u_int8_t bFunctionSubClass;
u_int8_t bFunctionProtocol;
u_int8_t iFunction;
uint8_t bFirstInterface;
uint8_t bInterfaceCount;
uint8_t bFunctionClass;
uint8_t bFunctionSubClass;
uint8_t bFunctionProtocol;
uint8_t iFunction;
} __attribute__ ((packed));
@ -378,11 +378,11 @@ struct usb_interface_assoc_descriptor {
* encryption types available for setting up a CC/association.
*/
struct usb_security_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t wTotalLength;
u_int8_t bNumEncryptionTypes;
uint16_t wTotalLength;
uint8_t bNumEncryptionTypes;
};
/*-------------------------------------------------------------------------*/
@ -391,28 +391,28 @@ struct usb_security_descriptor {
* may be retrieved.
*/
struct usb_key_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t tTKID[3];
u_int8_t bReserved;
u_int8_t bKeyData[0];
uint8_t tTKID[3];
uint8_t bReserved;
uint8_t bKeyData[0];
};
/*-------------------------------------------------------------------------*/
/* USB_DT_ENCRYPTION_TYPE: bundled in DT_SECURITY groups */
struct usb_encryption_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bEncryptionType;
uint8_t bEncryptionType;
#define USB_ENC_TYPE_UNSECURE 0
#define USB_ENC_TYPE_WIRED 1 /* non-wireless mode */
#define USB_ENC_TYPE_CCM_1 2 /* aes128/cbc session */
#define USB_ENC_TYPE_RSA_1 3 /* rsa3072/sha1 auth */
u_int8_t bEncryptionValue; /* use in SET_ENCRYPTION */
u_int8_t bAuthKeyIndex;
uint8_t bEncryptionValue; /* use in SET_ENCRYPTION */
uint8_t bAuthKeyIndex;
};
@ -420,36 +420,36 @@ struct usb_encryption_descriptor {
/* USB_DT_BOS: group of wireless capabilities */
struct usb_bos_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int16_t wTotalLength;
u_int8_t bNumDeviceCaps;
uint16_t wTotalLength;
uint8_t bNumDeviceCaps;
};
/*-------------------------------------------------------------------------*/
/* USB_DT_DEVICE_CAPABILITY: grouped with BOS */
struct usb_dev_cap_header {
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t bDevCapabilityType;
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDevCapabilityType;
};
#define USB_CAP_TYPE_WIRELESS_USB 1
struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t bDevCapabilityType;
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bDevCapabilityType;
u_int8_t bmAttributes;
uint8_t bmAttributes;
#define USB_WIRELESS_P2P_DRD (1 << 1)
#define USB_WIRELESS_BEACON_MASK (3 << 2)
#define USB_WIRELESS_BEACON_SELF (1 << 2)
#define USB_WIRELESS_BEACON_DIRECTED (2 << 2)
#define USB_WIRELESS_BEACON_NONE (3 << 2)
u_int16_t wPHYRates; /* bit rates, Mbps */
uint16_t wPHYRates; /* bit rates, Mbps */
#define USB_WIRELESS_PHY_53 (1 << 0) /* always set */
#define USB_WIRELESS_PHY_80 (1 << 1)
#define USB_WIRELESS_PHY_107 (1 << 2) /* always set */
@ -458,10 +458,10 @@ struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
#define USB_WIRELESS_PHY_320 (1 << 5)
#define USB_WIRELESS_PHY_400 (1 << 6)
#define USB_WIRELESS_PHY_480 (1 << 7)
u_int8_t bmTFITXPowerInfo; /* TFI power levels */
u_int8_t bmFFITXPowerInfo; /* FFI power levels */
u_int16_t bmBandGroup;
u_int8_t bReserved;
uint8_t bmTFITXPowerInfo; /* TFI power levels */
uint8_t bmFFITXPowerInfo; /* FFI power levels */
uint16_t bmBandGroup;
uint8_t bReserved;
};
/*-------------------------------------------------------------------------*/
@ -470,15 +470,15 @@ struct usb_wireless_cap_descriptor { /* Ultra Wide Band */
* each endpoint descriptor for a wireless device
*/
struct usb_wireless_ep_comp_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
uint8_t bLength;
uint8_t bDescriptorType;
u_int8_t bMaxBurst;
u_int8_t bMaxSequence;
u_int16_t wMaxStreamDelay;
u_int16_t wOverTheAirPacketSize;
u_int8_t bOverTheAirInterval;
u_int8_t bmCompAttributes;
uint8_t bMaxBurst;
uint8_t bMaxSequence;
uint16_t wMaxStreamDelay;
uint16_t wOverTheAirPacketSize;
uint8_t bOverTheAirInterval;
uint8_t bmCompAttributes;
#define USB_ENDPOINT_SWITCH_MASK 0x03 /* in bmCompAttributes */
#define USB_ENDPOINT_SWITCH_NO 0
#define USB_ENDPOINT_SWITCH_SWITCH 1
@ -492,13 +492,13 @@ struct usb_wireless_ep_comp_descriptor {
* exchanging short lived session keys. The handshake depends on a CC.
*/
struct usb_handshake {
u_int8_t bMessageNumber;
u_int8_t bStatus;
u_int8_t tTKID[3];
u_int8_t bReserved;
u_int8_t CDID[16];
u_int8_t nonce[16];
u_int8_t MIC[8];
uint8_t bMessageNumber;
uint8_t bStatus;
uint8_t tTKID[3];
uint8_t bReserved;
uint8_t CDID[16];
uint8_t nonce[16];
uint8_t MIC[8];
};
/*-------------------------------------------------------------------------*/
@ -508,9 +508,9 @@ struct usb_handshake {
* wired USB!), and some devices may support CCs with multiple hosts.
*/
struct usb_connection_context {
u_int8_t CHID[16]; /* persistent host id */
u_int8_t CDID[16]; /* device id (unique w/in host context) */
u_int8_t CK[16]; /* connection key */
uint8_t CHID[16]; /* persistent host id */
uint8_t CDID[16]; /* device id (unique w/in host context) */
uint8_t CK[16]; /* connection key */
};
/*-------------------------------------------------------------------------*/

View File

@ -15,16 +15,16 @@
#define USB_DT_DFU 0x21
struct usb_dfu_func_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int8_t bmAttributes;
uint8_t bLength;
uint8_t bDescriptorType;
uint8_t bmAttributes;
#define USB_DFU_CAN_DOWNLOAD (1 << 0)
#define USB_DFU_CAN_UPLOAD (1 << 1)
#define USB_DFU_MANIFEST_TOL (1 << 2)
#define USB_DFU_WILL_DETACH (1 << 3)
u_int16_t wDetachTimeOut;
u_int16_t wTransferSize;
u_int16_t bcdDFUVersion;
uint16_t wDetachTimeOut;
uint16_t wTransferSize;
uint16_t bcdDFUVersion;
} __attribute__ ((packed));
#define USB_DT_DFU_SIZE 9
@ -41,10 +41,10 @@ struct usb_dfu_func_descriptor {
#define USB_REQ_DFU_ABORT 0x06
struct dfu_status {
u_int8_t bStatus;
u_int8_t bwPollTimeout[3];
u_int8_t bState;
u_int8_t iString;
uint8_t bStatus;
uint8_t bwPollTimeout[3];
uint8_t bState;
uint8_t iString;
} __attribute__((packed));
#define DFU_STATUS_OK 0x00

View File

@ -214,16 +214,16 @@
#define HID_FEATURE_REPORT 2
struct usb_hid_class_descriptor {
u_int8_t bDescriptorType;
u_int16_t wDescriptorLength;
uint8_t bDescriptorType;
uint16_t wDescriptorLength;
} __attribute__ ((packed));
struct usb_hid_descriptor {
u_int8_t bLength;
u_int8_t bDescriptorType;
u_int16_t bcdHID;
u_int8_t bCountryCode;
u_int8_t bNumDescriptors;
uint8_t bLength;
uint8_t bDescriptorType;
uint16_t bcdHID;
uint8_t bCountryCode;
uint8_t bNumDescriptors;
struct hid_class_descriptor desc[1];
} __attribute__ ((packed));

View File

@ -205,105 +205,6 @@ Boston, MA 02111-1307, USA. */
.endm
ENTRY(__udivsi3)
ENTRY(__aeabi_uidiv)
subs r2, r1, #1
moveq pc, lr
bcc Ldiv0
cmp r0, r1
bls 11f
tst r1, r2
beq 12f
ARM_DIV_BODY r0, r1, r2, r3
mov r0, r2
mov pc, lr
11: moveq r0, #1
movne r0, #0
mov pc, lr
12: ARM_DIV2_ORDER r1, r2
mov r0, r0, lsr r2
mov pc, lr
ENTRY(__umodsi3)
subs r2, r1, #1 @ compare divisor with 1
bcc Ldiv0
cmpne r0, r1 @ compare dividend with divisor
moveq r0, #0
tsthi r1, r2 @ see if divisor is power of 2
andeq r0, r0, r2
movls pc, lr
ARM_MOD_BODY r0, r1, r2, r3
mov pc, lr
ENTRY(__divsi3)
ENTRY(__aeabi_idiv)
cmp r1, #0
eor ip, r0, r1 @ save the sign of the result.
beq Ldiv0
rsbmi r1, r1, #0 @ loops below use unsigned.
subs r2, r1, #1 @ division by 1 or -1 ?
beq 10f
movs r3, r0
rsbmi r3, r0, #0 @ positive dividend value
cmp r3, r1
bls 11f
tst r1, r2 @ divisor is power of 2 ?
beq 12f
ARM_DIV_BODY r3, r1, r0, r2
cmp ip, #0
rsbmi r0, r0, #0
mov pc, lr
10: teq ip, r0 @ same sign ?
rsbmi r0, r0, #0
mov pc, lr
11: movlo r0, #0
moveq r0, ip, asr #31
orreq r0, r0, #1
mov pc, lr
12: ARM_DIV2_ORDER r1, r2
cmp ip, #0
mov r0, r3, lsr r2
rsbmi r0, r0, #0
mov pc, lr
ENTRY(__modsi3)
cmp r1, #0
beq Ldiv0
rsbmi r1, r1, #0 @ loops below use unsigned.
movs ip, r0 @ preserve sign of dividend
rsbmi r0, r0, #0 @ if negative make positive
subs r2, r1, #1 @ compare divisor with 1
cmpne r0, r1 @ compare dividend with divisor
moveq r0, #0
tsthi r1, r2 @ see if divisor is power of 2
andeq r0, r0, r2
bls 10f
ARM_MOD_BODY r0, r1, r2, r3
10: cmp ip, #0
rsbmi r0, r0, #0
mov pc, lr
#ifdef CONFIG_AEABI

151
firmware/scripts/git-version-gen Executable file
View File

@ -0,0 +1,151 @@
#!/bin/sh
# Print a version string.
scriptversion=2010-01-28.01
# Copyright (C) 2007-2010 Free Software Foundation, Inc.
#
# 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 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# This script is derived from GIT-VERSION-GEN from GIT: http://git.or.cz/.
# It may be run two ways:
# - from a git repository in which the "git describe" command below
# produces useful output (thus requiring at least one signed tag)
# - from a non-git-repo directory containing a .tarball-version file, which
# presumes this script is invoked like "./git-version-gen .tarball-version".
# In order to use intra-version strings in your project, you will need two
# separate generated version string files:
#
# .tarball-version - present only in a distribution tarball, and not in
# a checked-out repository. Created with contents that were learned at
# the last time autoconf was run, and used by git-version-gen. Must not
# be present in either $(srcdir) or $(builddir) for git-version-gen to
# give accurate answers during normal development with a checked out tree,
# but must be present in a tarball when there is no version control system.
# Therefore, it cannot be used in any dependencies. GNUmakefile has
# hooks to force a reconfigure at distribution time to get the value
# correct, without penalizing normal development with extra reconfigures.
#
# .version - present in a checked-out repository and in a distribution
# tarball. Usable in dependencies, particularly for files that don't
# want to depend on config.h but do want to track version changes.
# Delete this file prior to any autoconf run where you want to rebuild
# files to pick up a version string change; and leave it stale to
# minimize rebuild time after unrelated changes to configure sources.
#
# It is probably wise to add these two files to .gitignore, so that you
# don't accidentally commit either generated file.
#
# Use the following line in your configure.ac, so that $(VERSION) will
# automatically be up-to-date each time configure is run (and note that
# since configure.ac no longer includes a version string, Makefile rules
# should not depend on configure.ac for version updates).
#
# AC_INIT([GNU project],
# m4_esyscmd([build-aux/git-version-gen .tarball-version]),
# [bug-project@example])
#
# Then use the following lines in your Makefile.am, so that .version
# will be present for dependencies, and so that .tarball-version will
# exist in distribution tarballs.
#
# BUILT_SOURCES = $(top_srcdir)/.version
# $(top_srcdir)/.version:
# echo $(VERSION) > $@-t && mv $@-t $@
# dist-hook:
# echo $(VERSION) > $(distdir)/.tarball-version
case $# in
1) ;;
*) echo 1>&2 "Usage: $0 \$srcdir/.tarball-version"; exit 1;;
esac
tarball_version_file=$1
nl='
'
# First see if there is a tarball-only version file.
# then try "git describe", then default.
if test -f $tarball_version_file
then
v=`cat $tarball_version_file` || exit 1
case $v in
*$nl*) v= ;; # reject multi-line output
[0-9]*) ;;
*) v= ;;
esac
test -z "$v" \
&& echo "$0: WARNING: $tarball_version_file seems to be damaged" 1>&2
fi
if test -n "$v"
then
: # use $v
elif
v=`git describe --abbrev=4 --match='v*' HEAD 2>/dev/null \
|| git describe --abbrev=4 HEAD 2>/dev/null` \
&& case $v in
[0-9]*) ;;
v[0-9]*) ;;
*) (exit 1) ;;
esac
then
# Is this a new git that lists number of commits since the last
# tag or the previous older version that did not?
# Newer: v6.10-77-g0f8faeb
# Older: v6.10-g0f8faeb
case $v in
*-*-*) : git describe is okay three part flavor ;;
*-*)
: git describe is older two part flavor
# Recreate the number of commits and rewrite such that the
# result is the same as if we were using the newer version
# of git describe.
vtag=`echo "$v" | sed 's/-.*//'`
numcommits=`git rev-list "$vtag"..HEAD | wc -l`
v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`;
;;
esac
# Change the first '-' to a '.', so version-comparing tools work properly.
# Remove the "g" in git describe's output string, to save a byte.
v=`echo "$v" | sed 's/-/./;s/\(.*\)-g/\1-/'`;
else
v=UNKNOWN
fi
v=`echo "$v" |sed 's/^v//'`
# Don't declare a version "dirty" merely because a time stamp has changed.
git status > /dev/null 2>&1
dirty=`sh -c 'git diff-index --name-only HEAD' 2>/dev/null` || dirty=
case "$dirty" in
'') ;;
*) # Append the suffix only if there isn't one already.
case $v in
*-dirty) ;;
*) v="$v-dirty" ;;
esac ;;
esac
# Omit the trailing newline, so that m4_esyscmd can use the result directly.
echo "$v" | tr -d '\012'
# Local variables:
# eval: (add-hook 'write-file-hooks 'time-stamp)
# time-stamp-start: "scriptversion="
# time-stamp-format: "%:y-%02m-%02d.%02H"
# time-stamp-end: "$"
# End:

View File

@ -7,11 +7,11 @@ DATE=`LC_ALL=C LANG=C date +%Y%m%d-%H%M%S`
BY=`whoami`
HOST=`hostname | $TRUNCATE`
BYHOST=`echo ${BY}@${HOST} | $TRUNCATE`
SVNREV=`svn info | grep \^Revision: | cut -c 11-`
#SVNREV=`svn info | grep \^Revision: | cut -c 11-`
#svn st | grep \^M >/dev/null
#[ "$?" -eq "0" ] && SVNREV=${SVNREV}-unclean
svn st | grep \^M >/dev/null
[ "$?" -eq "0" ] && SVNREV=${SVNREV}-unclean
SVNREV=`scripts/git-version-gen .tarball-version`
echo "#ifndef _COMPILE_H"
echo "#define _COMPILE_H"

View File

@ -28,27 +28,28 @@
#include <sys/types.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
static int utf8_to_utf16le(const char *s, u_int16_t *cp, unsigned len)
static int utf8_to_utf16le(const char *s, uint16_t *cp, unsigned len)
{
int count = 0;
u_int8_t c;
u_int16_t uchar;
uint8_t c;
uint16_t uchar;
/* this insists on correct encodings, though not minimal ones.
* BUT it currently rejects legit 4-byte UTF-8 code points,
* which need surrogate pairs. (Unicode 3.1 can use them.)
*/
while (len != 0 && (c = (u_int8_t) *s++) != 0) {
while (len != 0 && (c = (uint8_t) *s++) != 0) {
if (c & 0x80) {
// 2-byte sequence:
// 00000yyyyyxxxxxx = 110yyyyy 10xxxxxx
if ((c & 0xe0) == 0xc0) {
uchar = (c & 0x1f) << 6;
c = (u_int8_t) *s++;
c = (uint8_t) *s++;
if ((c & 0xc0) != 0xc0)
goto fail;
c &= 0x3f;
@ -59,13 +60,13 @@ static int utf8_to_utf16le(const char *s, u_int16_t *cp, unsigned len)
} else if ((c & 0xf0) == 0xe0) {
uchar = (c & 0x0f) << 12;
c = (u_int8_t) *s++;
c = (uint8_t) *s++;
if ((c & 0xc0) != 0xc0)
goto fail;
c &= 0x3f;
uchar |= c << 6;
c = (u_int8_t) *s++;
c = (uint8_t) *s++;
if ((c & 0xc0) != 0xc0)
goto fail;
c &= 0x3f;
@ -96,7 +97,7 @@ fail:
}
#define COLUMNS 6
static int print_array16(u_int16_t *buf, int len)
static int print_array16(uint16_t *buf, int len)
{
int i;
for (i = 0; i < len; i++) {
@ -130,10 +131,10 @@ static void print_structhdr(int i, int size)
{
printf( "static const struct {\n"
"\tstruct usb_descriptor_header hdr;\n"
"\tu_int16_t wData[];\n"
"\tuint16_t wData[];\n"
"} __attribute__((packed)) string%d = {\n"
"\t.hdr = {\n"
"\t\t.bLength = sizeof(struct usb_descriptor_header) + %u * sizeof(u_int16_t),\n"
"\t\t.bLength = sizeof(struct usb_descriptor_header) + %u * sizeof(uint16_t),\n"
"\t\t.bDescriptorType = USB_DT_STRING,\n"
"\t},\n"
"\t.wData = {", i, size);
@ -146,7 +147,7 @@ static void print_structftr(void)
int main(int argc, char **argv)
{
char asciibuf[512+1];
u_int16_t utf16buf[1024+1];
uint16_t utf16buf[1024+1];
int len;
int j, i = 1;
@ -160,7 +161,7 @@ int main(int argc, char **argv)
print_structftr();
#if 0
printf("static const struct usb_string_descriptor string0 = {\n"
"\t.bLength = sizeof(string0) + 1 * sizeof(u_int16_t),\n"
"\t.bLength = sizeof(string0) + 1 * sizeof(uint16_t),\n"
"\t.bDescriptorType = USB_DT_STRING,\n"
"\t.wData[0] = 0x0409, /* English */\n"
"};\n\n");
@ -176,7 +177,7 @@ int main(int argc, char **argv)
print_structhdr(i, len);
#if 0
printf("static const struct usb_string_descriptor string%d = {\n"
"\t.bLength = sizeof(string%d) + %d * sizeof(u_int16_t),\n"
"\t.bLength = sizeof(string%d) + %d * sizeof(uint16_t),\n"
"\t.bDescriptorType = USB_DT_STRING,\n"
"\t.wData = {", i, i, len);
#endif

View File

@ -72,9 +72,9 @@
static int past_manifest = 0;
static int switch_to_ram = 0; /* IRQ handler requests main to jump to RAM */
static u_int16_t usb_if_nr = 0; /* last SET_INTERFACE */
static u_int16_t usb_if_alt_nr = 0; /* last SET_INTERFACE AltSetting */
static u_int16_t usb_if_alt_nr_dnload = 0; /* AltSetting during last dnload */
static uint16_t usb_if_nr = 0; /* last SET_INTERFACE */
static uint16_t usb_if_alt_nr = 0; /* last SET_INTERFACE AltSetting */
static uint16_t usb_if_alt_nr_dnload = 0; /* AltSetting during last dnload */
static void __dfufunc udp_init(void)
{
@ -96,13 +96,15 @@ static void __dfufunc udp_init(void)
static void __dfufunc udp_ep0_send_zlp(void);
/* Send Data through the control endpoint */
static void __dfufunc udp_ep0_send_data(const char *pData, u_int32_t length)
static void __dfufunc udp_ep0_send_data(const char *pData, uint32_t length,
uint32_t window_length)
{
AT91PS_UDP pUdp = AT91C_BASE_UDP;
u_int32_t cpt = 0, len_remain = length;
uint32_t cpt = 0, len_remain;
AT91_REG csr;
DEBUGE("send_data: %u bytes ", length);
len_remain = MIN(length, window_length);
DEBUGE("send_data: %u/%u bytes ", length, window_length);
do {
cpt = MIN(len_remain, 8);
@ -135,7 +137,7 @@ static void __dfufunc udp_ep0_send_data(const char *pData, u_int32_t length)
while (pUdp->UDP_CSR[0] & AT91C_UDP_TXCOMP) ;
}
if ((length % 8) == 0) {
if ((length % 8) == 0 && length < window_length) {
/* if the length is a multiple of the EP size, we need
* to send another ZLP (zero-length packet) to tell the
* host the transfer has completed. */
@ -144,27 +146,13 @@ static void __dfufunc udp_ep0_send_data(const char *pData, u_int32_t length)
}
}
static void udp_ep0_recv_clean(void)
{
unsigned int i;
u_int8_t dummy;
const AT91PS_UDP pUdp = AT91C_BASE_UDP;
while (!(pUdp->UDP_CSR[0] & AT91C_UDP_RX_DATA_BK0)) ;
for (i = 0; i < (pUdp->UDP_CSR[0] >> 16); i++)
dummy = pUdp->UDP_FDR[0];
pUdp->UDP_CSR[0] &= ~(AT91C_UDP_RX_DATA_BK0);
}
/* receive data from EP0 */
static int __dfufunc udp_ep0_recv_data(u_int8_t *data, u_int16_t len)
static int __dfufunc udp_ep0_recv_data(uint8_t *data, uint16_t len)
{
AT91PS_UDP pUdp = AT91C_BASE_UDP;
AT91_REG csr;
u_int16_t i, num_rcv;
u_int32_t num_rcv_total = 0;
uint16_t i, num_rcv;
uint32_t num_rcv_total = 0;
do {
/* FIXME: do we need to check whether we've been interrupted
@ -218,10 +206,10 @@ static void __dfufunc udp_ep0_send_stall(void)
static int first_download = 1;
static u_int8_t *ptr, *ptr_max;
static __dfudata u_int8_t dfu_status;
__dfudata u_int32_t dfu_state = DFU_STATE_appIDLE;
static u_int32_t pagebuf32[AT91C_IFLASH_PAGE_SIZE/4];
static uint8_t *ptr, *ptr_max;
static __dfudata uint8_t dfu_status;
__dfudata uint32_t dfu_state = DFU_STATE_appIDLE;
static uint32_t pagebuf32[AT91C_IFLASH_PAGE_SIZE/4];
static void chk_first_dnload_set_ptr(void)
{
@ -230,25 +218,25 @@ static void chk_first_dnload_set_ptr(void)
switch (usb_if_alt_nr) {
case 0:
ptr = (u_int8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
ptr = (uint8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
ptr_max = AT91C_IFLASH + AT91C_IFLASH_SIZE - ENVIRONMENT_SIZE;
break;
case 1:
ptr = (u_int8_t *) AT91C_IFLASH;
ptr = (uint8_t *) AT91C_IFLASH;
ptr_max = AT91C_IFLASH + SAM7DFU_SIZE;
break;
case 2:
ptr = (u_int8_t *) AT91C_ISRAM + SAM7DFU_RAM_SIZE;
ptr = (uint8_t *) AT91C_ISRAM + SAM7DFU_RAM_SIZE;
ptr_max = AT91C_ISRAM + AT91C_ISRAM_SIZE;
break;
}
first_download = 0;
}
static int __dfufunc handle_dnload_flash(u_int16_t val, u_int16_t len)
static int __dfufunc handle_dnload_flash(uint16_t __unused val, uint16_t len)
{
volatile u_int32_t *p;
u_int8_t *pagebuf = (u_int8_t *) pagebuf32;
volatile uint32_t *p;
uint8_t *pagebuf = (uint8_t *) pagebuf32;
int i;
DEBUGE("download ");
@ -269,7 +257,7 @@ static int __dfufunc handle_dnload_flash(u_int16_t val, u_int16_t len)
return RET_STALL;
}
chk_first_dnload_set_ptr();
p = (volatile u_int32_t *)ptr;
p = (volatile uint32_t *)ptr;
if (len == 0) {
DEBUGP("zero-size write -> MANIFEST_SYNC ");
@ -305,13 +293,13 @@ static int __dfufunc handle_dnload_flash(u_int16_t val, u_int16_t len)
flash_page(p-1);
}
}
ptr = (u_int8_t *) p;
ptr = (uint8_t *) p;
#endif
return RET_ZLP;
}
static int __dfufunc handle_dnload_ram(u_int16_t val, u_int16_t len)
static int __dfufunc handle_dnload_ram(uint16_t __unused val, uint16_t len)
{
DEBUGE("download ");
@ -351,7 +339,7 @@ static int __dfufunc handle_dnload_ram(u_int16_t val, u_int16_t len)
return RET_ZLP;
}
static int __dfufunc handle_dnload(u_int16_t val, u_int16_t len)
static int __dfufunc handle_dnload(uint16_t val, uint16_t len)
{
usb_if_alt_nr_dnload = usb_if_alt_nr;
switch (usb_if_alt_nr) {
@ -362,8 +350,8 @@ static int __dfufunc handle_dnload(u_int16_t val, u_int16_t len)
}
}
#define AT91C_IFLASH_END ((u_int8_t *)AT91C_IFLASH + AT91C_IFLASH_SIZE)
static __dfufunc int handle_upload(u_int16_t val, u_int16_t len)
#define AT91C_IFLASH_END ((uint8_t *)AT91C_IFLASH + AT91C_IFLASH_SIZE)
static __dfufunc int handle_upload(uint16_t __unused val, uint16_t len)
{
DEBUGE("upload ");
if (len > AT91C_IFLASH_PAGE_SIZE) {
@ -376,11 +364,11 @@ static __dfufunc int handle_upload(u_int16_t val, u_int16_t len)
chk_first_dnload_set_ptr();
if (ptr + len > AT91C_IFLASH_END) {
len = AT91C_IFLASH_END - (u_int8_t *)ptr;
len = AT91C_IFLASH_END - (uint8_t *)ptr;
first_download = 1;
}
udp_ep0_send_data((char *)ptr, len);
udp_ep0_send_data((char *)ptr, len, len);
ptr+= len;
return len;
@ -389,7 +377,7 @@ static __dfufunc int handle_upload(u_int16_t val, u_int16_t len)
static __dfufunc void handle_getstatus(void)
{
struct dfu_status dstat;
u_int32_t fsr = AT91F_MC_EFC_GetStatus(AT91C_BASE_MC);
uint32_t fsr = AT91F_MC_EFC_GetStatus(AT91C_BASE_MC);
DEBUGE("getstatus(fsr=0x%08x) ", fsr);
@ -423,20 +411,20 @@ static __dfufunc void handle_getstatus(void)
dstat.iString = 0;
/* FIXME: set dstat.bwPollTimeout */
udp_ep0_send_data((char *)&dstat, sizeof(dstat));
udp_ep0_send_data((char *)&dstat, sizeof(dstat), sizeof(dstat));
}
static void __dfufunc handle_getstate(void)
{
u_int8_t u8 = dfu_state;
uint8_t u8 = dfu_state;
DEBUGE("getstate ");
udp_ep0_send_data((char *)&u8, sizeof(u8));
udp_ep0_send_data((char *)&u8, sizeof(u8), sizeof(u8));
}
/* callback function for DFU requests */
int __dfufunc dfu_ep0_handler(u_int8_t req_type, u_int8_t req,
u_int16_t val, u_int16_t len)
int __dfufunc dfu_ep0_handler(uint8_t __unused req_type, uint8_t req,
uint16_t val, uint16_t len)
{
int rc, ret = RET_NOTHING;
@ -485,11 +473,11 @@ int __dfufunc dfu_ep0_handler(u_int8_t req_type, u_int8_t req,
goto out;
}
dfu_state = DFU_STATE_dfuDNLOAD_SYNC;
ptr = (u_int8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
ptr = (uint8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
ret = handle_dnload(val, len);
break;
case USB_REQ_DFU_UPLOAD:
ptr = (u_int8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
ptr = (uint8_t *) AT91C_IFLASH + SAM7DFU_SIZE;
dfu_state = DFU_STATE_dfuUPLOAD_IDLE;
handle_upload(val, len);
break;
@ -664,7 +652,7 @@ out:
return 0;
}
static u_int8_t cur_config;
static uint8_t cur_config;
/* USB DFU Device descriptor in DFU mode */
__dfustruct const struct usb_device_descriptor dfu_dev_descriptor = {
@ -761,9 +749,9 @@ __dfustruct const struct _dfu_desc dfu_cfg_descriptor = {
static __dfufunc void dfu_udp_ep0_handler(void)
{
AT91PS_UDP pUDP = AT91C_BASE_UDP;
u_int8_t bmRequestType, bRequest;
u_int16_t wValue, wIndex, wLength, wStatus;
u_int32_t csr = pUDP->UDP_CSR[0];
uint8_t bmRequestType, bRequest;
uint16_t wValue, wIndex, wLength, wStatus;
uint32_t csr = pUDP->UDP_CSR[0];
DEBUGE("CSR=0x%04x ", csr);
@ -810,7 +798,7 @@ static __dfufunc void dfu_udp_ep0_handler(void)
/* Handle supported standard device request Cf Table 9-3 in USB
* speciication Rev 1.1 */
switch ((bRequest << 8) | bmRequestType) {
u_int8_t desc_type, desc_index;
uint8_t desc_type, desc_index;
case STD_GET_DESCRIPTOR:
DEBUGE("GET_DESCRIPTOR ");
desc_type = wValue >> 8;
@ -820,15 +808,13 @@ static __dfufunc void dfu_udp_ep0_handler(void)
/* Return Device Descriptor */
udp_ep0_send_data((const char *)
&dfu_dev_descriptor,
MIN(sizeof(dfu_dev_descriptor),
wLength));
sizeof(dfu_dev_descriptor), wLength);
break;
case USB_DT_CONFIG:
/* Return Configuration Descriptor */
udp_ep0_send_data((const char *)
&dfu_cfg_descriptor,
MIN(sizeof(dfu_cfg_descriptor),
wLength));
sizeof(dfu_cfg_descriptor), wLength);
break;
case USB_DT_STRING:
/* Return String Descriptor */
@ -839,14 +825,12 @@ static __dfufunc void dfu_udp_ep0_handler(void)
DEBUGE("bLength=%u, wLength=%u ",
usb_strings[desc_index]->bLength, wLength);
udp_ep0_send_data((const char *) usb_strings[desc_index],
MIN(usb_strings[desc_index]->bLength,
wLength));
usb_strings[desc_index]->bLength, wLength);
break;
case USB_DT_CS_DEVICE:
/* Return Function descriptor */
udp_ep0_send_data((const char *) &dfu_cfg_descriptor.func_dfu,
MIN(sizeof(dfu_cfg_descriptor.func_dfu),
wLength));
sizeof(dfu_cfg_descriptor.func_dfu), wLength);
break;
default:
udp_ep0_send_stall();
@ -861,8 +845,10 @@ static __dfufunc void dfu_udp_ep0_handler(void)
break;
case STD_SET_CONFIGURATION:
DEBUGE("SET_CONFIG ");
if (wValue)
if (wValue) {
DEBUGE("VALUE!=0 ");
}
cur_config = wValue;
udp_ep0_send_zlp();
pUDP->UDP_GLBSTATE =
@ -879,18 +865,20 @@ static __dfufunc void dfu_udp_ep0_handler(void)
break;
case STD_GET_CONFIGURATION:
DEBUGE("GET_CONFIG ");
udp_ep0_send_data((char *)&(cur_config),
sizeof(cur_config));
/* Table 9.4 wLength One */
udp_ep0_send_data((char *)&(cur_config), sizeof(cur_config), 1);
break;
case STD_GET_STATUS_ZERO:
DEBUGE("GET_STATUS_ZERO ");
wStatus = 0;
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
break;
case STD_GET_STATUS_INTERFACE:
DEBUGE("GET_STATUS_INTERFACE ");
wStatus = 0;
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
break;
case STD_GET_STATUS_ENDPOINT:
DEBUGE("GET_STATUS_ENDPOINT(EPidx=%u) ", wIndex&0x0f);
@ -899,14 +887,14 @@ static __dfufunc void dfu_udp_ep0_handler(void)
if ((pUDP->UDP_GLBSTATE & AT91C_UDP_CONFG) && (wIndex == 0)) {
wStatus =
(pUDP->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
udp_ep0_send_data((char *)&wStatus,
sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
} else if ((pUDP->UDP_GLBSTATE & AT91C_UDP_FADDEN)
&& (wIndex == 0)) {
wStatus =
(pUDP->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
udp_ep0_send_data((char *)&wStatus,
sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
} else
udp_ep0_send_stall();
break;
@ -1005,10 +993,8 @@ static __dfufunc void dfu_udp_irq(void)
}
/* this is only called once before DFU mode, no __dfufunc required */
static void dfu_switch(void)
static __noreturn void dfu_switch(void)
{
AT91PS_AIC pAic = AT91C_BASE_AIC;
DEBUGE("\r\nsam7dfu: switching to DFU mode\r\n");
dfu_state = DFU_STATE_appDETACH;
@ -1074,9 +1060,9 @@ void __dfufunc dfu_main(void)
}
if (switch_to_ram) {
void (*ram_app_entry)(void);
int i;
for (i = 0; i < 32; i++)
AT91F_AIC_DisableIt(AT91C_BASE_AIC, i);
int j;
for (j = 0; j < 32; j++)
AT91F_AIC_DisableIt(AT91C_BASE_AIC, j);
/* jump into RAM */
AT91F_DBGU_Printk("JUMP TO RAM\r\n");
ram_app_entry = AT91C_ISRAM + SAM7DFU_RAM_SIZE;

View File

@ -124,13 +124,13 @@ struct _dfu_desc {
struct dfuapi {
void (*udp_init)(void);
void (*ep0_send_data)(const char *data, u_int32_t len);
void (*ep0_send_data)(const char *data, uint32_t len, uint32_t wlen);
void (*ep0_send_zlp)(void);
void (*ep0_send_stall)(void);
int (*dfu_ep0_handler)(u_int8_t req_type, u_int8_t req,
u_int16_t val, u_int16_t len);
int (*dfu_ep0_handler)(uint8_t req_type, uint8_t req,
uint16_t val, uint16_t len);
void (*dfu_switch)(void);
u_int32_t *dfu_state;
uint32_t *dfu_state;
const struct usb_device_descriptor *dfu_dev_descriptor;
const struct _dfu_desc *dfu_cfg_descriptor;
};

View File

@ -28,7 +28,7 @@ struct blinker {
enum blinkcode_state state;
int num;
int cur;
u_int8_t led;
uint8_t led;
};
static struct blinker blink_state[NUM_LEDS];

View File

@ -45,18 +45,17 @@
#include <asm/system.h>
#include <compile.h>
//#define DEBUG_UNBUFFERED
/* In case we find that while (); is non interruptible, we may need to
* uncommend this line: */
// #define ALLOW_INTERRUPT_LOOP asm("nop;nop;nop;nop;nop;nop;nop;nop;")
#define ALLOW_INTERRUPT_LOOP
/* DEBUG_BUFFER_SIZE MUST BE A POWER OF 2 */
#define DEBUG_BUFFER_SIZE (1 << 10)
#define DEBUG_BUFFER_MASK (DEBUG_BUFFER_SIZE - 1)
#define USART_SYS_LEVEL 4
/*---------------------------- Global Variable ------------------------------*/
//*--------------------------1--------------------------------------------------
//* \fn AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel
//*----------------------------------------------------------------------------
void AT91F_DBGU_Ready(void)
{
while (!(AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY)) ;
}
//*----------------------------------------------------------------------------
//* Function Name : Send_reset
@ -69,7 +68,7 @@ static void Send_reset(void)
// Acknoledge the interrupt
// Mark the End of Interrupt on the AIC
AT91C_BASE_AIC->AIC_EOICR = 0;
AT91F_DBGU_Ready();
while (!(AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXEMPTY)) ;
// Jump in reset
pfct();
}
@ -79,7 +78,7 @@ static void Send_reset(void)
//* Object : C handler interrupt function called by the sysirq
//* demultiplexer
//*----------------------------------------------------------------------------
static void DBGU_irq_handler(u_int32_t sr)
static void DBGU_irq_handler(uint32_t sr)
{
static char value;
@ -92,26 +91,26 @@ static void DBGU_irq_handler(u_int32_t sr)
break;
case '1': //* info
udp_pullup_off();
AT91F_DBGU_Printk("Set Pull up\n\r");
AT91F_DBGU_Frame("Set Pull up\n\r");
// Reset Application
Send_reset();
break;
case '2':
AT91F_DBGU_Printk("Toggling LED 1\n\r");
AT91F_DBGU_Frame("Toggling LED 1\n\r");
led_toggle(1);
break;
case '3':
AT91F_DBGU_Printk("Toggling LED 2\n\r");
AT91F_DBGU_Frame("Toggling LED 2\n\r");
led_toggle(2);
break;
case '9':
AT91F_DBGU_Printk("Resetting SAM7\n\r");
AT91F_DBGU_Frame("Resetting SAM7\n\r");
AT91F_RSTSoftReset(AT91C_BASE_RSTC, AT91C_RSTC_PROCRST|
AT91C_RSTC_PERRST|AT91C_RSTC_EXTRST);
break;
default:
if (_main_dbgu(value) < 0)
AT91F_DBGU_Printk("\n\r");
AT91F_DBGU_Frame("\n\r");
break;
} // end switch
}
@ -123,6 +122,8 @@ void dbgu_rb_init(void);
//*----------------------------------------------------------------------------
void AT91F_DBGU_Init(void)
{
unsigned int rst_status = AT91F_RSTGetStatus(AT91C_BASE_RSTC);
dbgu_rb_init();
//* Open PIO for DBGU
@ -146,15 +147,17 @@ void AT91F_DBGU_Init(void)
//* open interrupt
sysirq_register(AT91SAM7_SYSIRQ_DBGU, &DBGU_irq_handler);
AT91F_DBGU_Printk("\n\r");
AT91F_DBGU_Printk("(C) 2006-2011 by Harald Welte <hwelte@hmw-consulting.de>\n\r"
debugp("\n\r");
debugp("(C) 2006-2011 by Harald Welte <hwelte@hmw-consulting.de>\n\r"
"This software is FREE SOFTWARE licensed under GNU GPL\n\r");
AT91F_DBGU_Printk("Version " COMPILE_SVNREV
debugp("Version " COMPILE_SVNREV
" compiled " COMPILE_DATE
" by " COMPILE_BY "\n\r\n\r");
AT91F_DBGU_Printk("\n\rDEBUG Interface:\n\r"
debugp("\n\rDEBUG Interface:\n\r"
"0) Set Pull-up 1) Clear Pull-up 2) Toggle LED1 3) "
"Toggle LED2\r\n9) Reset\n\r");
debugp("RSTC_SR=0x%08x\n\r", rst_status);
}
/*
@ -168,32 +171,37 @@ void AT91F_DBGU_Fini(void)
// Maybe FIXME, do more? -- Henryk Plötz <henryk@ploetzli.ch>
}
//*----------------------------------------------------------------------------
//* \fn AT91F_DBGU_Printk
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Printk(char *buffer)
{
while (*buffer != '\0') {
while (!AT91F_US_TxReady((AT91PS_USART) AT91C_BASE_DBGU)) ;
AT91F_US_PutChar((AT91PS_USART) AT91C_BASE_DBGU, *buffer++);
}
}
//*----------------------------------------------------------------------------
//* \fn AT91F_DBGU_Frame
//* \brief This function is used to send a string through the DBGU channel
//* \brief This function is used to send a string through the DBGU channel (Very low level debugging)
//*----------------------------------------------------------------------------
void AT91F_DBGU_Frame(char *buffer)
{
unsigned char len;
for (len = 0; buffer[len] != '\0'; len++) {
unsigned long intcFlags;
unsigned int len = 0;
while (buffer[len++]) ALLOW_INTERRUPT_LOOP;
len--;
local_irq_save(intcFlags);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 9; // Disable transfer
if (AT91C_BASE_DBGU->DBGU_TNCR) {
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 8; // Resume transfer
local_irq_restore(intcFlags);
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0) ALLOW_INTERRUPT_LOOP;
local_irq_save(intcFlags);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 9; // Disable transfer
AT91C_BASE_DBGU->DBGU_TPR = (unsigned)buffer;
AT91C_BASE_DBGU->DBGU_TCR = len;
} else if (AT91C_BASE_DBGU->DBGU_TCR) {
AT91C_BASE_DBGU->DBGU_TNPR = (unsigned)buffer;
AT91C_BASE_DBGU->DBGU_TNCR = len;
} else {
AT91C_BASE_DBGU->DBGU_TPR = (unsigned)buffer;
AT91C_BASE_DBGU->DBGU_TCR = len;
}
AT91F_US_SendFrame((AT91PS_USART) AT91C_BASE_DBGU,
(unsigned char *)buffer, len, 0, 0);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 8; // Resume transfer
local_irq_restore(intcFlags);
/* Return ONLY after we complete Transfer */
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0) ALLOW_INTERRUPT_LOOP;
}
//*----------------------------------------------------------------------------
@ -235,105 +243,180 @@ hexdump(const void *data, unsigned int len)
}
struct dbgu {
char buf[4096];
char *next_inbyte;
char *next_outbyte;
char buf[DEBUG_BUFFER_SIZE];
/* Since debugp appears to require to be re-entrant, we need a
* bit more state variables
* in_head Position where incoming *append* characters have
* finished copy to buffer
* in_tail Position where NEW incoming *append* characters
* should COPY to
* out_head Position where the LAST *possibly incomplete*
* dbgu_rb_flush started from
* out_tail Position where the NEXT dbug_rb_flush should
* start from
* The position in the RING should be in this order:
* --> out_tail --> in_head --> in_tail --> out_head -->
*/
volatile unsigned int in_head, in_tail, out_head, out_tail;
/* flush_stack is to indicate rb_flush is being executed, NOT to
* execute again */
volatile unsigned int flush_stack;
/* append_stack is to indicate the re-entrack stack order of the
* current dbgu_append call */
volatile unsigned int append_stack;
};
static struct dbgu dbgu;
void dbgu_rb_init(void)
{
memset(dbgu.buf, 0, sizeof(dbgu.buf));
dbgu.next_inbyte = &dbgu.buf[0];
dbgu.next_outbyte = &dbgu.buf[0];
}
/* pull one char out of debug ring buffer */
static int dbgu_rb_pull(char *ret)
{
unsigned long flags;
local_irq_save(flags);
if (dbgu.next_outbyte == dbgu.next_inbyte) {
local_irq_restore(flags);
return -1;
}
*ret = *dbgu.next_outbyte;
dbgu.next_outbyte++;
if (dbgu.next_outbyte == &dbgu.buf[0]+sizeof(dbgu.buf)) {
//AT91F_DBGU_Printk("WRAP DURING PULL\r\n");
dbgu.next_outbyte = &dbgu.buf[0];
} else if (dbgu.next_outbyte > &dbgu.buf[0]+sizeof(dbgu.buf)) {
//AT91F_DBGU_Printk("OUTBYTE > END_OF_BUF!!\r\n");
dbgu.next_outbyte -= sizeof(dbgu.buf);
}
local_irq_restore(flags);
return 0;
}
static void __rb_flush(void)
{
char ch;
while (dbgu_rb_pull(&ch) >= 0) {
while (!AT91F_US_TxReady((AT91PS_USART) AT91C_BASE_DBGU)) ;
AT91F_US_PutChar((AT91PS_USART) AT91C_BASE_DBGU, ch);
}
dbgu.in_head = dbgu.in_tail = dbgu.out_head = dbgu.out_tail = 0;
dbgu.flush_stack = dbgu.append_stack = 0;
}
/* flush pending data from debug ring buffer to serial port */
void dbgu_rb_flush(void)
{
__rb_flush();
}
static void __dbgu_rb_append(char *data, int len)
static void dbgu_rb_flush(void)
{
char *pos = dbgu.next_inbyte;
unsigned long intcFlags;
unsigned int flush_stack, start, len;
if (dbgu.in_head == dbgu.out_tail)
return;
dbgu.next_inbyte += len;
if (dbgu.next_inbyte >= &dbgu.buf[0]+sizeof(dbgu.buf)) {
AT91F_DBGU_Printk("WRAP DURING APPEND\r\n");
dbgu.next_inbyte -= sizeof(dbgu.buf);
/* Transmit can ONLY be disabled when Interrupt is disabled. We
* don't want to be interrupted while Transmit is disabled. */
local_irq_save(intcFlags);
flush_stack = dbgu.flush_stack;
dbgu.flush_stack = 1;
if (flush_stack) {
local_irq_restore(intcFlags);
return;
}
memcpy(pos, data, len);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 9; // Disable transfer
start = (unsigned)dbgu.buf + dbgu.out_tail;
len = (dbgu.in_head - dbgu.out_tail) & DEBUG_BUFFER_MASK;
if (dbgu.in_head > dbgu.out_tail || dbgu.in_head == 0) { // Just 1 fragmentf
if (AT91C_BASE_DBGU->DBGU_TNCR) {
if (AT91C_BASE_DBGU->DBGU_TNPR + AT91C_BASE_DBGU->DBGU_TNCR == start) {
AT91C_BASE_DBGU->DBGU_TNCR += len;
} else {
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 8; // Resume transfer
local_irq_restore(intcFlags);
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0) ALLOW_INTERRUPT_LOOP;
dbgu.out_head = dbgu.out_tail; // in case we are interrupted, they may need more space
/* Since the ONLY place where Transmit is started is dbgu_rb_flush and AT91F_DBGU_Frame and:
* 1) AT91F_DBGU_Frame always leave the dbgu in a TX completed state
* 2) dbgu_rb is non-reentrant by safeguard at the beginning of this routing
* We can assume that after this INTERRUPTIBLE while loop, there are NO data to be transmitted
*/
local_irq_save(intcFlags);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 9; // Disable transfer
AT91C_BASE_DBGU->DBGU_TPR = start;
AT91C_BASE_DBGU->DBGU_TCR = len;
}
} else if (AT91C_BASE_DBGU->DBGU_TCR) {
if (AT91C_BASE_DBGU->DBGU_TPR + AT91C_BASE_DBGU->DBGU_TCR == start) {
dbgu.out_head = AT91C_BASE_DBGU->DBGU_TPR - (unsigned)dbgu.buf;
AT91C_BASE_DBGU->DBGU_TCR += len;
} else {
AT91C_BASE_DBGU->DBGU_TNPR = start;
AT91C_BASE_DBGU->DBGU_TNCR = len;
}
} else {
AT91C_BASE_DBGU->DBGU_TPR = start;
AT91C_BASE_DBGU->DBGU_TCR = len;
dbgu.out_head = dbgu.out_tail;
}
} else { // 2 fragments
if ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0) {
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 8; // Resume transfer
local_irq_restore(intcFlags);
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0) ALLOW_INTERRUPT_LOOP;
dbgu.out_head = dbgu.out_tail; // in case we are interrupted, they may need more space
local_irq_save(intcFlags);
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 9; // Disable transfer
}
AT91C_BASE_DBGU->DBGU_TPR = start;
AT91C_BASE_DBGU->DBGU_TCR = DEBUG_BUFFER_SIZE - dbgu.out_tail;
AT91C_BASE_DBGU->DBGU_TNPR = (unsigned)dbgu.buf;
AT91C_BASE_DBGU->DBGU_TNCR = dbgu.in_head;
dbgu.out_head = dbgu.out_tail;
}
AT91C_BASE_DBGU->DBGU_PTCR = 1 << 8; // Resume transfer
dbgu.out_tail = dbgu.in_head;
dbgu.flush_stack = 0;
local_irq_restore(intcFlags);
}
void dbgu_rb_append(char *data, int len)
{
unsigned long flags;
int bytes_left;
char *data_cur;
/* Rules:
* 1) ONLY the LOWEST order of dbgu_rb_append CAN update in_head;
* 2) WHEN updateing in_head, always set it to the current in_tail (since all higher order dbgu_rb_append have completed
* 3) ONLY the LOWEST order of dbgu_rb_append MAY call dbgu_rb_flush
*/
unsigned long intcFlags;
unsigned int append_stack, avail, local_head;
if (len <= 0)
return;
local_irq_save(flags);
bytes_left = &dbgu.buf[0]+sizeof(dbgu.buf)-dbgu.next_inbyte;
data_cur = data;
if (len > bytes_left) {
AT91F_DBGU_Printk("LEN > BYTES_LEFT\r\n");
__rb_flush();
__dbgu_rb_append(data_cur, bytes_left);
len -= bytes_left;
data_cur += bytes_left;
local_irq_save(intcFlags);
append_stack = dbgu.append_stack++;
if (AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE)
dbgu.out_head = dbgu.out_tail;
avail = (dbgu.out_head - 1 - dbgu.in_tail) & DEBUG_BUFFER_MASK;
local_head = (unsigned)len;
if (local_head > avail) {
local_irq_restore(intcFlags);
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0);
local_irq_save(intcFlags);
while ((AT91C_BASE_DBGU->DBGU_CSR & AT91C_US_TXBUFE) == 0);
dbgu.out_head = dbgu.out_tail;
avail = (dbgu.out_head - 1 - dbgu.in_tail) & DEBUG_BUFFER_MASK;
if (local_head > avail) {
local_head -= avail;
AT91C_BASE_DBGU->DBGU_TPR = (unsigned)data;
AT91C_BASE_DBGU->DBGU_TCR = local_head;
data += local_head;
len = avail;
}
}
__dbgu_rb_append(data_cur, len);
local_irq_restore(flags);
local_head = dbgu.in_tail;
dbgu.in_tail += len;
dbgu.in_tail &= DEBUG_BUFFER_MASK;
local_irq_restore(intcFlags);
if (dbgu.out_head <= local_head) {
// We may have to wrap around: out_head won't change because NO call to flush will be made YET
avail = DEBUG_BUFFER_SIZE - local_head;
if (avail >= (unsigned)len) {
memcpy(dbgu.buf + local_head, data, (size_t)len);
} else {
memcpy(dbgu.buf + local_head, data, (size_t)avail);
memcpy(dbgu.buf, data + avail, (size_t)(len - avail));
}
} else {
memcpy(dbgu.buf + local_head, data, len);
}
local_irq_save(intcFlags);
dbgu.append_stack--;
if (!append_stack)
dbgu.in_head = dbgu.in_tail;
local_irq_restore(intcFlags);
if (!append_stack)
dbgu_rb_flush();
}
static char dbg_buf[256];
static int line_num = 0;
void debugp(const char *format, ...)
{
va_list ap;
va_start(ap, format);
vsnprintf(dbg_buf, sizeof(dbg_buf)-1, format, ap);
sprintf(dbg_buf, "[%06X] ", line_num++);
vsnprintf(dbg_buf + 9, sizeof(dbg_buf)-10, format, ap);
va_end(ap);
dbg_buf[sizeof(dbg_buf)-1] = '\0';

View File

@ -17,17 +17,14 @@
#define AT91C_DBGU_BAUD 115200
//#define DEBUGP(x) AT91F_DBGU_Printk(x)
//* ----------------------- External Function Prototype -----------------------
extern const char *hexdump(const void *data, unsigned int len);
void AT91F_DBGU_Init(void);
void AT91F_DBGU_Fini(void);
void AT91F_DBGU_Printk( char *buffer);
void AT91F_DBGU_Frame( char *buffer);
void AT91F_DBGU_Frame(char *buffer);
#define AT91F_DBGU_Printk(x) AT91F_DBGU_Frame(x)
int AT91F_DBGU_Get( char *val);
void dbgu_rb_flush(void);
#ifndef __WinARM__
void AT91F_DBGU_scanf(char * type,unsigned int * val);
#endif

View File

@ -58,7 +58,7 @@ void fifo_check_raise_int(struct fifo *fifo)
}
u_int16_t fifo_data_put(struct fifo *fifo, u_int16_t len, u_int8_t *data)
uint16_t fifo_data_put(struct fifo *fifo, uint16_t len, uint8_t *data)
{
if (len > fifo_available(fifo)) {
len = fifo_available(fifo);
@ -71,7 +71,7 @@ u_int16_t fifo_data_put(struct fifo *fifo, u_int16_t len, u_int8_t *data)
fifo->producer += len;
} else {
/* difficult: wrap around */
u_int16_t chunk_len;
uint16_t chunk_len;
chunk_len = fifo->size - fifo->producer;
memcpy(&fifo->data[fifo->producer], data, chunk_len);
@ -86,9 +86,9 @@ u_int16_t fifo_data_put(struct fifo *fifo, u_int16_t len, u_int8_t *data)
}
u_int16_t fifo_data_get(struct fifo *fifo, u_int16_t len, u_int8_t *data)
uint16_t fifo_data_get(struct fifo *fifo, uint16_t len, uint8_t *data)
{
u_int16_t avail = fifo_available(fifo);
uint16_t avail = fifo_available(fifo);
if (avail < len)
len = avail;
@ -98,7 +98,7 @@ u_int16_t fifo_data_get(struct fifo *fifo, u_int16_t len, u_int8_t *data)
memcpy(data, &fifo->data[fifo->consumer], len);
} else {
/* difficult case: wrap */
u_int16_t chunk_len = fifo->size - fifo->consumer;
uint16_t chunk_len = fifo->size - fifo->consumer;
memcpy(data, &fifo->data[fifo->consumer], chunk_len);
memcpy(data+chunk_len, &fifo->data[0], len - chunk_len);
}
@ -108,8 +108,8 @@ u_int16_t fifo_data_get(struct fifo *fifo, u_int16_t len, u_int8_t *data)
return len;
}
int fifo_init(struct fifo *fifo, u_int16_t size,
void (*cb)(struct fifo *fifo, u_int8_t event, void *data), void *cb_data)
int fifo_init(struct fifo *fifo, uint16_t size,
void (*cb)(struct fifo *fifo, uint8_t event, void *data), void *cb_data)
{
if (size > sizeof(fifo->data))
return -EINVAL;

View File

@ -6,23 +6,23 @@
#define FIFO_SIZE 1024
struct fifo {
u_int16_t size; /* actual FIFO size, can be smaller than 'data' */
u_int16_t producer; /* index of producer */
u_int16_t consumer; /* index of consumer */
u_int16_t watermark;
u_int8_t irq;
u_int8_t irq_en;
u_int8_t status;
void (*callback)(struct fifo *fifo, u_int8_t event, void *data);
uint16_t size; /* actual FIFO size, can be smaller than 'data' */
uint16_t producer; /* index of producer */
uint16_t consumer; /* index of consumer */
uint16_t watermark;
uint8_t irq;
uint8_t irq_en;
uint8_t status;
void (*callback)(struct fifo *fifo, uint8_t event, void *data);
void *cb_data;
u_int8_t data[FIFO_SIZE];
uint8_t data[FIFO_SIZE];
};
extern int fifo_init(struct fifo *fifo, u_int16_t size,
void (*callback)(struct fifo *fifo, u_int8_t event, void *data), void *cb_data);
extern u_int16_t fifo_data_get(struct fifo *fifo, u_int16_t len, u_int8_t *data);
extern u_int16_t fifo_data_put(struct fifo *fifo, u_int16_t len, u_int8_t *data);
extern int fifo_init(struct fifo *fifo, uint16_t size,
void (*callback)(struct fifo *fifo, uint8_t event, void *data), void *cb_data);
extern uint16_t fifo_data_get(struct fifo *fifo, uint16_t len, uint8_t *data);
extern uint16_t fifo_data_put(struct fifo *fifo, uint16_t len, uint8_t *data);
extern int fifo_available(struct fifo *fifo);
#endif

View File

@ -13,34 +13,34 @@
#define EFCS_CMD_CLEAR_NVM_BIT 0xd
#define EFCS_CMD_SET_SECURITY_BIT 0xf
static u_int16_t page_from_ramaddr(const void *addr)
static uint16_t page_from_ramaddr(const void *addr)
{
u_int32_t ramaddr = (u_int32_t) addr;
ramaddr -= (u_int32_t) AT91C_IFLASH;
uint32_t ramaddr = (uint32_t) addr;
ramaddr -= (uint32_t) AT91C_IFLASH;
return ((ramaddr >> AT91C_IFLASH_PAGE_SHIFT));
}
#define PAGES_PER_LOCKREGION (AT91C_IFLASH_LOCK_REGION_SIZE>>AT91C_IFLASH_PAGE_SHIFT)
#define IS_FIRST_PAGE_OF_LOCKREGION(x) ((x % PAGES_PER_LOCKREGION) == 0)
#define LOCKREGION_FROM_PAGE(x) (x / PAGES_PER_LOCKREGION)
static int is_page_locked(u_int16_t page)
static int is_page_locked(uint16_t page)
{
u_int16_t lockregion = LOCKREGION_FROM_PAGE(page);
uint16_t lockregion = LOCKREGION_FROM_PAGE(page);
return (AT91C_BASE_MC->MC_FSR & (lockregion << 16));
}
static void unlock_page(u_int16_t page)
static void unlock_page(uint16_t page)
{
page &= 0x3ff;
AT91F_MC_EFC_PerformCmd(AT91C_BASE_MC, AT91C_MC_FCMD_UNLOCK |
AT91C_MC_CORRECT_KEY | (page << 8));
}
void flash_page(u_int8_t *addr)
void flash_page(uint8_t *addr)
{
u_int16_t page = page_from_ramaddr(addr) & 0x3ff;
u_int32_t fsr = AT91F_MC_EFC_GetStatus(AT91C_BASE_MC);
uint16_t page = page_from_ramaddr(addr) & 0x3ff;
uint32_t fsr = AT91F_MC_EFC_GetStatus(AT91C_BASE_MC);
DEBUGP("flash_page(0x%x=%u) ", addr, page);
if (is_page_locked(page)) {

View File

@ -1,5 +1,5 @@
#ifndef _FLASH_H
#define _FLASH_H
extern void flash_page(u_int8_t *addr);
extern void flash_page(uint8_t *addr);
extern void flash_init(void);
#endif

View File

@ -77,7 +77,6 @@ int main(void)
while (1) {
/* Call application specific main idle function */
_main_func();
dbgu_rb_flush();
/* restart watchdog timer */
wdt_restart();

View File

@ -94,13 +94,15 @@ static const struct dfuapi *dfu = DFU_API_LOCATION;
static struct udp_pcd upcd;
struct epstate {
u_int32_t state_busy;
u_int32_t state_pending;
uint32_t state_busy;
uint32_t state_pending;
};
static const struct epstate epstate[] = {
[0] = { .state_busy = RCTX_STATE_INVALID },
[1] = { .state_busy = RCTX_STATE_INVALID },
[0] = { .state_busy = RCTX_STATE_UDP_EP0_BUSY,
.state_pending = RCTX_STATE_UDP_EP0_PENDING },
[1] = { .state_busy = RCTX_STATE_UDP_EP1_BUSY,
.state_pending = RCTX_STATE_UDP_EP1_PENDING },
[2] = { .state_busy = RCTX_STATE_UDP_EP2_BUSY,
.state_pending = RCTX_STATE_UDP_EP2_PENDING },
[3] = { .state_busy = RCTX_STATE_UDP_EP3_BUSY,
@ -112,8 +114,6 @@ static void reset_ep(unsigned int ep)
AT91PS_UDP pUDP = upcd.pUdp;
struct req_ctx *rctx;
//pUDP->UDP_CSR[ep] = AT91C_UDP_EPEDS;
atomic_set(&upcd.ep[ep].pkts_in_transit, 0);
/* free all currently transmitting contexts */
@ -125,6 +125,7 @@ static void reset_ep(unsigned int ep)
pUDP->UDP_RSTEP |= (1 << ep);
pUDP->UDP_RSTEP &= ~(1 << ep);
pUDP->UDP_CSR[ep] = AT91C_UDP_EPEDS;
upcd.ep[ep].incomplete.rctx = NULL;
}
@ -137,9 +138,9 @@ void udp_unthrottle(void)
pUDP->UDP_IER = AT91C_UDP_EPINT1;
}
static int __udp_refill_ep(int ep)
int udp_refill_ep(int ep)
{
u_int16_t i;
uint16_t i;
AT91PS_UDP pUDP = upcd.pUdp;
struct req_ctx *rctx;
unsigned int start, end;
@ -152,9 +153,11 @@ static int __udp_refill_ep(int ep)
/* If there are already two packets in transit, the DPR of
* the SAM7 UDC doesn't have space for more data */
if (atomic_read(&upcd.ep[ep].pkts_in_transit) == 2) {
if (atomic_read(&upcd.ep[ep].pkts_in_transit) == 2)
return -EBUSY;
}
/* disable endpoint interrup */
pUDP->UDP_IDR |= 1 << ep;
/* If we have an incompletely-transmitted req_ctx (>EP size),
* we need to transmit the rest and finish the transaction */
@ -165,8 +168,23 @@ static int __udp_refill_ep(int ep)
/* get pending rctx and start transmitting from zero */
rctx = req_ctx_find_get(0, epstate[ep].state_pending,
epstate[ep].state_busy);
if (!rctx)
if (!rctx) {
/* re-enable endpoint interrupt */
pUDP->UDP_IER |= 1 << ep;
return 0;
}
if (rctx->tot_len == 0) {
/* re-enable endpoint interrupt */
pUDP->UDP_IER |= 1 << ep;
req_ctx_put(rctx);
return 0;
}
DEBUGPCR("USBT(D=%08X, L=%04u, P=$02u) H4/T4: %02X %02X %02X %02X / %02X %02X %02X %02X",
rctx->data, rctx->tot_len, req_ctx_count(epstate[ep].state_pending),
rctx->data[4], rctx->data[5], rctx->data[6], rctx->data[7],
rctx->data[rctx->tot_len - 4], rctx->data[rctx->tot_len - 3],
rctx->data[rctx->tot_len - 2], rctx->data[rctx->tot_len - 1]);
start = 0;
upcd.ep[ep].incomplete.bytes_sent = 0;
@ -178,8 +196,6 @@ static int __udp_refill_ep(int ep)
end = start + AT91C_EP_IN_SIZE;
/* fill FIFO/DPR */
DEBUGII("RCTX_tx(ep=%u,ctx=%u):%u ", ep, req_ctx_num(rctx),
end - start);
for (i = start; i < end; i++)
pUDP->UDP_FDR[ep] = rctx->data[i];
@ -188,15 +204,13 @@ static int __udp_refill_ep(int ep)
pUDP->UDP_CSR[ep] |= AT91C_UDP_TXPKTRDY;
}
if ((end - start < AT91C_EP_OUT_SIZE) ||
(((end - start) == 0) && end && (rctx->tot_len % AT91C_EP_OUT_SIZE) == 0)) {
if (end == rctx->tot_len) {
/* CASE 1: return context to pool, if
* - packet transfer < AT91C_EP_OUT_SIZE
* - after ZLP of transfer == AT91C_EP_OUT_SIZE
* - after ZLP of transfer % AT91C_EP_OUT_SIZE == 0
* - after last packet of transfer % AT91C_EP_OUT_SIZE != 0
*/
DEBUGII("RCTX(ep=%u,ctx=%u)_tx_done ", ep, req_ctx_num(rctx));
upcd.ep[ep].incomplete.rctx = NULL;
req_ctx_put(rctx);
} else {
@ -204,30 +218,20 @@ static int __udp_refill_ep(int ep)
* - after data of transfer == AT91C_EP_OUT_SIZE
* - after data of transfer > AT91C_EP_OUT_SIZE
* - after last packet of transfer % AT91C_EP_OUT_SIZE == 0
*/
*/
upcd.ep[ep].incomplete.rctx = rctx;
upcd.ep[ep].incomplete.bytes_sent += end - start;
DEBUGII("RCTX(ep=%u)_tx_cont ", ep);
}
/* re-enable endpoint interrupt */
pUDP->UDP_IER |= 1 << ep;
return 1;
}
int udp_refill_ep(int ep)
{
unsigned long flags;
int ret;
local_irq_save(flags);
ret = __udp_refill_ep(ep);
local_irq_restore(flags);
return ret;
}
static void udp_irq(void)
{
u_int32_t csr;
uint32_t csr;
AT91PS_UDP pUDP = upcd.pUdp;
AT91_REG isr = pUDP->UDP_ISR;
@ -238,19 +242,18 @@ static void udp_irq(void)
DEBUGI("ENDBUSRES ");
pUDP->UDP_ICR = AT91C_UDP_ENDBUSRES;
pUDP->UDP_IER = AT91C_UDP_EPINT0;
/* reset all endpoints */
pUDP->UDP_RSTEP = (unsigned int)-1;
pUDP->UDP_RSTEP = 0;
reset_ep(0);
reset_ep(1);
reset_ep(2);
reset_ep(3);
/* Enable the function */
pUDP->UDP_FADDR = AT91C_UDP_FEN;
/* Configure endpoint 0 */
pUDP->UDP_CSR[0] = (AT91C_UDP_EPEDS | AT91C_UDP_EPTYPE_CTRL);
upcd.cur_config = 0;
upcd.state = USB_STATE_DEFAULT;
reset_ep(1);
reset_ep(2);
reset_ep(3);
#ifdef CONFIG_DFU
if (*dfu->dfu_state == DFU_STATE_appDETACH) {
@ -267,8 +270,8 @@ static void udp_irq(void)
udp_ep0_handler();
}
if (isr & AT91C_UDP_EPINT1) {
u_int32_t cur_rcv_bank = upcd.cur_rcv_bank;
u_int16_t i, pkt_size;
uint32_t cur_rcv_bank = upcd.cur_rcv_bank;
uint16_t i, pkt_size;
struct req_ctx *rctx;
csr = pUDP->UDP_CSR[1];
@ -359,7 +362,7 @@ cont_ep2:
if (atomic_dec_return(&upcd.ep[2].pkts_in_transit) == 1)
pUDP->UDP_CSR[2] |= AT91C_UDP_TXPKTRDY;
__udp_refill_ep(2);
udp_refill_ep(2);
}
}
if (isr & AT91C_UDP_EPINT3) {
@ -374,7 +377,7 @@ cont_ep2:
if (atomic_dec_return(&upcd.ep[3].pkts_in_transit) == 1)
pUDP->UDP_CSR[3] |= AT91C_UDP_TXPKTRDY;
__udp_refill_ep(3);
udp_refill_ep(3);
}
}
if (isr & AT91C_UDP_RXSUSP) {
@ -468,9 +471,9 @@ void udp_reset(void)
static void udp_ep0_handler(void)
{
AT91PS_UDP pUDP = upcd.pUdp;
u_int8_t bmRequestType, bRequest;
u_int16_t wValue, wIndex, wLength, wStatus;
u_int32_t csr = pUDP->UDP_CSR[0];
uint8_t bmRequestType, bRequest;
uint16_t wValue, wIndex, wLength, wStatus;
uint32_t csr = pUDP->UDP_CSR[0];
DEBUGE("CSR=0x%04x ", csr);
@ -518,7 +521,7 @@ static void udp_ep0_handler(void)
/* Handle supported standard device request Cf Table 9-3 in USB
* speciication Rev 1.1 */
switch ((bRequest << 8) | bmRequestType) {
u_int8_t desc_type, desc_index;
uint8_t desc_type, desc_index;
case STD_GET_DESCRIPTOR:
DEBUGE("GET_DESCRIPTOR(wValue=0x%04x, wIndex=0x%04x) ",
wValue, wIndex);
@ -531,12 +534,12 @@ static void udp_ep0_handler(void)
if (*dfu->dfu_state != DFU_STATE_appIDLE)
udp_ep0_send_data((const char *)
dfu->dfu_dev_descriptor,
MIN(dfu->dfu_dev_descriptor->bLength,
wLength));
dfu->dfu_dev_descriptor->bLength,
wLength);
else
#endif
udp_ep0_send_data((const char *) &dev_descriptor,
MIN(sizeof(dev_descriptor), wLength));
sizeof(dev_descriptor), wLength);
break;
case USB_DT_CONFIG:
/* Return Configuration Descriptor */
@ -544,12 +547,12 @@ static void udp_ep0_handler(void)
if (*dfu->dfu_state != DFU_STATE_appIDLE)
udp_ep0_send_data((const char *)
dfu->dfu_cfg_descriptor,
MIN(dfu->dfu_cfg_descriptor->ucfg.wTotalLength,
wLength));
dfu->dfu_cfg_descriptor->ucfg.wTotalLength,
wLength);
else
#endif
udp_ep0_send_data((const char *) &cfg_descriptor,
MIN(sizeof(cfg_descriptor), wLength));
sizeof(cfg_descriptor), wLength);
break;
case USB_DT_STRING:
#ifdef CONFIG_USB_STRING
@ -559,8 +562,8 @@ static void udp_ep0_handler(void)
DEBUGE("bLength=%u, wLength=%u\n",
usb_strings[desc_index]->bLength, wLength);
udp_ep0_send_data((const char *) usb_strings[desc_index],
MIN(usb_strings[desc_index]->bLength,
wLength));
usb_strings[desc_index]->bLength,
wLength);
#else
goto out_stall;
#endif
@ -568,7 +571,7 @@ static void udp_ep0_handler(void)
case USB_DT_CS_DEVICE:
/* Return Function descriptor */
udp_ep0_send_data((const char *) &dfu->dfu_cfg_descriptor->func_dfu,
MIN(sizeof(dfu->dfu_cfg_descriptor->func_dfu), wLength));
sizeof(dfu->dfu_cfg_descriptor->func_dfu), wLength);
break;
case USB_DT_INTERFACE:
/* Return Interface descriptor */
@ -578,21 +581,27 @@ static void udp_ep0_handler(void)
case 0:
udp_ep0_send_data((const char *)
&cfg_descriptor.uif,
MIN(sizeof(cfg_descriptor.uif),
wLength));
sizeof(cfg_descriptor.uif),
wLength);
break;
#ifdef CONFIG_DFU
case 1:
udp_ep0_send_data((const char *)
&cfg_descriptor.uif_dfu[0],
MIN(sizeof(cfg_descriptor.uif_dfu[0]),
wLength));
sizeof(cfg_descriptor.uif_dfu[0]),
wLength);
break;
case 2:
udp_ep0_send_data((const char *)
&cfg_descriptor.uif_dfu[1],
MIN(sizeof(cfg_descriptor.uif_dfu[1]),
wLength));
sizeof(cfg_descriptor.uif_dfu[1]),
wLength);
break;
case 3:
udp_ep0_send_data((const char *)
&cfg_descriptor.uif_dfu[2],
sizeof(cfg_descriptor.uif_dfu[2]),
wLength);
break;
#endif
default:
@ -673,8 +682,9 @@ static void udp_ep0_handler(void)
switch (upcd.state) {
case USB_STATE_ADDRESS:
case USB_STATE_CONFIGURED:
/* Table 9.4 wLength One */
udp_ep0_send_data((char *)&(upcd.cur_config),
sizeof(upcd.cur_config));
sizeof(upcd.cur_config), 1);
break;
default:
goto out_stall;
@ -685,13 +695,15 @@ static void udp_ep0_handler(void)
DEBUGE("GET_INTERFACE ");
if (upcd.state != USB_STATE_CONFIGURED)
goto out_stall;
/* Table 9.4 wLength One */
udp_ep0_send_data((char *)&(upcd.cur_altsett),
sizeof(upcd.cur_altsett));
sizeof(upcd.cur_altsett), 1);
break;
case STD_GET_STATUS_ZERO:
DEBUGE("GET_STATUS_ZERO ");
wStatus = 0;
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
break;
case STD_GET_STATUS_INTERFACE:
DEBUGE("GET_STATUS_INTERFACE ");
@ -699,7 +711,8 @@ static void udp_ep0_handler(void)
(upcd.state == USB_STATE_ADDRESS && wIndex != 0))
goto out_stall;
wStatus = 0;
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
break;
case STD_GET_STATUS_ENDPOINT:
DEBUGE("GET_STATUS_ENDPOINT(EPidx=%u) ", wIndex&0x0f);
@ -711,14 +724,14 @@ static void udp_ep0_handler(void)
if ((pUDP->UDP_GLBSTATE & AT91C_UDP_CONFG) && (wIndex <= 3)) {
wStatus =
(pUDP->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
udp_ep0_send_data((char *)&wStatus,
sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
} else if ((pUDP->UDP_GLBSTATE & AT91C_UDP_FADDEN)
&& (wIndex == 0)) {
wStatus =
(pUDP->UDP_CSR[wIndex] & AT91C_UDP_EPEDS) ? 0 : 1;
udp_ep0_send_data((char *)&wStatus,
sizeof(wStatus));
/* Table 9.4 wLength Two */
udp_ep0_send_data((char *)&wStatus, sizeof(wStatus), 2);
} else
goto out_stall;
break;

View File

@ -27,20 +27,20 @@
struct pioirq_state {
irq_handler_t *handlers[NR_PIO];
u_int32_t usbmask;
u_int32_t usb_throttled; /* atomic? */
uint32_t usbmask;
uint32_t usb_throttled; /* atomic? */
};
static struct pioirq_state pirqs;
/* low-level handler, used by Cstartup_app.S PIOA fast forcing and
* by regular interrupt handler below */
void __ramfunc __pio_irq_demux(u_int32_t pio)
void __ramfunc __pio_irq_demux(uint32_t pio)
{
u_int8_t send_usb = 0;
uint8_t send_usb = 0;
int i;
DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio);
//DEBUGPCRF("PIO_ISR_STATUS = 0x%08x", pio);
for (i = 0; i < NR_PIO; i++) {
if (pio & (1 << i) && pirqs.handlers[i])
@ -59,15 +59,15 @@ void __ramfunc __pio_irq_demux(u_int32_t pio)
pirqs.usb_throttled = 1;
} else {
struct openpcd_hdr *opcdh;
u_int32_t *regmask;
uint32_t *regmask;
opcdh = (struct openpcd_hdr *) irq_rctx->data;
regmask = (u_int32_t *) (irq_rctx->data + sizeof(*opcdh));
regmask = (uint32_t *) (irq_rctx->data + sizeof(*opcdh));
opcdh->cmd = OPENPCD_CMD_PIO_IRQ;
opcdh->reg = 0x00;
opcdh->flags = 0x00;
opcdh->val = 0x00;
irq_rctx->tot_len = sizeof(*opcdh) + sizeof(u_int32_t);
irq_rctx->tot_len = sizeof(*opcdh) + sizeof(uint32_t);
req_ctx_set_state(irq_rctx, RCTX_STATE_UDP_EP3_PENDING);
}
}
@ -78,23 +78,23 @@ void __ramfunc __pio_irq_demux(u_int32_t pio)
/* regular interrupt handler, in case fast forcing for PIOA disabled */
static void pio_irq_demux(void)
{
u_int32_t pio = AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA);
uint32_t pio = AT91F_PIO_GetInterruptStatus(AT91C_BASE_PIOA);
__pio_irq_demux(pio);
}
void pio_irq_enable(u_int32_t pio)
void pio_irq_enable(uint32_t pio)
{
AT91F_PIO_InterruptEnable(AT91C_BASE_PIOA, pio);
}
void pio_irq_disable(u_int32_t pio)
void pio_irq_disable(uint32_t pio)
{
AT91F_PIO_InterruptDisable(AT91C_BASE_PIOA, pio);
}
int pio_irq_register(u_int32_t pio, irq_handler_t *handler)
int pio_irq_register(uint32_t pio, irq_handler_t *handler)
{
u_int8_t num = ffs(pio);
uint8_t num = ffs(pio);
if (num == 0)
return -EINVAL;
@ -111,9 +111,9 @@ int pio_irq_register(u_int32_t pio, irq_handler_t *handler)
return 0;
}
void pio_irq_unregister(u_int32_t pio)
void pio_irq_unregister(uint32_t pio)
{
u_int8_t num = ffs(pio);
uint8_t num = ffs(pio);
if (num == 0)
return;

View File

@ -2,12 +2,12 @@
#define _PIO_IRQ_H
#define NR_PIO 32
typedef void irq_handler_t(u_int32_t pio);
typedef void irq_handler_t(uint32_t pio);
extern void pio_irq_enable(u_int32_t pio);
extern void pio_irq_disable(u_int32_t pio);
extern int pio_irq_register(u_int32_t pio, irq_handler_t *func);
extern void pio_irq_unregister(u_int32_t pio);
extern void pio_irq_enable(uint32_t pio);
extern void pio_irq_disable(uint32_t pio);
extern int pio_irq_register(uint32_t pio, irq_handler_t *func);
extern void pio_irq_unregister(uint32_t pio);
extern void pio_irq_init(void);
#endif

View File

@ -103,7 +103,7 @@ void timer_add(struct timer_list *tl)
local_irq_restore(flags);
}
static void pit_irq(u_int32_t sr)
static void pit_irq(uint32_t sr)
{
struct timer_list *tl, *next;
@ -125,21 +125,21 @@ static void pit_irq(u_int32_t sr)
}
}
void pit_mdelay(u_int32_t ms)
void pit_mdelay(uint32_t ms)
{
u_int32_t end;
uint32_t end;
end = (AT91F_PITGetPIIR(AT91C_BASE_PITC) + ms) % 20;
while (end < AT91F_PITGetPIIR(AT91C_BASE_PITC)) { }
}
void mdelay(u_int32_t ms)
void mdelay(uint32_t ms)
{
return pit_mdelay(ms);
}
void usleep(u_int32_t us)
void usleep(uint32_t us)
{
return;
return pit_mdelay(us/1000);

View File

@ -20,6 +20,6 @@ extern void timer_add(struct timer_list *timer);
extern int timer_del(struct timer_list *timer);
extern void pit_init(void);
extern void pit_mdelay(u_int32_t ms);
extern void pit_mdelay(uint32_t ms);
#endif

View File

@ -42,7 +42,7 @@
static AT91PS_PWMC pwm = AT91C_BASE_PWMC;
/* find highest bit set. returns bit (32..1) or 0 in case no bit set */
static int fhs(u_int32_t val)
static int fhs(uint32_t val)
{
int i;
@ -55,16 +55,16 @@ static int fhs(u_int32_t val)
}
/* set frequency of PWM signal to freq */
int pwm_freq_set(int channel, u_int32_t freq)
int pwm_freq_set(int channel, uint32_t freq)
{
/* in order to get maximum resolution, the pre-scaler must be set to
* something like freq << 16. However, the mimimum pre-scaled frequency
* we can get is MCLK (48MHz), the minimum is MCLK/(1024*255) =
* 48MHz/261120 = 183Hz */
u_int32_t overall_div;
u_int32_t presc_total;
u_int8_t cpre = 0;
u_int16_t cprd;
uint32_t overall_div;
uint32_t presc_total;
uint8_t cpre = 0;
uint16_t cprd;
if (freq > MCLK)
return -ERANGE;
@ -104,9 +104,9 @@ void pwm_stop(int channel)
AT91F_PWMC_StopChannel(AT91C_BASE_PWMC, (1 << channel));
}
void pwm_duty_set_percent(int channel, u_int16_t duty)
void pwm_duty_set_percent(int channel, uint16_t duty)
{
u_int32_t tmp = pwm->PWMC_CH[channel].PWMC_CPRDR & 0xffff;
uint32_t tmp = pwm->PWMC_CH[channel].PWMC_CPRDR & 0xffff;
tmp = tmp << 16; /* extend value by 2^16 */
tmp = tmp / 100; /* tmp = 1 % of extended cprd */
@ -120,7 +120,7 @@ void pwm_duty_set_percent(int channel, u_int16_t duty)
static int pwm_usb_in(struct req_ctx *rctx)
{
struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
u_int32_t *freq;
uint32_t *freq;
switch (poh->cmd) {
case OPENPCD_CMD_PWM_ENABLE:
@ -138,7 +138,7 @@ static int pwm_usb_in(struct req_ctx *rctx)
case OPENPCD_CMD_PWM_FREQ_SET:
if (rctx->tot_len < sizeof(*poh)+4)
break;
freq = (u_int32_t *) ((unsigned char *) poh) + sizeof(*poh);
freq = (uint32_t *) ((unsigned char *) poh) + sizeof(*poh);
pwm_freq_set(0, *freq);
break;
case OPENPCD_CMD_PWM_FREQ_GET:

View File

@ -1,10 +1,10 @@
#ifndef _PWM_H
#define _PWM_H
extern void pwm_freq_set(int channel, u_int32_t freq);
extern void pwm_freq_set(int channel, uint32_t freq);
extern void pwm_start(int channel);
extern void pwm_stop(int channel);
extern void pwm_duty_set_percent(int channel, u_int16_t duty);
extern void pwm_duty_set_percent(int channel, uint16_t duty);
extern void pwm_init(void);
extern void pwm_fini(void);

View File

@ -29,77 +29,187 @@
/* FIXME: locking, FIFO order processing */
#if defined(__AT91SAM7S64__) || defined(RUN_FROM_RAM)
#define NUM_RCTX_SMALL 16
#define NUM_RCTX_LARGE 1
#define NUM_RCTX_SMALL 0
#define NUM_RCTX_LARGE 8
#else
#define NUM_RCTX_SMALL 8
#define NUM_RCTX_LARGE 4
#define NUM_RCTX_SMALL 0
#define NUM_RCTX_LARGE 20
#endif
#define NUM_REQ_CTX (NUM_RCTX_SMALL+NUM_RCTX_LARGE)
static u_int8_t rctx_data[NUM_RCTX_SMALL][RCTX_SIZE_SMALL];
static u_int8_t rctx_data_large[NUM_RCTX_LARGE][RCTX_SIZE_LARGE];
static uint8_t rctx_data[NUM_RCTX_SMALL][RCTX_SIZE_SMALL];
static uint8_t rctx_data_large[NUM_RCTX_LARGE][RCTX_SIZE_LARGE];
static struct req_ctx req_ctx[NUM_REQ_CTX];
/* queue of RCTX indexed by their current state */
static struct req_ctx *req_ctx_queues[RCTX_STATE_COUNT], *req_ctx_tails[RCTX_STATE_COUNT];
static unsigned req_counts[RCTX_STATE_COUNT];
struct req_ctx __ramfunc *req_ctx_find_get(int large,
unsigned long old_state,
unsigned long new_state)
{
struct req_ctx *toReturn;
unsigned long flags;
u_int8_t i;
if (large)
i = NUM_RCTX_SMALL;
else
i = 0;
for (; i < NUM_REQ_CTX; i++) {
local_irq_save(flags);
if (req_ctx[i].state == old_state) {
req_ctx[i].state = new_state;
local_irq_restore(flags);
return &req_ctx[i];
}
local_irq_restore(flags);
if (old_state >= RCTX_STATE_COUNT || new_state >= RCTX_STATE_COUNT) {
DEBUGPCR("Invalid parameters for req_ctx_find_get");
return NULL;
}
return NULL;
local_irq_save(flags);
toReturn = req_ctx_queues[old_state];
if (toReturn) {
if ((req_ctx_queues[old_state] = toReturn->next))
toReturn->next->prev = NULL;
else
req_ctx_tails[old_state] = NULL;
req_counts[old_state]--;
if ((toReturn->prev = req_ctx_tails[new_state]))
toReturn->prev->next = toReturn;
else
req_ctx_queues[new_state] = toReturn;
req_ctx_tails[new_state] = toReturn;
toReturn->state = new_state;
toReturn->next = NULL;
req_counts[new_state]++;
}
local_irq_restore(flags);
return toReturn;
}
u_int8_t req_ctx_num(struct req_ctx *ctx)
uint8_t req_ctx_num(struct req_ctx *ctx)
{
return ((char *)ctx - (char *)&req_ctx[0])/sizeof(*ctx);
return ctx - req_ctx;
}
void req_ctx_set_state(struct req_ctx *ctx, unsigned long new_state)
{
unsigned long flags;
unsigned old_state;
/* FIXME: do we need this kind of locking, we're UP! */
if (new_state >= RCTX_STATE_COUNT) {
DEBUGPCR("Invalid new_state for req_ctx_set_state");
return;
}
local_irq_save(flags);
old_state = ctx->state;
if (ctx->prev)
ctx->prev->next = ctx->next;
else
req_ctx_queues[old_state] = ctx->next;
if (ctx->next)
ctx->next->prev = ctx->prev;
else
req_ctx_tails[old_state] = ctx->prev;
req_counts[old_state]--;
if ((ctx->prev = req_ctx_tails[new_state]))
ctx->prev->next = ctx;
else
req_ctx_queues[new_state] = ctx;
req_ctx_tails[new_state] = ctx;
ctx->state = new_state;
ctx->next = NULL;
req_counts[new_state]++;
local_irq_restore(flags);
}
#ifdef DEBUG_REQCTX
void req_print(int state) {
int count = 0;
struct req_ctx *ctx, *last = NULL;
DEBUGP("State [%02i] start <==> ", state);
ctx = req_ctx_queues[state];
while (ctx) {
if (last != ctx->prev)
DEBUGP("*INV_PREV* ");
DEBUGP("%08X => ", ctx);
last = ctx;
ctx = ctx->next;
count++;
if (count > NUM_REQ_CTX) {
DEBUGP("*WILD POINTER* => ");
break;
}
}
DEBUGPCR("NULL");
if (!req_ctx_queues[state] && req_ctx_tails[state]) {
DEBUGPCR("NULL head, NON-NULL tail");
}
if (last != req_ctx_tails[state]) {
DEBUGPCR("Tail does not match last element");
}
}
#endif
void req_ctx_put(struct req_ctx *ctx)
{
req_ctx_set_state(ctx, RCTX_STATE_FREE);
unsigned long intcFlags;
unsigned old_state;
local_irq_save(intcFlags);
old_state = ctx->state;
if (ctx->prev)
ctx->prev->next = ctx->next;
else
req_ctx_queues[old_state] = ctx->next;
if (ctx->next)
ctx->next->prev = ctx->prev;
else
req_ctx_tails[old_state] = ctx->prev;
req_counts[old_state]--;
if ((ctx->prev = req_ctx_tails[RCTX_STATE_FREE]))
ctx->prev->next = ctx;
else
req_ctx_queues[RCTX_STATE_FREE] = ctx;
req_ctx_tails[RCTX_STATE_FREE] = ctx;
ctx->state = RCTX_STATE_FREE;
ctx->next = NULL;
req_counts[RCTX_STATE_FREE]++;
local_irq_restore(intcFlags);
}
unsigned int req_ctx_count(unsigned long state)
{
if (state >= RCTX_STATE_COUNT)
return 0;
return req_counts[state];
}
void req_ctx_init(void)
{
int i;
for (i = 0; i < NUM_RCTX_SMALL; i++) {
req_ctx[i].prev = req_ctx + i - 1;
req_ctx[i].next = req_ctx + i + 1;
req_ctx[i].size = RCTX_SIZE_SMALL;
req_ctx[i].tot_len = 0;
req_ctx[i].data = rctx_data[i];
req_ctx[i].state = RCTX_STATE_FREE;
DEBUGPCR("SMALL req_ctx[%02i] initialized at %08X, Data: %08X => %08X",
i, req_ctx + i, req_ctx[i].data, req_ctx[i].data + RCTX_SIZE_SMALL);
}
for (i = 0; i < NUM_RCTX_LARGE; i++) {
req_ctx[NUM_RCTX_SMALL+i].size = RCTX_SIZE_LARGE;
req_ctx[NUM_RCTX_SMALL+i].data = rctx_data_large[i];
for (; i < NUM_REQ_CTX; i++) {
req_ctx[i].prev = req_ctx + i - 1;
req_ctx[i].next = req_ctx + i + 1;
req_ctx[i].size = RCTX_SIZE_LARGE;
req_ctx[i].tot_len = 0;
req_ctx[i].data = rctx_data_large[i];
req_ctx[i].state = RCTX_STATE_FREE;
DEBUGPCR("LARGE req_ctx[%02i] initialized at %08X, Data: %08X => %08X",
i, req_ctx + i, req_ctx[i].data, req_ctx[i].data + RCTX_SIZE_LARGE);
}
req_ctx[0].prev = NULL;
req_ctx[NUM_REQ_CTX - 1].next = NULL;
req_ctx_queues[RCTX_STATE_FREE] = req_ctx;
req_ctx_tails[RCTX_STATE_FREE] = req_ctx + NUM_REQ_CTX - 1;
req_counts[RCTX_STATE_FREE] = NUM_REQ_CTX;
for (i = RCTX_STATE_FREE + 1; i < RCTX_STATE_COUNT; i++) {
req_ctx_queues[i] = req_ctx_tails[i] = NULL;
req_counts[i] = 0;
}
}

View File

@ -1,11 +1,10 @@
#ifndef _REQ_CTX_H
#define _REQ_CTX_H
#define RCTX_SIZE_LARGE 2048
#define RCTX_SIZE_SMALL 128
#define RCTX_SIZE_LARGE 960
#define RCTX_SIZE_SMALL 320
#define MAX_HDRSIZE sizeof(struct openpcd_hdr)
#define MAX_REQSIZE (64-MAX_HDRSIZE)
#define req_buf_payload(x) (x->data[x->hdr_len])
#define req_buf_hdr(x) (x->data[0])
@ -14,36 +13,39 @@
#include <lib_AT91SAM7.h>
struct req_ctx {
volatile u_int32_t state;
u_int16_t size;
u_int16_t tot_len;
u_int8_t *data;
volatile uint32_t state;
volatile struct req_ctx *prev, *next;
uint16_t size;
uint16_t tot_len;
uint8_t *data;
};
#define RCTX_STATE_FREE 0xfe
#define RCTX_STATE_UDP_RCV_BUSY 0x01
#define RCTX_STATE_UDP_RCV_DONE 0x02
#define RCTX_STATE_MAIN_PROCESSING 0x03
#define RCTX_STATE_RC632IRQ_BUSY 0x04
#define RCTX_STATE_UDP_EP2_PENDING 0x10
#define RCTX_STATE_UDP_EP2_BUSY 0x11
#define RCTX_STATE_UDP_EP3_PENDING 0x12
#define RCTX_STATE_UDP_EP3_BUSY 0x13
#define RCTX_STATE_SSC_RX_BUSY 0x20
#define RCTX_STATE_LIBRFID_BUSY 0x30
#define RCTX_STATE_PIOIRQ_BUSY 0x80
#define RCTX_STATE_INVALID 0xff
#define RCTX_STATE_FREE 0
#define RCTX_STATE_UDP_RCV_BUSY 1
#define RCTX_STATE_UDP_RCV_DONE 2
#define RCTX_STATE_MAIN_PROCESSING 3
#define RCTX_STATE_RC632IRQ_BUSY 4
#define RCTX_STATE_UDP_EP2_PENDING 5
#define RCTX_STATE_UDP_EP2_BUSY 6
#define RCTX_STATE_UDP_EP3_PENDING 7
#define RCTX_STATE_UDP_EP3_BUSY 8
#define RCTX_STATE_SSC_RX_BUSY 9
#define RCTX_STATE_LIBRFID_BUSY 10
#define RCTX_STATE_PIOIRQ_BUSY 11
#define RCTX_STATE_INVALID 12
// Nominally UNUSED states
#define RCTX_STATE_UDP_EP0_PENDING 13
#define RCTX_STATE_UDP_EP0_BUSY 14
#define RCTX_STATE_UDP_EP1_PENDING 15
#define RCTX_STATE_UDP_EP1_BUSY 16
// Count of the number of STATES
#define RCTX_STATE_COUNT 17
extern struct req_ctx __ramfunc *req_ctx_find_get(int large, unsigned long old_state, unsigned long new_state);
extern struct req_ctx *req_ctx_find_busy(void);
extern void req_ctx_set_state(struct req_ctx *ctx, unsigned long new_state);
extern void req_ctx_put(struct req_ctx *ctx);
extern u_int8_t req_ctx_num(struct req_ctx *ctx);
extern uint8_t req_ctx_num(struct req_ctx *ctx);
unsigned int req_ctx_count(unsigned long state);
#endif /* _REQ_CTX_H */

View File

@ -25,15 +25,15 @@
#include <os/system_irq.h>
#include <os/dbgu.h>
#include <string.h>
#include "../openpcd.h"
static sysirq_hdlr *sysirq_hdlrs[AT91SAM7_SYSIRQ_COUNT];
static void sys_irq(void)
void sys_irq(uint32_t previous_pc)
{
u_int32_t sr;
DEBUGP("sys_irq ");
uint32_t sr;
/* Somehow Atmel decided to do really stupid interrupt sharing
* for commonly-used interrupts such as the timer irq */
@ -139,6 +139,10 @@ static void sys_irq(void)
if (*AT91C_WDTC_WDMR & AT91C_WDTC_WDFIEN) {
sr = *AT91C_WDTC_WDSR;
if (sr) {
char dbg_buf[100];
sprintf(dbg_buf, "sys_irq [Old PC = %08X]\n\r", previous_pc);
AT91F_DBGU_Frame(dbg_buf);
DEBUGP("WDT(");
if (sysirq_hdlrs[AT91SAM7_SYSIRQ_WDT]) {
DEBUGP("handler ");
@ -154,6 +158,14 @@ static void sys_irq(void)
DEBUGPCR("END");
}
static void sysirq_entry(void)
{
/* DON'T MODIFY THIS SECTION AND Cstartup.S/IRQ_Handler_Entry */
register unsigned *previous_pc asm("r0");
asm("ADD R1, SP, #16; LDR R0, [R1]");
sys_irq(previous_pc);
}
void sysirq_register(enum sysirqs irq, sysirq_hdlr *hdlr)
{
if (irq >= AT91SAM7_SYSIRQ_COUNT)
@ -167,6 +179,6 @@ void sysirq_init(void)
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_SYS,
OPENPCD_IRQ_PRIO_SYS,
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL,
&sys_irq);
&sysirq_entry);
AT91F_AIC_EnableIt(AT91C_BASE_AIC, AT91C_ID_SYS);
}

View File

@ -14,7 +14,7 @@ enum sysirqs {
AT91SAM7_SYSIRQ_COUNT
};
typedef void sysirq_hdlr(u_int32_t sr);
typedef void sysirq_hdlr(uint32_t sr);
extern void sysirq_register(enum sysirqs irq, sysirq_hdlr *hdlr);
extern void sysirq_init(void);

View File

@ -31,7 +31,7 @@
static AT91PS_TCB tcb = AT91C_BASE_TCB;
/* set carrier divider to a specific */
void tc_cdiv_set_divider(u_int16_t div)
void tc_cdiv_set_divider(uint16_t div)
{
tcb->TCB_TC0.TC_RC = div;

View File

@ -7,7 +7,7 @@
static AT91PS_TCB tcb;
extern void tc_cdiv_phase_add(int16_t inc);
extern void tc_cdiv_set_divider(u_int16_t div);
extern void tc_cdiv_set_divider(uint16_t div);
static inline void tc_cdiv_phase_inc(void)
{

View File

@ -33,13 +33,13 @@
static usb_cmd_fn *cmd_hdlrs[16];
int usb_hdlr_register(usb_cmd_fn *hdlr, u_int8_t class)
int usb_hdlr_register(usb_cmd_fn *hdlr, uint8_t class)
{
cmd_hdlrs[class] = hdlr;
return 0;
}
void usb_hdlr_unregister(u_int8_t class)
void usb_hdlr_unregister(uint8_t class)
{
cmd_hdlrs[class] = NULL;
}

View File

@ -18,8 +18,8 @@ enum usbapi_err {
typedef int usb_cmd_fn(struct req_ctx *rctx);
extern int usb_hdlr_register(usb_cmd_fn *hdlr, u_int8_t class);
extern void usb_hdlr_unregister(u_int8_t class);
extern int usb_hdlr_register(usb_cmd_fn *hdlr, uint8_t class);
extern void usb_hdlr_unregister(uint8_t class);
extern void usb_in_process(void);
extern void usb_out_process(void);

View File

@ -18,14 +18,14 @@
#define OPENPCD_API_VERSION (0x01)
#define CONFIG_AREA_ADDR ((void*)(AT91C_IFLASH + AT91C_IFLASH_SIZE - ENVIRONMENT_SIZE))
#define CONFIG_AREA_WORDS ( AT91C_IFLASH_PAGE_SIZE/sizeof(u_int32_t) )
#define CONFIG_AREA_WORDS ( AT91C_IFLASH_PAGE_SIZE/sizeof(uint32_t) )
volatile u_int32_t config_stack[ CONFIG_AREA_WORDS ];
volatile uint32_t config_stack[ CONFIG_AREA_WORDS ];
static int gen_setenv(const void* buffer,int len)
{
volatile unsigned int i;
u_int32_t *dst;
uint32_t *dst;
if( len >= sizeof(config_stack) )
len=sizeof(config_stack);
@ -35,7 +35,7 @@ static int gen_setenv(const void* buffer,int len)
/* retrieve current content to allow partial flashing */
/* flash changes */
dst=(u_int32_t*)CONFIG_AREA_ADDR;
dst=(uint32_t*)CONFIG_AREA_ADDR;
for(i=0;i<CONFIG_AREA_WORDS;i++)
*dst++=config_stack[i];
@ -59,7 +59,7 @@ static int gen_usb_rx(struct req_ctx *rctx)
struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
struct openpcd_compile_version *ver =
(struct openpcd_compile_version *)poh->data;
u_int32_t len = rctx->tot_len-sizeof(*poh);
uint32_t len = rctx->tot_len-sizeof(*poh);
/* initialize transmit length to header length */
rctx->tot_len = sizeof(*poh);
@ -107,7 +107,7 @@ static int gen_usb_rx(struct req_ctx *rctx)
poh->flags |= OPENPCD_FLAG_RESPOND;
#ifdef PCD
rctx->tot_len += 4;
if (rc632_get_serial(NULL, (u_int32_t *)poh->data) < 0) {
if (rc632_get_serial(NULL, (uint32_t *)poh->data) < 0) {
DEBUGP("ERROR) ");
return USB_ERR(USB_ERR_CMD_NOT_IMPL);
}
@ -132,7 +132,7 @@ static int gen_usb_rx(struct req_ctx *rctx)
void usbcmd_gen_init(void)
{
DEBUGP("Inititalizing usbcmd_gen_init\n");
DEBUGP("Inititalizing usbcmd_gen_init\n\r");
/* setup FLASH write support for environment storage */
flash_init();

View File

@ -1,6 +1,6 @@
#ifndef _USBAPI_GENERIC_H
#define _USBAPI_GENERIC_H
extern void usbcmd_gen_init(void);
extern int gen_setenv(void* data,u_int32_t pos,u_int32_t length);
extern int gen_getenv(void* data,u_int32_t pos,u_int32_t length);
extern int gen_setenv(void* data,uint32_t pos,uint32_t length);
extern int gen_getenv(void* data,uint32_t pos,uint32_t length);
#endif

View File

@ -23,13 +23,19 @@
#include <os/dbgu.h>
#include <os/system_irq.h>
#define WDT_WDD 0xFF
#define WDT_WDV 0xFF
#ifdef WDT_DEBUG
#undef WDT_DEBUG
#endif/*WDT_DEBUG*/
static void wdt_irq(u_int32_t sr)
static void wdt_irq(uint32_t sr)
{
DEBUGPCRF("================> WATCHDOG EXPIRED !!!!!");
if (sr & 1)
AT91F_DBGU_Frame("================> WATCHDOG EXPIRED !!!!!\n\r");
if (sr & 2)
AT91F_DBGU_Frame("================> WATCHDOG ERROR !!!!!\n\r");
}
void wdt_restart(void)
@ -41,11 +47,12 @@ void wdt_init(void)
{
sysirq_register(AT91SAM7_SYSIRQ_WDT, &wdt_irq);
#ifdef WDT_DEBUG
AT91F_WDTSetMode(AT91C_BASE_WDTC, (0xff << 16) |
AT91F_WDTSetMode(AT91C_BASE_WDTC, (WDT_WDD << 16) |
AT91C_WDTC_WDDBGHLT | AT91C_WDTC_WDIDLEHLT |
AT91C_WDTC_WDFIEN);
AT91C_WDTC_WDFIEN | WDT_WDV);
#else
AT91F_WDTSetMode(AT91C_BASE_WDTC, (0x80 << 16) |
AT91C_WDTC_WDRSTEN | 0x80);
AT91F_WDTSetMode(AT91C_BASE_WDTC, (WDT_WDD << 16) |
AT91C_WDTC_WDDBGHLT | AT91C_WDTC_WDIDLEHLT |
AT91C_WDTC_WDRSTEN | WDT_WDV);
#endif
}

View File

@ -7,9 +7,9 @@
#include <sys/types.h>
struct opcd_cmd_hdr {
u_int8_t cmd;
u_int8_t arg1;
u_int16_t arg2;
uint8_t cmd;
uint8_t arg1;
uint16_t arg2;
} __attribute__ ((packed));
enum opcd_cmd {
@ -28,8 +28,8 @@ enum opcd_cmd {
};
struct opcd_status_hdr {
u_int8_t cause, /* interrupt cause register RC632 */
u_int8_t prim_status, /* primary status register RC632 */
uint8_t cause, /* interrupt cause register RC632 */
uint8_t prim_status, /* primary status register RC632 */
} __attribute__ ((packed));
#endif /* _OPENPCD_H */

View File

@ -59,30 +59,30 @@ int _main_dbgu(char key)
}
struct openpcd_l2_connectinfo {
u_int32_t proto_supported;
uint32_t proto_supported;
u_int8_t speed_rx;
u_int8_t speed_tx;
uint8_t speed_rx;
uint8_t speed_tx;
u_int8_t uid_len;
u_int8_t uid[10];
uint8_t uid_len;
uint8_t uid[10];
} __attribute__ ((packed));
struct openpcd_proto_connectinfo {
} __attribute__ ((packed));
struct openpcd_proto_tcl_connectinfo {
u_int8_t fsc;
u_int8_t fsd;
u_int8_t ta;
u_int8_t sfgt;
uint8_t fsc;
uint8_t fsd;
uint8_t ta;
uint8_t sfgt;
u_int8_t flags;
u_int8_t cid;
u_int8_t nad;
uint8_t flags;
uint8_t cid;
uint8_t nad;
u_int8_t ats_tot_len;
u_int8_t ats_snippet[0];
uint8_t ats_tot_len;
uint8_t ats_snippet[0];
} __attribute__ ((packed));
static int init_proto(void)

View File

@ -40,7 +40,7 @@ static struct rfid_reader_handle *rh;
static struct rfid_layer2_handle *l2h;
static struct rfid_protocol_handle *ph;
static u_int8_t sector = 0;
static uint8_t sector = 0;
void _init_func(void)
{
@ -74,30 +74,30 @@ int _main_dbgu(char key)
}
struct openpcd_l2_connectinfo {
u_int32_t proto_supported;
uint32_t proto_supported;
u_int8_t speed_rx;
u_int8_t speed_tx;
uint8_t speed_rx;
uint8_t speed_tx;
u_int8_t uid_len;
u_int8_t uid[10];
uint8_t uid_len;
uint8_t uid[10];
} __attribute__ ((packed));
struct openpcd_proto_connectinfo {
} __attribute__ ((packed));
struct openpcd_proto_tcl_connectinfo {
u_int8_t fsc;
u_int8_t fsd;
u_int8_t ta;
u_int8_t sfgt;
uint8_t fsc;
uint8_t fsd;
uint8_t ta;
uint8_t sfgt;
u_int8_t flags;
u_int8_t cid;
u_int8_t nad;
uint8_t flags;
uint8_t cid;
uint8_t nad;
u_int8_t ats_tot_len;
u_int8_t ats_snippet[0];
uint8_t ats_tot_len;
uint8_t ats_snippet[0];
} __attribute__ ((packed));
/* mifare classic helper */

View File

@ -37,7 +37,7 @@
#define RAH NULL
u_int32_t delay_scan,delay_blink,last_uid,last_polled_uid;
uint32_t delay_scan,delay_blink,last_uid,last_polled_uid;
static struct rfid_reader_handle *rh;
static struct rfid_layer2_handle *l2h;
@ -54,10 +54,10 @@ static int usb_presence_rx(struct req_ctx *rctx)
if(last_polled_uid)
{
rctx->tot_len += 4;
poh->data[0]=(u_int8_t)(last_polled_uid>>24);
poh->data[1]=(u_int8_t)(last_polled_uid>>16);
poh->data[2]=(u_int8_t)(last_polled_uid>> 8);
poh->data[3]=(u_int8_t)(last_polled_uid );
poh->data[0]=(uint8_t)(last_polled_uid>>24);
poh->data[1]=(uint8_t)(last_polled_uid>>16);
poh->data[2]=(uint8_t)(last_polled_uid>> 8);
poh->data[3]=(uint8_t)(last_polled_uid );
last_polled_uid=0;
}
break;
@ -124,16 +124,16 @@ int _main_dbgu(char key)
void _main_func(void)
{
u_int32_t uid;
uint32_t uid;
int status;
status = rfid_layer2_open(l2h);
if (status >= 0 && l2h->uid_len==4)
{
uid=((u_int32_t)l2h->uid[0]) |
((u_int32_t)l2h->uid[1])<< 8|
((u_int32_t)l2h->uid[2])<<16|
((u_int32_t)l2h->uid[3])<<24;
uid=((uint32_t)l2h->uid[0]) |
((uint32_t)l2h->uid[1])<< 8|
((uint32_t)l2h->uid[2])<<16|
((uint32_t)l2h->uid[3])<<24;
delay_scan=100;

View File

@ -39,14 +39,14 @@
#define RAH NULL
static u_int8_t force_100ask = 1;
static u_int8_t mod_conductance = 0x3f;
static u_int8_t cw_conductance = 0x3f;
static u_int16_t duty_percent = 22;
static uint8_t force_100ask = 1;
static uint8_t mod_conductance = 0x3f;
static uint8_t cw_conductance = 0x3f;
static uint16_t duty_percent = 22;
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static u_int32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
static u_int8_t pwm_freq_idx = 0;
static uint32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
static uint8_t pwm_freq_idx = 0;
static void rc632_modulate_mfin()
{
@ -61,11 +61,11 @@ static void rc632_modulate_mfin()
#define COND_MANT(x) (x & 0x0f)
#define COND_EXP(x) ((x & 0x30) >> 4)
static const u_int16_t rsrel_expfact[] = { 1000, 1925, 3706, 7133 };
static const uint16_t rsrel_expfact[] = { 1000, 1925, 3706, 7133 };
static u_int32_t calc_conduct_rel(u_int8_t inp)
static uint32_t calc_conduct_rel(uint8_t inp)
{
u_int32_t cond_rel;
uint32_t cond_rel;
cond_rel = COND_MANT(inp) * rsrel_expfact[COND_EXP(inp)];
cond_rel = cond_rel / 1000;
@ -73,14 +73,14 @@ static u_int32_t calc_conduct_rel(u_int8_t inp)
return cond_rel;
}
static const u_int8_t rsrel_table[] = {
static const uint8_t rsrel_table[] = {
0, 16, 32, 48, 1, 17, 2, 3, 33, 18, 4, 5, 19, 6, 7, 49, 34, 20,
8, 9, 21, 10, 11, 35, 22, 12, 13, 23, 14, 50, 36, 15, 24, 25,
37, 26, 27, 51, 38, 28, 29, 39, 30, 52, 31, 40, 41, 53, 42, 43,
54, 44, 45, 55, 46, 47, 56, 57, 58, 59, 60, 61, 62, 63 };
static const u_int16_t cdivs[] = { 128, 64, 32, 16 };
static const uint16_t cdivs[] = { 128, 64, 32, 16 };
static int cdiv_idx = 0;
static void help(void)

View File

@ -83,25 +83,25 @@ static const char frame_14443a[] = {
0x00, 0xff, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66,
};
static void reg_inc(u_int8_t reg)
static void reg_inc(uint8_t reg)
{
u_int8_t val;
uint8_t val;
opcd_rc632_reg_read(RAH, reg, &val);
opcd_rc632_reg_write(RAH, reg, val++);
DEBUGPCRF("reg 0x%02x = 0x%02x", reg, val);
}
static void reg_dec(u_int8_t reg)
static void reg_dec(uint8_t reg)
{
u_int8_t val;
uint8_t val;
opcd_rc632_reg_read(RAH, reg, &val);
opcd_rc632_reg_write(RAH, reg, val--);
DEBUGPCRF("reg 0x%02x = 0x%02x", reg, val);
}
static u_int8_t ana_out_sel;
static u_int8_t mfout_sel;
static u_int8_t speed_idx;
static uint8_t ana_out_sel;
static uint8_t mfout_sel;
static uint8_t speed_idx;
static void help(void)
{
@ -114,7 +114,7 @@ static void help(void)
"{: dev cdiv }: inc cdiv");
}
static u_int16_t cdivs[] = { 128, 64, 32, 16 };
static uint16_t cdivs[] = { 128, 64, 32, 16 };
int _main_dbgu(char key)
{

View File

@ -72,7 +72,7 @@ static const AT91PS_SPI pSPI = AT91C_BASE_SPI;
/* SPI irq handler */
static void spi_irq(void)
{
u_int32_t status = pSPI->SPI_SR;
uint32_t status = pSPI->SPI_SR;
DEBUGPSPIIRQ("spi_irq: 0x%08x ", status);
@ -95,8 +95,8 @@ static void spi_irq(void)
}
#ifdef SPI_USES_DMA
static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
u_int8_t *rx_data, u_int16_t *rx_len)
static int spi_transceive(const uint8_t *tx_data, uint16_t tx_len,
uint8_t *rx_data, uint16_t *rx_len)
{
DEBUGPSPI("DMA Xfer tx=%s\r\n", hexdump(tx_data, tx_len));
if (*rx_len < tx_len) {
@ -129,12 +129,12 @@ static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
}
#else
/* stupid polling transceiver routine */
static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
u_int8_t *rx_data, u_int16_t *rx_len)
static int spi_transceive(const uint8_t *tx_data, uint16_t tx_len,
uint8_t *rx_data, uint16_t *rx_len)
{
u_int16_t tx_cur = 0;
u_int16_t rx_len_max = 0;
u_int16_t rx_cnt = 0;
uint16_t tx_cur = 0;
uint16_t rx_len_max = 0;
uint16_t rx_cnt = 0;
/* disable RC632 interrupt because it wants to do SPI transactions */
AT91F_AIC_DisableIt(AT91C_BASE_AIC, OPENPCD_IRQ_RC632);
@ -148,8 +148,8 @@ static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
//AT91F_SPI_Enable(pSPI);
while (1) {
u_int32_t sr = pSPI->SPI_SR;
u_int8_t tmp;
uint32_t sr = pSPI->SPI_SR;
uint8_t tmp;
if (sr & AT91C_SPI_RDRF) {
tmp = pSPI->SPI_RDR;
rx_cnt++;
@ -181,8 +181,8 @@ static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
/* static buffers used by RC632 access primitives below.
* Since we only have one */
static u_int8_t spi_outbuf[SPI_MAX_XFER_LEN];
static u_int8_t spi_inbuf[SPI_MAX_XFER_LEN];
static uint8_t spi_outbuf[SPI_MAX_XFER_LEN];
static uint8_t spi_inbuf[SPI_MAX_XFER_LEN];
#define FIFO_ADDR (RC632_REG_FIFO_DATA << 1)
@ -191,9 +191,9 @@ static u_int8_t spi_inbuf[SPI_MAX_XFER_LEN];
/* RC632 access primitives */
int opcd_rc632_reg_write(struct rfid_asic_handle *hdl,
u_int8_t addr, u_int8_t data)
uint8_t addr, uint8_t data)
{
u_int16_t rx_len = 2;
uint16_t rx_len = 2;
DEBUG632("[0x%02x] <= 0x%02x", addr, data);
@ -208,13 +208,13 @@ int opcd_rc632_reg_write(struct rfid_asic_handle *hdl,
#define RC632_REGSET_START 0x10
#define RC632_REGSET_END 0x3f
#define RC632_REGSET_MAXSIZE (RC632_REGSET_END-RC632_REGSET_START)
static u_int8_t regset_buf[RC632_REGSET_MAXSIZE * 2];
static uint8_t regset_buf[RC632_REGSET_MAXSIZE * 2];
int opcd_rc632_reg_write_set(struct rfid_asic_handle *hdl,
u_int8_t *regs, int len)
uint8_t *regs, int len)
{
u_int8_t i, j = 0;
u_int16_t rx_len;
uint8_t i, j = 0;
uint16_t rx_len;
if (len > RC632_REGSET_MAXSIZE)
return -E2BIG;
@ -232,9 +232,9 @@ int opcd_rc632_reg_write_set(struct rfid_asic_handle *hdl,
}
int opcd_rc632_fifo_write(struct rfid_asic_handle *hdl,
u_int8_t len, u_int8_t *data, u_int8_t flags)
uint8_t len, uint8_t *data, uint8_t flags)
{
u_int16_t rx_len = sizeof(spi_inbuf);
uint16_t rx_len = sizeof(spi_inbuf);
if (len > sizeof(spi_outbuf)-1)
len = sizeof(spi_outbuf)-1;
@ -247,9 +247,9 @@ int opcd_rc632_fifo_write(struct rfid_asic_handle *hdl,
}
int opcd_rc632_reg_read(struct rfid_asic_handle *hdl,
u_int8_t addr, u_int8_t *val)
uint8_t addr, uint8_t *val)
{
u_int16_t rx_len = 2;
uint16_t rx_len = 2;
addr = (addr << 1) & 0x7e;
@ -265,12 +265,12 @@ int opcd_rc632_reg_read(struct rfid_asic_handle *hdl,
}
int opcd_rc632_fifo_read(struct rfid_asic_handle *hdl,
u_int8_t max_len, u_int8_t *data)
uint8_t max_len, uint8_t *data)
{
int ret;
u_int8_t fifo_length;
u_int8_t i;
u_int16_t rx_len;
uint8_t fifo_length;
uint8_t i;
uint16_t rx_len;
ret = opcd_rc632_reg_read(hdl, RC632_REG_FIFO_LENGTH, &fifo_length);
if (ret < 0)
@ -296,9 +296,9 @@ int opcd_rc632_fifo_read(struct rfid_asic_handle *hdl,
}
int opcd_rc632_set_bits(struct rfid_asic_handle *hdl,
u_int8_t reg, u_int8_t bits)
uint8_t reg, uint8_t bits)
{
u_int8_t val;
uint8_t val;
int ret;
ret = opcd_rc632_reg_read(hdl, reg, &val);
@ -311,9 +311,9 @@ int opcd_rc632_set_bits(struct rfid_asic_handle *hdl,
}
int opcd_rc632_clear_bits(struct rfid_asic_handle *hdl,
u_int8_t reg, u_int8_t bits)
uint8_t reg, uint8_t bits)
{
u_int8_t val;
uint8_t val;
int ret;
ret = opcd_rc632_reg_read(hdl, reg, &val);
@ -331,7 +331,7 @@ static void rc632_irq(void)
{
struct req_ctx *irq_rctx;
struct openpcd_hdr *irq_opcdh;
u_int8_t cause;
uint8_t cause;
/* CL RC632 has interrupted us */
opcd_rc632_reg_read(NULL, RC632_REG_INTERRUPT_RQ, &cause);
@ -392,7 +392,7 @@ void rc632_unthrottle(void)
AT91F_AIC_EnableIt(AT91C_BASE_AIC, OPENPCD_IRQ_RC632);
}
void rc632_power(u_int8_t up)
void rc632_power(uint8_t up)
{
DEBUGPCRF("powering %s RC632", up ? "up" : "down");
if (up)
@ -414,7 +414,7 @@ void rc632_reset(void)
/* wait for startup phase to finish */
while (1) {
u_int8_t val;
uint8_t val;
opcd_rc632_reg_read(NULL, RC632_REG_COMMAND, &val);
if (val == 0x00)
break;
@ -427,7 +427,7 @@ void rc632_reset(void)
static int rc632_usb_in(struct req_ctx *rctx)
{
struct openpcd_hdr *poh = (struct openpcd_hdr *) rctx->data;
u_int16_t len = rctx->tot_len-sizeof(*poh);
uint16_t len = rctx->tot_len-sizeof(*poh);
/* initialize transmit length to header length */
rctx->tot_len = sizeof(*poh);
@ -443,7 +443,7 @@ static int rc632_usb_in(struct req_ctx *rctx)
/* FIFO read always has to provoke a response */
poh->flags &= OPENPCD_FLAG_RESPOND;
{
u_int16_t req_len = poh->val, remain_len = req_len, pih_len;
uint16_t req_len = poh->val, remain_len = req_len, pih_len;
#if 0
if (req_len > MAX_PAYLOAD_LEN) {
pih_len = MAX_PAYLOAD_LEN;
@ -598,9 +598,9 @@ void rc632_exit(void)
#ifdef DEBUG
static int rc632_reg_write_verify(struct rfid_asic_handle *hdl,
u_int8_t reg, u_int8_t val)
uint8_t reg, uint8_t val)
{
u_int8_t tmp;
uint8_t tmp;
opcd_rc632_reg_write(hdl, reg, val);
opcd_rc632_reg_read(hdl, reg, &tmp);
@ -612,11 +612,11 @@ static int rc632_reg_write_verify(struct rfid_asic_handle *hdl,
int rc632_dump(void)
{
u_int8_t i;
u_int16_t rx_len = sizeof(spi_inbuf);
uint8_t i;
uint16_t rx_len = sizeof(spi_inbuf);
for (i = 0; i <= 0x3f; i++) {
u_int8_t reg = i;
uint8_t reg = i;
if (reg == RC632_REG_FIFO_DATA)
reg = 0x3e;

View File

@ -7,17 +7,17 @@
#include <librfid/rfid_asic.h>
extern int opcd_rc632_reg_write(struct rfid_asic_handle *hdl,
u_int8_t addr, u_int8_t data);
uint8_t addr, uint8_t data);
extern int opcd_rc632_fifo_write(struct rfid_asic_handle *hdl,
u_int8_t len, u_int8_t *data, u_int8_t flags);
uint8_t len, uint8_t *data, uint8_t flags);
extern int opcd_rc632_reg_read(struct rfid_asic_handle *hdl,
u_int8_t addr, u_int8_t *val);
uint8_t addr, uint8_t *val);
extern int opcd_rc632_fifo_read(struct rfid_asic_handle *hdl,
u_int8_t max_len, u_int8_t *data);
uint8_t max_len, uint8_t *data);
extern int opcd_rc632_clear_bits(struct rfid_asic_handle *hdl,
u_int8_t reg, u_int8_t bits);
uint8_t reg, uint8_t bits);
extern int opcd_rc632_set_bits(struct rfid_asic_handle *hdl,
u_int8_t reg, u_int8_t bits);
uint8_t reg, uint8_t bits);
extern void rc632_init(void);
extern void rc632_exit(void);
@ -27,6 +27,6 @@ extern void rc632_unthrottle(void);
extern int rc632_test(struct rfid_asic_handle *hdl);
extern int rc632_dump(void);
extern void rc632_power(u_int8_t up);
extern void rc632_power(uint8_t up);
#endif

View File

@ -49,10 +49,10 @@ struct rfid_asic rc632;
static int
rc632_set_bit_mask(struct rfid_asic_handle *handle,
u_int8_t reg, u_int8_t mask, u_int8_t val)
uint8_t reg, uint8_t mask, uint8_t val)
{
int ret;
u_int8_t tmp;
uint8_t tmp;
ret = opcd_rc632_reg_read(handle, reg, &tmp);
if (ret < 0)
@ -98,10 +98,10 @@ rc632_power_down(struct rfid_asic_handle *handle)
int
rc632_write_eeprom(struct rfid_asic_handle *handle,
u_int16_t addr, u_int8_t len, u_int8_t *data)
uint16_t addr, uint8_t len, uint8_t *data)
{
u_int8_t sndbuf[MAX_WRITE_LEN + 2];
u_int8_t reg;
uint8_t sndbuf[MAX_WRITE_LEN + 2];
uint8_t reg;
int ret;
if (len > MAX_WRITE_LEN)
@ -146,11 +146,11 @@ rc632_write_eeprom(struct rfid_asic_handle *handle,
}
int
rc632_read_eeprom(struct rfid_asic_handle *handle, u_int16_t addr, u_int8_t len,
u_int8_t *recvbuf)
rc632_read_eeprom(struct rfid_asic_handle *handle, uint16_t addr, uint8_t len,
uint8_t *recvbuf)
{
u_int8_t sndbuf[3];
u_int8_t err;
uint8_t sndbuf[3];
uint8_t err;
int ret;
sndbuf[0] = (addr & 0xff);
@ -187,8 +187,8 @@ rc632_read_eeprom(struct rfid_asic_handle *handle, u_int16_t addr, u_int8_t len,
#define RC632_E2_RS_MAX_P 14
int rc632_get_serial(struct rfid_asic_handle *handle,
u_int32_t *serial)
uint32_t *serial)
{
return rc632_read_eeprom(handle, RC632_E2_PRODUCT_SERIAL,
4, (u_int8_t *)serial);
4, (uint8_t *)serial);
}

View File

@ -11,9 +11,9 @@ int
rc632_turn_off_rf(struct rfid_asic_handle *handle);
int
rc632_read_eeprom(struct rfid_asic_handle *handle, u_int16_t addr, u_int8_t len,
u_int8_t *recvbuf);
rc632_read_eeprom(struct rfid_asic_handle *handle, uint16_t addr, uint8_t len,
uint8_t *recvbuf);
int rc632_get_serial(struct rfid_asic_handle *handle,
u_int32_t *serial);
uint32_t *serial);
#endif /* _RC632_HIGHLEVEL_H */

View File

@ -57,7 +57,7 @@ static struct adc_state adc_state;
static void adc_irq(void)
{
u_int32_t sr = adc->ADC_SR;
uint32_t sr = adc->ADC_SR;
struct req_ctx *rctx = adc_state.rctx;
DEBUGADC("adc_irq(SR=0x%08x, IMR=0x%08x, state=%u): ",
@ -102,12 +102,12 @@ static void adc_irq(void)
}
#if 0
u_int16_t adc_read_fieldstr(void)
uint16_t adc_read_fieldstr(void)
{
return adc->ADC_CDR4;
}
u_int16_T adc_read_pll_dem(void)
uint16_T adc_read_pll_dem(void)
{
return adc
}

View File

@ -1,7 +1,7 @@
#ifndef _DA_H
#define _DA_H
extern void da_comp_carr(u_int8_t position);
extern void da_comp_carr(uint8_t position);
extern void da_init(void);
#endif

View File

@ -25,10 +25,10 @@
static struct decoder_algo *decoder_algo[DECODER_NUM_ALGOS];
static int get_next_data(struct decoder_state *st, u_int8_t *data)
static int get_next_data(struct decoder_state *st, uint8_t *data)
{
u_int8_t parity_sample;
u_int32_t bytesample;
uint8_t parity_sample;
uint32_t bytesample;
bytesample = st->algo->get_next_bytesample(st, &parity_sample);
@ -36,7 +36,7 @@ static int get_next_data(struct decoder_state *st, u_int8_t *data)
}
/* iterate over sample buffer (size N bytes) and decode data */
int decoder_decode(u_int8_t algo, const char *sample_buf,
int decoder_decode(uint8_t algo, const char *sample_buf,
int sample_buf_size, char *data_buf)
{
int i, ret;
@ -46,7 +46,7 @@ int decoder_decode(u_int8_t algo, const char *sample_buf,
return -EINVAL;
st.buf = sample_buf;
st.buf32 = (u_int32_t *) st.buf;
st.buf32 = (uint32_t *) st.buf;
st.bit_ofs = 0;
st.algo = decoder_algo[algo];

View File

@ -4,22 +4,22 @@
struct decoder_state;
struct decoder_algo {
u_int8_t oversampling_rate;
u_int8_t bits_per_sampled_char;
u_int32_t bytesample_mask;
int (*decode_sample)(const u_int32_t sample, u_int8_t data);
u_int32_t (*get_next_bytesample)(struct decoder_state *st, u_int8_t *parity_sample);
uint8_t oversampling_rate;
uint8_t bits_per_sampled_char;
uint32_t bytesample_mask;
int (*decode_sample)(const uint32_t sample, uint8_t data);
uint32_t (*get_next_bytesample)(struct decoder_state *st, uint8_t *parity_sample);
};
struct decoder_state {
struct decoder_algo *algo;
u_int8_t bit_ofs;
uint8_t bit_ofs;
const char *buf;
const u_int32_t *buf32;
const uint32_t *buf32;
};
extern int decoder_register(int algnum, struct decoder_algo *algo);
extern int decoder_decode(u_int8_t algo, const char *sample_buf,
extern int decoder_decode(uint8_t algo, const char *sample_buf,
int sample_buf_size, char *data_buf);
#define DECODER_MILLER 0

View File

@ -55,7 +55,7 @@
#define SEQ_Z 0x1
/* decode a single sampled bit */
static u_int8_t miller_decode_sampled_bit(u_int32_t sampled_bit)
static uint8_t miller_decode_sampled_bit(uint32_t sampled_bit)
{
switch (sampled_bit) {
case SEQ_X:
@ -73,13 +73,13 @@ static u_int8_t miller_decode_sampled_bit(u_int32_t sampled_bit)
}
/* decode a single 32bit data sample of an 8bit miller encoded word */
static int miller_decode_sample(u_int32_t sample, u_int8_t *data)
static int miller_decode_sample(uint32_t sample, uint8_t *data)
{
u_int8_t ret = 0;
uint8_t ret = 0;
unsigned int i;
for (i = 0; i < sizeof(sample)/OVERSAMPLING_RATE; i++) {
u_int8_t bit = miller_decode_sampled_bit(sample & 0xf);
uint8_t bit = miller_decode_sampled_bit(sample & 0xf);
if (bit == 1)
ret |= 1;
@ -98,10 +98,10 @@ static int miller_decode_sample(u_int32_t sample, u_int8_t *data)
return ret;
}
static u_int32_t get_next_bytesample(struct decoder_state *ms,
u_int8_t *parity_sample)
static uint32_t get_next_bytesample(struct decoder_state *ms,
uint8_t *parity_sample)
{
u_int32_t ret = 0;
uint32_t ret = 0;
/* get remaining bits from the current word */
ret = *(ms->buf32) >> ms->bit_ofs;

View File

@ -60,12 +60,12 @@
/* currently this code will only work with oversampling_rate == 1 */
#define OVERSAMPLING_RATE 1
static u_int32_t get_next_bytesample(struct decoder_state *st,
u_int8_t *parity_sample)
static uint32_t get_next_bytesample(struct decoder_state *st,
uint8_t *parity_sample)
{
u_int32_t ret = 0;
u_int8_t bits_per_sampled_char = st->algo->bits_per_sampled_char;
u_int8_t bytesample_mask = st->algo->bytesample_mask;
uint32_t ret = 0;
uint8_t bits_per_sampled_char = st->algo->bits_per_sampled_char;
uint8_t bytesample_mask = st->algo->bytesample_mask;
/* FIXME: shift start and stop bit into parity_sample and just
* return plain 8-bit data word */
@ -83,7 +83,7 @@ static u_int32_t get_next_bytesample(struct decoder_state *st,
return ret & bytesample_mask;
}
static int nrzl_decode_sample(const u_int32_t sample, u_int8_t *data)
static int nrzl_decode_sample(const uint32_t sample, uint8_t *data)
{
*data = (sample >> 1) & 0xff;

View File

@ -46,7 +46,7 @@
#define MANCHESTER_SEQ_E 0x5500
#define MANCHESTER_SEQ_F 0x5555
static u_int32_t manchester_sample_size(u_int8_t frame_bytelen)
static uint32_t manchester_sample_size(uint8_t frame_bytelen)
{
/* 16 bits (2 bytes) per bit => 16 bytes samples per data byte,
* plus 16bit (2 bytes) parity per data byte
@ -60,13 +60,13 @@ static u_int32_t manchester_sample_size(u_int8_t frame_bytelen)
struct manch_enc_state {
const char *data;
char *samples;
u_int16_t *samples16;
uint16_t *samples16;
};
static void manchester_enc_byte(struct manch_enc_state *mencs, u_int8_t data)
static void manchester_enc_byte(struct manch_enc_state *mencs, uint8_t data)
{
int i;
u_int8_t sum_1 = 0;
uint8_t sum_1 = 0;
/* append 8 sample blobs, one for each bit */
for (i = 0; i < 8; i++) {
@ -86,8 +86,8 @@ static void manchester_enc_byte(struct manch_enc_state *mencs, u_int8_t data)
mencs->samples16++
}
int manchester_encode(char *sample_buf, u_int16_t sample_buf_len,
const char *data, u_int8_t data_len)
int manchester_encode(char *sample_buf, uint16_t sample_buf_len,
const char *data, uint8_t data_len)
{
int i, enc_size;
struct manch_enc_state mencs
@ -112,10 +112,10 @@ int manchester_encode(char *sample_buf, u_int16_t sample_buf_len,
#define BPSK_SPEED_212
static u_int32_t bpsk_sample_size(u_int8_t frame_bytelen)
static uint32_t bpsk_sample_size(uint8_t frame_bytelen)
int bpsk_encode(char *sample_buf, u_int16_t sample_buf_len,
const char *data, u_int8_t data_len)
int bpsk_encode(char *sample_buf, uint16_t sample_buf_len,
const char *data, uint8_t data_len)
{
/* burst of 32 sub carrier cycles */
memset(sample_buf, 0x55, 8);

View File

@ -23,7 +23,7 @@
#include "../openpcd.h"
void load_mod_level(u_int8_t level)
void load_mod_level(uint8_t level)
{
if (level > 3)
level = 3;

View File

@ -1,7 +1,7 @@
#ifndef _LOAD_MODULATION_H
#define _LOAD_MODULATION_H
extern void load_mod_level(u_int8_t level);
extern void load_mod_level(uint8_t level);
extern void load_mod_init(void);
#endif

View File

@ -35,15 +35,15 @@
#include <picc/ssc_picc.h>
#include <picc/load_modulation.h>
static const u_int16_t cdivs[] = { 8192, 2048, 1024, 512, 128, 64, 32, 16 };
static u_int8_t cdiv_idx = 6;
static const uint16_t cdivs[] = { 8192, 2048, 1024, 512, 128, 64, 32, 16 };
static uint8_t cdiv_idx = 6;
static u_int16_t duty_percent = 22;
static uint16_t duty_percent = 22;
#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
static u_int32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
static u_int8_t pwm_freq_idx = 0;
static uint32_t pwm_freq[] = { 105937, 211875, 423750, 847500 };
static uint8_t pwm_freq_idx = 0;
static u_int8_t load_mod = 0;
static uint8_t load_mod = 0;
#define DA_BASELINE 192
@ -88,10 +88,10 @@ static void help(void)
int _main_dbgu(char key)
{
static u_int8_t poti = DA_BASELINE;
static u_int8_t pll_inh = 1;
static u_int8_t ssc_mode = 1;
static u_int8_t sync_enabled = 0;
static uint8_t poti = DA_BASELINE;
static uint8_t pll_inh = 1;
static uint8_t ssc_mode = 1;
static uint8_t sync_enabled = 0;
DEBUGPCRF("main_dbgu");

View File

@ -16,7 +16,7 @@
#ifdef DEBUG
/* Our registers, including their power-up default values */
static u_int16_t opicc_regs[_OPICC_NUM_REGS] = {
static uint16_t opicc_regs[_OPICC_NUM_REGS] = {
[OPICC_REG_14443A_UIDLEN] = 4,
[OPICC_REG_14443A_FDT0] = 1236,
[OPICC_REG_14443A_FDT1] = 1172,
@ -30,14 +30,14 @@ static u_int16_t opicc_regs[_OPICC_NUM_REGS] = {
[OPICC_REG_RX_COMP_LEVEL] = 0,
};
u_int16_t opicc_reg_read(enum opicc_reg reg)
uint16_t opicc_reg_read(enum opicc_reg reg)
{
if (reg < _OPICC_NUM_REGS)
return opicc_regs[reg];
return 0;
}
void opicc_reg_write(enum opicc_reg reg, u_int16_t val)
void opicc_reg_write(enum opicc_reg reg, uint16_t val)
{
if (reg < _OPICC_NUM_REGS)
opicc_regs[reg] = val;
@ -52,7 +52,7 @@ void opicc_reg_write(enum opicc_reg reg, u_int16_t val)
static int opicc_reg_usb_in(struct req_ctx *rctx)
{
struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->data[0];
u_int16_t *val16 = (u_int16_t *) poh->data;
uint16_t *val16 = (uint16_t *) poh->data;
poh->val = 0;
rctx->tot_len = sizeof(*poh);
@ -60,11 +60,11 @@ static int opicc_reg_usb_in(struct req_ctx *rctx)
switch (poh->cmd) {
case OPENPCD_CMD_PICC_REG_READ:
*val16 = opicc_reg_read(poh->reg);
rctx->tot_len += sizeof(u_int16_t);
rctx->tot_len += sizeof(uint16_t);
poh->flags |= OPENPCD_FLAG_RESPOND;
break;
case OPENPCD_CMD_PICC_REG_WRITE:
if (rctx->tot_len < sizeof(*poh) + sizeof(u_int16_t)) {
if (rctx->tot_len < sizeof(*poh) + sizeof(uint16_t)) {
/* we only have an 8bit write */
opicc_reg_write(poh->reg, poh->val);
} else

View File

@ -5,10 +5,10 @@
#include <sys/types.h>
#ifdef DEBUG
u_int16_t opicc_reg_read(enum opicc_reg reg);
void opicc_reg_write(enum opicc_reg reg, u_int16_t val);
uint16_t opicc_reg_read(enum opicc_reg reg);
void opicc_reg_write(enum opicc_reg reg, uint16_t val);
#else
u_int16_t opicc_regs[_OPICC_NUM_REGS];
uint16_t opicc_regs[_OPICC_NUM_REGS];
#define opicc_reg_read(x) (opicc_regs[x])
#define opicc_reg_write(x, y) (opicc_regs[x] = y)
#endif

View File

@ -4,19 +4,19 @@
struct piccsim_state {
enum rfid_layer2_id l2prot;
unsigned char uid[10];
u_int8_t uid_len;
uint8_t uid_len;
union {
struct {
enum iso14443a_state state;
enum iso14443a_level level;
u_int32_t flags;
uint32_t flags;
} iso14443a;
struct {
} iso14443b;
} l2;
union {
u_int32_t flags;
uint32_t flags;
} proto;
}

View File

@ -38,7 +38,7 @@ int pll_is_locked(void)
return AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, OPENPICC_PIO_PLL_LOCK);
}
static void pll_lock_change_cb(u_int32_t pio)
static void pll_lock_change_cb(uint32_t pio)
{
DEBUGPCRF("PLL LOCK: %d", pll_is_locked());
#if 1

View File

@ -25,7 +25,7 @@
static const AT91PS_SPI spi = AT91C_BASE_SPI;
void poti_comp_carr(u_int8_t position)
void poti_comp_carr(uint8_t position)
{
volatile int i;

View File

@ -1,7 +1,7 @@
#ifndef _POTI_H
#define _POTI_H
extern void poti_comp_carr(u_int8_t position);
extern void poti_comp_carr(uint8_t position);
extern void poti_init(void);
#endif

View File

@ -62,7 +62,7 @@ struct ssc_state {
};
static struct ssc_state ssc_state;
static const u_int16_t ssc_dmasize[] = {
static const uint16_t ssc_dmasize[] = {
[SSC_MODE_NONE] = 16,
[SSC_MODE_14443A_SHORT] = 16, /* 64 bytes */
[SSC_MODE_14443A_STANDARD] = 16, /* 64 bytes */
@ -91,8 +91,8 @@ static const u_int16_t ssc_dmasize[] = {
void ssc_rx_mode_set(enum ssc_mode ssc_mode)
{
u_int8_t data_len, num_data, sync_len;
u_int32_t start_cond;
uint8_t data_len, num_data, sync_len;
uint32_t start_cond;
/* disable Rx and all Rx interrupt sources */
AT91F_SSC_DisableRx(AT91C_BASE_SSC);
@ -151,8 +151,8 @@ out_set_mode:
static void ssc_tx_mode_set(enum ssc_mode ssc_mode)
{
u_int8_t data_len, num_data, sync_len;
u_int32_t start_cond;
uint8_t data_len, num_data, sync_len;
uint32_t start_cond;
/* disable Tx */
AT91F_SSC_DisableTx(AT91C_BASE_SSC);
@ -308,7 +308,7 @@ static int8_t ssc_rx_refill(void)
static void __ramfunc ssc_irq(void)
{
u_int32_t ssc_sr = ssc->SSC_SR;
uint32_t ssc_sr = ssc->SSC_SR;
int i, *tmp, emptyframe = 0;
DEBUGP("ssc_sr=0x%08x, mode=%u: ", ssc_sr, ssc_state.mode);
@ -327,7 +327,7 @@ static void __ramfunc ssc_irq(void)
/* Experimental start SSC on frame, stop on FFFFFFFF */
if (ssc_state.mode == SSC_MODE_CONTINUOUS) {
//ssc->SSC_RCMR = (ssc->SSC_RCMR & ~AT91C_SSC_START) | AT91C_SSC_START_CONTINOUS;
tmp = (u_int32_t*)ssc_state.rx_ctx[0]->data;
tmp = (uint32_t*)ssc_state.rx_ctx[0]->data;
for(i = ssc_state.rx_ctx[0]->size / 4; i >= 0 ; i--) {
if( *tmp++ == 0xFFFFFFFF ) {
*(tmp-1) = 0xAAAAAAAA; // debug marker
@ -345,7 +345,7 @@ static void __ramfunc ssc_irq(void)
#endif
/* Ignore empty frames */
if (ssc_state.mode == SSC_MODE_CONTINUOUS) {
tmp = (u_int32_t*)ssc_state.rx_ctx[0]->data + MAX_HDRSIZE;
tmp = (uint32_t*)ssc_state.rx_ctx[0]->data + MAX_HDRSIZE;
emptyframe = 1;
for(i = (ssc_state.rx_ctx[0]->size-MAX_HDRSIZE) / 4 - 8/*WTF?*/; i > 0; i--) {
if( *tmp++ != 0xFFFFFFFF ) {
@ -417,7 +417,7 @@ static void __ramfunc ssc_irq(void)
if (ssc_sr & AT91C_SSC_RXSYN)
DEBUGP("RXSYN ");
if (ssc_sr & AT91C_SSC_RXRDY) {
u_int32_t sample = ssc->SSC_RHR;
uint32_t sample = ssc->SSC_RHR;
DEBUGP("RXRDY=0x%08x ", sample);
/* Try to set FDT compare register ASAP */
if (sample == REQA) {

View File

@ -7,9 +7,9 @@
//#define USE_IRQ
static u_int8_t enabled;
static uint8_t enabled;
static void pio_data_change(u_int32_t pio)
static void pio_data_change(uint32_t pio)
{
DEBUGP("PIO_FRAME_IRQ: ");
/* we get one interrupt for each change. If now, after the
@ -46,7 +46,7 @@ static void __ramfunc cdsync_cb(void)
void tc_cdiv_sync_reset(void)
{
if (enabled) {
u_int32_t tmp = *AT91C_PIOA_ISR;
uint32_t tmp = *AT91C_PIOA_ISR;
volatile int i;
DEBUGPCRF("CDIV_SYNC_FLOP");

View File

@ -39,7 +39,7 @@
static AT91PS_TC tcfdt = AT91C_BASE_TC2;
void tc_fdt_set(u_int16_t count)
void tc_fdt_set(uint16_t count)
{
tcfdt->TC_RA = count;
}
@ -47,14 +47,14 @@ void tc_fdt_set(u_int16_t count)
/* 'count' number of carrier cycles after the last modulation pause,
* we deem the frame to have ended */
void tc_frame_end_set(u_int16_t count)
void tc_frame_end_set(uint16_t count)
{
tcfdt->TC_RB = count;
}
static void tc_fdt_irq(void)
{
u_int32_t sr = tcfdt->TC_SR;
uint32_t sr = tcfdt->TC_SR;
DEBUGP("tc_fdt_irq: TC2_SR=0x%08x TC2_CV=0x%08x ",
sr, tcfdt->TC_CV);

View File

@ -4,6 +4,6 @@
#include <sys/types.h>
extern void tc_fdt_init(void);
extern void tc_fdt_set(u_int16_t count);
extern void tc_fdt_set(uint16_t count);
#endif

View File

@ -30,8 +30,17 @@
#define SIMTRACE_PIO_SC_SW AT91C_PIO_PA20
#define SIMTRACE_PIO_IO_SW AT91C_PIO_PA19
/* to set power for VCC_SIM for early prototype
* unused pin in v1.0p
*/
#define SIMTRACE_PIO_VCC_SIM AT91C_PIO_PA5
#define SIMTRACE_PIO_VCC_PHONE AT91C_PIO_PA30
/* to set power source for VCC_SIM for v1.0(p) */
#define SIMTRACE_PIO_SIM_LDOEN AT91C_PIO_PA5
#define SIMTRACE_PIO_SIM_nPWRFWD AT91C_PIO_PA26
/* VCC_PHONE detection */
#define SIMTRACE_PIO_VCC_PHONE AT91C_PIO_PA25
/* SPI flash */
#define PIO_SPIF_nWP AT91C_PIO_PA15

View File

@ -85,46 +85,78 @@ enum pts_state {
struct iso7816_3_handle {
enum iso7816_3_state state;
u_int8_t fi;
u_int8_t di;
u_int8_t wi;
u_int32_t waiting_time;
uint8_t fi;
uint8_t di;
uint8_t wi;
uint32_t waiting_time;
enum atr_state atr_state;
u_int8_t atr_idx;
u_int8_t atr_hist_len;
u_int8_t atr_last_td;
u_int8_t atr[64];
uint8_t atr_idx;
uint8_t atr_hist_len;
uint8_t atr_last_td;
uint8_t atr[64];
uint16_t prot_t_supported;
enum pts_state pts_state;
u_int8_t pts_req[6];
u_int8_t pts_resp[6];
uint8_t pts_req[6];
uint8_t pts_resp[6];
struct simtrace_hdr sh;
int rctx_must_be_sent;
struct req_ctx *rctx;
struct simtrace_stats stats;
};
struct iso7816_3_handle isoh;
/* Table 6 from ISO 7816-3 */
static const u_int16_t fi_table[] = {
0, 372, 558, 744, 1116, 1488, 1860, 0,
static const uint16_t fi_table[] = {
372, 372, 558, 744, 1116, 1488, 1860, 0,
0, 512, 768, 1024, 1536, 2048, 0, 0
};
/* Table 7 from ISO 7816-3 */
static const u_int8_t di_table[] = {
0, 1, 2, 4, 8, 16, 0, 0,
0, 0, 2, 4, 8, 16, 32, 64,
static const uint8_t di_table[] = {
0, 1, 2, 4, 8, 16, 32, 64,
12, 20, 2, 4, 8, 16, 32, 64,
};
/* compute the F/D ratio based on Fi and Di values */
static int compute_fidi_ratio(u_int8_t fi, u_int8_t di)
void iso_uart_report_errors(void)
{
u_int16_t f, d;
static unsigned lastOverrun = 0, lastParity = 0, lastFrame = 0;
if (isoh.stats.overrun != lastOverrun) {
DEBUGPCR("UART overrun: %u", lastOverrun = isoh.stats.overrun);
}
if (isoh.stats.frame_err != lastFrame) {
DEBUGPCR("UART frame error: %u", lastFrame = isoh.stats.frame_err);
}
if (isoh.stats.parity_err != lastParity) {
DEBUGPCR("UART parity error: %u", lastParity = isoh.stats.parity_err);
}
}
void iso_uart_stats_dump(void)
{
DEBUGPCRF("no_rctx: %u, rctx_sent: %u, rst: %u, pps: %u, bytes: %u, "
"parity_err: %u, frame_err: %u, overrun:%u",
isoh.stats.no_rctx, isoh.stats.rctx_sent, isoh.stats.rst,
isoh.stats.pps, isoh.stats.bytes, isoh.stats.parity_err,
isoh.stats.frame_err, isoh.stats.overrun);
}
struct simtrace_stats *iso_uart_stats_get(void)
{
return &isoh.stats;
}
/* compute the F/D ratio based on Fi and Di values */
static int compute_fidi_ratio(uint8_t fi, uint8_t di)
{
uint16_t f, d;
int ret;
if (fi >= ARRAY_SIZE(fi_table) ||
@ -139,6 +171,8 @@ static int compute_fidi_ratio(u_int8_t fi, u_int8_t di)
if (d == 0)
return -EINVAL;
/* See table 7 of ISO 7816-3: From 1000 on we divide by 1/d,
* which equals a multiplication by d */
if (di < 8)
ret = f / d;
else
@ -173,6 +207,10 @@ static void send_rctx(struct iso7816_3_handle *ih)
if (!rctx)
return;
/* Put Fi and Di into res[2] array */
ih->sh.res[0] = ih->fi;
ih->sh.res[1] = ih->di;
/* copy the simtrace header */
memcpy(rctx->data, &ih->sh, sizeof(ih->sh));
@ -180,6 +218,8 @@ static void send_rctx(struct iso7816_3_handle *ih)
memset(&ih->sh, 0, sizeof(ih->sh));
ih->rctx = NULL;
ih->stats.rctx_sent++;
}
@ -190,6 +230,7 @@ static void set_atr_state(struct iso7816_3_handle *ih, enum atr_state new_atrs)
ih->atr_idx = 0;
ih->atr_hist_len = 0;
ih->atr_last_td = 0;
ih->prot_t_supported = (1 << 0);
memset(ih->atr, 0, sizeof(ih->atr));
} else if (ih->atr_state == new_atrs)
return;
@ -248,11 +289,36 @@ static void set_state(struct iso7816_3_handle *ih, enum iso7816_3_state new_stat
ih->state = new_state;
}
static void atr_done_wait_apdu(struct iso7816_3_handle *ih)
{
set_atr_state(ih, ATR_S_DONE);
/* send off the USB context */
ih->rctx_must_be_sent = 1;
/* update the waiting time */
ih->waiting_time = 960 * di_table[ih->di] * ih->wi;
tc_etu_set_wtime(ih->waiting_time);
}
static enum iso7816_3_state
transition_to_tck(struct iso7816_3_handle *ih)
{
if (ih->prot_t_supported == 0x01) {
/* If only T=0 supported, there is no TCK but we
* immediately transition to APDUs */
atr_done_wait_apdu(ih);
return ISO7816_S_WAIT_APDU;
} else {
set_atr_state(ih, ATR_S_WAIT_TCK);
return ISO7816_S_IN_ATR;
}
}
/* determine the next ATR state based on received interface byte */
static enum atr_state next_intb_state(struct iso7816_3_handle *ih, u_int8_t ch)
static enum atr_state next_intb_state(struct iso7816_3_handle *ih, uint8_t ch)
{
switch (ih->atr_state) {
case ATR_S_WAIT_TD:
ih->prot_t_supported |= (1 << (ch & 0xf));
case ATR_S_WAIT_T0:
ih->atr_last_td = ch;
goto from_td;
@ -284,12 +350,16 @@ from_tc:
if (ih->atr_last_td & 0x80)
return ATR_S_WAIT_TD;
return ATR_S_WAIT_HIST;
/* Historical bytes are common, but optional! */
if (ih->atr_hist_len)
return ATR_S_WAIT_HIST;
else
return transition_to_tck(ih);
}
/* process an incomng ATR byte */
static enum iso7816_3_state
process_byte_atr(struct iso7816_3_handle *ih, u_int8_t byte)
process_byte_atr(struct iso7816_3_handle *ih, uint8_t byte)
{
/* add byte to ATR buffer */
ih->atr[ih->atr_idx] = byte;
@ -321,16 +391,11 @@ process_byte_atr(struct iso7816_3_handle *ih, u_int8_t byte)
ih->atr_hist_len--;
/* after all historical bytes are recieved, go to TCK */
if (ih->atr_hist_len == 0)
set_atr_state(ih, ATR_S_WAIT_TCK);
return transition_to_tck(ih);
break;
case ATR_S_WAIT_TCK:
/* FIXME: process and verify the TCK */
set_atr_state(ih, ATR_S_DONE);
/* send off the USB context */
ih->rctx_must_be_sent = 1;
/* update the waiting time */
ih->waiting_time = 960 * di_table[ih->di] * ih->wi;
tc_etu_set_wtime(ih->waiting_time);
atr_done_wait_apdu(ih);
return ISO7816_S_WAIT_APDU;
}
@ -347,9 +412,9 @@ static void set_pts_state(struct iso7816_3_handle *ih, enum pts_state new_ptss)
/* Determine the next PTS state */
static enum pts_state next_pts_state(struct iso7816_3_handle *ih)
{
u_int8_t is_resp = ih->pts_state & 0x10;
u_int8_t sstate = ih->pts_state & 0x0f;
u_int8_t *pts_ptr;
uint8_t is_resp = ih->pts_state & 0x10;
uint8_t sstate = ih->pts_state & 0x0f;
uint8_t *pts_ptr;
if (!is_resp)
pts_ptr = ih->pts_req;
@ -388,7 +453,7 @@ from_pts3:
}
static enum iso7816_3_state
process_byte_pts(struct iso7816_3_handle *ih, u_int8_t byte)
process_byte_pts(struct iso7816_3_handle *ih, uint8_t byte)
{
switch (ih->pts_state) {
case PTS_S_WAIT_REQ_PTSS:
@ -421,6 +486,7 @@ process_byte_pts(struct iso7816_3_handle *ih, u_int8_t byte)
ih->fi = byte >> 4;
ih->di = byte & 0xf;
DEBUGPCR("found Fi=%u Di=%u", ih->fi, ih->di);
ih->sh.flags |= SIMTRACE_FLAG_PPS_FIDI;
ih->pts_resp[_PTS1] = byte;
break;
case PTS_S_WAIT_RESP_PTS2:
@ -444,11 +510,13 @@ process_byte_pts(struct iso7816_3_handle *ih, u_int8_t byte)
return ISO7816_S_IN_PTS;
}
static void process_byte(struct iso7816_3_handle *ih, u_int8_t byte)
static void process_byte(struct iso7816_3_handle *ih, uint8_t byte)
{
int new_state = -1;
struct req_ctx *rctx;
ih->stats.bytes++;
if (!ih->rctx)
refill_rctx(ih);
@ -462,6 +530,7 @@ static void process_byte(struct iso7816_3_handle *ih, u_int8_t byte)
case ISO7816_S_WAIT_APDU:
if (byte == 0xff) {
new_state = process_byte_pts(ih, byte);
ih->stats.pps++;
goto out_silent;
}
case ISO7816_S_IN_APDU:
@ -479,7 +548,8 @@ static void process_byte(struct iso7816_3_handle *ih, u_int8_t byte)
rctx = ih->rctx;
if (!rctx) {
DEBUGPCR("==> Lost byte, missing rctx");
//DEBUGPCR("==> Lost byte, missing rctx");
ih->stats.no_rctx++;
return;
}
@ -511,10 +581,30 @@ void iso7816_wtime_expired(void)
set_state(&isoh, ISO7816_S_WAIT_APDU);
}
void iso_uart_flush(void)
{
send_rctx(&isoh);
}
void iso_uart_idleflush(void)
{
static struct req_ctx *last_req = NULL;
static uint16_t last_len = 0;
if (last_req == isoh.rctx &&
last_len == isoh.rctx->tot_len &&
req_ctx_count(RCTX_STATE_UDP_EP2_PENDING) == 0 &&
(isoh.sh.flags & SIMTRACE_FLAG_ATR) == 0) {
send_rctx(&isoh);
}
last_req = isoh.rctx;
last_len = isoh.rctx->tot_len;
}
static __ramfunc void usart_irq(void)
{
u_int32_t csr = usart->US_CSR;
u_int8_t octet;
uint32_t csr = usart->US_CSR;
uint8_t octet;
//DEBUGP("USART IRQ, CSR=0x%08x\n", csr);
@ -530,25 +620,46 @@ static __ramfunc void usart_irq(void)
}
if (csr & (AT91C_US_PARE|AT91C_US_FRAME|AT91C_US_OVRE)) {
uint8_t nb_err = usart->US_NER;
/* FIXME: some error has occurrerd */
//DEBUGP("NER=%02x ", nb_err);
/* clear the status */
usart->US_CR |= AT91C_US_RSTSTA;
if (csr & AT91C_US_PARE)
isoh.stats.parity_err++;
if (csr & AT91C_US_FRAME)
isoh.stats.frame_err++;
if (csr & AT91C_US_OVRE)
isoh.stats.overrun++;
}
if (csr & AT91C_US_INACK) {
/* we would have sent a NACK if INACK was not set */
usart->US_CR |= AT91C_US_RSTNACK;
}
}
/* handler for the RST input pin state change */
static void reset_pin_irq(u_int32_t pio)
static void reset_pin_irq(uint32_t pio)
{
if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, pio)) {
/* make sure to flush pending req_ctx */
iso_uart_flush();
DEBUGPCR("nRST");
set_state(&isoh, ISO7816_S_RESET);
} else {
/* make sure to flush pending req_ctx */
iso_uart_flush();
DEBUGPCR("RST");
set_state(&isoh, ISO7816_S_WAIT_ATR);
isoh.stats.rst++;
}
}
void iso_uart_dump(void)
{
u_int32_t csr = usart->US_CSR;
uint32_t csr = usart->US_CSR;
DEBUGPCR("USART CSR=0x%08x", csr);
}
@ -588,12 +699,12 @@ void iso_uart_clk_master(unsigned int master)
if (master) {
usart->US_MR = AT91C_US_USMODE_ISO7816_0 | AT91C_US_CLKS_CLOCK |
AT91C_US_CHRL_8_BITS | AT91C_US_NBSTOP_1_BIT |
AT91C_US_CKLO;
AT91C_US_CKLO | AT91C_US_INACK;
usart->US_BRGR = (0x0000 << 16) | 16;
} else {
usart->US_MR = AT91C_US_USMODE_ISO7816_0 | AT91C_US_CLKS_EXT |
AT91C_US_CHRL_8_BITS | AT91C_US_NBSTOP_1_BIT |
AT91C_US_CKLO;
AT91C_US_CKLO | AT91C_US_INACK;
usart->US_BRGR = (0x0000 << 16) | 0x0001;
}
}
@ -602,6 +713,8 @@ void iso_uart_init(void)
{
DEBUGPCR("USART Initializing");
memset(&isoh, 0, sizeof(isoh));
refill_rctx(&isoh);
/* make sure we get clock from the power management controller */
@ -611,6 +724,7 @@ void iso_uart_init(void)
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, SIMTRACE_PIO_IO, SIMTRACE_PIO_CLK);
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, SIMTRACE_PIO_nRST);
/* Configure Interrupt */
AT91F_AIC_ConfigureIt(AT91C_BASE_AIC, AT91C_ID_US0,
OPENPCD_IRQ_PRIO_USART,
AT91C_AIC_SRCTYPE_INT_HIGH_LEVEL, &usart_irq);
@ -624,7 +738,7 @@ void iso_uart_init(void)
/* ISO7816 T=0 mode with external clock input */
usart->US_MR = AT91C_US_USMODE_ISO7816_0 | AT91C_US_CLKS_EXT |
AT91C_US_CHRL_8_BITS | AT91C_US_NBSTOP_1_BIT |
AT91C_US_CKLO;
AT91C_US_CKLO | AT91C_US_INACK;
/* Disable all interrupts */
usart->US_IDR = 0xff;

View File

@ -1,6 +1,15 @@
#ifndef SIMTRACE_ISO7816_UART_H
#define SIMTRACE_ISO7816_UART_H
struct simtrace_stats *iso_uart_stats_get(void);
void iso_uart_report_errors(void);
void iso_uart_stats_dump(void);
void iso_uart_dump(void);
void iso_uart_rst(unsigned int state);
void iso_uart_rx_mode(void);
void iso_uart_clk_master(unsigned int master);
void iso_uart_init(void);
void iso_uart_flush(void);
void iso_uart_idleflush(void);
#endif

View File

@ -25,7 +25,6 @@
#include <os/led.h>
#include <os/pcd_enumerate.h>
#include <os/usb_handler.h>
#include "../openpcd.h"
#include "../simtrace.h"
#include <os/main.h>
#include <os/pio_irq.h>
@ -33,6 +32,11 @@
#include <simtrace/tc_etu.h>
#include <simtrace/iso7816_uart.h>
#include <simtrace/sim_switch.h>
#include <simtrace/prod_info.h>
#include "spi_flash.h"
#include "prod_info.h"
void _init_func(void)
{
@ -57,8 +61,22 @@ int _main_dbgu(char key)
DEBUGPCRF("main_dbgu");
switch (key) {
case 'f':
spiflash_id();
case 'g':
for (i = 1; i <= 16; i++) {
int s = spiflash_otp_get_lock(i);
DEBUGPCR("OTP region %d locked: %d", i, s);
}
break;
case 'p':
prod_info_write(0, SIMTRACE_VER(1,4,0), 0);
break;
case 'P':
{
uint32_t version;
int rc = prod_info_get(&version, NULL);
if (rc >= 0)
DEBUGPCR("Version: 0x%08x\n", version);
}
break;
case '?':
help();

View File

@ -33,6 +33,7 @@
#include <simtrace/tc_etu.h>
#include <simtrace/iso7816_uart.h>
#include <simtrace/sim_switch.h>
#include <simtrace_usb.h>
enum simtrace_md {
SIMTRACE_MD_OFF,
@ -52,6 +53,46 @@ enum simtrace_md {
SIMTRACE_PIO_IO | \
SIMTRACE_PIO_IO_T)
enum simtrace_power_mode {
SIMTRACE_PWR_OFF,
SIMTRACE_PWR_PASS,
SIMTRACE_PWR_LDO
};
void simtrace_set_power(enum simtrace_power_mode mode)
{
switch (mode) {
case SIMTRACE_PWR_PASS:
/* switch VCC_SIM pin into output mode, as in the first
* generation prototype we use it directly to supply Vcc
* to the SIM. Pin unused in v1.0(p) and v1.1p */
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
/* v1.0/1.1: pass-throguh power from the reader/phone (FPC) */
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_LDOEN);
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_nPWRFWD);
break;
case SIMTRACE_PWR_LDO:
/* switch VCC_SIM pin into output mode, as in the first
* generation prototype we use it directly to supply Vcc
* to the SIM. Pin unused in v1.0(p) and v1.1p */
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
/* v1.0/1.1: power from the internal 3.3V LDO */
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_nPWRFWD);
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_LDOEN);
break;
default:
case SIMTRACE_PWR_OFF:
/* switch VCC_SIM pin into output mode, as in the first
* generation prototype we use it directly to supply Vcc
* to the SIM. Pin unused in v1.0(p) and v1.1p */
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
/* switch all power paths off */
AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_LDOEN);
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_nPWRFWD);
break;
}
}
static void simtrace_set_mode(enum simtrace_md mode)
{
switch (mode) {
@ -62,12 +103,6 @@ static void simtrace_set_mode(enum simtrace_md mode)
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, UART1_PINS);
AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, UART1_PINS);
/* switch VCC_SIM pin into output mode, as in the first
* generation prototype we use it directly to supply Vcc
* to the SIM */
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
/* switch UART0 pins to 'ISO7816 card mode' */
AT91F_PIO_CfgInput(AT91C_BASE_PIOA, UART0_PINS);
AT91F_PIO_CfgPullupDis(AT91C_BASE_PIOA, UART0_PINS);
@ -83,8 +118,56 @@ static void simtrace_set_mode(enum simtrace_md mode)
}
}
static int simtrace_usb_in(struct req_ctx *rctx)
{
struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->data[0];
struct simtrace_stats *stats_in;
struct simtrace_stats *stats = (struct simtrace_stats *) poh->data;
switch (poh->cmd) {
case SIMTRACE_MSGT_STATS:
stats_in = iso_uart_stats_get();
memcpy(stats, stats_in, sizeof(*stats));
req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_PENDING);
break;
default:
req_ctx_set_state(rctx, RCTX_STATE_FREE);
break;
}
return 0;
}
static volatile unsigned spuirq_pc, spuirq_count = 0;
static void check_spurious_irq()
{
static unsigned last_count = 0;
if (last_count != spuirq_count) {
DEBUGPCR("SPURRIOUS IRQ %i [Old PC = %08X]", spuirq_count, spuirq_pc);
last_count = spuirq_count;
}
}
static void custom_spurious_handler(unsigned previous_pc)
{
unsigned flags;
local_irq_save(flags);
spuirq_pc = previous_pc;
spuirq_count++;
local_irq_restore(flags);
}
static void custom_spurious_entry(void)
{
register unsigned *previous_pc asm("r0");
asm("ADD R1, SP, #16; LDR R0, [R1]");
custom_spurious_handler(previous_pc);
}
void _init_func(void)
{
AT91C_BASE_AIC->AIC_SPU = (int)custom_spurious_entry;
/* low-level hardware initialization */
pio_irq_init();
iso_uart_init();
@ -92,12 +175,19 @@ void _init_func(void)
sim_switch_init();
usbtest_init();
usb_hdlr_register(&simtrace_usb_in, OPENPCD_CMD_CLS_ADC);
/* high-level protocol */
//opicc_usbapi_init();
led_switch(1, 0);
led_switch(2, 1);
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_SIM);
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_nPWRFWD);
AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SIM_LDOEN);
/* default: use local LDO to supply power */
simtrace_set_power(SIMTRACE_PWR_LDO);
iso_uart_rx_mode();
simtrace_set_mode(SIMTRACE_MD_SNIFFER);
}
@ -110,7 +200,7 @@ static void help(void)
"l: set nRST to low (active)\r\n"
"h: set nRST to high (inactive)\r\n"
"o: set nRST to input\r\n"
"r: set Rx mode for UART\r\n"
"t: ISO UART statistics\r\n"
"s: disconnect SIM bus switch\r\n"
"S: connect SIM bus switch\r\n");
}
@ -127,6 +217,9 @@ int _main_dbgu(char key)
case 'S':
simtrace_set_mode(SIMTRACE_MD_SNIFFER);
break;
case 't':
iso_uart_stats_dump();
break;
case 'r':
iso_uart_rx_mode();
break;
@ -155,6 +248,8 @@ int _main_dbgu(char key)
void _main_func(void)
{
static unsigned loopLow = 0, loopHigh = 0;
/* first we try to get rid of pending to-be-sent stuff */
usb_out_process();
@ -162,4 +257,15 @@ void _main_func(void)
usb_in_process();
udp_unthrottle();
if ((loopLow & 0xFFFF) == 0) {
DEBUGPCR("Heart beat %08X", loopHigh++);
}
if ((loopLow & 0x3F) == 0) {
iso_uart_idleflush();
}
loopLow++;
iso_uart_report_errors();
check_spurious_irq();
}

View File

@ -0,0 +1,100 @@
/* Maintainance of production information in SPI flash
* (C) 2013 by Harald Welte <laforge@gnumonks.org>
*
* 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.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <AT91SAM7.h>
#include <lib_AT91SAM7.h>
#include <openpcd.h>
#include <os/dbgu.h>
#include "spi_flash.h"
#include "prod_info.h"
#include "../simtrace.h"
#define OTP_REGION_PRODINFO 1
#define PRODINFO_MAGIC 0x51075ACE
struct simtrace_prod_info
{
/* magic value */
uint32_t magic;
/* unix timestamp of production date (0=unknown) */
uint32_t production_ts;
/* hardware version */
uint32_t version;
/* re-works applied */
uint32_t reworks;
} __attribute__((packed));
int prod_info_write(uint32_t ts, uint32_t version, uint32_t reworks)
{
struct simtrace_prod_info pi = {
.magic = PRODINFO_MAGIC,
.production_ts = ts,
.version = version,
.reworks = reworks,
};
uint8_t *pi8 = (uint8_t *) &pi;
uint32_t addr = OTP_ADDR(OTP_REGION_PRODINFO);
unsigned int rc;
int i;
spiflash_write_protect(0);
for (i = 0; i < sizeof(pi); i++) {
DEBUGPCR("0x%02x writing 0x%0x", addr+i, pi8[i]);
spiflash_write_enable(1);
rc = spiflash_otp_write(addr+i, pi8[i]);
if (rc < 0)
break;
do { } while (spiflash_read_status() & 1);
}
spiflash_otp_set_lock(OTP_REGION_PRODINFO);
spiflash_write_protect(1);
return rc;
}
int prod_info_get(uint32_t *ver, uint32_t *reworks)
{
struct simtrace_prod_info pi;
uint32_t addr = OTP_ADDR(OTP_REGION_PRODINFO);
spiflash_otp_read(addr, (uint8_t *) &pi, sizeof(pi));
if (pi.magic != PRODINFO_MAGIC)
return -1;
if (ver)
*ver = pi.version;
if (reworks)
*reworks = pi.reworks;
return 0;
}

View File

@ -0,0 +1,12 @@
#ifndef _PROD_INFO_H
#define _PROD_INFO_H
#define SIMTRACE_VER(a, b, c) (((a & 0xff) << 16) | \
((b & 0xff) << 8) | \
((c & 0xff) << 0))
int prod_info_write(uint32_t ts, uint32_t version, uint32_t reworks);
int prod_info_get(uint32_t *ver, uint32_t *reworks);
#endif

View File

@ -48,20 +48,23 @@ void sim_switch_mode(int connect_io, int connect_misc)
AT91F_PIO_SetOutput(AT91C_BASE_PIOA, SIMTRACE_PIO_SC_SW);
}
static void sw_sim_irq(u_int32_t pio)
static void sw_sim_irq(uint32_t pio)
{
if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, pio))
if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, SIMTRACE_PIO_SW_SIM))
DEBUGPCR("SIM card inserted");
else
DEBUGPCR("SIM card removed");
}
static void vcc_phone_irq(u_int32_t pio)
static void vcc_phone_irq(uint32_t pio)
{
if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, pio))
if (!AT91F_PIO_IsInputSet(AT91C_BASE_PIOA, SIMTRACE_PIO_VCC_PHONE)) {
DEBUGPCR("VCC_PHONE off");
else
/* flush any pending req_ctx to make sure the next ATR
* will be aligned to position 0 */
iso_uart_flush();
} else
DEBUGPCR("VCC_PHONE on");
}

View File

@ -1,5 +1,5 @@
/* Driver for a SST25VF040B spi flash attached to AT91SAM7 SPI
* (C) 2011 by Harald Welte <hwelte@hmw-consulting.de>
/* Driver for a SST25VF040B/S25FL032P spi flash attached to AT91SAM7 SPI
* (C) 2011-2013 by Harald Welte <laforge@gnumonks.org>
*
* 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
@ -30,11 +30,49 @@
#include <os/dbgu.h>
#include <os/pio_irq.h>
#include "spi_flash.h"
#include "../simtrace.h"
#include "../openpcd.h"
#define DEBUGPSPI DEBUGP
//#define DEBUGPSPI(x, y ...) do { } while (0)
//#define DEBUGPSPI DEBUGP
#define DEBUGPSPI(x, y ...) do { } while (0)
/* taken from Spansion S25FL032P data sheet */
/* read */
#define SPIF_CMD_READ 0x03
#define SPIF_CMD_FAST_READ 0x0B
#define SPIF_CMD_RDID 0x9F
#define SPIF_CMD_READ_ID 0x90
/* write control */
#define SPIF_CMD_WREN 0x06
#define SPIF_CMD_WRDI 0x04
/* erase */
#define SPIF_CMD_P4E 0x20 /* 4kB parameter sector erase */
#define SPIF_CMD_P8E 0x40 /* 4kB parameter sector erase */
#define SPIF_CMD_SE 0xD8 /* 64kB sector erase */
#define SPIF_CMD_BE 0x60 /* bulk erase */
/* program */
#define SPIF_CMD_PP 0x02 /* page program */
/* status & config */
#define SPIF_CMD_RDSR 0x05 /* read status register */
#define SPIF_CMD_WRR 0x01 /* write status + cfg register */
#define SPIF_CMD_RCR 0x35 /* read config register */
#define SPIF_CMD_CLSR 0x30 /* reset the erase and program fail flag */
/* power saving */
#define SPIF_CMD_DP 0xB9
#define SPIF_CMD_RES 0xAB
/* otp */
#define SPIF_CMD_OTPP 0x42 /* otp program */
#define SPIF_CMD_OTPR 0x4B /* otp read */
static const AT91PS_SPI pSPI = AT91C_BASE_SPI;
@ -50,11 +88,16 @@ void spiflash_write_protect(int on)
static __ramfunc void spi_irq(void)
{
u_int32_t status = pSPI->SPI_SR;
uint32_t status = pSPI->SPI_SR;
AT91F_AIC_ClearIt(AT91C_BASE_AIC, AT91C_ID_SPI);
}
static const uint8_t chipid_s25fl032p[3] = { 0x01, 0x02, 0x15 };
static uint8_t chip_id[3];
static uint32_t otp_supported;
void spiflash_init(void)
{
DEBUGP("spiflash_init\r\n");
@ -91,14 +134,20 @@ void spiflash_init(void)
AT91C_SPI_OVRES |
AT91C_SPI_ENDRX |
AT91C_SPI_ENDTX);
spiflash_get_id(chip_id);
if (!memcmp(chip_id, chipid_s25fl032p, sizeof(chip_id)))
otp_supported = 1;
}
static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
u_int8_t *rx_data, u_int16_t *rx_len)
static int spi_transceive(const uint8_t *tx_data, uint16_t tx_len,
uint8_t *rx_data, uint16_t *rx_len, uint16_t rx_skip)
{
u_int16_t tx_cur = 0;
u_int16_t rx_len_max = 0;
u_int16_t rx_cnt = 0;
uint16_t tx_cur = 0;
uint16_t rx_len_max = 0;
uint16_t rx_cnt = 0;
uint8_t tmp;
DEBUGPSPI("spi_transceive: enter(tx_len=%u) ", tx_len);
@ -107,38 +156,203 @@ static int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len,
*rx_len = 0;
}
/* make sure we drain any remaining rx data */
tmp = pSPI->SPI_RDR;
//AT91F_SPI_Enable(pSPI);
while (1) {
u_int32_t sr = pSPI->SPI_SR;
u_int8_t tmp;
while (1) {
uint32_t sr = pSPI->SPI_SR;
if (sr & AT91C_SPI_RDRF) {
tmp = pSPI->SPI_RDR;
rx_cnt++;
if (rx_len && *rx_len < rx_len_max)
if (rx_cnt > rx_skip &&
rx_len && *rx_len < rx_len_max)
rx_data[(*rx_len)++] = tmp;
}
if (sr & AT91C_SPI_TDRE) {
if (tx_len > tx_cur)
pSPI->SPI_TDR = tx_data[tx_cur++];
else
pSPI->SPI_TDR = 0;
}
if (rx_len) {
if (*rx_len >= rx_len_max)
break;
} else {
if (tx_len <= tx_cur)
break;
}
if (tx_cur >= tx_len && rx_cnt >= tx_len)
break;
}
/* make sure we drain any remaining rx data */
tmp = pSPI->SPI_RDR;
//AT91F_SPI_Disable(pSPI);
if (rx_data)
DEBUGPSPI(" leave(%02x %02x)\r\n", rx_data[0], rx_data[1]);
else
if (rx_data) {
int i;
DEBUGPSPI("leave(): ");
for (i = 0; i < *rx_len; i++)
DEBUGPSPI("0x%02x ", rx_data[i]);
DEBUGPSPI("\r\n");
} else
DEBUGPSPI("leave()\r\n");
return 0;
}
void spiflash_id(void)
void spiflash_get_id(uint8_t *id)
{
const u_int8_t tx_data[] = { 0x9f, 0, 0, 0 };
u_int8_t rx_data[] = { 0,0,0,0 };
u_int16_t rx_len = sizeof(rx_data);
const uint8_t tx_data[] = { SPIF_CMD_RDID, 0, 0, 0 };
uint8_t rx_data[] = { 0,0,0,0 };
uint16_t rx_len = sizeof(rx_data);
spi_transceive(tx_data, sizeof(tx_data), rx_data, &rx_len);
DEBUGP("SPI ID: %02x %02x %02x\n", rx_data[1], rx_data[2], rx_data[3]);
spi_transceive(tx_data, sizeof(tx_data), rx_data, &rx_len, 1);
DEBUGPSPI("SPI ID: %02x %02x %02x\r\n",
rx_data[0], rx_data[1], rx_data[2]);
memcpy(id, rx_data, 3);
}
int spiflash_read_status(void)
{
const uint8_t tx_data[] = { SPIF_CMD_RDSR, 0 };
uint8_t rx_data[1];
uint16_t rx_len = sizeof(rx_data);
spi_transceive(tx_data, sizeof(tx_data), rx_data, &rx_len, 1);
DEBUGPSPI("SPI Flash status: 0x%02x\r\n", rx_data[0]);
return rx_data[0];
}
void spiflash_clear_status(void)
{
const uint8_t tx_data[] = { SPIF_CMD_CLSR };
spi_transceive(tx_data, sizeof(tx_data), NULL, 0, 0);
}
int spiflash_write_enable(int enable)
{
uint8_t tx_data[1];
if (enable)
tx_data[0] = SPIF_CMD_WREN;
else
tx_data[0] = SPIF_CMD_WRDI;
spi_transceive(tx_data, sizeof(tx_data), NULL, 0, 0);
return 0;
}
int spiflash_otp_read(uint32_t otp_addr, uint8_t *out, uint16_t rx_len)
{
uint8_t tx_data[] = { SPIF_CMD_OTPR, 0, 0, 0, 0 };
if (!otp_supported) {
DEBUGP("OTP not supported!\r\n");
return -1;
}
tx_data[1] = (otp_addr >> 16) & 0xFF;
tx_data[2] = (otp_addr >> 8) & 0xFF;
tx_data[3] = (otp_addr) & 0xFF;
spi_transceive(tx_data, sizeof(tx_data), out, &rx_len, 5);
DEBUGPSPI("OTP READ(0x%x): ", otp_addr);
int i;
for (i = 0; i < rx_len; i++)
DEBUGPSPI("%02x ", out[i]);
DEBUGPSPI("\r\n");
return rx_len;
}
int spiflash_otp_write(uint32_t otp_addr, uint8_t data)
{
uint8_t tx_data[] = { SPIF_CMD_OTPP, 0, 0, 0, 0 };
if (!otp_supported) {
DEBUGP("OTP not supported!\r\n");
return -1;
}
tx_data[1] = (otp_addr >> 16) & 0xFF;
tx_data[2] = (otp_addr >> 8) & 0xFF;
tx_data[3] = (otp_addr) & 0xFF;
tx_data[4] = data;
spiflash_write_enable(1);
spi_transceive(tx_data, sizeof(tx_data), NULL, 0, 0);
spiflash_write_enable(0);
if (spiflash_read_status() & (1 << 6))
return -1;
return 0;
}
static int otp_region2addr(uint8_t region)
{
/* see Figure 10.1 of S25FL032P data sheet */
if (region > 31 || region < 1)
return -1;
else if (region > 24)
return 0x215;
else if (region > 16)
return 0x214;
else if (region > 8)
return 0x113;
else
return 0x112;
}
static int otp_region2bit(uint8_t region)
{
/* see Figure 10.1 of S25FL032P data sheet */
if (region > 31 || region < 1)
return -1;
else if (region > 24)
return region - 25;
else if (region > 16)
return region - 17;
else if (region > 8)
return region - 9;
else
return region - 1;
}
int spiflash_otp_get_lock(uint8_t region)
{
uint32_t addr;
uint8_t bit, data;
if (region > 31 || region < 1)
return -1;
bit = otp_region2bit(region);
addr = otp_region2addr(region);
spiflash_otp_read(addr, &data, 1);
if (!(data & (1 << bit)))
return 1;
else
return 0;
}
int spiflash_otp_set_lock(uint8_t region)
{
uint32_t addr;
uint8_t bit;
if (region > 31 || region < 1)
return -1;
bit = otp_region2bit(region);
addr = otp_region2addr(region);
/* clear the respective bit */
return spiflash_otp_write(addr, ~(1 << bit));
}

View File

@ -0,0 +1,19 @@
#ifndef SPI_FLASH_H
#define SPI_FLASH_H
#include <sys/types.h>
#define OTP_ADDR(x) (0x114 + ( ((x) - 1) * 16 ) )
void spiflash_init(void);
void spiflash_get_id(uint8_t *id);
int spiflash_read_status(void);
void spiflash_clear_status(void);
void spiflash_write_protect(int on);
int spiflash_write_enable(int enable);
int spiflash_otp_read(uint32_t otp_addr, uint8_t *out, uint16_t rx_len);
int spiflash_otp_write(uint32_t otp_addr, uint8_t data);
int spiflash_otp_get_lock(uint8_t region);
int spiflash_otp_set_lock(uint8_t region);
#endif

View File

@ -26,14 +26,14 @@
static AT91PS_TCB tcb;
static AT91PS_TC tcetu = AT91C_BASE_TC0;
static u_int16_t waiting_time = 9600;
static u_int16_t clocks_per_etu = 372;
static u_int16_t wait_events;
static uint16_t waiting_time = 9600;
static uint16_t clocks_per_etu = 372;
static uint16_t wait_events;
static __ramfunc void tc_etu_irq(void)
{
u_int32_t sr = tcetu->TC_SR;
static u_int16_t nr_events;
uint32_t sr = tcetu->TC_SR;
static uint16_t nr_events;
if (sr & AT91C_TC_ETRGS) {
/* external trigger, i.e. we have seen a bit on I/O */
@ -73,14 +73,14 @@ static void recalc_nr_events(void)
tcetu->TC_RC = clocks_per_etu * 12;
}
void tc_etu_set_wtime(u_int16_t wtime)
void tc_etu_set_wtime(uint16_t wtime)
{
waiting_time = wtime;
recalc_nr_events();
//DEBUGPCR("wtime=%u, actually waiting %u", wtime, wait_events * 12);
}
void tc_etu_set_etu(u_int16_t etu)
void tc_etu_set_etu(uint16_t etu)
{
clocks_per_etu = etu;
recalc_nr_events();

View File

@ -1,4 +1,4 @@
void tc_etu_set_wtime(u_int16_t wtime);
void tc_etu_set_etu(u_int16_t etu);
void tc_etu_set_wtime(uint16_t wtime);
void tc_etu_set_etu(uint16_t etu);
void tc_etu_init(void);

View File

@ -417,7 +417,7 @@ loop_rel_t: cmp r2, r3
ldr r4, =_remap_call_dfu
bx r4
.size _startup, . - _startup
.size InitReset,.-InitReset
.endfunc
/* "exit" dummy to avoid sbrk write read etc. needed by the newlib default "exit" */