carl9170 firmware: reorganize pattern generator
authorChristian Lamparter <chunkeey@googlemail.com>
Sat, 23 Nov 2013 13:21:48 +0000 (14:21 +0100)
committerChristian Lamparter <chunkeey@googlemail.com>
Sat, 23 Nov 2013 13:21:48 +0000 (14:21 +0100)
Prepare this feature so it can be merged into the main branch.

Signed-off-by: Christian Lamparter <chunkeey@googlemail.com>
carlfw/CMakeLists.txt
carlfw/Kconfig
carlfw/include/carl9170.h
carlfw/include/pattern_generator.h [new file with mode: 0644]
carlfw/include/radar.h [deleted file]
carlfw/src/fw.c
carlfw/src/main.c
carlfw/src/pattern_generator.c [new file with mode: 0644]

index 124352e1986ccc3b88cc1d8b4154b317dc5049b1..cacccd984184fad79fce5772ad1f61afa1b94188 100644 (file)
@@ -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)
 
index 4cec81cef2e7f424b9c90e768c8bff6aa945ad90..caa38485cb8ea6f9b0ba3957391d9888804a0620 100644 (file)
@@ -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
index ed5120df22ba1b88a0e07358e0d740ee2694cd48..26a0975819b824f2229ed2028e8e67a7f62153dc 100644 (file)
@@ -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 (file)
index 0000000..e08f9fc
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * carl9170 firmware - used by the ar9170 wireless device
+ *
+ * Pattern Generator definitions
+ *
+ * Copyright 2012, 2013 Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * 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 (file)
index 864882a..0000000
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * carl9170 firmware - used by the ar9170 wireless device
- *
- * Radar pulse definitions
- *
- * Copyright 2012 Christian Lamparter <chunkeey@googlemail.com>
- *
- * 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:
- * <http://linuxwireless.org/en/developers/DFS>
- */
-
-/* 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 */
index be9001a099b751cfa6629501d06175611559209f..a999e2d4a059eede39e7f59f71b10ce85619d7ff 100644 (file)
@@ -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,
index 50415fedbbb760e77ef29ec6fede2b9f1a907cb7..fc44d50af2fddcddf5be8d1d7e74c902838bd761 100644 (file)
@@ -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 (file)
index 0000000..79cad0b
--- /dev/null
@@ -0,0 +1,54 @@
+/*
+ * carl9170 firmware - used by the ar9170 wireless device
+ *
+ * pattern generator
+ *
+ * Copyright 2013      Christian Lamparter <chunkeey@googlemail.com>
+ *
+ * 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 */