25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 
 
 

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