• Main Page
  • Modules
  • Data Structures
  • Files
  • Directories
  • File List
  • Globals

main.c

Go to the documentation of this file.
00001 
00044 #include "lpc_config.h"
00045 
00046 #include "uart/uart.h"
00047 #include "timer/timer.h"
00048 #include "rtc/rtc.h"
00049 #include "eth/eth.h"
00050 #include "i2c/i2c.h"
00051 #include "lcd/lcd.h"
00052 #include "cli/cli.h"
00053 #include "sft/grlib/grlib.h"
00054 #include "mult/api_services.h"
00055 #include <stdio.h>
00056 
00057 /* Function prototypes */
00058 void PLLInit( void );
00059 void GPIOInit(void);
00060 void LCDbcd(int val);
00061 
00062 
00063 extern volatile int I2CCount;
00064 extern volatile char I2CMasterBuffer[BUFSIZE];
00065 extern volatile int I2CCmd, I2CMasterState;
00066 extern volatile int I2CReadLength, I2CWriteLength;
00067 
00068 int read_temp(void)
00069 {
00070   int i;
00071 
00072 
00073   for ( i = 0; i < BUFSIZE; i++ )       /* clear buffer */
00074   {
00075         I2CMasterBuffer[i] = 0;
00076   }
00077   I2CWriteLength = 2;
00078   I2CReadLength = 0;
00079   I2CMasterBuffer[0] = LM75_ADDR;
00080   I2CMasterBuffer[1] = LM75_CONFIG;
00081   I2CMasterBuffer[2] = 0x00;
00082 
00083   I2CCmd = LM75_CONFIG;
00084   I2CEngine();
00085 
00086   for ( i = 0; i < BUFSIZE; i++ )
00087   {
00088         I2CMasterBuffer[i] = 0;
00089   }
00090   I2CWriteLength = 1;
00091   I2CReadLength = 2;
00092   I2CMasterBuffer[0] = LM75_ADDR;
00093   I2CMasterBuffer[1] = LM75_TEMP;
00094   I2CMasterBuffer[2] = LM75_ADDR | RD_BIT;
00095   I2CCmd = LM75_TEMP;
00096   I2CEngine();
00097 
00098   /* The temp reading value should reside in I2CMasterBuffer char 3, 4, ... */
00099   return (I2CMasterBuffer[3] << 8 | I2CMasterBuffer[4]);
00100 }
00101 
00102 void LigaAC()
00103 {
00104 //      Liga 1.23
00105 //      PINSEL3 &= ~(3<<14); //1.23 GPIO
00106 //      PINMODE3 |= 3<<14;   //1.23 Pull Down
00107         FIO1DIR |= (1<<23); //1.23 Output
00108         FIO1SET = 1<<23;     //1.23 ON
00109 }
00110 void DesligaAC()
00111 {
00112 //      Desliga 1.23
00113 //      PINSEL3 &= ~(3<<14); //1.23 GPIO
00114 //      PINMODE3 |= 3<<14;   //1.23 Pull Down
00115         FIO1DIR |= (1<<23); //1.23 Output
00116         FIO1CLR = 1<<23;     //1.23 OFF
00117 }
00118 
00119 
00120 
00121 RTCTime localtime;
00122 unsigned char temp0, temp1, setpoint, ac_auto_on, ac_modo;
00123 
00124 int main( void )
00125 {
00126         int i;
00127         int temp;
00128         char  str[20];
00129         char buff[MAX_TAM_SIZE_STRING];
00130         char dest[MAX_COMMAND_SIZE];
00131         str_t *tp;
00132         RTCTime temp_time;
00133         struct txtinfo stxt;
00134         PLLInit();
00135         GPIOInit();
00136 
00137     RTCInit();
00138     RTCStart();
00139 
00140     UARTInit(115200,UART_CH_0,0);
00141 
00142 
00143         uart_puts("\nDelay test: ");
00144         delayMs(1000);
00145         uart_putc('.');
00146         delayMs(1000);
00147         uart_putc('.');
00148         uart_puts(" Ok\n");
00149 
00150         uart_puts("RTC test: ..");
00151         temp_time = RTCGetTime();
00152         RTCClearTime();
00153         delayMs(1000);
00154         temp_time = RTCGetTime();
00155         uart_puts(" Ok\n");
00156 
00157         T0Init(1000);
00158         T0Start();
00159         uart_puts("Timer test: ");
00160         delayMs(1000);
00161         uart_puts(" Ok\n");
00162 
00163         uart_puts("Init lcd ..");
00164         init_lcd();
00165         lcd_clr();
00166         lcd_goto(1,0);
00167         lcd_string("UIP Aplication");
00168         uart_puts("Ok");
00169 
00170         uart_puts("\nETH...");
00171         ethernet_init();
00172         uart_puts(" Ok");
00173 
00174 
00175         uart_puts("\nI2C...");
00176         temp = I2CInit( (int)I2CMASTER );
00177         if (temp!=TRUE) uart_puts("erro");
00178         uart_puts("initd...");
00179         temp=read_temp();
00180         temp1 = temp>>8;
00181         temp0 = temp&0xf;
00182         sprintf(str, " %d,%dC ",temp1,temp0 );
00183         uart_puts(str);
00184         uart_puts("Ok");
00185 
00186     uart_puts("\nNokia LCD init.. ");
00187     lcd_nokia_init(&stxt);      /* Inicializa display grafico (fundo branco) */
00188     uart_puts(" ok\n");
00189 
00190 
00191         do_init(tp);
00192         uart_puts(tp->resp);
00193         uart_puts(CLI_PROMPT);
00194         UARTTakeString(dest, UART_CH_0);
00195         CLI_Builder(dest, buff);
00196         uart_puts(buff);
00197 
00198         while(1)
00199     {
00200                 fflush(stdout);
00201 
00202                 /* Escreve hora:minuto:segundo no LCD de texto */
00203                 lcd_goto(2,0);
00204                 LCDbcd(RTC_HOUR);
00205                 lcd_putc(':');
00206                 LCDbcd(RTC_MIN);
00207                 lcd_putc(':');
00208                 LCDbcd(RTC_SEC);
00209 
00210 #if 0
00211                 if(global_chat_flag==0){//se em 1 significa que uart esta dedicada para atender o chat.
00212                         if(UARTTakeStringAsync(dest, UART_CH_0) == 0){
00213                                 if (strlen(dest)>2){
00214                                 CLI_Builder(dest,buff);
00215                                 uart_puts(buff);
00216                                 memset(dest, '\0', sizeof(dest));
00217 
00218                                 if(global_chat_flag==0) uart_puts(CLI_PROMPT);
00219                                 }
00220                         }
00221                 }
00222 
00223 #endif
00224 
00225         if(global_chat_flag!=1){//se em 1 significa que uart esta dedivada para atender o chat.
00226                 uart_puts(CLI_PROMPT);
00227                 UARTTakeString(dest, UART_CH_0);
00228                 if (strlen(dest)>2){
00229                 CLI_Builder(dest,buff);
00230                 uart_puts(buff);
00231                 memset(dest, '\0', sizeof(dest));
00232                 }
00233         }
00234 
00235 
00236 
00237         }
00238 
00239 
00240 
00241         return 0;
00242 }
00243 
00244 
00245 void PLLInit( void )
00246 {
00247         int i;
00248         #ifdef RUN_FROM_RAM
00249                 /* Remap the interrupt vectors to RAM if we are are running from RAM. */
00250                 SCB_MEMMAP = 2;
00251         #endif
00252 
00253         /* Disable the PLL. */
00254         PLLCON = 0;
00255         PLLFEED = PLL_FEED_BYTE1;
00256         PLLFEED = PLL_FEED_BYTE2;
00257 
00258         /* Configure clock source. */
00259         SCS |= OSC_ENABLE;
00260         while( !( SCS & OSC_STAT ) );
00261         CLKSRCSEL = OSC_SELECT;
00262 
00263         /* Setup the PLL to multiply the XTAL input by 8. */
00264         PLLCFG = ( PLL_MUL | PLL_DIV );
00265         PLLFEED = PLL_FEED_BYTE1;
00266         PLLFEED = PLL_FEED_BYTE2;
00267 
00268         /* Turn on and wait for the PLL to lock... */
00269         PLLCON = PLL_ENABLE;
00270         PLLFEED = PLL_FEED_BYTE1;
00271         PLLFEED = PLL_FEED_BYTE2;
00272         /* Configurate CPU clock to divide PLL by 4... */
00273         CCLKCFG = CPU_CLK_DIV;
00274         while( !( PLLSTAT & PLL_LOCK ) );
00275 
00276         /* Connecting the clock. */
00277         PLLCON = PLL_CONNECT;
00278         PLLFEED = PLL_FEED_BYTE1;
00279         PLLFEED = PLL_FEED_BYTE2;
00280         while( !( PLLSTAT & PLL_CONNECTED ) );
00281 
00282         MAMCR = 0;
00283         MAMTIM = 3;
00284         MAMCR = 2;
00285 
00286 }
00287 void GPIOInit(void)
00288 {
00289         // Set to inputs
00290         IODIR0  = 0;
00291         IODIR1  = 0;
00292         FIO0DIR = 0;
00293         FIO1DIR = 0;
00294         FIO2DIR = 0;
00295         FIO3DIR = 0;
00296         FIO4DIR = 0;
00297 
00298         // Enable Fast GPIO
00299         SCS|=0x01;
00300 
00301         // clear mask registers
00302         FIO0MASK =0;
00303         FIO1MASK =0;
00304         FIO2MASK =0;
00305         FIO3MASK =0;
00306         FIO4MASK = 0;
00307 
00308         // Reset all GPIO pins to default primary function
00309         PINSEL0 =0;
00310         PINSEL1 =0;
00311         PINSEL2 =0;
00312         PINSEL3 =0;
00313         PINSEL4 =0;
00314         PINSEL5 =0;
00315         PINSEL6 =0;
00316         PINSEL7 =0;
00317         PINSEL8 =0;
00318         PINSEL9 =0;
00319         PINSEL10= 0;
00320         PINSEL11= 0;
00321 
00322 //      PCONP = 0xC00006; //All timers on only
00323 }
00324 
00325 void DABT_Routine()
00326 {
00327         register unsigned long *r14 asm("%lr");
00328         unsigned long reg;
00329         char str[50];
00330         reg = (unsigned long)r14;
00331         sprintf(str, "\nData Abort Exception at 0x%x : OPCODE=0x%x", reg-8, *(unsigned long*)(reg-8));
00332         uart_puts(str);
00333         disableIRQ();
00334         while(1);
00335 }
00336 
00337 void PABT_Routine()
00338 {
00339         register unsigned long *r14 asm("%r14");
00340         unsigned long reg;
00341         char str[50];
00342         reg = (unsigned long)r14;
00343         sprintf(str, "\nPrefetch Abort Exception at 0x%x", reg-4);
00344         uart_puts(str);
00345         disableIRQ();
00346         while(1);
00347 }
00348 
00349 void LCDbcd(int val)
00350 {
00351         lcd_putc((val / 10)  + '0');
00352         lcd_putc((val % 10) + '0');
00353 }
00354 
00355 
00356 void SWI_Routine(){     uart_puts("SWI"); disableIRQ(); while(1);}
00357 void FIQ_Routine(){     uart_puts("FIQ"); disableIRQ(); while(1);}
00358 void UNDF_Routine(){ uart_puts("UNDEF"); disableIRQ();  while(1);}
00359 
00360 

Generated on Fri Jun 17 2011 01:55:43 for Mult-UIP by  doxygen 1.7.1