int main(void)
{
	e_mutex_t *mutex;
	volatile unsigned *po;
	unsigned time_p;
	unsigned time_c;
	int i;
	unsigned *box;
	unsigned *box1;
	
	// Define the address of mutex
	mutex = (int *)0x00004000;
	
	// Define the address of counter
	po = (int *)0x00006000;
	
	// Define the mailbox
	box = (int *)0x00006200;
	box1 = (int *)0x00006300;
	
	// Initialize the counter to 0
	*po = 0;
			
	// Initialize the mutex in core (0,0)
	e_mutex_init(0, 0, mutex, MUTEXATTR_NULL);
	
	// Start counting 
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	time_p = e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);

	// Wait to get the key
	e_mutex_lock(0, 0, mutex);
		
	// Add 1 to counter
	po[0] = po[0] + 1;
	
	// Release the key
	e_mutex_unlock(0, 0, mutex);

	while(po[0] != 16) {};
	
	// Return the value of counter
	time_c = e_ctimer_get(E_CTIMER_0);

	*box = time_p - time_c;
	*box1 = po[0];
	
return 0;
}
int main(void)
{
	e_mutex_t *mutex;
	volatile unsigned *po;
	unsigned time_p;
	unsigned time_c;
	unsigned clk_hardcode;
	int i;
	unsigned *box;
	unsigned *box1;
	clk_hardcode = 19118172;
	mutex = (int *)0x00004000;
	po = (int *)0x00006000;
	box = (int *)0x00006200;
	box1 = (int *)0x00006300;
	*po = 0;
			
	//for (i=0; i<16; i++)
	//	((unsigned *) 0x6200)[i] = 0xdeadbeef;
	// Initialize the mutex in core (0,0)
	e_mutex_init(0, 0, mutex, MUTEXATTR_NULL);
	
	// Start counting 
	e_ctimer_set(E_CTIMER_0, E_CTIMER_MAX) ;
	e_ctimer_start(E_CTIMER_0, E_CTIMER_CLK);
	time_p = e_ctimer_get(E_CTIMER_0);

	// Wait to get the key
	e_mutex_lock(0, 0, mutex);
		
	// Add 1 to counter
	po[0] = po[0] + 1;
	
	// Release the key
	e_mutex_unlock(0, 0, mutex);

	while(po[0] != 16) {};
	
	// Return the value of counter
	time_c = e_ctimer_get(E_CTIMER_0);

	*box = time_p - time_c;
	*box1 = po[0];
	
return 0;
}
Exemple #3
0
void EXT_MEM_TEXT
bsp_send(int pid, const void* tag, const void* payload, int nbytes) {
    unsigned int index;
    unsigned int payload_offset;
    unsigned int total_nbytes = coredata.tagsize + nbytes;

    ebsp_message_queue* q =
        &combuf->message_queue[coredata.read_queue_index ^ 1];

    e_mutex_lock(0, 0, &coredata.payload_mutex);

    index = q->count;
    payload_offset = combuf->data_payloads.buffer_size;

    if ((payload_offset + total_nbytes > MAX_PAYLOAD_SIZE) ||
        (index >= MAX_MESSAGES)) {
        index = -1;
        payload_offset = -1;
    } else {
        q->count++;
        combuf->data_payloads.buffer_size += total_nbytes;
    }

    e_mutex_unlock(0, 0, &coredata.payload_mutex);

    if (index == -1)
        return ebsp_message(err_send_overflow);

    // We are now ready to save the request and payload
    void* tag_ptr = &combuf->data_payloads.buf[payload_offset];
    payload_offset += coredata.tagsize;
    void* payload_ptr = &combuf->data_payloads.buf[payload_offset];

    q->message[index].pid = pid;
    q->message[index].tag = tag_ptr;
    q->message[index].payload = payload_ptr;
    q->message[index].nbytes = nbytes;

    ebsp_memcpy(tag_ptr, tag, coredata.tagsize);
    ebsp_memcpy(payload_ptr, payload, nbytes);
}