/** * @brief Shell loop. * Wait for commands in command_queue, run it, report command run status via usart tty. */ void shell_run() { char local_command[CMD_SIZE]; queue_init(&command_queue); usart_send_str("************************************\r\n"); usart_send_str("Welcome to Neuraxis shell\r\n"); usart_send_str("************************************\r\n>"); while(1) { if( !queue_is_empty(&command_queue) ) { strcpy(local_command, queue_dequeue(&command_queue)); cmd_status_t status = cmd_run(local_command); if(status == CMD_SUCCESSFUL ) { usart_send_str("Command '"); usart_send_str(local_command); usart_send_str("' successfully executed\r\n"); } else { usart_send_str("Command '"); usart_send_str(local_command); usart_send_str("' can't be executed\r\n"); } usart_send_byte((uint8_t) '>'); } else { __WFI(); } } }
int main(void) { DDRA = 0xff; // Set LED Pins as output PORTA = 0x01; // Init usart usart_init(); PORTA = 0x02; usart_send_str("\nStarting overhead test.\n"); usart_send_str("Measuring performance without OS...\n"); PORTA = 0x04; // Initialize the timer and enable interrupts timer_one_second_init(); timer_one_second_start(); sei(); // The loop will run exactly 1 second and then the timer interrupt will set runTest to 0 while(runTest) { for (uint8_t i=0; i<50; i++) { // Do something useless tmp1 *= 2; } //Increment counter, but do it in a "critical section", because it is a 16 bit operation cli(); counter1++; sei(); } PORTA = 0x08; // Disable interrupts and stop timer cli(); timer_one_second_stop(); usart_send_str("Value: "); usart_send_number(counter1, 10, 1); usart_send_str("\n"); usart_send_str("Measuring performance with OS and two tasks...\n"); PORTA = 0x10; runTest = 1; // Restart timer for OS test timer_one_second_init(); timer_one_second_start(); sei(); StartOS(); while(1); }
int main(void) { // Init GPIO: all leds on DDRA = 0xFF; PORTA = 0xFF; // init USART (9600 baud, 8N1) usart_init(); // make sure the USART works // (and PC can check that it has the right test) usart_send_str("async-n-semaphore test\r\n"); // wait for the PC while (usart_recv() != 's') usart_send('?'); // enable USART receive interrupts UCSRxB |= (1<<RXCIE0); // Init Os StartOS(); //NOTE: Since OS is used, program will never get here! while(1); }
/** * UART2 Receive hander. * Shell implementation. This function (handler) fill command queue by new valid command received * from UART2. */ void USART2_IRQHandler() { static char buffer[CMD_SIZE]; static uint16_t char_number; static uint8_t received_byte; received_byte = USART2->DR; USART2->DR = USART2->DR; if( ( char_number+1 )> ( CMD_SIZE-2 ) ) { char_number=0; usart_send_str("Exceed command line limit (63 chars)\r\n>"); usart_send_str("\n\r>"); } else { buffer[char_number] = received_byte; if( (char)received_byte == '\b') { if(char_number-1>-1) char_number--; else usart_send_byte((uint8_t)'>'); } else if( (char) received_byte == '\n' ) { buffer[char_number]='\0'; //set end of null terminated string if (!cmd_check(buffer)) usart_send_str("\n\rUndefined command\n\r"); else { usart_send_str("\n\rCommand enqueued\n\r"); queue_enqueue(&command_queue, buffer); } usart_send_str("\n\r>"); char_number=0; } else { char_number++; } } USART_ClearITPendingBit(USART2, USART_IT_RXNE); }
int main(void) { DDRA = 0xff; // Set LED Pins as output PORTA = 0x01; // Init usart usart_init(); PORTA = 0x02; usart_send_str("\nStarting preemption test.\n"); StartOS(); while(1); }
int main(void) { //Init variables for(int i=0; i<NUMTASKS; i++) c[i] = 0; DDRA = 0xff; // Set LED Pins as output PORTA = 0x01; // Init usart usart_init(); PORTA = 0x02; usart_send_str("\nStarting multiple tasks test.\n"); StartOS(); while(1); }
RS232_SPEC void usart_send_number(int32_t number, uint8_t base, uint8_t min_places) { char chars[32 + 2 + 1]; char* x = chars + sizeof(chars) / sizeof(*chars); *(--x) = 0; if (number < 0) { usart_send('-'); number = -number; } // special case for zero which would otherwise yield an empty string if (number == 0) { *(--x) = '0'; if (min_places) --min_places; } while (number || min_places) { uint8_t digit = number % base; if (number == 0 && base == 10) // cannot use '0' to fill the space because that would // make it an octal number digit = ' '; else if (digit < 10) digit += '0'; else digit += 'a' - 10; *(--x) = digit; number /= base; if (min_places) --min_places; } switch (base) { case 2: usart_send('0'); usart_send('b'); break; case 8: usart_send('0'); break; case 10: break; case 16: usart_send('0'); usart_send('x'); break; default: usart_send_number(base, 10, 0); usart_send('#'); break; } usart_send_str(x); }
/***usart1.2发送数据 将测量结果提供给主板***/ __task void send_result(void) { u8 j=0; u8 send_i=0; os_sem_init(resultsem,0); while(1) { os_sem_wait(resultsem,0xffff); if(send_config==1) { for(j=view_detial[send_i][0]+1;j<view_detial[send_i][0]+4;j++) { itoa(view_detial[send_i][j],view_send,10); usart_send_str(USART1,view_send); usart_send_str(USART1," "); } } /*** ***/ else { itoa(refresh.yy,view_send,10); usart_send_str(USART1,view_send); usart_send_str(USART1," "); itoa(refresh.wj,view_send,10); usart_send_str(USART1,view_send); usart_send_str(USART1," "); itoa(refresh.yj,view_send,10); usart_send_str(USART1,view_send); usart_send_str(USART1," "); itoa(refresh.jb,view_send,10); usart_send_str(USART1,view_send); usart_send_str(USART1," "); } /*******/ // usart_send_str(USART1," "); // itoa(t1,view_send,10); // usart_send_str(USART1,view_send); // usart_send_str(USART1," "); // itoa(t2,view_send,10); // usart_send_str(USART1,view_send); /***调试 计数***/ memset(view_detial[send_i],0,106); send_i++; if(send_i==5) send_i=0; i++; itoa(i,view_send,10); usart_send_str(USART1," "); usart_send_str(USART1,view_send); /*** ***/ memset(view_send,0,10); usart_send_enter(USART1); } }
/***485通讯 字符串***/ void send_485(char *s) { dir_485(TX); usart_send_str(USART2,s); dir_485(RX); }