fw/layer1: Fix missing include in prim_pm.c
[osmocom-bb.git] / src / target / firmware / layer1 / prim_pm.c
index 8d05ad9..134bffd 100644 (file)
 #include <calypso/dsp.h>
 #include <calypso/timer.h>
 #include <comm/sercomm.h>
+#include <asm/system.h>
 
 #include <layer1/sync.h>
 #include <layer1/agc.h>
 #include <layer1/tdma_sched.h>
 #include <layer1/tpu_window.h>
 #include <layer1/l23_api.h>
+#include <layer1/prim.h>
 
-#include <l1a_l23_interface.h>
+#include <l1ctl_proto.h>
 
 static void l1ddsp_meas_read(uint8_t nbmeas, uint16_t *pm)
 {
@@ -57,53 +59,62 @@ static void l1ddsp_meas_read(uint8_t nbmeas, uint16_t *pm)
 }
 
 /* scheduler callback to issue a power measurement task to the DSP */
-static int l1s_pm_cmd(__unused uint8_t p1,
+static int l1s_pm_cmd(uint8_t num_meas,
                      __unused uint8_t p2, uint16_t arfcn)
 {
        putchart('P');
 
-       dsp_api.db_w->d_task_md = 2;
+       dsp_api.db_w->d_task_md = num_meas; /* number of measurements */
        dsp_api.ndb->d_fb_mode = 0; /* wideband search */
-       dsp_end_scenario();
+
+       /* Tell the RF frontend to set the gain appropriately */
+       rffe_set_gain(-85, CAL_DSP_TGT_BB_LVL);
 
        /* Program TPU */
-       //l1s_rx_win_ctrl(arfcn, L1_RXWIN_PW);
-       l1s_rx_win_ctrl(arfcn, L1_RXWIN_NB);
-       tpu_end_scenario();
+       /* FIXME: RXWIN_PW needs to set up multiple times in case
+        * num_meas > 1 */
+       l1s_rx_win_ctrl(arfcn, L1_RXWIN_PW, 0);
+       //l1s_rx_win_ctrl(arfcn, L1_RXWIN_NB);
 
        return 0;
 }
 
 /* scheduler callback to read power measurement resposnse from the DSP */
-static int l1s_pm_resp(__unused uint8_t p1, __unused uint8_t p2,
+static int l1s_pm_resp(uint8_t num_meas, __unused uint8_t p2,
                       uint16_t arfcn)
 {
-       struct l1ctl_pm_resp *pmr;
+       struct l1ctl_pm_conf *pmr;
        uint16_t pm_level[2];
 
        putchart('p');
 
-       l1ddsp_meas_read(2, pm_level);
+       l1ddsp_meas_read(num_meas, pm_level);
+
+       printf("PM MEAS: ARFCN=%u, %-4d dBm at baseband, %-4d dBm at RF\n",
+               arfcn, pm_level[0]/8, agc_inp_dbm8_by_pm(pm_level[0])/8);
 
-       printf("PM MEAS: %-4d dBm, %-4d dBm ARFCN=%u\n",
+       printd("PM MEAS: %-4d dBm, %-4d dBm ARFCN=%u\n",
                agc_inp_dbm8_by_pm(pm_level[0])/8,
                agc_inp_dbm8_by_pm(pm_level[1])/8, arfcn);
 
        if (!l1s.pm.msg)
-               l1s.pm.msg = l1ctl_msgb_alloc(L1CTL_PM_RESP);
+               l1s.pm.msg = l1ctl_msgb_alloc(L1CTL_PM_CONF);
 
        if (msgb_tailroom(l1s.pm.msg) < sizeof(*pmr)) {
                /* flush current msgb */
                l1_queue_for_l2(l1s.pm.msg);
                /* allocate a new msgb and initialize header */
-               l1s.pm.msg = l1ctl_msgb_alloc(L1CTL_PM_RESP);
+               l1s.pm.msg = l1ctl_msgb_alloc(L1CTL_PM_CONF);
        }
 
        pmr = msgb_put(l1s.pm.msg, sizeof(*pmr));
        pmr->band_arfcn = htons(arfcn);
        /* FIXME: do this as RxLev rather than DBM8 ? */
        pmr->pm[0] = dbm2rxlev(agc_inp_dbm8_by_pm(pm_level[0])/8);
-       pmr->pm[1] = dbm2rxlev(agc_inp_dbm8_by_pm(pm_level[1])/8);
+       if (num_meas > 1)
+               pmr->pm[1] = dbm2rxlev(agc_inp_dbm8_by_pm(pm_level[1])/8);
+       else
+               pmr->pm[1] = 0;
 
        if (l1s.pm.mode == 1) {
                if (l1s.pm.range.arfcn_next <= l1s.pm.range.arfcn_end) {
@@ -122,10 +133,21 @@ static int l1s_pm_resp(__unused uint8_t p1, __unused uint8_t p2,
        return 0;
 }
 
+static const struct tdma_sched_item pm_sched_set[] = {
+       SCHED_ITEM_DT(l1s_pm_cmd, 0, 1, 0),     SCHED_END_FRAME(),
+                                               SCHED_END_FRAME(),
+       SCHED_ITEM(l1s_pm_resp, -4, 1, 0),      SCHED_END_FRAME(),
+       SCHED_END_SET()
+};
+
 /* Schedule a power measurement test */
 void l1s_pm_test(uint8_t base_fn, uint16_t arfcn)
 {
-       printf("l1s_pm_test(%u, %u)\n", base_fn, arfcn);
-       tdma_schedule(base_fn, &l1s_pm_cmd, 0, 0, arfcn);
-       tdma_schedule(base_fn + 2, &l1s_pm_resp, 0, 0, arfcn);
+       unsigned long flags;
+
+       printd("l1s_pm_test(%u, %u)\n", base_fn, arfcn);
+
+       local_firq_save(flags);
+       tdma_schedule_set(base_fn, pm_sched_set, arfcn);
+       local_irq_restore(flags);
 }