Ejemplo n.º 1
0
void wd_initialize(void)
{
  /* Initialize the free watchdog list */

  sq_init(&g_wdfreelist);

  /* The g_wdfreelist must be loaded at initialization time to hold the
   * configured number of watchdogs.
   */

  g_wdpool = (FAR wdog_t*)kmalloc(sizeof(wdog_t) * CONFIG_PREALLOC_WDOGS);
  if (g_wdpool)
    {
      FAR wdog_t *wdog = g_wdpool;
      int i;

      for (i = 0; i < CONFIG_PREALLOC_WDOGS; i++)
        {
          sq_addlast((FAR sq_entry_t*)wdog++, &g_wdfreelist);
        }
    }

  /* The g_wdactivelist queue must be reset at initialization time. */

  sq_init(&g_wdactivelist);
}
Ejemplo n.º 2
0
static inline void psock_lost_connection(FAR struct socket *psock,
        FAR struct tcp_conn_s *conn)
{
    FAR sq_entry_t *entry;
    FAR sq_entry_t *next;

    /* Do not allow any further callbacks */

    psock->s_sndcb->flags = 0;
    psock->s_sndcb->event = NULL;

    /* Free all queued write buffers */

    for (entry = sq_peek(&conn->unacked_q); entry; entry = next)
    {
        next = sq_next(entry);
        tcp_wrbuffer_release((FAR struct tcp_wrbuffer_s *)entry);
    }

    for (entry = sq_peek(&conn->write_q); entry; entry = next)
    {
        next = sq_next(entry);
        tcp_wrbuffer_release((FAR struct tcp_wrbuffer_s *)entry);
    }

    /* Reset write buffering variables */

    sq_init(&conn->unacked_q);
    sq_init(&conn->write_q);
    conn->sent = 0;
}
Ejemplo n.º 3
0
void sig_initialize(void)
{
  /* Initialize free lists */

  sq_init(&g_sigfreeaction);
  sq_init(&g_sigpendingaction);
  sq_init(&g_sigpendingirqaction);
  sq_init(&g_sigpendingsignal);
  sq_init(&g_sigpendingirqsignal);

  /* Add a block of signal structures to each list */

  g_sigpendingactionalloc =
     sig_allocateblock(&g_sigpendingaction,
                       NUM_PENDING_ACTIONS,
                       SIG_ALLOC_FIXED);

  g_sigpendingirqactionalloc =
     sig_allocateblock(&g_sigpendingirqaction,
                       NUM_PENDING_INT_ACTIONS,
                       SIG_ALLOC_IRQ);

  sig_allocateactionblock();

  g_sigpendingsignalalloc =
     sig_allocatependingsignalblock(&g_sigpendingsignal,
                             NUM_SIGNALS_PENDING,
                             SIG_ALLOC_FIXED);

  g_sigpendingirqsignalalloc =
     sig_allocatependingsignalblock(&g_sigpendingirqsignal,
                             NUM_INT_SIGNALS_PENDING,
                             SIG_ALLOC_IRQ);
}
Ejemplo n.º 4
0
/**
 * @brief Receiving data process initialization
 *
 * This function allocates OS resource to support the data receiving
 * function. It allocates buffers for receiving data.
 * The semaphore works as message queue and all tasks are done in the
 * thread.
 *
 * @param bundle Greybus bundle handle
 * @return 0 for success, -errno for failures.
 */
