示例#1
0
void
cyg_spi_transaction_tick(cyg_spi_device* device, cyg_bool polled, cyg_uint32 count)
{
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_ASSERT(bus->spi_current_device == device, "SPI ticks requested without claiming the bus");
    CYG_CHECK_FUNC_PTR(bus->spi_transaction_tick, "SPI device has not provided a tick function");

    (*(bus->spi_transaction_tick))(device, polled, count);
}
示例#2
0
void
cyg_spi_transaction_transfer(cyg_spi_device* device, cyg_bool polled,
                             cyg_uint32 count, const cyg_uint8* tx_data, cyg_uint8* rx_data,
                             cyg_bool drop_cs)
{
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_ASSERT(bus->spi_current_device == device, "SPI transfer requested without claiming the bus");
    CYG_CHECK_FUNC_PTR(bus->spi_transaction_transfer, "SPI device has not provided a transfer function");
    (*(bus->spi_transaction_transfer))(device, polled, count, tx_data, rx_data, drop_cs);
}
示例#3
0
文件: usbs.c 项目: EPiCS/reconos_v2
void
usbs_start_tx(usbs_tx_endpoint* endpoint)
{
    CYG_CHECK_DATA_PTR( endpoint, "A valid USB endpoint must be supplied");
    CYG_CHECK_FUNC_PTR( endpoint->start_tx_fn, "The USB endpoint must support receive operations");
    (*endpoint->start_tx_fn)(endpoint);
}
示例#4
0
文件: usbs.c 项目: EPiCS/reconos_v2
void
usbs_set_tx_endpoint_halted(usbs_tx_endpoint* endpoint, cyg_bool halted)
{
    CYG_CHECK_DATA_PTR( endpoint, "A valid USB endpoint must be supplied");
    CYG_CHECK_FUNC_PTR( endpoint->set_halted_fn, "The USB endpoint should have a set-halted function");
    (*endpoint->set_halted_fn)(endpoint, halted);
}
示例#5
0
文件: fatfs.c 项目: KarenHung/ecosgit
static int
fatfs_get_attrib(cyg_mtab_entry  *mte,
                 cyg_dir          dir,
                 const char      *name,
                 cyg_fs_attrib_t * const file_attrib)
{
    fatfs_disk_t      *disk = (fatfs_disk_t *) mte->data;
    fatfs_dirsearch_t  ds;
    int                err;

    CYG_TRACE4(TFS, "get_attrib mte=%p dir=%p name='%s' buf=%x", 
                    mte, dir, name, file_attrib);

    init_dirsearch(&ds, disk, (fatfs_node_t *) dir, name);

    err = fatfs_find(&ds);
    if (err != ENOERR)
        return err;

    // Get the attribute field
    CYG_CHECK_DATA_PTR(file_attrib,"Invalid destination attribute pointer");
    *file_attrib = ds.node->dentry.attrib;

    return ENOERR;
}
示例#6
0
// set_config is basically just a clone of the above, but using a different
// bus-specific operation.
int
cyg_spi_set_config(cyg_spi_device* device, cyg_uint32 key, const void* buf, cyg_uint32* len)
{
    int             result;
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_CHECK_FUNC_PTR(bus->spi_set_config, "SPI bus driver has not provided a set_config function");

    while (!cyg_drv_mutex_lock(&(bus->spi_lock)));
    result = (*(bus->spi_set_config))(device, key, buf, len);
    cyg_drv_mutex_unlock(&(bus->spi_lock));

    return result;
}
示例#7
0
void
cyg_spi_transaction_end(cyg_spi_device* device)
{
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_ASSERT(bus->spi_current_device == device, "SPI transfer requested without claiming the bus");
    CYG_CHECK_FUNC_PTR(bus->spi_transaction_end, "SPI device has not provided an end function");

    // First, call the bus' end function.
    (*(bus->spi_transaction_end))(device);

    // Then release the SPI bus for other threads.
    cyg_drv_mutex_unlock(&(bus->spi_lock));
}
示例#8
0
文件: usbs.c 项目: EPiCS/reconos_v2
Cyg_ErrNo
usbs_devtab_cwrite(cyg_io_handle_t handle, const void* buf, cyg_uint32* size)
{
    usbs_callback_data  wait;
    cyg_devtab_entry_t* devtab_entry;
    usbs_tx_endpoint*   endpoint;
    int                 result = ENOERR;
    
    CYG_REPORT_FUNCTION();
    
    wait.completed      = 0;
    cyg_drv_mutex_init(&wait.lock);
    cyg_drv_cond_init(&wait.signal, &wait.lock);

    devtab_entry      = (cyg_devtab_entry_t*) handle;
    CYG_CHECK_DATA_PTR( devtab_entry, "A valid endpoint must be supplied");
    endpoint          = (usbs_tx_endpoint*) devtab_entry->priv;
    
    CYG_CHECK_DATA_PTR( endpoint, "The handle must correspond to a USB endpoint");
    CYG_CHECK_FUNC_PTR( endpoint->start_tx_fn, "The endpoint must have a start_tx function");

    endpoint->buffer            = (unsigned char*) buf;
    endpoint->buffer_size       = (int) *size;
    endpoint->complete_fn       = &usbs_devtab_callback;
    endpoint->complete_data     = (void*) &wait;
    (*endpoint->start_tx_fn)(endpoint);
    
    cyg_drv_mutex_lock(&wait.lock);
    cyg_drv_dsr_lock();
    while (!wait.completed) {
        cyg_drv_cond_wait(&wait.signal);
    }
    cyg_drv_dsr_unlock();
    cyg_drv_mutex_unlock(&wait.lock);
    if (wait.result < 0) {
        result = wait.result;
    } else {
        *size = wait.result;
    }
    
    cyg_drv_cond_destroy(&wait.signal);
    cyg_drv_mutex_destroy(&wait.lock);

    CYG_REPORT_RETURN();
    return result;
}
示例#9
0
文件: usbs.c 项目: EPiCS/reconos_v2
void
usbs_start(usbs_control_endpoint* endpoint)
{
    CYG_CHECK_DATA_PTR( endpoint, "A valid USB endpoint must be supplied");
    CYG_CHECK_FUNC_PTR( endpoint->start_fn, "The USB endpoint should have a start function");

    (*endpoint->start_fn)(endpoint);
}
示例#10
0
文件: dns.c 项目: LucidOne/Rovio
/* Initialise the resolver. Open a socket and bind it to the address
   of the server.  return -1 if something goes wrong, otherwise 0. If
   we are being called a second time we have to be careful to allow
   any ongoing lookups to finish before we close the socket and
   connect to a different DNS server. The danger here is that we may
   have to wait for upto 32 seconds if the DNS server is down.
 */
