Skip to content

Commit

Permalink
Adding support for using Digital pin 8 on Arduino as the interrupt pi…
Browse files Browse the repository at this point in the history
…n for WiShield
  • Loading branch information
asynclabs committed Jul 23, 2009
1 parent 9858517 commit 2fa2255
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 0 deletions.
20 changes: 20 additions & 0 deletions WiServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

extern "C" {
#include "g2100.h"
#include "spi.h"
#include "uip.h"
#include "server.h"
#include "global-conf.h"
Expand Down Expand Up @@ -83,7 +84,18 @@ void Server::init(pageServingFunction function) {

// WiShield init
zg_init();

#ifdef USE_DIG0_INTR
attachInterrupt(0, zg_isr, LOW);
#endif

#ifdef USE_DIG8_INTR
// set digital pin 8 on Arduino
// as ZG interrupt pin
PCICR |= (1<<PCIE0);
PCMSK0 |= (1<<PCINT0);
#endif

while(zg_get_conn_state() != 1) {
zg_drv_process();
}
Expand All @@ -106,6 +118,14 @@ void Server::init(pageServingFunction function) {
#endif // DEBUG
}

#ifdef USE_DIG8_INTR
// PCINT0 interrupt vector
ISR(PCINT0_vect)
{
zg_isr();
}
#endif

void Server::setIndicatorPins(int tx, int rx) {
// Store the pin numbers
txPin = tx;
Expand Down
19 changes: 19 additions & 0 deletions WiShield.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ extern "C" {
#include "global-conf.h"
#include "network.h"
#include "g2100.h"
#include "spi.h"
void stack_init(void);
void stack_process(void);
}
Expand All @@ -48,7 +49,17 @@ extern "C" {
void WiShield::init()
{
zg_init();

#ifdef USE_DIG0_INTR
attachInterrupt(0, zg_isr, LOW);
#endif

#ifdef USE_DIG8_INTR
// set digital pin 8 on Arduino
// as ZG interrupt pin
PCICR |= (1<<PCIE0);
PCMSK0 |= (1<<PCINT0);
#endif

while(zg_get_conn_state() != 1) {
zg_drv_process();
Expand All @@ -63,4 +74,12 @@ void WiShield::run()
zg_drv_process();
}

#if defined USE_DIG8_INTR && !defined APP_WISERVER
// PCINT0 interrupt vector
ISR(PCINT0_vect)
{
zg_isr();
}
#endif

WiShield WiFi;
28 changes: 28 additions & 0 deletions spi.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,26 @@
#ifndef SPI_H_
#define SPI_H_

// Uncomment one line below to
// specify which Arduino pin
// to use as WiShield interrupt
//#define USE_DIG0_INTR // use digital pin 0
#define USE_DIG8_INTR // use digital pin 8


#ifdef USE_DIG0_INTR
#define ZG2100_ISR_DISABLE() (EIMSK &= ~(0x01))
#define ZG2100_ISR_ENABLE() (EIMSK |= 0x01)
#define ZG2100_ISR_GET(X) (X = EIMSK)
#define ZG2100_ISR_SET(X) (EIMSK = X)
#endif

#ifdef USE_DIG8_INTR
#define ZG2100_ISR_DISABLE() (PCMSK0 &= ~(0x01))
#define ZG2100_ISR_ENABLE() (PCMSK0 |= 0x01)
#define ZG2100_ISR_GET(X) (X = PCMSK0)
#define ZG2100_ISR_SET(X) (PCMSK0 = X)
#endif

//AVR Mega168 SPI HAL
#define BIT0 0x01
Expand All @@ -51,6 +67,10 @@
#define BIT6 0x40
#define BIT7 0x80

#ifdef USE_DIG8_INTR
#define ZG2100_INTR BIT0
#endif

#define SPI0_SS_BIT BIT2
#define SPI0_SS_DDR DDRB
#define SPI0_SS_PORT PORTB
Expand Down Expand Up @@ -78,11 +98,19 @@
#define SPI0_RecvBute() SPI0_RxData()

// PB4(MISO), PB3(MOSI), PB5(SCK), PB2(/SS) // CS=1, waiting for SPI start // SPI mode 0, 8MHz
#ifdef USE_DIG8_INTR
#define SPI0_Init() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
DDRB &= ~(SPI0_MISO_BIT|ZG2100_INTR);\
PORTB = SPI0_SS_BIT;\
SPCR = 0x50;\
SPSR = 0x01
#else
#define SPI0_Init() DDRB |= SPI0_SS_BIT|SPI0_SCLK_BIT|SPI0_MOSI_BIT|LEDConn_BIT;\
DDRB &= ~SPI0_MISO_BIT;\
PORTB = SPI0_SS_BIT;\
SPCR = 0x50;\
SPSR = 0x01
#endif

//ZG2100 SPI HAL
#define ZG2100_SpiInit SPI0_Init
Expand Down

0 comments on commit 2fa2255

Please sign in to comment.