From 3b42a77d3fd438bbea8dfdbe1b7f9dcf4ae11481 Mon Sep 17 00:00:00 2001 From: "(no author)" <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> Date: Sun, 10 Sep 2006 14:37:15 +0000 Subject: add PWM and load modulation to main_openpicc git-svn-id: https://svn.openpcd.org:2342/trunk@172 6dc7ffe9-61d6-0310-9af1-9938baff3ed1 --- openpcd/firmware/Makefile | 5 +- openpcd/firmware/src/picc/load_modulation.c | 20 +++-- openpcd/firmware/src/picc/main_openpicc.c | 109 +++++++++++++++++++++++++++- 3 files changed, 119 insertions(+), 15 deletions(-) diff --git a/openpcd/firmware/Makefile b/openpcd/firmware/Makefile index e700012..fc62dbe 100644 --- a/openpcd/firmware/Makefile +++ b/openpcd/firmware/Makefile @@ -87,18 +87,19 @@ SRCARM += src/os/pcd_enumerate.c src/os/fifo.c src/os/dbgu.c \ src/os/led.c src/os/req_ctx.c src/os/trigger.c \ src/os/main.c src/os/syscalls.c src/os/usb_handler.c \ src/os/usb_benchmark.c src/os/dfu.c src/start/Cstartup_SAM7.c \ - src/os/tc_cdiv.c src/os/pit.c + src/os/tc_cdiv.c src/os/pit.c src/os/pwm.c ifdef PCD # PCD support code SRCARM += src/pcd/rc632.c src/pcd/rc632_highlevel.c \ - src/pcd/pwm.c src/pcd/rfid_layer2_iso14443a.c + src/pcd/rfid_layer2_iso14443a.c # finally, the actual main application SRCARM += src/pcd/$(TARGET).c else # PICC support code 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/load_modulation.c \ src/picc/decoder_nrzl.c src/picc/poti.c src/picc/pll.c # finally, the actual main application SRCARM += src/picc/$(TARGET).c diff --git a/openpcd/firmware/src/picc/load_modulation.c b/openpcd/firmware/src/picc/load_modulation.c index d2af070..65c59d1 100644 --- a/openpcd/firmware/src/picc/load_modulation.c +++ b/openpcd/firmware/src/picc/load_modulation.c @@ -1,6 +1,3 @@ - -#ifdef CONFIG_PICCSIM - #include #include @@ -12,20 +9,21 @@ void load_mod_level(u_int8_t level) level = 3; if (level & 0x1) - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD1); + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD1); else - AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD1); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD1); if (level & 0x2) - AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD2); + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD2); else - AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD2); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD2); } void load_mod_init(void) { - AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD1); - AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPCD_PIO_LOAD2); -} + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD1); + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD2); -#endif /* CONFIG_PICCSIM */ + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD1); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, OPENPICC_PIO_LOAD2); +} diff --git a/openpcd/firmware/src/picc/main_openpicc.c b/openpcd/firmware/src/picc/main_openpicc.c index 3b3ba2a..80f6dbf 100644 --- a/openpcd/firmware/src/picc/main_openpicc.c +++ b/openpcd/firmware/src/picc/main_openpicc.c @@ -8,18 +8,46 @@ #include #include "../openpcd.h" #include +#include +#include #include +#include + +static const u_int16_t cdivs[] = { 128, 64, 32, 16 }; +static int cdiv_idx = 0; + +static u_int16_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 u_int8_t load_mod = 0; void _init_func(void) { pll_init(); poti_init(); + load_mod_init(); tc_cdiv_init(); + pwm_init(); //adc_init(); //ssc_rx_init(); // ssc_tx_init(); } +static void help(void) +{ + DEBUGPCR("q: poti decrease q: poti increase\r\n" + "e: poti retransmit P: PLL inhibit toggle"); + DEBUGPCR("o: decrease duty p: increase duty\r\n" + "k: stop pwm l: start pwn\r\n" + "n: decrease freq m: incresae freq"); + DEBUGPCR("u: PA23 const 1 y: PA23 const 0\r\n" + "t: PA23 PWM0\r\n" + "{: decrease cdiv_idx }: increse cdiv idx\r\n" + "<: decrease cdiv_phase >: increase cdiv_phase"); +} + int _main_dbgu(char key) { unsigned char value; @@ -36,7 +64,7 @@ int _main_dbgu(char key) DEBUGPCRF("Poti: %u", poti); break; case 'w': - if (poti < 126) + if (poti < 127) poti++; poti_comp_carr(poti); DEBUGPCRF("Poti: %u", poti); @@ -45,13 +73,90 @@ int _main_dbgu(char key) poti_comp_carr(poti); DEBUGPCRF("Poti: %u", poti); break; - case 'p': + case 'P': pll_inh++; pll_inh &= 0x01; pll_inhibit(pll_inh); DEBUGPCRF("PLL Inhibit: %u\n", pll_inh); break; + case 'o': + if (duty_percent >= 1) + duty_percent--; + pwm_duty_set_percent(0, duty_percent); + break; + case 'p': + if (duty_percent <= 99) + duty_percent++; + pwm_duty_set_percent(0, duty_percent); + break; + case 'k': + pwm_stop(0); + break; + case 'l': + pwm_start(0); + break; + case 'n': + if (pwm_freq_idx > 0) { + pwm_freq_idx--; + pwm_stop(0); + pwm_freq_set(0, pwm_freq[pwm_freq_idx]); + pwm_start(0); + pwm_duty_set_percent(0, 22); /* 22% of 9.43uS = 2.07uS */ + } + break; + case 'm': + if (pwm_freq_idx < ARRAY_SIZE(pwm_freq)-1) { + pwm_freq_idx++; + pwm_stop(0); + pwm_freq_set(0, pwm_freq[pwm_freq_idx]); + pwm_start(0); + pwm_duty_set_percent(0, 22); /* 22% of 9.43uS = 2.07uS */ + } + break; + case 'u': + DEBUGPCRF("PA23 output high"); + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23); + AT91F_PIO_SetOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23); + break; + case 'y': + DEBUGPCRF("PA23 output low"); + AT91F_PIO_CfgOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23); + AT91F_PIO_ClearOutput(AT91C_BASE_PIOA, AT91C_PIO_PA23); + break; + case 't': + DEBUGPCRF("PA23 PeriphA (PWM)"); + AT91F_PIO_CfgPeriph(AT91C_BASE_PIOA, 0, AT91C_PA23_PWM0); + break; + case '?': + help(); + break; + case '<': + tc_cdiv_phase_inc(); + break; case '>': + tc_cdiv_phase_dec(); + break; + case '{': + if (cdiv_idx > 0) + cdiv_idx--; + tc_cdiv_set_divider(cdivs[cdiv_idx]); + break; + case '}': + if (cdiv_idx < ARRAY_SIZE(cdivs)-1) + cdiv_idx++; + tc_cdiv_set_divider(cdivs[cdiv_idx]); + break; + case 'v': + if (load_mod > 0) + load_mod--; + load_mod_level(load_mod); + DEBUGPCR("load_mod: %u\n", load_mod); + break; + case 'b': + if (load_mod < 3) + load_mod++; + load_mod_level(load_mod); + DEBUGPCR("load_mod: %u\n", load_mod); break; } -- cgit v1.2.3