/** @brief Function for reading two digit decimal numbers from the serial port. Backspace is supported on the first char. */ static uint8_t get_dec2(void) { uint8_t buf[2]; uint8_t i = 0; uint8_t c; buf[0] = buf[1] = 0; while (i < 2) { c = uart_get(); if ((i > 0) && (c == BS)) { uart_put(c); i--; } else if ((c >= '0') && (c <= '9')) { uart_put(c); buf[i] = c - '0'; i++; } else { uart_put(BELL); } } uart_putstring((const uint8_t *)"\r\n"); return buf[0] * 10 + buf[1]; }
void command_usart_input(uint8_t event, char *cmd) { uint8_t status, current; if (event == 0) { if (uart_available()) { // data ready current = uart_get(); status = command_usart_parse(¤t); if (status == CHAR_NORMAL) { if (g_buffer_pos >= B_SIZE) { // reset when full g_buffer_pos = 0; } uart_put(current); // echo valid char back g_buffer[g_buffer_pos] = current; // add to buffer g_command_status = CMD_IN_PROCESS; g_buffer_pos++; } else if (status == CHAR_ENTER) { // enter pressed g_buffer[g_buffer_pos] = '\0'; // mark current pos as end g_buffer_pos = 0; g_command_status = CMD_RDY; } } if (g_command_status == CMD_RDY) { // copy buffer to command strcpy(cmd, g_buffer); g_command_status = CMD_IN_PROCESS; } else { // set command as "still empty" cmd[0] = '\0'; } } }
/** @brief Function for reading the data rate. */ void get_datarate(void) { uint8_t c; uart_putstring((const uint8_t *)"Enter data rate ('0'=250 Kbit/s, '1'=1 Mbit/s and '2'=2 Mbit/s):"); while (true) { c = uart_get(); if ((c >= '0') && (c <= '2')) { uart_put(c); break; } else { uart_put(BELL); } } if (c == '0') { mode_ = RADIO_MODE_MODE_Nrf_250Kbit; } else if (c == '1') { mode_ = RADIO_MODE_MODE_Nrf_1Mbit; } else { mode_ = RADIO_MODE_MODE_Nrf_2Mbit; } uart_putstring((const uint8_t *)"\r\n"); }
/** @brief Function for reading the output power. */ void get_power(void) { uint8_t c; uart_putstring((const uint8_t *)"Enter output power ('0'=+4 dBm, '1'=0 dBm,...,'7'=-30 dBm):"); while (true) { c = uart_get(); if ((c >= '0') && (c <= '7')) { uart_put(c); break; } else { uart_put(BELL); } } switch(c) { case '0': txpower_ = RADIO_TXPOWER_TXPOWER_Pos4dBm; break; case '1': txpower_ = RADIO_TXPOWER_TXPOWER_0dBm; break; case '2': txpower_ = RADIO_TXPOWER_TXPOWER_Neg4dBm; break; case '3': txpower_ = RADIO_TXPOWER_TXPOWER_Neg8dBm; break; case '4': txpower_ = RADIO_TXPOWER_TXPOWER_Neg12dBm; break; case '5': txpower_ = RADIO_TXPOWER_TXPOWER_Neg16dBm; break; case '6': txpower_ = RADIO_TXPOWER_TXPOWER_Neg20dBm; break; case '7': // fall through default: txpower_ = RADIO_TXPOWER_TXPOWER_Neg30dBm; break; } uart_putstring((const uint8_t *)"\r\n"); }
int main(void) { WDTCTL = WDTPW | WDTHOLD; // Stop watchdog timer BCSCTL1 = CALBC1_8MHZ; // Set DCO to 8Mhz DCOCTL = CALDCO_8MHZ; // Set DCO to 8Mhz P2DIR |= (BIT0|BIT1|BIT2|BIT3); P2OUT |= BIT0|BIT1|BIT2|BIT3; uart_init(); __bis_SR_register(GIE); unsigned char i; while(1) { i = uart_get(); btns(i); } return 0; }
void HanddleUART2(void) { unsigned char c; int Tp; TICK MeterConcurrentTime; MeterConcurrentTime = TickGet(); if( ( TickGetDiff( MeterConcurrentTime, TotalMeterGetConnceted1 ) ) > TIMETOCHECKNWKTABLE) { CompareNWKTable(); TotalMeterGetConnceted1 = TickGet(); } if(MyCommandFlag.ACK != ACK_PENDING) { if(MyCommandFlag.DataSent == TRUE) { if(MyCommandFlag.ACK == ACK_NOTRECEIVED) { //xprintf("ACK not Received :(\n\r"); MyAskForDeviceAddress(FALSE,PrvSendIeeeAddr); } else if(MyCommandFlag.ACK == ACK_RECEIVED) { //xprintf("ACK Received :)\n\r"); } else { xprintf("This staage I am not Expected\n\t"); } MyCommandFlag.DataSent = FALSE; } else { ACKTimeOut = TickGet(); } } else { TICK currentTime; currentTime = TickGet(); if( ( TickGetDiff( currentTime, ACKTimeOut ) ) > (ONE_SECOND) *5) { MyCommandFlag.ACK = ACK_NOTRECEIVED; ACKTimeOut = TickGet(); } } if(uart_kbhit() != 0) { c = uart_get(); //x2putc(c); Uart2Buffer[NumberofReceived] = c; if(Uart2Buffer[0] == 0x2B || Uart2Buffer[0] == 0x1B) { NumberofReceived++; } else { NumberofReceived = 0; } if(NumberofReceived >=2 && numberofdatareceived == 0) { HowManyData = c; numberofdatareceived = 1; } if(HowManyData !=0 && NumberofReceived == HowManyData+1) { //xprintf("\n\r Data Received \n\r"); //for(Tp=0;Tp<=HowManyData;Tp++) // xprintf("\n\r Data is: %d\n\r",Uart2Buffer[Tp]); //xprintf("\n\r How many data = %d",HowManyData); Uart2Datalen = HowManyData; NumberofReceived = 0; numberofdatareceived = 0; HowManyData = 0; while(uart_kbhit() != 0) c = uart_get(); CheckDataAndSend(); } } }
/** @brief Function for main application entry. */ int main(void) { radio_tests_t test = RADIO_TEST_NOP; radio_tests_t cur_test = RADIO_TEST_NOP; init(); uart_config(TX_PIN_NUMBER, RX_PIN_NUMBER); uart_putstring((const uint8_t *)"RF Test\r\n"); NVIC_EnableIRQ(TIMER0_IRQn); __enable_irq(); while (true) { __WFI(); switch (uart_get()) { case 'a': while (true) { uart_putstring((const uint8_t *)"Enter start channel \ (two decimal digits, 00 to 80):"); channel_start_ = get_dec2(); if (channel_start_ <= 80) break; uart_putstring((const uint8_t *)"Channel must be between 0 and 80\r\n"); } test = cur_test; break; case 'b': while (true) { uart_putstring((const uint8_t *)"Enter end channel \ (two decimal digits, 00 to 80):"); channel_end_ = get_dec2(); if (channel_end_ <= 80) { break; } uart_putstring((const uint8_t *)"Channel must be between 0 and 80\r\n"); } test = cur_test; break; case 'c': test = RADIO_TEST_TXCC; break; case 'd': while (true) { uart_putstring((const uint8_t *)"Enter delay in ms \ (two decimal digits, 01 to 99):"); delayms_ = get_dec2(); if ((delayms_ > 0) && (delayms_ < 100)) { break; } uart_putstring((const uint8_t *)"Delay must be between 1 and 99\r\n"); } test = cur_test; break; case 'e': radio_sweep_end(); cur_test = RADIO_TEST_NOP; break; case 'm': get_datarate(); test = cur_test; break; case 'o': test = RADIO_TEST_TXMC; uart_putstring((const uint8_t *)"TX modulated carrier\r\n"); break; case 'p': get_power(); test = cur_test; break; case 'r': test = RADIO_TEST_RXSWEEP; uart_putstring((const uint8_t *)"RX Sweep\r\n"); break; case 's': print_parameters(); break; case 't': test = RADIO_TEST_TXSWEEP; uart_putstring((const uint8_t *)"TX Sweep\r\n"); break; case 'x': test = RADIO_TEST_RXC; uart_putstring((const uint8_t *)"RX constant carrier\r\n"); break; case 'h': // Fall through. default: help(); break; } switch (test) { case RADIO_TEST_TXCC: if (sweep) { radio_sweep_end(); sweep = false; } radio_tx_carrier(txpower_, mode_, channel_start_); cur_test = test; test = RADIO_TEST_NOP; break; case RADIO_TEST_TXMC: if (sweep) { radio_sweep_end(); sweep = false; } radio_modulated_tx_carrier(txpower_, mode_, channel_start_); cur_test = test; test = RADIO_TEST_NOP; break; case RADIO_TEST_TXSWEEP: radio_tx_sweep_start(txpower_, mode_, channel_start_, channel_end_, delayms_); sweep = true; cur_test = test; test = RADIO_TEST_NOP; break; case RADIO_TEST_RXC: if (sweep) { radio_sweep_end(); sweep = false; } radio_rx_carrier(mode_, channel_start_); cur_test = test; test = RADIO_TEST_NOP; break; case RADIO_TEST_RXSWEEP: radio_rx_sweep_start(mode_, channel_start_, channel_end_, delayms_); sweep = true; cur_test = test; test = RADIO_TEST_NOP; break; case RADIO_TEST_NOP: // Fall through. default: // No implementation needed. break; } } }
void check_debug_uart(void) { static uint8_t inputbuf[RX_LINE_SIZE], inputptr = 0; uint8_t i, recv; int16_t ticks; while(uart_available(DEBUG)) { recv = uart_get(DEBUG); if(recv == '\r') { fprintf(&debug, "\r\n"); if(inputptr) { switch(inputbuf[0]) { case '?': // print drive command list fprintf_P(&debug, PSTR("stop() ........................ | p00\r\n")); fprintf_P(&debug, PSTR("fwd_both(speed) ............... | p0300, p0400, p15 u8\r\n")); fprintf_P(&debug, PSTR("rev_both(speed) ............... | p0301, p0401, p15 u8\r\n")); fprintf_P(&debug, PSTR("forward(Lspeed, Rspeed) ....... | p0300, p0400, p11 u8, p12 u8\r\n")); fprintf_P(&debug, PSTR("reverse(Lspeed, Rspeed) ....... | p0301, p0401, p11 u8, p12 u8\r\n")); fprintf_P(&debug, PSTR("turnCCW(Lspeed, Rspeed) ....... | p0301, p0400, p11 u8, p12 u8\r\n")); fprintf_P(&debug, PSTR("turnCW (Lspeed, Rspeed) ....... | p0300, p0401, p11 u8, p12 u8\r\n")); fprintf_P(&debug, PSTR("set_abs_pos(pos) .............. | p1a s16\r\n")); fprintf_P(&debug, PSTR("set_rel_pos(sect, pos) ........ | p1b u8 u8\r\n")); fprintf_P(&debug, PSTR("pos_corr_on() ................. | p1f01\r\n")); fprintf_P(&debug, PSTR("pos_corr_off() ................ | p1f00\r\n")); fprintf_P(&debug, PSTR("nav_abs_pos(speed, pos) ....... | p31 u8 s16\r\n")); fprintf_P(&debug, PSTR("nav_rel_pos(speed, sect, pos) . | p32 u8 u8 u8\r\n")); break; case 'p': // passthrough to DRIVE MCU for(i = 1; i < inputptr; i++) { uart_put(DRIVE, inputbuf[i]); } uart_put(DRIVE, '\r'); break; case 'r': // toggle reverse passthrough from DRIVE MCU rev_passthru ^= 1; break; case 'd': // local dump on/off local_dump ^= 1; break; case 's': // start/stop main thread run_main ^= 1; if(run_main) { fprintf_P(&debug, PSTR("Main thread started!\r\n")); } else { fprintf_P(&debug, PSTR("Main thread stopped!\r\n")); stop(); } break; case 't': // start/stop test thread if(inputptr != 2) { cmd_err(); break; } run_test = htoa(0, inputbuf[1]); if(!run_test) { fprintf_P(&debug, PSTR("All test sequences stopped!\r\n")); stop(); } else { fprintf_P(&debug, PSTR("Started test sequence %u!\r\n"), run_test); } break; case ' ': // stop all motors run_main = 0; run_test = 0; pid_on = 0; stop(); set_speed_3(0); set_speed_4(0); break; case 'u': fprintf_P(&debug, PSTR("%lu\r\n"), uptime()); break; case 'b': #define VBAT_FACTOR 0.0044336 fprintf_P(&debug, PSTR("4 x %1.2fV\r\n"), (float)read_adc(VSENS) * VBAT_FACTOR); break; case 'm': // servo power if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; } inputbuf[1] == '0' ? clr_bit(SPWR) : set_bit(SPWR); break; case '9': // magnets if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; } if(inputbuf[1] == '0') { clr_bit(FET1); clr_bit(FET2); fprintf_P(&debug, PSTR("Magnets off!\r\n")); } else { set_bit(FET1); set_bit(FET2); fprintf_P(&debug, PSTR("Magnets on!\r\n")); } break; case '1': // PID on/off if(inputptr != 2 || (inputbuf[1] & ~1) != '0') { cmd_err(); break; } if(inputbuf[1] == '0') { pid_on = 0; fprintf_P(&debug, PSTR("PID off!\r\n")); } else { pid_on = 1; fprintf_P(&debug, PSTR("PID on!\r\n")); reset_pid(); } break; case '3': // turn motor commands if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } switch(inputbuf[1]) { case '0': // forward (uint8_t speed) if(inputptr != 4) { cmd_err(); break; } motor3_fwd(); set_speed_3(htoa(inputbuf[2], inputbuf[3]) * 40); break; case '1': // reverse (uint8_t speed) if(inputptr != 4) { cmd_err(); break; } motor3_rev(); set_speed_3(htoa(inputbuf[2], inputbuf[3]) * 40); break; case '2': // set reference target (int16_t ticks) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } pid_target[MOTOR3] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '3': // set reference speed (int16_t ticks) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } pid_speed[MOTOR3] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '4': // set P (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ENC3_P = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '5': // set I (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ENC3_I = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '6': // set D (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ENC3_D = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '7': // set noise gate (int16_t level) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ENC3_NOISE_GATE = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case 'f': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } ticks = deg2ticks(htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5])); cli(); V_encoder = ticks; sei(); reset_pid(); break; default: cmd_err(); } break; case '4': // lift motor commands if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } switch(inputbuf[1]) { case '0': // up (uint8_t speed) if(inputptr != 4) { cmd_err(); break; } motor4_fwd(); set_speed_4(htoa(inputbuf[2], inputbuf[3]) * 40); break; case '1': // down (uint8_t speed) if(inputptr != 4) { cmd_err(); break; } motor4_rev(); set_speed_4(htoa(inputbuf[2], inputbuf[3]) * 40); break; case '2': // set reference target (int16_t ticks) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } pid_target[MOTOR4] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '3': // set reference speed (int16_t ticks) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } pid_speed[MOTOR4] = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '4': // set P (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ACTU_P = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '5': // set I (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ACTU_I = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '6': // set D (int16_t factor) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ACTU_D = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '7': // set noise gate (int16_t level) if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } //ACTU_NOISE_GATE = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; default: cmd_err(); } break; case '5': // servo5 commands if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } servo5(htoa(inputbuf[2], inputbuf[3])); //OCR0A = htoa(inputbuf[1], inputbuf[2]); break; case '6': // servo6 commands if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } servo6(htoa(inputbuf[2], inputbuf[3])); //OCR0B = htoa(inputbuf[1], inputbuf[2]); break; case '7': // servo7 commands if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } servo7(htoa(inputbuf[2], inputbuf[3])); //OCR2A = htoa(inputbuf[1], inputbuf[2]); break; case '8': // servo8 commands if(inputptr != 4 || !isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } servo8(htoa(inputbuf[2], inputbuf[3])); //OCR2B = htoa(inputbuf[1], inputbuf[2]); break; case 'x': if(!isHex(inputbuf[2]) || !isHex(inputbuf[3])) { cmd_err(); break; } switch(inputbuf[1]) { case '1': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } param1 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '2': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } param2 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '3': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } param3 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '4': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } param4 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; case '5': // set reference angle if(inputptr != 6 || !isHex(inputbuf[4]) || !isHex(inputbuf[5])) { cmd_err(); break; } param5 = htoa(inputbuf[2], inputbuf[3]) << 8 | htoa(inputbuf[4], inputbuf[5]); break; } break; default: cmd_err(); } inputptr = 0; } } else if(recv == 0x7f) { if(!inputptr) { uart_put(DEBUG, '\a'); } else { fprintf(&debug, "\b\e[K"); inputptr--; } } else { if(inputptr == RX_LINE_SIZE) { uart_put(DEBUG, '\a'); } else { uart_put(DEBUG, recv); inputbuf[inputptr] = recv; inputptr++; } } }
// // syscall entry point // long int syscall(unsigned long int command,...){ int ret; va_list ap; ret = 0; va_start(ap,command); switch (command) { // SYS case SYS_INIT: { tick_init(); // raw-handler int_init(); // raw-handler syscall(SYS_TIMER_INIT); syscall(SYS_DMA_INIT); syscall(SYS_VRAM_INIT); syscall(SYS_SCREEN_INIT); syscall(SYS_UART_INIT); ret = 0; } break; // TIMER case SYS_TIMER_INIT: { timer_init(&timer); ret = 0; } break; case SYS_TIMER_GET_COUNT: { ret = timer_get_count(&timer); } break; // DMA case SYS_DMA_INIT: { unsigned long int base; unsigned long int irq; base = va_arg(ap,unsigned long int); irq = va_arg(ap,unsigned long int); dma.ch = dma_channel; dma.ch_size = DMA_CH_SIZE; dma.ch[0].buf = dma_buffer_ch0; dma.ch[0].buf_size = DMA_BUF_SIZE; dma_init(&dma,DMA_BASE,DMA_IRQ); ret = 0; } break; case SYS_DMA_ADD: { unsigned long int ch; void *src; void *dst; unsigned long int size; ch = va_arg(ap,unsigned long int); src = va_arg(ap,void *); dst = va_arg(ap,void *); size = va_arg(ap,unsigned long int); dma_add(&dma,ch,src,dst,size); ret = 0; } break; case SYS_DMA_ADD_FULL: { unsigned long int ch; ch = va_arg(ap,unsigned long int); ret = (long int)dma_add_full(&dma,ch); } break; case SYS_DMA_GET_HANDLE: { ret = (long int)&dma; } break; case SYS_DMA_GET_CH: { ret = 0; } break; // VRAM case SYS_VRAM_INIT: { vram_init(&vram,&dma,0); ret = 0; } break; case SYS_VRAM_CLEAR: { vram_clear(&vram); ret = 0; } break; case SYS_VRAM_IMAGE_PASTE: { IMAGE *img; unsigned long int x; unsigned long int y; img = va_arg(ap,IMAGE *); x = va_arg(ap,unsigned long int); y = va_arg(ap,unsigned long int); vram_image_paste(&vram,img,x,y); ret = 0; } break; case SYS_VRAM_IMAGE_PASTE_FILTER: { IMAGE *img; unsigned long int x; unsigned long int y; img = va_arg(ap,IMAGE *); x = va_arg(ap,unsigned long int); y = va_arg(ap,unsigned long int); vram_image_paste_filter(&vram,img,x,y); ret = 0; } break; case SYS_VRAM_IMAGE_CLEAR: { IMAGE *img; unsigned long int x; unsigned long int y; img = va_arg(ap,IMAGE *); x = va_arg(ap,unsigned long int); y = va_arg(ap,unsigned long int); vram_image_clear(&vram,img,x,y); ret = 0; } break; // SCREEN case SYS_SCREEN_INIT: { screen_init(&scr,&vram); ret = 0; } break; case SYS_SCREEN_CLEAR: { screen_clear(&scr); ret = 0; } break; case SYS_SCREEN_LOCATE: { unsigned long int x; unsigned long int y; x = va_arg(ap,unsigned long int); y = va_arg(ap,unsigned long int); screen_locate(&scr,x,y); ret = 0; } break; case SYS_SCREEN_SCROLL: { unsigned long int height; height = va_arg(ap,unsigned long int); screen_scroll(&scr,height); ret = 0; } break; case SYS_SCREEN_PUT_STRING: { unsigned char *s; s = va_arg(ap,unsigned char *); screen_put_string(&scr,s); ret = 0; } break; case SYS_SCREEN_PUT_CHAR: { unsigned char c; c = va_arg(ap,unsigned int); // usigned char screen_put_char(&scr,c); ret = 0; } break; case SYS_SCREEN_PRINT: { unsigned char c; c = va_arg(ap,unsigned int); // unsigned char screen_print(&scr,c); ret = 0; } break; //case SYS_SCREEN_IMAGE: { // IMAGE *image; // image = va_arg(ap,IMAGE *); // screen_image(&scr,image); // ret = 0; //} break; case SYS_SCREEN_SET_LOCATE_X: { unsigned long int x; x = va_arg(ap,unsigned long int); screen_set_locate_x(&scr,x); ret = 0; } break; case SYS_SCREEN_SET_LOCATE_Y: { unsigned long int y; y = va_arg(ap,unsigned long int); screen_set_locate_y(&scr,y); ret = 0; } break; case SYS_SCREEN_GET_LOCATE_X: { ret = screen_get_locate_x(&scr); } break; case SYS_SCREEN_GET_LOCATE_Y: { ret = screen_get_locate_y(&scr); } break; case SYS_SCREEN_SET_COLOR_FG: { unsigned long int r,g,b; r = va_arg(ap,unsigned long int); g = va_arg(ap,unsigned long int); b = va_arg(ap,unsigned long int); screen_set_color_fg(&scr,r,g,b); ret = 0; } break; case SYS_SCREEN_SET_COLOR_BG: { unsigned long int r,g,b; r = va_arg(ap,unsigned long int); g = va_arg(ap,unsigned long int); b = va_arg(ap,unsigned long int); screen_set_color_bg(&scr,r,g,b); ret = 0; } break; // UART case SYS_UART_INIT: { unsigned long int base; unsigned long int irq; base = va_arg(ap,unsigned long int); irq = va_arg(ap,unsigned long int); uart.tx.buf = uart_buffer_tx; uart.tx.buf_size = UART_TX_BUF_SIZE; uart.rx.buf = uart_buffer_rx; uart.rx.buf_size = UART_RX_BUF_SIZE; uart_init(&uart,UART_BASE,UART_IRQ); ret = 0; } break; case SYS_UART_GET: { ret = (long int)uart_get(&uart); } break; case SYS_UART_GET_EXIST: { ret = (long int)uart_get_exist(&uart); } break; case SYS_UART_GET_CLEAR: { uart_get_clear(&uart); ret = 0; } break; case SYS_UART_PUT: { unsigned int data; data = va_arg(ap,unsigned int); uart_put(&uart,(unsigned char)data); ret = 0; } break; case SYS_UART_PUT_FULL: { ret = uart_put_full(&uart); } break; case SYS_UART_PUT_CLEAR: { uart_put_clear(&uart); ret = 0; } break; case SYS_UART_PUT_STRING: { unsigned char *string; string = va_arg(ap,unsigned char *); uart_put_string(&uart,string); ret = 0; } break; case SYS_UART_IS_CTS: { ret = uart_is_cts(&uart); } break; case SYS_UART_IS_DSR: { ret = uart_is_dsr(&uart); } break; case SYS_UART_IS_RI: { ret = uart_is_ri(&uart); } break; case SYS_UART_IS_DCD: { ret = uart_is_dcd(&uart); } break; case SYS_UART_DTR: { unsigned long int data; data = va_arg(ap,unsigned long int); uart_dtr(&uart,data); ret = 0; } break; case SYS_UART_RTS: { unsigned long int data; data = va_arg(ap,unsigned long int); uart_rts(&uart,data); ret = 0; } break; } va_end(ap); return ret; }
void check_drive_uart(void) { static uint8_t inputbuf[RX_LINE_SIZE], inputptr = 0; uint8_t i, recv; while(uart_available(DRIVE)) { recv = uart_get(DRIVE); if(recv == '\r') { if(inputptr) { if(inputbuf[0] == '@') { // reverse command from DRIVE MCU switch(inputbuf[1]) { case '1': // drive complete if(inputptr != 3 || inputbuf[2] != '0') { break; } drive_complete = 1; break; case '4': // track info update switch(inputbuf[2]) { case '4': // absolute position if(inputptr != 11) { break; } abspL = htoa(inputbuf[ 3], inputbuf[ 4]) << 8 | htoa(inputbuf[ 5], inputbuf[ 6]); abspR = htoa(inputbuf[ 7], inputbuf[ 8]) << 8 | htoa(inputbuf[ 9], inputbuf[10]); break; case '5': // relative position if(inputptr != 15) { break; } sectL = htoa(inputbuf[ 3], inputbuf[ 4]); relpL = htoa(inputbuf[ 5], inputbuf[ 6]) << 8 | htoa(inputbuf[ 7], inputbuf[ 8]); sectL = htoa(inputbuf[ 9], inputbuf[10]); relpL = htoa(inputbuf[11], inputbuf[12]) << 8 | htoa(inputbuf[13], inputbuf[14]); break; case '6': // track sensors if(inputptr != 7) { break; } trksL = htoa(inputbuf[3], inputbuf[4]); trksR = htoa(inputbuf[5], inputbuf[6]); break; } break; } } else if(rev_passthru) { for(i = 0; i < inputptr; i++) { uart_put(DEBUG, inputbuf[i]); } fprintf(&debug, "\r\n"); } inputptr = 0; } } else if(recv == '\n') { ; } else { if(inputptr != RX_LINE_SIZE) { inputbuf[inputptr] = recv; inputptr++; } } } }