コード例 #1
0
ファイル: mutexa.c プロジェクト: Wangwenxue/FutureMove-T-box
void MutexA
   (
      uint32_t   parameter
   )
{
   MUTEX_ATTR_STRUCT      mutex_init;

   /* initialize a mutex Mutex1 */
   if (_mutatr_init(&mutex_init) == MQX_EOK) {
      _mutatr_set_wait_protocol(&mutex_init,MUTEX_QUEUEING);
      _mutatr_set_sched_protocol(&mutex_init,MUTEX_NO_PRIO_INHERIT);
      _mutex_init(&Mutex1,&mutex_init);
   }

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      if (_mutex_lock(&Mutex1) != MQX_EOK) { 
         /* an error occurred */
      }

      /* access shared resource */

      _time_delay_ticks(1);
      _mutex_unlock(&Mutex1);
   } /* endwhile */ 
} /*end of task*/
コード例 #2
0
ファイル: sender.c プロジェクト: zhouglu/K60F120M
void Sender
   (
      uint_32   parameter
   )
{
   _mqx_uint  msg[MSG_SIZE];
   _task_id   created_task;
   
   created_task = _task_create(0, RESPONDER, 0);
   if (created_task == MQX_NULL_TASK_ID) {
      /* task creation failed */
   }

   /*
   * Service the message queue - Sender_Queue
   */
   _lwmsgq_receive((pointer)sender_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
   _lwmsgq_send((pointer)responder_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);   

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      /*
      * Service the message queue - Sender_Queue
      */
      _lwmsgq_receive((pointer)sender_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
      _time_delay_ticks(3);
      _lwmsgq_send((pointer)responder_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
      putchar('.');
   } /* endwhile */ 

} /*end of task*/
コード例 #3
0
ファイル: mqx_tasks.c プロジェクト: c-kel/Assorted
/*
** ===================================================================
**     Event       :  Task3_task (module mqx_tasks)
**
**     Component   :  Task3 [MQXLite_task]
**     Description :
**         MQX task routine. The routine is generated into mqx_tasks.c
**         file.
**     Parameters  :
**         NAME            - DESCRIPTION
**         task_init_data  - 
**     Returns     : Nothing
** ===================================================================
*/
void Task3_task(uint32_t task_init_data)
{
	for(;;){
	volatile int16 xr,yr,zr;
	uint16 br;
	static char * st1 ="\n\rAccelerometer x value: "  ;
	static char * st2 ="\n\rAccelerometer y value: " ;
	static char * st3 ="\n\rAccelerometer z value: " ;
	static char * st4 ="\n\rLight Sensor value: " ;
	_lwsem_wait(&i2csem);
	xr=xw, yr=yw, zr=zw, br=bw;
	_lwsem_post(&i2csem);
	Term1_Cls();
	Term1_MoveTo(1,1);
	Term1_SendStr(st1);
	Term1_SendNum(xr);
	Term1_SendStr(st2);
	Term1_SendNum(yr);
	Term1_SendStr(st3);
	Term1_SendNum(zr);
	Term1_SendStr(st4);
	Term1_SendNum(br);
	Term1_SendStr(" ");

	_time_delay_ticks(50);
	}
//Term1_SendStr("\r \n");
	
}
コード例 #4
0
ファイル: sema.c プロジェクト: kylemanna/kinetis-sdk1
void SemA
   (
      uint32_t   parameter
   )
{
   _mqx_uint  sem_result;
   void      *Sem1_handle;

   /* create semaphore - sem.Sem1 */
   sem_result = _sem_create("sem.Sem1", 1, 0);
   if (sem_result != MQX_OK) {
      /* semaphore sem.Sem1 not be created */
   } /* endif */
   /* open connection to semaphore sem.Sem1 */
   sem_result = _sem_open("sem.Sem1",&Sem1_handle);
   if (sem_result != MQX_OK) {
      /* could not open sem.Sem1  */
   } /* endif */

   /*
   ** LOOP -
   */
   while ( TRUE ) {
      /* wait for semaphore sem.Sem1 */
      sem_result = _sem_wait_ticks(Sem1_handle, NO_TIMEOUT);
      if (sem_result != MQX_OK) {
         /* waiting on semaphore sem.Sem1 failed */
      }
      /* semaphore obtained, perform work */
      _time_delay_ticks(1);
      /* semaphore protected work done, release semaphore */
      sem_result = _sem_post(Sem1_handle);
   } /* endwhile */
} /*end of task*/
コード例 #5
0
ファイル: mqx_tasks.c プロジェクト: 51104271/CW_FRDM-KE06Z
/*
 ** ===================================================================
 **     Event       :  kernel_log_task (module mqx_tasks)
 **
 **     Component   :  Task4 [MQXLite_task]
 **     Description :
 **         MQX task routine. The routine is generated into mqx_tasks.c
 **         file.
 **     Parameters  :
 **         NAME            - DESCRIPTION
 **         task_init_data  - 
 **     Returns     : Nothing
 ** ===================================================================
 */
void kernel_log_task(uint32_t task_init_data) {
	int counter = 0;

	while (1) {
		counter++;

		/* Write your code here ... */
		_time_delay_ticks(60000 / 5);
		_klog_show_stack_usage();
	}
}
コード例 #6
0
ファイル: mqx_tasks.c プロジェクト: c-kel/Assorted
/*
** ===================================================================
**     Event       :  Task1_task (module mqx_tasks)
**
**     Component   :  Task1 [MQXLite_task]
**     Description :
**         MQX task routine. The routine is generated into mqx_tasks.c
**         file.
**     Parameters  :
**         NAME            - DESCRIPTION
**         task_init_data  - 
**     Returns     : Nothing
** ===================================================================
*/
void Task1_task(uint32_t task_init_data)
{
	Light_Sense_Calibrate(TRUE);
	for(;;){
		
		Light_Sense_Measure(TRUE); 
		_lwsem_wait(&adcsem);
		Light_Sense_GetValue16(&bw); 
		_lwsem_post(&adcsem);
		_time_delay_ticks(2);
	}
}
コード例 #7
0
ファイル: atimesli.c プロジェクト: kylemanna/kinetis-sdk1
void ATimeSliceTask
   (
      uint32_t   parameter
   )
{

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      _time_delay_ticks(3);
   } /* endwhile */ 
} /*end of task*/
コード例 #8
0
ファイル: mqx_tasks.c プロジェクト: Vinhuit/Freescale
void Task1_task2(uint32_t task_init_data)
{
		LWSEM_STRUCT lwsem;
		LDD_TDeviceData* btn1_ptr, *led_ptr;
	  uint32_t button_press_count = 0;
	  button_state_t  button_state, button_last_state;

	  _lwsem_create(&lwsem, 0);
	
    btn1_ptr = GPIO1_Init(&lwsem);
		/* TODO: Enable pull up because board does not have external pull up resistor */
		PORTC_PCR3 |= PORT_PCR_PE_MASK | PORT_PCR_PS_MASK;

		led_ptr = LED_Init(NULL);
	
	  printf("\n====================== GPIO Example ======================\n");
    printf("The (SW1) button is configured to trigger GPIO interrupt.\n");
    printf("Press the (SW1) button 3x to continue.\n\n");
    button_press_count = 1;

    while(button_press_count < 4){
        /* wait for button press, lwsem is set in button isr */
        _lwsem_wait(&lwsem);
        printf("Button pressed %dx\r", button_press_count++);
    }

		printf("The (SW1) button state is now polled.\n");
    printf("Press the (SW1) button to switch LED on or off\n\n");
		while (1)
		{

			  if (0 == GPIO1_GetFieldValue(btn1_ptr, BUTTON1))
        {
            button_state = BUTTON_PRESSED;
        }
        else
        {
            button_state = BUTTON_RELEASED;
        }

				if (button_state != button_last_state)  {
            printf("Button %s\r", button_state == BUTTON_PRESSED ? "pressed " : "released");
            button_last_state = button_state;
					
					  /* Set LED on or off arcodingly */
						LED_PutVal(led_ptr, button_state == BUTTON_PRESSED ? FALSE : TRUE);
        }
        /* Check button state every 20 ticks*/
        _time_delay_ticks(20);
		}
}
コード例 #9
0
ファイル: lwevent.c プロジェクト: jewlenchow/MQX_3.8.1
void simulated_ISR_task 
   (
      uint_32 initial_data
   )
{

   while (TRUE) {
      _time_delay_ticks(200);
      if (_lwevent_set(&lwevent,0x01) != MQX_OK) {
         printf("\nSet Event failed");
         _task_block();
      }
   }
}
コード例 #10
0
ファイル: lweventa.c プロジェクト: kylemanna/kinetis-sdk1
/*TASK---------------------------------------------------------------
*
* Task Name   :  LWEventA
* Comments    :
*
*END*--------------------------------------------------------------*/
void LWEventA
   (
      uint32_t   parameter
   )
{
   _mqx_uint event_result;

   while ( TRUE ) {
      /* set lwevent bit */
      event_result = _lwevent_set(&lwevent, 1);
      if (event_result != MQX_OK) {
         /* setting the event event.Event1 failed */
      } /* endif */
      _time_delay_ticks(1);
   }
}
コード例 #11
0
ファイル: mqx_tasks.c プロジェクト: c-kel/Assorted
/*
** ===================================================================
**     Event       :  Task2_task (module mqx_tasks)
**
**     Component   :  Task2 [MQXLite_task]
**     Description :
**         MQX task routine. The routine is generated into mqx_tasks.c
**         file.
**     Parameters  :
**         NAME            - DESCRIPTION
**         task_init_data  - 
**     Returns     : Nothing
** ===================================================================
*/
void Task2_task(uint32_t task_init_data)
{	
	for(;;){
		byte c;
		Accel_SendChar(0x00);
		Accel_RecvChar(&c);
		Accel_SendStop();		
		if (c&&0x01){
			Accel_SendChar(0x01);
			Accel_RecvBlock(vec, 6, &snt);
			Accel_SendStop();
			_lwsem_wait(&i2csem);
			xw=vec[0]; yw=vec[1]; zw=vec[2];
			_lwsem_post(&i2csem);
		}
		_time_delay_ticks(2);
	}
}
コード例 #12
0
/*
** ===================================================================
**     Event       :  ColorTask (module mqx_tasks)
**
**     Component   :  Task3 [MQXLite_task]
**     Description :
**         MQX task routine. The routine is generated into mqx_tasks.c
**         file.
**     Parameters  :
**         NAME            - DESCRIPTION
**         task_init_data  - 
**     Returns     : Nothing
** ===================================================================
*/
void ColorTask(uint32_t task_init_data)
{
  LDD_TError Error;
  signed char Color[3];
  while(1)
  {
    Error = !ReadAccRegs(I2C_DeviceData, &DataState, OUT_X_MSB, 3 * ACC_REG_SIZE, (uint8_t*) Color);  // Read x,y,z acceleration data.
    if (!Error) {
      if (!BlinkFlag) {
        PWMTimerRGB_Enable(PWMTimerRGB_DeviceData);
        PWMTimerRGB_SetOffsetTicks(PWMTimerRGB_DeviceData, 0,1000*(1<<(abs(Color[0]/10)))); // x axis - red LED 
        PWMTimerRGB_SetOffsetTicks(PWMTimerRGB_DeviceData, 1, 1000*(1<<(abs(Color[1]/10)))); // y axis - green LED 
        PWMTimerRGB_SetOffsetTicks(PWMTimerRGB_DeviceData, 2, 1000*(1<<(abs(Color[2]/10)))); // z axis - blue LED
      }
    }
  _time_delay_ticks(1);
  }
}
コード例 #13
0
ファイル: lwsemb.c プロジェクト: kylemanna/kinetis-sdk1
/*TASK---------------------------------------------------------------
*
* Task Name   :  LWSemB
* Comments    :
*
*END*--------------------------------------------------------------*/
void LWSemB
   (
      uint32_t   parameter
   )
{
   _mqx_uint sem_result;

   while ( TRUE ) {
      /* wait for lw semaphore until it is available */
      sem_result = _lwsem_wait_ticks(&lwsem, NO_TIMEOUT);
      if (sem_result != MQX_OK) {
         /* waiting on semaphore sem.Sem1 failed */
      }
      /* semaphore obtained, perform work */
      _time_delay_ticks(1);
      /* semaphore protected work done, release semaphore */
      sem_result = _lwsem_post(&lwsem);
   }
}
コード例 #14
0
ファイル: lweventa.c プロジェクト: zhouglu/K60F120M
void LWEventA
   (
      uint_32   parameter
   )
{
   _mqx_uint event_result;

   /* 
   ** LOOP - 
   */
   while ( TRUE ) {
      /* set lwevent bit */
      event_result = _lwevent_set(&lwevent, 1);
      if (event_result != MQX_OK) {
         /* setting the event event.Event1 failed */
      } /* endif */
      _time_delay_ticks(1);
   } /* endwhile */ 
} /*end of task*/
コード例 #15
0
ファイル: mutexb.c プロジェクト: kylemanna/kinetis-sdk1
void MutexB
   (
      uint32_t   parameter
   )
{

   /*
   ** LOOP -
   */
   while ( TRUE ) {
      if (_mutex_lock(&Mutex1) != MQX_EOK) {
         /* an error occurred */
      }

      /* access shared resource */

      _time_delay_ticks(1);
      _mutex_unlock(&Mutex1);
   } /* endwhile */
} /*end of task*/
コード例 #16
0
ファイル: client.c プロジェクト: gxliu/MQX_3.8.0
void client_task
   (
      uint_32 index
   )
{
   _mqx_uint          msg[MSG_SIZE];
  
   while (TRUE) {
      msg[0] = ('A'+ index);
     
      printf("Client Task %ld\n", index);
      _lwmsgq_send((pointer)server_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL);

      _time_delay_ticks(1);
      
      /* wait for a return message */
      _lwmsgq_receive((pointer)client_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
   }

}
コード例 #17
0
ファイル: isr.c プロジェクト: Wangwenxue/FutureMove-T-box
void main_task
    (
        uint32_t initial_data
    )
{
    MY_ISR_STRUCT_PTR  isr_ptr;

    uint32_t result;

    /* Create the lightweight semaphore */
    result = _lwsem_create(&lwsem, 0);
    if (result != MQX_OK) {
        printf("\nCreating sem failed: 0x%X", result);
        _task_block();
    }

    isr_ptr               =  _mem_alloc_zero((_mem_size)sizeof(MY_ISR_STRUCT));
    isr_ptr->TICK_COUNT   =  0;
    isr_ptr->OLD_ISR_DATA =  _int_get_isr_data(BSP_TIMER_INTERRUPT_VECTOR);
    isr_ptr->OLD_ISR      =  _int_get_isr(BSP_TIMER_INTERRUPT_VECTOR);

    /* Native MQX interrupt handling method, ISR is installed into the interrupt vector table in kernel */
    if(! _int_install_isr(BSP_TIMER_INTERRUPT_VECTOR, new_tick_isr, isr_ptr))
    {
        printf("Install interrupt handler to interrupt vector table of MQX kernel failed.\n");
        _task_block();
    }
#ifndef DEMO_ENABLE_KERNEL_ISR
    _time_delay_ticks(200);
    printf("\nTick count = %d\n", isr_ptr->TICK_COUNT);
    _task_block();
#else
    printf("\n====================== ISR Example =======================\n");
    printf("Press the SW1 to blink LED1, press it again to turn it off\n");
    while(1)
    {
      _lwsem_wait(&lwsem);
      num_tick = isr_ptr->TICK_COUNT;
    }
#endif /* DEMO_ENABLE_KERNEL_ISR */
}
コード例 #18
0
ファイル: event.c プロジェクト: kylemanna/kinetis-sdk1
void simulated_ISR_task 
   (
      uint32_t initial_data
   )
{
   void   *event_ptr;

   /* open event connection */
   if (_event_open("event.global",&event_ptr) != MQX_OK)  {
      printf("\nOpen Event failed");
      _task_block();
   }

   while (TRUE) {
      _time_delay_ticks(200);
      if (_event_set(event_ptr,0x01) != MQX_OK) {
         printf("\nSet Event failed");
         _task_block();
      }
   }
}
コード例 #19
0
ファイル: klog.c プロジェクト: mihaSoro/MQX-3.7.0
void main_task
   (
      uint_32 initial_data
   )
{
   _mqx_uint result;
   _mqx_uint i;

   /* Create the kernel log */
   result = _klog_create(2*1024, 0);
   if (result != MQX_OK) {
      printf("Main task: _klog_create failed %08x", result);
      _mqx_exit(0);
   }

   /* Enable kernel logging */
   _klog_control(KLOG_ENABLED | KLOG_CONTEXT_ENABLED |
      KLOG_INTERRUPTS_ENABLED| KLOG_SYSTEM_CLOCK_INT_ENABLED |
      KLOG_FUNCTIONS_ENABLED | KLOG_TIME_FUNCTIONS |
      KLOG_INTERRUPT_FUNCTIONS, TRUE);

   /* Write data into kernel log */   
   for (i = 0; i < 10; i++) {
      _time_delay_ticks(5 * i);
   }

   /* Disable kernel logging */
   _klog_control(0xFFFFFFFF, FALSE);

   /* Read data from the kernel log */
   printf("\nKernel log contains:\n");
   while (_klog_display()){
   }

   _mqx_exit(0);

}
コード例 #20
0
ファイル: mqx_tasks.c プロジェクト: c-kel/Assorted
/*
 ** ===================================================================
 **     Event       :  Task1_task (module mqx_tasks)
 **
 **     Component   :  Task1 [MQXLite_task]
 **     Description :
 **         MQX task routine. The routine is generated into mqx_tasks.c
 **         file.
 **     Parameters  :
 **         NAME            - DESCRIPTION
 **         task_init_data  - 
 **     Returns     : Nothing
 ** ===================================================================
 */
void Task1_task(uint32_t task_init_data)
{  
	static float alpha=0.01;
	int16 vec[3];
	int16 current[3]; //current 
	int16 previous[3]; //previous
	int counter;	
	int i;
	for(;;){
		byte c;
		Accel_SendChar(0x00);
		Accel_RecvChar(&c);
		Accel_SendStop();		
		if (c&&0x01){
			for(counter=0;counter<31;counter++){
				Accel_SendChar(0x01);
				Accel_RecvBlock(&vec, 6, &snt);
				Accel_SendStop();
//				current[0]=(vec[0]&0x1f - vec[0]&0x20) *256 + vec[1];
//				current[1]=(vec[2]&0x1f - vec[2]&0x20) *256 + vec[3];
//				current[2]=(vec[4]&0x1f - vec[4]&0x20) *256 + vec[5];
				//Term1_SendNum();
				for(i=0; i<3; i++){
					current[i]=current[i]/2048;					
					previous[i]= current[i];
				}
				_lwsem_wait(&i2csem);
				for(i=0; i<3; i++){
					result[i]= alpha * (float)current[i] + (1-alpha) * (float)previous[i];
				}
				_lwsem_post(&i2csem);
			}

		}
		_time_delay_ticks(5);
	}
}
コード例 #21
0
ファイル: usermode.c プロジェクト: zhouglu/K60F120M
static void usr_task(uint_32 initial_data) 
{
    _mqx_uint *msg;
    pointer ptr;
    
    /* allocate message object from default User memory pool */
    msg = (_mqx_uint*)_usr_mem_alloc(MSG_SIZE * sizeof(_mqx_uint));
  
    while (1) 
    {
        /* build the message with our signature */
        msg[0] = ('A'+ initial_data);
        
        /* demonstrate allocation from user pool created dynamically */
        ptr = _usr_mem_alloc_from(usr_pool_id, 16);

        /* send message to the privilege task and wait 'random' number of time */
        _usr_lwmsgq_send((pointer)que, msg, LWMSGQ_SEND_BLOCK_ON_FULL);
        _time_delay_ticks((initial_data + 1)* 10);

        /* this memory was not really needed, just for a demo purpose */
        _usr_mem_free(ptr);
    }
}
コード例 #22
0
ファイル: pcb_mqxa.c プロジェクト: gaodebang/eth-com-project
void _io_pcb_mqxa_read_task
   (
      /* [IN] the device info */
      uint_32 parameter
   )
{ /* Body */
   IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr;
   IO_PCB_STRUCT_PTR           pcb_ptr;
   uchar_ptr                   input_ptr;
   uchar_ptr                   input_init_ptr;
   boolean                     got_length = 0;
   _mem_size                   input_length = 0;
   _mem_size                   max_length = 0;
   _mem_size                   count = 0;
   _mqx_uint                   state = 0;
   _mqx_uint                   next_state = 0;
   uchar                       crc0 = 0;
   uchar                       crc1 = 0;
   uchar                       packet_crc0 = 0;
   uchar                       packet_crc1 = 0;
   uchar                       tmp;
   uchar                       c;

   info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)parameter;

   /* Get a PCB */
   pcb_ptr = _io_pcb_alloc(info_ptr->READ_PCB_POOL, FALSE);
#if MQX_CHECK_ERRORS
   if (pcb_ptr == NULL) {
      _task_block();
   } /* Endif */
#endif
   max_length     = info_ptr->INIT.INPUT_MAX_LENGTH;
   input_init_ptr = pcb_ptr->FRAGMENTS[0].FRAGMENT;

   state      = AP_STATE_SYNC; /* Waiting for sync */
   next_state = AP_STATE_SYNC; /* Waiting for sync */

   while (TRUE) {

      if (info_ptr->INIT.IS_POLLED) {
         while (!fstatus(info_ptr->FD)) {
            _time_delay_ticks(1);
         } /* Endwhile */
      } /* Endif */
      c = (uchar)fgetc(info_ptr->FD);

      switch (state) {

         case AP_STATE_SYNC:
            if (c == AP_SYNC) {
               /* Sync detected. Start packet reception. */
               state      = AP_STATE_READING;
               next_state = AP_STATE_SYNC;
               count      = 0;
               input_ptr  = input_init_ptr;
               crc0       = 0x7e;
               crc1       = 0x7e;
               got_length = FALSE;
            } /* Endif */
            break;

         case AP_STATE_SYNC_SKIP:
            if (c != AP_SYNC) {
               /* Single sync detected. Restart message reception. */
               count      = 0;
               input_ptr  = input_init_ptr;
               crc0       = 0x7e;
               crc1       = 0x7e;
               got_length = FALSE;
               *input_ptr++ = c;
               ++count;
               AP_CHECKSUM(c, crc0, crc1);
               state = AP_STATE_READING;
            } else {
               state = next_state;
            } /* Endif */
            break;

         case AP_STATE_READING:
            *input_ptr++ = c;
            ++count;
            AP_CHECKSUM(c, crc0, crc1);

            if (got_length ) {
               if (count >= input_length){
                  state = AP_STATE_CS0;
               } /* Endif */
            } else {
               if ( count > MQXA_MSG_CONTROL_OFFSET) {
                  /* The complete packet header has been read in */
                  input_length = GET_LENGTH(input_init_ptr);
                  if (input_length > max_length) {
                     next_state = AP_STATE_SYNC;
                     ++info_ptr->RX_PACKETS_TOO_LONG;
                  } else {
                     got_length = TRUE;
                     if (count >= input_length) {
                        state = AP_STATE_CS0;
                     } /* Endif */
                 } /* Endif */
               } /* Endif */
            } /* Endif */

            if (c == AP_SYNC) {
               next_state = state;
               state      = AP_STATE_SYNC_SKIP;
            } /* Endif */
            break;

         case AP_STATE_CS0:
            packet_crc0 = c;
            state = AP_STATE_CS1;
            if (c == AP_SYNC) {
               next_state = state;
               state      = AP_STATE_SYNC_SKIP;
            } /* Endif */
            break;

         case AP_STATE_CS1:
            packet_crc1 = c;
            state = AP_STATE_DONE;
            if (c == AP_SYNC) {
               next_state = state;
               state      = AP_STATE_SYNC_SKIP;
            } /* Endif */
            break;

         default:
            state = AP_STATE_SYNC;
            break;

      } /* Endswitch */

      if ( state == AP_STATE_DONE ) {
         /* Calculate the CRCs */
         crc1  = (crc1 + 2 * crc0) & 0xFF;
         tmp   = crc0 - crc1;
         crc1  = (crc1 - (crc0 * 2)) & 0xFF;
         crc0  = tmp & 0xFF;

         if ((crc0 == packet_crc0) && (crc1 == packet_crc1)) {
            ++info_ptr->RX_PACKETS;
            pcb_ptr->FRAGMENTS[0].LENGTH = input_length;
            if (info_ptr->READ_CALLBACK_FUNCTION) {
               /* Start CR 398 */
               (*info_ptr->READ_CALLBACK_FUNCTION)(info_ptr->CALLBACK_FD, pcb_ptr);
               /* End CR */
            } else {
               _queue_enqueue((QUEUE_STRUCT_PTR)&info_ptr->READ_QUEUE,
                  (QUEUE_ELEMENT_STRUCT_PTR)&pcb_ptr->QUEUE);
               _lwsem_post(&info_ptr->READ_LWSEM);
            }/* Endif */
            pcb_ptr = _io_pcb_alloc(info_ptr->READ_PCB_POOL, TRUE);
            /* Start CR 385 */
            if (pcb_ptr == NULL) {
               /* Start CR 399 */
               while (pcb_ptr == NULL) {
                  _time_delay_ticks(2);
                  pcb_ptr = _io_pcb_alloc(info_ptr->READ_PCB_POOL, TRUE);
               } /* Endwhile */
               /* End CR 399 */
            } /* Endif */
            /* End CR 385 */
            input_init_ptr = pcb_ptr->FRAGMENTS[0].FRAGMENT;
         } else {
            ++info_ptr->RX_PACKETS_BAD_CRC;
         } /* Endif */
         state = AP_STATE_SYNC;
      } /* Endif */

   } /* Endwhile */

} /* Endbody */
コード例 #23
0
ファイル: usbmfs.c プロジェクト: gxliu/MQX_3.8.0
_mqx_int _io_usb_mfs_open_internal
   (
   IO_USB_MFS_STRUCT_PTR            info_ptr,
   CLASS_CALL_STRUCT_PTR            ccs_ptr 
   )
{ /* Body */
   uint_32     i;
   USB_STATUS error;
   REQ_SENSE_DATA_FORMAT sense;


   error = usb_mass_ufi_inquiry(&info_ptr->COMMAND, (uchar_ptr) &info_ptr->INQUIRY_DATA, sizeof(INQUIRY_DATA_FORMAT));

   if ((error!=MQX_OK) && (error!=USB_STATUS_TRANSFER_QUEUED)) {
      return IO_ERROR_INQUIRE;
   } /* Endif */

   if (_lwsem_wait_ticks(&info_ptr->COMMAND_DONE, USBCFG_MFS_LWSEM_TIMEOUT) != MQX_OK) {

   /* Send the call now */

      /* Wait for the completion */
      usb_mass_ufi_cancel(&info_ptr->COMMAND);
      return IO_ERROR_TIMEOUT;
   } /* Endif */


   if (info_ptr->COMMAND_STATUS != MQX_OK) {
      return IO_ERROR_INQUIRE;
   } /* Endif */

   for (i = 0; i < USBCFG_MFS_MAX_RETRIES; i++)
   {
      if (i) {
         /* Delay for a user-specified amount of time */
         _time_delay_ticks(USBCFG_MFS_OPEN_READ_CAPACITY_RETRY_DELAY);
      }
      
      /* Send the call now */
      error = usb_mass_ufi_read_capacity(&info_ptr->COMMAND, (uchar_ptr) &info_ptr->CAPACITY,
         sizeof(MASS_STORAGE_READ_CAPACITY_CMD_STRUCT_INFO));

      if ((error!=MQX_OK) && (error!=USB_STATUS_TRANSFER_QUEUED)) {
         return IO_ERROR_READ;
      } /* Endif */

      if (_lwsem_wait_ticks(&info_ptr->COMMAND_DONE, USBCFG_MFS_LWSEM_TIMEOUT) != MQX_OK) {
         usb_mass_ufi_cancel(&info_ptr->COMMAND);
         return IO_ERROR_TIMEOUT;
      } /* Endif */
      
      if (info_ptr->COMMAND_STATUS == MQX_OK)
         break;
      
      
      error = usb_mass_ufi_request_sense(&info_ptr->COMMAND, (char_ptr)&sense, sizeof(REQ_SENSE_DATA_FORMAT));

      if ((error!=MQX_OK) && (error!=USB_STATUS_TRANSFER_QUEUED)) {
         return IO_ERROR_READ;
      }

      if (_lwsem_wait_ticks(&info_ptr->COMMAND_DONE, USBCFG_MFS_LWSEM_TIMEOUT) != MQX_OK) {
         usb_mass_ufi_cancel(&info_ptr->COMMAND);
         return IO_ERROR_TIMEOUT;
      }
   }
   
   if (info_ptr->COMMAND_STATUS == MQX_OK) {
      info_ptr->BCOUNT = LONG_BE_TO_HOST(*(uint_32*)&info_ptr->CAPACITY.BLLBA);
      info_ptr->BLENGTH = LONG_BE_TO_HOST(*(uint_32*)&info_ptr->CAPACITY.BLENGTH);

      /* should read this to support  low level format */
      info_ptr->NUMBER_OF_HEADS   = 0;
      info_ptr->NUMBER_OF_TRACKS  = 0;
      info_ptr->SECTORS_PER_TRACK = 0;

      info_ptr->SIZE_BYTES = info_ptr->BLENGTH * info_ptr->BCOUNT;
   } /* Endif */
   
   return (_mqx_int)info_ptr->COMMAND_STATUS;
} /* Endbody */
コード例 #24
0
ファイル: cortex.c プロジェクト: Vinhuit/Freescale
/*!
 * \brief 	MQX API handler for usermode - part of wrapper around standard MQX API
 *  which require privilege mode.
 *
 * \param[in] api_no API number - number of wrapped function
 * \param[in] params generic parameter - direct use with called MQX API fn
 *
 * \return uint32_t return of called function
 */
uint32_t _mqx_api_call_handler
    (
        // [IN] API number - number of wrapped function
        MQX_API_NUMBER_ENUM api_no,
        // [IN] generic parameter - direct use with called MQX API fn
        MQX_API_CALL_PARAMS_PTR params
    )
{
    int32_t res = -1;
    uint32_t param0 = params->param0;
    uint32_t param1 = params->param1;
    uint32_t param2 = params->param2;
    uint32_t param3 = params->param3;
    uint32_t param4 = params->param4;

    switch (api_no) {

    // _lwsem
    case MQX_API_LWSEM_POLL:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)))
            res = (uint32_t)_lwsem_poll((LWSEM_STRUCT_PTR)param0);
        break;
    case MQX_API_LWSEM_POST:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)))
            res = _lwsem_post((LWSEM_STRUCT_PTR)param0);
        break;
    case MQX_API_LWSEM_WAIT:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)))
            res = _lwsem_wait((LWSEM_STRUCT_PTR)param0);
        break;
    case MQX_API_LWSEM_CREATE:
        res = _lwsem_create_internal((LWSEM_STRUCT_PTR)param0, (_mqx_int)param1, (bool)param2, TRUE);
        break;
