Changes between Initial Version and Version 1 of Component/Vci Fd Access


Ignore:
Timestamp:
Oct 29, 2007, 12:55:10 PM (17 years ago)
Author:
Nicolas Pouillon
Comment:

Fd Access

Legend:

Unmodified
Added
Removed
Modified
  • Component/Vci Fd Access

    v1 v1  
     1[wiki:Component SocLib Components General Index]
     2
     3= !VciFdAccess Functional Description =
     4
     5This VCI component is both a target and an initiator.
     6 * Addressing as a target allows to configure it for a transfer.
     7 * Initiator will do the transfer
     8
     9There is only one access context handled at a time, but fd can be changed for each operation, many fd can be open at the same time.
     10
     11An IRQ is optionally asserted when transfer is finished.
     12
     13This hardware component checks for segmentation violation, and can be used
     14as a default target.
     15
     16= Memory region layout =
     17
     18 * `FD_ACCESS_FD` File descriptor for the transfer
     19
     20 * `FD_ACCESS_BUFFER` Buffer (in SoC memory) for the transfer
     21
     22 * `FD_ACCESS_SIZE` Size of the transfer
     23
     24 * `FD_ACCESS_HOW` Type of open() operation
     25
     26 * `FD_ACCESS_WHENCE` Type of offset when changing file pointer
     27
     28 * `FD_ACCESS_OP` Type of operation, writing here initiates the operation.[[BR]]
     29   This register goes back to FD_ACCESS_NOOP when operation is finished.
     30
     31 * `FD_ACCESS_RETVAL` Return value
     32
     33 * `FD_ACCESS_ERRNO` Errno
     34
     35 * `FD_ACCESS_IRQ_ENABLE` Boolean enabling the IRQ line
     36
     37 * `FD_ACCESS_MODE` (aliases with WHENCE) Mode for open() with a O_CREAT
     38
     39= Operations codes =
     40
     41 * `FD_ACCESS_NOOP` Nothing
     42
     43 * `FD_ACCESS_OPEN` open()[[BR]]
     44   path: `FD_ACCESS_BUFFER`[[BR]]
     45   `FD_ACCESS_SIZE` must contain the length of path[[BR]]
     46   returned fd is in `FD_ACCESS_RETVAL`
     47
     48 * `FD_ACCESS_CLOSE` close()
     49
     50 * `FD_ACCESS_READ` read()
     51
     52 * `FD_ACCESS_WRITE` write()
     53
     54 * `FD_ACCESS_LSEEK` lseek()
     55
     56= Component usage =
     57
     58For extensibility issues, you should access this component using globally-defined offsets.
     59
     60You should include file source:trunk/soclib/include/soclib/fd_access.h from your software, it
     61defines `FD_ACCESS_FD`, `FD_ACCESS_BUFFER`, ...
     62
     63Sample code:
     64{{{
     65#include "soclib/fd_access.h"
     66
     67static const void* fd_base = 0xc0000000;
     68
     69int open( const char *path, const int how, const int mode )
     70{
     71        soclib_io_set(fd_base, FD_ACCESS_BUFFER, (uint32_t)path);
     72        soclib_io_set(fd_base, FD_ACCESS_SIZE, strlen(path));
     73        soclib_io_set(fd_base, FD_ACCESS_HOW, how);
     74        soclib_io_set(fd_base, FD_ACCESS_MODE, mode);
     75        soclib_io_set(fd_base, FD_ACCESS_OP, FD_ACCESS_OPEN);
     76        while (soclib_io_get(fd_base, FD_ACCESS_OP))
     77                ;
     78        errno = soclib_io_get(fd_base, FD_ACCESS_ERRNO);
     79        return soclib_io_get(fd_base, FD_ACCESS_RETVAL);
     80}
     81
     82int close( const int fd )
     83{
     84        soclib_io_set(fd_base, FD_ACCESS_FD, fd);
     85        soclib_io_set(fd_base, FD_ACCESS_OP, FD_ACCESS_CLOSE);
     86        while (soclib_io_get(fd_base, FD_ACCESS_OP))
     87                ;
     88        errno = soclib_io_get(fd_base, FD_ACCESS_ERRNO);
     89        return soclib_io_get(fd_base, FD_ACCESS_RETVAL);
     90}
     91
     92// Beware your caches could contain stale memory image after this call
     93int read( const int fd, const void *buffer, const size_t len )
     94{
     95        soclib_io_set(fd_base, FD_ACCESS_FD, fd);
     96        soclib_io_set(fd_base, FD_ACCESS_BUFFER, (uint32_t)buffer);
     97        soclib_io_set(fd_base, FD_ACCESS_SIZE, len);
     98        soclib_io_set(fd_base, FD_ACCESS_OP, FD_ACCESS_READ);
     99        while (soclib_io_get(fd_base, FD_ACCESS_OP))
     100                ;
     101        errno = soclib_io_get(fd_base, FD_ACCESS_ERRNO);
     102        return soclib_io_get(fd_base, FD_ACCESS_RETVAL);
     103}
     104
     105int write( const int fd, const void *buffer, const size_t len )
     106{
     107        soclib_io_set(fd_base, FD_ACCESS_FD, fd);
     108        soclib_io_set(fd_base, FD_ACCESS_BUFFER, (uint32_t)buffer);
     109        soclib_io_set(fd_base, FD_ACCESS_SIZE, len);
     110        soclib_io_set(fd_base, FD_ACCESS_OP, FD_ACCESS_WRITE);
     111        while (soclib_io_get(fd_base, FD_ACCESS_OP))
     112                ;
     113        errno = soclib_io_get(fd_base, FD_ACCESS_ERRNO);
     114        return soclib_io_get(fd_base, FD_ACCESS_RETVAL);
     115}
     116
     117int lseek( const int fd, const off_t offset, int whence )
     118{
     119        soclib_io_set(fd_base, FD_ACCESS_FD, fd);
     120        soclib_io_set(fd_base, FD_ACCESS_SIZE, offset);
     121        soclib_io_set(fd_base, FD_ACCESS_WHENCE, whence);
     122        soclib_io_set(fd_base, FD_ACCESS_OP, FD_ACCESS_LSEEK);
     123        while (soclib_io_get(fd_base, FD_ACCESS_OP))
     124                ;
     125        errno = soclib_io_get(fd_base, FD_ACCESS_ERRNO);
     126        return soclib_io_get(fd_base, FD_ACCESS_RETVAL);
     127}
     128}}}
     129
     130(add -I/path/to/soclib/include to your compilation command-line)
     131
     132= Component definition =
     133
     134Available in source:trunk/soclib/desc/soclib/vci_fd_access.sd
     135
     136== Usage ==
     137
     138!VciFdAccess has no other parameter than VCI ones, it may be used like others, see [wiki:SoclibCc/VciParameters SoclibCc/VciParameters]
     139{{{
     140Uses( 'vci_fd_access', **vci_parameters )
     141}}}
     142
     143= !VciFdAccess CABA  Implementation =
     144
     145The caba implementation is in
     146 * source:trunk/soclib/systemc/include/caba/target/vci_fd_access.h
     147 * source:trunk/soclib/systemc/src/caba/target/vci_fd_access.cc
     148
     149== Template parameters: ==
     150
     151 * The VCI parameters
     152
     153== Constructor parameters ==
     154{{{
     155VciFdAccess(
     156     sc_module_name name,   //  Component Name
     157     const soclib::common::IntTab & index,  // Target index
     158     const soclib::common::MappingTable &mt )   // MappingTable
     159}}}
     160
     161== Ports ==
     162
     163 * sc_in<bool> '''p_resetn''' : Global system reset
     164 * sc_in<bool> '''p_clk''' : Global system clock
     165 * soclib::caba::!VciTarget<vci_param> '''p_vci_target''' : The VCI target port
     166 * soclib::caba::!VciInitiator<vci_param> '''p_vci_initiator''' : The VCI initiator port
     167 * sc_out<bool> '''p_irq''' : Interrupt port