dos2unix on all files + tab madness
[pyfrprog.git] / MAIN.c
1 /* THIS SAMPLE CODE IS PROVIDED AS IS AND IS SUBJECT TO ALTERATIONS. FUJITSU */
2 /* MICROELECTRONICS ACCEPTS NO RESPONSIBILITY OR LIABILITY FOR ANY ERRORS OR */
3 /* ELIGIBILITY FOR ANY PURPOSES.                                             */
4 /*                 (C) Fujitsu Microelectronics Europe GmbH                  */
5 /*------------------------------------------------------------------------
6   MAIN.C
7   - description
8   - See README.TXT for project description and disclaimer.
9
10   06.10.06  1.01   UMa    changed includes
11 -------------------------------------------------------------------------*/
12
13  
14 /*************************@INCLUDE_START************************/
15 #include "mb91465k.h"
16 #include "vectors.h"
17 #include "RLT.h"
18 #include "Flash.h"
19 /**************************@INCLUDE_END*************************/
20
21 /*********************@GLOBAL_VARIABLES_START*******************/
22 /**********************@GLOBAL_VARIABLES_END********************/
23
24
25 /*******************@FUNCTION_DECLARATION_START*****************/
26
27 /*********************@FUNCTION_HEADER_START*********************
28 *@FUNCTION NAME:    main()                                      *
29 *                                                               *
30 *@DESCRIPTION:      The main function controls the program flow *
31 *                                                               *
32 *@PARAMETER:        none                                        *
33 *                                                               *
34 *@RETURN:           none                                        *
35 *                                                               *
36 ***********************@FUNCTION_HEADER_END*********************/
37
38
39 void main(void)
40 {
41         unsigned char error = 0;
42         unsigned char global_error = 0; 
43         unsigned int i;
44         
45         /*      Enable Clock Monitor    */
46         CSCFG_MONCKI = 1;
47         CMCFG = 0x0D;
48                 
49         __EI();                    /* enable interrupts */
50         __set_il(31);              /* allow all levels */
51         InitIrqLevels();           /* init interrupts */
52
53         PORTEN = 0x3;           /* enable I/O Ports */
54                                 /* This feature is not supported by MB91V460A */
55                                /* For all other devices the I/O Ports must be enabled*/
56
57         /*      Enable LEDs     */
58         DDR27 = 0xFF;
59         PDR27 = 0x00;
60
61         /*      Initialize Reload Timer Channel 0       */
62         RLT_InitializeTimer(0, RLT_RUMMODE_RELOAD, RLT_CLOCKMODE_DIV32, RLT_TRIGGER_SOFTWARE, RLT_OUTOUTMODE_HIGHLEVEL);
63         RLT_SetReloadValue(0,0x1388);   // CLKP/32, 0.01s Interval => 0x1388 counts
64         RLT_EnableInterrupt(0);
65         RLT_TriggerTimer(0);
66                  
67         /*      Initialize UART4        */
68         InitUart4();
69
70         /*      Output Welcome Message  */
71         Puts4(" \n\n");
72         Puts4("\n\n********** Welcome to FUJITSU FLASH Programming Demo **********\n");
73
74         /*      Do BlankCheck on Sector at 0xA0000      */
75         Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");
76         error = FLASH_SectorBlankCheck(0xA0000, 0x4000);
77         if( error == 1 )
78         {
79                 Puts4("done.\n");
80         }
81         else
82         {
83                 Puts4("failed.\n");
84         }
85                 
86         /*      Show Current Content of 0xA0000 ... 0xA001F     */
87         i=0;
88         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
89         while(i < 0x20)
90         {
91                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");
92                 i++;
93                 if( (i % 0x10) == 0 ) Puts4("\n");
94         }
95         Puts4("\n");
96         
97         /*      SectorErase of FLASH Memory     0xA0000*/
98         Puts4("Sector Erase of 0xA0000 ... ");
99         error = FLASH_SectorErase(0xA0000);
100         error = FLASH_SectorErase(0xA0004);
101         if( error == 1 )
102         {
103                 Puts4("done.\n");
104         }
105         else
106         {
107                 global_error = 1;
108                 Puts4("failed.\n");
109         }
110
111         /*      Do BlankCheck on Sectors at 0xA0000 */
112         Puts4("Blank Check of FLASH Sector at 0xA0000 ... ");
113         error = FLASH_SectorBlankCheck(0xA0000, 0x4000);
114         if( error == 1 )
115         {
116                 Puts4("done.\n");
117         }
118         else
119         {
120                 global_error = 1;
121                 Puts4("failed.\n");
122         }
123                 
124         /*      Show Current Content of 0xA0000 ... 0xA001F     */
125         i=0;
126         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
127         while(i < 0x20)
128         {
129                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");
130                 i++;
131                 if( (i % 0x10) == 0 ) Puts4("\n");
132         }
133         Puts4("\n");
134         
135         /*      Write 0x55AA to 0xA0002 */
136         Puts4("Write 0x55AA to 0xA0002 ... ");
137         error = FLASH_WriteHalfWord(0xA0002,0x55AA);
138         if( error == 1 )
139         {
140                 Puts4("done.\n");
141         }
142         else
143         {
144                 global_error = 1;
145                 Puts4("failed.\n");
146         }
147
148         /*      Write 0x33CC to 0xA0004 */
149         Puts4("Write 0x33CC to 0xA0004 ... ");
150         error = FLASH_WriteHalfWord(0xA0004,0x33CC);
151         if( error == 1 )
152         {
153                 Puts4("done.\n");
154         }
155         else
156         {
157                 global_error = 1;
158                 Puts4("failed.\n");
159         }
160                 
161         /*      Show Current Content of 0xA0000 ... 0xA001F     */
162         i=0;
163         Puts4("\nCurrent Content of FLASH at 0xA0000 ... 0xA001F:\n");
164         while(i < 0x20)
165         {
166                 Puts4("0x"); Puthex4( *(unsigned char *)(0xA0000 + i), 2); Puts4("  ");
167                 i++;
168                 if( (i % 0x10) == 0 ) Puts4("\n");
169         }
170         Puts4("\n");
171
172                                 
173         /*      Output Ready Meassage   */
174         if( global_error != 0 )
175         {
176                 Puts4("\n********* FLASH Programming Demo failed **********\n");
177         }
178         else
179         {
180                 Puts4("\n********* FLASH Programming Demo done **********\n");
181         }
182                                         
183     while(1)                   /* endless loop */
184     {    
185          
186        HWWD_CL = 0;   
187        
188        /* feed hardware watchdog */
189        /* (Only for devices with hardware (R/C based) watchdog) */
190        /* The hardware (R/C based) watchdog is started */
191        /* automatically after power-up and can not be stopped */
192        /* If the hardware watchdog is not cleared frequently */
193        /* a reset is generated. */           
194     }   
195 }
196
197
198 /********************@FUNCTION_DECLARATION_END******************/