From f88cbaafd53a92977be2c33cece175b1576e7071 Mon Sep 17 00:00:00 2001 From: eddyem Date: Tue, 4 Aug 2015 16:55:28 +0300 Subject: [PATCH] add init on poweron --- with_opencm3/hardware_ini.c | 4 ++-- with_opencm3/main.c | 2 ++ with_opencm3/stepper_motors.c | 2 +- with_opencm3/stepper_motors.h | 2 ++ with_opencm3/user_proto.c | 12 ++++++++++-- with_opencm3/user_proto.h | 2 ++ 6 files changed, 19 insertions(+), 5 deletions(-) diff --git a/with_opencm3/hardware_ini.c b/with_opencm3/hardware_ini.c index b7a4320..a0ecc45 100644 --- a/with_opencm3/hardware_ini.c +++ b/with_opencm3/hardware_ini.c @@ -192,9 +192,9 @@ void adc_dma_on(){ void ADC_init(){ rcc_peripheral_enable_clock(&RCC_APB2ENR, RCC_APB2ENR_ADC1EN); // enable clocking - rcc_periph_clock_enable(RCC_ADC1); +// rcc_periph_clock_enable(RCC_ADC1); rcc_set_adcpre(RCC_CFGR_ADCPRE_PCLK2_DIV4); - rcc_periph_clock_enable(RCC_GPIOA | RCC_GPIOB | RCC_GPIOC); // clocking for ADC ports + //rcc_periph_clock_enable(RCC_GPIOA | RCC_GPIOB | RCC_GPIOC); // clocking for ADC ports // channels 4-7: PA7-PA4 (ADC IN 4..7); U10 (PA0); U36 (PA1) gpio_set_mode(GPIOA, GPIO_MODE_INPUT, GPIO_CNF_INPUT_ANALOG, GPIO4|GPIO5|GPIO6|GPIO7|GPIO1|GPIO0); // channels 0,1: PB1, PB0 (ADC IN 8, 9) diff --git a/with_opencm3/main.c b/with_opencm3/main.c index e264dfc..f2649dc 100644 --- a/with_opencm3/main.c +++ b/with_opencm3/main.c @@ -32,6 +32,7 @@ #include "onewire.h" #include "stepper_motors.h" #include "powerhw.h" +#include "init_on_power.h" volatile uint32_t Timer = 0, tOVRFL = 0; // global timer (milliseconds), overflow counter usbd_device *usbd_dev; @@ -215,6 +216,7 @@ int main(){ LED_STATUS_OK(); // All initialized - light up LED while(1){ + init_on_poweron_proc(); usbd_poll(usbd_dev); if(oldusbdatalen != usbdatalen){ // there's something in USB buffer usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen, usb_send); diff --git a/with_opencm3/stepper_motors.c b/with_opencm3/stepper_motors.c index fff91aa..f22ecc4 100644 --- a/with_opencm3/stepper_motors.c +++ b/with_opencm3/stepper_motors.c @@ -35,7 +35,7 @@ static volatile int32_t Motor_abs_steps[5] = {0, 0, 0, 0, 0}; // increments that will be added each step to Motor_abs_steps (+1/-1) static int8_t Motor_step_increment[5] = {1,1,1,1,1}; // flag of active motor -static volatile uint8_t Motor_active[5] = {0, 0, 0, 0, 0}; +volatile uint8_t Motor_active[5] = {0, 0, 0, 0, 0}; /* * Wait flags: if non-zero, flag just decremented * (we need it to wait a little on turrets' fixed positions to omit Halls' histeresis) diff --git a/with_opencm3/stepper_motors.h b/with_opencm3/stepper_motors.h index 01b2e8e..1cf6218 100644 --- a/with_opencm3/stepper_motors.h +++ b/with_opencm3/stepper_motors.h @@ -86,6 +86,8 @@ extern uint8_t move2pos[]; // export this array for ability of moving turret to given position from outside +extern volatile uint8_t Motor_active[]; + void steppers_init(); void process_stepper_motors(); uint8_t move_motor(uint8_t num, int32_t steps); diff --git a/with_opencm3/user_proto.c b/with_opencm3/user_proto.c index a967e79..4f38706 100644 --- a/with_opencm3/user_proto.c +++ b/with_opencm3/user_proto.c @@ -27,6 +27,7 @@ #include "stepper_motors.h" #include "powerhw.h" #include "AD7794.h" +#include "init_on_power.h" // mode: curmode_t mode = BYTE_MODE; // text protocol, activated on 1st meeteng of '[' @@ -272,7 +273,7 @@ void help(sendfun s){ //pr("n"); pr("o\topen shutter"); pr(STR_MOTORS_VOLTAGE "\tshow motors voltage"); - //pr("q"); + pr("q\tget initialisation status"); pr("r\treinit shutter"); pr(STR_EXTADC_VALUES "\tshow AD7794 values"); pr(STR_SHTR_STATE "\tprint shutter state"); @@ -281,7 +282,7 @@ void help(sendfun s){ //pr("w"); pr("x\tset timer period for turrets' motors"); //pr("y"); - //pr("z"); + pr("z\treinitialisation (move linear stages to zero position)"); pr("\nAfter entering of user value press '+' to submit or '-' to reject it"); #undef pr } @@ -467,6 +468,10 @@ int parce_incoming_buf(char *buf, int len, sendfun s){ if(mode != BYTE_MODE) return 0; OW_fill_next_ID(); break; + case CMD_INIT_STATUS: // [q] - get init status + print_init_status(); + do_echo = 0; + break; case 'Q': // 1-wire scan OFF OW_scan = 0; break; @@ -522,6 +527,9 @@ int parce_incoming_buf(char *buf, int len, sendfun s){ get_motors_position(); do_echo = 0; break; + case 'z': + forced_init(); + break; /* case '_': P("set: ", s); diff --git a/with_opencm3/user_proto.h b/with_opencm3/user_proto.h index 9756495..af3fa60 100644 --- a/with_opencm3/user_proto.h +++ b/with_opencm3/user_proto.h @@ -96,6 +96,8 @@ void print_hex(uint8_t *buff, uint8_t l, sendfun s); #define STR_EXTADC_INIT "i" #define CMD_MOTORS_VOLTAGE 'p' #define STR_MOTORS_VOLTAGE "p" +#define CMD_INIT_STATUS 'q' +#define STR_INIT_STATUS "q" #define CMD_EXTADC_VALUES 's' #define STR_EXTADC_VALUES "s" #define CMD_SHTR_STATE 't'