Пример #1
0
/*
 * 1.����豸����
 * 2.���IP���Զ��MCU��ֻ��Workingʱ���ã�
 * 2.��ʼ��Э��������ָ����λ��Ϣ
 * 3.����IDLE״̬
 * 4.��ʼ״̬������
 */
void ProtectAssistCell::start() {
    GeneralLogic::instance().assignSlot( CardCPU::itsSlot() );
    if( CardCPU::itsSlot() == 1 ) {
        os_dly_wait(300);
    }
    SoftWDT::instance().init(); //首先建立软狗,否则其它任务无法注册
    GeneralLogic::instance().FSMStart();
    DeviceComponent::initDeviceComponentCommon();
    CommunicationModule::initCommon();
//    SoftWDT::instance().startSoftWDT(); //开启软狗
    if( getOMUWorkingStateByHardware() == OMU_Working ) {
        omu = new OMUWorking();
#ifdef EZ_DEBUG
    std::cout << "OMUWorking" << std::endl;
#endif
    }
    else {
        omu = new OMUStandby(); //
#ifdef EZ_DEBUG
    std::cout << "OMUStandby" << std::endl;
#endif
    }

    working_state_check = os_tsk_create_ex(check_working, P_Protect, this);
}
Пример #2
0
void quicksort( array_t array ) {
	array_interval_t interval;
	qsort_task_parameters_t task_param;
	
	// Based on MTE 241 course notes--you can change this if you want
	//  - in the course notes, this sorts from a to c - 1
	interval.array =  array;
	interval.a     =  0;
	interval.c     =  array.length-1;
	
	task_param.interval = interval;

	// If you are using priorities, you can change this
	task_param.priority = 10;
	
	//start the quick_sort threading
	os_tsk_create_ex( quick_sort_task, task_param.priority, &task_param ); 
}
Пример #3
0
__task void quick_sort_task( void* void_ptr){
	
	// Make all declarations at head of fcn
	array_type *aptr, pivot, tmp;
	size_t pivotIndex, a, c, lo, hi, length;
	
	array_interval_t int_right, int_left;
	qsort_task_parameters_t *param, left_param, right_param;
	// End declarations
	
	param = (qsort_task_parameters_t *) void_ptr;
	aptr = param->interval.array.array;
	a = param->interval.a;
	c = param->interval.c;
	
	length = c - a + 1;
	
	if (length <= USE_INSERTION_SORT)
	{
		insertion_sort(param->interval);
		os_tsk_delete_self();
	}
	
	pivotIndex = (size_t) (a + (c - a + 1)*(1.0*rand()/RAND_MAX));
	pivot = aptr[pivotIndex];
	lo = a;
	hi = c;
	
	while(lo <= hi)
	{
		while(aptr[lo] < pivot)
			lo += 1;
		while(aptr[hi] > pivot)
			hi -= 1;
		if (lo <= hi)
		{
			tmp = aptr[lo];
			aptr[lo] = aptr[hi];
			aptr[hi] = tmp;
			lo += 1;
			hi -= 1;
		}
	}
	
	int_left.array = param->interval.array;
	int_right.array = param->interval.array;
	left_param.priority = param->priority + 1;
	right_param.priority = param->priority + 1;
	
	int_left.a = a;
	int_left.c = hi;
	int_right.a = lo;
	int_right.c = c;
	
	left_param.interval = int_left;
	right_param.interval = int_right;
	
	os_tsk_create_ex( quick_sort_task, left_param.priority, &left_param ); 
	os_tsk_create_ex( quick_sort_task, right_param.priority, &right_param );
	
	os_tsk_delete_self();
}