You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

287 lines
5.7 KiB

  1. /*
  2. Description:
  3. This is a template file for standard C header file.
  4. */
  5. /* ************************************************************************** */
  6. /* Revision:
  7. ### 20120515 JFM
  8. Original version.
  9. ### YYYYMMDD Initial, Bug Identification
  10. Change description.
  11. */
  12. //JFM WINC TODO
  13. #include "define.h"
  14. #include "Uart.h"
  15. #include "BoardCfg.h"
  16. #include "timer.h"
  17. #include "Watchdog.h"
  18. //#include "PWMCtrl.h"
  19. //#include "KnobEncoderCtrl.h"
  20. //#include "LedLightCtrl.h"
  21. //#include "PrintfServer.h"
  22. //#include "MasterCtrlInterface.h"
  23. //#include "SDCardMgr.h"
  24. //#include "FatFS/ff.h"
  25. #include "main.h"
  26. #include "NetworkProtocol.h"
  27. #include "ChaletPowerRelay.h"
  28. #include "BatteryMonitor.h"
  29. #include "CurrentSensor.h"
  30. #include "I2C.h"
  31. #include "SPI_Flash.h"
  32. #include "TemperatureSensor.h"
  33. #include "LoraWatchdog.h"
  34. #include "LCDCtrl.h"
  35. #include "SIM7080GInterface.h"
  36. #include "LTENetworkInterface.h"
  37. #include "BootloaderInterface.h"
  38. #include "VolumeTransducer.h"
  39. #include "DACInterface.h"
  40. #include "AudioConsole.h"
  41. #include "VUMeter.h"
  42. #include "PushBtnMgr.h"
  43. #include "AudioConsoleLedMgr.h"
  44. #include "hd44780.h"
  45. //#define NO_WIFI
  46. #ifndef NO_WIFI
  47. #include "Terminal.h"
  48. #include "WiFiCtrl.h"
  49. #include "InternalUart.h"
  50. #endif
  51. #ifdef USE_PRINTF
  52. void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
  53. #elif defined USE_SYSLOG
  54. #include "Syslog.h"
  55. #include "LoraNetworkInterface.h"
  56. void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
  57. #endif
  58. #define HEARTBEAT_LED_TIMEOUT 50 //400
  59. #define VOLTS_PER_BITS (float)3.3/1023
  60. static void InitializeBoard(void);
  61. #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF, WDTPS = PS4096 //Watchdog timeout = 4,096s
  62. #pragma config POSCMOD = EC, FNOSC = PRIPLL, FPBDIV = DIV_1
  63. //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1
  64. #pragma config ICESEL = ICS_PGx2, BWP = OFF
  65. #pragma config FSOSCEN = OFF
  66. int main(void)
  67. {
  68. int mRetCode = 1;
  69. SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); //Use peripheral library to optimize configuration
  70. INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);// configure for multi-vectored mode interrupts
  71. OSCCONbits.SOSCEN = 0;
  72. #ifndef __32MX330F064H__
  73. AD1PCFG = 0xFFFF; //Sart with I/O pins configured as digital I/O
  74. #endif
  75. InitBoard();
  76. INTEnableInterrupts();
  77. TimerInit();
  78. InitWatchdog();
  79. // I2CInit();
  80. // InitChaletPowerRelay();
  81. // InitBatteryMonitor();
  82. // InitHarakiriRelay();
  83. // InitTempSensor();
  84. // InitUart();
  85. // LoraNetworkInterfaceInit();
  86. //// InitLoraWatchdog();
  87. InitSPIFlash();
  88. // InitLCDCtrl();
  89. // InitLTEModule();
  90. // LTENetworkInterfaceInit();
  91. VolumeTransducerInit();
  92. DACInit();
  93. AudioConsoleInit();
  94. VUMeterInit();
  95. PushBtnMgrInit();
  96. AudioConsoleLedMgrInit();
  97. #ifdef USE_SYSLOG
  98. InitSyslog();
  99. #endif
  100. printf("ChaletDuino V2 Initialized\n");
  101. SPIFlashCheckAndConfigure();
  102. // TempSensorCheckAndConfigure();
  103. BootloaderInterfaceInit();
  104. // SPIFlashErase64KSector(0x180000,1);
  105. //
  106. // unsigned char test[100];
  107. // int i = 0;
  108. //
  109. // for(i = 0; i < 100; i++)
  110. // {
  111. // test[i] = i;
  112. // }
  113. //
  114. //
  115. // SPIFlashWriteBuffer(test,100,0x180000);
  116. //
  117. // for(i = 0; i < 100; i++)
  118. // {
  119. // test[i] = 0;
  120. // }
  121. //
  122. // SPIFlashReadBuffer(test,100,0x180000);
  123. //
  124. #ifndef NO_WIFI
  125. InitTerminal();
  126. InitWiFi();
  127. #endif
  128. // unsigned int bw;
  129. // FRESULT res;
  130. // res = f_mount(&FatFs, "", 0); /* Give a work area to the default drive */
  131. // if(!res)
  132. // {
  133. // printf("Could not mount SD card\n");
  134. // }
  135. // else
  136. // {
  137. // printf("SD Card mounted successfuly");
  138. // }
  139. //
  140. // if (f_open(&File[0], "newfile.txt", FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) /* Create a file */
  141. //// {
  142. //
  143. // res = f_write(&File[0], "It works!\r\n", 11, &bw); /* Write data to the file */
  144. //
  145. // res = f_close(&File[0]); /* Close the file */
  146. //
  147. // }
  148. // int res = OpenPrintfServer();
  149. TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT);
  150. // printf("Lora Monitor Started\n");
  151. printf("test %d\n", 1);
  152. EnableWatchdog();
  153. KickWatchdog();
  154. mRetCode = 1;
  155. // DACSetValue(BUREAU_DAC_CHANNEL,0xFFFF);
  156. int DACTest = 0;
  157. int Increment = 10;
  158. while(mRetCode == 1)
  159. {
  160. KickWatchdog();
  161. #ifndef NO_WIFI
  162. TickWiFi();
  163. #endif
  164. TickTerminal();
  165. // UartTick();
  166. // ChaletPowerRelayTick();
  167. // BatteryMonitorTick();
  168. SyslogTick();
  169. // TickTempSensor();
  170. BootloaderInterfaceTick();
  171. VolumeTransducerTick();
  172. AudioConsoleTick();
  173. PushButtonMgrTick();
  174. AudioConsoleLedMgrTick();
  175. // TickLoraWatchdog();
  176. // TickLCDCtrl();
  177. // TickLTEModule();
  178. // TickLTENetworkInterface();
  179. if(IsTimerExpired(HEARTBEAT_LED_TMR))
  180. {
  181. HEARTBEAT_LED_2_PIN = ~HEARTBEAT_LED_2_PIN;
  182. // DACSetValue(BUREAU_DAC_CHANNEL,DACTest);
  183. // DACSetValue(CUISINE_DAC_CHANNEL,DACTest);
  184. // DACTest += Increment;
  185. // if(DACTest > 1013)
  186. // Increment = -10;
  187. // if(DACTest <= 10)
  188. // Increment = 10;
  189. TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT);
  190. }
  191. }
  192. return mRetCode;
  193. }
  194. void InitializeBoard()
  195. {
  196. InitBoard();
  197. }
  198. #ifdef USE_PRINTF
  199. void _mon_putc(char c)
  200. {
  201. U2TXREG = c;
  202. while (U2STAbits.TRMT==0);
  203. }
  204. #elif defined USE_SYSLOG
  205. void _mon_putc(char c)
  206. {
  207. SyslogNewByte(c);
  208. }
  209. #endif
  210. //EOF