예제 #1
0
int main( int argc, char **argv )
{
    void *retval;
    pthread_attr_t attr;
    struct sched_param schedparam;

    CYG_TEST_INIT();

    sa.sin_family = AF_INET;
    sa.sin_len = sizeof(sa);
    inet_aton("127.0.0.1", &sa.sin_addr);
    sa.sin_port = htons(1234);
    init_all_network_interfaces();
    
    // Create test threads

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 5;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread1_stack[sizeof(thread1_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread1_stack) );

        pthread_create( &thread1,
                        &attr,
                        pthread_entry1,
                        (void *)0x12345671);
    }

    {
        pthread_attr_init( &attr );

        schedparam.sched_priority = 10;
        pthread_attr_setinheritsched( &attr, PTHREAD_EXPLICIT_SCHED );
        pthread_attr_setschedpolicy( &attr, SCHED_RR );
        pthread_attr_setschedparam( &attr, &schedparam );
        pthread_attr_setstackaddr( &attr, (void *)&thread2_stack[sizeof(thread2_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread2_stack) );

        pthread_create( &thread2,
                        &attr,
                        pthread_entry2,
                        (void *)0x12345672);
    }
    
    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join(thread1)");
    pthread_join( thread1, &retval );

    // And thread 2
    CYG_TEST_INFO( "Main: calling pthread_join(thread2)");
    pthread_join( thread2, &retval );

    diag_printf("INFO: pselect returns: %d\n", pselect_wakeups );
    diag_printf("INFO: pselect EINTR returns: %d\n", pselect_eintr );
    diag_printf("INFO: SIGUSR1 sent: %d\n", sigusr1_sent );
    diag_printf("INFO: SIGUSR1 delivered: %d\n", sigusr1_calls );
    
    CYG_TEST_CHECK( sigusr1_sent == sigusr1_calls, "SIGUSR1 calls != delivered");
    CYG_TEST_CHECK( sigusr1_sent == pselect_eintr, "SIGUSR1 calls != pselect EINTR wakeups");
    
    CYG_TEST_PASS_FINISH("pselect");
}
예제 #2
0
파일: cache.c 프로젝트: 0xCA5A/dd-wrt
static void entry0( void )
{
    register CYG_INTERRUPT_STATE oldints;

#ifdef HAL_CACHE_UNIFIED

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();             // rely on above definition
    HAL_UCACHE_INVALIDATE_ALL();
    HAL_UCACHE_DISABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Cache off");
    time1();

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();             // rely on above definition
    HAL_UCACHE_INVALIDATE_ALL();
    HAL_UCACHE_ENABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Cache on");
    time1();

#else // HAL_CACHE_UNIFIED

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();
    HAL_ICACHE_INVALIDATE_ALL();
    HAL_DCACHE_INVALIDATE_ALL();
    HAL_ICACHE_DISABLE();
    HAL_DCACHE_DISABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Dcache off Icache off");
    time1();

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();
    HAL_ICACHE_INVALIDATE_ALL();
    HAL_DCACHE_INVALIDATE_ALL();
    HAL_ICACHE_DISABLE();
    HAL_DCACHE_ENABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Dcache on  Icache off");
    time1();

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();
    HAL_ICACHE_INVALIDATE_ALL();
    HAL_DCACHE_INVALIDATE_ALL();
    HAL_ICACHE_ENABLE();
    HAL_DCACHE_DISABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Dcache off Icache on");
    time1();

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();
    HAL_ICACHE_INVALIDATE_ALL();
    HAL_DCACHE_INVALIDATE_ALL();
    HAL_ICACHE_ENABLE();
    HAL_DCACHE_ENABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Dcache on  Icache on");
    time1();

    HAL_DISABLE_INTERRUPTS(oldints);
    HAL_DCACHE_PURGE_ALL();
    HAL_ICACHE_INVALIDATE_ALL();
    HAL_DCACHE_INVALIDATE_ALL();
    HAL_ICACHE_DISABLE();
    HAL_DCACHE_DISABLE();
    HAL_RESTORE_INTERRUPTS(oldints);
    CYG_TEST_INFO("Dcache off Icache off");
    time1();

#endif // HAL_CACHE_UNIFIED

    CYG_TEST_PASS_FINISH("End of test");
}
예제 #3
0
externC void
cyg_start( void )
{
    CYG_TEST_INIT();
    CYG_TEST_PASS_FINISH("Incorrect configuration for this test");
}
예제 #4
0
int main( int argc, char **argv )
{
    int err;
    int existingdirents=-1;
#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    struct cyg_fs_block_usage usage;
#endif

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    err = mount( "/dev/disk0/1", "/", "fatfs" );    
    if( err < 0 ) SHOW_RESULT( mount, err );    

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    listdir( "/", true, -1, &existingdirents );

    // --------------------------------------------------------------
#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
		usage.total_blocks, usage.total_blocks * usage.block_size); 
    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
		usage.free_blocks, usage.free_blocks * usage.block_size); 
    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
#endif
    // --------------------------------------------------------------

    createfile( "/foo", 20257 );
    checkfile( "foo" );
    copyfile( "foo", "fee");
    checkfile( "fee" );
    comparefiles( "foo", "/fee" );
    diag_printf("<INFO>: mkdir bar\n");
    err = mkdir( "/bar", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/" , true, existingdirents+3, NULL );

    copyfile( "fee", "/bar/fum" );
    checkfile( "bar/fum" );
    comparefiles( "/fee", "bar/fum" );

    diag_printf("<INFO>: cd bar\n");
    err = chdir( "bar" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/bar" );
    
    diag_printf("<INFO>: rename /foo bundy\n");    
    err = rename( "/foo", "bundy" );
    if( err < 0 ) SHOW_RESULT( rename, err );
    
    listdir( "/", true, existingdirents+2, NULL );
    listdir( "" , true, 4, NULL );

    checkfile( "/bar/bundy" );
    comparefiles("/fee", "bundy" );

#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
		usage.total_blocks, usage.total_blocks * usage.block_size); 
    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
		usage.free_blocks, usage.free_blocks * usage.block_size); 
    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