static int uart_receiver_cb_init(struct gb_bundle *bundle)
{
    struct gb_uart_info *info = bundle->priv;
    int ret;

    sq_init(&info->free_queue);
    sq_init(&info->data_queue);

    info->entries = MAX_RX_BUF_NUMBER;
    info->rx_buf_size = MAX_RX_BUF_SIZE;

    ret = uart_alloc_buf(info->entries, info->rx_buf_size, &info->free_queue);
    if (ret) {
        goto err_free_data_buf;
    }

    ret = sem_init(&info->rx_sem, 0, 0);
    if (ret) {
        goto err_free_data_buf;
    }

    ret = pthread_create(&info->rx_thread, NULL, uart_rx_thread, bundle);
    if (ret) {
        goto err_destroy_rx_sem;
    }

    return 0;

err_destroy_rx_sem:
    sem_destroy(&info->rx_sem);
err_free_data_buf:
    uart_free_buf(&info->free_queue);

    return ret;
}
Ejemplo n.º 5
0
void mq_initialize(void)
{
  /* Initialize the message free lists */

  sq_init(&g_msgfree);
  sq_init(&g_msgfreeirq);
  sq_init(&g_desalloc);

  /* Allocate a block of messages for general use */

  g_msgalloc =
    mq_msgblockalloc(&g_msgfree, CONFIG_PREALLOC_MQ_MSGS,
                     MQ_ALLOC_FIXED);

  /* Allocate a block of messages for use exclusively by
   * interrupt handlers
   */

  g_msgfreeirqalloc =
    mq_msgblockalloc(&g_msgfreeirq, NUM_INTERRUPT_MSGS,
                     MQ_ALLOC_IRQ);

  /* Allocate a block of message queue descriptors */

  mq_desblockalloc();
}
Ejemplo n.º 6
0
/**
 * @brief Receiving data process initialization
 *
 * This function allocates OS resource to support the data receiving
 * function. It allocates two types of operations for undetermined length of
 * data. The semaphore works as message queue and all tasks are done in the
 * thread.
 *
 * @param None.
 * @return 0 for success, -errno for failures.
 */
static int uart_receiver_cb_init(void)
{
    int ret;

    sq_init(&info->free_queue);
    sq_init(&info->data_queue);

    info->entries = MAX_RX_OPERATION;
    info->rx_buf_size = MAX_RX_BUF_SIZE;

    ret = uart_alloc_op(info->entries, info->rx_buf_size, &info->free_queue);
    if (ret) {
        return ret;
    }

    ret = sem_init(&info->rx_sem, 0, 0);
    if (ret) {
        goto err_free_data_op;
    }

    ret = pthread_create(&info->rx_thread, NULL, uart_rx_thread, info);
    if (ret) {
        goto err_destroy_rx_sem;
    }

    return 0;

err_destroy_rx_sem:
    sem_destroy(&info->rx_sem);
err_free_data_op:
    uart_free_op(&info->free_queue);

    return -ret;
}
Ejemplo n.º 7
0
struct uip_conn *uip_tcpaccept(struct uip_tcpip_hdr *buf)
{
  struct uip_conn *conn = uip_tcpalloc();
  if (conn)
    {
      /* Fill in the necessary fields for the new connection. */

      conn->rto           = UIP_RTO;
      conn->timer         = UIP_RTO;
      conn->sa            = 0;
      conn->sv            = 4;
      conn->nrtx          = 0;
      conn->lport         = buf->destport;
      conn->rport         = buf->srcport;
      conn->mss           = UIP_TCP_INITIAL_MSS;
      uip_ipaddr_copy(conn->ripaddr, uip_ip4addr_conv(buf->srcipaddr));
      conn->tcpstateflags = UIP_SYN_RCVD;

      uip_tcpinitsequence(conn->sndseq);
      conn->unacked       = 1;
#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
      conn->expired       = 0;
      conn->isn           = 0;
      conn->sent          = 0;
#endif

      /* rcvseq should be the seqno from the incoming packet + 1. */

      memcpy(conn->rcvseq, buf->seqno, 4);

#ifdef CONFIG_NET_TCP_READAHEAD
      /* Initialize the list of TCP read-ahead buffers */

      sq_init(&conn->readahead);
#endif

#ifdef CONFIG_NET_TCP_WRITE_BUFFERS
      /* Initialize the write buffer lists */

      sq_init(&conn->write_q);
      sq_init(&conn->unacked_q);
#endif

      /* And, finally, put the connection structure into the active list.
       * Interrupts should already be disabled in this context.
       */

      dq_addlast(&conn->node, &g_active_tcp_connections);
    }

