nicer output; still don't work as desired :/
[pyfrprog.git] / pkernel / main.c
1 #include "mb91465k.h"
2 #include "vectors.h"
3 #include "rlt.h"
4 #include "flash.h"
5
6 void main(void)
7 {
8         unsigned char error = 0;
9         unsigned char global_error = 0; 
10         unsigned int i, baseaddr;
11         unsigned int toflash[] = {0x9b00,
12                                                                 0x0d4e,
13                                                                 0xcff1,
14                                                                 0x1601,
15                                                                 0x9b05,
16                                                                 0x04c7,
17                                                                 0xc106,
18                                                                 0x1656,
19                                                                 0xe0fb}; //len = 9
20         
21         /*      Enable Clock Monitor    */
22         CSCFG_MONCKI = 1;
23         CMCFG = 0x0D;
24                 
25         __EI();                    /* enable interrupts */
26         __set_il(31);              /* allow all levels */
27         InitIrqLevels();           /* init interrupts */
28
29         PORTEN = 0x3;           /* enable I/O Ports */
30                                 /* This feature is not supported by MB91V460A */
31                                /* For all other devices the I/O Ports must be enabled*/
32
33         /*      Enable LEDs     */
34         DDR14 = 0xFF;
35         PDR14 = 0xff;
36
37         /*      Initialize Reload Timer Channel 0       */
38         RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);
39         RLT_SetReloadValue(0,0xfffe);
40         RLT_TriggerTimer(0);
41         RLT_EnableInterrupt(0, 1);
42
43         /*      Initialize UART4        */
44         InitUart4();
45
46         /*      Output Welcome Message  */
47         Puts4(" \n\n");
48         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
49
50 #if 0
51         i = 0;
52         baseaddr = 0xf4000;
53         for (; i <0x30; i+=4) {
54                 error = FLASH_SectorErase(baseaddr + i);
55                 Puts4("\nerased: ");
56                 Puts4(error == 1 ? "[success] " : "[failed] ");
57                 Puthex4(baseaddr + i, 6);
58         }
59 #endif
60         i=0;
61         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
62         while(i < 0x20)
63         {
64                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
65                 i++;
66                 if( (i % 0x10) == 0 ) Puts4("\n");
67         }
68         Puts4("\n");
69
70
71         i = 0;
72         baseaddr = 0xf4000;
73         for(; i<9; i++) {
74                 Puts4("\nwrite: ");
75                 error = FLASH_WriteHalfWord(baseaddr + (2*i), toflash[i]);
76                 Puts4(error == 1 ? "[sucess] " : "[failed] ");
77                 Puts4("0x");
78                 Puthex4(toflash[i], 4);
79                 Puts4(" @0x");
80                 Puthex4(baseaddr + (2*i), 6);
81         }
82
83         i=0;
84         Puts4("\nCurrent Content of FLASH at 0xf4000 ... 0xf401F:\n");
85         while(i < 0x20)
86         {
87                 Puts4("0x"); Puthex4( *(unsigned char *)(0xf4000 + i), 2); Puts4(" ");
88                 i++;
89                 if( (i % 0x10) == 0 ) Puts4("\n");
90         }
91         Puts4("\n");
92
93                                 
94         /*      Output Ready Meassage   */
95         if( global_error != 0 )
96         {
97                 Puts4("\n********* FLASH Programming Demo failed **********\n");
98         }
99         else
100         {
101                 Puts4("\n********* FLASH Programming Demo done **********\n");
102         }
103
104         RLT_EnableInterrupt(0, 0);
105                                         
106     while(1)
107     {    
108          
109        HWWD_CL = 0;   
110     }   
111 }
112