void send_ack(uint8_t seq_num) { border_packet_t *packet = (border_packet_t *)get_serial_out_buffer(0); packet->empty = 0; packet->type = BORDER_PACKET_ACK_TYPE; packet->seq_num = seq_num; writepacket((uint8_t *)packet, sizeof (border_packet_t)); }
void flowcontrol_send_over_uart(border_packet_t *packet, int len) { struct send_slot *slot; uint8_t args[] = {packet->seq_num}; sem_wait(&(slwin_stat.send_win_not_full)); packet->seq_num = ++slwin_stat.last_frame; slot = &(slwin_stat.send_win[packet->seq_num % BORDER_SWS]); memcpy(slot->frame, (uint8_t *)packet, len); slot->frame_len = len; if (set_timeout(&slot->timeout, BORDER_SL_TIMEOUT, (void *)args) != 0) { printf("ERROR: Error invoking timeout timer\n"); return; } writepacket((uint8_t *)packet, len); }
static void sending_slot(void) { while (1) { msg_t m; msg_receive(&m); uint8_t seq_num = *((uint8_t *) m.content.ptr); struct send_slot *slot = &(slwin_stat.send_win[seq_num % BORDER_SWS]); border_packet_t *tmp = (border_packet_t *)slot->frame; if (seq_num == tmp->seq_num) { writepacket(slot->frame, slot->frame_len); if (set_timeout(&slot->timeout, timex_set(0, BORDER_SL_TIMEOUT), (void *)m.content.ptr) != 0) { printf("ERROR: Error invoking timeout timer\n"); } } } }