  return conn;
}
Ejemplo n.º 8
0
int main ( int argc, char * argv[] )
{
#ifndef SQ_DISABLE_AUTOMATION_INTERFACE
   static SQServer server;

   sq_init ();

   sq_server_init ( &server, 4321 );

   type_test_init();

   while ( SQ_TRUE )
   {
      if ( sq_thread_is_supported() )
      {
         sq_system_sleep ( 1000 );
      }
      sq_server_poll ( &server );
   }

   sq_shutdown ();
#endif

   SQ_UNUSED_PARAMETER(argc);
   SQ_UNUSED_PARAMETER(argv);
}
Ejemplo n.º 9
0
void up_dmainitialize(void)
{
  int i;

  for (i = 0; i < DMA_CHANNEL_NUM; i++)
    {
      g_dma.phydmach[i].inprogress = 0;
      sq_init(&g_dma.phydmach[i].req_q);
    }

  nxsem_init(&g_dma.exclsem, 0, 1);

  if (irq_attach(LC823450_IRQ_DMAC, dma_interrupt, NULL) != 0)
    {
      return;
    }
  up_enable_irq(LC823450_IRQ_DMAC);

  /* Clock & Reset */

  modifyreg32(MCLKCNTBASIC, 0, MCLKCNTBASIC_DMAC_CLKEN);
  modifyreg32(MRSTCNTBASIC, 0, MRSTCNTBASIC_DMAC_RSTB);

  /* DMAC enable */

  modifyreg32(DMACCONFIG, 0, DMACCONFIG_EN);

#ifdef DMA_TEST
  lc823450_dma_test();
#endif

  /* clock disable */

  modifyreg32(MCLKCNTBASIC, MCLKCNTBASIC_DMAC_CLKEN, 0);
}
Ejemplo n.º 10
0
void SpacePlane::init(){

	static bool initialized = false;
	if(!initialized){
		sq_init(modPath() << _SC("models/SpacePlane.nut"),
			ModelScaleProcess(modelScale) <<=
			SingleDoubleProcess(hitRadius, _SC("hitRadius")) <<=
			MassProcess(defaultMass) <<=
			SingleDoubleProcess(maxHealthValue, _SC("maxhealth"), false) <<=
			Vec3dListProcess(engines, _SC("engines")) <<=
			DrawOverlayProcess(overlayDisp)
			);
		initialized = true;
	}

	undocktime = 0.f;
	health = getMaxHealth();
	mass = defaultMass;
	people = RandomSequence((unsigned long)this).next() % 100 + 100;
	engineHeat = 0.f;

	pf.resize(engines.size());
	for(int i = 0; i < pf.size(); i++)
		pf[i] = NULL;
}
Ejemplo n.º 11
0
/*
 * Initialise the HRT.
 */
void	hrt_init(void)
{
	//printf("hrt_init\n");
	sq_init(&callout_queue);
	sem_init(&_hrt_lock, 0, 1);
	memset(&_hrt_work, 0, sizeof(_hrt_work));
}
void net_initroute(void)
{
  int i;

  /* Initialize the routing table and the free list */

  sq_init(&g_routes);
  sq_init(&g_freeroutes);

  /* All all of the pre-allocated routing table entries to a free list */

  for (i = 0; i < CONFIG_NET_MAXROUTES; i++)
    {
      sq_addlast((FAR sq_entry_t *)&g_preallocroutes[i],
                 (FAR sq_queue_t *)&g_freeroutes);
    }    
}
Ejemplo n.º 13
0
void uip_tcpreadaheadinit(void)
{
    int i;

    sq_init(&g_freebuffers);
    for (i = 0; i < CONFIG_NET_NTCP_READAHEAD_BUFFERS; i++)
    {
        sq_addfirst(&g_buffers[i].rh_node, &g_freebuffers);
    }
}
Ejemplo n.º 14
0
/**
 * Initialise the high-resolution timing module.
 */
