Imported Upstream version 3.2.2
[debian/gnuradio] / gcell / lib / runtime / spu / gc_logging.c
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008 Free Software Foundation, Inc.
4  * 
5  * This file is part of GNU Radio
6  * 
7  * GNU Radio is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation; either version 3, or (at your option)
10  * any later version.
11  * 
12  * GNU Radio is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, write to the Free Software Foundation, Inc.,
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20  */
21
22 #include <gcell/gc_logging.h>
23 #include <gcell/gc_spu_args.h>
24 #include <spu_intrinsics.h>
25 #include <spu_mfcio.h>
26
27 static gc_eaddr_t     log_base_ea;      // base address of log entries in EA
28 static uint32_t       log_idx_mask;     // nentries - 1
29 static uint32_t       log_idx;          // current log entry index
30 static uint32_t       log_seqno;
31
32 static int            log_tags;         // two consecutive tags
33 static int            tmp_buffer_busy;  // bitmask: buffer busy state
34 static int            tmp_buffer_idx;   // 0 or 1
35 static gc_log_entry_t tmp_buffer[2];
36
37 void
38 _gc_log_init(gc_log_t info)
39 {
40   spu_write_decrementer(~0);
41
42   log_base_ea = info.base;
43   log_idx_mask = info.nentries - 1;
44   log_idx = 0;
45   log_seqno = 0;
46
47   log_tags = mfc_multi_tag_reserve(2);
48   tmp_buffer_busy = 0;
49   tmp_buffer_idx = 0;
50
51   gc_log_write0(GCL_SS_SYS, 0);
52 }
53
54 void
55 _gc_log_write(gc_log_entry_t entry)
56 {
57   if (log_base_ea == 0)
58     return;
59
60   entry.seqno = log_seqno++;
61   entry.timestamp = spu_read_decrementer();
62
63   if (tmp_buffer_busy & (1 << tmp_buffer_idx)){
64     mfc_write_tag_mask(1 << (log_tags + tmp_buffer_idx));
65     mfc_read_tag_status_all();
66   }
67
68   tmp_buffer[tmp_buffer_idx] = entry;   // save local copy
69
70   mfc_put(&tmp_buffer[tmp_buffer_idx],
71           log_base_ea + log_idx * sizeof(entry), sizeof(entry),
72           log_tags + tmp_buffer_idx, 0, 0);
73
74   tmp_buffer_busy |= (1 << tmp_buffer_idx);
75   tmp_buffer_idx ^= 0x1;
76   log_idx = (log_idx + 1) & log_idx_mask;
77 }