]> git.zerfleddert.de Git - raggedstone/blame - xps/raggedstone.c
white space; fixme
[raggedstone] / xps / raggedstone.c
CommitLineData
7fb867f8 1#include "xparameters.h"
2#include "xgpio_l.h"
3
4#include "stdio.h"
5
6#include "xutil.h"
7
8#define DISP7(a,b,c,d,e,f,g) (0|((~(a|b<<1|c<<2|d<<3|e<<4|f<<5|g<<6))&0xff))
9
10void display_num(unsigned short num) {
11 unsigned int val = 0x00;
12 int i;
13 unsigned short digit;
14
15 XGpio_mSetDataDirection(XPAR_SEVENSEG_BASEADDR, 1, 0x00000000);
16
17 for (i=0; i<5; i++) {
18 digit = ((num>>(4*i)) & 0xf);
19 switch(digit) {
20 case 0x0:
21 val = DISP7(1,1,1,1,1,1,0);
22 break;
23 case 0x1:
24 val = DISP7(0,1,1,0,0,0,0);
25 break;
26 case 0x2:
27 val = DISP7(1,1,0,1,1,0,1);
28 break;
29 case 0x3:
30 val = DISP7(1,1,1,1,0,0,1);
31 break;
32 case 0x4:
33 val = DISP7(0,1,1,0,0,1,1);
34 break;
35 case 0x5:
36 val = DISP7(1,0,1,1,0,1,1);
37 break;
38 case 0x6:
39 val = DISP7(1,0,1,1,1,1,1);
40 break;
41 case 0x7:
42 val = DISP7(1,1,1,0,0,0,0);
43 break;
44 case 0x8:
45 val = DISP7(1,1,1,1,1,1,1);
46 break;
47 case 0x9:
48 val = DISP7(1,1,1,1,0,1,1);
49 break;
50 case 0xa:
51 val = DISP7(1,1,1,0,1,1,1);
52 break;
53 case 0xb:
54 val = DISP7(0,0,1,1,1,1,1);
55 break;
56 case 0xc:
57 val = DISP7(1,0,0,1,1,1,0);
58 break;
59 case 0xd:
60 val = DISP7(0,1,1,1,1,0,1);
61 break;
62 case 0xe:
63 val = DISP7(1,0,0,1,1,1,1);
64 break;
65 case 0xf:
66 val = DISP7(1,0,0,0,1,1,1);
67 break;
68 }
69
70 val |= 1 << (8+(3-i));
71
72 if (i == 4)
73 val = 0x00;
74
75 XGpio_mSetDataReg(XPAR_SEVENSEG_BASEADDR, 1, val);
76 if (i != 4)
77 for (val = 0; val < 100000; val++);
78 }
79}
80
81void flash_chip_erase() {
82 volatile unsigned char *flash = (volatile unsigned char*)XPAR_FLASH_MEM0_BASEADDR;
83
84 flash[0x555] = 0xAA;
85 flash[0xAAA] = 0x55;
86 flash[0x555] = 0x80;
87 flash[0x555] = 0xAA;
88 flash[0xAAA] = 0x55;
89 flash[0x555] = 0x10;
90}
91
92void flash_erase_sector(unsigned int addr) {
93 volatile unsigned char *flash = (volatile unsigned char*)XPAR_FLASH_MEM0_BASEADDR;
94
95 flash[0x555] = 0xAA;
96 flash[0xAAA] = 0x55;
97 flash[0x555] = 0x80;
98 flash[0x555] = 0xAA;
99 flash[0xAAA] = 0x55;
100 flash[addr] = 0x30;
101}
102
103void flash_program_byte(unsigned int addr, unsigned char value) {
104 volatile unsigned char *flash = (volatile unsigned char*)XPAR_FLASH_MEM0_BASEADDR;
105 unsigned int count = 0xffffffff;
106
107 if (flash[addr] != 0xff)
108 return;
109
110 flash[0x555] = 0xAA;
111 flash[0xAAA] = 0x55;
112 flash[0x555] = 0xA0;
113 flash[addr] = value;
114
115 while (flash[addr] != value && count) { count--; }
116}
117
118void flash_identify(int enable) {
119 volatile unsigned char *flash = (volatile unsigned char*)XPAR_FLASH_MEM0_BASEADDR;
120
121 flash[0x555] = 0xAA;
122 flash[0xAAA] = 0x55;
123 flash[0x555] = enable?0x90:0xF0;
124}
125
126int main (void) {
127 int i,a;
128 volatile unsigned char *flash = (volatile unsigned char*)XPAR_FLASH_MEM0_BASEADDR;
129
130 XGpio_mSetDataDirection(XPAR_LEDS_BASEADDR, 1, 0x00000000);
131 XGpio_mSetDataReg(XPAR_LEDS_BASEADDR, 1, 0x00);
132 print("\r\nHallo Raggedstone!\r\n");
133 for (i = 0; i < 1500000000; i++);
134
135 flash_identify(1);
136 putnum(flash[0]|flash[1]<<8|flash[2]<<16|flash[3]<<24);
137 print("\r\n");
138 flash_identify(0);
139 putnum(flash[0]|flash[1]<<8|flash[2]<<16|flash[3]<<24);
140 print("\r\n");
141
142 for (i = 0; i < 1500000000; i++);
143 i = 0;
144 while(1) {
145 print("Hallo Raggedstone ");
146 display_num(i>>8);
147 putnum(i);
148 XGpio_mSetDataReg(XPAR_LEDS_BASEADDR, 1, (i & 0xf00)>>8);
149 print("\r\n");
150 if (i == 0x7ffff)
151 i = 0;
152 else
153 i++;
154 }
155 return 0;
156}
Impressum, Datenschutz