void
hrt_init(void)
{
	sq_init(&callout_queue);
	hrt_tim_init();

#ifdef HRT_PPM_CHANNEL
	/* configure the PPM input pin */
	stm32_configgpio(GPIO_PPM_IN);
#endif
}
Ejemplo n.º 15
0
void pm_initialize(void)
{
  /* Initialize the registry and the PM global data structures.  The PM
   * global data structure resides in .bss which is zeroed at boot time.  So
   * it is only required to initialize non-zero elements of the PM global
   * data structure here.
   */

  sq_init(&g_pmglobals.registry);
  sem_init(&g_pmglobals.regsem, 0, 1);
}
Ejemplo n.º 16
0
/*
 * Initialise the HRT.
 */
void	hrt_init(void)
{
	sq_init(&callout_queue);

	int sem_ret = px4_sem_init(&_hrt_lock, 0, 1);

	if (sem_ret) {
		PX4_ERR("SEM INIT FAIL: %s", strerror(errno));
	}

	memset(&_hrt_work, 0, sizeof(_hrt_work));
}
Ejemplo n.º 17
0
void uip_tcpwrbuffer_init(void)
{
  int i;

  sq_init(&g_wrbuffer.freebuffers);

  for (i = 0; i < CONFIG_NET_NTCP_WRITE_BUFFERS; i++)
    {
      sq_addfirst(&g_wrbuffer.buffers[i].wb_node, &g_wrbuffer.freebuffers);
    }

  sem_init(&g_wrbuffer.sem, 0, CONFIG_NET_NTCP_WRITE_BUFFERS);
}
Ejemplo n.º 18
0
int conman_client_handle_events(struct conman_client_s *client)
{
  sq_queue_t qevents;
  int ret;

  sq_init(&qevents);

  ret = conman_wait_for_response(client, true, &qevents);

  handle_queued_events(client, &qevents);

  return ret;
}
Ejemplo n.º 19
0
void tcp_wrbuffer_initialize(void)
{
  int i;

  sq_init(&g_wrbuffer.freebuffers);

  for (i = 0; i < CONFIG_NET_TCP_NWRBCHAINS; i++)
    {
      sq_addfirst(&g_wrbuffer.buffers[i].wb_node, &g_wrbuffer.freebuffers);
    }

  sem_init(&g_wrbuffer.sem, 0, CONFIG_NET_TCP_NWRBCHAINS);
}
Ejemplo n.º 20
0
void ieee80211_crypto_attach(struct ieee80211_s *ic)
{
  sq_init(&ic->ic_pmksa);
  if (ic->ic_caps & IEEE80211_C_RSN)
    {
      ic->ic_rsnprotos = IEEE80211_PROTO_WPA | IEEE80211_PROTO_RSN;
      ic->ic_rsnakms = IEEE80211_AKM_PSK;
      ic->ic_rsnciphers = IEEE80211_CIPHER_TKIP | IEEE80211_CIPHER_CCMP;
      ic->ic_rsngroupcipher = IEEE80211_CIPHER_TKIP;
      ic->ic_rsngroupmgmtcipher = IEEE80211_CIPHER_BIP;
    }

  ic->ic_set_key = ieee80211_set_key;
  ic->ic_delete_key = ieee80211_delete_key;
}
Ejemplo n.º 21
0
int conman_client_get_connection_status(struct conman_client_s *client,
                                        struct conman_status_s *status)
{
  sq_queue_t qevents;
  int ret;

  if (!status)
    {
      return ERROR;
    }

  ret = conman_send_req(client->sd, CONMAN_MSG_GET_CONNECTION_STATUS,
                        NULL, 0);
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(sizeof(*status) == client->payloadlen);

