示例#1
0
static void power_down_mdm(struct mdm_modem_drv *mdm_drv)
{
	int i;

	for (i = MDM_MODEM_TIMEOUT; i > 0; i -= MDM_MODEM_DELTA) {
		pet_watchdog();
		msleep(MDM_MODEM_DELTA);
		if (gpio_get_value(mdm_drv->mdm2ap_status_gpio) == 0)
			break;
	}

	if (i <= 0) {
		pr_err("%s: MDM2AP_STATUS never went low.\n",
			 __func__);
		gpio_direction_output(mdm_drv->ap2mdm_pmic_reset_n_gpio, 0);

		for (i = MDM_HOLD_TIME; i > 0; i -= MDM_MODEM_DELTA) {
			pet_watchdog();
			msleep(MDM_MODEM_DELTA);
		}
	}
	/* Also remove the hsic device on 9k power down. */
	MDM_DBG("%s: Removing hsic device\n", __func__);
	if (ifline_status == IFLINE_UP) {
		platform_device_del(&msm_device_hsic_host);
		ifline_status = IFLINE_DOWN;
	}
}
示例#2
0
static void on_read_ready(int fd, short event_type, struct ConnectionState *st) {
  assert(event_type == EV_READ);
  if (st->client_conn == fd) {
    st->client_ready[READ] = 1;
    event_del(st->ev_client_read);

    if (st->cleanup_waiting == SSL_ERROR_WANT_READ) {
      cleanup_connection_ssl_try_shutdown(st);
      return;
    } 

//    g_slice_free(st->ev_client_read);
//    st->ev_client_read = 0;
  } else if (st->service_conn == fd) {
    st->service_ready[READ] = 1;
    event_del(st->ev_service_read);
//    g_slice_free(st->ev_service_read);
//    st->ev_service_read = 0;
  } else {
    //fprintf(stderr,"Error: on_read_ready(%d, %d, %p)\n", fd, event_type, st);
    cleanup_connection(st);
    return;
  }

  try_to_forward(st);
  pet_watchdog(st);
}
/* 
	Sets all task states atomically by suspending the RTOS scheduler and watchdog,
	grabbing all mutexes to ensure no task is suspended while holding one, and
	resuming or suspending tasks as specified, and setting the current
	state variable (atomically in here)
*/
void set_all_task_states(const task_states states, sat_state_t state, sat_state_t prev_sat_state)
{
	// determine whether antenna deployed before taking ALL mutexes
	bool antenna_deployed = antenna_did_deploy();
	
	// IMPORTANT: take all mutexes to ensure no task is suspended while holding one.
	// Note that the ordering here is important to avoid deadlock 
	// (this is a coarse operation, but we consider it fine because these transitions
	// should be fairly rare)
	bool got_all = true;
	uint8_t num_retries = 0;
	do {
		// take all mutexes, but give them back if any fails and try again
		got_all = take_all_mutexes();
		configASSERT(got_all);
		num_retries++;
		
	} while (!got_all && num_retries < TASK_STATE_CHANGE_MUTEX_TAKE_RETRIES);
	
	configASSERT(got_all);
	
	// if we failed to get some mutex, continue on (if we've failed at this point
	// it's probably deadlock, so continue with the state change) (log error of course)
	if (!got_all) {
		// (use watchdog to represent this crazy failure)
		log_error(ELOC_STATE_HANDLING, ECODE_ALL_MUTEX_TIMEOUT, true);
	}
	{
		// NOTE we have the watchdog mutex as required for calling set_single_task_state
		pet_watchdog(); // in case this takes a bit and we're close
		vTaskSuspendAll();
		// values given by external-facing functions
		current_sat_state = state;
		current_task_states = states;

		for (int task_id = 0; task_id < NUM_TASKS; task_id++) {
			// antenna deploy task is independently handled
			if (task_id != ANTENNA_DEPLOY_TASK) {
				set_single_task_state(states.states[task_id], task_id);
			} else {
				set_antenna_deploy_by_sat_state(prev_sat_state, state, antenna_deployed);
			}
		}
		xTaskResumeAll();
	}
	give_all_mutexes();
}
示例#4
0
void charm_panic_wait_mdm_shutdown(void)
{
	int i;

	CHARM_DBG("%s: waiting MDM2AP_ERRFATAL high for MDM/Q6 shutdown\n", __func__);

	for (i = 0; i < CHARM_MODEM_TIMEOUT; i += CHARM_MODEM_DELTA) {
		pet_watchdog();
		mdelay(CHARM_MODEM_DELTA);
		if (gpio_get_value(MDM2AP_ERRFATAL) == 1)
			break;
	}

	if (i >= CHARM_MODEM_TIMEOUT) {
		pr_err("%s: MDM2AP_ERRFATAL never went high in %d(ms)!\n", __func__, CHARM_MODEM_TIMEOUT);
		gpio_direction_output(AP2MDM_PMIC_RESET_N, 0);
	}
}
/**
 * Only task configured to start at boot; starts the rest of RTOS.
 * We use this task to do most of the startup because it allows
 * use of various RTOS functionality (which can cause issues when used
 * before the scheduler is running).
 * WARNING: The vApplicationDaemonTaskStartupHook did not work for us.
 */
