79cad0b9f4076ccdc0d506ff4ca6879887ef845f
[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
26 #if defined(CARL9170FW_PATTERN_GENERATOR)
27
28 void radar_pattern_generator(void)
29 {
30         if (fw.phy.state == CARL9170_PHY_ON) {
31                 if (likely(fw.wlan.soft_radar == NO_RADAR ||
32                     fw.wlan.soft_radar >= __CARL9170FW_NUM_RADARS))
33                         return;
34
35                 const struct radar_info *radar = &radars[fw.wlan.soft_radar];
36                 if (radar->pulses >= fw.wlan.pattern_index) {
37                         fw.wlan.pattern_index = 0;
38                 }
39
40                 if (radar->pulses > fw.wlan.pattern_index) {
41                         const struct radar_info_pattern *pattern = &radar->pattern[fw.wlan.pattern_index];
42                         if (is_after_usecs(fw.wlan.radar_last, pattern->pulse_interval)) {
43                                 fw.wlan.radar_last = get_clock_counter();
44                                 set(0x1C3BC0, pattern->pulse_pattern);
45                                 set(0x1C3BBC, pattern->pulse_mode);
46                                 udelay(pattern->pulse_width);
47                                 set(0x1C3BBC, ~pattern->pulse_mode);
48                                 fw.wlan.pattern_index++;
49                         }
50                 }
51         }
52 }
53
54 #endif /* CONFIG_CARL9170FW_RADAR */