#include #include "stdlib.h" // Test code for dual-serial port devices // // If a character arrives on port 0, then // echo the character and the very next character // If a character arrives on port 2, then // echo the character and the next next character //#define getchar() uart_recv(NULL) //#define putchar(x) uart_send(x, NULL) extern int uart_send(char c, FILE *fp); extern int uart_recv(FILE *fp); //#define DUAL #define NEW_SINGLE void test_stack(void) { uint8_t c; printf("add:%x\n\r", (unsigned int) &c); }; void test_mem(void) { uint8_t c; char *ptr = malloc(1); printf("add:%x, %x\n\r", (unsigned int) &c, (unsigned int) ptr); free(ptr); }; int main(void) { DDRB = 3; static uint16_t counter = 0; PORTB = 1; delay_ms(250); PORTB = 2; delay_ms(250); PORTB = 3; delay_ms(250); PORTB = 0; delay_ms(1000); // The first open serial port will be attached to // stdin, stdout, stderr #ifdef DUAL FILE* fp0 = serial_init(0, 9600); FILE* fp1 = serial_init(1, 9600); #else #ifdef NEW_SINGLE FILE* fp0 = serial_init(0, 9600); #else serial0_init(9600); #endif #endif char c; #ifdef DUAL fprintf(fp0, "hello world\n\r"); fprintf(fp1, "hello other world\n\r"); while(1) { if(serial_input_waiting(fp0)) { c = fgetc(fp0); fprintf(fp0, "%c:%c\n\r", c, c+1); PORTB ^= 2; } if(serial_input_waiting(fp1)) { c = fgetc(fp1); fprintf(fp1, "%c:%c\n\r", c, c+2); PORTB ^= 2; } delay_ms(1); if(++counter == 100) { counter = 0; PORTB ^= 1; }; }; #else //printf("hello world single\n\r"); putchar('#'); putchar('#'); putchar('#'); while(1) { #ifdef NEW_SINGLE if(serial_input_waiting(fp0)) { #else if(kbhit()) { #endif c = getchar(); //printf("%c:%c\n\r", c, c+1); putchar(c); putchar(':'); putchar(c+1); putchar('\n'); putchar('\r'); PORTB ^= 2; test_mem(); } delay_ms(1); if(++counter == 100) { counter = 0; PORTB ^= 1; }; }; #endif }