1 ///////////////////////////////////////////////////////////////////////////////
\r
2 // Copyright 2003 DEIS - Universita' di Bologna
\r
5 // author DEIS - Universita' di Bologna
\r
6 // Davide Bertozzi - dbertozzi@deis.unibo.it
\r
7 // Mirko Loghi - mloghi@deis.unibo.it
\r
8 // Federico Angiolini - fangiolini@deis.unibo.it
\r
9 // Francesco Poletti - fpoletti@deis.unibo.it
\r
10 // portions by Massimo Scardamaglia - mascard@vizzavi.it
\r
11 // info Provides support for testbench compilation
\r
13 ///////////////////////////////////////////////////////////////////////////////
\r
16 #include "appsupport.h"
\r
18 volatile char *time_low_ptr = (char *)(SIMSUPPORT_BASE + GET_TIME_ADDRESS_LO);
\r
19 volatile char *time_high_ptr = (char *)(SIMSUPPORT_BASE + GET_TIME_ADDRESS_HI);
\r
20 volatile char *time_stop_ptr = (char *)(SIMSUPPORT_BASE + STOP_TIME_ADDRESS);
\r
21 volatile char *time_rel_ptr = (char *)(SIMSUPPORT_BASE + RELEASE_TIME_ADDRESS);
\r
23 volatile char *cycle_low_ptr = (char *)(SIMSUPPORT_BASE + GET_CYCLE_ADDRESS_LO);
\r
24 volatile char *cycle_high_ptr = (char *)(SIMSUPPORT_BASE + GET_CYCLE_ADDRESS_HI);
\r
25 volatile char *cycle_stop_ptr = (char *)(SIMSUPPORT_BASE + STOP_CYCLE_ADDRESS);
\r
26 volatile char *cycle_rel_ptr = (char *)(SIMSUPPORT_BASE + RELEASE_CYCLE_ADDRESS);
\r
29 ///////////////////////////////////////////////////////////////////////////////
\r
30 // pr - Allows printing debug info even without support from an OS. See
\r
31 // user_swi.cpp for printable messages, or to create your own
\r
33 void pr(int proc, int msg_num, int num_arg)
\r
35 #ifndef __OPTIMIZE__
\r
36 __asm ("ldr r1, %0" : : "g" (proc) : "r1" );
\r
37 __asm ("ldr r2, %0" : : "g" (msg_num) : "r2" );
\r
38 __asm ("ldr r3, %0" : : "g" (num_arg) : "r3" );
\r
39 __asm ("swi " SWI_PRINTstr);
\r
41 __asm ("mov r1, %0" : : "g" (proc) : "r1" );
\r
42 __asm ("mov r2, %0" : : "g" (msg_num) : "r2" );
\r
43 __asm ("mov r3, %0" : : "g" (num_arg) : "r3" );
\r
44 __asm ("swi " SWI_PRINTstr);
\r
48 ///////////////////////////////////////////////////////////////////////////////
\r
49 // get_proc_id - Allows getting the processor's ID (from 1 onwards)
\r
50 unsigned int get_proc_id()
\r
52 char *ptr = (char *)(SIMSUPPORT_BASE + GET_CPU_ID_ADDRESS);
\r
53 return (*(unsigned long int *)ptr);
\r
56 ///////////////////////////////////////////////////////////////////////////////
\r
57 // get_proc_num - Allows getting the number of processors in the platform
\r
58 unsigned int get_proc_num()
\r
60 char *ptr = (char *)(SIMSUPPORT_BASE + GET_CPU_CNT_ADDRESS);
\r
61 return (*(unsigned long int *)ptr);
\r
64 // ---------------------------
\r
65 // Frequency scaling functions
\r
66 // ---------------------------
\r
67 volatile unsigned int *freqdevice = (unsigned int *)FREQ_BASE;
\r
69 ///////////////////////////////////////////////////////////////////////////////
\r
70 // scale_this_core_frequency - Scales the frequency of the core on which
\r
71 // the application is running
\r
72 void scale_this_core_frequency(unsigned short int divider)
\r
74 freqdevice[get_proc_id() - 1] = divider;
\r
76 ///////////////////////////////////////////////////////////////////////////////
\r
77 // scale_device_frequency - Scales the frequency of any device in the system
\r
78 void scale_device_frequency(unsigned short int divider, int ID)
\r
80 freqdevice[ID] = divider;
\r
82 ///////////////////////////////////////////////////////////////////////////////
\r
83 // get_this_core_frequency - Gets the frequency divider of the core on which
\r
84 // the application is running
\r
85 unsigned short int get_this_core_frequency()
\r
87 return (freqdevice[get_proc_id() - 1]);
\r
89 ///////////////////////////////////////////////////////////////////////////////
\r
90 // get_device_frequency - Gets the frequency divider of any device in the system
\r
91 unsigned short int get_device_frequency(int ID)
\r
93 return (freqdevice[ID]);
\r
96 ///////////////////////////////////////////////////////////////////////////////
\r
97 // get_time - Allows getting the current simulation time
\r
98 unsigned long long int get_time()
\r
100 unsigned long long int time;
\r
102 *time_stop_ptr = 1;
\r
103 time = (((unsigned long long int)(*(unsigned long int *)time_high_ptr)) << 32) + *(unsigned long int *)time_low_ptr;
\r
109 ///////////////////////////////////////////////////////////////////////////////
\r
110 // get_cycle - Allows getting the current simulation cycle
\r
111 unsigned long long int get_cycle1()
\r
113 unsigned long long int cycle;
\r
115 *cycle_stop_ptr = 1;
\r
116 cycle = (((unsigned long long int)(*(unsigned long int *)cycle_high_ptr)) << 32) + *(unsigned long int *)cycle_low_ptr;
\r
117 *cycle_rel_ptr = 1;
\r
122 extern rtems_id timer_sem_id;
\r
123 unsigned long long int get_cycle()
\r
125 unsigned long long int cycle;
\r
126 rtems_status_code rtems_status;
\r
128 rtems_status = rtems_semaphore_obtain(timer_sem_id, RTEMS_WAIT, RTEMS_NO_TIMEOUT);
\r
129 *cycle_stop_ptr = 1;
\r
130 cycle = (((unsigned long long int)(*(unsigned long int *)cycle_high_ptr))
\r
131 << 32) + *(unsigned long int *)cycle_low_ptr;
\r
132 *cycle_rel_ptr = 1;
\r
133 rtems_status = rtems_semaphore_release(timer_sem_id);
\r