C8051F32x firmware infrastructure

Sign in or create your account | Project List | Help

C8051F32x firmware infrastructure Commit Details

Date:2010-10-21 15:05:26 (13 years 5 months ago)
Author:Werner Almesberger
Commit:3bbf31853678e5b9cd9d9496437546c3ea8a06dd
Message:Switched from four-spaces to one-tab indentation.

Files: f32x/boundary.c (1 diff)
f32x/c2-om.c (3 diffs)
f32x/f32x.c (2 diffs)
f32x/flash.c (3 diffs)
f32x/gpio.h (1 diff)
f32x/rt.c (1 diff)

Change Details

f32x/boundary.c
2727
2828static uint8_t reg_read(uint8_t addr)
2929{
30    c2_addr_write(addr);
31    return c2_data_read(1);
30    c2_addr_write(addr);
31    return c2_data_read(1);
3232}
3333
3434
3535static void reg_write(uint8_t addr, uint8_t value)
3636{
37    c2_addr_write(addr);
38    c2_data_write(value, 1);
37    c2_addr_write(addr);
38    c2_data_write(value, 1);
3939}
4040
4141
4242static const char *parse(const char *s, uint8_t *port, uint8_t *mode, int bits)
4343{
44    int pos;
45
46    *port = *mode = 0;
47    pos = 0;
48    while (pos != bits) {
49    switch (*s++) {
50    case '.':
51        continue;
52    case '1':
53        *port |= 1 << pos;
54        /* fall through */
55    case '0':
56        *mode |= 1 << pos;
57        break;
58    case 'r':
59    case 'R':
60        *port |= 1 << pos;
61        break;
62    case 0:
63        fprintf(stderr, "not enough pin settings\n");
64        exit(1);
65    default:
66        fprintf(stderr, "unrecognized pin setting \"%c\"\n", s[-1]);
67        exit(1);
68    }
69    pos++;
70    }
71    return s;
44    int pos;
45
46    *port = *mode = 0;
47    pos = 0;
48    while (pos != bits) {
49        switch (*s++) {
50        case '.':
51                continue;
52        case '1':
53            *port |= 1 << pos;
54            /* fall through */
55        case '0':
56            *mode |= 1 << pos;
57            break;
58        case 'r':
59        case 'R':
60            *port |= 1 << pos;
61            break;
62        case 0:
63            fprintf(stderr, "not enough pin settings\n");
64            exit(1);
65        default:
66            fprintf(stderr,
67                "unrecognized pin setting \"%c\"\n", s[-1]);
68            exit(1);
69        }
70        pos++;
71        }
72    return s;
7273}
7374
7475
7576static void setup(const char *init)
7677{
77    uint8_t p0, p0mdout, p2, p2mdout;
78
79    init = parse(init, &p0, &p0mdout, 8);
80    init = parse(init, &p2, &p2mdout, 6);
81    if (*init) {
82    fprintf(stderr, "too many pin settings\n");
83    exit(1);
84    }
85    reg_write(P0, p0);
86    reg_write(P0MDOUT, p0mdout);
87    reg_write(P2, p2);
88    reg_write(P2MDOUT, p2mdout);
78    uint8_t p0, p0mdout, p2, p2mdout;
79
80    init = parse(init, &p0, &p0mdout, 8);
81    init = parse(init, &p2, &p2mdout, 6);
82    if (*init) {
83        fprintf(stderr, "too many pin settings\n");
84        exit(1);
85    }
86    reg_write(P0, p0);
87    reg_write(P0MDOUT, p0mdout);
88    reg_write(P2, p2);
89    reg_write(P2MDOUT, p2mdout);
8990}
9091
9192
9293static void print(uint8_t v, int bits)
9394{
94    int pos;
95    int pos;
9596
96    for (pos = 0; pos != bits; pos++)
97    putchar(v & (1 << pos) ? '1' : '0');
97    for (pos = 0; pos != bits; pos++)
98        putchar(v & (1 << pos) ? '1' : '0');
9899}
99100
100101
101102static void scan(void)
102103{
103    uint8_t p0, p2;
104
105    p0 = reg_read(P0);
106    p2 = reg_read(P2);
107    print(p0, 8);
108    putchar('.');
109    print(p2, 6);
110    putchar('\n');
104    uint8_t p0, p2;
105
106    p0 = reg_read(P0);
107    p2 = reg_read(P2);
108    print(p0, 8);
109    putchar('.');
110    print(p2, 6);
111    putchar('\n');
111112}
112113
113114
114115static void __attribute__((unused)) dump(void)
115116{
116    fprintf(stderr, "GPIOCN %02x\n", reg_read(0xe2));
117    fprintf(stderr, " P0 %02x\n", reg_read(P0));
118    fprintf(stderr, " P0MDOUT %02x\n", reg_read(P0MDOUT));
119    fprintf(stderr, " P2 %02x\n", reg_read(P2));
120    fprintf(stderr, " P2MDOUT %02x\n", reg_read(P2MDOUT));
117    fprintf(stderr, "GPIOCN %02x\n", reg_read(0xe2));
118    fprintf(stderr, " P0 %02x\n", reg_read(P0));
119    fprintf(stderr, " P0MDOUT %02x\n", reg_read(P0MDOUT));
120    fprintf(stderr, " P2 %02x\n", reg_read(P2));
121    fprintf(stderr, " P2MDOUT %02x\n", reg_read(P2MDOUT));
121122}
122123
123124
124125void boundary(const char *init)
125126{
126127//dump();
127    setup(init);
128    scan();
128    setup(init);
129    scan();
129130}
f32x/c2-om.c
3232
3333static void c2_pulse(void)
3434{
35    gpio_low(C2CK);
36    gpio_high(C2CK);
35    gpio_low(C2CK);
36    gpio_high(C2CK);
3737}
3838
3939
4040static void c2_send(uint32_t value, int bits)
4141{
42    int i;
42    int i;
4343
44    for (i = 0; i != bits; i++) {
45    gpio_set(C2D, (value >> i) & 1);
46    c2_pulse();
47    }
44    for (i = 0; i != bits; i++) {
45        gpio_set(C2D, (value >> i) & 1);
46        c2_pulse();
47    }
4848}
4949
5050
5151static uint32_t c2_recv(int bits)
5252{
53    uint32_t v = 0;
54    int i;
55
56    for (i = 0; i != bits; i++) {
57    v |= gpio_get(C2D) << i;
58    c2_pulse();
59    }
60    return v;
53    uint32_t v = 0;
54    int i;
55
56    for (i = 0; i != bits; i++) {
57        v |= gpio_get(C2D) << i;
58        c2_pulse();
59        }
60    return v;
6161}
6262
6363
...... 
6666
6767static void om_addr_write(uint8_t addr)
6868{
69    c2_pulse();
70    gpio_output(C2D);
71    c2_send(C2_ADDR_WRITE, 2);
72    c2_send(addr, 8);
73    gpio_input(C2D);
74    c2_pulse();
69    c2_pulse();
70    gpio_output(C2D);
71    c2_send(C2_ADDR_WRITE, 2);
72    c2_send(addr, 8);
73    gpio_input(C2D);
74    c2_pulse();
7575}
7676
7777
7878static uint8_t om_addr_read(void)
7979{
80    c2_pulse();
81    gpio_output(C2D);
82    c2_send(C2_ADDR_READ, 2);
83    gpio_input(C2D);
84    c2_pulse();
85    return c2_recv(8);
80    c2_pulse();
81    gpio_output(C2D);
82    c2_send(C2_ADDR_READ, 2);
83    gpio_input(C2D);
84    c2_pulse();
85    return c2_recv(8);
8686}
8787
8888
8989static void om_data_write(uint32_t data, int bytes)
9090{
91    c2_pulse();
92    gpio_output(C2D);
93    c2_send(C2_DATA_WRITE, 2);
94    c2_send(bytes-1, 2);
95    c2_send(data, 8*bytes);
96    gpio_input(C2D);
97    c2_pulse();
98    while (!c2_recv(1));
91    c2_pulse();
92    gpio_output(C2D);
93    c2_send(C2_DATA_WRITE, 2);
94    c2_send(bytes-1, 2);
95    c2_send(data, 8*bytes);
96    gpio_input(C2D);
97    c2_pulse();
98    while (!c2_recv(1));
9999}
100100
101101
102102static uint32_t om_data_read(int bytes)
103103{
104    c2_pulse();
105    gpio_output(C2D);
106    c2_send(C2_DATA_READ, 2);
107    c2_send(bytes-1, 2);
108    gpio_input(C2D);
109    c2_pulse();
110    while (!c2_recv(1));
111    return c2_recv(8*bytes);
104    c2_pulse();
105    gpio_output(C2D);
106    c2_send(C2_DATA_READ, 2);
107    c2_send(bytes-1, 2);
108    gpio_input(C2D);
109    c2_pulse();
110    while (!c2_recv(1));
111    return c2_recv(8*bytes);
112112}
113113
114114
...... 
117117
118118static void om_init(void)
119119{
120    gpio_init();
121    gpio_input(C2D);
122    gpio_output(C2CK);
123    gpio_low(C2CK);
124    usleep(20);
125    gpio_high(C2CK);
126    usleep(2);
120    gpio_init();
121    gpio_input(C2D);
122    gpio_output(C2CK);
123    gpio_low(C2CK);
124    usleep(20);
125    gpio_high(C2CK);
126    usleep(2);
127127}
128128
129129
130130static void om_reset(void)
131131{
132    gpio_input(C2D);
133    gpio_low(C2CK);
134    usleep(20);
135// gpio_input(C2CK);
136    gpio_output(C2CK);
137    gpio_high(C2CK);
132    gpio_input(C2D);
133    gpio_low(C2CK);
134    usleep(20);
135// gpio_input(C2CK);
136    gpio_output(C2CK);
137    gpio_high(C2CK);
138138}
139139
140140
f32x/f32x.c
3030
3131static void dump(const char *title, void *data, size_t size)
3232{
33    int i, j;
34
35    fprintf(stderr, "%s:\n", title);
36    for (i = 0; i < size; i += 16) {
37    fprintf(stderr, " %04x", i);
38    for (j = 0; j != 16 && i+j < size; j++)
39        fprintf(stderr, " %02x", ((uint8_t *) data)[i+j]);
40    fprintf(stderr, "\n");
41    }
33    int i, j;
34
35    fprintf(stderr, "%s:\n", title);
36    for (i = 0; i < size; i += 16) {
37        fprintf(stderr, " %04x", i);
38        for (j = 0; j != 16 && i+j < size; j++)
39            fprintf(stderr, " %02x", ((uint8_t *) data)[i+j]);
40        fprintf(stderr, "\n");
41    }
4242}
4343
4444
4545static void flash_device(void *data, size_t size)
4646{
47    int i;
48    size_t len;
49    uint8_t buf[256];
50
51    for (i = 0; i < size; i += 256)
52    fputc('-', stderr);
53    fputc('\r', stderr);
54
55    flash_init();
56    flash_device_erase();
57
58    for (i = 0; i < size; i += 256) {
59    fputc('*', stderr);
60    fflush(stderr);
61    len = size-i <= 256 ? size-i : 256;
62    flash_block_write(i, data+i, len);
63    }
64    fputc('\r', stderr);
65
66    for (i = 0; i < size; i += 256) {
67    fputc('#', stderr);
68    fflush(stderr);
69    len = size-i <= 256 ? size-i : 256;
70    flash_block_read(i, buf, len);
71    if (memcmp(buf, data+i, len)) {
72        fprintf(stderr, "compare error at 0x%04x\n", i);
73        dump("Expected", data+i, len);
74        dump("Read", buf, len);
75        exit(1);
47    int i;
48    size_t len;
49    uint8_t buf[256];
50
51    for (i = 0; i < size; i += 256)
52        fputc('-', stderr);
53    fputc('\r', stderr);
54
55    flash_init();
56    flash_device_erase();
57
58    for (i = 0; i < size; i += 256) {
59        fputc('*', stderr);
60        fflush(stderr);
61        len = size-i <= 256 ? size-i : 256;
62        flash_block_write(i, data+i, len);
63    }
64    fputc('\r', stderr);
65
66    for (i = 0; i < size; i += 256) {
67        fputc('#', stderr);
68        fflush(stderr);
69        len = size-i <= 256 ? size-i : 256;
70        flash_block_read(i, buf, len);
71        if (memcmp(buf, data+i, len)) {
72            fprintf(stderr, "compare error at 0x%04x\n", i);
73            dump("Expected", data+i, len);
74            dump("Read", buf, len);
75            exit(1);
76        }
7677    }
77    }
78    fputc('\n', stderr);
78    fputc('\n', stderr);
7979}
8080
8181
8282static void erase_flash(void)
8383{
84    flash_init();
85    flash_device_erase();
84    flash_init();
85    flash_device_erase();
8686}
8787
8888
8989static void dump_flash(size_t size)
9090{
91    int i, j;
92    size_t len;
93    uint8_t buf[256], last[256];
94    int skipping = 0;
95
96    flash_init();
97    for (i = 0; i < size; i += 16) {
98    len = size-i <= 16 ? size-i : 16;
99    flash_block_read(i, buf, len);
100    if (i && !memcmp(last, buf, len)) {
101        printf("%04x: *%c", i, skipping ? '\r' : '\n');
102        fflush(stdout);
103        skipping = 1;
104        continue;
91    int i, j;
92    size_t len;
93    uint8_t buf[256], last[256];
94    int skipping = 0;
95
96    flash_init();
97    for (i = 0; i < size; i += 16) {
98        len = size-i <= 16 ? size-i : 16;
99        flash_block_read(i, buf, len);
100        if (i && !memcmp(last, buf, len)) {
101            printf("%04x: *%c", i, skipping ? '\r' : '\n');
102            fflush(stdout);
103            skipping = 1;
104            continue;
105        }
106        skipping = 0;
107        memcpy(last, buf, len);
108        printf("%04x:", i);
109        for (j = 0; j != len; j++)
110            printf(" %02x", buf[j]);
111        printf(" ");
112        for (j = 0; j != len; j++)
113            printf("%c",
114                buf[j] >= ' ' && buf[j] <= '~' ? buf[j] : '.');
115        putchar('\n');
116        fflush(stdout);
105117    }
106    skipping = 0;
107    memcpy(last, buf, len);
108    printf("%04x:", i);
109    for (j = 0; j != len; j++)
110        printf(" %02x", buf[j]);
111    printf(" ");
112    for (j = 0; j != len; j++)
113        printf("%c", buf[j] >= ' ' && buf[j] <= '~' ? buf[j] : '.');
114    putchar('\n');
115    fflush(stdout);
116    }
117118}
118119
119120
120121static void identify(void)
121122{
122    int i;
123
124    c2_addr_write(0);
125    printf("Dev");
126    for (i = 0; i != 10; i++)
127    printf(" 0x%02x", c2_data_read(1));
128    c2_addr_write(1);
129    printf("\nRev");
130    for (i = 0; i != 10; i++)
131    printf(" 0x%02x", c2_data_read(1));
132    printf("\n");
123    int i;
124
125    c2_addr_write(0);
126    printf("Dev");
127    for (i = 0; i != 10; i++)
128        printf(" 0x%02x", c2_data_read(1));
129    c2_addr_write(1);
130    printf("\nRev");
131    for (i = 0; i != 10; i++)
132        printf(" 0x%02x", c2_data_read(1));
133    printf("\n");
133134}
134135
135136
136137static void do_flash(const char *name)
137138{
138    FILE *file;
139    uint8_t code[16384];
139    FILE *file;
140    uint8_t code[16384];
140141
141    file = fopen(name, "r");
142    if (!file) {
143    perror(name);
144    exit(1);
145    }
146    file_size = fread(code, 1, sizeof(code), file);
147    (void) fclose(file);
148    flash_device(code, file_size);
142    file = fopen(name, "r");
143    if (!file) {
144        perror(name);
145        exit(1);
146    }
147    file_size = fread(code, 1, sizeof(code), file);
148    (void) fclose(file);
149    flash_device(code, file_size);
149150}
150151
151152
152153static void protect(void)
153154{
154    uint8_t pages, lock_byte;
155    uint8_t pages, lock_byte;
155156
156    pages = (file_size+511) >> 9;
157    printf("Protecting %d page%s\n", pages, pages == 1 ? "" : "s");
158    lock_byte = ~pages;
159    flash_block_write(LOCK_BYTE, &lock_byte, 1);
157    pages = (file_size+511) >> 9;
158    printf("Protecting %d page%s\n", pages, pages == 1 ? "" : "s");
159    lock_byte = ~pages;
160    flash_block_write(LOCK_BYTE, &lock_byte, 1);
160161}
161162
162163
163164static void usage(const char *name)
164165{
165    fprintf(stderr,
166    fprintf(stderr,
166167"usage: %s [-p] file\n"
167168" %s -d\n"
168169" %s -e\n"
...... 
179180" -p Protect the data after writing\n"
180181"Invocation without argument resets the F32x.\n"
181182  , name, name, name, name, name);
182    exit(1);
183    exit(1);
183184}
184185
185186
186187int main(int argc, char **argv)
187188{
188    c2_init();
189    identify();
190
191    switch (argc) {
192    case 1:
193    /* just reset */
194    break;
195    case 2:
196    if (!strcmp(argv[1], "-d"))
197        dump_flash(0x4000);
198    else if (!strcmp(argv[1], "-e"))
199        erase_flash();
200    else if (*argv[1] == '-')
201        usage(*argv);
202    else {
203        do_flash(argv[1]);
204        identify();
205    }
206    break;
207    case 3:
208    if (!strcmp(argv[1], "-p")) {
209        if (*argv[2] == '-')
189    c2_init();
190    identify();
191
192    switch (argc) {
193    case 1:
194        /* just reset */
195        break;
196    case 2:
197        if (!strcmp(argv[1], "-d"))
198            dump_flash(0x4000);
199        else if (!strcmp(argv[1], "-e"))
200            erase_flash();
201        else if (*argv[1] == '-')
202            usage(*argv);
203        else {
204            do_flash(argv[1]);
205            identify();
206        }
207        break;
208    case 3:
209        if (!strcmp(argv[1], "-p")) {
210            if (*argv[2] == '-')
211                usage(*argv);
212                do_flash(argv[2]);
213                protect();
214                identify();
215                break;
216        }
217        if (strcmp(argv[1], "-b"))
218            usage(*argv);
219        boundary(argv[2]);
220        break;
221    default:
210222        usage(*argv);
211        do_flash(argv[2]);
212        protect();
213        identify();
214        break;
215223    }
216    if (strcmp(argv[1], "-b"))
217        usage(*argv);
218    boundary(argv[2]);
219    break;
220    default:
221    usage(*argv);
222    }
223    c2_reset();
224
225    return 0;
224    c2_reset();
225
226    return 0;
226227}
f32x/flash.c
2525
2626static uint8_t _c2_addr_read(void)
2727{
28    uint8_t x;
28    uint8_t x;
2929
30    usleep(1000);
31    x = c2_addr_read();
32// fprintf(stderr, "got 0x%02x\n", x);
33    return x;
30    usleep(1000);
31    x = c2_addr_read();
32// fprintf(stderr, "got 0x%02x\n", x);
33    return x;
3434}
3535
3636
3737static void wait_busy(void)
3838{
39    while (_c2_addr_read() & InBusy);
39    while (_c2_addr_read() & InBusy);
4040}
4141
4242
4343static void wait_ready(void)
4444{
45    while (!(_c2_addr_read() & OutReady));
45    while (!(_c2_addr_read() & OutReady));
4646}
4747
4848
4949static void fpdat_write(uint8_t value)
5050{
51    c2_data_write(value, 1);
52    wait_busy();
51    c2_data_write(value, 1);
52    wait_busy();
5353}
5454
5555
5656static uint8_t fpdat_read(void)
5757{
58    wait_ready();
59    return c2_data_read(1);
58    wait_ready();
59    return c2_data_read(1);
6060}
6161
6262
6363static void check_status(void)
6464{
65    uint8_t status;
65    uint8_t status;
6666
67    status = fpdat_read();
68    if (status != FLASH_STATUS_OK) {
69    fprintf(stderr, "status 0x%02x\n", status);
70    exit(1);
71    }
67    status = fpdat_read();
68    if (status != FLASH_STATUS_OK) {
69        fprintf(stderr, "status 0x%02x\n", status);
70        exit(1);
71    }
7272}
7373
7474
...... 
7777
7878void flash_device_erase(void)
7979{
80    c2_addr_write(FPDAT);
81    fpdat_write(FLASH_DEVICE_ERASE);
82    check_status();
83    fpdat_write(FLASH_ERASE_MAGIC1);
84    fpdat_write(FLASH_ERASE_MAGIC2);
85    fpdat_write(FLASH_ERASE_MAGIC3);
86    check_status();
80    c2_addr_write(FPDAT);
81    fpdat_write(FLASH_DEVICE_ERASE);
82    check_status();
83    fpdat_write(FLASH_ERASE_MAGIC1);
84    fpdat_write(FLASH_ERASE_MAGIC2);
85    fpdat_write(FLASH_ERASE_MAGIC3);
86    check_status();
8787}
8888
8989
9090void flash_block_write(uint16_t addr, const void *data, size_t size)
9191{
92    int i;
93
94    if (!size)
95    return;
96    c2_addr_write(FPDAT);
97    fpdat_write(FLASH_BLOCK_WRITE);
98    check_status();
99    fpdat_write(addr >> 8);
100    fpdat_write(addr);
101    fpdat_write(size);
102    check_status();
103    for (i = 0; i != size; i++)
104    fpdat_write(((uint8_t *) data)[i]);
92    int i;
93
94    if (!size)
95        return;
96    c2_addr_write(FPDAT);
97    fpdat_write(FLASH_BLOCK_WRITE);
98    check_status();
99    fpdat_write(addr >> 8);
100    fpdat_write(addr);
101    fpdat_write(size);
102    check_status();
103    for (i = 0; i != size; i++)
104        fpdat_write(((uint8_t *) data)[i]);
105105}
106106
107107
108108void flash_block_read(uint16_t addr, void *data, size_t size)
109109{
110    int i;
111
112    if (!size)
113    return;
114    c2_addr_write(FPDAT);
115    fpdat_write(FLASH_BLOCK_READ);
116    check_status();
117    fpdat_write(addr >> 8);
118    fpdat_write(addr);
119    fpdat_write(size);
120    check_status();
121    for (i = 0; i != size; i++)
122    ((uint8_t *) data)[i] = fpdat_read();
110    int i;
111
112    if (!size)
113        return;
114    c2_addr_write(FPDAT);
115    fpdat_write(FLASH_BLOCK_READ);
116    check_status();
117    fpdat_write(addr >> 8);
118    fpdat_write(addr);
119    fpdat_write(size);
120    check_status();
121    for (i = 0; i != size; i++)
122        ((uint8_t *) data)[i] = fpdat_read();
123123}
124124
125125
126126void flash_init(void)
127127{
128    c2_addr_write(FPCTL);
129    c2_data_write(FLASH_INIT_MAGIC1, 1);
130    c2_data_write(FLASH_INIT_MAGIC2, 1);
131    usleep(20000);
128    c2_addr_write(FPCTL);
129    c2_data_write(FLASH_INIT_MAGIC1, 1);
130    c2_data_write(FLASH_INIT_MAGIC2, 1);
131    usleep(20000);
132132}
133133
134134
...... 
136136
137137uint8_t fp_reg_read(uint8_t addr)
138138{
139    c2_addr_write(FPDAT);
140    fpdat_write(REG_READ);
141    check_status();
142    fpdat_write(addr);
143    fpdat_write(1);
144    return fpdat_read();
139    c2_addr_write(FPDAT);
140    fpdat_write(REG_READ);
141    check_status();
142    fpdat_write(addr);
143    fpdat_write(1);
144    return fpdat_read();
145145}
146146
147147
148148void fp_reg_write(uint8_t addr, uint8_t value)
149149{
150    c2_addr_write(FPDAT);
151    fpdat_write(REG_WRITE);
152    check_status();
153    fpdat_write(addr);
154    fpdat_write(1);
155    fpdat_write(value);
150    c2_addr_write(FPDAT);
151    fpdat_write(REG_WRITE);
152    check_status();
153    fpdat_write(addr);
154    fpdat_write(1);
155    fpdat_write(value);
156156}
157
f32x/gpio.h
3131
3232static inline void gpio_high(unsigned port, unsigned bit)
3333{
34    port_dat(port) |= 1 << bit;
34    port_dat(port) |= 1 << bit;
3535}
3636
3737
3838static inline void gpio_low(unsigned port, unsigned bit)
3939{
40    port_dat(port) &= ~(1 << bit);
40    port_dat(port) &= ~(1 << bit);
4141}
4242
4343
4444static inline void gpio_set(unsigned port, unsigned bit, int value)
4545{
46    if (value)
47    gpio_high(port, bit);
48    else
49    gpio_low(port, bit);
46    if (value)
47        gpio_high(port, bit);
48    else
49        gpio_low(port, bit);
5050}
5151
5252
5353static inline int gpio_get(unsigned port, unsigned bit)
5454{
55    return (port_dat(port) >> bit) & 1;
55    return (port_dat(port) >> bit) & 1;
5656}
5757
5858
5959static inline void gpio_output(unsigned port, unsigned bit)
6060{
61    port_con(port) = (port_con(port) & ~(3 << bit*2)) | (1 << bit*2);
61    port_con(port) = (port_con(port) & ~(3 << bit*2)) | (1 << bit*2);
6262}
6363
6464
6565static inline void gpio_input(unsigned port, unsigned bit)
6666{
67    port_con(port) &= ~(3 << bit*2);
67    port_con(port) &= ~(3 << bit*2);
6868}
6969
7070
f32x/rt.c
2222
2323static void realtimize(void)
2424{
25    struct sched_param prm;
26
27    prm.sched_priority = sched_get_priority_max(SCHED_FIFO);
28    if (prm.sched_priority < 0) {
29    perror("sched_get_priority_max SCHED_FIFO");
30    exit(1);
31    }
32    if (sched_setscheduler(0, SCHED_FIFO, &prm) < 0) {
33    perror("sched_setscheduler SCHED_FIFO");
34    exit(1);
35    }
25    struct sched_param prm;
26
27    prm.sched_priority = sched_get_priority_max(SCHED_FIFO);
28    if (prm.sched_priority < 0) {
29        perror("sched_get_priority_max SCHED_FIFO");
30        exit(1);
31    }
32    if (sched_setscheduler(0, SCHED_FIFO, &prm) < 0) {
33        perror("sched_setscheduler SCHED_FIFO");
34        exit(1);
35    }
3636}
3737
3838
3939static void unrealtime(void)
4040{
41    struct sched_param prm = { .sched_priority = 0 };
41    struct sched_param prm = { .sched_priority = 0 };
4242
43    if (sched_setscheduler(0, SCHED_OTHER, &prm) < 0) {
44    perror("sched_setscheduler SCHED_OTHER");
45    exit(1);
46    }
43    if (sched_setscheduler(0, SCHED_OTHER, &prm) < 0) {
44        perror("sched_setscheduler SCHED_OTHER");
45        exit(1);
46    }
4747}
4848
4949
5050void rt(int on)
5151{
52    if (on)
53    realtimize();
54    else
55    unrealtime();
52    if (on)
53        realtimize();
54    else
55        unrealtime();
5656}

Archive Download the corresponding diff file

Branches:
master



interactive