Exemplo n.º 1
0
/* This function is invoked by the main CAmkES thread in this component. */
int run(void)
{
    int error = camkes_io_port_ops(&io_port_ops);
    assert(!error);

    /* Use the dataport address */
    void *bga_ptr = (void *)mock_hdmi;

    bga = bga_init(bga_ptr, out16, in16);
    bga_set_mode(bga, 1024, 768, 24); /* 1024x768 resolution at 24 BPP */

    ringbuffer_t *low = rb_new((void *)low_input, sizeof(*low_input));
    if (low == NULL) {
        abort();
    }

    ringbuffer_t *high = rb_new((void *)high_input, sizeof(*high_input));
    if (high == NULL) {
        abort();
    }

    borders();

    /* Check both inputs for data and pass it to the relevant framebuffer. */
    while (true) {
        char c;

        if ((c = (char)rb_poll_byte(low)) != 0) {
            write_low(c);
        }

        if ((c = (char)rb_poll_byte(high)) != 0) {
            write_high(c);
        }
    }

    return 0;
}
Exemplo n.º 2
0
int main(int argc, char* argv[])
{
    int opt, option_index;
    int test_num  = -1;
    int level = -1;
    context_t ctx = NULL;
    security_context_t ctx_check = NULL;
    char *path = NULL;
    char *log_path = NULL;
    time_t t;

    static struct option long_options[] = {
      {"output",  required_argument, 0, 'o'},
      {"test",    required_argument, 0, 't'},
      {"file",    required_argument, 0, 'f'},
      {0, 0, 0, 0}
    };
    
    while ((opt = getopt_long(argc, argv, "o:t:f:",
                              long_options, &option_index)) != -1)
    {
        switch (opt) {            
            case 'o':
                log_path = optarg;
                if (freopen(log_path, "a+", stdout) == NULL) {
                    exit(-1);
                }
                if (freopen(log_path, "a+", stderr) == NULL) {
                    exit(-1);
                }
                break;
            case 't':
                test_num = atoi(optarg);
                break;
            case 'f':
                path = optarg;
                break;
            default:
                printf("bad argument.\n");
                exit(-1);
            }
    }     

    if (test_num == -1) {
        printf("no test specified.\n");
        exit(-1);
    } else if (path == NULL) {
        printf("no path specified.\n");
        exit(-1);
    }

    time(&t);
    printf("\n%s", ctime(&t));
    getcon(&ctx_check);
    printf("Context: '%s'\n", ctx_check); 
    ctx = context_new(ctx_check);
    const char *range = context_range_get(ctx);

    if (strncmp(LVL_HIGH"-", range, sizeof(LVL_HIGH"-")-1) == 0) {
        level = AT_HIGH;
        printf("process is at high\n");
    } else if (strncmp(LVL_LOW"-", range, sizeof(LVL_LOW"-")-1) == 0) {
        level = AT_LOW;
        printf("process is at low\n");
    } else {
        printf("unexpected level\n");
        exit(-1);
    }

    fflush(stdout); fflush(stderr);

    switch(test_num) {
        case 1:
            read_low(level, path);
            break;
        case 2:
            read_high(level, path);
            break;
        case 3:
            write_low(level, path);
            break;
        case 4:
            write_high(level, path);
            break;
        default:
            printf("invalid test chosen\n");
            exit(-1);
            break;
    }
    return 0;
}