Project

General

Profile

Download (3.11 KB) Statistics
| Branch: | Tag: | Revision:
1 32985a29 laforge
/* NRZ-L decoder implementation for OpenPICC
2 548ec55e (no author)
 * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
3
 *
4 32985a29 laforge
 *  This program is free software; you can redistribute it and/or modify
5
 *  it under the terms of the GNU General Public License as published by 
6
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  (at your option) any later version.
8
 *
9
 *  This program is distributed in the hope that it will be useful,
10
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 *  GNU General Public License for more details.
13
 *
14
 *  You should have received a copy of the GNU General Public License
15
 *  along with this program; if not, write to the Free Software
16
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
 *
18
 */
19
20
/*
21 548ec55e (no author)
 * speed(kbps)	106	212	424	848
22
 * etu		128/fc	64/fc	32/fc	16/fc
23
 * etu(usec)	9.4	4.7	2.35	1.18
24
 *
25
 * NRZ-L coding with logic level
26
 *
27
 * logic 1:	carrier high field amplitude (no modulation)
28
 * logic 0:	carrier low field amplitude
29
 *
30
 * Character transmission format:
31
 *	start bit:	logic 0
32
 *	data:		eight bits, lsb first
33
 *	stop bit	logic 1
34
 *
35
 * Frame Format:
36
 *
37
 * 		SOF char [EGT char, ...] EOF
38
 *
39
 * 	SOF: falling edge, 10..11 etu '0', rising edge in 1etu, 2..3etu '1'
40
 *	EGT: between 0 and 57uS 
41
 *	EOF: falling edge, 10..11 etu '0', rising edge in 1etu
42
 *
43
 *
44
 * Sampling
45
 * - sample once per bit clock, exactly in the middle of it
46
 * - synchronize CARRIER_DIV TC0 to first falling edge
47
 * - Configure CARRIER_DIV RA compare (rising edge) to be at
48
 *   etu/2 carrier clocks.
49
 * - problem: SOF 12..14etu length, therefore we cannot specify
50
 *            SOF as full start condition and then sample with 10bit
51
 *            frames :(
52
 * 
53
 */
54
55 29d8974f (no author)
#include <errno.h>
56 548ec55e (no author)
#include <sys/types.h>
57 29d8974f (no author)
#include <os/dbgu.h>
58
#include <picc/decoder.h>
59 548ec55e (no author)
60
/* currently this code will only work with oversampling_rate == 1 */
61
#define OVERSAMPLING_RATE 1
62
63 373c172a Harald Welte
static uint32_t get_next_bytesample(struct decoder_state *st,
64
				     uint8_t *parity_sample)
65 548ec55e (no author)
{
66 373c172a Harald Welte
	uint32_t ret = 0;
67
	uint8_t bits_per_sampled_char = st->algo->bits_per_sampled_char;
68
	uint8_t bytesample_mask = st->algo->bytesample_mask;
69 548ec55e (no author)
70
	/* FIXME: shift start and stop bit into parity_sample and just
71
	 * return plain 8-bit data word */
72
	
73
	/* first part of 10-databit bytesample */
74
	ret = (*(st->buf32) >> st->bit_ofs) & bytesample_mask;
75
76
	if (st->bit_ofs > 32 - bits_per_sampled_char) {
77
		/* second half of 10-databit bytesample */
78
		st->buf32++;
79
		ret |= (*(st->buf32) << (32 - st->bit_ofs));
80
	}
81
	st->bit_ofs = (st->bit_ofs + bits_per_sampled_char) % 32;
82
83
	return ret & bytesample_mask;
84
}
85
86 373c172a Harald Welte
static int nrzl_decode_sample(const uint32_t sample, uint8_t *data)
87 548ec55e (no author)
{
88
	*data = (sample >> 1) & 0xff;
89
90
	if (!(sample & 0x01)) {
91
		DEBUGPCRF("invalid start bit 0!");
92
		return -EIO;
93
	}
94
	if (sample & 0x20) {
95
		DEBUGPCRF("invalid stop bit 1!");
96
		return -EIO;
97
	}
98
99
	return 0;
100
}
101
102
static struct decoder_algo nrzl_decoder = {
103
	.oversampling_rate = OVERSAMPLING_RATE,
104
	.bits_per_sampled_char = 10 * OVERSAMPLING_RATE,
105 29d8974f (no author)
	.bytesample_mask = 0x3ff,
106 548ec55e (no author)
	.decode_sample = &nrzl_decode_sample,
107
	.get_next_bytesample = &get_next_bytesample,
108
};
Add picture from clipboard (Maximum size: 48.8 MB)