_mqx_int _io_pcb_shm_close ( /* [IN] the file handle */ FILE_DEVICE_STRUCT_PTR fd_ptr ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; IO_PCB_SHM_INIT_STRUCT_PTR init_ptr; #if MQX_CHECK_ERRORS if (!(fd_ptr->FLAGS & IO_FLAG_IS_PCB_DEVICE)) { fd_ptr->ERROR = IO_PCB_NOT_A_PCB_DEVICE; return(IO_ERROR); } #endif info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR; init_ptr = &info_ptr->INIT; if (!_int_install_isr(init_ptr->RX_VECTOR, info_ptr->RX_OLDISR_PTR, info_ptr->RX_OLDISR_DATA)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } if (init_ptr->TX_VECTOR) { if (!_int_install_isr(init_ptr->TX_VECTOR, info_ptr->TX_OLDISR_PTR, info_ptr->TX_OLDISR_DATA)) { return MQX_IO_PCB_SHM_INSTALL_ISR_FAILLED; } } _lwsem_destroy(&info_ptr->READ_LWSEM); _lwsem_destroy(&info_ptr->WRITE_LWSEM); while (_queue_get_size(&info_ptr->WRITE_QUEUE)) { pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->WRITE_QUEUE)); _io_pcb_free(pcb_ptr); } while (_queue_get_size(&info_ptr->READ_QUEUE)) { pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _io_pcb_free(pcb_ptr); } return(MQX_OK); }
_mqx_int _io_pcb_mqxa_close ( /* [IN] the file handle */ FILE_DEVICE_STRUCT_PTR fd_ptr ) { /* Body */ IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; #if MQX_CHECK_ERRORS if (!(fd_ptr->FLAGS & IO_FLAG_IS_PCB_DEVICE)) { fd_ptr->ERROR = IO_PCB_NOT_A_PCB_DEVICE; return(IO_ERROR); }/* Endif */ #endif info_ptr = (IO_PCB_MQXA_INFO_STRUCT_PTR)fd_ptr->DEV_DATA_PTR; if (info_ptr->FD) { fclose(info_ptr->FD); info_ptr->FD = NULL; }/* Endif */ if (info_ptr->INPUT_TASK) { #if MQX_TASK_DESTRUCTION _task_destroy(info_ptr->INPUT_TASK); #endif info_ptr->INPUT_TASK = 0; }/* Endif */ if (info_ptr->OUTPUT_TASK ) { #if MQX_TASK_DESTRUCTION _task_destroy(info_ptr->OUTPUT_TASK); #endif info_ptr->OUTPUT_TASK = 0; }/* Endif */ _lwsem_destroy(&info_ptr->READ_LWSEM); _lwsem_destroy(&info_ptr->WRITE_LWSEM); while (_queue_get_size(&info_ptr->WRITE_QUEUE)) { pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->WRITE_QUEUE)); _io_pcb_free(pcb_ptr); } /* Endwhile */ while (_queue_get_size(&info_ptr->READ_QUEUE)) { pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _io_pcb_free(pcb_ptr); } /* Endwhile */ return(MQX_OK); } /* Endbody */
_mqx_int _io_pcb_shm_read ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR _PTR_ pcb_ptr ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; _int_disable(); if (fd_ptr->FLAGS & IO_O_NONBLOCK) { if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); return(MQX_OK); } } _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); return(MQX_OK); }
_mqx_int _io_pcb_shm_read ( /* [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; _int_disable(); if (fd_ptr->FLAGS & IO_O_NONBLOCK) { if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); return(MQX_OK); } } _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((void *)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); return(MQX_OK); }
_mqx_uint _io_pcb_test ( /* The PCB pool in error */ pointer _PTR_ pool_in_error, /* The PCB in error */ pointer _PTR_ pcb_in_error ) { /* Body */ KERNEL_DATA_STRUCT_PTR kernel_data; IO_PCB_POOL_STRUCT_PTR pool_ptr; _mqx_uint i; _mqx_uint result; _GET_KERNEL_DATA(kernel_data); *pool_in_error = NULL; *pcb_in_error = NULL; _INT_DISABLE(); result = _queue_test((QUEUE_STRUCT_PTR)(&kernel_data->IO_PCB_POOLS), pool_in_error); if (result != MQX_OK) { _int_enable(); return(result); }/* Endif */ pool_ptr = (pointer)kernel_data->IO_PCB_POOLS.NEXT; for (i = 0; i < _queue_get_size((QUEUE_STRUCT_PTR)(&kernel_data->IO_PCB_POOLS)); i++) { if (pool_ptr->VALID != IO_PCB_VALID) { /* START CR 2062 */ _int_enable(); /* END CR 2062 */ *pool_in_error = (pointer)pool_ptr; return(IO_PCB_POOL_INVALID); }/* Endif */ pool_ptr = (pointer)pool_ptr->QUEUE.NEXT; } /* Endfor */ /* START CR 2062 */ _int_enable(); /* END CR 2062 */ return(MQX_OK); } /* Endbody */
_mqx_int _io_pcb_mqxa_read ( /* [IN] the file descriptor */ FILE_DEVICE_STRUCT_PTR fd_ptr, /* [IN] the pcb address from which to write data */ IO_PCB_STRUCT_PTR _PTR_ pcb_ptr ) { /* Body */ IO_PCB_MQXA_INFO_STRUCT_PTR info_ptr; info_ptr = fd_ptr->DEV_DATA_PTR; if (info_ptr->FD) { _int_disable(); /* ** Start CR 383 ** if (info_ptr->FD->FLAGS & IO_O_NONBLOCK) { */ if (fd_ptr->FLAGS & IO_O_NONBLOCK) { /* End CR 383 */ if (! _queue_get_size(&info_ptr->READ_QUEUE)) { *pcb_ptr = NULL; _int_enable(); /* ** Start CR 384 ** return(0); */ return MQX_OK; /* End CR 384 */ } /* Endif */ } /* Endif */ _lwsem_wait(&info_ptr->READ_LWSEM); *pcb_ptr = (IO_PCB_STRUCT_PTR) ((pointer)_queue_dequeue(&info_ptr->READ_QUEUE)); _int_enable(); /* ** Start CR 384 ** return(0); */ return MQX_OK; /* End CR 384 */ }/* Endif */ return(IO_ERROR); } /* Endbody */
void _io_pcb_shm_tx ( /* [IN] the device info */ pointer handle ) { IO_PCB_SHM_INFO_STRUCT_PTR info_ptr; IO_PCB_STRUCT_PTR pcb_ptr; IO_PCB_SHM_BUFFER_STRUCT_PTR bd_ptr; IO_PCB_SHM_INIT_STRUCT_PTR init_ptr; IO_PCB_FRAGMENT_STRUCT_PTR frag_ptr; uint_32 work = FALSE; uint_16 num_frags; info_ptr = (IO_PCB_SHM_INFO_STRUCT_PTR)handle; init_ptr = &info_ptr->INIT; while (TRUE) { _int_disable(); /* Check if queue empty */ if (!_queue_get_size(&info_ptr->WRITE_QUEUE)) { _int_enable(); break; } /* Check if queue empty */ if (!(info_ptr->TXENTRIES)) { _int_enable(); info_ptr->TX_BD_RUNOVER++; break; } /* Get the packet from output queue */ pcb_ptr = (IO_PCB_STRUCT_PTR)((pointer) _queue_dequeue(&info_ptr->WRITE_QUEUE)); /* Get the next buffer descriptor */ bd_ptr = &info_ptr->TX_RING_PTR[info_ptr->TXNEXT]; /* Flush packet */ num_frags = pcb_ptr->NUMBER_OF_FRAGMENTS; for(frag_ptr = (IO_PCB_FRAGMENT_STRUCT_PTR) &(pcb_ptr->FRAGMENTS[0]); num_frags; num_frags--, frag_ptr++) { _DCACHE_FLUSH_MLINES(frag_ptr->FRAGMENT,frag_ptr->LENGTH); frag_ptr->FRAGMENT = _bsp_vtop(frag_ptr->FRAGMENT); } /* Set the buffer descriptor */ bd_ptr->PACKET_PTR = (IO_PCB_STRUCT_PTR) _bsp_vtop(pcb_ptr); bd_ptr->CONTROL = (IO_PCB_SHM_BUFFER_OWN|IO_PCB_SHM_BUFFER_ALOCATED); _DCACHE_FLUSH_LINE(bd_ptr); /* Update Info structure */ info_ptr->TXNEXT = NEXT_INDEX(info_ptr->TXNEXT, info_ptr->TX_LENGTH); info_ptr->TXENTRIES--; work = TRUE; _int_enable(); } if (work) { /* Trigger remote ISR */ (*init_ptr->INT_TRIGGER)(init_ptr->REMOTE_RX_VECTOR); } }