int proc_hw_thread_exit( proc_interface_t * iface, void * ret)
{
    volatile int * cmd;
    int status;   

    if(ret != NULL) 
    {
        // Setup return value in V-HWTI
        *(iface->res_reg) = (int)ret;
        
        // Place return value in global TCB array for safe-keeping (V-HWTI return reg is too volatile when using dynamic APIs)
        // IMPORTANT - as V-HWTI may be re-used by a smart function, then move return value
        //to global data struct "threads" retval location
        volatile hthread_thread_t * tcb_array = (hthread_thread_t*) *(iface->gctx_ptr);
        Huint tid = *(iface->tid_reg);
        tcb_array[tid].retval = ret;
    }

    // IMPORTANT - set V-HWTI utilized field back to free!!!!!
    *(iface->uti_reg) = 0;

    // Perform hthread_exit()
    cmd = (int*)(encode_cmd(*(iface->tid_reg),HT_CMD_EXIT_THREAD));
    status = *cmd;

	 //xil_printf("Thread ID %d exit status = 0x%08x\r\n",*(iface->tid_reg), status);	
	 return status;
}
int proc_hw_thread_exit( proc_interface_t * iface, void * ret)
{
    volatile int * cmd;
    int status;  

    // Store execution time - 
    volatile hthread_time_t * timer = (hthread_time_t *) LOCAL_TIMER;
    hthread_time_t stop = *timer;
    hthread_time_t start = *(iface->execution_time);
    *(iface->execution_time) = stop-start;

    // Return a value (if any) first
    if(ret != NULL) 
    {
        // Setup return value in V-HWTI
        *(iface->res_reg) = (int)ret;
        
        // Place return value in global TCB array for safe-keeping 
        // (V-HWTI return reg is too volatile when using dynamic APIs)
        // IMPORTANT - as V-HWTI may be re-used by a smart function, then move return value
        //to global data struct "threads" retval location
        volatile hthread_thread_t * tcb_array = (hthread_thread_t*) *(iface->gctx_ptr);
        Huint tid = *(iface->tid_reg);
        tcb_array[tid].retval = ret;
    }

    // If there was an accelerator used, we need to update the
    // first use accelerator for this particular function it ran.
    // The host processor is responsible for writing the proper address.
    if (*(iface->first_used_accelerator) != MAGIC_NUMBER) {
        volatile unsigned int * first_used_acc = (unsigned int *) *(iface->first_used_ptr);
        if (first_used_acc != NULL)
            *first_used_acc = *(iface->first_used_accelerator);
    }

    // We should also update the last used accelerator, checking to see
    // if the previous last used accelerator is equal to the currently
    // loader accelerator.
    if (*(iface->last_used_accelerator) != prev_last_used_accelerator) {

        // Update the last used accelerator
        volatile unsigned int * last_used_acc = (unsigned int *) *(iface->last_used_ptr);
        if (last_used_acc != NULL) {
            *last_used_acc = *(iface->last_used_accelerator);
        }

        // Update the previous_last_used_accelerator to current
        prev_last_used_accelerator = *(iface->last_used_accelerator);
    }

    // Perform hthread_exit() second
    cmd = (int*)(encode_cmd(*(iface->tid_reg),HT_CMD_EXIT_THREAD));
    status = *cmd;

    // Mark in the V-HWTI that this slave is free third
    *(iface->uti_reg) = 0;

	 //xil_printf("Thread ID %d exit status = 0x%08x\r\n",*(iface->tid_reg), status);	
	 return status;
}
Beispiel #3
0
void test_command_with_args() {
    uint8_t buf[255];
    int pos = 0;
    int rc;
    uint8_t dest;
    uint8_t code;
    uint16_t mref;

    rc = encode_cmd(buf, &pos, LS1P_ADDR_ARM, LS1P_REQ_CODE_CMDLOG, 314);
    assert(rc == LS1P_API_OK);
    assert(pos == 3);
    assert(buf[0] == 0x01);

    rc = encode_uint8(buf, &pos, 123);
    assert(rc == LS1P_API_OK);
    assert(pos == 4);

    rc = encode_uint16(buf, &pos, 4023);
    assert(rc == LS1P_API_OK);
    assert(pos == 6);

    assert(buf[0] == 0x01);
    assert(buf[1] == 0x01);
    assert(buf[2] == 0x3A);
    assert(buf[3] == 0x7B);
    assert(buf[4] == 0x0F);
    assert(buf[5] == 0xB7);

    rc = decode_cmd(buf, &pos, &dest, &code, &mref);
    assert(rc == LS1P_API_OK);
    assert(dest == LS1P_ADDR_ARM);
    assert(code == LS1P_REQ_CODE_CMDLOG);
    assert(mref == 314);
    assert(pos == 3);
}
int main ( int argc, char *argv[] )
{
	if(argc<4) {
		printf("Expecting at least four params.\n");
		return 1;
	}
  wiringPiSetup () ;
  //setup pins
  pinMode (0, OUTPUT) ;//LED
  pinMode (1, OUTPUT) ;//Sender
  
  digitalWrite (1, LOW) ;
  int system_type=0;
  char unit_type='A';
  char onoff=0;
  int retries=5;
  system_type=atoi(argv[1]);
  unit_type=argv[2][0];
  if(strcmp(argv[3],"on")==0){
	  onoff=1;
  }
  if(argc>=4){
	  retries=atoi(argv[4]);
  }
  printf("Brennenstuhl remote power socket. \nSystem code: %i \nUnit code: %c\nSwitch %i ",system_type,unit_type,onoff);
  printf(argv[3]);
  printf("\nRetries %i\n",retries);
 
  
  
  
 

	//signal sending init
	int signal[PULSE_CNT];
	char cmd[CMD_LEN];
	if(encode_cmd(cmd,CMD_LEN,system_type,unit_type,onoff)){
		  if(encode_signal(signal,PULSE_CNT,cmd,CMD_LEN)){
			  int j=0;
			  for(j=0;j<retries;j++){
				  char pulse=START_PULSE;
				  int i=0;
				  for(i=0;i<PULSE_CNT;i++){
					 send_pulse(signal[i],pulse,1);
					 pulse=pulse*-1+1;
				  }
			  }
			  
		  }
	  }  
	  digitalWrite(0,LOW);
	  digitalWrite(1,LOW);
 
  return 0 ;
}
void proc_hw_thread_exit( proc_interface_t * iface, void * ret)
{
    volatile int * cmd;
    int status;   

    // Setup return value
    *(iface->res_reg) = (int)ret;

    cmd = (int*)(encode_cmd(*(iface->tid_reg),HT_CMD_EXIT_THREAD));
    status = *cmd;
}
Beispiel #6
0
void test_nonzero_dest()
{
    uint8_t buf[255];
    int pos = 0;
    int rc;

    rc = encode_cmd(buf, &pos, LS1P_ADDR_ARDUINO, LS1P_REQ_CODE_UNDEFINED, 315);
    assert(rc == LS1P_API_OK);
    assert(pos == 3);
    assert(buf[0] == 0x20);
}
Beispiel #7
0
int main( int argc, char *argv[] )
{
	unsigned int base;
	unsigned int cmd;
	unsigned int id;
	unsigned int mx;
    
	if( argc < 3 )
	{
		printf( "Usage: %s <thread id> <mutex id> [base addr]\n", argv[0] );
		return 1;
	}

	base	= BASE;
	id 	    = atoi( argv[1] );
    mx      = atoi( argv[2] );

	if( argc >= 4 )
	{
		base = strtol( argv[3], NULL, 16 );
	}
	
	printf( "\n\n" );
	printf(	"HWTI Base Address:      0x%04x\n", base	);
	printf( "Thread ID:              %u\n", id );
	printf( "Mutex ID:               %u\n", mx );
	printf( "-----------------------------------------------\n" );

	cmd = encode_cmd(id, HT_CMD_CLEAR_THREAD );
	printf(	"Clear Thread:           mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(id, HT_CMD_JOIN_THREAD );
	printf(	"Join Thread:            mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(id, HT_CMD_DETACH_THREAD );
	printf(	"Detach Thread:          mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(id, HT_CMD_READ_THREAD );
	printf(	"Read Thread:            mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(id, HT_CMD_ADD_THREAD );
	printf(	"Add Thread:             mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(id, HT_CMD_EXIT_THREAD );
	printf(	"Exit Thread:            mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_CREATE_THREAD_J );
	printf(	"Create Joinable Thread: mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_CREATE_THREAD_D );
	printf(	"Create Detached Thread: mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_NEXT_THREAD );
	printf(	"Next Thread:            mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_CURRENT_THREAD );
	printf(	"Current Thread:         mrd 0x%04x\n", cmd	);

    cmd = encode_cmd(0, HT_CMD_EXCEPTION_REG);
	printf(	"Exception Cause:        mrd 0x%04x\n", cmd	);

	cmd = sched_cmd(0, id, HT_CMD_SCHED_SET_IDLE_THREAD );
	printf(	"Idle Thread:            mrd 0x%04x\n", cmd	);

    cmd = sched_cmd(0, id, HT_CMD_SCHED_HIGHPRI );
	printf(	"High/DBG Thread:        mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_QUE_LENGTH );
	printf(	"Queue Length:           mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_SOFT_STOP );
	printf(	"Soft Stop:              mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_SOFT_START );
	printf(	"Soft Start:             mrd 0x%04x\n", cmd	);

	cmd = encode_cmd(0, HT_CMD_SOFT_RESET );
	printf(	"Soft Reset:             mrd 0x%04x\n", cmd	);

    cmd = mutex_cmd( HT_MUTEX_LOCK, id, mx );
    //cmd = blk_sema_cmd( HT_CMD_REQUEST, id, mx );
	printf(	"Mutex Lock:             mrd 0x%04x\n", cmd	);
    
    cmd = mutex_cmd( HT_MUTEX_UNLOCK, id, mx );
    //cmd = blk_sema_cmd( HT_CMD_RELEASE, id, mx );
	printf(	"Mutex Unlock:           mrd 0x%04x\n", cmd	);
    
    cmd = mutex_cmd( HT_MUTEX_TRY, id, mx );
    //cmd = blk_sema_cmd( HT_CMD_TRYLOCK, id, mx );
	printf(	"Mutex Try Lock:         mrd 0x%04x\n", cmd	);
    
    cmd = mutex_cmd( HT_MUTEX_OWNER, 0, mx );
	printf(	"Mutex Owner:            mrd 0x%04x\n", cmd	);
    
    cmd = mutex_cmd( HT_MUTEX_KIND, 0, mx );
	printf(	"Mutex Kind:             mrd 0x%04x\n", cmd	);
    
    cmd = mutex_cmd( HT_MUTEX_COUNT, 0, mx );
	printf(	"Mutex Count:            mrd 0x%04x\n", cmd	);
    
    cmd = cvr_sema_cmd(HT_CMD_SIGNAL, id, mx);
	printf(	"Cond Signal:            mrd 0x%04x\n", cmd	);

    cmd = cvr_sema_cmd(HT_CMD_CWAIT, id, mx);
	printf(	"Cond Wait:              mrd 0x%04x\n", cmd	);

    cmd = cvr_sema_cmd(HT_CMD_BROADCAST, id, mx);
	printf(	"Cond Broad:             mrd 0x%04x\n", cmd	);

    cmd = sched_cmd(0, id, HT_CMD_SCHED_ENTRY);
	printf(	"Sched Entry:            mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_SETSCHEDPARAM );
	printf(	"Set Sched Param:        mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_GETSCHEDPARAM );
	printf(	"Get Sched Param:        mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_SYSCALL_LOCK );
    cmd |= 0x00040000;
	printf(	"Syscall lock:           mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_SYSCALL_LOCK );
	printf(	"Syscall unlock:         mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_MALLOC_LOCK );
    cmd |= 0x00040000;
	printf(	"Malloc lock:            mrd 0x%04x\n", cmd	);

    cmd = sched_cmd( 0, id, HT_CMD_SCHED_MALLOC_LOCK );
	printf(	"Malloc unlock:          mrd 0x%04x\n", cmd	);

    cmd = hwti_cmd( base, HT_CMD_HWTI_COMMAND );
	printf(	"HWTI Reset:             mrd 0x%04x\n", cmd	);

    cmd = hwti_cmd( base, HT_CMD_HWTI_SETID );
	printf(	"HWTI Set ID:            mrd 0x%04x\n", cmd	);

    cmd = hwti_cmd( base, HT_CMD_HWTI_SETARG );
	printf(	"HWTI Set Arg:           mrd 0x%04x\n", cmd	);

    cmd = hwti_cmd( base, HT_CMD_HWTI_RESULTS );
	printf(	"HWTI Results:           mrd 0x%04x\n", cmd	);

    cmd = cbis_encode_cmd( CBIS_WRITE, id, mx );
	printf(	"CBIS Associate (TID = %d, IID = %d)  mrd 0x%04x\n", id, mx, cmd	);

	printf( "\n\n" );
	return 0;
}
int proc_hw_thread_exit( proc_interface_t * iface, void * ret)
{
    volatile int * cmd;
    int status;  
    volatile hthread_thread_t * tcb_array = (hthread_thread_t*) *(iface->gctx_ptr);

    // Store execution time - 
    hthread_time_t stop = hthread_time_get();
    hthread_time_t start = *(iface->execution_time);
    *(iface->execution_time) = stop-start;
    
    // Get TID for storing return value (if any) and
    // execution time back in TCB[tid].    
    Huint tid = *(iface->tid_reg);
    tcb_array[tid].execution_time = stop-start;

    // Return a value (if any) first
    if(ret != NULL) 
    {
        // Setup return value in V-HWTI
        *(iface->res_reg) = (int)ret;
        
        // Place return value in global TCB for safe-keeping before scheduling
        // another thread onto this slave (and using it's V-HWTI registers).
        tcb_array[tid].retval = ret;
    }

    // If there was an accelerator used, we need to update the
    // first use accelerator for this particular function it ran.
    // The host processor is responsible for writing the proper address.
    if (*(iface->first_used_accelerator) != NO_ACC) {
        volatile unsigned int * first_used_acc = (unsigned int *) *(iface->first_used_ptr);
        if (first_used_acc != NULL)
            *first_used_acc = *(iface->first_used_accelerator);
    }

    // We should also update the last used accelerator, checking to see
    // if the previous last used accelerator is equal to the currently
    // loader accelerator.
    if (*(iface->last_used_accelerator) != prev_last_used_accelerator) {

        // Update the last used accelerator
        volatile unsigned int * last_used_acc = (unsigned int *) *(iface->last_used_ptr);
        if (last_used_acc != NULL) {
            *last_used_acc = *(iface->last_used_accelerator);
        }

        // Update the previous_last_used_accelerator to current
        prev_last_used_accelerator = *(iface->last_used_accelerator);
    }

    // Perform hthread_exit() second
    cmd = (int*)(encode_cmd(*(iface->tid_reg),HT_CMD_EXIT_THREAD));
    status = *cmd;

    // Mark in the V-HWTI that this slave is free
    *(iface->uti_reg) = 0;

	 //xil_printf("Thread ID %d exit status = 0x%08x\r\n",*(iface->tid_reg), status);	
	 return status;
}