int  
cyg_dns_res_init(struct in_addr *dns_server)
{
    struct sockaddr_in server;
    struct servent *sent;
    static int init =0;

    CYG_REPORT_FUNCNAMETYPE( "cyg_dns_res_init", "returning %d" );
    CYG_REPORT_FUNCARG1( "dns_server=%08x", dns_server );

    CYG_CHECK_DATA_PTR( dns_server, "dns_server is not a valid pointer!" );

    if (init) {
      cyg_drv_mutex_lock(&dns_mutex);
      cyg_thread_free_data_index(ptdindex);
      if (s >= 0) {
        close(s);
      }
    } else {
      init = 1;
      cyg_drv_mutex_init(&dns_mutex);
      cyg_drv_mutex_lock(&dns_mutex);
    }
    

    s = socket(PF_INET, SOCK_DGRAM, 0);
    if (s < 0) {
        cyg_drv_mutex_unlock(&dns_mutex);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }
  
    sent = getservbyname("domain", "udp");
    if (sent == (struct servent *)0) {
        s = -1;
        cyg_drv_mutex_unlock(&dns_mutex);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }
  
    memcpy((char *)&server.sin_addr, (const void *)dns_server, sizeof(server.sin_addr));
    server.sin_port = sent->s_port;
    server.sin_family = AF_INET;
    server.sin_len = sizeof(server);

    if (connect(s, (struct sockaddr *)&server, sizeof(server)) < 0) {
        s = -1;
        cyg_drv_mutex_unlock(&dns_mutex);
        CYG_REPORT_RETVAL( -1 );
        return -1;
    }
    ptdindex = cyg_thread_new_data_index();  
  
    cyg_drv_mutex_unlock(&dns_mutex);
  
    CYG_REPORT_RETVAL( 0 );
    return 0;
}
示例#11
0
// transaction-begin involves getting sole access to the bus, then calling
// the bus driver's begin function to set up the hardware appropriately for
// the target device.
void
cyg_spi_transaction_begin(cyg_spi_device* device)
{
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_CHECK_FUNC_PTR(bus->spi_transaction_begin, "SPI device has not provided a transaction_begin function");

    while (!cyg_drv_mutex_lock(&(bus->spi_lock)));
#ifdef CYGDBG_USE_ASSERTS
    bus->spi_current_device = device;
#endif

    // This thread now has exclusive access to the bus
    (*(bus->spi_transaction_begin))(device);

    // All done. Return with the bus still locked.
}
示例#12
0
文件: tassert4.c 项目: 0xCA5A/dd-wrt
int main(int argc, char** argv)
{
    CYG_ASSERT( true, message);
    CYG_ASSERT( false, message);
    CYG_ASSERTC(true);
    CYG_ASSERTC(false);
    
    CYG_FAIL(message);
    
    CYG_CHECK_DATA_PTR( &argc, message);
    CYG_CHECK_DATA_PTR( 0,     message);
    CYG_CHECK_FUNC_PTR( &main, message);
    CYG_CHECK_FUNC_PTR( 0,     message);
    CYG_CHECK_DATA_PTRC(&argc);
    CYG_CHECK_DATA_PTRC(0);
    CYG_CHECK_FUNC_PTRC(&main);
    CYG_CHECK_FUNC_PTRC(0);

    CYG_PRECONDITION(true, message);
    CYG_PRECONDITION(false, message);
    CYG_PRECONDITIONC(true);
    CYG_PRECONDITIONC(false);

    CYG_POSTCONDITION(true, message);
    CYG_POSTCONDITION(false, message);
    CYG_POSTCONDITIONC(true);
    CYG_POSTCONDITIONC(false);

    CYG_LOOP_INVARIANT(true, message);
    CYG_LOOP_INVARIANT(false, message);
    CYG_LOOP_INVARIANTC(true);
    CYG_LOOP_INVARIANTC(false);

    CYG_INVARIANT(true, message);
    CYG_INVARIANT(false, message);
    CYG_INVARIANTC(true);
    CYG_INVARIANTC(false);
    
    CYG_TEST_PASS_FINISH("disabled assertions in C code do nothing");
    return 0;
}
示例#13
0
// A variant of the above which returns immediately if some other thread
// is using the bus.
cyg_bool
cyg_spi_transaction_begin_nb(cyg_spi_device* device)
{
    cyg_bool        result  = false;
    cyg_spi_bus*    bus;
    CYG_CHECK_DATA_PTR(device, "valid SPI device pointer required");

    bus = device->spi_bus;
    CYG_CHECK_DATA_PTR(bus, "SPI device does not point at a valid bus structure");
    CYG_CHECK_FUNC_PTR(bus->spi_transaction_begin, "SPI device has not provided a transaction_begin function");

    if (cyg_drv_mutex_trylock(&(bus->spi_lock))) {
#ifdef CYGDBG_USE_ASSERTS
        bus->spi_current_device = device;
#endif
        (*(bus->spi_transaction_begin))(device);
        result = true;
    }

    return result;
}
示例#14
0
文件: usbs.c 项目: EPiCS/reconos_v2
void
usbs_start_tx_buffer(usbs_tx_endpoint* endpoint,
                     const unsigned char* buf, int size,
                     void (*callback_fn)(void*, int), void *callback_arg)
{
    CYG_CHECK_DATA_PTR( endpoint, "A valid USB endpoint must be supplied");
    CYG_CHECK_FUNC_PTR( endpoint->start_tx_fn, "The USB endpoint must support receive operations");

    endpoint->buffer            = buf;
    endpoint->buffer_size       = size;
    endpoint->complete_fn       = callback_fn;
    endpoint->complete_data     = callback_arg;
    (*endpoint->start_tx_fn)(endpoint);
}
示例#15
0
文件: dns.c 项目: LucidOne/Rovio
/* Send the query to the server and read the response back. Return -1
   if it fails, otherwise put the response back in msg and return the
   length of the response. */
