mirror of https://github.com/noisymime/Arduino.git
WiFi library to the new format
This commit is contained in:
parent
e7ef38e27c
commit
fd7e9c6d90
|
@ -1,163 +0,0 @@
|
|||
/*
|
||||
Wifi Twitter Client with Strings
|
||||
|
||||
This sketch connects to Twitter using using an Arduino WiFi shield.
|
||||
It parses the XML returned, and looks for <text>this is a tweet</text>
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 23 apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS; // status of the wifi connection
|
||||
|
||||
// initialize the library instance:
|
||||
WiFiClient client;
|
||||
|
||||
const unsigned long requestInterval = 30*1000; // delay between requests; 30 seconds
|
||||
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(199,59,149,200); // numeric IP for api.twitter.com
|
||||
char server[] = "api.twitter.com"; // name address for twitter API
|
||||
|
||||
boolean requested; // whether you've made a request since connecting
|
||||
unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
|
||||
|
||||
String currentLine = ""; // string to hold the text from server
|
||||
String tweet = ""; // string to hold the tweet
|
||||
boolean readingTweet = false; // if you're currently reading the tweet
|
||||
|
||||
void setup() {
|
||||
// reserve space for the strings:
|
||||
currentLine.reserve(256);
|
||||
tweet.reserve(150);
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (client.connected()) {
|
||||
if (client.available()) {
|
||||
// read incoming bytes:
|
||||
char inChar = client.read();
|
||||
|
||||
// add incoming byte to end of line:
|
||||
currentLine += inChar;
|
||||
|
||||
// if you get a newline, clear the line:
|
||||
if (inChar == '\n') {
|
||||
currentLine = "";
|
||||
}
|
||||
// if the current line ends with <text>, it will
|
||||
// be followed by the tweet:
|
||||
if ( currentLine.endsWith("<text>")) {
|
||||
// tweet is beginning. Clear the tweet string:
|
||||
readingTweet = true;
|
||||
tweet = "";
|
||||
// break out of the loop so this character isn't added to the tweet:
|
||||
return;
|
||||
}
|
||||
// if you're currently reading the bytes of a tweet,
|
||||
// add them to the tweet String:
|
||||
if (readingTweet) {
|
||||
if (inChar != '<') {
|
||||
tweet += inChar;
|
||||
}
|
||||
else {
|
||||
// if you got a "<" character,
|
||||
// you've reached the end of the tweet:
|
||||
readingTweet = false;
|
||||
Serial.println(tweet);
|
||||
// close the connection to the server:
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (millis() - lastAttemptTime > requestInterval) {
|
||||
// if you're not connected, and two minutes have passed since
|
||||
// your last connection, then attempt to connect again:
|
||||
connectToServer();
|
||||
}
|
||||
}
|
||||
|
||||
void connectToServer() {
|
||||
// attempt to connect, and wait a millisecond:
|
||||
Serial.println("connecting to server...");
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("making HTTP request...");
|
||||
// make HTTP GET request to twitter:
|
||||
client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino HTTP/1.1");
|
||||
client.println("Host: api.twitter.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
// note the time of this connect attempt:
|
||||
lastAttemptTime = millis();
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,20 +0,0 @@
|
|||
/*
|
||||
*
|
||||
@file socket.c
|
||||
@brief define function of socket API
|
||||
*
|
||||
*/
|
||||
#include <inttypes.h>
|
||||
#include "socket.h"
|
||||
|
||||
SOCKET socket(uint8 protocol) {return 0;} // Opens a socket(TCP or UDP or IP_RAW mode)
|
||||
void close(SOCKET s) {} // Close socket
|
||||
uint8 connect(SOCKET s, uint8 * addr, uint16 port) {return 0;} // Establish TCP connection (Active connection)
|
||||
void disconnect(SOCKET s) {} // disconnect the connection
|
||||
uint8 listen(SOCKET s) { return 0;} // Establish TCP connection (Passive connection)
|
||||
uint16 send(SOCKET s, const uint8 * buf, uint16 len) { return 0;} // Send data (TCP)
|
||||
uint16 recv(SOCKET s, uint8 * buf, uint16 len) {return 0;} // Receive data (TCP)
|
||||
uint16 sendto(SOCKET s, const uint8 * buf, uint16 len, uint8 * addr, uint16 port) {return 0;} // Send data (UDP/IP RAW)
|
||||
uint16 recvfrom(SOCKET s, uint8 * buf, uint16 len, uint8 * addr, uint16 *port) {return 0;} // Receive data (UDP/IP RAW)
|
||||
|
||||
uint16 igmpsend(SOCKET s, const uint8 * buf, uint16 len) {return 0;}
|
|
@ -1,199 +0,0 @@
|
|||
#include "wifi_drv.h"
|
||||
#include "WiFi.h"
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "debug.h"
|
||||
}
|
||||
|
||||
// XXX: don't make assumptions about the value of MAX_SOCK_NUM.
|
||||
int16_t WiFiClass::_state[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
|
||||
uint16_t WiFiClass::_server_port[MAX_SOCK_NUM] = { 0, 0, 0, 0 };
|
||||
|
||||
WiFiClass::WiFiClass()
|
||||
{
|
||||
// Driver initialization
|
||||
init();
|
||||
}
|
||||
|
||||
void WiFiClass::init()
|
||||
{
|
||||
WiFiDrv::wifiDriverInit();
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::getSocket()
|
||||
{
|
||||
for (uint8_t i = 0; i < MAX_SOCK_NUM; ++i)
|
||||
{
|
||||
if (WiFiClass::_server_port[i] == 0)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return NO_SOCKET_AVAIL;
|
||||
}
|
||||
|
||||
char* WiFiClass::firmwareVersion()
|
||||
{
|
||||
return WiFiDrv::getFwVersion();
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
if (WiFiDrv::wifiSetNetwork(ssid, strlen(ssid)) != WL_FAILURE)
|
||||
{
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
|
||||
}else
|
||||
{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid, uint8_t key_idx, const char *key)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
// set encryption key
|
||||
if (WiFiDrv::wifiSetKey(ssid, strlen(ssid), key_idx, key, strlen(key)) != WL_FAILURE)
|
||||
{
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
|
||||
}else{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::begin(char* ssid, const char *passphrase)
|
||||
{
|
||||
uint8_t status = WL_IDLE_STATUS;
|
||||
uint8_t attempts = WL_MAX_ATTEMPT_CONNECTION;
|
||||
|
||||
// set passphrase
|
||||
if (WiFiDrv::wifiSetPassphrase(ssid, strlen(ssid), passphrase, strlen(passphrase))!= WL_FAILURE)
|
||||
{
|
||||
do
|
||||
{
|
||||
delay(WL_DELAY_START_CONNECTION);
|
||||
status = WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
while ((( status == WL_IDLE_STATUS)||(status == WL_SCAN_COMPLETED))&&(--attempts>0));
|
||||
}else{
|
||||
status = WL_CONNECT_FAILED;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
|
||||
int WiFiClass::disconnect()
|
||||
{
|
||||
return WiFiDrv::disconnect();
|
||||
}
|
||||
|
||||
uint8_t* WiFiClass::macAddress(uint8_t* mac)
|
||||
{
|
||||
uint8_t* _mac = WiFiDrv::getMacAddress();
|
||||
memcpy(mac, _mac, WL_MAC_ADDR_LENGTH);
|
||||
return mac;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::localIP()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getIpAddress(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::subnetMask()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getSubnetMask(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
IPAddress WiFiClass::gatewayIP()
|
||||
{
|
||||
IPAddress ret;
|
||||
WiFiDrv::getGatewayIP(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
char* WiFiClass::SSID()
|
||||
{
|
||||
return WiFiDrv::getCurrentSSID();
|
||||
}
|
||||
|
||||
uint8_t* WiFiClass::BSSID(uint8_t* bssid)
|
||||
{
|
||||
uint8_t* _bssid = WiFiDrv::getCurrentBSSID();
|
||||
memcpy(bssid, _bssid, WL_MAC_ADDR_LENGTH);
|
||||
return bssid;
|
||||
}
|
||||
|
||||
int32_t WiFiClass::RSSI()
|
||||
{
|
||||
return WiFiDrv::getCurrentRSSI();
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::encryptionType()
|
||||
{
|
||||
return WiFiDrv::getCurrentEncryptionType();
|
||||
}
|
||||
|
||||
|
||||
int8_t WiFiClass::scanNetworks()
|
||||
{
|
||||
uint8_t attempts = 10;
|
||||
uint8_t numOfNetworks = 0;
|
||||
|
||||
if (WiFiDrv::startScanNetworks() == WL_FAILURE)
|
||||
return WL_FAILURE;
|
||||
do
|
||||
{
|
||||
delay(2000);
|
||||
numOfNetworks = WiFiDrv::getScanNetworks();
|
||||
}
|
||||
while (( numOfNetworks == 0)&&(--attempts>0));
|
||||
return numOfNetworks;
|
||||
}
|
||||
|
||||
char* WiFiClass::SSID(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getSSIDNetoworks(networkItem);
|
||||
}
|
||||
|
||||
int32_t WiFiClass::RSSI(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getRSSINetoworks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::encryptionType(uint8_t networkItem)
|
||||
{
|
||||
return WiFiDrv::getEncTypeNetowrks(networkItem);
|
||||
}
|
||||
|
||||
uint8_t WiFiClass::status()
|
||||
{
|
||||
return WiFiDrv::getConnectionStatus();
|
||||
}
|
||||
|
||||
int WiFiClass::hostByName(const char* aHostname, IPAddress& aResult)
|
||||
{
|
||||
return WiFiDrv::getHostByName(aHostname, aResult);
|
||||
}
|
||||
|
||||
WiFiClass WiFi;
|
|
@ -1,183 +0,0 @@
|
|||
#ifndef WiFi_h
|
||||
#define WiFi_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
}
|
||||
|
||||
#include "IPAddress.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
|
||||
class WiFiClass
|
||||
{
|
||||
private:
|
||||
|
||||
static void init();
|
||||
public:
|
||||
static int16_t _state[MAX_SOCK_NUM];
|
||||
static uint16_t _server_port[MAX_SOCK_NUM];
|
||||
|
||||
WiFiClass();
|
||||
|
||||
/*
|
||||
* Get the first socket available
|
||||
*/
|
||||
static uint8_t getSocket();
|
||||
|
||||
/*
|
||||
* Get firmware version
|
||||
*/
|
||||
static char* firmwareVersion();
|
||||
|
||||
|
||||
/* Start Wifi connection for OPEN networks
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
*/
|
||||
int begin(char* ssid);
|
||||
|
||||
/* Start Wifi connection with WEP encryption.
|
||||
* Configure a key into the device. The key type (WEP-40, WEP-104)
|
||||
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param key_idx: The key index to set. Valid values are 0-3.
|
||||
* param key: Key input buffer.
|
||||
*/
|
||||
int begin(char* ssid, uint8_t key_idx, const char* key);
|
||||
|
||||
/* Start Wifi connection with passphrase
|
||||
* the most secure supported mode will be automatically selected
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param passphrase: Passphrase. Valid characters in a passphrase
|
||||
* must be between ASCII 32-126 (decimal).
|
||||
*/
|
||||
int begin(char* ssid, const char *passphrase);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: one value of wl_status_t enum
|
||||
*/
|
||||
int disconnect(void);
|
||||
|
||||
/*
|
||||
* Get the interface MAC address.
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
uint8_t* macAddress(uint8_t* mac);
|
||||
|
||||
/*
|
||||
* Get the interface IP address.
|
||||
*
|
||||
* return: Ip address value
|
||||
*/
|
||||
IPAddress localIP();
|
||||
|
||||
/*
|
||||
* Get the interface subnet mask address.
|
||||
*
|
||||
* return: subnet mask address value
|
||||
*/
|
||||
IPAddress subnetMask();
|
||||
|
||||
/*
|
||||
* Get the gateway ip address.
|
||||
*
|
||||
* return: gateway ip address value
|
||||
*/
|
||||
IPAddress gatewayIP();
|
||||
|
||||
/*
|
||||
* Return the current SSID associated with the network
|
||||
*
|
||||
* return: ssid string
|
||||
*/
|
||||
char* SSID();
|
||||
|
||||
/*
|
||||
* Return the current BSSID associated with the network.
|
||||
* It is the MAC address of the Access Point
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
uint8_t* BSSID(uint8_t* bssid);
|
||||
|
||||
/*
|
||||
* Return the current RSSI /Received Signal Strength in dBm)
|
||||
* associated with the network
|
||||
*
|
||||
* return: signed value
|
||||
*/
|
||||
int32_t RSSI();
|
||||
|
||||
/*
|
||||
* Return the Encryption Type associated with the network
|
||||
*
|
||||
* return: one value of wl_enc_type enum
|
||||
*/
|
||||
uint8_t encryptionType();
|
||||
|
||||
/*
|
||||
* Start scan WiFi networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
int8_t scanNetworks();
|
||||
|
||||
/*
|
||||
* Return the SSID discovered during the network scan.
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: ssid string of the specified item on the networks scanned list
|
||||
*/
|
||||
char* SSID(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the encryption type of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
||||
*/
|
||||
uint8_t encryptionType(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the RSSI of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: signed value of RSSI of the specified item on the networks scanned list
|
||||
*/
|
||||
int32_t RSSI(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return Connection status.
|
||||
*
|
||||
* return: one of the value defined in wl_status_t
|
||||
*/
|
||||
uint8_t status();
|
||||
|
||||
/*
|
||||
* Resolve the given hostname to an IP address.
|
||||
* param aHostname: Name to be resolved
|
||||
* param aResult: IPAddress structure to store the returned IP address
|
||||
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||
* else error code
|
||||
*/
|
||||
int hostByName(const char* aHostname, IPAddress& aResult);
|
||||
|
||||
friend class WiFiClient;
|
||||
friend class WiFiServer;
|
||||
};
|
||||
|
||||
extern WiFiClass WiFi;
|
||||
|
||||
#endif
|
|
@ -1,40 +0,0 @@
|
|||
#ifndef wificlient_h
|
||||
#define wificlient_h
|
||||
#include "Arduino.h"
|
||||
#include "Print.h"
|
||||
#include "Client.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
class WiFiClient : public Client {
|
||||
|
||||
public:
|
||||
WiFiClient();
|
||||
WiFiClient(uint8_t sock);
|
||||
|
||||
uint8_t status();
|
||||
virtual int connect(IPAddress ip, uint16_t port);
|
||||
virtual int connect(const char *host, uint16_t port);
|
||||
virtual size_t write(uint8_t);
|
||||
virtual size_t write(const uint8_t *buf, size_t size);
|
||||
virtual int available();
|
||||
virtual int read();
|
||||
virtual int read(uint8_t *buf, size_t size);
|
||||
virtual int peek();
|
||||
virtual void flush();
|
||||
virtual void stop();
|
||||
virtual uint8_t connected();
|
||||
virtual operator bool();
|
||||
|
||||
friend class WiFiServer;
|
||||
|
||||
using Print::write;
|
||||
|
||||
private:
|
||||
static uint16_t _srcport;
|
||||
uint8_t _sock; //not used
|
||||
uint16_t _socket;
|
||||
|
||||
uint8_t getFirstSocket();
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,88 +0,0 @@
|
|||
#include <string.h>
|
||||
#include "server_drv.h"
|
||||
|
||||
extern "C" {
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
|
||||
WiFiServer::WiFiServer(uint16_t port)
|
||||
{
|
||||
_port = port;
|
||||
}
|
||||
|
||||
void WiFiServer::begin()
|
||||
{
|
||||
uint8_t _sock = WiFiClass::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startServer(_port, _sock);
|
||||
WiFiClass::_server_port[_sock] = _port;
|
||||
}
|
||||
}
|
||||
|
||||
WiFiClient WiFiServer::available(byte* status)
|
||||
{
|
||||
static int cycle_server_down = 0;
|
||||
const int TH_SERVER_DOWN = 50;
|
||||
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
||||
{
|
||||
if (WiFiClass::_server_port[sock] == _port)
|
||||
{
|
||||
WiFiClient client(sock);
|
||||
uint8_t _status = client.status();
|
||||
uint8_t _ser_status = this->status();
|
||||
|
||||
if (status != NULL)
|
||||
*status = _status;
|
||||
|
||||
//server not in listen state, restart it
|
||||
if ((_ser_status == 0)&&(cycle_server_down++ > TH_SERVER_DOWN))
|
||||
{
|
||||
ServerDrv::startServer(_port, sock);
|
||||
cycle_server_down = 0;
|
||||
}
|
||||
|
||||
if (_status == ESTABLISHED)
|
||||
{
|
||||
return client; //TODO
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return WiFiClient(255);
|
||||
}
|
||||
|
||||
uint8_t WiFiServer::status() {
|
||||
return ServerDrv::getServerState(0);
|
||||
}
|
||||
|
||||
|
||||
size_t WiFiServer::write(uint8_t b)
|
||||
{
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiServer::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for (int sock = 0; sock < MAX_SOCK_NUM; sock++)
|
||||
{
|
||||
if (WiFiClass::_server_port[sock] != 0)
|
||||
{
|
||||
WiFiClient client(sock);
|
||||
|
||||
if (WiFiClass::_server_port[sock] == _port &&
|
||||
client.status() == ESTABLISHED)
|
||||
{
|
||||
n+=client.write(buffer, size);
|
||||
}
|
||||
}
|
||||
}
|
||||
return n;
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
#ifndef wifiserver_h
|
||||
#define wifiserver_h
|
||||
|
||||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
}
|
||||
|
||||
#include "Server.h"
|
||||
|
||||
class WiFiClient;
|
||||
|
||||
class WiFiServer : public Server {
|
||||
private:
|
||||
uint16_t _port;
|
||||
void* pcb;
|
||||
public:
|
||||
WiFiServer(uint16_t);
|
||||
WiFiClient available(uint8_t* status = NULL);
|
||||
void begin();
|
||||
virtual size_t write(uint8_t);
|
||||
virtual size_t write(const uint8_t *buf, size_t size);
|
||||
uint8_t status();
|
||||
|
||||
using Print::write;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,123 +0,0 @@
|
|||
/*
|
||||
|
||||
This example connects to an unencrypted Wifi network.
|
||||
Then it prints the MAC address of the Wifi shield,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // the name of your network
|
||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to open SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
|
||||
// print your subnet mask:
|
||||
IPAddress subnet = WiFi.subnetMask();
|
||||
Serial.print("NetMask: ");
|
||||
Serial.println(subnet);
|
||||
|
||||
// print your gateway address:
|
||||
IPAddress gateway = WiFi.gatewayIP();
|
||||
Serial.print("Gateway: ");
|
||||
Serial.println(gateway);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
}
|
||||
|
|
@ -1,128 +0,0 @@
|
|||
/*
|
||||
|
||||
This example connects to a WEP-encrypted Wifi network.
|
||||
Then it prints the MAC address of the Wifi shield,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
If you use 40-bit WEP, you need a key that is 10 characters long,
|
||||
and the characters must be hexadecimal (0-9 or A-F).
|
||||
e.g. for 40-bit, ABBADEAF01 will work, but ABBADEAF won't work
|
||||
(too short) and ABBAISDEAF won't work (I and S are not
|
||||
hexadecimal characters).
|
||||
|
||||
For 128-bit, you need a string that is 26 characters long.
|
||||
D0D0DEADF00DABBADEAFBEADED will work because it's 26 characters,
|
||||
all in the 0-9, A-F range.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char key[] = "D0D0DEADF00DABBADEAFBEADED"; // your network key
|
||||
int keyIndex = 0; // your network key Index number
|
||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WEP network, SSID: ");
|
||||
Serial.println(ssid);
|
||||
status = WiFi.begin(ssid, keyIndex, key);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// once you are connected :
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
|
||||
This example connects to an unencrypted Wifi network.
|
||||
Then it prints the MAC address of the Wifi shield,
|
||||
the IP address obtained, and other network details.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
int status = WL_IDLE_STATUS; // the Wifi radio's status
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to WPA SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
|
||||
// you're connected now, so print out the data:
|
||||
Serial.print("You're connected to the network");
|
||||
printCurrentNet();
|
||||
printWifiData();
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// check the network connection once every 10 seconds:
|
||||
delay(10000);
|
||||
printCurrentNet();
|
||||
}
|
||||
|
||||
void printWifiData() {
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
Serial.println(ip);
|
||||
|
||||
// print your MAC address:
|
||||
byte mac[6];
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC address: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
|
||||
}
|
||||
|
||||
void printCurrentNet() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print the MAC address of the router you're attached to:
|
||||
byte bssid[6];
|
||||
WiFi.BSSID(bssid);
|
||||
Serial.print("BSSID: ");
|
||||
Serial.print(bssid[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(bssid[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(bssid[0],HEX);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.println(rssi);
|
||||
|
||||
// print the encryption type:
|
||||
byte encryption = WiFi.encryptionType();
|
||||
Serial.print("Encryption Type:");
|
||||
Serial.println(encryption,HEX);
|
||||
Serial.println();
|
||||
}
|
||||
|
|
@ -1,118 +0,0 @@
|
|||
/*
|
||||
|
||||
This example prints the Wifi shield's MAC address, and
|
||||
scans for available Wifi networks using the Wifi shield.
|
||||
Every ten seconds, it scans again. It doesn't actually
|
||||
connect to any network, so no encryption scheme is specified.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 21 Junn 2012
|
||||
by Tom Igoe and Jaymes Dec
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// Print WiFi MAC address:
|
||||
printMacAddress();
|
||||
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
listNetworks();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
delay(10000);
|
||||
// scan for existing networks:
|
||||
Serial.println("Scanning available networks...");
|
||||
listNetworks();
|
||||
}
|
||||
|
||||
void printMacAddress() {
|
||||
// the MAC address of your Wifi shield
|
||||
byte mac[6];
|
||||
|
||||
// print your MAC address:
|
||||
WiFi.macAddress(mac);
|
||||
Serial.print("MAC: ");
|
||||
Serial.print(mac[5],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[4],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[3],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[2],HEX);
|
||||
Serial.print(":");
|
||||
Serial.print(mac[1],HEX);
|
||||
Serial.print(":");
|
||||
Serial.println(mac[0],HEX);
|
||||
}
|
||||
|
||||
void listNetworks() {
|
||||
// scan for nearby networks:
|
||||
Serial.println("** Scan Networks **");
|
||||
int numSsid = WiFi.scanNetworks();
|
||||
if (numSsid == -1)
|
||||
{
|
||||
Serial.println("Couldn't get a wifi connection");
|
||||
while(true);
|
||||
}
|
||||
|
||||
// print the list of networks seen:
|
||||
Serial.print("number of available networks:");
|
||||
Serial.println(numSsid);
|
||||
|
||||
// print the network number and name for each network found:
|
||||
for (int thisNet = 0; thisNet<numSsid; thisNet++) {
|
||||
Serial.print(thisNet);
|
||||
Serial.print(") ");
|
||||
Serial.print(WiFi.SSID(thisNet));
|
||||
Serial.print("\tSignal: ");
|
||||
Serial.print(WiFi.RSSI(thisNet));
|
||||
Serial.print(" dBm");
|
||||
Serial.print("\tEncryption: ");
|
||||
printEncryptionType(WiFi.encryptionType(thisNet));
|
||||
}
|
||||
}
|
||||
|
||||
void printEncryptionType(int thisType) {
|
||||
// read the encryption type and print out the name:
|
||||
switch (thisType) {
|
||||
case ENC_TYPE_WEP:
|
||||
Serial.println("WEP");
|
||||
break;
|
||||
case ENC_TYPE_TKIP:
|
||||
Serial.println("WPA");
|
||||
break;
|
||||
case ENC_TYPE_CCMP:
|
||||
Serial.println("WPA2");
|
||||
break;
|
||||
case ENC_TYPE_NONE:
|
||||
Serial.println("None");
|
||||
break;
|
||||
case ENC_TYPE_AUTO:
|
||||
Serial.println("Auto");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,130 +0,0 @@
|
|||
/*
|
||||
WiFi Web Server LED Blink
|
||||
|
||||
A simple web server that lets you blink an LED via the web.
|
||||
This sketch will print the IP address of your WiFi Shield (once connected)
|
||||
to the Serial monitor. From there, you can open that address in a web browser
|
||||
to turn on and off the LED on pin 9.
|
||||
|
||||
If the IP address of your shield is yourAddress:
|
||||
http://yourAddress/H turns the LED on
|
||||
http://yourAddress/L turns it off
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
* LED attached to pin 9
|
||||
|
||||
created 25 Nov 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(9600); // initialize serial communication
|
||||
pinMode(9, OUTPUT); // set the LED pin mode
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
while(true); // don't continue
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to Network named: ");
|
||||
Serial.println(ssid); // print the network name (SSID);
|
||||
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
server.begin(); // start the web server on port 80
|
||||
printWifiStatus(); // you're connected now, so print out the status
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
WiFiClient client = server.available(); // listen for incoming clients
|
||||
|
||||
if (client) { // if you get a client,
|
||||
Serial.println("new client"); // print a message out the serial port
|
||||
String currentLine = ""; // make a String to hold incoming data from the client
|
||||
while (client.connected()) { // loop while the client's connected
|
||||
if (client.available()) { // if there's bytes to read from the client,
|
||||
char c = client.read(); // read a byte, then
|
||||
Serial.write(c); // print it out the serial monitor
|
||||
if (c == '\n') { // if the byte is a newline character
|
||||
|
||||
// if the current line is blank, you got two newline characters in a row.
|
||||
// that's the end of the client HTTP request, so send a response:
|
||||
if (currentLine.length() == 0) {
|
||||
// HTTP headers always start with a response code (e.g. HTTP/1.1 200 OK)
|
||||
// and a content-type so the client knows what's coming, then a blank line:
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-type:text/html");
|
||||
client.println();
|
||||
|
||||
// the content of the HTTP response follows the header:
|
||||
client.print("Click <a href=\"/H\">here</a> turn the LED on pin 9 on<br>");
|
||||
client.print("Click <a href=\"/L\">here</a> turn the LED on pin 9 off<br>");
|
||||
|
||||
// The HTTP response ends with another blank line:
|
||||
client.println();
|
||||
// break out of the while loop:
|
||||
break;
|
||||
}
|
||||
else { // if you got a newline, then clear currentLine:
|
||||
currentLine = "";
|
||||
}
|
||||
}
|
||||
else if (c != '\r') { // if you got anything else but a carriage return character,
|
||||
currentLine += c; // add it to the end of the currentLine
|
||||
}
|
||||
|
||||
// Check to see if the client request was "GET /H" or "GET /L":
|
||||
if (currentLine.endsWith("GET /H")) {
|
||||
digitalWrite(9, HIGH); // GET /H turns the LED on
|
||||
}
|
||||
if (currentLine.endsWith("GET /L")) {
|
||||
digitalWrite(9, LOW); // GET /L turns the LED off
|
||||
}
|
||||
}
|
||||
}
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disonnected");
|
||||
}
|
||||
}
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
// print where to go in a browser:
|
||||
Serial.print("To see this page in action, open a browser to http://");
|
||||
Serial.println(ip);
|
||||
}
|
|
@ -1,111 +0,0 @@
|
|||
/*
|
||||
Chat Server
|
||||
|
||||
A simple server that distributes any incoming messages to all
|
||||
connected clients. To use telnet to your device's IP address and type.
|
||||
You can see the client's input in the serial monitor as well.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 18 Dec 2009
|
||||
by David A. Mellis
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
|
||||
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
WiFiServer server(23);
|
||||
|
||||
boolean alreadyConnected = false; // whether or not the client was connected previously
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// start the server:
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// wait for a new client:
|
||||
WiFiClient client = server.available();
|
||||
|
||||
|
||||
// when the client sends the first byte, say hello:
|
||||
if (client) {
|
||||
if (!alreadyConnected) {
|
||||
// clead out the input buffer:
|
||||
client.flush();
|
||||
Serial.println("We have a new client");
|
||||
client.println("Hello, client!");
|
||||
alreadyConnected = true;
|
||||
}
|
||||
|
||||
if (client.available() > 0) {
|
||||
// read the bytes incoming from the client:
|
||||
char thisChar = client.read();
|
||||
// echo the bytes back to the client:
|
||||
server.write(thisChar);
|
||||
// echo the bytes to the server as well:
|
||||
Serial.write(thisChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
|
@ -1,191 +0,0 @@
|
|||
/*
|
||||
Wifi Pachube sensor client
|
||||
|
||||
This sketch connects an analog sensor to Pachube (http://www.pachube.com)
|
||||
using an Arduino Wifi shield.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
This example has been updated to use version 2.0 of the Pachube API.
|
||||
To make it work, create a feed with a datastream, and give it the ID
|
||||
sensor1. Or change the code below to match your feed.
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 13 Mar 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 8 Sept 2012
|
||||
by Scott Fitzgerald
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
|
||||
#define FEEDID 00000 // replace your feed ID
|
||||
#define USERAGENT "My Arduino Project" // user agent is the project name
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
// initialize the library instance:
|
||||
WiFiClient client;
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
IPAddress server(216,52,233,121); // numeric IP for api.pachube.com
|
||||
//char server[] = "api.pachube.com"; // name address for pachube API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// if there's no net connection, but there was one last time
|
||||
// through the loop, then stop the client:
|
||||
if (!client.connected() && lastConnected) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(sensorReading);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
// the loop:
|
||||
lastConnected = client.connected();
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void sendData(int thisData) {
|
||||
// if there's a successful connection:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connecting...");
|
||||
// send the HTTP PUT request:
|
||||
client.print("PUT /v2/feeds/");
|
||||
client.print(FEEDID);
|
||||
client.println(".csv HTTP/1.1");
|
||||
client.println("Host: api.pachube.com");
|
||||
client.print("X-ApiKey: ");
|
||||
client.println(APIKEY);
|
||||
client.print("User-Agent: ");
|
||||
client.println(USERAGENT);
|
||||
client.print("Content-Length: ");
|
||||
|
||||
// calculate the length of the sensor reading in bytes:
|
||||
// 8 bytes for "sensor1," + number of digits of the data:
|
||||
int thisLength = 8 + getLength(thisData);
|
||||
client.println(thisLength);
|
||||
|
||||
// last pieces of the HTTP PUT request:
|
||||
client.println("Content-Type: text/csv");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
// here's the actual content of the PUT request:
|
||||
client.print("sensor1,");
|
||||
client.println(thisData);
|
||||
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
// note the time that the connection was made or attempted:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
|
||||
|
||||
// This method calculates the number of digits in the
|
||||
// sensor reading. Since each digit of the ASCII decimal
|
||||
// representation is a byte, the number of digits equals
|
||||
// the number of bytes:
|
||||
|
||||
int getLength(int someValue) {
|
||||
// there's at least one byte:
|
||||
int digits = 1;
|
||||
// continually divide the value by ten,
|
||||
// adding one to the digit count for each
|
||||
// time you divide, until you're at 0:
|
||||
int dividend = someValue /10;
|
||||
while (dividend > 0) {
|
||||
dividend = dividend /10;
|
||||
digits++;
|
||||
}
|
||||
// return the number of digits:
|
||||
return digits;
|
||||
}
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -1,177 +0,0 @@
|
|||
/*
|
||||
Wifi Pachube sensor client with Strings
|
||||
|
||||
This sketch connects an analog sensor to Pachube (http://www.pachube.com)
|
||||
using a Arduino Wifi shield.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
This example has been updated to use version 2.0 of the pachube.com API.
|
||||
To make it work, create a feed with a datastream, and give it the ID
|
||||
sensor1. Or change the code below to match your feed.
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* Analog sensor attached to analog in 0
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 16 Mar 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
modified 8 Sept 2012
|
||||
by Scott Fitzgerald
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
#define APIKEY "YOUR API KEY GOES HERE" // replace your pachube api key here
|
||||
#define FEEDID 00000 // replace your feed ID
|
||||
#define USERAGENT "My Arduino Project" // user agent is the project name
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
// initialize the library instance:
|
||||
WiFiClient client;
|
||||
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(216,52,233,121); // numeric IP for api.pachube.com
|
||||
char server[] = "api.pachube.com"; // name address for pachube API
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; //delay between updates to pachube.com
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// read the analog sensor:
|
||||
int sensorReading = analogRead(A0);
|
||||
// convert the data to a String to send it:
|
||||
|
||||
String dataString = "sensor1,";
|
||||
dataString += sensorReading;
|
||||
|
||||
// you can append multiple readings to this String if your
|
||||
// pachube feed is set up to handle multiple values:
|
||||
int otherSensorReading = analogRead(A1);
|
||||
dataString += "\nsensor2,";
|
||||
dataString += otherSensorReading;
|
||||
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.print(c);
|
||||
}
|
||||
|
||||
// if there's no net connection, but there was one last time
|
||||
// through the loop, then stop the client:
|
||||
if (!client.connected() && lastConnected) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
sendData(dataString);
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
// the loop:
|
||||
lastConnected = client.connected();
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void sendData(String thisData) {
|
||||
// if there's a successful connection:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connecting...");
|
||||
// send the HTTP PUT request:
|
||||
client.print("PUT /v2/feeds/");
|
||||
client.print(FEEDID);
|
||||
client.println(".csv HTTP/1.1");
|
||||
client.println("Host: api.pachube.com");
|
||||
client.print("X-ApiKey: ");
|
||||
client.println(APIKEY);
|
||||
client.print("User-Agent: ");
|
||||
client.println(USERAGENT);
|
||||
client.print("Content-Length: ");
|
||||
client.println(thisData.length());
|
||||
|
||||
// last pieces of the HTTP PUT request:
|
||||
client.println("Content-Type: text/csv");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
// here's the actual content of the PUT request:
|
||||
client.println(thisData);
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
// note the time that the connection was made or attempted:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
|
@ -1,164 +0,0 @@
|
|||
/*
|
||||
Wifi Twitter Client with Strings
|
||||
|
||||
This sketch connects to Twitter using using an Arduino WiFi shield.
|
||||
It parses the XML returned, and looks for <text>this is a tweet</text>
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
This example uses the String library, which is part of the Arduino core from
|
||||
version 0019.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 23 apr 2012
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
This code is in the public domain.
|
||||
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "password"; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS; // status of the wifi connection
|
||||
|
||||
// initialize the library instance:
|
||||
WiFiClient client;
|
||||
|
||||
const unsigned long requestInterval = 30*1000; // delay between requests; 30 seconds
|
||||
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
//IPAddress server(199,59,149,200); // numeric IP for api.twitter.com
|
||||
char server[] = "api.twitter.com"; // name address for twitter API
|
||||
|
||||
boolean requested; // whether you've made a request since connecting
|
||||
unsigned long lastAttemptTime = 0; // last time you connected to the server, in milliseconds
|
||||
|
||||
String currentLine = ""; // string to hold the text from server
|
||||
String tweet = ""; // string to hold the tweet
|
||||
boolean readingTweet = false; // if you're currently reading the tweet
|
||||
|
||||
void setup() {
|
||||
// reserve space for the strings:
|
||||
currentLine.reserve(256);
|
||||
tweet.reserve(150);
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
connectToServer();
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (client.connected()) {
|
||||
if (client.available()) {
|
||||
// read incoming bytes:
|
||||
char inChar = client.read();
|
||||
|
||||
// add incoming byte to end of line:
|
||||
currentLine += inChar;
|
||||
|
||||
// if you get a newline, clear the line:
|
||||
if (inChar == '\n') {
|
||||
currentLine = "";
|
||||
}
|
||||
// if the current line ends with <text>, it will
|
||||
// be followed by the tweet:
|
||||
if ( currentLine.endsWith("<text>")) {
|
||||
// tweet is beginning. Clear the tweet string:
|
||||
readingTweet = true;
|
||||
tweet = "";
|
||||
// break out of the loop so this character isn't added to the tweet:
|
||||
return;
|
||||
}
|
||||
// if you're currently reading the bytes of a tweet,
|
||||
// add them to the tweet String:
|
||||
if (readingTweet) {
|
||||
if (inChar != '<') {
|
||||
tweet += inChar;
|
||||
}
|
||||
else {
|
||||
// if you got a "<" character,
|
||||
// you've reached the end of the tweet:
|
||||
readingTweet = false;
|
||||
Serial.println(tweet);
|
||||
// close the connection to the server:
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (millis() - lastAttemptTime > requestInterval) {
|
||||
// if you're not connected, and two minutes have passed since
|
||||
// your last connection, then attempt to connect again:
|
||||
connectToServer();
|
||||
}
|
||||
}
|
||||
|
||||
void connectToServer() {
|
||||
// attempt to connect, and wait a millisecond:
|
||||
Serial.println("connecting to server...");
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("making HTTP request...");
|
||||
// make HTTP GET request to twitter:
|
||||
client.println("GET /1/statuses/user_timeline.xml?screen_name=arduino HTTP/1.1");
|
||||
client.println("Host:api.twitter.com");
|
||||
client.println("Connection:close");
|
||||
client.println();
|
||||
}
|
||||
// note the time of this connect attempt:
|
||||
lastAttemptTime = millis();
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,120 +0,0 @@
|
|||
|
||||
/*
|
||||
Web client
|
||||
|
||||
This sketch connects to a website (http://www.google.com)
|
||||
using a WiFi shield.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password (use for WPA, or use as key for WEP)
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
// if you don't want to use DNS (and reduce your sketch size)
|
||||
// use the numeric IP instead of the name for the server:
|
||||
IPAddress server(173,194,73,105); // numeric IP for Google (no DNS)
|
||||
//char server[] = "www.google.com"; // name address for Google (using DNS)
|
||||
|
||||
// Initialize the Ethernet client library
|
||||
// with the IP address and port of the server
|
||||
// that you want to connect to (port 80 is default for HTTP):
|
||||
WiFiClient client;
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
Serial.println("Connected to wifi");
|
||||
printWifiStatus();
|
||||
|
||||
Serial.println("\nStarting connection to server...");
|
||||
// if you get a connection, report back via serial:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connected to server");
|
||||
// Make a HTTP request:
|
||||
client.println("GET /search?q=arduino HTTP/1.1");
|
||||
client.println("Host:www.google.com");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there are incoming bytes available
|
||||
// from the server, read them and print them:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if the server's disconnected, stop the client:
|
||||
if (!client.connected()) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting from server.");
|
||||
client.stop();
|
||||
|
||||
// do nothing forevermore:
|
||||
while(true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,138 +0,0 @@
|
|||
/*
|
||||
Repeating Wifi Web client
|
||||
|
||||
This sketch connects to a a web server and makes a request
|
||||
using an Arduino Wifi shield.
|
||||
|
||||
Circuit:
|
||||
* Wifi shield attached to pins 10, 11, 12, 13
|
||||
|
||||
created 23 April 2012
|
||||
modifide 31 May 2012
|
||||
by Tom Igoe
|
||||
|
||||
http://arduino.cc/en/Tutorial/WifiWebClientRepeating
|
||||
This code is in the public domain.
|
||||
*/
|
||||
|
||||
#include <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
// Initialize the Wifi client library
|
||||
WiFiClient client;
|
||||
|
||||
// server address:
|
||||
char server[] = "www.arduino.cc";
|
||||
//IPAddress server(64,131,82,241);
|
||||
|
||||
unsigned long lastConnectionTime = 0; // last time you connected to the server, in milliseconds
|
||||
boolean lastConnected = false; // state of the connection last time through the main loop
|
||||
const unsigned long postingInterval = 10*1000; // delay between updates, in milliseconds
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// if there's incoming data from the net connection.
|
||||
// send it out the serial port. This is for debugging
|
||||
// purposes only:
|
||||
while (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
}
|
||||
|
||||
// if there's no net connection, but there was one last time
|
||||
// through the loop, then stop the client:
|
||||
if (!client.connected() && lastConnected) {
|
||||
Serial.println();
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
|
||||
// if you're not connected, and ten seconds have passed since
|
||||
// your last connection, then connect again and send data:
|
||||
if(!client.connected() && (millis() - lastConnectionTime > postingInterval)) {
|
||||
httpRequest();
|
||||
}
|
||||
// store the state of the connection for next time through
|
||||
// the loop:
|
||||
lastConnected = client.connected();
|
||||
}
|
||||
|
||||
// this method makes a HTTP connection to the server:
|
||||
void httpRequest() {
|
||||
// if there's a successful connection:
|
||||
if (client.connect(server, 80)) {
|
||||
Serial.println("connecting...");
|
||||
// send the HTTP PUT request:
|
||||
client.println("GET /latest.txt HTTP/1.1");
|
||||
client.println("Host: www.arduino.cc");
|
||||
client.println("User-Agent: arduino-ethernet");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
|
||||
// note the time that the connection was made:
|
||||
lastConnectionTime = millis();
|
||||
}
|
||||
else {
|
||||
// if you couldn't make a connection:
|
||||
Serial.println("connection failed");
|
||||
Serial.println("disconnecting.");
|
||||
client.stop();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,132 +0,0 @@
|
|||
/*
|
||||
Web Server
|
||||
|
||||
A simple web server that shows the value of the analog input pins.
|
||||
using a WiFi shield.
|
||||
|
||||
This example is written for a network using WPA encryption. For
|
||||
WEP or WPA, change the Wifi.begin() call accordingly.
|
||||
|
||||
Circuit:
|
||||
* WiFi shield attached
|
||||
* Analog inputs attached to pins A0 through A5 (optional)
|
||||
|
||||
created 13 July 2010
|
||||
by dlf (Metodo2 srl)
|
||||
modified 31 May 2012
|
||||
by Tom Igoe
|
||||
*/
|
||||
|
||||
#inlcude <SPI.h>
|
||||
#include <WiFi.h>
|
||||
|
||||
char ssid[] = "yourNetwork"; // your network SSID (name)
|
||||
char pass[] = "secretPassword"; // your network password
|
||||
int keyIndex = 0; // your network key Index number (needed only for WEP)
|
||||
|
||||
int status = WL_IDLE_STATUS;
|
||||
|
||||
WiFiServer server(80);
|
||||
|
||||
void setup() {
|
||||
//Initialize serial and wait for port to open:
|
||||
Serial.begin(9600);
|
||||
while (!Serial) {
|
||||
; // wait for serial port to connect. Needed for Leonardo only
|
||||
}
|
||||
|
||||
// check for the presence of the shield:
|
||||
if (WiFi.status() == WL_NO_SHIELD) {
|
||||
Serial.println("WiFi shield not present");
|
||||
// don't continue:
|
||||
while(true);
|
||||
}
|
||||
|
||||
// attempt to connect to Wifi network:
|
||||
while ( status != WL_CONNECTED) {
|
||||
Serial.print("Attempting to connect to SSID: ");
|
||||
Serial.println(ssid);
|
||||
// Connect to WPA/WPA2 network. Change this line if using open or WEP network:
|
||||
status = WiFi.begin(ssid, pass);
|
||||
|
||||
// wait 10 seconds for connection:
|
||||
delay(10000);
|
||||
}
|
||||
server.begin();
|
||||
// you're connected now, so print out the status:
|
||||
printWifiStatus();
|
||||
}
|
||||
|
||||
|
||||
void loop() {
|
||||
// listen for incoming clients
|
||||
WiFiClient client = server.available();
|
||||
if (client) {
|
||||
Serial.println("new client");
|
||||
// an http request ends with a blank line
|
||||
boolean currentLineIsBlank = true;
|
||||
while (client.connected()) {
|
||||
if (client.available()) {
|
||||
char c = client.read();
|
||||
Serial.write(c);
|
||||
// if you've gotten to the end of the line (received a newline
|
||||
// character) and the line is blank, the http request has ended,
|
||||
// so you can send a reply
|
||||
if (c == '\n' && currentLineIsBlank) {
|
||||
// send a standard http response header
|
||||
client.println("HTTP/1.1 200 OK");
|
||||
client.println("Content-Type: text/html");
|
||||
client.println("Connection: close");
|
||||
client.println();
|
||||
client.println("<!DOCTYPE HTML>");
|
||||
client.println("<html>");
|
||||
// add a meta refresh tag, so the browser pulls again every 5 seconds:
|
||||
client.println("<meta http-equiv=\"refresh\" content=\"5\">");
|
||||
// output the value of each analog input pin
|
||||
for (int analogChannel = 0; analogChannel < 6; analogChannel++) {
|
||||
int sensorReading = analogRead(analogChannel);
|
||||
client.print("analog input ");
|
||||
client.print(analogChannel);
|
||||
client.print(" is ");
|
||||
client.print(sensorReading);
|
||||
client.println("<br />");
|
||||
}
|
||||
client.println("</html>");
|
||||
break;
|
||||
}
|
||||
if (c == '\n') {
|
||||
// you're starting a new line
|
||||
currentLineIsBlank = true;
|
||||
}
|
||||
else if (c != '\r') {
|
||||
// you've gotten a character on the current line
|
||||
currentLineIsBlank = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// give the web browser time to receive the data
|
||||
delay(1);
|
||||
// close the connection:
|
||||
client.stop();
|
||||
Serial.println("client disonnected");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void printWifiStatus() {
|
||||
// print the SSID of the network you're attached to:
|
||||
Serial.print("SSID: ");
|
||||
Serial.println(WiFi.SSID());
|
||||
|
||||
// print your WiFi shield's IP address:
|
||||
IPAddress ip = WiFi.localIP();
|
||||
Serial.print("IP Address: ");
|
||||
Serial.println(ip);
|
||||
|
||||
// print the received signal strength:
|
||||
long rssi = WiFi.RSSI();
|
||||
Serial.print("signal strength (RSSI):");
|
||||
Serial.print(rssi);
|
||||
Serial.println(" dBm");
|
||||
}
|
||||
|
|
@ -1,43 +0,0 @@
|
|||
#######################################
|
||||
# Syntax Coloring Map For WiFi
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
WiFi KEYWORD1
|
||||
Client KEYWORD1
|
||||
Server KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
status KEYWORD2
|
||||
connect KEYWORD2
|
||||
write KEYWORD2
|
||||
available KEYWORD2
|
||||
read KEYWORD2
|
||||
flush KEYWORD2
|
||||
stop KEYWORD2
|
||||
connected KEYWORD2
|
||||
begin KEYWORD2
|
||||
disconnect KEYWORD2
|
||||
macAddress KEYWORD2
|
||||
localIP KEYWORD2
|
||||
subnetMask KEYWORD2
|
||||
gatewayIP KEYWORD2
|
||||
SSID KEYWORD2
|
||||
BSSID KEYWORD2
|
||||
RSSI KEYWORD2
|
||||
encryptionType KEYWORD2
|
||||
getResult KEYWORD2
|
||||
getSocket KEYWORD2
|
||||
WiFiClient KEYWORD2
|
||||
WiFiServer KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
|
@ -1,77 +0,0 @@
|
|||
//*********************************************/
|
||||
//
|
||||
// File: debug.h
|
||||
//
|
||||
// Author: dlf (Metodo2 srl)
|
||||
//
|
||||
//********************************************/
|
||||
|
||||
|
||||
#ifndef Debug_H
|
||||
#define Debug_H
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#define PRINT_FILE_LINE() do { \
|
||||
Serial.print("[");Serial.print(__FILE__); \
|
||||
Serial.print("::");Serial.print(__LINE__);Serial.print("]");\
|
||||
}while (0);
|
||||
|
||||
#ifdef _DEBUG_
|
||||
|
||||
#define INFO(format, args...) do { \
|
||||
char buf[250]; \
|
||||
sprintf(buf, format, args); \
|
||||
Serial.println(buf); \
|
||||
} while(0);
|
||||
|
||||
#define INFO1(x) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.println(x); \
|
||||
}while (0);
|
||||
|
||||
|
||||
#define INFO2(x,y) do { PRINT_FILE_LINE() Serial.print("-I-");\
|
||||
Serial.print(x,16);Serial.print(",");Serial.println(y,16); \
|
||||
}while (0);
|
||||
|
||||
|
||||
#else
|
||||
#define INFO1(x) do {} while(0);
|
||||
#define INFO2(x,y) do {} while(0);
|
||||
#define INFO(format, args...) do {} while(0);
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
#define WARN(args) do { PRINT_FILE_LINE() \
|
||||
Serial.print("-W-"); Serial.println(args); \
|
||||
}while (0);
|
||||
#else
|
||||
#define WARN(args) do {} while (0);
|
||||
#endif
|
||||
|
||||
#if _DEBUG_SPI_
|
||||
#define DBG_PIN2 5
|
||||
#define DBG_PIN 4
|
||||
|
||||
#define START() digitalWrite(DBG_PIN2, HIGH);
|
||||
#define END() digitalWrite(DBG_PIN2, LOW);
|
||||
#define SET_TRIGGER() digitalWrite(DBG_PIN, HIGH);
|
||||
#define RST_TRIGGER() digitalWrite(DBG_PIN, LOW);
|
||||
|
||||
#define INIT_TRIGGER() pinMode(DBG_PIN, OUTPUT); \
|
||||
pinMode(DBG_PIN2, OUTPUT); \
|
||||
RST_TRIGGER()
|
||||
#define TOGGLE_TRIGGER() SET_TRIGGER() \
|
||||
delayMicroseconds(2); \
|
||||
RST_TRIGGER()
|
||||
#else
|
||||
#define START()
|
||||
#define END()
|
||||
#define SET_TRIGGER()
|
||||
#define RST_TRIGGER()
|
||||
#define INIT_TRIGGER()
|
||||
#define TOGGLE_TRIGGER()
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -1,260 +0,0 @@
|
|||
//#define _DEBUG_
|
||||
|
||||
#include "server_drv.h"
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "spi_drv.h"
|
||||
|
||||
extern "C" {
|
||||
#include "wl_types.h"
|
||||
#include "debug.h"
|
||||
}
|
||||
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::startServer(uint16_t port, uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_SERVER_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_SERVER_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::startClient(uint32_t ipAddress, uint16_t port, uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_3);
|
||||
SpiDrv::sendParam((uint8_t*)&ipAddress, sizeof(ipAddress));
|
||||
SpiDrv::sendParam(port);
|
||||
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(START_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
// Start server TCP on port specified
|
||||
void ServerDrv::stopClient(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(STOP_CLIENT_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(STOP_CLIENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
|
||||
uint8_t ServerDrv::getServerState(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_STATE_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_STATE_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint8_t ServerDrv::getClientState(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CLIENT_STATE_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_CLIENT_STATE_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint8_t ServerDrv::availData(uint8_t sock)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(AVAIL_DATA_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
return (_data == 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::getData(uint8_t sock, uint8_t *data, uint8_t peek)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock));
|
||||
SpiDrv::sendParam(peek, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(GET_DATA_TCP_CMD, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
*data = _data;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ServerDrv::getDataBuf(uint8_t sock, uint8_t *_data, uint16_t *_dataLen)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_DATABUF_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendBuffer(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
if (!SpiDrv::waitResponseData16(GET_DATABUF_TCP_CMD, _data, _dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (*_dataLen!=0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
bool ServerDrv::sendData(uint8_t sock, const uint8_t *data, uint16_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SEND_DATA_TCP_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendBuffer(&sock, sizeof(sock));
|
||||
SpiDrv::sendBuffer((uint8_t *)data, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseData8(SEND_DATA_TCP_CMD, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
if (_dataLen!=0)
|
||||
{
|
||||
return (_data == 1);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
uint8_t ServerDrv::checkDataSent(uint8_t sock)
|
||||
{
|
||||
const uint16_t TIMEOUT_DATA_SENT = 25;
|
||||
uint16_t timeout = 0;
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
|
||||
do {
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam(&sock, sizeof(sock), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
if (!SpiDrv::waitResponseCmd(DATA_SENT_TCP_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse isDataSent");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
if (_data) timeout = 0;
|
||||
else{
|
||||
++timeout;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
}while((_data==0)&&(timeout<TIMEOUT_DATA_SENT));
|
||||
return (timeout==TIMEOUT_DATA_SENT)?0:1;
|
||||
}
|
||||
|
||||
ServerDrv serverDrv;
|
|
@ -1,34 +0,0 @@
|
|||
#ifndef Server_Drv_h
|
||||
#define Server_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "wifi_spi.h"
|
||||
|
||||
class ServerDrv
|
||||
{
|
||||
public:
|
||||
// Start server TCP on port specified
|
||||
static void startServer(uint16_t port, uint8_t sock);
|
||||
|
||||
static void startClient(uint32_t ipAddress, uint16_t port, uint8_t sock);
|
||||
|
||||
static void stopClient(uint8_t sock);
|
||||
|
||||
static uint8_t getServerState(uint8_t sock);
|
||||
|
||||
static uint8_t getClientState(uint8_t sock);
|
||||
|
||||
static bool getData(uint8_t sock, uint8_t *data, uint8_t peek = 0);
|
||||
|
||||
static bool getDataBuf(uint8_t sock, uint8_t *data, uint16_t *len);
|
||||
|
||||
static bool sendData(uint8_t sock, const uint8_t *data, uint16_t len);
|
||||
|
||||
static uint8_t availData(uint8_t sock);
|
||||
|
||||
static uint8_t checkDataSent(uint8_t sock);
|
||||
};
|
||||
|
||||
extern ServerDrv serverDrv;
|
||||
|
||||
#endif
|
|
@ -1,83 +0,0 @@
|
|||
#ifndef SPI_Drv_h
|
||||
#define SPI_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "wifi_spi.h"
|
||||
|
||||
#define SPI_START_CMD_DELAY 12
|
||||
|
||||
#define NO_LAST_PARAM 0
|
||||
#define LAST_PARAM 1
|
||||
|
||||
#define DUMMY_DATA 0xFF
|
||||
|
||||
#define WAIT_FOR_SLAVE_SELECT() \
|
||||
SpiDrv::waitForSlaveReady(); \
|
||||
SpiDrv::spiSlaveSelect();
|
||||
|
||||
|
||||
|
||||
class SpiDrv
|
||||
{
|
||||
private:
|
||||
//static bool waitSlaveReady();
|
||||
static void waitForSlaveSign();
|
||||
static void getParam(uint8_t* param);
|
||||
public:
|
||||
|
||||
static void begin();
|
||||
|
||||
static void end();
|
||||
|
||||
static void spiDriverInit();
|
||||
|
||||
static void spiSlaveSelect();
|
||||
|
||||
static void spiSlaveDeselect();
|
||||
|
||||
static char spiTransfer(volatile char data);
|
||||
|
||||
static void waitForSlaveReady();
|
||||
|
||||
//static int waitSpiChar(char waitChar, char* readChar);
|
||||
|
||||
static int waitSpiChar(unsigned char waitChar);
|
||||
|
||||
static int readAndCheckChar(char checkChar, char* readChar);
|
||||
|
||||
static char readChar();
|
||||
|
||||
static int waitResponseParams(uint8_t cmd, uint8_t numParam, tParam* params);
|
||||
|
||||
static int waitResponseCmd(uint8_t cmd, uint8_t numParam, uint8_t* param, uint8_t* param_len);
|
||||
|
||||
static int waitResponseData8(uint8_t cmd, uint8_t* param, uint8_t* param_len);
|
||||
|
||||
static int waitResponseData16(uint8_t cmd, uint8_t* param, uint16_t* param_len);
|
||||
/*
|
||||
static int waitResponse(uint8_t cmd, tParam* params, uint8_t* numParamRead, uint8_t maxNumParams);
|
||||
|
||||
static int waitResponse(uint8_t cmd, uint8_t numParam, uint8_t* param, uint16_t* param_len);
|
||||
*/
|
||||
static int waitResponse(uint8_t cmd, uint8_t* numParamRead, uint8_t** params, uint8_t maxNumParams);
|
||||
|
||||
static void sendParam(uint8_t* param, uint8_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParamLen8(uint8_t param_len);
|
||||
|
||||
static void sendParamLen16(uint16_t param_len);
|
||||
|
||||
static uint8_t readParamLen8(uint8_t* param_len = NULL);
|
||||
|
||||
static uint16_t readParamLen16(uint16_t* param_len = NULL);
|
||||
|
||||
static void sendBuffer(uint8_t* param, uint16_t param_len, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendParam(uint16_t param, uint8_t lastParam = NO_LAST_PARAM);
|
||||
|
||||
static void sendCmd(uint8_t cmd, uint8_t numParam);
|
||||
};
|
||||
|
||||
extern SpiDrv spiDrv;
|
||||
|
||||
#endif
|
|
@ -1,491 +0,0 @@
|
|||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "Arduino.h"
|
||||
#include "spi_drv.h"
|
||||
#include "wifi_drv.h"
|
||||
|
||||
#define _DEBUG_
|
||||
|
||||
extern "C" {
|
||||
#include "wifi_spi.h"
|
||||
#include "wl_types.h"
|
||||
#include "debug.h"
|
||||
}
|
||||
|
||||
// Array of data to cache the information related to the networks discovered
|
||||
char WiFiDrv::_networkSsid[][WL_SSID_MAX_LENGTH] = {{"1"},{"2"},{"3"},{"4"},{"5"}};
|
||||
int32_t WiFiDrv::_networkRssi[WL_NETWORKS_LIST_MAXNUM] = { 0 };
|
||||
uint8_t WiFiDrv::_networkEncr[WL_NETWORKS_LIST_MAXNUM] = { 0 };
|
||||
|
||||
// Cached values of retrieved data
|
||||
char WiFiDrv::_ssid[] = {0};
|
||||
uint8_t WiFiDrv::_bssid[] = {0};
|
||||
uint8_t WiFiDrv::_mac[] = {0};
|
||||
uint8_t WiFiDrv::_localIp[] = {0};
|
||||
uint8_t WiFiDrv::_subnetMask[] = {0};
|
||||
uint8_t WiFiDrv::_gatewayIp[] = {0};
|
||||
// Firmware version
|
||||
char WiFiDrv::fwVersion[] = {0};
|
||||
|
||||
|
||||
// Private Methods
|
||||
|
||||
void WiFiDrv::getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip)
|
||||
{
|
||||
tParam params[PARAM_NUMS_3] = { {0, (char*)ip}, {0, (char*)mask}, {0, (char*)gwip}};
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_IPADDR_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, sizeof(_dummy), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
SpiDrv::waitResponseParams(GET_IPADDR_CMD, PARAM_NUMS_3, params);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
}
|
||||
|
||||
// Public Methods
|
||||
|
||||
|
||||
void WiFiDrv::wifiDriverInit()
|
||||
{
|
||||
SpiDrv::begin();
|
||||
}
|
||||
|
||||
int8_t WiFiDrv::wifiSetNetwork(char* ssid, uint8_t ssid_len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_NET_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(SET_NET_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return(_data == WIFI_SPI_ACK) ? WL_SUCCESS : WL_FAILURE;
|
||||
}
|
||||
|
||||
int8_t WiFiDrv::wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_2);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)passphrase, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(SET_PASSPHRASE_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
|
||||
int8_t WiFiDrv::wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SET_KEY_CMD, PARAM_NUMS_3);
|
||||
SpiDrv::sendParam((uint8_t*)ssid, ssid_len, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam(&key_idx, KEY_IDX_LEN, NO_LAST_PARAM);
|
||||
SpiDrv::sendParam((uint8_t*)key, len, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(SET_KEY_CMD, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return _data;
|
||||
}
|
||||
|
||||
int8_t WiFiDrv::disconnect()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(DISCONNECT_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
int8_t result = SpiDrv::waitResponseCmd(DISCONNECT_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::getConnectionStatus()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = -1;
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CONN_STATUS_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _data;
|
||||
}
|
||||
|
||||
uint8_t* WiFiDrv::getMacAddress()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_MACADDR_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_MACADDR_CMD, PARAM_NUMS_1, _mac, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _mac;
|
||||
}
|
||||
|
||||
void WiFiDrv::getIpAddress(IPAddress& ip)
|
||||
{
|
||||
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
||||
ip = _localIp;
|
||||
}
|
||||
|
||||
void WiFiDrv::getSubnetMask(IPAddress& mask)
|
||||
{
|
||||
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
||||
mask = _subnetMask;
|
||||
}
|
||||
|
||||
void WiFiDrv::getGatewayIP(IPAddress& ip)
|
||||
{
|
||||
getNetworkData(_localIp, _subnetMask, _gatewayIp);
|
||||
ip = _gatewayIp;
|
||||
}
|
||||
|
||||
char* WiFiDrv::getCurrentSSID()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_SSID_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CURR_SSID_CMD, PARAM_NUMS_1, (uint8_t*)_ssid, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _ssid;
|
||||
}
|
||||
|
||||
uint8_t* WiFiDrv::getCurrentBSSID()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_BSSID_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CURR_BSSID_CMD, PARAM_NUMS_1, _bssid, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return _bssid;
|
||||
}
|
||||
|
||||
int32_t WiFiDrv::getCurrentRSSI()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
int32_t rssi = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CURR_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&rssi, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return rssi;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::getCurrentEncryptionType()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1);
|
||||
|
||||
uint8_t _dummy = DUMMY_DATA;
|
||||
SpiDrv::sendParam(&_dummy, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t dataLen = 0;
|
||||
uint8_t encType = 0;
|
||||
SpiDrv::waitResponseCmd(GET_CURR_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return encType;
|
||||
}
|
||||
|
||||
int8_t WiFiDrv::startScanNetworks()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(START_SCAN_NETWORKS, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
|
||||
if (!SpiDrv::waitResponseCmd(START_SCAN_NETWORKS, PARAM_NUMS_1, &_data, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
_data = WL_FAILURE;
|
||||
}
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return (_data == WL_FAILURE)? _data : WL_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
uint8_t WiFiDrv::getScanNetworks()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(SCAN_NETWORKS, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t ssidListNum = 0;
|
||||
SpiDrv::waitResponse(SCAN_NETWORKS, &ssidListNum, (uint8_t**)_networkSsid, WL_NETWORKS_LIST_MAXNUM);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return ssidListNum;
|
||||
}
|
||||
|
||||
char* WiFiDrv::getSSIDNetoworks(uint8_t networkItem)
|
||||
{
|
||||
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
||||
return NULL;
|
||||
|
||||
return _networkSsid[networkItem];
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::getEncTypeNetowrks(uint8_t networkItem)
|
||||
{
|
||||
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
||||
return NULL;
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1);
|
||||
|
||||
SpiDrv::sendParam(&networkItem, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t dataLen = 0;
|
||||
uint8_t encType = 0;
|
||||
SpiDrv::waitResponseCmd(GET_IDX_ENCT_CMD, PARAM_NUMS_1, (uint8_t*)&encType, &dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return encType;
|
||||
}
|
||||
|
||||
int32_t WiFiDrv::getRSSINetoworks(uint8_t networkItem)
|
||||
{
|
||||
if (networkItem >= WL_NETWORKS_LIST_MAXNUM)
|
||||
return NULL;
|
||||
int32_t networkRssi = 0;
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1);
|
||||
|
||||
SpiDrv::sendParam(&networkItem, 1, LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t dataLen = 0;
|
||||
SpiDrv::waitResponseCmd(GET_IDX_RSSI_CMD, PARAM_NUMS_1, (uint8_t*)&networkRssi, &dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return networkRssi;
|
||||
}
|
||||
|
||||
uint8_t WiFiDrv::reqHostByName(const char* aHostname)
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1);
|
||||
SpiDrv::sendParam((uint8_t*)aHostname, strlen(aHostname), LAST_PARAM);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _data = 0;
|
||||
uint8_t _dataLen = 0;
|
||||
uint8_t result = SpiDrv::waitResponseCmd(REQ_HOST_BY_NAME_CMD, PARAM_NUMS_1, &_data, &_dataLen);
|
||||
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
int WiFiDrv::getHostByName(IPAddress& aResult)
|
||||
{
|
||||
uint8_t _ipAddr[WL_IPV4_LENGTH];
|
||||
IPAddress dummy(0xFF,0xFF,0xFF,0xFF);
|
||||
int result = 0;
|
||||
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_HOST_BY_NAME_CMD, PARAM_NUMS_1, _ipAddr, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}else{
|
||||
aResult = _ipAddr;
|
||||
result = (aResult != dummy);
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return result;
|
||||
}
|
||||
|
||||
int WiFiDrv::getHostByName(const char* aHostname, IPAddress& aResult)
|
||||
{
|
||||
uint8_t retry = 10;
|
||||
if (reqHostByName(aHostname))
|
||||
{
|
||||
while(!getHostByName(aResult) && --retry > 0)
|
||||
{
|
||||
delay(1000);
|
||||
}
|
||||
}else{
|
||||
return 0;
|
||||
}
|
||||
return (retry>0);
|
||||
}
|
||||
|
||||
char* WiFiDrv::getFwVersion()
|
||||
{
|
||||
WAIT_FOR_SLAVE_SELECT();
|
||||
// Send Command
|
||||
SpiDrv::sendCmd(GET_FW_VERSION_CMD, PARAM_NUMS_0);
|
||||
|
||||
//Wait the reply elaboration
|
||||
SpiDrv::waitForSlaveReady();
|
||||
|
||||
// Wait for reply
|
||||
uint8_t _dataLen = 0;
|
||||
if (!SpiDrv::waitResponseCmd(GET_FW_VERSION_CMD, PARAM_NUMS_1, (uint8_t*)fwVersion, &_dataLen))
|
||||
{
|
||||
WARN("error waitResponse");
|
||||
}
|
||||
SpiDrv::spiSlaveDeselect();
|
||||
return fwVersion;
|
||||
}
|
||||
|
||||
WiFiDrv wiFiDrv;
|
|
@ -1,219 +0,0 @@
|
|||
#ifndef WiFi_Drv_h
|
||||
#define WiFi_Drv_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "wifi_spi.h"
|
||||
#include "IPAddress.h"
|
||||
|
||||
// Key index length
|
||||
#define KEY_IDX_LEN 1
|
||||
// 5 secs of delay to have the connection established
|
||||
#define WL_DELAY_START_CONNECTION 5000
|
||||
// firmware version string length
|
||||
#define WL_FW_VER_LENGTH 6
|
||||
|
||||
class WiFiDrv
|
||||
{
|
||||
private:
|
||||
// settings of requested network
|
||||
static char _networkSsid[WL_NETWORKS_LIST_MAXNUM][WL_SSID_MAX_LENGTH];
|
||||
static int32_t _networkRssi[WL_NETWORKS_LIST_MAXNUM];
|
||||
static uint8_t _networkEncr[WL_NETWORKS_LIST_MAXNUM];
|
||||
|
||||
// firmware version string in the format a.b.c
|
||||
static char fwVersion[WL_FW_VER_LENGTH];
|
||||
|
||||
// settings of current selected network
|
||||
static char _ssid[WL_SSID_MAX_LENGTH];
|
||||
static uint8_t _bssid[WL_MAC_ADDR_LENGTH];
|
||||
static uint8_t _mac[WL_MAC_ADDR_LENGTH];
|
||||
static uint8_t _localIp[WL_IPV4_LENGTH];
|
||||
static uint8_t _subnetMask[WL_IPV4_LENGTH];
|
||||
static uint8_t _gatewayIp[WL_IPV4_LENGTH];
|
||||
|
||||
/*
|
||||
* Get network Data information
|
||||
*/
|
||||
static void getNetworkData(uint8_t *ip, uint8_t *mask, uint8_t *gwip);
|
||||
|
||||
static uint8_t reqHostByName(const char* aHostname);
|
||||
|
||||
static int getHostByName(IPAddress& aResult);
|
||||
|
||||
public:
|
||||
|
||||
/*
|
||||
* Driver initialization
|
||||
*/
|
||||
static void wifiDriverInit();
|
||||
|
||||
/*
|
||||
* Set the desired network which the connection manager should try to
|
||||
* connect to.
|
||||
*
|
||||
* The ssid of the desired network should be specified.
|
||||
*
|
||||
* param ssid: The ssid of the desired network.
|
||||
* param ssid_len: Lenght of ssid string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetNetwork(char* ssid, uint8_t ssid_len);
|
||||
|
||||
/* Start Wifi connection with passphrase
|
||||
* the most secure supported mode will be automatically selected
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param ssid_len: Lenght of ssid string.
|
||||
* param passphrase: Passphrase. Valid characters in a passphrase
|
||||
* must be between ASCII 32-126 (decimal).
|
||||
* param len: Lenght of passphrase string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetPassphrase(char* ssid, uint8_t ssid_len, const char *passphrase, const uint8_t len);
|
||||
|
||||
/* Start Wifi connection with WEP encryption.
|
||||
* Configure a key into the device. The key type (WEP-40, WEP-104)
|
||||
* is determined by the size of the key (5 bytes for WEP-40, 13 bytes for WEP-104).
|
||||
*
|
||||
* param ssid: Pointer to the SSID string.
|
||||
* param ssid_len: Lenght of ssid string.
|
||||
* param key_idx: The key index to set. Valid values are 0-3.
|
||||
* param key: Key input buffer.
|
||||
* param len: Lenght of key string.
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t wifiSetKey(char* ssid, uint8_t ssid_len, uint8_t key_idx, const void *key, const uint8_t len);
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: WL_SUCCESS or WL_FAILURE
|
||||
*/
|
||||
static int8_t disconnect();
|
||||
|
||||
/*
|
||||
* Disconnect from the network
|
||||
*
|
||||
* return: one value of wl_status_t enum
|
||||
*/
|
||||
static uint8_t getConnectionStatus();
|
||||
|
||||
/*
|
||||
* Get the interface MAC address.
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
static uint8_t* getMacAddress();
|
||||
|
||||
/*
|
||||
* Get the interface IP address.
|
||||
*
|
||||
* return: copy the ip address value in IPAddress object
|
||||
*/
|
||||
static void getIpAddress(IPAddress& ip);
|
||||
|
||||
/*
|
||||
* Get the interface subnet mask address.
|
||||
*
|
||||
* return: copy the subnet mask address value in IPAddress object
|
||||
*/
|
||||
static void getSubnetMask(IPAddress& mask);
|
||||
|
||||
/*
|
||||
* Get the gateway ip address.
|
||||
*
|
||||
* return: copy the gateway ip address value in IPAddress object
|
||||
*/
|
||||
static void getGatewayIP(IPAddress& ip);
|
||||
|
||||
/*
|
||||
* Return the current SSID associated with the network
|
||||
*
|
||||
* return: ssid string
|
||||
*/
|
||||
static char* getCurrentSSID();
|
||||
|
||||
/*
|
||||
* Return the current BSSID associated with the network.
|
||||
* It is the MAC address of the Access Point
|
||||
*
|
||||
* return: pointer to uint8_t array with length WL_MAC_ADDR_LENGTH
|
||||
*/
|
||||
static uint8_t* getCurrentBSSID();
|
||||
|
||||
/*
|
||||
* Return the current RSSI /Received Signal Strength in dBm)
|
||||
* associated with the network
|
||||
*
|
||||
* return: signed value
|
||||
*/
|
||||
static int32_t getCurrentRSSI();
|
||||
|
||||
/*
|
||||
* Return the Encryption Type associated with the network
|
||||
*
|
||||
* return: one value of wl_enc_type enum
|
||||
*/
|
||||
static uint8_t getCurrentEncryptionType();
|
||||
|
||||
/*
|
||||
* Start scan WiFi networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
static int8_t startScanNetworks();
|
||||
|
||||
/*
|
||||
* Get the networks available
|
||||
*
|
||||
* return: Number of discovered networks
|
||||
*/
|
||||
static uint8_t getScanNetworks();
|
||||
|
||||
/*
|
||||
* Return the SSID discovered during the network scan.
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: ssid string of the specified item on the networks scanned list
|
||||
*/
|
||||
static char* getSSIDNetoworks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the RSSI of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: signed value of RSSI of the specified item on the networks scanned list
|
||||
*/
|
||||
static int32_t getRSSINetoworks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Return the encryption type of the networks discovered during the scanNetworks
|
||||
*
|
||||
* param networkItem: specify from which network item want to get the information
|
||||
*
|
||||
* return: encryption type (enum wl_enc_type) of the specified item on the networks scanned list
|
||||
*/
|
||||
static uint8_t getEncTypeNetowrks(uint8_t networkItem);
|
||||
|
||||
/*
|
||||
* Resolve the given hostname to an IP address.
|
||||
* param aHostname: Name to be resolved
|
||||
* param aResult: IPAddress structure to store the returned IP address
|
||||
* result: 1 if aIPAddrString was successfully converted to an IP address,
|
||||
* else error code
|
||||
*/
|
||||
static int getHostByName(const char* aHostname, IPAddress& aResult);
|
||||
|
||||
/*
|
||||
* Get the firmware version
|
||||
* result: version as string with this format a.b.c
|
||||
*/
|
||||
static char* getFwVersion();
|
||||
|
||||
};
|
||||
|
||||
extern WiFiDrv wiFiDrv;
|
||||
|
||||
#endif
|
|
@ -1,31 +0,0 @@
|
|||
/*
|
||||
* wl_types.h
|
||||
*
|
||||
* Created on: Jul 30, 2010
|
||||
* Author: dlafauci
|
||||
*/
|
||||
|
||||
|
||||
#ifndef _WL_TYPES_H_
|
||||
#define _WL_TYPES_H_
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
typedef enum {
|
||||
WL_FAILURE = -1,
|
||||
WL_SUCCESS = 1,
|
||||
} wl_error_code_t;
|
||||
|
||||
/* Authentication modes */
|
||||
enum wl_auth_mode {
|
||||
AUTH_MODE_INVALID,
|
||||
AUTH_MODE_AUTO,
|
||||
AUTH_MODE_OPEN_SYSTEM,
|
||||
AUTH_MODE_SHARED_KEY,
|
||||
AUTH_MODE_WPA,
|
||||
AUTH_MODE_WPA2,
|
||||
AUTH_MODE_WPA_PSK,
|
||||
AUTH_MODE_WPA2_PSK
|
||||
};
|
||||
|
||||
#endif //_WL_TYPES_H_
|
4
hardware/arduino/avr/libraries/WiFi/WiFiClient.cpp → libraries/WiFi/arch/avr/WiFiClient.cpp
Normal file → Executable file
4
hardware/arduino/avr/libraries/WiFi/WiFiClient.cpp → libraries/WiFi/arch/avr/WiFiClient.cpp
Normal file → Executable file
|
@ -1,7 +1,7 @@
|
|||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "socket.h"
|
||||
#include "utility/socket.h"
|
||||
#include "string.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ extern "C" {
|
|||
#include "WiFi.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
#include "server_drv.h"
|
||||
#include "utility/server_drv.h"
|
||||
|
||||
|
||||
uint16_t WiFiClient::_srcport = 1024;
|
|
@ -4,8 +4,8 @@ extern "C" {
|
|||
#include "utility/wifi_spi.h"
|
||||
}
|
||||
#include <string.h>
|
||||
#include "server_drv.h"
|
||||
#include "wifi_drv.h"
|
||||
#include "utility/server_drv.h"
|
||||
#include "utility/wifi_drv.h"
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiUdp.h"
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#define SOCK_NOT_AVAIL 255
|
||||
|
||||
#include "wl_definitions.h"
|
||||
#include "utility/wl_definitions.h"
|
||||
/**
|
||||
* The 8-bit signed data type.
|
||||
*/
|
|
@ -1,16 +1,17 @@
|
|||
|
||||
#include "Arduino.h"
|
||||
#include "spi_drv.h"
|
||||
#include <SPI.h>
|
||||
#include "utility/spi_drv.h"
|
||||
#include "pins_arduino.h"
|
||||
//#define _DEBUG_
|
||||
extern "C" {
|
||||
#include "debug.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
#define DATAOUT 11 // MOSI
|
||||
#define DATAIN 12 // MISO
|
||||
#define SPICLOCK 13 // sck
|
||||
#define SLAVESELECT 10 // ss
|
||||
#define SLAVESELECT 10 // ss
|
||||
#define SLAVEREADY 7 // handshake pin
|
||||
#define WIFILED 9 // led on wifi shield
|
||||
|
||||
|
@ -20,15 +21,7 @@ extern "C" {
|
|||
|
||||
void SpiDrv::begin()
|
||||
{
|
||||
// Set direction register for SCK and MOSI pin.
|
||||
// MISO pin automatically overrides to INPUT.
|
||||
// When the SS pin is set as OUTPUT, it can be used as
|
||||
// a general purpose output port (it doesn't influence
|
||||
// SPI operations).
|
||||
|
||||
pinMode(SCK, OUTPUT);
|
||||
pinMode(MOSI, OUTPUT);
|
||||
pinMode(SS, OUTPUT);
|
||||
SPI.begin();
|
||||
pinMode(SLAVESELECT, OUTPUT);
|
||||
pinMode(SLAVEREADY, INPUT);
|
||||
pinMode(WIFILED, OUTPUT);
|
||||
|
@ -42,17 +35,10 @@ void SpiDrv::begin()
|
|||
#ifdef _DEBUG_
|
||||
INIT_TRIGGER()
|
||||
#endif
|
||||
|
||||
// Warning: if the SS pin ever becomes a LOW INPUT then SPI
|
||||
// automatically switches to Slave, so the data direction of
|
||||
// the SS pin MUST be kept as OUTPUT.
|
||||
SPCR |= _BV(MSTR);
|
||||
SPCR |= _BV(SPE);
|
||||
//SPSR |= _BV(SPI2X);
|
||||
}
|
||||
|
||||
void SpiDrv::end() {
|
||||
SPCR &= ~_BV(SPE);
|
||||
SPI.end();
|
||||
}
|
||||
|
||||
void SpiDrv::spiSlaveSelect()
|
||||
|
@ -66,6 +52,7 @@ void SpiDrv::spiSlaveDeselect()
|
|||
digitalWrite(SLAVESELECT,HIGH);
|
||||
}
|
||||
|
||||
/*
|
||||
void delaySpi()
|
||||
{
|
||||
int i = 0;
|
||||
|
@ -75,14 +62,11 @@ void delaySpi()
|
|||
int a =a+1;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
char SpiDrv::spiTransfer(volatile char data)
|
||||
{
|
||||
SPDR = data; // Start the transmission
|
||||
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
|
||||
{
|
||||
};
|
||||
char result = SPDR;
|
||||
char result = SPI.transfer(data);
|
||||
DELAY_TRANSFER();
|
||||
|
||||
return result; // return the received byte
|
|
@ -1,7 +1,7 @@
|
|||
#ifndef WiFi_Spi_h
|
||||
#define WiFi_Spi_h
|
||||
|
||||
#include "wl_definitions.h"
|
||||
#include "utility/wl_definitions.h"
|
||||
|
||||
#define CMD_FLAG 0
|
||||
#define REPLY_FLAG 1<<7
|
||||
|
@ -56,7 +56,7 @@ enum {
|
|||
GET_FW_VERSION_CMD = 0x37,
|
||||
GET_TEST_CMD = 0x38,
|
||||
SEND_DATA_UDP_CMD = 0x39,
|
||||
GET_REMOTE_DATA_CMD = 0x3A,
|
||||
GET_REMOTE_DATA_CMD = 0x3A,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
|
20
hardware/arduino/sam/libraries/WiFi/WiFiClient.cpp → libraries/WiFi/arch/sam/WiFiClient.cpp
Normal file → Executable file
20
hardware/arduino/sam/libraries/WiFi/WiFiClient.cpp → libraries/WiFi/arch/sam/WiFiClient.cpp
Normal file → Executable file
|
@ -1,7 +1,7 @@
|
|||
extern "C" {
|
||||
#include "utility/wl_definitions.h"
|
||||
#include "utility/wl_types.h"
|
||||
#include "socket.h"
|
||||
#include "utility/socket.h"
|
||||
#include "string.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
@ -9,7 +9,7 @@ extern "C" {
|
|||
#include "WiFi.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
#include "server_drv.h"
|
||||
#include "utility/server_drv.h"
|
||||
|
||||
|
||||
uint16_t WiFiClient::_srcport = 1024;
|
||||
|
@ -54,7 +54,7 @@ int WiFiClient::connect(IPAddress ip, uint16_t port) {
|
|||
}
|
||||
|
||||
size_t WiFiClient::write(uint8_t b) {
|
||||
return write(&b, static_cast<size_t>(1));
|
||||
return write(&b, 1);
|
||||
}
|
||||
|
||||
size_t WiFiClient::write(const uint8_t *buf, size_t size) {
|
||||
|
@ -130,13 +130,13 @@ void WiFiClient::stop() {
|
|||
return;
|
||||
|
||||
ServerDrv::stopClient(_sock);
|
||||
WiFiClass::_state[_sock] = NA_STATE;
|
||||
|
||||
unsigned long start = millis();
|
||||
|
||||
int count = 0;
|
||||
// wait maximum 5 secs for the connection to close
|
||||
while (status() != CLOSED && ++count < 50)
|
||||
delay(100);
|
||||
|
||||
// wait a second for the connection to close
|
||||
while (status() != CLOSED && millis() - start < 1000)
|
||||
delay(1);
|
||||
_sock = 255;
|
||||
}
|
||||
|
||||
|
@ -150,7 +150,7 @@ uint8_t WiFiClient::connected() {
|
|||
return !(s == LISTEN || s == CLOSED || s == FIN_WAIT_1 ||
|
||||
s == FIN_WAIT_2 || s == TIME_WAIT ||
|
||||
s == SYN_SENT || s== SYN_RCVD ||
|
||||
(s == CLOSE_WAIT && !available()));
|
||||
(s == CLOSE_WAIT));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -170,7 +170,7 @@ WiFiClient::operator bool() {
|
|||
uint8_t WiFiClient::getFirstSocket()
|
||||
{
|
||||
for (int i = 0; i < MAX_SOCK_NUM; i++) {
|
||||
if (WiFiClass::_state[i] == 0)
|
||||
if (WiFiClass::_state[i] == NA_STATE)
|
||||
{
|
||||
return i;
|
||||
}
|
|
@ -0,0 +1,163 @@
|
|||
|
||||
extern "C" {
|
||||
#include "utility/debug.h"
|
||||
#include "utility/wifi_spi.h"
|
||||
}
|
||||
#include <string.h>
|
||||
#include "utility/server_drv.h"
|
||||
#include "utility/wifi_drv.h"
|
||||
|
||||
#include "WiFi.h"
|
||||
#include "WiFiUdp.h"
|
||||
#include "WiFiClient.h"
|
||||
#include "WiFiServer.h"
|
||||
|
||||
|
||||
/* Constructor */
|
||||
WiFiUDP::WiFiUDP() : _sock(NO_SOCKET_AVAIL) {}
|
||||
|
||||
/* Start WiFiUDP socket, listening at local port PORT */
|
||||
uint8_t WiFiUDP::begin(uint16_t port) {
|
||||
|
||||
uint8_t sock = WiFiClass::getSocket();
|
||||
if (sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startServer(port, sock, UDP_MODE);
|
||||
WiFiClass::_server_port[sock] = port;
|
||||
_sock = sock;
|
||||
_port = port;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
/* return number of bytes available in the current packet,
|
||||
will return zero if parsePacket hasn't been called yet */
|
||||
int WiFiUDP::available() {
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
return ServerDrv::availData(_sock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Release any resources being used by this WiFiUDP instance */
|
||||
void WiFiUDP::stop()
|
||||
{
|
||||
if (_sock == NO_SOCKET_AVAIL)
|
||||
return;
|
||||
|
||||
ServerDrv::stopClient(_sock);
|
||||
|
||||
_sock = NO_SOCKET_AVAIL;
|
||||
}
|
||||
|
||||
int WiFiUDP::beginPacket(const char *host, uint16_t port)
|
||||
{
|
||||
// Look up the host first
|
||||
int ret = 0;
|
||||
IPAddress remote_addr;
|
||||
if (WiFi.hostByName(host, remote_addr))
|
||||
{
|
||||
return beginPacket(remote_addr, port);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int WiFiUDP::beginPacket(IPAddress ip, uint16_t port)
|
||||
{
|
||||
if (_sock == NO_SOCKET_AVAIL)
|
||||
_sock = WiFiClass::getSocket();
|
||||
if (_sock != NO_SOCKET_AVAIL)
|
||||
{
|
||||
ServerDrv::startClient(uint32_t(ip), port, _sock, UDP_MODE);
|
||||
WiFiClass::_state[_sock] = _sock;
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int WiFiUDP::endPacket()
|
||||
{
|
||||
return ServerDrv::sendUdpData(_sock);
|
||||
}
|
||||
|
||||
size_t WiFiUDP::write(uint8_t byte)
|
||||
{
|
||||
return write(&byte, 1);
|
||||
}
|
||||
|
||||
size_t WiFiUDP::write(const uint8_t *buffer, size_t size)
|
||||
{
|
||||
ServerDrv::insertDataBuf(_sock, buffer, size);
|
||||
return size;
|
||||
}
|
||||
|
||||
int WiFiUDP::parsePacket()
|
||||
{
|
||||
return available();
|
||||
}
|
||||
|
||||
int WiFiUDP::read()
|
||||
{
|
||||
uint8_t b;
|
||||
if (available())
|
||||
{
|
||||
ServerDrv::getData(_sock, &b);
|
||||
return b;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int WiFiUDP::read(unsigned char* buffer, size_t len)
|
||||
{
|
||||
if (available())
|
||||
{
|
||||
uint16_t size = 0;
|
||||
if (!ServerDrv::getDataBuf(_sock, buffer, &size))
|
||||
return -1;
|
||||
// TODO check if the buffer is too smal respect to buffer size
|
||||
return size;
|
||||
}else{
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
int WiFiUDP::peek()
|
||||
{
|
||||
uint8_t b;
|
||||
if (!available())
|
||||
return -1;
|
||||
|
||||
ServerDrv::getData(_sock, &b, 1);
|
||||
return b;
|
||||
}
|
||||
|
||||
void WiFiUDP::flush()
|
||||
{
|
||||
while (available())
|
||||
read();
|
||||
}
|
||||
|
||||
IPAddress WiFiUDP::remoteIP()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
IPAddress ip(_remoteIp);
|
||||
return ip;
|
||||
}
|
||||
|
||||
uint16_t WiFiUDP::remotePort()
|
||||
{
|
||||
uint8_t _remoteIp[4] = {0};
|
||||
uint8_t _remotePort[2] = {0};
|
||||
|
||||
WiFiDrv::getRemoteData(_sock, _remoteIp, _remotePort);
|
||||
uint16_t port = (_remotePort[0]<<8)+_remotePort[1];
|
||||
return port;
|
||||
}
|
||||
|
|
@ -14,7 +14,7 @@
|
|||
|
||||
#define SOCK_NOT_AVAIL 255
|
||||
|
||||
#include "wl_definitions.h"
|
||||
#include "utility/wl_definitions.h"
|
||||
/**
|
||||
* The 8-bit signed data type.
|
||||
*/
|
||||
|
@ -67,7 +67,7 @@ typedef volatile unsigned long vuint32;
|
|||
|
||||
/* bsd */
|
||||
typedef uint8 u_char; /**< 8-bit value */
|
||||
typedef uint16_t SOCKET;
|
||||
typedef uint16_t SOCKET;
|
||||
//typedef uint16 u_short; /**< 16-bit value */
|
||||
typedef uint16 u_int; /**< 16-bit value */
|
||||
typedef uint32 u_long; /**< 32-bit value */
|
|
@ -1,11 +1,11 @@
|
|||
|
||||
#include "Arduino.h"
|
||||
#include <SPI.h>
|
||||
#include "spi_drv.h"
|
||||
#include "utility/spi_drv.h"
|
||||
#include "pins_arduino.h"
|
||||
//#define _DEBUG_
|
||||
extern "C" {
|
||||
#include "debug.h"
|
||||
#include "utility/debug.h"
|
||||
}
|
||||
|
||||
#define DATAOUT 11 // MOSI
|
|
@ -1,144 +1,154 @@
|
|||
#ifndef WiFi_Spi_h
|
||||
#define WiFi_Spi_h
|
||||
|
||||
#include "wl_definitions.h"
|
||||
|
||||
#define CMD_FLAG 0
|
||||
#define REPLY_FLAG 1<<7
|
||||
#define DATA_FLAG 0x40
|
||||
|
||||
#define WIFI_SPI_ACK 1
|
||||
#define WIFI_SPI_ERR 0xFF
|
||||
|
||||
#define TIMEOUT_CHAR 1000
|
||||
|
||||
//#define MAX_SOCK_NUM 4 /**< Maxmium number of socket */
|
||||
#define NO_SOCKET_AVAIL 255
|
||||
|
||||
#define START_CMD 0xE0
|
||||
#define END_CMD 0xEE
|
||||
#define ERR_CMD 0xEF
|
||||
|
||||
enum {
|
||||
SET_NET_CMD = 0x10,
|
||||
SET_PASSPHRASE_CMD = 0x11,
|
||||
SET_KEY_CMD = 0x12,
|
||||
TEST_CMD = 0x13,
|
||||
|
||||
GET_CONN_STATUS_CMD = 0x20,
|
||||
GET_IPADDR_CMD = 0x21,
|
||||
GET_MACADDR_CMD = 0x22,
|
||||
GET_CURR_SSID_CMD = 0x23,
|
||||
GET_CURR_BSSID_CMD = 0x24,
|
||||
GET_CURR_RSSI_CMD = 0x25,
|
||||
GET_CURR_ENCT_CMD = 0x26,
|
||||
SCAN_NETWORKS = 0x27,
|
||||
START_SERVER_TCP_CMD= 0x28,
|
||||
GET_STATE_TCP_CMD = 0x29,
|
||||
DATA_SENT_TCP_CMD = 0x2A,
|
||||
AVAIL_DATA_TCP_CMD = 0x2B,
|
||||
GET_DATA_TCP_CMD = 0x2C,
|
||||
START_CLIENT_TCP_CMD= 0x2D,
|
||||
STOP_CLIENT_TCP_CMD = 0x2E,
|
||||
GET_CLIENT_STATE_TCP_CMD= 0x2F,
|
||||
DISCONNECT_CMD = 0x30,
|
||||
GET_IDX_SSID_CMD = 0x31,
|
||||
GET_IDX_RSSI_CMD = 0x32,
|
||||
GET_IDX_ENCT_CMD = 0x33,
|
||||
REQ_HOST_BY_NAME_CMD= 0x34,
|
||||
GET_HOST_BY_NAME_CMD= 0x35,
|
||||
START_SCAN_NETWORKS = 0x36,
|
||||
GET_FW_VERSION_CMD = 0x37,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
|
||||
SEND_DATA_TCP_CMD = 0x44,
|
||||
GET_DATABUF_TCP_CMD = 0x45,
|
||||
};
|
||||
|
||||
|
||||
enum wl_tcp_state {
|
||||
CLOSED = 0,
|
||||
LISTEN = 1,
|
||||
SYN_SENT = 2,
|
||||
SYN_RCVD = 3,
|
||||
ESTABLISHED = 4,
|
||||
FIN_WAIT_1 = 5,
|
||||
FIN_WAIT_2 = 6,
|
||||
CLOSE_WAIT = 7,
|
||||
CLOSING = 8,
|
||||
LAST_ACK = 9,
|
||||
TIME_WAIT = 10
|
||||
};
|
||||
|
||||
|
||||
enum numParams{
|
||||
PARAM_NUMS_0,
|
||||
PARAM_NUMS_1,
|
||||
PARAM_NUMS_2,
|
||||
PARAM_NUMS_3,
|
||||
PARAM_NUMS_4,
|
||||
PARAM_NUMS_5,
|
||||
MAX_PARAM_NUMS
|
||||
};
|
||||
|
||||
#define MAX_PARAMS MAX_PARAM_NUMS-1
|
||||
#define PARAM_LEN_SIZE 1
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
char* param;
|
||||
}tParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint16_t dataLen;
|
||||
char* data;
|
||||
}tDataParam;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tParam params[MAX_PARAMS];
|
||||
}tSpiMsg;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tDataParam params[MAX_PARAMS];
|
||||
}tSpiMsgData;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
//unsigned char totLen;
|
||||
unsigned char nParam;
|
||||
}tSpiHdr;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint32_t param;
|
||||
}tLongParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint16_t param;
|
||||
}tIntParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint8_t param;
|
||||
}tByteParam;
|
||||
|
||||
#endif
|
||||
#ifndef WiFi_Spi_h
|
||||
#define WiFi_Spi_h
|
||||
|
||||
#include <inttypes.h>
|
||||
#include "utility/wl_definitions.h"
|
||||
|
||||
#define CMD_FLAG 0
|
||||
#define REPLY_FLAG 1<<7
|
||||
#define DATA_FLAG 0x40
|
||||
|
||||
#define WIFI_SPI_ACK 1
|
||||
#define WIFI_SPI_ERR 0xFF
|
||||
|
||||
#define TIMEOUT_CHAR 1000
|
||||
|
||||
//#define MAX_SOCK_NUM 4 /**< Maxmium number of socket */
|
||||
#define NO_SOCKET_AVAIL 255
|
||||
|
||||
#define START_CMD 0xE0
|
||||
#define END_CMD 0xEE
|
||||
#define ERR_CMD 0xEF
|
||||
#define CMD_POS 1 // Position of Command OpCode on SPI stream
|
||||
#define PARAM_LEN_POS 2 // Position of Param len on SPI stream
|
||||
|
||||
|
||||
enum {
|
||||
SET_NET_CMD = 0x10,
|
||||
SET_PASSPHRASE_CMD = 0x11,
|
||||
SET_KEY_CMD = 0x12,
|
||||
TEST_CMD = 0x13,
|
||||
SET_IP_CONFIG_CMD = 0x14,
|
||||
SET_DNS_CONFIG_CMD = 0x15,
|
||||
|
||||
GET_CONN_STATUS_CMD = 0x20,
|
||||
GET_IPADDR_CMD = 0x21,
|
||||
GET_MACADDR_CMD = 0x22,
|
||||
GET_CURR_SSID_CMD = 0x23,
|
||||
GET_CURR_BSSID_CMD = 0x24,
|
||||
GET_CURR_RSSI_CMD = 0x25,
|
||||
GET_CURR_ENCT_CMD = 0x26,
|
||||
SCAN_NETWORKS = 0x27,
|
||||
START_SERVER_TCP_CMD= 0x28,
|
||||
GET_STATE_TCP_CMD = 0x29,
|
||||
DATA_SENT_TCP_CMD = 0x2A,
|
||||
AVAIL_DATA_TCP_CMD = 0x2B,
|
||||
GET_DATA_TCP_CMD = 0x2C,
|
||||
START_CLIENT_TCP_CMD= 0x2D,
|
||||
STOP_CLIENT_TCP_CMD = 0x2E,
|
||||
GET_CLIENT_STATE_TCP_CMD= 0x2F,
|
||||
DISCONNECT_CMD = 0x30,
|
||||
GET_IDX_SSID_CMD = 0x31,
|
||||
GET_IDX_RSSI_CMD = 0x32,
|
||||
GET_IDX_ENCT_CMD = 0x33,
|
||||
REQ_HOST_BY_NAME_CMD= 0x34,
|
||||
GET_HOST_BY_NAME_CMD= 0x35,
|
||||
START_SCAN_NETWORKS = 0x36,
|
||||
GET_FW_VERSION_CMD = 0x37,
|
||||
GET_TEST_CMD = 0x38,
|
||||
SEND_DATA_UDP_CMD = 0x39,
|
||||
GET_REMOTE_DATA_CMD = 0x3A,
|
||||
|
||||
// All command with DATA_FLAG 0x40 send a 16bit Len
|
||||
|
||||
SEND_DATA_TCP_CMD = 0x44,
|
||||
GET_DATABUF_TCP_CMD = 0x45,
|
||||
INSERT_DATABUF_CMD = 0x46,
|
||||
};
|
||||
|
||||
|
||||
enum wl_tcp_state {
|
||||
CLOSED = 0,
|
||||
LISTEN = 1,
|
||||
SYN_SENT = 2,
|
||||
SYN_RCVD = 3,
|
||||
ESTABLISHED = 4,
|
||||
FIN_WAIT_1 = 5,
|
||||
FIN_WAIT_2 = 6,
|
||||
CLOSE_WAIT = 7,
|
||||
CLOSING = 8,
|
||||
LAST_ACK = 9,
|
||||
TIME_WAIT = 10
|
||||
};
|
||||
|
||||
|
||||
enum numParams{
|
||||
PARAM_NUMS_0,
|
||||
PARAM_NUMS_1,
|
||||
PARAM_NUMS_2,
|
||||
PARAM_NUMS_3,
|
||||
PARAM_NUMS_4,
|
||||
PARAM_NUMS_5,
|
||||
MAX_PARAM_NUMS
|
||||
};
|
||||
|
||||
#define MAX_PARAMS MAX_PARAM_NUMS-1
|
||||
#define PARAM_LEN_SIZE 1
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
char* param;
|
||||
}tParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint16_t dataLen;
|
||||
char* data;
|
||||
}tDataParam;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tParam params[MAX_PARAMS];
|
||||
}tSpiMsg;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
unsigned char nParam;
|
||||
tDataParam params[MAX_PARAMS];
|
||||
}tSpiMsgData;
|
||||
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
unsigned char cmd;
|
||||
unsigned char tcmd;
|
||||
//unsigned char totLen;
|
||||
unsigned char nParam;
|
||||
}tSpiHdr;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint32_t param;
|
||||
}tLongParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint16_t param;
|
||||
}tIntParam;
|
||||
|
||||
typedef struct __attribute__((__packed__))
|
||||
{
|
||||
uint8_t paramLen;
|
||||
uint8_t param;
|
||||
}tByteParam;
|
||||
|
||||
#endif
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
@ -0,0 +1,121 @@
|
|||
#!/bin/sh
|
||||
|
||||
#WIFI_FW_PATH="/hardware/arduino/firmwares/wifishield/binary"
|
||||
WIFI_FW_PATH="/libraries/WiFi/extras/binary"
|
||||
AVR_TOOLS_PATH="/hardware/tools/avr/bin"
|
||||
|
||||
TARGET_MICRO="at32uc3a1256"
|
||||
|
||||
|
||||
progname=$0
|
||||
|
||||
usage () {
|
||||
cat <<EOF
|
||||
Usage: $progname [-a Arduino_path] [-f which_firmware] [-h]
|
||||
-a set the path where the Arduino IDE is installed
|
||||
-f the firmware you want to upload, valid parameters are:
|
||||
shield - to upgrade the WiFi shield firmware
|
||||
all - to upgrade both firmwares
|
||||
-h help
|
||||
EOF
|
||||
exit 0
|
||||
}
|
||||
|
||||
upgradeHDmodule () {
|
||||
sleep 1 # Give time to the shield to end the boot
|
||||
echo "****Upgrade HD WiFi module firmware****\n"
|
||||
dfu-programmer $TARGET_MICRO erase
|
||||
dfu-programmer $TARGET_MICRO flash --suppress-bootloader-mem $WIFI_FW_PATH/wifi_dnld.hex
|
||||
dfu-programmer $TARGET_MICRO start
|
||||
|
||||
if [ $? != 0 ] ; then
|
||||
echo "\nError during device initialization, please close the J3 jumper and press the reset button.\nTry -h for help\n"
|
||||
exit 1 # if the device is not recognized exit
|
||||
fi
|
||||
|
||||
echo -n "\nPress the RESET button on the shield then type [ENTER] to upgrade the firmware of the shield..\n"
|
||||
read readEnter
|
||||
}
|
||||
|
||||
upgradeShield () {
|
||||
sleep 1 # Give time to the shield to end the boot
|
||||
echo "****Upgrade WiFi Shield firmware****\n"
|
||||
dfu-programmer $TARGET_MICRO erase
|
||||
dfu-programmer $TARGET_MICRO flash --suppress-bootloader-mem $WIFI_FW_PATH/wifiHD.hex
|
||||
dfu-programmer $TARGET_MICRO start
|
||||
|
||||
if [ $? != 0 ] ; then
|
||||
echo "\nError during device initialization, please close the J3 jumper and press the reset button.\nTry -h for help\n"
|
||||
exit 1 # if the device is not recognized exit
|
||||
fi
|
||||
|
||||
echo "\nDone. Remove the J3 jumper and press the RESET button on the shield."
|
||||
echo "Thank you!\n"
|
||||
}
|
||||
|
||||
|
||||
cat <<EOF
|
||||
|
||||
Arduino WiFi Shield upgrade
|
||||
=========================================
|
||||
Instructions:
|
||||
|
||||
To access to the USB devices correctly, the dfu-programmer needs to have the root permissions.
|
||||
|
||||
You can upgrade the firmware of the antenna togheter with the shield firmware or only the shield firmware
|
||||
if there aren't changes on the antenna firmware.
|
||||
|
||||
Use the '-h' parameter for help
|
||||
=========================================
|
||||
|
||||
EOF
|
||||
|
||||
if [ $USER = 'root' ] ; then #check if the current user is root
|
||||
while getopts ":a:f:h" opt; do
|
||||
case $opt in
|
||||
a)
|
||||
ARDUINO_PATH=$OPTARG
|
||||
WIFI_FW_PATH=$ARDUINO_PATH$WIFI_FW_PATH
|
||||
AVR_TOOLS_PATH=$ARDUINO_PATH$AVR_TOOLS_PATH
|
||||
cd $AVR_TOOLS_PATH
|
||||
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifi_dnld.elf $WIFI_FW_PATH/wifi_dnld.hex
|
||||
./avr-objcopy --output-target=ihex $WIFI_FW_PATH/wifiHD.elf $WIFI_FW_PATH/wifiHD.hex
|
||||
;;
|
||||
f)
|
||||
if [ "$ARDUINO_PATH" != "" ] ; then
|
||||
if [ "$OPTARG" = "all" ] ; then
|
||||
upgradeHDmodule
|
||||
upgradeShield
|
||||
exit 0
|
||||
else
|
||||
if [ "$OPTARG" = "shield" ] ; then
|
||||
upgradeShield
|
||||
exit 0
|
||||
else
|
||||
echo "invalid parameter for the -f [firmware] option, please retry."
|
||||
echo "Type -h for help\n"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
echo "Arduino Path not setted. Retry...\n"
|
||||
fi
|
||||
;;
|
||||
h)
|
||||
usage ;;
|
||||
\?)
|
||||
echo "Invalid option: $OPTARG" >&2
|
||||
usage
|
||||
exit 1
|
||||
;;
|
||||
:)
|
||||
echo "Option -$OPTARG requires an argument." >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
done
|
||||
else
|
||||
echo "Please retry running the script as root.\n"
|
||||
fi
|
||||
|
||||
shift $(($OPTIND - 1))
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,77 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>wifiHD</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.genmakebuilder</name>
|
||||
<triggers>clean,full,incremental,</triggers>
|
||||
<arguments>
|
||||
<dictionary>
|
||||
<key>?name?</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.append_environment</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildArguments</key>
|
||||
<value></value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildCommand</key>
|
||||
<value>make</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.buildLocation</key>
|
||||
<value>${workspace_loc:/wifiHD/Debug}</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.contents</key>
|
||||
<value>org.eclipse.cdt.make.core.activeConfigSettings</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableAutoBuild</key>
|
||||
<value>false</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableCleanBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.enableFullBuild</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.stopOnError</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
<dictionary>
|
||||
<key>org.eclipse.cdt.make.core.useDefaultBuildCmd</key>
|
||||
<value>true</value>
|
||||
</dictionary>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.cdt.managedbuilder.core.ScannerConfigBuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>com.atmel.avr32.core.nature</nature>
|
||||
<nature>org.eclipse.cdt.core.cnature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.managedBuildNature</nature>
|
||||
<nature>org.eclipse.cdt.managedbuilder.core.ScannerConfigNature</nature>
|
||||
</natures>
|
||||
<linkedResources>
|
||||
<link>
|
||||
<name>UC3 Software Framework</name>
|
||||
<type>2</type>
|
||||
<locationURI>framework:/com.atmel.avr32.sf.uc3</locationURI>
|
||||
</link>
|
||||
</linkedResources>
|
||||
</projectDescription>
|
Binary file not shown.
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,170 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Memory access control configuration file.
|
||||
*
|
||||
* This file contains the possible external configuration of the memory access
|
||||
* control.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONF_ACCESS_H_
|
||||
#define _CONF_ACCESS_H_
|
||||
|
||||
#include "compiler.h"
|
||||
#include "board.h"
|
||||
|
||||
|
||||
/*! \name Activation of Logical Unit Numbers
|
||||
*/
|
||||
//! @{
|
||||
#define LUN_0 DISABLE //!< On-Chip Virtual Memory.
|
||||
#define LUN_1 ENABLE //!< AT45DBX Data Flash.
|
||||
#define LUN_2 DISABLE //!< SD/MMC Card over SPI.
|
||||
#define LUN_3 DISABLE
|
||||
#define LUN_4 DISABLE
|
||||
#define LUN_5 DISABLE
|
||||
#define LUN_6 DISABLE
|
||||
#define LUN_7 DISABLE
|
||||
#define LUN_USB DISABLE //!< Host Mass-Storage Memory.
|
||||
//! @}
|
||||
|
||||
/*! \name LUN 0 Definitions
|
||||
*/
|
||||
//! @{
|
||||
#define VIRTUAL_MEM LUN_0
|
||||
#define LUN_ID_VIRTUAL_MEM LUN_ID_0
|
||||
#define LUN_0_INCLUDE "virtual_mem.h"
|
||||
#define Lun_0_test_unit_ready virtual_test_unit_ready
|
||||
#define Lun_0_read_capacity virtual_read_capacity
|
||||
#define Lun_0_wr_protect virtual_wr_protect
|
||||
#define Lun_0_removal virtual_removal
|
||||
#define Lun_0_usb_read_10 virtual_usb_read_10
|
||||
#define Lun_0_usb_write_10 virtual_usb_write_10
|
||||
#define Lun_0_mem_2_ram virtual_mem_2_ram
|
||||
#define Lun_0_ram_2_mem virtual_ram_2_mem
|
||||
#define LUN_0_NAME "\"On-Chip Virtual Memory\""
|
||||
//! @}
|
||||
|
||||
/*! \name LUN 1 Definitions
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_MEM LUN_1
|
||||
#define LUN_ID_AT45DBX_MEM LUN_ID_1
|
||||
#define LUN_1_INCLUDE "at45dbx_mem.h"
|
||||
#define Lun_1_test_unit_ready at45dbx_test_unit_ready
|
||||
#define Lun_1_read_capacity at45dbx_read_capacity
|
||||
#define Lun_1_wr_protect at45dbx_wr_protect
|
||||
#define Lun_1_removal at45dbx_removal
|
||||
#define Lun_1_usb_read_10 at45dbx_usb_read_10
|
||||
#define Lun_1_usb_write_10 at45dbx_usb_write_10
|
||||
#define Lun_1_mem_2_ram at45dbx_df_2_ram
|
||||
#define Lun_1_ram_2_mem at45dbx_ram_2_df
|
||||
#define LUN_1_NAME "\"AT45DBX Data Flash\""
|
||||
//! @}
|
||||
|
||||
/*! \name LUN 2 Definitions
|
||||
*/
|
||||
//! @{
|
||||
#define SD_MMC_SPI_MEM LUN_2
|
||||
#define LUN_ID_SD_MMC_SPI_MEM LUN_ID_2
|
||||
#define LUN_2_INCLUDE "sd_mmc_spi_mem.h"
|
||||
#define Lun_2_test_unit_ready sd_mmc_spi_test_unit_ready
|
||||
#define Lun_2_read_capacity sd_mmc_spi_read_capacity
|
||||
#define Lun_2_wr_protect sd_mmc_spi_wr_protect
|
||||
#define Lun_2_removal sd_mmc_spi_removal
|
||||
#define Lun_2_usb_read_10 sd_mmc_spi_usb_read_10
|
||||
#define Lun_2_usb_write_10 sd_mmc_spi_usb_write_10
|
||||
#define Lun_2_mem_2_ram sd_mmc_spi_mem_2_ram
|
||||
#define Lun_2_ram_2_mem sd_mmc_spi_ram_2_mem
|
||||
#define LUN_2_NAME "\"SD/MMC Card over SPI\""
|
||||
//! @}
|
||||
|
||||
/*! \name USB LUNs Definitions
|
||||
*/
|
||||
//! @{
|
||||
#define MEM_USB LUN_USB
|
||||
#define LUN_ID_MEM_USB LUN_ID_USB
|
||||
#define LUN_USB_INCLUDE "host_mem.h"
|
||||
#define Lun_usb_test_unit_ready(lun) host_test_unit_ready(lun)
|
||||
#define Lun_usb_read_capacity(lun, nb_sect) host_read_capacity(lun, nb_sect)
|
||||
#define Lun_usb_read_sector_size(lun) host_read_sector_size(lun)
|
||||
#define Lun_usb_wr_protect(lun) host_wr_protect(lun)
|
||||
#define Lun_usb_removal() host_removal()
|
||||
#define Lun_usb_mem_2_ram(addr, ram) host_read_10_ram(addr, ram)
|
||||
#define Lun_usb_ram_2_mem(addr, ram) host_write_10_ram(addr, ram)
|
||||
#define LUN_USB_NAME "\"Host Mass-Storage Memory\""
|
||||
//! @}
|
||||
|
||||
/*! \name Actions Associated with Memory Accesses
|
||||
*
|
||||
* Write here the action to associate with each memory access.
|
||||
*
|
||||
* \warning Be careful not to waste time in order not to disturb the functions.
|
||||
*/
|
||||
//! @{
|
||||
#define memory_start_read_action(nb_sectors)
|
||||
#define memory_stop_read_action()
|
||||
#define memory_start_write_action(nb_sectors)
|
||||
#define memory_stop_write_action()
|
||||
//! @}
|
||||
|
||||
/*! \name Activation of Interface Features
|
||||
*/
|
||||
//! @{
|
||||
#define ACCESS_USB DISABLED //!< MEM <-> USB interface.
|
||||
#define ACCESS_MEM_TO_RAM ENABLED //!< MEM <-> RAM interface.
|
||||
#define ACCESS_STREAM ENABLED //!< Streaming MEM <-> MEM interface. //mlf
|
||||
#define ACCESS_STREAM_RECORD DISABLED //!< Streaming MEM <-> MEM interface in record mode.
|
||||
#define ACCESS_MEM_TO_MEM DISABLED //!< MEM <-> MEM interface.
|
||||
#define ACCESS_CODEC DISABLED //!< Codec interface.
|
||||
//! @}
|
||||
|
||||
/*! \name Specific Options for Access Control
|
||||
*/
|
||||
//! @{
|
||||
#define GLOBAL_WR_PROTECT DISABLED //!< Management of a global write protection.
|
||||
//! @}
|
||||
|
||||
|
||||
#endif // _CONF_ACCESS_H_
|
|
@ -0,0 +1,83 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT45DBX configuration file.
|
||||
*
|
||||
* This file contains the possible external configuration of the AT45DBX.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONF_AT45DBX_H_
|
||||
#define _CONF_AT45DBX_H_
|
||||
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
#if AT45DBX_MEM == DISABLE
|
||||
#error conf_at45dbx.h is #included although AT45DBX_MEM is disabled
|
||||
#endif
|
||||
|
||||
|
||||
#include "at45dbx.h"
|
||||
|
||||
|
||||
//_____ D E F I N I T I O N S ______________________________________________
|
||||
|
||||
//! Size of AT45DBX data flash memories to manage.
|
||||
#define AT45DBX_MEM_SIZE AT45DBX_1MB
|
||||
|
||||
//! Number of AT45DBX components to manage.
|
||||
#define AT45DBX_MEM_CNT 1
|
||||
|
||||
//! First chip select used by AT45DBX components on the SPI module instance.
|
||||
//! AT45DBX_SPI_NPCS0_PIN always corresponds to this first NPCS, whatever it is.
|
||||
#define AT45DBX_SPI_FIRST_NPCS AT45DBX_SPI_NPCS
|
||||
|
||||
//! SPI master speed in Hz.
|
||||
#define AT45DBX_SPI_MASTER_SPEED 12000000
|
||||
|
||||
//! Number of bits in each SPI transfer.
|
||||
#define AT45DBX_SPI_BITS 8
|
||||
|
||||
|
||||
#endif // _CONF_AT45DBX_H_
|
|
@ -0,0 +1,108 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief CONF_EBI EBI/SMC driver for AVR32 UC3.
|
||||
*
|
||||
* \note The values defined in this file are device-specific. See the device
|
||||
* datasheet for further information.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SMC module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONF_EBI_H_
|
||||
#define _CONF_EBI_H_
|
||||
|
||||
#include "compiler.h"
|
||||
#include "board.h"
|
||||
|
||||
#if (ET024006DHU_SMC_USE_NCS == 0)
|
||||
#define SMC_USE_NCS0
|
||||
#define SMC_COMPONENT_CS0 ET024006DHU_SMC_COMPONENT_CS
|
||||
#else
|
||||
|
||||
#if (ET024006DHU_SMC_USE_NCS == 2)
|
||||
#define SMC_USE_NCS2
|
||||
#define SMC_COMPONENT_CS2 ET024006DHU_SMC_COMPONENT_CS
|
||||
|
||||
#else
|
||||
#error This board is not supported
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#define EBI_DATA_0 ET024006DHU_EBI_DATA_0
|
||||
#define EBI_DATA_1 ET024006DHU_EBI_DATA_1
|
||||
#define EBI_DATA_2 ET024006DHU_EBI_DATA_2
|
||||
#define EBI_DATA_3 ET024006DHU_EBI_DATA_3
|
||||
#define EBI_DATA_4 ET024006DHU_EBI_DATA_4
|
||||
#define EBI_DATA_5 ET024006DHU_EBI_DATA_5
|
||||
#define EBI_DATA_6 ET024006DHU_EBI_DATA_6
|
||||
#define EBI_DATA_7 ET024006DHU_EBI_DATA_7
|
||||
#define EBI_DATA_8 ET024006DHU_EBI_DATA_8
|
||||
#define EBI_DATA_9 ET024006DHU_EBI_DATA_9
|
||||
#define EBI_DATA_10 ET024006DHU_EBI_DATA_10
|
||||
#define EBI_DATA_11 ET024006DHU_EBI_DATA_11
|
||||
#define EBI_DATA_12 ET024006DHU_EBI_DATA_12
|
||||
#define EBI_DATA_13 ET024006DHU_EBI_DATA_13
|
||||
#define EBI_DATA_14 ET024006DHU_EBI_DATA_14
|
||||
#define EBI_DATA_15 ET024006DHU_EBI_DATA_15
|
||||
|
||||
#if BOARD==EVK1105
|
||||
#ifdef EVK1105_REV3
|
||||
#define EBI_ADDR_19 AVR32_EBI_ADDR_19
|
||||
#define EBI_NCS_2 ET024006DHU_EBI_NCS
|
||||
#else
|
||||
#define EBI_ADDR_21 ET024006DHU_EBI_ADDR_21
|
||||
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||
#endif
|
||||
#elif BOARD == UC3C_EK
|
||||
#define EBI_ADDR_22 AVR32_EBI_ADDR_22
|
||||
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||
#elif BOARD == EVK1104
|
||||
#define EBI_ADDR_21 ET024006DHU_EBI_ADDR_21
|
||||
#define EBI_NCS_0 ET024006DHU_EBI_NCS
|
||||
#endif
|
||||
|
||||
|
||||
#define EBI_NWE0 ET024006DHU_EBI_NWE
|
||||
#define EBI_NRD ET024006DHU_EBI_NRD
|
||||
|
||||
#endif // _CONF_EBI_H_
|
|
@ -0,0 +1,73 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief SD/MMC configuration file.
|
||||
*
|
||||
* This file contains the possible external configuration of the SD/MMC.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CONF_SD_MMC_SPI_H_
|
||||
#define _CONF_SD_MMC_SPI_H_
|
||||
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
#if SD_MMC_SPI_MEM == DISABLE
|
||||
#error conf_sd_mmc_spi.h is #included although SD_MMC_SPI_MEM is disabled
|
||||
#endif
|
||||
|
||||
|
||||
#include "sd_mmc_spi.h"
|
||||
|
||||
|
||||
//_____ D E F I N I T I O N S ______________________________________________
|
||||
|
||||
//! SPI master speed in Hz.
|
||||
#define SD_MMC_SPI_MASTER_SPEED 12000000
|
||||
|
||||
//! Number of bits in each SPI transfer.
|
||||
#define SD_MMC_SPI_BITS 8
|
||||
|
||||
|
||||
#endif // _CONF_SD_MMC_SPI_H_
|
|
@ -0,0 +1,74 @@
|
|||
/* This file is part of the ATMEL AVR32-SoftwareFramework-AT32UC3A-1.4.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AVR32 UC3 ISP trampoline.
|
||||
*
|
||||
* In order to be able to program a project with both BatchISP and JTAGICE mkII
|
||||
* without having to take the general-purpose fuses into consideration, add this
|
||||
* file to the project and change the program entry point to _trampoline.
|
||||
*
|
||||
* The pre-programmed ISP will be erased if JTAGICE mkII is used.
|
||||
*
|
||||
* - Compiler: GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32UC devices can be used.
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (C) 2006-2008, Atmel Corporation All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of ATMEL may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE EXPRESSLY AND
|
||||
* SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
||||
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
|
||||
#include "conf_isp.h"
|
||||
|
||||
|
||||
//! @{
|
||||
//! \verbatim
|
||||
|
||||
|
||||
// This must be linked @ 0x80000000 if it is to be run upon reset.
|
||||
.section .reset, "ax", @progbits
|
||||
|
||||
|
||||
.global _trampoline
|
||||
.type _trampoline, @function
|
||||
_trampoline:
|
||||
// Jump to program start.
|
||||
rjmp program_start
|
||||
|
||||
.org PROGRAM_START_OFFSET
|
||||
program_start:
|
||||
// Jump to the C runtime startup routine.
|
||||
lda.w pc, _stext
|
||||
|
||||
|
||||
//! \endverbatim
|
||||
//! @}
|
|
@ -0,0 +1,237 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1100 board header file.
|
||||
*
|
||||
* This file contains definitions and services related to the features of the
|
||||
* EVK1100 board rev. B and C.
|
||||
*
|
||||
* To use this board, define BOARD=EVK1100.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _ARDUINO_H_
|
||||
#define _ARDUINO_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
|
||||
# include "led.h"
|
||||
#endif // __AVR32_ABI_COMPILER__
|
||||
|
||||
|
||||
/*! \name Oscillator Definitions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
// RCOsc has no custom calibration by default. Set the following definition to
|
||||
// the appropriate value if a custom RCOsc calibration has been applied to your
|
||||
// part.
|
||||
//#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< RCOsc frequency: Hz.
|
||||
|
||||
#define FOSC32 32768 //!< Osc32 frequency: Hz.
|
||||
#define OSC32_STARTUP AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC //!< Osc32 startup time: RCOsc periods.
|
||||
|
||||
#define FOSC0 12000000 //!< Osc0 frequency: Hz.
|
||||
#define OSC0_STARTUP AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC //!< Osc0 startup time: RCOsc periods.
|
||||
|
||||
// Osc1 crystal is not mounted by default. Set the following definitions to the
|
||||
// appropriate values if a custom Osc1 crystal is mounted on your board.
|
||||
//#define FOSC1 12000000 //!< Osc1 frequency: Hz.
|
||||
//#define OSC1_STARTUP AVR32_PM_OSCCTRL1_STARTUP_2048_RCOSC //!< Osc1 startup time: RCOsc periods.
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
//! Number of LEDs.
|
||||
#define LED_COUNT 0
|
||||
|
||||
/*! \name GPIO Connections of LEDs
|
||||
*/
|
||||
//! @{
|
||||
#define LED0_GPIO AVR32_PIN_PB19
|
||||
#define LED1_GPIO AVR32_PIN_PB20
|
||||
#define LED2_GPIO AVR32_PIN_PB21
|
||||
#define DEB_PIN_GPIO AVR32_PIN_PA20
|
||||
#define DEB2_PIN_GPIO AVR32_PIN_PB00
|
||||
//! @}
|
||||
|
||||
/*! \name PWM Channels of LEDs
|
||||
*/
|
||||
//! @{
|
||||
#define LED0_PWM 0
|
||||
#define LED1_PWM 1
|
||||
#define LED2_PWM 2
|
||||
//! @}
|
||||
|
||||
/*! \name PWM Functions of LEDs
|
||||
*/
|
||||
//! @{
|
||||
#define LED0_PWM_FUNCTION AVR32_PWM_0_FUNCTION
|
||||
#define LED1_PWM_FUNCTION AVR32_PWM_1_FUNCTION
|
||||
#define LED2_PWM_FUNCTION AVR32_PWM_2_FUNCTION
|
||||
//! @}
|
||||
|
||||
/*! \name Color Identifiers of LEDs to Use with LED Functions
|
||||
*/
|
||||
//! @{
|
||||
#define LED_MONO0_GREEN LED0
|
||||
#define LED_MONO1_RED LED1
|
||||
#define LED_MONO2_BLU LED2
|
||||
//! @}
|
||||
|
||||
#if 0
|
||||
/*! \name SPI Connections of the DIP204 LCD
|
||||
*/
|
||||
//! @{
|
||||
#define DIP204_SPI (&AVR32_SPI1)
|
||||
#define DIP204_SPI_NPCS 2
|
||||
#define DIP204_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||
#define DIP204_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||
#define DIP204_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||
#define DIP204_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||
#define DIP204_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||
#define DIP204_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||
#define DIP204_SPI_NPCS_PIN AVR32_SPI1_NPCS_2_0_PIN
|
||||
#define DIP204_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_2_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
/*! \name GPIO and PWM Connections of the DIP204 LCD Backlight
|
||||
*/
|
||||
//! @{
|
||||
#define DIP204_BACKLIGHT_PIN AVR32_PIN_PB18
|
||||
#define DIP204_PWM_CHANNEL 6
|
||||
#define DIP204_PWM_PIN AVR32_PWM_6_PIN
|
||||
#define DIP204_PWM_FUNCTION AVR32_PWM_6_FUNCTION
|
||||
//! @}
|
||||
#endif
|
||||
|
||||
/*! \name SPI Connections of the AT45DBX Data Flash Memory
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_SPI (&AVR32_SPI1)
|
||||
#define AT45DBX_SPI_NPCS 2
|
||||
#define AT45DBX_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||
#define AT45DBX_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||
#define AT45DBX_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||
#define AT45DBX_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_NPCS2_PIN AVR32_SPI1_NPCS_2_0_PIN
|
||||
#define AT45DBX_SPI_NPCS2_FUNCTION AVR32_SPI1_NPCS_2_0_FUNCTION
|
||||
#define AT45DBX_CHIP_RESET AVR32_PIN_PA02
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name GPIO and SPI Connections of the SD/MMC Connector
|
||||
*/
|
||||
//! @{
|
||||
//#define SD_MMC_CARD_DETECT_PIN AVR32_PIN_PA02
|
||||
//#define SD_MMC_WRITE_PROTECT_PIN AVR32_PIN_PA07
|
||||
#define SD_MMC_SPI (&AVR32_SPI1)
|
||||
#define SD_MMC_SPI_NPCS 1
|
||||
#define SD_MMC_SPI_SCK_PIN AVR32_SPI1_SCK_0_0_PIN
|
||||
#define SD_MMC_SPI_SCK_FUNCTION AVR32_SPI1_SCK_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_MISO_PIN AVR32_SPI1_MISO_0_0_PIN
|
||||
#define SD_MMC_SPI_MISO_FUNCTION AVR32_SPI1_MISO_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_MOSI_PIN AVR32_SPI1_MOSI_0_0_PIN
|
||||
#define SD_MMC_SPI_MOSI_FUNCTION AVR32_SPI1_MOSI_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_NPCS_PIN AVR32_SPI1_NPCS_1_0_PIN
|
||||
#define SD_MMC_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_1_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
/* Timer Counter to generate clock for WiFi chip*/
|
||||
# define WIFI_TC (&AVR32_TC)
|
||||
# define WIFI_TC_CHANNEL_ID 0
|
||||
# define WIFI_TC_CHANNEL_PIN AVR32_TC_A0_0_0_PIN
|
||||
# define WIFI_TC_CHANNEL_FUNCTION AVR32_TC_A0_0_0_FUNCTION
|
||||
// Note that TC_A0_0_0 pin is pin 6 (PB23) on AT32UC3A1512 QFP100.
|
||||
|
||||
/* Pin related to WiFi chip communication */
|
||||
#ifndef USE_POLL
|
||||
#define USE_POLL
|
||||
#endif
|
||||
#define SPI_CS 0
|
||||
#define AVR32_SPI AVR32_SPI1
|
||||
#define GPIO_IRQ_PIN AVR32_PIN_PA03
|
||||
#define GPIO_IRQ AVR32_GPIO_IRQ_7
|
||||
#define GPIO_W_RESET_PIN AVR32_PIN_PA07
|
||||
#define GPIO_W_SHUTDOWN_PIN AVR32_PIN_PA09
|
||||
|
||||
/* Pin related to shield communication */
|
||||
#define ARDUINO_HANDSHAKE_PIN AVR32_PIN_PA25
|
||||
#define ARDUINO_EXTINT_PIN AVR32_PIN_PA04 //not used
|
||||
|
||||
#define AVR32_PDCA_PID_TX AVR32_PDCA_PID_SPI1_TX
|
||||
#define AVR32_PDCA_PID_RX AVR32_PDCA_PID_SPI1_RX
|
||||
|
||||
|
||||
#if 0
|
||||
/*! \name TWI Connections of the Spare TWI Connector
|
||||
*/
|
||||
//! @{
|
||||
#define SPARE_TWI (&AVR32_TWI)
|
||||
#define SPARE_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||
#define SPARE_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||
#define SPARE_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||
#define SPARE_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name SPI Connections of the Spare SPI Connector
|
||||
*/
|
||||
//! @{
|
||||
#define SPARE_SPI (&AVR32_SPI0)
|
||||
#define SPARE_SPI_NPCS 0
|
||||
#define SPARE_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define SPARE_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define SPARE_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define SPARE_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define SPARE_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define SPARE_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define SPARE_SPI_NPCS_PIN AVR32_SPI0_NPCS_0_0_PIN
|
||||
#define SPARE_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
|
||||
//! @}
|
||||
#endif
|
||||
|
||||
#endif // _ARDUINO_H_
|
|
@ -0,0 +1,346 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1100 board LEDs support package.
|
||||
*
|
||||
* This file contains definitions and services related to the LED features of
|
||||
* the EVK1100 board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#include <avr32/io.h>
|
||||
#include "preprocessor.h"
|
||||
#include "compiler.h"
|
||||
#include "arduino.h"
|
||||
#include "led.h"
|
||||
|
||||
|
||||
//! Structure describing LED hardware connections.
|
||||
typedef const struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
U32 PORT; //!< LED GPIO port.
|
||||
U32 PIN_MASK; //!< Bit-mask of LED pin in GPIO port.
|
||||
} GPIO; //!< LED GPIO descriptor.
|
||||
struct
|
||||
{
|
||||
S32 CHANNEL; //!< LED PWM channel (< 0 if N/A).
|
||||
S32 FUNCTION; //!< LED pin PWM function (< 0 if N/A).
|
||||
} PWM; //!< LED PWM descriptor.
|
||||
} tLED_DESCRIPTOR;
|
||||
|
||||
|
||||
//! Hardware descriptors of all LEDs.
|
||||
static tLED_DESCRIPTOR LED_DESCRIPTOR[LED_COUNT] =
|
||||
{
|
||||
#define INSERT_LED_DESCRIPTOR(LED_NO, unused) \
|
||||
{ \
|
||||
{LED##LED_NO##_GPIO / 32, 1 << (LED##LED_NO##_GPIO % 32)},\
|
||||
{LED##LED_NO##_PWM, LED##LED_NO##_PWM_FUNCTION } \
|
||||
},
|
||||
MREPEAT(LED_COUNT, INSERT_LED_DESCRIPTOR, ~)
|
||||
#undef INSERT_LED_DESCRIPTOR
|
||||
};
|
||||
|
||||
|
||||
//! Saved state of all LEDs.
|
||||
static volatile U32 LED_State = (1 << LED_COUNT) - 1;
|
||||
|
||||
|
||||
U32 LED_Read_Display(void)
|
||||
{
|
||||
return LED_State;
|
||||
}
|
||||
|
||||
|
||||
void LED_Display(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
LED_State = leds;
|
||||
|
||||
// For all LEDs...
|
||||
for (led_descriptor = &LED_DESCRIPTOR[0];
|
||||
led_descriptor < LED_DESCRIPTOR + LED_COUNT;
|
||||
led_descriptor++)
|
||||
{
|
||||
// Set the LED to the requested state.
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
if (leds & 1)
|
||||
{
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U32 LED_Read_Display_Mask(U32 mask)
|
||||
{
|
||||
return Rd_bits(LED_State, mask);
|
||||
}
|
||||
|
||||
|
||||
void LED_Display_Mask(U32 mask, U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
mask &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Wr_bits(LED_State, mask, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (mask)
|
||||
{
|
||||
// Select the next specified LED and set it to the requested state.
|
||||
led_shift = 1 + ctz(mask);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
leds >>= led_shift - 1;
|
||||
if (leds & 1)
|
||||
{
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= 1;
|
||||
mask >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bool LED_Test(U32 leds)
|
||||
{
|
||||
return Tst_bits(LED_State, leds);
|
||||
}
|
||||
|
||||
|
||||
void LED_Off(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Clr_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and turn it off.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LED_On(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Set_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and turn it on.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LED_Toggle(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Tgl_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and toggle it.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U32 LED_Read_Display_Field(U32 field)
|
||||
{
|
||||
return Rd_bitfield(LED_State, field);
|
||||
}
|
||||
|
||||
|
||||
void LED_Display_Field(U32 field, U32 leds)
|
||||
{
|
||||
// Move the bit-field to the appropriate position for the bit-mask.
|
||||
LED_Display_Mask(field, leds << ctz(field));
|
||||
}
|
||||
|
||||
|
||||
U8 LED_Get_Intensity(U32 led)
|
||||
{
|
||||
tLED_DESCRIPTOR *led_descriptor;
|
||||
|
||||
// Check that the argument value is valid.
|
||||
led = ctz(led);
|
||||
led_descriptor = &LED_DESCRIPTOR[led];
|
||||
if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0;
|
||||
|
||||
// Return the duty cycle value if the LED PWM channel is enabled, else 0.
|
||||
return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ?
|
||||
AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0;
|
||||
}
|
||||
|
||||
|
||||
void LED_Set_Intensity(U32 leds, U8 intensity)
|
||||
{
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_pwm_channel_t *led_pwm_channel;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// For each specified LED...
|
||||
for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift)
|
||||
{
|
||||
// Select the next specified LED and check that it has a PWM channel.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
if (led_descriptor->PWM.CHANNEL < 0) continue;
|
||||
|
||||
// Initialize or update the LED PWM channel.
|
||||
led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL];
|
||||
if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)))
|
||||
{
|
||||
led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) &
|
||||
~(AVR32_PWM_CALG_MASK |
|
||||
AVR32_PWM_CPOL_MASK |
|
||||
AVR32_PWM_CPD_MASK);
|
||||
led_pwm_channel->cprd = 0x000000FF;
|
||||
led_pwm_channel->cdty = intensity;
|
||||
AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR32_PWM.isr;
|
||||
while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL)));
|
||||
led_pwm_channel->cupd = intensity;
|
||||
}
|
||||
|
||||
// Switch the LED pin to its PWM function.
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
if (led_descriptor->PWM.FUNCTION & 0x1)
|
||||
{
|
||||
led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
if (led_descriptor->PWM.FUNCTION & 0x2)
|
||||
{
|
||||
led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,191 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1100 board LEDs support package.
|
||||
*
|
||||
* This file contains definitions and services related to the LED features of
|
||||
* the EVK1100 board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LED_H_
|
||||
#define _LED_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
|
||||
/*! \name Identifiers of LEDs to Use with LED Functions
|
||||
*/
|
||||
//! @{
|
||||
#define LED0 0x01
|
||||
#define LED1 0x02
|
||||
#define LED2 0x04
|
||||
#define LED3 0x08
|
||||
#define LED4 0x10
|
||||
#define LED5 0x20
|
||||
#define LED6 0x40
|
||||
#define LED7 0x80
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \brief Gets the last state of all LEDs set through the LED API.
|
||||
*
|
||||
* \return State of all LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display(void);
|
||||
|
||||
/*! \brief Sets the state of all LEDs.
|
||||
*
|
||||
* \param leds New state of all LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The pins of all LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display(U32 leds);
|
||||
|
||||
/*! \brief Gets the last state of the specified LEDs set through the LED API.
|
||||
*
|
||||
* \param mask LEDs of which to get the state (1 bit per LED).
|
||||
*
|
||||
* \return State of the specified LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display_Mask(U32 mask);
|
||||
|
||||
/*! \brief Sets the state of the specified LEDs.
|
||||
*
|
||||
* \param mask LEDs of which to set the state (1 bit per LED).
|
||||
*
|
||||
* \param leds New state of the specified LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display_Mask(U32 mask, U32 leds);
|
||||
|
||||
/*! \brief Tests the last state of the specified LEDs set through the LED API.
|
||||
*
|
||||
* \param leds LEDs of which to test the state (1 bit per LED).
|
||||
*
|
||||
* \return \c TRUE if at least one of the specified LEDs has a state on, else
|
||||
* \c FALSE.
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern Bool LED_Test(U32 leds);
|
||||
|
||||
/*! \brief Turns off the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to turn off (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Off(U32 leds);
|
||||
|
||||
/*! \brief Turns on the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to turn on (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_On(U32 leds);
|
||||
|
||||
/*! \brief Toggles the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to toggle (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Toggle(U32 leds);
|
||||
|
||||
/*! \brief Gets as a bit-field the last state of the specified LEDs set through
|
||||
* the LED API.
|
||||
*
|
||||
* \param field LEDs of which to get the state (1 bit per LED).
|
||||
*
|
||||
* \return State of the specified LEDs (1 bit per LED, beginning with the first
|
||||
* specified LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display_Field(U32 field);
|
||||
|
||||
/*! \brief Sets as a bit-field the state of the specified LEDs.
|
||||
*
|
||||
* \param field LEDs of which to set the state (1 bit per LED).
|
||||
* \param leds New state of the specified LEDs (1 bit per LED, beginning with
|
||||
* the first specified LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display_Field(U32 field, U32 leds);
|
||||
|
||||
/*! \brief Gets the intensity of the specified LED.
|
||||
*
|
||||
* \param led LED of which to get the intensity (1 bit per LED; only the least
|
||||
* significant set bit is used).
|
||||
*
|
||||
* \return Intensity of the specified LED (0x00 to 0xFF).
|
||||
*
|
||||
* \warning The PWM channel of the specified LED is supposed to be used only by
|
||||
* this module.
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U8 LED_Get_Intensity(U32 led);
|
||||
|
||||
/*! \brief Sets the intensity of the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs of which to set the intensity (1 bit per LED).
|
||||
* \param intensity New intensity of the specified LEDs (0x00 to 0xFF).
|
||||
*
|
||||
* \warning The PWM channels of the specified LEDs are supposed to be used only
|
||||
* by this module.
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to PWM output mode.
|
||||
*/
|
||||
extern void LED_Set_Intensity(U32 leds, U8 intensity);
|
||||
|
||||
|
||||
#endif // _LED_H_
|
|
@ -0,0 +1,433 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1105 board header file.
|
||||
*
|
||||
* This file contains definitions and services related to the features of the
|
||||
* EVK1105 board rev. B.
|
||||
*
|
||||
* To use this board, define BOARD=EVK1105.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _EVK1105_H_
|
||||
#define _EVK1105_H_
|
||||
|
||||
#ifdef EVK1105_REV3
|
||||
# include "evk1105_rev3.h"
|
||||
#else
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
#ifdef __AVR32_ABI_COMPILER__ // Automatically defined when compiling for AVR32, not when assembling.
|
||||
# include "led.h"
|
||||
#endif // __AVR32_ABI_COMPILER__
|
||||
|
||||
|
||||
/*! \name Oscillator Definitions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
// RCOsc has no custom calibration by default. Set the following definition to
|
||||
// the appropriate value if a custom RCOsc calibration has been applied to your
|
||||
// part.
|
||||
//#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< RCOsc frequency: Hz.
|
||||
|
||||
#define FOSC32 32768 //!< Osc32 frequency: Hz.
|
||||
#define OSC32_STARTUP AVR32_PM_OSCCTRL32_STARTUP_8192_RCOSC //!< Osc32 startup time: RCOsc periods.
|
||||
|
||||
#define FOSC0 12000000 //!< Osc0 frequency: Hz.
|
||||
#define OSC0_STARTUP AVR32_PM_OSCCTRL0_STARTUP_2048_RCOSC //!< Osc0 startup time: RCOsc periods.
|
||||
|
||||
#define FOSC1 11289600 //!< Osc1 frequency: Hz
|
||||
#define OSC1_STARTUP AVR32_PM_OSCCTRL1_STARTUP_2048_RCOSC //!< Osc1 startup time: RCOsc periods.
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name SDRAM Definitions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
//! Part header file of used SDRAM(s).
|
||||
#define SDRAM_PART_HDR "MT48LC16M16A2TG7E/mt48lc16m16a2tg7e.h"
|
||||
|
||||
//! Data bus width to use the SDRAM(s) with (16 or 32 bits; always 16 bits on
|
||||
//! UC3).
|
||||
#define SDRAM_DBW 16
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name USB Definitions
|
||||
*/
|
||||
//! @{
|
||||
//! Multiplexed pin used for USB_ID: AVR32_USBB_USB_ID_x_x.
|
||||
//! To be selected according to the AVR32_USBB_USB_ID_x_x_PIN and
|
||||
//! AVR32_USBB_USB_ID_x_x_FUNCTION definitions from <avr32/uc3axxxx.h>.
|
||||
#define AVR32_USBB_USB_ID_0_2_PIN 21
|
||||
#define AVR32_USBB_USB_ID_0_2_FUNCTION 2
|
||||
#define USB_ID AVR32_USBB_USB_ID_0_2
|
||||
|
||||
//! Multiplexed pin used for USB_VBOF: AVR32_USBB_USB_VBOF_x_x.
|
||||
//! To be selected according to the AVR32_USBB_USB_VBOF_x_x_PIN and
|
||||
//! AVR32_USBB_USB_VBOF_x_x_FUNCTION definitions from <avr32/uc3axxxx.h>.
|
||||
# define USB_VBOF AVR32_USBB_USB_VBOF_0_1
|
||||
|
||||
|
||||
//! Active level of the USB_VBOF output pin.
|
||||
# define USB_VBOF_ACTIVE_LEVEL LOW
|
||||
|
||||
//! USB overcurrent detection pin.
|
||||
# define USB_OVERCURRENT_DETECT_PIN AVR32_PIN_PX15
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
//! GPIO connection of the MAC PHY PWR_DOWN/INT signal.
|
||||
# define MACB_INTERRUPT_PIN AVR32_PIN_PA26
|
||||
|
||||
|
||||
|
||||
//! Number of LEDs.
|
||||
#define LED_COUNT 4
|
||||
|
||||
/*! \name GPIO Connections of LEDs
|
||||
*/
|
||||
//! @{
|
||||
# define LED0_GPIO AVR32_PIN_PB27
|
||||
# define LED1_GPIO AVR32_PIN_PB28
|
||||
# define LED2_GPIO AVR32_PIN_PA05
|
||||
# define LED3_GPIO AVR32_PIN_PA06
|
||||
//! @}
|
||||
|
||||
/*! \name Color Identifiers of LEDs to Use with LED Functions
|
||||
*/
|
||||
//! @{
|
||||
#define LED_MONO0_GREEN LED0
|
||||
#define LED_MONO1_GREEN LED1
|
||||
#define LED_MONO2_GREEN LED2
|
||||
#define LED_MONO3_GREEN LED3
|
||||
//! @}
|
||||
|
||||
/*! \name PWM Channels of LEDs
|
||||
*/
|
||||
//! @{
|
||||
#define LED0_PWM 4
|
||||
#define LED1_PWM 5
|
||||
#define LED2_PWM (-1)
|
||||
#define LED3_PWM (-1)
|
||||
//! @}
|
||||
|
||||
/*! \name PWM Functions of LEDs
|
||||
*/
|
||||
//! @{
|
||||
/* TODO: Implement PWM functionality */
|
||||
#define LED0_PWM_FUNCTION (-1)//AVR32_PWM_0_FUNCTION
|
||||
#define LED1_PWM_FUNCTION (-1)//AVR32_PWM_1_FUNCTION
|
||||
#define LED2_PWM_FUNCTION (-1)
|
||||
#define LED3_PWM_FUNCTION (-1)
|
||||
//! @}
|
||||
|
||||
//! External interrupt connection of touch sensor.
|
||||
#define QT1081_EIC_EXTINT_PIN AVR32_EIC_EXTINT_1_PIN
|
||||
#define QT1081_EIC_EXTINT_FUNCTION AVR32_EIC_EXTINT_1_FUNCTION
|
||||
#define QT1081_EIC_EXTINT_IRQ AVR32_EIC_IRQ_1
|
||||
#define QT1081_EIC_EXTINT_INT AVR32_EIC_INT1
|
||||
/*! \name Touch sensor low power mode select
|
||||
*/
|
||||
#define QT1081_LP_MODE AVR32_PIN_PB29
|
||||
|
||||
/*! \name GPIO Connections of touch buttons
|
||||
*/
|
||||
//! @{
|
||||
#define QT1081_TOUCH_SENSOR_0 AVR32_PIN_PB22
|
||||
#define QT1081_TOUCH_SENSOR_0_PRESSED 1
|
||||
#define QT1081_TOUCH_SENSOR_1 AVR32_PIN_PB23
|
||||
#define QT1081_TOUCH_SENSOR_1_PRESSED 1
|
||||
#define QT1081_TOUCH_SENSOR_2 AVR32_PIN_PB24
|
||||
#define QT1081_TOUCH_SENSOR_2_PRESSED 1
|
||||
#define QT1081_TOUCH_SENSOR_3 AVR32_PIN_PB25
|
||||
#define QT1081_TOUCH_SENSOR_3_PRESSED 1
|
||||
#define QT1081_TOUCH_SENSOR_4 AVR32_PIN_PB26
|
||||
#define QT1081_TOUCH_SENSOR_4_PRESSED 1
|
||||
|
||||
#define QT1081_TOUCH_SENSOR_ENTER QT1081_TOUCH_SENSOR_4
|
||||
#define QT1081_TOUCH_SENSOR_ENTER_PRESSED QT1081_TOUCH_SENSOR_4_PRESSED
|
||||
#define QT1081_TOUCH_SENSOR_LEFT QT1081_TOUCH_SENSOR_3
|
||||
#define QT1081_TOUCH_SENSOR_LEFT_PRESSED QT1081_TOUCH_SENSOR_3_PRESSED
|
||||
#define QT1081_TOUCH_SENSOR_RIGHT QT1081_TOUCH_SENSOR_2
|
||||
#define QT1081_TOUCH_SENSOR_RIGHT_PRESSED QT1081_TOUCH_SENSOR_2_PRESSED
|
||||
#define QT1081_TOUCH_SENSOR_UP QT1081_TOUCH_SENSOR_0
|
||||
#define QT1081_TOUCH_SENSOR_UP_PRESSED QT1081_TOUCH_SENSOR_0_PRESSED
|
||||
#define QT1081_TOUCH_SENSOR_DOWN QT1081_TOUCH_SENSOR_1
|
||||
#define QT1081_TOUCH_SENSOR_DOWN_PRESSED QT1081_TOUCH_SENSOR_1_PRESSED
|
||||
//! @}
|
||||
|
||||
/*! \name SPI Connections of the AT45DBX Data Flash Memory
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_SPI (&AVR32_SPI0)
|
||||
#define AT45DBX_SPI_NPCS 0
|
||||
#define AT45DBX_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define AT45DBX_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define AT45DBX_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define AT45DBX_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define AT45DBX_SPI_NPCS0_PIN AVR32_SPI0_NPCS_0_0_PIN
|
||||
#define AT45DBX_SPI_NPCS0_FUNCTION AVR32_SPI0_NPCS_0_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
/*! \name GPIO and SPI Connections of the SD/MMC Connector
|
||||
*/
|
||||
//! @{
|
||||
#define SD_MMC_CARD_DETECT_PIN AVR32_PIN_PA02
|
||||
#define SD_MMC_WRITE_PROTECT_PIN AVR32_PIN_PA18
|
||||
#define SD_MMC_SPI (&AVR32_SPI0)
|
||||
#define SD_MMC_SPI_NPCS 1
|
||||
#define SD_MMC_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define SD_MMC_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define SD_MMC_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define SD_MMC_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define SD_MMC_SPI_NPCS_PIN AVR32_SPI0_NPCS_1_0_PIN
|
||||
#define SD_MMC_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_1_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name TWI expansion
|
||||
*/
|
||||
//! @{
|
||||
#define EXPANSION_TWI (&AVR32_TWI)
|
||||
#define EXPANSION_RESET AVR32_PIN_PX16
|
||||
#define EXPANSION_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||
#define EXPANSION_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||
#define EXPANSION_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||
#define EXPANSION_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
/*! \name Wireless expansion
|
||||
*/
|
||||
|
||||
#define WEXPANSION_EXTINT_PIN AVR32_EIC_EXTINT_8_PIN
|
||||
#define WEXPANSION_EXTINT_FUNCTION AVR32_EIC_EXTINT_8_FUNCTION
|
||||
#define WEXPANSION_GPIO1 AVR32_PIN_PB30
|
||||
#define WEXPANSION_GPIO2 AVR32_PIN_PB31
|
||||
|
||||
#define WEXPANSION_SPI (&AVR32_SPI0)
|
||||
#define WEXPANSION_SPI_NPCS 2
|
||||
#define WEXPANSION_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define WEXPANSION_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define WEXPANSION_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define WEXPANSION_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define WEXPANSION_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define WEXPANSION_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define WEXPANSION_SPI_NPCS_PIN AVR32_SPI0_NPCS_2_0_PIN
|
||||
#define WEXPANSION_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_2_0_FUNCTION
|
||||
|
||||
//! @}
|
||||
|
||||
/*! \name ET024006DHU TFT display
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define ET024006DHU_TE_PIN AVR32_PIN_PX19
|
||||
#define ET024006DHU_RESET_PIN AVR32_PIN_PX22
|
||||
#define ET024006DHU_BL_PIN AVR32_PWM_6_PIN
|
||||
#define ET024006DHU_BL_FUNCTION AVR32_PWM_6_FUNCTION
|
||||
#define ET024006DHU_DNC_PIN AVR32_EBI_ADDR_21_1_PIN
|
||||
#define ET024006DHU_DNC_FUNCTION AVR32_EBI_ADDR_21_1_FUNCTION
|
||||
#define ET024006DHU_EBI_NCS_PIN AVR32_EBI_NCS_0_1_PIN
|
||||
#define ET024006DHU_EBI_NCS_FUNCTION AVR32_EBI_NCS_0_1_FUNCTION
|
||||
|
||||
//! @}
|
||||
/*! \name Optional SPI connection to the TFT
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define ET024006DHU_SPI (&AVR32_SPI0)
|
||||
#define ET024006DHU_SPI_NPCS 3
|
||||
#define ET024006DHU_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define ET024006DHU_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define ET024006DHU_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define ET024006DHU_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define ET024006DHU_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define ET024006DHU_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define ET024006DHU_SPI_NPCS_PIN AVR32_SPI1_NPCS_3_0_PIN
|
||||
#define ET024006DHU_SPI_NPCS_FUNCTION AVR32_SPI1_NPCS_3_0_FUNCTION
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Audio amplifier connection to the DAC
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define TPA6130_ABDAC (&AVR32_ABDAC)
|
||||
|
||||
#define TPA6130_DATA0_PIN AVR32_ABDAC_DATA_0_1_PIN
|
||||
#define TPA6130_DATA0_FUNCTION AVR32_ABDAC_DATA_0_1_FUNCTION
|
||||
#define TPA6130_DATAN0_PIN AVR32_ABDAC_DATAN_0_1_PIN
|
||||
#define TPA6130_DATAN0_FUNCTION AVR32_ABDAC_DATAN_0_1_FUNCTION
|
||||
#define TPA6130_DATA1_PIN AVR32_ABDAC_DATA_1_1_PIN
|
||||
#define TPA6130_DATA1_FUNCTION AVR32_ABDAC_DATA_1_1_FUNCTION
|
||||
#define TPA6130_DATAN1_PIN AVR32_ABDAC_DATAN_1_1_PIN
|
||||
#define TPA6130_DATAN1_FUNCTION AVR32_ABDAC_DATAN_1_1_FUNCTION
|
||||
|
||||
#define TPA6130_ABDAC_PDCA_PID AVR32_PDCA_PID_ABDAC_TX
|
||||
#define TPA6130_ABDAC_PDCA_CHANNEL 0
|
||||
#define TPA6130_ABDAC_PDCA_IRQ AVR32_PDCA_IRQ_0
|
||||
#define TPA6130_ABDAC_PDCA_INT_LEVEL AVR32_INTC_INT3
|
||||
|
||||
#define TPA6130_TWI (&AVR32_TWI)
|
||||
#define TPA6130_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||
#define TPA6130_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||
#define TPA6130_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||
#define TPA6130_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||
|
||||
//! }@
|
||||
/*! \name TI TLV320AIC23B sound chip
|
||||
*/
|
||||
//! @{
|
||||
#define TLV320_SSC (&AVR32_SSC)
|
||||
#define TLV320_SSC_TX_CLOCK_PIN AVR32_SSC_TX_CLOCK_0_PIN
|
||||
#define TLV320_SSC_TX_CLOCK_FUNCTION AVR32_SSC_TX_CLOCK_0_FUNCTION
|
||||
#define TLV320_SSC_TX_DATA_PIN AVR32_SSC_TX_DATA_0_PIN
|
||||
#define TLV320_SSC_TX_DATA_FUNCTION AVR32_SSC_TX_DATA_0_FUNCTION
|
||||
#define TLV320_SSC_TX_FRAME_SYNC_PIN AVR32_SSC_TX_FRAME_SYNC_0_PIN
|
||||
#define TLV320_SSC_TX_FRAME_SYNC_FUNCTION AVR32_SSC_TX_FRAME_SYNC_0_FUNCTION
|
||||
|
||||
#define TLV320_TWI (&AVR32_TWI)
|
||||
#define TLV320_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||
#define TLV320_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||
#define TLV320_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||
#define TLV320_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||
|
||||
#define TLV320_PM_GCLK_PIN AVR32_PM_GCLK_0_0_PIN
|
||||
#define TLV320_PM_GCLK_FUNCTION AVR32_PM_GCLK_0_0_FUNCTION
|
||||
//! @}
|
||||
|
||||
////! \name SPI: Apple Authentication Chip Hardware Connections
|
||||
////! @{
|
||||
#define IPOD_AUTH_CHIP_SPI (&AVR32_SPI0)
|
||||
#define IPOD_AUTH_CHIP_SPI_IRQ AVR32_SPI0_IRQ
|
||||
#define IPOD_AUTH_CHIP_SPI_NPCS 2
|
||||
#define IPOD_AUTH_CHIP_SPI_SCK_PIN AVR32_SPI0_SCK_0_0_PIN
|
||||
#define IPOD_AUTH_CHIP_SPI_SCK_FUNCTION AVR32_SPI0_SCK_0_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_SPI_MISO_PIN AVR32_SPI0_MISO_0_0_PIN
|
||||
#define IPOD_AUTH_CHIP_SPI_MISO_FUNCTION AVR32_SPI0_MISO_0_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_SPI_MOSI_PIN AVR32_SPI0_MOSI_0_0_PIN
|
||||
#define IPOD_AUTH_CHIP_SPI_MOSI_FUNCTION AVR32_SPI0_MOSI_0_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_SPI_NPCS_PIN AVR32_SPI0_NPCS_2_0_PIN
|
||||
#define IPOD_AUTH_CHIP_SPI_NPCS_FUNCTION AVR32_SPI0_NPCS_2_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_SPI_N_RESET_PIN AVR32_PIN_PB30
|
||||
#define IPOD_AUTH_CHIP_SPI_CP_READY_PIN AVR32_PIN_PB31
|
||||
//! }@
|
||||
|
||||
/*! \name Connections of the iPOD Authentication Coprocessor
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define IPOD_AUTH_CHIP_TWI (&AVR32_TWI)
|
||||
#define IPOD_AUTH_CHIP_TWI_SCL_PIN AVR32_TWI_SCL_0_0_PIN
|
||||
#define IPOD_AUTH_CHIP_TWI_SCL_FUNCTION AVR32_TWI_SCL_0_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_TWI_SDA_PIN AVR32_TWI_SDA_0_0_PIN
|
||||
#define IPOD_AUTH_CHIP_TWI_SDA_FUNCTION AVR32_TWI_SDA_0_0_FUNCTION
|
||||
#define IPOD_AUTH_CHIP_TWI_N_RESET_PIN AVR32_PIN_PX16
|
||||
|
||||
//! @}
|
||||
|
||||
/*! \name USART connection to the UC3B board controller
|
||||
*/
|
||||
//! @{
|
||||
|
||||
#define USART0_RXD_PIN AVR32_USART0_RXD_0_0_PIN
|
||||
#define USART0_RXD_FUNCTION AVR32_USART0_RXD_0_0_FUNCTION
|
||||
#define USART0_TXD_PIN AVR32_USART0_TXD_0_0_PIN
|
||||
#define USART0_TXD_FUNCTION AVR32_USART0_TXD_0_0_FUNCTION
|
||||
#define USART0_RTS_PIN AVR32_USART0_RTS_0_0_PIN
|
||||
#define USART0_RTS_FUNCTION AVR32_USART0_RTS_0_0_FUNCTION
|
||||
#define USART0_CTS_PIN AVR32_USART0_CTS_0_0_PIN
|
||||
#define USART0_CTS_FUNCTION AVR32_USART0_CTS_0_0_FUNCTION
|
||||
|
||||
//! @}
|
||||
|
||||
#define ADC_VEXT_PIN AVR32_ADC_AD_7_PIN
|
||||
#define ADC_VEXT_FUNCTION AVR32_ADC_AD_7_FUNCTION
|
||||
|
||||
/*! \name LCD Connections of the ET024006DHU display
|
||||
*/
|
||||
//! @{
|
||||
#define ET024006DHU_SMC_USE_NCS 0
|
||||
#define ET024006DHU_SMC_COMPONENT_CS "smc_et024006dhu.h"
|
||||
|
||||
#define ET024006DHU_EBI_DATA_0 AVR32_EBI_DATA_0
|
||||
#define ET024006DHU_EBI_DATA_1 AVR32_EBI_DATA_1
|
||||
#define ET024006DHU_EBI_DATA_2 AVR32_EBI_DATA_2
|
||||
#define ET024006DHU_EBI_DATA_3 AVR32_EBI_DATA_3
|
||||
#define ET024006DHU_EBI_DATA_4 AVR32_EBI_DATA_4
|
||||
#define ET024006DHU_EBI_DATA_5 AVR32_EBI_DATA_5
|
||||
#define ET024006DHU_EBI_DATA_6 AVR32_EBI_DATA_6
|
||||
#define ET024006DHU_EBI_DATA_7 AVR32_EBI_DATA_7
|
||||
#define ET024006DHU_EBI_DATA_8 AVR32_EBI_DATA_8
|
||||
#define ET024006DHU_EBI_DATA_9 AVR32_EBI_DATA_9
|
||||
#define ET024006DHU_EBI_DATA_10 AVR32_EBI_DATA_10
|
||||
#define ET024006DHU_EBI_DATA_11 AVR32_EBI_DATA_11
|
||||
#define ET024006DHU_EBI_DATA_12 AVR32_EBI_DATA_12
|
||||
#define ET024006DHU_EBI_DATA_13 AVR32_EBI_DATA_13
|
||||
#define ET024006DHU_EBI_DATA_14 AVR32_EBI_DATA_14
|
||||
#define ET024006DHU_EBI_DATA_15 AVR32_EBI_DATA_15
|
||||
|
||||
#define ET024006DHU_EBI_ADDR_21 AVR32_EBI_ADDR_21_1
|
||||
|
||||
#define ET024006DHU_EBI_NWE AVR32_EBI_NWE0_0
|
||||
#define ET024006DHU_EBI_NRD AVR32_EBI_NRD_0
|
||||
#define ET024006DHU_EBI_NCS AVR32_EBI_NCS_0_1
|
||||
//! @}
|
||||
|
||||
|
||||
#endif // !EVK1105_REVA
|
||||
|
||||
#endif // _EVK1105_H_
|
|
@ -0,0 +1,346 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1105 board LEDs support package.
|
||||
*
|
||||
* This file contains definitions and services related to the LED features of
|
||||
* the EVK1105 board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#include <avr32/io.h>
|
||||
#include "preprocessor.h"
|
||||
#include "compiler.h"
|
||||
#include "evk1105.h"
|
||||
#include "led.h"
|
||||
|
||||
|
||||
//! Structure describing LED hardware connections.
|
||||
typedef const struct
|
||||
{
|
||||
struct
|
||||
{
|
||||
U32 PORT; //!< LED GPIO port.
|
||||
U32 PIN_MASK; //!< Bit-mask of LED pin in GPIO port.
|
||||
} GPIO; //!< LED GPIO descriptor.
|
||||
struct
|
||||
{
|
||||
S32 CHANNEL; //!< LED PWM channel (< 0 if N/A).
|
||||
S32 FUNCTION; //!< LED pin PWM function (< 0 if N/A).
|
||||
} PWM; //!< LED PWM descriptor.
|
||||
} tLED_DESCRIPTOR;
|
||||
|
||||
|
||||
//! Hardware descriptors of all LEDs.
|
||||
static tLED_DESCRIPTOR LED_DESCRIPTOR[LED_COUNT] =
|
||||
{
|
||||
#define INSERT_LED_DESCRIPTOR(LED_NO, unused) \
|
||||
{ \
|
||||
{LED##LED_NO##_GPIO / 32, 1 << (LED##LED_NO##_GPIO % 32)},\
|
||||
{LED##LED_NO##_PWM, LED##LED_NO##_PWM_FUNCTION } \
|
||||
},
|
||||
MREPEAT(LED_COUNT, INSERT_LED_DESCRIPTOR, ~)
|
||||
#undef INSERT_LED_DESCRIPTOR
|
||||
};
|
||||
|
||||
|
||||
//! Saved state of all LEDs.
|
||||
static volatile U32 LED_State = (1 << LED_COUNT) - 1;
|
||||
|
||||
|
||||
U32 LED_Read_Display(void)
|
||||
{
|
||||
return LED_State;
|
||||
}
|
||||
|
||||
|
||||
void LED_Display(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
LED_State = leds;
|
||||
|
||||
// For all LEDs...
|
||||
for (led_descriptor = &LED_DESCRIPTOR[0];
|
||||
led_descriptor < LED_DESCRIPTOR + LED_COUNT;
|
||||
led_descriptor++)
|
||||
{
|
||||
// Set the LED to the requested state.
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
if (leds & 1)
|
||||
{
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U32 LED_Read_Display_Mask(U32 mask)
|
||||
{
|
||||
return Rd_bits(LED_State, mask);
|
||||
}
|
||||
|
||||
|
||||
void LED_Display_Mask(U32 mask, U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
mask &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Wr_bits(LED_State, mask, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (mask)
|
||||
{
|
||||
// Select the next specified LED and set it to the requested state.
|
||||
led_shift = 1 + ctz(mask);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
leds >>= led_shift - 1;
|
||||
if (leds & 1)
|
||||
{
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= 1;
|
||||
mask >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bool LED_Test(U32 leds)
|
||||
{
|
||||
return Tst_bits(LED_State, leds);
|
||||
}
|
||||
|
||||
|
||||
void LED_Off(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Clr_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and turn it off.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrs = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LED_On(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Set_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and turn it on.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrc = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LED_Toggle(U32 leds)
|
||||
{
|
||||
// Use the LED descriptors to get the connections of a given LED to the MCU.
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// Make sure only existing LEDs are specified.
|
||||
leds &= (1 << LED_COUNT) - 1;
|
||||
|
||||
// Update the saved state of all LEDs with the requested changes.
|
||||
Tgl_bits(LED_State, leds);
|
||||
|
||||
// While there are specified LEDs left to manage...
|
||||
while (leds)
|
||||
{
|
||||
// Select the next specified LED and toggle it.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
led_gpio_port->ovrt = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->oders = led_descriptor->GPIO.PIN_MASK;
|
||||
led_gpio_port->gpers = led_descriptor->GPIO.PIN_MASK;
|
||||
leds >>= led_shift;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
U32 LED_Read_Display_Field(U32 field)
|
||||
{
|
||||
return Rd_bitfield(LED_State, field);
|
||||
}
|
||||
|
||||
|
||||
void LED_Display_Field(U32 field, U32 leds)
|
||||
{
|
||||
// Move the bit-field to the appropriate position for the bit-mask.
|
||||
LED_Display_Mask(field, leds << ctz(field));
|
||||
}
|
||||
|
||||
|
||||
U8 LED_Get_Intensity(U32 led)
|
||||
{
|
||||
tLED_DESCRIPTOR *led_descriptor;
|
||||
|
||||
// Check that the argument value is valid.
|
||||
led = ctz(led);
|
||||
led_descriptor = &LED_DESCRIPTOR[led];
|
||||
if (led >= LED_COUNT || led_descriptor->PWM.CHANNEL < 0) return 0;
|
||||
|
||||
// Return the duty cycle value if the LED PWM channel is enabled, else 0.
|
||||
return (AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)) ?
|
||||
AVR32_PWM.channel[led_descriptor->PWM.CHANNEL].cdty : 0;
|
||||
}
|
||||
|
||||
|
||||
void LED_Set_Intensity(U32 leds, U8 intensity)
|
||||
{
|
||||
tLED_DESCRIPTOR *led_descriptor = &LED_DESCRIPTOR[0] - 1;
|
||||
volatile avr32_pwm_channel_t *led_pwm_channel;
|
||||
volatile avr32_gpio_port_t *led_gpio_port;
|
||||
U8 led_shift;
|
||||
|
||||
// For each specified LED...
|
||||
for (leds &= (1 << LED_COUNT) - 1; leds; leds >>= led_shift)
|
||||
{
|
||||
// Select the next specified LED and check that it has a PWM channel.
|
||||
led_shift = 1 + ctz(leds);
|
||||
led_descriptor += led_shift;
|
||||
if (led_descriptor->PWM.CHANNEL < 0) continue;
|
||||
|
||||
// Initialize or update the LED PWM channel.
|
||||
led_pwm_channel = &AVR32_PWM.channel[led_descriptor->PWM.CHANNEL];
|
||||
if (!(AVR32_PWM.sr & (1 << led_descriptor->PWM.CHANNEL)))
|
||||
{
|
||||
led_pwm_channel->cmr = (AVR32_PWM_CPRE_MCK << AVR32_PWM_CPRE_OFFSET) &
|
||||
~(AVR32_PWM_CALG_MASK |
|
||||
AVR32_PWM_CPOL_MASK |
|
||||
AVR32_PWM_CPD_MASK);
|
||||
led_pwm_channel->cprd = 0x000000FF;
|
||||
led_pwm_channel->cdty = intensity;
|
||||
AVR32_PWM.ena = 1 << led_descriptor->PWM.CHANNEL;
|
||||
}
|
||||
else
|
||||
{
|
||||
AVR32_PWM.isr;
|
||||
while (!(AVR32_PWM.isr & (1 << led_descriptor->PWM.CHANNEL)));
|
||||
led_pwm_channel->cupd = intensity;
|
||||
}
|
||||
|
||||
// Switch the LED pin to its PWM function.
|
||||
led_gpio_port = &AVR32_GPIO.port[led_descriptor->GPIO.PORT];
|
||||
if (led_descriptor->PWM.FUNCTION & 0x1)
|
||||
{
|
||||
led_gpio_port->pmr0s = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->pmr0c = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
if (led_descriptor->PWM.FUNCTION & 0x2)
|
||||
{
|
||||
led_gpio_port->pmr1s = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
else
|
||||
{
|
||||
led_gpio_port->pmr1c = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
led_gpio_port->gperc = led_descriptor->GPIO.PIN_MASK;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,187 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief AT32UC3A EVK1105 board LEDs support package.
|
||||
*
|
||||
* This file contains definitions and services related to the LED features of
|
||||
* the EVK1105 board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 AT32UC3A devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _LED_H_
|
||||
#define _LED_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
|
||||
/*! \name Identifiers of LEDs to Use with LED Functions
|
||||
*/
|
||||
//! @{
|
||||
#define LED0 0x01
|
||||
#define LED1 0x02
|
||||
#define LED2 0x04
|
||||
#define LED3 0x08
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \brief Gets the last state of all LEDs set through the LED API.
|
||||
*
|
||||
* \return State of all LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display(void);
|
||||
|
||||
/*! \brief Sets the state of all LEDs.
|
||||
*
|
||||
* \param leds New state of all LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The pins of all LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display(U32 leds);
|
||||
|
||||
/*! \brief Gets the last state of the specified LEDs set through the LED API.
|
||||
*
|
||||
* \param mask LEDs of which to get the state (1 bit per LED).
|
||||
*
|
||||
* \return State of the specified LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display_Mask(U32 mask);
|
||||
|
||||
/*! \brief Sets the state of the specified LEDs.
|
||||
*
|
||||
* \param mask LEDs of which to set the state (1 bit per LED).
|
||||
*
|
||||
* \param leds New state of the specified LEDs (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display_Mask(U32 mask, U32 leds);
|
||||
|
||||
/*! \brief Tests the last state of the specified LEDs set through the LED API.
|
||||
*
|
||||
* \param leds LEDs of which to test the state (1 bit per LED).
|
||||
*
|
||||
* \return \c TRUE if at least one of the specified LEDs has a state on, else
|
||||
* \c FALSE.
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern Bool LED_Test(U32 leds);
|
||||
|
||||
/*! \brief Turns off the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to turn off (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Off(U32 leds);
|
||||
|
||||
/*! \brief Turns on the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to turn on (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_On(U32 leds);
|
||||
|
||||
/*! \brief Toggles the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs to toggle (1 bit per LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Toggle(U32 leds);
|
||||
|
||||
/*! \brief Gets as a bit-field the last state of the specified LEDs set through
|
||||
* the LED API.
|
||||
*
|
||||
* \param field LEDs of which to get the state (1 bit per LED).
|
||||
*
|
||||
* \return State of the specified LEDs (1 bit per LED, beginning with the first
|
||||
* specified LED).
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U32 LED_Read_Display_Field(U32 field);
|
||||
|
||||
/*! \brief Sets as a bit-field the state of the specified LEDs.
|
||||
*
|
||||
* \param field LEDs of which to set the state (1 bit per LED).
|
||||
* \param leds New state of the specified LEDs (1 bit per LED, beginning with
|
||||
* the first specified LED).
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to GPIO output mode.
|
||||
*/
|
||||
extern void LED_Display_Field(U32 field, U32 leds);
|
||||
|
||||
/*! \brief Gets the intensity of the specified LED.
|
||||
*
|
||||
* \param led LED of which to get the intensity (1 bit per LED; only the least
|
||||
* significant set bit is used).
|
||||
*
|
||||
* \return Intensity of the specified LED (0x00 to 0xFF).
|
||||
*
|
||||
* \warning The PWM channel of the specified LED is supposed to be used only by
|
||||
* this module.
|
||||
*
|
||||
* \note The GPIO pin configuration of all LEDs is left unchanged.
|
||||
*/
|
||||
extern U8 LED_Get_Intensity(U32 led);
|
||||
|
||||
/*! \brief Sets the intensity of the specified LEDs.
|
||||
*
|
||||
* \param leds LEDs of which to set the intensity (1 bit per LED).
|
||||
* \param intensity New intensity of the specified LEDs (0x00 to 0xFF).
|
||||
*
|
||||
* \warning The PWM channels of the specified LEDs are supposed to be used only
|
||||
* by this module.
|
||||
*
|
||||
* \note The pins of the specified LEDs are set to PWM output mode.
|
||||
*/
|
||||
extern void LED_Set_Intensity(U32 leds, U8 intensity);
|
||||
|
||||
|
||||
#endif // _LED_H_
|
|
@ -0,0 +1,120 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Standard board header file.
|
||||
*
|
||||
* This file includes the appropriate board header file according to the
|
||||
* defined board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include <avr32/io.h>
|
||||
|
||||
/*! \name Base Boards
|
||||
*/
|
||||
//! @{
|
||||
#define EVK1100 1 //!< AT32UC3A EVK1100 board.
|
||||
#define EVK1101 2 //!< AT32UC3B EVK1101 board.
|
||||
#define UC3C_EK 3 //!< AT32UC3C UC3C_EK board.
|
||||
#define EVK1104 4 //!< AT32UC3A3 EVK1104 board.
|
||||
#define EVK1105 5 //!< AT32UC3A EVK1105 board.
|
||||
#define STK1000 6 //!< AT32AP7000 STK1000 board.
|
||||
#define NGW100 7 //!< AT32AP7000 NGW100 board.
|
||||
#define STK600_RCUC3L0 8 //!< STK600 RCUC3L0 board.
|
||||
#define UC3L_EK 9 //!< AT32UC3L-EK board.
|
||||
#define USER_BOARD 99 //!< User-reserved board (if any).
|
||||
//! @}
|
||||
|
||||
/*! \name Extension Boards
|
||||
*/
|
||||
//! @{
|
||||
#define EXT1102 1 //!< AT32UC3B EXT1102 board.
|
||||
#define MC300 2 //!< AT32UC3 MC300 board.
|
||||
#define USER_EXT_BOARD 99 //!< User-reserved extension board (if any).
|
||||
//! @}
|
||||
|
||||
#if BOARD == EVK1100
|
||||
#include "EVK1100/evk1100.h"
|
||||
#elif BOARD == EVK1101
|
||||
#include "EVK1101/evk1101.h"
|
||||
#elif BOARD == UC3C_EK
|
||||
#include "UC3C_EK/uc3c_ek.h"
|
||||
#elif BOARD == EVK1104
|
||||
#include "EVK1104/evk1104.h"
|
||||
#elif BOARD == EVK1105
|
||||
#include "EVK1105/evk1105.h"
|
||||
#elif BOARD == STK1000
|
||||
#include "STK1000/stk1000.h"
|
||||
#elif BOARD == NGW100
|
||||
#include "NGW100/ngw100.h"
|
||||
#elif BOARD == STK600_RCUC3L0
|
||||
#include "STK600/RCUC3L0/stk600_rcuc3l0.h"
|
||||
#elif BOARD == UC3L_EK
|
||||
#include "UC3L_EK/uc3l_ek.h"
|
||||
#elif BOARD == ARDUINO
|
||||
#include "ARDUINO/arduino.h"
|
||||
#else
|
||||
#error No known AVR32 board defined
|
||||
#endif
|
||||
|
||||
#if (defined EXT_BOARD)
|
||||
#if EXT_BOARD == EXT1102
|
||||
#include "EXT1102/ext1102.h"
|
||||
#elif EXT_BOARD == MC300
|
||||
#include "MC300/mc300.h"
|
||||
#elif EXT_BOARD == USER_EXT_BOARD
|
||||
// User-reserved area: #include the header file of your extension board here
|
||||
// (if any).
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FRCOSC
|
||||
#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< Default RCOsc frequency.
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _BOARD_H_
|
|
@ -0,0 +1,120 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Standard board header file.
|
||||
*
|
||||
* This file includes the appropriate board header file according to the
|
||||
* defined board.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _BOARD_H_
|
||||
#define _BOARD_H_
|
||||
|
||||
#include <avr32/io.h>
|
||||
|
||||
/*! \name Base Boards
|
||||
*/
|
||||
//! @{
|
||||
#define EVK1100 1 //!< AT32UC3A EVK1100 board.
|
||||
#define EVK1101 2 //!< AT32UC3B EVK1101 board.
|
||||
#define UC3C_EK 3 //!< AT32UC3C UC3C_EK board.
|
||||
#define EVK1104 4 //!< AT32UC3A3 EVK1104 board.
|
||||
#define EVK1105 5 //!< AT32UC3A EVK1105 board.
|
||||
#define STK1000 6 //!< AT32AP7000 STK1000 board.
|
||||
#define NGW100 7 //!< AT32AP7000 NGW100 board.
|
||||
#define STK600_RCUC3L0 8 //!< STK600 RCUC3L0 board.
|
||||
#define UC3L_EK 9 //!< AT32UC3L-EK board.
|
||||
#define USER_BOARD 99 //!< User-reserved board (if any).
|
||||
//! @}
|
||||
|
||||
/*! \name Extension Boards
|
||||
*/
|
||||
//! @{
|
||||
#define EXT1102 1 //!< AT32UC3B EXT1102 board.
|
||||
#define MC300 2 //!< AT32UC3 MC300 board.
|
||||
#define USER_EXT_BOARD 99 //!< User-reserved extension board (if any).
|
||||
//! @}
|
||||
|
||||
#if BOARD == EVK1100
|
||||
#include "EVK1100/evk1100.h"
|
||||
#elif BOARD == EVK1101
|
||||
#include "EVK1101/evk1101.h"
|
||||
#elif BOARD == UC3C_EK
|
||||
#include "UC3C_EK/uc3c_ek.h"
|
||||
#elif BOARD == EVK1104
|
||||
#include "EVK1104/evk1104.h"
|
||||
#elif BOARD == EVK1105
|
||||
#include "EVK1105/evk1105.h"
|
||||
#elif BOARD == STK1000
|
||||
#include "STK1000/stk1000.h"
|
||||
#elif BOARD == NGW100
|
||||
#include "NGW100/ngw100.h"
|
||||
#elif BOARD == STK600_RCUC3L0
|
||||
#include "STK600/RCUC3L0/stk600_rcuc3l0.h"
|
||||
#elif BOARD == UC3L_EK
|
||||
#include "UC3L_EK/uc3l_ek.h"
|
||||
#elif BOARD == ARDUINO
|
||||
#include "ARDUINO/arduino.h"
|
||||
#else
|
||||
#error No known AVR32 board defined
|
||||
#endif
|
||||
|
||||
#if (defined EXT_BOARD)
|
||||
#if EXT_BOARD == EXT1102
|
||||
#include "EXT1102/ext1102.h"
|
||||
#elif EXT_BOARD == MC300
|
||||
#include "MC300/mc300.h"
|
||||
#elif EXT_BOARD == USER_EXT_BOARD
|
||||
// User-reserved area: #include the header file of your extension board here
|
||||
// (if any).
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#ifndef FRCOSC
|
||||
#define FRCOSC AVR32_PM_RCOSC_FREQUENCY //!< Default RCOsc frequency.
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _BOARD_H_
|
|
@ -0,0 +1,653 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Management of the AT45DBX data flash controller through SPI.
|
||||
*
|
||||
* This file manages the accesses to the AT45DBX data flash components.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
//_____ I N C L U D E S ___________________________________________________
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
|
||||
#if AT45DBX_MEM == ENABLE
|
||||
|
||||
#include "compiler.h"
|
||||
#include "board.h"
|
||||
#include "gpio.h"
|
||||
#include "spi.h"
|
||||
#include "conf_at45dbx.h"
|
||||
#include "at45dbx.h"
|
||||
|
||||
|
||||
#if AT45DBX_MEM_CNT > 4
|
||||
#error AT45DBX_MEM_CNT must not exceed 4
|
||||
#endif
|
||||
|
||||
|
||||
//_____ D E F I N I T I O N S ______________________________________________
|
||||
|
||||
/*! \name AT45DBX Group A Commands
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_CMDA_RD_PAGE 0xD2 //!< Main Memory Page Read (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDA_RD_ARRAY_LEG 0xE8 //!< Continuous Array Read, Legacy Command (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDA_RD_ARRAY_LF_SM 0x03 //!< Continuous Array Read, Low-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDA_RD_ARRAY_AF_SM 0x0B //!< Continuous Array Read, Any-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDA_RD_SECTOR_PROT_REG 0x32 //!< Read Sector Protection Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDA_RD_SECTOR_LKDN_REG 0x35 //!< Read Sector Lockdown Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDA_RD_SECURITY_REG 0x77 //!< Read Security Register (Serial/8-bit Mode).
|
||||
//! @}
|
||||
|
||||
/*! \name AT45DBX Group B Commands
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_CMDB_ER_PAGE 0x81 //!< Page Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_ER_BLOCK 0x50 //!< Block Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_ER_SECTOR 0x7C //!< Sector Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_ER_CHIP 0xC794809A //!< Chip Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF1 0x53 //!< Main Memory Page to Buffer 1 Transfer (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_XFR_PAGE_TO_BUF2 0x55 //!< Main Memory Page to Buffer 2 Transfer (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF1 0x60 //!< Main Memory Page to Buffer 1 Compare (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_CMP_PAGE_TO_BUF2 0x61 //!< Main Memory Page to Buffer 2 Compare (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE_ER 0x83 //!< Buffer 1 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE_ER 0x86 //!< Buffer 2 to Main Memory Page Program with Built-in Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_BUF1_TO_PAGE 0x88 //!< Buffer 1 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_BUF2_TO_PAGE 0x89 //!< Buffer 2 to Main Memory Page Program without Built-in Erase (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_PAGE_TH_BUF1 0x82 //!< Main Memory Page Program through Buffer 1 (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_PR_PAGE_TH_BUF2 0x85 //!< Main Memory Page Program through Buffer 2 (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF1 0x58 //!< Auto Page Rewrite through Buffer 1 (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDB_RWR_PAGE_TH_BUF2 0x59 //!< Auto Page Rewrite through Buffer 2 (Serial/8-bit Mode).
|
||||
//! @}
|
||||
|
||||
/*! \name AT45DBX Group C Commands
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_CMDC_RD_BUF1_LF_SM 0xD1 //!< Buffer 1 Read, Low-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDC_RD_BUF2_LF_SM 0xD3 //!< Buffer 2 Read, Low-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDC_RD_BUF1_AF_SM 0xD4 //!< Buffer 1 Read, Any-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDC_RD_BUF2_AF_SM 0xD6 //!< Buffer 2 Read, Any-Frequency Mode (Serial Mode).
|
||||
#define AT45DBX_CMDC_RD_BUF1_AF_8M 0x54 //!< Buffer 1 Read, Any-Frequency Mode (8-bit Mode).
|
||||
#define AT45DBX_CMDC_RD_BUF2_AF_8M 0x56 //!< Buffer 2 Read, Any-Frequency Mode (8-bit Mode).
|
||||
#define AT45DBX_CMDC_WR_BUF1 0x84 //!< Buffer 1 Write (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDC_WR_BUF2 0x87 //!< Buffer 2 Write (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDC_RD_STATUS_REG 0xD7 //!< Status Register Read (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDC_RD_MNFCT_DEV_ID_SM 0x9F //!< Manufacturer and Device ID Read (Serial Mode).
|
||||
//! @}
|
||||
|
||||
/*! \name AT45DBX Group D Commands
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_CMDD_EN_SECTOR_PROT 0x3D2A7FA9 //!< Enable Sector Protection (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_DIS_SECTOR_PROT 0x3D2A7F9A //!< Disable Sector Protection (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_ER_SECTOR_PROT_REG 0x3D2A7FCF //!< Erase Sector Protection Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_PR_SECTOR_PROT_REG 0x3D2A7FFC //!< Program Sector Protection Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_LKDN_SECTOR 0x3D2A7F30 //!< Sector Lockdown (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_PR_SECURITY_REG 0x9B000000 //!< Program Security Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_PR_CONF_REG 0x3D2A80A6 //!< Program Configuration Register (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_DEEP_PWR_DN 0xB9 //!< Deep Power-down (Serial/8-bit Mode).
|
||||
#define AT45DBX_CMDD_RSM_DEEP_PWR_DN 0xAB //!< Resume from Deep Power-down (Serial/8-bit Mode).
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Bit-Masks and Values for the Status Register
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_MSK_BUSY 0x80 //!< Busy status bit-mask.
|
||||
#define AT45DBX_BUSY 0x00 //!< Busy status value (0x00 when busy, 0x80 when ready).
|
||||
#define AT45DBX_MSK_DENSITY 0x3C //!< Device density bit-mask.
|
||||
//! @}
|
||||
#if AT45DBX_MEM_SIZE == AT45DBX_1MB
|
||||
|
||||
/*! \name AT45DB081 Memories
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_DENSITY 0x24 //!< Device density value.
|
||||
#define AT45DBX_BYTE_ADDR_BITS 9 //!< Address bits for byte position within buffer.
|
||||
|
||||
//! @}
|
||||
#elif AT45DBX_MEM_SIZE == AT45DBX_2MB
|
||||
|
||||
/*! \name AT45DB161 Memories
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_DENSITY 0x2C //!< Device density value.
|
||||
#define AT45DBX_BYTE_ADDR_BITS 10 //!< Address bits for byte position within buffer.
|
||||
//! @}
|
||||
|
||||
#elif AT45DBX_MEM_SIZE == AT45DBX_4MB
|
||||
|
||||
/*! \name AT45DB321 Memories
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_DENSITY 0x34 //!< Device density value.
|
||||
#define AT45DBX_BYTE_ADDR_BITS 10 //!< Address bits for byte position within buffer.
|
||||
//! @}
|
||||
|
||||
#elif AT45DBX_MEM_SIZE == AT45DBX_8MB
|
||||
|
||||
/*! \name AT45DB642 Memories
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_DENSITY 0x3C //!< Device density value.
|
||||
#define AT45DBX_BYTE_ADDR_BITS 11 //!< Address bits for byte position within buffer.
|
||||
//! @}
|
||||
|
||||
#else
|
||||
#error AT45DBX_MEM_SIZE is not defined to a supported value
|
||||
#endif
|
||||
|
||||
//! Address bits for page selection.
|
||||
#define AT45DBX_PAGE_ADDR_BITS (AT45DBX_MEM_SIZE - AT45DBX_PAGE_BITS)
|
||||
|
||||
//! Number of bits for addresses within pages.
|
||||
#define AT45DBX_PAGE_BITS (AT45DBX_BYTE_ADDR_BITS - 1)
|
||||
|
||||
//! Page size in bytes.
|
||||
#define AT45DBX_PAGE_SIZE (1 << AT45DBX_PAGE_BITS)
|
||||
|
||||
//! Bit-mask for byte position within buffer in \ref gl_ptr_mem.
|
||||
#define AT45DBX_MSK_PTR_BYTE ((1 << AT45DBX_PAGE_BITS) - 1)
|
||||
|
||||
//! Bit-mask for page selection in \ref gl_ptr_mem.
|
||||
#define AT45DBX_MSK_PTR_PAGE (((1 << AT45DBX_PAGE_ADDR_BITS) - 1) << AT45DBX_PAGE_BITS)
|
||||
|
||||
//! Bit-mask for byte position within sector in \ref gl_ptr_mem.
|
||||
#define AT45DBX_MSK_PTR_SECTOR ((1 << AT45DBX_SECTOR_BITS) - 1)
|
||||
|
||||
|
||||
/*! \brief Sends a dummy byte through SPI.
|
||||
*/
|
||||
#define spi_write_dummy() spi_write(AT45DBX_SPI, 0xFF)
|
||||
|
||||
|
||||
//! Boolean indicating whether memory is in busy state.
|
||||
static Bool at45dbx_busy;
|
||||
|
||||
//! Memory data pointer.
|
||||
static U32 gl_ptr_mem;
|
||||
|
||||
//! Sector buffer.
|
||||
static U8 sector_buf[AT45DBX_SECTOR_SIZE];
|
||||
|
||||
|
||||
/*! \name Control Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Bool at45dbx_init(spi_options_t spiOptions, unsigned int pba_hz)
|
||||
{
|
||||
// Setup SPI registers according to spiOptions.
|
||||
for (spiOptions.reg = AT45DBX_SPI_FIRST_NPCS;
|
||||
spiOptions.reg < AT45DBX_SPI_FIRST_NPCS + AT45DBX_MEM_CNT;
|
||||
spiOptions.reg++)
|
||||
{
|
||||
if (spi_setupChipReg(AT45DBX_SPI, &spiOptions, pba_hz) != SPI_OK) return KO;
|
||||
}
|
||||
|
||||
// Memory ready.
|
||||
at45dbx_busy = FALSE;
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Selects or unselects a DF memory.
|
||||
*
|
||||
* \param memidx Memory ID of DF to select or unselect.
|
||||
* \param bSelect Boolean indicating whether the DF memory has to be selected.
|
||||
*/
|
||||
static void at45dbx_chipselect_df(U8 memidx, Bool bSelect)
|
||||
{
|
||||
if (bSelect)
|
||||
{
|
||||
// Select SPI chip.
|
||||
spi_selectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Unselect SPI chip.
|
||||
spi_unselectChip(AT45DBX_SPI, AT45DBX_SPI_FIRST_NPCS + memidx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_mem_check(void)
|
||||
{
|
||||
U8 df;
|
||||
U16 status = 0;
|
||||
|
||||
// DF memory check.
|
||||
for (df = 0; df < AT45DBX_MEM_CNT; df++)
|
||||
{
|
||||
// Select the DF memory to check.
|
||||
at45dbx_chipselect_df(df, TRUE);
|
||||
|
||||
// Send the Status Register Read command.
|
||||
spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG);
|
||||
|
||||
// Send a dummy byte to read the status register.
|
||||
spi_write_dummy();
|
||||
spi_read(AT45DBX_SPI, &status);
|
||||
|
||||
// Unselect the checked DF memory.
|
||||
at45dbx_chipselect_df(df, FALSE);
|
||||
|
||||
// Unexpected device density value.
|
||||
if ((status & AT45DBX_MSK_DENSITY) < AT45DBX_DENSITY) return KO;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
/*! \brief Waits until the DF is ready.
|
||||
*/
|
||||
static void at45dbx_wait_ready(void)
|
||||
{
|
||||
U16 status;
|
||||
|
||||
// Select the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||
|
||||
// Send the Status Register Read command.
|
||||
spi_write(AT45DBX_SPI, AT45DBX_CMDC_RD_STATUS_REG);
|
||||
|
||||
// Read the status register until the DF is ready.
|
||||
do
|
||||
{
|
||||
// Send a dummy byte to read the status register.
|
||||
spi_write_dummy();
|
||||
spi_read(AT45DBX_SPI, &status);
|
||||
} while ((status & AT45DBX_MSK_BUSY) == AT45DBX_BUSY);
|
||||
|
||||
// Unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_read_open(U32 sector)
|
||||
{
|
||||
U32 addr;
|
||||
|
||||
// Set the global memory pointer to a byte address.
|
||||
gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
|
||||
|
||||
// If the DF memory is busy, wait until it's ready.
|
||||
if (at45dbx_busy) at45dbx_wait_ready();
|
||||
at45dbx_busy = FALSE;
|
||||
|
||||
// Select the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||
|
||||
// Initiate a page read at a given sector.
|
||||
|
||||
// Send the Main Memory Page Read command.
|
||||
spi_write(AT45DBX_SPI, AT45DBX_CMDA_RD_PAGE);
|
||||
|
||||
// Send the three address bytes, which comprise:
|
||||
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
|
||||
// - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
|
||||
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||
addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
|
||||
Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
|
||||
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||
|
||||
// Send 32 don't care clock cycles to initialize the read operation.
|
||||
spi_write_dummy();
|
||||
spi_write_dummy();
|
||||
spi_write_dummy();
|
||||
spi_write_dummy();
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void at45dbx_read_close(void)
|
||||
{
|
||||
// Unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory ready.
|
||||
at45dbx_busy = FALSE;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_write_open(U32 sector)
|
||||
{
|
||||
U32 addr;
|
||||
|
||||
// Set the global memory pointer to a byte address.
|
||||
gl_ptr_mem = sector << AT45DBX_SECTOR_BITS; // gl_ptr_mem = sector * AT45DBX_SECTOR_SIZE.
|
||||
|
||||
// If the DF memory is busy, wait until it's ready.
|
||||
if (at45dbx_busy) at45dbx_wait_ready();
|
||||
at45dbx_busy = FALSE;
|
||||
|
||||
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||
// Select the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||
|
||||
// Transfer the content of the current page to buffer 1.
|
||||
|
||||
// Send the Main Memory Page to Buffer 1 Transfer command.
|
||||
spi_write(AT45DBX_SPI, AT45DBX_CMDB_XFR_PAGE_TO_BUF1);
|
||||
|
||||
// Send the three address bytes, which comprise:
|
||||
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be read;
|
||||
// - then AT45DBX_BYTE_ADDR_BITS don't care bits.
|
||||
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||
addr = Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS;
|
||||
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||
|
||||
// Unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Wait for end of page transfer.
|
||||
at45dbx_wait_ready();
|
||||
#endif
|
||||
|
||||
// Select the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, TRUE);
|
||||
|
||||
// Initiate a page write at a given sector.
|
||||
|
||||
// Send the Main Memory Page Program through Buffer 1 command.
|
||||
spi_write(AT45DBX_SPI, AT45DBX_CMDB_PR_PAGE_TH_BUF1);
|
||||
|
||||
// Send the three address bytes, which comprise:
|
||||
// - (24 - (AT45DBX_PAGE_ADDR_BITS + AT45DBX_BYTE_ADDR_BITS)) reserved bits;
|
||||
// - then AT45DBX_PAGE_ADDR_BITS bits specifying the page in main memory to be written;
|
||||
// - then AT45DBX_BYTE_ADDR_BITS bits specifying the starting byte address within that page.
|
||||
// NOTE: The bits of gl_ptr_mem above the AT45DBX_MEM_SIZE bits are useless for the local
|
||||
// DF addressing. They are used for DF discrimination when there are several DFs.
|
||||
addr = (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_PAGE) << AT45DBX_BYTE_ADDR_BITS) |
|
||||
Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE);
|
||||
spi_write(AT45DBX_SPI, LSB2W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB1W(addr));
|
||||
spi_write(AT45DBX_SPI, LSB0W(addr));
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
void at45dbx_write_close(void)
|
||||
{
|
||||
// While end of logical sector not reached, zero-fill remaining memory bytes.
|
||||
while (Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_SECTOR))
|
||||
{
|
||||
spi_write(AT45DBX_SPI, 0x00);
|
||||
gl_ptr_mem++;
|
||||
}
|
||||
|
||||
// Unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory busy.
|
||||
at45dbx_busy = TRUE;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Single-Byte Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
U8 at45dbx_read_byte(void)
|
||||
{
|
||||
U16 data;
|
||||
|
||||
// Memory busy.
|
||||
if (at45dbx_busy)
|
||||
{
|
||||
// Being here, we know that we previously finished a page read.
|
||||
// => We have to access the next page.
|
||||
|
||||
// Memory ready.
|
||||
at45dbx_busy = FALSE;
|
||||
|
||||
// Eventually select the next DF and open the next page.
|
||||
// NOTE: at45dbx_read_open input parameter is a sector.
|
||||
at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||
}
|
||||
|
||||
// Send a dummy byte to read the next data byte.
|
||||
spi_write_dummy();
|
||||
spi_read(AT45DBX_SPI, &data);
|
||||
gl_ptr_mem++;
|
||||
|
||||
// If end of page reached,
|
||||
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||
{
|
||||
// unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory busy.
|
||||
at45dbx_busy = TRUE;
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_write_byte(U8 b)
|
||||
{
|
||||
// Memory busy.
|
||||
if (at45dbx_busy)
|
||||
{
|
||||
// Being here, we know that we previously launched a page programming.
|
||||
// => We have to access the next page.
|
||||
|
||||
// Eventually select the next DF and open the next page.
|
||||
// NOTE: at45dbx_write_open input parameter is a sector.
|
||||
at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||
}
|
||||
|
||||
// Write the next data byte.
|
||||
spi_write(AT45DBX_SPI, b);
|
||||
gl_ptr_mem++;
|
||||
|
||||
// If end of page reached,
|
||||
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||
{
|
||||
// unselect the DF memory gl_ptr_mem points to in order to program the page.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory busy.
|
||||
at45dbx_busy = TRUE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Multiple-Sector Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Bool at45dbx_read_multiple_sector(U16 nb_sector)
|
||||
{
|
||||
while (nb_sector--)
|
||||
{
|
||||
// Read the next sector.
|
||||
at45dbx_read_sector_2_ram(sector_buf);
|
||||
at45dbx_read_multiple_sector_callback(sector_buf);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_write_multiple_sector(U16 nb_sector)
|
||||
{
|
||||
while (nb_sector--)
|
||||
{
|
||||
// Write the next sector.
|
||||
at45dbx_write_multiple_sector_callback(sector_buf);
|
||||
at45dbx_write_sector_from_ram(sector_buf);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Single-Sector Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Bool at45dbx_read_sector_2_ram(void *ram)
|
||||
{
|
||||
U8 *_ram = ram;
|
||||
U16 i;
|
||||
U16 data;
|
||||
|
||||
// Memory busy.
|
||||
if (at45dbx_busy)
|
||||
{
|
||||
// Being here, we know that we previously finished a page read.
|
||||
// => We have to access the next page.
|
||||
|
||||
// Memory ready.
|
||||
at45dbx_busy = FALSE;
|
||||
|
||||
// Eventually select the next DF and open the next page.
|
||||
// NOTE: at45dbx_read_open input parameter is a sector.
|
||||
at45dbx_read_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||
}
|
||||
|
||||
// Read the next sector.
|
||||
for (i = AT45DBX_SECTOR_SIZE; i; i--)
|
||||
{
|
||||
// Send a dummy byte to read the next data byte.
|
||||
spi_write_dummy();
|
||||
spi_read(AT45DBX_SPI, &data);
|
||||
*_ram++ = data;
|
||||
}
|
||||
|
||||
// Update the memory pointer.
|
||||
gl_ptr_mem += AT45DBX_SECTOR_SIZE;
|
||||
|
||||
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||
// If end of page reached,
|
||||
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||
#endif
|
||||
{
|
||||
// unselect the DF memory gl_ptr_mem points to.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory busy.
|
||||
at45dbx_busy = TRUE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_write_sector_from_ram(const void *ram)
|
||||
{
|
||||
const U8 *_ram = ram;
|
||||
U16 i;
|
||||
|
||||
// Memory busy.
|
||||
if (at45dbx_busy)
|
||||
{
|
||||
// Being here, we know that we previously launched a page programming.
|
||||
// => We have to access the next page.
|
||||
|
||||
// Eventually select the next DF and open the next page.
|
||||
// NOTE: at45dbx_write_open input parameter is a sector.
|
||||
at45dbx_write_open(gl_ptr_mem >> AT45DBX_SECTOR_BITS); // gl_ptr_mem / AT45DBX_SECTOR_SIZE.
|
||||
}
|
||||
|
||||
// Write the next sector.
|
||||
for (i = AT45DBX_SECTOR_SIZE; i; i--)
|
||||
{
|
||||
// Write the next data byte.
|
||||
spi_write(AT45DBX_SPI, *_ram++);
|
||||
}
|
||||
|
||||
// Update the memory pointer.
|
||||
gl_ptr_mem += AT45DBX_SECTOR_SIZE;
|
||||
|
||||
#if AT45DBX_PAGE_SIZE > AT45DBX_SECTOR_SIZE
|
||||
// If end of page reached,
|
||||
if (!Rd_bitfield(gl_ptr_mem, AT45DBX_MSK_PTR_BYTE))
|
||||
#endif
|
||||
{
|
||||
// unselect the DF memory gl_ptr_mem points to in order to program the page.
|
||||
at45dbx_chipselect_df(gl_ptr_mem >> AT45DBX_MEM_SIZE, FALSE);
|
||||
|
||||
// Memory busy.
|
||||
at45dbx_busy = TRUE;
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#endif // AT45DBX_MEM == ENABLE
|
|
@ -0,0 +1,270 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Management of the AT45DBX data flash controller through SPI.
|
||||
*
|
||||
* This file manages the accesses to the AT45DBX data flash components.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _AT45DBX_H_
|
||||
#define _AT45DBX_H_
|
||||
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
#if AT45DBX_MEM == DISABLE
|
||||
#error at45dbx.h is #included although AT45DBX_MEM is disabled
|
||||
#endif
|
||||
|
||||
|
||||
#include "spi.h"
|
||||
|
||||
|
||||
//_____ D E F I N I T I O N S ______________________________________________
|
||||
|
||||
/*! \name Available AT45DBX Sizes
|
||||
*
|
||||
* Number of address bits of available AT45DBX data flash memories.
|
||||
*
|
||||
* \note Only memories with page sizes of at least 512 bytes (sector size) are
|
||||
* supported.
|
||||
*/
|
||||
//! @{
|
||||
#define AT45DBX_1MB 20
|
||||
#define AT45DBX_2MB 21
|
||||
#define AT45DBX_4MB 22
|
||||
#define AT45DBX_8MB 23
|
||||
//! @}
|
||||
|
||||
// AT45DBX_1MB
|
||||
#define AT45DBX_SECTOR_BITS 8 //! Number of bits for addresses within sectors.
|
||||
// AT45DBX_2MB AT45DBX_4MB AT45DBX_8MB
|
||||
//#define AT45DBX_SECTOR_BITS 9 //! Number of bits for addresses within sectors.
|
||||
|
||||
//! Sector size in bytes.
|
||||
#define AT45DBX_SECTOR_SIZE (1 << AT45DBX_SECTOR_BITS)
|
||||
|
||||
|
||||
//_____ D E C L A R A T I O N S ____________________________________________
|
||||
|
||||
/*! \name Control Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Initializes the data flash controller and the SPI channel by which
|
||||
* the DF is controlled.
|
||||
*
|
||||
* \param spiOptions Initialization options of the DF SPI channel.
|
||||
* \param pba_hz SPI module input clock frequency (PBA clock, Hz).
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*/
|
||||
extern Bool at45dbx_init(spi_options_t spiOptions, unsigned int pba_hz);
|
||||
|
||||
/*! \brief Performs a memory check on all DFs.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*/
|
||||
extern Bool at45dbx_mem_check(void);
|
||||
|
||||
/*! \brief Opens a DF memory in read mode at a given sector.
|
||||
*
|
||||
* \param sector Start sector.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note Sector may be page-unaligned (depending on the DF page size).
|
||||
*/
|
||||
extern Bool at45dbx_read_open(U32 sector);
|
||||
|
||||
/*! \brief Unselects the current DF memory.
|
||||
*/
|
||||
extern void at45dbx_read_close(void);
|
||||
|
||||
/*! \brief This function opens a DF memory in write mode at a given sector.
|
||||
*
|
||||
* \param sector Start sector.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note Sector may be page-unaligned (depending on the DF page size).
|
||||
*
|
||||
* \note If \ref AT45DBX_PAGE_SIZE > \ref AT45DBX_SECTOR_SIZE, page content is
|
||||
* first loaded in buffer to then be partially updated by write byte or
|
||||
* write sector functions.
|
||||
*/
|
||||
extern Bool at45dbx_write_open(U32 sector);
|
||||
|
||||
/*! \brief Fills the end of the current logical sector and launches page programming.
|
||||
*/
|
||||
extern void at45dbx_write_close(void);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Single-Byte Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Performs a single byte read from DF memory.
|
||||
*
|
||||
* \return The read byte.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||
* function.
|
||||
*/
|
||||
extern U8 at45dbx_read_byte(void);
|
||||
|
||||
/*! \brief Performs a single byte write to DF memory.
|
||||
*
|
||||
* \param b The byte to write.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||
* function.
|
||||
*/
|
||||
extern Bool at45dbx_write_byte(U8 b);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Multiple-Sector Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Reads \a nb_sector sectors from DF memory.
|
||||
*
|
||||
* Data flow is: DF -> callback.
|
||||
*
|
||||
* \param nb_sector Number of contiguous sectors to read.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||
* function.
|
||||
*
|
||||
* \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
|
||||
* \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
|
||||
* byte.
|
||||
*/
|
||||
extern Bool at45dbx_read_multiple_sector(U16 nb_sector);
|
||||
|
||||
/*! \brief Callback function invoked after each sector read during
|
||||
* \ref at45dbx_read_multiple_sector.
|
||||
*
|
||||
* \param psector Pointer to read sector.
|
||||
*/
|
||||
extern void at45dbx_read_multiple_sector_callback(const void *psector);
|
||||
|
||||
/*! \brief Writes \a nb_sector sectors to DF memory.
|
||||
*
|
||||
* Data flow is: callback -> DF.
|
||||
*
|
||||
* \param nb_sector Number of contiguous sectors to write.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||
* function.
|
||||
*
|
||||
* \note As \ref AT45DBX_PAGE_SIZE is always a multiple of
|
||||
* \ref AT45DBX_SECTOR_SIZE, there is no need to check page end for each
|
||||
* byte.
|
||||
*/
|
||||
extern Bool at45dbx_write_multiple_sector(U16 nb_sector);
|
||||
|
||||
/*! \brief Callback function invoked before each sector write during
|
||||
* \ref at45dbx_write_multiple_sector.
|
||||
*
|
||||
* \param psector Pointer to sector to write.
|
||||
*/
|
||||
extern void at45dbx_write_multiple_sector_callback(void *psector);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Single-Sector Access Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Reads 1 DF sector to a RAM buffer.
|
||||
*
|
||||
* Data flow is: DF -> RAM.
|
||||
*
|
||||
* \param ram Pointer to RAM buffer.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_read_open
|
||||
* function.
|
||||
*/
|
||||
extern Bool at45dbx_read_sector_2_ram(void *ram);
|
||||
|
||||
/*! \brief Writes 1 DF sector from a RAM buffer.
|
||||
*
|
||||
* Data flow is: RAM -> DF.
|
||||
*
|
||||
* \param ram Pointer to RAM buffer.
|
||||
*
|
||||
* \retval OK Success.
|
||||
* \retval KO Failure.
|
||||
*
|
||||
* \note First call must be preceded by a call to the \ref at45dbx_write_open
|
||||
* function.
|
||||
*/
|
||||
extern Bool at45dbx_write_sector_from_ram(const void *ram);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#endif // _AT45DBX_H_
|
|
@ -0,0 +1,234 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief CTRL_ACCESS interface for the AT45DBX data flash controller.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
//_____ I N C L U D E S ___________________________________________________
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
|
||||
#if AT45DBX_MEM == ENABLE
|
||||
|
||||
#include "conf_at45dbx.h"
|
||||
#include "at45dbx.h"
|
||||
#include "at45dbx_mem.h"
|
||||
|
||||
|
||||
//_____ D E F I N I T I O N S ______________________________________________
|
||||
|
||||
//! Whether to detect write accesses to the memory.
|
||||
#define AT45DBX_MEM_TEST_CHANGE_STATE ENABLED
|
||||
|
||||
|
||||
#if (ACCESS_USB == ENABLED || ACCESS_MEM_TO_RAM == ENABLED) && AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||
|
||||
//! Memory data modified flag.
|
||||
static volatile Bool s_b_data_modify = FALSE;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*! \name Control Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Ctrl_status at45dbx_test_unit_ready(void)
|
||||
{
|
||||
return (at45dbx_mem_check() == OK) ? CTRL_GOOD : CTRL_NO_PRESENT;
|
||||
}
|
||||
|
||||
|
||||
Ctrl_status at45dbx_read_capacity(U32 *u32_nb_sector)
|
||||
{
|
||||
*u32_nb_sector = (AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) - 1;
|
||||
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_wr_protect(void)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
Bool at45dbx_removal(void)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#if ACCESS_USB == ENABLED
|
||||
|
||||
#include "usb_drv.h"
|
||||
#include "scsi_decoder.h"
|
||||
|
||||
|
||||
/*! \name MEM <-> USB Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector)
|
||||
{
|
||||
if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||
|
||||
at45dbx_read_open(addr);
|
||||
at45dbx_read_multiple_sector(nb_sector);
|
||||
at45dbx_read_close();
|
||||
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
|
||||
void at45dbx_read_multiple_sector_callback(const void *psector)
|
||||
{
|
||||
U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
|
||||
|
||||
// Transfer read sector to the USB interface.
|
||||
while (data_to_transfer)
|
||||
{
|
||||
while (!Is_usb_in_ready(g_scsi_ep_ms_in))
|
||||
{
|
||||
if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_in))
|
||||
return; // USB Reset
|
||||
}
|
||||
|
||||
Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_in);
|
||||
data_to_transfer = usb_write_ep_txpacket(g_scsi_ep_ms_in, psector,
|
||||
data_to_transfer, &psector);
|
||||
Usb_ack_in_ready_send(g_scsi_ep_ms_in);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector)
|
||||
{
|
||||
if (addr + nb_sector > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||
|
||||
#if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||
if (nb_sector) s_b_data_modify = TRUE;
|
||||
#endif
|
||||
|
||||
at45dbx_write_open(addr);
|
||||
at45dbx_write_multiple_sector(nb_sector);
|
||||
at45dbx_write_close();
|
||||
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
|
||||
void at45dbx_write_multiple_sector_callback(void *psector)
|
||||
{
|
||||
U16 data_to_transfer = AT45DBX_SECTOR_SIZE;
|
||||
|
||||
// Transfer sector to write from the USB interface.
|
||||
while (data_to_transfer)
|
||||
{
|
||||
while (!Is_usb_out_received(g_scsi_ep_ms_out))
|
||||
{
|
||||
if(!Is_usb_endpoint_enabled(g_scsi_ep_ms_out))
|
||||
return; // USB Reset
|
||||
}
|
||||
|
||||
Usb_reset_endpoint_fifo_access(g_scsi_ep_ms_out);
|
||||
data_to_transfer = usb_read_ep_rxpacket(g_scsi_ep_ms_out, psector,
|
||||
data_to_transfer, &psector);
|
||||
Usb_ack_out_received_free(g_scsi_ep_ms_out);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // ACCESS_USB == ENABLED
|
||||
|
||||
|
||||
#if ACCESS_MEM_TO_RAM == ENABLED
|
||||
|
||||
/*! \name MEM <-> RAM Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram)
|
||||
{
|
||||
if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||
|
||||
at45dbx_read_open(addr);
|
||||
at45dbx_read_sector_2_ram(ram);
|
||||
at45dbx_read_close();
|
||||
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
|
||||
Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram)
|
||||
{
|
||||
if (addr + 1 > AT45DBX_MEM_CNT << (AT45DBX_MEM_SIZE - AT45DBX_SECTOR_BITS)) return CTRL_FAIL;
|
||||
|
||||
#if AT45DBX_MEM_TEST_CHANGE_STATE == ENABLED
|
||||
s_b_data_modify = TRUE;
|
||||
#endif
|
||||
|
||||
at45dbx_write_open(addr);
|
||||
at45dbx_write_sector_from_ram(ram);
|
||||
at45dbx_write_close();
|
||||
|
||||
return CTRL_GOOD;
|
||||
}
|
||||
|
||||
|
||||
//! @}
|
||||
|
||||
#endif // ACCESS_MEM_TO_RAM == ENABLED
|
||||
|
||||
|
||||
#endif // AT45DBX_MEM == ENABLE
|
|
@ -0,0 +1,164 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief CTRL_ACCESS interface for the AT45DBX data flash controller.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an SPI module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _AT45DBX_MEM_H_
|
||||
#define _AT45DBX_MEM_H_
|
||||
|
||||
|
||||
#include "conf_access.h"
|
||||
|
||||
#if AT45DBX_MEM == DISABLE
|
||||
#error at45dbx_mem.h is #included although AT45DBX_MEM is disabled
|
||||
#endif
|
||||
|
||||
|
||||
#include "ctrl_access.h"
|
||||
|
||||
|
||||
//_____ D E C L A R A T I O N S ____________________________________________
|
||||
|
||||
/*! \name Control Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Tests the memory state and initializes the memory if required.
|
||||
*
|
||||
* The TEST UNIT READY SCSI primary command allows an application client to poll
|
||||
* a LUN until it is ready without having to allocate memory for returned data.
|
||||
*
|
||||
* This command may be used to check the media status of LUNs with removable
|
||||
* media.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_test_unit_ready(void);
|
||||
|
||||
/*! \brief Returns the address of the last valid sector in the memory.
|
||||
*
|
||||
* \param u32_nb_sector Pointer to the address of the last valid sector.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_read_capacity(U32 *u32_nb_sector);
|
||||
|
||||
/*! \brief Returns the write-protection state of the memory.
|
||||
*
|
||||
* \return \c TRUE if the memory is write-protected, else \c FALSE.
|
||||
*
|
||||
* \note Only used by removable memories with hardware-specific write
|
||||
* protection.
|
||||
*/
|
||||
extern Bool at45dbx_wr_protect(void);
|
||||
|
||||
/*! \brief Tells whether the memory is removable.
|
||||
*
|
||||
* \return \c TRUE if the memory is removable, else \c FALSE.
|
||||
*/
|
||||
extern Bool at45dbx_removal(void);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#if ACCESS_USB == ENABLED
|
||||
|
||||
/*! \name MEM <-> USB Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Tranfers data from the memory to USB.
|
||||
*
|
||||
* \param addr Address of first memory sector to read.
|
||||
* \param nb_sector Number of sectors to transfer.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_usb_read_10(U32 addr, U16 nb_sector);
|
||||
|
||||
/*! \brief Tranfers data from USB to the memory.
|
||||
*
|
||||
* \param addr Address of first memory sector to write.
|
||||
* \param nb_sector Number of sectors to transfer.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_usb_write_10(U32 addr, U16 nb_sector);
|
||||
|
||||
//! @}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#if ACCESS_MEM_TO_RAM == ENABLED
|
||||
|
||||
/*! \name MEM <-> RAM Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Copies 1 data sector from the memory to RAM.
|
||||
*
|
||||
* \param addr Address of first memory sector to read.
|
||||
* \param ram Pointer to RAM buffer to write.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_df_2_ram(U32 addr, void *ram);
|
||||
|
||||
/*! \brief Copies 1 data sector from RAM to the memory.
|
||||
*
|
||||
* \param addr Address of first memory sector to write.
|
||||
* \param ram Pointer to RAM buffer to read.
|
||||
*
|
||||
* \return Status.
|
||||
*/
|
||||
extern Ctrl_status at45dbx_ram_2_df(U32 addr, const void *ram);
|
||||
|
||||
//! @}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _AT45DBX_MEM_H_
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -0,0 +1 @@
|
|||
Revision: 2491
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,35 @@
|
|||
#ifndef WL_OS_H
|
||||
#define WL_OS_H
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
void *owl_os_alloc(size_t size);
|
||||
void *owl_os_realloc(void *ptr, size_t size);
|
||||
void owl_os_free(void *p);
|
||||
void *owl_os_memcpy(void *dst, const void *src, size_t n);
|
||||
void *owl_os_memset(void *s, int c, size_t n);
|
||||
void *owl_os_memmove(void *dst, const void *src, size_t n);
|
||||
size_t owl_os_strlen(char *s);
|
||||
char *owl_os_strncpy(char *dst, const char *src, size_t n);
|
||||
int owl_os_strncmp(const char *s1, const char *s2, size_t n);
|
||||
int owl_os_strcmp(const char *s1, const char *s2);
|
||||
char *owl_os_strcpy(char *dst, const char *src);
|
||||
char *owl_os_strdup(const char *s);
|
||||
char *owl_os_strndup(const char *s, size_t n);
|
||||
int owl_os_memcmp(const void *s1, const void *s2, size_t n);
|
||||
long int owl_os_strtol(const char *nptr, char **endptr, int base);
|
||||
char *owl_os_strchr(const char *s, int c);
|
||||
char *owl_os_strrchr(const char *s, int c);
|
||||
int owl_os_strcasecmp(const char *s1, const char *s2);
|
||||
char *owl_os_strstr(const char *haystack, const char *needle);
|
||||
|
||||
int owl_os_snprintf(char *str, size_t size, const char *format, ...)
|
||||
__attribute__((format(printf, 3, 4)));
|
||||
|
||||
int owl_os_vprintf(const char *format, va_list arg); /* debug only */
|
||||
int owl_os_printf(const char *format, ...) /* debug only */
|
||||
__attribute__((format(printf, 1, 2)));
|
||||
|
||||
#endif /* WL_OS_H */
|
||||
|
|
@ -0,0 +1,172 @@
|
|||
/*!
|
||||
* \file wl_sdio.h
|
||||
* \brief SDIO interface for wl_api.
|
||||
* Copyright (C) 2010 HD Wireless AB
|
||||
*
|
||||
* You should have received a copy of the license along with this library.
|
||||
*/
|
||||
|
||||
#ifndef WL_SDIO_H
|
||||
#define WL_SDIO_H
|
||||
|
||||
/** \defgroup wl_sdio SDIO Interface
|
||||
*
|
||||
* These functions implement the interface that the wl_api library
|
||||
* needs to work with a SDIO transport layer.
|
||||
*
|
||||
* The functions prototyped here must be implemented when porting the
|
||||
* wl_api library to a new platform with a different SDIO configuration
|
||||
*
|
||||
* On platforms supported by H&D Wireless these functions are
|
||||
* implemented in the file avr32_sdio.c
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maximum transfer size. This will set an upper limit on the len parameter
|
||||
* passed to owl_sdio_tx() and owl_sdio_rx().
|
||||
*
|
||||
*/
|
||||
#define MAX_BLOCK_LEN 512
|
||||
|
||||
|
||||
/**
|
||||
* This flag might be set when owl_sdio_cmd() is called in case the cmd will
|
||||
* be followed by a data transfer. If the flag is set, the transfer direction is
|
||||
* from the device to the host (read). Otherwise, the transfer direction is
|
||||
* from the host to the device (write).
|
||||
*
|
||||
*/
|
||||
#define CMD_FLAG_TO_HOST (1 << 0)
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that the sdio driver needs to be polled in order to make
|
||||
* forward progress, i.e. it does not support interrupts
|
||||
*
|
||||
* The actual polling will result in owl_sdio_cmd() being called to
|
||||
* request status information from the device.
|
||||
*
|
||||
* To activate polling, this flag should be set in owl_sdio_init().
|
||||
*/
|
||||
#define SDIO_FLAG_POLL (1 << 0)
|
||||
|
||||
/**
|
||||
* Indicates that the sdio driver only supports 1-bit mode.
|
||||
*
|
||||
* To set 1-bit mode, this flag should be set in owl_sdio_init().
|
||||
*/
|
||||
#define SDIO_FLAG_1BIT_MODE (1 << 1)
|
||||
|
||||
/**
|
||||
* This function will be invoked when wlan initialization should be performed,
|
||||
* this happens when the wl_fw_download() function in the transport group of
|
||||
* wl_api is invoked.
|
||||
*
|
||||
* The wifi device supports sdio high speed mode and clock frequencies up to
|
||||
* 50 MHz.
|
||||
*
|
||||
* The function is responsible for doing any necessary sdio initialization such
|
||||
* as allocating gpio's, setting up the mci master, one time allocations of
|
||||
* dma buffers etc.
|
||||
*
|
||||
* @param flags is an out parameter that should hold any sdio flags upon return.
|
||||
* The avaible flags are prefixed with SDIO_FLAG_
|
||||
*
|
||||
*
|
||||
*/
|
||||
void owl_sdio_init(uint8_t *flags);
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This function will be invoked when an sdio cmd should be sent to the
|
||||
* device.
|
||||
*
|
||||
* @param idx is the sdio command number
|
||||
* @param arg is the sdio command argument
|
||||
* @param flags specifies other options, such as any transfer direction.
|
||||
* @param rsp should hold the command response upon return. If null, the
|
||||
* response can be ignored.
|
||||
* @param data holds a pointer to any data that might follow the command. This
|
||||
* allows the sdio driver to setup dma transfers while waiting for the
|
||||
* command response. NULL if no data transfer will follow. Note that
|
||||
* the same data pointer will be passed to owl_sdio_tx(), which should
|
||||
* start the actual transfer.
|
||||
* @param len is the length of the data buffer.
|
||||
*
|
||||
*/
|
||||
void owl_sdio_cmd(uint8_t idx, uint32_t arg, uint8_t flags, uint32_t *rsp,
|
||||
const uint8_t *data, uint16_t len);
|
||||
|
||||
|
||||
/**
|
||||
* This function will be invoked when data should be transmitted to the device.
|
||||
*
|
||||
* If wl_fw_downlad() was called with the size_align parameter set to non-zero,
|
||||
* the pad parameter should be used. If the pad parameter is not 0, additional
|
||||
* data must be transmitted after the data buffer has be sent. Depending on
|
||||
* how the data buffer was first allocated (probably by an TCP/IP stack), it
|
||||
* might be safe or unsafe to continue reading beyond the data buffer to
|
||||
* transmit the additional padding bytes.
|
||||
*
|
||||
* @param data holds a pointer to the data to transmit, the pointer is the
|
||||
* same as the one passed to wl_tx().
|
||||
* @param len is the number of bytes that should be transmitted, including
|
||||
* padding.
|
||||
* @param pad is the number of padding bytes to send.
|
||||
*
|
||||
*/
|
||||
void owl_sdio_tx(const uint8_t *data, uint16_t len, uint8_t pad);
|
||||
|
||||
|
||||
/**
|
||||
* This function will be invoked when data should be received from the device.
|
||||
*
|
||||
* @param data should hold the read data upon return.
|
||||
* @param len is the number of bytes to read.
|
||||
*
|
||||
*/
|
||||
void owl_sdio_rx(uint8_t *data, uint16_t len);
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when sdio rx interrupts from the device should be enabled or
|
||||
* disabled.
|
||||
*
|
||||
* If SDIO_FLAG_POLL was set in wl_spi_init(), then this function can be
|
||||
* left empty.
|
||||
*
|
||||
* @param enable specifies if interrupts should be enabled or disabled.
|
||||
*
|
||||
*/
|
||||
void owl_sdio_irq(uint8_t enable);
|
||||
|
||||
|
||||
/**
|
||||
* Delay executiom for the specified number of ms. This function will be called
|
||||
* with delays in the 10-20 ms range during fw download and startup of the
|
||||
* Wi-Fi device. This function can be implemented with a simple for-loop if
|
||||
* desired (beware of optimization). The timing does not have to be accurate as
|
||||
* long as the actual delay becomes at least the specified number of ms.
|
||||
*
|
||||
* @param ms is the minimal amount of time to wait [ms].
|
||||
*
|
||||
*/
|
||||
void owl_sdio_mdelay(uint32_t ms);
|
||||
|
||||
|
||||
/**
|
||||
* This function should be called whenever an interrupt is detected. It can
|
||||
* be called from an interrupt context.
|
||||
*
|
||||
* If SDIO_FLAG_POLL was set in owl_sdio_init(), then wl_sdio_irq()
|
||||
* should never be called.
|
||||
*
|
||||
*/
|
||||
extern void wl_sdio_irq(void);
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,185 @@
|
|||
/*!
|
||||
* \file wl_spi.h
|
||||
* \brief SPI interface for wl_api.
|
||||
* Copyright (C) 2010 HD Wireless AB
|
||||
*
|
||||
* You should have received a copy of the license along with this library.
|
||||
*/
|
||||
|
||||
#ifndef WL_SPI_H
|
||||
#define WL_SPI_H
|
||||
|
||||
#ifndef WITHOUT_STDINT
|
||||
#include <stdint.h>
|
||||
#endif
|
||||
|
||||
/** \defgroup wl_spi SPI Interface
|
||||
*
|
||||
* These functions implement the interface that the wl_api library
|
||||
* needs to work with a SPI transport layer.
|
||||
*
|
||||
* The functions prototyped here must be implemented when porting the
|
||||
* wl_api library to a new platform with a different SPI configuration
|
||||
*
|
||||
* On platforms supported by H&D Wireless these functions are
|
||||
* implemented in the file avr32_spi.c
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* Maximum transfer size. This will set an upper limit on the len parameter
|
||||
* passed to owl_spi_txrx().
|
||||
*
|
||||
*
|
||||
*/
|
||||
#define MAX_BLOCK_LEN 512
|
||||
|
||||
|
||||
/**
|
||||
* Indicates that the spi driver needs to be polled in order to make
|
||||
* forward progress, i.e. it does not support interrupts through SD pin 8.
|
||||
*
|
||||
* The actual polling will result in owl_spi_txrx() being call to
|
||||
* request status information from the device.
|
||||
*
|
||||
* To activate polling, this flag should be set in owl_spi_init().
|
||||
*
|
||||
* See wl_poll() and wl_register_rx_isr() for more information regarding
|
||||
* polled and interrupt modes.
|
||||
*
|
||||
*/
|
||||
#define SPI_FLAG_POLL (1 << 0)
|
||||
|
||||
|
||||
/**
|
||||
* This function will be invoked when wlan device initialization should be
|
||||
* performed, this happens when the wl_fw_download() function in the transport
|
||||
* group of wl_api is invoked.
|
||||
*
|
||||
* The wifi device requires spi mode 3, i.e. clock polarity high and sample
|
||||
* on second phase. This corresponds to CPOL=1, CPHA=1. Maximum frequency on
|
||||
* spi clock is 30 MHz.
|
||||
*
|
||||
* The function is also responsible for doing any necessary spi initialization
|
||||
* such as allocating gpio's, setting up the SPI master, one time allocations of
|
||||
* dma buffers etc.
|
||||
*
|
||||
*
|
||||
* If the SPB105 device is used, two signals; POWER (pin 10 on SPB105) and
|
||||
* SHUTDOWN (pin 4 on SPB105) might be connected to gpio's on the host.
|
||||
* The GPIO_POWER_PIN is the main power supply to the device. The
|
||||
* GPIO_SHUTDOWN_PIN (active low) should be defined as an input.
|
||||
*
|
||||
* After GPIO_POWER_PIN is pulled high by the host, the device will pull the
|
||||
* GPIO_SHUTDOWN_PIN high once the device is properly powered.
|
||||
*
|
||||
* However, if pin 4 (GPIO_SHUTDOWN_PIN) is not connected to the host, a delay
|
||||
* of up to 250 ms must be added after GPIO_POWER_PIN is pulled high to ensure
|
||||
* that startup is completed. The actual time is usually much shorter, therefore
|
||||
* one might try to reduce the delay for a particualar hardware design.
|
||||
*
|
||||
* On SPB104, the GPIO_POWER_PIN will be connected to VCC and GPIO_SHUTDOWN_PIN
|
||||
* will be unconnected; hence we have to make sure that we have enough delay
|
||||
* after powering on the host. Since the device power-on usually happens at the
|
||||
* same time as the host power-on, the startup time of the host can be
|
||||
* subtracted from any delay put into owl_spi_init().
|
||||
*
|
||||
* @param flags is an out parameter that should hold any spi flags upon return.
|
||||
* The avaible flags are prefixed with SPI_FLAG_
|
||||
*
|
||||
* @return 0 on success
|
||||
* -1 if any error occurs
|
||||
*
|
||||
*/
|
||||
int owl_spi_init(uint8_t *flags);
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when a spi transfer should be performed.
|
||||
*
|
||||
* All buffers that are allocated by the wl library will have a size that is
|
||||
* aligned to 4. If size-unaligned data is passed to this function, it is
|
||||
* always allocated by the ip stack. If 4-byte size alignment (e.g. for DMA)
|
||||
* is required, 1-3 extra padding bytes can be transmitted after the in buffer.
|
||||
* These bytes must be 0xff.
|
||||
*
|
||||
* Since size-unaligned data always comes from the ip stack, the out ptr is
|
||||
* always NULL for such data.
|
||||
*
|
||||
* @param in points a buffer which holds the data to be transmitted. If NULL,
|
||||
* then \a len bytes with the value 0xff should be transmitted on the
|
||||
* bus.
|
||||
* @param out points a buffer should hold the data received from the device. If
|
||||
* NULL, any received data can be discarded.
|
||||
* @param len is the length of the in and out buffers.
|
||||
*
|
||||
*/
|
||||
void owl_spi_txrx(const uint8_t *in, uint8_t* out, uint16_t len);
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when spi rx interrupts from the device should be enabled or disabled.
|
||||
* Note that the spi interrupts are obtained from pin 8 on SPB104 or pin 3 from
|
||||
* SPB105. This pin can be be connected to a gpio on the host. The irq line
|
||||
* will signal an interrupt on both edges.
|
||||
*
|
||||
* In general, the wifi device will not issue a new interrupt unless the
|
||||
* last interrupt has been handled. Also, during normal operation (i.e after
|
||||
* the complete callback registered in wl_init() has been invoked),
|
||||
* owl_spi_irq() will never be invoked so interrupts will be enabled all
|
||||
* the time. For the SPI-mode, the purpose of owl_spi_irq() is basically to
|
||||
* make sure that the first interrupt (coming after the reset performed in
|
||||
* owl_spi_init()) is ignored.
|
||||
*
|
||||
* If SPI_FLAG_POLL was set in owl_spi_init(), then this function can be
|
||||
* left empty and the wifi device will be used in polled mode. In polled mode,
|
||||
* the interrupt line is not used. Regardless of polled or interrupt-mode,
|
||||
* wl_poll() must be called to ensure progress of the driver.
|
||||
*
|
||||
* @param enable specifies if interrupts should be enabled or disabled.
|
||||
*
|
||||
*/
|
||||
void owl_spi_irq(uint8_t enable);
|
||||
|
||||
|
||||
/**
|
||||
* Invoked when the spi cs for the wifi device should be enabled. Note that
|
||||
* multiple calls to owl_spi_txrx() might be done during a 'single' chip
|
||||
* select.
|
||||
*
|
||||
* @param enable specifies whether chip select should be asserted or deasserted,
|
||||
* The chip select signal is active low, so if enable is '1' then the
|
||||
* chip select connected to the wifi device should be set to '0'.
|
||||
*
|
||||
*/
|
||||
void owl_spi_cs(uint8_t enable);
|
||||
|
||||
|
||||
/**
|
||||
* Delay executiom for the specified number of ms. This function will be called
|
||||
* with delays in the 10-20 ms range during fw download and startup of the
|
||||
* Wi-Fi device. This function can be implemented with a simple for-loop if
|
||||
* desired (beware of optimization). The timing does not have to be accurate as
|
||||
* long as the actual delay becomes at least the specified number of ms.
|
||||
*
|
||||
* @param ms is the minimal amount of time to wait [ms].
|
||||
*
|
||||
*/
|
||||
void owl_spi_mdelay(uint32_t ms);
|
||||
|
||||
|
||||
/**
|
||||
* This function should be called whenever an interrupt is detected. It can
|
||||
* be called from an interrupt context.
|
||||
*
|
||||
* If SPI_FLAG_POLL was set in owl_spi_init(), then wl_spi_irq()
|
||||
* should never be called.
|
||||
*
|
||||
*/
|
||||
extern void wl_spi_irq(void);
|
||||
|
||||
|
||||
/*! @} */
|
||||
|
||||
#endif
|
|
@ -0,0 +1,154 @@
|
|||
/*
|
||||
* Programming interface for wlap_api.
|
||||
* Copyright (C) 2011 HD Wireless AB
|
||||
*
|
||||
* You should have received a copy of the license along with this library.
|
||||
*/
|
||||
|
||||
/*! \file wlap_api.h *************************************************************
|
||||
*
|
||||
* \brief WiFi AP API
|
||||
*
|
||||
* This file provides the wlap_api interface.
|
||||
*
|
||||
* - Compiler: GNU GCC for AVR32
|
||||
* - Supported devices:
|
||||
* \li SPB104 + EVK1100
|
||||
* \li SPB104 + EVK1101
|
||||
* \li SPB104 + EVK1104
|
||||
* \li SPB104 + EVK1105 (SPI)
|
||||
* \li SPB104 + EVK1105 (SPI + irq)
|
||||
* \li SPB105 + EVK1105 (SPI)
|
||||
* - AppNote:
|
||||
*
|
||||
* \author H&D Wireless AB: \n
|
||||
*
|
||||
*****************************************************************************
|
||||
*
|
||||
* \section intro Introduction
|
||||
* This is the documentation for the WiFi AP Driver API \a wlap_api.
|
||||
*
|
||||
* \section files Main Files
|
||||
* - wlap_api.h : WiFi driver interface.
|
||||
* - libwlap_api_*.*.a - Driver library.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef WLAP_API_H
|
||||
#define WLAP_API_H
|
||||
|
||||
#define WLAP_API_RELEASE_NAME "unknown"
|
||||
|
||||
#include <wl_api.h>
|
||||
|
||||
/** \defgroup wl_softap Access Point Mode
|
||||
*
|
||||
* \brief Support the WiFi Access Point mode.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
/*
|
||||
* Station representation
|
||||
*
|
||||
*/
|
||||
struct wl_sta_t
|
||||
{
|
||||
struct wl_mac_addr_t bssid; /**< The BSSID of the network. */
|
||||
uint8_t queued_pkt_cnt; /**< Number of queueud packets for
|
||||
this STA. */
|
||||
uint8_t in_ps; /**< Is the STA in power save mode. */
|
||||
uint8_t aid; /**< STA AID */
|
||||
};
|
||||
|
||||
/* Station list representation. Array of pointers to wl_sta_t entries. */
|
||||
struct wl_sta_list_t
|
||||
{
|
||||
struct wl_sta_t **sta; /**< The list of pointers to stations */
|
||||
size_t cnt; /**< Number of stations */
|
||||
};
|
||||
|
||||
/*! \brief Get the list of currently associated stations (SoftAP).
|
||||
*
|
||||
* Retrieves the list of current stations from
|
||||
* the driver.
|
||||
*
|
||||
* This function is not thread safe. It must be called in the
|
||||
* same execution context as wl_poll().
|
||||
*
|
||||
* @param network_list Output buffer. The API call returns
|
||||
* a pointer to allocated memory containing the network list.
|
||||
* @return
|
||||
* - WL_SUCCESS
|
||||
* - WL_FAILURE.
|
||||
*/
|
||||
wl_err_t wlap_get_sta_list(struct wl_sta_list_t **network_list);
|
||||
|
||||
|
||||
/*! Callback used to read data from a TX packet.
|
||||
* This function is supplied by the user of the API.
|
||||
*
|
||||
* @param dst Destination buffer. The data should be copied
|
||||
* to this buffer.
|
||||
* @param src_handle Handle to the source packet from where
|
||||
* the data should be copied. This handle is the same one that
|
||||
* is passed in parameter \a pkt_handle to \a wl_process_tx().
|
||||
* @param read_len Number of bytes to copy from \a src_handle
|
||||
* to \a dst.
|
||||
* @param offset The offset in bytes, counting from the
|
||||
* beginning of the Ethernet header, from where to copy data.
|
||||
* @return
|
||||
* - The number of bytes copied. This number may be smaller
|
||||
* than the length requested in \a read_len but it may not
|
||||
* be shorter than the length of the packet counting from
|
||||
* \a offset. In other words, if the caller of this function
|
||||
* receives a return count that is shorter than \a read_len
|
||||
* he will assume that all packet data has been read.
|
||||
* - < 0 on error.
|
||||
*/
|
||||
typedef ssize_t (*wl_pkt_read_cb_t)(char *dst,
|
||||
void *src_handle,
|
||||
size_t read_len,
|
||||
int offset);
|
||||
|
||||
/*! \brief Register a data access function for TX packets (SoftAP).
|
||||
*
|
||||
* When a TX data packet has a different representation than a single
|
||||
* contiguous buffer in memory then a packet read function must be
|
||||
* implemented and registered with this call. Whenever the library
|
||||
* needs to read packet data it will call this function to do it.
|
||||
*
|
||||
* This function can be ignored if the TX packet representation is
|
||||
* a single contiguous buffer. This function is only needed in SoftAP
|
||||
* mode.
|
||||
*
|
||||
* @param pkt_read_cb Read callback.
|
||||
* @param ctx Context
|
||||
*/
|
||||
void wl_register_pkt_read_cb(wl_pkt_read_cb_t pkt_read_cb);
|
||||
|
||||
/*! \brief Start a network using the SoftAP mode.
|
||||
*
|
||||
* This call will cause the WiFi chip to start sending beacons
|
||||
* and accept associations from WiFi stations.
|
||||
*
|
||||
*/
|
||||
wl_err_t wlap_start_ap(const char *ssid,
|
||||
const size_t ssid_len,
|
||||
const uint8_t channel,
|
||||
const enum wl_auth_mode auth_mode,
|
||||
const enum wl_enc_type enc_type);
|
||||
|
||||
/*! \brief Disconnect a STA (SoftAP)
|
||||
*
|
||||
* @param bssid The BSSID of the station to disconnect.
|
||||
* @return
|
||||
* - WL_SUCCESS
|
||||
* - WL_FAILURE.
|
||||
*/
|
||||
wl_err_t wlap_disconnect_sta(const struct wl_mac_addr_t bssid);
|
||||
|
||||
|
||||
/*! @} */ /* End wl_softap group */
|
||||
|
||||
|
||||
#endif
|
|
@ -0,0 +1,309 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file has been prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief Cycle counter driver.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32UC devices.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _CYCLE_COUNTER_H_
|
||||
#define _CYCLE_COUNTER_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
|
||||
//! Structure holding private information, automatically initialized by the
|
||||
//! cpu_set_timeout() function.
|
||||
typedef struct
|
||||
{
|
||||
//! The cycle count at the begining of the timeout.
|
||||
unsigned long delay_start_cycle;
|
||||
|
||||
//! The cycle count at the end of the timeout.
|
||||
unsigned long delay_end_cycle;
|
||||
|
||||
//! Enable/disable the timout detection
|
||||
unsigned char timer_state;
|
||||
#define CPU_TIMER_STATE_STARTED 0
|
||||
#define CPU_TIMER_STATE_REACHED 1
|
||||
#define CPU_TIMER_STATE_STOPPED 2
|
||||
} t_cpu_time;
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Convert milli-seconds into CPU cycles.
|
||||
*
|
||||
* \param ms: Number of millisecond.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*
|
||||
* \return the converted number of CPU cycles.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ U32 cpu_ms_2_cy(unsigned long ms, unsigned long fcpu_hz)
|
||||
{
|
||||
return ((unsigned long long)ms * fcpu_hz + 999) / 1000;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Convert micro-seconds into CPU cycles.
|
||||
*
|
||||
* \param us: Number of microsecond.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*
|
||||
* \return the converted number of CPU cycles.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ U32 cpu_us_2_cy(unsigned long us, unsigned long fcpu_hz)
|
||||
{
|
||||
return ((unsigned long long)us * fcpu_hz + 999999) / 1000000;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Convert CPU cycles into milli-seconds.
|
||||
*
|
||||
* \param cy: Number of CPU cycles.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*
|
||||
* \return the converted number of milli-second.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ U32 cpu_cy_2_ms(unsigned long cy, unsigned long fcpu_hz)
|
||||
{
|
||||
return ((unsigned long long)cy * 1000 + fcpu_hz-1) / fcpu_hz;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Convert CPU cycles into micro-seconds.
|
||||
*
|
||||
* \param cy: Number of CPU cycles.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*
|
||||
* \return the converted number of micro-second.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ U32 cpu_cy_2_us(unsigned long cy, unsigned long fcpu_hz)
|
||||
{
|
||||
return ((unsigned long long)cy * 1000000 + fcpu_hz-1) / fcpu_hz;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Set a timer variable.
|
||||
*
|
||||
* Ex: t_cpu_time timer;
|
||||
* cpu_set_timeout( cpu_ms_2_cy(10, FOSC0), &timer ); // timeout in 10 ms
|
||||
* if( cpu_is_timeout(&timer) )
|
||||
* cpu_stop_timeout(&timer);
|
||||
* ../..
|
||||
*
|
||||
* \param delay: (input) delay in CPU cycles before timeout.
|
||||
* \param cpu_time: (output) internal information used by the timer API.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void cpu_set_timeout(unsigned long delay, t_cpu_time *cpu_time)
|
||||
{
|
||||
cpu_time->delay_start_cycle = Get_system_register(AVR32_COUNT);
|
||||
cpu_time->delay_end_cycle = cpu_time->delay_start_cycle + delay;
|
||||
cpu_time->timer_state = CPU_TIMER_STATE_STARTED;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Test if a timer variable reached its timeout.
|
||||
*
|
||||
* Once the timeout is reached, the function will always return TRUE,
|
||||
* until the cpu_stop_timeout() function is called.
|
||||
*
|
||||
* Ex: t_cpu_time timer;
|
||||
* cpu_set_timeout( 10, FOSC0, &timer ); // timeout in 10 ms
|
||||
* if( cpu_is_timeout(&timer) )
|
||||
* cpu_stop_timeout(&timer);
|
||||
* ../..
|
||||
*
|
||||
* \param cpu_time: (input) internal information used by the timer API.
|
||||
*
|
||||
* \return TRUE if timeout occured, otherwise FALSE.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ unsigned long cpu_is_timeout(t_cpu_time *cpu_time)
|
||||
{
|
||||
unsigned long current_cycle_count = Get_system_register(AVR32_COUNT);
|
||||
|
||||
if( cpu_time->timer_state==CPU_TIMER_STATE_STOPPED )
|
||||
return FALSE;
|
||||
|
||||
// Test if the timeout as already occured.
|
||||
else if (cpu_time->timer_state == CPU_TIMER_STATE_REACHED)
|
||||
return TRUE;
|
||||
|
||||
// If the ending cycle count of this timeout is wrapped, ...
|
||||
else if (cpu_time->delay_start_cycle > cpu_time->delay_end_cycle)
|
||||
{
|
||||
if (current_cycle_count < cpu_time->delay_start_cycle && current_cycle_count > cpu_time->delay_end_cycle)
|
||||
{
|
||||
cpu_time->timer_state = CPU_TIMER_STATE_REACHED;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (current_cycle_count < cpu_time->delay_start_cycle || current_cycle_count > cpu_time->delay_end_cycle)
|
||||
{
|
||||
cpu_time->timer_state = CPU_TIMER_STATE_REACHED;
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Stop a timeout detection.
|
||||
*
|
||||
* Ex: t_cpu_time timer;
|
||||
* cpu_set_timeout( 10, FOSC0, &timer ); // timeout in 10 ms
|
||||
* if( cpu_is_timeout(&timer) )
|
||||
* cpu_stop_timeout(&timer);
|
||||
* ../..
|
||||
*
|
||||
* \param cpu_time: (input) internal information used by the timer API.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void cpu_stop_timeout(t_cpu_time *cpu_time)
|
||||
{
|
||||
cpu_time->timer_state = CPU_TIMER_STATE_STOPPED;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Test if a timer is stopped.
|
||||
*
|
||||
* \param cpu_time: (input) internal information used by the timer API.
|
||||
*
|
||||
* \return TRUE if timer is stopped, otherwise FALSE.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ unsigned long cpu_is_timer_stopped(t_cpu_time *cpu_time)
|
||||
{
|
||||
|
||||
if( cpu_time->timer_state==CPU_TIMER_STATE_STOPPED )
|
||||
return TRUE;
|
||||
else
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
/*!
|
||||
* \brief Waits during at least the specified delay (in millisecond) before returning.
|
||||
*
|
||||
* \param delay: Number of millisecond to wait.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void cpu_delay_ms(unsigned long delay, unsigned long fcpu_hz)
|
||||
{
|
||||
t_cpu_time timer;
|
||||
cpu_set_timeout( cpu_ms_2_cy(delay, fcpu_hz), &timer);
|
||||
while( !cpu_is_timeout(&timer) );
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Waits during at least the specified delay (in microsecond) before returning.
|
||||
*
|
||||
* \param delay: Number of microsecond to wait.
|
||||
* \param fcpu_hz: CPU frequency in Hz.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void cpu_delay_us(unsigned long delay, unsigned long fcpu_hz)
|
||||
{
|
||||
t_cpu_time timer;
|
||||
cpu_set_timeout( cpu_us_2_cy(delay, fcpu_hz), &timer);
|
||||
while( !cpu_is_timeout(&timer) );
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Waits during at least the specified delay (in CPU cycles) before returning.
|
||||
*
|
||||
* \param delay: Number of CPU cycles to wait.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void cpu_delay_cy(unsigned long delay)
|
||||
{
|
||||
t_cpu_time timer;
|
||||
cpu_set_timeout( delay, &timer);
|
||||
while( !cpu_is_timeout(&timer) );
|
||||
}
|
||||
|
||||
|
||||
#define Get_sys_count() ( Get_system_register(AVR32_COUNT) )
|
||||
#define Set_sys_count(x) ( Set_system_register(AVR32_COUNT, (x)) )
|
||||
#define Get_sys_compare() ( Get_system_register(AVR32_COMPARE) )
|
||||
#define Set_sys_compare(x) ( Set_system_register(AVR32_COMPARE, (x)) )
|
||||
|
||||
|
||||
#endif // _CYCLE_COUNTER_H_
|
|
@ -0,0 +1,995 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief SMC on EBI driver for AVR32 UC3.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with a SMC module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#include "compiler.h"
|
||||
#include "preprocessor.h"
|
||||
#include "gpio.h"
|
||||
#include "smc.h"
|
||||
|
||||
// Configure the SM Controller with SM setup and timing information for all chip select
|
||||
#define SMC_CS_SETUP(ncs) { \
|
||||
U32 nwe_setup = ((NWE_SETUP * hsb_mhz_up + 999) / 1000); \
|
||||
U32 ncs_wr_setup = ((NCS_WR_SETUP * hsb_mhz_up + 999) / 1000); \
|
||||
U32 nrd_setup = ((NRD_SETUP * hsb_mhz_up + 999) / 1000); \
|
||||
U32 ncs_rd_setup = ((NCS_RD_SETUP * hsb_mhz_up + 999) / 1000); \
|
||||
U32 nwe_pulse = ((NWE_PULSE * hsb_mhz_up + 999) / 1000); \
|
||||
U32 ncs_wr_pulse = ((NCS_WR_PULSE * hsb_mhz_up + 999) / 1000); \
|
||||
U32 nrd_pulse = ((NRD_PULSE * hsb_mhz_up + 999) / 1000); \
|
||||
U32 ncs_rd_pulse = ((NCS_RD_PULSE * hsb_mhz_up + 999) / 1000); \
|
||||
U32 nwe_cycle = ((NWE_CYCLE * hsb_mhz_up + 999) / 1000); \
|
||||
U32 nrd_cycle = ((NRD_CYCLE * hsb_mhz_up + 999) / 1000); \
|
||||
\
|
||||
/* Some coherence checks... */ \
|
||||
/* Ensures CS is active during Rd or Wr */ \
|
||||
if( ncs_rd_setup + ncs_rd_pulse < nrd_setup + nrd_pulse ) \
|
||||
ncs_rd_pulse = nrd_setup + nrd_pulse - ncs_rd_setup; \
|
||||
if( ncs_wr_setup + ncs_wr_pulse < nwe_setup + nwe_pulse ) \
|
||||
ncs_wr_pulse = nwe_setup + nwe_pulse - ncs_wr_setup; \
|
||||
\
|
||||
/* ncs_hold = n_cycle - ncs_setup - ncs_pulse */ \
|
||||
/* n_hold = n_cycle - n_setup - n_pulse */ \
|
||||
/* */ \
|
||||
/* All holds parameters must be positive or null, so: */ \
|
||||
/* nwe_cycle shall be >= ncs_wr_setup + ncs_wr_pulse */ \
|
||||
if( nwe_cycle < ncs_wr_setup + ncs_wr_pulse ) \
|
||||
nwe_cycle = ncs_wr_setup + ncs_wr_pulse; \
|
||||
\
|
||||
/* nwe_cycle shall be >= nwe_setup + nwe_pulse */ \
|
||||
if( nwe_cycle < nwe_setup + nwe_pulse ) \
|
||||
nwe_cycle = nwe_setup + nwe_pulse; \
|
||||
\
|
||||
/* nrd_cycle shall be >= ncs_rd_setup + ncs_rd_pulse */ \
|
||||
if( nrd_cycle < ncs_rd_setup + ncs_rd_pulse ) \
|
||||
nrd_cycle = ncs_rd_setup + ncs_rd_pulse; \
|
||||
\
|
||||
/* nrd_cycle shall be >= nrd_setup + nrd_pulse */ \
|
||||
if( nrd_cycle < nrd_setup + nrd_pulse ) \
|
||||
nrd_cycle = nrd_setup + nrd_pulse; \
|
||||
\
|
||||
AVR32_SMC.cs[ncs].setup = (nwe_setup << AVR32_SMC_SETUP0_NWE_SETUP_OFFSET) | \
|
||||
(ncs_wr_setup << AVR32_SMC_SETUP0_NCS_WR_SETUP_OFFSET) | \
|
||||
(nrd_setup << AVR32_SMC_SETUP0_NRD_SETUP_OFFSET) | \
|
||||
(ncs_rd_setup << AVR32_SMC_SETUP0_NCS_RD_SETUP_OFFSET); \
|
||||
AVR32_SMC.cs[ncs].pulse = (nwe_pulse << AVR32_SMC_PULSE0_NWE_PULSE_OFFSET) | \
|
||||
(ncs_wr_pulse << AVR32_SMC_PULSE0_NCS_WR_PULSE_OFFSET) | \
|
||||
(nrd_pulse << AVR32_SMC_PULSE0_NRD_PULSE_OFFSET) | \
|
||||
(ncs_rd_pulse << AVR32_SMC_PULSE0_NCS_RD_PULSE_OFFSET); \
|
||||
AVR32_SMC.cs[ncs].cycle = (nwe_cycle << AVR32_SMC_CYCLE0_NWE_CYCLE_OFFSET) | \
|
||||
(nrd_cycle << AVR32_SMC_CYCLE0_NRD_CYCLE_OFFSET); \
|
||||
AVR32_SMC.cs[ncs].mode = (((NCS_CONTROLLED_READ) ? AVR32_SMC_MODE0_READ_MODE_NCS_CONTROLLED : \
|
||||
AVR32_SMC_MODE0_READ_MODE_NRD_CONTROLLED) << AVR32_SMC_MODE0_READ_MODE_OFFSET) | \
|
||||
+ (((NCS_CONTROLLED_WRITE) ? AVR32_SMC_MODE0_WRITE_MODE_NCS_CONTROLLED : \
|
||||
AVR32_SMC_MODE0_WRITE_MODE_NWE_CONTROLLED) << AVR32_SMC_MODE0_WRITE_MODE_OFFSET) | \
|
||||
(NWAIT_MODE << AVR32_SMC_MODE0_EXNW_MODE_OFFSET) | \
|
||||
(((SMC_8_BIT_CHIPS) ? AVR32_SMC_MODE0_BAT_BYTE_WRITE : \
|
||||
AVR32_SMC_MODE0_BAT_BYTE_SELECT) << AVR32_SMC_MODE0_BAT_OFFSET) | \
|
||||
(((SMC_DBW <= 8 ) ? AVR32_SMC_MODE0_DBW_8_BITS : \
|
||||
(SMC_DBW <= 16) ? AVR32_SMC_MODE0_DBW_16_BITS : \
|
||||
AVR32_SMC_MODE0_DBW_32_BITS) << AVR32_SMC_MODE0_DBW_OFFSET) | \
|
||||
(TDF_CYCLES << AVR32_SMC_MODE0_TDF_CYCLES_OFFSET) | \
|
||||
(TDF_OPTIM << AVR32_SMC_MODE0_TDF_MODE_OFFSET) | \
|
||||
(PAGE_MODE << AVR32_SMC_MODE0_PMEN_OFFSET) | \
|
||||
(PAGE_SIZE << AVR32_SMC_MODE0_PS_OFFSET); \
|
||||
smc_tab_cs_size[ncs] = (U8)EXT_SM_SIZE; \
|
||||
}
|
||||
|
||||
static U8 smc_tab_cs_size[6];
|
||||
|
||||
static void smc_enable_muxed_pins(void);
|
||||
|
||||
|
||||
void smc_init(unsigned long hsb_hz)
|
||||
{
|
||||
unsigned long hsb_mhz_up = (hsb_hz + 999999) / 1000000;
|
||||
|
||||
//! Whether to use the NCS0 pin
|
||||
#ifdef SMC_USE_NCS0
|
||||
#include SMC_COMPONENT_CS0
|
||||
|
||||
// Setup SMC for NCS0
|
||||
SMC_CS_SETUP(0)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
|
||||
|
||||
//! Whether to use the NCS1 pin
|
||||
#ifdef SMC_USE_NCS1
|
||||
#include SMC_COMPONENT_CS1
|
||||
|
||||
// Enable SM mode for CS1 if necessary.
|
||||
AVR32_HMATRIX.sfr[AVR32_EBI_HMATRIX_NR] &= ~(1 << AVR32_EBI_SDRAM_CS);
|
||||
AVR32_HMATRIX.sfr[AVR32_EBI_HMATRIX_NR];
|
||||
|
||||
// Setup SMC for NCS1
|
||||
SMC_CS_SETUP(1)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
|
||||
//! Whether to use the NCS2 pin
|
||||
#ifdef SMC_USE_NCS2
|
||||
#include SMC_COMPONENT_CS2
|
||||
|
||||
// Setup SMC for NCS2
|
||||
SMC_CS_SETUP(2)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
|
||||
//! Whether to use the NCS3 pin
|
||||
#ifdef SMC_USE_NCS3
|
||||
#include SMC_COMPONENT_CS3
|
||||
|
||||
// Setup SMC for NCS3
|
||||
SMC_CS_SETUP(3)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
|
||||
//! Whether to use the NCS4 pin
|
||||
#ifdef SMC_USE_NCS4
|
||||
#include SMC_COMPONENT_CS4
|
||||
|
||||
// Setup SMC for NCS4
|
||||
SMC_CS_SETUP(4)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
|
||||
//! Whether to use the NCS5 pin
|
||||
#ifdef SMC_USE_NCS5
|
||||
#include SMC_COMPONENT_CS5
|
||||
|
||||
// Setup SMC for NCS5
|
||||
SMC_CS_SETUP(5)
|
||||
|
||||
#ifdef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW_GLOBAL < SMC_DBW)
|
||||
#undef SMC_DBW_GLOBAL
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_DBW == 8)
|
||||
#define SMC_DBW_GLOBAL 8
|
||||
#elif (SMC_DBW == 16)
|
||||
#define SMC_DBW_GLOBAL 16
|
||||
#elif (SMC_DBW == 32)
|
||||
#define SMC_DBW_GLOBAL 32
|
||||
#else
|
||||
#error error in SMC_DBW size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS_GLOBAL < SMC_8_BIT)
|
||||
#undef SMC_8_BIT_CHIPS_GLOBAL
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (SMC_8_BIT_CHIPS == TRUE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL TRUE
|
||||
#elif (SMC_8_BIT_CHIPS == FALSE)
|
||||
#define SMC_8_BIT_CHIPS_GLOBAL FALSE
|
||||
#else
|
||||
#error error in SMC_8_BIT_CHIPS size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE_GLOBAL < NWAIT_MODE)
|
||||
#undef NWAIT_MODE_GLOBAL
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
#else
|
||||
#if (NWAIT_MODE == AVR32_SMC_EXNW_MODE_DISABLED)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#elif (NWAIT_MODE == AVR32_SMC_EXNW_MODE_FROZEN)
|
||||
#define NWAIT_MODE_GLOBAL AVR32_SMC_EXNW_MODE_FROZEN
|
||||
#else
|
||||
#error error in NWAIT_MODE size
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
#undef EXT_SM_SIZE
|
||||
#undef SMC_DBW
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#undef NWE_SETUP
|
||||
#undef NCS_WR_SETUP
|
||||
#undef NRD_SETUP
|
||||
#undef NCS_RD_SETUP
|
||||
#undef NCS_WR_PULSE
|
||||
#undef NWE_PULSE
|
||||
#undef NCS_RD_PULSE
|
||||
#undef NRD_PULSE
|
||||
#undef NCS_WR_HOLD
|
||||
#undef NWE_HOLD
|
||||
#undef NWE_CYCLE
|
||||
#undef NCS_RD_HOLD
|
||||
#undef NRD_CYCLE
|
||||
#undef TDF_CYCLES
|
||||
#undef TDF_OPTIM
|
||||
#undef PAGE_MODE
|
||||
#undef PAGE_SIZE
|
||||
#undef NCS_CONTROLLED_READ
|
||||
#undef NCS_CONTROLLED_WRITE
|
||||
#undef NWAIT_MODE
|
||||
#endif
|
||||
// Put the multiplexed MCU pins used for the SM under control of the SMC.
|
||||
smc_enable_muxed_pins();
|
||||
}
|
||||
|
||||
/*! \brief Puts the multiplexed MCU pins used for the SMC
|
||||
*
|
||||
*/
|
||||
static void smc_enable_muxed_pins(void)
|
||||
{
|
||||
static const gpio_map_t SMC_EBI_GPIO_MAP =
|
||||
{
|
||||
// Enable data pins.
|
||||
#ifdef EBI_DATA_0
|
||||
{ATPASTE2(EBI_DATA_0,_PIN),ATPASTE2(EBI_DATA_0,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_1
|
||||
{ATPASTE2(EBI_DATA_1,_PIN),ATPASTE2(EBI_DATA_1,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_2
|
||||
{ATPASTE2(EBI_DATA_2,_PIN),ATPASTE2(EBI_DATA_2,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_3
|
||||
{ATPASTE2(EBI_DATA_3,_PIN),ATPASTE2(EBI_DATA_3,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_4
|
||||
{ATPASTE2(EBI_DATA_4,_PIN),ATPASTE2(EBI_DATA_4,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_5
|
||||
{ATPASTE2(EBI_DATA_5,_PIN),ATPASTE2(EBI_DATA_5,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_6
|
||||
{ATPASTE2(EBI_DATA_6,_PIN),ATPASTE2(EBI_DATA_6,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_7
|
||||
{ATPASTE2(EBI_DATA_7,_PIN),ATPASTE2(EBI_DATA_7,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_8
|
||||
{ATPASTE2(EBI_DATA_8,_PIN),ATPASTE2(EBI_DATA_8,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_9
|
||||
{ATPASTE2(EBI_DATA_9,_PIN),ATPASTE2(EBI_DATA_9,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_10
|
||||
{ATPASTE2(EBI_DATA_10,_PIN),ATPASTE2(EBI_DATA_10,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_11
|
||||
{ATPASTE2(EBI_DATA_11,_PIN),ATPASTE2(EBI_DATA_11,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_12
|
||||
{ATPASTE2(EBI_DATA_12,_PIN),ATPASTE2(EBI_DATA_12,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_13
|
||||
{ATPASTE2(EBI_DATA_13,_PIN),ATPASTE2(EBI_DATA_13,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_14
|
||||
{ATPASTE2(EBI_DATA_14,_PIN),ATPASTE2(EBI_DATA_14,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_15
|
||||
{ATPASTE2(EBI_DATA_15,_PIN),ATPASTE2(EBI_DATA_15,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_16
|
||||
{ATPASTE2(EBI_DATA_16,_PIN),ATPASTE2(EBI_DATA_16,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_17
|
||||
{ATPASTE2(EBI_DATA_17,_PIN),ATPASTE2(EBI_DATA_17,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_18
|
||||
{ATPASTE2(EBI_DATA_18,_PIN),ATPASTE2(EBI_DATA_18,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_19
|
||||
{ATPASTE2(EBI_DATA_19,_PIN),ATPASTE2(EBI_DATA_19,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_20
|
||||
{ATPASTE2(EBI_DATA_20,_PIN),ATPASTE2(EBI_DATA_20,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_21
|
||||
{ATPASTE2(EBI_DATA_21,_PIN),ATPASTE2(EBI_DATA_21,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_22
|
||||
{ATPASTE2(EBI_DATA_22,_PIN),ATPASTE2(EBI_DATA_22,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_23
|
||||
{ATPASTE2(EBI_DATA_23,_PIN),ATPASTE2(EBI_DATA_23,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_24
|
||||
{ATPASTE2(EBI_DATA_24,_PIN),ATPASTE2(EBI_DATA_24,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_25
|
||||
{ATPASTE2(EBI_DATA_25,_PIN),ATPASTE2(EBI_DATA_25,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_26
|
||||
{ATPASTE2(EBI_DATA_26,_PIN),ATPASTE2(EBI_DATA_26,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_27
|
||||
{ATPASTE2(EBI_DATA_27,_PIN),ATPASTE2(EBI_DATA_27,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_28
|
||||
{ATPASTE2(EBI_DATA_28,_PIN),ATPASTE2(EBI_DATA_28,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_29
|
||||
{ATPASTE2(EBI_DATA_29,_PIN),ATPASTE2(EBI_DATA_29,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_30
|
||||
{ATPASTE2(EBI_DATA_30,_PIN),ATPASTE2(EBI_DATA_30,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_DATA_31
|
||||
{ATPASTE2(EBI_DATA_31,_PIN),ATPASTE2(EBI_DATA_31,_FUNCTION)},
|
||||
#endif
|
||||
|
||||
// Enable address pins.
|
||||
#if SMC_DBW_GLOBAL <= 8
|
||||
#ifdef EBI_ADDR_0
|
||||
{ATPASTE2(EBI_ADDR_0,_PIN),ATPASTE2(EBI_ADDR_0,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#if SMC_DBW_GLOBAL <= 16
|
||||
#ifdef EBI_ADDR_1
|
||||
{ATPASTE2(EBI_ADDR_1,_PIN),ATPASTE2(EBI_ADDR_1,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#ifdef EBI_ADDR_2
|
||||
{ATPASTE2(EBI_ADDR_2,_PIN),ATPASTE2(EBI_ADDR_2,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_3
|
||||
{ATPASTE2(EBI_ADDR_3,_PIN),ATPASTE2(EBI_ADDR_3,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_4
|
||||
{ATPASTE2(EBI_ADDR_4,_PIN),ATPASTE2(EBI_ADDR_4,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_5
|
||||
{ATPASTE2(EBI_ADDR_5,_PIN),ATPASTE2(EBI_ADDR_5,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_6
|
||||
{ATPASTE2(EBI_ADDR_6,_PIN),ATPASTE2(EBI_ADDR_6,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_7
|
||||
{ATPASTE2(EBI_ADDR_7,_PIN),ATPASTE2(EBI_ADDR_7,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_8
|
||||
{ATPASTE2(EBI_ADDR_8,_PIN),ATPASTE2(EBI_ADDR_8,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_9
|
||||
{ATPASTE2(EBI_ADDR_9,_PIN),ATPASTE2(EBI_ADDR_9,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_10
|
||||
{ATPASTE2(EBI_ADDR_10,_PIN),ATPASTE2(EBI_ADDR_10,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_11
|
||||
{ATPASTE2(EBI_ADDR_11,_PIN),ATPASTE2(EBI_ADDR_11,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_12
|
||||
{ATPASTE2(EBI_ADDR_12,_PIN),ATPASTE2(EBI_ADDR_12,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_13
|
||||
{ATPASTE2(EBI_ADDR_13,_PIN),ATPASTE2(EBI_ADDR_13,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_14
|
||||
{ATPASTE2(EBI_ADDR_14,_PIN),ATPASTE2(EBI_ADDR_14,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_15
|
||||
{ATPASTE2(EBI_ADDR_15,_PIN),ATPASTE2(EBI_ADDR_15,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_16
|
||||
{ATPASTE2(EBI_ADDR_16,_PIN),ATPASTE2(EBI_ADDR_16,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_17
|
||||
{ATPASTE2(EBI_ADDR_17,_PIN),ATPASTE2(EBI_ADDR_17,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_18
|
||||
{ATPASTE2(EBI_ADDR_18,_PIN),ATPASTE2(EBI_ADDR_18,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_19
|
||||
{ATPASTE2(EBI_ADDR_19,_PIN),ATPASTE2(EBI_ADDR_19,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_20
|
||||
{ATPASTE2(EBI_ADDR_20,_PIN),ATPASTE2(EBI_ADDR_20,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_21
|
||||
{ATPASTE2(EBI_ADDR_21,_PIN),ATPASTE2(EBI_ADDR_21,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_22
|
||||
{ATPASTE2(EBI_ADDR_22,_PIN),ATPASTE2(EBI_ADDR_22,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_ADDR_23
|
||||
{ATPASTE2(EBI_ADDR_23,_PIN),ATPASTE2(EBI_ADDR_23,_FUNCTION)},
|
||||
#endif
|
||||
|
||||
#if SMC_DBW_GLOBAL <= 8
|
||||
#undef SMC_8_BIT_CHIPS
|
||||
#define SMC_8_BIT_CHIPS TRUE
|
||||
#endif
|
||||
|
||||
// Enable data mask pins.
|
||||
#if !SMC_8_BIT_CHIPS_GLOBAL
|
||||
#ifdef EBI_ADDR_0
|
||||
{ATPASTE2(EBI_ADDR_0,_PIN),ATPASTE2(EBI_ADDR_0,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef EBI_NWE0
|
||||
{ATPASTE2(EBI_NWE0,_PIN),ATPASTE2(EBI_NWE0,_FUNCTION)},
|
||||
#endif
|
||||
|
||||
#if SMC_DBW_GLOBAL >= 16
|
||||
#ifdef EBI_NWE1
|
||||
{ATPASTE2(EBI_NWE1,_PIN),ATPASTE2(EBI_NWE1,_FUNCTION)},
|
||||
#endif
|
||||
#if SMC_DBW_GLOBAL >= 32
|
||||
#ifdef EBI_ADDR_1
|
||||
{ATPASTE2(EBI_ADDR_1,_PIN),ATPASTE2(EBI_ADDR_1,_FUNCTION)},
|
||||
#endif
|
||||
#ifdef EBI_NWE3
|
||||
{ATPASTE2(EBI_NWE3,_PIN),ATPASTE2(EBI_NWE3,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
#ifdef EBI_NRD
|
||||
{ATPASTE2(EBI_NRD,_PIN),ATPASTE2(EBI_NRD,_FUNCTION)},
|
||||
#endif
|
||||
|
||||
// Enable control pins.
|
||||
#if NWAIT_MODE_GLOBAL != AVR32_SMC_EXNW_MODE_DISABLED
|
||||
#ifdef EBI_NWAIT
|
||||
{ATPASTE2(EBI_NWAIT,_PIN),ATPASTE2(EBI_NWAIT,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS0
|
||||
#ifdef EBI_NCS_0
|
||||
{ATPASTE2(EBI_NCS_0,_PIN),ATPASTE2(EBI_NCS_0,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS1
|
||||
#ifdef EBI_NCS_1
|
||||
{ATPASTE2(EBI_NCS_1,_PIN),ATPASTE2(EBI_NCS_1,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS2
|
||||
#ifdef EBI_NCS_2
|
||||
{ATPASTE2(EBI_NCS_2,_PIN),ATPASTE2(EBI_NCS_2,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS3
|
||||
#ifdef EBI_NCS_3
|
||||
{ATPASTE2(EBI_NCS_3,_PIN),ATPASTE2(EBI_NCS_3,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS4
|
||||
#ifdef EBI_NCS_4
|
||||
{ATPASTE2(EBI_NCS_4,_PIN),ATPASTE2(EBI_NCS_4,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
#ifdef SMC_USE_NCS5
|
||||
#ifdef EBI_NCS_5
|
||||
{ATPASTE2(EBI_NCS_5,_PIN),ATPASTE2(EBI_NCS_5,_FUNCTION)},
|
||||
#endif
|
||||
#endif
|
||||
};
|
||||
|
||||
gpio_enable_module(SMC_EBI_GPIO_MAP, sizeof(SMC_EBI_GPIO_MAP) / sizeof(SMC_EBI_GPIO_MAP[0]));
|
||||
}
|
||||
|
||||
unsigned char smc_get_cs_size(unsigned char cs)
|
||||
{
|
||||
return smc_tab_cs_size[cs];
|
||||
}
|
|
@ -0,0 +1,68 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief SMC on EBI driver for AVR32 UC3.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with a SMC module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _SMC_H_
|
||||
#define _SMC_H_
|
||||
|
||||
#include <avr32/io.h>
|
||||
|
||||
#include "compiler.h"
|
||||
#include "conf_ebi.h"
|
||||
|
||||
/*! \brief Initializes the AVR32 SMC module and the connected SRAM(s).
|
||||
* \param hsb_hz HSB frequency in Hz (the HSB frequency is applied to the SMC).
|
||||
* \note Each access to the SMC address space validates the mode of the SMC
|
||||
* and generates an operation corresponding to this mode.
|
||||
*/
|
||||
extern void smc_init(unsigned long hsb_hz);
|
||||
|
||||
/*! \brief Return the size of the peripheral connected .
|
||||
* \param cs The chip select value
|
||||
*/
|
||||
extern unsigned char smc_get_cs_size(unsigned char cs);
|
||||
|
||||
#endif // _SMC_H_
|
|
@ -0,0 +1,183 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief EIC driver for AVR32 UC3.
|
||||
*
|
||||
* AVR32 External Interrupt Controller driver module.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an EIC module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#include <avr32/io.h>
|
||||
#include "compiler.h"
|
||||
#include "preprocessor.h"
|
||||
#include "eic.h"
|
||||
|
||||
|
||||
|
||||
void eic_init(volatile avr32_eic_t *eic, const eic_options_t *opt, unsigned int nb_lines)
|
||||
{
|
||||
int i;
|
||||
for (i = 0; i < nb_lines; i++)
|
||||
{
|
||||
// Set up mode level
|
||||
eic->mode = (opt[i].eic_mode == 1) ? (eic->mode | (1 << opt[i].eic_line)) : (eic->mode & ~(1 << opt[i].eic_line));
|
||||
// Set up edge type
|
||||
eic->edge = (opt[i].eic_edge == 1) ? (eic->edge | (1 << opt[i].eic_line)) : (eic->edge & ~(1 << opt[i].eic_line));
|
||||
// Set up level
|
||||
eic->level = (opt[i].eic_level == 1) ? (eic->level | (1 << opt[i].eic_line)) : (eic->level & ~(1 << opt[i].eic_line));
|
||||
// Set up if filter is used
|
||||
eic->filter = (opt[i].eic_filter == 1) ? (eic->filter | (1 << opt[i].eic_line)) : (eic->filter & ~(1 << opt[i].eic_line));
|
||||
// Set up which mode is used : asynchronous mode/ synchronous mode
|
||||
eic->async = (opt[i].eic_async == 1) ? (eic->async | (1 << opt[i].eic_line)) : (eic->async & ~(1 << opt[i].eic_line));
|
||||
}
|
||||
}
|
||||
|
||||
void eic_enable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
|
||||
{
|
||||
eic->en = mask_lines;
|
||||
}
|
||||
|
||||
void eic_enable_line(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
// Enable line line_number
|
||||
eic->en = 1 << line_number;
|
||||
}
|
||||
|
||||
void eic_disable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
|
||||
{
|
||||
eic->dis = mask_lines;
|
||||
}
|
||||
|
||||
void eic_disable_line(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
// Disable line line_number
|
||||
eic->dis = 1 << line_number;
|
||||
}
|
||||
|
||||
Bool eic_is_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
return (eic->ctrl & (1 << line_number)) != 0;
|
||||
}
|
||||
|
||||
void eic_enable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
|
||||
{
|
||||
eic->ier = mask_lines;
|
||||
}
|
||||
|
||||
void eic_enable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
// Enable line line_number
|
||||
eic->ier = 1 << line_number;
|
||||
}
|
||||
|
||||
void eic_disable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
|
||||
{
|
||||
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
|
||||
|
||||
if (global_interrupt_enabled) Disable_global_interrupt();
|
||||
eic->idr = mask_lines;
|
||||
eic->imr;
|
||||
if (global_interrupt_enabled) Enable_global_interrupt();
|
||||
}
|
||||
|
||||
void eic_disable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
|
||||
|
||||
// Disable line line_number
|
||||
if (global_interrupt_enabled) Disable_global_interrupt();
|
||||
eic->idr = 1 << line_number;
|
||||
eic->imr;
|
||||
if (global_interrupt_enabled) Enable_global_interrupt();
|
||||
}
|
||||
|
||||
Bool eic_is_interrupt_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
return (eic->imr & (1 << line_number)) != 0;
|
||||
}
|
||||
|
||||
void eic_clear_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines)
|
||||
{
|
||||
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
|
||||
|
||||
if (global_interrupt_enabled) Disable_global_interrupt();
|
||||
eic->icr = mask_lines;
|
||||
eic->isr;
|
||||
if (global_interrupt_enabled) Enable_global_interrupt();
|
||||
}
|
||||
|
||||
void eic_clear_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
Bool global_interrupt_enabled = Is_global_interrupt_enabled();
|
||||
|
||||
// Clear line line_number
|
||||
if (global_interrupt_enabled) Disable_global_interrupt();
|
||||
eic->icr = 1 << line_number;
|
||||
eic->isr;
|
||||
if (global_interrupt_enabled) Enable_global_interrupt();
|
||||
}
|
||||
|
||||
Bool eic_is_interrupt_line_pending(volatile avr32_eic_t *eic, unsigned int line_number)
|
||||
{
|
||||
return (eic->isr & (1 << line_number)) != 0;
|
||||
}
|
||||
|
||||
#if !defined(AVR32_EIC_301_H_INCLUDED)
|
||||
void eic_enable_interrupt_scan(volatile avr32_eic_t *eic,unsigned int presc)
|
||||
{
|
||||
// Enable SCAN function with PRESC value
|
||||
eic->scan |= (presc << AVR32_EIC_SCAN_PRESC_OFFSET) | (1 << AVR32_EIC_SCAN_EN_OFFSET);
|
||||
}
|
||||
|
||||
void eic_disable_interrupt_scan(volatile avr32_eic_t *eic)
|
||||
{
|
||||
// Disable SCAN function
|
||||
eic->scan = 0 << AVR32_EIC_SCAN_EN_OFFSET;
|
||||
}
|
||||
|
||||
unsigned long eic_get_interrupt_pad_scan(volatile avr32_eic_t *eic)
|
||||
{
|
||||
// Return pad number that causes interrupt
|
||||
return(eic->scan>>AVR32_EIC_SCAN_PIN_OFFSET);
|
||||
}
|
||||
#endif
|
|
@ -0,0 +1,275 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file is prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief EIC driver for AVR32 UC3.
|
||||
*
|
||||
* AVR32 External Interrupt Controller driver module.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with an EIC module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
******************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _EIC_H_
|
||||
#define _EIC_H_
|
||||
|
||||
#include "compiler.h"
|
||||
|
||||
/*! \name External Interrupt lines
|
||||
*/
|
||||
//! @{
|
||||
#if (UC3A || UC3B)
|
||||
#define EXT_INT0 AVR32_EIC_INT0 //!< Line 0
|
||||
#define EXT_INT1 AVR32_EIC_INT1 //!< Line 1
|
||||
#define EXT_INT2 AVR32_EIC_INT2 //!< Line 2
|
||||
#define EXT_INT3 AVR32_EIC_INT3 //!< Line 3
|
||||
#define EXT_INT4 AVR32_EIC_INT4 //!< Line 4
|
||||
#define EXT_INT5 AVR32_EIC_INT5 //!< Line 5
|
||||
#define EXT_INT6 AVR32_EIC_INT6 //!< Line 6
|
||||
#define EXT_INT7 AVR32_EIC_INT7 //!< Line 7
|
||||
#define EXT_NMI AVR32_EIC_NMI //!< Line 8
|
||||
#else
|
||||
#define EXT_INT0 AVR32_EIC_INT1 //!< Line 0
|
||||
#define EXT_INT1 AVR32_EIC_INT2 //!< Line 1
|
||||
#define EXT_INT2 AVR32_EIC_INT3 //!< Line 2
|
||||
#define EXT_INT3 AVR32_EIC_INT4 //!< Line 3
|
||||
#define EXT_INT4 AVR32_EIC_INT5 //!< Line 4
|
||||
#define EXT_INT5 AVR32_EIC_INT6 //!< Line 5
|
||||
#define EXT_INT6 AVR32_EIC_INT7 //!< Line 6
|
||||
#define EXT_INT7 AVR32_EIC_INT8 //!< Line 7
|
||||
#define EXT_NMI AVR32_EIC_NMI //!< Line 8
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
||||
|
||||
/*! \name Mode Trigger Options
|
||||
*/
|
||||
//! @{
|
||||
#define EIC_MODE_EDGE_TRIGGERED AVR32_EIC_EDGE_IRQ //!<
|
||||
#define EIC_MODE_LEVEL_TRIGGERED AVR32_EIC_LEVEL_IRQ //!<
|
||||
//! @}
|
||||
|
||||
/*! \name Edge level Options
|
||||
*/
|
||||
//! @{
|
||||
#define EIC_EDGE_FALLING_EDGE AVR32_EIC_FALLING_EDGE //!<
|
||||
#define EIC_EDGE_RISING_EDGE AVR32_EIC_RISING_EDGE //!<
|
||||
//! @}
|
||||
|
||||
/*! \name Level Options
|
||||
*/
|
||||
//! @{
|
||||
#define EIC_LEVEL_LOW_LEVEL AVR32_EIC_LOW_LEVEL //!<
|
||||
#define EIC_LEVEL_HIGH_LEVEL AVR32_EIC_HIGH_LEVEL //!<
|
||||
//! @}
|
||||
|
||||
/*! \name Filter Options
|
||||
*/
|
||||
//! @{
|
||||
#define EIC_FILTER_ENABLED AVR32_EIC_FILTER_ON //!<
|
||||
#define EIC_FILTER_DISABLED AVR32_EIC_FILTER_OFF //!<
|
||||
//! @}
|
||||
|
||||
/*! \name Synch Mode Options
|
||||
*/
|
||||
//! @{
|
||||
#define EIC_SYNCH_MODE AVR32_EIC_SYNC //!<
|
||||
#define EIC_ASYNCH_MODE AVR32_EIC_USE_ASYNC //!<
|
||||
//! @}
|
||||
|
||||
//! Configuration parameters of the EIC module.
|
||||
typedef struct
|
||||
{
|
||||
//!Line
|
||||
unsigned char eic_line;
|
||||
|
||||
//! Mode : EDGE_LEVEL or TRIGGER_LEVEL
|
||||
unsigned char eic_mode;
|
||||
|
||||
//! Edge : FALLING_EDGE or RISING_EDGE
|
||||
unsigned char eic_edge;
|
||||
|
||||
//! Level : LOW_LEVEL or HIGH_LEVEL
|
||||
unsigned char eic_level;
|
||||
|
||||
//! Filter: NOT_FILTERED or FILTERED
|
||||
unsigned char eic_filter;
|
||||
|
||||
//! Async: SYNC mode or ASYNC
|
||||
unsigned char eic_async;
|
||||
|
||||
} eic_options_t;
|
||||
|
||||
|
||||
/*! \brief Init the EIC driver.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param opt Configuration parameters of the EIC module (see \ref eic_options_t)
|
||||
* \param nb_lines Number of lines to consider, equal to size of opt buffer
|
||||
*/
|
||||
extern void eic_init(volatile avr32_eic_t *eic, const eic_options_t *opt, unsigned int nb_lines);
|
||||
|
||||
/*! \brief Enable the EIC driver.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param mask_lines Mask for current selected lines
|
||||
*/
|
||||
extern void eic_enable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines);
|
||||
|
||||
/*! \brief Enable the EIC driver.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param line_number Line number to enable
|
||||
*/
|
||||
extern void eic_enable_line(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Disable the EIC driver.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param mask_lines Mask for current selected lines
|
||||
*/
|
||||
extern void eic_disable_lines(volatile avr32_eic_t *eic, unsigned int mask_lines);
|
||||
|
||||
/*! \brief Disable the EIC driver.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param line_number Line number to disable
|
||||
*/
|
||||
extern void eic_disable_line(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Tells whether an EIC line is enabled.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param line_number Line number to test
|
||||
*
|
||||
* \return Whether an EIC line is enabled.
|
||||
*/
|
||||
extern Bool eic_is_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \name Interrupt Control Functions
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Enable the interrupt feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param mask_lines Mask for current selected lines
|
||||
*/
|
||||
extern void eic_enable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines);
|
||||
|
||||
/*! \brief Enable the interrupt feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param line_number Line number to enable
|
||||
*/
|
||||
extern void eic_enable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Disable the interrupt feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param mask_lines Mask for current selected lines
|
||||
*/
|
||||
extern void eic_disable_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines);
|
||||
|
||||
/*! \brief Disable the interrupt feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param line_number Line number to disable
|
||||
*/
|
||||
extern void eic_disable_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Tells whether an EIC interrupt line is enabled.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param line_number Line number to test
|
||||
*
|
||||
* \return Whether an EIC interrupt line is enabled.
|
||||
*/
|
||||
extern Bool eic_is_interrupt_line_enabled(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Clear the interrupt flag.
|
||||
* Call this function once you've handled the interrupt.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param mask_lines Mask for current selected lines
|
||||
*/
|
||||
extern void eic_clear_interrupt_lines(volatile avr32_eic_t *eic, unsigned int mask_lines);
|
||||
|
||||
/*! \brief Clear the interrupt flag.
|
||||
* Call this function once you've handled the interrupt.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param line_number Line number to clear
|
||||
*/
|
||||
extern void eic_clear_interrupt_line(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Tells whether an EIC interrupt line is pending.
|
||||
*
|
||||
* \param eic Base address of the EIC module
|
||||
* \param line_number Line number to test
|
||||
*
|
||||
* \return Whether an EIC interrupt line is pending.
|
||||
*/
|
||||
extern Bool eic_is_interrupt_line_pending(volatile avr32_eic_t *eic, unsigned int line_number);
|
||||
|
||||
/*! \brief Enable the interrupt scan feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
* \param presc Prescale select for the keypad scan rate in the range [0,31].
|
||||
*/
|
||||
extern void eic_enable_interrupt_scan(volatile avr32_eic_t *eic, unsigned int presc);
|
||||
|
||||
/*! \brief Disable the interrupt scan feature of the EIC.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
*/
|
||||
extern void eic_disable_interrupt_scan(volatile avr32_eic_t *eic);
|
||||
|
||||
/*! \brief Return scan pad number that causes interrupt.
|
||||
*
|
||||
* \param eic Base address of the EIC (i.e. &AVR32_EIC).
|
||||
*/
|
||||
extern unsigned long eic_get_interrupt_pad_scan(volatile avr32_eic_t *eic);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#endif // _EIC_H_
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,458 @@
|
|||
/* This source file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file has been prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief GPIO driver for AVR32 UC3.
|
||||
*
|
||||
* This file defines a useful set of functions for the GPIO.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with a GPIO module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
//! GPIO module instance.
|
||||
#define GPIO AVR32_GPIO
|
||||
|
||||
|
||||
/*! \name Peripheral Bus Interface
|
||||
*/
|
||||
//! @{
|
||||
|
||||
|
||||
int gpio_enable_module(const gpio_map_t gpiomap, unsigned int size)
|
||||
{
|
||||
int status = GPIO_SUCCESS;
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
status |= gpio_enable_module_pin(gpiomap->pin, gpiomap->function);
|
||||
gpiomap++;
|
||||
}
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
|
||||
int gpio_enable_module_pin(unsigned int pin, unsigned int function)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
// Enable the correct function.
|
||||
switch (function)
|
||||
{
|
||||
case 0: // A function.
|
||||
gpio_port->pmr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1c = 1 << (pin & 0x1F);
|
||||
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
gpio_port->pmr2c = 1 << (pin & 0x1F);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 1: // B function.
|
||||
gpio_port->pmr0s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1c = 1 << (pin & 0x1F);
|
||||
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
gpio_port->pmr2c = 1 << (pin & 0x1F);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 2: // C function.
|
||||
gpio_port->pmr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1s = 1 << (pin & 0x1F);
|
||||
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
gpio_port->pmr2c = 1 << (pin & 0x1F);
|
||||
#endif
|
||||
break;
|
||||
|
||||
case 3: // D function.
|
||||
gpio_port->pmr0s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1s = 1 << (pin & 0x1F);
|
||||
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
gpio_port->pmr2c = 1 << (pin & 0x1F);
|
||||
#endif
|
||||
break;
|
||||
|
||||
#if defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
case 4: // E function.
|
||||
gpio_port->pmr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr2s = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
case 5: // F function.
|
||||
gpio_port->pmr0s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr2s = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
case 6: // G function.
|
||||
gpio_port->pmr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr2s = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
case 7: // H function.
|
||||
gpio_port->pmr0s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr1s = 1 << (pin & 0x1F);
|
||||
gpio_port->pmr2s = 1 << (pin & 0x1F);
|
||||
break;
|
||||
#endif
|
||||
|
||||
default:
|
||||
return GPIO_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
// Disable GPIO control.
|
||||
gpio_port->gperc = 1 << (pin & 0x1F);
|
||||
|
||||
return GPIO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void gpio_enable_gpio(const gpio_map_t gpiomap, unsigned int size)
|
||||
{
|
||||
unsigned int i;
|
||||
|
||||
for (i = 0; i < size; i++)
|
||||
{
|
||||
gpio_enable_gpio_pin(gpiomap->pin);
|
||||
gpiomap++;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void gpio_enable_gpio_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->oderc = 1 << (pin & 0x1F);
|
||||
gpio_port->gpers = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
// The open-drain mode is not synthesized on the current AVR32 products.
|
||||
// If one day some AVR32 products have this feature, the corresponding part
|
||||
// numbers should be listed in the #if below.
|
||||
// Note that other functions are available in this driver to use pins with open
|
||||
// drain in GPIO mode. The advantage of the open-drain mode functions over these
|
||||
// other functions is that they can be used not only in GPIO mode but also in
|
||||
// module mode.
|
||||
#if 0
|
||||
|
||||
|
||||
void gpio_enable_pin_open_drain(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->odmers = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
void gpio_disable_pin_open_drain(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->odmerc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
void gpio_enable_pin_pull_up(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->puers = 1 << (pin & 0x1F);
|
||||
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
gpio_port->pderc = 1 << (pin & 0x1F);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
void gpio_disable_pin_pull_up(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->puerc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
// Added support of Pull-up Resistor, Pull-down Resistor and Buskeeper Control.
|
||||
|
||||
/*! \brief Enables the pull-down resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
void gpio_enable_pin_pull_down(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->puerc = 1 << (pin & 0x1F);
|
||||
gpio_port->pders = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Disables the pull-down resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
void gpio_disable_pin_pull_down(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->pderc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Enables the buskeeper functionality on a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
void gpio_enable_pin_buskeeper(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->puers = 1 << (pin & 0x1F);
|
||||
gpio_port->pders = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Disables the buskeeper functionality on a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
void gpio_disable_pin_buskeeper(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->puerc = 1 << (pin & 0x1F);
|
||||
gpio_port->pderc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int gpio_get_pin_value(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
return (gpio_port->pvr >> (pin & 0x1F)) & 1;
|
||||
}
|
||||
|
||||
|
||||
int gpio_get_gpio_pin_output_value(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
return (gpio_port->ovr >> (pin & 0x1F)) & 1;
|
||||
}
|
||||
|
||||
|
||||
int gpio_get_gpio_open_drain_pin_output_value(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
return ((gpio_port->oder >> (pin & 0x1F)) & 1) ^ 1;
|
||||
}
|
||||
|
||||
|
||||
void gpio_set_gpio_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->ovrs = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 1.
|
||||
gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_clr_gpio_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->ovrc = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
|
||||
gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_tgl_gpio_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->ovrt = 1 << (pin & 0x1F); // Toggle the I/O line.
|
||||
gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_set_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_clr_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->ovrc = 1 << (pin & 0x1F); // Value to be driven on the I/O line: 0.
|
||||
gpio_port->oders = 1 << (pin & 0x1F); // The GPIO output driver is enabled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_tgl_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
gpio_port->ovrc = 1 << (pin & 0x1F); // Value to be driven on the I/O line if the GPIO output driver is enabled: 0.
|
||||
gpio_port->odert = 1 << (pin & 0x1F); // The GPIO output driver is toggled for that pin.
|
||||
gpio_port->gpers = 1 << (pin & 0x1F); // The GPIO module controls that pin.
|
||||
}
|
||||
|
||||
|
||||
void gpio_enable_pin_glitch_filter(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->gfers = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
void gpio_disable_pin_glitch_filter(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->gferc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Configure the edge detector of an input pin
|
||||
*
|
||||
* \param pin The pin number.
|
||||
* \param mode The edge detection mode (\ref GPIO_PIN_CHANGE, \ref GPIO_RISING_EDGE
|
||||
* or \ref GPIO_FALLING_EDGE).
|
||||
*
|
||||
* \return \ref GPIO_SUCCESS or \ref GPIO_INVALID_ARGUMENT.
|
||||
*/
|
||||
static int gpio_configure_edge_detector(unsigned int pin, unsigned int mode)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
// Configure the edge detector.
|
||||
switch (mode)
|
||||
{
|
||||
case GPIO_PIN_CHANGE:
|
||||
gpio_port->imr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->imr1c = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
case GPIO_RISING_EDGE:
|
||||
gpio_port->imr0s = 1 << (pin & 0x1F);
|
||||
gpio_port->imr1c = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
case GPIO_FALLING_EDGE:
|
||||
gpio_port->imr0c = 1 << (pin & 0x1F);
|
||||
gpio_port->imr1s = 1 << (pin & 0x1F);
|
||||
break;
|
||||
|
||||
default:
|
||||
return GPIO_INVALID_ARGUMENT;
|
||||
}
|
||||
|
||||
return GPIO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
int gpio_enable_pin_interrupt(unsigned int pin, unsigned int mode)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
// Enable the glitch filter.
|
||||
gpio_port->gfers = 1 << (pin & 0x1F);
|
||||
|
||||
// Configure the edge detector.
|
||||
if(GPIO_INVALID_ARGUMENT == gpio_configure_edge_detector(pin, mode))
|
||||
return(GPIO_INVALID_ARGUMENT);
|
||||
|
||||
// Enable interrupt.
|
||||
gpio_port->iers = 1 << (pin & 0x1F);
|
||||
|
||||
return GPIO_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
void gpio_disable_pin_interrupt(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->ierc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
int gpio_get_pin_interrupt_flag(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
return (gpio_port->ifr >> (pin & 0x1F)) & 1;
|
||||
}
|
||||
|
||||
|
||||
void gpio_clear_pin_interrupt_flag(unsigned int pin)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
gpio_port->ifrc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
|
||||
//#
|
||||
//# Peripheral Event System Support.
|
||||
//#
|
||||
#if UC3L
|
||||
int gpio_configure_pin_periph_event_mode(unsigned int pin, unsigned int mode, unsigned int use_igf)
|
||||
{
|
||||
volatile avr32_gpio_port_t *gpio_port = &GPIO.port[pin >> 5];
|
||||
|
||||
if(TRUE == use_igf)
|
||||
{
|
||||
// Enable the glitch filter.
|
||||
gpio_port->gfers = 1 << (pin & 0x1F);
|
||||
}
|
||||
else
|
||||
{
|
||||
// Disable the glitch filter.
|
||||
gpio_port->gferc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
// Configure the edge detector.
|
||||
return(gpio_configure_edge_detector(pin, mode));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
//! @}
|
|
@ -0,0 +1,583 @@
|
|||
/* This header file is part of the ATMEL AVR-UC3-SoftwareFramework-1.7.0 Release */
|
||||
|
||||
/*This file has been prepared for Doxygen automatic documentation generation.*/
|
||||
/*! \file *********************************************************************
|
||||
*
|
||||
* \brief GPIO header for AVR32 UC3.
|
||||
*
|
||||
* This file contains basic GPIO driver functions.
|
||||
*
|
||||
* - Compiler: IAR EWAVR32 and GNU GCC for AVR32
|
||||
* - Supported devices: All AVR32 devices with a GPIO module can be used.
|
||||
* - AppNote:
|
||||
*
|
||||
* \author Atmel Corporation: http://www.atmel.com \n
|
||||
* Support and FAQ: http://support.atmel.no/
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
/* Copyright (c) 2009 Atmel Corporation. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* 3. The name of Atmel may not be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* 4. This software may only be redistributed and used in connection with an Atmel
|
||||
* AVR product.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ATMEL "AS IS" AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT ARE
|
||||
* EXPRESSLY AND SPECIFICALLY DISCLAIMED. IN NO EVENT SHALL ATMEL BE LIABLE FOR
|
||||
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _GPIO_H_
|
||||
#define _GPIO_H_
|
||||
|
||||
#include <avr32/io.h>
|
||||
#include "compiler.h"
|
||||
|
||||
/*! \name Return Values of the GPIO API
|
||||
*/
|
||||
//! @{
|
||||
#define GPIO_SUCCESS 0 //!< Function successfully completed.
|
||||
#define GPIO_INVALID_ARGUMENT 1 //!< Input parameters are out of range.
|
||||
//! @}
|
||||
|
||||
|
||||
/*! \name Interrupt Trigger Modes
|
||||
*/
|
||||
//! @{
|
||||
#define GPIO_PIN_CHANGE 0 //!< Interrupt triggered upon pin change.
|
||||
#define GPIO_RISING_EDGE 1 //!< Interrupt triggered upon rising edge.
|
||||
#define GPIO_FALLING_EDGE 2 //!< Interrupt triggered upon falling edge.
|
||||
//! @}
|
||||
|
||||
|
||||
//! A type definition of pins and modules connectivity.
|
||||
typedef struct
|
||||
{
|
||||
unsigned char pin; //!< Module pin.
|
||||
unsigned char function; //!< Module function.
|
||||
} gpio_map_t[];
|
||||
|
||||
|
||||
/*! \name Peripheral Bus Interface
|
||||
*
|
||||
* Low-speed interface with a non-deterministic number of clock cycles per
|
||||
* access.
|
||||
*
|
||||
* This interface operates with lower clock frequencies (fPB <= fCPU), and its
|
||||
* timing is not deterministic since it needs to access a shared bus which may
|
||||
* be heavily loaded.
|
||||
*
|
||||
* \note This interface is immediately available without initialization.
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Enables specific module modes for a set of pins.
|
||||
*
|
||||
* \param gpiomap The pin map.
|
||||
* \param size The number of pins in \a gpiomap.
|
||||
*
|
||||
* \return \ref GPIO_SUCCESS or \ref GPIO_INVALID_ARGUMENT.
|
||||
*/
|
||||
extern int gpio_enable_module(const gpio_map_t gpiomap, unsigned int size);
|
||||
|
||||
/*! \brief Enables a specific module mode for a pin.
|
||||
*
|
||||
* \param pin The pin number.\n
|
||||
* Refer to the product header file `uc3x.h' (where x is the part
|
||||
* number; e.g. x = a0512) for module pins. E.g., to enable a PWM
|
||||
* channel output, the pin number can be AVR32_PWM_3_PIN for PWM
|
||||
* channel 3.
|
||||
* \param function The pin function.\n
|
||||
* Refer to the product header file `uc3x.h' (where x is the
|
||||
* part number; e.g. x = a0512) for module pin functions. E.g.,
|
||||
* to enable a PWM channel output, the pin function can be
|
||||
* AVR32_PWM_3_FUNCTION for PWM channel 3.
|
||||
*
|
||||
* \return \ref GPIO_SUCCESS or \ref GPIO_INVALID_ARGUMENT.
|
||||
*/
|
||||
extern int gpio_enable_module_pin(unsigned int pin, unsigned int function);
|
||||
|
||||
/*! \brief Enables the GPIO mode of a set of pins.
|
||||
*
|
||||
* \param gpiomap The pin map.
|
||||
* \param size The number of pins in \a gpiomap.
|
||||
*/
|
||||
extern void gpio_enable_gpio(const gpio_map_t gpiomap, unsigned int size);
|
||||
|
||||
/*! \brief Enables the GPIO mode of a pin.
|
||||
*
|
||||
* \param pin The pin number.\n
|
||||
* Refer to the product header file `uc3x.h' (where x is the part
|
||||
* number; e.g. x = a0512) for pin definitions. E.g., to enable the
|
||||
* GPIO mode of PX21, AVR32_PIN_PX21 can be used. Module pins such as
|
||||
* AVR32_PWM_3_PIN for PWM channel 3 can also be used to release
|
||||
* module pins for GPIO.
|
||||
*/
|
||||
extern void gpio_enable_gpio_pin(unsigned int pin);
|
||||
|
||||
// The open-drain mode is not synthesized on the current AVR32 products.
|
||||
// If one day some AVR32 products have this feature, the corresponding part
|
||||
// numbers should be listed in the #if below.
|
||||
// Note that other functions are available in this driver to use pins with open
|
||||
// drain in GPIO mode. The advantage of the open-drain mode functions over these
|
||||
// other functions is that they can be used not only in GPIO mode but also in
|
||||
// module mode.
|
||||
#if 0
|
||||
|
||||
/*! \brief Enables the open-drain mode of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_enable_pin_open_drain(unsigned int pin);
|
||||
|
||||
/*! \brief Disables the open-drain mode of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_open_drain(unsigned int pin);
|
||||
|
||||
#endif
|
||||
|
||||
/*! \brief Enables the pull-up resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_enable_pin_pull_up(unsigned int pin);
|
||||
|
||||
/*! \brief Disables the pull-up resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_pull_up(unsigned int pin);
|
||||
|
||||
#if defined(AVR32_GPIO_200_H_INCLUDED) || defined(AVR32_GPIO_210_H_INCLUDED) || defined(AVR32_GPIO_211_H_INCLUDED)
|
||||
// Added support of Pull-up Resistor, Pull-down Resistor and Buskeeper Control.
|
||||
|
||||
/*! \brief Enables the pull-down resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_enable_pin_pull_down(unsigned int pin);
|
||||
|
||||
/*! \brief Disables the pull-down resistor of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_pull_down(unsigned int pin);
|
||||
|
||||
/*! \brief Enables the buskeeper functionality on a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_enable_pin_buskeeper(unsigned int pin);
|
||||
|
||||
/*! \brief Disables the buskeeper functionality on a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_buskeeper(unsigned int pin);
|
||||
|
||||
#endif
|
||||
|
||||
/*! \brief Returns the value of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \return The pin value.
|
||||
*/
|
||||
extern int gpio_get_pin_value(unsigned int pin);
|
||||
|
||||
/*! \brief Returns the output value set for a GPIO pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \return The pin output value.
|
||||
*
|
||||
* \note This function must be used in conjunction with \ref gpio_set_gpio_pin,
|
||||
* \ref gpio_clr_gpio_pin and \ref gpio_tgl_gpio_pin.
|
||||
*/
|
||||
extern int gpio_get_gpio_pin_output_value(unsigned int pin);
|
||||
|
||||
/*! \brief Returns the output value set for a GPIO pin using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \return The pin output value.
|
||||
*
|
||||
* \note This function must be used in conjunction with
|
||||
* \ref gpio_set_gpio_open_drain_pin, \ref gpio_clr_gpio_open_drain_pin
|
||||
* and \ref gpio_tgl_gpio_open_drain_pin.
|
||||
*/
|
||||
extern int gpio_get_gpio_open_drain_pin_output_value(unsigned int pin);
|
||||
|
||||
/*! \brief Drives a GPIO pin to 1.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_set_gpio_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Drives a GPIO pin to 0.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_clr_gpio_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Toggles a GPIO pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_tgl_gpio_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Drives a GPIO pin to 1 using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_set_gpio_open_drain_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Drives a GPIO pin to 0 using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_clr_gpio_open_drain_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Toggles a GPIO pin using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_tgl_gpio_open_drain_pin(unsigned int pin);
|
||||
|
||||
/*! \brief Enables the glitch filter of a pin.
|
||||
*
|
||||
* When the glitch filter is enabled, a glitch with duration of less than 1
|
||||
* clock cycle is automatically rejected, while a pulse with duration of 2 clock
|
||||
* cycles or more is accepted. For pulse durations between 1 clock cycle and 2
|
||||
* clock cycles, the pulse may or may not be taken into account, depending on
|
||||
* the precise timing of its occurrence. Thus for a pulse to be guaranteed
|
||||
* visible it must exceed 2 clock cycles, whereas for a glitch to be reliably
|
||||
* filtered out, its duration must not exceed 1 clock cycle. The filter
|
||||
* introduces 2 clock cycles latency.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_enable_pin_glitch_filter(unsigned int pin);
|
||||
|
||||
/*! \brief Disables the glitch filter of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_glitch_filter(unsigned int pin);
|
||||
|
||||
/*! \brief Enables the interrupt of a pin with the specified settings.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
* \param mode The trigger mode (\ref GPIO_PIN_CHANGE, \ref GPIO_RISING_EDGE or
|
||||
* \ref GPIO_FALLING_EDGE).
|
||||
*
|
||||
* \return \ref GPIO_SUCCESS or \ref GPIO_INVALID_ARGUMENT.
|
||||
*/
|
||||
extern int gpio_enable_pin_interrupt(unsigned int pin, unsigned int mode);
|
||||
|
||||
/*! \brief Disables the interrupt of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_disable_pin_interrupt(unsigned int pin);
|
||||
|
||||
/*! \brief Gets the interrupt flag of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \return The pin interrupt flag.
|
||||
*/
|
||||
extern int gpio_get_pin_interrupt_flag(unsigned int pin);
|
||||
|
||||
/*! \brief Clears the interrupt flag of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*/
|
||||
extern void gpio_clear_pin_interrupt_flag(unsigned int pin);
|
||||
|
||||
//! @}
|
||||
|
||||
|
||||
#if (defined AVR32_GPIO_LOCAL_ADDRESS)
|
||||
/*! \name Local Bus Interface
|
||||
*
|
||||
* High-speed interface with only one clock cycle per access.
|
||||
*
|
||||
* This interface operates with high clock frequency (fCPU), and its timing is
|
||||
* deterministic since it does not need to access a shared bus which may be
|
||||
* heavily loaded.
|
||||
*
|
||||
* \warning To use this interface, the clock frequency of the peripheral bus on
|
||||
* which the GPIO peripheral is connected must be set to the CPU clock
|
||||
* frequency (fPB = fCPU).
|
||||
*
|
||||
* \note This interface has to be initialized in order to be available.
|
||||
*/
|
||||
//! @{
|
||||
|
||||
/*! \brief Enables the local bus interface for GPIO.
|
||||
*
|
||||
* \note This function must have been called at least once before using other
|
||||
* functions in this interface.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_init(void)
|
||||
{
|
||||
Set_system_register(AVR32_CPUCR,
|
||||
Get_system_register(AVR32_CPUCR) | AVR32_CPUCR_LOCEN_MASK);
|
||||
}
|
||||
|
||||
/*! \brief Enables the output driver of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin.
|
||||
* \ref gpio_enable_gpio_pin can be called for this purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_enable_pin_output_driver(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Disables the output driver of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_disable_pin_output_driver(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Returns the value of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \return The pin value.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ int gpio_local_get_pin_value(unsigned int pin)
|
||||
{
|
||||
return (AVR32_GPIO_LOCAL.port[pin >> 5].pvr >> (pin & 0x1F)) & 1;
|
||||
}
|
||||
|
||||
/*! \brief Drives a GPIO pin to 1.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin nor its output
|
||||
* driver. \ref gpio_enable_gpio_pin and
|
||||
* \ref gpio_local_enable_pin_output_driver can be called for this
|
||||
* purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_set_gpio_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].ovrs = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Drives a GPIO pin to 0.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin nor its output
|
||||
* driver. \ref gpio_enable_gpio_pin and
|
||||
* \ref gpio_local_enable_pin_output_driver can be called for this
|
||||
* purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_clr_gpio_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Toggles a GPIO pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init must have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin nor its output
|
||||
* driver. \ref gpio_enable_gpio_pin and
|
||||
* \ref gpio_local_enable_pin_output_driver can be called for this
|
||||
* purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_tgl_gpio_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].ovrt = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Initializes the configuration of a GPIO pin so that it can be used
|
||||
* with GPIO open-drain functions.
|
||||
*
|
||||
* \note This function must have been called at least once before using
|
||||
* \ref gpio_local_set_gpio_open_drain_pin,
|
||||
* \ref gpio_local_clr_gpio_open_drain_pin or
|
||||
* \ref gpio_local_tgl_gpio_open_drain_pin.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_init_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].ovrc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Drives a GPIO pin to 1 using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init and \ref gpio_local_init_gpio_open_drain_pin must
|
||||
* have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin.
|
||||
* \ref gpio_enable_gpio_pin can be called for this purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_set_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].oderc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Drives a GPIO pin to 0 using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init and \ref gpio_local_init_gpio_open_drain_pin must
|
||||
* have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin.
|
||||
* \ref gpio_enable_gpio_pin can be called for this purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_clr_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].oders = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Toggles a GPIO pin using open drain.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
* \note \ref gpio_local_init and \ref gpio_local_init_gpio_open_drain_pin must
|
||||
* have been called beforehand.
|
||||
*
|
||||
* \note This function does not enable the GPIO mode of the pin.
|
||||
* \ref gpio_enable_gpio_pin can be called for this purpose.
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_local_tgl_gpio_open_drain_pin(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO_LOCAL.port[pin >> 5].odert = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
//! @}
|
||||
#endif // AVR32_GPIO_LOCAL_ADDRESS
|
||||
|
||||
#if UC3L
|
||||
//! @{
|
||||
/*! \name Peripheral Event System support
|
||||
*
|
||||
* The GPIO can be programmed to output peripheral events whenever an interrupt
|
||||
* condition is detected, such as pin value change, or only when a rising or
|
||||
* falling edge is detected.
|
||||
*
|
||||
*/
|
||||
|
||||
/*! \brief Enables the peripheral event generation of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_enable_pin_periph_event(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO.port[pin >> 5].oderc = 1 << (pin & 0x1F); // The GPIO output driver is disabled for that pin.
|
||||
AVR32_GPIO.port[pin >> 5].evers = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Disables the peripheral event generation of a pin.
|
||||
*
|
||||
* \param pin The pin number.
|
||||
*
|
||||
*/
|
||||
#if (defined __GNUC__)
|
||||
__attribute__((__always_inline__))
|
||||
#endif
|
||||
extern __inline__ void gpio_disable_pin_periph_event(unsigned int pin)
|
||||
{
|
||||
AVR32_GPIO.port[pin >> 5].everc = 1 << (pin & 0x1F);
|
||||
}
|
||||
|
||||
/*! \brief Configure the peripheral event trigger mode of a pin
|
||||
*
|
||||
* \param pin The pin number.
|
||||
* \param mode The trigger mode (\ref GPIO_PIN_CHANGE, \ref GPIO_RISING_EDGE or
|
||||
* \ref GPIO_FALLING_EDGE).
|
||||
* \param use_igf use the Input Glitch Filter (TRUE) or not (FALSE).
|
||||
*
|
||||
* \return \ref GPIO_SUCCESS or \ref GPIO_INVALID_ARGUMENT.
|
||||
*/
|
||||
extern int gpio_configure_pin_periph_event_mode(unsigned int pin, unsigned int mode, unsigned int use_igf);
|
||||
|
||||
//! @}
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _GPIO_H_
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue