Advertisement
Guest User

jebane stmy

a guest
Jan 19th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.58 KB | None | 0 0
  1. void send_pc(char *format, ...) {
  2.     char tmp_tab[128];
  3.     int i;
  4.     volatile int idx;
  5.     idx = tx.head;
  6.  
  7.     va_list arglist;
  8.     va_start(arglist, format);
  9.     vsprintf(tmp_tab, format, arglist);
  10.     va_end(arglist);
  11.  
  12.     for (i = 0; i < strlen(tmp_tab); i++) {
  13.         tx.buff[idx] = tmp_tab[i];
  14.         idx++;
  15.         if (idx >= BUFF_SIZE) {
  16.             idx = 0;
  17.         }
  18.     }
  19.     __disable_irq();
  20.     if ((tx.head != tx.tail)) {
  21.         tx.head = idx;
  22.         uint8_t tmp = tx.buff[tx.tail];
  23.         HAL_UART_Transmit_IT(&huart2, &tmp, 1);
  24.         tx.tail++;
  25.         if (tx.tail >= BUFF_SIZE)
  26.             tx.tail = 0;
  27.     } else {
  28.         tx.head = idx;
  29.     }
  30.     __enable_irq();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement