w00t, wtf IT WORKS NOW!!!1
[pyfrprog.git] / pkernel / main.c
1 #include "mb91465k.h"
2 #include "flash.h"
3
4 #pragma section CODE=IRAM,attr=CODE
5
6 void increaseled(void)
7 {
8         PDR14 = (PDR14+1)%256;
9         HWWD_CL = 0;
10 }
11
12 void main(void)
13 {
14         unsigned char error = 0;
15         unsigned char global_error = 0; 
16         unsigned int i, baseaddr;
17         unsigned int toflash[] = {0x9b00,
18                                                                 0x0d4e,
19                                                                 0xcff1,
20                                                                 0x1601,
21                                                                 0x9b05,
22                                                                 0x04c7,
23                                                                 0xc106,
24                                                                 0x1656,
25                                                                 0xe0fb}; //len = 9
26         
27         PORTEN = 0x3;           /* enable I/O Ports */
28                                 /* This feature is not supported by MB91V460A */
29                                /* For all other devices the I/O Ports must be enabled*/
30
31         /*      Enable LEDs     */
32         DDR14 = 0xFF;
33         PDR14 = 0xff;
34
35         /*      Initialize UART4        */
36         InitUart4();
37
38         /*      Output Welcome Message  */
39         Puts4(" \n\n");
40         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
41
42 #if 1
43         i = 0;
44         baseaddr = 0xf4000;
45         for (; i <0x30; i+=4) {
46                 error = FLASH_SectorErase(baseaddr + i);
47                 Puts4("\nerased: ");
48                 Puts4(error == 1 ? "[success] " : "[failed] ");
49                 Puthex4(baseaddr + i, 6);
50         }
51 #endif
52         i=0;
53         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
54         while(i < 0x20)
55         {
56                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
57                 i++;
58                 if( (i % 0x10) == 0 ) Puts4("\n");
59         }
60         Puts4("\n");
61
62
63         i = 0;
64         baseaddr = 0xf4000;
65         for(; i<9; i++) {
66                 Puts4("\nwrite: ");
67                 error = FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);
68                 Puts4(error == 1 ? "[sucess] " : "[failed] ");
69                 Puts4("0x");
70                 Puthex4(toflash[i], 4);
71                 Puts4(" @0x");
72                 Puthex4(baseaddr + (2*i), 6);
73         }
74
75         /*      Output Ready Meassage   */
76         if( global_error != 0 )
77         {
78                 Puts4("\n********* FLASH Programming Demo failed **********\n");
79         }
80         else
81         {
82                 Puts4("\n********* FLASH Programming Demo done **********\n");
83         }
84
85     while(1)
86     {    
87          
88        HWWD_CL = 0;   
89     }   
90 }
91