Exemple #1
0
void torc_waitall3()
{
	torc_t *self = _torc_self();
	int remdeps;

        _lock_acquire (&self->lock);
        --self->ndep;
        _lock_release (&self->lock);
	while (1)
	{
	        _lock_acquire (&self->lock);
		remdeps = self->ndep;
	        _lock_release (&self->lock);
		if (remdeps == 0)
			break;
		else {
			thread_sleep(0);
			//usleep(1*1000);
			//sched_yield();
		}
	}
}
Exemple #2
0
esp_err_t esp_phy_rf_deinit(void)
{
    assert((s_phy_rf_init_count <= 2) && (s_phy_rf_init_count >= 1));

    _lock_acquire(&s_phy_rf_init_lock);
    if (s_phy_rf_init_count == 1) {
        // Disable PHY and RF.
        phy_close_rf();
        // Disable WiFi/BT common peripheral clock. Do not disable clock for hardware RNG
        periph_module_disable(PERIPH_WIFI_BT_COMMON_MODULE);
    } else {
#if CONFIG_SW_COEXIST_ENABLE
        coex_deinit();
#endif
    }
    s_phy_rf_init_count--;
    _lock_release(&s_phy_rf_init_lock);
    return ESP_OK;
}
Exemple #3
0
void esp_mpi_acquire_hardware( void )
{
    /* newlib locks lazy initialize on ESP-IDF */
    _lock_acquire(&mpi_lock);

    REG_SET_BIT(DPORT_PERI_CLK_EN_REG, DPORT_PERI_EN_RSA);
    /* also clear reset on digital signature, otherwise RSA is held in reset */
    REG_CLR_BIT(DPORT_PERI_RST_EN_REG,
                DPORT_PERI_EN_RSA
                | DPORT_PERI_EN_DIGITAL_SIGNATURE);

    REG_CLR_BIT(DPORT_RSA_PD_CTRL_REG, DPORT_RSA_PD);

    while(REG_READ(RSA_CLEAN_REG) != 1);

    // Note: from enabling RSA clock to here takes about 1.3us

#ifdef CONFIG_MBEDTLS_MPI_USE_INTERRUPT
    rsa_isr_initialise();
#endif
}
Exemple #4
0
esp_err_t esp_phy_rf_init(const esp_phy_init_data_t* init_data,
        esp_phy_calibration_mode_t mode, esp_phy_calibration_data_t* calibration_data)
{
    assert((s_phy_rf_init_count <= 1) && (s_phy_rf_init_count >= 0));

    _lock_acquire(&s_phy_rf_init_lock);
    if (s_phy_rf_init_count == 0) {
        // Enable WiFi/BT common peripheral clock
        periph_module_enable(PERIPH_WIFI_BT_COMMON_MODULE);
        ESP_LOGV(TAG, "register_chipv7_phy, init_data=%p, cal_data=%p, mode=%d",
                init_data, calibration_data, mode);
        phy_set_wifi_mode_only(0);
        register_chipv7_phy(init_data, calibration_data, mode);
        coex_bt_high_prio();
    } else {
#if CONFIG_SW_COEXIST_ENABLE
        coex_init();
#endif
    }
    s_phy_rf_init_count++;
    _lock_release(&s_phy_rf_init_lock);
    return ESP_OK;
}
Exemple #5
0
void torc_task_detached(int queue, void (*work)(), int narg, ...)
{
	va_list ap;
	int i;
	torc_t * rte;
//	torc_t *self = _torc_self();

#if 0
	/* Check if rte_init has been called */
	_lock_acquire(&self->lock);
	if (self->ndep == 0) self->ndep = 1;
	_lock_release(&self->lock);

	_torc_depadd(self, 1);
#endif

	rte = _torc_get_reused_desc();
	_initialize(rte);

	_torc_set_work_routine(rte, work);
    	rte->narg = narg;	
	rte->rte_type = 1;	/* external */
	rte->inter_node = 1;
#if 0
	rte->parent = self;
#else
	rte->parent = NULL;
#endif
//	rte->level = self->level + 1;
//	rte->level = self->level;
	rte->level = 0;

#if 0 //def TORC_STATS
	if (!invisible_flag)
	created[self->vp_id]++;

	if (invisible_flag)
		rte->rte_type = 2;	/* invisible */
#endif

	if (narg>MAX_TORC_ARGS) Error("narg > MAX_TORC_ARGS");

	va_start(ap, narg);
	for (i=0; i<narg; i++) {
		rte->quantity[i] = va_arg (ap, int);
		rte->dtype[i] = va_arg (ap, MPI_Datatype);
#if 1
		rte->btype[i] = _torc_mpi2b_type(rte->dtype[i]);
#endif
		rte->callway[i] = va_arg (ap, int);
		if ((rte->callway[i] == CALL_BY_COP)&&(rte->quantity[i] > 1))
			rte->callway[i] = CALL_BY_COP2;
#if DBG
		printf("ARG %d : Q = %d, T = %d, C = %x O\n", i, rte->quantity[i], rte->dtype[i], rte->callway[i]); fflush(0);
#endif
	}
	
	for (i=0; i<narg; i++) {
		if (rte->quantity[i] == 0) {	// peh: 02.07.2015
			VIRT_ADDR dummy = va_arg (ap, VIRT_ADDR);
			continue;
		}
		if (rte->callway[i] == CALL_BY_COP) {
			int typesize;
			MPI_Type_size(rte->dtype[i], &typesize);
			switch (typesize) {
			case 4:
				rte->localarg[i] = *va_arg (ap, INT32 *);
				break;
			case 8:
				rte->localarg[i] = *va_arg (ap, INT64 *);
				break;
			default:
				Error("typesize not 4 or 8!");
				break;
			}
		}
		else if (rte->callway[i] == CALL_BY_COP2) {
Exemple #6
0
static FINDLOCK_T
lock_acquire(LOCK_T *a_theLock, int *a_fd, char *a_root, char *a_key,
	char *a_object, int a_quiet, int a_wait, long a_timeout,
	int a_exclusive, char *a_altRoot, pid_t a_pid, zoneid_t a_zid)
{
	int		notified = 0;
	FINDLOCK_T	result;
	time_t		timeout;
	int		closeOnExit = 0;

	/* reset the lock */

	bzero(a_theLock, sizeof (LOCK_T));

	/* open file if not open */

	if ((*a_fd) < 0) {
		(*a_fd) = _openLockFile(a_altRoot);
		if ((*a_fd) < 0) {
			return (FINDLOCK_ERROR);
		}
		closeOnExit++;
	}

	/* compute time after which acquire times out */

	timeout = time((time_t *)NULL) + a_timeout;

	for (;;) {
		time_t	curtime;

		/* attempt to aquire the lock */

		result = _lock_acquire(a_theLock, *a_fd, a_key, a_object,
				a_quiet, a_exclusive, a_pid, a_zid);

		/* return result if any result other than object is locked */

		switch (result) {
		case FINDLOCK_LOCKACQUIRED:

			/* close lock file if opened in this function */

			if (closeOnExit) {
				(void) close(*a_fd);
				*a_fd = -1;
			}

			return (FINDLOCK_LOCKACQUIRED);

		case FINDLOCK_FOUND:
		case FINDLOCK_NOTFOUND:
		case FINDLOCK_KEYMISMATCH:
		case FINDLOCK_NOTLOCKED:
		case FINDLOCK_ERROR:
		default:
			/* close lock file if opened in this function */

			if (closeOnExit) {
				(void) close(*a_fd);
				*a_fd = -1;
			}

			return (result);

		case FINDLOCK_LOCKED:
			;
			/* FALLTHROUGH */
		}

		/*
		 * object locked OR SIGINT/SIGHUP interrupt received;
		 * return error if not waiting for lock OR signal received
		 */

		if ((a_wait == 0) || (signal_received != 0)) {
			log_msg(a_quiet ? LOG_MSG_DEBUG : LOG_MSG_ERR,
				MSG_LOCK_ACQUIRE_BUSY_FIRST,
				a_exclusive ? MSG_LOCK_EXC : MSG_LOCK_SHR,
				a_object, a_key,
				a_theLock->_lrLock.lockObject,
				a_theLock->_lrLock.lockExclusive ?
						MSG_LOCK_EXC : MSG_LOCK_SHR,
				a_theLock->_lrLock.lockExclusive !=
					a_exclusive ? "" :
					MSG_LOCK_ACQUIRE_BUSY_ADDITIONAL);

			/* close lock file if opened in this function */

			if (closeOnExit) {
				(void) close(*a_fd);
				*a_fd = -1;
			}

			return (FINDLOCK_LOCKED);
		}

		/* waiting for lock - if timeout specified see if time left */

		if (a_timeout > 0) {
			curtime = time((time_t *)NULL);
			if (curtime > timeout) {
				log_msg(a_quiet ? LOG_MSG_DEBUG : LOG_MSG_ERR,
					MSG_LOCK_ACQUIRE_TIMEDOUT,
					a_exclusive ?
						MSG_LOCK_EXC : MSG_LOCK_SHR,
					a_object, a_key);

				/* close lock file if opened in this function */

				if (closeOnExit) {
					(void) close(*a_fd);
					*a_fd = -1;
				}

				return (FINDLOCK_ERROR);
			}
		}

		/*
		 * waiting to aquire lock:
		 * - notify waiting (one time only)
		 * - close lock file
		 * - sleep
		 * - open lock file
		 * - try again
		 */

		/* notify once */

		if (notified++ == 0) {
			log_msg(a_quiet ? LOG_MSG_DEBUG : LOG_MSG_WRN,
				MSG_LOCK_ACQUIRE_WAITING,
				a_object);
		}

		/* close lock file */

		(void) close(*a_fd);

		/* wait (sleep) */

		(void) sleep(LOCK_SLEEP_INTERVAL);

		/* open the lock file and try again */

		*a_fd = _openLockFile(a_root);
		if (*a_fd < 0) {
			log_msg(LOG_MSG_ERR, MSG_LOCK_ACQUIRE_REOPEN_FAILED,
				a_object);

			/* close lock file if opened in this function */

			if (closeOnExit) {
				(void) close(*a_fd);
				*a_fd = -1;
			}

			return (FINDLOCK_ERROR);
		}
	}
}