Project

General

Profile

Revision 277

added queue. implemented working queues

View differences:

uart.c
23 23
#define UART_DLM                                1
24 24

  
25 25
/// LCR
26
//#define UART_BITS_PER_CHAR_POS                  0
26
#define UART_BITS_PER_CHAR_POS                  0
27 27
#define UART_STOP_BITS_POS                      2
28 28
#define UART_PARITY_POS                         3
29 29
#define UART_BREAK_CONTROL_POS                  6
......
80 80
#define UART_GET_TRANSMITTER_EMPTY(n)           (((n)&UART_TRANSMITTER_EMPTY        )>>UART_TRANSMITTER_EMPTY_POS        )
81 81

  
82 82
/// IIR
83
#define UART_INT_PEND_POS                       1
84

  
85
#define UART_INT_PEND                           (BIT(3)|BIT(2)|BIT(1))
86

  
83 87
#define UART_GET_IF_INT_PEND(n)                 (!((n)&1))
84
#define UART_GET_INT_PEND(n)                    (((n)&0xE)>>1)
85
#define UART_INT_RX                             0x2 //0b010
86
#define UART_INT_TX                             0x1 //0b001
88
typedef enum {
89
    uart_int_receiver_line_stat = (         BIT(1) | BIT(0)),
90
    uart_int_rx                 = (         BIT(1)         ),
91
    uart_int_char_timeout_fifo  = (BIT(2) | BIT(1)         ),
92
    uart_int_tx                 = (                  BIT(0)),
93
    uart_int_modem_stat         = (0)
94
} uart_int_code;
95
#define UART_GET_INT_PEND(n)                    ((uart_int_code)(((n)&UART_INT_PEND)>>UART_INT_PEND_POS))
87 96

  
88 97
int (subscribe_uart_interrupt)(uint8_t interrupt_bit, int *interrupt_id) {
89 98
    if (interrupt_id == NULL) return 1;
......
272 281
#define NCTP_END        0xFF
273 282
#define NCTP_OK         0xFF
274 283
#define NCTP_NOK        0x00
275
#define NCTP_MAX_SIZE   1024 //in bytes
276 284

  
277 285
queue_t *out = NULL;
278 286
queue_t *in  = NULL;
......
296 304

  
297 305
int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]){
298 306
    {
299
        int cnt = 0;
307
        size_t cnt = 0;
300 308
        for(size_t i = 0; i < num; ++i){
301 309
            cnt += sz[i];
302
            if(cnt > NCTP_MAX_SIZE) return TRANS_REFUSED;
310
            if(cnt > queue_max_size) return TRANS_REFUSED;
303 311
        }
304 312
    }
305 313
    int ret;
......
337 345
static int nctp_receive(void){
338 346
    int ret;
339 347
    uint8_t c;
348
    int num_ends = 0;
340 349
    while(uart_receiver_ready(COM1_ADDR)){
341 350
        if((ret = uart_get_char(COM1_ADDR, &c))) return ret;
342 351
        uint8_t *tmp = malloc(sizeof(uint8_t)); *tmp = c;
343 352
        queue_push(in, tmp);
344
        if(c == NCTP_END) process();
353
        if(c == NCTP_END) ++num_ends;
345 354
    }
355
    while(num_ends-- > 0) process();
346 356
    return SUCCESS;
347 357
}
348 358

  
......
352 362
    if((nctp_ih_err = uart_get_iir(COM1_ADDR, &iir))) return;
353 363
    if(UART_GET_IF_INT_PEND(iir)){
354 364
        switch(UART_GET_INT_PEND(iir)){
355
            case UART_INT_RX: nctp_receive (); break;
356
            case UART_INT_TX: nctp_transmit(); break;
365
            case uart_int_rx: nctp_receive (); break;
366
            case uart_int_tx: nctp_transmit(); break;
357 367
            default: break;
358 368
        }
359 369
    }

Also available in: Unified diff