Root/lm32/logic/sakc/firmware/ddr-phaser/main.c

1/**
2 * DDR Phase Shifter
3 */
4
5#include "spike_hw.h"
6
7/******************************************************************************
8 * Control DDR phase shift
9 */
10inline int ps_ready()
11{
12    return (gpio0->in & (1 << 16)); // return 1 when ready, 0 otherwise
13}
14
15inline void ps_inc()
16{
17    uint32_t tmp;
18
19    while ( ! ps_ready() );
20
21    tmp = gpio0->out;
22    gpio0->out = tmp | (1 << 16);
23    gpio0->out = tmp;
24    
25    while ( ! ps_ready() );
26}
27
28inline void ps_dec()
29{
30    uint32_t tmp;
31
32    while ( ! ps_ready() );
33
34    tmp = gpio0->out;
35    gpio0->out = tmp | (1 << 17);
36    gpio0->out = tmp;
37    
38    while ( ! ps_ready() );
39}
40
41/******************************************************************************
42 * Simple memory tester
43 *
44 * Returns -1 on error, 0 when OK.
45 */
46inline int memtest(uint32_t size)
47{
48    volatile uint32_t *p;
49    int res = 0;
50
51    for (p=(uint32_t *)RAM_START; p<(uint32_t *)(RAM_START+size); p++) {
52        *p = (uint32_t) p;
53    }
54    
55    for (p=(uint32_t *)RAM_START; p<(uint32_t *)(RAM_START+size); p++) {
56        if (*p != (uint32_t)p) {
57            res = -1;
58        }
59    }
60
61    return res;
62}
63
64
65void scan_phase(int dir, uint32_t size)
66{
67    int i;
68
69    for (i=0; i<=255; i++) {
70        if (memtest(size) == 0)
71            uart_putchar('O');
72        else
73            uart_putchar('-');
74
75        if (dir == 1) ps_inc(); else ps_dec();
76    }
77}
78
79
80
81int main(int argc, char **argv)
82{
83    uint32_t scan_size = 16*1024; // scan 16 kByte
84
85    // Initialize stuff
86    uart_init();
87
88    uart_putstr("\r\n\r\n** SOC-LM32 DDR PAHSER **\n\n");
89    uart_putstr("'O' => Memtest OK ; '-' => Memtest failed\n\n");
90    uart_putstr("Press [u] for upward scan, [d] for downward\n");
91
92    for(;;) {
93        uint8_t c = uart_getchar();
94
95        switch (c) {
96            case 'u': // scan upward
97                scan_phase(1, scan_size);
98                break;
99            case 'd': // scan downward
100                scan_phase(-1, scan_size);
101                break;
102        }
103    }
104}
105
106

Archive Download this file

Branches:
master



interactive