Revision 287
implemented final, working version of uart and protocol
proj/libs/uart/include/uart.h | ||
---|---|---|
50 | 50 |
int uart_disable_int_tx(int base_addr); |
51 | 51 |
|
52 | 52 |
/// NCTP - Non-critical transmission protocol |
53 |
int nctp_init(void); |
|
53 |
int nctp_init(void (*proc_func)(const uint8_t*, const size_t));
|
|
54 | 54 |
int nctp_free(void); |
55 | 55 |
|
56 | 56 |
int nctp_send(size_t num, uint8_t* ptr[], size_t sz[]); |
... | ... | |
58 | 58 |
int nctp_ih_err; |
59 | 59 |
void nctp_ih(void); |
60 | 60 |
|
61 |
/// HLTP - High-level transmission protocol |
|
62 |
int hltp_send_string(const char *p); |
|
63 |
|
|
64 | 61 |
#endif //UART_H_INCLUDED |
proj/libs/uart/src/uart.c | ||
---|---|---|
284 | 284 |
|
285 | 285 |
queue_t *out = NULL; |
286 | 286 |
queue_t *in = NULL; |
287 |
void (*process)(const uint8_t*, const size_t); |
|
287 | 288 |
|
288 |
int nctp_init(void){ |
|
289 |
int nctp_init(void (*proc_func)(const uint8_t*, const size_t)){
|
|
289 | 290 |
out = queue_ctor(); if(out == NULL) return NULL_PTR; |
290 | 291 |
in = queue_ctor(); if(in == NULL) return NULL_PTR; |
292 |
process = proc_func; |
|
291 | 293 |
return SUCCESS; |
292 | 294 |
} |
293 | 295 |
int nctp_free(void){ |
... | ... | |
326 | 328 |
} |
327 | 329 |
return SUCCESS; |
328 | 330 |
} |
329 |
|
|
330 | 331 |
static int nctp_transmit(void){ |
331 | 332 |
if(!queue_empty(out)){ |
332 | 333 |
int ret = uart_send_char(COM1_ADDR, *(uint8_t*)queue_top(out)); |
... | ... | |
335 | 336 |
}else return SUCCESS; |
336 | 337 |
} |
337 | 338 |
|
338 |
static void process(){
|
|
339 |
static void nctp_process_received(){
|
|
339 | 340 |
free(queue_top(in)); queue_pop(in); |
341 |
size_t sz = 1024; uint8_t *p = malloc(sz*sizeof(uint8_t)); |
|
342 |
size_t i = 0; |
|
340 | 343 |
while(*(uint8_t*)queue_top(in) != NCTP_END){ |
341 |
printf("%c", *(uint8_t*)queue_top(in)); |
|
344 |
//printf("%c\n", *(uint8_t*)queue_top(in)); |
|
345 |
p[i++] = *(uint8_t*)queue_top(in); |
|
342 | 346 |
free(queue_top(in)); queue_pop(in); |
347 |
if(i >= sz) p = realloc(p, sz=2*sz); |
|
343 | 348 |
} |
344 |
printf("\n"); |
|
345 | 349 |
free(queue_top(in)); queue_pop(in); |
350 |
process(p, i); |
|
351 |
free(p); |
|
346 | 352 |
} |
347 | 353 |
static int nctp_receive(void){ |
348 | 354 |
int ret; |
... | ... | |
354 | 360 |
queue_push(in, tmp); |
355 | 361 |
if(c == NCTP_END) ++num_ends; |
356 | 362 |
} |
357 |
while(num_ends-- > 0) process();
|
|
363 |
while(num_ends-- > 0) nctp_process_received();
|
|
358 | 364 |
return SUCCESS; |
359 | 365 |
} |
360 | 366 |
|
... | ... | |
370 | 376 |
} |
371 | 377 |
} |
372 | 378 |
} |
373 |
|
|
374 |
/// HLTP |
|
375 |
int hltp_send_string(const char *p){ |
|
376 |
uint8_t* ptr[1]; ptr[0] = (uint8_t*)p; |
|
377 |
size_t sz[1]; sz[0] = strlen(p)+1; |
|
378 |
return nctp_send(1, ptr, sz); |
|
379 |
} |
proj/src/interrupts_func.c | ||
---|---|---|
4 | 4 |
#include "timer.h" |
5 | 5 |
#include "keyboard.h" |
6 | 6 |
#include "mouse.h" |
7 |
#include "uart.h"
|
|
7 |
#include "hltp.h"
|
|
8 | 8 |
#include "utils.h" |
9 | 9 |
#include "errors.h" |
10 | 10 |
|
... | ... | |
50 | 50 |
NULL, |
51 | 51 |
}; |
52 | 52 |
|
53 |
static void process_received(const uint8_t *p, const size_t sz){ |
|
54 |
void *q = NULL; |
|
55 |
hltp_type t = hltp_interpret(p, sz, &q); |
|
56 |
switch(t){ |
|
57 |
case hltp_type_string:{ |
|
58 |
char *s = q; |
|
59 |
printf("%s\n", s); |
|
60 |
} break; |
|
61 |
default: break; |
|
62 |
} |
|
63 |
} |
|
64 |
|
|
53 | 65 |
int (subscribe_all)(void) { |
54 | 66 |
|
55 | 67 |
/// Timer interrupt handling |
... | ... | |
111 | 123 |
return SBCR_ERROR; |
112 | 124 |
} |
113 | 125 |
uart_subscribed = 1; |
114 |
nctp_init(); |
|
126 |
nctp_init(process_received);
|
|
115 | 127 |
|
116 | 128 |
return SUCCESS; |
117 | 129 |
} |
proj/src/proj.c | ||
---|---|---|
12 | 12 |
#include "mouse.h" |
13 | 13 |
#include "graph.h" |
14 | 14 |
#include "rtc.h" |
15 |
#include "uart.h"
|
|
15 |
#include "hltp.h"
|
|
16 | 16 |
#include "interrupts_func.h" |
17 | 17 |
#include "makecode_map.h" |
18 | 18 |
|
proj/DR.mk | ||
---|---|---|
9 | 9 |
.PATH: ${.CURDIR}/libs/classes/src |
10 | 10 |
.PATH: ${.CURDIR}/libs/utils/src |
11 | 11 |
|
12 |
SRCS= proj.c list.c queue.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 uart.c makecode_map.c |
|
12 |
SRCS= proj.c list.c queue.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 uart.c hltp.c makecode_map.c
|
|
13 | 13 |
IPATHS=-I./include -I./libs/graph/include -I./libs/kbc/include -I./libs/rtc/include -I./libs/timer/include -I./libs/uart/include -I./libs/classes/include -I./libs/utils/include -I./maps -I./media/xpm |
14 | 14 |
|
15 | 15 |
CPPFLAGS += -pedantic ${IPATHS} -D LCOM_MACRO #-D __LCOM_OPTIMIZED_ |
Also available in: Unified diff