int main(void) { InitLED(); RED_ON(); RED_OFF(); RED_TOGGLE(); RED_OFF(); GREEN_ON(); GREEN_OFF(); GREEN_TOGGLE(); GREEN_OFF(); BLUE_ON(); BLUE_OFF(); BLUE_TOGGLE(); BLUE_OFF(); if (xTaskCreate( MainTask, /* pointer to the task */ (signed char *)"Main", /* task name for kernel awareness debugging */ configMINIMAL_STACK_SIZE, /* task stack size */ (void*)NULL, /* optional task startup argument */ tskIDLE_PRIORITY, /* initial priority */ (xTaskHandle*)NULL /* optional task handle to create */ ) != pdPASS) { /*lint -e527 */ for(;;){}; /* error! probably out of memory */ /*lint +e527 */ } vTaskStartScheduler(); /* does not return */ return 0; }
/** * Main system entry point */ int main (void) { SystemInit(); /* Initialise Pins */ CUTDOWN_OFF(); HEATER_OFF(); MBED_OFF(); GREEN_OFF(); /* Update the value of SystemCoreClock */ SystemCoreClockUpdate(); /* Initialise Interfaces */ i2c_init(); spi_init(process_imu_frame); // IMU sd_spi_init(); // SD uart_init(); // GPS pwrmon_init(); // ADC /* Initialise Sensors */ init_barometer(); /* SD Card */ if (initialise_card()) { // Initialised to something if (disk_initialize() == 0) { // Disk initialisation was successful sd_good = 1; } } GREEN_ON(); /* Configure the SysTick */ NVIC_SetPriority(SysTick_IRQn, 0); // Highest Priority Interrupt SysTick_Config(SystemCoreClock / RTTY_BAUD); /* Watchdog - Disabled for debugging */ #ifndef WATCHDOG_DISABLED init_watchdog(); #endif struct barometer* b; struct imu_raw ir; struct gps_data gd; struct gps_time gt; double alt, ext_temp; int tx_length; // The length of the built tx string char tx_string[TX_STRING_LENGTH]; while (1) { /* Grab Data */ pwrmon_start(pwrmon_callback); b = get_barometer(); get_imu_raw_data(&ir); get_gps_data(&gd); get_gps_time(>); ext_temp = get_temperature(); /* Data Processing */ if (b->valid) { alt = pressure_to_altitude(b->pressure); } else { alt = -1; b->temperature = -1; } /* Act on the data */ control_gsm(alt); control_cutdown(ticks_until_cutdown, alt); control_heater(b->temperature); /* Create a protocol string */ int cutstat; if (ticks_until_cutdown == 0) { cutstat = -1; } else { cutstat = ticks_until_cutdown / (RTTY_BAUD*60); } tx_length = build_communications_frame(tx_string, TX_STRING_LENGTH, >, b, &gd, alt, ext_temp, &ir, cutstat, cutdown_voltage); /* Transmit - Quietly fails if another transmission is ongoing */ rtty_set_string(tx_string, tx_length); /* Store */ if (sd_good) { tx_length -= 2; // Remove \n\0 tx_length += communications_frame_add_extra(tx_string + tx_length, TX_STRING_LENGTH - tx_length, &ir); disk_write_next_block((uint8_t*)tx_string, tx_length+1); // Include null terminator } /* Housekeeping */ GREEN_TOGGLE(); feed_watchdog(); } }