po_hi_gprof_rtems_leon.c 19.5 KB
Newer Older
1
2
3
4
5
/*
 * This is a part of PolyORB-HI-C distribution, a minimal
 * middleware written for generated code from AADL models.
 * You should use it with the Ocarina toolsuite.
 *
yoogx's avatar
yoogx committed
6
 * For more informations, please visit http://taste.tuxfamily.org/wiki
7
 *
yoogx's avatar
yoogx committed
8
 * Copyright (C) 2010-2014 ESA & ISAE.
9
10
 */

11
12
#ifdef __PO_HI_USE_GPROF

13
14
15
16
17
18
19
20
21
#include <po_hi_debug.h>
#include <drivers/po_hi_rtems_utils.h>

#include <pci.h>
#include <rasta.h>
#include <apbuart_rasta.h>



22
#define CONFIG_OS_PROFILE_OVER_SERIAL 1
23
#define SERIAL_VERBOSE_MODE 1
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95

/*
 * Histogram counters are unsigned shorts (according to the kernel).
 */
#define	HISTCOUNTER	unsigned short

/*
 * Fraction of text space to allocate for histogram counters here, 1/2
 */
#define	HISTFRACTION_LOG2   (1)
#define	HISTFRACTION        (1 << HISTFRACTION_LOG2)

/*
 * Fraction of text space to allocate for from hash buckets.
 * The value of HASHFRACTION is based on the minimum number of bytes
 * of separation between two subroutine call points in the object code.
 * Given MIN_SUBR_SEPARATION bytes of separation the value of
 * HASHFRACTION is calculated as:
 *
 * 	HASHFRACTION = MIN_SUBR_SEPARATION / (2 * sizeof(short) - 1);
 *
 * For the VAX,
 *	the shortest two call sequence is:
 * 		calls	$0,(r0)
 *		calls	$0,(r0)
 * 	which is separated by only three bytes, thus HASHFRACTION is 
 *	calculated as:
 *		HASHFRACTION = 3 / (2 * 2 - 1) = 1
 *
 * For the m68k,
 *	the shortest two call sequence is:
 * 		jsr	a0
 *		jsr	a0
 * 	which is separated by only four bytes, thus HASHFRACTION is 
 *	calculated as:
 *		HASHFRACTION = 4 / (2 * 2 - 1) = 1
 *
 * For all RISC machines
 *	the shortest two call sequence is 2 32-bit instructions,
 * 	which is separated by only four bytes, thus HASHFRACTION is 
 *	calculated as:
 *		HASHFRACTION = 4 / (2 * 2 - 1) = 1
 *
 * For the i386,
 *	the shortest two call sequence is:
 * 		call	%eax
 *		call	%eax
 * 	which is separated by only two bytes, thus HASHFRACTION is 
 *	calculated as:
 *		HASHFRACTION = 2 / (2 * 2 - 1) = 0
 *	So on the i386 we use a HASHFRACTION of 1 instead and it can fail
 *	to determine that two call sites are different.  But since all
 *	the call site address in gprof(1) is currently used for is
 *	to determine which routine was doing the calling it works for now.
 *
 * Note that the division above rounds down, thus if MIN_SUBR_FRACTION
 * is less than three, this algorithm will not work!
 */
#define	HASHFRACTION	1

/*
 * percent of text space to allocate for tostructs with a minimum.
 */
#define ARCDENSITY	4
#define MINARCS		50

#ifndef ASSEMBLER
/*
 * The tostruct is used internal to the monitor library routines to implement
 * the recording of calls via mcount().
 */
struct tostruct {
96
97
98
99
    char		*selfpc;
    long		count;
    unsigned short	link;
    unsigned short	order;
100
101
102
103
104
105
106
107
108
};

/*
 * The phdr (profile header) structure is what appears at the beginning of a
 * mon.out (cc(1) -p) and gmon.out (cc(1) -pg) file and describes the histogram
 * counters.  The histogram counters are unsigned shorts which follow after the
 * header for ncnt - sizeof(struct phdr) bytes.
 */
struct phdr {
109
110
111
112
    char	*lpc; 	/* low program counter */
    char	*hpc; 	/* high program counter */
    int		ncnt;	/* number of bytes of histogram counters minius
                       sizeof(struct phdr) that follow */
113
114
115
116
117
118
119
120
121
};

