Exemple #1
0
/*
 ** ===================================================================
 **     Event       :  Control_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 Control_task(uint32_t task_init_data) {
	int counter = 0;

	/* init msg queues */
	if (_lwmsgq_init((pointer) controller_msg_queue, NUM_CTRL_MESSAGES,
			MESSAGE_SIZE_MAX_TYPE_ALIGNED) != MQX_OK) {
		DEBUG("Initialize msgq failed\n");
	}
	if (_lwmsgq_init((pointer) rcom_msg_queue, NUM_RCOM_MESSAGES,
			MESSAGE_SIZE_MAX_TYPE_ALIGNED) != MQX_OK) {
		DEBUG("Initialize msgq failed\n");
	}

	if (_task_create_at(0, REMOTE_COM_TASK, 0, Remote_com_task_stack,
			REMOTE_COM_TASK_STACK_SIZE) == MQX_NULL_TASK_ID ) {
		NOTIFY("Error on creating Remote_com task\n");
	}

#if EN_KERNEL_LOG
	if (_task_create_at(0, KERNEL_LOG_TASK, 0, kernel_log_task_stack,
			KERNEL_LOG_TASK_STACK_SIZE) == MQX_NULL_TASK_ID ) {
		NOTIFY("Error on creating kernel_log task\n");
	}
