Beispiel #1
0
void led_error(void){
	while(1){
		uint32_t pinmask;
		pinmask = (1<<18);
		hwpl_core_privcall(led_priv_on, &pinmask);
		usleep(50*1000);
		hwpl_core_privcall(led_priv_off, &pinmask);
		usleep(50*1000);
	}
}
/*! \details This function sets \a thread's scheduling policy and scheduling parameters to
 * \a policy and \a param respectively.
 *
 * \return Zero on success or -1 with errno (see \ref ERRNO) set to:
 * - ESRCH:  thread is not a valid
 * - EINVAL:  param is NULL or the priority is invalid
 *
 */
int pthread_setschedparam(pthread_t thread,
		int policy,
		struct sched_param *param){

	int min_prio;
	int max_prio;
	priv_set_pthread_scheduling_param_t args;

	if ( param == NULL ){
		errno = EINVAL;
		return -1;
	}

	if ( sched_check_tid(thread) < 0 ){
		errno = ESRCH;
		return -1;
	}

	max_prio = sched_get_priority_max(policy);
	min_prio = sched_get_priority_min(policy);

	if ( ((uint8_t)param->sched_priority >= min_prio) &&
			((uint8_t)param->sched_priority <= max_prio) ){
		args.tid = thread;
		args.policy = policy;
		args.param = param;
		hwpl_core_privcall(priv_set_scheduling_param, &args);
		return 0;
	}

	//The scheduling priority is invalid
	errno = EINVAL;
	return -1;
}
Beispiel #3
0
link_phy_t link_phy_open(const char * name, int baudrate){
	link_phy_t fd;
	uint32_t pinmask;

#ifdef __PHY_USB
	fd = link_phy_usb_open();
	if( fd <  0){
		led_error();
		return -1;
	}

#else
	uart_attr_t attr;

	fd = open("/dev/uart0", O_RDWR);
	if( fd <  0){
		return -1;
	}

	attr.baudrate = 460800;
	attr.parity = UART_PARITY_EVEN;
	attr.pin_assign = 0;
	attr.start = UART_ATTR_START_BITS_1;
	attr.stop = UART_ATTR_STOP_BITS_2;
	attr.width = 8;
	if( ioctl(fd, I_UART_SETATTR, &attr) < 0 ){
		return -1;
	}

#endif

	pinmask = (1<<18);
	hwpl_core_privcall(led_priv_on, &pinmask);
	usleep(50*1000);
	hwpl_core_privcall(led_priv_off, &pinmask);
	pinmask = (1<<20);
	hwpl_core_privcall(led_priv_on, &pinmask);
	usleep(75*1000);
	hwpl_core_privcall(led_priv_off, &pinmask);
	pinmask = (1<<21);
	hwpl_core_privcall(led_priv_on, &pinmask);
	usleep(100*1000);
	hwpl_core_privcall(led_priv_off, &pinmask);
	pinmask = (1<<23);
	hwpl_core_privcall(led_priv_on, &pinmask);
	usleep(200*1000);
	hwpl_core_privcall(led_priv_off, &pinmask);

	link_phy_flush(fd);

#ifdef XIVELY
	init_devices();
#endif

	return fd;
}
void unistd_clr_action(open_file_t * open_file){
	unistd_priv_attr_t args;
	hwpl_action_t action;
	args.fs = open_file->fs;
	args.handle = open_file->handle;
	args.request = I_GLOBAL_SETACTION;
	args.ctl = &action;
	action.callback = 0;
	hwpl_core_privcall(unistd_priv_ioctl, &args);
}
Beispiel #5
0
void crt_load_data(void * global_impure, void * code_start, int code_size, int data_size){
	priv_load_data_t args;

	//If the caller doesn't have the ability to write this memory location, a fault will occur
	memset(global_impure, 0, data_size);

	//Now copy the data in priv mode
	args.global_impure = global_impure;
	args.data = code_start + code_size;
	args.size = data_size;
	hwpl_core_privcall(priv_load_data, &args);
}
Beispiel #6
0
int task_new_process(void (*p)(int,char*const*),
		void (*cleanup)(void*),
		int argc,
		char *const argv[],
		task_memories_t * mem,
		void * reent_ptr){

	int tid;
	int err;
	void * stackaddr;
	new_task_t task;
	task_memories_t task_memories;
	static int task_process_counter = 1;

	//Variable initialization
	stackaddr = mem->data.addr + mem->data.size;

	//Check the stack alignment
	if ( (unsigned int)stackaddr & 0x03 ){
		errno = EIO;
		return -1;
	}

	//Initialize the task
	task.stackaddr = stackaddr;
	task.start = (uint32_t)p;
	task.stop = (uint32_t)cleanup;
	task.r0 = (uint32_t)argc;
	task.r1 = (uint32_t)argv;

	task.pid = task_process_counter++; //Assign a new pid
	//task.mem_size = mem_size;
	task.reent = (struct _reent*)reent_ptr;
	task.global_reent = task.reent;

	task.flags = TASK_FLAGS_USED |
			TASK_FLAGS_PARENT(task_current);

	memcpy(&task_memories, mem, sizeof(task_memories_t));

	if ( (err = task_mpu_calc_protection(&task_memories)) < 0 ){
		return err;
	}
	task.mem = &task_memories;

	//Do a priv call while accessing the task table so there are no interruptions
	hwpl_core_privcall( (core_privcall_t)task_priv_new_task, &task);
	tid = task.tid;
	return tid;
}
Beispiel #7
0
void powerdown(int seconds){
	bool deepsleep;
	deepsleep = false;
	if ( seconds > 0 ){
		if (set_alarm(seconds) == 0 ){
			deepsleep = true;
		}
	} else if ( seconds == 0 ){
		deepsleep = true;
	}

	if ( deepsleep ){
		hwpl_core_privcall(priv_powerdown, NULL);
	}
}
Beispiel #8
0
int hibernate(int seconds){
	bool deepsleep;
	int ret = -1;
	deepsleep = false;
	if ( seconds > 0 ){
		if (set_alarm(seconds) == 0 ){
			deepsleep = true;
		}
	} else if ( seconds == 0 ){
		deepsleep = true;
	}


	if( deepsleep ){
		hwpl_core_privcall(priv_hibernate, NULL);
	}
	return ret;
}
Beispiel #9
0
void cl_dev_setdelay_mutex(pthread_mutex_t * mutex){
	hwpl_core_privcall(set_delay_mutex, mutex);
}
int device_data_transfer(open_file_t * open_file, void * buf, int nbyte, int read){
	int tmp;
	int mode;
	priv_device_data_transfer_t args;

	if ( nbyte == 0 ){
		return 0;
	}

	args.fs = (const sysfs_t*)open_file->fs;
	args.handle = (device_t *)open_file->handle;
	args.read = read;
	args.op.loc = open_file->loc;
	args.op.flags = open_file->flags;
	args.op.buf = buf;
	args.op.callback = priv_data_transfer_callback;
	args.op.context = &args;
#if SINGLE_TASK == 0
	args.op.tid = task_get_current();
#else
	args.op.tid = 0;
#endif

	if ( (mode = get_mode(args.fs, args.handle)) < 0 ){
		return -1;
	}

	//privilege call for the operation
	do {

#if SINGLE_TASK > 0
		waiting = false;
#endif
		args.op.nbyte = nbyte;
		args.ret = -101010;

		//This transfers the data
		hwpl_core_privcall(priv_device_data_transfer, &args);
		//We arrive here if the data is done transferring or there is no data to transfer and O_NONBLOCK is set
		//or if there was an error
		if( sched_get_unblock_type(task_get_current()) == SCHED_UNBLOCK_SIGNAL ){
			unistd_clr_action(open_file);
			errno = EINTR;
			return -1;
		}

#if SINGLE_TASK != 0
		while ( waiting == true ){
			core_sleep(CORE_SLEEP);
		}
#endif
		if ( args.ret > 0 ){
			//The operation happened synchronously
			tmp = args.ret;
			break;
		} else if ( args.ret == 0 ){
			//the operation happened asynchronously
			if ( args.op.nbyte > 0 ){
				//The operation has completed and transferred args.op.nbyte bytes
				tmp = args.op.nbyte;
				break;
			} else if ( args.op.nbyte == 0 ){
				//There was no data to read/write -- try again
				if (args.op.flags & O_NONBLOCK ){
					errno = ENODATA;
					return -1;
				}
			} else if ( args.op.nbyte < 0 ){
				//there was an error executing the operation (or the operation was cancelled)
				return -1;
			}
		} else if ( args.ret < 0 ){
			//there was an error starting the operation (such as EAGAIN)
			if( args.ret == -101010 ){
				errno = ENXIO; //this is a rare/strange error where hwpl_core_privcall fails to run properly
			}
			return -1;
		}
	} while ( args.ret == 0 );


	if ( ((mode & S_IFMT) != S_IFCHR) && (tmp > 0) ){
		open_file->loc += tmp;
	}

	return tmp;
}