summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-13 04:37:38 +0000
committerhenryk <henryk@6dc7ffe9-61d6-0310-9af1-9938baff3ed1>2007-11-13 04:37:38 +0000
commitee1f021427f8966fb29e70eab1a3be4345af65b1 (patch)
treeda67b9d102daaea09e06be52cc53c186a17ed507
parent3d0a9bd40be2d014e0877eb623042c899d8cbe66 (diff)
Get tc_cdiv working (presumably, need to check on the oscilloscope)
Add adc code to read the field strength git-svn-id: https://svn.openpcd.org:2342/trunk@325 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r--openpicc/Makefile2
-rw-r--r--openpicc/application/adc.c45
-rw-r--r--openpicc/application/adc.h7
-rw-r--r--openpicc/application/cmd.c5
-rw-r--r--openpicc/application/main.c12
-rw-r--r--openpicc/application/tc_cdiv.c16
-rw-r--r--openpicc/application/tc_cdiv.h2
-rwxr-xr-xopenpicc/at91flash_automatic1
-rw-r--r--openpicc/config/board.h7
9 files changed, 84 insertions, 13 deletions
diff --git a/openpicc/Makefile b/openpicc/Makefile
index de01b48..a1b7a55 100644
--- a/openpicc/Makefile
+++ b/openpicc/Makefile
@@ -75,11 +75,13 @@ ARM_SRC= \
application/cmd.c \
application/env.c \
application/da.c \
+ application/adc.c \
application/pll.c \
application/pio_irq.c \
application/ssc_picc.c \
application/tc_cdiv_sync.c \
application/tc_fdt.c \
+ application/tc_cdiv.c \
os/boot/Cstartup_SAM7.c \
os/core/list.c \
os/core/queue.c \
diff --git a/openpicc/application/adc.c b/openpicc/application/adc.c
new file mode 100644
index 0000000..4aa900e
--- /dev/null
+++ b/openpicc/application/adc.c
@@ -0,0 +1,45 @@
+/* AT91 ADC for OpenPICC
+ * (C) 2007 Henryk Plötz <henryk@ploetzli.ch>
+ *
+ * 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 "openpicc.h"
+#include "board.h"
+
+#include <sys/types.h>
+#include <lib_AT91SAM7.h>
+
+static AT91S_ADC* adc = AT91C_BASE_ADC;
+
+int adc_get_field_strength(void)
+{
+ adc->ADC_CR = AT91C_ADC_START;
+ while( (adc->ADC_SR & AT91C_ADC_EOC4)==0) ;
+ return adc->ADC_CDR4;
+}
+
+void adc_init(void)
+{
+ // PRESCAL = 4 -> ADC clock = MCLK / 10 = 4.8 MHz (max is 5 MHz at 10 bit)
+ // Start time <20 us -> STARTUP=11
+ // Track and hold time >600 ns -> SHTIM=2
+ adc->ADC_MR = AT91C_ADC_TRGEN_DIS | AT91C_ADC_LOWRES_10_BIT |
+ AT91C_ADC_SLEEP_MODE | (4 << 8) | (11 << 16) | (2 << 24);
+ adc->ADC_IDR = 0xfffff;
+ adc->ADC_CHER = OPENPICC_ADC_FIELD_STRENGTH;
+}
diff --git a/openpicc/application/adc.h b/openpicc/application/adc.h
new file mode 100644
index 0000000..751055f
--- /dev/null
+++ b/openpicc/application/adc.h
@@ -0,0 +1,7 @@
+#ifndef _ADC_H
+#define _ADC_H
+
+extern int adc_get_field_strength(void);
+extern void adc_init(void);
+
+#endif
diff --git a/openpicc/application/cmd.c b/openpicc/application/cmd.c
index d7ce784..e6b8947 100644
--- a/openpicc/application/cmd.c
+++ b/openpicc/application/cmd.c
@@ -11,6 +11,8 @@
#include "openpicc.h"
#include "led.h"
#include "da.h"
+#include "adc.h"
+#include "tc_cdiv.h"
#include "tc_cdiv_sync.h"
#include "pio_irq.h"
@@ -230,6 +232,9 @@ void prvExecCommand(u_int32_t cmd, portCHAR *args) {
i = pio_irq_get_count() & (~(unsigned int)0);
DumpUIntToUSB(i);
DumpStringToUSB("\n\r");
+ DumpStringToUSB(" * current field strength: ");
+ DumpUIntToUSB(adc_get_field_strength());
+ DumpStringToUSB("\n\r");
DumpStringToUSB(
" *\n\r"
" *****************************************************\n\r"
diff --git a/openpicc/application/main.c b/openpicc/application/main.c
index 8f950ab..8d0070d 100644
--- a/openpicc/application/main.c
+++ b/openpicc/application/main.c
@@ -39,9 +39,11 @@
#include "env.h"
#include "cmd.h"
#include "da.h"
+#include "adc.h"
#include "pll.h"
#include "pio_irq.h"
#include "ssc_picc.h"
+#include "tc_cdiv.h"
#include "tc_cdiv_sync.h"
/**********************************************************************/
@@ -85,16 +87,18 @@ int main (void)
pio_irq_init();
- tc_cdiv_sync_init();
- ssc_tx_init();
- //ssc_rx_init();
-
vLedInit();
da_init();
+ adc_init();
pll_init();
+ tc_cdiv_init();
+ tc_cdiv_sync_init();
+ ssc_tx_init();
+ //ssc_rx_init();
+
xTaskCreate (vUSBCDCTask, (signed portCHAR *) "USB", TASK_USB_STACK,
NULL, TASK_USB_PRIORITY, NULL);
diff --git a/openpicc/application/tc_cdiv.c b/openpicc/application/tc_cdiv.c
index 6f06ba5..638586d 100644
--- a/openpicc/application/tc_cdiv.c
+++ b/openpicc/application/tc_cdiv.c
@@ -23,12 +23,12 @@
#include <lib_AT91SAM7.h>
#include <AT91SAM7.h>
-#include <os/dbgu.h>
+#include "dbgu.h"
-#include "../openpcd.h"
-#include <os/tc_cdiv.h>
+#include "openpicc.h"
+#include "tc_cdiv.h"
-static AT91PS_TCB tcb = AT91C_BASE_TCB;
+AT91PS_TCB tcb = AT91C_BASE_TCB;
/* set carrier divider to a specific */
void tc_cdiv_set_divider(u_int16_t div)
@@ -56,10 +56,10 @@ void tc_cdiv_init(void)
{
/* Cfg PA28(TCLK1), PA0(TIOA0), PA1(TIOB0), PA20(TCLK2) as Periph B */
AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0,
- OPENPCD_PIO_CARRIER_IN |
- OPENPCD_PIO_CARRIER_DIV_OUT |
- OPENPCD_PIO_CDIV_HELP_OUT |
- OPENPCD_PIO_CDIV_HELP_IN);
+ OPENPICC_PIO_CARRIER_IN |
+ OPENPICC_PIO_CARRIER_DIV_OUT |
+ OPENPICC_PIO_CDIV_HELP_OUT |
+ OPENPICC_PIO_CDIV_HELP_IN);
AT91F_PMC_EnablePeriphClock(AT91C_BASE_PMC,
((unsigned int) 1 << AT91C_ID_TC0));
diff --git a/openpicc/application/tc_cdiv.h b/openpicc/application/tc_cdiv.h
index d5744f9..33ff5b9 100644
--- a/openpicc/application/tc_cdiv.h
+++ b/openpicc/application/tc_cdiv.h
@@ -5,7 +5,7 @@
#include <sys/types.h>
#include <lib_AT91SAM7.h>
-static AT91PS_TCB tcb;
+extern AT91PS_TCB tcb;
extern void tc_cdiv_phase_add(int16_t inc);
extern void tc_cdiv_set_divider(u_int16_t div);
diff --git a/openpicc/at91flash_automatic b/openpicc/at91flash_automatic
index 8f92989..1c607f8 100755
--- a/openpicc/at91flash_automatic
+++ b/openpicc/at91flash_automatic
@@ -88,6 +88,7 @@ while true; do
else
echo "UART at $UART"
fi
+ sleep 1
if do_flash; then
echo
attention
diff --git a/openpicc/config/board.h b/openpicc/config/board.h
index 80ae94b..813a7a3 100644
--- a/openpicc/config/board.h
+++ b/openpicc/config/board.h
@@ -71,6 +71,13 @@
#define OPENPICC_PIO_AB_DETECT AT91C_PIO_PA22
#define OPENPICC_PIO_PLL_INHIBIT AT91C_PIO_PA24
+#define OPENPICC_ADC_FIELD_STRENGTH AT91C_ADC_CH4
+
+#define OPENPICC_PIO_CARRIER_IN AT91C_PA28_TCLK1
+#define OPENPICC_PIO_CARRIER_DIV_OUT AT91C_PA1_TIOB0
+#define OPENPICC_PIO_CDIV_HELP_OUT AT91C_PA0_TIOA0
+#define OPENPICC_PIO_CDIV_HELP_IN AT91C_PA29_TCLK2
+
#define OPENPICC_IRQ_PRIO_SSC (AT91C_AIC_PRIOR_HIGHEST-1)
#define OPENPCD_IRQ_PRIO_TC_FDT (AT91C_AIC_PRIOR_LOWEST+3)
personal git repositories of Harald Welte. Your mileage may vary