|
-
- /*
- Description:
- This is a template file for standard C header file.
-
- */
-
- /* ************************************************************************** */
- /* Revision:
- ### 20120515 JFM
- Original version.
-
- ### YYYYMMDD Initial, Bug Identification
- Change description.
- */
-
- //JFM WINC TODO
-
-
- #include "define.h"
-
-
- #include "Uart.h"
- #include "BoardCfg.h"
- #include "timer.h"
- #include "Watchdog.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"
- #include "TemperatureSensor.h"
- #include "LoraWatchdog.h"
- #include "LCDCtrl.h"
- #include "SIM7080GInterface.h"
- #include "LTENetworkInterface.h"
- #include "BootloaderInterface.h"
-
- #include "VolumeTransducer.h"
- #include "DACInterface.h"
- #include "AudioConsole.h"
-
- #include "hd44780.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
- #elif defined USE_SYSLOG
- #include "Syslog.h"
- #include "LoraNetworkInterface.h"
- void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
- #endif
-
- #define HEARTBEAT_LED_TIMEOUT 50 //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 = PS4096 //Watchdog timeout = 4,096s
- #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
- #pragma config FSOSCEN = 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
- OSCCONbits.SOSCEN = 0;
-
- #ifndef __32MX330F064H__
- AD1PCFG = 0xFFFF; //Sart with I/O pins configured as digital I/O
- #endif
-
- InitBoard();
- INTEnableInterrupts();
-
- TimerInit();
- InitWatchdog();
- // I2CInit();
- // InitChaletPowerRelay();
- // InitBatteryMonitor();
- // InitHarakiriRelay();
- // InitTempSensor();
-
-
- // InitUart();
- // LoraNetworkInterfaceInit();
- //// InitLoraWatchdog();
-
-
-
- InitSPIFlash();
- // InitLCDCtrl();
-
- // InitLTEModule();
- // LTENetworkInterfaceInit();
-
- VolumeTransducerInit();
- DACInit();
- AudioConsoleInit();
-
- #ifdef USE_SYSLOG
- InitSyslog();
- #endif
-
-
- printf("ChaletDuino V2 Initialized\n");
-
- SPIFlashCheckAndConfigure();
- // TempSensorCheckAndConfigure();
-
- BootloaderInterfaceInit();
-
-
- // SPIFlashErase64KSector(0x180000,1);
- //
- // unsigned char test[100];
- // int i = 0;
- //
- // for(i = 0; i < 100; i++)
- // {
- // test[i] = i;
- // }
- //
- //
- // SPIFlashWriteBuffer(test,100,0x180000);
- //
- // for(i = 0; i < 100; i++)
- // {
- // test[i] = 0;
- // }
- //
- // SPIFlashReadBuffer(test,100,0x180000);
- //
-
-
- #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");
- printf("test %d\n", 1);
-
- EnableWatchdog();
- KickWatchdog();
- mRetCode = 1;
-
- // DACSetValue(BUREAU_DAC_CHANNEL,0xFFFF);
-
- int DACTest = 0;
- int Increment = 10;
- VU1_BACKLIGHT_PIN = LED_ON;
- VU2_BACKLIGHT_PIN = LED_ON;
-
- while(mRetCode == 1)
- {
-
- KickWatchdog();
-
- #ifndef NO_WIFI
- TickWiFi();
- #endif
- TickTerminal();
- // UartTick();
- // ChaletPowerRelayTick();
- // BatteryMonitorTick();
- SyslogTick();
- // TickTempSensor();
- BootloaderInterfaceTick();
-
- VolumeTransducerTick();
- AudioConsoleTick();
- // TickLoraWatchdog();
- // TickLCDCtrl();
- // TickLTEModule();
- // TickLTENetworkInterface();
-
- if(IsTimerExpired(HEARTBEAT_LED_TMR))
- {
- HEARTBEAT_LED_2_PIN = ~HEARTBEAT_LED_2_PIN;
- //
- // ONBOARD_LED2_PIN = ~HEARTBEAT_LED_2_PIN;
- // ONBOARD_LED3_PIN = ~HEARTBEAT_LED_2_PIN;
- // ONBOARD_LED7_PIN = ~HEARTBEAT_LED_2_PIN;
- PUSH_BUTTON_LED1_PIN = !PUSH_BUTTON_INPUT1_PIN;
- PUSH_BUTTON_LED2_PIN = !PUSH_BUTTON_INPUT2_PIN;
- PUSH_BUTTON_LED3_PIN = !PUSH_BUTTON_INPUT3_PIN;
- PUSH_BUTTON_LED4_PIN = !PUSH_BUTTON_INPUT4_PIN;
- PUSH_BUTTON_LED5_PIN = !PUSH_BUTTON_INPUT5_PIN;
- PUSH_BUTTON_LED6_PIN = !PUSH_BUTTON_INPUT6_PIN;
- PUSH_BUTTON_LED7_PIN = !PUSH_BUTTON_INPUT7_PIN;
-
-
- DACSetValue(BUREAU_DAC_CHANNEL,DACTest);
- DACSetValue(CUISINE_DAC_CHANNEL,DACTest);
- DACTest += Increment;
- if(DACTest > 1013)
- Increment = -10;
- if(DACTest <= 10)
- Increment = 10;
-
-
-
- TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT);
-
- }
- }
-
- return mRetCode;
- }
-
-
- void InitializeBoard()
- {
- InitBoard();
-
- }
-
- #ifdef USE_PRINTF
- void _mon_putc(char c)
- {
- U2TXREG = c;
- while (U2STAbits.TRMT==0);
- }
- #elif defined USE_SYSLOG
- void _mon_putc(char c)
- {
- SyslogNewByte(c);
- }
-
- #endif
-
- //EOF
|