#ifndef SerialPortIoCtlH
#define SerialPortIoCtlH SerialPortIoCtlH

case IOCTL_FLUSHPORT:
{
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        reset_read_write_fifo( &dev_obj->uart_port[cl_data->port] );
    }
    break;
}
case IOCTL_GETNUMOFBYTESAVAIL:
{
    u32 bytes_available = 0;
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        bytes_available = getnumber_bytes_available( &dev_obj->uart_port[cl_data->port] );
    }
    //PRINTKM ( IOCTL, ( PKTD "IOCTL_GETNUMOFBYTESAVAIL bytes_available %u, out_size %u (%u)\n", dev_obj->index, bytes_available, mvio.out_size, sizeof( u32 ) ) );
    if( mvio.out_size >= sizeof( u32 ) )
    {
        memcpy( IOBUFFER_TO( void* ), ( void* )&bytes_available, sizeof( u32 ) );
        ( ( struct mv_ioctl* )io_buffer )->bytes_returned = sizeof( u32 );
        write_back_to_user = TRUE;
    }
    break;
}
case IOCTL_SETBAUDRATE:
{
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        set_baudrate( &dev_obj->uart_port[cl_data->port], cl_data->data );
    }
    break;
}
case IOCTL_SERIALINIT:
{
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        PRINTKM ( IOCTL, ( PKTD "IOCTL_SERIALINIT port %d\n", dev_obj->index, cl_data->port ) );
        error = create_serial( &dev_obj->hyperion_base, dev_obj->reg_def, &dev_obj->uart_port[cl_data->port], cl_data->port + ebrhUart0, dev_obj->index );
        //if successful return 1, on error return 0
        //reset_read_write_fifo( &dev_obj->uart_port[cl_data->port] );
    }
    break;
}
case IOCTL_SERIALCLOSE:
{
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        PRINTKM ( IOCTL, ( PKTD "IOCTL_SERIALCLOSE port %d\n", dev_obj->index, cl_data->port ) );
        close_serial( &dev_obj->uart_port[cl_data->port] );
    }
    break;
}
case IOCTL_SERIALREAD:
{
    unsigned long read_status;
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        read_status = read_serial_data( &dev_obj->uart_port[cl_data->port], cl_data->data, IOBUFFER_TO( unsigned char* ), mvio.out_size );
        if( read_status == secNoError )
        {
            ( ( struct mv_ioctl* )io_buffer )->bytes_returned = ( read_status == secNoError ) ? mvio.out_size : 0;
        }
        write_back_to_user = TRUE;
    }
    break;
}
case IOCTL_SERIALWRITE:
{
    unsigned long bytes_written;
    CAMERA_LINK_DATA* cl_data = IOBUFFER_TO( CAMERA_LINK_DATA* );
    if( mvio.in_size >= sizeof( CAMERA_LINK_DATA ) && cl_data->port < UART_NUM )
    {
        bytes_written = write_serial_data( &dev_obj->uart_port[cl_data->port], cl_data->data, IOBUFFER_TO( unsigned char* ) + sizeof( CAMERA_LINK_DATA ) , mvio.in_size - sizeof( CAMERA_LINK_DATA ) );
        ( ( struct mv_ioctl* )io_buffer )->bytes_returned = bytes_written;
        write_back_to_user = TRUE;
    }
    break;
}
#endif //SerialPortIoCtlH