/*
 * In a gmon.out (cc(1) -pg) file what follows the above histogram counters are
 * the raw arcs.  A raw arc contains pointers to the calling site, the called
 * site and a count.  These repeat in the gmon.out file after the histogram
 * counters to the end of the file.
 */
struct rawarc {
122
123
124
    unsigned long	raw_frompc;
    unsigned long	raw_selfpc;
    unsigned long	raw_count;
125
126
127
128
129
130
131
132
133
134
};

/*
 * In order to support more information than in the original mon.out and
 * gmon.out files there is an alternate gmon.out file format.  The alternate
 * gmon.out file format starts with a magic number then separates the
 * information with gmon_data structs.
 */
#define GMON_MAGIC 0xbeefbabe
struct gmon_data {
135
136
    unsigned long type; /* constant for type of data following this struct */
    unsigned long size; /* size in bytes of the data following this struct */
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
};

/*
 * The GMONTYPE_SAMPLES gmon_data.type is for the histogram counters described
 * above and has a struct phdr followed by the counters.
 */
#define GMONTYPE_SAMPLES	1
/*
 * The GMONTYPE_RAWARCS gmon_data.type is for the raw arcs described above.
 */
#define GMONTYPE_RAWARCS	2
/*
 * The GMONTYPE_ARCS_ORDERS gmon_data.type is for the raw arcs with a call
 * order field.  The order is the order is a sequence number for the order each
 * call site was executed.  Raw_order values start at 1 not zero.  Other than
 * the raw_order field this is the same information as in the struct rawarc.
 */
#define GMONTYPE_ARCS_ORDERS	3
struct rawarc_order {
156
157
158
159
    unsigned long	raw_frompc;
    unsigned long	raw_selfpc;
    unsigned long	raw_count;
    unsigned long	raw_order;
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
};
/*
 * The GMONTYPE_RLD_STATE gmon_data.type is for the rld_load()'ed state of the
 * program.
 * The informations starts with an unsigned long with the count of states:
 *	rld_nloaded_states
 * Then each state follows in the file.  The state is made up of 
 *	header_addr (where rld loaded this set of objects)
 *	nobjectfiles (the number of objects in this set)
 *		offsets into the string table (one for each object in the set)
 *	nbytes of string table
 *		the file name strings null terminated.
 */
#define GMONTYPE_RLD_STATE	4
/*
 * The GMONTYPE_DYLD_STATE gmon_data.type is for the dynamic link editor state
 * of the program.
 * The informations starts with an unsigned long with the count of states:
 *      image_count
 * Then each state follows in the file.  The state is made up of 
 *      image_header (the address where dyld loaded this image)
 *      vmaddr_slide (the amount dyld slid this image from it's vmaddress)
 *      name (the file name dyld loaded this image from)
 */
#define GMONTYPE_DYLD_STATE     5
#endif /* !ASSEMBLER */

/*
 * general rounding functions.
 */
#define ROUNDDOWN(x,y)	(((x)/(y))*(y))
#define ROUNDUP(x,y)	((((x)+(y)-1)/(y))*(y))

193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
/**
 *  \file   gmon.c
 *  \brief  This file implements the gprof stub on the LEON2/3 over RTEMS.
 *
 *  The file implements the mcoung function responsible for recording the
 *  call-graph table.
 *  It also implements the functionality of the profil() function (see man(2)
 *  profil) by replacing the clock isr and wrapping the real Clock_isr() RTEMS
 *  function.
 *
 *  \author  Aitor Viana Sanchez (avs), Aitor.Viana.Sanchez@esa.int
 *
 *  \internal
 *    Created:  05/17/2010
 *   Revision:  $Id: gmon.c 1.4 05/17/2010 avs Exp $
 *   Compiler:  gcc/g++
 *    Company:  European Space Agency (ESA-ESTEC)
 *  Copyright:  Copyright (c) 2010, Aitor Viana Sanchez
 *
 *  This source code is released for free distribution under the terms of the
 *  GNU General Public License as published by the Free Software Foundation.
 * =====================================================================================
 */
216

217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
/*-
 * Copyright (c) 1991, 1998 The Regents of the University of California.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. [rescinded 22 July 1999]
 * 4. Neither the name of the University nor the names of its contributors
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */

static char sccsid[] = "@(#)gmon.c	1.0 (E.S.A) 10/05/2010";

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdint.h>

