Exemplo n.º 1
0
Arquivo: sched.c Projeto: nesl/umpu
void* ker_sys_get_module_state( void )
{
	sos_module_t *m = ker_get_module(curr_pid);
	
	if(m == NULL) return NULL;
	return m->handler_state;
}
Exemplo n.º 2
0
Arquivo: sched.c Projeto: nesl/umpu
/**
 * @brief get message rules
 */
int8_t sched_get_msg_rule(sos_pid_t pid, sos_ker_flag_t *rules)
{
  sos_module_t *handle = ker_get_module(pid);
  if(handle == NULL) return -EINVAL;
  *rules = handle->flag & 0xF0;
  return 0;
}
Exemplo n.º 3
0
Arquivo: sched.c Projeto: nesl/umpu
void* ker_get_module_state(sos_pid_t pid)
{
	sos_module_t *m = ker_get_module(pid);
	if(m == NULL) return NULL;
	
	return m->handler_state;
}
Exemplo n.º 4
0
Arquivo: sched.c Projeto: nesl/umpu
/**
 * @brief query the existence of task
 * @param pid module id
 * @return 0 for exist, -EINVAL otherwise
 *
 */
int8_t ker_query_task(uint8_t pid)
{
  sos_module_t *handle = ker_get_module(pid);
  if(handle == NULL){
	return -EINVAL;
  }
  return 0;
}
Exemplo n.º 5
0
Arquivo: sched.c Projeto: nesl/umpu
/**
 * @brief Message filtering rules interface
 * @param rules_in  new rule
 */
int8_t ker_msg_change_rules(sos_pid_t sid, uint8_t rules_in)
{
  sos_module_t *handle = ker_get_module(sid);
  if(handle == NULL) return -EINVAL;
  //! keep kernel state
  handle->flag &= 0x0F;

  handle->flag |= (rules_in & 0xF0);
  return 0;
}
Exemplo n.º 6
0
Arquivo: sched.c Projeto: nesl/umpu
/**
 * @brief register task with handle
 * Here we assume the state has been initialized.
 * We just need to link to the bin
 */
static int8_t sched_register_module(sos_module_t *h, mod_header_ptr p,
		void *init, uint8_t init_size)
{
  HAS_CRITICAL_SECTION;
  uint8_t num_timers;
  uint8_t bins = hash_pid(h->pid);

  if(ker_get_module(h->pid) != NULL) {
		return -EEXIST;
	//ker_deregister_module(h->pid);
	DEBUG("Module %d is already registered\n", h->pid);
  }

  //! Read the number of timers to be pre-allocated
  num_timers = sos_read_header_byte(p, offsetof(mod_header_t, num_timers));
  if (num_timers > 0){
	//! If there is no memory to pre-allocate the requested timers
	if (timer_preallocate(h->pid, num_timers) < 0){
		return -ENOMEM;
	}
  }

  // link the functions
  fntable_link(h);
  ENTER_CRITICAL_SECTION();
  /**
   * here is critical section.
   * We need to prevent others to search this module
   */
  // add to the bin
  h->next = mod_bin[bins];
  mod_bin[bins] = h;
  LEAVE_CRITICAL_SECTION();
  DEBUG("Register %d, Code ID %d,  Handle = %x\n", h->pid,
		  sos_read_header_byte(h, offsetof(mod_header_t, mod_id)),
		  (unsigned int)h);


  // send an init message to application
  // XXX : need to check the failure
  if(post_long(h->pid, KER_SCHED_PID, MSG_INIT, init_size, init, SOS_MSG_RELEASE | SOS_MSG_SYSTEM_PRIORITY) != SOS_OK) {
	  timer_remove_all(h->pid);
	  return -ENOMEM;
  }
  return SOS_OK;
}
Exemplo n.º 7
0
Arquivo: monitor.c Projeto: nesl/umpu
int8_t ker_register_monitor(sos_pid_t pid, uint8_t type, monitor_cb *cb)
{
	cb->mod_handle = ker_get_module(pid);
	if(cb->mod_handle == NULL) return -ESRCH;
	cb->type = type;
	cb->next = NULL;
	if(cb_list == NULL) {
		/**
		 * Current list is empty
		 */
		cb_list = cb;
	} else {
		/**
		 * List is not empty, traverse the list to the end
		 * and add this new CB
		 */
		monitor_cb *curr = cb_list;
		while(curr->next != NULL){ curr = curr->next; }
		curr->next = cb;
	}
	return SOS_OK;
}
Exemplo n.º 8
0
//----------------------------------------------------------
int8_t sfi_get_domain_id(sos_pid_t pid)
{
#ifdef SFI_DOMS_2
  return MOD_DOM_ID;
#endif
#ifdef SFI_DOMS_8
  int8_t retdomid;
  // Ram - For the time being assign all kernel PIDs to be
  // KER_DOM_ID
  sos_module_t* handle;
  if (pid < APP_MOD_MIN_PID){
    retdomid = KER_DOM_ID;
  }
  else{
    handle = ker_get_module(pid);
    if (NULL == handle)
      return -EINVAL;
    retdomid = sos_read_header_byte(handle->header, offsetof(mod_header_t, dom_id));
  }
  return retdomid;
#endif
}
Exemplo n.º 9
0
Arquivo: sched.c Projeto: nesl/umpu
/**
 * @brief dispatch short message
 * This is used by the callback that was register by interrupt handler
 */
