static void hrt_queue_refresh(void) { int elapsed; dq_entry_t *pent; struct hrt_s *tmp; irqstate_t flags; flags = spin_lock_irqsave(); elapsed = (uint64_t)getreg32(rMT20CNT) * (1000 * 1000) * 10 / XT1OSC_CLK; for (pent = hrt_timer_queue.head; pent; pent = dq_next(pent)) { tmp = container_of(pent, struct hrt_s, ent); tmp->usec -= elapsed; } cont: /* serch for expired */ for (pent = hrt_timer_queue.head; pent; pent = dq_next(pent)) { tmp = container_of(pent, struct hrt_s, ent); if (tmp->usec <= 0) { dq_rem(pent, &hrt_timer_queue); spin_unlock_irqrestore(flags); nxsem_post(&tmp->sem); flags = spin_lock_irqsave(); goto cont; } else { break; } } spin_unlock_irqrestore(flags); }
static void hrt_usleep_add(struct hrt_s *phrt) { dq_entry_t *pent; irqstate_t flags; /* Disable MTM2-Ch0 */ putreg32(0, rMT2OPR); hrt_queue_refresh(); flags = spin_lock_irqsave(); /* add phrt to hrt_timer_queue */ for (pent = hrt_timer_queue.head; pent; pent = dq_next(pent)) { struct hrt_s *tmp = container_of(pent, struct hrt_s, ent); if (tmp->usec >= phrt->usec) { break; } } if (pent) { dq_addbefore(pent, &phrt->ent, &hrt_timer_queue); } else { dq_addlast(&phrt->ent, &hrt_timer_queue); } spin_unlock_irqrestore(flags); hrt_usleep_setup(); }
int psock_local_connect(FAR struct socket *psock, FAR const struct sockaddr *addr) { FAR struct local_conn_s *client; FAR struct sockaddr_un *unaddr = (FAR struct sockaddr_un *)addr; FAR struct local_conn_s *conn; DEBUGASSERT(psock && psock->s_conn); client = (FAR struct local_conn_s *)psock->s_conn; if (client->lc_state == LOCAL_STATE_ACCEPT || client->lc_state == LOCAL_STATE_CONNECTED) { return -EISCONN; } /* Find the matching server connection */ net_lock(); for (conn = (FAR struct local_conn_s *)g_local_listeners.head; conn; conn = (FAR struct local_conn_s *)dq_next(&conn->lc_node)) { /* Anything in the listener list should be a stream socket in the * istening state */ DEBUGASSERT(conn->lc_state == LOCAL_STATE_LISTENING && conn->lc_proto == SOCK_STREAM); /* Handle according to the server connection type */ switch (conn->lc_type) { case LOCAL_TYPE_UNNAMED: /* A Unix socket that is not bound to any name */ case LOCAL_TYPE_ABSTRACT: /* lc_path is length zero */ { #warning Missing logic net_unlock(); return OK; } break; case LOCAL_TYPE_PATHNAME: /* lc_path holds a null terminated string */ { if (strncmp(conn->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1) == 0) { int ret = OK; /* Bind the address and protocol */ client->lc_proto = conn->lc_proto; strncpy(client->lc_path, unaddr->sun_path, UNIX_PATH_MAX-1); client->lc_path[UNIX_PATH_MAX-1] = '\0'; client->lc_instance_id = local_generate_instance_id(); /* The client is now bound to an address */ client->lc_state = LOCAL_STATE_BOUND; /* We have to do more for the SOCK_STREAM family */ if (conn->lc_proto == SOCK_STREAM) { ret = local_stream_connect(client, conn, _SS_ISNONBLOCK(psock->s_flags)); } else { net_unlock(); } return ret; } } break; default: /* Bad, memory must be corrupted */ DEBUGPANIC(); /* PANIC if debug on, else fall through */ case LOCAL_TYPE_UNTYPED: /* Type is not determined until the socket is bound */ { net_unlock(); return -EINVAL; } } } net_unlock(); return -EADDRNOTAVAIL; }