#endif

	while (1) {
		counter++;

		/* Write your code here ... */
		controller_app((pointer) rcom_msg_queue,
				(pointer) controller_msg_queue);
	}
}
/*
** Function used to init session structure
**
** IN:
**      FTPSRV_SESSION_STRUCT* session - session structure pointer
**      FTPSRV_STRUCT *server - pointer to server structure (needed for session parameters)
**      const int sock - socket handle used for communication with client
**
** OUT:
**      none
**
** Return Value: 
**      none
*/
static void ftpsrv_ses_init(FTPSRV_STRUCT *server, FTPSRV_SESSION_STRUCT *session, const int sock)
{
    if (server && session)
    {
        /* Some buffer of arbitrary size so we can get filesystem pointer */
        char      dev_name[16] = {0};

        /* Init session structure */
        session->control_sock = sock;
        session->connected = TRUE;
        session->auth_tbl = server->params.auth_table;
        session->root_dir = (char*) server->params.root_dir;
        session->cur_dir = RTCS_mem_alloc_zero(sizeof("\\"));
        session->cur_dir[0] = '\\';
        session->start_time = RTCS_time_get();

        _io_get_dev_for_path(dev_name, NULL, 16, session->root_dir, NULL);
        session->fs_ptr = _io_get_fs_by_name(dev_name);
        session->msg_queue = RTCS_mem_alloc_zero(sizeof(LWMSGQ_STRUCT) + FTPSRV_NUM_MESSAGES*sizeof(FTPSRV_TRANSFER_MSG)*sizeof(_mqx_max_type));
        if (session->msg_queue != NULL)
        {
            _lwmsgq_init(session->msg_queue, FTPSRV_NUM_MESSAGES, sizeof(FTPSRV_TRANSFER_MSG)/sizeof(_mqx_max_type));
        }
    }
}
Exemple #3
0
os_msgq_handle OS_MsgQ_create(uint32_t max_msg_number, uint32_t msg_size)
{
    void* msgq;
    uint32_t size = sizeof(LWMSGQ_STRUCT) + max_msg_number * msg_size * 4;
    
    msgq = _mem_alloc_system_zero(size);
    if (msgq == NULL)
    {
        return NULL;
    }

    if (_lwmsgq_init(msgq, max_msg_number, msg_size) != MQX_OK)
    {
        _mem_free(msgq);
        return NULL;
    }
       
    return (os_msgq_handle)msgq;
}
Exemple #4
0
void buttons_init(void) {
	btn_table[0] = &yes_btn;
	btn_table[1] = &no_btn;
	disable_buttons();
	_lwmsgq_init((pointer) btns_msg_queue, NUM_BTN_MESSAGES, MSG_SIZE_ALIGNED);
}
Exemple #5
0
void USB_task(uint_32 param)
{ 
    _usb_host_handle     host_handle;
    USB_STATUS           error;
    pointer              usb_fs_handle = NULL;
    usb_msg_t            msg;
    /* Store mounting point used. A: is the first one, bit #0 assigned, Z: is the last one, bit #25 assigned */
    uint_32              fs_mountp = 0;
   
#if DEMOCFG_USE_POOLS && defined(DEMOCFG_MFS_POOL_ADDR) && defined(DEMOCFG_MFS_POOL_SIZE)
    _MFS_pool_id = _mem_create_pool((pointer)DEMOCFG_MFS_POOL_ADDR, DEMOCFG_MFS_POOL_SIZE);
#endif

    /* This event will inform other tasks that the filesystem on USB was successfully installed */
    _lwsem_create(&USB_Stick, 0);
    
    if (MQX_OK != _lwmsgq_init(usb_taskq, 20, USB_TASKQ_GRANM)) {
        // lwmsgq_init failed
        _task_block();
    }

    USB_lock();
    _int_install_unexpected_isr();
   if (MQX_OK != _usb_host_driver_install(USBCFG_DEFAULT_HOST_CONTROLLER)) {
      printf("\n Driver installation failed");
      _task_block();
   }

    error = _usb_host_init(USBCFG_DEFAULT_HOST_CONTROLLER, &host_handle);
    if (error == USB_OK) {
        error = _usb_host_driver_info_register(host_handle, (pointer)ClassDriverInfoTable);
        if (error == USB_OK) {
            error = _usb_host_register_service(host_handle, USB_SERVICE_HOST_RESUME,NULL);
        }
    }

    USB_unlock();

    if (error != USB_OK) {
        _task_block();
    }
      
    for (;;) {
        /* Wait for event sent as a message */
        _lwmsgq_receive(&usb_taskq, (_mqx_max_type *) &msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0);
         
        //if (device.STATE == USB_DEVICE_ATTACHED) {
        if (msg.body == USB_EVENT_ATTACH) {
          /* This event is not so important, because it does not inform about successfull USB stack enumeration */
        } else if (msg.body == USB_EVENT_INTF && fs_mountp != 0x3FFC)  { /* if mountpoints c: to z: are already used */

            // Install the file system, use device->ccs as a handle
            usb_fs_handle = usb_filesystem_install( (pointer) msg.ccs, "USB:", "PM_C1:", "c:");
                  
            if (usb_fs_handle) {
                DEVICE_STRUCT_PTR dsp = (DEVICE_STRUCT_PTR) msg.ccs;
                dsp->mount = 'c';

                // Mark file system as mounted
                fs_mountp |= 1 << (dsp->mount - 'a');
                // Unlock the USB_Stick = signal to the application as available
                _lwsem_post(&USB_Stick);
            }
        } else if (msg.body == USB_EVENT_DETACH) {
            DEVICE_STRUCT_PTR dsp = (DEVICE_STRUCT_PTR) msg.ccs;

            if (dsp->mount >= 'a' && dsp->mount <= 'z') {
                // Lock the USB_Stick = mark as unavailable
                _lwsem_wait(&USB_Stick);

                // Remove the file system 
                usb_filesystem_uninstall(usb_fs_handle);
                // Mark file system as unmounted
                fs_mountp &= ~(1 << (dsp->mount - 'a'));
            }

            /* Here, the device finishes its lifetime */            
            _mem_free(dsp);
        }
    }
}
Exemple #6
0
void uart_tx_task ( uint32_t initial_data )
{  
   SMTPLG_Header * plg_head_p = (SMTPLG_Header *) command_txd_buf;
   SMTPLG_Body * plg_body_p = (SMTPLG_Body *)(command_txd_buf + CMD_HEAD_NUM);  //Note, fix a bug,  not plg_head_p + CMD_HEAD_NUM;
   uint32_t len = 0;
   _mqx_uint res;
   msg_t msg;
   static uint8_t opt_cnt = SMTPLG_CMD_OP_GET_ACT_PWR;
   
   uart_tx_dev  = fopen( UART_CHANNEL, NULL );					   
   if( uart_tx_dev == NULL )
   {
     /* device could not be opened */
     printf("__Evanguo: Open uart tx dev failed, uart_tx_task blocked\n");
     _task_block();
   }
   
   if (MQX_OK != _lwmsgq_init(uart_tx_taskq, 10, TX_TASKQ_GRANM)) 
   {
     printf("lwmsgq_init connect_taskq failed\n");
     _task_block();
   }
   
   command_send(CMD_GET, cls_shiftor_opc(SMTPLG_CMD_CLS_APP, SMTPLG_CMD_OP_GET_PWR_STS), NULL, 0);
   
   rtc_date.fullYear = 2014;
   rtc_date.month = 1;
   rtc_date.mDay = 1;
   
   while(1){
     if((res = _lwmsgq_receive(&uart_tx_taskq, (_mqx_max_type *) &msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY,  100 /* ticks */, 0)) == MQX_OK){  /* 1tick =5ms */
       plg_head_p->CLA = msg.cmd_cls;
       plg_head_p->INS = msg.cmd_opc;
       
       if(msg.type == CMD_SET){
         if(msg.len > 1){
          // if((plg_head_p->CLA == SMTPLG_CMD_CLS_APP)&&((plg_head_p->INS == SMTPLG_CMD_OP_SET_TIMER_BEGIN)||  \
		  	             //                               (plg_head_p->INS == SMTPLG_CMD_OP_SET_TIMER_END)||(plg_head_p->INS == SMTPLG_CMD_OP_SET_CUR_TIME)))
           { /* SET work time */
             plg_head_p->P1 = 0;
             plg_head_p->P2 = 0;
             plg_head_p->P3 = 0;
             plg_head_p->LC = (uint8_t)msg.len;
             if(plg_head_p->LC > CMD_BODY_NUM) 
               plg_head_p->LC = CMD_BODY_NUM;
                                           
             _mem_zero((void *)plg_body_p->Data, CMD_BODY_NUM);
             _mem_copy((void *)msg.data, (void *)plg_body_p->Data, plg_head_p->LC);
             //len = CMD_HEAD_NUM + plg_head_p->LC;
             len = CMD_HEAD_NUM + CMD_BODY_NUM;
           } 
         }
         else if(msg.len == 1){
           plg_head_p->P1 = *(uint8_t *)msg.data;   /* ON/OFF */
           plg_head_p->P2 = 0;
           plg_head_p->P3 = 0;
           plg_head_p->LC = 0;
           len = CMD_HEAD_NUM;
        }
       }
       else if(msg.type == CMD_GET){
           plg_head_p->P1 = 0;
           plg_head_p->P2 = 0;
           plg_head_p->P3 = 0;
           plg_head_p->LC = 0;
           len = CMD_HEAD_NUM;      
       }
       else if(msg.type == CMD_ACK){
         if((plg_head_p->CLA == SMTPLG_CMD_CLS_WIFI_CTL)&&(plg_head_p->INS == SMTPLG_CMD_OP_WIFI_INIT)){
           plg_head_p->P1 = *(uint8_t *)msg.data;   /* ON/OFF */
           plg_head_p->P2 = *((uint8_t *)msg.data + 1);
           plg_head_p->P3 = 0;
           plg_head_p->LC = 0;
           len = CMD_HEAD_NUM;
        }
       }
     }  
     else if(res == LWMSGQ_TIMEOUT){		
       //printf("__Evanguo: wait msg time out\n");
       msg.type == CMD_GET;
       plg_head_p->CLA = SMTPLG_CMD_CLS_APP;
       plg_head_p->INS = opt_cnt ++;	  
       plg_head_p->P1 = 0;
       plg_head_p->P2 = 0;
       plg_head_p->P3 = 0;
       plg_head_p->LC = 0;
       len = CMD_HEAD_NUM;
       if( opt_cnt > SMTPLG_CMD_OP_GET_HIST_TIME)
         opt_cnt = SMTPLG_CMD_OP_GET_ACT_PWR;
     }
     else{
       printf("__Evanguo: _lwmsgq_receive uart_tx_taskq failed\n");
     }
     plg_head_p->MAGIC1 = MAGIC_NUMBER_1;
     plg_head_p->MAGIC2 = MAGIC_NUMBER_2;

     if(UI_data_flag == TRUE){
       write( uart_tx_dev, (void *)plg_head_p, len);
       fflush( uart_tx_dev );  /* ioctl  IO_IOCTL_FLUSH_OUTPUT */
     }
     
   }

   fclose(uart_tx_dev);
}