Fixed bugs when work in mustdie's terminal

This commit is contained in:
eddyem
2015-05-14 12:55:58 +03:00
parent 20b10be5ad
commit 26e13666e1
27 changed files with 11817 additions and 335 deletions

Binary file not shown.

View File

@@ -152,7 +152,8 @@ int main(){
usb_disconnect(); // turn off USB while initializing all
// init USART1
// init USART3 (master) & USART1 (slave)
UART_init(USART3);
UART_init(USART1);
// USB
@@ -189,7 +190,8 @@ int main(){
usbdatalen = parce_incoming_buf(usbdatabuf, usbdatalen, usb_send);
oldusbdatalen = usbdatalen;
}
check_and_parce_UART(USART1); // also check data in UART buffers
check_and_parce_UART(USART3); // check data in master UART buffers
check_and_parce_UART(USART1); // also check data in slave UART buffers
if(ad7794_on){
if(Timer != lastTRDread){ // run this not more than once in 1ms
lastTRDread = Timer;

View File

@@ -28,7 +28,7 @@
#define TURRETS_PAUSE_US (50000)
// max amount of steps to add to turret for moving to next position
#define TURRETS_NEXT_POS_STEPS (500)
// (index/4) in accel_mults[] for started acceleration
// (index*4) in accel_mults[] for started acceleration
#define START_MOTORS_ACCEL_IDX_4 (63)
#ifndef CONCAT

View File

@@ -80,6 +80,8 @@ void UART_init(uint32_t UART){
rccgpio = RCC_GPIOA; // RCC timing of GPIO pin (for output)
TX_buffer[1].end = 0; // reset counters
TX_buffer[1].start = 0;
RX_buffer[1].end = 0;
RX_buffer[1].start = 0;
// output pin setup
gpioport = GPIO_BANK_USART2_TX;
gpiopin = GPIO_USART2_TX;
@@ -90,6 +92,8 @@ void UART_init(uint32_t UART){
rccgpio = RCC_GPIOB;
TX_buffer[2].end = 0;
TX_buffer[2].start = 0;
RX_buffer[2].end = 0;
RX_buffer[2].start = 0;
gpioport = GPIO_BANK_USART3_TX;
gpiopin = GPIO_USART3_TX;
break;
@@ -100,6 +104,8 @@ void UART_init(uint32_t UART){
rccgpio = RCC_GPIOA;
TX_buffer[0].end = 0;
TX_buffer[0].start = 0;
RX_buffer[0].end = 0;
RX_buffer[0].start = 0;
gpioport = GPIO_BANK_USART1_TX;
gpiopin = GPIO_USART1_TX;
}
@@ -145,7 +151,7 @@ void UART_isr(uint32_t UART){
if((USART_CR1(UART) & USART_CR1_TXEIE) && (USART_SR(UART) & USART_SR_TXE)){
switch(UART){
case USART1:
bufidx = 0;
bufidx = 0;
break;
case USART2:
bufidx = 1;
@@ -161,8 +167,9 @@ void UART_isr(uint32_t UART){
if(bufidx != curbuff->end){ // there's data in buffer
// Put data into the transmit register
usart_send(UART, curbuff->buf[bufidx]);
if(++(curbuff->start) == UART_TX_DATA_SIZE) // bufidx > endidx && got end of buffer
if(++(curbuff->start) == UART_TX_DATA_SIZE){ // reload start
curbuff->start = 0;
}
}else{ // Disable the TXE interrupt, it's no longer needed
USART_CR1(UART) &= ~USART_CR1_TXEIE;
// empty indexes

View File

@@ -292,22 +292,27 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
return 0;
}
}else if(mode == LINE_MODE){ // text mode: check for "]\n" presence
uint8_t bad_cmd = 1;
uint8_t bad_cmd = 1, found_end = 0;
if(buf[0] == '['){
for(j = 1; j < len; j++){
if(buf[j] != '\n') continue; // search end of line
else{
if(buf[j-1] == ']'){
bad_cmd = 0;
len = j; buf[j] = 0; // truncate buffer to only one command
break;
for(j = 1; j < len; j++){
if(buf[j] == ']' && found_end == 0){
found_end = j; // store position of command's end
continue;
}
if(buf[j] != '\n' && buf[j] != '\r') continue; // search end of line
else{
return 0; // end of line without closing bracket
if(found_end){ // open brace have a pair
bad_cmd = 0;
len = found_end+1; // save "]" in buffer for correct integer values reading
buf[len] = 0; // truncate buffer to only one command
break;
}
else{
return 0; // end of line without closing bracket
}
}
}
}} else{
}else{
return 0;
}
if(bad_cmd){
@@ -322,8 +327,8 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
I = stepper_proc;
READINT();
}else switch (command){
case '[': // line mode - do nothing, this is start symbol
//mode = LINE_MODE;
case '[':
case ']':
break;
case '+': // user check number value & confirm it's right
if(mode != BYTE_MODE) return 0; // bad command - no echo
@@ -509,7 +514,7 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
gpio_clear(MOTOR_EN_PORT, MOTOR_EN_MASK);
break;
*/
case '\n': // show newline, space and tab as is
case '\n': // show newline, cr, space and tab as is
case '\r':
case ' ':
case '\t':
@@ -520,9 +525,12 @@ int parce_incoming_buf(char *buf, int len, sendfun s){
if(mode == BYTE_MODE) s(command); // echo readed byte in byte mode
}
if(mode == LINE_MODE){ // process command which needs for user value
if(I && Uval_ready == UVAL_ENTERED){
if(I){
if(Uval_ready == UVAL_ENTERED)
do_echo = I(User_value, s);
else
do_echo = 0; // if entered value is wrong, don't echo command
Uval_ready = UVAL_BAD; // clear Uval_ready
do_echo = I(User_value, s);
I = NULL;
}
}
@@ -589,8 +597,9 @@ int read_int(char *buf, int cnt){
User_value = User_value * 10 + (int32_t)(chr - '0');
enteredDigits++;
}
if(Uval_ready == UVAL_ENTERED) // reading has met an non-numeric character
if(Uval_ready == UVAL_ENTERED){ // reading has met an non-numeric character
User_value *= sign;
}
return readed;
}