#if MQX_HAS_TICK
    case MQX_API_LWSEM_WAIT_FOR:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)) && (!param1 || _psp_mem_check_access(param1, sizeof(MQX_TICK_STRUCT), MPU_UM_RW)))
            res = _lwsem_wait_for((LWSEM_STRUCT_PTR)param0, (MQX_TICK_STRUCT_PTR)param1);
        break;
    case MQX_API_LWSEM_WAIT_TICKS:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)))
            res = _lwsem_wait_ticks((LWSEM_STRUCT_PTR)param0, (_mqx_uint)param1);
        break;
    case MQX_API_LWSEM_WAIT_UNTIL:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0)) && (!param1 || _psp_mem_check_access(param1, sizeof(MQX_TICK_STRUCT), MPU_UM_RW)))
            res = _lwsem_wait_until((LWSEM_STRUCT_PTR)param0, (MQX_TICK_STRUCT_PTR)param1);
        break;
    case MQX_API_LWSEM_DESTROY:
        if (MQX_OK == (res = _lwsem_usr_check((LWSEM_STRUCT_PTR)param0))) {
            res = _lwsem_destroy_internal((LWSEM_STRUCT_PTR)param0, TRUE);
        }
        break;

#endif // MQX_HAS_TICK

    // _lwevent
