168 lines
4.0 KiB
C
168 lines
4.0 KiB
C
#include "cmsis_os.h"
|
|
#include "at32f435_437_clock.h"
|
|
#include "MainModesArbiter.h"
|
|
#include "Gpios.h"
|
|
#include "Adcs.h"
|
|
#include "StorageOnFlash.h"
|
|
#include "Rtcs.h"
|
|
#include "PeripheralInterfaces.h"
|
|
#include <FirmwareLoader.h>
|
|
#include "JSONSettings.h"
|
|
//#include "i2c_smbus.h"
|
|
#include "delay_sec.h"
|
|
#include "stdlib.h"
|
|
|
|
#include "at32_emac.h"
|
|
#include "netconf.h"
|
|
#include "http_server.h"
|
|
#include "MainModesArbiter.h"
|
|
|
|
#include "DeviceStorageIni.h"
|
|
|
|
#include "md5alg.h"
|
|
|
|
#define FIRMWARE_AREA_LENGTH (1024 * 1024)
|
|
#define FIRMWARE_UPDATE_ADDR (0x08260000)
|
|
#define FIRMWARE_MAIN_ADDR (0x08100000)
|
|
|
|
tFirmwareLoader FIRMWARE_MAIN_LOADER;
|
|
|
|
uint8_t getBit() {
|
|
uint16_t bits = 0;
|
|
bits = (bits << 1) | ((((bits >> 11) ^ (bits >> 9))) & 0b1);
|
|
uint8_t bit = bits & 0b1;
|
|
return bit;
|
|
}
|
|
|
|
#define FIRMWARE_BOOT_AREA_LENGTH (896 * 1024)
|
|
#define FIRMWARE_BOOT_UPDATE_ADDR (0x08000000)
|
|
#define FIRMWARE_BOOT_MAIN_ADDR (0x08000000)
|
|
|
|
tFirmwareLoader FIRMWARE_BOOT_LOADER;
|
|
|
|
tMma MAIN_ENV;
|
|
|
|
volatile uint8_t bufFreeOperation[1500];
|
|
volatile uint8_t bufFreeOperationKV[1500];
|
|
volatile uint8_t bufFillOperation[1500];
|
|
|
|
|
|
extern void main2();
|
|
|
|
extern void FS_Init(tFs *env);
|
|
|
|
void vApplicationStackOverflowHook(TaskHandle_t xTask,
|
|
signed char *pcTaskName) {
|
|
int a = 0;
|
|
}
|
|
|
|
void extend_sram(void);
|
|
|
|
void extend_sram(void) {
|
|
// check if ram has been set to expectant size, if not, change eopb0
|
|
if (((USD->eopb0) & 0x07) != FLASH_EOPB0_SRAM_512K) {
|
|
flash_unlock();
|
|
// erase user system data bytes
|
|
flash_user_system_data_erase();
|
|
|
|
// change sram size
|
|
flash_eopb0_config(FLASH_EOPB0_SRAM_512K);
|
|
|
|
flash_lock();
|
|
|
|
// system reset
|
|
nvic_system_reset();
|
|
}
|
|
}
|
|
|
|
|
|
uint32_t get_fattime(void) {
|
|
struct tm stm;
|
|
RTCS.rtcI0.getTM(&RTCS, &stm);
|
|
|
|
return (DWORD) (stm.tm_year - 80) << 25 |
|
|
(DWORD) (stm.tm_mon + 1) << 21 |
|
|
(DWORD) stm.tm_mday << 16 |
|
|
(DWORD) stm.tm_hour << 11 |
|
|
(DWORD) stm.tm_min << 5 |
|
|
(DWORD) stm.tm_sec >> 1;
|
|
}
|
|
|
|
extern void Mma_InitFs(tMma *env);
|
|
|
|
|
|
osMessageQueueId_t EthDataQueue;
|
|
|
|
//void loop() {
|
|
// volatile uint32_t a = 0;
|
|
// ++a;
|
|
// ++a;
|
|
//}
|
|
|
|
void mx_clkout1_init();
|
|
|
|
int main(void) {
|
|
system_clock_config();
|
|
// asm(".rept 2 ; bl loop ; .endr");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
|
|
memset(bufFreeOperation, 0, sizeof(bufFreeOperation));
|
|
memset(bufFreeOperationKV, 0x56, sizeof(bufFreeOperationKV));
|
|
memset(bufFillOperation, 0x55, sizeof(bufFillOperation));
|
|
|
|
|
|
// md5a_context md5ctx;
|
|
// uint8_t md5sum[16];
|
|
// md5a_starts(&md5ctx);
|
|
// md5a_update(&md5ctx, inp, sizeof(inp));
|
|
// md5a_finish(&md5ctx, md5sum);
|
|
|
|
|
|
// flash_eopb0_config(FLASH_EOPB0_SRAM_512K);
|
|
|
|
delay_init();
|
|
|
|
FirmwareLoader_Init(&FIRMWARE_MAIN_LOADER, FIRMWARE_AREA_LENGTH, FIRMWARE_MAIN_ADDR, FIRMWARE_UPDATE_ADDR);
|
|
FirmwareLoader_Init(&FIRMWARE_BOOT_LOADER, FIRMWARE_BOOT_AREA_LENGTH, FIRMWARE_BOOT_MAIN_ADDR,
|
|
FIRMWARE_BOOT_UPDATE_ADDR);
|
|
|
|
osKernelInitialize();
|
|
|
|
InitPeripheralInterfaces();
|
|
|
|
Mma_Init(&MAIN_ENV, &GPIOS, &ADCS, &SERIAL_PORTS, &RTCS, &NVM_STORAGE, &FIRMWARE_MAIN_LOADER,
|
|
&FIRMWARE_BOOT_LOADER);
|
|
|
|
Mma_InitFs(&MAIN_ENV);
|
|
|
|
DeviceStorageIni_Init(&MAIN_ENV.storageIni, file_setup, file_counter, &MAIN_ENV.fs, settings, SettingSizeTbl);
|
|
|
|
EthDataQueue = osMessageQueueNew(256, 4, NULL);
|
|
|
|
adc_ordinary_software_trigger_enable(MAIN_ENV.adcs->vcc.ADCx, TRUE);
|
|
while (adc_flag_get(MAIN_ENV.adcs->vcc.ADCx, ADC_OCCE_FLAG) == RESET) {
|
|
}
|
|
uint16_t data = adc_ordinary_conversion_data_get(MAIN_ENV.adcs->vcc.ADCx);
|
|
adc_flag_clear(MAIN_ENV.adcs->vcc.ADCx, ADC_OCCO_FLAG);
|
|
|
|
|
|
error_status status = emac_system_init_eth();
|
|
tcpip_stack_init(data);
|
|
|
|
Mma_StartThread(&MAIN_ENV);
|
|
|
|
osKernelStart();
|
|
|
|
while (1) {
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
asm("nop");
|
|
}
|
|
} |