From: Christian Lamparter Date: Sat, 23 Nov 2013 13:21:48 +0000 (+0100) Subject: carl9170 firmware: reorganize pattern generator X-Git-Url: https://jxself.org/git/?p=carl9170fw.git;a=commitdiff_plain;h=593709de14b8c10bce1164eeb22fa7b77a9e4bce carl9170 firmware: reorganize pattern generator Prepare this feature so it can be merged into the main branch. Signed-off-by: Christian Lamparter --- diff --git a/carlfw/CMakeLists.txt b/carlfw/CMakeLists.txt index 124352e..cacccd9 100644 --- a/carlfw/CMakeLists.txt +++ b/carlfw/CMakeLists.txt @@ -17,7 +17,7 @@ set(CARLFW_CFLAGS "${CARLFW_CFLAGS_DEF} ${CARLFW_CFLAGS_EXTRA} ${CARLFW_CFLAGS_A include_directories (../include/linux ../include/shared ../include include) set(carl9170_main_src src/main.c src/wlan.c src/wlanrx.c src/wlantx.c - src/fw.c src/gpio.c src/timer.c + src/fw.c src/gpio.c src/timer.c src/pattern_generator.c src/uart.c src/dma.c src/hostif.c src/reboot.S src/printf.c src/rf.c src/cam.c src/wol.c) diff --git a/carlfw/Kconfig b/carlfw/Kconfig index 4cec81c..caa3848 100644 --- a/carlfw/Kconfig +++ b/carlfw/Kconfig @@ -85,7 +85,7 @@ config CARL9170FW_EXPERIMENTAL def_bool y prompt "Experimental Features" -config CARL9170FW_RADAR +config CARL9170FW_PATTERN_GENERATOR def_bool n prompt "Radar pattern generator" depends on CARL9170FW_EXPERIMENTAL diff --git a/carlfw/include/carl9170.h b/carlfw/include/carl9170.h index ed5120d..26a0975 100644 --- a/carlfw/include/carl9170.h +++ b/carlfw/include/carl9170.h @@ -33,7 +33,6 @@ #include "dma.h" #include "usb.h" #include "cmd.h" -#include "radar.h" struct carl9170_bar_ctx { uint8_t ta[6]; diff --git a/carlfw/include/pattern_generator.h b/carlfw/include/pattern_generator.h new file mode 100644 index 0000000..e08f9fc --- /dev/null +++ b/carlfw/include/pattern_generator.h @@ -0,0 +1,42 @@ +/* + * carl9170 firmware - used by the ar9170 wireless device + * + * Pattern Generator definitions + * + * Copyright 2012, 2013 Christian Lamparter + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#ifndef __CARL9170FW_RADAR_H +#define __CARL9170FW_RADAR_H + +#include "generated/autoconf.h" +#include "types.h" +#include "compiler.h" +#include "fwdesc.h" +#include "pattern.h" + +#if defined(CARL9170FW_PATTERN_GENERATOR) +void radar_pattern_generator(void); + +#else +static inline void radar_pattern_generator(void) +{ +} + +#endif + +#endif /* __CARL9170FW_RADAR_H */ diff --git a/carlfw/include/radar.h b/carlfw/include/radar.h deleted file mode 100644 index 864882a..0000000 --- a/carlfw/include/radar.h +++ /dev/null @@ -1,157 +0,0 @@ -/* - * carl9170 firmware - used by the ar9170 wireless device - * - * Radar pulse definitions - * - * Copyright 2012 Christian Lamparter - * - * 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., - * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - */ - -#ifndef __CARL9170FW_RADAR_H -#define __CARL9170FW_RADAR_H - -#include "generated/autoconf.h" -#include "types.h" -#include "compiler.h" -#include "fwdesc.h" - -enum RADAR_TYPE { - NO_RADAR = 0, - ONE_KHZ, - TEN_KHZ, - - ONE_TWO_KHZ, - - FCC1, - FCC4, - - ETSIFIXED, - - /* keep last */ - __CARL9170FW_NUM_RADARS -}; - -struct radar_info { - unsigned int pulses; - const struct radar_info_pattern *pattern; -}; - -struct radar_info_pattern { - unsigned int pulse_width; - unsigned int pulse_interval; - uint32_t pulse_pattern; - uint32_t pulse_mode; -}; - -static const struct radar_info_pattern radar_NO_RADAR[0] = { }; -static const struct radar_info_pattern radar_ONE_KHZ[] = { - { - .pulse_width = 1, - .pulse_interval = 1000, - .pulse_pattern = 0xa7438080, - .pulse_mode = 0x5f01, - }, -}; - -static const struct radar_info_pattern radar_TEN_KHZ[] = { - { - .pulse_width = 1, - .pulse_interval = 100, - .pulse_pattern = 0x436f0001, - .pulse_mode = 0x5f01, - }, -}; - -static const struct radar_info_pattern radar_ONE_TWO_KHZ[] = { - { - .pulse_width = 1, - .pulse_interval = 1000, - .pulse_pattern = 0xa7438080, - .pulse_mode = 0x5f01, - }, - - { - .pulse_width = 10, - .pulse_interval = 500, - .pulse_pattern = 0xa7431001, - .pulse_mode = 0x5f01, - }, -}; - -/* - * Data taken from: - * - */ - -/* FCC Test Signal 1 - 1us pulse, 1428 us interval */ -static const struct radar_info_pattern radar_FCC1[] = { - { - .pulse_width = 1, - .pulse_interval = 1428, - .pulse_pattern = 0xa7438080, - .pulse_mode = 0x5f01, - }, -}; - -/* FCC Test Signal 4 - 11-20us pulse, 200-500 us interval */ -static const struct radar_info_pattern radar_FCC4[] = { - { - .pulse_width = 11, - .pulse_interval = 200, - .pulse_pattern = 0xf3128008, - .pulse_mode = 0x5f01, - }, -}; - -/* ETSI Test Signal 1 (Fixed) - 1us Pulse, 750 us interval */ -static const struct radar_info_pattern radar_ETSIFIXED[] = { - { - .pulse_width = 1, - .pulse_interval = 750, - .pulse_pattern = 0x8a5f8080, - .pulse_mode = 0x5f01, - }, -}; - - -#define ADD_RADAR(name) [name] = { .pulses = ARRAY_SIZE(radar_## name), .pattern = radar_## name } - -static const struct radar_info radars[__CARL9170FW_NUM_RADARS] = { - ADD_RADAR(NO_RADAR), - ADD_RADAR(ONE_KHZ), - ADD_RADAR(TEN_KHZ), - ADD_RADAR(ONE_TWO_KHZ), - ADD_RADAR(FCC1), - ADD_RADAR(FCC4), - ADD_RADAR(ETSIFIXED), -}; - -#define MAP_ENTRY(idx) [idx] = { .index = idx, .name = # idx , } -#define NAMED_MAP_ENTRY(idx, named) [idx] = {.index = idx, .name = named, } - -static const struct carl9170fw_radar_map_entry radar_names[__CARL9170FW_NUM_RADARS] = { - MAP_ENTRY(NO_RADAR), - MAP_ENTRY(ONE_KHZ), - MAP_ENTRY(TEN_KHZ), - MAP_ENTRY(ONE_TWO_KHZ), - - MAP_ENTRY(FCC1), - MAP_ENTRY(FCC4), - - MAP_ENTRY(ETSIFIXED), -}; - -#endif /* __CARL9170FW_RADAR_H */ diff --git a/carlfw/src/fw.c b/carlfw/src/fw.c index be9001a..a999e2d 100644 --- a/carlfw/src/fw.c +++ b/carlfw/src/fw.c @@ -21,6 +21,7 @@ */ #include "carl9170.h" #include "fwdsc.h" +#include "pattern_generator.h" #define FILL(small, big, more...) \ .small = { \ @@ -101,7 +102,7 @@ const struct carl9170_firmware_descriptor __section(fwdsc) __visible carl9170fw_ .release = CARL9170FW_VERSION_GIT), -#ifdef CONFIG_CARL9170FW_RADAR +#if defined(CARL9170FW_PATTERN_GENERATOR) FILL(radar, RADAR, .soft_radar = cpu_to_le32(&fw.wlan.soft_radar), .num_radars = __CARL9170FW_NUM_RADARS, diff --git a/carlfw/src/main.c b/carlfw/src/main.c index 50415fe..fc44d50 100644 --- a/carlfw/src/main.c +++ b/carlfw/src/main.c @@ -31,7 +31,7 @@ #include "wl.h" #include "rf.h" #include "usb.h" -#include "radar.h" +#include "pattern_generator.h" #define AR9170_WATCH_DOG_TIMER 0x100 @@ -107,38 +107,6 @@ static void tally_update(void) fw.counter++; } -#ifdef CONFIG_CARL9170FW_RADAR -static void radar_pattern_generator(void) -{ - if (fw.phy.state == CARL9170_PHY_ON) { - if (fw.wlan.soft_radar == NO_RADAR || - fw.wlan.soft_radar >= __CARL9170FW_NUM_RADARS) - return; - - const struct radar_info *radar = &radars[fw.wlan.soft_radar]; - if (radar->pulses >= fw.wlan.pattern_index) { - fw.wlan.pattern_index = 0; - } - - if (radar->pulses > fw.wlan.pattern_index) { - const struct radar_info_pattern *pattern = &radar->pattern[fw.wlan.pattern_index]; - if (is_after_usecs(fw.wlan.radar_last, pattern->pulse_interval)) { - fw.wlan.radar_last = get_clock_counter(); - set(0x1C3BC0, pattern->pulse_pattern); - set(0x1C3BBC, pattern->pulse_mode); - udelay(pattern->pulse_width); - set(0x1C3BBC, ~pattern->pulse_mode); - fw.wlan.pattern_index++; - } - } - } -} -#else -static void radar_pattern_generator(void) -{ -} -#endif /* CONFIG_CARL9170FW_RADAR */ - static void __noreturn main_loop(void) { /* main loop */ diff --git a/carlfw/src/pattern_generator.c b/carlfw/src/pattern_generator.c new file mode 100644 index 0000000..79cad0b --- /dev/null +++ b/carlfw/src/pattern_generator.c @@ -0,0 +1,54 @@ +/* + * carl9170 firmware - used by the ar9170 wireless device + * + * pattern generator + * + * Copyright 2013 Christian Lamparter + * + * 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., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + */ + +#include "carl9170.h" +#include "pattern_generator.h" + +#if defined(CARL9170FW_PATTERN_GENERATOR) + +void radar_pattern_generator(void) +{ + if (fw.phy.state == CARL9170_PHY_ON) { + if (likely(fw.wlan.soft_radar == NO_RADAR || + fw.wlan.soft_radar >= __CARL9170FW_NUM_RADARS)) + return; + + const struct radar_info *radar = &radars[fw.wlan.soft_radar]; + if (radar->pulses >= fw.wlan.pattern_index) { + fw.wlan.pattern_index = 0; + } + + if (radar->pulses > fw.wlan.pattern_index) { + const struct radar_info_pattern *pattern = &radar->pattern[fw.wlan.pattern_index]; + if (is_after_usecs(fw.wlan.radar_last, pattern->pulse_interval)) { + fw.wlan.radar_last = get_clock_counter(); + set(0x1C3BC0, pattern->pulse_pattern); + set(0x1C3BBC, pattern->pulse_mode); + udelay(pattern->pulse_width); + set(0x1C3BBC, ~pattern->pulse_mode); + fw.wlan.pattern_index++; + } + } + } +} + +#endif /* CONFIG_CARL9170FW_RADAR */