コード例 #1
0
void hdlc_test(void)
{
    u8_t data;

    // Enable RS-485 PIO for loopback operation
    BIT_SET_HI(PORT_RS485_TX_EN_O, BIT_RS485_TX_EN_O);
    BIT_SET_HI(DDR_RS485_TX_EN_O, BIT_RS485_TX_EN_O);

    BIT_SET_LO(PORT_RS485_RX_EN_O, BIT_RS485_RX_EN_O);
    BIT_SET_HI(DDR_RS485_RX_EN_O, BIT_RS485_RX_EN_O);

    // Initialise modules
    uart0_init();
    uart1_init();
    printf_init();
    hdlc_init(&hdlc_on_rx_frame);

    // Enable global interrupts
    sei();
        
    // Send an HDLC packet
    data = 0x55;
    hdlc_tx_frame(&data,1);

    // Process received data
    for(;;)
    {
        if(uart1_get_rx_byte(&data))
        {
            PRINTF("%02X ", data);
            // Feed received data to HDLC layer
            hdlc_on_rx_byte(data);
        }
    }
}
コード例 #2
0
ファイル: run.c プロジェクト: cupidljh/test
int main(int argc, char *argv[])
{
	hdlc_enc hdlc_enc[10];
	hdlc_dec hdlc_dec;

	if (argc == 1) {
		fputs("[error] no file \n", stderr);
		exit(1);
	}

	hdlc_init(hdlc_enc, &hdlc_dec); // hdlc encode, decode 구조체 초기화
	hdlc_encode(argv[1], hdlc_enc); // file data encode

	hdlc_decode(hdlc_enc, &hdlc_dec);//hdlc_decode(hdlc_enc, hdlc_dec);// file data decode

	return 0;
}
コード例 #3
0
ファイル: ws_uart_app.c プロジェクト: ivmi/esp-ginx-rc
static int  ICACHE_FLASH_ATTR ws_app_client_connected(http_connection *c){

	NODE_DBG("Webscoket app client connected %p",c);
		
	//create config
	struct ws_app_context *context = (struct  ws_app_context*)os_zalloc(sizeof(struct ws_app_context));
	context->conn=c;
	c->reverse = context; //so we may find it on callbacks

    int i;
    for (i=0; i<MAX_CONNECTIONS; i++)
    {
        if (clients[i] == NULL)
        {
            clients[i] = context;
            break;
        }
    }

    // set uart interrupt handler
    uart_register_data_callback(on_uart_data);
    hdlc_init(uart_put_char, on_uart_frame);
	NODE_DBG("\tcontext %p",context);
}
コード例 #4
0
void uos_init (void)
{
	mutex_group_t *g;

	/* Baud 9600. */
	uart_init (&uart, 0, PRIO_UART, KHZ, 9600);
	timer_init (&timer, KHZ, 50);
	watchdog_alive ();

	/* Configure control pins. */
	control_link_led (0);
        gpio_config (PIN_DCD, 1);               /* P0 - output */
        gpio_config (PIN_CTS, 1);		/* P4 - output */
        gpio_config (PIN_LINK, 1);              /* P16 - output */
        gpio_config (PIN_DSR, 1);		/* P21 - output */

	configure_ram (RAM_START, RAM_START + RAM_SIZE, REFRESH_USEC, IO_START);
	mem_init (&pool, RAM_START, RAM_START + RAM_SIZE);
	watchdog_alive ();

	/* Configure Ethernet. */
	eth = mem_alloc (&pool, sizeof (eth_t));
	if (! eth) {
		debug_printf ("No memory for eth_t\n");
		uos_halt (1);
	}

	/*
	 * Create a group of two locks: timer and eth.
	 */
	g = mutex_group_init (group, sizeof(group));
	mutex_group_add (g, &eth->netif.lock);
	mutex_group_add (g, &timer.decisec);
	ip = mem_alloc (&pool, sizeof (*ip));
	if (! ip) {
		debug_printf ("No memory for ip_t\n");
		uos_halt (1);
	}
	arp = arp_init (arp_data, sizeof(arp_data), ip);
	ip_init (ip, &pool, PRIO_IP, &timer, arp, g);

	/*
	 * Create interface eth0 144.206.181.188 / 255.255.255.0
	 */
	eth_init (eth, "eth0", PRIO_ETH_RX, PRIO_ETH_TX, &pool, arp);
	route_add_netif (ip, &route, (unsigned char*) "\220\316\265\274",
		24, &eth->netif);

	/* Configure HDLC. */
	hdlc = mem_alloc (&pool, sizeof (hdlc_t));
	if (! hdlc) {
		debug_printf ("No memory for hdlc_t\n");
		uos_halt (1);
	}
	hdlc_init (hdlc, 0, "hdlc0", PRIO_HDLC_RX, PRIO_HDLC_TX,
		&pool, KHZ * 1000);
	hdlc->callback_receive = receive_hdlc;

	stack_console = mem_alloc (&pool, CONSOLE_STACKSZ);
	assert (stack_console != 0);
	task_create (main_console, 0, "console", PRIO_CONSOLE,
		stack_console, CONSOLE_STACKSZ);

	stack_poll = mem_alloc (&pool, POLL_STACKSZ);
	assert (stack_poll != 0);
	task_create (main_poll, 0, "poll", PRIO_POLL,
		stack_poll, POLL_STACKSZ);

	stack_telnet = mem_alloc (&pool, TELNET_STACKSZ);
	assert (stack_telnet != 0);
	task_create (main_telnet, 0, "telnet", PRIO_TELNET,
		stack_telnet, TELNET_STACKSZ);
}
コード例 #5
0
ファイル: CANcontrol.c プロジェクト: kevinkrieger/CAN
void main(int argc, int* argv) {
	int i;
	int rv;

	start_gui("hellO",args,arg,0,DEF_CB,"draw_hello",draw_hello,DONE);
	create_window("Hello",0,0,200,100,0,SET_PROP,"ON_REDRAW",1,"draw_hello",DONE);
	run_event_loop(&rv);

	printf("Opening %s... ",BTSERIAL);
	//can_board = fopen(BTSERIAL,"r+");
	can_board = open(BTSERIAL,O_RDWR|O_NONBLOCK);
	hdlc_frame = malloc(sizeof(HDLC_OBJ_T));
	ringbuffer = malloc(sizeof(RINGBUFF_T));
	RingBuffer_Init(ringbuffer, rb_data, rb_itemSize, RB_LEN);
	printf("Ringbuffer initialized\r\n");
	hdlc_init();

	if (can_board != 0) {
		printf("Success\r\n");
			printf("1 - Send command\r\n" 
					"2 - Listen only\r\n");
		while(1) {
			if(inputAvailable()) {
				printf("Input available\r\n");
				scanf("%d",&input);
				if(input == 1) {
					sendCommand();
				} else if (input == 2) {
					while(1) {
						//fscanf(can_board, "%s",(char *)buffer);
						numread = read(can_board,buffer,64);
						if(numread > 0) {
							printf("%s\r\n",(char *)buffer);
						}
					}
				}
			printf("1 - Send command\r\n" 
					"2 - Listen only\r\n");
			}
	//		else {
	//			printf("no input available");
	//		}
			//numread = fread(buffer,1,64,can_board);
			numread = read(can_board,buffer,64);
			if(numread > 0) {
				printf("Read something:");
				RingBuffer_InsertMult(ringbuffer, buffer,numread);
				for(i = 0; i< numread; i++){
					printf(" %x",buffer[i]);
				}
				printf("\r\n");
				hdlc_frame_parser(ringbuffer);
			} else {
				printf("Nothing read\r\n");
			}
			sleep(1);
		}
	//	fclose(can_board);
		close(can_board);
	}
	return;
}