Project

General

Profile

Revision 269

small chat working with DR.mk

View differences:

proj/include/hltp.h
1 1
#ifndef HLTP_H_INCLUDED
2 2
#define HLTP_H_INCLUDED
3 3

  
4
int hltp_send_string(int port, const char *p);
4
int hltp_send_string(int base_addr, const char *p);
5 5

  
6
int hltp_get_string(int base_addr, char **p);
7

  
6 8
#endif //HLTP_H_INCLUDED
proj/include/nctp.h
11 11
 * @param   port    Port to send message to
12 12
 * @param   num     Number of pairs of address/numbytes to send
13 13
 */
14
int nctp_send(int port, size_t num, uint8_t* ptr[], size_t sz[]);
14
int nctp_send(int base_addr, size_t num, uint8_t* ptr[], size_t sz[]);
15 15

  
16
int ntcp_get(int port, uint8_t *dest);
16
int nctp_get (int base_addr, uint8_t **dest);
17 17

  
18 18
#endif //NCTP_H_INCLUDED
proj/src/hltp.c
4 4

  
5 5
#include "nctp.h"
6 6

  
7
int hltp_send_string(int port, const char *p){
8
    uint8_t* ptr[] = {p};
9
    size_t    sz[] = {strlen(p)};
10
    return nctp_send(port, 1, ptr, sz);
7
int hltp_send_string(int base_addr, const char *p){
8
    uint8_t* ptr[1]; ptr[0] = (uint8_t*)p;
9
    size_t    sz[1]; sz[0] = strlen(p)+1;
10
    return nctp_send(base_addr, 1, ptr, sz);
11 11
}
12 12

  
13
int hltp_get_string(int port, char *p){
14
    return nctp_get(port, p);
13
int hltp_get_string(int base_addr, char **p){
14
    return nctp_get(base_addr, (uint8_t**)p);
15 15
}
proj/src/proj.c
31 31
#include "list.h"
32 32

  
33 33
#ifdef DIOGO
34
    #include "test7.h"
34
    #include "uart.h"
35
    #include "hltp.h"
35 36
#endif
36 37

  
37 38
int main(int argc, char* argv[]) {
......
59 60
    /// subscribe interrupts
60 61
    if (subscribe_all()) { return 1; }
61 62

  
62
    /// initialize graphics
63
    if(graph_init(GRAPH_MODE)){
64
        printf("%s: failed to initalize graphics.\n", __func__);
65
        if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
66
        return 1;
67
    }
63
    #ifndef DIOGO
64
        /// initialize graphics
65
        if(graph_init(GRAPH_MODE)){
66
            printf("%s: failed to initalize graphics.\n", __func__);
67
            if (cleanup()) printf("%s: failed to cleanup.\n", __func__);
68
            return 1;
69
        }
70
    #endif
68 71

  
69 72
    /// Load stuff
70 73
    basic_sprite_t       *bsp_crosshair = NULL;
......
75 78
    map_t                *map1          = NULL;
76 79
    sprite_t             *sp_crosshair  = NULL;
77 80
    {
78
        graph_clear_screen();
79
        text_t *txt = text_ctor(consolas, "Loading...");
80
        text_draw(txt);
81
        text_dtor(txt);
82
        graph_draw();
81
        #ifndef DIOGO
82
            graph_clear_screen();
83
            text_t *txt = text_ctor(consolas, "Loading...");
84
            text_draw(txt);
85
            text_dtor(txt);
86
            graph_draw();
87
        #endif
83 88

  
84 89
        bsp_crosshair = get_crosshair(); if(bsp_crosshair == NULL) printf("Failed to get crosshair\n");
85 90
        bsp_shooter   = get_shooter  (); if(bsp_shooter   == NULL) printf("Failed to get shooter\n");
......
136 141
    #ifndef DIOGO
137 142
        int click = 0;
138 143
    #endif
144
    #ifdef DIOGO
145
        char *s = NULL;
146
    #endif
139 147

  
140 148
    while (game_state != EXIT) {
141 149
        /* Get a request message. */
......
198 206
                                case MENU:
199 207
                                    if ((scancode[0]) == ESC_BREAK_CODE) game_state = EXIT;
200 208

  
201
                                    else if ((scancode[0]) == A_MAKE_CODE) buffer[buffer_pos++] = 'A';
202

  
209
                                    else if ((scancode[0]) == A_MAKE_CODE){
210
                                        buffer[buffer_pos++] = 'A';
211
                                        printf("%c", buffer[buffer_pos-1]);
212
                                    }
203 213
                                    else if ((scancode[0]) == ENTER_MAKE_CODE) {
204
                                        // func1
205

  
214
                                        buffer[buffer_pos] = '\0';
215
                                        printf("\nSending string -%s-\n", buffer);
216
                                        printf("Send string output: %d\n",
217
                                            hltp_send_string(COM1_ADDR, buffer));
206 218
                                        buffer_pos = 0;
207 219
                                    }
208 220

  
......
249 261
                            #endif
250 262
                            #ifdef DIOGO
251 263
                            case COM1_IRQ:
252
                                char *s = NULL;
253
                                hltp_get_string(1, s);
254
                                printf("You've got mail: %s\n", s);
255
                                break;
264
                                {
265
                                    printf("You've got mail");
266
                                    int r = hltp_get_string(COM1_ADDR, &s);
267
                                    printf(" (return code %d)", r);
268
                                    printf(": -%s-\n", s);
269
                                }break;
256 270
                            #endif
257 271
                            }
258 272
                        }
......
267 281
        }
268 282
    }
269 283

  
284
    #ifdef DIOGO
285
        free(s);
286
    #endif
287

  
270 288
    while(list_size(shooter_list) > 0){
271 289
        gunner_t *p = list_erase(shooter_list, list_begin(shooter_list));
272 290
        gunner_dtor(p);
proj/src/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
}
proj/DR.mk
2 2

  
3 3
.PATH: ${.CURDIR}/src
4 4

  
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c hltp.c
6 6

  
7 7
CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D DIOGO #-D __LCOM_OPTIMIZED_
8 8

  
proj/Makefile
2 2

  
3 3
.PATH: ${.CURDIR}/src
4 4

  
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c hltp.c
6 6

  
7 7
CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D __LCOM_OPTIMIZED_
8 8

  
proj/TB.mk
2 2

  
3 3
.PATH: ${.CURDIR}/src
4 4

  
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c
5
SRCS= proj.c list.c graph.c kbc.c keyboard.c mouse.c utils.c timer.c interrupts_func.c proj_func.c fast_math.c rectangle.c font.c xpm_utils.c ent.c rtc.c test7.c uart.c hltp.c
6 6

  
7 7
CPPFLAGS += -pedantic -I./include -I./maps -I./media/xpm -D LCOM_MACRO -D TELMO #-D __LCOM_OPTIMIZED_
8 8

  

Also available in: Unified diff