#if MQX_USE_LWEVENTS
    case MQX_API_LWEVENT_CLEAR:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0)))
            res = _lwevent_clear((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1);
        break;
    case MQX_API_LWEVENT_SET:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0)))
            res = _lwevent_set((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1);
        break;
    case MQX_API_LWEVENT_SET_AUTO_CLEAR:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0)))
            res = _lwevent_set_auto_clear((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1);
        break;
    case MQX_API_LWEVENT_WAIT_FOR:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0)) && \
            (!param3 || _psp_mem_check_access(param3, sizeof(MQX_TICK_STRUCT), MPU_UM_RW))) {
            res = _lwevent_wait_for((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1, (bool)param2, (MQX_TICK_STRUCT_PTR)param3);
        }
        break;
    case MQX_API_LWEVENT_WAIT_FOR_TICKS:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0))) {
            res = _lwevent_wait_ticks((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1, (bool)param2, (_mqx_uint)param3);
        }
        break;
    case MQX_API_LWEVENT_WAIT_UNTIL:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0)) && \
            (!param3 || _psp_mem_check_access(param3, sizeof(MQX_TICK_STRUCT), MPU_UM_RW))) {
            res = _lwevent_wait_until((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1, (bool)param2, (MQX_TICK_STRUCT_PTR)param3);
        }
        break;
    case MQX_API_LWEVENT_GET_SIGNALLED:
        res = _lwevent_get_signalled();
        break;

    case MQX_API_LWEVENT_CREATE:
        res = _lwevent_create_internal((LWEVENT_STRUCT_PTR)param0, (_mqx_uint)param1, TRUE);
        break;

    case MQX_API_LWEVENT_DESTROY:
        if (MQX_OK == (res = _lwevent_usr_check((LWEVENT_STRUCT_PTR)param0))) {
            res = _lwevent_destroy_internal((LWEVENT_STRUCT_PTR)param0, TRUE);
        }
        break;
#endif

#if MQX_USE_LWMSGQ
    case MQX_API_LWMSGQ_INIT:
        res = _lwmsgq_init_internal((void *)param0, (_mqx_uint)param1, (_mqx_uint)param2, TRUE);
        break;
    case MQX_API_LWMSGQ_RECEIVE:
        if (MQX_OK == (res = _lwmsgq_usr_check((LWMSGQ_STRUCT_PTR)param0)) && \
            _psp_mem_check_access(param1, ((LWMSGQ_STRUCT_PTR)param0)->MSG_SIZE, MPU_UM_RW) && \
            (!param4 || _psp_mem_check_access(param4, sizeof(MQX_TICK_STRUCT), MPU_UM_RW)))
            res = _lwmsgq_receive((void *)param0, (_mqx_max_type_ptr)param1, (_mqx_uint)param2, (_mqx_uint)param3, (MQX_TICK_STRUCT_PTR)param4);

        break;
    case MQX_API_LWMSGQ_SEND:
        if (MQX_OK == (res = _lwmsgq_usr_check((LWMSGQ_STRUCT_PTR)param0)) && \
            _psp_mem_check_access(param1, ((LWMSGQ_STRUCT_PTR)param0)->MSG_SIZE, MPU_UM_RW))
            res = _lwmsgq_send((void *)param0, (_mqx_max_type_ptr)param1, (_mqx_uint)param2);
        break;
#endif // MQX_USE_LWMSGQ

    case MQX_API_TASK_CREATE:
        res = _task_create_internal((_processor_number)param0, (_mqx_uint)param1, (uint32_t)param2, TRUE);
        break;
    case MQX_API_TASK_DESTROY:
        res = _task_destroy_internal((_task_id)param0, TRUE);
        break;
    case MQX_API_TASK_ABORT:
        res = _task_abort_internal((_task_id)param0, TRUE);
        break;
    case MQX_API_TASK_READY:
        _task_ready((void *)param0);
        res = MQX_OK;       // irelevant, function is without return value
        break;
    case MQX_API_TASK_SET_ERROR:
        res = _task_set_error((_mqx_uint)param0);
        break;
    case MQX_API_TASK_GET_TD:
        res = (uint32_t)_task_get_td((_task_id)param0);
        break;

#if MQX_USE_LWMEM
    case MQX_API_LWMEM_ALLOC:
        res = (uint32_t)_usr_lwmem_alloc_internal((_mem_size)param0);
        break;

    case MQX_API_LWMEM_ALLOC_FROM:
        if (_psp_mem_check_access(param0, sizeof(LWMEM_POOL_STRUCT), MPU_UM_RW) && \
            _psp_mem_check_access((uint32_t)(((LWMEM_POOL_STRUCT_PTR)param0)->POOL_ALLOC_START_PTR), (char*)(((LWMEM_POOL_STRUCT_PTR)param0)->POOL_ALLOC_END_PTR) - (char*)(((LWMEM_POOL_STRUCT_PTR)param0)->POOL_ALLOC_START_PTR), MPU_UM_RW))
            res = (uint32_t)_lwmem_alloc_from((_lwmem_pool_id)param0, (_mem_size)param1);
        else
            res = 0; // NULL, allocation failed
        break;

    case MQX_API_LWMEM_FREE:
        if (_psp_mem_check_access(param0, 4, MPU_UM_RW))
            res = _lwmem_free((void *)param0);
        break;

    case MQX_API_LWMEM_CREATE_POOL:\
        if (_psp_mem_check_access(param0, sizeof(LWMEM_POOL_STRUCT), MPU_UM_RW) && \
            _psp_mem_check_access(param1, param2, MPU_UM_RW))
            res = (uint32_t)_lwmem_create_pool((LWMEM_POOL_STRUCT_PTR)param0, (void *)param1, (_mem_size)param2);
        break;

    case MQX_API_LWMEM_REALLOC:
        if (_psp_mem_check_access(param0, 4, MPU_UM_RW))
          res = (uint32_t)_lwmem_realloc((void *)param0,(_mem_size)param1);
        break;
#endif // MQX_USE_LWMEM

    // _time
    case MQX_API_TIME_DELAY:
        _time_delay(param0);
        res = MQX_OK;       // irelevant, function is without return value
        break;

#if MQX_HAS_TICK
    case MQX_API_TIME_DELAY_TICKS:
        _time_delay_ticks(param0);
        res = MQX_OK;       // irelevant, function is without return value
        break;
    case MQX_API_TIME_GET_ELAPSED_TICKS:
        if (_psp_mem_check_access(param0, sizeof(MQX_TICK_STRUCT), MPU_UM_RW)) {
            _time_get_elapsed_ticks((MQX_TICK_STRUCT_PTR)param0);
            res = MQX_OK;       // irelevant, function is without return value
        }
        else {
            _task_set_error(MQX_ACCESS_ERROR);
        }

        break;
#endif // MQX_HAS_TICK
    default:
        while (1);
    }

    return res;
}