void sched_dispatch_short_message(sos_pid_t dst, sos_pid_t src,
		uint8_t type, uint8_t byte,
		uint16_t word, uint16_t flag)
{
	sos_module_t *handle;
	msg_handler_t handler;
	void *handler_state;

	MsgParam *p;

	handle = ker_get_module(dst);
	if( handle == NULL ) { return; }

	handler = (msg_handler_t)sos_read_header_ptr(handle->header,
			offsetof(mod_header_t,
				module_handler));
	handler_state = handle->handler_state;

	p = (MsgParam*)(short_msg.data);	

	short_msg.did = dst;
	short_msg.sid = src;
	short_msg.type = type;
	p->byte = byte;
	p->word = word;
	short_msg.flag = flag;

	/*
	 * Update current pid
	 */
	//	curr_pid = dst;
	ker_log( SOS_LOG_HANDLE_MSG, curr_pid, type );
	ker_push_current_pid(dst);
	handler(handler_state, &short_msg);
	ker_pop_current_pid();
	ker_log( SOS_LOG_HANDLE_MSG_END, curr_pid, type );
}
Exemplo n.º 10
0
Arquivo: sched.c Projeto: nesl/umpu
static void do_dispatch()
{
  Message *e;                                // Current message being dispatched
  sos_module_t *handle;                      // Pointer to the control block of the destination module
  Message *inner_msg = NULL;                 // Message sent as a payload in MSG_PKT_SENDDONE
  sos_pid_t senddone_dst_pid = NULL_PID;     // Destination module ID for the MSG_PKT_SENDDONE
  uint8_t senddone_flag = SOS_MSG_SEND_FAIL; // Status information for the MSG_PKT_SENDDONE

  SOS_MEASUREMENT_DEQUEUE_START();
  e = mq_dequeue(&schedpq);
  SOS_MEASUREMENT_DEQUEUE_END();
  handle = ker_get_module(e->did);
  // Destination module might muck around with the
  // type field. So we check type before dispatch
	if(e->type == MSG_PKT_SENDDONE) {
		inner_msg = (Message*)(e->data);
	}
	// Check for reliable message delivery
	if(flag_msg_reliable(e->flag)) {
		senddone_dst_pid = e->sid;	
	}
	// Deliver message to the monitor
	// Ram - Modules might access kernel domain here
	monitor_deliver_incoming_msg_to_monitor(e);

	if(handle != NULL) {
		if(sched_message_filtered(handle, e) == false) {
			int8_t ret;
			msg_handler_t handler;
			void *handler_state;

			DEBUG("###################################################################\n");
			DEBUG("MESSAGE FROM %d TO %d OF TYPE %d\n", e->sid, e->did, e->type);
			DEBUG("###################################################################\n");


			// Get the function pointer to the message handler
			handler = (msg_handler_t)sos_read_header_ptr(handle->header,
					offsetof(mod_header_t,
						module_handler));
			// Get the pointer to the module state
			handler_state = handle->handler_state;
			// Change ownership if the release flag is set
			// Ram - How to deal with memory blocks that are not released ?
			if(flag_msg_release(e->flag)){
				ker_change_own(e->data, e->did);
			}

			DEBUG("RUNNING HANDLER OF MODULE %d \n", handle->pid);
			//			curr_pid = handle->pid;
			ker_log( SOS_LOG_HANDLE_MSG, curr_pid, e->type );
			ker_push_current_pid(handle->pid);
			ret = handler(handler_state, e);
			ker_pop_current_pid();
			ker_log( SOS_LOG_HANDLE_MSG_END, curr_pid, e->type );
			DEBUG("FINISHED HANDLER OF MODULE %d \n", handle->pid);
			if (ret == SOS_OK) senddone_flag = 0;
		}
	} else {
		//XXX no error notification for now.
		DEBUG("Scheduler: Unable to find module\n");
	}
	if(inner_msg != NULL) {
		//! this is SENDDONE message
		msg_dispose(inner_msg);
		msg_dispose(e);
	} else {
		if(senddone_dst_pid != NULL_PID) {
			if(post_long(senddone_dst_pid,
						KER_SCHED_PID,
						MSG_PKT_SENDDONE,
						sizeof(Message), e,
						senddone_flag) < 0) {
				msg_dispose(e);
			}
		} else {
			//! return message back to the pool
			msg_dispose(e);
		}
	}
}