#include <rtems.h>
#include <bsp.h>
257
258
259
260
261
262
263
264

void _mcount() __attribute__((weak, alias("mcount")));

/*  These variables are defined in the linkcmd linker script and point to the
 *  start and end of the text area
 */
extern unsigned int _endtext, text_start;
extern int initialize_serial();
265
extern void end_serial ();
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
extern void write_serial(uint8_t vector[] , unsigned int dim);

/*
 *	froms is actually a bunch of unsigned shorts indexing tos
 */
static int		profiling = 3;
static long		tolimit = 0;
static unsigned long	s_textsize = 0;

static unsigned short	*froms;
static struct tostruct	*tos = 0;
static char		*s_lowpc = 0;
static char		*s_highpc = 0;

static int	ssiz;
static int	s_profil_sz = 0;
static char	*sbuf = 0;
static char *s_profil = 0;

#define	MSG "No space for profiling buffer(s)\n"

#define SAVE_L1( _pc_ )  \
288
289
290
    do{ \
        asm volatile( "mov %%l1, %0" : "=r" (_pc_) : "0" (_pc_) );    \
    }while(0)
291
292
293
294
295
296

static void moncontrol( int mode );
static rtems_isr profile_clock_isr(rtems_vector_number vector);

static void moncontrol( int mode )
{
297
298
299
300
301
302
303
304
305
306
307
    if (mode) {
        /* start */
        s_profil = sbuf + sizeof(struct phdr);
        s_profil_sz = ssiz - sizeof(struct phdr);
        profiling = 0;
    } else {
        /* stop */
        s_profil = 0;
        s_profil_sz = 0;
        profiling = 3;
    }
308
309
310
311
}

static void _mcleanup()
{
312
313
314
315
316
317
318
319
    int			fromindex;
    int			endfrom;
    char		*frompc;
    int			toindex;
    struct rawarc	rawarc;
    int ret = -1;

    moncontrol(0);
320
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
321
322
323
324
325
    ret = initialize_serial();
    if( ret >= 0 )
    {
        write_serial( (uint8_t*)sbuf , (unsigned int)ssiz );
    }
326
#endif
327

328
//    fprintf( stderr , "[mcleanup] sbuf 0x%x ssiz %d\n" , (unsigned int)sbuf , (unsigned int)ssiz );
329
330
331
332
333
334
335
336
    endfrom = s_textsize / (HASHFRACTION * sizeof(*froms));
    for ( fromindex = 0 ; fromindex < endfrom ; fromindex++ ) {
        if ( froms[fromindex] == 0 ) {
            continue;
        }
        frompc = s_lowpc + (fromindex * HASHFRACTION * sizeof(*froms));
        for (toindex=froms[fromindex]; toindex!=0; toindex=tos[toindex].link) 
        {
337
           /*
338
339
340
341
342
            fprintf( stderr ,
                    "[mcleanup] frompc 0x%x selfpc 0x%x count %d\n" ,
                    (unsigned int)frompc , 
                    (unsigned int)tos[toindex].selfpc , 
                    (unsigned int)tos[toindex].count );
343
                    */
344
345
346
347
348
            rawarc.raw_frompc = (unsigned long) frompc;
            rawarc.raw_selfpc = (unsigned long) tos[toindex].selfpc;
            rawarc.raw_count = tos[toindex].count;
            if( ret >= 0 )
            {
349
350
351
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
            write_serial( (uint8_t*)&rawarc , (unsigned int)sizeof(rawarc));
#endif
352
353
354
            }
        }
    }
355
356
357
358
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
    end_serial ();
#endif

359
360
361
362
}

