summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author(no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-09-09 17:20:40 +0000
committer(no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2006-09-09 17:20:40 +0000
commit29d8974fe20c8d9d35adbcced625d661e51a6c26 (patch)
tree5812fef4d0d297f2767ea98427efdb92544b8643
parent48fbcc6bff88cddfee7288489c96b93bb1436875 (diff)
- tons of compile fixes for untested PICC code
git-svn-id: https://svn.openpcd.org:2342/trunk@160 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r--openpcd/firmware/Makefile4
-rw-r--r--openpcd/firmware/src/picc/adc.c112
-rw-r--r--openpcd/firmware/src/picc/decoder.c15
-rw-r--r--openpcd/firmware/src/picc/decoder.h8
-rw-r--r--openpcd/firmware/src/picc/decoder_miller.c11
-rw-r--r--openpcd/firmware/src/picc/decoder_nrzl.c8
-rw-r--r--openpcd/firmware/src/picc/main_openpicc.c1
-rw-r--r--openpcd/firmware/src/picc/ssc_picc.c3
8 files changed, 142 insertions, 20 deletions
diff --git a/openpcd/firmware/Makefile b/openpcd/firmware/Makefile
index 1098c4f..f4ff886 100644
--- a/openpcd/firmware/Makefile
+++ b/openpcd/firmware/Makefile
@@ -97,7 +97,9 @@ SRCARM += src/pcd/rc632.c src/pcd/rc632_highlevel.c \
SRCARM += src/pcd/$(TARGET).c
else
# PICC support code
-SRCARM += src/picc/tc_fdt.c src/picc/ssc_picc.c
+SRCARM += src/picc/tc_fdt.c src/picc/ssc_picc.c src/picc/adc.c \
+ src/picc/decoder.c src/picc/decoder_miller.c \
+ src/picc/decoder_nrzl.c
# finally, the actual main application
SRCARM += src/picc/$(TARGET).c
endif
diff --git a/openpcd/firmware/src/picc/adc.c b/openpcd/firmware/src/picc/adc.c
new file mode 100644
index 0000000..1438a08
--- /dev/null
+++ b/openpcd/firmware/src/picc/adc.c
@@ -0,0 +1,112 @@
+/* AT91SAM7 ADC controller routines for OpenPCD / OpenPICC
+ * (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
+ *
+ */
+
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <AT91SAM7.h>
+#include <lib_AT91SAM7.h>
+#include <openpcd.h>
+
+#include <os/usb_handler.h>
+#include "../openpcd.h"
+#include <os/dbgu.h>
+
+#define OPENPICC_ADC_CH_FIELDSTR AT91C_ADC_CH4
+#define OPENPICC_ADC_CH_PLL_DEM AT91C_ADC_CH5
+
+static const AT91PS_ADC adc = AT91C_BASE_ADC;
+
+enum adc_states {
+ ADC_NONE,
+ ADC_READ_CONTINUOUS,
+ ADC_READ_CONTINUOUS_USB,
+ ADC_READ_SINGLE,
+};
+
+struct adc_state {
+ enum adc_states state;
+ struct req_ctx *rctx;
+};
+
+static struct adc_state adc_state;
+
+static void adc_int(void)
+{
+ u_int32_t sr = adc->ADC_SR;
+ struct req_ctx *rctx = adc_state.rctx;
+ u_int16_t *val = (u_int16_t *) &(rctx->tx.data[rctx->tx.tot_len]);
+
+ switch (adc_state.state) {
+ case ADC_NONE:
+ break;
+ case ADC_READ_CONTINUOUS_USB:
+ if (sr & AT91C_ADC_ENDRX) {
+ /* rctx full, get rid of it */
+ req_ctx_set_state(rctx, RCTX_STATE_UDP_EP2_PENDING);
+ adc_state.state = ADC_NONE;
+ adc_state.rctx = NULL;
+
+ /* Disable EOC interrupts since we don't want to
+ * re-start conversion any further*/
+ AT91F_ADC_DisableIt(AT91C_BASE_ADC,
+ AT91C_ADC_EOC4|AT91C_ADC_EOC5);
+ AT91F_PDC_DisableRx(AT91C_BASE_PDC_ADC);
+ }
+
+ if (sr & (AT91C_ADC_EOC4|AT91C_ADC_EOC5)) {
+ /* re-start conversion, since we need more values */
+ AT91F_ADC_StartConversion(adc);
+ }
+ break;
+ }
+}
+
+#if 0
+u_int16_t adc_read_fieldstr(void)
+{
+ return adc->ADC_CDR4;
+}
+
+u_int16_T adc_read_pll_dem(void)
+{
+ return adc
+}
+#endif
+
+static int adc_usb_in(struct req_ctx *rctx)
+{
+ struct openpcd_hdr *poh = (struct openpcd_hdr *) &rctx->rx.data[0];
+ struct openpcd_hdr *pih = (struct openpcd_hdr *) &rctx->tx.data[0];
+
+ switch (poh->cmd) {
+ case OPENPCD_CMD_ADC_READ:
+ //channel = poh->reg;
+ if (adc_state.rctx) {
+ /* FIXME: do something */
+ req_ctx_put(rctx);
+ }
+
+ adc_state.state = ADC_READ_CONTINUOUS_USB;
+ adc_state.rctx = rctx;
+ AT91F_ADC_EnableChannel(AT91C_BASE_ADC, OPENPICC_ADC_CH_FIELDSTR);
+ AT91F_ADC_EnableIt(AT91C_BASE_ADC, AT91C_ADC_ENDRX |
+ OPENPICC_ADC_CH_FIELDSTR);
+ AT91F_PDC_SetRx(AT91C_BASE_PDC_ADC, rctx->rx.data, 60 /*FIXME*/);
+ AT91F_PDC_EnableRx(AT91C_BASE_PDC_ADC);
+ break;
+ }
+}
+
+int adc_init(void)
+{
+ AT91F_ADC_CfgPMC();
+ AT91F_ADC_CfgTimings(AT91C_BASE_ADC, 48 /*MHz*/, 5 /*MHz*/,
+ 20/*uSec*/, 700/*nSec*/);
+ AT91F_ADC_EnableChannel(AT91C_BASE_ADC, OPENPICC_ADC_CH_FIELDSTR |
+ OPENPICC_ADC_CH_PLL_DEM);
+
+ usb_hdlr_register(&adc_usb_in, OPENPCD_CMD_CLS_ADC);
+}
diff --git a/openpcd/firmware/src/picc/decoder.c b/openpcd/firmware/src/picc/decoder.c
index 2ca051f..9f9191a 100644
--- a/openpcd/firmware/src/picc/decoder.c
+++ b/openpcd/firmware/src/picc/decoder.c
@@ -2,8 +2,11 @@
* (C) 2006 by Harald Welte <hwelte@hmw-consulting.de>
*/
+#include <errno.h>
#include <sys/types.h>
-#include "decoder.h"
+#include <picc/decoder.h>
+
+#include <os/dbgu.h>
static struct decoder_algo *decoder_algo[DECODER_NUM_ALGOS];
@@ -21,7 +24,7 @@ static int get_next_data(struct decoder_state *st, u_int8_t *data)
int decoder_decode(u_int8_t algo, const char *sample_buf,
int sample_buf_size, char *data_buf)
{
- int ret;
+ int i, ret;
struct decoder_state st;
if (algo >= DECODER_NUM_ALGOS)
@@ -45,17 +48,17 @@ int decoder_decode(u_int8_t algo, const char *sample_buf,
return i+1;
}
-int decoder_register(int algo, struct decoder_algo *algo)
+int decoder_register(int algnum, struct decoder_algo *algo)
{
- if (algo >= DECODER_NUM_ALGOS)
+ if (algnum >= DECODER_NUM_ALGOS)
return -EINVAL;
- decoder_algos[algo] = algo;
+ decoder_algo[algnum] = algo;
return 0;
}
-int decoder_init(void)
+void decoder_init(void)
{
decoder_register(DECODER_MILLER, &miller_decoder);
decoder_register(DECODER_NRZL, &nrzl_decoder);
diff --git a/openpcd/firmware/src/picc/decoder.h b/openpcd/firmware/src/picc/decoder.h
index 950efd2..aef0e20 100644
--- a/openpcd/firmware/src/picc/decoder.h
+++ b/openpcd/firmware/src/picc/decoder.h
@@ -6,7 +6,7 @@ struct decoder_state;
struct decoder_algo {
u_int8_t oversampling_rate;
u_int8_t bits_per_sampled_char;
- u_int8_t bytesample_mask;
+ 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);
};
@@ -18,7 +18,7 @@ struct decoder_state {
const u_int32_t *buf32;
};
-extern int decoder_register(int algo, struct decoder_algo *algo);
+extern int decoder_register(int algnum, struct decoder_algo *algo);
extern int decoder_decode(u_int8_t algo, const char *sample_buf,
int sample_buf_size, char *data_buf);
@@ -26,7 +26,7 @@ extern int decoder_decode(u_int8_t algo, const char *sample_buf,
#define DECODER_NRZL 1
#define DECODER_NUM_ALGOS 2
-extern struct decoder_algo nrzl_decoder;
-extern struct decoder_algo miller_decoder;
+static struct decoder_algo nrzl_decoder;
+static struct decoder_algo miller_decoder;
#endif
diff --git a/openpcd/firmware/src/picc/decoder_miller.c b/openpcd/firmware/src/picc/decoder_miller.c
index 4036511..1394a17 100644
--- a/openpcd/firmware/src/picc/decoder_miller.c
+++ b/openpcd/firmware/src/picc/decoder_miller.c
@@ -25,7 +25,9 @@
*/
#include <sys/types.h>
-#include "decoder.h"
+
+#include <os/dbgu.h>
+#include <picc/decoder.h>
#define OVERSAMPLING_RATE 4
@@ -47,7 +49,7 @@ static u_int8_t miller_decode_sampled_bit(u_int32_t sampled_bit)
return 0;
break;
default:
- DEBUGP("unknown sequence sample `%x' ", bit_sample);
+ DEBUGP("unknown sequence sample `%x' ", sampled_bit);
return 2;
break;
}
@@ -57,7 +59,7 @@ static u_int8_t miller_decode_sampled_bit(u_int32_t sampled_bit)
static int miller_decode_sample(u_int32_t sample, u_int8_t *data)
{
u_int8_t ret = 0;
- int err, i;
+ unsigned int i;
for (i = 0; i < sizeof(sample)/OVERSAMPLING_RATE; i++) {
u_int8_t bit = miller_decode_sampled_bit(sample & 0xf);
@@ -83,7 +85,6 @@ static u_int32_t get_next_bytesample(struct decoder_state *ms,
u_int8_t *parity_sample)
{
u_int32_t ret = 0;
- u_int8_t parity_sample;
/* get remaining bits from the current word */
ret = *(ms->buf32) >> ms->bit_ofs;
@@ -91,7 +92,7 @@ static u_int32_t get_next_bytesample(struct decoder_state *ms,
ms->buf32++;
/* if required, get remaining bits from next word */
- if (bit_ofs)
+ if (ms->bit_ofs)
ret |= *(ms->buf32) << (32 - ms->bit_ofs);
*parity_sample = (*(ms->buf32) >> ms->bit_ofs & 0xf);
diff --git a/openpcd/firmware/src/picc/decoder_nrzl.c b/openpcd/firmware/src/picc/decoder_nrzl.c
index bb297db..a1b79aa 100644
--- a/openpcd/firmware/src/picc/decoder_nrzl.c
+++ b/openpcd/firmware/src/picc/decoder_nrzl.c
@@ -35,8 +35,10 @@
*
*/
+#include <errno.h>
#include <sys/types.h>
-#include "decoder.h"
+#include <os/dbgu.h>
+#include <picc/decoder.h>
/* currently this code will only work with oversampling_rate == 1 */
#define OVERSAMPLING_RATE 1
@@ -64,7 +66,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 u_int32_t sample, u_int8_t *data)
{
*data = (sample >> 1) & 0xff;
@@ -83,7 +85,7 @@ static int nrzl_decode_sample(const u_int32_t sample, u_int8_t data)
static struct decoder_algo nrzl_decoder = {
.oversampling_rate = OVERSAMPLING_RATE,
.bits_per_sampled_char = 10 * OVERSAMPLING_RATE,
- .bytesample_mask = 0x3ff;
+ .bytesample_mask = 0x3ff,
.decode_sample = &nrzl_decode_sample,
.get_next_bytesample = &get_next_bytesample,
};
diff --git a/openpcd/firmware/src/picc/main_openpicc.c b/openpcd/firmware/src/picc/main_openpicc.c
index 795f460..59e5bac 100644
--- a/openpcd/firmware/src/picc/main_openpicc.c
+++ b/openpcd/firmware/src/picc/main_openpicc.c
@@ -12,6 +12,7 @@
void _init_func(void)
{
tc_cdiv_init();
+ adc_init();
ssc_rx_init();
// ssc_tx_init();
}
diff --git a/openpcd/firmware/src/picc/ssc_picc.c b/openpcd/firmware/src/picc/ssc_picc.c
index ac371b7..2949da6 100644
--- a/openpcd/firmware/src/picc/ssc_picc.c
+++ b/openpcd/firmware/src/picc/ssc_picc.c
@@ -255,7 +255,7 @@ static void ssc_irq(void)
case SSC_MODE_14443A_STANDARD:
if (ssc_sr & (AT91C_SSC_ENDRX | AT91C_SSC_RXBUFF)) {
-#if 0
+#if 1
/* Mark primary RCTX as ready to send for usb */
req_ctx_set_state(ssc_state.rx_ctx[0],
RCTX_STATE_UDP_EP2_PENDING);
@@ -319,6 +319,7 @@ static int ssc_usb_in(struct req_ctx *rctx)
/* FIXME: implement this */
switch (poh->cmd) {
case OPENPCD_CMD_SSC_READ:
+
break;
case OPENPCD_CMD_SSC_WRITE:
break;
personal git repositories of Harald Welte. Your mileage may vary