Project

General

Profile

Revision 269

small chat working with DR.mk

View differences:

uart.c
256 256
    return uart_set_ier(base_addr, ier);
257 257
}
258 258

  
259
static int uart_has_communication_error(int base_addr){
259
/*static*/ int uart_has_communication_error(int base_addr){
260 260
    int ret;
261 261
    uint8_t lsr;
262 262
    if((ret = uart_get_lsr(base_addr, &lsr))) return 1;
......
305 305
    int ret;
306 306
    for(size_t k = 0; k < NCTP_TRIES; ++k){
307 307
        if((ret = nctp_send_char_poll(base_addr, c))) return ret;
308
        if(nctp_expect_ok(base_addr) == SUCCESS) return SUCCESS;
308
        return SUCCESS;
309
        //if(nctp_expect_ok(base_addr) == SUCCESS) return SUCCESS;
309 310
    }
310 311
    return TRANS_FAILED;
311 312
}
......
313 314
    int ret;
314 315
    for(size_t k = 0; k < NCTP_TRIES; ++k){
315 316
        if((ret = nctp_get_char_poll (base_addr, p))) return ret;
316
        if(!uart_has_communication_error(base_addr))
317
            return nctp_send_char_try(base_addr, NCTP_OK ); //If it does not have any errors
317
        return SUCCESS;
318
        //if(!uart_has_communication_error(base_addr))
319
            //return nctp_send_char_try(base_addr, NCTP_OK ); //If it does not have any errors
318 320
    }
319 321
    if((ret = nctp_send_char_poll(base_addr, NCTP_NOK))) return ret;
320 322
    return TRANS_FAILED;
321 323
}
322 324

  
323
int nctp_send(int port, size_t num, uint8_t* ptr[], size_t sz[]){
325
static int nctp_send_inner(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]){
324 326
    {
325 327
        int cnt = 0;
326 328
        for(size_t i = 0; i < num; ++i){
......
329 331
        }
330 332
    }
331 333

  
332
    int base_addr;{
333
        switch(port){
334
            case 1: base_addr = COM1_ADDR; break;
335
            case 2: base_addr = COM2_ADDR; break;
336
            default: return INVALID_ARG;
337
        }
338
    }
339

  
340 334
    int ret;
341 335

  
342
    if((ret = uart_disable_int_rx(base_addr))) return ret;
343
    if((ret = uart_disable_int_tx(base_addr))) return ret;
344

  
345 336
    if((ret = nctp_send_char_try(base_addr, NCTP_START))) return ret;
346 337
    for(size_t i = 0; i < num; ++i){
347 338
        uint8_t *p = ptr[i]; size_t s = sz[i];
......
353 344

  
354 345
    return SUCCESS;
355 346
}
356
int ntcp_get(int port, uint8_t *dest){
357
    int base_addr;{
358
        switch(port){
359
            case 1: base_addr = COM1_ADDR; break;
360
            case 2: base_addr = COM2_ADDR; break;
361
            default: return INVALID_ARG;
362
        }
363
    }
347
int nctp_send(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]){
348
    int ret;
349
    if((ret = uart_disable_int_rx(base_addr))) return ret;
350
    if((ret = uart_disable_int_tx(base_addr))) return ret;
351
    int r = nctp_send_inner(base_addr, num, ptr, sz);
352
    if((ret = uart_enable_int_rx(base_addr))) return ret;
353
    if((ret = uart_disable_int_tx(base_addr))) return ret;
354
    return r;
355
}
364 356

  
357
static int nctp_get_inner(int base_addr, uint8_t **dest){
365 358
    int ret;
366
    free(dest);
367
    dest = malloc(NCTP_MAX_SIZE*sizeof(uint8_t)); size_t i = 0;
368
    if(dest == NULL) return NULL_PTR;
359
    free(*dest);
360
    *dest = malloc(NCTP_MAX_SIZE*sizeof(uint8_t)); size_t i = 0;
361
    if(*dest == NULL) return NULL_PTR;
369 362
    uint8_t c;
370 363
    if((ret = nctp_get_char_try (base_addr, &c     ))) return ret;
371 364
    while(true){
372 365
        if(i >= NCTP_MAX_SIZE) return TRANS_REFUSED;
373 366
        if((ret = nctp_get_char_try (base_addr, &c))) return ret;
374
        if(c == NCTP_END) break;
375
        else              dest[i] = c;
376
        ++i;
367
        if(c == NCTP_END) return SUCCESS;
368
        else              (*dest)[i++] = c;
377 369
    }
378
    return SUCCESS;
379 370
}
371
int nctp_get(int base_addr, uint8_t **dest){
372
    int ret;
373
    if((ret = uart_disable_int_rx(base_addr))) return ret;
374
    if((ret = uart_disable_int_tx(base_addr))) return ret;
375
    int r = nctp_get_inner(base_addr, dest);
376
    if((ret = uart_enable_int_rx(base_addr))) return ret;
377
    if((ret = uart_disable_int_tx(base_addr))) return ret;
378
    return r;
379
}

Also available in: Unified diff