}
+/***************************************************************************** */
+/* GPIO */
+
+extern void zero_cross_detect(uint32_t gpio);
+extern void overvoltage_protect(uint32_t gpio);
+
+void board_io_config(void)
+{
+ /* Immediatly turn off Mosfet / Triac */
+ config_gpio(&ac_ctrl, 0, GPIO_DIR_OUT, 1);
+ /* Start with FAN ON */
+ config_gpio(&fan_ctrl, 0, GPIO_DIR_OUT, 1);
+
+ /* Configure Input GPIO */
+ config_gpio(&ext_disable_in_pin, 0, GPIO_DIR_IN, 0);
+ config_gpio(&overtemperature_pin, 0, GPIO_DIR_IN, 0);
+
+ /* Over-voltage protection */
+ set_gpio_callback(overvoltage_protect, &overvoltage_pin, EDGE_RISING);
+
+ /* Zero-crossing detection */
+ set_gpio_callback(zero_cross_detect, &zero_cross_in_pin, EDGE_FALLING);
+}
+
+
/***************************************************************************** */
/* Internal modules */
+
const struct lpc_tc_config ac_timer_conf_zc = {
.mode = LPC_TIMER_MODE_TIMER | LPC_TIMER_MODE_MATCH,
.match_control = { LPC_TIMER_INT_RESET_ON_MATCH, 0, 0, 0, },
ssp_master_on(SSP_BUS_0, LPC_SSP_FRAME_SPI, 8, 4*1000*1000);
adc_on(NULL);
adc_start_burst_conversion(ADC_MCH(0) | ADC_MCH(1) | ADC_MCH(2), LPC_ADC_SEQ(0));
- timer_on(LPC_TIMER_32B0, 0, zero_cross); /* This one is used to generate the second zero-crossing */
+ /* Configure and start timers */
+ /* This one is used to generate the second zero-crossing, which is not seen by the ZC detector */
+ timer_on(LPC_TIMER_32B0, 0, zero_cross);
timer_counter_config(LPC_TIMER_32B0, &ac_timer_conf_zc);
- timer_on(LPC_TIMER_32B1, 0, ac_switch_on); /* This one is used to generate the power PMW */
+ /* This one is used to generate the power PMW */
+ timer_on(LPC_TIMER_32B1, 0, ac_switch_on);
timer_counter_config(LPC_TIMER_32B1, &ac_timer_conf_delay);
- timer_on(LPC_TIMER_16B0, 0, power_track); /* This one is used to call the load power tracking ADC sampler */
+ /* This one is used to call the load power tracking ADC sampler */
+ timer_on(LPC_TIMER_16B0, 0, power_track);
timer_counter_config(LPC_TIMER_16B0, &ac_timer_conf_power_track);
}
/***************************************************************************** */
-extern void zero_cross_detect(uint32_t gpio);
-extern void overvoltage_protect(uint32_t gpio);
-void board_io_config(void)
-{
- /* Immediatly turn off Mosfet / Triac */
- config_gpio(&ac_ctrl, 0, GPIO_DIR_OUT, 1);
- /* Start with FAN ON */
- config_gpio(&fan_ctrl, 0, GPIO_DIR_OUT, 1);
+/* External components */
- /* Configure Input GPIO */
- config_gpio(&ext_disable_in_pin, 0, GPIO_DIR_IN, 0);
- config_gpio(&overtemperature_pin, 0, GPIO_DIR_IN, 0);
+/* Thermocouple reading */
+const struct max31855_sensor_config thermocouple = {
+ .ssp_bus_num = 0,
+ .chip_select = LPC_GPIO_0_7,
+};
- /* Over-voltage protection */
- set_gpio_callback(overvoltage_protect, &overvoltage_pin, EDGE_RISING);
+/* RTC and time */
+#define RTC_ADDR 0xA2
- /* Zero-crossing detection */
- set_gpio_callback(zero_cross_detect, &zero_cross_in_pin, EDGE_FALLING);
+/* TMP101 I2C temperature sensor on Power board */
+#define TMP101_ADDR1 0x94 /* Pin Addr0 (pin5 of tmp101) connected to VCC */
+struct tmp101_sensor_config tmp101_sensor_power = {
+ .bus_num = I2C0,
+ .addr = TMP101_ADDR1,
+ .resolution = TMP_RES_ELEVEN_BITS,
+};
+
+/* TMP101 I2C temperature sensor on display board */
+#define TMP101_ADDR0 0x90 /* Pin Addr0 (pin5 of tmp101) connected to GND */
+struct tmp101_sensor_config tmp101_sensor_display = {
+ .bus_num = I2C0,
+ .addr = TMP101_ADDR0,
+ .resolution = TMP_RES_ELEVEN_BITS,
+};
+
+int temp_read(uint32_t uart, int* deci_degrees_disp, int* deci_degrees_power)
+{
+ int ret = 0;
+ int conv = 0;
+
+ if (interface_board_present != 0) {
+ ret = tmp101_sensor_read(&tmp101_sensor_display, NULL, deci_degrees_disp);
+ if (ret == 0) {
+ conv |= CONV_DISPLAY_OK;
+ } else {
+ uprintf(uart, "TMP101 read error on display board : %d\n", ret);
+ }
+ }
+ if (power_board_present != 0) {
+ ret = tmp101_sensor_read(&tmp101_sensor_power, NULL, deci_degrees_power);
+ if (ret == 0) {
+ conv |= CONV_POWER_OK;
+ } else {
+ uprintf(uart, "TMP101 read error on power board : %d\n", ret);
+ }
+ }
+ return conv;
}
+uint8_t interface_board_present = 0;
+uint8_t power_board_present = 0;
+
+/* Configure external components */
+int external_components_config(uint32_t uart)
+{
+ int ret = 0;
+ int retcode = 0;
+
+ /* RTC : must be done first to be able to access RTC RAM for uSD init */
+ scialys_time_config(I2C0, RTC_ADDR);
+ scialys_time_init_check(uart);
+
+ /* uSD card */
+ scialys_uSD_config((struct pio *)&uSD_cs, SSP_BUS_0);
+ scialys_uSD_detect(uart);
+ scialys_uSD_logs_init(uart);
+
+ /* Thermocouple configuration */
+ max31855_sensor_config(&thermocouple);
+
+ /* TMP101 sensor config on power board */
+ power_board_present = 1;
+ ret = tmp101_sensor_config(&tmp101_sensor_power);
+ if (ret != 0) {
+ uprintf(uart, "Temp config error on power board: %d\n", ret);
+ power_board_present = 0;
+ retcode -= 1;
+ } else {
+ ret = tmp101_sensor_set_continuous_conversion(&tmp101_sensor_power);
+ if (ret != 0) {
+ uprintf(uart, "Temp config part 2 error on power board: %d\n", ret);
+ power_board_present = 0;
+ retcode -= 2;
+ }
+ }
+
+ /* TMP101 sensor config on display board */
+ ret = tmp101_sensor_config(&tmp101_sensor_display);
+ if (ret != 0) {
+ uprintf(uart, "Temp config error on display board: %d\n", ret);
+ interface_board_present = 0;
+ retcode -= 4;
+ } else {
+ ret = tmp101_sensor_set_continuous_conversion(&tmp101_sensor_display);
+ if (ret != 0) {
+ uprintf(uart, "Temp config part 2 error on display board: %d\n", ret);
+ interface_board_present = 0;
+ retcode -= 8;
+ } else {
+ interface_board_present = 1;
+ }
+ }
+
+ /* Configure interface board if present */
+ if (interface_board_present == 1) {
+ ret = interface_config(uart);
+ if (ret != 0) {
+ retcode -= 16;
+ }
+ }
+
+ return retcode;
+}
+
/***************************************************************************** */
-/* Load or update user configuration from internal User Flash */
+/* App config and/or default values :
+ * Load or update user configuration from internal User Flash */
+
/* The configuration is stored in the first user info page.
- * The third one is used to store the "last used" uSD block only once per week
- * in order to prevent deterioration of the flash block. This information is
+ * The third user info page is used to store the "last used" uSD block only once per
+ * week in order to prevent deterioration of the flash block. This information is
* stored in the RTC RAM backed by the supercapa each time a new block is used.
*/
* the board config part to RAM so that access to these is quicker.
* If in need of memory, the config could be used from flash at the expense of execution time
*/
-void read_internal_config(void)
+void scialys_read_internal_config(void)
{
struct scialys_config* conf;
uint8_t* mem = NULL;
}
/* Update the board config in user flash */
-int user_flash_update(void)
+int scialys_user_flash_update(void)
{
uint8_t* mem = NULL;
int ret = 0;
#define MANUAL_TYPE_TARGET 2
#define DEFAULT_MANUAL_FORCE_TYPE MANUAL_TYPE_TARGET
-void check_config(void)
+void scialys_check_config(void)
{
/* If config version error (old config) then only update new fields */
switch (sc_conf.conf_version) {
/* Read main configuration - or set to default one */
void read_scialys_main_config(void)
{
- read_internal_config();
+ scialys_read_internal_config();
/* Config version error ? */
if (sc_conf.conf_version != CONFIG_VERSION) {
sc_conf.config_ok = 0;
return;
}
/* Config is either blank or not up to date, update missing parts with defaults */
- check_config();
-}
-
-
-/***************************************************************************** */
-/* Configure external components */
-
-/* Thermocouple reading */
-const struct max31855_sensor_config thermocouple = {
- .ssp_bus_num = 0,
- .chip_select = LPC_GPIO_0_7,
-};
-
-/* RTC and time */
-#define RTC_ADDR 0xA2
-
-/* TMP101 I2C temperature sensor on Power board */
-#define TMP101_ADDR1 0x94 /* Pin Addr0 (pin5 of tmp101) connected to VCC */
-struct tmp101_sensor_config tmp101_sensor_power = {
- .bus_num = I2C0,
- .addr = TMP101_ADDR1,
- .resolution = TMP_RES_ELEVEN_BITS,
-};
-
-/* TMP101 I2C temperature sensor on display board */
-#define TMP101_ADDR0 0x90 /* Pin Addr0 (pin5 of tmp101) connected to GND */
-struct tmp101_sensor_config tmp101_sensor_display = {
- .bus_num = I2C0,
- .addr = TMP101_ADDR0,
- .resolution = TMP_RES_ELEVEN_BITS,
-};
-
-int temp_read(uint32_t uart, int* deci_degrees_disp, int* deci_degrees_power)
-{
- int ret = 0;
- int conv = 0;
-
- if (interface_board_present != 0) {
- ret = tmp101_sensor_read(&tmp101_sensor_display, NULL, deci_degrees_disp);
- if (ret == 0) {
- conv |= CONV_DISPLAY_OK;
- } else {
- uprintf(uart, "TMP101 read error on display board : %d\n", ret);
- }
- }
- if (power_board_present != 0) {
- ret = tmp101_sensor_read(&tmp101_sensor_power, NULL, deci_degrees_power);
- if (ret == 0) {
- conv |= CONV_POWER_OK;
- } else {
- uprintf(uart, "TMP101 read error on power board : %d\n", ret);
- }
- }
- return conv;
+ scialys_check_config();
}
-
-uint8_t interface_board_present = 0;
-uint8_t power_board_present = 0;
-
-
-int external_comp_config(uint32_t uart)
-{
- int ret = 0;
- int retcode = 0;
-
- /* RTC : must be done first to be able to access RTC RAM for uSD init */
- time_config(I2C0, RTC_ADDR);
- time_init_check(uart);
-
- /* uSD card */
- uSD_config((struct pio *)&uSD_cs, SSP_BUS_0);
- uSD_detect(uart);
- uSD_logs_init(uart);
-
- /* Thermocouple configuration */
- max31855_sensor_config(&thermocouple);
-
- /* TMP101 sensor config on power board */
- power_board_present = 1;
- ret = tmp101_sensor_config(&tmp101_sensor_power);
- if (ret != 0) {
- uprintf(uart, "Temp config error on power board: %d\n", ret);
- power_board_present = 0;
- retcode -= 1;
- } else {
- ret = tmp101_sensor_set_continuous_conversion(&tmp101_sensor_power);
- if (ret != 0) {
- uprintf(uart, "Temp config part 2 error on power board: %d\n", ret);
- power_board_present = 0;
- retcode -= 2;
- }
- }
-
- /* TMP101 sensor config on display board */
- ret = tmp101_sensor_config(&tmp101_sensor_display);
- if (ret != 0) {
- uprintf(uart, "Temp config error on display board: %d\n", ret);
- interface_board_present = 0;
- retcode -= 4;
- } else {
- ret = tmp101_sensor_set_continuous_conversion(&tmp101_sensor_display);
- if (ret != 0) {
- uprintf(uart, "Temp config part 2 error on display board: %d\n", ret);
- interface_board_present = 0;
- retcode -= 8;
- } else {
- interface_board_present = 1;
- }
- }
-
- /* Configure interface board if present */
- if (interface_board_present == 1) {
- ret = interface_config(uart);
- if (ret != 0) {
- retcode -= 16;
- }
- }
-
- return retcode;
-}