  memcpy(status, client->payload, sizeof(*status));
  free(client->payload);
  client->payload = NULL;

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Ejemplo n.º 22
0
Archivo: if_sq.c Proyecto: MarginC/kame
int
sq_ioctl(struct ifnet *ifp, u_long cmd, caddr_t data)
{
	int s, error = 0;

	s = splnet();

	error = ether_ioctl(ifp, cmd, data);
	if (error == ENETRESET) {
		/*
		 * Multicast list has changed; set the hardware filter
		 * accordingly.
		 */
		error = sq_init(ifp);
	}

	splx(s);
	return (error);
}
Ejemplo n.º 23
0
int conman_client_request_connection(struct conman_client_s *client,
                                     enum conman_connection_type_e type,
                                     uint32_t *connid)
{
  sq_queue_t qevents;
  int ret;

  ret = conman_send_req(client->sd, CONMAN_MSG_CREATE_CONNECTION, &type,
      sizeof(type));
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(sizeof(*connid) == client->payloadlen);

  memcpy(connid, client->payload, sizeof(*connid));
  free(client->payload);
  client->payload = NULL;

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Ejemplo n.º 24
0
Archivo: if_sq.c Proyecto: MarginC/kame
/* Device timeout/watchdog routine. */
void
sq_watchdog(struct ifnet *ifp)
{
	u_int32_t status;
	struct sq_softc *sc = ifp->if_softc;

	status = bus_space_read_4(sc->sc_hpct, sc->sc_hpch, HPC_ENETX_CTL);
	log(LOG_ERR, "%s: device timeout (prev %d, next %d, free %d, "
		     "status %08x)\n", sc->sc_dev.dv_xname, sc->sc_prevtx,
				       sc->sc_nexttx, sc->sc_nfreetx, status);

	sq_trace_dump(sc);

	memset(&sq_trace, 0, sizeof(sq_trace));
	sq_trace_idx = 0;

	++ifp->if_oerrors;

	sq_init(ifp);
}
Ejemplo n.º 25
0
int
camera_init(Camera *camera, GPContext *context)
{
	GPPortSettings settings;
	int ret = 0;

	/* First, set up all the function pointers */
	camera->functions->summary	= camera_summary;
	camera->functions->manual	= camera_manual;
	camera->functions->about	= camera_about;
	camera->functions->capture_preview
					= camera_capture_preview;
	camera->functions->exit		= camera_exit;

	GP_DEBUG ("Initializing the camera\n");

	ret = gp_port_get_settings(camera->port,&settings);
	if (ret < 0) return ret;
 
	ret = gp_port_set_settings(camera->port,settings);
	if (ret < 0) return ret;

	/* Tell the CameraFilesystem where to get lists from */
	gp_filesystem_set_funcs (camera->fs, &fsfuncs, camera);
	camera->pl = malloc (sizeof (CameraPrivateLibrary));
	if (!camera->pl) return GP_ERROR_NO_MEMORY;
	camera->pl->model = 0;
	camera->pl->catalog = NULL;
	camera->pl->nb_entries = 0;
	camera->pl->last_fetched_entry = -1;
	camera->pl->last_fetched_data = NULL;

	/* Connect to the camera */
	ret = sq_init (camera->port, camera->pl);
	if (ret != GP_OK) {
		free(camera->pl);
		return ret;
	};

	return GP_OK;
}
Ejemplo n.º 26
0
static int do_command_no_payload(struct conman_client_s *client, uint8_t type,
                                 const void *buf, size_t buflen)
{
  sq_queue_t qevents;
  int ret;

  ret = conman_send_req(client->sd, type, buf, buflen);
  if (ret != OK)
    {
      conman_dbg("conman_send_req failed\n");
      return ERROR;
    }

  sq_init(&qevents);

  ret = conman_wait_for_response(client, false, &qevents);
  if (ret != OK)
    {
      conman_dbg("conman communication failed\n");
      ret = ERROR;
      goto out;
    }

  if (client->respval != CONMAN_RESP_OK)
    {
      ret = ERROR;
      goto out;
    }

  DEBUGASSERT(client->payload == NULL);

  ret = OK;

out:
  handle_queued_events(client, &qevents);
  return ret;
}
Ejemplo n.º 27
0
int
sq_ioctl(struct ifnet *ifp, u_long cmd, void *data)
{
	int s, error = 0;

	SQ_TRACE(SQ_IOCTL, (struct sq_softc *)ifp->if_softc, 0, 0);

	s = splnet();

	error = ether_ioctl(ifp, cmd, data);
	if (error == ENETRESET) {
		/*
		 * Multicast list has changed; set the hardware filter
		 * accordingly.
		 */
		if (ifp->if_flags & IFF_RUNNING)
			error = sq_init(ifp);
		else
			error = 0;
	}

	splx(s);
	return error;
}
Ejemplo n.º 28
0
int uip_tcpconnect(struct uip_conn *conn, const struct sockaddr_in *addr)
#endif
{
  uip_lock_t flags;
  int port;

  /* The connection is expected to be in the UIP_ALLOCATED state.. i.e.,
   * allocated via up_tcpalloc(), but not yet put into the active connections
   * list.
   */

  if (!conn || conn->tcpstateflags != UIP_ALLOCATED)
    {
      return -EISCONN;
    }

  /* If the TCP port has not alread been bound to a local port, then select
   * one now.
   */

  flags = uip_lock();
  port = uip_selectport(ntohs(conn->lport));
  uip_unlock(flags);

  if (port < 0)
    {
      return port;
    }

  /* Initialize and return the connection structure, bind it to the port number */

  conn->tcpstateflags = UIP_SYN_SENT;
  uip_tcpinitsequence(conn->sndseq);

  conn->initialmss = conn->mss = UIP_TCP_MSS;
  conn->unacked    = 1;    /* TCP length of the SYN is one. */
  conn->nrtx       = 0;
  conn->timer      = 1;    /* Send the SYN next time around. */
  conn->rto        = UIP_RTO;
  conn->sa         = 0;
  conn->sv         = 16;   /* Initial value of the RTT variance. */
  conn->lport      = htons((uint16_t)port);

  /* The sockaddr port is 16 bits and already in network order */

  conn->rport = addr->sin_port;

  /* The sockaddr address is 32-bits in network order. */

  uip_ipaddr_copy(conn->ripaddr, addr->sin_addr.s_addr);

  /* Initialize the list of TCP read-ahead buffers */

#if CONFIG_NET_NTCP_READAHEAD_BUFFERS > 0
  sq_init(&conn->readahead);
#endif

  /* And, finally, put the connection structure into the active
   * list. Because g_active_tcp_connections is accessed from user level and
   * interrupt level, code, it is necessary to keep interrupts disabled during
   * this operation.
   */

  flags = uip_lock();
  dq_addlast(&conn->node, &g_active_tcp_connections);
  uip_unlock(flags);

  return OK;
}
Ejemplo n.º 29
0
void os_start(void)
{
  int i;

  slldbg("Entry\n");

  /* Initialize all task lists */

  dq_init(&g_readytorun);
  dq_init(&g_pendingtasks);
  dq_init(&g_waitingforsemaphore);
#ifndef CONFIG_DISABLE_SIGNALS
  dq_init(&g_waitingforsignal);
#endif
#ifndef CONFIG_DISABLE_MQUEUE
  dq_init(&g_waitingformqnotfull);
  dq_init(&g_waitingformqnotempty);
#endif
#ifdef CONFIG_PAGING
  dq_init(&g_waitingforfill);
#endif
  dq_init(&g_inactivetasks);
  sq_init(&g_delayeddeallocations);

  /* Initialize the logic that determine unique process IDs. */

  g_lastpid = 0;
  for (i = 0; i < CONFIG_MAX_TASKS; i++)
    {
      g_pidhash[i].tcb = NULL;
      g_pidhash[i].pid = INVALID_PROCESS_ID;
    }

  /* Assign the process ID of ZERO to the idle task */

  g_pidhash[ PIDHASH(0)].tcb = &g_idletcb;
  g_pidhash[ PIDHASH(0)].pid = 0;

  /* Initialize a TCB for this thread of execution.  NOTE:  The default
   * value for most components of the g_idletcb are zero.  The entire
   * structure is set to zero.  Then only the (potentially) non-zero
   * elements are initialized. NOTE:  The idle task is the only task in
   * that has pid == 0 and sched_priority == 0.
   */

  bzero((void*)&g_idletcb, sizeof(_TCB));
  g_idletcb.task_state = TSTATE_TASK_RUNNING;
  g_idletcb.entry.main = (main_t)os_start;

#if CONFIG_TASK_NAME_SIZE > 0
  strncpy(g_idletcb.name, g_idlename, CONFIG_TASK_NAME_SIZE-1);
  g_idletcb.argv[0] = g_idletcb.name;
#else
  g_idletcb.argv[0] = (char*)g_idlename;
#endif /* CONFIG_TASK_NAME_SIZE */

  /* Then add the idle task's TCB to the head of the ready to run list */

  dq_addfirst((FAR dq_entry_t*)&g_idletcb, (FAR dq_queue_t*)&g_readytorun);

  /* Initialize the processor-specific portion of the TCB */

  g_idletcb.flags = TCB_FLAG_TTYPE_KERNEL;
  up_initial_state(&g_idletcb);

  /* Initialize the semaphore facility(if in link).  This has to be done
   * very early because many subsystems depend upon fully functional
   * semaphores.
   */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (sem_initialize != NULL)
#endif
    {
      sem_initialize();
    }

  /* Initialize the memory manager */

#ifndef CONFIG_HEAP_BASE
  {
    FAR void *heap_start;
    size_t heap_size;
    up_allocate_heap(&heap_start, &heap_size);
    kmm_initialize(heap_start, heap_size);
  }
#else
  kmm_initialize((void*)CONFIG_HEAP_BASE, CONFIG_HEAP_SIZE);
#endif

  /* Initialize the interrupt handling subsystem (if included) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (irq_initialize != NULL)
#endif
    {
      irq_initialize();
    }

  /* Initialize the watchdog facility (if included in the link) */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (wd_initialize != NULL)
#endif
    {
      wd_initialize();
    }

  /* Initialize the POSIX timer facility (if included in the link) */

#ifndef CONFIG_DISABLE_CLOCK
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (clock_initialize != NULL)
#endif
    {
      clock_initialize();
    }
#endif

#ifndef CONFIG_DISABLE_POSIX_TIMERS
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (timer_initialize != NULL)
#endif
    {
      timer_initialize();
    }
#endif

  /* Initialize the signal facility (if in link) */

#ifndef CONFIG_DISABLE_SIGNALS
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (sig_initialize != NULL)
#endif
    {
      sig_initialize();
    }
#endif

  /* Initialize the named message queue facility (if in link) */

#ifndef CONFIG_DISABLE_MQUEUE
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (mq_initialize != NULL)
#endif
    {
      mq_initialize();
    }
#endif

  /* Initialize the thread-specific data facility (if in link) */

#ifndef CONFIG_DISABLE_PTHREAD
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (pthread_initialize != NULL)
#endif
    {
      pthread_initialize();
    }
#endif

  /* Initialize the file system (needed to support device drivers) */

#if CONFIG_NFILE_DESCRIPTORS > 0
#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (fs_initialize != NULL)
#endif
    {
      fs_initialize();
    }
#endif

  /* Initialize the network system */

#ifdef CONFIG_NET
#if 0
  if (net_initialize != NULL)
#endif
    {
      net_initialize();
    }
#endif

  /* The processor specific details of running the operating system
   * will be handled here.  Such things as setting up interrupt
   * service routines and starting the clock are some of the things
   * that are different for each  processor and hardware platform.
   */

  up_initialize();

  /* Initialize the C libraries (if included in the link).  This
   * is done last because the libraries may depend on the above.
   */

#ifdef CONFIG_HAVE_WEAKFUNCTIONS
  if (lib_initialize != NULL)
#endif
    {
      lib_initialize();
    }

  /* Create stdout, stderr, stdin on the IDLE task.  These will be
   * inherited by all of the threads created by the IDLE task.
   */

  (void)sched_setupidlefiles(&g_idletcb);

  /* Create initial tasks and bring-up the system */

  (void)os_bringup();

  /* When control is return to this point, the system is idle. */

  sdbg("Beginning Idle Loop\n");
  for (;;)
    {
      /* Perform garbage collection (if it is not being done by the worker
       * thread).  This cleans-up memory de-allocations that were queued
       * because they could not be freed in that execution context (for
       * example, if the memory was freed from an interrupt handler).
       */

#ifndef CONFIG_SCHED_WORKQUEUE
      /* We must have exclusive access to the memory manager to do this
       * BUT the idle task cannot wait on a semaphore.  So we only do
       * the cleanup now if we can get the semaphore -- this should be
       * possible because if the IDLE thread is running, no other task is!
       */

      if (kmm_trysemaphore() == 0)
        {
          sched_garbagecollection();
          kmm_givesemaphore();
        }
#endif

      /* Perform any processor-specific idle state operations */

      up_idle();
    }
}
Ejemplo n.º 30
0
int usbmsc_configure(unsigned int nluns, void **handle)
{
	FAR struct usbmsc_alloc_s *alloc;
	FAR struct usbmsc_dev_s *priv;
	FAR struct usbmsc_driver_s *drvr;
	int ret;

#ifdef CONFIG_DEBUG
	if (nluns > 15) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_TOOMANYLUNS), 0);
		return -EDOM;
	}
