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.
 
 
 
 

291 regels
6.2 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 "hd44780.h"
  42. //#define NO_WIFI
  43. #ifndef NO_WIFI
  44. #include "Terminal.h"
  45. #include "WiFiCtrl.h"
  46. #include "InternalUart.h"
  47. #endif
  48. #ifdef USE_PRINTF
  49. void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
  50. #elif defined USE_SYSLOG
  51. #include "Syslog.h"
  52. #include "LoraNetworkInterface.h"
  53. void _mon_putc(char c); //override from stdio to redirect stdout on uart 3B
  54. #endif
  55. #define HEARTBEAT_LED_TIMEOUT 50 //400
  56. #define VOLTS_PER_BITS (float)3.3/1023
  57. static void InitializeBoard(void);
  58. #pragma config FPLLMUL = MUL_20, FPLLIDIV = DIV_2, FPLLODIV = DIV_1, FWDTEN = OFF, WDTPS = PS4096 //Watchdog timeout = 4,096s
  59. #pragma config POSCMOD = EC, FNOSC = PRIPLL, FPBDIV = DIV_1
  60. //#pragma config POSCMOD = XT, FNOSC = PRIPLL, FPBDIV = DIV_1
  61. #pragma config ICESEL = ICS_PGx2, BWP = OFF
  62. #pragma config FSOSCEN = OFF
  63. int main(void)
  64. {
  65. int mRetCode = 1;
  66. SYSTEMConfig(SYS_FREQ, SYS_CFG_WAIT_STATES | SYS_CFG_PCACHE); //Use peripheral library to optimize configuration
  67. INTConfigureSystem(INT_SYSTEM_CONFIG_MULT_VECTOR);// configure for multi-vectored mode interrupts
  68. OSCCONbits.SOSCEN = 0;
  69. #ifndef __32MX330F064H__
  70. AD1PCFG = 0xFFFF; //Sart with I/O pins configured as digital I/O
  71. #endif
  72. InitBoard();
  73. INTEnableInterrupts();
  74. TimerInit();
  75. InitWatchdog();
  76. // I2CInit();
  77. // InitChaletPowerRelay();
  78. // InitBatteryMonitor();
  79. // InitHarakiriRelay();
  80. // InitTempSensor();
  81. // InitUart();
  82. // LoraNetworkInterfaceInit();
  83. //// InitLoraWatchdog();
  84. InitSPIFlash();
  85. // InitLCDCtrl();
  86. // InitLTEModule();
  87. // LTENetworkInterfaceInit();
  88. VolumeTransducerInit();
  89. DACInit();
  90. AudioConsoleInit();
  91. #ifdef USE_SYSLOG
  92. InitSyslog();
  93. #endif
  94. printf("ChaletDuino V2 Initialized\n");
  95. SPIFlashCheckAndConfigure();
  96. // TempSensorCheckAndConfigure();
  97. BootloaderInterfaceInit();
  98. // SPIFlashErase64KSector(0x180000,1);
  99. //
  100. // unsigned char test[100];
  101. // int i = 0;
  102. //
  103. // for(i = 0; i < 100; i++)
  104. // {
  105. // test[i] = i;
  106. // }
  107. //
  108. //
  109. // SPIFlashWriteBuffer(test,100,0x180000);
  110. //
  111. // for(i = 0; i < 100; i++)
  112. // {
  113. // test[i] = 0;
  114. // }
  115. //
  116. // SPIFlashReadBuffer(test,100,0x180000);
  117. //
  118. #ifndef NO_WIFI
  119. InitTerminal();
  120. InitWiFi();
  121. #endif
  122. // unsigned int bw;
  123. // FRESULT res;
  124. // res = f_mount(&FatFs, "", 0); /* Give a work area to the default drive */
  125. // if(!res)
  126. // {
  127. // printf("Could not mount SD card\n");
  128. // }
  129. // else
  130. // {
  131. // printf("SD Card mounted successfuly");
  132. // }
  133. //
  134. // if (f_open(&File[0], "newfile.txt", FA_WRITE | FA_CREATE_ALWAYS) == FR_OK) /* Create a file */
  135. //// {
  136. //
  137. // res = f_write(&File[0], "It works!\r\n", 11, &bw); /* Write data to the file */
  138. //
  139. // res = f_close(&File[0]); /* Close the file */
  140. //
  141. // }
  142. // int res = OpenPrintfServer();
  143. TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT);
  144. // printf("Lora Monitor Started\n");
  145. printf("test %d\n", 1);
  146. EnableWatchdog();
  147. KickWatchdog();
  148. mRetCode = 1;
  149. // DACSetValue(BUREAU_DAC_CHANNEL,0xFFFF);
  150. int DACTest = 0;
  151. int Increment = 10;
  152. VU1_BACKLIGHT_PIN = LED_ON;
  153. VU2_BACKLIGHT_PIN = LED_ON;
  154. while(mRetCode == 1)
  155. {
  156. KickWatchdog();
  157. #ifndef NO_WIFI
  158. TickWiFi();
  159. #endif
  160. TickTerminal();
  161. // UartTick();
  162. // ChaletPowerRelayTick();
  163. // BatteryMonitorTick();
  164. SyslogTick();
  165. // TickTempSensor();
  166. BootloaderInterfaceTick();
  167. VolumeTransducerTick();
  168. AudioConsoleTick();
  169. // TickLoraWatchdog();
  170. // TickLCDCtrl();
  171. // TickLTEModule();
  172. // TickLTENetworkInterface();
  173. if(IsTimerExpired(HEARTBEAT_LED_TMR))
  174. {
  175. HEARTBEAT_LED_2_PIN = ~HEARTBEAT_LED_2_PIN;
  176. //
  177. // ONBOARD_LED2_PIN = ~HEARTBEAT_LED_2_PIN;
  178. // ONBOARD_LED3_PIN = ~HEARTBEAT_LED_2_PIN;
  179. // ONBOARD_LED7_PIN = ~HEARTBEAT_LED_2_PIN;
  180. PUSH_BUTTON_LED1_PIN = !PUSH_BUTTON_INPUT1_PIN;
  181. PUSH_BUTTON_LED2_PIN = !PUSH_BUTTON_INPUT2_PIN;
  182. PUSH_BUTTON_LED3_PIN = !PUSH_BUTTON_INPUT3_PIN;
  183. PUSH_BUTTON_LED4_PIN = !PUSH_BUTTON_INPUT4_PIN;
  184. PUSH_BUTTON_LED5_PIN = !PUSH_BUTTON_INPUT5_PIN;
  185. PUSH_BUTTON_LED6_PIN = !PUSH_BUTTON_INPUT6_PIN;
  186. PUSH_BUTTON_LED7_PIN = !PUSH_BUTTON_INPUT7_PIN;
  187. DACSetValue(BUREAU_DAC_CHANNEL,DACTest);
  188. DACSetValue(CUISINE_DAC_CHANNEL,DACTest);
  189. DACTest += Increment;
  190. if(DACTest > 1013)
  191. Increment = -10;
  192. if(DACTest <= 10)
  193. Increment = 10;
  194. TimerStart(HEARTBEAT_LED_TMR,HEARTBEAT_LED_TIMEOUT);
  195. }
  196. }
  197. return mRetCode;
  198. }
  199. void InitializeBoard()
  200. {
  201. InitBoard();
  202. }
  203. #ifdef USE_PRINTF
  204. void _mon_putc(char c)
  205. {
  206. U2TXREG = c;
  207. while (U2STAbits.TRMT==0);
  208. }
  209. #elif defined USE_SYSLOG
  210. void _mon_putc(char c)
  211. {
  212. SyslogNewByte(c);
  213. }
  214. #endif
  215. //EOF