/* Description: This is a template file for standard C header file. */ /* ************************************************************************** */ /* Revision: ### 20120515 JFM Original version. ### YYYYMMDD Initial, Bug Identification Change description. */ #include "define.h" #include "Uart.h" #include "BoardCfg.h" #include "timer.h" //#include "PWMCtrl.h" //#include "KnobEncoderCtrl.h" //#include "LedLightCtrl.h" //#include "PrintfServer.h" //#include "MasterCtrlInterface.h" //#include "SDCardMgr.h" //#include "FatFS/ff.h" #include "main.h" #include "NetworkProtocol.h" #include "ChaletPowerRelay.h" #include "BatteryMonitor.h" #include "CurrentSensor.h" #include "I2C.h" #include "SPI_Flash.h" //#define NO_WIFI #ifndef NO_WIFI #include "Terminal.h" #include "WiFiCtrl.h" #include "InternalUart.h" #endif #ifdef USE_PRINTF void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B #endif #define HEARTBEAT_LED_TIMEOUT 400 #define VOLTS_PER_BITS (float)3.3/1023 static void InitializeBoard(void); #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF, WDTPS = PS128 #pragma config POSCMOD = EC, FNOSC = PRIPLL, FPBDIV = DIV_1 //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1 #pragma config ICESEL = ICS_PGx2, BWP = OFF int main(void) { int mRetCode = 1; SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); //Use peripheral library to optimize configuration INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);// configure for multi-vectored mode interrupts #ifndef __32MX330F064H__ AD1PCFG = 0xFFFF; //Sart with I/O pins configured as digital I/O #endif InitBoard(); INTEnableInterrupts(); TimerInit(); // I2CInit(); InitChaletPowerRelay(); InitBatteryMonitor(); InitUart(); ProtocolInit(); InitSPIFlash(); printf("ChaletDuino V2 Initialized\n"); SPIFlashCheckAndConfigure(); #ifndef NO_WIFI InitTerminal(); InitWiFi(); #endif // unsigned int bw; // FRESULT res; // res = f_mount(&FatFs, "", 0); /* Give a work area to the default drive */ // if(!res) // { // printf("Could not mount SD card\n"); // } // else // { // printf("SD Card mounted successfuly"); // } // // if (f_open(&File[0], "newfile.txt", FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) /* Create a file */ //// { // // res = f_write(&File[0], "It works!\r\n", 11, &bw); /* Write data to the file */ // // res = f_close(&File[0]); /* Close the file */ // // } // int res = OpenPrintfServer(); TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT); // printf("Lora Monitor Started\n"); // EnableWatchdog(); mRetCode = 1; // unsigned int LoraData = 0; // float raw,conv; // AD1CON1bits.SAMP = 1; while(mRetCode == 1) { // mRetCode = RunPA(); // UartTick(); #ifndef NO_WIFI TickWiFi(); #endif TickTerminal(); UartTick(); ChaletPowerRelayTick(); BatteryMonitorTick(); if(IsTimerExpired(HEARTBEAT_LED_TMR)) { HEARTBEAT_LED_1_PIN = ~HEARTBEAT_LED_1_PIN; TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT); // AD1CON1bits.SAMP = 0; // while(AD1CON1bits.DONE == 0); // adc = ADC1BUF0; // AD1CON1bits.SAMP = 1; // adc &= 0xFFFE; // conv = (float)adc / 1023; // conv *= 3.3; // raw = conv; // conv *= 11; // conv += 0.2; // printf("Value: 0x%x - %f - %f\n",adc,raw,conv); } } return mRetCode; } void InitializeBoard() { InitBoard(); } #ifdef USE_PRINTF void _mon_putc(char c) { U2TXREG = c; while (U2STAbits.TRMT==0); } #endif //EOF