Esempio n. 1
0
/* main function, don't change without consulting Josh */
int main(){
  init(); //call initializations
    
  //enable interrupts
  PMIC.CTRL = 7; //enable all interrupt levels
  sei();  //global interrupt enable
  
  while(1){  //don't break out of loop
    resolve_buffers(BUFFER_ALLOWED); //resolve some of the buffer
    
    if(in_queue){ //if there is a message, throw to the handler
      Message m; //set pointer to null
      int status = VECTOR_ERROR_TYPE;	//default to error
      queue_pop(&m, IN_QUEUE); //get incoming message
      
      //wait until allowed to start
      if(!start_ok && m.type != START_TYPE){
        free_msg(m);
        continue; 
      }
      
      //send to receiver
      uint8_t index = m.type & 0x3F; //index is last 6 bits of message type
      switch(m.type >> 6){ //determine data type (first 2 bits)
        case 0: //no data type
          if(index < NO_DATA_ARRAY_SIZE) status = (*no_data_func[index])(m);
          break;
        case 1: //1b data type
          if(index < DATA_1B_ARRAY_SIZE) status = (*data_1b_func[index])(m);
          break;
        case 2: //2b data type
          if(index < DATA_2B_ARRAY_SIZE) status = (*data_2b_func[index])(m);
          break;
        case 3: //nb data type
          if(index < DATA_NB_ARRAY_SIZE) status = (*data_nb_func[index])(m);
          break;
      }
      
      if(VECTOR_ERROR_TYPE == status) status = no_func(m); //report bad vectors
      
      free_msg(m);  //free data memory
      
      if(status != OK && status < 0x40){ //report single byte errors
        Message err; //create a message
        err.type = (uint8_t) status; //set the type to the error code
        err.size = 0;
        queue_push(err,OUT_QUEUE);  //report errors to host computer
      } 
    }
  }
}
Esempio n. 2
0
int semaphore_entry(void)
{
/* para evitar que la función modifique los valores del mensaje recibido, 
 * creamos variables locales de manera de evitar tener que acceder 
 * al mensaje para armar la respuesta, es más ineficiente, pero...
 */
	int return_val;

	sem_t sema;
	sem_t *semaux;
	int pshared, oflags, permission, initial, value_now, argc, phsared;
	char name[MAX_NAME];



#ifdef DEBUG
/*
int i;
char *m1;*/
printf("en el semaphore.c\n");/*
for (i = 0; i < 100; i++)
{
	if ((m1 = malloc(128)) == NULL)
	{
		printf("FALLO MALLOC en la iteracion %d\n", i);
		break;
	}
	strcpy(m1, "malloc\n");
	printf("i = %d m1 = %d m1 = %s\n", i, (int)m1, m1);
}*/
#endif
	


	sema = mensaje_semaforo;
	oflags = mensaje_oflag;
	permission = mensaje_permisos;
	initial = mensaje_valInicial;
	value_now = mensaje_valActual;
	argc = mensaje_cantArg;
	pshared = mensaje_pshared;

	sys_copy (who, D, (phys_bytes) mensaje_nombre, FS_PROC_NR, D,  (phys_bytes) name,  (phys_bytes) MAX_NAME);
	name[MAX_NAME - 1] = '\0';

	switch(mensaje_funcion)
	{
		case SEM_OPEN: if (argc == 4)
			       {
#ifdef DEBUG
printf("SEMOPEN name: %s, oflags: %d, permission: %d, initial: %d\n", name, oflags, permission, initial);
#endif 
					semaux = sem_open(name, oflags, permission,
								   initial);
			       }
			       else
			       {
#ifdef DEBUG
printf("SEMOPEN name: %s, oflags: %d\n", name, oflags);
#endif 
					semaux = sem_open(name, oflags);
			       }
			       answer(*semaux,0,0,1);
			       break;

		case SEM_CLOSE: 
				return_val = sem_close(&sema);
				answer(return_val,sema,0,2);
				break;

		case SEM_INIT:  return_val = sem_init(&sema, pshared, initial);
				answer(return_val,sema,0,2);
				break;

		case SEM_WAIT:  return_val = sem_wait(&sema);
				answer(return_val,sema,0,2);
				break;

		case SEM_POST:  return_val = sem_post(&sema);
				answer(return_val,sema,0,2);
				break;

		case SEM_ULINK: return_val = sem_unlink(name);
				answer(return_val,0,0,1);
				break;

		case SEM_GETVAL: return_val = sem_getvalue(&sema, &value_now);
				 answer(return_val,sema,value_now,3);
				 break;

		case SEM_TRYWAIT: return_val = sem_trywait(&sema);
				  answer(return_val,sema,0,2);
				  break;
 
		case SEM_DESTROY: return_val = sem_destroy(&sema);
				  answer(return_val,sema,0,2);
				  break;

		case SEM_TIMEDWAIT: return_val = no_func();
				    answer(return_val,0,0,1);
				    break;
	}
#ifdef DEBUG
printf("fin de semaphore.c\n");
#endif
	if (return_val != 0)
		return (errno);		
	return(OK);
}
Esempio n. 3
0
///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////

#include "exsdk.h"
#include "lua.h"
#include "lauxlib.h"
#include "lualib.h"

///////////////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////////////

const char *buff = "\
function test_1 () no_func() end\n\
function test_2 ( x, y )\n\
    print(x)\n\
    print(y)\n\
    test_1()\n\
end\n\
my_table = { t = test_2 }\n\
";

static int __traceback ( lua_State *_l ) {
    lua_getglobal ( _l, "debug" );
    lua_getfield ( _l, -1, "traceback" );
    lua_pushvalue ( _l, 1 );
    lua_pushinteger ( _l, 2 );
    lua_call ( _l, 2, 1 );
    return 1;