Example #1
0
/******************************************************************************
**                          FUNCTION DEFINITIONS
*******************************************************************************/
int main(void)
{
    /* This function will enable clocks for the DMTimer2 instance */
    DMTimer2ModuleClkConfig();

    /* Initialize the UART console */
    ConsoleUtilsInit();

    /* Select the console type based on compile time check */
    ConsoleUtilsSetType(CONSOLE_UART);

    /* Enable IRQ in CPSR */
    IntMasterIRQEnable();

    /* Register DMTimer2 interrupts on to AINTC */
    DMTimerAintcConfigure();

    /* Perform the necessary configurations for DMTimer */
    DMTimerSetUp();

    /* Enable the DMTimer interrupts */
    DMTimerIntEnable(SOC_DMTIMER_2_REGS, DMTIMER_INT_OVF_EN_FLAG);

    ConsoleUtilsPrintf("Tencounter: ");

    /* Start the DMTimer */
    DMTimerEnable(SOC_DMTIMER_2_REGS);  

    while(cntValue)
    {
        if(flagIsr == 1)
        {
            ConsoleUtilsPrintf("\b%d",(cntValue - 1));
            cntValue--;
            flagIsr = 0;
        }
    }

    /* Stop the DMTimer */
    DMTimerDisable(SOC_DMTIMER_2_REGS); 

    PRINT_STATUS(S_PASS);

    /* Halt the program */
    while(1);
}
Example #2
0
File: main.cpp Project: CCJY/coliru
int main()
{
    device<port_a, 0> sensor_0;
    device<port_a, 1> sensor_1;
    device<port_b, 0> relay_0;
    device<port_b, 1> relay_1;

    std::cout << "Everything's off" << std::endl;
    PRINT_STATUS(sensor_0);
    PRINT_STATUS(sensor_1);
    PRINT_STATUS(relay_0);
    PRINT_STATUS(relay_1);
    
    std::cout << "Turn on sensor 0" << std::endl;
    sensor_0 = 1;
    PRINT_STATUS(sensor_0);
    PRINT_STATUS(sensor_1);
    std::cout << "Turn on sensor 1" << std::endl;
    sensor_1 = 1;
    PRINT_STATUS(sensor_0);
    PRINT_STATUS(sensor_1);
    std::cout << "Turn on relay 0" << std::endl;
    relay_0 = 1;
    PRINT_STATUS(relay_0);
    PRINT_STATUS(relay_1);
    std::cout << "Turn on relay 1" << std::endl;
    relay_1 = 1;
    PRINT_STATUS(relay_0);
    PRINT_STATUS(relay_1);
    
    return 0;
}
Example #3
0
static void validate_file(const char *path, int number,
	uint64_t *ptr_ok, uint64_t *ptr_corrupted, uint64_t *ptr_changed,
	uint64_t *ptr_overwritten, uint64_t *ptr_size, int *ptr_read_all,
	struct timeval *ptr_dt, int progress)
{
	char *full_fn;
	const char *filename;
	const int num_int64 = SECTOR_SIZE >> 3;
	uint64_t sector[num_int64];
	FILE *f;
	int fd;
	size_t sectors_read;
	uint64_t expected_offset;
	int final_errno;
	struct timeval t1, t2;
	/* Progress time. */
	struct timeval pt1 = { .tv_sec = -1000, .tv_usec = 0 };

	*ptr_ok = *ptr_corrupted = *ptr_changed = *ptr_overwritten = 0;

	full_fn = full_fn_from_number(&filename, path, number);
	assert(full_fn);
	printf("Validating file %s ... %s", filename, progress ? BLANK : "");
	fflush(stdout);
#ifdef __CYGWIN__
	/* We don't need write access, but some kernels require that
	 * the file descriptor passed to fdatasync(2) to be writable.
	 */
	f = fopen(full_fn, "rb+");
#else
	f = fopen(full_fn, "rb");
#endif
	if (!f)
		err(errno, "Can't open file %s", full_fn);
	fd = fileno(f);
	assert(fd >= 0);

	/* If the kernel follows our advice, f3read won't ever read from cache
	 * even when testing small memory cards without a remount, and
	 * we should have a better reading-speed measurement.
	 */
	assert(!fdatasync(fd));
	assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_DONTNEED));

	/* Obtain initial time. */
	assert(!gettimeofday(&t1, NULL));
	/* Help the kernel to help us. */
	assert(!posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL));

	sectors_read = fread(sector, SECTOR_SIZE, 1, f);
	final_errno = errno;
	expected_offset = (uint64_t)number * GIGABYTES;
	while (sectors_read > 0) {
		uint64_t rn;
		int error_count, i;

		assert(sectors_read == 1);

		rn = sector[0];
		error_count = 0;
		for (i = 1; error_count <= TOLERANCE && i < num_int64; i++) {
			rn = random_number(rn);
			if (rn != sector[i])
				error_count++;
		}

		if (expected_offset == sector[0]) {
			if (error_count == 0)
				(*ptr_ok)++;
			else if (error_count <= TOLERANCE)
				(*ptr_changed)++;
			else
				(*ptr_corrupted)++;
		} else if (error_count <= TOLERANCE)
			(*ptr_overwritten)++;
		else
			(*ptr_corrupted)++;

		sectors_read = fread(sector, SECTOR_SIZE, 1, f);
		final_errno = errno;
		expected_offset += SECTOR_SIZE;

		if (progress) {
			struct timeval pt2;
			assert(!gettimeofday(&pt2, NULL));
			/* Avoid often printouts. */
			if (delay_ms(&pt1, &pt2) >= 200) {
				PRINT_STATUS(CLEAR);
				fflush(stdout);
				pt1 = pt2;
			}
		}
	}
	assert(!gettimeofday(&t2, NULL));
	update_dt(ptr_dt, &t1, &t2);

	*ptr_read_all = feof(f);
	*ptr_size = ftell(f);

	PRINT_STATUS(progress ? CLEAR : "");
	if (!*ptr_read_all) {
		assert(ferror(f));
		printf(" - NOT fully read due to \"%s\"",
			strerror(final_errno));
	}
	printf("\n");

	fclose(f);
	free(full_fn);
}