#endif

	/* Allocate the structures needed */

	alloc = (FAR struct usbmsc_alloc_s *)kmm_malloc(sizeof(struct usbmsc_alloc_s));
	if (!alloc) {
		usbtrace(TRACE_CLSERROR(USBMSC_TRACEERR_ALLOCDEVSTRUCT), 0);
		return -ENOMEM;
	}

	/* Initialize the USB storage driver structure */

	priv = &alloc->dev;
	memset(priv, 0, sizeof(struct usbmsc_dev_s));

	/* Initialize semaphores */
	sem_init(&priv->thsynch, 0, 0);
	sem_init(&priv->thlock, 0, 1);
	sem_init(&priv->thwaitsem, 0, 0);

	/*
	 * The thsynch and thwaitsem semaphores are used for signaling and,
	 * hence, should not have priority inheritance enabled.
	 */
	sem_setprotocol(&priv->thsynch, SEM_PRIO_NONE);
	sem_setprotocol(&priv->thwaitsem, SEM_PRIO_NONE);

	sq_init(&priv->wrreqlist);

	priv->nluns = nluns;

	/* Allocate the LUN table */

	priv->luntab = (FAR struct usbmsc_lun_s *)
				   kmm_malloc(priv->nluns * sizeof(struct usbmsc_lun_s));

	if (!priv->luntab) {
		ret = -ENOMEM;
		goto errout;
	}

	memset(priv->luntab, 0, priv->nluns * sizeof(struct usbmsc_lun_s));

	/* Initialize the USB class driver structure */

	drvr = &alloc->drvr;
#ifdef CONFIG_USBDEV_DUALSPEED
	drvr->drvr.speed = USB_SPEED_HIGH;
#else
	drvr->drvr.speed = USB_SPEED_FULL;
#endif
	drvr->drvr.ops = &g_driverops;
	drvr->dev = priv;

	/* Return the handle and success */

	*handle = (FAR void *)alloc;
	return OK;

errout:
	usbmsc_uninitialize(alloc);
	return ret;
}