void monstartup(char *lowpc, char *highpc)
{
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
    int			monsize;
    char		*buffer;

    printf("%s\n", sccsid);
    /*
     *	round lowpc and highpc to multiples of the density we're using
     *	so the rest of the scaling (here and in gprof) stays in ints.
     */
    lowpc = (char *)
        ROUNDDOWN((unsigned) lowpc, HISTFRACTION*sizeof(HISTCOUNTER));
    s_lowpc = lowpc;
    highpc = (char *)
        ROUNDUP((unsigned) highpc, HISTFRACTION*sizeof(HISTCOUNTER));
    s_highpc = highpc;
    s_textsize = highpc - lowpc;
    monsize = (s_textsize / HISTFRACTION) + sizeof(struct phdr);
    buffer = (char*)malloc( monsize );
    if ( buffer == (char *) -1 ) 
    {
        printf("%s\n", MSG);
        return;
    }
    froms = (unsigned short *) malloc( s_textsize / HASHFRACTION );
    if ( froms == (unsigned short *) -1 ) 
    {
        printf("%s\n", MSG);
        froms = 0;
        return;
    }
    tolimit = s_textsize * ARCDENSITY / 100;
    if ( tolimit < MINARCS ) {
        tolimit = MINARCS;
    } else if ( tolimit > 65534 ) {
        tolimit = 65534;
    }
    tos = (struct tostruct *) malloc( tolimit * sizeof( struct tostruct ) );
    if ( tos == (struct tostruct *) -1 ) 
    {
        printf("%s\n", MSG);
        froms = 0;
        tos = 0;
        return;
    }
    tos[0].link = 0;
    sbuf = buffer;
    bzero( buffer, sizeof(buffer) );
    ssiz = monsize;
    ( (struct phdr *) sbuf ) -> lpc = lowpc;
    ( (struct phdr *) sbuf ) -> hpc = highpc;
    ( (struct phdr *) sbuf ) -> ncnt = ssiz;
    monsize -= sizeof(struct phdr);
    if ( monsize <= 0 )
        return;

    printf("PC histrogram scale = %d\n", HISTFRACTION);

    /*  Register the new clock driver   */
    set_vector( profile_clock_isr, 0x18, 1 );
    atexit( _mcleanup );
    moncontrol(1);
423
424
425
426
}

void mcount()
{
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
    register char			*selfpc;
    register unsigned short		*frompcindex;
    register struct tostruct	*top;
    register struct tostruct	*prevtop;
    register long			toindex;
    static int first_call = 1;

    if( first_call )
    {
        monstartup((char*)&text_start, (char*)&_endtext);
        first_call = 0;
    }

    /*
     *	find the return address for mcount,
     *	and the return address for mcount's caller.
     */

    /* selfpc = pc pushed by mcount call.
       This identifies the function that was just entered.  */
    selfpc = (void *) __builtin_return_address (0);
    /* frompcindex = pc in preceding frame.
       This identifies the caller of the function just entered.  */
    frompcindex = (void *) __builtin_return_address (1);

    /*
     *	check that we are profiling
     *	and that we aren't recursively invoked.
     */
    if (profiling) {
        goto out;
    }
    profiling++;
    /*
     *	check that frompcindex is a reasonable pc value.
     *	for example:	signal catchers get called from the stack,
     *			not from text space.  too bad.
     */
    frompcindex = (unsigned short *) ((long) frompcindex - (long) s_lowpc);
    if ((unsigned long) frompcindex > s_textsize) {
        goto done;
    }
    frompcindex =
        &froms[((long) frompcindex) / (HASHFRACTION * sizeof(*froms))];
    toindex = *frompcindex;
    if (toindex == 0) {
        /*
         *	first time traversing this arc
         */
        toindex = ++tos[0].link;
        if (toindex >= tolimit) {
478
            goto overflow;
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
        }
        *frompcindex = toindex;
        top = &tos[toindex];
        top->selfpc = selfpc;
        top->count = 1;
        top->link = 0;
        goto done;
    }
    top = &tos[toindex];
    if (top->selfpc == selfpc) {
        /*
         *	arc at front of chain; usual case.
         */
        top->count++;
        goto done;
    }
    /*
     *	have to go looking down chain for it.
     *	top points to what we are looking at,
     *	prevtop points to previous top.
     *	we know it is not at the head of the chain.
     */
    for (; /* goto done */; ) {
        if (top->link == 0) {
            /*
             *	top is end of the chain and none of the chain
             *	had top->selfpc == selfpc.
             *	so we allocate a new tostruct
             *	and link it to the head of the chain.
             */
            toindex = ++tos[0].link;
            if (toindex >= tolimit) {
                goto overflow;
            }
            top = &tos[toindex];
            top->selfpc = selfpc;
            top->count = 1;
            top->link = *frompcindex;
            *frompcindex = toindex;
            goto done;
        }
        /*
         *	otherwise, check the next arc on the chain.
         */
        prevtop = top;
        top = &tos[top->link];
        if (top->selfpc == selfpc) {
            /*
             *	there it is.
             *	increment its count
             *	move it to the head of the chain.
             */
            top->count++;
            toindex = prevtop->link;
            prevtop->link = top->link;
            top->link = *frompcindex;
            *frompcindex = toindex;
            goto done;
        }

    }
540
done:
541
542
    profiling--;
    /* and fall through */
543
out:
544
    return;		/* normal return restores saved registers */
545
546

overflow:
547
548
549
    profiling++; /* halt further profiling */
    fprintf( stderr, "%s: tos overflow", __func__ );
    goto out;
550
551
552
}