static int 
send_recv(char * msg, int len, int msglen)
{
    struct dns_header *dns_hdr;
    struct timeval timeout;
    int finished = false;
    int backoff = 2;
    fd_set readfds;
    int written;
    int ret;

    CYG_REPORT_FUNCNAMETYPE( "send_recv", "returning %d" );
    CYG_REPORT_FUNCARG3( "msg=%08x, len=%d, msglen", msg, len, msglen );

    CYG_CHECK_DATA_PTR( msg, "msg is not a valid pointer!" );
    
    dns_hdr = (struct dns_header *) msg;
    
    do { 
        written = write(s, msg, len);
        if (written < 0 || (written!=len)) {
            ret = -1;
            break;
        }

        FD_ZERO(&readfds);
        FD_SET(s, &readfds);
    
        timeout.tv_sec = backoff;
        timeout.tv_usec = 0;
        backoff = backoff << 1;

        ret = select(s+1, &readfds, NULL, NULL, &timeout);
        if (ret < 0) {
            ret = -1;
            break;
        }
        /* Timeout */
        if (ret == 0) {
            if (backoff > 16) {
                h_errno = TRY_AGAIN;
                ret = -1;
                break;
            }
        }
        if (ret == 1) {
            ret = read(s, msg, msglen);
            if (ret < 0) {
                ret = -1;
                break;
            }
            /* Reply to an old query. Ignore it */
            if (ntohs(dns_hdr->id) != (id-1)) {
                continue;
            }
            finished = true;
        }
    } while (!finished);

    CYG_REPORT_RETVAL( ret );

    return ret;
}
示例#16
0
文件: usbs.c 项目: EPiCS/reconos_v2
cyg_bool
usbs_tx_endpoint_halted(usbs_tx_endpoint* endpoint)
{
   CYG_CHECK_DATA_PTR( endpoint, "A valid USB endpoint must be supplied");
   return endpoint->halted;
}