_mqx_int _io_pcb_mqxa_write ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR pcb_ptr ) { /* Body */ IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; if (info_ptr->FD) { _queue_enqueue((QUEUE_STRUCT_PTR)((pointer)&info_ptr->WRITE_QUEUE), (QUEUE_ELEMENT_STRUCT_PTR)((pointer)&pcb_ptr->QUEUE)); _lwsem_post(&info_ptr->WRITE_LWSEM); /* ** Start CR 384 ** return(0); */ return MQX_OK; /* End CR 384 */ }/* Endif */ return(IO_ERROR); } /* Endbody */
MFS_HANDLE_PTR MFS_Get_handle ( MFS_DRIVE_STRUCT_PTR drive_ptr, /*[IN] the drive on which to operate */ MFS_DIR_ENTRY_PTR dir_entry_ptr /* [IN] pointer to the directory information for this file handle */ ) { MFS_HANDLE_PTR handle_ptr; handle_ptr = _partition_alloc_system_zero( drive_ptr->HANDLE_PARTITION ); printf("alloc handle 0x%x\n", (uint_32)handle_ptr); /* ** initialize the handle */ if ( handle_ptr != NULL ) { _queue_enqueue( &drive_ptr->HANDLE_LIST, (QUEUE_ELEMENT_STRUCT_PTR) handle_ptr); printf("enqueue handle 0x%x\n", (uint_32)handle_ptr); handle_ptr->VALID = MFS_VALID; if ( dir_entry_ptr ) { _mem_copy(dir_entry_ptr, &handle_ptr->DIR_ENTRY,sizeof(MFS_DIR_ENTRY)); } } return(handle_ptr); }
_mqx_int _io_pcb_shm_write ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR pcb_ptr ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; _queue_enqueue((QUEUE_STRUCT_PTR)((pointer)&info_ptr->WRITE_QUEUE), (QUEUE_ELEMENT_STRUCT_PTR)((pointer)&pcb_ptr->QUEUE)); _DCACHE_FLUSH_MLINES(pcb_ptr, sizeof(IO_PCB_STRUCT)); _io_pcb_shm_tx((pointer)info_ptr); return(MQX_OK); }
_mqx_int _io_pcb_shm_write ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to read data */ char *data_ptr, /* [IN] the number of characters to input */ _mqx_int num ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr = fd_ptr->DEV_DATA_PTR; IO_PCB_STRUCT_PTR pcb_ptr = (IO_PCB_STRUCT_PTR)data_ptr; _queue_enqueue((QUEUE_STRUCT_PTR)((void *)&info_ptr->WRITE_QUEUE), (QUEUE_ELEMENT_STRUCT_PTR)((void *)&pcb_ptr->QUEUE)); _DCACHE_FLUSH_MLINES(pcb_ptr, sizeof(IO_PCB_STRUCT)); _io_pcb_shm_tx((void *)info_ptr); return(MQX_OK); }
_mqx_int _io_pcb_shm_ioctl ( /* [IN] the file handle for the device */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the ioctl command */ _mqx_uint cmd, /* [IN] the ioctl parameters */ pointer param_ptr ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; _mqx_uint result = MQX_OK; _psp_code_addr old_value; _psp_code_addr_ptr pc_ptr = (_psp_code_addr_ptr)param_ptr; _psp_data_addr_ptr pd_ptr = (_psp_data_addr_ptr)param_ptr; boolean _PTR_ bool_param_ptr; IO_PCB_SHM_INIT_STRUCT_PTR init_ptr; info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR; init_ptr = &info_ptr->INIT; switch (cmd) { case IO_PCB_IOCTL_ENQUEUE_READQ: pcb_ptr = (IO_PCB_STRUCT_PTR)*pd_ptr; _queue_enqueue((QUEUE_STRUCT_PTR)&info_ptr->READ_QUEUE, (QUEUE_ELEMENT_STRUCT_PTR)&pcb_ptr->QUEUE); _lwsem_post(&info_ptr->READ_LWSEM); break; case IO_PCB_IOCTL_READ_CALLBACK_SET: old_value = (_psp_code_addr)info_ptr->READ_CALLBACK_FUNCTION; info_ptr->READ_CALLBACK_FUNCTION = (void (_CODE_PTR_)( FILE_DEVICE_STRUCT_PTR, IO_PCB_STRUCT_PTR))*pc_ptr; *pc_ptr = old_value; break; case IO_PCB_IOCTL_SET_INPUT_POOL: old_value = (_psp_code_addr)info_ptr->READ_PCB_POOL; info_ptr->READ_PCB_POOL = (_io_pcb_pool_id)*pc_ptr; *pc_ptr = old_value; info_ptr->FD = fd_ptr; break; case IO_PCB_IOCTL_START: info_ptr->RX_OLDISR_PTR = _int_get_isr( init_ptr->RX_VECTOR); info_ptr->RX_OLDISR_DATA = _int_get_isr_data(init_ptr->RX_VECTOR); info_ptr->TX_OLDISR_PTR = _int_get_isr( init_ptr->TX_VECTOR); info_ptr->TX_OLDISR_DATA = _int_get_isr_data(init_ptr->TX_VECTOR); #if BSPCFG_IO_PCB_SHM_SUPPORT if (_bsp_io_pcb_shm_int_install(init_ptr,info_ptr)!=MQX_OK) { _mem_free(info_ptr); return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } #else /* Install rx ISR */ if (!_int_install_isr(init_ptr->RX_VECTOR, _io_pcb_shm_rx_isr, info_ptr)) { _mem_free(info_ptr); return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } /* Install the tx finished ISR */ if (!_int_install_isr(init_ptr->TX_VECTOR, _io_pcb_shm_tx_isr, info_ptr)) { _mem_free(info_ptr); return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } #endif break; case IO_PCB_IOCTL_UNPACKED_ONLY: bool_param_ptr = (boolean _PTR_)param_ptr; *bool_param_ptr = TRUE; break; default: /* result = _io_ioctl(info_ptr->FD, cmd, param_ptr); */ break; } return result; }
void _io_pcb_shm_rx_isr ( /* [IN] the info structure */ pointer handle ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; IO_PCB_SHM_INIT_STRUCT_PTR init_ptr; IO_PCB_STRUCT_PTR local_pcb_ptr; IO_PCB_STRUCT_PTR remote_pcb_ptr; IO_PCB_FRAGMENT_STRUCT_PTR frag_ptr; IO_PCB_SHM_BUFFER_STRUCT_PTR bd_ptr; uchar_ptr data_addr; uint_32 data_length; uint_32 cntrl; uint_16 num_frags; uint_32 max_size; boolean discard; info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)handle; init_ptr = &info_ptr->INIT; /* Get the next RX buffer descriptor */ bd_ptr = &info_ptr->RX_RING_PTR[info_ptr->RXNEXT]; _DCACHE_INVALIDATE_LINE(bd_ptr); cntrl = bd_ptr->CONTROL; remote_pcb_ptr = (IO_PCB_STRUCT_PTR) _bsp_ptov(bd_ptr->PACKET_PTR); _DCACHE_INVALIDATE_MBYTES(remote_pcb_ptr, sizeof(*remote_pcb_ptr)); num_frags = remote_pcb_ptr->NUMBER_OF_FRAGMENTS; /* Disable interrupts */ _int_disable(); while(cntrl == (IO_PCB_SHM_BUFFER_OWN|IO_PCB_SHM_BUFFER_ALOCATED)){ discard = FALSE; /* Get a PCB */ local_pcb_ptr = _io_pcb_alloc(info_ptr->READ_PCB_POOL, FALSE); if ((local_pcb_ptr == NULL)) { break; } data_addr = local_pcb_ptr->FRAGMENTS[0].FRAGMENT; data_length = ((IO_PCB_SHM_INIT_STRUCT_PTR) &info_ptr->INIT)->INPUT_MAX_LENGTH; max_size = ((IO_PCB_SHM_INIT_STRUCT_PTR) &info_ptr->INIT)->INPUT_MAX_LENGTH; /* Copy packet */ for(frag_ptr = (IO_PCB_FRAGMENT_STRUCT_PTR) &(remote_pcb_ptr->FRAGMENTS[0]); num_frags; num_frags--, frag_ptr++) { if(frag_ptr->LENGTH > max_size){ discard = TRUE; break; } _DCACHE_INVALIDATE_MBYTES(frag_ptr->FRAGMENT, frag_ptr->LENGTH); _mem_copy(_bsp_ptov((pointer)frag_ptr->FRAGMENT), (pointer)data_addr, frag_ptr->LENGTH); data_addr += frag_ptr->LENGTH; data_length -= frag_ptr->LENGTH; } local_pcb_ptr->FRAGMENTS[0].LENGTH = max_size - data_length; if (info_ptr->READ_CALLBACK_FUNCTION) { (*info_ptr->READ_CALLBACK_FUNCTION)(info_ptr->FD, local_pcb_ptr); } else { _queue_enqueue((QUEUE_STRUCT_PTR)&info_ptr->READ_QUEUE, (QUEUE_ELEMENT_STRUCT_PTR)&local_pcb_ptr->QUEUE); _lwsem_post(&info_ptr->READ_LWSEM); } /* Set the buffer pointer and control bits */ bd_ptr->CONTROL &= IO_PCB_SHM_BUFFER_ALOCATED; _DCACHE_FLUSH_LINE(bd_ptr); /* Update Info structure */ info_ptr->RXNEXT = NEXT_INDEX(info_ptr->RXNEXT, info_ptr->RX_LENGTH); info_ptr->RXENTRIES--; /* Get the next RX buffer descriptor */ bd_ptr = &info_ptr->RX_RING_PTR[info_ptr->RXNEXT]; _DCACHE_INVALIDATE_LINE(bd_ptr); cntrl = bd_ptr->CONTROL; remote_pcb_ptr = (IO_PCB_STRUCT_PTR) _bsp_ptov(bd_ptr->PACKET_PTR); _DCACHE_INVALIDATE_MBYTES(remote_pcb_ptr, sizeof(*remote_pcb_ptr)); num_frags = remote_pcb_ptr->NUMBER_OF_FRAGMENTS; } if (init_ptr->TX_VECTOR == 0) { _io_pcb_shm_tx_isr(handle); } /* Reception successful */ if (!discard) { /* Trigger remote side */ (*init_ptr->INT_TRIGGER)(init_ptr->REMOTE_TX_VECTOR); } _int_enable(); }
_mqx_int _io_pcb_mqxa_ioctl ( /* [IN] the file handle for the device */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the ioctl command */ _mqx_uint cmd, /* [IN] the ioctl parameters */ pointer param_ptr ) { /* Body */ TASK_TEMPLATE_STRUCT input_tt = { 0, _io_pcb_mqxa_read_task, IO_PCB_MQXA_STACK_SIZE, 0, "io_pcb_mqxa_read_task", 0, 0, 0}; TASK_TEMPLATE_STRUCT output_tt = { 0, _io_pcb_mqxa_write_task, IO_PCB_MQXA_STACK_SIZE, 0, "io_pcb_mqxa_write_task", 0, 0, 0}; IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; _mqx_uint result = MQX_OK; _psp_code_addr old_value; _psp_code_addr_ptr pc_ptr = (_psp_code_addr_ptr)param_ptr; _psp_data_addr_ptr pd_ptr = (_psp_data_addr_ptr)param_ptr; boolean _PTR_ bool_param_ptr; info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR; switch (cmd) { case IO_PCB_IOCTL_ENQUEUE_READQ: pcb_ptr = (IO_PCB_STRUCT_PTR)*pd_ptr; _queue_enqueue((QUEUE_STRUCT_PTR)&info_ptr->READ_QUEUE, (QUEUE_ELEMENT_STRUCT_PTR)&pcb_ptr->QUEUE); _lwsem_post(&info_ptr->READ_LWSEM); break; case IO_PCB_IOCTL_READ_CALLBACK_SET: old_value = (_psp_code_addr)info_ptr->READ_CALLBACK_FUNCTION; /* Start CR 398 */ info_ptr->CALLBACK_FD = fd_ptr; /* End CR */ info_ptr->READ_CALLBACK_FUNCTION = (void (_CODE_PTR_)( FILE_DEVICE_STRUCT_PTR, IO_PCB_STRUCT_PTR))*pc_ptr; *pc_ptr = old_value; break; case IO_PCB_IOCTL_SET_INPUT_POOL: old_value = (_psp_code_addr)info_ptr->READ_PCB_POOL; info_ptr->READ_PCB_POOL = (_io_pcb_pool_id)*pc_ptr; *pc_ptr = old_value; break; case IO_PCB_IOCTL_START: if (info_ptr->INPUT_TASK == MQX_NULL_TASK_ID) { input_tt.TASK_PRIORITY = info_ptr->INIT.INPUT_TASK_PRIORITY; input_tt.CREATION_PARAMETER = (uint_32)info_ptr; output_tt.TASK_PRIORITY = info_ptr->INIT.OUTPUT_TASK_PRIORITY; output_tt.CREATION_PARAMETER = (uint_32)info_ptr; info_ptr->INPUT_TASK = _task_create(0, 0, (uint_32)&input_tt); if (info_ptr->INPUT_TASK == MQX_NULL_TASK_ID){ return(_task_get_error()); } /* Endif */ info_ptr->OUTPUT_TASK = _task_create(0, 0, (uint_32)&output_tt); if (info_ptr->OUTPUT_TASK == MQX_NULL_TASK_ID){ return(_task_get_error()); } /* Endif */ }/* Endif */ break; case IO_PCB_IOCTL_UNPACKED_ONLY: bool_param_ptr = (boolean _PTR_)param_ptr; *bool_param_ptr = TRUE; break; default: result = _io_ioctl(info_ptr->FD, cmd, param_ptr); break; } /* Endswitch */ return result; } /* Endbody */
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 */