Ignore:
Timestamp:
Jul 31, 2019, 5:43:21 PM (5 years ago)
Author:
bouyer
Message:

Firmware for V2 boards

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/software/firmware/serial.c

    r1 r11  
    66unsigned char uart_txbuf_prod;
    77volatile unsigned char uart_txbuf_cons;
     8
     9char uart_rxbuf[UART_BUFSIZE];
     10volatile unsigned char uart_rxbuf_prod;
     11unsigned char uart_rxbuf_cons;
     12
     13#define LEDR LATAbits.LATA7
    814
    915PUTCHAR(c) /* Macro */
     
    4147}
    4248
     49void
     50uart_putchar_raw(char c)
     51{
     52        unsigned char new_uart_txbuf_prod;
     53        new_uart_txbuf_prod = (uart_txbuf_prod + 1) & UART_BUFSIZE_MASK;
     54        while (new_uart_txbuf_prod == uart_txbuf_cons) {
     55                PIE1bits.TX1IE = 1; /* ensure we'll make progress */
     56        }
     57        uart_txbuf[uart_txbuf_prod] = c;
     58        uart_txbuf_prod = new_uart_txbuf_prod;
     59        PIE1bits.TX1IE = 1;
     60}
     61
     62void
     63uart_putchar_hard(char c) __wparam {
     64        while (PIR1bits.TX1IF == 0)
     65                ;
     66        TXREG1 = c;
     67}
     68
    4369char
    4470getchar(void)
    4571{
    4672        char c;
     73        char en;
     74        en = PIE1bits.RC1IE;
     75        PIE1bits.RC1IE = 0;
    4776        while (!PIR1bits.RC1IF); /* wait for a char */
    4877        c = RCREG1;
     
    5180                RCSTA1bits.CREN = 1;
    5281        }
     82        PIE1bits.RC1IE = en;
    5383        return c;
    5484}
     85
     86char
     87uart_getchar()
     88{
     89        register char c;
     90        LEDR = 1;
     91        while (uart_rxbuf_cons == uart_rxbuf_prod)
     92                ;
     93
     94        uart_rxbuf_cons = (uart_rxbuf_cons + 1) & UART_BUFSIZE_MASK;
     95        c = uart_rxbuf[uart_rxbuf_cons];
     96        LEDR = 0;
     97        return c;
     98}
Note: See TracChangeset for help on using the changeset viewer.