2017-05-30 22:58:20 +00:00
|
|
|
#include "ch.h"
|
|
|
|
#include "hal.h"
|
|
|
|
|
|
|
|
#include "debug.h"
|
2017-09-01 22:36:45 +00:00
|
|
|
#include "threads.h"
|
2017-05-30 22:58:20 +00:00
|
|
|
#include "padc.h"
|
|
|
|
#include "usbcfg.h"
|
2017-07-26 22:35:48 +00:00
|
|
|
#include "shell.h"
|
|
|
|
|
|
|
|
static const ShellCommand commands[] = {
|
|
|
|
{"dbgon", debugOnUSB_On},
|
|
|
|
{"dbgoff", debugOnUSB_Off},
|
2017-09-08 14:28:01 +00:00
|
|
|
{"picture", printPicture},
|
2017-07-26 22:35:48 +00:00
|
|
|
// {"printconfig", printConfig}, FIXME: This feature is faulty at the moment
|
|
|
|
{NULL, NULL}
|
|
|
|
};
|
|
|
|
|
|
|
|
static const ShellConfig shell_cfg = {
|
|
|
|
(BaseSequentialStream *)&SDU1,
|
|
|
|
commands
|
|
|
|
};
|
2017-05-30 22:58:20 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Main routine is starting up system, runs the software watchdog (module monitoring), controls LEDs
|
|
|
|
*/
|
|
|
|
int main(void) {
|
|
|
|
halInit(); // Startup HAL
|
|
|
|
chSysInit(); // Startup RTOS
|
|
|
|
|
2017-07-01 02:12:22 +00:00
|
|
|
// Voltage switching (1.8V <=> 3.0V)
|
2017-09-07 19:56:00 +00:00
|
|
|
if(ACTIVATE_USB || ACTIVATE_3V)
|
2017-07-01 02:12:22 +00:00
|
|
|
{
|
|
|
|
boost_voltage(true); // Ramp up voltage to 3V
|
|
|
|
chThdSleepMilliseconds(100);
|
|
|
|
}
|
2017-05-30 22:58:20 +00:00
|
|
|
|
2017-06-12 14:46:03 +00:00
|
|
|
// Init debugging (Serial debug port, LEDs)
|
|
|
|
DEBUG_INIT();
|
2017-05-30 22:58:20 +00:00
|
|
|
TRACE_INFO("MAIN > Startup");
|
|
|
|
|
2017-09-07 19:56:00 +00:00
|
|
|
// Start USB
|
|
|
|
if(ACTIVATE_USB)
|
2017-07-01 02:12:22 +00:00
|
|
|
{
|
|
|
|
sduObjectInit(&SDU1);
|
|
|
|
sduStart(&SDU1, &serusbcfg);
|
|
|
|
|
|
|
|
usbDisconnectBus(serusbcfg.usbp);
|
|
|
|
chThdSleepMilliseconds(100);
|
|
|
|
usbStart(serusbcfg.usbp, &usbcfg);
|
|
|
|
usbConnectBus(serusbcfg.usbp);
|
2017-07-24 22:46:23 +00:00
|
|
|
usb_initialized = true;
|
2017-07-01 02:12:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Startup threads
|
2017-06-12 14:46:03 +00:00
|
|
|
start_essential_threads(); // Startup required modules (tracking managemer, watchdog)
|
|
|
|
start_user_modules(); // Startup optional modules (eg. POSITION, LOG, ...)
|
2017-05-30 22:58:20 +00:00
|
|
|
|
2017-06-12 14:46:03 +00:00
|
|
|
// Print time every 10 sec
|
2017-05-30 22:58:20 +00:00
|
|
|
while(true) {
|
2017-07-26 22:35:48 +00:00
|
|
|
if (SDU1.config->usbp->state == USB_ACTIVE) {
|
2017-09-07 19:56:00 +00:00
|
|
|
thread_t *shelltp = chThdCreateFromHeap(NULL, THD_WORKING_AREA_SIZE(512), "shell", NORMALPRIO+1, shellThread, (void*)&shell_cfg);
|
2017-07-26 22:35:48 +00:00
|
|
|
chThdWait(shelltp);
|
|
|
|
}
|
|
|
|
chThdSleepMilliseconds(1000);
|
2017-05-30 22:58:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|