#endif
    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink fee\n");    
    err = unlink( "/fee" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink fum\n");        
    err = unlink( "fum" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink /bar/bundy\n");        
    err = unlink( "/bar/bundy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");        
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    diag_printf("<INFO>: rmdir /bar\n");        
    err = rmdir( "/bar" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    listdir( "/", false, existingdirents, NULL );

    // --------------------------------------------------------------

#if 0
    diag_printf("<INFO>: mkdir disk2\n");
    err = mkdir( "/disk2", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
#else
    diag_printf("<INFO>: mount /disk2\n");    
    err = mount( "/dev/disk0/2", "/disk2", "fatfs" );    
    if( err < 0 ) SHOW_RESULT( mount, err );    
#endif
    
    listdir( "/disk2" , true, -1, &existingdirents);
        
    createfile( "/disk2/tinky", 4567 );
    copyfile( "/disk2/tinky", "/disk2/laalaa" );
    checkfile( "/disk2/tinky");
    checkfile( "/disk2/laalaa");
    comparefiles( "/disk2/tinky", "/disk2/laalaa" );

    diag_printf("<INFO>: cd /disk2\n");    
    err = chdir( "/disk2" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/disk2" );
        
    diag_printf("<INFO>: mkdir noonoo\n");    
    err = mkdir( "noonoo", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/disk2" , true, existingdirents+3, NULL);

    diag_printf("<INFO>: cd noonoo\n");
    err = chdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/disk2/noonoo" );
    
    createfile( "tinky", 6789 );
    checkfile( "tinky" );

    createfile( "dipsy", 34567 );
    checkfile( "dipsy" );
    copyfile( "dipsy", "po" );
    checkfile( "po" );
    comparefiles( "dipsy", "po" );

    listdir( ".", true, 5, NULL );
    listdir( "", true, 5, NULL );
    listdir( "..", true, existingdirents+3, NULL );

    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink dipsy\n");    
    err = unlink( "dipsy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink po\n");    
    err = unlink( "po" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd ..\n"); 
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2" );
    
    diag_printf("<INFO>: rmdir noonoo\n"); 
    err = rmdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    // --------------------------------------------------------------

    err = mkdir( "x", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y/z", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    err = mkdir( "x/y/z/w", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    diag_printf("<INFO>: cd /disk2/x/y/z/w\n");
    err = chdir( "/disk2/x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z/w" );

    diag_printf("<INFO>: cd ..\n");
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z" );
    
    diag_printf("<INFO>: cd .\n");
    err = chdir( "." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y/z" );

    diag_printf("<INFO>: cd ../../y\n");
    err = chdir( "../../y" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2/x/y" );

    diag_printf("<INFO>: cd ../..\n");
    err = chdir( "../.." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/disk2" );

    diag_printf("<INFO>: rmdir x/y/z/w\n"); 
    err = rmdir( "x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y/z\n"); 
    err = rmdir( "x/y/z" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y\n"); 
    err = rmdir( "x/y" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x\n"); 
    err = rmdir( "x" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    // --------------------------------------------------------------

    checkcwd( "/disk2" );
    
    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink laalaa\n");    
    err = unlink( "laalaa" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");    
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/" );

    listdir( "/disk2", true, -1, NULL );
    
#if 0
    diag_printf("<INFO>: rmdir dir\n"); 
    err = rmdir( "disk2" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
#else
    diag_printf("<INFO>: umount /disk2\n");    
    err = umount( "/disk2" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
#endif
    
#ifdef CYGCFG_FS_FAT_USE_ATTRIBUTES
    // Create file
    diag_printf("<INFO>: create /foo\n");
    createfile( "/foo", 20257 );

    // Verify it is created with archive bit set
    checkattrib( "/foo", S_FATFS_ARCHIVE );

    // Make it System
    diag_printf("<INFO>: attrib -A+S /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_SYSTEM );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now System
    checkattrib( "/foo", S_FATFS_SYSTEM );

    // Make it Hidden
    diag_printf("<INFO>: attrib -S+H /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_HIDDEN );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now Hidden
    checkattrib( "/foo", S_FATFS_HIDDEN );

    // Make it Read-only
    diag_printf("<INFO>: attrib -H+R /foo\n");
    err = cyg_fs_set_attrib( "/foo", S_FATFS_RDONLY );
    if( err < 0 ) SHOW_RESULT( chmod system , err );

    // Verify it is now Read-only
    checkattrib( "/foo", S_FATFS_RDONLY );

    // Verify we cannot unlink a read-only file
    diag_printf("<INFO>: unlink /foo\n");
    err = unlink( "/foo" );
    if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( unlink, err );

    // Verify we cannot rename a read-only file
    diag_printf("<INFO>: rename /foo bundy\n");
    err = rename( "/foo", "bundy" );
    if( (err != -1) || (errno != EPERM) ) SHOW_RESULT( rename, err );

    // Verify we cannot open read-only file for writing
    int fd;
    diag_printf("<INFO>: create file /foo\n");
    fd = open( "/foo", O_WRONLY );
    if( (err != -1) || (errno != EACCES) ) SHOW_RESULT( open, err );
    if( err > 0 ) close(fd);

    // Make it Normal
    diag_printf("<INFO>: attrib -H /foo\n");
    err = cyg_fs_set_attrib( "/foo", 0 );
    if( err < 0 ) SHOW_RESULT( chmod none , err );

    // Verify it is now nothing
    checkattrib( "/foo", 0 );

    // Now delete our test file
    diag_printf("<INFO>: unlink /foo\n");
    err = unlink( "/foo" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

#endif // CYGCFG_FS_FAT_USE_ATTRIBUTES

    maxfile("file.max");

    listdir( "/", true, -1, NULL );    
        
    diag_printf("<INFO>: unlink file.max\n");    
    err = unlink( "file.max" );
    if( err < 0 ) SHOW_RESULT( unlink, err );    
    diag_printf("<INFO>: umount /\n");    
    err = umount( "/" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
    
    CYG_TEST_PASS_FINISH("fatfs1");
}
예제 #5
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can0_thread(cyg_addrword_t data)
{
    cyg_uint32             len;
    cyg_can_event          rx_event;
    cyg_can_remote_buf     rtr_buf;
    cyg_can_remote_buf     rtr_buf2;
    cyg_can_msgbuf_info    msgbox_info;
    cyg_can_mode           mode; 
    cyg_can_state          state;
    
    //
    // before we start configuring the CAN hardware we stop the chip
    //
    mode = CYGNUM_CAN_MODE_STOP;
    len = sizeof(mode);
    if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_MODE ,&mode, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    
    //
    // now check if FlexCAN modul is really stopped
    //
    len = sizeof(state);
    if (ENOERR != cyg_io_get_config(hDrvFlexCAN, CYG_IO_GET_CONFIG_CAN_STATE ,&state, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
    } 
    
    if (state != CYGNUM_CAN_STATE_STOPPED)
    {
        CYG_TEST_FAIL_FINISH("Error stopping FlexCAN /dev/can0");
    }

    //
    // We would like to setup 2 remote buffers - check if we have enough
    // free message buffers
    //
    len = sizeof(msgbox_info);
    if (ENOERR != cyg_io_get_config(hDrvFlexCAN, CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO ,&msgbox_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
    } 
    else
    {
        diag_printf("Message boxes available: %d    free: %d\n", 
                    msgbox_info.count, msgbox_info.free);
    }
    
    if (msgbox_info.free < 2)
    {
        CYG_TEST_FAIL_FINISH("Not enough free message buffers/dev/can0");
    }

   
    //
    // Setup the first remote response buffer for resception of standard
    // remote frames
    //
    rtr_buf.cfg_id      = CYGNUM_CAN_MSGBUF_REMOTE_BUF_ADD;
    rtr_buf.msg.id      = 0x7FF;
    rtr_buf.msg.ext     = CYGNUM_CAN_ID_STD;
    rtr_buf.msg.rtr     = CYGNUM_CAN_FRAME_DATA;
    rtr_buf.msg.dlc     = 1;
    rtr_buf.msg.data[0] = 0xAB;
    
    len = sizeof(rtr_buf);
    if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_MSGBUF ,&rtr_buf, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    
    //
    // setup the second remote response buffer for reception of extended
    // remote frames
    // 
    rtr_buf2.cfg_id      = CYGNUM_CAN_MSGBUF_REMOTE_BUF_ADD;
    rtr_buf2.msg.id      = 0x800;
    rtr_buf2.msg.ext     = CYGNUM_CAN_ID_EXT;
    rtr_buf2.msg.rtr     = CYGNUM_CAN_FRAME_DATA;
    rtr_buf2.msg.dlc     = 4;
    rtr_buf2.msg.data[0] = 0xAB;
    
    len = sizeof(rtr_buf2);
    if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_MSGBUF ,&rtr_buf2, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    
    if (rtr_buf.handle == CYGNUM_CAN_MSGBUF_NA)
    {
        CYG_TEST_FAIL_FINISH("No free message buffer available for /dev/can0");
    }
    
    //
    // now configuration is finished and we can start chip again
    //
    mode = CYGNUM_CAN_MODE_START;
    len = sizeof(mode);
    if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_MODE ,&mode, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    
    diag_printf("Test of FlexCAN remote response buffer configuration\n"
                "If a CAN node sends a remote request with ID 0x7FF\n"
                "or 0x800 then the FlexCAN modul should respond with\n"
                "data frames.\n");
    diag_printf("!!! This test can be stopped by sending a data frame with ID 0x100 !!!\n\n");
    
    len = sizeof(msgbox_info);
    if (ENOERR != cyg_io_get_config(hDrvFlexCAN, CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO ,&msgbox_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    else
    {
        diag_printf("Message boxes available: %d    free: %d\n", 
                    msgbox_info.count, msgbox_info.free);
    }
    
    while (1)
    {
        len = sizeof(rx_event); 
            
        if (ENOERR != cyg_io_read(hDrvFlexCAN, &rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
        }
        
        if (0x100 == rx_event.msg.id)
        {
            CYG_TEST_PASS_FINISH("flexcan_remote test OK"); 
        }
        else
        {
            print_can_flags(rx_event.flags, "");
            print_can_msg(&rx_event.msg, "");    
        }
    }

              
}
예제 #6
0
//===========================================================================
//                             WRITER THREAD 
//===========================================================================
void can0_thread(cyg_addrword_t data)
{
    cyg_io_handle_t    hCAN0;
    cyg_uint32         len;
    cyg_can_buf_info_t buf_info;
    cyg_uint16         i;
    cyg_can_event      rx_event;
    cyg_can_message    tx_msg =
    {
        0x000,                                               // CAN identifier
        {0x00, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7},    // 8 data bytes
        CYGNUM_CAN_ID_STD,                                   // standard frame
        CYGNUM_CAN_FRAME_DATA,                               // data frame
        4,                                                   // data length code
    };
   
    
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) 
    {
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
    }
    
    //
    // first we read the buffer info
    //
    len = sizeof(buf_info);
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
    }
    
    //
    // check if buffer is really empty
    //
    if (buf_info.rx_count != 0)
    {
        CYG_TEST_FAIL_FINISH("Receive buffer of /dev/can0 is not empty.");
    }
    
    //
    // now send messages - because TX events are supported each transmitted CAN message
    // will cause a TX event that is filled into receive queue
    //
    diag_printf("Sending %d CAN messages to /dev/can0 \n", buf_info.rx_bufsize);
    for (i = 0; i < buf_info.rx_bufsize; ++i)
    {
        tx_msg.id = i;
        tx_msg.data[0] = i;
        len = sizeof(tx_msg);
        
        if (ENOERR != cyg_io_write(hCAN0, &tx_msg, &len))
        {
            CYG_TEST_FAIL_FINISH("Error writing to /dev/can0");
        }
        else
        {
            print_can_msg(&tx_msg, "");
        }
    }
    
    //
    // now we read the buffer info - we expect a completely filled recieve queue
    //
    len = sizeof(buf_info);
    if (ENOERR != cyg_io_get_config(hCAN0, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&buf_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
    }
    
    //
    // if receive queue is not completely filled, then we have an error here
    //
    if (buf_info.rx_bufsize != buf_info.rx_count)
    {
        diag_printf("RX bufsize: %d    events in RX buffer: %d\n", buf_info.rx_bufsize, buf_info.rx_count);
        CYG_TEST_FAIL_FINISH("Receive queue of /dev/can0 not completely filled.");
    }
    
    //
    // now we read the receive queue
    //
    diag_printf("Receiving %d TX events from /dev/can0 \n", buf_info.rx_count);
    for (i = 0; i < buf_info.rx_count; ++i)
    {
        len = sizeof(rx_event);
        
        if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
        }
        
        //
        // we expect only a set TX flag because no other events may arrive for the
        // loopback driver
        //
        if (!(rx_event.flags & CYGNUM_CAN_EVENT_TX) || (rx_event.flags & !CYGNUM_CAN_EVENT_TX))
        {
            CYG_TEST_FAIL_FINISH("Unexpected receive event flags.");
        }
        
        //
        // Now check if TX events contain valid data - we know that the ID and the first
        // data byte contain the message number
        //
        if ((rx_event.msg.id != i) || (rx_event.msg.data[0] != i))
        {
            CYG_TEST_FAIL_FINISH("Received invalid data in TX event");
        }
        else
        {
            print_can_msg(&rx_event.msg, "");
        }     
    } // for (i = 0; i < buf_info.rx_count; ++i)
           
    CYG_TEST_PASS_FINISH("can_txevent test OK");                     
}
예제 #7
0
externC void
cyg_start( void )
{
    Cyg_ErrNo stat;
    cyg_io_handle_t flash_handle;
    cyg_io_flash_getconfig_erase_t e;
    cyg_io_flash_getconfig_devsize_t d;
    cyg_io_flash_getconfig_blocksize_t b;
    cyg_io_flash_getconfig_lock_t l;
    cyg_io_flash_getconfig_unlock_t u;
    CYG_ADDRWORD flash_start, flash_end;
    CYG_ADDRWORD flash_test_start, flash_addr;
    cyg_uint32 flash_block_size, flash_num_blocks;
    CYG_ADDRWORD test_buf1, test_buf2;
    cyg_uint32 *lp1, *lp2;
    int i, len;
    cyg_bool passed, ok;

    CYG_TEST_INIT();

    passed = true;

    if ((stat = cyg_io_lookup(FLASH_TEST_DEVICE, &flash_handle)) == -ENOENT) {
        stat = cyg_io_lookup(FLASH_TEST_DEVICE2, &flash_handle);
    }

    if (stat != 0) {
        diag_printf("FLASH: driver init failed: %s\n", strerror(-stat));
        CYG_TEST_FAIL_FINISH("FLASH driver init failed");
    }

    len = sizeof(d);
    stat = cyg_io_get_config( flash_handle, CYG_IO_GET_CONFIG_FLASH_DEVSIZE, &d, &len );
    flash_start = 0;
    // Keep 'end' address as last valid location, to avoid wrap around problems
    flash_end = d.dev_size - 1;

    len = sizeof(b);
    b.offset = 0;
    stat = cyg_io_get_config( flash_handle, CYG_IO_GET_CONFIG_FLASH_BLOCKSIZE, &b, &len );
    flash_block_size = b.block_size;
    flash_num_blocks = d.dev_size/flash_block_size;

    diag_printf("FLASH: %p - %p, %d blocks of 0x%x bytes each.\n", 
                (void*)flash_start, (void*)(flash_end + 1), flash_num_blocks, flash_block_size);

    // Verify that the testing limits are within the bounds of the
    // physical device.  Also verify that the size matches with
    // the erase block size on the device
    if ((FLASH_TEST_OFFSET > (flash_end - flash_start)) ||
        ((FLASH_TEST_OFFSET + FLASH_TEST_LENGTH) > (flash_end - flash_start))) {
        CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits");
    }
    if ((FLASH_TEST_LENGTH % flash_block_size) != 0) {
        CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size");
    }

    // Allocate two buffers large enough for the test
    test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1;
    test_buf2 = test_buf1 + FLASH_TEST_LENGTH;
    if (CYGMEM_SECTION_heap1_SIZE < (FLASH_TEST_LENGTH * 2)) {
        CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region");
    }
    diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2);
    flash_test_start = flash_start + FLASH_TEST_OFFSET;


#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
    // Unlock test
    diag_printf("... Unlock test\n");
    ok = true;
    u.offset = flash_test_start;
    u.len = FLASH_TEST_LENGTH;
    len = sizeof(u);
    if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_UNLOCK, &u, &len ) ) != 0 || u.flasherr != 0)
    {
        diag_printf("FLASH: unlock failed: %s %s\n", strerror(stat), cyg_flash_errmsg(u.flasherr));
        ok = false;
    }
#endif
    
    // Erase test
    diag_printf("... Erase test\n");
    ok = true;

    e.offset = flash_test_start;
    e.len = FLASH_TEST_LENGTH;
    len = sizeof(e);
    if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_ERASE, &e, &len ) ) != 0 || e.flasherr != 0)
    {
        diag_printf("FLASH: erase failed: %s %s\n", cyg_epcs_errmsg(stat), cyg_epcs_errmsg(e.flasherr));
        ok = false;
    }
    len = FLASH_TEST_LENGTH;
    if (ok && (stat = cyg_io_bread(flash_handle, (void *)test_buf1, &len, flash_test_start)) != 0)
    {
        diag_printf("FLASH: read/verify after erase failed: %s\n", cyg_epcs_errmsg(stat));
        ok = false;
    }    
    lp1 = (cyg_uint32 *)test_buf1;
    for (i = 0;  i < FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        if (*lp1++ != 0xFFFFFFFF) {
            diag_printf("FLASH: non-erased data found at offset %p\n", (void*)((CYG_ADDRWORD)(lp1-1) - test_buf1));
            diag_dump_buf((void *)(lp1-1), 32);
            ok = false;
            break;
        }
    }

    // Try reading in little pieces
    len = FLASH_TEST_LENGTH;
    flash_addr = flash_test_start;
    while (len > 0) {
        cyg_uint32 l = 0x200;
        if ((stat = cyg_io_bread(flash_handle, (void *)test_buf1, &l, flash_addr)) != CYG_FLASH_ERR_OK) {
            diag_printf("FLASH: read[short]/verify after erase failed: %s\n", strerror(stat));
            ok = false;
            break;
        }    
        flash_addr = flash_addr + l;
        len -= l;
        lp1 = (cyg_uint32 *)test_buf1;
        for (i = 0;  i < 0x200;  i += sizeof(cyg_uint32)) {
            if (*lp1++ != 0xFFFFFFFF) {
                diag_printf("FLASH: non-erased data found at offset %p\n", 
                            (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1));
                diag_dump_buf((void *)(lp1-1), 32);
                ok = false;
                len = 0;
                break;
            }
        }
    }
    
    if (!ok) {
        CYG_TEST_INFO("FLASH erase failed");
        passed = false;
    }

    // Simple write/verify test
    diag_printf("... Write/verify test\n");
    lp1 = (cyg_uint32 *)test_buf1;
    for (i = 0;  i < FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        *lp1 = (cyg_uint32)lp1;
        lp1++;
    }
    ok = true;
    len = FLASH_TEST_LENGTH;
    if (ok && (stat = cyg_io_bwrite(flash_handle, (void *)test_buf1,
                                    &len, flash_test_start)) != 0) {
        diag_printf("FLASH: write failed: %s\n", strerror(stat));
        ok = false;
    }


    len = FLASH_TEST_LENGTH;
    if (ok && (stat = cyg_io_bread(flash_handle,  (void *)test_buf2, &len, flash_test_start)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: read/verify after write failed: %s\n", strerror(stat));
        ok = false;
    }    
    lp1 = (cyg_uint32 *)test_buf1;
    lp2 = (cyg_uint32 *)test_buf2;
    for (i = 0;  i < FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        if (*lp2++ != *lp1++) {
            diag_printf("FLASH: incorrect data found at offset %p\n", (void *)((CYG_ADDRWORD)(lp2-1) - test_buf2));
            diag_dump_buf((void *)(lp2-1), 32);
            ok = false;
            break;
        }
    }

    // Try reading in little pieces
    len = FLASH_TEST_LENGTH;
    flash_addr = flash_test_start;
    lp1 = (cyg_uint32 *)test_buf1;
    lp2 = (cyg_uint32 *)test_buf2;
    while (len > 0) {
        cyg_uint32 l = 0x200;
        if ((stat = cyg_io_bread(flash_handle, (void *)lp2, &l, flash_addr)) != 0) {
            diag_printf("FLASH: read[short]/verify after erase failed: %s\n", strerror(stat));
            ok = false;
            break;
        }    
        flash_addr = flash_addr + l;
        len -= l;
        for (i = 0;  i < l;  i += sizeof(cyg_uint32)) {
            if (*lp2++ != *lp1++) {
                diag_printf("FLASH: incorrect data found at offset %p\n", 
                            (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2));
                diag_dump_buf((void *)(lp2-1), 32);
                ok = false;
                len = 0;
                break;
            }
        }
    }

#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
    // Lock test
    diag_printf("... Lock test\n");
    ok = true;
    l.offset = flash_test_start;
    l.len = FLASH_TEST_LENGTH;
    len = sizeof(l);
    if ((stat = cyg_io_get_config(flash_handle, CYG_IO_GET_CONFIG_FLASH_LOCK, &l, &len ) ) != 0 || l.flasherr != 0 )
    {
        diag_printf("FLASH: unlock failed: %s %s\n", strerror(stat), cyg_flash_errmsg(l.flasherr));
        ok = false;
    }
#endif
    
    if (!ok) {
        CYG_TEST_INFO("FLASH write/verify failed");
    }

    if (passed) {
        CYG_TEST_PASS_FINISH("FLASH test1");
    } else {
        CYG_TEST_FAIL_FINISH("FLASH test1");
    }
}
예제 #8
0
void
pci_test( void )
{
    cyg_pci_device dev_info;
    CYG_PCI_ADDRESS64 mem_base;
    CYG_PCI_ADDRESS64 mem_assigned_addr;
    CYG_PCI_ADDRESS32 io_base;
    CYG_PCI_ADDRESS32 io_assigned_addr;

    // Verify that space type requests are checked.
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO;
    CYG_TEST_CHECK(!cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv accepted IO request");
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM;
    CYG_TEST_CHECK(!cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                   &io_assigned_addr),
                   "cyg_pci_allocate_io_priv accepted MEM request");

    // Check allocation and alignment of IO space
    io_base = 0x0000;
    // Size 4
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffffc;
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                                            &io_assigned_addr),
                   "cyg_pci_allocate_io_priv(4) failed");
    CYG_TEST_CHECK(0x0004 == io_base,
                   "cyg_pci_allocate_io_priv(4) size failed");
    CYG_TEST_CHECK(0x0000 == io_assigned_addr,
                   "cyg_pci_allocate_io_priv(4) align failed");
    // Size 8 (alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffff8;
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                                            &io_assigned_addr),
                   "cyg_pci_allocate_io_priv(8) failed");
    CYG_TEST_CHECK(0x0010 == io_base,
                   "cyg_pci_allocate_io_priv(8) size failed");
    CYG_TEST_CHECK(0x0008 == io_assigned_addr,
                   "cyg_pci_allocate_io_priv(8) align failed");
    // Size 16 (no alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xfffffff0;
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                                            &io_assigned_addr),
                   "cyg_pci_allocate_io_priv(16) failed");
    CYG_TEST_CHECK(0x0020 == io_base,
                   "cyg_pci_allocate_io_priv(16) size failed");
    CYG_TEST_CHECK(0x0010 == io_assigned_addr,
                   "cyg_pci_allocate_io_priv(16) align failed");
    // Size 64 (alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xffffffc0;
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                                            &io_assigned_addr),
                   "cyg_pci_allocate_io_priv(64) failed");
    CYG_TEST_CHECK(0x0080 == io_base,
                   "cyg_pci_allocate_io_priv(64) size failed");
    CYG_TEST_CHECK(0x0040 == io_assigned_addr,
                   "cyg_pci_allocate_io_priv(64) align failed");
    // Size 256 (alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_IO | 0xffffff00;
    CYG_TEST_CHECK(cyg_pci_allocate_io_priv(&dev_info, 0, &io_base,
                                            &io_assigned_addr),
                   "cyg_pci_allocate_io_priv(256) failed");
    CYG_TEST_CHECK(0x0200 == io_base,
                   "cyg_pci_allocate_io_priv(256) size failed");
    CYG_TEST_CHECK(0x0100 == io_assigned_addr,
                   "cyg_pci_allocate_io_priv(256) align failed");

    // Check allocation and alignment of MEM space
    mem_base = 0x00000000;
    // Size 16 (no alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xfffffff0;
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv(16) failed");
    CYG_TEST_CHECK(0x00000010 == mem_base,
                   "cyg_pci_allocate_memory_priv(16) size failed");
    CYG_TEST_CHECK(0x00000000 == mem_assigned_addr,
                   "cyg_pci_allocate_memory_priv(16) align failed");
    // Size 64 (alignment required - <1MB)
    dev_info.base_size[0] = (CYG_PCI_CFG_BAR_SPACE_MEM
                             | CYG_PRI_CFG_BAR_MEM_TYPE_1M
                             | 0xffffffc0);
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv(64/<1MB) failed");
    CYG_TEST_CHECK(0x00000080 == mem_base,
                   "cyg_pci_allocate_memory_priv(64/<1MB) size failed");
    CYG_TEST_CHECK(0x00000040 == mem_assigned_addr,
                   "cyg_pci_allocate_memory_priv(64/<1MB) align failed");
    // Size 1MB (alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xfff00000;
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv(1MB) failed");
    CYG_TEST_CHECK(0x00200000 == mem_base,
                   "cyg_pci_allocate_memory_priv(1MB) size failed");
    CYG_TEST_CHECK(0x00100000 == mem_assigned_addr,
                   "cyg_pci_allocate_memory_priv(1MB) align failed");
    // Size 16MB (alignment required)
    dev_info.base_size[0] = CYG_PCI_CFG_BAR_SPACE_MEM | 0xff000000;
    CYG_TEST_CHECK(cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv(16MB) failed");
    CYG_TEST_CHECK(0x02000000 == mem_base,
                   "cyg_pci_allocate_memory_priv(16MB) size failed");
    CYG_TEST_CHECK(0x01000000 == mem_assigned_addr,
                   "cyg_pci_allocate_memory_priv(16MB) align failed");
    // Size 32 (no alignment required - <1MB - FAILS!)
    // Note: When more clever allocation has been made for the bottom
    // 1MB of PCI memory space, this test needs to be made more elaborate.
    dev_info.base_size[0] = (CYG_PCI_CFG_BAR_SPACE_MEM
                             | CYG_PRI_CFG_BAR_MEM_TYPE_1M
                             | 0xffffffe0);
    CYG_TEST_CHECK(!cyg_pci_allocate_memory_priv(&dev_info, 0, &mem_base,
                   &mem_assigned_addr),
                   "cyg_pci_allocate_memory_priv(32/<1MB) unexpectedly worked!");

    // TBD: Check 64bit MEM allocation.

    CYG_TEST_PASS_FINISH("pci2 test OK");
}
예제 #9
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can_thread(cyg_addrword_t data)
{
    cyg_uint32              len;
    cyg_can_message         tx_msg;
    cyg_can_info_t          can_info;
    cyg_can_baud_rate_t     baud;
    cyg_uint8               i = 0;
    cyg_uint8               j = 0;

    //
    // Check that all cannels have the same baudrate
    //
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN0
    len = sizeof(can_info);
    if (ENOERR != cyg_io_get_config(hCAN_Tbl[0], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 0");    
    } 
    else
    {
        baud = can_info.baud;
        ++i;
    }
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN1
    len = sizeof(can_info);
    if (ENOERR != cyg_io_get_config(hCAN_Tbl[1], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 1");    
    }
    else
    {
        if (i && (baud != can_info.baud))
        {
            CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 0 and 1");               
        }
        baud = can_info.baud;
        ++i;
    }
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN2
    len = sizeof(can_info);
    if (ENOERR != cyg_io_get_config(hCAN_Tbl[2], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 2");    
    } 
    else
    {
        if (i && (baud != can_info.baud))
        {
            CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 1 and 2");               
        }
        baud = can_info.baud;
        ++i;
    }
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN3
    len = sizeof(can_info);
    if (ENOERR != cyg_io_get_config(hCAN_Tbl[3], CYG_IO_GET_CONFIG_CAN_INFO, &can_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading baudrate of CAN channel 3");    
    }
    else
    {
        if (i && (baud != can_info.baud))
        {
            CYG_TEST_FAIL_FINISH("Error - different baudrates for CAN channel 2 and 3");               
        }
        baud = can_info.baud;
        ++i;
    }
#endif
    
    diag_printf("\n\nYou should no receive 4 CAN messages from each active CAN channel\n");
    
    //
    // Now each CAN channel sends 10 CAN messages
    //
    for (i = 0; i < 4; ++i)
    {
        if (hCAN_Tbl[i])
        {
            CYG_CAN_MSG_SET_PARAM(tx_msg, i * 0x100, CYGNUM_CAN_ID_STD, 4, CYGNUM_CAN_FRAME_DATA);
            tx_msg.data.dwords[0] = 0;
            tx_msg.data.dwords[1] = 0;
            char err_msg[64];
            diag_snprintf(err_msg, sizeof(err_msg), "Error sending TX using CAN channel %d", i);
            for (j = 0; j < 4; ++j)
            {
                tx_msg.id = i * 0x100 + j; 
                tx_msg.data.bytes[0] = j;
                len = sizeof(tx_msg);
                if (ENOERR != cyg_io_write(hCAN_Tbl[i], &tx_msg, &len))
                {
                    CYG_TEST_FAIL_FINISH(err_msg);     
                }
            }
        } //  if (hCAN_Tbl[i])
    } // for (i = 0; i < 4; ++i)
    
    CYG_TEST_PASS_FINISH("LPC2xxx CAN multi channel TX test OK");
}
예제 #10
0
파일: signal3.c 프로젝트: KarenHung/ecosgit
int main (int argc, char **argv)
{
    int ret_val;
    sigset_t set;
    int sig;
    struct itimerspec timerValue;	// Timeout value on eCos
    timer_t timer1;			// Timer
    struct sigevent sev;

    CYG_TEST_INIT();

    {
        struct sigaction sa;

        sa.sa_handler = sigusr1;
        sigfillset( &sa.sa_mask );
        sa.sa_flags = 0;

        ret_val = sigaction( SIGUSR1, &sa, NULL );

        CYG_TEST_CHECK( ret_val == 0 , "sigaction returned error");
    }
    
    // unblock all the signals
    sigfillset (&set);
    pthread_sigmask (SIG_UNBLOCK, &set, (sigset_t*)NULL);
    
    //--------------------------------------------------------------------
    // <start of timer initialization section>
    //--------------------------------------------------------------------
	
    // Notification type --- Deliver the signal
    sev.sigev_notify                = SIGEV_SIGNAL;
    sev.sigev_signo                 = SIGUSR1;
    sev.sigev_value.sival_int       = 0xABCDEF01;
	
    // Timer values	--- 1 Second
    timerValue.it_value.tv_sec           = 1;
    timerValue.it_value.tv_nsec          = 0;
    timerValue.it_interval.tv_sec        = 1;
    timerValue.it_interval.tv_nsec       = 0;
	
    ret_val = timer_create (CLOCK_REALTIME, &sev, &timer1);

    CYG_TEST_CHECK( ret_val==0, "Error in creating the timer");

    ret_val = timer_settime (timer1, 0, &timerValue, NULL );
    CYG_TEST_CHECK( ret_val==0,"Error in setting the time");

    //--------------------------------------------------------------------
    // <end of timer initialization section>
    //--------------------------------------------------------------------

    CYG_TEST_INFO ("Timer initialisation is completed..");

    CYG_TEST_INFO ("Calling pause()");
    ret_val = pause();
    CYG_TEST_CHECK( ret_val==-1, "pause() did not return -1");
    CYG_TEST_CHECK( EINTR==errno, "errno set to EINTR");
    CYG_TEST_CHECK( sigusr1_called==1, "Siguser1 handler not called");
    
    // Block all the signals
    sigfillset (&set);
    pthread_sigmask (SIG_BLOCK, &set, (sigset_t*)NULL);

    CYG_TEST_INFO ("Calling sigwait()");    
    // Wait for any signal to arrive
    sigfillset (&set);
    ret_val = sigwait (&set, &sig);

    CYG_TEST_CHECK( ret_val==0, "sigwait returned error");
    CYG_TEST_CHECK( sig==SIGUSR1, "sigwait returned wrong signo!");
    CYG_TEST_CHECK( sigusr1_called==1, "Siguser1 handler called!");
    
    CYG_TEST_INFO ("Program terminating");

    CYG_TEST_PASS_FINISH( "signal3" );
    return 0;
}
예제 #11
0
int main(int argc, char **argv)
{
    int ret;
    sigset_t mask;
    pthread_attr_t attr;
    void *retval;
    union sigval value;
    
    CYG_TEST_INIT();

    // Make a full signal set
    sigfillset( &mask );

    
    // Install signal handlers
    {
        struct sigaction sa;

        sa.sa_handler = sigusr2;
        sa.sa_mask = mask;
        sa.sa_flags = 0;

        ret = sigaction( SIGUSR2, &sa, NULL );

        CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
    }

    {
        struct sigaction sa;

        sa.sa_handler = sigalrm;
        sa.sa_mask = mask;
        sa.sa_flags = 0;

        ret = sigaction( SIGALRM, &sa, NULL );

        CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
    }
    
    
    // Mask all signals
    pthread_sigmask( SIG_SETMASK, &mask, NULL );
    
    sem_init( &sem, 0, 0 );
    
    // Create test thread
    pthread_attr_init( &attr );

    pthread_attr_setstackaddr( &attr, (void *)&thread_stack[sizeof(thread_stack)] );
    pthread_attr_setstacksize( &attr, sizeof(thread_stack) );

    pthread_create( &thread1,
                    &attr,
                    pthread_entry1,
                    (void *)0x12345678);

    // Wait for other thread to get started
    CYG_TEST_INFO( "Main: calling sem_wait()");
    sem_wait( &sem );

    value.sival_int = 0;

    // send a signal to the other thread
    CYG_TEST_INFO( "Main: calling sigqueue(SIGUSR1)");
    sigqueue( 0, SIGUSR1, value );

    // Send the signal via kill
    CYG_TEST_INFO( "Main: calling kill(0, SIGUSR2)");
    kill( 0, SIGUSR2 );

    // Wait for thread1 to call pause()
    CYG_TEST_INFO( "Main: calling sleep(1)");
    sleep(1);

    // And again
    CYG_TEST_INFO( "Main: calling kill(0, SIGUSR2)");
    kill( 0, SIGUSR2 );

    // Set up an alarm for 1 second hence
    CYG_TEST_INFO( "Main: calling alarm(1)");
    alarm(1);
    
    // Wait for alarm signal to be delivered to thread1
    CYG_TEST_INFO( "Main: calling sleep(2)");
    sleep(2);
    
    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join()");
    pthread_join( thread1, &retval );

    CYG_TEST_CHECK( sigusr2_called == 2, "SIGUSR2 signal handler not called twice" );

    CYG_TEST_CHECK( sigalrm_called == 1, "SIGALRM signal handler not called" );    
    
    // check retval
    
    if( (long)retval == 0x12345678+SIGUSR1 )
        CYG_TEST_PASS_FINISH( "signal1" );
    else
        CYG_TEST_FAIL_FINISH( "signal1" );
}
예제 #12
0
int main( int argc, char **argv )
{
    int err;
    char address[16];
#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    struct cyg_fs_block_usage usage;
#endif

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    diag_printf("<INFO>: ROMFS root follows\n");
    listdir( "/", true );

    diag_printf("<INFO>: cd /etc\n" );
    err = chdir( "/etc" );
    if ( err < 0 ) {
        SHOW_RESULT( chdir, err );
        CYG_TEST_FAIL_FINISH("romfs1");
    }

    diag_printf("<INFO>: ROMFS list of '' follows\n");
    listdir( "", true );

    diag_printf("<INFO>: ROMFS list of /etc follows\n");
    listdir( "/etc", true );

    diag_printf("<INFO>: ROMFS list of . follows\n");
    listdir( ".", true );
    
#ifdef CYGPKG_FS_RAM
    err = mount( "", "/var", "ramfs" );
    if( err < 0 ) SHOW_RESULT( mount, err );

    copyfile( "/etc/passwd", "/var/passwd_copy" );

    comparefiles( "/etc/passwd", "/var/passwd_copy" );
#endif
    
    diag_printf("<INFO>: ROMFS list of / follows\n");
#ifdef CYGPKG_FS_RAM
    diag_printf("<INFO>: Note that /var now gives stat() info for RAMFS\n");
#endif
    listdir( "/", true );

    diag_printf("<INFO>: Mount ROMFS again onto /mnt\n");
    sprintf( address, "%p", (void*)&filedata[0] );
    err = mount( address, "/mnt", "romfs" );
    if( err < 0 ) SHOW_RESULT( mount, err );    

    comparefiles( "/etc/passwd", "/mnt/etc/passwd" );


    err = mkdir( "/foo", 0 );
    CHKFAIL_TYPE( mkdir, err, EROFS );

    err = rename( "/var", "/tmp" );	// RAMFS is mounted here
#ifdef CYGPKG_FS_RAM
    CHKFAIL_TYPE( rename, err, EXDEV );
#else
    CHKFAIL_TYPE( rename, err, EROFS );
#endif

    err = rename( "/var/passwd_copy", "/mnt/etc/passwd_copy" );
    CHKFAIL_TYPE( rename, err, EXDEV );

    err = rename( "/etc", "/tmp" );
    CHKFAIL_TYPE( rename, err, EROFS );

    diag_printf("<INFO>: cd /etc\n");
    err = chdir( "/etc" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = chdir( "/mnt/etc" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    listdir( ".", true );

    diag_printf("<INFO>: unlink /tmp\n");        
    err = unlink( "/tmp" );
    CHKFAIL_TYPE( unlink, err, EROFS );

    diag_printf("<INFO>: mount random area\n");
    sprintf(address, "%p", (void*)(&filedata[0] + 0x100));
    err = mount( address, "/tmp", "romfs" );
    CHKFAIL_TYPE( mount, err, ENOENT );

    err = umount( "/mnt" );
    if( err < 0 ) SHOW_RESULT( umount, err );    

    err = umount( "/var" );
#ifdef CYGPKG_FS_RAM
    if( err < 0 ) SHOW_RESULT( umount, err );    
#else
    CHKFAIL_TYPE( umount, err, EINVAL );
#endif

#if defined(CYGSEM_FILEIO_BLOCK_USAGE)
    err = cyg_fs_getinfo("/", FS_INFO_BLOCK_USAGE, &usage, sizeof(usage));
    if( err < 0 ) SHOW_RESULT( cyg_fs_getinfo, err );
    diag_printf("<INFO>: total size: %6lld blocks, %10lld bytes\n",
		usage.total_blocks, usage.total_blocks * usage.block_size); 
    diag_printf("<INFO>: free size:  %6lld blocks, %10lld bytes\n",
		usage.free_blocks, usage.free_blocks * usage.block_size); 
    diag_printf("<INFO>: block size: %6u bytes\n", usage.block_size);
#endif
    // --------------------------------------------------------------

    err = umount( "/" );
    if( err < 0 ) SHOW_RESULT( umount, err );    


    CYG_TEST_PASS_FINISH("romfs1");
}
예제 #13
0
파일: console.c 프로젝트: LucidOne/Rovio
void
console_test( CYG_ADDRWORD x )
{
    Cyg_ErrNo res;
    cyg_io_handle_t handle;
    char msg[] = "This is a test\n";
    int msglen = sizeof(msg)-1;
    char in_msg[80];
    int in_msglen = sizeof(in_msg)-1;
    cyg_serial_info_t serial_info;
    cyg_tty_info_t tty_info;
    char short_msg[] = "This is a short message\n";
    char long_msg[] = "This is a longer message 0123456789abcdefghijklmnopqrstuvwxyz\n";
    char filler[] = "          ";
    char prompt[] = "\nPlease enter some data: ";
    int i, len;

    res = cyg_io_lookup(CYGDAT_IO_SERIAL_TTY_CONSOLE, &handle);
    if (res != ENOERR) {
        diag_printf("Can't lookup - DEVIO error: %d\n", res);
        return;
    }
    len = sizeof(serial_info);
    res = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_SERIAL_INFO, &serial_info, &len);
    if (res != ENOERR) {
        diag_printf("Can't get serial config - DEVIO error: %d\n", res);
hang();
        return;
    }
    len = sizeof(tty_info);
    res = cyg_io_get_config(handle, CYG_IO_GET_CONFIG_TTY_INFO, &tty_info, &len);
    if (res != ENOERR) {
        diag_printf("Can't get tty config - DEVIO error: %d\n", res);
hang();
        return;
    }
    diag_printf("Config - baud: %d, stop: %d, parity: %d, out flags: %x, in flags: %x\n", 
                serial_info.baud, serial_info.stop, serial_info.parity,
                tty_info.tty_out_flags, tty_info.tty_in_flags);
    len = sizeof(serial_info);
    res = cyg_io_set_config(handle, CYG_IO_SET_CONFIG_SERIAL_INFO, &serial_info, &len);
    if (res != ENOERR) {
        diag_printf("Can't set serial config - DEVIO error: %d\n", res);
hang();
        return;
    }
    len = sizeof(tty_info);
    res = cyg_io_set_config(handle, CYG_IO_SET_CONFIG_TTY_INFO, &tty_info, &len);
    if (res != ENOERR) {
        diag_printf("Can't set tty config - DEVIO error: %d\n", res);
hang();
        return;
    }
    msglen = strlen(msg);
    res = cyg_io_write(handle, msg, &msglen);
    if (res != ENOERR) {
        diag_printf("Can't write data - DEVIO error: %d\n", res);
hang();
        return;
    }
    for (i = 0;  i < 10;  i++) {
        len = strlen(short_msg);
        res = cyg_io_write(handle, short_msg, &len);
        if (res != ENOERR) {
            diag_printf("Can't write [short] data - DEVIO error: %d\n", res);
            hang();
            return;
        }
    }
    for (i = 0;  i < 100;  i++) {
        len = (i % 10) + 1;
        cyg_io_write(handle, filler, &len);
        len = strlen(long_msg);
        res = cyg_io_write(handle, long_msg, &len);
        if (res != ENOERR) {
            diag_printf("Can't write [long] data - DEVIO error: %d\n", res);
            hang();
            return;
        }
    }
    len = strlen(prompt);
    cyg_io_write(handle, prompt, &len);
    res = cyg_io_read(handle, in_msg, &in_msglen);
    if (res != ENOERR) {
        diag_printf("Can't read data - DEVIO error: %d\n", res);
hang();
        return;
    }
    diag_printf("Read %d bytes\n", in_msglen);
    dump_buf(in_msg, in_msglen);
    CYG_TEST_PASS_FINISH("Console I/O test OK");
}
예제 #14
0
void kintr0_main( void )
{
    cyg_vector_t v = (CYGNUM_HAL_VSR_MIN + 11) % CYGNUM_HAL_VSR_COUNT;
    cyg_vector_t v1;
    cyg_vector_t lvl1 = CYGNUM_HAL_ISR_MIN + (1 % CYGNUM_HAL_ISR_COUNT);
    cyg_vector_t lvl2 = CYGNUM_HAL_ISR_MIN + (15 % CYGNUM_HAL_ISR_COUNT);
    int in_use;

    cyg_VSR_t *old_vsr, *new_vsr;

    CYG_TEST_INIT();
 
#ifdef CYGPKG_HAL_MIPS_TX39    
    // This can be removed when PR 17831 is fixed
    if ( cyg_test_is_simulator )
        v1 = 12 % CYGNUM_HAL_ISR_COUNT;
    else /* NOTE TRAILING ELSE... */
#endif
    v1 = CYGNUM_HAL_ISR_MIN + ( 6 % CYGNUM_HAL_ISR_COUNT);

    CHECK(flash());
    CHECK(flash());

    // Make sure the chosen levels are not already in use.
    HAL_INTERRUPT_IN_USE( lvl1, in_use );
    intr0 = 0;
    if (!in_use)
        cyg_interrupt_create(lvl1, 1, (cyg_addrword_t)777, isr0, dsr0, 
                             &intr0, &intr_obj[0]);
    
    HAL_INTERRUPT_IN_USE( lvl2, in_use );
    intr1 = 0;
    if (!in_use && lvl1 != lvl2)
        cyg_interrupt_create(lvl2, 1, 888, isr1, dsr1, &intr1, &intr_obj[1]);

    // Check these functions at least exist

    cyg_interrupt_disable();
    cyg_interrupt_enable();

    if (intr0)
        cyg_interrupt_attach(intr0);
    if (intr1)
        cyg_interrupt_attach(intr1);
    if (intr0)
        cyg_interrupt_detach(intr0);
    if (intr1)
        cyg_interrupt_detach(intr1);

    // If this attaching interrupt replaces the previous interrupt
    // instead of adding to it we could be in a big mess if the
    // vector is being used by something important.
        
    cyg_interrupt_get_vsr( v, &old_vsr );
    cyg_interrupt_set_vsr( v, vsr0 );
    cyg_interrupt_get_vsr( v, &new_vsr );
    CHECK( vsr0 == new_vsr );

    new_vsr = NULL;
    cyg_interrupt_get_vsr( v, &new_vsr );
    cyg_interrupt_set_vsr( v, old_vsr );
    CHECK( new_vsr == vsr0 );

    cyg_interrupt_set_vsr( v, new_vsr );
    new_vsr = NULL;
    cyg_interrupt_get_vsr( v, &new_vsr );       
    CHECK( vsr0 == new_vsr );

    cyg_interrupt_set_vsr( v, old_vsr );
    CHECK( vsr0 == new_vsr );
    new_vsr = NULL;
    cyg_interrupt_get_vsr( v, &new_vsr );
    CHECK( old_vsr == new_vsr );
        
    CHECK( NULL != vsr0 );

    cyg_interrupt_mask(v1);
    cyg_interrupt_unmask(v1);
        
    cyg_interrupt_configure(v1, true, true);

    CYG_TEST_PASS_FINISH("Kernel C API Intr 0 OK");
}
예제 #15
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can0_thread(cyg_addrword_t data)
{
    cyg_uint32             len;
    cyg_can_event          rx_event1;
    cyg_can_event          rx_event2;
    cyg_can_msgbuf_info    msgbox_info;
    cyg_can_mode           mode; 
    cyg_can_state          state;
    
   
    diag_printf("Test of FlexCAN standby mode with selfwakeup\n"
                "As soon as a message arrives the FlexCAN modul\n"
                "will leave standby and generates a leave standby event.\n"
                "Each time you send a message you should see LSTY first\n"
                "for \"leaving standby\" and then \"RX\" for the\n"
                "RX event that caused the leave standby event. You can send\n"
                "a CAN data frame with any ID\n");
                
    diag_printf("!!! This test can be stopped by sending a data frame with ID 0x100 !!!\n\n");
    
    len = sizeof(msgbox_info);
    if (ENOERR != cyg_io_get_config(hDrvFlexCAN, CYG_IO_GET_CONFIG_CAN_MSGBUF_INFO ,&msgbox_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    } 
    else
    {
        diag_printf("Message boxes available: %d    free: %d\n", 
                    msgbox_info.count, msgbox_info.free);
    }
    
    while (1)
    {
       //
       // now we set FlexCAN into standby mode
       //
       mode = CYGNUM_CAN_MODE_STANDBY;
       len = sizeof(mode);
       if (ENOERR != cyg_io_set_config(hDrvFlexCAN, CYG_IO_SET_CONFIG_CAN_MODE ,&mode, &len))
       {
           CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
       } 
    
       //
       // now check if FlexCAN modul is really in standby mode
       //
       len = sizeof(state);
       if (ENOERR != cyg_io_get_config(hDrvFlexCAN, CYG_IO_GET_CONFIG_CAN_STATE ,&state, &len))
       {
           CYG_TEST_FAIL_FINISH("Error reading config of /dev/can0");
       } 
    
   
       if (state != CYGNUM_CAN_STATE_STANDBY)
       {
           CYG_TEST_FAIL_FINISH("Error stopping FlexCAN /dev/can0");
       }
       
       //
       // as soon as a message arrives the FlexCAN modul leaves standby mode
       // and we should receive a CYGNUM_CAN_EVENT_LEAVING_STANDBY event but
       // we will also receive a RX event because a message arrived
       // 
       len = sizeof(rx_event1);      
       if (ENOERR != cyg_io_read(hDrvFlexCAN, &rx_event1, &len))
       {
           CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
       }
       
       len = sizeof(rx_event2);      
       if (ENOERR != cyg_io_read(hDrvFlexCAN, &rx_event2, &len))
       {
           CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
       }
       
       print_can_flags(rx_event1.flags, "");
       print_can_flags(rx_event2.flags, "");
       
       //
       // The first event we receive should be a leaving standby event because
       // first flexcan leaves standby and then a message will be received
       // 
       if (!(rx_event1.flags & CYGNUM_CAN_EVENT_LEAVING_STANDBY))
       {
           CYG_TEST_FAIL_FINISH("CYGNUM_CAN_EVENT_LEAVING_STANDBY event expexted /dev/can0");
       }
       
       if (rx_event2.msg.id == 0x100)
       {
           CYG_TEST_PASS_FINISH("flexcan_wake test OK");
       }
    }              
}
예제 #16
0
파일: fileio1.c 프로젝트: berte/mediaplayer
int main( int argc, char **argv )
{
    int err;
    //int i;
    int existingdirents=-1;

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/", "jffs3" );
    if( err < 0 ) SHOW_RESULT( mount, err );    

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    listdir( "/", true, -1, &existingdirents );
    if ( existingdirents < 2 )
        CYG_TEST_FAIL("Not enough dir entries\n");

    // --------------------------------------------------------------

    createfile( "/foo", 202 );
    checkfile( "foo" );
    copyfile( "foo", "fee");
    checkfile( "fee" );
    comparefiles( "foo", "/fee" );
    diag_printf("<INFO>: mkdir bar\n");
    err = mkdir( "/bar", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/" , true, existingdirents+3, NULL );

    copyfile( "fee", "/bar/fum" );
    checkfile( "bar/fum" );
    comparefiles( "/fee", "bar/fum" );

    diag_printf("<INFO>: cd bar\n");
    err = chdir( "bar" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/bar" );
    
    diag_printf("<INFO>: rename /foo bundy\n");    
    err = rename( "/foo", "bundy" );
    if( err < 0 ) SHOW_RESULT( rename, err );
    
    listdir( "/", true, existingdirents+2, NULL );
    listdir( "" , true, 4, NULL );

    checkfile( "/bar/bundy" );
    comparefiles("/fee", "bundy" );

    // --------------------------------------------------------------

    createfile( LONGNAME1, 123 );
    checkfile( LONGNAME1 );
    copyfile( LONGNAME1, LONGNAME2 );

    listdir( "", false, 6, NULL );
    
    diag_printf("<INFO>: unlink " LONGNAME1 "\n");    
    err = unlink( LONGNAME1 );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink " LONGNAME2 "\n");    
    err = unlink( LONGNAME2 );
    if( err < 0 ) SHOW_RESULT( unlink, err );
    
    
    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink fee\n");    
    err = unlink( "/fee" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink fum\n");        
    err = unlink( "fum" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink /bar/bundy\n");        
    err = unlink( "/bar/bundy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");        
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/" );
    
    diag_printf("<INFO>: rmdir /bar\n");        
    err = rmdir( "/bar" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    listdir( "/", false, existingdirents, NULL );

    // --------------------------------------------------------------

    diag_printf("<INFO>: mount /jffs3 \n");
    err = mount( CYGDAT_IO_FLASH_BLOCK_DEVICE_NAME_1, "/jffs3", "jffs3" );
    if( err < 0 ) SHOW_RESULT( mount, err );    

    createfile( "/jffs3/tinky", 456 );
    copyfile( "/jffs3/tinky", "/jffs3/laalaa" );
    checkfile( "/jffs3/tinky");
    checkfile( "/jffs3/laalaa");
    comparefiles( "/jffs3/tinky", "/jffs3/laalaa" );

    diag_printf("<INFO>: cd /jffs3\n");    
    err = chdir( "/jffs3" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/jffs3" );
        
    diag_printf("<INFO>: mkdir noonoo\n");    
    err = mkdir( "noonoo", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "." , true, existingdirents+3, NULL);

    diag_printf("<INFO>: cd noonoo\n");
    err = chdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    checkcwd( "/jffs3/noonoo" );
    
    createfile( "tinky", 678 );
    checkfile( "tinky" );

    createfile( "dipsy", 3456 );
    checkfile( "dipsy" );
    copyfile( "dipsy", "po" );
    checkfile( "po" );
    comparefiles( "dipsy", "po" );


    /*for(i=0;i<2048;i++) {
        diag_printf("<INFO>: churningchurningchurning................................ITERATION = %d\n", i);    
        createfile( "churningchurningchurning", 4096 );
        diag_printf("<INFO>: unlink churningchurningchurning\n");    
        err = unlink( "churningchurningchurning" );
        if( err < 0 ) SHOW_RESULT( unlink, err );
    }*/


    listdir( ".", true, 5, NULL );
    listdir( "", true, 5, NULL );
    listdir( "..", true, existingdirents+3, NULL );

    // --------------------------------------------------------------

    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink dipsy\n");    
    err = unlink( "dipsy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink po\n");    
    err = unlink( "po" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd ..\n"); 
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3" );
    
    diag_printf("<INFO>: rmdir noonoo\n"); 
    err = rmdir( "noonoo" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    // --------------------------------------------------------------

    err = mkdir( "x", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    err = mkdir( "x/y/z", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    err = mkdir( "x/y/z/w", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );
    
    diag_printf("<INFO>: cd /jffs3/x/y/z/w\n");
    err = chdir( "/jffs3/x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3/x/y/z/w" );

    diag_printf("<INFO>: cd ..\n");
    err = chdir( ".." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3/x/y/z" );
    
    diag_printf("<INFO>: cd .\n");
    err = chdir( "." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3/x/y/z" );

    diag_printf("<INFO>: cd ../../y\n");
    err = chdir( "../../y" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3/x/y" );

    diag_printf("<INFO>: cd ../..\n");
    err = chdir( "../.." );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/jffs3" );

    diag_printf("<INFO>: rmdir x/y/z/w\n"); 
    err = rmdir( "x/y/z/w" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y/z\n"); 
    err = rmdir( "x/y/z" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x/y\n"); 
    err = rmdir( "x/y" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    diag_printf("<INFO>: rmdir x\n"); 
    err = rmdir( "x" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );
    
    // --------------------------------------------------------------
    
    diag_printf("<INFO>: unlink tinky\n");    
    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: unlink laalaa\n");    
    err = unlink( "laalaa" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    diag_printf("<INFO>: cd /\n");    
    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );
    checkcwd( "/" );
    
    diag_printf("<INFO>: umount /jffs3\n");    
    err = umount( "/jffs3" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
    
    diag_printf("<INFO>: umount /\n");    
    err = umount( "/" );
    if( err < 0 ) SHOW_RESULT( umount, err );    
    
    CYG_TEST_PASS_FINISH("fileio1");
}
예제 #17
0
//===========================================================================
// Thread 0
//===========================================================================
void can_rx_thread(cyg_addrword_t data)
{
    cyg_uint32    len;
    cyg_can_event rx_event;
    cyg_can_event loop_rx_event;
    cyg_uint32    msg_cnt = 0;
    cyg_uint8     i;

    while (msg_cnt < 0xF0)
    {
        
        //
        // First receive CAN event from real CAN hardware
        //
        len = sizeof(rx_event);
        if (ENOERR != cyg_io_read(hCAN_Tbl[1], &rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from channel 1");   
        }
        
        if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
        {
            print_can_msg(&rx_event.msg, "RX chan 1:");
        } // if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
        else
        {
            print_can_flags(rx_event.flags, "");    
        }
        
        //
        // Now receive CAN event from loop CAN driver
        //
        len = sizeof(loop_rx_event);
        if (ENOERR != cyg_io_read(hLoopCAN_Tbl[1], &loop_rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from loop channel 1");   
        }
        
        if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
        {
            print_can_msg(&rx_event.msg, "RX loop 1:");
        } // if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
        else
        {
            print_can_flags(rx_event.flags, "");    
        }   
        
        //
        // Chaeck message ID and DLC of HW CAN message and CAN message from loop driver
        // booth should be the same
        //
        if (rx_event.msg.id != loop_rx_event.msg.id)
        {
            CYG_TEST_FAIL_FINISH("Received message IDs of hw CAN channel and loop CAN channel are not equal");      
        }
        
        if (rx_event.msg.dlc != loop_rx_event.msg.dlc)
        {
            CYG_TEST_FAIL_FINISH("Received DLCs of hw CAN msg and loop CAN msg are not equal");      
        }
        
        //
        // Now check each data byte of the receive message
        //
        for (i = 0; i < rx_event.msg.dlc; ++i)
        {
            if (rx_event.msg.data.bytes[i] != loop_rx_event.msg.data.bytes[i])
            {
                CYG_TEST_FAIL_FINISH("Data of hw CAN msg and loop CAN  msg are not equal");          
            }
            
            if (rx_event.msg.data.bytes[i] != (i + msg_cnt))
            {
                CYG_TEST_FAIL_FINISH("CAN message contains unexpected data");         
            }
        }
        
        msg_cnt++;
    } // while (1)
    
    CYG_TEST_PASS_FINISH("CAN rx/tx test OK");         
}
예제 #18
0
void
timers_test(cyg_addrword_t data)
{
    int loops = LOOPS;
    int i;
    CYG_INTERRUPT_STATE istate;
    
    CYG_TEST_INIT();
    
    CYG_TEST_INFO("Start Timers test");
    
    for( i = 0; timers[i].timer != 0; i++ )
    {
        struct timer *t = &timers[i];

        init_timer( t->base, t->interval );

        cyg_interrupt_create( t->vector,
                              t->priority,
                              (cyg_addrword_t)t,
                              timer_isr,
                              timer_dsr,
                              &t->interrupt_handle,
                              &t->interrupt_object
            );

        cyg_interrupt_attach( t->interrupt_handle );
        cyg_interrupt_unmask( t->vector );
                              
    }

    while( loops-- )
    {
        int j;

        // 5 second delay
        cyg_thread_delay( 5*100 );

        // Disable interrupts while we print details, otherwise it
        // comes out very slowly.
        HAL_DISABLE_INTERRUPTS( istate );
        
        if( max_nesting > max_nesting_seen )
            max_nesting_seen = max_nesting;
        
        diag_printf("\nISRs max_nesting %d max_nesting_seen %d\n", max_nesting, max_nesting_seen );
        max_nesting = 0;

        diag_printf(" T      Ticks ");

        for( j = 0; j < 9; j++ )
            diag_printf("%9d ", j );
        diag_printf("\n");
            
        for( i = 0; timers[i].timer != 0; i++ )
        {
            struct timer *t = &timers[i];

            diag_printf("%2d: %9d ", t->timer, t->ticks );

            for( j = 0; j < 9; j++ )
                diag_printf("%9d ", t->preempt[j] );
            diag_printf("\n");

        }

        diag_printf("DSRs\n");

        diag_printf(" T:           ");

        for( j = 0; j < 9; j++ )
            diag_printf("%9d ", j );
        diag_printf("\n");
        
        for( i = 0; timers[i].timer != 0; i++ )
        {
            struct timer *t = &timers[i];

            diag_printf("%2d:  preempt: ", t->timer);
            
            for( j = 0; j < 9; j++ )
                diag_printf("%9d ", t->preempt_dsr[j] );
            diag_printf("\n");

            diag_printf("       count: ");

            for( j = 0; j < 9; j++ )
                diag_printf("%9d ", t->dsr_count[j] );
            diag_printf("\n");
        }
        
        HAL_RESTORE_INTERRUPTS( istate );        
    }

    CYG_TEST_PASS_FINISH("Timers test");
}
예제 #19
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can_thread(cyg_addrword_t data)
{
    cyg_uint32              len;
    cyg_can_callback_cfg    callback_cfg;
    cyg_can_message         tx_msg;
    cyg_bool_t              wait_res;
    
    //
    // open CAN0 device driver
    //
    if (ENOERR != cyg_io_lookup("/dev/can0", &hCAN0)) 
    {
        CYG_TEST_FAIL_FINISH("Error opening /dev/can0");
    }
    
    //
    // open CAN1 device driver
    //
    if (ENOERR != cyg_io_lookup("/dev/can1", &hCAN1)) 
    {
        CYG_TEST_FAIL_FINISH("Error opening /dev/can1");
    }
    
    //
    // configure CAN0 callback
    //
    len = sizeof(callback_cfg);
    callback_cfg.flag_mask = 0xFFFF;
    callback_cfg.data = (CYG_ADDRWORD) hCAN0;
    callback_cfg.callback_func = callback_func;
    
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_CAN_CALLBACK,
            &callback_cfg, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing config of /dev/can0");
    }
    
    //
    // transmit message from CAN1 to CAN0
    //
    tx_msg.id  = 0x001;
    tx_msg.ext = CYGNUM_CAN_ID_STD;
    tx_msg.rtr = CYGNUM_CAN_FRAME_DATA;
    tx_msg.dlc = 0;
    len = sizeof(tx_msg); 
    
    if (ENOERR != cyg_io_write(hCAN1, &tx_msg, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing message to /dev/can1");
    }
    
    //
    // Wait CAN0 callback
    //
    cyg_mutex_lock(&can_lock);
    
    wait_res = cyg_cond_timed_wait(&can_wait, 100);
    
    cyg_mutex_unlock(&can_lock);
    
    //
    // If result of wait is a signal operation, test is successed
    // If timeout - test is failed, because callback_func() hasn't been
    // called with correct parameters
    //
    if(wait_res)
    {
        CYG_TEST_PASS_FINISH("can_callback test OK");
    }
    else
    {
        CYG_TEST_FAIL_FINISH("can_callback test FAILED");
    }
}
예제 #20
0
externC void
cyg_start( void )
{
    int stat;
    void *err_addr;
    CYG_ADDRWORD flash_start, flash_end;
    void **flash_start_addr = (void *)&flash_start;
    void **flash_end_addr = (void *)&flash_end;
    void *flash_test_start, *flash_addr;
    cyg_int32 flash_block_size, flash_num_blocks;
    CYG_ADDRWORD test_buf1, test_buf2;
    cyg_uint32 *lp1, *lp2;
    int i, len;
    cyg_bool passed, ok;

    CYG_TEST_INIT();

#if 0
    int j;
    
    diag_printf("Testing udelay: ");
    for (i = 0;  i < 30;  i++) {
        for (j = 0;  j < 1000;  j++) {
            CYGACC_CALL_IF_DELAY_US(1000);  // Should be 1 second
        }
        diag_printf(".");
    }
    diag_printf("\n");
#endif

    passed = true;

    if ((stat = flash_init(diag_printf)) != 0) {
        diag_printf("FLASH: driver init failed: %s\n", flash_errmsg(stat));
        CYG_TEST_FAIL_FINISH("FLASH driver init failed");
    }
    flash_get_limits((void *)0, flash_start_addr, flash_end_addr);
    // Keep 'end' address as last valid location, to avoid wrap around problems
    flash_end = flash_end - 1;
    flash_get_block_info(&flash_block_size, &flash_num_blocks);

    diag_printf("FLASH: 0x%x - 0x%x, %d blocks of 0x%x bytes each.\n", 
                flash_start, flash_end + 1, flash_num_blocks, 
                flash_block_size);

    // Verify that the testing limits are within the bounds of the
    // physical device.  Also verify that the size matches with
    // the erase block size on the device
    if ((CYGNUM_IO_FLASH_TEST_OFFSET > (flash_end - flash_start)) ||
        ((CYGNUM_IO_FLASH_TEST_OFFSET + CYGNUM_IO_FLASH_TEST_LENGTH) > (flash_end - flash_start))) {
        CYG_TEST_FAIL_FINISH("FLASH test region outside physical limits");
    }
    if ((CYGNUM_IO_FLASH_TEST_LENGTH % flash_block_size) != 0) {
        CYG_TEST_FAIL_FINISH("FLASH test region must be integral multiple of erase block size");
    }

    // Allocate two buffers large enough for the test
    test_buf1 = (CYG_ADDRWORD)CYGMEM_SECTION_heap1;
    test_buf2 = test_buf1 + CYGNUM_IO_FLASH_TEST_LENGTH;
    if (CYGMEM_SECTION_heap1_SIZE < (CYGNUM_IO_FLASH_TEST_LENGTH * 2)) {
        CYG_TEST_FAIL_FINISH("FLASH not enough heap space - reduce size of test region");
    }
    diag_printf("... Using test buffers at %p and %p\n", (void *)test_buf1, (void *)test_buf2);
    flash_test_start = (void *)(flash_start + CYGNUM_IO_FLASH_TEST_OFFSET);

#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING    
    // Unlock test
    diag_printf("... Unlock test\n");
    ok = true;
    if ((stat = flash_unlock(flash_test_start, 
                             CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
#endif
    
    // Erase test
    diag_printf("... Erase test\n");
    ok = true;
    if ((stat = flash_erase(flash_test_start, 
                            CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: erase failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
    if (ok && (stat = flash_read(flash_test_start, (void *)test_buf1,
                           CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: read/verify after erase failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
    lp1 = (cyg_uint32 *)test_buf1;
    for (i = 0;  i < CYGNUM_IO_FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        if (*lp1++ != 0xFFFFFFFF) {
            diag_printf("FLASH: non-erased data found at offset %x\n", (CYG_ADDRWORD)(lp1-1) - test_buf1);
            diag_dump_buf((void *)(lp1-1), 32);
            ok = false;
            break;
        }
    }
    // Try reading in little pieces
    len = CYGNUM_IO_FLASH_TEST_LENGTH;
    flash_addr = flash_test_start;
    while (len > 0) {
        if ((stat = flash_read(flash_addr, (void *)test_buf1, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
            diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
            ok = false;
            break;
        }    
        flash_addr = (cyg_uint8 *)flash_addr + 0x200;
        len -= 0x200;
        lp1 = (cyg_uint32 *)test_buf1;
        for (i = 0;  i < 0x200;  i += sizeof(cyg_uint32)) {
            if (*lp1++ != 0xFFFFFFFF) {
                diag_printf("FLASH: non-erased data found at offset %p\n", 
                            (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp1-1) - test_buf1));
                diag_dump_buf((void *)(lp1-1), 32);
                ok = false;
                len = 0;
                break;
            }
        }
    }
    
    if (!ok) {
        CYG_TEST_INFO("FLASH erase failed");
        passed = false;
    }

    // Simple write/verify test
    diag_printf("... Write/verify test\n");
    lp1 = (cyg_uint32 *)test_buf1;
    for (i = 0;  i < CYGNUM_IO_FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        *lp1 = (cyg_uint32)lp1;
        lp1++;
    }
    ok = true;
    if (ok && (stat = flash_program(flash_test_start, (void *)test_buf1,
                                    CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: write failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
    if (ok && (stat = flash_read(flash_test_start, (void *)test_buf2,
                                    CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: read/verify after write failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
    lp1 = (cyg_uint32 *)test_buf1;
    lp2 = (cyg_uint32 *)test_buf2;
    for (i = 0;  i < CYGNUM_IO_FLASH_TEST_LENGTH;  i += sizeof(cyg_uint32)) {
        if (*lp2++ != *lp1++) {
            diag_printf("FLASH: incorrect data found at offset %x\n", (CYG_ADDRWORD)(lp2-1) - test_buf2);
            diag_dump_buf((void *)(lp2-1), 32);
            ok = false;
            break;
        }
    }
    // Try reading in little pieces
    len = CYGNUM_IO_FLASH_TEST_LENGTH;
    flash_addr = flash_test_start;
    lp1 = (cyg_uint32 *)test_buf1;
    lp2 = (cyg_uint32 *)test_buf2;
    while (len > 0) {
        if ((stat = flash_read(flash_addr, lp2, 0x200, &err_addr)) != CYG_FLASH_ERR_OK) {
            diag_printf("FLASH: read[short]/verify after erase failed: %s\n", flash_errmsg(stat));
            ok = false;
            break;
        }    
        flash_addr = (cyg_uint8 *)flash_addr + 0x200;
        len -= 0x200;
        for (i = 0;  i < 0x200;  i += sizeof(cyg_uint32)) {
            if (*lp2++ != *lp1++) {
                diag_printf("FLASH: incorrect data found at offset %p\n", 
                            (cyg_uint8 *)flash_addr + (CYG_ADDRWORD)((lp2-1) - test_buf2));
                diag_dump_buf((void *)(lp2-1), 32);
                ok = false;
                len = 0;
                break;
            }
        }
    }
    
    if (!ok) {
        CYG_TEST_INFO("FLASH write/verify failed");
    }

#ifdef CYGHWR_IO_FLASH_BLOCK_LOCKING
    // Lock test
    diag_printf("... Lock test\n");
    ok = true;
    if ((stat = flash_lock(flash_test_start, 
                           CYGNUM_IO_FLASH_TEST_LENGTH, &err_addr)) != CYG_FLASH_ERR_OK) {
        diag_printf("FLASH: unlock failed: %s\n", flash_errmsg(stat));
        ok = false;
    }    
#endif
    
    if (passed) {
        CYG_TEST_PASS_FINISH("FLASH test1");
    } else {
        CYG_TEST_FAIL_FINISH("FLASH test1");
    }
}
예제 #21
0
void
net_test(test_param_t param)
{
#ifdef __ECOS
    cyg_serial_baud_rate_t old;    
    cyg_ppp_options_t options;
    cyg_ppp_handle_t ppp_handle;

    CYG_TEST_INIT();
#endif

//    int i;
    if (param == 0) {
        test_printf("Start Network Characterization - SLAVE\n");
#ifdef __ECOS
        init_all_network_interfaces();
        calibrate_load(DESIRED_BACKGROUND_LOAD);
#if 0
// I can see what this is trying to do, but I get "bind: Address already in
// use" errors from the 2nd interface - and the parameter is not used
// anyway, so one thread does quite well enough (but only tests one i/f at
// once).

// Comment in the 'int i' above too.
        for (i = 1;  i < CYGHWR_NET_DRIVERS;  i++) {
            cyg_thread_resume(main_thread_handle[i]);   // Start other threads
        }
#endif
#endif
    }

#ifdef __ECOS

    old = ppp_test_set_baud( CYGNUM_SERIAL_BAUD_115200 );

    ppp_test_announce( "NC_TEST_SLAVE" );
    
    cyg_ppp_options_init( &options );

//    options.debug = 1;
//    options.kdebugflag = 1;

//    options.script = script;
//    options.flowctl = CYG_PPP_FLOWCTL_SOFTWARE;

    ppp_handle = cyg_ppp_up( CYGPKG_PPP_TEST_DEVICE, &options );

    CYG_TEST_INFO( "Waiting for PPP to come up");
    
    cyg_ppp_wait_up( ppp_handle );
#endif
    
    nc_slave(param);
#ifdef CYGDBG_NET_TIMING_STATS
    show_net_times();
#endif

#ifdef __ECOS
    CYG_TEST_INFO( "Bringing PPP down");

    cyg_ppp_down( ppp_handle );
    
    CYG_TEST_INFO( "Waiting for PPP to go down");

    cyg_ppp_wait_down( ppp_handle );

    cyg_thread_delay( 200 );

    ppp_test_set_baud( old );

    ppp_test_finish();

    CYG_TEST_PASS_FINISH( "Network Characterization - SLAVE" );
    
#endif
    
    cyg_test_exit();
}
예제 #22
0
//===========================================================================
//                            READER THREAD
//===========================================================================
void can1_thread(cyg_addrword_t data)
{
    cyg_io_handle_t    hCAN1;
    cyg_uint8          i;
    cyg_uint32         len;
    cyg_can_buf_info_t rx_buf_info;
    cyg_can_event      rx_event;
    cyg_can_message    tx_msg;
    
    if (ENOERR != cyg_io_lookup("/dev/can1", &hCAN1)) 
    {
        CYG_TEST_FAIL_FINISH("Error opening /dev/can1");
    }
    
    len = sizeof(rx_buf_info);
    if (ENOERR != cyg_io_get_config(hCAN1, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&rx_buf_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can1");
    }
    
    //
    // first we send the size of our receive buffer to the writer
    // we setup tx message now
    //
    tx_msg.id  = 0x000;
    tx_msg.ext = CYGNUM_CAN_ID_STD;
    tx_msg.rtr = CYGNUM_CAN_FRAME_DATA;
    tx_msg.dlc = sizeof(rx_buf_info.rx_bufsize);
    
    //
    // we store size of rx buffer in CAN message. We do not need to care about
    // endianess here because this is a loopback driver test and we will receive
    // our own messages
    //
    *((cyg_uint32 *)tx_msg.data) = rx_buf_info.rx_bufsize;
    len = sizeof(tx_msg); 
    
    //
    // as soon as we send a CAN message, thread 0 will resume because it is waiting
    // for a message
    //
    diag_printf("/dev/can1: Sending size of RX buffer %d\n", rx_buf_info.rx_bufsize);        
    if (ENOERR != cyg_io_write(hCAN1, &tx_msg, &len))
    {
        CYG_TEST_FAIL_FINISH("Error writing to /dev/can1");
    }
    cyg_thread_delay(10); // let thread 0 run
       
    //
    // now we check if we received CAN messages  - if receive buffer is not full
    // the we have an error here because we expect a full receive buffer
    //
    len = sizeof(rx_buf_info);
    if (ENOERR != cyg_io_get_config(hCAN1, CYG_IO_GET_CONFIG_CAN_BUFFER_INFO ,&rx_buf_info, &len))
    {
        CYG_TEST_FAIL_FINISH("Error reading config of /dev/can1");
    }
    
    if (rx_buf_info.rx_bufsize != rx_buf_info.rx_count)
    {
        CYG_TEST_FAIL_FINISH("RX buffer of /dev/can1 does not contain number of expected messages");
    }
    
    //
    // now we wait for messages from /dev/can0
    //
    diag_printf("/dev/can1: Receiving %d CAN messages\n", rx_buf_info.rx_count);
    for (i = 0; i < rx_buf_info.rx_count; ++i)
    {
        len = sizeof(rx_event);
        if (ENOERR != cyg_io_read(hCAN1, &rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
        }
        else
        {
            if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
            {
                print_can_msg(&rx_event.msg, "");
                if (rx_event.msg.data[0] != (i + 1))
                {
                    CYG_TEST_FAIL_FINISH("Received /dev/can1 RX event contains invalid data");
                }                    
            }
            else
            {
                CYG_TEST_FAIL_FINISH("Unexpected CAN event for /dev/can1");
            }
            
            //
            // now check if any other flag is set
            //
            if (rx_event.flags &  CYGNUM_CAN_EVENT_OVERRUN_RX)
            {
                diag_printf("RX queue overrun successfully indicated for /dev/can1\n");

//
// if TX events are supported then we have already a TX event in receive queue because
// we sent a message and the RX queue overrun will occur one message earlier
//
#if defined(CYGOPT_IO_CAN_TX_EVENT_SUPPORT)
                if (i < (rx_buf_info.rx_bufsize - 2))
#else
                if (i < (rx_buf_info.rx_bufsize - 1))
#endif
                {
                    CYG_TEST_FAIL_FINISH("RX queue overrun occured too early for /dev/can1");
                }
                else
                {
                    CYG_TEST_PASS_FINISH("can_overrun2 test OK"); 
                }
            } // if (rx_event.flags &  CYGNUM_CAN_EVENT_OVERRUN_RX)  
        }
        
    }
}
예제 #23
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can_thread(cyg_addrword_t data)
{
    cyg_uint32              len;
    cyg_uint8               i = 0;

    //
    // Check that all cannels have the same baudrate
    //
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN0
    can_setup_channel(hCAN_Tbl[0], 0);
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN1
    can_setup_channel(hCAN_Tbl[1], 1);
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN2
    can_setup_channel(hCAN_Tbl[2], 2);
#endif
    
#ifdef CYGPKG_DEVS_CAN_LPC2XXX_CAN3
    can_setup_channel(hCAN_Tbl[3], 3);
#endif
    
    diag_printf("\n\nThis test uses all available CAN channels for reception\n"
                "of CAN standard messages. The following messages will be received:\n\n");
    
    for (i = 0; i < 4; ++i)
    {
        if (hCAN_Tbl[i])
        {
            diag_printf("CAN channel %d: msg: 0x%03x - 0x%03x\n", i, i * 0x100, i * 0x100 + 9);
        }
    }
    
    diag_printf("\n\nYou can stop this test by sending a message with ID 0xX09\n");
    
    while (1)
    {
        for (i = 0; i < 4; ++i)
        {
            if (hCAN_Tbl[i])
            {
                Cyg_ErrNo     ret;
                cyg_can_event rx_event; 
                
                len = sizeof(rx_event);
                ret = cyg_io_read(hCAN_Tbl[i], &rx_event, &len);
                if ((ret == -EAGAIN) || (ret == -EINTR))
                {
                    continue;    
                }
                
                if (ENOERR != ret)
                {
                    CYG_TEST_FAIL_FINISH("Error reading from channel");
                }
                else
                {
                    diag_printf("Channel %d events: ", i);
                    print_can_flags(rx_event.flags, "");
                    if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
                    {
                        print_can_msg(&rx_event.msg, "");
                        if ((rx_event.msg.id & 9) == 9)
                        {
                            CYG_TEST_PASS_FINISH("LPC2xxx CAN multi channel RX test OK");    
                        }
                    } // if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
                }
            } // if (hCAN_Tbl[i])
        } // for (i = 0; i < 4; ++i)
    } // while (1)
}
예제 #24
0
//===========================================================================
//                             READER THREAD 
//===========================================================================
void can0_thread(cyg_addrword_t data)
{
    cyg_uint32              len;
    cyg_can_event           rx_event;
    cyg_can_filtergroup_cfg acc_filt_grp;
    cyg_can_msgbuf_cfg      msgbox_cfg;
    
    //
    // First we reset message buffer configuration - this is mandatory bevore starting
    // message buffer runtime configuration. This call clears/frees all message buffers
    // The CAN controller cannot receive any further CAN message after this call
    //
    msgbox_cfg.cfg_id = CYGNUM_CAN_MSGBUF_RESET_ALL;
    len = sizeof(msgbox_cfg);
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_CAN_MSGBUF ,&msgbox_cfg, &len))
    {
        CYG_TEST_FAIL_FINISH("Error resetting message buffer configuration of /dev/can0");
    } 
    
    //
    // Now we setup two different acceptance filter groups. Acceptance filter
    // groups are not part of the CAN I/O layer and are a LPC2xxx specific
    // feature. You should not use appcetance filter groups if you would like
    // to code portable eCos CAN applications
    //
#ifdef CYGOPT_IO_CAN_STD_CAN_ID    
    acc_filt_grp.ext            = CYGNUM_CAN_ID_STD;
    acc_filt_grp.lower_id_bound = 0x100;
    acc_filt_grp.upper_id_bound = 0x110;
    len = sizeof(acc_filt_grp);
    
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_LPC2XXX_ACCFILT_GROUP ,&acc_filt_grp, &len))
    {
        CYG_TEST_FAIL_FINISH("Error adding filter group to /dev/can0");
    } 
#endif // CYGOPT_IO_CAN_STD_CAN_ID
    
#ifdef CYGOPT_IO_CAN_EXT_CAN_ID   
    acc_filt_grp.ext            = CYGNUM_CAN_ID_EXT;
    acc_filt_grp.lower_id_bound = 0x2000;
    acc_filt_grp.upper_id_bound = 0x2200;
    len = sizeof(acc_filt_grp);
    
    if (ENOERR != cyg_io_set_config(hCAN0, CYG_IO_SET_CONFIG_LPC2XXX_ACCFILT_GROUP ,&acc_filt_grp, &len))
    {
        CYG_TEST_FAIL_FINISH("Error adding filter group to /dev/can0");
    } 
#endif // CYGOPT_IO_CAN_STD_CAN_ID
    
    diag_printf("\n\nNow try to send CAN messages. The device should only\n"
                    "receive standard messages identifiers in the range of 0x100\n"
                    "to 0x110 and/or extended identifiers in the range 0x2000 to\n"
                    "0x2200. As soon as a standard message with ID 0x110 or an\n"
                    "extended message with ID 0x2200 arrives, the test finishes\n\n");
    
    while (1)
    {
        len = sizeof(rx_event); 
            
        if (ENOERR != cyg_io_read(hCAN0, &rx_event, &len))
        {
            CYG_TEST_FAIL_FINISH("Error reading from /dev/can0");
        }
        else
        {
            print_can_flags(rx_event.flags, "");
            
            if (rx_event.flags & CYGNUM_CAN_EVENT_RX)
            {
                print_can_msg(&rx_event.msg, "");
#ifdef CYGOPT_IO_CAN_STD_CAN_ID
                if (rx_event.msg.id == 0x110)
                {
                    CYG_TEST_PASS_FINISH("LPC2xxx CAN message filter group test OK");
                }
#endif // CYGOPT_IO_CAN_STD_CAN_ID

#ifdef CYGOPT_IO_CAN_EXT_CAN_ID          
                if (rx_event.msg.id == 0x2200)
                {
                    CYG_TEST_PASS_FINISH("LPC2xxx CAN message filter group test OK");
                }
#endif // CYGOPT_IO_CAN_EXT_CAN_ID  
                
                if (((rx_event.msg.id > 0x110) && (rx_event.msg.id < 0x2000))
                   || (rx_event.msg.id > 0x2200))
                {
                    CYG_TEST_FAIL_FINISH("Received CAN identifier outside filter group bounds");
                }
            }
        } 
    } // while (1)
}
예제 #25
0
파일: fileio1.c 프로젝트: janfj/dd-wrt
int main( int argc, char **argv )
{
    int err;

    CYG_TEST_INIT();

    // --------------------------------------------------------------

    createfile( "/foo", 202 );
    checkfile( "foo" );
    copyfile( "foo", "fee");
    checkfile( "fee" );
    comparefiles( "foo", "/fee" );

    err = mkdir( "/bar", 0 );
    if( err < 0 ) SHOW_RESULT( mkdir, err );

    listdir( "/" , false);

    copyfile( "fee", "/bar/fum" );
    checkfile( "bar/fum" );
    comparefiles( "/fee", "bar/fum" );


    err = chdir( "bar" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = rename( "/foo", "bundy" );
    if( err < 0 ) SHOW_RESULT( rename, err );

    listdir( "/", true );
    listdir( "" , true );

    checkfile( "/bar/bundy" );
    comparefiles("/fee", "bundy" );

    testfs_dump();

    // --------------------------------------------------------------

    err = unlink( "/fee" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "fum" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "/bar/bundy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = rmdir( "/bar" );
    if( err < 0 ) SHOW_RESULT( rmdir, err );

    listdir( "/", false );

    // --------------------------------------------------------------

    err = mount( "", "/ram", "testfs" );
    if( err < 0 ) SHOW_RESULT( mount, err );

    createfile( "/ram/tinky", 456 );
    copyfile( "/ram/tinky", "/ram/laalaa" );
    checkfile( "/ram/tinky");
    checkfile( "/ram/laalaa");
    comparefiles( "/ram/tinky", "/ram/laalaa" );

    err = chdir( "/ram" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    createfile( "tinky", 678 );
    checkfile( "tinky" );

    maxfile( "dipsy" );
    checkfile( "dipsy" );
    copyfile( "dipsy", "po" );
    checkfile( "po" );
    comparefiles( "dipsy", "po" );

    testfs_dump();

    // --------------------------------------------------------------

    err = unlink( "tinky" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "dipsy" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "po" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = unlink( "laalaa" );
    if( err < 0 ) SHOW_RESULT( unlink, err );

    err = chdir( "/" );
    if( err < 0 ) SHOW_RESULT( chdir, err );

    err = umount( "/ram" );
    if( err < 0 ) SHOW_RESULT( umount, err );

    CYG_TEST_PASS_FINISH("fileio1");
}
예제 #26
0
파일: kclock0.c 프로젝트: EPiCS/reconos_v2
void kclock0_main(void)
{
    CYG_TEST_INIT();

    CHECK(flash());
    CHECK(flash());

    cyg_counter_create( &counter0, &counter0o);

    CHECK( 0 == cyg_counter_current_value( counter0 ) );

    cyg_counter_tick(counter0);

    CHECK( 1 == cyg_counter_current_value(counter0) );

    cyg_counter_tick(counter0);

    CHECK( 2 == cyg_counter_current_value(counter0) );

    cyg_counter_set_value( counter0, 0xffffffff );

    CHECK( 0xffffffff == cyg_counter_current_value(counter0) );

    cyg_counter_tick(counter0); // Overflows 32 bits
    
    CHECK( 0x100000000ULL == cyg_counter_current_value(counter0) );

    cyg_counter_set_value(counter0, 11);
    CHECK( 11 == cyg_counter_current_value(counter0) );
    
    /* the call_me functions cause the "called" bits to toggle
    // checking the value of called checks the parity of # of calls
    // made by each alarm.
    */

    cyg_alarm_create(counter0,
                     call_me,  (cyg_addrword_t)0x1, &alarm0, &alarmo[0]);
    cyg_alarm_create(counter0,
                     call_me,  (cyg_addrword_t)0x2, &alarm1, &alarmo[1]);
    cyg_alarm_create(counter0,
                     call_me2, (cyg_addrword_t)0x4, &alarm2, &alarmo[2]);
    
    CHECK( 0x00 == called );
    cyg_alarm_initialize(alarm0, 12,3);
    cyg_alarm_initialize(alarm2, 21,2);
    CHECK( 0x00 == called );

    cyg_counter_tick(counter0);         /* 12 a0 */
    CHECK( 0x01 == called );

    cyg_alarm_initialize(alarm1, 13,0);
    cyg_counter_tick(counter0);         /* 13 a1 */
    CHECK( 0x03 == called );

    cyg_alarm_initialize(alarm1, 17,0);
    cyg_counter_tick(counter0);         /* 14 */
    CHECK( 0x03 == called );

    cyg_counter_tick(counter0);         /* 15 a0 */
    CHECK( 0x02 == called );

    cyg_counter_tick(counter0);         /* 16 */
    cyg_counter_tick(counter0);         /* 17 a1 */
    CHECK( 0x00 == called );

    cyg_counter_tick(counter0);         /* 18 a0 */
    CHECK( 0x01 == called );

    cyg_counter_tick(counter0);         /* 19 */
    cyg_counter_tick(counter0);         /* 20 */
    cyg_counter_tick(counter0);         /* 21 a0 a2 */
    CHECK( 0x14 == called );

    cyg_counter_tick(counter0);         /* 22 */
    cyg_counter_tick(counter0);         /* 23 a2 */
    CHECK( 0x00 == called );
    
    cyg_alarm_disable(alarm2);  

    cyg_counter_tick(counter0);         /* 24 a0 */
    cyg_counter_tick(counter0);         /* 25 */
    CHECK( 0x01 == called );
    
    cyg_alarm_enable(alarm2);           /* a2 (enabled at 25) */
    CHECK( 0x15 == called );

    cyg_counter_tick(counter0);         /* 26 */
    CHECK( 0x15 == called );
    
    cyg_counter_tick(counter0);         /* 27 a0 a2 */
    cyg_counter_tick(counter0);         /* 28 */
    CHECK( 0x00 == called );
    
    cyg_counter_tick(counter0);         /* 29 a2 */
    cyg_counter_tick(counter0);         /* 30 a0 */
    cyg_counter_tick(counter0);         /* 31 a2 */
    CHECK( 0x01 == called );

    res0.dividend = 100;
    res0.divisor   = 3;

    cyg_clock_create( res0, &clock0, &clock0o );

    res1 = cyg_clock_get_resolution(clock0);
    CHECK( res0.dividend == res1.dividend );
    CHECK( res0.divisor == res1.divisor );

    res1.dividend = 12;
    res1.divisor = 25;

    cyg_clock_set_resolution(clock0, res1);
    res0 = cyg_clock_get_resolution(clock0);
    CHECK( res0.dividend == res1.dividend );
    CHECK( res0.divisor == res1.divisor );

    cyg_clock_to_counter(clock0, &counter1);

    CHECK( 0 == cyg_counter_current_value( counter1 ) );
    CHECK( 0 == cyg_current_time() );

    cyg_counter_tick(counter1);

    CHECK( 1 == cyg_counter_current_value(counter1) );

    res0 = cyg_clock_get_resolution(cyg_real_time_clock());

    /* Current time should be 0 as interrupts will still be disabled */
    CHECK( 0 == cyg_current_time() );

    CYG_TEST_PASS_FINISH("Kernel C API Clock 0 OK");
}
예제 #27
0
void controller( cyg_addrword_t id )
{
    cyg_priority_t pri;
    int i;

    cyg_mutex_init( &worker_mutex );
    cyg_cond_init( &worker_cv, &worker_mutex );
    
// 1 thread, it is running, it calls BREAKME();
//  +++ Thread status returned:
//  +++ 1 thread, running, is the current one
    
    breakme();

// Create N more threads; they are all suspended after creation.  Adjust
// the priorities of all the threads to lower than the controlling thread.
// Make them all be distinct priorities as far as possible.  BREAKME();
//  +++ 1 thread, running, + N suspended ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;

        cyg_thread_create(pri, worker, (cyg_addrword_t)i, "worker",
                          (void *)(&thread_stack[i]), STACKSIZE,
                          &thread_handle[i], &thread[i]);

    }

    breakme();

// Adjust the priorities of all the threads to lower than the controlling
// thread.  Make them all be THE SAME priority.  BREAKME();
//  +++ 1 thread, running, + N suspended ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();
    
// Release all the N threads, BREAKME();
//  +++ 1 thread, running, + N ready ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_resume( thread_handle[i] );
    }

    breakme();

// Adjust the priorities of all the threads, lower than the controlling
// thread.  Make them all be distinct priorities as far as possible.
// BREAKME();
//  +++ 1 thread, running, + N ready ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();
    
// Command all the N threads to sleep; switch my own priority to lower
// than theirs so that they all run and sleep, then I get back in and
// BREAKME();
// +++ 1 thread, running, + N sleeping ones of different prios.

    worker_state = WORKER_STATE_WAIT;

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );

    breakme();
    
// Make them all be THE SAME priority; BREAKME();
//  +++ 1 thread, running, + N sleeping ones of same prio.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of same prio.

    cyg_cond_broadcast( &worker_cv );

    breakme();

// Adjust the priorities of all the threads, higher than the controlling
// thread.  Make them all be distinct priorities as far as possible.
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of different prios.

    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME();
//  +++ 1 thread, running, + N sleeping ones of different prios.

    cyg_cond_broadcast( &worker_cv );

    breakme();

// Set them all the same prio, set me to the same prio, BREAKME();
//  +++ 1 running, + N sleeping, *all* the same prio.

    for( i = 0; i < THREADS; i++ )
    {
        cyg_thread_set_priority( thread_handle[i], WORKER_PRI );
    }

    breakme();

// Wake them all up, they'll loop once and sleep again; I get in and
// BREAKME(); repeatedly until they have all slept again.
//  +++ 1 running, + some sleeping, some ready, *all* the same prio.

    cyg_cond_broadcast( &worker_cv );

//    cyg_thread_yield();
    
    do
    {
        breakme();
        
    } while( workers_asleep != THREADS-1 ); 

    breakme();
    
// Suspend some of the threads, BREAKME();
//  +++ 1 running, + some sleeping, some suspended, *all* the same prio.

    for( i = 1; i < THREADS; i++ )
    {
        // suspend every 3rd thread
        if( 0 == (i % 3) ) cyg_thread_suspend( thread_handle[i] );
    }

    breakme();


// Change the prios all different, change my prio to highest , BREAKME();
//  +++ 1 running, + some sleeping, some suspended, different prios.

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_HI );
        
    for( i = 1; i < THREADS; i++ )
    {
        pri = CONTROLLER_PRI_HI + 1 + i % WORKER_PRI_RANGE;
        
        cyg_thread_set_priority( thread_handle[i], pri );
    }

    breakme();
    
// Wake up all the threads, BREAKME();
//  +++ 1 running, + some ready, some suspended/ready, different prios.

    cyg_cond_broadcast( &worker_cv );

    breakme();


// Change my prio to lowest, let all the threads run, BREAKME().
//  +++ 1 running + some sleeping, some suspended/ready, different prios.

    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );
    
    breakme();
    
// Resume all the threads, BREAKME();
//  +++ 1 running, + N ready, different prios.

    for( i = 1; i < THREADS; i++ )
    {
        cyg_thread_resume( thread_handle[i] );
    }
    
    breakme();
    
// Command some of the N threads to call BREAKME(); themselves (then sleep
// again).  Change my prio to low, so that they all get to run and hit the
// breakpoint.
//  +++ A different one running every time, others in a mixture of
//      ready and sleeping states.
    
    worker_state = WORKER_STATE_BREAK;

    cyg_cond_broadcast( &worker_cv );
    
    cyg_thread_set_priority( thread_handle[0], CONTROLLER_PRI_LO );
    
    breakme();
    
// Command all the threads to exit; switch my own priority to lower
// than theirs so that they all run and exit, then I get back in and
// BREAKME();
//  +++ 1 thread, running, + N dormant ones.

    worker_state = WORKER_STATE_EXIT;

    cyg_cond_broadcast( &worker_cv );
    
    breakme();

#if 0

// Cannot do this yet...
    
// Destroy some of the N threads to invalidate their IDs.  Re-create them
// with new IDs, so that we get IDs 1,2,4,6,8,11,12,13,14,15 in use instead
// of 1,2,3,4,5,6,7,8,9, if you see what I mean.  Do all the above again.
// Loop forever, or whatever...

#endif

    breakme();
    
    CYG_TEST_PASS_FINISH("GDB Thread test OK");
    
}
예제 #28
0
파일: sigsetjmp.c 프로젝트: 0xCA5A/dd-wrt
int main(int argc, char **argv)
{
    int ret;
    sigset_t mask;
    pthread_attr_t attr;
    void *retval;
    
    CYG_TEST_INIT();

    // Make a full signal set
    sigfillset( &mask );

    
    // Install signal handlers
    {
        struct sigaction sa;

        sa.sa_sigaction = sigusr1;
        sa.sa_mask = mask;
        sa.sa_flags = SA_SIGINFO;

        ret = sigaction( SIGUSR1, &sa, NULL );

        CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
    }
    {
        struct sigaction sa;

        sa.sa_sigaction = sigusr2;
        sa.sa_mask = mask;
        sa.sa_flags = SA_SIGINFO;

        ret = sigaction( SIGUSR2, &sa, NULL );

        CYG_TEST_CHECK( ret == 0 , "sigaction returned error");
    }


    // Create the timers

    {
        struct sigevent sev;
        struct itimerspec value;
        
        sev.sigev_notify                = SIGEV_SIGNAL;
        sev.sigev_signo                 = SIGUSR1;
        sev.sigev_value.sival_int       = 0xABCDEF01;

        value.it_value.tv_sec           = 1;
        value.it_value.tv_nsec          = 0;
        value.it_interval.tv_sec        = 0;
        value.it_interval.tv_nsec       = 0;
        
        ret = timer_create( CLOCK_REALTIME, &sev, &timer1 );

        CYG_TEST_CHECK( ret == 0 , "timer_create returned error");

        ret = timer_settime( timer1, 0, &value, NULL );

        CYG_TEST_CHECK( ret == 0 , "timer_settime returned error");
    }

    {
        struct sigevent sev;
        struct itimerspec value;
        
        sev.sigev_notify                = SIGEV_SIGNAL;
        sev.sigev_signo                 = SIGUSR2;
        sev.sigev_value.sival_int       = 0xABCDEF02;

        value.it_value.tv_sec           = 0;
        value.it_value.tv_nsec          = 500000000;
        value.it_interval.tv_sec        = 0;
        value.it_interval.tv_nsec       = 250000000;
        
        ret = timer_create( CLOCK_REALTIME, &sev, &timer2 );

        CYG_TEST_CHECK( ret == 0 , "timer_create returned error");

        ret = timer_settime( timer2, 0, &value, NULL );

        CYG_TEST_CHECK( ret == 0 , "timer_settime returned error");
    }

    
    // Mask all signals
    pthread_sigmask( SIG_SETMASK, &mask, NULL );
    
    sem_init( &sem, 0, 0 );
    
    // Create test threads

    {
        pthread_attr_init( &attr );

        pthread_attr_setstackaddr( &attr, (void *)&thread1_stack[sizeof(thread1_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread1_stack) );

        pthread_create( &thread1,
                        &attr,
                        pthread_entry1,
                        (void *)0x12345671);
    }

    {
        pthread_attr_init( &attr );

        pthread_attr_setstackaddr( &attr, (void *)&thread2_stack[sizeof(thread2_stack)] );
        pthread_attr_setstacksize( &attr, sizeof(thread2_stack) );

        pthread_create( &thread2,
                        &attr,
                        pthread_entry2,
                        (void *)0x12345672);
    }
    
    // Wait for other thread to get started
    CYG_TEST_INFO( "Main: calling sem_wait()");
    sem_wait( &sem );
    CYG_TEST_INFO( "Main: calling sem_wait() again");    
    sem_wait( &sem );

    // Now join with thread1
    CYG_TEST_INFO( "Main: calling pthread_join(thread1)");
    pthread_join( thread1, &retval );

    CYG_TEST_CHECK( retval == (void *)0x12345671, "Thread 1 retval wrong");
    
    // And thread 2
    CYG_TEST_INFO( "Main: calling pthread_join(thread2)");
    pthread_join( thread2, &retval );

    // now delete the timers
    CYG_TEST_INFO( "Main: calling timer_delete(timer1)");    
    ret = timer_delete( timer1 );

    CYG_TEST_CHECK( ret == 0 , "timer_delete(timer1) returned error");

    CYG_TEST_INFO( "Main: calling timer_delete(timer2)");    
    ret = timer_delete( timer2 );

    CYG_TEST_CHECK( ret == 0 , "timer_delete(timer2) returned error");

    
    CYG_TEST_CHECK( retval == (void *)0x12345672, "Thread 2 retval wrong");
    
    CYG_TEST_CHECK( sigusr1_called == 1, "SIGUSR1 signal handler not called once" );
    CYG_TEST_CHECK( sigusr2_called == 6, "SIGUSR2 signal handler not called six times" );

    CYG_TEST_PASS_FINISH( "sigsetjmp" );
}
예제 #29
0
void cyg_user_start(void)
{
    int ret;
    char data[1024];
    void *flash_start, *flash_end;
    int block_size, blocks;
    char *prog_start;
    unsigned char * ptr;

    CYG_TEST_INIT();
  
    ret=flash_init(NULL,0,(_printf *)diag_printf);
  
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_init");

    flash_dev_query(data);
    CYG_TEST_PASS_FAIL(!strncmp(data,"Linux Synthetic Flash",sizeof(data)),
                       "flash_query"); 

    ret = flash_get_limits(NULL,&flash_start,&flash_end);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_limits");

    ret = flash_get_block_info(&block_size, &blocks);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_get_block_info");

    /* Erase the whole flash. Not recommended on real hardware since this
     will probably erase the bootloader etc!!! */
    ret=flash_erase(flash_start,block_size * blocks,NULL);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase1");

    /* check that its actually been erased, and test the mmap area */
    for (ptr=flash_start,ret=0; ptr < (unsigned char *)flash_end; ptr++) {
        if (*ptr != 0xff) {
            ret++;
        }
    }
  
    CYG_TEST_PASS_FAIL((ret == 0),"flash empty check");

    ret = flash_program(flash_start,&copyright,sizeof(copyright),NULL);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program1");
  
    /* Check the contents made it into the flash */
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
                       "flash program contents");

    /* .. and check nothing else changed */
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
         ptr < (unsigned char *)flash_end; ptr++) {
        if (*ptr != 0xff) {
            ret++;
        }
    }
  
    CYG_TEST_PASS_FAIL((ret == 0),"flash program overrun check");

    /* Program over a block boundary */
    prog_start = (unsigned char *)flash_start + block_size - sizeof(copyright)/2;
    ret = flash_program(prog_start,&copyright,sizeof(copyright),NULL);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_program2");
  
    /* Check the first version is still OK */
    CYG_TEST_PASS_FAIL(!strncmp(flash_start,copyright,sizeof(copyright)),
                       "Original contents");
  
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)),
                       "New program contents");

    /* Check the bit in between is still erased */
    for (ptr=(unsigned char *)flash_start+sizeof(copyright),ret=0; 
         ptr < (unsigned char *)prog_start; ptr++) {
        if (*ptr != 0xff) {
            ret++;
        }
    }
    CYG_TEST_PASS_FAIL((ret == 0),"flash erase check1");
  
    /* Erase the second block and make sure the first is not erased */
    ret=flash_erase((void *)((unsigned)flash_start+block_size),
                    block_size,NULL);
    CYG_TEST_PASS_FAIL((ret == FLASH_ERR_OK),"flash_erase2");

    /* Check the erase worked */
    for (ptr=(unsigned char *)flash_start+block_size,ret=0; 
         ptr < (unsigned char *)flash_start+block_size*2; ptr++) {
        if (*ptr != 0xff) {
            ret++;
        }
    }

    CYG_TEST_PASS_FAIL((ret == 0), "flash erase check2");
  
    /* Lastly check the first half of the copyright message is still there */
    CYG_TEST_PASS_FAIL(!strncmp(prog_start,copyright,sizeof(copyright)/2),
                       "Block 1 OK");

#if 0
    /* This test it fatal! Its not run by default!
     Check the flash is read only, by trying to write to it. We expect
     to get an exception */

    *(char *)flash_start = 'a';
#endif

    CYG_TEST_PASS_FINISH("flash1");
}
예제 #30
0
void cyg_start (void)
{
    CYG_TEST_INIT();
    CYG_TEST_PASS_FINISH("N/A: Stand-alone GDB stubs only");
}