carl9170 firmware: add radar pattern generator
[carl9170fw.git] / carlfw / src / pattern_generator.c
1 /*
2  * carl9170 firmware - used by the ar9170 wireless device
3  *
4  * pattern generator
5  *
6  * Copyright 2013       Christian Lamparter <chunkeey@googlemail.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  */
22
23 #include "carl9170.h"
24 #include "pattern_generator.h"
25 #include "fwdsc.h"
26 #include "timer.h"
27
28 #if defined(CONFIG_CARL9170FW_PATTERN_GENERATOR)
29
30 void pattern_generator(void)
31 {
32         if (fw.phy.state == CARL9170_PHY_ON) {
33                 if (likely(fw.wlan.soft_pattern == NO_PATTERN ||
34                     fw.wlan.soft_pattern >= __CARL9170FW_NUM_PATTERNS))
35                         return;
36
37                 const struct pattern_info *pattern = &patterns[fw.wlan.soft_pattern];
38                 if (pattern->pulses >= fw.wlan.pattern_index) {
39                         fw.wlan.pattern_index = 0;
40                 }
41
42                 if (pattern->pulses > fw.wlan.pattern_index) {
43                         const struct pattern_pulse_info *ppi = &pattern->pattern[fw.wlan.pattern_index];
44                         if (is_after_usecs(fw.wlan.pattern_last, ppi->pulse_interval)) {
45                                 fw.wlan.pattern_last = get_clock_counter();
46                                 set(0x1C3BC0, ppi->pulse_pattern);
47                                 set(0x1C3BBC, ppi->pulse_mode);
48                                 udelay(ppi->pulse_width);
49                                 set(0x1C3BBC, 0);
50                                 set(0x1C3BC0, 0);
51                                 fw.wlan.pattern_index++;
52                         }
53                 }
54         }
55 }
56
57 #endif /* CONFIG_CONFIG_CARL9170FW_RADAR */