void startup_task(void* pvParameters) {
	print("EQUiSatOS starting... ");
	
	#ifdef WRITE_DEFAULT_MRAM_VALS
		// utility function to write initial state to MRAM (ONCE before launch)
		write_custom_state();
	#endif
	
	/************************************************************************/
	/* DATA INITIALIZATION                                                  */
	/************************************************************************/	

	// Initialize misc. state mutexes
	hardware_state_mutex = xSemaphoreCreateMutexStatic(&_hardware_state_mutex_d);
	critical_action_mutex = xSemaphoreCreateMutexStatic(&_critical_action_mutex_d);

	// Initialize EQUiStack mutexes
	_idle_equistack_mutex = xSemaphoreCreateMutexStatic(&_idle_equistack_mutex_d);
	_attitude_equistack_mutex = xSemaphoreCreateMutexStatic(&_attitude_equistack_mutex_d);
	_flash_equistack_mutex = xSemaphoreCreateMutexStatic(&_flash_equistack_mutex_d);
	_flash_cmp_equistack_mutex = xSemaphoreCreateMutexStatic(&_flash_cmp_equistack_mutex_d);
	_low_power_equistack_mutex = xSemaphoreCreateMutexStatic(&_low_power_equistack_mutex_d);

	// Initialize EQUiStacks
	equistack_Init(&idle_readings_equistack, &_idle_equistack_arr,
		sizeof(idle_data_t), IDLE_STACK_MAX, _idle_equistack_mutex);
	equistack_Init(&attitude_readings_equistack, &_attitude_equistack_arr,
		sizeof(attitude_data_t), ATTITUDE_STACK_MAX, _attitude_equistack_mutex);
	equistack_Init(&flash_readings_equistack, &_flash_equistack_arr,
		sizeof(flash_data_t), FLASH_STACK_MAX, _flash_equistack_mutex);
 	equistack_Init(&flash_cmp_readings_equistack, &_flash_cmp_equistack_arr,
		sizeof(flash_cmp_data_t), FLASH_CMP_STACK_MAX, _flash_cmp_equistack_mutex);
 	equistack_Init(&low_power_readings_equistack, &_low_power_equistack_arr,
		sizeof(low_power_data_t), LOW_POWER_STACK_MAX, _low_power_equistack_mutex);
		
	/************************************************************************/
	/* ESSENTIAL INITIALIZATION                                             */
	/************************************************************************/
	// read state from MRAM for first time
	// this initializes the error equistacks, so make sure no errors
	// are logged before this (they shouldn't be before RTOS is started...)
	configure_state_from_reboot();

	// function in global to init things that use RTOS 
	// (MUST be done after config state from reboot)
	global_init_post_rtos();

	// populate task_handles array and setup constants
	pre_init_rtos_tasks();
	
	#if configUSE_TRACE_FACILITY == 1
		// name mutexes
		vTraceSetMutexName(critical_action_mutex, "CA");
		vTraceSetMutexName(i2c_irpow_mutex, "I2C");
		vTraceSetMutexName(irpow_semaphore, "IRPOW");
		vTraceSetMutexName(processor_adc_mutex, "ADC");
		vTraceSetMutexName(hardware_state_mutex, "HWST");
		vTraceSetMutexName(watchdog_mutex, "WD");
		vTraceSetMutexName(mram_spi_cache_mutex, "SPI");
		
		vTraceSetMutexName(_idle_equistack_mutex, "eqIDLE");
		vTraceSetMutexName(_attitude_equistack_mutex, "eqATT");
		vTraceSetMutexName(_flash_equistack_mutex , "eqF_BST");
		vTraceSetMutexName(_flash_cmp_equistack_mutex, "eqF_CMP");
		vTraceSetMutexName(_low_power_equistack_mutex, "eqLP");
		vTraceSetMutexName(_error_equistack_mutex, "eqERR");
	#endif
	
	// note RTOS is ready for watchdog callback, and log error if it already tripped
	rtos_ready = true;
	if (got_early_warning_callback_in_boot) {
		log_error(ELOC_WATCHDOG, ECODE_WATCHDOG_EARLY_WARNING, true);
	}

	/************************************************************************/
	/* TASK CREATION                                                        */
	/************************************************************************/

	// NOTE: We can't actually set task state before they are started below,
	// and tasks start as active (resumed), so we have the tasks themselves
	// call the function below which will either suspend them or leave them
	// running as defined by the configuration of initial state.

	// suspend the scheduler while adding tasks so their task handles
	// are non-null when they start executing (i.e. they can be controlled)
	pet_watchdog(); // in case this takes a bit and we're close
	vTaskSuspendAll();
	
	/************************************************************************/
	/* TESTING/MISC                                                         */
	/************************************************************************/
	create_testing_tasks();
	/************************************************************************/
	/* END TESTING                                                          */
	/************************************************************************/
	
	#ifndef ONLY_RUN_TESTING_TASKS
	battery_charging_task_handle = xTaskCreateStatic(battery_charging_task,
		"battery charging action task",
		TASK_BATTERY_CHARGING_STACK_SIZE,
		NULL,
		TASK_BATTERY_CHARGING_PRIORITY,
		battery_charging_task_stack,
		&battery_charging_task_buffer);

	antenna_deploy_task_handle = xTaskCreateStatic(antenna_deploy_task,
		"antenna deploy action task",
		TASK_ANTENNA_DEPLOY_STACK_SIZE,
		NULL,
		TASK_ANTENNA_DEPLOY_PRIORITY,
		antenna_deploy_task_stack,
		&antenna_deploy_task_buffer);

	state_handling_task_handle = xTaskCreateStatic(state_handling_task,
		"state handling action task",
		TASK_STATE_HANDLING_STACK_SIZE,
		NULL,
		TASK_STATE_HANDLING_PRIORITY,
		state_handling_task_stack,
		&state_handling_task_buffer);

	watchdog_task_handle = xTaskCreateStatic(watchdog_task,
		"watchdog task",
		TASK_WATCHDOG_STACK_SIZE,
		NULL,
		TASK_WATCHDOG_PRIORITY,
		watchdog_task_stack,
		&watchdog_task_buffer);

	persistent_data_backup_task_handle = xTaskCreateStatic(persistent_data_backup_task,
		"persistent data backup task",
		TASK_PERSISTENT_DATA_BACKUP_STACK_SIZE,
		NULL,
		TASK_PERSISTENT_DATA_BACKUP_PRIORITY,
		persistent_data_backup_task_stack,
		&persistent_data_backup_task_buffer);

	flash_activate_task_handle = xTaskCreateStatic(flash_activate_task,
		"flash action task",
		TASK_FLASH_ACTIVATE_STACK_SIZE,
		NULL,
		TASK_FLASH_ACTIVATE_PRIORITY,
		flash_activate_task_stack,
		&flash_activate_task_buffer);

	transmit_task_handle = xTaskCreateStatic(transmit_task,
		"transmit action task",
		TASK_TRANSMIT_STACK_SIZE,
		NULL,
		TASK_TRANSMIT_PRIORITY,
		transmit_task_stack,
		&transmit_task_buffer);

	/* Data tasks */

	idle_data_task_handle = xTaskCreateStatic(idle_data_task,
		"idle data reader task",
		TASK_IDLE_DATA_RD_STACK_SIZE,
		NULL,
		TASK_IDLE_DATA_RD_PRIORITY,
		idle_data_task_stack,
		&idle_data_task_buffer);

	attitude_data_task_handle = xTaskCreateStatic(attitude_data_task,
		"attitude data reader task",
		TASK_ATTITUDE_DATA_RD_STACK_SIZE,
		NULL,
		TASK_ATTITUDE_DATA_DATA_RD_PRIORITY,
		attitude_data_task_stack,
		&attitude_data_task_buffer);

	low_power_data_task_handle = xTaskCreateStatic(low_power_data_task,
		"low power data reader task",
		TASK_LOW_POWER_DATA_RD_STACK_SIZE,
		NULL,
		TASK_LOW_POWER_DATA_RD_PRIORITY,
		low_power_data_task_stack,
		&low_power_data_task_buffer);
	#endif

	xTaskResumeAll();

	setTXEnable(false);
	usart_send_string((uint8_t*) "EQUiSatOS started");
	setTXEnable(true);
	
	print("initialization complete.\n");
	
	// delete this task after it's done booting
	vTaskDelete(NULL);
}