static void report(const char *prefix, uint64_t i)
{
	double f = (double) (i * SECTOR_SIZE);
	const char *unit = adjust_unit(&f);
	printf("%s %.2f %s (%" PRIu64 " sectors)\n", prefix, f, unit, i);
}
int main( int i_argc, char **ppsz_argv )
{
    char *client_socket_tmpl = "dvblastctl.clientsock.XXXXXX";
    char *psz_srv_socket = NULL;
    int i;
    char *p_cmd, *p_arg1 = NULL, *p_arg2 = NULL;
    ssize_t i_size;
    struct sockaddr_un sun_client, sun_server;
    uint8_t p_buffer[COMM_BUFFER_SIZE];
    uint8_t *p_data = p_buffer + COMM_HEADER_SIZE;
    uint16_t i_pid = 0;
    struct dvblastctl_option opt = { 0, 0, 0 };

    for ( ; ; )
    {
        int c;

        static const struct option long_options[] =
        {
            {"remote-socket", required_argument, NULL, 'r'},
            {"print", required_argument, NULL, 'x'},
            {"help", no_argument, NULL, 'h'},
            {0, 0, 0, 0}
        };

        if ( (c = getopt_long(i_argc, ppsz_argv, "r:x:h", long_options, NULL)) == -1 )
            break;

        switch ( c )
        {
        case 'r':
            psz_srv_socket = optarg;
            break;

        case 'x':
            if ( !strcmp(optarg, "text") )
                i_print_type = PRINT_TEXT;
            else if ( !strcmp(optarg, "xml") )
                i_print_type = PRINT_XML;
            else
                msg_Warn( NULL, "unrecognized print type %s", optarg );
            /* Make stdout line-buffered */
            setvbuf(stdout, NULL, _IOLBF, 0);
            break;

        case 'h':
        default:
            usage();
        }
    }

    /* Validate commands */
#define usage_error(msg, ...) \
        do { \
            msg_Err( NULL, msg, ##__VA_ARGS__ ); \
            usage(); \
        } while(0)
    p_cmd  = ppsz_argv[optind];
    p_arg1 = ppsz_argv[optind + 1];
    p_arg2 = ppsz_argv[optind + 2];

    if ( !psz_srv_socket )
        usage_error( "Remote socket is not set.\n" );

    if ( !p_cmd )
       usage_error( "Command is not set.\n" );

    i = 0;
    do {
        if ( streq(ppsz_argv[optind], options[i].opt) )
        {
            opt = options[i];
            break;
        }
    } while ( options[++i].opt );

    if ( !opt.opt )
        usage_error( "Unknown command: %s\n", p_cmd );

    if ( opt.nparams == 1 && !p_arg1 )
        usage_error( "%s option needs parameter.\n", opt.opt );

    if ( opt.nparams == 2 && (!p_arg1 || !p_arg2) )
        usage_error( "%s option needs two parameters.\n", opt.opt );
#undef usage_error

    /* Create client socket name */
    char *tmpdir = getenv("TMPDIR");
    snprintf( psz_client_socket, PATH_MAX - 1, "%s/%s",
       tmpdir ? tmpdir : "/tmp", client_socket_tmpl );
    psz_client_socket[PATH_MAX - 1] = '\0';

    int tmp_fd = mkstemp(psz_client_socket);
    if ( tmp_fd > -1 ) {
        close(tmp_fd);
        unlink(psz_client_socket);
    } else {
        return_error( "Cannot build UNIX socket %s (%s)", psz_client_socket, strerror(errno) );
    }

    if ( (i_fd = socket( AF_UNIX, SOCK_DGRAM, 0 )) < 0 )
        return_error( "Cannot create UNIX socket (%s)", strerror(errno) );

    i = COMM_MAX_MSG_CHUNK;
    setsockopt( i_fd, SOL_SOCKET, SO_RCVBUF, &i, sizeof(i) );

    memset( &sun_client, 0, sizeof(sun_client) );
    sun_client.sun_family = AF_UNIX;
    strncpy( sun_client.sun_path, psz_client_socket,
             sizeof(sun_client.sun_path) );
    sun_client.sun_path[sizeof(sun_client.sun_path) - 1] = '\0';

    if ( bind( i_fd, (struct sockaddr *)&sun_client,
               SUN_LEN(&sun_client) ) < 0 )
        return_error( "Cannot bind (%s)", strerror(errno) );

    memset( &sun_server, 0, sizeof(sun_server) );
    sun_server.sun_family = AF_UNIX;
    strncpy( sun_server.sun_path, psz_srv_socket, sizeof(sun_server.sun_path) );
    sun_server.sun_path[sizeof(sun_server.sun_path) - 1] = '\0';

    p_buffer[0] = COMM_HEADER_MAGIC;
    p_buffer[1] = opt.cmd;
    memset( p_buffer + 2, 0, COMM_HEADER_SIZE - 2 );
    i_size = COMM_HEADER_SIZE;

    /* Handle commands that send parameters */
    switch ( opt.cmd )
    {
    case CMD_INVALID:
    case CMD_RELOAD:
    case CMD_SHUTDOWN:
    case CMD_FRONTEND_STATUS:
    case CMD_MMI_STATUS:
    case CMD_GET_PAT:
    case CMD_GET_CAT:
    case CMD_GET_NIT:
    case CMD_GET_SDT:
    case CMD_GET_PIDS:
        /* These commands need no special handling because they have no parameters */
        break;
    case CMD_GET_PMT:
    {
        uint16_t i_sid = atoi(p_arg1);
        i_size = COMM_HEADER_SIZE + 2;
        p_data[0] = (uint8_t)((i_sid >> 8) & 0xff);
        p_data[1] = (uint8_t)(i_sid & 0xff);
        break;
    }
    case CMD_GET_PID:
    {
        i_pid = (uint16_t)atoi(p_arg1);
        i_size = COMM_HEADER_SIZE + 2;
        p_data[0] = (uint8_t)((i_pid >> 8) & 0xff);
        p_data[1] = (uint8_t)(i_pid & 0xff);
        break;
    }
    case CMD_MMI_SEND_TEXT:
    {
        struct cmd_mmi_send *p_cmd = (struct cmd_mmi_send *)p_data;
        p_cmd->i_slot = atoi(p_arg1);

        en50221_mmi_object_t object;
        object.i_object_type = EN50221_MMI_ANSW;
        if ( !p_arg2 || p_arg2[0] == '\0' )
        {
             object.u.answ.b_ok = 0;
             object.u.answ.psz_answ = "";
        }
        else
        {
             object.u.answ.b_ok = 1;
             object.u.answ.psz_answ = p_arg2;
        }
        i_size = COMM_BUFFER_SIZE - COMM_HEADER_SIZE
                  - ((void *)&p_cmd->object - (void *)p_cmd);
        if ( en50221_SerializeMMIObject( (uint8_t *)&p_cmd->object,
                                         &i_size, &object ) == -1 )
            return_error( "Comm buffer is too small" );

        i_size += COMM_HEADER_SIZE
                   + ((void *)&p_cmd->object - (void *)p_cmd);
        break;
    }
    case CMD_MMI_SEND_CHOICE:
    {
        struct cmd_mmi_send *p_cmd = (struct cmd_mmi_send *)p_data;
        p_cmd->i_slot = atoi(p_arg1);

        i_size = COMM_HEADER_SIZE + sizeof(struct cmd_mmi_send);
        p_cmd->object.i_object_type = EN50221_MMI_MENU_ANSW;
        p_cmd->object.u.menu_answ.i_choice = atoi(p_arg2);
        break;
    }
    case CMD_MMI_SLOT_STATUS:
    case CMD_MMI_OPEN:
    case CMD_MMI_CLOSE:
    case CMD_MMI_RECV:
    {
        p_data[0] = atoi(p_arg1);
        i_size = COMM_HEADER_SIZE + 1;
        break;
    }
    default:
        /* This should not happen */
        return_error( "Unhandled option (%d)", opt.cmd );
    }

    /* Send command and receive answer */
    if ( sendto( i_fd, p_buffer, i_size, 0, (struct sockaddr *)&sun_server,
                 SUN_LEN(&sun_server) ) < 0 )
        return_error( "Cannot send comm socket (%s)", strerror(errno) );

    uint32_t i_packet_size = 0, i_received = 0;
    do {
        i_size = recv( i_fd, p_buffer + i_received, COMM_MAX_MSG_CHUNK, 0 );
        if ( i_size == -1 )
            break;
        if ( !i_packet_size ) {
            uint32_t *p_packet_size = (uint32_t *)&p_buffer[4];
            i_packet_size = *p_packet_size;
            if ( i_packet_size > COMM_BUFFER_SIZE ) {
                i_size = -1;
                break;
            }
        }
        i_received += i_size;
    } while ( i_received < i_packet_size );

    clean_client_socket();
    if ( i_size < COMM_HEADER_SIZE )
        return_error( "Cannot recv from comm socket, size:%zd (%s)", i_size, strerror(errno) );

    /* Process answer */
    if ( p_buffer[0] != COMM_HEADER_MAGIC )
        return_error( "Wrong protocol version 0x%x", p_buffer[0] );

    now = mdate();

    ctl_cmd_answer_t c_answer = p_buffer[1];
    switch ( c_answer )
    {
    case RET_OK:
        break;

    case RET_MMI_WAIT:
        exit(252);
        break;

    case RET_ERR:
        return_error( "Request failed" );
        break;

    case RET_HUH:
        return_error( "Internal error" );
        break;

    case RET_NODATA:
        return_error( "No data" );
        break;

    case RET_PAT:
    case RET_CAT:
    case RET_NIT:
    case RET_SDT:
    {
        uint8_t *p_flat_data = p_buffer + COMM_HEADER_SIZE;
        unsigned int i_flat_data_size = i_size - COMM_HEADER_SIZE;
        uint8_t **pp_sections = psi_unpack_sections( p_flat_data, i_flat_data_size );

        switch( c_answer )
        {
            case RET_PAT: pat_table_print( pp_sections, psi_print, NULL, i_print_type ); break;
            case RET_CAT: cat_table_print( pp_sections, psi_print, NULL, i_print_type ); break;
            case RET_NIT: nit_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break;
            case RET_SDT: sdt_table_print( pp_sections, psi_print, NULL, psi_iconv, NULL, i_print_type ); break;
            default: break; /* Can't happen */
        }

        psi_table_free( pp_sections );
        free( pp_sections );
        break;
    }

    case RET_PMT:
    {
        pmt_print( p_data, psi_print, NULL, psi_iconv, NULL, i_print_type );
        break;
    }

    case RET_PID:
    {
        print_pids_header();
        print_pid( i_pid, (ts_pid_info_t *)p_data );
        print_pids_footer();
        break;
    }

    case RET_PIDS:
    {
        print_pids( p_data );
        break;
    }

    case RET_FRONTEND_STATUS:
    {
        int ret = 1;
        struct ret_frontend_status *p_ret =
            (struct ret_frontend_status *)&p_buffer[COMM_HEADER_SIZE];
        if ( i_size != COMM_HEADER_SIZE + sizeof(struct ret_frontend_status) )
            return_error( "Bad frontend status" );

        if ( i_print_type == PRINT_XML )
            printf("<FRONTEND>\n");

#define PRINT_TYPE( x ) \
    do { \
        if ( i_print_type == PRINT_XML ) \
            printf( " <TYPE type=\"%s\"/>\n", STRINGIFY(x) ); \
        else \
            printf( "type: %s\n", STRINGIFY(x) ); \
    } while(0)
        switch ( p_ret->info.type )
        {
        case FE_QPSK: PRINT_TYPE(QPSK); break;
        case FE_QAM : PRINT_TYPE(QAM); break;
        case FE_OFDM: PRINT_TYPE(OFDM); break;
        case FE_ATSC: PRINT_TYPE(ATSC); break;
        default     : PRINT_TYPE(UNKNOWN); break;
        }
#undef PRINT_TYPE

#define PRINT_INFO( x ) \
    do { \
        if ( i_print_type == PRINT_XML ) \
            printf( " <SETTING %s=\"%u\"/>\n", STRINGIFY(x), p_ret->info.x ); \
        else \
            printf( "%s: %u\n", STRINGIFY(x), p_ret->info.x ); \
    } while(0)
        PRINT_INFO( frequency_min );
        PRINT_INFO( frequency_max );
        PRINT_INFO( frequency_stepsize );
        PRINT_INFO( frequency_tolerance );
        PRINT_INFO( symbol_rate_min );
        PRINT_INFO( symbol_rate_max );
        PRINT_INFO( symbol_rate_tolerance );
        PRINT_INFO( notifier_delay );
#undef PRINT_INFO

        if ( i_print_type == PRINT_TEXT )
            printf("\ncapability list:\n");

#define PRINT_CAPS( x ) \
    do { \
        if ( p_ret->info.caps & (FE_##x) ) { \
            if ( i_print_type == PRINT_XML ) { \
                printf( " <CAPABILITY %s=\"1\"/>\n", STRINGIFY(x) ); \
            } else { \
                printf( "%s\n", STRINGIFY(x) ); \
            } \
        } \
    } while(0)
        PRINT_CAPS( IS_STUPID );
        PRINT_CAPS( CAN_INVERSION_AUTO );
        PRINT_CAPS( CAN_FEC_1_2 );
        PRINT_CAPS( CAN_FEC_2_3 );
        PRINT_CAPS( CAN_FEC_3_4 );
        PRINT_CAPS( CAN_FEC_4_5 );
        PRINT_CAPS( CAN_FEC_5_6 );
        PRINT_CAPS( CAN_FEC_6_7 );
        PRINT_CAPS( CAN_FEC_7_8 );
        PRINT_CAPS( CAN_FEC_8_9 );
        PRINT_CAPS( CAN_FEC_AUTO );
        PRINT_CAPS( CAN_QPSK );
        PRINT_CAPS( CAN_QAM_16 );
        PRINT_CAPS( CAN_QAM_32 );
        PRINT_CAPS( CAN_QAM_64 );
        PRINT_CAPS( CAN_QAM_128 );
        PRINT_CAPS( CAN_QAM_256 );
        PRINT_CAPS( CAN_QAM_AUTO );
        PRINT_CAPS( CAN_TRANSMISSION_MODE_AUTO );
        PRINT_CAPS( CAN_BANDWIDTH_AUTO );
        PRINT_CAPS( CAN_GUARD_INTERVAL_AUTO );
        PRINT_CAPS( CAN_HIERARCHY_AUTO );
        PRINT_CAPS( CAN_MUTE_TS );

#define DVBAPI_VERSION ((DVB_API_VERSION)*100+(DVB_API_VERSION_MINOR))

#if DVBAPI_VERSION >= 301
        PRINT_CAPS( CAN_8VSB );
        PRINT_CAPS( CAN_16VSB );
        PRINT_CAPS( NEEDS_BENDING );
        PRINT_CAPS( CAN_RECOVER );
#endif
#if DVBAPI_VERSION >= 500
        PRINT_CAPS( HAS_EXTENDED_CAPS );
#endif
#if DVBAPI_VERSION >= 501
        PRINT_CAPS( CAN_2G_MODULATION );
#endif
#undef PRINT_CAPS

        if ( i_print_type == PRINT_TEXT )
            printf("\nstatus:\n");

#define PRINT_STATUS( x ) \
    do { \
        if ( p_ret->i_status & (FE_##x) ) { \
            if ( i_print_type == PRINT_XML ) { \
                printf( " <STATUS status=\"%s\"/>\n", STRINGIFY(x) ); \
            } else { \
                printf( "%s\n", STRINGIFY(x) ); \
            } \
        } \
    } while(0)
        PRINT_STATUS( HAS_SIGNAL );
        PRINT_STATUS( HAS_CARRIER );
        PRINT_STATUS( HAS_VITERBI );
        PRINT_STATUS( HAS_SYNC );
        PRINT_STATUS( HAS_LOCK );
        PRINT_STATUS( REINIT );
#undef PRINT_STATUS

        if ( p_ret->i_status & FE_HAS_LOCK )
        {
            if ( i_print_type == PRINT_XML )
            {
                printf(" <VALUE bit_error_rate=\"%d\"/>\n", p_ret->i_ber);
                printf(" <VALUE signal_strength=\"%d\"/>\n", p_ret->i_strength);
                printf(" <VALUE SNR=\"%d\"/>\n", p_ret->i_snr);
            } else {
                printf("\nBit error rate: %d\n", p_ret->i_ber);
                printf("Signal strength: %d\n", p_ret->i_strength);
                printf("SNR: %d\n", p_ret->i_snr);
            }
            ret = 0;
        }

        if ( i_print_type == PRINT_XML )
            printf("</FRONTEND>\n" );

        exit(ret);
        break;
    }

    case RET_MMI_STATUS:
    {
        struct ret_mmi_status *p_ret =
            (struct ret_mmi_status *)&p_buffer[COMM_HEADER_SIZE];
        if ( i_size != COMM_HEADER_SIZE + sizeof(struct ret_mmi_status) )
            return_error( "Bad MMI status" );

        printf("CA interface with %d %s, type:\n", p_ret->caps.slot_num,
               p_ret->caps.slot_num == 1 ? "slot" : "slots");
#define PRINT_CAPS( x, s )                                              \
        if ( p_ret->caps.slot_type & (CA_##x) )                         \
            printf(s "\n");
        PRINT_CAPS( CI, "CI high level interface" );
        PRINT_CAPS( CI_LINK, "CI link layer level interface" );
        PRINT_CAPS( CI_PHYS, "CI physical layer level interface (not supported)" );
        PRINT_CAPS( DESCR, "built-in descrambler" );
        PRINT_CAPS( SC, "simple smartcard interface" );
#undef PRINT_CAPS

        printf("\n%d available %s\n", p_ret->caps.descr_num,
            p_ret->caps.descr_num == 1 ? "descrambler (key)" :
                                         "descramblers (keys)");
#define PRINT_DESC( x )                                                 \
        if ( p_ret->caps.descr_type & (CA_##x) )                        \
            printf( STRINGIFY(x) "\n" );
        PRINT_DESC( ECD );
        PRINT_DESC( NDS );
        PRINT_DESC( DSS );
#undef PRINT_DESC

        exit( p_ret->caps.slot_num );
        break;
    }

    case RET_MMI_SLOT_STATUS:
    {
        struct ret_mmi_slot_status *p_ret =
            (struct ret_mmi_slot_status *)&p_buffer[COMM_HEADER_SIZE];
        if ( i_size < COMM_HEADER_SIZE + sizeof(struct ret_mmi_slot_status) )
            return_error( "Bad MMI slot status" );

        printf("CA slot #%u: ", p_ret->sinfo.num);

#define PRINT_TYPE( x, s )                                                  \
        if ( p_ret->sinfo.type & (CA_##x) )                                 \
            printf(s);

        PRINT_TYPE( CI, "high level, " );
        PRINT_TYPE( CI_LINK, "link layer level, " );
        PRINT_TYPE( CI_PHYS, "physical layer level, " );
#undef PRINT_TYPE

        if ( p_ret->sinfo.flags & CA_CI_MODULE_READY )
        {
            printf("module present and ready\n");
            exit(0);
        }

        if ( p_ret->sinfo.flags & CA_CI_MODULE_PRESENT )
            printf("module present, not ready\n");
        else
            printf("module not present\n");

        exit(1);
        break;
    }

    case RET_MMI_RECV:
    {
        struct ret_mmi_recv *p_ret =
            (struct ret_mmi_recv *)&p_buffer[COMM_HEADER_SIZE];
        if ( i_size < COMM_HEADER_SIZE + sizeof(struct ret_mmi_recv) )
            return_error( "Bad MMI recv" );

        en50221_UnserializeMMIObject( &p_ret->object, i_size
          - COMM_HEADER_SIZE - ((void *)&p_ret->object - (void *)p_ret) );

        switch ( p_ret->object.i_object_type )
        {
        case EN50221_MMI_ENQ:
            printf("%s\n", p_ret->object.u.enq.psz_text);
            printf("(empty to cancel)\n");
            exit(p_ret->object.u.enq.b_blind ? 253 : 254);
            break;

        case EN50221_MMI_MENU:
            printf("%s\n", p_ret->object.u.menu.psz_title);
            printf("%s\n", p_ret->object.u.menu.psz_subtitle);
            printf("0 - Cancel\n");
            for ( i = 0; i < p_ret->object.u.menu.i_choices; i++ )
                printf("%d - %s\n", i + 1,
                       p_ret->object.u.menu.ppsz_choices[i]);
            printf("%s\n", p_ret->object.u.menu.psz_bottom);
            exit(p_ret->object.u.menu.i_choices);
            break;

        case EN50221_MMI_LIST:
            printf("%s\n", p_ret->object.u.menu.psz_title);
            printf("%s\n", p_ret->object.u.menu.psz_subtitle);
            for ( i = 0; i < p_ret->object.u.menu.i_choices; i++ )
                printf("%s\n", p_ret->object.u.menu.ppsz_choices[i]);
            printf("%s\n", p_ret->object.u.menu.psz_bottom);
            printf("(0 to cancel)\n");
            exit(0);
            break;

        default:
            return_error( "Unknown MMI object" );
            break;
        }

        exit(255);
        break;
    }

    default:
        return_error( "Unknown command answer: %u", c_answer );
    }

    return 0;
}
Example #5
0
/*
** Main function.
*/
int main(void)
{
    unsigned int numByteChunks = 0;
    unsigned char *pBuffer = NULL;
    unsigned int remainBytes = 0;

    /* Configure and enable the MMU. */
    MMUConfigAndEnable();

    /* Enable all levels of Cache. */
    CacheEnable(CACHE_ALL);

    /* Configuring the system clocks for EDMA. */
    EDMAModuleClkConfig();

    /* Configuring the system clocks for UART0 instance. */
    UART0ModuleClkConfig();

    /* Performing Pin Multiplexing for UART0 instance. */
    UARTPinMuxSetup(0);

    /* Enabling IRQ in CPSR of ARM processor. */
    IntMasterIRQEnable();

    /* Initializing the ARM Interrupt Controller. */
    IntAINTCInit();

    /* Initializing the EDMA. */
    EDMA3Initialize();

    /* Initializing the UART0 instance for use. */
    UARTInitialize();

    /* Select the console type based on compile time check */
    ConsoleUtilsSetType(CONSOLE_UART);

    /*
    ** Configuring the EDMA.
    */

    /* Request DMA Channel and TCC for UART Transmit*/
    EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,
                        EDMA3_UART_TX_CHA_NUM, EDMA3_UART_TX_CHA_NUM,
                        EVT_QUEUE_NUM);

    /* Registering Callback Function for TX*/
    cb_Fxn[EDMA3_UART_TX_CHA_NUM] = &callback;

    /* Request DMA Channel and TCC for UART Receive */
    EDMA3RequestChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,
                        EDMA3_UART_RX_CHA_NUM, EDMA3_UART_RX_CHA_NUM,
                        EVT_QUEUE_NUM);

    /* Registering Callback Function for RX*/
    cb_Fxn[EDMA3_UART_RX_CHA_NUM] = &callback;

    /******************** Transmission of a string **************************/

    numByteChunks = (sizeof(welcome) - 1) / txBytesPerEvent;
    remainBytes = (sizeof(welcome) - 1) % txBytesPerEvent;

    /* Configuring EDMA PaRAM sets to transmit data. */
    UARTTxEDMAPaRAMSetConfig(welcome,
                             numByteChunks * txBytesPerEvent,
                             EDMA3_UART_TX_CHA_NUM,
                             EDMA3CC_OPT(DUMMY_CH_NUM),
                             EDMA3_UART_TX_CHA_NUM);

    /* Configuring the PaRAM set for Dummy Transfer. */
    TxDummyPaRAMConfEnable();

    /* Enable EDMA Transfer */
    EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM,
                        EDMA3_TRIG_MODE_EVENT);

    /* Wait for return from callback */
    while(0 == clBackFlag);
    clBackFlag = 0;

    /* Remaining bytes are transferred through polling method. */
    if(0 != remainBytes)
    {
        pBuffer = welcome + (sizeof(welcome) - 1) - remainBytes;
        UARTPuts((char*)pBuffer, remainBytes);
    }

    /******************** Transmission of a string **************************/

    numByteChunks = (sizeof(intent) - 1) / txBytesPerEvent;
    remainBytes = (sizeof(intent) - 1) % txBytesPerEvent;

    /* Enabling DMA Mode 1. */
    UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE);

    /* Configuring EDMA PaRAM sets to transmit data. */
    UARTTxEDMAPaRAMSetConfig(intent,
                             numByteChunks * txBytesPerEvent,
                             EDMA3_UART_TX_CHA_NUM,
                             EDMA3CC_OPT(DUMMY_CH_NUM),
                             EDMA3_UART_TX_CHA_NUM);

    /* Configuring the PaRAM set for Dummy Transfer. */
    TxDummyPaRAMConfEnable();

    /* Enable EDMA Transfer */
    EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM,
                        EDMA3_TRIG_MODE_EVENT);

    /* Wait for return from callback */
    while(0 == clBackFlag);
    clBackFlag = 0;

    /* Remaining bytes are transferred through polling method. */
    if(0 != remainBytes)
    {
        pBuffer = intent + (sizeof(intent) - 1) - remainBytes;
        UARTPuts((char*)pBuffer, remainBytes);
    }

    /******************** Transmission of a string **************************/

    numByteChunks = (sizeof(enter) - 1) / txBytesPerEvent;
    remainBytes = (sizeof(enter) - 1) % txBytesPerEvent;

    /* Enabling DMA Mode 1. */
    UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE);

    /* Configuring EDMA PaRAM sets to transmit data. */
    UARTTxEDMAPaRAMSetConfig(enter,
                             numByteChunks * txBytesPerEvent,
                             EDMA3_UART_TX_CHA_NUM,
                             EDMA3CC_OPT(DUMMY_CH_NUM),
                             EDMA3_UART_TX_CHA_NUM);

    /* Configuring the PaRAM set for Dummy Transfer. */
    TxDummyPaRAMConfEnable();

    /* Enable EDMA Transfer */
    EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM,
                        EDMA3_TRIG_MODE_EVENT);

    /* Wait for return from callback */
    while(0 == clBackFlag);
    clBackFlag = 0;

    /* Remaining bytes are transferred through polling method. */
    if(0 != remainBytes)
    {
        pBuffer = enter + (sizeof(enter) - 1) - remainBytes;
        UARTPuts((char*)pBuffer, remainBytes);
    }

    /********************* Receiving Data from User *************************/

    /* Enabling DMA Mode 1. */
    UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE);

    /* Configuring the PaRAM set for reception. */
    UARTRxEDMAPaRAMSetConfig(rxBuffer,
                             NUM_RX_BYTES,
                             EDMA3_UART_RX_CHA_NUM,
                             0xFFFF,
                             EDMA3_UART_RX_CHA_NUM);

    /* Enable EDMA Transfer */
    EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_RX_CHA_NUM,
                        EDMA3_TRIG_MODE_EVENT);

    /* Wait for return from callback */
    while(0 == clBackFlag);
    clBackFlag = 0;

    /******************* Echoing received bytes *****************************/

    numByteChunks = (NUM_RX_BYTES) / txBytesPerEvent;
    remainBytes = (NUM_RX_BYTES) % txBytesPerEvent;

    /* Enabling DMA Mode 1. */
    UARTDMAEnable(UART_INSTANCE_BASE_ADD, UART_DMA_MODE_1_ENABLE);

    /* Configuring EDMA PaRAM sets to transmit data. */
    UARTTxEDMAPaRAMSetConfig(rxBuffer,
                             numByteChunks * txBytesPerEvent,
                             EDMA3_UART_TX_CHA_NUM,
                             EDMA3CC_OPT(DUMMY_CH_NUM),
                             EDMA3_UART_TX_CHA_NUM);

    /* Configuring the PaRAM set for Dummy Transfer. */
    TxDummyPaRAMConfEnable();

    /* Enable EDMA Transfer */
    EDMA3EnableTransfer(SOC_EDMA30CC_0_REGS, EDMA3_UART_TX_CHA_NUM,
                        EDMA3_TRIG_MODE_EVENT);

    /* Wait for return from callback */
    while(0 == clBackFlag);
    clBackFlag = 0;

    /* Remaining bytes are transferred through polling method. */
    if(0 != remainBytes)
    {
        pBuffer = rxBuffer + NUM_RX_BYTES - remainBytes;
        UARTPuts((char*)pBuffer, remainBytes);
    }

    /******************* Freeing of allocated channels **********************/

    /* Free EDMA3 Channels for TX and RX */
    EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,
                     EDMA3_UART_TX_CHA_NUM, EDMA3_TRIG_MODE_EVENT,
                     EDMA3_UART_TX_CHA_NUM, EVT_QUEUE_NUM);

    EDMA3FreeChannel(SOC_EDMA30CC_0_REGS, EDMA3_CHANNEL_TYPE_DMA,
                     EDMA3_UART_RX_CHA_NUM, EDMA3_TRIG_MODE_EVENT,
                     EDMA3_UART_RX_CHA_NUM, EVT_QUEUE_NUM);

    /* Support for Automation Testing. */
    PRINT_STATUS(S_PASS);

    while(1);
}
Example #6
0
int
main(int argc, char * const argv[])
{
	int ch;
	int fdr, fdw;
	off_t t, d, start, len;
	size_t i, j;
	int error, state;
	u_char *buf;
	u_int sectorsize;
	off_t stripesize;
	time_t t1, t2;
	struct stat sb;
	u_int n, snapshot = 60;

	while ((ch = getopt(argc, argv, "b:r:w:s:")) != -1) {
		switch (ch) {
		case 'b':
			bigsize = strtoul(optarg, NULL, 0);
			break;
		case 'r':
			rworklist = strdup(optarg);
			if (rworklist == NULL)
				err(1, "Cannot allocate enough memory");
			break;
		case 's':
			snapshot = strtoul(optarg, NULL, 0);
			break;
		case 'w':
			wworklist = strdup(optarg);
			if (wworklist == NULL)
				err(1, "Cannot allocate enough memory");
			break;
		default:
			usage();
			/* NOTREACHED */
		}
	}
	argc -= optind;
	argv += optind;

	if (argc < 1 || argc > 2)
		usage();

	fdr = open(argv[0], O_RDONLY);
	if (fdr < 0)
		err(1, "Cannot open read descriptor %s", argv[0]);

	error = fstat(fdr, &sb);
	if (error < 0)
		err(1, "fstat failed");
	if (S_ISBLK(sb.st_mode) || S_ISCHR(sb.st_mode)) {
		error = ioctl(fdr, DIOCGSECTORSIZE, &sectorsize);
		if (error < 0)
			err(1, "DIOCGSECTORSIZE failed");

		error = ioctl(fdr, DIOCGSTRIPESIZE, &stripesize);
		if (error == 0 && stripesize > sectorsize)
			sectorsize = stripesize;

		minsize = sectorsize;
		bigsize = rounddown(bigsize, sectorsize);

		error = ioctl(fdr, DIOCGMEDIASIZE, &t);
		if (error < 0)
			err(1, "DIOCGMEDIASIZE failed");
	} else {
		t = sb.st_size;
	}

	if (bigsize < minsize)
		bigsize = minsize;

	for (ch = 0; (bigsize >> ch) > minsize; ch++)
		continue;
	medsize = bigsize >> (ch / 2);
	medsize = rounddown(medsize, minsize);

	fprintf(stderr, "Bigsize = %zu, medsize = %zu, minsize = %zu\n",
	    bigsize, medsize, minsize);

	buf = malloc(bigsize);
	if (buf == NULL)
		err(1, "Cannot allocate %zu bytes buffer", bigsize);

	if (argc > 1) {
		fdw = open(argv[1], O_WRONLY | O_CREAT, DEFFILEMODE);
		if (fdw < 0)
			err(1, "Cannot open write descriptor %s", argv[1]);
		if (ftruncate(fdw, t) < 0)
			err(1, "Cannot truncate output %s to %jd bytes",
			    argv[1], (intmax_t)t);
	} else
		fdw = -1;

	if (rworklist != NULL) {
		d = read_worklist(t);
	} else {
		new_lump(0, t, 0);
		d = 0;
	}
	if (wworklist != NULL)
		signal(SIGINT, sighandler);

	t1 = 0;
	start = len = i = state = 0;
	PRINT_HEADER;
	n = 0;
	for (;;) {
		lp = TAILQ_FIRST(&lumps);
		if (lp == NULL)
			break;
		while (lp->len > 0 && !aborting) {
			/* These are only copied for printing stats */
			start = lp->start;
			len = lp->len;
			state = lp->state;

			i = MIN(lp->len, (off_t)bigsize);
			if (lp->state == 1)
				i = MIN(lp->len, (off_t)medsize);
			if (lp->state > 1)
				i = MIN(lp->len, (off_t)minsize);
			time(&t2);
			if (t1 != t2 || lp->len < (off_t)bigsize) {
				PRINT_STATUS(start, i, len, state, d, t);
				t1 = t2;
				if (++n == snapshot) {
					save_worklist();
					n = 0;
				}
			}
			if (i == 0) {
				errx(1, "BOGUS i %10jd", (intmax_t)i);
			}
			fflush(stdout);
			j = pread(fdr, buf, i, lp->start);
			if (j == i) {
				d += i;
				if (fdw >= 0)
					j = pwrite(fdw, buf, i, lp->start);
				else
					j = i;
				if (j != i)
					printf("\nWrite error at %jd/%zu\n",
					    lp->start, i);
				lp->start += i;
				lp->len -= i;
				continue;
			}
			printf("\n%jd %zu failed (%s)\n",
			    lp->start, i, strerror(errno));
			if (errno == EINVAL) {
				printf("read() size too big? Try with -b 131072");
				aborting = 1;
			}
			if (errno == ENXIO)
				aborting = 1;
			new_lump(lp->start, i, lp->state + 1);
			lp->start += i;
			lp->len -= i;
		}
		if (aborting) {
			save_worklist();
			return (0);
		}
		TAILQ_REMOVE(&lumps, lp, list);
		free(lp);
	}
	PRINT_STATUS(start, i, len, state, d, t);
	save_worklist();
	printf("\nCompleted\n");
	return (0);
}
Example #7
0
File: main.cpp Project: CCJY/coliru
int main()
{
    door_sensor   door_sensor;
    window_sensor window_sensor;
    alarm         alarm;
    spotlight     spotlight;

    std::cout << "Everything's off" << std::endl;
    PRINT_STATUS(door_sensor);
    PRINT_STATUS(window_sensor);
    PRINT_STATUS(alarm);
    PRINT_STATUS(spotlight);
    
    std::cout << "Turn on door sensor" << std::endl;
    door_sensor = 1;
    PRINT_STATUS(door_sensor);
    PRINT_STATUS(window_sensor);
    std::cout << "Turn on window sensor" << std::endl;
    window_sensor = 1;
    PRINT_STATUS(door_sensor);
    PRINT_STATUS(window_sensor);
    std::cout << "Turn on alarm" << std::endl;
    alarm = 1;
    PRINT_STATUS(alarm);
    PRINT_STATUS(spotlight);
    std::cout << "Turn on spotlight" << std::endl;
    spotlight = 1;
    PRINT_STATUS(alarm);
    PRINT_STATUS(spotlight);
    
    return 0;
}