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*/
static void privilege_task(uint_32 initial_data) { _mqx_uint msg[MSG_SIZE]; _lwmem_pool_id mem_pool_id; LWMEM_POOL_STRUCT mem_pool; pointer mem_pool_start; LWMEM_POOL_STRUCT_PTR usr_pool_ptr; pointer usr_pool_start; /* memory pool: Read-Only for User tasks */ mem_pool_start = _mem_alloc(1024); mem_pool_id = _lwmem_create_pool(&mem_pool, mem_pool_start, 1024); _mem_set_pool_access(mem_pool_id, POOL_USER_RO_ACCESS); /* message queue to communicate between this task and User tasks */ que = (uint_32*)_mem_alloc_from(mem_pool_id, sizeof(LWMSGQ_STRUCT) + NUM_MESSAGES * MSG_SIZE * sizeof(_mqx_uint)); _usr_lwmsgq_init((pointer)que, NUM_MESSAGES, MSG_SIZE); /* memory pool: Read-Write for user tasks */ usr_pool_ptr = _usr_mem_alloc(sizeof(LWMEM_POOL_STRUCT)); usr_pool_start = _mem_alloc(1024); usr_pool_id = _lwmem_create_pool(usr_pool_ptr, usr_pool_start, 1024); _mem_set_pool_access(usr_pool_id, POOL_USER_RW_ACCESS); /* create the user "main" task, whcih then creates the others */ _task_create(0, USR_MAIN_TASK, USR_TASK_CNT); /* receive messages from user tasks and print */ while (1) { _lwmsgq_receive((pointer)que, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0); printf(" %c \n", msg[0]); } }
uint32_t OS_MsgQ_recv(os_msgq_handle msgq, void* msg, uint32_t flag, uint32_t timeout) { if (MQX_OK != _lwmsgq_receive(msgq, (uint32_t *) msg, flag, timeout, NULL)) { return (uint32_t)OS_MSGQ_ERROR; } return (uint32_t)OS_MSGQ_OK; }
uint32_t OS_MsgQ_Is_Empty(os_msgq_handle msgq, void* msg) { uint32_t ret; ret = LWMSGQ_IS_EMPTY(msgq); if (!ret) { if (MQX_OK != _lwmsgq_receive(msgq, (uint32_t *) msg, OS_MSGQ_RECEIVE_BLOCK_ON_EMPTY, 1, NULL)) { return (uint32_t)OS_MSGQ_ERROR; } } return ret; }
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); } }
void Responder ( uint32_t parameter ) { uint32_t msg[MSG_SIZE]; /* ** LOOP - */ while ( TRUE ) { /* * Service the message queue - Responder_Queue */ _lwmsgq_receive((void *)responder_queue, msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, 0); _lwmsgq_send((void *)sender_queue, msg, LWMSGQ_SEND_BLOCK_ON_FULL); putchar('.'); } /* endwhile */ } /*end of task*/
/*! * \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; }
void remote_com_app(pointer rcom_msg_queue, pointer controller_msg_queue, sync_buffer_t *rcom_to_controller_sync_buffer) { SWM_msg_t msg; if (_lwmsgq_receive(rcom_msg_queue, (_mqx_max_type_ptr) &msg, LWMSGQ_RECEIVE_BLOCK_ON_EMPTY, 0, NULL ) != MQX_OK) { DEBUG("ERR: receive msg failed\n"); } char *result = NULL; char *rcom_to_controller_buffer = NULL; switch (msg.cmd) { case RCOM_START_CMD: DEBUG("RCOM starting...\n"); if (!sim900_start()) { DEBUG("\tERR: SIM start failed\n"); msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } msg.result_type = SUCCESS; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); break; case RCOM_STOP_CMD: DEBUG("RCOM stoping...\n"); sim900_stop(); break; case RCOM_CONFIGURE_CMD: DEBUG("RCOM configuring...\n"); if (!sim900_default_config()) { DEBUG("\tERR: SIM configuration failed\n"); msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } DEBUG("RCOM checking SIM inserted...\n"); if (!sim900_check_SIM_inserted()) { DEBUG("\tERR: SIM removed\n"); msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } DEBUG("RCOM setting APN auto-ly...\n"); if (!set_APN_auto()) { DEBUG("\tERR: Can't set APN\n"); msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } msg.result_type = SUCCESS; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); break; case RCOM_CONNECT_INTERNET_CMD: DEBUG("RCOM connecting internet...\n"); if (!sim900_connect_internet()) { DEBUG("\tERR: Can't connect internet\n"); msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } msg.result_type = SUCCESS; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); break; case RCOM_SEND_SMS_MSG_CMD: DEBUG("RCOM sending SMS msg...\n"); // sim900_send_sms("0947380243", "nvhien"); break; case RCOM_HAVE_SMS_MSG_CMD: DEBUG("RCOM reading SMS msg...\n"); result = sim900_read_SMS_msg(msg.content.value); rcom_to_controller_buffer = (char*) sync_buffer_get_resource_to_write( rcom_to_controller_sync_buffer); SIM900_SMS_msg_t sms_msg; sms_msg.phone_number = rcom_to_controller_buffer + sizeof(SIM900_SMS_msg_t); sim900_get_phone_number_from_SMS_msg(result, sms_msg.phone_number); sim900_normalize_phone_number(sms_msg.phone_number, VN_phone_code); sms_msg.content = sms_msg.phone_number + strlen(sms_msg.phone_number) + 1; sim900_get_content_from_SMS_msg(result, sms_msg.content); memcpy(rcom_to_controller_buffer, (void*) &sms_msg, sizeof(SIM900_SMS_msg_t)); sync_buffer_allow_read(rcom_to_controller_sync_buffer); msg.result_type = SUCCESS; msg.content.ptr = (void*) rcom_to_controller_sync_buffer; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); break; case RCOM_MAKE_MISSED_CALL_CMD: DEBUG("RCOM making missed voice call...\n"); // sim900_make_missed_voice_call(buffer); break; case RCOM_REPORT_DATA_CMD: break; case RCOM_UPDATE_DATA_CMD: break; case RCOM_POLL_COMMAND_CMD: break; case RCOM_GET_TIMESTAMP_CMD: DEBUG("RCOM getting timestamp...\n"); result = sim900_HTTP_GET(URL_time_stamp); if (!result) { msg.result_type = FAIL; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); return; } sync_buffer_write(rcom_to_controller_sync_buffer, (uint8_t*) result, strlen(result) + 1); sync_buffer_allow_read(rcom_to_controller_sync_buffer); msg.result_type = SUCCESS; msg.content.ptr = (void*) rcom_to_controller_sync_buffer; _lwmsgq_send(controller_msg_queue, (_mqx_max_type_ptr) &msg, 0); break; default: break; } return; }
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); } } }
/* Task for reading/writing file */ void ftpsrv_transfer_task(void* init_ptr, void* creator) { FTPSRV_TRANSFER_PARAM* param = (FTPSRV_TRANSFER_PARAM*) init_ptr; MQX_FILE_PTR file = param->file; uint32_t mode = param->mode; uint32_t sock = param->sock; FTPSRV_SESSION_STRUCT* session = param->session; void* data_buffer; char* msg_str; if (session->state == FTPSRV_STATE_TRANSFER) { RTCS_task_resume_creator(creator, (uint32_t) RTCS_ERROR); return; } data_buffer = RTCS_mem_alloc(FTPSRVCFG_DATA_BUFFER_SIZE); if (data_buffer == NULL) { RTCS_task_resume_creator(creator, (uint32_t) RTCS_ERROR); return; } session->transfer_tid = _task_get_id(); session->state = FTPSRV_STATE_TRANSFER; RTCS_task_resume_creator(creator, (uint32_t) RTCS_OK); while (1) { FTPSRV_TRANSFER_MSG message; _mqx_uint retval; /* Reading from file */ if (mode == FTPSRV_MODE_READ) { uint32_t length; int32_t error; length = fread((void*) data_buffer, 1, FTPSRVCFG_DATA_BUFFER_SIZE, file); if ((length != FTPSRVCFG_DATA_BUFFER_SIZE) && ferror(file) && !feof(file)) { msg_str = (char*) ftpsrvmsg_locerr; break; } error = send(sock, data_buffer, length, 0); if (error == RTCS_ERROR) { msg_str = (char*) ftpsrvmsg_locerr; break; } if (feof(file)) { msg_str = (char*) ftpsrvmsg_trans_complete; break; } } /* Writing to file */ else if ((mode == FTPSRV_MODE_WRITE) || (mode == FTPSRV_MODE_APPEND)) { uint32_t length; int32_t received; received = recv(sock, data_buffer, FTPSRVCFG_DATA_BUFFER_SIZE, 0); if (received == RTCS_ERROR) { msg_str = (char*) ftpsrvmsg_trans_complete; break; } length = fwrite((void*) data_buffer, 1, received, file); if (length != received) { if (length == IO_ERROR) { msg_str = (char*) ftpsrvmsg_no_space; } else { msg_str = (char*) ftpsrvmsg_writefail; } break; } } retval = _lwmsgq_receive((void*) session->msg_queue, (uint32_t *)&message, LWMSGQ_TIMEOUT_FOR, 1, NULL); if (retval != MQX_OK) { continue; } if (message.command == FTPSRV_CMD_ABORT) { msg_str = (char*) ftpsrvmsg_trans_abort; break; } else if (message.command == FTPSRV_CMD_STAT) { /* TODO: Add code to print out transfer statistics */ } } _mem_free(data_buffer); fclose(file); ftpsrv_send_msg(session, msg_str); shutdown(sock, FLAG_CLOSE_TX); session->state = FTPSRV_STATE_IDLE; }
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); }