extern rtems_status_code __real_Clock_isr();
553
extern rtems_status_code Clock_isr();
554
555
556
557

static uint32_t pc = 0;
rtems_isr __wrap_Clock_isr()
{
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
    if( s_profil && s_profil_sz )
    {
       /*   This identifies the function that was just entered.  */
//        SAVE_L1(pc);
        if( pc )
        {
            pc -= (int)s_lowpc;
            pc = (pc >> HISTFRACTION_LOG2);
            if( pc < s_profil_sz )  s_profil[pc]++;
        }
    }
    pc = 0;

    __real_Clock_isr();
    
}
574

575
576
577
578
579
static rtems_isr profile_clock_isr(rtems_vector_number vector)
{
    SAVE_L1(pc);
    Clock_isr(vector);
    
580
581
}

582
#if (CONFIG_OS_PROFILE_OVER_SERIAL == 1)
583

584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <termios.h>
#include <stdio.h>
#include <errno.h>
#include <sys/systm.h>

#define SERIAL_VERBOSE_MODE   1
#define BAUDRATE B57600

/******************************************************
 *         Private global variables declaration
 ******************************************************/

/**
 * the serial connection file descriptor
 **/
static int serialFD = -1;


/******************************************************
 *            Function implementation
 ******************************************************/

int initialize_serial()
610
{
611
612
613
614
615
   __DEBUGMSG ("[RASTA SERIAL] Init\n");
   init_pci();
   __DEBUGMSG ("[RASTA SERIAL] Initializing RASTA ...\n");
  if  ( rasta_register() ){
    __DEBUGMSG(" ERROR !\n");
616
    return -1;
617
  }
618
   __DEBUGMSG(" OK !\n");
619
620
621



622
  serialFD = open( "/dev/apburasta0" , O_RDWR);
623
624
625
  if( serialFD < 0 )
  {
#if(SERIAL_VERBOSE_MODE == 1)
626
    printk("can't open new device! error = %d\n" , serialFD);
627
628
629
630
#endif
    return -1;
  }
  
631
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_SET_BAUDRATE, 38400); /* stream mode */
632
633
634
635
636
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_SET_BLOCKING, APBUART_BLK_RX | APBUART_BLK_TX | APBUART_BLK_FLUSH);
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_SET_TXFIFO_LEN, 64);  /* Transmitt buffer 64 chars */
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_SET_RXFIFO_LEN, 256); /* Receive buffer 256 chars */
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_SET_ASCII_MODE, 0); /* Make \n go \n\r or \r\n */
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_CLR_STATS, 0);
637
638
639
640
641
642
  __PO_HI_DRIVERS_RTEMS_UTILS_IOCTL(serialFD, APBUART_START, 0);
  if (tcflush (serialFD, TCIOFLUSH) != 0)
  {
     __DEBUGMSG("[GPROF] Error when trying to flush\n");
  }

643
644

#if(SERIAL_VERBOSE_MODE == 1)
645
    printk("Serial init done (using file descriptor %d)\n" , serialFD);
646
#endif
647
648
  
  return 0;
649
650
}

651
652
void write_serial(uint8_t vector[] , unsigned int dim)
{
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
   write(serialFD , vector , dim);
   /*
   for (i = 0 ; i < dim ; i++)
   {
      write(serialFD , &vector[i] , 1);
   }
   */

   if (tcflush (serialFD, TCIOFLUSH) != 0)
   {
      __DEBUGMSG("[GPROF] Error when trying to flush serial port\n");
   }
}

void end_serial ()
{
      __DEBUGMSG("[GPROF] Analysis results sent\n");
670
671
672
673
674
675
}

#endif /* TIMELINE_USE_SERIAL_CABLE */



676
#endif