main.c 2.74 KB
Newer Older
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
1
2
#include "ch.h"
#include "hal.h"
3
#include "board.h"
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
4
#include "chprintf.h"
5

6
#include "./threads/status.h"
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
7
#include "./threads/sensors.h"
8
#include "./threads/display.h"
9
#include "./threads/dac.h"
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
10
#include "./threads/comm.h"
11
#include "./usb/usbcfg.h"
12

13
// Callback placeholders
14
15
16
#define usb_lld_connect_bus(usbp)
#define usb_lld_disconnect_bus(usbp)

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
/*
 * Application entry point.
 */
int main(void) {

  /*
   * System initializations.
   * - HAL initialization, this also initializes the configured device drivers
   *   and performs the board-specific initializations.
   * - Kernel initialization, the main() function becomes a thread and the
   *   RTOS is active.
   */
  halInit();
  chSysInit();

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
32
33
34
35
36
37
38
39
40
41
42
43
44
45
  /*
   * Configures GPIO
   */
  palSetLineMode(LINE_LED0, PAL_MODE_OUTPUT_PUSHPULL); // LED0 output
  palSetLineMode(LINE_LED1, PAL_MODE_OUTPUT_PUSHPULL); // LED1 output
  palSetLineMode(LINE_LED2, PAL_MODE_OUTPUT_PUSHPULL); // LED2 output
  palSetPadMode(GPIOB, 6, PAL_MODE_ALTERNATE(4)); // I2C1 SCL
  palSetPadMode(GPIOB, 7, PAL_MODE_ALTERNATE(4)); // I2C1 SDA
  palSetPadMode(GPIOB, 10, PAL_MODE_ALTERNATE(7)); // UART3
  palSetPadMode(GPIOB, 11, PAL_MODE_ALTERNATE(7)); // UART3
  palSetPadMode(GPIOA, 11, PAL_MODE_ALTERNATE(14)); // USB
  palSetPadMode(GPIOA, 12, PAL_MODE_ALTERNATE(14)); // USB
  palSetPadMode(GPIOA, 1, PAL_MODE_INPUT_ANALOG); // ADC1_IN2 
  palSetPadMode(GPIOB, 13, PAL_MODE_INPUT_ANALOG); // ADC3_IN5
46
47
  palSetPadMode(GPIOA, 4, PAL_MODE_INPUT_ANALOG); // Reduce power consumption as we're using the DAC here
  palSetPadMode(GPIOA, 5, PAL_MODE_INPUT_ANALOG); // Reduce power consumption as we're using the DAC here
48

49
50
51
  /*
   * Initializes USB serial interfaces
   */
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
52
  chThdSleepMilliseconds(500);
53
54
55
56
57
58
59
60
  sduObjectInit(&SDU1);
  sduStart(&SDU1, &serusbcfg1);
  sduObjectInit(&SDU2);
  sduStart(&SDU2, &serusbcfg2);

  usbStart(serusbcfg1.usbp, &usbcfg);
  usbConnectBus(serusbcfg1.usbp);

Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
61
62
63
64
65
66
  /*
   * Activates the serial driver 3 using the driver default configuration.
   */
  sdStart(&SD3, NULL);

  /*
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
67
   * Activates the ADC 1 and 3 drivers
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
68
   */
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
69
70
  adcStart(&ADCD1, NULL);
  adcStart(&ADCD3, NULL);
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
71

72
73
74
  /*
   * Starts running the threads
   */
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
75
  //chThdSleepMilliseconds(500);
76
  chThdCreateStatic(waStatus, sizeof(waStatus), NORMALPRIO, Status, NULL);
77
//  chThdCreateStatic(waDisplay, sizeof(waDisplay), NORMALPRIO, Display, NULL);
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
78
  chThdCreateStatic(waSensors, sizeof(waSensors), NORMALPRIO, Sensors, NULL);
79
  chThdCreateStatic(waDAC, sizeof(waDAC), NORMALPRIO, DACt, NULL);
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
80
  chThdCreateStatic(waComm, sizeof(waComm), NORMALPRIO, Comm, NULL);
81
  
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
82
  /*
83
84
   * Normal main() thread activity.
   * For now it just sleeps in a loop.
Pedro Henrique Kopper's avatar
Pedro Henrique Kopper committed
85
86
87
88
89
   */
  while (true) {
    chThdSleepMilliseconds(500);
  }
}