Arduino Sample code for LinkSprite Mamba Powerline Communication Shield

Mamba http://www.linksprite.com/product/showproduct.php?id=69&lang=enis a linksprite produced powerline communication shield for arduino.

A sample code is:

#include <stdio.h>
#include <stdbool.h>
#include <string.h>
#include <avr/interrupt.h>
#include <util/delay.h>

#include "spi.h"
#include "ports.h"
#include "plm1.h"

#define MOSI            B,3
#define MISO            B,4
#define SCK             B,5


static volatile bool uart_tx_flag = false;      /* Flag for Tx UART interrupt. */
static volatile bool uart_rx_flag = false;      /* Flag for Rx UART interrupt. */
static uint8_t uart_rx_data;                    /* Rx UART data read. */

uint8_t rx_packet[PLM_RX_MAX_PACKET_SIZE];
uint8_t rx_length = 0;
uint8_t tx_packet[PLM_TX_MAX_PACKET_SIZE];
uint8_t tx_length = 0;

uint8_t incomingByte = 0;	// for incoming serial data

void setup()                    
{
   PIN_OUTPUT(MOSI);
   PIN_OUTPUT(SCK);
   PIN_OUTPUT(nPLM_RESET);
   PIN_OUTPUT(PLM_CS);
   PIN_INPUT(MISO);

   /* SPI communication must be initialized before plm1 library. */
   spi_init( SPI_SPEED_F16 );

   /* Initialization of plm1 library. */
   plm1_init();


   /* Activate external interrupt 0 for PLM-1 */
   EIFR = 0xFF;                              /* Clear external interrupt flags. */
   EICRA = _BV( ISC00 ) | _BV( ISC01 );      /* INT0 activated on a rising edge. */
   EIMSK = _BV( INT0 );                      /* Enable only external interrupt 0 (PLM). */


   Serial.begin(9600);           // set up Serial library at 9600 bps

   /* Activate global interrupts. */
   sei();
   
  
}

void
loop( void )
{

      // send data only when you receive data:
      if (Serial.available() > 0) {
	   // read the incoming byte:
	   incomingByte = Serial.read();

           plm1_send_data(&incomingByte, 1);
      }

      /* When a packet is received, plm1_receive returns the length of the 
       * packet and copies the contents of the packet in rx_packet. */
      if( (rx_length = plm1_receive(rx_packet)) )
      {
          Serial.print(byte(rx_packet[0]));
      }

}




/* Interrupt Service Routine provenant de la ligne d'interruption du PLM. */
SIGNAL(INT0_vect)
{
   plm1_interrupt();
}

The library can be downloaded from: http://www.linksprite.com/download/showdownload.php?lang=en&id=117