Main Page | Data Structures | File List | Data Fields | Globals | Related Pages

link.c File Reference

Link layer implementation. More...

#include <avr/io.h>
#include <avr/signal.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include <stdlib.h>
#include <string.h>
#include "net/link.h"
#include "net/buffers.h"
#include "net.h"

Go to the source code of this file.

Data Structures

struct  receive_info_t
 Structure containing all variables concerning packet reception. More...

struct  send_info_t
 Variables needed for transmitting. More...


Defines

#define ext_init()   sbi(MCUCR, LNK_EXT_ISCx1)
#define ext_enable()   {GIFR = _BV(LNK_EXT_INT); sbi(GIMSK, LNK_EXT_INT);}
#define ext_disable()   cbi(GIMSK, LNK_EXT_INT)
#define UDR   UDR0
#define USR   UCSR0A
#define UCR   UCSR0B
#define UBRR   UBRR0
#define RENAME_ISR
#define POLY_CRC16   0x1021
 CCITT CRC polynominal.


Enumerations

enum  recv_stat_e { RECV_STAT_FREE, RECV_STAT_RECEIVING, RECV_STAT_EXAMINE }
 Actual receive state. More...

enum  send_stat_e { SEND_STAT_IDLE, SEND_STAT_WAIT, SEND_STAT_SEND_DATA, SEND_STAT_INFORM }
 Actual send state. More...


Functions

void lnk_con (void)
 Called from link layer if a packet was delivered.

void lnk_init (void)
 Perform initialization of link layer.

void lnk_process (void)
 Process link layer specific tasks.

int8_t lnk_requ (net_buf_t *buf, uint8_t backlog)
 Schedule a packet for sending.

uint8_t lnk_clear_to_send (void)
 Check if link layer is able to process further packets.

void lnk_get_error_stats (struct lnk_err_t *buf)
 Fill a buffer with link layer error statistics.


Detailed Description

Link layer implementation.

This layer is rather hardware specific. Read the following carefully to understand what parts are used and how. I assume you are familiar with the protocol itself. If not read OpenHome.doc.

In the first place it uses Timer/Counter0 exclusively for slot timing. The timer is configured through to following definitions located in your net.h:

Both values must be adjusted that Timer/Counter0 meets the desired slot time. Use the lowest prescaler that is possible to reach a maximum resulution. Otherwise the timing is prone to jitter and might be inconsistent between different nodes in the network which increases the possibility of collisions!

Attention:
Since timing is done in software it must also be ensured that interrupts are not disabled too long. This implies that you should use SIGNAL()'s only if really neccesary and keep them as short as possible. Always consider using INTERRUPT() instead. In most cases it should be possible to disable interrupts only for a minimum of time. Take it as a sign of inefficient coding if your code contains large code blocks with disabled interrupts.
Secondly a external interrupt is used which can sense falling edges. See net.h Configuration Parameters for configuring the actial interrupt line. It is used to immidiately detect the start bit if another node on the bus starts transmitting. As this is also a time-critical task keep the previous paragraph in mind.

Author:
Jan Klötzke
History:

Definition in file link.c.


Enumeration Type Documentation

enum recv_stat_e
 

Actual receive state.

Enumeration values:
RECV_STAT_FREE  listen for packet
RECV_STAT_RECEIVING  receiving packet
RECV_STAT_EXAMINE  examine packet

Definition at line 91 of file link.c.

enum send_stat_e
 

Actual send state.

Enumeration values:
SEND_STAT_IDLE  nothing to do
SEND_STAT_WAIT  wait for a free slot
SEND_STAT_SEND_DATA  currently sending data
SEND_STAT_INFORM  inform network layer that packet was sent

Definition at line 98 of file link.c.


Function Documentation

uint8_t lnk_clear_to_send void   ) 
 

Check if link layer is able to process further packets.

Returns:
Returns a nonzero value if the link layer is ready to process the next packet.

Definition at line 426 of file link.c.

References SEND_STAT_IDLE, and send_info_t::status.

Referenced by net_clear_to_send(), and net_requ().

void lnk_con void   ) 
 

Called from link layer if a packet was delivered.

Simply passes event to upper layers.

Definition at line 139 of file network.c.

References net_con().

Referenced by lnk_process().

void lnk_get_error_stats struct lnk_err_t buf  ) 
 

Fill a buffer with link layer error statistics.

Parameters:
buf A pointer to a structure receiving the error statistics.

Definition at line 436 of file link.c.

void lnk_init void   ) 
 

Perform initialization of link layer.

This function must be called before any other network functions are called.

Definition at line 289 of file link.c.

References receive_info_t::crc16, send_info_t::slot, and receive_info_t::slots.

void lnk_process void   ) 
 

Process link layer specific tasks.

Call this function as often as possible from your main loop. It processes link layer specific tasks such as passing received packets to upper layers and scheduling send requests.

Attention:
Must not be called from a interrupt routine. The implementation is not thread-save.

Definition at line 317 of file link.c.

References send_info_t::backlog, send_info_t::backlog_add, receive_info_t::buf, receive_info_t::crc16, lnk_con(), lnk_ind(), receive_info_t::pos, RECV_STAT_EXAMINE, RECV_STAT_FREE, lnk_err_t::rx_crc, lnk_err_t::rx_len, SEND_STAT_IDLE, SEND_STAT_INFORM, SEND_STAT_WAIT, send_info_t::slot, receive_info_t::slots, send_info_t::status, and receive_info_t::status.

int8_t lnk_requ net_buf_t *  buf,
uint8_t  backlog
 

Schedule a packet for sending.

This function returns without waiting for the packet to be sent. If the packet is fully transmitted then lnk_con is called.

Parameters:
buf A network buffer containing the data to be sent. Must not be released until lnk_con() is called.
backlog Link layer backlog field. See OpenHome.doc for a detailed discussion of this field.
Returns:
Zero if a transmission is already in progress and the packet could not be processed. Otherwise it returns a nonzero value.

Definition at line 383 of file link.c.

References send_info_t::backlog_add, send_info_t::data, POLY_CRC16, SEND_STAT_IDLE, SEND_STAT_WAIT, send_info_t::slot, and send_info_t::status.

Referenced by net_requ().


Generated on Fri Oct 17 16:45:54 2003 for OpenHome by doxygen 1.3.3