target/rf: Make the trf6151_set_arfcn use ARFCN_UPLINK flag to select UL/DL
[osmocom-bb.git] / src / target / firmware / layer1 / prim_tx_nb.c
blobdf13c757b8572425a4032193f43423c0b1cb589b
1 /* Layer 1 - Transmit Normal Burst */
3 /* (C) 2010 by Dieter Spaar <spaar@mirider.augusta.de>
4 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
6 * All Rights Reserved
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.
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.
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.
24 #include <stdint.h>
25 #include <stdio.h>
26 #include <string.h>
27 #include <stdlib.h>
29 #include <defines.h>
30 #include <debug.h>
31 #include <memory.h>
32 #include <byteorder.h>
33 #include <osmocom/gsm/gsm_utils.h>
34 #include <osmocom/core/msgb.h>
35 #include <calypso/dsp_api.h>
36 #include <calypso/irq.h>
37 #include <calypso/tpu.h>
38 #include <calypso/tsp.h>
39 #include <calypso/dsp.h>
40 #include <calypso/timer.h>
41 #include <comm/sercomm.h>
43 #include <layer1/sync.h>
44 #include <layer1/agc.h>
45 #include <layer1/tdma_sched.h>
46 #include <layer1/mframe_sched.h>
47 #include <layer1/tpu_window.h>
48 #include <layer1/l23_api.h>
49 #include <layer1/rfch.h>
50 #include <layer1/prim.h>
52 #include <l1ctl_proto.h>
55 static uint32_t last_txnb_fn;
57 /* p1: type of operation (0: one NB, 1: one RACH burst, 2: four NB) */
58 static int l1s_tx_resp(__unused uint8_t p1, __unused uint8_t burst_id,
59 __unused uint16_t p3)
61 putchart('t');
63 dsp_api.r_page_used = 1;
65 if (burst_id == 3) {
66 last_txnb_fn = l1s.current_time.fn - 4;
67 l1s_compl_sched(L1_COMPL_TX_NB);
70 return 0;
73 /* p1: type of operation (0: one NB, 1: one RACH burst, 2: four NB) */
74 static int l1s_tx_cmd(uint8_t p1, uint8_t burst_id, uint16_t p3)
76 uint16_t arfcn;
77 uint8_t tsc, tn;
78 uint8_t mf_task_id = p3 & 0xff;
79 uint8_t mf_task_flags = p3 >> 8;
81 putchart('T');
83 /* before sending first of the four bursts, copy data to API ram */
84 if (burst_id == 0) {
85 uint16_t *info_ptr = dsp_api.ndb->a_cu;
86 struct msgb *msg;
87 const uint8_t *data;
89 /* distinguish between DCCH and ACCH */
90 if (mf_task_flags & MF_F_SACCH) {
91 msg = msgb_dequeue(&l1s.tx_queue[L1S_CHAN_SACCH]);
92 data = msg ? msg->l3h : pu_get_meas_frame();
93 } else {
94 msg = msgb_dequeue(&l1s.tx_queue[L1S_CHAN_MAIN]);
95 data = msg ? msg->l3h : pu_get_idle_frame();
98 /* Fill data block Header */
99 info_ptr[0] = (1 << B_BLUD); // 1st word: Set B_BLU bit.
100 info_ptr[1] = 0; // 2nd word: cleared.
101 info_ptr[2] = 0; // 3rd word: cleared.
103 /* Copy the actual data after the header */
104 dsp_memcpy_to_api(&info_ptr[3], data, 23, 0);
106 if (msg)
107 msgb_free(msg);
110 rfch_get_params(&l1s.next_time, &arfcn, &tsc, &tn);
112 l1s_tx_apc_helper(arfcn);
114 if (p1 == 0)
115 /* DUL_DSP_TASK, one normal burst */
116 dsp_load_tch_param(&l1s.next_time,
117 SIG_ONLY_MODE, INVALID_CHANNEL, 0, 0, 0, tn);
119 else if (p1 == 2)
120 /* DUL_DSP_TASK, four normal bursts */
121 dsp_load_tch_param(&l1s.next_time,
122 SIG_ONLY_MODE, SDCCH_4, 0, 0, 0, tn);
124 dsp_load_tx_task(DUL_DSP_TASK, burst_id, tsc);
126 l1s_tx_win_ctrl(arfcn | ARFCN_UPLINK, L1_TXWIN_NB, 0, 3);
128 return 0;
131 /* Asynchronous completion handler for NB transmit */
132 static void l1a_tx_nb_compl(__unused enum l1_compl c)
134 struct msgb *msg;
136 msg = l1_create_l2_msg(L1CTL_DATA_CONF, last_txnb_fn, 0, 0);
137 l1_queue_for_l2(msg);
140 void l1s_tx_test(uint8_t base_fn, uint8_t type)
142 printf("Starting TX %d\n", type);
144 if (type == 0) {// one normal burst
145 tdma_schedule(base_fn, &l1s_tx_cmd, 0, 0, 0, 3);
146 tdma_schedule(base_fn + 2, &l1s_tx_resp, 0, 0, 0, 3);
147 } else if (type == 2) { // four normal bursts
148 tdma_schedule(base_fn, &l1s_tx_cmd, 2, 0, 0, 3);
149 tdma_schedule(base_fn + 1, &l1s_tx_cmd, 2, 1, 0, 3);
150 tdma_schedule(base_fn + 2, &l1s_tx_resp, 2, 0, 0, 3);
151 tdma_schedule(base_fn + 2, &l1s_tx_cmd, 2, 2, 0, 3);
152 tdma_schedule(base_fn + 3, &l1s_tx_resp, 2, 1, 0, 3);
153 tdma_schedule(base_fn + 3, &l1s_tx_cmd, 2, 3, 0, 3);
154 tdma_schedule(base_fn + 4, &l1s_tx_resp, 2, 2, 0, 3);
155 tdma_schedule(base_fn + 5, &l1s_tx_resp, 2, 3, 0, 3);
159 /* sched sets for uplink */
160 const struct tdma_sched_item nb_sched_set_ul[] = {
161 SCHED_ITEM_DT(l1s_tx_cmd, 3, 2, 0), SCHED_END_FRAME(),
162 SCHED_ITEM_DT(l1s_tx_cmd, 3, 2, 1), SCHED_END_FRAME(),
163 SCHED_ITEM(l1s_tx_resp, -4, 2, 0), SCHED_ITEM_DT(l1s_tx_cmd, 3, 2, 2), SCHED_END_FRAME(),
164 SCHED_ITEM(l1s_tx_resp, -4, 2, 1), SCHED_ITEM_DT(l1s_tx_cmd, 3, 2, 3), SCHED_END_FRAME(),
165 SCHED_ITEM(l1s_tx_resp, -4, 2, 2), SCHED_END_FRAME(),
166 SCHED_ITEM(l1s_tx_resp, -4, 2, 3), SCHED_END_FRAME(),
167 SCHED_END_SET()
170 static __attribute__ ((constructor)) void prim_tx_nb_init(void)
172 l1s.completion[L1_COMPL_TX_NB] = &l1a_tx_nb_compl;