diff --git a/.gitignore b/.gitignore index 241c7708fd..850758cf1e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,11 @@ *.py[cod] +# Distribution dir +dist + +# MANIFEST file +MANIFEST + # Private settings private_settings.py @@ -53,4 +59,4 @@ uVision Project/ debug.log # Ignore OS X Desktop Services Store files -.DS_Store \ No newline at end of file +.DS_Store diff --git a/MANIFEST b/MANIFEST new file mode 100644 index 0000000000..3d917d208a --- /dev/null +++ b/MANIFEST @@ -0,0 +1,96 @@ +# file GENERATED by distutils, do NOT edit +LICENSE +setup.py +workspace_tools/__init__.py +workspace_tools/__init__.pyc +workspace_tools/autotest.py +workspace_tools/build.py +workspace_tools/build_api.py +workspace_tools/build_release.py +workspace_tools/client.py +workspace_tools/export_test.py +workspace_tools/hooks.py +workspace_tools/libraries.py +workspace_tools/make.py +workspace_tools/options.py +workspace_tools/patch.py +workspace_tools/paths.py +workspace_tools/project.py +workspace_tools/server.py +workspace_tools/settings.py +workspace_tools/size.py +workspace_tools/syms.py +workspace_tools/synch.py +workspace_tools/targets.py +workspace_tools/tests.py +workspace_tools/utils.py +workspace_tools/data/__init__.py +workspace_tools/data/example_test_spec.json +workspace_tools/data/support.py +workspace_tools/data/rpc/RPCClasses.h +workspace_tools/data/rpc/class.cpp +workspace_tools/dev/__init__.py +workspace_tools/dev/dsp_fir.py +workspace_tools/dev/rpc_classes.py +workspace_tools/export/__init__.py +workspace_tools/export/codered.py +workspace_tools/export/codered_lpc1768_cproject.tmpl +workspace_tools/export/codered_lpc1768_project.tmpl +workspace_tools/export/codered_lpc4088_cproject.tmpl +workspace_tools/export/codered_lpc4088_project.tmpl +workspace_tools/export/codesourcery.py +workspace_tools/export/codesourcery_lpc1768.tmpl +workspace_tools/export/ds5_5.py +workspace_tools/export/ds5_5_lpc11u24.cproject.tmpl +workspace_tools/export/ds5_5_lpc11u24.launch.tmpl +workspace_tools/export/ds5_5_lpc11u24.project.tmpl +workspace_tools/export/ds5_5_lpc1768.cproject.tmpl +workspace_tools/export/ds5_5_lpc1768.launch.tmpl +workspace_tools/export/ds5_5_lpc1768.project.tmpl +workspace_tools/export/exporters.py +workspace_tools/export/gcc_arm_lpc1768.tmpl +workspace_tools/export/gccarm.py +workspace_tools/export/iar.ewp.tmpl +workspace_tools/export/iar.eww.tmpl +workspace_tools/export/iar.py +workspace_tools/export/uvision4.py +workspace_tools/export/uvision4_kl25z.uvopt.tmpl +workspace_tools/export/uvision4_kl25z.uvproj.tmpl +workspace_tools/export/uvision4_lpc1114.uvopt.tmpl +workspace_tools/export/uvision4_lpc1114.uvproj.tmpl +workspace_tools/export/uvision4_lpc11c24.uvopt.tmpl +workspace_tools/export/uvision4_lpc11c24.uvproj.tmpl +workspace_tools/export/uvision4_lpc11u24.uvopt.tmpl +workspace_tools/export/uvision4_lpc11u24.uvproj.tmpl +workspace_tools/export/uvision4_lpc1347.uvopt.tmpl +workspace_tools/export/uvision4_lpc1347.uvproj.tmpl +workspace_tools/export/uvision4_lpc1768.uvopt.tmpl +workspace_tools/export/uvision4_lpc1768.uvproj.tmpl +workspace_tools/export/uvision4_lpc4088.uvopt.tmpl +workspace_tools/export/uvision4_lpc4088.uvproj.tmpl +workspace_tools/export/uvision4_lpc812.uvopt.tmpl +workspace_tools/export/uvision4_lpc812.uvproj.tmpl +workspace_tools/host_tests/__init__.py +workspace_tools/host_tests/echo.py +workspace_tools/host_tests/host_test.py +workspace_tools/host_tests/mbedrpc.py +workspace_tools/host_tests/net_test.py +workspace_tools/host_tests/rpc.py +workspace_tools/host_tests/tcpecho_client.py +workspace_tools/host_tests/tcpecho_server.py +workspace_tools/host_tests/tcpecho_server_loop.py +workspace_tools/host_tests/udpecho_client.py +workspace_tools/host_tests/udpecho_server.py +workspace_tools/host_tests/example/BroadcastReceive.py +workspace_tools/host_tests/example/BroadcastSend.py +workspace_tools/host_tests/example/MulticastReceive.py +workspace_tools/host_tests/example/MulticastSend.py +workspace_tools/host_tests/example/TCPEchoClient.py +workspace_tools/host_tests/example/TCPEchoServer.py +workspace_tools/host_tests/example/UDPEchoClient.py +workspace_tools/host_tests/example/UDPEchoServer.py +workspace_tools/host_tests/example/__init__.py +workspace_tools/toolchains/__init__.py +workspace_tools/toolchains/arm.py +workspace_tools/toolchains/gcc.py +workspace_tools/toolchains/iar.py diff --git a/MANIFEST.in b/MANIFEST.in new file mode 100644 index 0000000000..8294764a5c --- /dev/null +++ b/MANIFEST.in @@ -0,0 +1,2 @@ +graft workspace_tools +include __init__.py LICENSE diff --git a/libraries/USBHost/USBHost/USBHost.cpp b/libraries/USBHost/USBHost/USBHost.cpp index 3a4fef5ad4..1d2dca5203 100644 --- a/libraries/USBHost/USBHost/USBHost.cpp +++ b/libraries/USBHost/USBHost/USBHost.cpp @@ -28,8 +28,6 @@ USBHost * USBHost::instHost = NULL; #define MIN(a, b) ((a > b) ? b : a) -DigitalOut l4(LED4); - /** * How interrupts are processed: * - new device connected: @@ -72,7 +70,6 @@ void USBHost::usb_process() { if (evt.status == osEventMail) { - l4 = !l4; message_t * usb_msg = (message_t*)evt.value.p; switch (usb_msg->event_id) { diff --git a/libraries/USBHost/USBHost/USBHostConf.h b/libraries/USBHost/USBHost/USBHostConf.h index 1f90d0186f..b0d9ff76b8 100644 --- a/libraries/USBHost/USBHost/USBHostConf.h +++ b/libraries/USBHost/USBHost/USBHostConf.h @@ -53,10 +53,15 @@ */ #define USBHOST_SERIAL 1 +/* +* Enable USB3Gmodule +*/ +#define USBHOST_3GMODULE 1 + /* * Maximum number of interfaces of a usb device */ -#define MAX_INTF 3 +#define MAX_INTF 4 /* * Maximum number of endpoints on each interface diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerial.h b/libraries/USBHost/USBHost3GModule/IUSBHostSerial.h similarity index 94% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerial.h rename to libraries/USBHost/USBHost3GModule/IUSBHostSerial.h index d52df46ec2..5814fdd883 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerial.h +++ b/libraries/USBHost/USBHost3GModule/IUSBHostSerial.h @@ -24,8 +24,16 @@ * Generic interface to abstract 3G dongles' impl */ +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + #include "IUSBHostSerialListener.h" +// This is needed by some versions of GCC +#undef putc +#undef getc + class IUSBHostSerial { public: @@ -82,4 +90,6 @@ public: }; +#endif /* USBHOST_3GMODULE */ + #endif /* IUSBHOSTSERIAL_H_ */ diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerialListener.h b/libraries/USBHost/USBHost3GModule/IUSBHostSerialListener.h similarity index 94% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerialListener.h rename to libraries/USBHost/USBHost3GModule/IUSBHostSerialListener.h index c3f11de84e..525b734637 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/IUSBHostSerialListener.h +++ b/libraries/USBHost/USBHost3GModule/IUSBHostSerialListener.h @@ -21,6 +21,10 @@ #ifndef IUSBHOSTSERIALLISTENER_H_ #define IUSBHOSTSERIALLISTENER_H_ +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + class IUSBHostSerialListener { public: @@ -28,5 +32,6 @@ public: virtual void writeable() = 0; //Called when new space is available }; +#endif /* USBHOST_3GMODULE */ #endif /* IUSBHOSTSERIALLISTENER_H_ */ diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.cpp b/libraries/USBHost/USBHost3GModule/WANDongle.cpp similarity index 66% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.cpp rename to libraries/USBHost/USBHost3GModule/WANDongle.cpp index bd28eb0855..e0d3cfdffe 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.cpp +++ b/libraries/USBHost/USBHost3GModule/WANDongle.cpp @@ -16,19 +16,23 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + #define __DEBUG__ 0 #ifndef __MODULE__ #define __MODULE__ "WANDongle.cpp" #endif -#include "core/dbg.h" -#include +#include "dbg.h" +#include #include "rtos.h" #include "WANDongle.h" #include "WANDongleInitializer.h" -WANDongle::WANDongle() : m_pInitializer(NULL), m_serialCount(0) +WANDongle::WANDongle() : m_pInitializer(NULL), m_serialCount(0), m_totalInitializers(0) { host = USBHost::getHostInst(); init(); @@ -43,7 +47,7 @@ bool WANDongle::tryConnect() { //FIXME should run on USB thread - DBG("Trying to connect device"); + USB_DBG("Trying to connect device"); if (dev_connected) { return true; @@ -51,40 +55,29 @@ bool WANDongle::tryConnect() m_pInitializer = NULL; - host->lock(); - - for (int i = 0; i < MAX_DEVICE_NB; i++) + for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) { if ((dev = host->getDevice(i)) != NULL) { m_pInitializer = NULL; //Will be set in setVidPid callback - DBG("Found one device reset it"); - int ret = host->resetDevice(dev); + USB_DBG("Enumerate"); + int ret = host->enumerate(dev, this); if(ret) { - host->unlock(); - return false; - } - - DBG("Enumerate"); - ret = host->enumerate(dev, this); - if(ret) - { - host->unlock(); return false; } - DBG("Device has VID:%04x PID:%04x", dev->getVid(), dev->getPid()); + USB_DBG("Device has VID:%04x PID:%04x", dev->getVid(), dev->getPid()); if(m_pInitializer) //If an initializer has been found { - DBG("m_pInitializer=%p", m_pInitializer); - DBG("m_pInitializer->getSerialVid()=%04x", m_pInitializer->getSerialVid()); - DBG("m_pInitializer->getSerialPid()=%04x", m_pInitializer->getSerialPid()); + USB_DBG("m_pInitializer=%p", m_pInitializer); + USB_DBG("m_pInitializer->getSerialVid()=%04x", m_pInitializer->getSerialVid()); + USB_DBG("m_pInitializer->getSerialPid()=%04x", m_pInitializer->getSerialPid()); if ((dev->getVid() == m_pInitializer->getSerialVid()) && (dev->getPid() == m_pInitializer->getSerialPid())) { - DBG("The dongle is in virtual serial mode"); + USB_DBG("The dongle is in virtual serial mode"); host->registerDriver(dev, 0, this, &WANDongle::init); m_serialCount = m_pInitializer->getSerialPortCount(); if( m_serialCount > WANDONGLE_MAX_SERIAL_PORTS ) @@ -93,41 +86,37 @@ bool WANDongle::tryConnect() } for(int j = 0; j < m_serialCount; j++) { - DBG("Connecting serial port #%d", j+1); - DBG("Ep %p", m_pInitializer->getEp(dev, j, false)); - DBG("Ep %p", m_pInitializer->getEp(dev, j, true)); + USB_DBG("Connecting serial port #%d", j+1); + USB_DBG("Ep %p", m_pInitializer->getEp(dev, j, false)); + USB_DBG("Ep %p", m_pInitializer->getEp(dev, j, true)); m_serial[j].connect( dev, m_pInitializer->getEp(dev, j, false), m_pInitializer->getEp(dev, j, true) ); } - DBG("Device connected"); + USB_DBG("Device connected"); dev_connected = true; - host->unlock(); return true; } else if ((dev->getVid() == m_pInitializer->getMSDVid()) && (dev->getPid() == m_pInitializer->getMSDPid())) { - DBG("Vodafone K3370 dongle detected in MSD mode"); + USB_DBG("Vodafone K3370 dongle detected in MSD mode"); //Try to switch if( m_pInitializer->switchMode(dev) ) { - DBG("Switched OK"); - host->unlock(); + USB_DBG("Switched OK"); return false; //Will be connected on a next iteration } else { - ERR("Could not switch mode"); - host->unlock(); + USB_ERR("Could not switch mode"); return false; } } } //if() } //if() } //for() - host->unlock(); return false; } @@ -141,7 +130,7 @@ bool WANDongle::disconnect() return true; } -WAN_DONGLE_TYPE WANDongle::getDongleType() +int WANDongle::getDongleType() { if( m_pInitializer != NULL ) { @@ -177,28 +166,28 @@ void WANDongle::init() /*virtual*/ void WANDongle::setVidPid(uint16_t vid, uint16_t pid) { - //Load right initializer - WANDongleInitializer** initializer = WANDongleInitializer::getInitializers(host); - - while(*initializer) + WANDongleInitializer* initializer; + + for(int i = 0; i < m_totalInitializers; i++) { - DBG("*initializer=%p", *initializer); - DBG("(*initializer)->getSerialVid()=%04x", (*initializer)->getSerialVid()); - DBG("(*initializer)->getSerialPid()=%04x", (*initializer)->getSerialPid()); - if ((dev->getVid() == (*initializer)->getSerialVid()) && (dev->getPid() == (*initializer)->getSerialPid())) + initializer = m_Initializers[i]; + USB_DBG("initializer=%p", initializer); + USB_DBG("initializer->getSerialVid()=%04x", initializer->getSerialVid()); + USB_DBG("initializer->getSerialPid()=%04x", initializer->getSerialPid()); + if ((dev->getVid() == initializer->getSerialVid()) && (dev->getPid() == initializer->getSerialPid())) { - DBG("The dongle is in virtual serial mode"); - m_pInitializer = *initializer; + USB_DBG("The dongle is in virtual serial mode"); + m_pInitializer = initializer; break; } - else if ((dev->getVid() == (*initializer)->getMSDVid()) && (dev->getPid() == (*initializer)->getMSDPid())) + else if ((dev->getVid() == initializer->getMSDVid()) && (dev->getPid() == initializer->getMSDPid())) { - DBG("Vodafone K3370 dongle detected in MSD mode"); - m_pInitializer = *initializer; + USB_DBG("Dongle detected in MSD mode"); + m_pInitializer = initializer; break; } initializer++; - } //while() + } //for if(m_pInitializer) { m_pInitializer->setVidPid(vid, pid); @@ -228,3 +217,20 @@ void WANDongle::init() return false; } } + + +bool WANDongle::addInitializer(WANDongleInitializer* pInitializer) +{ + if (m_totalInitializers >= WANDONGLE_MAX_INITIALIZERS) + return false; + m_Initializers[m_totalInitializers++] = pInitializer; + return true; +} + +WANDongle::~WANDongle() +{ + for(int i = 0; i < m_totalInitializers; i++) + delete m_Initializers[i]; +} + +#endif /* USBHOST_3GMODULE */ diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.h b/libraries/USBHost/USBHost3GModule/WANDongle.h similarity index 89% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.h rename to libraries/USBHost/USBHost3GModule/WANDongle.h index 24b9808863..ab12bdc6e4 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongle.h +++ b/libraries/USBHost/USBHost3GModule/WANDongle.h @@ -19,6 +19,10 @@ #ifndef WANDONGLE_H #define WANDONGLE_H +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + #include "USBHost.h" #include "IUSBHostSerial.h" @@ -31,8 +35,6 @@ #define WANDONGLE_MAX_OUTEP_SIZE 64 #define WANDONGLE_MAX_INEP_SIZE 64 -#define WANDONGLE_MAX_SERIAL_PORTS 2 - /** A class to use a WAN (3G/LTE) access dongle * */ @@ -45,6 +47,11 @@ public: */ WANDongle(); + /* + * Destructor + */ + virtual ~WANDongle(); + /* * Check if a serial port device is connected * @@ -66,11 +73,12 @@ public: */ bool disconnect(); - WAN_DONGLE_TYPE getDongleType(); + int getDongleType(); IUSBHostSerial& getSerial(int index); int getSerialCount(); - + bool addInitializer(WANDongleInitializer* pInitializer); + //From IUSBEnumerator virtual void setVidPid(uint16_t vid, uint16_t pid); @@ -90,6 +98,11 @@ protected: WANDongleSerialPort m_serial[WANDONGLE_MAX_SERIAL_PORTS]; int m_serialCount; + + int m_totalInitializers; + WANDongleInitializer* m_Initializers[WANDONGLE_MAX_INITIALIZERS]; }; +#endif /* USBHOST_3GMODULE */ + #endif diff --git a/libraries/USBHost/USBHost3GModule/WANDongleInitializer.h b/libraries/USBHost/USBHost3GModule/WANDongleInitializer.h new file mode 100644 index 0000000000..a78d69bdbd --- /dev/null +++ b/libraries/USBHost/USBHost3GModule/WANDongleInitializer.h @@ -0,0 +1,73 @@ +/* Copyright (c) 2010-2012 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef WANDONGLEINITIALIZER_H +#define WANDONGLEINITIALIZER_H + +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + +#include + +#include "USBHost.h" +#include "IUSBEnumerator.h" + +// [TODO] move these declarations to a proper place +#define WANDONGLE_MAX_SERIAL_PORTS 2 +#define WANDONGLE_MAX_INITIALIZERS 6 + +#define WAN_DONGLE_TYPE_UNKNOWN (-1) + +class WANDongleInitializer : public IUSBEnumerator +{ +protected: + WANDongleInitializer(USBHost* pHost) { m_pHost = pHost; } + USBHost* m_pHost; + uint8_t m_serialIntfMap[WANDONGLE_MAX_SERIAL_PORTS]; + +public: + virtual ~WANDongleInitializer() {} + virtual uint16_t getMSDVid() = 0; + virtual uint16_t getMSDPid() = 0; + + virtual uint16_t getSerialVid() = 0; + virtual uint16_t getSerialPid() = 0; + + virtual bool switchMode(USBDeviceConnected* pDev) = 0; + + virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) { + return pDev->getEndpoint(m_serialIntfMap[serialPortNumber], BULK_ENDPOINT, tx ? OUT : IN, 0); + } + + virtual int getSerialPortCount() = 0; + + virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; + + virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed + + virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used + + virtual int getType() = 0; + + virtual uint8_t getSerialIntf(int index) { return m_serialIntfMap[index]; } +}; + +#endif /* USBHOST_3GMODULE */ + +#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.cpp b/libraries/USBHost/USBHost3GModule/WANDongleSerialPort.cpp similarity index 92% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.cpp rename to libraries/USBHost/USBHost3GModule/WANDongleSerialPort.cpp index b2ec1cc63c..4cb43379e4 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.cpp +++ b/libraries/USBHost/USBHost3GModule/WANDongleSerialPort.cpp @@ -16,13 +16,17 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + #define __DEBUG__ 0 #ifndef __MODULE__ #define __MODULE__ "WANDongleSerialPort.cpp" #endif -#include "core/dbg.h" -#include +#include "dbg.h" +#include #include "rtos.h" #include "WANDongleSerialPort.h" @@ -61,37 +65,34 @@ void WANDongleSerialPort::reset() int WANDongleSerialPort::readPacket() { - DBG("Read packet on %p", this); + USB_DBG("Read packet on %p", this); rx_mtx.lock(); if(lock_rx) { - ERR("Fail"); + USB_ERR("Fail"); rx_mtx.unlock(); return -1; } if( bulk_in == NULL ) { - WARN("Port is disconnected"); + USB_WARN("Port is disconnected"); rx_mtx.unlock(); return -1; } lock_rx = true; //Receiving rx_mtx.unlock(); -// DBG("readPacket"); +// USB_DBG("readPacket"); //lock_rx.lock(); - host->lock(); USB_TYPE res = host->bulkRead(dev, (USBEndpoint *)bulk_in, buf_in, ((USBEndpoint *)bulk_in)->getSize(), false); //Queue transfer if(res != USB_TYPE_PROCESSING) { - host->unlock(); //lock_rx.unlock(); - ERR("host->bulkRead() returned %d", res); + USB_ERR("host->bulkRead() returned %d", res); Thread::wait(100); return -1; } - host->unlock(); return 0; } @@ -100,34 +101,31 @@ int WANDongleSerialPort::writePacket() tx_mtx.lock(); if(lock_tx) { - ERR("Fail"); + USB_ERR("Fail"); tx_mtx.unlock(); return -1; } if( bulk_out == NULL ) { - WARN("Port is disconnected"); + USB_WARN("Port is disconnected"); tx_mtx.unlock(); return -1; } lock_tx = true; //Transmitting tx_mtx.unlock(); -// DBG("writePacket"); +// USB_DBG("writePacket"); //lock_tx.lock(); - host->lock(); USB_TYPE res = host->bulkWrite(dev, (USBEndpoint *)bulk_out, buf_out, buf_out_len, false); //Queue transfer if(res != USB_TYPE_PROCESSING) { - host->unlock(); //lock_tx.unlock(); - ERR("host->bulkWrite() returned %d", res); + USB_ERR("host->bulkWrite() returned %d", res); Thread::wait(100); return -1; } - host->unlock(); return 0; } @@ -144,7 +142,7 @@ int WANDongleSerialPort::putc(int c) } else { - ERR("CAN'T WRITE!"); + USB_ERR("CAN'T WRITE!"); } tx_mtx.unlock(); return c; @@ -164,7 +162,7 @@ int WANDongleSerialPort::getc() } else { - ERR("CAN'T READ!"); + USB_ERR("CAN'T READ!"); } rx_mtx.unlock(); return c; @@ -307,7 +305,7 @@ void WANDongleSerialPort::rxHandler() else //Error, try reading again { //lock_rx.unlock(); - DBG("Trying again"); + USB_DBG("Trying again"); readPacket(); } } @@ -338,3 +336,5 @@ void WANDongleSerialPort::txHandler() writePacket(); } } + +#endif /* USBHOST_3GMODULE */ diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.h b/libraries/USBHost/USBHost3GModule/WANDongleSerialPort.h similarity index 97% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.h rename to libraries/USBHost/USBHost3GModule/WANDongleSerialPort.h index 7dee8cc003..9da1717078 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleSerialPort.h +++ b/libraries/USBHost/USBHost3GModule/WANDongleSerialPort.h @@ -19,6 +19,10 @@ #ifndef WANDONGLESERIALPORT_H #define WANDONGLESERIALPORT_H +#include "USBHostConf.h" + +#ifdef USBHOST_3GMODULE + #include "USBHost.h" #include "IUSBHostSerial.h" @@ -123,4 +127,7 @@ protected: }; +#endif /* USBHOST_3GMODULE */ + #endif + diff --git a/libraries/mbed/api/CAN.h b/libraries/mbed/api/CAN.h index 25b7620c02..f494e77523 100644 --- a/libraries/mbed/api/CAN.h +++ b/libraries/mbed/api/CAN.h @@ -131,12 +131,13 @@ public: /** Read a CANMessage from the bus. * * @param msg A CANMessage to read to. + * @param handle message filter handle (0 for any message) * * @returns * 0 if no message arrived, * 1 if message arrived */ - int read(CANMessage &msg); + int read(CANMessage &msg, int handle = 0); /** Reset CAN interface. * @@ -169,6 +170,19 @@ public: */ int mode(Mode mode); + /** Filter out incomming messages + * + * @param id the id to filter on + * @param mask the mask applied to the id + * @param format format to filter on (Default CANAny) + * @param handle message filter handle (Optional) + * + * @returns + * 0 if filter change failed or unsupported, + * new filter handle if successful + */ + int filter(unsigned int id, unsigned int mask, CANFormat format = CANAny, int handle = 0); + /** Returns number of read errors to detect read overflow errors. */ unsigned char rderror(); diff --git a/libraries/mbed/api/InterruptIn.h b/libraries/mbed/api/InterruptIn.h index c460585fb1..45eb2ffc54 100644 --- a/libraries/mbed/api/InterruptIn.h +++ b/libraries/mbed/api/InterruptIn.h @@ -22,9 +22,7 @@ #include "gpio_api.h" #include "gpio_irq_api.h" - #include "FunctionPointer.h" -#include "CallChain.h" namespace mbed { @@ -73,197 +71,59 @@ public: /** Attach a function to call when a rising edge occurs on the input * * @param fptr A pointer to a void function, or 0 to set as none - * - * @returns - * The function object created for 'fptr' */ - pFunctionPointer_t rise(void (*fptr)(void)); - - /** Add a function to be called when a rising edge occurs at the end of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t rise_add(void (*fptr)(void)) { - return rise_add_common(fptr); - } - - /** Add a function to be called when a rising edge occurs at the beginning of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t rise_add_front(void (*fptr)(void)) { - return rise_add_common(fptr, true); - } + void rise(void (*fptr)(void)); /** Attach a member function to call when a rising edge occurs on the input * * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' */ template - pFunctionPointer_t rise(T* tptr, void (T::*mptr)(void)) { - _rise.clear(); - pFunctionPointer_t pf = _rise.add(tptr, mptr); + void rise(T* tptr, void (T::*mptr)(void)) { + _rise.attach(tptr, mptr); gpio_irq_set(&gpio_irq, IRQ_RISE, 1); - return pf; } - /** Add a function to be called when a rising edge occurs at the end of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t rise_add(T* tptr, void (T::*mptr)(void)) { - return rise_add_common(tptr, mptr); - } - - /** Add a function to be called when a rising edge occurs at the beginning of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t rise_add_front(T* tptr, void (T::*mptr)(void)) { - return rise_add_common(tptr, mptr, true); - } - - /** Remove a function from the list of functions to be called when a rising edge occurs - * - * @param pf the function object to remove - * - * @returns - * true if the function was found and removed, false otherwise - */ - bool rise_remove(pFunctionPointer_t pf); - /** Attach a function to call when a falling edge occurs on the input * * @param fptr A pointer to a void function, or 0 to set as none - * - * @returns - * The function object created for 'fptr' */ - pFunctionPointer_t fall(void (*fptr)(void)); - - /** Add a function to be called when a falling edge occurs at the end of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t fall_add(void (*fptr)(void)) { - return fall_add_common(fptr); - } - - /** Add a function to be called when a falling edge occurs at the beginning of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t fall_add_front(void (*fptr)(void)) { - return fall_add_common(fptr, true); - } + void fall(void (*fptr)(void)); /** Attach a member function to call when a falling edge occurs on the input * * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' */ template - pFunctionPointer_t fall(T* tptr, void (T::*mptr)(void)) { - _fall.clear(); - pFunctionPointer_t pf = _fall.add(tptr, mptr); + void fall(T* tptr, void (T::*mptr)(void)) { + _fall.attach(tptr, mptr); gpio_irq_set(&gpio_irq, IRQ_FALL, 1); - return pf; } - /** Add a function to be called when a falling edge occurs at the end of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t fall_add(T* tptr, void (T::*mptr)(void)) { - return fall_add_common(tptr, mptr); - } - - /** Add a function to be called when a falling edge occurs at the beginning of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t fall_add_front(T* tptr, void (T::*mptr)(void)) { - return fall_add_common(tptr, mptr, true); - } - - /** Remove a function from the list of functions to be called when a falling edge occurs - * - * @param pf the function object to remove - * - * @returns - * true if the function was found and removed, false otherwise - */ - bool fall_remove(pFunctionPointer_t pf); - /** Set the input pin mode * * @param mode PullUp, PullDown, PullNone */ void mode(PinMode pull); + /** Enable IRQ + */ + void enable_irq(); + + /** Disable IRQ + */ + void disable_irq(); + static void _irq_handler(uint32_t id, gpio_irq_event event); protected: - pFunctionPointer_t rise_add_common(void (*fptr)(void), bool front=false); - pFunctionPointer_t fall_add_common(void (*fptr)(void), bool front=false); - - template - pFunctionPointer_t rise_add_common(T* tptr, void (T::*mptr)(void), bool front=false) { - pFunctionPointer_t pf = front ? _rise.add_front(tptr, mptr) : _rise.add(tptr, mptr); - gpio_irq_set(&gpio_irq, IRQ_RISE, 1); - return pf; - } - template - pFunctionPointer_t fall_add_common(T* tptr, void (T::*mptr)(void), bool front=false) { - pFunctionPointer_t pf = front ? _fall.add_front(tptr, mptr) : _fall.add(tptr, mptr); - gpio_irq_set(&gpio_irq, IRQ_FALL, 1); - return pf; - } - gpio_t gpio; gpio_irq_t gpio_irq; - CallChain _rise; - CallChain _fall; + FunctionPointer _rise; + FunctionPointer _fall; }; } // namespace mbed diff --git a/libraries/mbed/api/RawSerial.h b/libraries/mbed/api/RawSerial.h new file mode 100644 index 0000000000..83c3ecc129 --- /dev/null +++ b/libraries/mbed/api/RawSerial.h @@ -0,0 +1,80 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_RAW_SERIAL_H +#define MBED_RAW_SERIAL_H + +#include "platform.h" + +#if DEVICE_SERIAL + +#include "SerialBase.h" +#include "serial_api.h" + +namespace mbed { + +/** A serial port (UART) for communication with other serial devices + * This is a variation of the Serial class that doesn't use streams, + * thus making it safe to use in interrupt handlers with the RTOS. + * + * Can be used for Full Duplex communication, or Simplex by specifying + * one pin as NC (Not Connected) + * + * Example: + * @code + * // Send a char to the PC + * + * #include "mbed.h" + * + * RawSerial pc(USBTX, USBRX); + * + * int main() { + * pc.putc('A'); + * } + * @endcode + */ +class RawSerial: public SerialBase { + +public: + /** Create a RawSerial port, connected to the specified transmit and receive pins + * + * @param tx Transmit pin + * @param rx Receive pin + * + * @note + * Either tx or rx may be specified as NC if unused + */ + RawSerial(PinName tx, PinName rx); + + /** Write a char to the serial port + * + * @param c The char to write + * + * @returns The written char or -1 if an error occured + */ + int putc(int c); + + /** Read a char from the serial port + * + * @returns The char read from the serial port + */ + int getc(); +}; + +} // namespace mbed + +#endif + +#endif diff --git a/libraries/mbed/api/Serial.h b/libraries/mbed/api/Serial.h index 92785b476f..d9fb6954f7 100644 --- a/libraries/mbed/api/Serial.h +++ b/libraries/mbed/api/Serial.h @@ -21,9 +21,8 @@ #if DEVICE_SERIAL #include "Stream.h" -#include "FunctionPointer.h" +#include "SerialBase.h" #include "serial_api.h" -#include "CallChain.h" namespace mbed { @@ -45,7 +44,7 @@ namespace mbed { * } * @endcode */ -class Serial : public Stream { +class Serial : public SerialBase, public Stream { public: /** Create a Serial port, connected to the specified transmit and receive pins @@ -58,167 +57,9 @@ public: */ Serial(PinName tx, PinName rx, const char *name=NULL); - /** Set the baud rate of the serial port - * - * @param baudrate The baudrate of the serial port (default = 9600). - */ - void baud(int baudrate); - - enum Parity { - None = 0, - Odd, - Even, - Forced1, - Forced0 - }; - - enum IrqType { - RxIrq = 0, - TxIrq - }; - - /** Set the transmission format used by the Serial port - * - * @param bits The number of bits in a word (5-8; default = 8) - * @param parity The parity used (Serial::None, Serial::Odd, Serial::Even, Serial::Forced1, Serial::Forced0; default = Serial::None) - * @param stop The number of stop bits (1 or 2; default = 1) - */ - void format(int bits=8, Parity parity=Serial::None, int stop_bits=1); - - /** Determine if there is a character available to read - * - * @returns - * 1 if there is a character available to read, - * 0 otherwise - */ - int readable(); - - /** Determine if there is space available to write a character - * - * @returns - * 1 if there is space to write a character, - * 0 otherwise - */ - int writeable(); - - /** Attach a function to call whenever a serial interrupt is generated - * - * @param fptr A pointer to a void function, or 0 to set as none - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t attach(void (*fptr)(void), IrqType type=RxIrq); - - /** Add a function to be called when a serial interrupt is generated at the end of the call chain - * - * @param fptr the function to add - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_handler(void (*fptr)(void), IrqType type=RxIrq) { - return add_handler_helper(fptr, type); - } - - /** Add a function to be called when a serial interrupt is generated at the beginning of the call chain - * - * @param fptr the function to add - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_handler_front(void (*fptr)(void), IrqType type=RxIrq) { - return add_handler_helper(fptr, type, true); - } - - /** Attach a member function to call whenever a serial interrupt is generated - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @param - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - if((mptr != NULL) && (tptr != NULL)) { - _irq[type].clear(); - pFunctionPointer_t pf = _irq[type].add(tptr, mptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - return pf; - } - else - return NULL; - } - - /** Add a function to be called when a serial interrupt is generated at the end of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - template - pFunctionPointer_t add_handler(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - return add_handler_helper(tptr, mptr, type); - } - - /** Add a function to be called when a serial interrupt is generated at the beginning of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * The function object created for 'fptr' - */ - template - pFunctionPointer_t add_handler_front(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { - return add_handler_helper(tptr, mptr, type, true); - } - - /** Remove a function from the list of functions to be called when a serial interrupt is generated - * - * @param pf the function object to remove - * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) - * - * @returns - * true if the function was found and removed, false otherwise - */ - bool remove_handler(pFunctionPointer_t pf, IrqType type=RxIrq); - - /** Generate a break condition on the serial line - */ - void send_break(); - - static void _irq_handler(uint32_t id, SerialIrq irq_type); - protected: virtual int _getc(); - virtual int _putc(int c); - pFunctionPointer_t add_handler_helper(void (*function)(void), IrqType type, bool front=false); - - template - pFunctionPointer_t add_handler_helper(T* tptr, void (T::*mptr)(void), IrqType type, bool front=false) { - if ((mptr != NULL) && (tptr != NULL)) { - pFunctionPointer_t pf = front ? _irq[type].add_front(tptr, mptr) : _irq[type].add(tptr, mptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - return pf; - } - else - return NULL; - } - - serial_t _serial; - CallChain _irq[2]; - int _baud; + virtual int _putc(int c); }; } // namespace mbed diff --git a/libraries/mbed/api/SerialBase.h b/libraries/mbed/api/SerialBase.h new file mode 100644 index 0000000000..77c0d006be --- /dev/null +++ b/libraries/mbed/api/SerialBase.h @@ -0,0 +1,120 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#ifndef MBED_SERIALBASE_H +#define MBED_SERIALBASE_H + +#include "platform.h" + +#if DEVICE_SERIAL + +#include "Stream.h" +#include "FunctionPointer.h" +#include "serial_api.h" + +namespace mbed { + +/** A base class for serial port implementations + * Can't be instantiated directly (use Serial or RawSerial) + */ +class SerialBase { + +public: + /** Set the baud rate of the serial port + * + * @param baudrate The baudrate of the serial port (default = 9600). + */ + void baud(int baudrate); + + enum Parity { + None = 0, + Odd, + Even, + Forced1, + Forced0 + }; + + enum IrqType { + RxIrq = 0, + TxIrq + }; + + /** Set the transmission format used by the serial port + * + * @param bits The number of bits in a word (5-8; default = 8) + * @param parity The parity used (SerialBase::None, SerialBase::Odd, SerialBase::Even, SerialBase::Forced1, SerialBase::Forced0; default = SerialBase::None) + * @param stop The number of stop bits (1 or 2; default = 1) + */ + void format(int bits=8, Parity parity=SerialBase::None, int stop_bits=1); + + /** Determine if there is a character available to read + * + * @returns + * 1 if there is a character available to read, + * 0 otherwise + */ + int readable(); + + /** Determine if there is space available to write a character + * + * @returns + * 1 if there is space to write a character, + * 0 otherwise + */ + int writeable(); + + /** Attach a function to call whenever a serial interrupt is generated + * + * @param fptr A pointer to a void function, or 0 to set as none + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + void attach(void (*fptr)(void), IrqType type=RxIrq); + + /** Attach a member function to call whenever a serial interrupt is generated + * + * @param tptr pointer to the object to call the member function on + * @param mptr pointer to the member function to be called + * @param type Which serial interrupt to attach the member function to (Seriall::RxIrq for receive, TxIrq for transmit buffer empty) + */ + template + void attach(T* tptr, void (T::*mptr)(void), IrqType type=RxIrq) { + if((mptr != NULL) && (tptr != NULL)) { + _irq[type].attach(tptr, mptr); + serial_irq_set(&_serial, (SerialIrq)type, 1); + } + } + + /** Generate a break condition on the serial line + */ + void send_break(); + + static void _irq_handler(uint32_t id, SerialIrq irq_type); + +protected: + SerialBase(PinName tx, PinName rx); + + int _base_getc(); + int _base_putc(int c); + + serial_t _serial; + FunctionPointer _irq[2]; + int _baud; +}; + +} // namespace mbed + +#endif + +#endif diff --git a/libraries/mbed/api/Ticker.h b/libraries/mbed/api/Ticker.h index 835de930f6..73da8a5fbe 100644 --- a/libraries/mbed/api/Ticker.h +++ b/libraries/mbed/api/Ticker.h @@ -18,7 +18,6 @@ #include "TimerEvent.h" #include "FunctionPointer.h" -#include "CallChain.h" namespace mbed { @@ -63,34 +62,9 @@ public: * * @param fptr pointer to the function to be called * @param t the time between calls in seconds - * - * @returns - * The function object created for 'fptr' */ - pFunctionPointer_t attach(void (*fptr)(void), float t) { - return attach_us(fptr, t * 1000000.0f); - } - - /** Add a function to be called by the Ticker at the end of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_function(void (*fptr)(void)) { - return add_function_helper(fptr); - } - - /** Add a function to be called by the Ticker at the beginning of the call chain - * - * @param fptr the function to add - * - * @returns - * The function object created for 'fptr' - */ - pFunctionPointer_t add_function_front(void (*fptr)(void)) { - return add_function_helper(fptr, true); + void attach(void (*fptr)(void), float t) { + attach_us(fptr, t * 1000000.0f); } /** Attach a member function to be called by the Ticker, specifiying the interval in seconds @@ -98,54 +72,20 @@ public: * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called * @param t the time between calls in seconds - * - * @returns - * The function object created for 'tptr' and 'mptr' */ template - pFunctionPointer_t attach(T* tptr, void (T::*mptr)(void), float t) { - return attach_us(tptr, mptr, t * 1000000.0f); - } - - /** Add a function to be called by the Ticker at the end of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t add_function(T* tptr, void (T::*mptr)(void)) { - return add_function_helper(tptr, mptr); - } - - /** Add a function to be called by the Ticker at the beginning of the call chain - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - * - * @returns - * The function object created for 'tptr' and 'mptr' - */ - template - pFunctionPointer_t add_function_front(T* tptr, void (T::*mptr)(void)) { - return add_function_helper(tptr, mptr, true); + void attach(T* tptr, void (T::*mptr)(void), float t) { + attach_us(tptr, mptr, t * 1000000.0f); } /** Attach a function to be called by the Ticker, specifiying the interval in micro-seconds * * @param fptr pointer to the function to be called * @param t the time between calls in micro-seconds - * - * @returns - * The function object created for 'fptr' */ - pFunctionPointer_t attach_us(void (*fptr)(void), unsigned int t) { - _chain.clear(); - pFunctionPointer_t pf = _chain.add(fptr); + void attach_us(void (*fptr)(void), unsigned int t) { + _function.attach(fptr); setup(t); - return pf; } /** Attach a member function to be called by the Ticker, specifiying the interval in micro-seconds @@ -153,50 +93,23 @@ public: * @param tptr pointer to the object to call the member function on * @param mptr pointer to the member function to be called * @param t the time between calls in micro-seconds - * - * @returns - * The function object created for 'tptr' and 'mptr' */ template - pFunctionPointer_t attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { - _chain.clear(); - pFunctionPointer_t pf = _chain.add(tptr, mptr); + void attach_us(T* tptr, void (T::*mptr)(void), unsigned int t) { + _function.attach(tptr, mptr); setup(t); - return pf; } /** Detach the function */ void detach(); - /** Remove a function from the Ticker's call chain - * - * @param pf the function object to remove - * - * @returns - * true if the function was found and removed, false otherwise - */ - bool remove_function(pFunctionPointer_t pf) { - bool res = _chain.remove(pf); - if (res && _chain.size() == 0) - detach(); - return res; - } - protected: void setup(unsigned int t); - pFunctionPointer_t add_function_helper(void (*fptr)(void), bool front=false); virtual void handler(); - template - pFunctionPointer_t add_function_helper(T* tptr, void (T::*mptr)(void), bool front=false) { - if (_chain.size() == 0) - return NULL; - return front ? _chain.add_front(tptr, mptr) : _chain.add(tptr, mptr); - } - unsigned int _delay; - CallChain _chain; + FunctionPointer _function; }; } // namespace mbed diff --git a/libraries/mbed/api/can_helper.h b/libraries/mbed/api/can_helper.h index 45aa231dc5..e427250e07 100644 --- a/libraries/mbed/api/can_helper.h +++ b/libraries/mbed/api/can_helper.h @@ -24,7 +24,8 @@ extern "C" { enum CANFormat { CANStandard = 0, - CANExtended = 1 + CANExtended = 1, + CANAny = 2 }; typedef enum CANFormat CANFormat; diff --git a/libraries/mbed/api/mbed.h b/libraries/mbed/api/mbed.h index bba24a76db..2beef24150 100644 --- a/libraries/mbed/api/mbed.h +++ b/libraries/mbed/api/mbed.h @@ -48,6 +48,7 @@ #include "I2CSlave.h" #include "Ethernet.h" #include "CAN.h" +#include "RawSerial.h" // mbed Internal components #include "Timer.h" diff --git a/libraries/mbed/common/CAN.cpp b/libraries/mbed/common/CAN.cpp index 2b1fd4fdac..b33ca9f80f 100644 --- a/libraries/mbed/common/CAN.cpp +++ b/libraries/mbed/common/CAN.cpp @@ -39,8 +39,8 @@ int CAN::write(CANMessage msg) { return can_write(&_can, msg, 0); } -int CAN::read(CANMessage &msg) { - return can_read(&_can, &msg); +int CAN::read(CANMessage &msg, int handle) { + return can_read(&_can, &msg, handle); } void CAN::reset() { @@ -63,19 +63,23 @@ int CAN::mode(Mode mode) { return can_mode(&_can, (CanMode)mode); } - void CAN::attach(void (*fptr)(void), IrqType type) { - if (fptr) { - _irq[(CanIrqType)type].attach(fptr); - can_irq_set(&_can, (CanIrqType)type, 1); - } else { - can_irq_set(&_can, (CanIrqType)type, 0); - } - } +int CAN::filter(unsigned int id, unsigned int mask, CANFormat format, int handle) { + return can_filter(&_can, id, mask, format, handle); +} - void CAN::_irq_handler(uint32_t id, CanIrqType type) { - CAN *handler = (CAN*)id; - handler->_irq[type].call(); +void CAN::attach(void (*fptr)(void), IrqType type) { + if (fptr) { + _irq[(CanIrqType)type].attach(fptr); + can_irq_set(&_can, (CanIrqType)type, 1); + } else { + can_irq_set(&_can, (CanIrqType)type, 0); } +} + +void CAN::_irq_handler(uint32_t id, CanIrqType type) { + CAN *handler = (CAN*)id; + handler->_irq[type].call(); +} } // namespace mbed diff --git a/libraries/mbed/common/CallChain.cpp b/libraries/mbed/common/CallChain.cpp index 76526f1256..d91bdbe8a8 100644 --- a/libraries/mbed/common/CallChain.cpp +++ b/libraries/mbed/common/CallChain.cpp @@ -38,13 +38,11 @@ int CallChain::find(pFunctionPointer_t f) const { } void CallChain::clear() { - __disable_irq(); for(int i = 0; i < _elements; i ++) { delete _chain[i]; _chain[i] = NULL; } _elements = 0; - __enable_irq(); } bool CallChain::remove(pFunctionPointer_t f) { @@ -52,12 +50,10 @@ bool CallChain::remove(pFunctionPointer_t f) { if ((i = find(f)) == -1) return false; - __disable_irq(); if (i != _elements - 1) memmove(_chain + i, _chain + i + 1, (_elements - i - 1) * sizeof(pFunctionPointer_t)); delete f; _elements --; - __enable_irq(); return true; } @@ -69,13 +65,11 @@ void CallChain::call() { void CallChain::_check_size() { if (_elements < _size) return; - __disable_irq(); _size = (_size < 4) ? 4 : _size + 4; pFunctionPointer_t* new_chain = new pFunctionPointer_t[_size](); memcpy(new_chain, _chain, _elements * sizeof(pFunctionPointer_t)); delete _chain; _chain = new_chain; - __enable_irq(); } pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { @@ -87,11 +81,9 @@ pFunctionPointer_t CallChain::common_add(pFunctionPointer_t pf) { pFunctionPointer_t CallChain::common_add_front(pFunctionPointer_t pf) { _check_size(); - __disable_irq(); memmove(_chain + 1, _chain, _elements * sizeof(pFunctionPointer_t)); _chain[0] = pf; _elements ++; - __enable_irq(); return pf; } diff --git a/libraries/mbed/common/InterruptIn.cpp b/libraries/mbed/common/InterruptIn.cpp index bf91f3cb9b..f553a0a020 100644 --- a/libraries/mbed/common/InterruptIn.cpp +++ b/libraries/mbed/common/InterruptIn.cpp @@ -36,58 +36,22 @@ void InterruptIn::mode(PinMode pull) { gpio_mode(&gpio, pull); } -pFunctionPointer_t InterruptIn::rise(void (*fptr)(void)) { - pFunctionPointer_t pf = NULL; - _rise.clear(); +void InterruptIn::rise(void (*fptr)(void)) { if (fptr) { - pf = _rise.add(fptr); + _rise.attach(fptr); gpio_irq_set(&gpio_irq, IRQ_RISE, 1); } else { gpio_irq_set(&gpio_irq, IRQ_RISE, 0); } - return pf; } -pFunctionPointer_t InterruptIn::rise_add_common(void (*fptr)(void), bool front) { - if (NULL == fptr) - return NULL; - pFunctionPointer_t pf = front ? _rise.add_front(fptr) : _rise.add(fptr); - gpio_irq_set(&gpio_irq, IRQ_RISE, 1); - return pf; -} - -bool InterruptIn::rise_remove(pFunctionPointer_t pf) { - bool res = _rise.remove(pf); - if (res && _rise.size() == 0) - gpio_irq_set(&gpio_irq, IRQ_RISE, 0); - return res; -} - -pFunctionPointer_t InterruptIn::fall(void (*fptr)(void)) { - pFunctionPointer_t pf = NULL; - _fall.clear(); +void InterruptIn::fall(void (*fptr)(void)) { if (fptr) { - pf = _fall.add(fptr); + _fall.attach(fptr); gpio_irq_set(&gpio_irq, IRQ_FALL, 1); } else { gpio_irq_set(&gpio_irq, IRQ_FALL, 0); } - return pf; -} - -pFunctionPointer_t InterruptIn::fall_add_common(void (*fptr)(void), bool front) { - if (NULL == fptr) - return NULL; - pFunctionPointer_t pf = front ? _fall.add_front(fptr) : _fall.add(fptr); - gpio_irq_set(&gpio_irq, IRQ_FALL, 1); - return pf; -} - -bool InterruptIn::fall_remove(pFunctionPointer_t pf) { - bool res = _fall.remove(pf); - if (res && _fall.size() == 0) - gpio_irq_set(&gpio_irq, IRQ_FALL, 0); - return res; } void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { @@ -99,6 +63,14 @@ void InterruptIn::_irq_handler(uint32_t id, gpio_irq_event event) { } } +void InterruptIn::enable_irq() { + gpio_irq_enable(&gpio_irq); +} + +void InterruptIn::disable_irq() { + gpio_irq_disable(&gpio_irq); +} + #ifdef MBED_OPERATORS InterruptIn::operator int() { return read(); diff --git a/libraries/mbed/common/RawSerial.cpp b/libraries/mbed/common/RawSerial.cpp new file mode 100644 index 0000000000..09225d520d --- /dev/null +++ b/libraries/mbed/common/RawSerial.cpp @@ -0,0 +1,36 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "RawSerial.h" +#include "wait_api.h" + +#if DEVICE_SERIAL + +namespace mbed { + +RawSerial::RawSerial(PinName tx, PinName rx) : SerialBase(tx, rx) { +} + +int RawSerial::getc() { + return _base_getc(); +} + +int RawSerial::putc(int c) { + return _base_putc(c); +} + +} // namespace mbed + +#endif diff --git a/libraries/mbed/common/Serial.cpp b/libraries/mbed/common/Serial.cpp index 27f300eaee..602c87a0a7 100644 --- a/libraries/mbed/common/Serial.cpp +++ b/libraries/mbed/common/Serial.cpp @@ -20,83 +20,15 @@ namespace mbed { -Serial::Serial(PinName tx, PinName rx, const char *name) : Stream(name) { - serial_init(&_serial, tx, rx); - _baud = 9600; - serial_irq_handler(&_serial, Serial::_irq_handler, (uint32_t)this); -} - -void Serial::baud(int baudrate) { - serial_baud(&_serial, baudrate); - _baud = baudrate; -} - -void Serial::format(int bits, Parity parity, int stop_bits) { - serial_format(&_serial, bits, (SerialParity)parity, stop_bits); -} - -int Serial::readable() { - return serial_readable(&_serial); -} - - -int Serial::writeable() { - return serial_writable(&_serial); -} - -pFunctionPointer_t Serial::attach(void (*fptr)(void), IrqType type) { - pFunctionPointer_t pf = NULL; - _irq[type].clear(); - if (fptr) { - pf = _irq[type].add(fptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - } else { - serial_irq_set(&_serial, (SerialIrq)type, 0); - } - return pf; -} - -pFunctionPointer_t Serial::add_handler_helper(void (*fptr)(void), IrqType type, bool front) { - if (NULL == fptr) - return NULL; - pFunctionPointer_t pf = front ? _irq[type].add_front(fptr) : _irq[type].add(fptr); - serial_irq_set(&_serial, (SerialIrq)type, 1); - return pf; -} - -bool Serial::remove_handler(pFunctionPointer_t pf, IrqType type) { - bool res = _irq[type].remove(pf); - if (res && _irq[type].size() == 0) - serial_irq_set(&_serial, (SerialIrq)type, 0); - return res; -} - -void Serial::_irq_handler(uint32_t id, SerialIrq irq_type) { - Serial *handler = (Serial*)id; - handler->_irq[irq_type].call(); +Serial::Serial(PinName tx, PinName rx, const char *name) : SerialBase(tx, rx), Stream(name) { } int Serial::_getc() { - return serial_getc(&_serial); + return _base_getc(); } int Serial::_putc(int c) { - serial_putc(&_serial, c); - return c; -} - -void Serial::send_break() { - // Wait for 1.5 frames before clearing the break condition - // This will have different effects on our platforms, but should - // ensure that we keep the break active for at least one frame. - // We consider a full frame (1 start bit + 8 data bits bits + - // 1 parity bit + 2 stop bits = 12 bits) for computation. - // One bit time (in us) = 1000000/_baud - // Twelve bits: 12000000/baud delay - // 1.5 frames: 18000000/baud delay - serial_break_set(&_serial); - wait_us(18000000/_baud); - serial_break_clear(&_serial); + return _base_putc(c); } } // namespace mbed diff --git a/libraries/mbed/common/SerialBase.cpp b/libraries/mbed/common/SerialBase.cpp new file mode 100644 index 0000000000..9026080a4f --- /dev/null +++ b/libraries/mbed/common/SerialBase.cpp @@ -0,0 +1,86 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "SerialBase.h" +#include "wait_api.h" + +#if DEVICE_SERIAL + +namespace mbed { + +SerialBase::SerialBase(PinName tx, PinName rx) { + serial_init(&_serial, tx, rx); + _baud = 9600; + serial_irq_handler(&_serial, SerialBase::_irq_handler, (uint32_t)this); +} + +void SerialBase::baud(int baudrate) { + serial_baud(&_serial, baudrate); + _baud = baudrate; +} + +void SerialBase::format(int bits, Parity parity, int stop_bits) { + serial_format(&_serial, bits, (SerialParity)parity, stop_bits); +} + +int SerialBase::readable() { + return serial_readable(&_serial); +} + + +int SerialBase::writeable() { + return serial_writable(&_serial); +} + +void SerialBase::attach(void (*fptr)(void), IrqType type) { + if (fptr) { + _irq[type].attach(fptr); + serial_irq_set(&_serial, (SerialIrq)type, 1); + } else { + serial_irq_set(&_serial, (SerialIrq)type, 0); + } +} + +void SerialBase::_irq_handler(uint32_t id, SerialIrq irq_type) { + SerialBase *handler = (SerialBase*)id; + handler->_irq[irq_type].call(); +} + +int SerialBase::_base_getc() { + return serial_getc(&_serial); +} + +int SerialBase::_base_putc(int c) { + serial_putc(&_serial, c); + return c; +} + +void SerialBase::send_break() { + // Wait for 1.5 frames before clearing the break condition + // This will have different effects on our platforms, but should + // ensure that we keep the break active for at least one frame. + // We consider a full frame (1 start bit + 8 data bits bits + + // 1 parity bit + 2 stop bits = 12 bits) for computation. + // One bit time (in us) = 1000000/_baud + // Twelve bits: 12000000/baud delay + // 1.5 frames: 18000000/baud delay + serial_break_set(&_serial); + wait_us(18000000/_baud); + serial_break_clear(&_serial); +} + +} // namespace mbed + +#endif diff --git a/libraries/mbed/common/Ticker.cpp b/libraries/mbed/common/Ticker.cpp index c23b4dbb29..7ae73ef089 100644 --- a/libraries/mbed/common/Ticker.cpp +++ b/libraries/mbed/common/Ticker.cpp @@ -22,7 +22,7 @@ namespace mbed { void Ticker::detach() { remove(); - _chain.clear(); + _function.attach(0); } void Ticker::setup(unsigned int t) { @@ -33,13 +33,7 @@ void Ticker::setup(unsigned int t) { void Ticker::handler() { insert(event.timestamp + _delay); - _chain.call(); -} - -pFunctionPointer_t Ticker::add_function_helper(void (*fptr)(void), bool front) { - if (_chain.size() == 0) - return NULL; - return front ? _chain.add_front(fptr) : _chain.add(fptr); + _function.call(); } } // namespace mbed diff --git a/libraries/mbed/common/Timeout.cpp b/libraries/mbed/common/Timeout.cpp index b71d446db7..ed7950212b 100644 --- a/libraries/mbed/common/Timeout.cpp +++ b/libraries/mbed/common/Timeout.cpp @@ -18,7 +18,7 @@ namespace mbed { void Timeout::handler() { - _chain.call(); + _function.call(); } } // namespace mbed diff --git a/libraries/mbed/hal/can_api.h b/libraries/mbed/hal/can_api.h index 5f2179cded..48bc104695 100644 --- a/libraries/mbed/hal/can_api.h +++ b/libraries/mbed/hal/can_api.h @@ -63,8 +63,9 @@ void can_irq_free (can_t *obj); void can_irq_set (can_t *obj, CanIrqType irq, uint32_t enable); int can_write (can_t *obj, CAN_Message, int cc); -int can_read (can_t *obj, CAN_Message *msg); +int can_read (can_t *obj, CAN_Message *msg, int handle); int can_mode (can_t *obj, CanMode mode); +int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle); void can_reset (can_t *obj); unsigned char can_rderror (can_t *obj); unsigned char can_tderror (can_t *obj); diff --git a/libraries/mbed/hal/gpio_irq_api.h b/libraries/mbed/hal/gpio_irq_api.h index 2eadb4f584..76c7e927ec 100644 --- a/libraries/mbed/hal/gpio_irq_api.h +++ b/libraries/mbed/hal/gpio_irq_api.h @@ -37,6 +37,8 @@ typedef void (*gpio_irq_handler)(uint32_t id, gpio_irq_event event); int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id); void gpio_irq_free(gpio_irq_t *obj); void gpio_irq_set (gpio_irq_t *obj, gpio_irq_event event, uint32_t enable); +void gpio_irq_enable(gpio_irq_t *obj); +void gpio_irq_disable(gpio_irq_t *obj); #ifdef __cplusplus } diff --git a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/bitfields.h b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/bitfields.h new file mode 100644 index 0000000000..59ea738645 --- /dev/null +++ b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/bitfields.h @@ -0,0 +1,1768 @@ +#ifndef MBED_BITFIELDS_H +#define MBED_BITFIELDS_H + +//! Massage  x for use in bitfield  name. +#define BFN_PREP(x, name) ( ((x)<>name##_SHIFT ) + +//! Set bitfield  name from  y to  x: y.name= x. +#define BFN_SET(y, x, name) (y = ((y)&~name##_MASK) | BFN_PREP(x,name) ) + + +/* SYSMEMREMAP, address 0x4004 8000 */ +#define SYSMEMREMAP_MAP_MASK 0x0003 // System memory remap +#define SYSMEMREMAP_MAP_SHIFT 0 + +/* PRESETCTRL, address 0x4004 8004 */ +#define PRESETCTRL_SSP0_RST_N (1 << 0) // SPI0 reset control +#define PRESETCTRL_I2C_RST_N (1 << 1) // I2C reset control +#define PRESETCTRL_SSP1_RST_N (1 << 2) // SPI1 reset control +#define PRESETCTRL_CAN_RST_N (1 << 3) // C_CAN reset control. See Section 3.1 for part specific details. + +/* SYSPLLCTRL, address 0x4004 8008 */ +#define SYSPLLCTRL_MSEL_MASK 0x001F // Feedback divider value. The division value M is the programmed MSEL value + 1. 00000: Division ratio M = 1 to 11111: Division ratio M = 32. +#define SYSPLLCTRL_MSEL_SHIFT 0 +#define SYSPLLCTRL_PSEL_MASK 0x0060 // Post divider ratio P. The division ratio is 2 P. +#define SYSPLLCTRL_PSEL_SHIFT 5 + +/* SYSPLLSTAT, address 0x4004 800C */ +#define SYSPLLSTAT_LOCK (1 << 0) // PLL lock status + +/* SYSOSCCTRL, address 0x4004 8020 */ +#define SYSOSCCTRL_BYPASS (1 << 0) // Bypass system oscillator +#define SYSOSCCTRL_FREQRANGE (1 << 1) // Determines frequency range for Low-power oscillator. + +/* WDTOSCCTRL, address 0x4004 8024 */ +#define WDTOSCCTRL_DIVSEL_MASK 0x001F // Select divider for Fclkana. wdt_osc_clk = Fclkana/ (2 (1 + DIVSEL)) 00000: 2 (1 + DIVSEL) = 2 00001: 2 (1 + DIVSEL) = 4 to 11111: 2 (1 + DIVSEL) = 64 +#define WDTOSCCTRL_DIVSEL_SHIFT 0 +#define WDTOSCCTRL_FREQSEL_MASK 0x01E0 // Select watchdog oscillator analog output frequency (Fclkana). +#define WDTOSCCTRL_FREQSEL_SHIFT 5 + +/* IRCCTRL, address 0x4004 8028 */ +#define IRCCTRL_TRIM_MASK 0x00FF // Trim value +#define IRCCTRL_TRIM_SHIFT 0 + +/* SYSRSTSTAT, address 0x4004 8030 */ +#define SYSRSTSTAT_POR (1 << 0) // POR reset status +#define SYSRSTSTAT_EXTRST (1 << 1) // Status of the external RESET pin. +#define SYSRSTSTAT_WDT (1 << 2) // Status of the Watchdog reset +#define SYSRSTSTAT_BOD (1 << 3) // Status of the Brown-out detect reset +#define SYSRSTSTAT_SYSRST (1 << 4) // Status of the software system reset + +/* SYSPLLCLKSEL, address 0x4004 8040 */ +#define SYSPLLCLKSEL_SEL_MASK 0x0003 // System PLL clock source +#define SYSPLLCLKSEL_SEL_SHIFT 0 + +/* SYSPLLCLKUEN, address 0x4004 8044 */ +#define SYSPLLCLKUEN_ENA (1 << 0) // Enable system PLL clock source update + +/* MAINCLKSEL, address 0x4004 8070 */ +#define MAINCLKSEL_SEL_MASK 0x0003 // Clock source for main clock +#define MAINCLKSEL_SEL_SHIFT 0 + +/* MAINCLKUEN, address 0x4004 8074 */ +#define MAINCLKUEN_ENA (1 << 0) // Enable main clock source update 0 + +/* SYSAHBCLKDIV, address 0x4004 8078 */ +#define SYSAHBCLKDIV_DIV_MASK 0x00FF // System AHB clock divider values 0: System clock disabled. 1: Divide by 1. to 255: Divide by 255. +#define SYSAHBCLKDIV_DIV_SHIFT 0 + +/* SYSAHBCLKCTRL, address 0x4004 8080 */ +#define SYSAHBCLKCTRL_SYS (1 << 0) // Enables clock for AHB to APB bridge, to the AHB matrix, to the Cortex-M0 FCLK and HCLK, to the SysCon, and to the PMU. This bit is read only. +#define SYSAHBCLKCTRL_ROM (1 << 1) // Enables clock for ROM. +#define SYSAHBCLKCTRL_RAM (1 << 2) // Enables clock for RAM. +#define SYSAHBCLKCTRL_FLASHREG (1 << 3) // Enables clock for flash register interface. +#define SYSAHBCLKCTRL_FLASHARRAY (1 << 4) // Enables clock for flash array access. +#define SYSAHBCLKCTRL_I2C (1 << 5) // Enables clock for I2C. +#define SYSAHBCLKCTRL_GPIO (1 << 6) // Enables clock for GPIO. +#define SYSAHBCLKCTRL_CT16B0 (1 << 7) // Enables clock for 16-bit counter/timer 0. +#define SYSAHBCLKCTRL_CT16B1 (1 << 8) // Enables clock for 16-bit counter/timer 1. +#define SYSAHBCLKCTRL_CT32B0 (1 << 9) // Enables clock for 32-bit counter/timer 0. +#define SYSAHBCLKCTRL_CT32B1 (1 << 10) // Enables clock for 32-bit counter/timer 1. +#define SYSAHBCLKCTRL_SSP0 (1 << 11) // Enables clock for SPI0. +#define SYSAHBCLKCTRL_UART (1 << 12) // Enables clock for UART. See Section 3.1 for part specific details. +#define SYSAHBCLKCTRL_ADC (1 << 13) // Enables clock for ADC. +#define SYSAHBCLKCTRL_WDT (1 << 15) // Enables clock for WDT. +#define SYSAHBCLKCTRL_IOCON (1 << 16) // Enables clock for I/O configuration block. +#define SYSAHBCLKCTRL_CAN (1 << 17) // Enables clock for C_CAN. See Section 3.1 for part specific details. +#define SYSAHBCLKCTRL_SSP1 (1 << 18) // Enables clock for SPI1. + +/* SSP0CLKDIV, address 0x4004 8094 */ +#define SSP0CLKDIV_DIV_MASK 0x00FF // SPI0_PCLK clock divider values 0: Disable SPI0_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define SSP0CLKDIV_DIV_SHIFT 0 + +/* UARTCLKDIV, address 0x4004 8098 */ +#define UARTCLKDIV_DIV_MASK 0x00FF // UART_PCLK clock divider values 0: Disable UART_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define UARTCLKDIV_DIV_SHIFT 0 + +/* SSP1CLKDIV, address 0x4004 809C */ +#define SSP1CLKDIV_DIV_MASK 0x00FF // SPI1_PCLK clock divider values 0: Disable SPI1_PCLK. 1: Divide by 1. to 255: Divide by 255. +#define SSP1CLKDIV_DIV_SHIFT 0 + +/* WDTCLKSEL, address 0x4004 80D0 */ +#define WDTCLKSEL_SEL_MASK 0x0003 // WDT clock source +#define WDTCLKSEL_SEL_SHIFT 0 + +/* WDTCLKUEN, address 0x4004 80D4 */ +#define WDTCLKUEN_ENA (1 << 0) // Enable WDT clock source update + +/* WDTCLKDIV, address 0x4004 80D8 */ +#define WDTCLKDIV_DIV_MASK 0x00FF // WDT clock divider values 0: Disable WDCLK. 1: Divide by 1. to 255: Divide by 255. +#define WDTCLKDIV_DIV_SHIFT 0 + +/* CLKOUTCLKSEL, address 0x4004 80E0 */ +#define CLKOUTCLKSEL_SEL_MASK 0x0003 // CLKOUT clock source +#define CLKOUTCLKSEL_SEL_SHIFT 0 + +/* CLKOUTUEN, address 0x4004 80E4 */ +#define CLKOUTUEN_ENA (1 << 0) // Enable CLKOUT clock source update 0 + +/* CLKOUTCLKDIV, address 0x4004 80E8 */ +#define CLKOUTCLKDIV_DIV_MASK 0x00FF // Clock output divider values 0: Disable CLKOUT. 1: Divide by 1. to 255: Divide by 255. +#define CLKOUTCLKDIV_DIV_SHIFT 0 + +/* PIOPORCAP0, address 0x4004 8100 */ +#define PIOPORCAP0_CAPPIO0_N_MASK 0x0FFF // Raw reset status input PIO0_n: PIO0_11 to PIO0_0 +#define PIOPORCAP0_CAPPIO0_N_SHIFT 0 +#define PIOPORCAP0_CAPPIO1_N_MASK 0xFFF000 // Raw reset status input PIO1_n: PIO1_11 to PIO1_0 +#define PIOPORCAP0_CAPPIO1_N_SHIFT 12 +#define PIOPORCAP0_CAPPIO2_N_MASK 0xFF000000 // Raw reset status input PIO2_n: PIO2_7 to PIO2_0 +#define PIOPORCAP0_CAPPIO2_N_SHIFT 24 + +/* PIOPORCAP1, address 0x4004 8104 */ +#define PIOPORCAP1_CAPPIO2_8 (1 << 0) // Raw reset status input PIO2_8 +#define PIOPORCAP1_CAPPIO2_9 (1 << 1) // Raw reset status input PIO2_9 +#define PIOPORCAP1_CAPPIO2_10 (1 << 2) // Raw reset status input PIO2_10 +#define PIOPORCAP1_CAPPIO2_11 (1 << 3) // Raw reset status input PIO2_11 +#define PIOPORCAP1_CAPPIO3_0 (1 << 4) // Raw reset status input PIO3_0 +#define PIOPORCAP1_CAPPIO3_1 (1 << 5) // Raw reset status input PIO3_1 +#define PIOPORCAP1_CAPPIO3_2 (1 << 6) // Raw reset status input PIO3_2 +#define PIOPORCAP1_CAPPIO3_3 (1 << 7) // Raw reset status input PIO3_3 +#define PIOPORCAP1_CAPPIO3_4 (1 << 8) // Raw reset status input PIO3_4 +#define PIOPORCAP1_CAPPIO3_5 (1 << 9) // Raw reset status input PIO3_5 + +/* BODCTRL, address 0x4004 8150 */ +#define BODCTRL_BODRSTLEV_MASK 0x0003 // BOD reset level +#define BODCTRL_BODRSTLEV_SHIFT 0 +#define BODCTRL_BODINTVAL_MASK 0x000C // BOD interrupt level +#define BODCTRL_BODINTVAL_SHIFT 2 +#define BODCTRL_BODRSTENA (1 << 4) // BOD reset enable + +/* SYSTCKCAL, address 0x4004 8154 */ +#define SYSTCKCAL_CAL_MASK 0x3FFFFFF // System tick timer calibration value +#define SYSTCKCAL_CAL_SHIFT 0 + +/* NMISRC, address 0x4004 8174 */ +#define NMISRC_IRQNO_MASK 0x001F // The IRQ number of the interrupt that acts as the Non-Maskable Interrupt 0 (NMI) if bit 31 in this register is 1. See Table 54 for the list of interrupt sources and their IRQ numbers. +#define NMISRC_IRQNO_SHIFT 0 +#define NMISRC_NMIEN (1 << 31) // Write a 1 to this bit to enable the Non-Maskable Interrupt (NMI) source selected by bits 4:0. + +/* STARTAPRP0, address 0x4004 8200 */ +#define STARTAPRP0_APRPIO0_N_MASK 0x0FFF // Edge select for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = Falling edge 1 = Rising edge +#define STARTAPRP0_APRPIO0_N_SHIFT 0 +#define STARTAPRP0_APRPIO1_0 (1 << 12) // Edge select for start logic input PIO1_0 0 = Falling edge 1 = Rising edge Reserved. Do not write a 1 to reserved bits in this register. + +/* STARTERP0, address 0x4004 8204 */ +#define STARTERP0_ERPIO0_N_MASK 0x0FFF // Enable start signal for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = Disabled 1 = Enabled +#define STARTERP0_ERPIO0_N_SHIFT 0 +#define STARTERP0_ERPIO1_0 (1 << 12) // Enable start signal for start logic input PIO1_0 0 = Disabled 1 = Enabled Reserved. Do not write a 1 to reserved bits in this register. + +/* STARTRSRP0CLR, address 0x4004 8208 */ +#define STARTRSRP0CLR_RSRPIO0_N_MASK 0x0FFF // Start signal reset for start logic input PIO0_n:PIO0_11 to PIO0_0 0 = Do nothing. 1 = Writing 1 resets the start signal. +#define STARTRSRP0CLR_RSRPIO0_N_SHIFT 0 +#define STARTRSRP0CLR_RSRPIO1_0 (1 << 12) // Start signal reset for start logic input PIO1_0 0 = Do nothing. 1 = Writing 1 resets the start signal. + +/* STARTSRP0, address 0x4004 820C */ +#define STARTSRP0_SRPIO0_N_MASK 0x0FFF // Start signal status for start logic input PIO0_n: PIO0_11 to PIO0_0 0 = No start signal received. 1 = Start signal pending. +#define STARTSRP0_SRPIO0_N_SHIFT 0 +#define STARTSRP0_SRPIO1_0 (1 << 12) // Start signal status for start logic input PIO1_0 0 = No start signal received. 1 = Start signal pending. + +/* PDSLEEPCFG, address 0x4004 8230 */ +#define PDSLEEPCFG_BOD_PD (1 << 3) // BOD power-down control in Deep-sleep mode, see Table 40. +#define PDSLEEPCFG_WDTOSC_PD (1 << 6) // Watchdog oscillator power control in Deep-sleep mode, see Table 40. + +/* PDAWAKECFG, address 0x4004 8234 */ +#define PDAWAKECFG_IRCOUT_PD (1 << 0) // IRC oscillator output wake-up configuration +#define PDAWAKECFG_IRC_PD (1 << 1) // IRC oscillator power-down wake-up configuration +#define PDAWAKECFG_FLASH_PD (1 << 2) // Flash wake-up configuration +#define PDAWAKECFG_BOD_PD (1 << 3) // BOD wake-up configuration +#define PDAWAKECFG_ADC_PD (1 << 4) // ADC wake-up configuration +#define PDAWAKECFG_SYSOSC_PD (1 << 5) // System oscillator wake-up configuration +#define PDAWAKECFG_WDTOSC_PD (1 << 6) // Watchdog oscillator wake-up configuration +#define PDAWAKECFG_SYSPLL_PD (1 << 7) // System PLL wake-up configuration + +/* PDRUNCFG, address 0x4004 8238 */ +#define PDRUNCFG_IRCOUT_PD (1 << 0) // IRC oscillator output power-down +#define PDRUNCFG_IRC_PD (1 << 1) // IRC oscillator power-down +#define PDRUNCFG_FLASH_PD (1 << 2) // Flash power-down +#define PDRUNCFG_BOD_PD (1 << 3) // BOD power-down +#define PDRUNCFG_ADC_PD (1 << 4) // ADC power-down +#define PDRUNCFG_SYSOSC_PD (1 << 5) // System oscillator power-down +#define PDRUNCFG_WDTOSC_PD (1 << 6) // Watchdog oscillator power-down +#define PDRUNCFG_SYSPLL_PD (1 << 7) // System PLL power-down + +/* DEVICE_ID, address 0x4004 83F4 */ +#define DEVICE_ID_DEVICEID_MASK 0xFFFFFFFF // Part ID numbers for LPC111x/LPC11Cxx parts +#define DEVICE_ID_DEVICEID_SHIFT 0 + +/* FLASHCFG, address 0x4003 C010 */ +#define FLASHCFG_FLASHTIM_MASK 0x0003 // Flash memory access time. FLASHTIM +1 is equal to the number of system clocks used for flash access. +#define FLASHCFG_FLASHTIM_SHIFT 0 + +/* PCON, address 0x4003 8000 */ +#define PCON_DPDEN (1 << 1) // Deep power-down mode enable +#define PCON_SLEEPFLAG (1 << 8) // Sleep mode flag +#define PCON_DPDFLAG (1 << 11) // Deep power-down flag + +/* GPREG0 - GPREG3, address 0x4003 8004 to 0x4003 8010 */ +#define GPREGn_GPDATA_MASK 0xFFFFFFFF // Data retained during Deep power-down mode. +#define GPREGn_GPDATA_SHIFT 0 + +/* GPREG4, address 0x4003 8014 */ +#define GPREG4_WAKEUPHYS (1 << 10) // WAKEUP pin hysteresis enable +#define GPREG4_GPDATA_MASK 0xFFFFF800 // Data retained during Deep power-down mode. +#define GPREG4_GPDATA_SHIFT 11 + +/* IOCON_PIO2_6, address 0x4004 4000 */ +#define IOCON_PIO2_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_6_FUNC_SHIFT 0 +#define IOCON_PIO2_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_6_MODE_SHIFT 3 +#define IOCON_PIO2_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_0, address 0x4004 4008 */ +#define IOCON_PIO2_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_0_FUNC_SHIFT 0 +#define IOCON_PIO2_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_0_MODE_SHIFT 3 +#define IOCON_PIO2_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_RESET_PIO0_0, address 0x4004 400C */ +#define IOCON_RESET_PIO0_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_RESET_PIO0_0_FUNC_SHIFT 0 +#define IOCON_RESET_PIO0_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_RESET_PIO0_0_MODE_SHIFT 3 +#define IOCON_RESET_PIO0_0_HYS (1 << 5) // Hysteresis. +#define IOCON_RESET_PIO0_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_1, address 0x4004 4010 */ +#define IOCON_PIO0_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_1_FUNC_SHIFT 0 +#define IOCON_PIO0_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_1_MODE_SHIFT 3 +#define IOCON_PIO0_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_8, address 0x4004 4014 */ +#define IOCON_PIO1_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_8_FUNC_SHIFT 0 +#define IOCON_PIO1_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_8_MODE_SHIFT 3 +#define IOCON_PIO1_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_2, address 0x4004 401C */ +#define IOCON_PIO0_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_2_FUNC_SHIFT 0 +#define IOCON_PIO0_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_2_MODE_SHIFT 3 +#define IOCON_PIO0_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_2_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_7, address 0x4004 4020 */ +#define IOCON_PIO2_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_7_FUNC_SHIFT 0 +#define IOCON_PIO2_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_7_MODE_SHIFT 3 +#define IOCON_PIO2_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_8, address 0x4004 4024 */ +#define IOCON_PIO2_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_8_FUNC_SHIFT 0 +#define IOCON_PIO2_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_8_MODE_SHIFT 3 +#define IOCON_PIO2_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_1, address 0x4004 4028 */ +#define IOCON_PIO2_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_1_FUNC_SHIFT 0 +#define IOCON_PIO2_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_1_MODE_SHIFT 3 +#define IOCON_PIO2_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_3, address 0x4004 402C */ +#define IOCON_PIO0_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_3_FUNC_SHIFT 0 +#define IOCON_PIO0_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_3_MODE_SHIFT 3 +#define IOCON_PIO0_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_4, address 0x4004 4030 */ +#define IOCON_PIO0_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_4_FUNC_SHIFT 0 +#define IOCON_PIO0_4_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, 00 default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_4_I2CMODE_SHIFT 8 + +/* IOCON_PIO0_5, address 0x4004 4034 */ +#define IOCON_PIO0_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_5_FUNC_SHIFT 0 +#define IOCON_PIO0_5_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_5_I2CMODE_SHIFT 8 + +/* IOCON_PIO1_9, address 0x4004 4038 */ +#define IOCON_PIO1_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_9_FUNC_SHIFT 0 +#define IOCON_PIO1_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_9_MODE_SHIFT 3 +#define IOCON_PIO1_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_4, address 0x4004 403C */ +#define IOCON_PIO3_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_4_FUNC_SHIFT 0 +#define IOCON_PIO3_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_4_MODE_SHIFT 3 +#define IOCON_PIO3_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_4, address 0x4004 4040 */ +#define IOCON_PIO2_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_4_FUNC_SHIFT 0 +#define IOCON_PIO2_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_4_MODE_SHIFT 3 +#define IOCON_PIO2_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_5, address 0x4004 4044 */ +#define IOCON_PIO2_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_5_FUNC_SHIFT 0 +#define IOCON_PIO2_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_5_MODE_SHIFT 3 +#define IOCON_PIO2_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_5, address 0x4004 4048 */ +#define IOCON_PIO3_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_5_FUNC_SHIFT 0 +#define IOCON_PIO3_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_5_MODE_SHIFT 3 +#define IOCON_PIO3_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_5_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_6, address 0x4004 404C */ +#define IOCON_PIO0_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_6_FUNC_SHIFT 0 +#define IOCON_PIO0_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_6_MODE_SHIFT 3 +#define IOCON_PIO0_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_7, address 0x4004 4050 */ +#define IOCON_PIO0_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_7_FUNC_SHIFT 0 +#define IOCON_PIO0_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_7_MODE_SHIFT 3 +#define IOCON_PIO0_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_9, address 0x4004 4054 */ +#define IOCON_PIO2_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_9_FUNC_SHIFT 0 +#define IOCON_PIO2_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_9_MODE_SHIFT 3 +#define IOCON_PIO2_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_10, address 0x4004 4058 */ +#define IOCON_PIO2_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_10_FUNC_SHIFT 0 +#define IOCON_PIO2_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_10_MODE_SHIFT 3 +#define IOCON_PIO2_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_10_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_2, address 0x4004 405C */ +#define IOCON_PIO2_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_2_FUNC_SHIFT 0 +#define IOCON_PIO2_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_2_MODE_SHIFT 3 +#define IOCON_PIO2_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_8, address 0x4004 4060 */ +#define IOCON_PIO0_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_8_FUNC_SHIFT 0 +#define IOCON_PIO0_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_8_MODE_SHIFT 3 +#define IOCON_PIO0_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_8_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO0_9, address 0x4004 4064 */ +#define IOCON_PIO0_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_9_FUNC_SHIFT 0 +#define IOCON_PIO0_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_9_MODE_SHIFT 3 +#define IOCON_PIO0_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_9_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SWCLK_PIO0_10, address 0x4004 4068 */ +#define IOCON_SWCLK_PIO0_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWCLK_PIO0_10_FUNC_SHIFT 0 +#define IOCON_SWCLK_PIO0_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWCLK_PIO0_10_MODE_SHIFT 3 +#define IOCON_SWCLK_PIO0_10_HYS (1 << 5) // Hysteresis. +#define IOCON_SWCLK_PIO0_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_10, address 0x4004 406C */ +#define IOCON_PIO1_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_10_FUNC_SHIFT 0 +#define IOCON_PIO1_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_10_MODE_SHIFT 3 +#define IOCON_PIO1_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_10_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_10_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_11, address 0x4004 4070 */ +#define IOCON_PIO2_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_11_FUNC_SHIFT 0 +#define IOCON_PIO2_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_11_MODE_SHIFT 3 +#define IOCON_PIO2_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_11_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO0_11, address 0x4004 4074 */ +#define IOCON_R_PIO0_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO0_11_FUNC_SHIFT 0 +#define IOCON_R_PIO0_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO0_11_MODE_SHIFT 3 +#define IOCON_R_PIO0_11_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO0_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO0_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_0, address 0x4004 4078 */ +#define IOCON_R_PIO1_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_0_FUNC_SHIFT 0 +#define IOCON_R_PIO1_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_0_MODE_SHIFT 3 +#define IOCON_R_PIO1_0_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_0_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_0_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO1_1, address 0x4004 407C */ +#define IOCON_R_PIO1_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_1_FUNC_SHIFT 0 +#define IOCON_R_PIO1_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_1_MODE_SHIFT 3 +#define IOCON_R_PIO1_1_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_1_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_R_PIO1_2, address 0x4004 4080 */ +#define IOCON_R_PIO1_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_2_FUNC_SHIFT 0 +#define IOCON_R_PIO1_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_2_MODE_SHIFT 3 +#define IOCON_R_PIO1_2_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_2_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_2_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_0, address 0x4004 4084 */ +#define IOCON_PIO3_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_0_FUNC_SHIFT 0 +#define IOCON_PIO3_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_0_MODE_SHIFT 3 +#define IOCON_PIO3_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_1, address 0x4004 4088 */ +#define IOCON_PIO3_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_1_FUNC_SHIFT 0 +#define IOCON_PIO3_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_1_MODE_SHIFT 3 +#define IOCON_PIO3_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_1_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO2_3, address 0x4004 408C */ +#define IOCON_PIO2_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_3_FUNC_SHIFT 0 +#define IOCON_PIO2_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_3_MODE_SHIFT 3 +#define IOCON_PIO2_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_3_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SWDIO_PIO1_3, address 0x4004 4090 */ +#define IOCON_SWDIO_PIO1_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWDIO_PIO1_3_FUNC_SHIFT 0 +#define IOCON_SWDIO_PIO1_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWDIO_PIO1_3_MODE_SHIFT 3 +#define IOCON_SWDIO_PIO1_3_HYS (1 << 5) // Hysteresis. +#define IOCON_SWDIO_PIO1_3_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_SWDIO_PIO1_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_4, address 0x4004 4094 */ +#define IOCON_PIO1_4_FUNC_MASK 0x0007 // Selects pin function. This pin functions as WAKEUP pin if the 000 LPC111x/LPC11Cxx is in Deep power-down mode regardless of the value of FUNC. All other values are reserved. +#define IOCON_PIO1_4_FUNC_SHIFT 0 +#define IOCON_PIO1_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_4_MODE_SHIFT 3 +#define IOCON_PIO1_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_4_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_4_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_11, address 0x4004 4098 */ +#define IOCON_PIO1_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_11_FUNC_SHIFT 0 +#define IOCON_PIO1_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_11_MODE_SHIFT 3 +#define IOCON_PIO1_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_11_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_2, address 0x4004 409C */ +#define IOCON_PIO3_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_2_FUNC_SHIFT 0 +#define IOCON_PIO3_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_2_MODE_SHIFT 3 +#define IOCON_PIO3_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_5, address 0x4004 40A0 */ +#define IOCON_PIO1_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_5_FUNC_SHIFT 0 +#define IOCON_PIO1_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_5_MODE_SHIFT 3 +#define IOCON_PIO1_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_5_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_6, address 0x4004 40A4 */ +#define IOCON_PIO1_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_6_FUNC_SHIFT 0 +#define IOCON_PIO1_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_6_MODE_SHIFT 3 +#define IOCON_PIO1_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_6_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO1_7, address 0x4004 40A8 */ +#define IOCON_PIO1_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_7_FUNC_SHIFT 0 +#define IOCON_PIO1_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_7_MODE_SHIFT 3 +#define IOCON_PIO1_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_7_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_PIO3_3, address 0x4004 40AC */ +#define IOCON_PIO3_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_3_FUNC_SHIFT 0 +#define IOCON_PIO3_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_3_MODE_SHIFT 3 +#define IOCON_PIO3_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_3_OD (1 << 10) // Selects pseudo open-drain mode. See Section 7.1 for part specific details. + +/* IOCON_SCK_LOC, address 0x4004 40B0 */ +#define IOCON_SCK_LOC_SCKLOC_MASK 0x0003 // Selects pin location for SCK0 function. +#define IOCON_SCK_LOC_SCKLOC_SHIFT 0 + +/* IOCON_DSR_LOC, address 0x4004 40B4 */ +#define IOCON_DSR_LOC_DSRLOC_MASK 0x0003 // elects pin location for DSR function. +#define IOCON_DSR_LOC_DSRLOC_SHIFT 0 + +/* IOCON_DCD_LOC, address 0x4004 40B8 */ +#define IOCON_DCD_LOC_DCDLOC_MASK 0x0003 // Selects pin location for DCD function. +#define IOCON_DCD_LOC_DCDLOC_SHIFT 0 + +/* IOCON_RI_LOC, address 0x4004 40BC */ +#define IOCON_RI_LOC_RILOC_MASK 0x0003 // Selects pin location for RI function. +#define IOCON_RI_LOC_RILOC_SHIFT 0 + +/* IOCON_PIO2_6, address 0x4004 4000 */ +#define IOCON_PIO2_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_6_FUNC_SHIFT 0 +#define IOCON_PIO2_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_6_MODE_SHIFT 3 +#define IOCON_PIO2_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_0, address 0x4004 4008 */ +#define IOCON_PIO2_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_0_FUNC_SHIFT 0 +#define IOCON_PIO2_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_0_MODE_SHIFT 3 +#define IOCON_PIO2_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_RESET_PIO0_0, address 0x4004 400C */ +#define IOCON_RESET_PIO0_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_RESET_PIO0_0_FUNC_SHIFT 0 +#define IOCON_RESET_PIO0_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_RESET_PIO0_0_MODE_SHIFT 3 +#define IOCON_RESET_PIO0_0_HYS (1 << 5) // Hysteresis. +#define IOCON_RESET_PIO0_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_1, address 0x4004 4010 */ +#define IOCON_PIO0_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_1_FUNC_SHIFT 0 +#define IOCON_PIO0_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_1_MODE_SHIFT 3 +#define IOCON_PIO0_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_8, address 0x4004 4014 */ +#define IOCON_PIO1_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_8_FUNC_SHIFT 0 +#define IOCON_PIO1_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_8_MODE_SHIFT 3 +#define IOCON_PIO1_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_2, address 0x4004 401C */ +#define IOCON_PIO0_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_2_FUNC_SHIFT 0 +#define IOCON_PIO0_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_2_MODE_SHIFT 3 +#define IOCON_PIO0_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_7, address 0x4004 4020 */ +#define IOCON_PIO2_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_7_FUNC_SHIFT 0 +#define IOCON_PIO2_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_7_MODE_SHIFT 3 +#define IOCON_PIO2_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_8, address 0x4004 4024 */ +#define IOCON_PIO2_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_8_FUNC_SHIFT 0 +#define IOCON_PIO2_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_8_MODE_SHIFT 3 +#define IOCON_PIO2_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_1, address 0x4004 4028 */ +#define IOCON_PIO2_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_1_FUNC_SHIFT 0 +#define IOCON_PIO2_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_1_MODE_SHIFT 3 +#define IOCON_PIO2_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_3, address 0x4004 402C */ +#define IOCON_PIO0_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_3_FUNC_SHIFT 0 +#define IOCON_PIO0_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_3_MODE_SHIFT 3 +#define IOCON_PIO0_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_4, address 0x4004 4030 */ +#define IOCON_PIO0_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_4_FUNC_SHIFT 0 +#define IOCON_PIO0_4_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, 00 default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_4_I2CMODE_SHIFT 8 + +/* IOCON_PIO0_5, address 0x4004 4034 */ +#define IOCON_PIO0_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_5_FUNC_SHIFT 0 +#define IOCON_PIO0_5_I2CMODE_MASK 0x0300 // Selects I2C mode. Select Standard mode (I2CMODE = 00, default) or Standard I/O functionality (I2CMODE = 01) if the pin function is GPIO (FUNC = 000). +#define IOCON_PIO0_5_I2CMODE_SHIFT 8 + +/* IOCON_PIO1_9, address 0x4004 4038 */ +#define IOCON_PIO1_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_9_FUNC_SHIFT 0 +#define IOCON_PIO1_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_9_MODE_SHIFT 3 +#define IOCON_PIO1_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_4, address 0x4004 403C */ +#define IOCON_PIO3_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_4_FUNC_SHIFT 0 +#define IOCON_PIO3_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_4_MODE_SHIFT 3 +#define IOCON_PIO3_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_4, address 0x4004 4040 */ +#define IOCON_PIO2_4_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_4_FUNC_SHIFT 0 +#define IOCON_PIO2_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_4_MODE_SHIFT 3 +#define IOCON_PIO2_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_5, address 0x4004 4044 */ +#define IOCON_PIO2_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_5_FUNC_SHIFT 0 +#define IOCON_PIO2_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_5_MODE_SHIFT 3 +#define IOCON_PIO2_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_5, address 0x4004 4048 */ +#define IOCON_PIO3_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_5_FUNC_SHIFT 0 +#define IOCON_PIO3_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_5_MODE_SHIFT 3 +#define IOCON_PIO3_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_6, address 0x4004 404C */ +#define IOCON_PIO0_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_6_FUNC_SHIFT 0 +#define IOCON_PIO0_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_6_MODE_SHIFT 3 +#define IOCON_PIO0_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_7, address 0x4004 4050 */ +#define IOCON_PIO0_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_7_FUNC_SHIFT 0 +#define IOCON_PIO0_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_7_MODE_SHIFT 3 +#define IOCON_PIO0_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_9, address 0x4004 4054 */ +#define IOCON_PIO2_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_9_FUNC_SHIFT 0 +#define IOCON_PIO2_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_9_MODE_SHIFT 3 +#define IOCON_PIO2_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_10, address 0x4004 4058 */ +#define IOCON_PIO2_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_10_FUNC_SHIFT 0 +#define IOCON_PIO2_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_10_MODE_SHIFT 3 +#define IOCON_PIO2_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_2, address 0x4004 405C */ +#define IOCON_PIO2_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_2_FUNC_SHIFT 0 +#define IOCON_PIO2_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_2_MODE_SHIFT 3 +#define IOCON_PIO2_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_8, address 0x4004 4060 */ +#define IOCON_PIO0_8_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_8_FUNC_SHIFT 0 +#define IOCON_PIO0_8_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_8_MODE_SHIFT 3 +#define IOCON_PIO0_8_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_8_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO0_9, address 0x4004 4064 */ +#define IOCON_PIO0_9_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO0_9_FUNC_SHIFT 0 +#define IOCON_PIO0_9_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO0_9_MODE_SHIFT 3 +#define IOCON_PIO0_9_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO0_9_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SWCLK_PIO0_10, address 0x4004 4068 */ +#define IOCON_SWCLK_PIO0_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWCLK_PIO0_10_FUNC_SHIFT 0 +#define IOCON_SWCLK_PIO0_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWCLK_PIO0_10_MODE_SHIFT 3 +#define IOCON_SWCLK_PIO0_10_HYS (1 << 5) // Hysteresis. +#define IOCON_SWCLK_PIO0_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_10, address 0x4004 406C */ +#define IOCON_PIO1_10_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_10_FUNC_SHIFT 0 +#define IOCON_PIO1_10_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_10_MODE_SHIFT 3 +#define IOCON_PIO1_10_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_10_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_10_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_11, address 0x4004 4070 */ +#define IOCON_PIO2_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_11_FUNC_SHIFT 0 +#define IOCON_PIO2_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_11_MODE_SHIFT 3 +#define IOCON_PIO2_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO0_11, address 0x4004 4074 */ +#define IOCON_R_PIO0_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO0_11_FUNC_SHIFT 0 +#define IOCON_R_PIO0_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO0_11_MODE_SHIFT 3 +#define IOCON_R_PIO0_11_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO0_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO0_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_0, address 0x4004 4078 */ +#define IOCON_R_PIO1_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_0_FUNC_SHIFT 0 +#define IOCON_R_PIO1_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_0_MODE_SHIFT 3 +#define IOCON_R_PIO1_0_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_0_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_1, address 0x4004 407C */ +#define IOCON_R_PIO1_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_1_FUNC_SHIFT 0 +#define IOCON_R_PIO1_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_1_MODE_SHIFT 3 +#define IOCON_R_PIO1_1_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_1_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_R_PIO1_2, address 0x4004 4080 */ +#define IOCON_R_PIO1_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_R_PIO1_2_FUNC_SHIFT 0 +#define IOCON_R_PIO1_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_R_PIO1_2_MODE_SHIFT 3 +#define IOCON_R_PIO1_2_HYS (1 << 5) // Hysteresis. +#define IOCON_R_PIO1_2_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_R_PIO1_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_0, address 0x4004 4084 */ +#define IOCON_PIO3_0_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_0_FUNC_SHIFT 0 +#define IOCON_PIO3_0_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_0_MODE_SHIFT 3 +#define IOCON_PIO3_0_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_0_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_1, address 0x4004 4088 */ +#define IOCON_PIO3_1_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_1_FUNC_SHIFT 0 +#define IOCON_PIO3_1_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_1_MODE_SHIFT 3 +#define IOCON_PIO3_1_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_1_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO2_3, address 0x4004 408C */ +#define IOCON_PIO2_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO2_3_FUNC_SHIFT 0 +#define IOCON_PIO2_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO2_3_MODE_SHIFT 3 +#define IOCON_PIO2_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO2_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SWDIO_PIO1_3, address 0x4004 4090 */ +#define IOCON_SWDIO_PIO1_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_SWDIO_PIO1_3_FUNC_SHIFT 0 +#define IOCON_SWDIO_PIO1_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_SWDIO_PIO1_3_MODE_SHIFT 3 +#define IOCON_SWDIO_PIO1_3_HYS (1 << 5) // Hysteresis. +#define IOCON_SWDIO_PIO1_3_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_SWDIO_PIO1_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_4, address 0x4004 4094 */ +#define IOCON_PIO1_4_FUNC_MASK 0x0007 // Selects pin function. This pin functions as WAKEUP pin if the 000 LPC111x/LPC11Cxx is in Deep power-down mode regardless of the value of FUNC. All other values are reserved. +#define IOCON_PIO1_4_FUNC_SHIFT 0 +#define IOCON_PIO1_4_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_4_MODE_SHIFT 3 +#define IOCON_PIO1_4_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_4_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_4_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_11, address 0x4004 4098 */ +#define IOCON_PIO1_11_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_11_FUNC_SHIFT 0 +#define IOCON_PIO1_11_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_11_MODE_SHIFT 3 +#define IOCON_PIO1_11_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_11_ADMODE (1 << 7) // Selects Analog/Digital mode +#define IOCON_PIO1_11_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_2, address 0x4004 409C */ +#define IOCON_PIO3_2_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_2_FUNC_SHIFT 0 +#define IOCON_PIO3_2_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_2_MODE_SHIFT 3 +#define IOCON_PIO3_2_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_2_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_5, address 0x4004 40A0 */ +#define IOCON_PIO1_5_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_5_FUNC_SHIFT 0 +#define IOCON_PIO1_5_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_5_MODE_SHIFT 3 +#define IOCON_PIO1_5_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_5_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_6, address 0x4004 40A4 */ +#define IOCON_PIO1_6_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_6_FUNC_SHIFT 0 +#define IOCON_PIO1_6_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_6_MODE_SHIFT 3 +#define IOCON_PIO1_6_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_6_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO1_7, address 0x4004 40A8 */ +#define IOCON_PIO1_7_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO1_7_FUNC_SHIFT 0 +#define IOCON_PIO1_7_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO1_7_MODE_SHIFT 3 +#define IOCON_PIO1_7_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO1_7_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_PIO3_3, address 0x4004 40AC */ +#define IOCON_PIO3_3_FUNC_MASK 0x0007 // Selects pin function. All other values are reserved. +#define IOCON_PIO3_3_FUNC_SHIFT 0 +#define IOCON_PIO3_3_MODE_MASK 0x0018 // Selects function mode (on-chip pull-up/pull-down resistor control). +#define IOCON_PIO3_3_MODE_SHIFT 3 +#define IOCON_PIO3_3_HYS (1 << 5) // Hysteresis. +#define IOCON_PIO3_3_OD (1 << 10) // Selects pseudo open-drain mode. + +/* IOCON_SCK0_LOC, address 0x4004 40B0 */ +#define IOCON_SCK0_LOC_SCKLOC_MASK 0x0003 // Selects pin location for SCK0 function. +#define IOCON_SCK0_LOC_SCKLOC_SHIFT 0 + +/* IOCON_DSR_LOC, address 0x4004 40B4 */ +#define IOCON_DSR_LOC_DSRLOC_MASK 0x0003 // elects pin location for DSR function. +#define IOCON_DSR_LOC_DSRLOC_SHIFT 0 + +/* IOCON_DCD_LOC, address 0x4004 40B8 */ +#define IOCON_DCD_LOC_DCDLOC_MASK 0x0003 // Selects pin location for DCD function. +#define IOCON_DCD_LOC_DCDLOC_SHIFT 0 + +/* IOCON_RI_LOC, address 0x4004 40BC */ +#define IOCON_RI_LOC_RILOC_MASK 0x0003 // Selects pin location for RI function. +#define IOCON_RI_LOC_RILOC_SHIFT 0 + +/* IOCON_SSEL1_LOC, address 0x4004 4018 */ +#define IOCON_SSEL1_LOC_SSEL1LOC_MASK 0x0003 // Selects pin location for SSEL1 function. +#define IOCON_SSEL1_LOC_SSEL1LOC_SHIFT 0 + +/* IOCON_CT16B0_CAP0_LOC, address 0x4004 40C0 */ +#define IOCON_CT16B0_CAP0_LOC_CT16B0_CAP0LOC_MASK 0x0003 // Selects pin location for CT16B0_CAP0 function. +#define IOCON_CT16B0_CAP0_LOC_CT16B0_CAP0LOC_SHIFT 0 + +/* IOCON_SCK1_LOC, address 0x4004 40C4 */ +#define IOCON_SCK1_LOC_SCK1LOC_MASK 0x0003 // Selects pin location for SCK1 function. +#define IOCON_SCK1_LOC_SCK1LOC_SHIFT 0 + +/* IOCON_MISO1_LOC, address 0x4004 40C8 */ +#define IOCON_MISO1_LOC_MISO1LOC_MASK 0x0003 // Selects pin location for the MISO1 function. +#define IOCON_MISO1_LOC_MISO1LOC_SHIFT 0 + +/* IOCON_MOSI1_LOC, address 0x4004 40CC */ +#define IOCON_MOSI1_LOC_MOSI1LOC_MASK 0x0003 // Selects pin location for the MOSI1 function. +#define IOCON_MOSI1_LOC_MOSI1LOC_SHIFT 0 + +/* IOCON_CT32B0_CAP0_LOC, address 0x4004 40D0 */ +#define IOCON_CT32B0_CAP0_LOC_CT32B0_CAP0LOC_MASK 0x0003 // Selects pin location for the CT32B0_CAP0 function. +#define IOCON_CT32B0_CAP0_LOC_CT32B0_CAP0LOC_SHIFT 0 + +/* IOCON_RXD_LOC, address 0x4004 40D4 */ +#define IOCON_RXD_LOC_RXDLOC_MASK 0x0003 // Selects pin location for the RXD function. +#define IOCON_RXD_LOC_RXDLOC_SHIFT 0 + +/* GPIO0DIR, address 0x5000 8000 to GPIO3DIR, address 0x5003 8000 */ +#define GPIO0DIR_IO_MASK 0x0FFF // Selects pin x as input or output (x = 0 to 11). 0 = Pin PIOn_x is configured as input. 1 = Pin PIOn_x is configured as output. +#define GPIO0DIR_IO_SHIFT 0 + +/* GPIO0IS, address 0x5000 8004 to GPIO3IS, address 0x5003 8004 */ +#define GPIO0IS_ISENSE_MASK 0x0FFF // Selects interrupt on pin x as level or edge sensitive (x = 0 to 0x00 11). 0 = Interrupt on pin PIOn_x is configured as edge sensitive. 1 = Interrupt on pin PIOn_x is configured as level sensitive. +#define GPIO0IS_ISENSE_SHIFT 0 + +/* GPIO0IBE, address 0x5000 8008 to GPIO3IBE, address 0x5003 8008 */ +#define GPIO0IBE_IBE_MASK 0x0FFF // Selects interrupt on pin x to be triggered on both edges (x = 0 0x00 to 11). 0 = Interrupt on pin PIOn_x is controlled through register GPIOnIEV. 1 = Both edges on pin PIOn_x trigger an interrupt. +#define GPIO0IBE_IBE_SHIFT 0 + +/* GPIO0IEV, address 0x5000 800C to GPIO3IEV, address 0x5003 800C */ +#define GPIO0IEV_IEV_MASK 0x0FFF // Selects interrupt on pin x to be triggered rising or falling edges (x = 0 to 11). 0 = Depending on setting in register GPIOnIS (see Table 175), falling edges or LOW level on pin PIOn_x trigger an interrupt. 1 = Depending on setting in register GPIOnIS (see Table 175), rising edges or HIGH level on pin PIOn_x trigger an interrupt. +#define GPIO0IEV_IEV_SHIFT 0 + +/* GPIO0IE, address 0x5000 8010 to GPIO3IE, address 0x5003 8010 */ +#define GPIO0IE_MASK_MASK 0x0FFF // Selects interrupt on pin x to be masked (x = 0 to 11). 0 = Interrupt on pin PIOn_x is masked. 1 = Interrupt on pin PIOn_x is not masked. +#define GPIO0IE_MASK_SHIFT 0 + +/* GPIO0RIS, address 0x5000 8014 to GPIO3RIS, address 0x5003 8014 */ +#define GPIO0RIS_RAWST_MASK 0x0FFF // Raw interrupt status (x = 0 to 11). 0 = No interrupt on pin PIOn_x. 1 = Interrupt requirements met on PIOn_x. +#define GPIO0RIS_RAWST_SHIFT 0 + +/* GPIO0MIS, address 0x5000 8018 to GPIO3MIS, address 0x5003 8018 */ +#define GPIO0MIS_MASK_MASK 0x0FFF // Selects interrupt on pin x to be masked (x = 0 to 11). 0 = No interrupt or interrupt masked on pin PIOn_x. 1 = Interrupt on PIOn_x. +#define GPIO0MIS_MASK_SHIFT 0 + +/* GPIO0IC, address 0x5000 801C to GPIO3IC, address 0x5003 801C */ +#define GPIO0IC_CLR_MASK 0x0FFF // Selects interrupt on pin x to be cleared (x = 0 to 11). Clears 0x00 the interrupt edge detection logic. This register is write-only. Remark: The synchronizer between the GPIO and the NVIC blocks causes a delay of 2 clocks. It is recommended to add two NOPs after the clear of the interrupt edge detection logic before the exit of the interrupt service routine. 0 = No effect. 1 = Clears edge detection logic for pin PIOn_x. +#define GPIO0IC_CLR_SHIFT 0 + +/* U0IIR - address 0x4004 8008, Read Only */ +#define U0IIR_INTSTATUS (1 << 0) // Interrupt status. Note that U0IIR[0] is active low. The pending interrupt can be determined by evaluating U0IIR[3:1]. +#define U0IIR_INTID_MASK 0x000E // Interrupt identification. U0IER[3:1] identifies an interrupt 0 corresponding to the UART Rx FIFO. All other combinations of U0IER[3:1] not listed below are reserved (100,101,111). +#define U0IIR_INTID_SHIFT 1 +#define U0IIR_FIFOENABLE_MASK 0x00C0 // These bits are equivalent to U0FCR[0]. +#define U0IIR_FIFOENABLE_SHIFT 6 +#define U0IIR_ABEOINT (1 << 8) // End of auto-baud interrupt. True if auto-baud has finished successfully and interrupt is enabled. +#define U0IIR_ABTOINT (1 << 9) // Auto-baud time-out interrupt. True if auto-baud has timed out and interrupt is enabled. Reserved, user software should not write ones to reserved bits. The value read from a reserved bit is not defined. + +/* U0FCR - address 0x4000 8008, Write Only */ +#define U0FCR_FIFOEN (1 << 0) // FIFO Enable +#define U0FCR_RXFIFORES (1 << 1) // RX FIFO Reset +#define U0FCR_TXFIFORES (1 << 2) // TX FIFO Reset +#define U0FCR_RXTL_MASK 0x00C0 // RX Trigger Level. These two bits determine how many 0 receiver UART FIFO characters must be written before an interrupt is activated. +#define U0FCR_RXTL_SHIFT 6 + +/* U0LCR - address 0x4000 800C */ +#define U0LCR_WLS_MASK 0x0003 // Word Length Select +#define U0LCR_WLS_SHIFT 0 +#define U0LCR_SBS (1 << 2) // Stop Bit Select +#define U0LCR_PE (1 << 3) // Parity Enable +#define U0LCR_PS_MASK 0x0030 // Parity Select 0x0 Odd parity. Number of 1s in the transmitted character and the attached parity bit will be odd. 0x1 Even Parity. Number of 1s in the transmitted character and the attached parity bit will be even. 0x2 Forced 1 stick parity. 0x3 Forced 0 stick parity. +#define U0LCR_PS_SHIFT 4 +#define U0LCR_BC (1 << 6) // Break Control +#define U0LCR_DLAB (1 << 7) // Divisor Latch Access Bit + +/* U0MCR - address 0x4000 8010 */ +#define U0MCR_DTRC (1 << 0) // DTR Control. Source for modem output pin, DTR. This bit reads as 0 when modem loopback mode is active. +#define U0MCR_RTSC (1 << 1) // RTS Control. Source for modem output pin RTS. This bit reads as 0 0 when modem loopback mode is active. +#define U0MCR_LMS (1 << 4) // Loopback Mode Select. The modem loopback mode provides a 0 mechanism to perform diagnostic loopback testing. Serial data from the transmitter is connected internally to serial input of the receiver. Input pin, RXD, has no effect on loopback and output pin, TXD is held in marking state. The four modem inputs (CTS, DSR, RI and DCD) are disconnected externally. Externally, the modem outputs (RTS, DTR) are set inactive. Internally, the four modem outputs are connected to the four modem inputs. As a result of these connections, the upper four bits of the U0MSR will be driven by the lower four bits of the U0MCR rather than the four modem inputs in normal mode. This permits modem status interrupts to be generated in loopback mode by writing the lower four bits of U0MCR. +#define U0MCR_RTSEN (1 << 6) // RTS flow control +#define U0MCR_CTSEN (1 << 7) // CTS flow control + +/* U0LSR - address 0x4000 8014, Read Only */ +#define U0LSR_RDR (1 << 0) // Receiver Data Ready. U0LSR[0] is set when the U0RBR holds 0 an unread character and is cleared when the UART RBR FIFO is empty. +#define U0LSR_OE (1 << 1) // Overrun Error. The overrun error condition is set as soon as it 0 occurs. A U0LSR read clears U0LSR[1]. U0LSR[1] is set when UART RSR has a new character assembled and the UART RBR FIFO is full. In this case, the UART RBR FIFO will not be overwritten and the character in the UART RSR will be lost. +#define U0LSR_PE (1 << 2) // Parity Error. When the parity bit of a received character is in the wrong state, a parity error occurs. A U0LSR read clears U0LSR[2]. Time of parity error detection is dependent on U0FCR[0]. Note: A parity error is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_FE (1 << 3) // Framing Error. When the stop bit of a received character is a 0 logic 0, a framing error occurs. A U0LSR read clears U0LSR[3]. The time of the framing error detection is dependent on U0FCR0. Upon detection of a framing error, the RX will attempt to re-synchronize to the data and assume that the bad stop bit is actually an early start bit. However, it cannot be assumed that the next received byte will be correct even if there is no Framing Error. Note: A framing error is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_BI (1 << 4) // Break Interrupt. When RXD1 is held in the spacing state (all zeros) for one full character transmission (start, data, parity, stop), a break interrupt occurs. Once the break condition has been detected, the receiver goes idle until RXD1 goes to marking state (all ones). A U0LSR read clears this status bit. The time of break detection is dependent on U0FCR[0]. Note: The break interrupt is associated with the character at the top of the UART RBR FIFO. +#define U0LSR_THRE (1 << 5) // Transmitter Holding Register Empty. THRE is set immediately 1 upon detection of an empty UART THR and is cleared on a U0THR write. +#define U0LSR_TEMT (1 << 6) // Transmitter Empty. TEMT is set when both U0THR and 1 U0TSR are empty; TEMT is cleared when either the U0TSR or the U0THR contain valid data. This bit is updated as soon as 50 % of the first stop bit has been transmitted or a byte has been written into the THR. +#define U0LSR_RXFE (1 << 7) // Error in RX FIFO. U0LSR[7] is set when a character with a RX 0 error such as framing error, parity error or break interrupt, is loaded into the U0RBR. This bit is cleared when the U0LSR register is read and there are no subsequent errors in the UART FIFO. + +/* U0MSR - address 0x4000 8018 */ +#define U0MSR_DCTS (1 << 0) // Delta CTS. Set upon state change of input CTS. Cleared on a U0MSR read. 0 No change detected on modem input CTS. 1 State change detected on modem input CTS. +#define U0MSR_DDSR (1 << 1) // Delta DSR. Set upon state change of input DSR. Cleared on a U0MSR read. 0 No change detected on modem input DSR. 1 State change detected on modem input DSR. +#define U0MSR_TERI (1 << 2) // Trailing Edge RI. Set upon low to high transition of input RI. Cleared 0 on a U0MSR read. 0 No change detected on modem input, RI. 1 Low-to-high transition detected on RI. +#define U0MSR_DDCD (1 << 3) // Delta DCD. Set upon state change of input DCD. Cleared on a U0MSR read. 0 No change detected on modem input DCD. 1 State change detected on modem input DCD. +#define U0MSR_CTS (1 << 4) // Clear To Send State. Complement of input signal CTS. This bit is connected to U0MCR[1] in modem loopback mode. +#define U0MSR_DSR (1 << 5) // Data Set Ready State. Complement of input signal DSR. This bit is connected to U0MCR[0] in modem loopback mode. +#define U0MSR_RI (1 << 6) // Ring Indicator State. Complement of input RI. This bit is connected to U0MCR[2] in modem loopback mode. +#define U0MSR_DCD (1 << 7) // Data Carrier Detect State. Complement of input DCD. This bit is connected to U0MCR[3] in modem loopback mode. + +/* U0SCR - address 0x4000 801C */ +#define U0SCR_PAD_MASK 0x00FF // A readable, writable byte. +#define U0SCR_PAD_SHIFT 0 + +/* U0ACR - address 0x4000 8020 */ +#define U0ACR_START (1 << 0) // Start bit. This bit is automatically cleared after auto-baud completion. +#define U0ACR_MODE (1 << 1) // Auto-baud mode select +#define U0ACR_AUTORESTART (1 << 2) // Restart enable +#define U0ACR_ABEOINTCLR (1 << 8) // End of auto-baud interrupt clear (write only accessible) +#define U0ACR_ABTOINTCLR (1 << 9) // Auto-baud time-out interrupt clear (write only accessible) + +/* U0TER - address 0x4000 8030 */ +#define U0TER_TXEN (1 << 7) // When this bit is 1, as it is after a Reset, data written to the THR 1 is output on the TXD pin as soon as any preceding data has been sent. If this bit cleared to 0 while a character is being sent, the transmission of that character is completed, but no further characters are sent until this bit is set again. In other words, a 0 in this bit blocks the transfer of characters from the THR or TX FIFO into the transmit shift register. Software can clear this bit when it detects that the a hardware-handshaking TX-permit signal (CTS) has gone false, or with software handshaking, when it receives an XOFF character (DC3). Software can set this bit again when it detects that the TX-permit signal has gone true, or when it receives an XON (DC1) character. Reserved + +/* U0RS485CTRL - address 0x4000 804C */ +#define U0RS485CTRL_NMMEN (1 << 0) // NMM enable. +#define U0RS485CTRL_RXDIS (1 << 1) // Receiver enable. +#define U0RS485CTRL_AADEN (1 << 2) // AAD enable. +#define U0RS485CTRL_SEL (1 << 3) // Select direction control pin +#define U0RS485CTRL_DCTRL (1 << 4) // Auto direction control enable. +#define U0RS485CTRL_OINV (1 << 5) // Polarity control. This bit reverses the polarity of the direction control signal on the RTS (or DTR) pin. + +/* U0RS485ADRMATCH - address 0x4000 8050 */ +#define U0RS485ADRMATCH_ADRMATCH_MASK 0x00FF // Contains the address match value. 0 +#define U0RS485ADRMATCH_ADRMATCH_SHIFT 0 + +/* U0RS485DLY - address 0x4000 8054 */ +#define U0RS485DLY_DLY_MASK 0x00FF // Contains the direction control (RTS or DTR) delay value. This register works in conjunction with an 8-bit counter. +#define U0RS485DLY_DLY_SHIFT 0 + +/* SSP0CR0 - address 0x4004 0000, SSP1CR0 - address 0x4005 8000 */ +#define SSP0CR0_DSS_MASK 0x000F // Data Size Select. This field controls the number of bits transferred in each frame. Values 0000-0010 are not supported and should not be used. +#define SSP0CR0_DSS_SHIFT 0 +#define SSP0CR0_FRF_MASK 0x0030 // Frame Format. +#define SSP0CR0_FRF_SHIFT 4 +#define SSP0CR0_CPOL (1 << 6) // Clock Out Polarity. This bit is only used in SPI mode. +#define SSP0CR0_CPHA (1 << 7) // Clock Out Phase. This bit is only used in SPI mode. +#define SSP0CR0_SCR_MASK 0xFF00 // Serial Clock Rate. The number of prescaler output clocks per 0x00 bit on the bus, minus one. Given that CPSDVSR is the prescale divider, and the APB clock PCLK clocks the prescaler, the bit frequency is PCLK / (CPSDVSR [SCR+1]). Reserved +#define SSP0CR0_SCR_SHIFT 8 + +/* SSP0CR1 - address 0x4004 0004, SSP1CR1 - address 0x4005 8004 */ +#define SSP0CR1_LBM (1 << 0) // Loop Back Mode. +#define SSP0CR1_SSE (1 << 1) // SPI Enable. +#define SSP0CR1_MS (1 << 2) // Master/Slave Mode.This bit can only be written when the SSE bit is 0. +#define SSP0CR1_SOD (1 << 3) // Slave Output Disable. This bit is relevant only in slave 0 mode (MS = 1). If it is 1, this blocks this SPI controller from driving the transmit data line (MISO). + +/* SSP0DR - address 0x4004 0008, SSP1DR - address 0x4005 8008 */ +#define SSP0DR_DATA_MASK 0xFFFF // Write: software can write data to be sent in a future frame to this 0x0000 register whenever the TNF bit in the Status register is 1, indicating that the Tx FIFO is not full. If the Tx FIFO was previously empty and the SPI controller is not busy on the bus, transmission of the data will begin immediately. Otherwise the data written to this register will be sent as soon as all previous data has been sent (and received). If the data length is less than 16 bit, software must right-justify the data written to this register. Read: software can read data from this register whenever the RNE bit in the Status register is 1, indicating that the Rx FIFO is not empty. When software reads this register, the SPI controller returns data from the least recent frame in the Rx FIFO. If the data length is less than 16 bit, the data is right-justified in this field with higher order bits filled with 0s. Reserved. +#define SSP0DR_DATA_SHIFT 0 + +/* SSP0SR - address 0x4004 000C, SSP1SR - address 0x4005 800C */ +#define SSP0SR_TFE (1 << 0) // Transmit FIFO Empty. This bit is 1 is the Transmit FIFO is empty, 0 if not. +#define SSP0SR_TNF (1 << 1) // Transmit FIFO Not Full. This bit is 0 if the Tx FIFO is full, 1 if not. 1 +#define SSP0SR_RNE (1 << 2) // Receive FIFO Not Empty. This bit is 0 if the Receive FIFO is empty, 1 if not. +#define SSP0SR_RFF (1 << 3) // Receive FIFO Full. This bit is 1 if the Receive FIFO is full, 0 if not. +#define SSP0SR_BSY (1 << 4) // Busy. This bit is 0 if the SPI controller is idle, 1 if it is currently sending/receiving a frame and/or the Tx FIFO is not empty. + +/* SSP0CPSR - address 0x4004 0010, SSP1CPSR - address 0x4005 8010 */ +#define SSP0CPSR_CPSDVSR_MASK 0x00FF // This even value between 2 and 254, by which SPI_PCLK is divided to yield the prescaler output clock. Bit 0 always reads as 0. +#define SSP0CPSR_CPSDVSR_SHIFT 0 + +/* SSP0IMSC - address 0x4004 0014, SSP1IMSC - address 0x4005 8014 */ +#define SSP0IMSC_RORIM (1 << 0) // Software should set this bit to enable interrupt when a Receive 0 Overrun occurs, that is, when the Rx FIFO is full and another frame is completely received. The ARM spec implies that the preceding frame data is overwritten by the new frame data when this occurs. +#define SSP0IMSC_RTIM (1 << 1) // Software should set this bit to enable interrupt when a Receive Time-out condition occurs. A Receive Time-out occurs when the Rx FIFO is not empty, and no has not been read for a time-out period. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0IMSC_RXIM (1 << 2) // Software should set this bit to enable interrupt when the Rx FIFO is at 0 least half full. +#define SSP0IMSC_TXIM (1 << 3) // Software should set this bit to enable interrupt when the Tx FIFO is at 0 least half empty. + +/* SSP0RIS - address 0x4004 0018, SSP1RIS - address 0x4005 8018 */ +#define SSP0RIS_RORRIS (1 << 0) // This bit is 1 if another frame was completely received while the 0 RxFIFO was full. The ARM spec implies that the preceding frame data is overwritten by the new frame data when this occurs. +#define SSP0RIS_RTRIS (1 << 1) // This bit is 1 if the Rx FIFO is not empty, and has not been read 0 for a time-out period. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0RIS_RXRIS (1 << 2) // This bit is 1 if the Rx FIFO is at least half full. +#define SSP0RIS_TXRIS (1 << 3) // This bit is 1 if the Tx FIFO is at least half empty. + +/* SSP0MIS - address 0x4004 001C, SSP1MIS - address 0x4005 801C */ +#define SSP0MIS_RORMIS (1 << 0) // This bit is 1 if another frame was completely received while the 0 RxFIFO was full, and this interrupt is enabled. +#define SSP0MIS_RTMIS (1 << 1) // This bit is 1 if the Rx FIFO is not empty, has not been read for a time-out period, and this interrupt is enabled. The time-out period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). +#define SSP0MIS_RXMIS (1 << 2) // This bit is 1 if the Rx FIFO is at least half full, and this interrupt 0 is enabled. +#define SSP0MIS_TXMIS (1 << 3) // This bit is 1 if the Tx FIFO is at least half empty, and this interrupt is enabled. + +/* SSP0ICR - address 0x4004 0020, SSP1ICR - address 0x4005 8020 */ +#define SSP0ICR_RORIC (1 << 0) // Writing a 1 to this bit clears the "frame was received when RxFIFO was full" interrupt. +#define SSP0ICR_RTIC (1 << 1) // Writing a 1 to this bit clears the Rx FIFO was not empty and has not been read for a timeout period interrupt. The timeout period is the same for master and slave modes and is determined by the SSP bit rate: 32 bits at PCLK / (CPSDVSR [SCR+1]). + +/* I2C0CONSET - address 0x4000 0000 */ +#define I2C0CONSET_AA (1 << 2) // Assert acknowledge flag. +#define I2C0CONSET_SI (1 << 3) // I2C interrupt flag. +#define I2C0CONSET_STO (1 << 4) // STOP flag. +#define I2C0CONSET_STA (1 << 5) // START flag. +#define I2C0CONSET_I2EN (1 << 6) // I2C interface enable. Reserved. The value read from a reserved bit is not defined. + +/* I2C0STAT - 0x4000 0004 */ +#define I2C0STAT_STATUS_MASK 0x00F8 // These bits give the actual status information about the I2 C interface. Reserved. The value read from a reserved bit is not defined. +#define I2C0STAT_STATUS_SHIFT 3 + +/* I2C0DAT - 0x4000 0008 */ +#define I2C0DAT_DATA_MASK 0x00FF // This register holds data values that have been received or are to 0 be transmitted. Reserved. The value read from a reserved bit is not defined. +#define I2C0DAT_DATA_SHIFT 0 + +/* I2C0ADR0 - 0x4000 000C */ +#define I2C0ADR0_GC (1 << 0) // General Call enable bit. +#define I2C0ADR0_ADDRESS_MASK 0x00FE // The I2C device address for slave mode. Reserved. The value read from a reserved bit is not defined. +#define I2C0ADR0_ADDRESS_SHIFT 1 + +/* I2C0SCLH - address 0x4000 0010 */ +#define I2C0SCLH_SCLH_MASK 0xFFFF // Count for SCL HIGH time period selection. +#define I2C0SCLH_SCLH_SHIFT 0 + +/* I2C0SCLL - 0x4000 0014 */ +#define I2C0SCLL_SCLL_MASK 0xFFFF // Count for SCL low time period selection. +#define I2C0SCLL_SCLL_SHIFT 0 + +/* I2C0CONCLR - 0x4000 0018 */ +#define I2C0CONCLR_AAC (1 << 2) // Assert acknowledge Clear bit. +#define I2C0CONCLR_SIC (1 << 3) // I2C interrupt Clear bit. +#define I2C0CONCLR_STAC (1 << 5) // START flag Clear bit. +#define I2C0CONCLR_I2ENC (1 << 6) // I2C interface Disable bit. Reserved. The value read from a reserved bit is not defined. + +/* I2C0MMCTRL - 0x4000 001C */ +#define I2C0MMCTRL_MM_ENA (1 << 0) // Monitor mode enable. +#define I2C0MMCTRL_ENA_SCL (1 << 1) // SCL output enable. + +/* I2C0DATA_BUFFER - 0x4000 002C */ +#define I2C0DATA_BUFFER_DATA_MASK 0x00FF // This register holds contents of the 8 MSBs of the DAT shift register. Reserved. The value read from a reserved bit is not defined. +#define I2C0DATA_BUFFER_DATA_SHIFT 0 + +/* CANCNTL, address 0x4005 0000 */ +#define CANCNTL_INIT (1 << 0) // Initialization +#define CANCNTL_IE (1 << 1) // Module interrupt enable +#define CANCNTL_SIE (1 << 2) // Status change interrupt enable +#define CANCNTL_EIE (1 << 3) // Error interrupt enable +#define CANCNTL_DAR (1 << 5) // Disable automatic retransmission +#define CANCNTL_CCE (1 << 6) // Configuration change enable +#define CANCNTL_TEST (1 << 7) // Test mode enable + +/* CANSTAT, address 0x4005 0004 */ +#define CANSTAT_LEC_MASK 0x0007 // Last error code Type of the last error to occur on the CAN bus.The LEC field holds a code which indicates the type of the last error to occur on the CAN bus. This field will be cleared to `0' when a message has been transferred (reception or transmission) without error. The unused code `111' may be written by the CPU to check for updates. +#define CANSTAT_LEC_SHIFT 0 +#define CANSTAT_TXOK (1 << 3) // Transmitted a message successfully This bit must be reset by the CPU. It is never reset by the CAN controller. +#define CANSTAT_RXOK (1 << 4) // Received a message successfully This bit must be reset by the CPU. It is never reset by the CAN controller. +#define CANSTAT_EPASS (1 << 5) // Error passive +#define CANSTAT_EWARN (1 << 6) // Warning status +#define CANSTAT_BOFF (1 << 7) // Busoff status + +/* CANEC, address 0x4005 0008 */ +#define CANEC_TEC_MASK 0x00FF // Transmit error counter Current value of the transmit error counter (maximum value 255) +#define CANEC_TEC_SHIFT 0 +#define CANEC_REC_MASK 0x7F00 // Receive error counter Current value of the receive error counter (maximum value 127). +#define CANEC_REC_SHIFT 8 +#define CANEC_RP (1 << 15) // Receive error passive + +/* CANBT, address 0x4005 000C */ +#define CANBT_BRP_MASK 0x003F // Baud rate prescaler The value by which the oscillator frequency is divided for generating the bit time quanta. The bit time is built up from a multiple of this quanta. Valid values for the Baud Rate Prescaler are 0 to 63.[1] +#define CANBT_BRP_SHIFT 0 +#define CANBT_SJW_MASK 0x00C0 // (Re)synchronization jump width Valid programmed values are 0 to 3.[1] +#define CANBT_SJW_SHIFT 6 +#define CANBT_TSEG1_MASK 0x0F00 // Time segment before the sample point Valid values are 1 to 15.[1] +#define CANBT_TSEG1_SHIFT 8 +#define CANBT_TSEG2_MASK 0x7000 // Time segment after the sample point Valid values are 0 to 7.[1] +#define CANBT_TSEG2_SHIFT 12 + +/* CANINT, address 0x4005 0010 */ +#define CANINT_INTID_MASK 0xFFFF // 0x0000 = No interrupt is pending. 0 0x0001 - 0x0020 = Number of message object which caused the interrupt. 0x0021 - 0x7FFF = Unused 0x8000 = Status interrupt 0x8001 - 0xFFFF = Unused +#define CANINT_INTID_SHIFT 0 + +/* CANTEST, address 0x4005 0014 */ +#define CANTEST_BASIC (1 << 2) // Basic mode +#define CANTEST_SILENT (1 << 3) // Silent mode +#define CANTEST_LBACK (1 << 4) // Loop back mode +#define CANTEST_TX_MASK 0x0060 // Control of CAN_TXD pins +#define CANTEST_TX_SHIFT 5 +#define CANTEST_RX (1 << 7) // Monitors the actual value of the CAN_RXD pin. + +/* CANBRPE, address 0x4005 0018 */ +#define CANBRPE_BRPE_MASK 0x000F // Baud rate prescaler extension By programming BRPE the Baud Rate Prescaler can be extended to values up to 1023. Hardware interprets the value as the value of BRPE (MSBs) and BRP (LSBs) plus one. Allowed values are 0 to 15. +#define CANBRPE_BRPE_SHIFT 0 + +/* CANIF1_CMDREQ, address 0x4005 0020 and CANIF2_CMDREQ, address 0x4005 0080 */ +#define CANIFn_CMDREQ_MN_MASK 0x003F // Message number 0x01 - 0x20 = Valid message numbers. The message object in the message RAM is selected for data transfer. 0x00 = Not a valid message number. This value is interpreted as 0x20.[1] 0x21 - 0x3F = Not a valid message number. This value is interpreted as 0x01 - 0x1F.[1] +#define CANIFn_CMDREQ_MN_SHIFT 0 +#define CANIFn_CMDREQ_BUSY (1 << 15) // BUSY flag + +/* CANIF1_CMDMSK, address 0x4005 0024 and CANIF2_CMDMSK, address 0x4005 0084 */ +#define CANIFn_CMDMSK_DATA_B (1 << 0) // Access data bytes 4-7 +#define CANIFn_CMDMSK_DATA_A (1 << 1) // Access data bytes 0-3 +#define CANIFn_CMDMSK_TXRQST (1 << 2) // Access transmission request bit (Write direction) +#define CANIFn_CMDMSK_NEWDAT (1 << 2) // Access new data bit (Read direction) +#define CANIFn_CMDMSK_CLRINTPND (1 << 3) // This bit is ignored in the write direction. +#define CANIFn_CMDMSK_CTRL (1 << 4) // Access control bits +#define CANIFn_CMDMSK_ARB (1 << 5) // Access arbitration bits +#define CANIFn_CMDMSK_MASK (1 << 6) // Access mask bits +#define CANIFn_CMDMSK_WR (1 << 7) // Write transfer Transfer data from the selected message buffer registers to the message object addressed by the command request register CANIFn_CMDREQ. +#define CANIFn_CMDMSK_RD (0 << 7) // Read transfer Read data from the selected message buffer registers to the message object addressed by the command request register CANIFn_CMDREQ. + +/* CANIF1_MSK1, address 0x4005 0028 and CANIF2_MASK1, address 0x4005 0088 */ +#define CANIFn_MSK1_MSK_MASK 0xFFFF // Identifier mask +#define CANIFn_MSK1_MSK_SHIFT 0 + +/* CANIF1_MSK2, address 0x4005 002C and CANIF2_MASK2, address 0x4005 008C */ +#define CANIFn_MSK2_MSK_MASK 0x1FFF // Identifier mask +#define CANIFn_MSK2_MSK_SHIFT 0 +#define CANIFn_MSK2_MDIR (1 << 14) // Mask message direction +#define CANIFn_MSK2_MXTD (1 << 15) // Mask extend identifier + +/* CANIF1_ARB1, address 0x4005 0030 and CANIF2_ARB1, address 0x4005 0090 */ +#define CANIFn_ARB1_ID_MASK 0xFFFF // Message identifier 29-bit identifier (extended frame) 11-bit identifier (standard frame) +#define CANIFn_ARB1_ID_SHIFT 0 + +/* CANIF1_ARB2, address 0x4005 0034 and CANIF2_ARB2, address 0x4005 0094 */ +#define CANIFn_ARB2_ID_MASK 0x1FFF // Message identifier 29-bit identifier (extended frame) 11-bit identifier (standard frame) +#define CANIFn_ARB2_ID_SHIFT 0 +#define CANIFn_ARB2_DIR (1 << 13) // Message direction +#define CANIFn_ARB2_XTD (1 << 14) // Extend identifier +#define CANIFn_ARB2_MSGVAL (1 << 15) // Message valid Remark: The CPU must reset the MSGVAL bit of all unused Messages Objects during the initialization before it resets bit INIT in the CAN Control Register. This bit must also be reset before the identifier ID28:0, the control bits XTD, DIR, or the Data Length Code DLC3:0 are modified, or if the Messages Object is no longer required. + +/* CANIF1_MCTRL, address 0x4005 0038 and CANIF2_MCTRL, address 0x4005 0098 */ +#define CANIFn_MCTRL_DLC_MASK 0x000F // Data length code Remark: The Data Length Code of a Message Object must be defined the same as in all the corresponding objects with the same identifier at other nodes. When the Message Handler stores a data frame, it will write the DLC to the value given by the received message. 0000 - 1000 = Data frame has 0 - 8 data bytes. 1001 - 1111 = Data frame has 8 data bytes. +#define CANIFn_MCTRL_DLC_SHIFT 0 +#define CANIFn_MCTRL_EOB (1 << 7) // End of buffer +#define CANIFn_MCTRL_TXRQST (1 << 8) // Transmit request +#define CANIFn_MCTRL_RMTEN (1 << 9) // Remote enable +#define CANIFn_MCTRL_RXIE (1 << 10) // Receive interrupt enable +#define CANIFn_MCTRL_TXIE (1 << 11) // Transmit interrupt enable +#define CANIFn_MCTRL_UMASK (1 << 12) // Use acceptance mask Remark: If UMASK is set to 1, the message object's mask bits have to be programmed during initialization of the message object before MAGVAL is set to 1. +#define CANIFn_MCTRL_INTPND (1 << 13) // Interrupt pending +#define CANIFn_MCTRL_MSGLST (1 << 14) // Message lost (only valid for message objects in the direction receive). +#define CANIFn_MCTRL_NEWDAT (1 << 15) // New data + +/* CANIF1_DA1, address 0x4005 003C and CANIF2_DA1, address 0x4005 009C */ +#define CANIFn_DA1_DATA0_MASK 0x00FF // Data byte 0 +#define CANIFn_DA1_DATA0_SHIFT 0 +#define CANIFn_DA1_DATA1_MASK 0xFF00 // Data byte 1 +#define CANIFn_DA1_DATA1_SHIFT 8 + +/* CANIF1_DA2, address 0x4005 0040 and CANIF2_DA2, address 0x4005 00A0 */ +#define CANIFn_DA2_DATA2_MASK 0x00FF // Data byte 2 +#define CANIFn_DA2_DATA2_SHIFT 0 +#define CANIFn_DA2_DATA3_MASK 0xFF00 // Data byte 3 +#define CANIFn_DA2_DATA3_SHIFT 8 + +/* CANIF1_DB1, address 0x4005 0044 and CANIF2_DB1, address 0x4005 00A4 */ +#define CANIFn_DB1_DATA4_MASK 0x00FF // Data byte 4 +#define CANIFn_DB1_DATA4_SHIFT 0 +#define CANIFn_DB1_DATA5_MASK 0xFF00 // Data byte 5 +#define CANIFn_DB1_DATA5_SHIFT 8 + +/* CANIF1_DB2, address 0x4005 0048 and CANIF2_DB2, address 0x4005 00A8 */ +#define CANIFn_DB2_DATA6_MASK 0x00FF // Data byte 6 +#define CANIFn_DB2_DATA6_SHIFT 0 +#define CANIFn_DB2_DATA7_MASK 0xFF00 // Data byte 7 +#define CANIFn_DB2_DATA7_SHIFT 8 + +/* CANTXREQ1, address 0x4005 0100 */ +#define CANTXREQ1_TXRQST_MASK 0xFFFF // Transmission request bit of message objects 16 to 1. 0 = This message object is not waiting for transmission. 1 = The transmission of this message object is requested and not yet done. Reserved +#define CANTXREQ1_TXRQST_SHIFT 0 + +/* CANTXREQ2, address 0x4005 0104 */ +#define CANTXREQ2_TXRQST_MASK 0xFFFF // Transmission request bit of message objects 32 to 17. 0 = This message object is not waiting for transmission. 1 = The transmission of this message object is requested and not yet done. Reserved +#define CANTXREQ2_TXRQST_SHIFT 0 + +/* CANND1, address 0x4005 0120 */ +#define CANND1_NEWDAT_MASK 0xFFFF // New data bits of message objects 16 to 1. 0 = No new data has been written into the data portion of this Message Object by the Message Handler since last time this flag was cleared by the CPU. 1 = The Message Handler or the CPU has written new data into the data portion of this Message Object. +#define CANND1_NEWDAT_SHIFT 0 + +/* CANND2, address 0x4005 0124 */ +#define CANND2_NEWDAT_MASK 0xFFFF // New data bits of message objects 32 to 17. 0 = No new data has been written into the data portion of this Message Object by the Message Handler since last time this flag was cleared by the CPU. 1 = The Message Handler or the CPU has written new data into the data portion of this Message Object. +#define CANND2_NEWDAT_SHIFT 0 + +/* CANIR1, address 0x4005 0140 */ +#define CANIR1_INTPND_INTERRUPT_MASK 0xFFFF // pending bits of message objects 16 to 1. essage object is ignored by the message essage object is the source of an interrupt. Reserved +#define CANIR1_INTPND_INTERRUPT_SHIFT 0 + +/* CANIR2, addresses 0x4005 0144 */ +#define CANIR2_INTPND_MASK 0xFFFF // Interrupt pending bits of message objects 32 to 17. 0 = This message object is ignored by the message handler. 1 = This message object is the source of an interrupt. Reserved +#define CANIR2_INTPND_SHIFT 0 + +/* CANMSGV1, addresses 0x4005 0160 */ +#define CANMSGV1_MSGVAL_MASK 0xFFFF // Message valid bits of message objects 16 to 1. 0 = This message object is ignored by the message handler. 1 = This message object is configured and should be considered by the message handler. Reserved +#define CANMSGV1_MSGVAL_SHIFT 0 + +/* CANMSGV2, address 0x4005 0164 */ +#define CANMSGV2_MSGVAL_MASK 0xFFFF // Message valid bits of message objects 32 to 17. 0 = This message object is ignored by the message handler. 1 = This message object is configured and should be considered by the message handler. Reserved +#define CANMSGV2_MSGVAL_SHIFT 0 + +/* CANCLKDIV, address 0x4005 0180 */ +#define CANCLKDIV_CLKDIVVAL_MASK 0x000F // Clock divider value. CAN_CLK = PCLK/(CLKDIVVAL +1) 0000: CAN_CLK = PCLK divided by 1. 0001: CAN_CLK = PCLK divided by 2. 0010: CAN_CLK = PCLK divided by 3 0011: CAN_CLK = PCLK divided by 4. ... 1111: CAN_CLK = PCLK divided by 16. +#define CANCLKDIV_CLKDIVVAL_SHIFT 0 + +/* TMR16B0IR - address 0x4000 C000 and TMR16B1IR - address 0x4001 0000 */ +#define TMR16B0IR_MR0 (1 << 0) // Interrupt flag for match channel 0. +#define TMR16B0IR_MR1 (1 << 1) // Interrupt flag for match channel 1. +#define TMR16B0IR_MR2 (1 << 2) // Interrupt flag for match channel 2. +#define TMR16B0IR_MR3 (1 << 3) // Interrupt flag for match channel 3. +#define TMR16B0IR_CR0 (1 << 4) // Interrupt flag for capture channel 0 event. + +/* TMR16B0TCR - address 0x4000 C004 and TMR16B1TCR - address 0x4001 0004 */ +#define TMR16B0TCR_CEN (1 << 0) // Counter Enable. When one, the Timer Counter and Prescale Counter are enabled for counting. When zero, the counters are disabled. +#define TMR16B0TCR_CRST (1 << 1) // Counter Reset. When one, the Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR16B0TC, address 0x4000 C008 and TMR16B1TC 0x4001 0008 */ +#define TMR16B0TC_TC_MASK 0xFFFF // Timer counter value. +#define TMR16B0TC_TC_SHIFT 0 + +/* TMR16B0PR, address 0x4000 C00C and TMR16B1PR 0x4001 000C */ +#define TMR16B0PR_PR_MASK 0xFFFF // Prescale max value. +#define TMR16B0PR_PR_SHIFT 0 + +/* TMR16B0PC, address 0x4001 C010 and TMR16B1PC 0x4000 0010 */ +#define TMR16B0PC_PC_MASK 0xFFFF // Prescale counter value. +#define TMR16B0PC_PC_SHIFT 0 + +/* TMR16B0MCR - address 0x4000 C014 and TMR16B1MCR - address 0x4001 0014 */ +#define TMR16B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR16B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR16B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR16B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR16B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR16B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR16B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR16B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR16B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR16B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR16B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR16B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR16B0MR0 to 3, addresses 0x4000 C018 to 24 and TMR16B1MR0 to 3, addresses 0x4001 0018 to 24 */ +#define TMR16B0MR0_to_3_MATCH_MASK 0xFFFF // Timer counter match value. +#define TMR16B0MR0_to_3_MATCH_SHIFT 0 + +/* TMR16B0CCR - address 0x4000 C028 and TMR16B1CCR - address 0x4001 0028 */ +#define TMR16B0CCR_CAP0RE (1 << 0) // Capture on CT16Bn_CAP0 rising edge: a sequence of 0 then 1 on CT16Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0FE (1 << 1) // Capture on CT16Bn_CAP0 falling edge: a sequence of 1 then 0 on CT16Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0I (1 << 2) // Interrupt on CT16Bn_CAP0 event: a CR0 load due to a CT16Bn_CAP0 event will generate an interrupt. + +/* TMR16B0CR0, address 0x4000 C02C and TMR16B1CR0, address 0x4001 002C */ +#define TMR16B0CR0_CAP_MASK 0xFFFF // Timer counter capture value. +#define TMR16B0CR0_CAP_SHIFT 0 + +/* TMR16B0EMR - address 0x4000 C03C and TMR16B1EMR - address 0x4001 003C */ +#define TMR16B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT16B0_MAT0/CT16B1_MAT0, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT16B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT16B0_MAT1/CT16B1_MAT1, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT16B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output match channel 2, whether or not 0 this output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. Note that on counter/timer 0 this match channel is not pinned out. This bit is driven to the CT16B1_MAT2 pin if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output of match channel 3. When a match 0 occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. There is no output pin available for this channel on either of the 16-bit timers. +#define TMR16B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR16B0EMR_EMC0_SHIFT 4 +#define TMR16B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR16B0EMR_EMC1_SHIFT 6 +#define TMR16B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR16B0EMR_EMC2_SHIFT 8 +#define TMR16B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR16B0EMR_EMC3_SHIFT 10 + +/* TMR16B0CTCR - address 0x4000 C070 and TMR16B1CTCR - address 0x4001 0070 */ +#define TMR16B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK 00 edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). +#define TMR16B0CTCR_CTM_SHIFT 0 + +/* TMR16B0PWMC - address 0x4000 C074 and TMR16B1PWMC- address 0x4001 0074 */ +#define TMR16B0PWMC_PWMEN0 (1 << 0) // PWM channel0 enable +#define TMR16B0PWMC_PWMEN1 (1 << 1) // PWM channel1 enable +#define TMR16B0PWMC_PWMEN2 (1 << 2) // PWM channel2 enable +#define TMR16B0PWMC_PWMEN3 (1 << 3) // PWM channel3 enable Note: It is recommended to use match channel 3 to set the PWM cycle because it is not pinned out. + +/* TMR16B0IR - address 0x4000 C000 and TMR16B1IR - address 0x4001 0000 */ +#define TMR16B0IR_MR0INT (1 << 0) // Interrupt flag for match channel 0. +#define TMR16B0IR_MR1INT (1 << 1) // Interrupt flag for match channel 1. +#define TMR16B0IR_MR2INT (1 << 2) // Interrupt flag for match channel 2. +#define TMR16B0IR_MR3INT (1 << 3) // Interrupt flag for match channel 3. +#define TMR16B0IR_CR0INT (1 << 4) // Interrupt flag for capture channel 0 event. +#define TMR16B0IR_CR1INT (1 << 5) // Interrupt flag for capture channel 1 event. + +/* TMR16B0TCR - address 0x4000 C004 and TMR16B1TCR - address 0x4001 0004 */ +#define TMR16B0TCR_CEN (1 << 0) // Counter Enable. When one, the Timer Counter and Prescale Counter are enabled for counting. When zero, the counters are disabled. +#define TMR16B0TCR_CRST (1 << 1) // Counter Reset. When one, the Timer Counter and the Prescale Counter are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR16B0TC, address 0x4000 C008 and TMR16B1TC 0x4001 0008 */ +#define TMR16B0TC_TC_MASK 0xFFFF // Timer counter value. +#define TMR16B0TC_TC_SHIFT 0 + +/* TMR16B0PR, address 0x4000 C00C and TMR16B1PR 0x4001 000C */ +#define TMR16B0PR_PR_MASK 0xFFFF // Prescale max value. +#define TMR16B0PR_PR_SHIFT 0 + +/* TMR16B0PC, address 0x4001 C010 and TMR16B1PC 0x4000 0010 */ +#define TMR16B0PC_PC_MASK 0xFFFF // Prescale counter value. +#define TMR16B0PC_PC_SHIFT 0 + +/* TMR16B0MCR - address 0x4000 C014 and TMR16B1MCR - address 0x4001 0014 */ +#define TMR16B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR16B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR16B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR16B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR16B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR16B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR16B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR16B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR16B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR16B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR16B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR16B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR16B0MR0 to 3, addresses 0x4000 C018 to 24 and TMR16B1MR0 to 3, addresses 0x4001 0018 to 24 */ +#define TMR16B0MR0_to_3_MATCH_MASK 0xFFFF // Timer counter match value. +#define TMR16B0MR0_to_3_MATCH_SHIFT 0 + +/* TMR16B0CCR - address 0x4000 C028 and TMR16B1CCR - address 0x4001 0028 */ +#define TMR16B0CCR_CAP0RE (1 << 0) // Capture on CT16Bn_CAP0 rising edge: a sequence of 0 then 1 on CT16Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0FE (1 << 1) // Capture on CT16Bn_CAP0 falling edge: a sequence of 1 then 0 on CT16Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP0I (1 << 2) // Interrupt on CT16Bn_CAP0 event: a CR0 load due to a CT16Bn_CAP0 event will generate an interrupt. +#define TMR16B0CCR_CAP1RE (1 << 3) // Capture on CT16Bn_CAP1 rising edge: a sequence of 0 then 1 on CT16Bn_CAP1 will cause CR1 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP1FE (1 << 4) // Capture on CT16Bn_CAP1 falling edge: a sequence of 1 then 0 on CT16Bn_CAP1 will 0 cause CR1 to be loaded with the contents of TC. +#define TMR16B0CCR_CAP1I (1 << 5) // Interrupt on CT16Bn_CAP1 event: a CR1 load due to a CT16Bn_CAP1 event will generate an interrupt. + +/* TMR16B0EMR - address 0x4000 C03C and TMR16B1EMR - address 0x4001 003C */ +#define TMR16B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT16B0_MAT0/CT16B1_MAT0, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT16B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT16B0_MAT1/CT16B1_MAT1, 0 whether or not this output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT16B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output match channel 2, whether or not 0 this output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. Note that on counter/timer 0 this match channel is not pinned out. This bit is driven to the CT16B1_MAT2 pin if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR16B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output of match channel 3. When a match 0 occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. There is no output pin available for this channel on either of the 16-bit timers. +#define TMR16B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR16B0EMR_EMC0_SHIFT 4 +#define TMR16B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR16B0EMR_EMC1_SHIFT 6 +#define TMR16B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR16B0EMR_EMC2_SHIFT 8 +#define TMR16B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR16B0EMR_EMC3_SHIFT 10 + +/* TMR16B0CTCR - address 0x4000 C070 and TMR16B1CTCR - address 0x4001 0070 */ +#define TMR16B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK 00 edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). +#define TMR16B0CTCR_CTM_SHIFT 0 +#define TMR16B0CTCR_SELCC_MASK 0x00E0 // When bit 4 is one, these bits select which capture input edge 0 will cause the timer and prescaler to be cleared. These bits have no effect when bit 4 is zero. +#define TMR16B0CTCR_SELCC_SHIFT 5 + +/* TMR16B0PWMC - address 0x4000 C074 and TMR16B1PWMC- address 0x4001 0074 */ +#define TMR16B0PWMC_PWMEN0 (1 << 0) // PWM channel0 enable +#define TMR16B0PWMC_PWMEN1 (1 << 1) // PWM channel1 enable +#define TMR16B0PWMC_PWMEN2 (1 << 2) // PWM channel2 enable +#define TMR16B0PWMC_PWMEN3 (1 << 3) // PWM channel3 enable Note: It is recommended to use match channel 3 to set the PWM cycle because it is not pinned out. + +/* TMR32B0IR - address 0x4001 4000 and TMR32B1IR - address 0x4001 8000 */ +#define TMR32B0IR_MR0_INTERRUPT (1 << 0) // Interrupt flag for match channel 0. +#define TMR32B0IR_MR1_INTERRUPT (1 << 1) // Interrupt flag for match channel 1. +#define TMR32B0IR_MR2_INTERRUPT (1 << 2) // Interrupt flag for match channel 2. +#define TMR32B0IR_MR3_INTERRUPT (1 << 3) // Interrupt flag for match channel 3. +#define TMR32B0IR_CR0_INTERRUPT (1 << 4) // Interrupt flag for capture channel 0 event. + +/* TMR32B0TCR - address 0x4001 4004 and TMR32B1TCR - address 0x4001 8004 */ +#define TMR32B0TCR_CEN (1 << 0) // When one, the Timer Counter and Prescale Counter are 0 enabled for counting. When zero, the counters are disabled. +#define TMR32B0TCR_CRST (1 << 1) // When one, the Timer Counter and the Prescale Counter 0 are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR32B0TC, address 0x4001 4008 and TMR32B1TC 0x4001 8008 */ +#define TMR32B0TC_TC_MASK 0xFFFFFFFF // Timer counter value. +#define TMR32B0TC_TC_SHIFT 0 + +/* TMR32B0PR, address 0x4001 400C and TMR32B1PR 0x4001 800C */ +#define TMR32B0PR_PR_MASK 0xFFFFFFFF // Prescale value. +#define TMR32B0PR_PR_SHIFT 0 + +/* TMR32B0PC, address 0x4001 4010 and TMR32B1PC 0x4001 8010 */ +#define TMR32B0PC_PC_MASK 0xFFFFFFFF // Prescale counter value. +#define TMR32B0PC_PC_SHIFT 0 + +/* TMR32B0MCR - address 0x4001 4014 and TMR32B1MCR - address 0x4001 8014 */ +#define TMR32B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR32B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR32B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR32B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR32B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR32B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR32B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR32B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR32B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR32B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR32B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR32B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR32B0MR0 to 3, addresses 0x4001 4018 to 24 and TMR32B1MR0 to 3, addresses 0x4001 8018 to 24 */ +#define TMR32B0MRn_MATCH_MASK 0xFFFFFFFF // Timer counter match value. +#define TMR32B0MRn_MATCH_SHIFT 0 + +/* TMR32B0CCR - address 0x4001 4028 and TMR32B1CCR - address 0x4001 8028 */ +#define TMR32B0CCR_CAP0RE (1 << 0) // Capture on CT32Bn_CAP0 rising edge: a sequence of 0 then 1 on CT32Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0FE (1 << 1) // Capture on CT32Bn_CAP0 falling edge: a sequence of 1 then 0 on CT32Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0I (1 << 2) // Interrupt on CT32Bn_CAP0 event: a CR0 load due to a CT32Bn_CAP0 event will generate an interrupt. + +/* TMR32B0CR0, addresses 0x4001 402C and TMR32B1CR0, addresses 0x4001 802C */ +#define TMR32B0CR0_CAP_MASK 0xFFFFFFFF // Timer counter capture value. +#define TMR32B0CR0_CAP_SHIFT 0 + +/* TMR32B0EMR - address 0x4001 403C and TMR32B1EMR - address0x4001 803C */ +#define TMR32B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT32Bn_MAT0, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT32B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT32Bn_MAT1, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT32B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output CT32Bn_MAT2, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. This bit is driven to the CT32B0_MAT2/CT16B1_MAT2 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output CT32Bn_MAT3, whether or not this output is connected to its pin. When a match occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. This bit is driven to the CT32B0_MAT3/CT16B1_MAT3 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR32B0EMR_EMC0_SHIFT 4 +#define TMR32B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR32B0EMR_EMC1_SHIFT 6 +#define TMR32B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR32B0EMR_EMC2_SHIFT 8 +#define TMR32B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR32B0EMR_EMC3_SHIFT 10 + +/* TMR32B0CTCR - address 0x4001 4070 and TMR32B1TCR - address 0x4001 8070 */ +#define TMR32B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). Timer Mode: every rising PCLK edge +#define TMR32B0CTCR_CTM_SHIFT 0 +#define TMR32B0CTCR_CIS_MASK 0x000C // Count Input Select. When bits 1:0 in this register are not 00, these bits select which CAP pin is sampled for clocking: +#define TMR32B0CTCR_CIS_SHIFT 2 + +/* TMR32B0PWMC - 0x4001 4074 and TMR32B1PWMC - 0x4001 8074 */ +#define TMR32B0PWMC_PWMEN0 (1 << 0) // PWM channel 0 enable +#define TMR32B0PWMC_PWMEN1 (1 << 1) // PWM channel 1 enable +#define TMR32B0PWMC_PWMEN2 (1 << 2) // PWM channel 2 enable +#define TMR32B0PWMC_PWMEN3 (1 << 3) // PWM channel 3 enable Note: It is recommended to use match channel 3 to set the PWM cycle. + +/* TMR32B0IR - address 0x4001 4000 and TMR32B1IR - address 0x4001 8000 */ +#define TMR32B0IR_MR0INT (1 << 0) // Interrupt flag for match channel 0. +#define TMR32B0IR_MR1INT (1 << 1) // Interrupt flag for match channel 1. +#define TMR32B0IR_MR2INT (1 << 2) // Interrupt flag for match channel 2. +#define TMR32B0IR_MR3INT (1 << 3) // Interrupt flag for match channel 3. +#define TMR32B0IR_CR0INT (1 << 4) // Interrupt flag for capture channel 0 event. +#define TMR32B0IR_CR1INT (1 << 5) // Interrupt flag for capture channel 1 event. + +/* TMR32B0TCR - address 0x4001 4004 and TMR32B1TCR - address 0x4001 8004 */ +#define TMR32B0TCR_CEN (1 << 0) // When one, the Timer Counter and Prescale Counter are 0 enabled for counting. When zero, the counters are disabled. +#define TMR32B0TCR_CRST (1 << 1) // When one, the Timer Counter and the Prescale Counter 0 are synchronously reset on the next positive edge of PCLK. The counters remain reset until TCR[1] is returned to zero. + +/* TMR32B0TC, address 0x4001 4008 and TMR32B1TC 0x4001 8008 */ +#define TMR32B0TC_TC_MASK 0xFFFFFFFF // Timer counter value. +#define TMR32B0TC_TC_SHIFT 0 + +/* TMR32B0PR, address 0x4001 400C and TMR32B1PR 0x4001 800C */ +#define TMR32B0PR_PR_MASK 0xFFFFFFFF // Prescale value. +#define TMR32B0PR_PR_SHIFT 0 + +/* TMR32B0PC, address 0x4001 4010 and TMR32B1PC 0x4001 8010 */ +#define TMR32B0PC_PC_MASK 0xFFFFFFFF // Prescale counter value. +#define TMR32B0PC_PC_SHIFT 0 + +/* TMR32B0MCR - address 0x4001 4014 and TMR32B1MCR - address 0x4001 8014 */ +#define TMR32B0MCR_MR0I (1 << 0) // Interrupt on MR0: an interrupt is generated when MR0 matches the value in the TC. +#define TMR32B0MCR_MR0R (1 << 1) // Reset on MR0: the TC will be reset if MR0 matches it. +#define TMR32B0MCR_MR0S (1 << 2) // Stop on MR0: the TC and PC will be stopped and TCR[0] will be set to 0 if MR0 matches 0 the TC. +#define TMR32B0MCR_MR1I (1 << 3) // Interrupt on MR1: an interrupt is generated when MR1 matches the value in the TC. +#define TMR32B0MCR_MR1R (1 << 4) // Reset on MR1: the TC will be reset if MR1 matches it. +#define TMR32B0MCR_MR1S (1 << 5) // Stop on MR1: the TC and PC will be stopped and TCR[0] will be set to 0 if MR1 matches 0 the TC. +#define TMR32B0MCR_MR2I (1 << 6) // Interrupt on MR2: an interrupt is generated when MR2 matches the value in the TC. +#define TMR32B0MCR_MR2R (1 << 7) // Reset on MR2: the TC will be reset if MR2 matches it. +#define TMR32B0MCR_MR2S (1 << 8) // Stop on MR2: the TC and PC will be stopped and TCR[0] will be set to 0 if MR2 matches 0 the TC. +#define TMR32B0MCR_MR3I (1 << 9) // Interrupt on MR3: an interrupt is generated when MR3 matches the value in the TC. +#define TMR32B0MCR_MR3R (1 << 10) // Reset on MR3: the TC will be reset if MR3 matches it. +#define TMR32B0MCR_MR3S (1 << 11) // Stop on MR3: the TC and PC will be stopped and TCR[0] will be set to 0 if MR3 matches 0 the TC. + +/* TMR32B0MR0 to 3, addresses 0x4001 4018 to 24 and TMR32B1MR0 to 3, addresses 0x4001 8018 to 24 */ +#define TMR32B0MRn_MATCH_MASK 0xFFFFFFFF // Timer counter match value. +#define TMR32B0MRn_MATCH_SHIFT 0 + +/* TMR32B0CCR - address 0x4001 4028 and TMR32B1CCR - address 0x4001 8028 */ +#define TMR32B0CCR_CAP0RE (1 << 0) // Capture on CT32Bn_CAP0 rising edge: a sequence of 0 then 1 on CT32Bn_CAP0 will cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0FE (1 << 1) // Capture on CT32Bn_CAP0 falling edge: a sequence of 1 then 0 on CT32Bn_CAP0 will 0 cause CR0 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP0I (1 << 2) // Interrupt on CT32Bn_CAP0 event: a CR0 load due to a CT32Bn_CAP0 event will generate an interrupt. +#define TMR32B0CCR_CAP1RE (1 << 3) // Capture on CT32Bn_CAP1 rising edge: a sequence of 0 then 1 on CT32Bn_CAP1 will cause CR1 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP1FE (1 << 4) // Capture on CT32Bn_CAP1 falling edge: a sequence of 1 then 0 on CT32Bn_CAP1 will 0 cause CR1 to be loaded with the contents of TC. +#define TMR32B0CCR_CAP1I (1 << 5) // Interrupt on CT32Bn_CAP1 event: a CR1 load due to a CT32Bn_CAP1 event will generate an interrupt. + +/* TMR32B0EMR - address 0x4001 403C and TMR32B1EMR - address0x4001 803C */ +#define TMR32B0EMR_EM0 (1 << 0) // External Match 0. This bit reflects the state of output CT32Bn_MAT0, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR0, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[5:4] control the functionality of this output. This bit is driven to the CT32B0_MAT0/CT16B1_MAT0 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM1 (1 << 1) // External Match 1. This bit reflects the state of output CT32Bn_MAT1, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR1, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[7:6] control the functionality of this output. This bit is driven to the CT32B0_MAT1/CT16B1_MAT1 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM2 (1 << 2) // External Match 2. This bit reflects the state of output CT32Bn_MAT2, whether or not this 0 output is connected to its pin. When a match occurs between the TC and MR2, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[9:8] control the functionality of this output. This bit is driven to the CT32B0_MAT2/CT16B1_MAT2 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EM3 (1 << 3) // External Match 3. This bit reflects the state of output CT32Bn_MAT3, whether or not this output is connected to its pin. When a match occurs between the TC and MR3, this bit can either toggle, go LOW, go HIGH, or do nothing. Bits EMR[11:10] control the functionality of this output. This bit is driven to the CT32B0_MAT3/CT16B1_MAT3 pins if the match function is selected in the IOCON registers (0 = LOW, 1 = HIGH). +#define TMR32B0EMR_EMC0_MASK 0x0030 // External Match Control 0. Determines the functionality of External Match 0. +#define TMR32B0EMR_EMC0_SHIFT 4 +#define TMR32B0EMR_EMC1_MASK 0x00C0 // External Match Control 1. Determines the functionality of External Match 1. +#define TMR32B0EMR_EMC1_SHIFT 6 +#define TMR32B0EMR_EMC2_MASK 0x0300 // External Match Control 2. Determines the functionality of External Match 2. +#define TMR32B0EMR_EMC2_SHIFT 8 +#define TMR32B0EMR_EMC3_MASK 0x0C00 // External Match Control 3. Determines the functionality of External Match 3. +#define TMR32B0EMR_EMC3_SHIFT 10 + +/* TMR32B0CTCR - address 0x4001 4070 and TMR32B1TCR - address 0x4001 8070 */ +#define TMR32B0CTCR_CTM_MASK 0x0003 // Counter/Timer Mode. This field selects which rising PCLK edges can increment Timer's Prescale Counter (PC), or clear PC and increment Timer Counter (TC). Timer Mode: every rising PCLK edge +#define TMR32B0CTCR_CTM_SHIFT 0 +#define TMR32B0CTCR_CIS_MASK 0x000C // Count Input Select. When bits 1:0 in this register are not 00, these bits select which CAP pin is sampled for clocking: +#define TMR32B0CTCR_CIS_SHIFT 2 +#define TMR32B0CTCR_ENCC (1 << 4) // Setting this bit to one enables clearing of the timer and the prescaler when the capture-edge event specified in bits 7:5 occurs. +#define TMR32B0CTCR_SELCC_MASK 0x00E0 // When bit 4 is one, these bits select which capture input edge 0 will cause the timer and prescaler to be cleared. These bits have no effect when bit 4 is zero. +#define TMR32B0CTCR_SELCC_SHIFT 5 + +/* TMR32B0PWMC - 0x4001 4074 and TMR32B1PWMC - 0x4001 8074 */ +#define TMR32B0PWMC_PWMEN0 (1 << 0) // PWM channel 0 enable +#define TMR32B0PWMC_PWMEN1 (1 << 1) // PWM channel 1 enable +#define TMR32B0PWMC_PWMEN2 (1 << 2) // PWM channel 2 enable +#define TMR32B0PWMC_PWMEN3 (1 << 3) // PWM channel 3 enable Note: It is recommended to use match channel 3 to set the PWM cycle. + +/* WDMOD - 0x4000 4000 */ +#define WDMOD_WDEN (1 << 0) // Watchdog enable bit. This bit is Set Only. Remark: Setting this bit to one also locks the watchdog clock source. Once the watchdog timer is enabled, the watchdog timer clock source cannot be changed. If the watchdog timer is needed in Deep-sleep mode, the watchdog clock source must be changed to the watchdog oscillator before setting this bit to one. +#define WDMOD_WDRESET (1 << 1) // Watchdog reset enable bit. This bit is Set Only. +#define WDMOD_WDTOF (1 << 2) // Watchdog time-out flag. Set when the watchdog timer times out, by a feed error, or by events associated with WDPROTECT, cleared by software. Causes a chip reset if WDRESET = 1. +#define WDMOD_WDINT (1 << 3) // Watchdog interrupt flag. Set when the timer reaches the value in WDWARNINT. Cleared by software. +#define WDMOD_WDPROTECT (1 << 4) // Watchdog update mode. This bit is Set Only. + +/* WDTC - 0x4000 4004 */ +#define WDTC_COUNT_MASK 0xFFFFFF // Watchdog time-out interval. +#define WDTC_COUNT_SHIFT 0 + +/* WDFEED - 0x4000 4008 */ +#define WDFEED_FEED_MASK 0x00FF // Feed value should be 0xAA followed by 0x55. +#define WDFEED_FEED_SHIFT 0 + +/* WDTV - 0x4000 400C */ +#define WDTV_COUNT_MASK 0xFFFFFF // Counter timer value. +#define WDTV_COUNT_SHIFT 0 + +/* WDWARNINT - 0x4000 4014 */ +#define WDWARNINT_WARNINT_MASK 0x03FF // Watchdog warning interrupt compare value. +#define WDWARNINT_WARNINT_SHIFT 0 + +/* WDWINDOW - 0x4000 4018 */ +#define WDWINDOW_WINDOW_MASK 0xFFFFFF // Watchdog window value. +#define WDWINDOW_WINDOW_SHIFT 0 + +/* WDMOD - address 0x4000 4000 */ +#define WDMOD_WDEN (1 << 0) // WDEN Watchdog enable bit (Set Only). When 1, the watchdog timer is running. Remark: Setting this bit to one also locks the watchdog clock source. Once the watchdog timer is enabled, the watchdog timer clock source cannot be changed. If the watchdog timer is needed in Deep-sleep mode, the watchdog clock source must be changed to the watchdog oscillator before setting this bit to one. The clock source lock feature is not available on all parts, see Section 23.1). +#define WDMOD_WDRESET_WDRESET (1 << 1) // Watchdog reset enable bit (Set Only). When 1, og time-out will cause a chip reset. +#define WDMOD_WDTOF (1 << 2) // WDTOF Watchdog time-out flag. Set when the watchdog +#define WDMOD_WDINT (1 << 3) // WDINT Watchdog interrupt flag (Read Only, not clearable by software). + +/* WDTC - address 0x4000 4004 */ +#define WDTC_COUNT_MASK 0xFFFFFF // Watchdog time-out interval. +#define WDTC_COUNT_SHIFT 0 + +/* WDFEED - address 0x4000 4008 */ +#define WDFEED_FEED_MASK 0x00FF // Feed value should be 0xAA followed by 0x55. +#define WDFEED_FEED_SHIFT 0 + +/* WDTV - address 0x4000 000C */ +#define WDTV_COUNT_MASK 0xFFFFFF // Counter timer value. +#define WDTV_COUNT_SHIFT 0 + +/* SYST_CSR - 0xE000 E010 */ +#define SYST_CSR_ENABLE (1 << 0) // System Tick counter enable. When 1, the counter is enabled. When 0, the counter is disabled. +#define SYST_CSR_TICKINT (1 << 1) // System Tick interrupt enable. When 1, the System Tick interrupt 0 is enabled. When 0, the System Tick interrupt is disabled. When enabled, the interrupt is generated when the System Tick counter counts down to 0. +#define SYST_CSR_CLKSOURCE (1 << 2) // System Tick clock source selection. When 1, the system clock (CPU) clock is selected. When 0, the system clock/2 is selected as the reference clock. +#define SYST_CSR_COUNTFLAG (1 << 16) // Returns 1 if the SysTick timer counted to 0 since the last read of this register. Reserved, user software should not write ones to reserved bits. The value read from a reserved bit is not defined. + +/* SYST_RVR - 0xE000 E014 */ +#define SYST_RVR_RELOAD_MASK 0xFFFFFF // This is the value that is loaded into the System Tick counter when it 0 counts down to 0. +#define SYST_RVR_RELOAD_SHIFT 0 + +/* SYST_CVR - 0xE000 E018 */ +#define SYST_CVR_CURRENT_MASK 0xFFFFFF // Reading this register returns the current value of the System Tick counter. Writing any value clears the System Tick counter and the COUNTFLAG bit in STCTRL. +#define SYST_CVR_CURRENT_SHIFT 0 + +/* SYST_CALIB - 0xE000 E01C */ +#define SYST_CALIB_TENMS_MASK 0xFFFFFF // See Table 461. +#define SYST_CALIB_TENMS_SHIFT 0 +#define SYST_CALIB_SKEW (1 << 30) // See Table 461. +#define SYST_CALIB_NOREF (1 << 31) // See Table 461. + +/* AD0CR - address 0x4001 C000 */ +#define AD0CR_SEL_MASK 0x00FF // Selects which of the AD7:0 pins is (are) to be sampled and converted. Bit 0 selects Pin 0x00 AD0, bit 1 selects pin AD1,..., and bit 7 selects pin AD7. In software-controlled mode (BURST = 0), only one channel can be selected, i.e. only one of these bits should be 1. In hardware scan mode (BURST = 1), any numbers of channels can be selected, i.e any or all bits can be set to 1. If all bits are set to 0, channel 0 is selected automatically (SEL = 0x01). +#define AD0CR_SEL_SHIFT 0 +#define AD0CR_CLKDIV_MASK 0xFF00 // The APB clock (PCLK) is divided by CLKDIV +1 to produce the clock for the ADC, which 0 should be less than or equal to 4.5 MHz. Typically, software should program the smallest value in this field that yields a clock of 4.5 MHz or slightly less, but in certain cases (such as a high-impedance analog source) a slower clock may be desirable. +#define AD0CR_CLKDIV_SHIFT 8 +#define AD0CR_BURST (1 << 16) // Burst mode Remark: If BURST is set to 1, the ADGINTEN bit in the AD0INTEN register (Table 365) must be set to 0. +#define AD0CR_CLKS_MASK 0xE0000 // This field selects the number of clocks used for each conversion in Burst mode, and the number of bits of accuracy of the result in the LS bits of ADDR, between 11 clocks (10 bits) and 4 clocks (3 bits). +#define AD0CR_CLKS_SHIFT 17 +#define AD0CR_START_MASK 0x7000000 // When the BURST bit is 0, these bits control whether and when an A/D conversion is started: +#define AD0CR_START_SHIFT 24 +#define AD0CR_EDGE (1 << 27) // This bit is significant only when the START field contains 010-111. In these cases: + +/* AD0GDR - address 0x4001 C004 */ +#define AD0GDR_V_VREF_MASK 0xFFC0 // When DONE is 1, this field contains a binary fraction representing X the voltage on the ADn pin selected by the SEL field, divided by the voltage on the VDD pin. Zero in the field indicates that the voltage on the ADn pin was less than, equal to, or close to that on VSS, while 0x3FF indicates that the voltage on ADn was close to, equal to, or greater than that on VREF. +#define AD0GDR_V_VREF_SHIFT 6 +#define AD0GDR_CHN_MASK 0x7000000 // These bits contain the channel from which the result bits V_VREF X were converted. +#define AD0GDR_CHN_SHIFT 24 +#define AD0GDR_OVERRUN (1 << 30) // This bit is 1 in burst mode if the results of one or more conversions 0 was (were) lost and overwritten before the conversion that produced the result in the V_VREF bits. +#define AD0GDR_DONE (1 << 31) // This bit is set to 1 when an A/D conversion completes. It is cleared 0 when this register is read and when the ADCR is written. If the ADCR is written while a conversion is still in progress, this bit is set and a new conversion is started. + +/* AD0INTEN - address 0x4001 C00C */ +#define AD0INTEN_ADINTEN_MASK 0x00FF // These bits allow control over which A/D channels generate 0x00 interrupts for conversion completion. When bit 0 is one, completion of a conversion on A/D channel 0 will generate an interrupt, when bit 1 is one, completion of a conversion on A/D channel 1 will generate an interrupt, etc. +#define AD0INTEN_ADINTEN_SHIFT 0 +#define AD0INTEN_ADGINTEN (1 << 8) // When 1, enables the global DONE flag in ADDR to generate an interrupt. When 0, only the individual A/D channels enabled by ADINTEN 7:0 will generate interrupts. Remark: This bit must be set to 0 in burst mode (BURST = 1 in the AD0CR register). Reserved. Unused, always 0. + +/* AD0DR0 to AD0DR7 - addresses 0x4001 C010 to 0x4001 C02C */ +#define AD0DRn_V_VREF_MASK 0xFFC0 // When DONE is 1, this field contains a binary fraction representing the NA voltage on the ADn pin, divided by the voltage on the VREF pin. Zero in the field indicates that the voltage on the ADn pin was less than, equal to, or close to that on VREF, while 0x3FF indicates that the voltage on AD input was close to, equal to, or greater than that on VREF. Reserved. +#define AD0DRn_V_VREF_SHIFT 6 +#define AD0DRn_OVERRUN (1 << 30) // This bit is 1 in burst mode if the results of one or more conversions was (were) lost and overwritten before the conversion that produced the result in the V_VREF bits.This bit is cleared by reading this register. +#define AD0DRn_DONE (1 << 31) // This bit is set to 1 when an A/D conversion completes. It is cleared when this register is read. + +/* AD0STAT - address 0x4001 C030 */ +#define AD0STAT_DONE_MASK 0x00FF // These bits mirror the DONE status flags that appear in the result register for each A/D channel n. +#define AD0STAT_DONE_SHIFT 0 +#define AD0STAT_OVERRUN_MASK 0xFF00 // These bits mirror the OVERRRUN status flags that appear in the result register for each A/D channel n. Reading ADSTAT allows checking the status of all A/D channels simultaneously. +#define AD0STAT_OVERRUN_SHIFT 8 +#define AD0STAT_ADINT (1 << 16) // This bit is the A/D interrupt flag. It is one when any of the individual A/D channel Done flags is asserted and enabled to contribute to the A/D interrupt via the ADINTEN register. Reserved. Unused, always 0. + +/* FLASHCFG, address 0x4003 C010 */ +#define FLASHCFG_FLASHTIM_MASK 0x0003 // Flash memory access time. FLASHTIM +1 is equal to the number of system clocks used for flash access. +#define FLASHCFG_FLASHTIM_SHIFT 0 + +/* FMSSTART - 0x4003 C020 */ +#define FMSSTART_START_MASK 0x1FFFF // Signature generation start address (corresponds to AHB byte address bits[20:4]). +#define FMSSTART_START_SHIFT 0 + +/* FMSSTOP - 0x4003 C024 */ +#define FMSSTOP_STOP_MASK 0x1FFFF // BIST stop address divided by 16 (corresponds to AHB byte address [20:4]). +#define FMSSTOP_STOP_SHIFT 0 +#define FMSSTOP_SIG_START (1 << 17) // Start control bit for signature generation. + +/* FMSTAT - 0x4003 CFE0 */ +#define FMSTAT_SIG_DONE (1 << 2) // When 1, a previously started signature generation has 0 completed. See FMSTATCLR register description for clearing this flag. + +/* FMSTATCLR - 0x0x4003 CFE8 */ +#define FMSTATCLR_SIG_DONE_CLR (1 << 2) // Writing a 1 to this bits clears the signature generation completion flag (SIG_DONE) in the FMSTAT register. + + +#endif diff --git a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h index 6e00f1e26b..4b9e4353c6 100644 --- a/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h +++ b/libraries/mbed/targets/cmsis/TARGET_NXP/TARGET_LPC11XX_11CXX/cmsis.h @@ -9,5 +9,6 @@ #include "LPC11xx.h" #include "cmsis_nvic.h" +#include "bitfields.h" #endif diff --git a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c index 18f98617de..1088accb35 100644 --- a/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c +++ b/libraries/mbed/targets/cmsis/TARGET_STM/TARGET_STM32F4XX/cmsis_nvic.c @@ -6,20 +6,22 @@ #include "cmsis_nvic.h" #define NVIC_RAM_VECTOR_ADDRESS (0x20000000) // Location of vectors in RAM -#define NVIC_FLASH_VECTOR_ADDRESS (0x0) // Initial vector position in flash + +static unsigned char vtor_relocated; void NVIC_SetVector(IRQn_Type IRQn, uint32_t vector) { uint32_t *vectors = (uint32_t*)SCB->VTOR; uint32_t i; // Copy and switch to dynamic vectors if the first time called - if (SCB->VTOR == NVIC_FLASH_VECTOR_ADDRESS) { + if (!vtor_relocated) { uint32_t *old_vectors = vectors; vectors = (uint32_t*)NVIC_RAM_VECTOR_ADDRESS; for (i=0; iVTOR = (uint32_t)NVIC_RAM_VECTOR_ADDRESS; + vtor_relocated = 1; } vectors[IRQn + 16] = vector; } diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL05Z/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL05Z/gpio_irq_api.c index b76a2ed505..e14f0b8ec7 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL05Z/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL05Z/gpio_irq_api.c @@ -154,3 +154,19 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { // Interrupt configuration and clear interrupt port->PCR[obj->pin] = (port->PCR[obj->pin] & ~PORT_PCR_IRQC_MASK) | irq_settings | PORT_PCR_ISF_MASK; } + +void gpio_irq_enable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_EnableIRQ(PORTA_IRQn); + } else if (obj->port == PortB) { + NVIC_EnableIRQ(PORTB_IRQn); + } +} + +void gpio_irq_disable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_DisableIRQ(PORTA_IRQn); + } else if (obj->port == PortB) { + NVIC_DisableIRQ(PORTB_IRQn); + } +} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/gpio_irq_api.c index 44d018d8ef..0af91e80bc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL25Z/gpio_irq_api.c @@ -143,3 +143,19 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { // Interrupt configuration and clear interrupt port->PCR[obj->pin] = (port->PCR[obj->pin] & ~PORT_PCR_IRQC_MASK) | irq_settings | PORT_PCR_ISF_MASK; } + +void gpio_irq_enable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_EnableIRQ(PORTA_IRQn); + } else if (obj->port == PortD) { + NVIC_EnableIRQ(PORTD_IRQn); + } +} + +void gpio_irq_disable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_DisableIRQ(PORTA_IRQn); + } else if (obj->port == PortD) { + NVIC_DisableIRQ(PORTD_IRQn); + } +} diff --git a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL46Z/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL46Z/gpio_irq_api.c index 44d018d8ef..0af91e80bc 100644 --- a/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL46Z/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_Freescale/TARGET_KL46Z/gpio_irq_api.c @@ -143,3 +143,19 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { // Interrupt configuration and clear interrupt port->PCR[obj->pin] = (port->PCR[obj->pin] & ~PORT_PCR_IRQC_MASK) | irq_settings | PORT_PCR_ISF_MASK; } + +void gpio_irq_enable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_EnableIRQ(PORTA_IRQn); + } else if (obj->port == PortD) { + NVIC_EnableIRQ(PORTD_IRQn); + } +} + +void gpio_irq_disable(gpio_irq_t *obj) { + if (obj->port == PortA) { + NVIC_DisableIRQ(PORTA_IRQn); + } else if (obj->port == PortD) { + NVIC_DisableIRQ(PORTD_IRQn); + } +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_irq_api.c index 4228ac5a6c..0a992633da 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11UXX/gpio_irq_api.c @@ -131,3 +131,11 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c new file mode 100644 index 0000000000..509957e4c3 --- /dev/null +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/TARGET_LPC11CXX/can_api.c @@ -0,0 +1,411 @@ +/* mbed Microcontroller Library + * Copyright (c) 2006-2013 ARM Limited + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "can_api.h" + +#include "cmsis.h" +#include "error.h" + +#include +#include + +/* Handy defines */ +#define MSG_OBJ_MAX 32 +#define DLC_MAX 8 + +#define ID_STD_MASK 0x07FF +#define ID_EXT_MASK 0x1FFFFFFF +#define DLC_MASK 0x0F + +static uint32_t can_irq_id = 0; +static can_irq_handler irq_handler; + +static uint32_t can_disable(can_t *obj) { + uint32_t sm = LPC_CAN->CNTL; + LPC_CAN->CNTL |= CANCNTL_INIT; + return sm; +} + +static inline void can_enable(can_t *obj) { + if (LPC_CAN->CNTL & CANCNTL_INIT) { + LPC_CAN->CNTL &= ~CANCNTL_INIT; + } +} + +int can_mode(can_t *obj, CanMode mode) { + return 0; // not implemented +} + +int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { + uint16_t i; + + // Find first free message object + if(handle == 0) { + uint32_t msgval = LPC_CAN->MSGV1 | (LPC_CAN->MSGV2 << 16); + // Find first free messagebox + for(i = 0; i < 32; i++) { + if((msgval & (1 << i)) == 0) { + handle = i+1; + break; + } + } + } + + if(handle > 0 && handle < 32) { + if(format == CANExtended) { + // Mark message valid, Direction = TX, Extended Frame, Set Identifier and mask everything + LPC_CAN->IF1_ARB1 = BFN_PREP(id, CANIFn_ARB1_ID); + LPC_CAN->IF1_ARB2 = CANIFn_ARB2_MSGVAL | CANIFn_ARB2_XTD | BFN_PREP(id >> 16, CANIFn_ARB2_ID); + LPC_CAN->IF1_MSK1 = BFN_PREP(mask, CANIFn_MSK1_MSK); + LPC_CAN->IF1_MSK2 = CANIFn_MSK2_MXTD | CANIFn_MSK2_MDIR | BFN_PREP(mask >> 16, CANIFn_MSK2_MSK); + } + else { + // Mark message valid, Direction = TX, Set Identifier and mask everything + LPC_CAN->IF1_ARB2 = CANIFn_ARB2_MSGVAL | BFN_PREP(id << 2, CANIFn_ARB2_ID); + LPC_CAN->IF1_MSK2 = CANIFn_MSK2_MDIR | BFN_PREP(mask << 2, CANIFn_MSK2_MSK); + } + + // Use mask, single message object and set DLC + LPC_CAN->IF1_MCTRL = CANIFn_MCTRL_UMASK | CANIFn_MCTRL_EOB | CANIFn_MCTRL_RXIE | BFN_PREP(DLC_MAX, CANIFn_MCTRL_DLC); + + // Transfer all fields to message object + LPC_CAN->IF1_CMDMSK = CANIFn_CMDMSK_WR | CANIFn_CMDMSK_MASK | CANIFn_CMDMSK_ARB | CANIFn_CMDMSK_CTRL; + + // Start Transfer to given message number + LPC_CAN->IF1_CMDREQ = BFN_PREP(handle, CANIFn_CMDREQ_MN); + + // Wait until transfer to message ram complete - TODO: maybe not block?? + while( LPC_CAN->IF1_CMDREQ & CANIFn_CMDREQ_BUSY ); + } + + return handle; +} + +static inline void can_irq() { + irq_handler(can_irq_id, IRQ_RX); +} + +// Register CAN object's irq handler +void can_irq_init(can_t *obj, can_irq_handler handler, uint32_t id) { + irq_handler = handler; + can_irq_id = id; +} + +// Unregister CAN object's irq handler +void can_irq_free(can_t *obj) { + LPC_CAN->CNTL &= ~CANCNTL_IE; // Disable Interrupts :) + + can_irq_id = 0; + NVIC_DisableIRQ(CAN_IRQn); +} + +// Clear or set a irq +void can_irq_set(can_t *obj, CanIrqType type, uint32_t enable) { + // Put CAN in Reset Mode and enable interrupt + can_disable(obj); + if(enable == 0) { + LPC_CAN->CNTL &= ~(CANCNTL_IE | CANCNTL_SIE); + } + else { + LPC_CAN->CNTL |= CANCNTL_IE | CANCNTL_SIE; + } + // Take it out of reset... + can_enable(obj); + + // Enable NVIC if at least 1 interrupt is active + NVIC_SetVector(CAN_IRQn, (uint32_t) &can_irq); + NVIC_EnableIRQ(CAN_IRQn); +} + +// This table has the sampling points as close to 75% as possible. The first +// value is TSEG1, the second TSEG2. +static const int timing_pts[23][2] = { + {0x0, 0x0}, // 2, 50% + {0x1, 0x0}, // 3, 67% + {0x2, 0x0}, // 4, 75% + {0x3, 0x0}, // 5, 80% + {0x3, 0x1}, // 6, 67% + {0x4, 0x1}, // 7, 71% + {0x5, 0x1}, // 8, 75% + {0x6, 0x1}, // 9, 78% + {0x6, 0x2}, // 10, 70% + {0x7, 0x2}, // 11, 73% + {0x8, 0x2}, // 12, 75% + {0x9, 0x2}, // 13, 77% + {0x9, 0x3}, // 14, 71% + {0xA, 0x3}, // 15, 73% + {0xB, 0x3}, // 16, 75% + {0xC, 0x3}, // 17, 76% + {0xD, 0x3}, // 18, 78% + {0xD, 0x4}, // 19, 74% + {0xE, 0x4}, // 20, 75% + {0xF, 0x4}, // 21, 76% + {0xF, 0x5}, // 22, 73% + {0xF, 0x6}, // 23, 70% + {0xF, 0x7}, // 24, 67% +}; + +static unsigned int can_speed(unsigned int sclk, unsigned int cclk, unsigned char psjw) { + uint32_t btr; + uint32_t clkdiv = 1; + uint16_t brp = 0; + uint32_t calcbit; + uint32_t bitwidth; + int hit = 0; + int bits = 0; + + bitwidth = sclk / cclk; + + brp = bitwidth / 0x18; + while ((!hit) && (brp < bitwidth / 4)) { + brp++; + for (bits = 22; bits > 0; bits--) { + calcbit = (bits + 3) * (brp + 1); + if (calcbit == bitwidth) { + hit = 1; + break; + } + } + } + + /* This might be funky + while(btr > 63 && clkdiv < 16) { + btr = btr / 2; + clkdiv = clkdiv * 2; + } + */ + clkdiv = clkdiv - 1; + + if (hit) { + btr = BFN_PREP(timing_pts[bits][1], CANBT_TSEG2) + | BFN_PREP(timing_pts[bits][0], CANBT_TSEG1) + | BFN_PREP(psjw, CANBT_SJW) + | BFN_PREP(brp, CANBT_BRP); + btr = btr | (clkdiv << 16); + + } else { + btr = 0; + } + + return btr; +} + + +int can_config_rxmsgobj(can_t *obj) { + uint16_t i = 0; + + // Make sure the interface is available + //while( LPC_CAN->IF1_CMDREQ & CANIFn_CMDREQ_BUSY ); + + // Mark message valid, Direction = RX, Don't care about anything else + LPC_CAN->IF1_ARB1 = 0; + LPC_CAN->IF1_ARB2 = 0; + LPC_CAN->IF1_MCTRL = 0; + + for ( i = 0; i < MSG_OBJ_MAX; i++ ) + { + // Transfer arb and control fields to message object + LPC_CAN->IF1_CMDMSK = CANIFn_CMDMSK_WR | CANIFn_CMDMSK_ARB | CANIFn_CMDMSK_CTRL | CANIFn_CMDMSK_TXRQST; + + // Start Transfer to given message number + LPC_CAN->IF1_CMDREQ = BFN_PREP(i, CANIFn_CMDREQ_MN); + + // Wait until transfer to message ram complete - TODO: maybe not block?? + while( LPC_CAN->IF1_CMDREQ & CANIFn_CMDREQ_BUSY ); + } + + // Accept all messages + can_filter(obj, 0, 0, CANStandard, 1); + + return 1; +} + + +void can_init(can_t *obj, PinName rd, PinName td) { + // Enable power and clock + LPC_SYSCON->PRESETCTRL |= PRESETCTRL_CAN_RST_N; + LPC_SYSCON->SYSAHBCLKCTRL |= SYSAHBCLKCTRL_CAN; + + // Enable Initialization mode + if (!(LPC_CAN->CNTL & CANCNTL_INIT)) { + LPC_CAN->CNTL |= CANCNTL_INIT; + } + + can_frequency(obj, 125000); + + // Resume operation + LPC_CAN->CNTL &= ~CANCNTL_INIT; + while ( LPC_CAN->CNTL & CANCNTL_INIT ); + + // Initialize RX message object + can_config_rxmsgobj(obj); +} + +void can_free(can_t *obj) { + LPC_SYSCON->SYSAHBCLKCTRL &= ~(SYSAHBCLKCTRL_CAN); + LPC_SYSCON->PRESETCTRL &= ~(PRESETCTRL_CAN_RST_N); +} + +int can_frequency(can_t *obj, int f) { + int btr = can_speed(SystemCoreClock, (unsigned int)f, 1); + int clkdiv = (btr >> 16) & 0x0F; + btr = btr & 0xFFFF; + + if (btr > 0) { + // Set the bit clock + LPC_CAN->CNTL |= CANCNTL_CCE; + LPC_CAN->CLKDIV = clkdiv; + LPC_CAN->BT = btr; + LPC_CAN->BRPE = 0x0000; + LPC_CAN->CNTL &= ~CANCNTL_CCE; + return 1; + } + return 0; +} + +int can_write(can_t *obj, CAN_Message msg, int cc) { + uint16_t msgnum = 0; + + // Make sure controller is enabled + can_enable(obj); + + // Make sure the interface is available + while( LPC_CAN->IF1_CMDREQ & CANIFn_CMDREQ_BUSY ); + + if(msg.format == CANExtended) { + // Mark message valid, Direction = TX, Extended Frame, Set Identifier and mask everything + LPC_CAN->IF1_ARB1 = BFN_PREP(msg.id, CANIFn_ARB1_ID); + LPC_CAN->IF1_ARB2 = CANIFn_ARB2_MSGVAL | CANIFn_ARB2_XTD | CANIFn_ARB2_DIR | BFN_PREP(msg.id >> 16, CANIFn_ARB2_ID); + LPC_CAN->IF1_MSK1 = BFN_PREP(ID_EXT_MASK, CANIFn_MSK1_MSK); + LPC_CAN->IF1_MSK2 = CANIFn_MSK2_MXTD | CANIFn_MSK2_MDIR | BFN_PREP(ID_EXT_MASK >> 16, CANIFn_MSK2_MSK); + } + else { + // Mark message valid, Direction = TX, Set Identifier and mask everything + LPC_CAN->IF1_ARB2 = CANIFn_ARB2_MSGVAL | CANIFn_ARB2_DIR | BFN_PREP(msg.id << 2, CANIFn_ARB2_ID); + LPC_CAN->IF1_MSK2 = CANIFn_MSK2_MDIR | BFN_PREP(ID_STD_MASK << 2, CANIFn_MSK2_MSK); + } + + // Use mask, request transmission, single message object and set DLC + LPC_CAN->IF1_MCTRL = CANIFn_MCTRL_UMASK | CANIFn_MCTRL_TXRQST | CANIFn_MCTRL_EOB | BFN_PREP(msg.len, CANIFn_MCTRL_DLC); + + LPC_CAN->IF1_DA1 = BFN_PREP(msg.data[1], CANIFn_DA1_DATA1) | BFN_PREP(msg.data[0], CANIFn_DA1_DATA0); + LPC_CAN->IF1_DA2 = BFN_PREP(msg.data[3], CANIFn_DA2_DATA3) | BFN_PREP(msg.data[2], CANIFn_DA2_DATA2); + LPC_CAN->IF1_DB1 = BFN_PREP(msg.data[5], CANIFn_DB1_DATA5) | BFN_PREP(msg.data[4], CANIFn_DB1_DATA4); + LPC_CAN->IF1_DB2 = BFN_PREP(msg.data[7], CANIFn_DB2_DATA7) | BFN_PREP(msg.data[6], CANIFn_DB2_DATA6); + + // Transfer all fields to message object + LPC_CAN->IF1_CMDMSK = CANIFn_CMDMSK_WR | CANIFn_CMDMSK_MASK | CANIFn_CMDMSK_ARB | CANIFn_CMDMSK_CTRL | CANIFn_CMDMSK_TXRQST | CANIFn_CMDMSK_DATA_A | CANIFn_CMDMSK_DATA_B; + + // Start Transfer to given message number + LPC_CAN->IF1_CMDREQ = BFN_PREP(msgnum, CANIFn_CMDREQ_MN); + + // Wait until transfer to message ram complete - TODO: maybe not block?? + while( LPC_CAN->IF1_CMDREQ & CANIFn_CMDREQ_BUSY); + + // Wait until TXOK is set, then clear it - TODO: maybe not block + //while( !(LPC_CAN->STAT & CANSTAT_TXOK) ); + LPC_CAN->STAT &= ~(CANSTAT_TXOK); + + return 1; +} + +int can_read(can_t *obj, CAN_Message *msg, int handle) { + uint16_t i; + + // Make sure controller is enabled + can_enable(obj); + + // Find first message object with new data + if(handle == 0) { + uint32_t newdata = LPC_CAN->ND1 | (LPC_CAN->ND2 << 16); + // Find first free messagebox + for(i = 0; i < 32; i++) { + if(newdata & (1 << i)) { + handle = i+1; + break; + } + } + } + + if(handle > 0 && handle < 32) { + // Wait until message interface is free + while( LPC_CAN->IF2_CMDREQ & CANIFn_CMDREQ_BUSY ); + + // Transfer all fields to message object + LPC_CAN->IF2_CMDMSK = CANIFn_CMDMSK_RD | CANIFn_CMDMSK_MASK | CANIFn_CMDMSK_ARB | CANIFn_CMDMSK_CTRL | CANIFn_CMDMSK_CLRINTPND | CANIFn_CMDMSK_TXRQST | CANIFn_CMDMSK_DATA_A | CANIFn_CMDMSK_DATA_B; + + // Start Transfer from given message number + LPC_CAN->IF2_CMDREQ = BFN_PREP(handle, CANIFn_CMDREQ_MN); + + // Wait until transfer to message ram complete + while( LPC_CAN->IF2_CMDREQ & CANIFn_CMDREQ_BUSY ); + + if (LPC_CAN->IF2_ARB2 & CANIFn_ARB2_XTD) { + msg->format = CANExtended; + msg->id = (LPC_CAN->IF2_ARB1 & CANIFn_ARB2_ID_MASK) << 16; + msg->id |= (LPC_CAN->IF2_ARB2 & CANIFn_ARB2_ID_MASK); + } + else { + msg->format = CANStandard; + msg->id = (LPC_CAN->IF2_ARB2 & CANIFn_ARB2_ID_MASK) >> 2; + } + + // TODO: Remote frame support + msg->type = CANData; + msg->len = BFN_GET(LPC_CAN->IF2_MCTRL, CANIFn_MCTRL_DLC); // TODO: If > 8, len = 8 + msg->data[0] = BFN_GET(LPC_CAN->IF2_DA1, CANIFn_DA1_DATA0); + msg->data[1] = BFN_GET(LPC_CAN->IF2_DA1, CANIFn_DA1_DATA1); + msg->data[2] = BFN_GET(LPC_CAN->IF2_DA2, CANIFn_DA2_DATA2); + msg->data[3] = BFN_GET(LPC_CAN->IF2_DA2, CANIFn_DA2_DATA3); + msg->data[4] = BFN_GET(LPC_CAN->IF2_DB1, CANIFn_DB1_DATA4); + msg->data[5] = BFN_GET(LPC_CAN->IF2_DB1, CANIFn_DB1_DATA5); + msg->data[6] = BFN_GET(LPC_CAN->IF2_DB2, CANIFn_DB2_DATA6); + msg->data[7] = BFN_GET(LPC_CAN->IF2_DB2, CANIFn_DB2_DATA7); + + LPC_CAN->STAT &= ~(CANSTAT_RXOK); + return 1; + } + + return 0; +} + +void can_reset(can_t *obj) { + LPC_SYSCON->PRESETCTRL &= ~PRESETCTRL_CAN_RST_N; + LPC_CAN->STAT = 0; + + can_config_rxmsgobj(obj); +} + +unsigned char can_rderror(can_t *obj) { + return BFN_GET(LPC_CAN->EC, CANEC_REC); +} + +unsigned char can_tderror(can_t *obj) { + return BFN_GET(LPC_CAN->EC, CANEC_TEC); +} + +void can_monitor(can_t *obj, int silent) { + if (silent) { + LPC_CAN->CNTL |= CANCNTL_TEST; + LPC_CAN->TEST |= CANTEST_SILENT; + } else { + LPC_CAN->CNTL &= ~(CANCNTL_TEST); + LPC_CAN->TEST &= ~CANTEST_SILENT; + } + + if (!(LPC_CAN->CNTL & CANCNTL_INIT)) { + LPC_CAN->CNTL |= CANCNTL_INIT; + } +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_irq_api.c index fbd12f8695..a8dc1f6c18 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC11XX_11CXX/gpio_irq_api.c @@ -174,3 +174,43 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } + +void gpio_irq_enable(gpio_irq_t *obj) { + uint32_t port_num = ((obj->pin & 0xF000) >> PORT_SHIFT); + switch (port_num) { + case 0: + NVIC_EnableIRQ(EINT0_IRQn); + break; + case 1: + NVIC_EnableIRQ(EINT1_IRQn); + break; + case 2: + NVIC_EnableIRQ(EINT2_IRQn); + break; + case 3: + NVIC_EnableIRQ(EINT3_IRQn); + break; + default: + break; + } +} + +void gpio_irq_disable(gpio_irq_t *obj) { + uint32_t port_num = ((obj->pin & 0xF000) >> PORT_SHIFT); + switch (port_num) { + case 0: + NVIC_DisableIRQ(EINT0_IRQn); + break; + case 1: + NVIC_DisableIRQ(EINT1_IRQn); + break; + case 2: + NVIC_DisableIRQ(EINT2_IRQn); + break; + case 3: + NVIC_DisableIRQ(EINT3_IRQn); + break; + default: + break; + } +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/gpio_irq_api.c index 5430e966f8..74b3e280cc 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC13XX/gpio_irq_api.c @@ -131,3 +131,12 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} + diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c index 62c0db2331..35b62ba241 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/can_api.c @@ -78,8 +78,11 @@ static inline void can_enable(can_t *obj) { } } -int can_mode(can_t *obj, CanMode mode) -{ +int can_mode(can_t *obj, CanMode mode) { + return 0; // not implemented +} + +int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { return 0; // not implemented } @@ -355,7 +358,7 @@ int can_write(can_t *obj, CAN_Message msg, int cc) { return 0; } -int can_read(can_t *obj, CAN_Message *msg) { +int can_read(can_t *obj, CAN_Message *msg, int handle) { CANMsg x; unsigned int *i = (unsigned int *)&x; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/gpio_irq_api.c index acdc3cb718..3cd2418390 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/gpio_irq_api.c @@ -150,3 +150,12 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ(EINT3_IRQn); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ(EINT3_IRQn); +} + diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/objects.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/objects.h index 86736c1ecd..ace5371b46 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/objects.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/objects.h @@ -47,6 +47,7 @@ struct pwmout_s { struct serial_s { LPC_UART_TypeDef *uart; int index; + uint8_t count; }; struct analogin_s { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c index 475af90454..96baef5689 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC176X/serial_api.c @@ -106,6 +106,7 @@ void serial_init(serial_t *obj, PinName tx, PinName rx) { case UART_2: obj->index = 2; break; case UART_3: obj->index = 3; break; } + obj->count = 0; is_stdio_uart = (uart == STDIO_UART) ? (1) : (0); @@ -283,6 +284,7 @@ int serial_getc(serial_t *obj) { void serial_putc(serial_t *obj, int c) { while (!serial_writable(obj)); obj->uart->THR = c; + obj->count++; } int serial_readable(serial_t *obj) { @@ -290,7 +292,13 @@ int serial_readable(serial_t *obj) { } int serial_writable(serial_t *obj) { - return obj->uart->LSR & 0x20; + int isWritable = 1; + if (obj->uart->LSR & 0x20) + obj->count = 0; + else if (obj->count >= 16) + isWritable = 0; + + return isWritable; } void serial_clear(serial_t *obj) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c index 79aaadc35a..f7ddf5278d 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/can_api.c @@ -72,6 +72,14 @@ static inline void can_enable(can_t *obj) { } } +int can_mode(can_t *obj, CanMode mode) { + return 0; // not implemented +} + +int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { + return 0; // not implemented +} + static int can_pclk(can_t *obj) { int value = 0; switch ((int)obj->dev) { @@ -247,7 +255,7 @@ int can_write(can_t *obj, CAN_Message msg, int cc) { return 0; } -int can_read(can_t *obj, CAN_Message *msg) { +int can_read(can_t *obj, CAN_Message *msg, int handle) { CANMsg x; unsigned int *i = (unsigned int *)&x; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/gpio_irq_api.c index 3741605f09..129e1ea5b4 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC23XX/gpio_irq_api.c @@ -143,3 +143,12 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ(EINT3_IRQn); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ(EINT3_IRQn); +} + diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c index 8d09fad8b2..0ff86f93bf 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/can_api.c @@ -83,6 +83,10 @@ int can_mode(can_t *obj, CanMode mode) return 0; // not implemented } +int can_filter(can_t *obj, uint32_t id, uint32_t mask, CANFormat format, int32_t handle) { + return 0; // not implemented +} + static inline void can_irq(uint32_t icr, uint32_t index) { uint32_t i; @@ -340,7 +344,7 @@ int can_write(can_t *obj, CAN_Message msg, int cc) { return 0; } -int can_read(can_t *obj, CAN_Message *msg) { +int can_read(can_t *obj, CAN_Message *msg, int handle) { CANMsg x; unsigned int *i = (unsigned int *)&x; diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c index 605f2d6d87..ececfabe69 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/gpio_irq_api.c @@ -164,3 +164,11 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ(GPIO_IRQn); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ(GPIO_IRQn); +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c index e399f62b20..5619a51435 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/i2c_api.c @@ -122,6 +122,15 @@ void i2c_init(i2c_t *obj, PinName sda, PinName scl) { pinmap_pinout(sda, PinMap_I2C_SDA); pinmap_pinout(scl, PinMap_I2C_SCL); + + // OpenDrain must explicitly be enabled for p0.0 and p0.1 + if (sda == P0_0) { + pin_mode(sda, OpenDrain); + } + if (scl == P0_1) { + pin_mode(scl, OpenDrain); + } + } inline int i2c_start(i2c_t *obj) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/port_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/port_api.c index 5f44eedd9e..8fe23e6dd0 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/port_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC408X/port_api.c @@ -17,8 +17,9 @@ #include "pinmap.h" #include "gpio_api.h" + PinName port_pin(PortName port, int pin_n) { - return (PinName)(LPC_GPIO0_BASE + ((port << PORT_SHIFT) | pin_n)); + return (PinName)(((port << PORT_SHIFT) | pin_n)); } void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/gpio_irq_api.c index dda9c147bb..c24fe223e2 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC43XX/gpio_irq_api.c @@ -134,3 +134,19 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { +#if !defined(CORE_M0) + NVIC_EnableIRQ((IRQn_Type)(PIN_INT0_IRQn + obj->ch)); +#else + NVIC_EnableIRQ((IRQn_Type)(PIN_INT4_IRQn + obj->ch)); +#endif +} + +void gpio_irq_disable(gpio_irq_t *obj) { +#if !defined(CORE_M0) + NVIC_DisableIRQ((IRQn_Type)(PIN_INT0_IRQn + obj->ch)); +#else + NVIC_DisableIRQ((IRQn_Type)(PIN_INT4_IRQn + obj->ch)); +#endif +} diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/device.h b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/device.h index ddb923bb83..f8699b5426 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/device.h +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/device.h @@ -48,7 +48,7 @@ #define DEVICE_DEBUG_AWARENESS 0 -#define DEVICE_STDIO_MESSAGES 1 +#define DEVICE_STDIO_MESSAGES 0 #define DEVICE_ERROR_RED 1 diff --git a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/gpio_irq_api.c b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/gpio_irq_api.c index c90c31a3da..95186d0228 100644 --- a/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/gpio_irq_api.c +++ b/libraries/mbed/targets/hal/TARGET_NXP/TARGET_LPC81X/TARGET_LPC81X_COMMON/gpio_irq_api.c @@ -125,3 +125,11 @@ void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable) { } } } + +void gpio_irq_enable(gpio_irq_t *obj) { + NVIC_EnableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} + +void gpio_irq_disable(gpio_irq_t *obj) { + NVIC_DisableIRQ((IRQn_Type)(PININT_IRQ + obj->ch)); +} diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.cpp b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.cpp deleted file mode 100644 index ba647dc30e..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.cpp +++ /dev/null @@ -1,265 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#define __DEBUG__ 0 -#ifndef __MODULE__ -#define __MODULE__ "WANDongleInitializer.cpp" -#endif - -#include "core/dbg.h" - -#include -using std::uint16_t; - -#include "WANDongleInitializer.h" - -WANDongleInitializer::WANDongleInitializer(USBHost* pHost) : m_pHost(pHost) -{ - -} - -WANDongleInitializer** WANDongleInitializer::getInitializers(USBHost* pHost) -{ - static VodafoneK3770Initializer vodafoneK3770(pHost); - static VodafoneK3772ZInitializer vodafoneK3772Z(pHost); - const static WANDongleInitializer* list[] = { &vodafoneK3770, &vodafoneK3772Z, NULL }; - return (WANDongleInitializer**)list; -} - -//Huawei K3770 (Vodafone) -// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 00 11 06 20 00 00 01 00 00 00 00 00 00 00 00 00 00" -static uint8_t vodafone_k3770_switch_packet[] = { - 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0, 0x11, 0x06, 0x20, 0, 0, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -VodafoneK3770Initializer::VodafoneK3770Initializer(USBHost* pHost) : WANDongleInitializer(pHost) -{ - -} - -uint16_t VodafoneK3770Initializer::getMSDVid() { return 0x12D1; } -uint16_t VodafoneK3770Initializer::getMSDPid() { return 0x14D1; } - -uint16_t VodafoneK3770Initializer::getSerialVid() { return 0x12D1; } -uint16_t VodafoneK3770Initializer::getSerialPid() { return 0x14C9; } - -bool VodafoneK3770Initializer::switchMode(USBDeviceConnected* pDev) -{ - for (int i = 0; i < pDev->getNbInterface(); i++) - { - if (pDev->getInterface(i)->intf_class == MSD_CLASS) - { - USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); - if ( pEp != NULL ) - { - DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); - m_pHost->bulkWrite(pDev, pEp, vodafone_k3770_switch_packet, 31); - return true; - } - } - } - return false; -} - -USBEndpoint* VodafoneK3770Initializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) -{ - return pDev->getEndpoint(serialPortNumber, BULK_ENDPOINT, tx?OUT:IN, 0); -} - -int VodafoneK3770Initializer::getSerialPortCount() -{ - return 2; -} - -/*virtual*/ void VodafoneK3770Initializer::setVidPid(uint16_t vid, uint16_t pid) -{ - if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) - { - m_hasSwitched = true; - m_currentSerialIntf = 0; - m_endpointsToFetch = 4; - } - else - { - m_hasSwitched = false; - m_endpointsToFetch = 1; - } -} - -/*virtual*/ bool VodafoneK3770Initializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed -{ - if( m_hasSwitched ) - { - if( intf_class == 0xFF ) - { - if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 4) ) - { - m_currentSerialIntf++; - return true; - } - m_currentSerialIntf++; - } - } - else - { - if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) - { - return true; - } - } - return false; -} - -/*virtual*/ bool VodafoneK3770Initializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used -{ - if( m_hasSwitched ) - { - if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) - { - m_endpointsToFetch--; - return true; - } - } - else - { - if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) - { - m_endpointsToFetch--; - return true; - } - } - return false; -} - -/*virtual*/ WAN_DONGLE_TYPE VodafoneK3770Initializer::getType() -{ - return WAN_DONGLE_TYPE_VODAFONEK3770; -} - -// NVIDIA (ICERA) /ZTE K3772-Z (Vodafone) -// Switching from mass storage device string is: "55 53 42 43 12 34 56 78 00 00 00 00 00 00 06 1b 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00" -static uint8_t vodafone_k3772_z_switch_packet[] = { - 0x55, 0x53, 0x42, 0x43, 0x12, 0x34, 0x56, 0x78, 0, 0, 0, 0, 0, 0, 0x06, 0x1b, 0, 0, 0, 0x02, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 -}; - -VodafoneK3772ZInitializer::VodafoneK3772ZInitializer(USBHost* pHost) : WANDongleInitializer(pHost) -{ - -} - -uint16_t VodafoneK3772ZInitializer::getMSDVid() { return 0x19D2; } -uint16_t VodafoneK3772ZInitializer::getMSDPid() { return 0x1179; } - -uint16_t VodafoneK3772ZInitializer::getSerialVid() { return 0x19D2; } -uint16_t VodafoneK3772ZInitializer::getSerialPid() { return 0x1181; } - -bool VodafoneK3772ZInitializer::switchMode(USBDeviceConnected* pDev) -{ - for (int i = 0; i < pDev->getNbInterface(); i++) - { - if (pDev->getInterface(i)->intf_class == MSD_CLASS) - { - USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); - if ( pEp != NULL ) - { - DBG("MSD descriptor found on device %p, intf %d, will now try to switch into serial mode", (void *)pDev, i); - m_pHost->bulkWrite(pDev, pEp, vodafone_k3772_z_switch_packet, 31); - return true; - } - } - } - return false; -} - -USBEndpoint* VodafoneK3772ZInitializer::getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) -{ - return pDev->getEndpoint((serialPortNumber==1)?0:1, BULK_ENDPOINT, tx?OUT:IN, 0); -} - -int VodafoneK3772ZInitializer::getSerialPortCount() -{ - return 2; -} - -/*virtual*/ void VodafoneK3772ZInitializer::setVidPid(uint16_t vid, uint16_t pid) -{ - if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) - { - m_hasSwitched = true; - m_currentSerialIntf = 0; - m_endpointsToFetch = 4; - } - else - { - m_hasSwitched = false; - m_endpointsToFetch = 1; - } -} - -/*virtual*/ bool VodafoneK3772ZInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed -{ - if( m_hasSwitched ) - { - DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); - if( intf_class == 0x0A ) - { - if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) ) - { - m_currentSerialIntf++; - return true; - } - m_currentSerialIntf++; - } - } - else - { - if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) - { - return true; - } - } - return false; -} - -/*virtual*/ bool VodafoneK3772ZInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used -{ - if( m_hasSwitched ) - { - DBG("USBEndpoint on Inteface #%d; Type:%d; Direction:%d", intf_nb, type, dir); - if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) - { - m_endpointsToFetch--; - return true; - } - } - else - { - if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) - { - m_endpointsToFetch--; - return true; - } - } - return false; -} - - -/*virtual*/ WAN_DONGLE_TYPE VodafoneK3772ZInitializer::getType() -{ - return WAN_DONGLE_TYPE_VODAFONEK3772Z; -} diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.h deleted file mode 100644 index 4120bc8baf..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USB3GModule/WANDongleInitializer.h +++ /dev/null @@ -1,130 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef WANDONGLEINITIALIZER_H -#define WANDONGLEINITIALIZER_H - -#include -using std::uint16_t; -using std::uint32_t; - -#include "USBHost.h" -#include "IUSBEnumerator.h" - -enum WAN_DONGLE_TYPE -{ - WAN_DONGLE_TYPE_UNKNOWN = -1, - WAN_DONGLE_TYPE_VODAFONEK3770 = 0, - WAN_DONGLE_TYPE_VODAFONEK3772Z = 1, -}; - -class WANDongleInitializer : public IUSBEnumerator -{ -protected: - WANDongleInitializer(USBHost* pHost); - USBHost* m_pHost; - -public: - virtual uint16_t getMSDVid() = 0; - virtual uint16_t getMSDPid() = 0; - - virtual uint16_t getSerialVid() = 0; - virtual uint16_t getSerialPid() = 0; - - virtual bool switchMode(USBDeviceConnected* pDev) = 0; - - virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx) = 0; - - virtual int getSerialPortCount() = 0; - - virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; - - virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed - - virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used - - virtual WAN_DONGLE_TYPE getType() = 0; - - static WANDongleInitializer** getInitializers(USBHost* pHost); -}; - -class VodafoneK3770Initializer : public WANDongleInitializer -{ -public: - VodafoneK3770Initializer(USBHost* pHost); - - virtual uint16_t getMSDVid(); - virtual uint16_t getMSDPid(); - - virtual uint16_t getSerialVid(); - virtual uint16_t getSerialPid(); - - virtual bool switchMode(USBDeviceConnected* pDev); - - virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); - - virtual int getSerialPortCount(); - - virtual void setVidPid(uint16_t vid, uint16_t pid); - - virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed - - virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used - - virtual WAN_DONGLE_TYPE getType(); - -private: - - bool m_hasSwitched; - int m_currentSerialIntf; - int m_endpointsToFetch; -}; - -class VodafoneK3772ZInitializer : public WANDongleInitializer -{ -public: - VodafoneK3772ZInitializer(USBHost* pHost); - - virtual uint16_t getMSDVid(); - virtual uint16_t getMSDPid(); - - virtual uint16_t getSerialVid(); - virtual uint16_t getSerialPid(); - - virtual bool switchMode(USBDeviceConnected* pDev); - - virtual USBEndpoint* getEp(USBDeviceConnected* pDev, int serialPortNumber, bool tx); - - virtual int getSerialPortCount(); - - virtual void setVidPid(uint16_t vid, uint16_t pid); - - virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed - - virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used - - virtual WAN_DONGLE_TYPE getType(); - -private: - - bool m_hasSwitched; - int m_currentSerialIntf; - int m_endpointsToFetch; -}; - -#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.cpp b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.cpp deleted file mode 100644 index d7551c264d..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.cpp +++ /dev/null @@ -1,122 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#include "USBDeviceConnected.h" - -USBDeviceConnected::USBDeviceConnected() { - init(); -} - -void USBDeviceConnected::init() { - hub = 0; - port = 0; - vid = 0; - pid = 0; - nb_interf = 0; - enumerated = false; - activeAddr = false; - sizeControlEndpoint = 8; - device_class = 0; - device_subclass = 0; - proto = 0; - speed = false; - for (int i = 0; i < MAX_INTF; i++) { - memset((void *)&intf[i], 0, sizeof(INTERFACE)); - intf[i].in_use = false; - for (int j = 0; j < MAX_ENDPOINT_PER_INTERFACE; j++) { - intf[i].ep[j] = NULL; - } - } -} - -INTERFACE * USBDeviceConnected::getInterface(uint8_t index) { - if (index >= MAX_INTF) { - return NULL; - } - return &intf[index]; -} - -bool USBDeviceConnected::addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) { - if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use)) { - return false; - } - intf[intf_nb].in_use = true; - intf[intf_nb].intf_class = intf_class; - intf[intf_nb].intf_subclass = intf_subclass; - intf[intf_nb].intf_protocol = intf_protocol; - intf[intf_nb].nb_endpoint = 0; - nb_interf++; - return true; -} - -bool USBDeviceConnected::addEndpoint(uint8_t intf_nb, USBEndpoint * ept) { - if ((intf_nb >= MAX_INTF) || (intf[intf_nb].in_use == false) || (intf[intf_nb].nb_endpoint >= MAX_ENDPOINT_PER_INTERFACE)) { - return false; - } - intf[intf_nb].nb_endpoint++; - - for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) { - if (intf[intf_nb].ep[i] == NULL) { - intf[intf_nb].ep[i] = ept; - return true; - } - } - return false; -} - -void USBDeviceConnected::init(uint8_t hub, uint8_t port, bool lowSpeed) { - init(); - this->hub = hub; - this->port = port; - this->speed = lowSpeed; -} - -void USBDeviceConnected::disconnect() { - for(int i = 0; i < nb_interf; i++) { - intf[i].detach.call(); - } - init(); -} - - - -USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index) { - if (intf_nb >= MAX_INTF) { - return NULL; - } - for (int i = 0; i < MAX_ENDPOINT_PER_INTERFACE; i++) { - if ((intf[intf_nb].ep[i]->getType() == type) && (intf[intf_nb].ep[i]->getDir() == dir)) { - if(index) - { - index--; - } - else - { - return intf[intf_nb].ep[i]; - } - } - } - return NULL; -} - -USBEndpoint * USBDeviceConnected::getEndpoint(uint8_t intf_nb, uint8_t index) { - if ((intf_nb >= MAX_INTF) || (index >= MAX_ENDPOINT_PER_INTERFACE)) { - return NULL; - } - return intf[intf_nb].ep[index]; -} diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.h deleted file mode 100644 index 86a333e1e3..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBDeviceConnected.h +++ /dev/null @@ -1,205 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USBDEVICECONNECTED_H -#define USBDEVICECONNECTED_H - -#include "stdint.h" -#include "USBEndpoint.h" - -#define MAX_ENDPOINT_PER_INTERFACE 2 -#define MAX_INTF 2 - -typedef struct { - bool in_use; - uint8_t nb_endpoint; - uint8_t intf_class; - uint8_t intf_subclass; - uint8_t intf_protocol; - USBEndpoint * ep[MAX_ENDPOINT_PER_INTERFACE]; - FunctionPointer detach; -}INTERFACE; - - -class USBDeviceConnected { -public: - - /* - * Constructor - */ - USBDeviceConnected(); - - /* - * Attach an USBEndpoint to this device - * - * @param ep pointeur on the USBEndpoint which will be attached - * @returns true if successful, false otherwise - */ - bool addEndpoint(uint8_t intf_nb, USBEndpoint * ep); - - /* - * Retrieve an USBEndpoint by its TYPE and DIRECTION - * - * @param intf_nb the interface on which to lookup the USBEndpoint - * @param type type of the USBEndpoint looked for - * @param direction of the USBEndpoint looked for - * @param index the index of the USBEndpoint whitin the interface - * @returns pointer on the USBEndpoint if found, NULL otherwise - */ - USBEndpoint * getEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint8_t index = 0); - - /* - * Retrieve an USBEndpoint by its index - * - * @param index index of the USBEndpoint - * @returns pointer on the USBEndpoint if found, NULL otherwise - */ - USBEndpoint * getEndpoint(uint8_t intf_nb, uint8_t index); - - bool addInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); - - uint8_t getNbInterface() {return nb_interf;}; - - INTERFACE * getInterface(uint8_t index); - - /** - * Attach a member function to call when a the device has been disconnected - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template - void onDisconnect(uint8_t intf_nb, T* tptr, void (T::*mptr)(void)) { - if ((mptr != NULL) && (tptr != NULL)) { - intf[intf_nb].detach.attach(tptr, mptr); - } - } - - /** - * Attach a callback called when the device has been disconnected - * - * @param fptr function pointer - */ - void onDisconnect(uint8_t intf_nb, void (*fn)(void)) { - if (fn != NULL) { - intf[intf_nb].detach.attach(fn); - } - } - - /* - * Disconnect the device by calling a callback function registered by a driver - */ - void disconnect(); - - /* - * Setters - */ - void init(uint8_t hub, uint8_t port, bool lowSpeed); - void setAddress(uint8_t addr) { - this->addr = addr; - }; - void setVid(uint16_t vid) { - this->vid = vid; - }; - void setPid(uint16_t pid) { - this->pid = pid; - }; - void setClass(uint8_t device_class) { - this->device_class = device_class; - }; - void setSubClass(uint8_t device_subclass) { - this->device_subclass = device_subclass; - }; - void setProtocol(uint8_t pr) { - proto = pr; - }; - void setSizeControlEndpoint(uint32_t size) { - sizeControlEndpoint = size; - }; - void activeAddress() { - activeAddr = true; - }; - void setEnumerated() { - enumerated = true; - }; - - /* - * Getters - */ - uint8_t getPort() { - return port; - }; - uint8_t getHub() { - return hub; - }; - uint8_t getAddress() { - return addr; - }; - uint16_t getVid() { - return vid; - }; - uint16_t getPid() { - return pid; - }; - uint8_t getClass() { - return device_class; - }; - uint8_t getSubClass() { - return device_subclass; - }; - uint8_t getProtocol() { - return proto; - }; - bool getSpeed() { - return speed; - }; - uint32_t getSizeControlEndpoint() { - return sizeControlEndpoint; - }; - bool isActiveAddress() { - return activeAddr; - }; - bool isEnumerated() { - return enumerated; - }; - - -private: - INTERFACE intf[MAX_INTF]; - //USBEndpoint * ep[MAX_ENDPOINT_PER_DEVICE]; - uint32_t sizeControlEndpoint; - uint8_t hub; - uint8_t port; - uint16_t vid; - uint16_t pid; - uint8_t addr; - uint8_t device_class; - uint8_t device_subclass; - uint8_t proto; - bool speed; - bool activeAddr; - bool enumerated; - - uint8_t nb_interf; - - - void init(); - -}; - -#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.cpp b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.cpp deleted file mode 100644 index c4860d45ec..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.cpp +++ /dev/null @@ -1,233 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - - -#define __DEBUG__ 0 //Maximum verbosity -#ifndef __MODULE__ -#define __MODULE__ "USBEndpoint.cpp" -#endif - -#include "core/dbg.h" -#include - -#include "USBEndpoint.h" - - -void USBEndpoint::init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]) { - this->hced = hced; - this->type = type; - this->dir = /*(type == CONTROL_ENDPOINT) ? OUT :*/ dir; - setup = (type == CONTROL_ENDPOINT) ? true : false; - - //TDs have been allocated by the host - memcpy((HCTD**)this->td_list, td_list, sizeof(HCTD*)*2); //TODO: Maybe should add a param for td_list size... at least a define - memcpy(td_list[0], 0, sizeof(HCTD)); - memcpy(td_list[1], 0, sizeof(HCTD)); - - this->hced->control = 0; - //Empty queue - this->hced->tailTD = (uint32_t)td_list[0]; - this->hced->headTD = (uint32_t)td_list[0]; - this->hced->nextED = 0; - - this->hced->control = ((ep_number & 0x7F) << 7) // Endpoint address - | (type != CONTROL_ENDPOINT ? ( dir << 11) : 0 ) // direction : Out = 1, 2 = In - | ((size & 0x3ff) << 16); // MaxPkt Size - - //carry = false; - transfer_len = 0; - transferred = 0; - buf_start = 0; - nextEp = NULL; - - td_current = td_list[0]; - td_next = td_list[1]; - - state = USB_TYPE_IDLE; -} - -void USBEndpoint::setSize(uint32_t size) { - hced->control &= ~(0x3ff << 16); - hced->control |= (size << 16); -} - - -uint32_t USBEndpoint::getSize() { - return (hced->control >> 16) & 0x3ff; -} - -void USBEndpoint::setDeviceAddress(uint8_t addr) { - hced->control &= ~(0x7f); - hced->control |= (addr & 0x7F); -} - -uint8_t USBEndpoint::getDeviceAddress() { - return hced->control & 0x7f; -} - -void USBEndpoint::setSpeed(uint8_t speed) { - if(speed) { - DBG("SET LOW SPEED"); - } - hced->control &= ~(1 << 13); - hced->control |= (speed << 13); -} - - -void USBEndpoint::setNextToken(uint32_t token) { //Only for control Eps - switch (token) { - case TD_SETUP: - dir = OUT; - setup = true; - break; - case TD_IN: - dir = IN; - setup = false; - break; - case TD_OUT: - dir = OUT; - setup = false; - break; - } -} - -volatile HCTD* USBEndpoint::getNextTD() -{ - return td_current/*(HCTD*) hced->tailTD*/; //It's the tailing one -} - -void USBEndpoint::queueTransfer() { - //Try with OHCI impl - //Caller of getNextTD() has now populated the td - //So insert it into queue - - //Find an OTHER free td - //TODO: if we had more than 2 tds, this would have to be changed - /*HCTD* toSendTD = (HCTD*) hced->tailTD;*/ - //HCTD* freeTD; -/* - if( hced->tailTD == td_list[0] ) - { - freeTD = td_list[1]; - } - else *//*if( hced->tailTD == (uint32_t) td_list[1] )*/ - /*{ - freeTD = td_list[0]; - } - */ - - /* - freeTD->control = 0; - freeTD->currBufPtr = 0; - freeTD->bufEnd = 0; - freeTD->nextTD = 0; - - td_current = toSendTD; -*/ - transfer_len = td_current->bufEnd - td_current->currBufPtr + 1; - transferred = transfer_len; - buf_start = td_current->currBufPtr; - - //No add this free TD at this end of the queue - state = USB_TYPE_PROCESSING; - td_current->nextTD = (volatile uint32_t)td_next; - hced->tailTD = (volatile uint32_t)td_next; - - #if 0 - // if TD list empty -> we put the head of the list - if (!hced->headTD) { - state = USB_TYPE_IDLE; - hced->headTD = (uint32_t)(td); - hced->tailTD = (uint32_t)(td); - tailTD = (HCTD *) (hced->headTD); - //DBG("queue null transfer: endpoint: %p, %08X\r\n", this, (uint32_t)(td)); - } else { - state = USB_TYPE_PROCESSING; - td->nextTD = (uint32_t)headTD & ~(0x0f); - hced->headTD = (uint32_t)(td) | ((carry) ? 0x2 : 0); - } - headTD = (HCTD *) ((hced->headTD) & ~(0x3)); - transfer_len = td->bufEnd - td->currBufPtr + 1; - transferred = transfer_len; - buf_start = td->currBufPtr; -#endif - //printf("queue real transfer: endpoint: %p \t headTD: %p \t head: %08X \t tail: %08X \t td: %08X \t nexttd: %08X\r\n", this, hced->headTD, hced->headTD, ((HCTD *)((hced->headTD) & ~(0x0f)))->nextTD, toSendTD, toSendTD->nextTD); -} - -volatile HCTD * USBEndpoint::getProcessedTD() -{ - return td_current; -} - -void USBEndpoint::setLengthTransferred(int len) { - transferred = len; -} - -uint32_t USBEndpoint::getBufStart() { - return buf_start; -} - -void USBEndpoint::unqueueTransfer(volatile HCTD * td) { - //printf("unqueue transfer: %p on endpoint: %p\r\n", (void *)td, this); - //headTD = tailTD; //FIXME FIXME -// hced->headTD = hced->headTD | (td-> & 0x02); - if(td != td_current) - { - ERR("MISMATCH"); - ERR("this=%p, td_current = %p, td_next=%p, td=%p", this, td_current, td_next, td); - error(""); - } - td->control=0; - td->currBufPtr=0; - td->bufEnd=0; - td->nextTD=0; - hced->headTD = hced->tailTD | (hced->headTD & 0x2); //Carry bit - td_current = td_next; - td_next = td; - DBG("current:%p, next:%p", td_current, td_next); -} - -ENDPOINT_TYPE USBEndpoint::getType() { - return type; -} - - -USBEndpoint * USBEndpoint::nextEndpoint() { - return (USBEndpoint*)nextEp; -} - - -void USBEndpoint::queueEndpoint(USBEndpoint * ed) { - nextEp = ed; - hced->nextED = (ed == NULL) ? 0 : (uint32_t)ed->getHCED(); -} - -volatile HCED * USBEndpoint::getHCED() { - return hced; -} - - -volatile HCTD * USBEndpoint::getHeadTD() { - //return headTD; - return (volatile HCTD*) (hced->headTD & ~0xF); -} - -volatile HCTD ** USBEndpoint::getTDList() -{ - return td_list; -} diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.h deleted file mode 100644 index 18a6028ddc..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBEndpoint.h +++ /dev/null @@ -1,189 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USBENDPOINT_H -#define USBENDPOINT_H - -#include "stdint.h" -#include "FunctionPointer.h" -#include "USBHostTypes.h" - - -enum ENDPOINT_TYPE { - CONTROL_ENDPOINT = 0, - ISOCHRONOUS_ENDPOINT, - BULK_ENDPOINT, - INTERRUPT_ENDPOINT -}; - -enum ENDPOINT_DIRECTION { - OUT = 1, - IN -}; - -class USBEndpoint { -public: - /* - * Constructor - */ - USBEndpoint() {state = USB_TYPE_FREE; nextEp = NULL;}; - - /* - * Initialize an endpoint - * - * @param hced hced associated to the endpoint - * @param type endpoint type - * @param dir endpoint direction - * @param size endpoint size - * @param ep_number endpoint number - */ - void init(HCED * hced, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t ep_number, HCTD* td_list[2]); - - /* - * Set next token. Warining: only useful for the control endpoint - * - * @param token IN, OUT or SETUP token - */ - void setNextToken(uint32_t token); - - /* - * Queue an endpoint - * - * endpoint endpoint which will be queued in the linked list - */ - void queueEndpoint(USBEndpoint * endpoint); - - /* - * Get a td to be queued - * - * @returns td hctd which will be queued - */ - volatile HCTD* getNextTD(); - - /* - * Queue a transfer on the endpoint - * - */ - void queueTransfer(); - - /* - * Get the currently processed td - * - * @returns td hctd that was queued - */ - volatile HCTD * getProcessedTD(); - - /* - * Unqueue a transfer from the endpoint - * - * @param td hctd which will be unqueued - */ - void unqueueTransfer(volatile HCTD * td); - - /* - * Return the next endpoint in the linked list - * - * @returns next endpoint - */ - USBEndpoint * nextEndpoint(); - - /** - * Attach a member function to call when a transfer is finished - * - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template - void attach(T* tptr, void (T::*mptr)(void)) { - if((mptr != NULL) && (tptr != NULL)) { - rx.attach(tptr, mptr); - } - } - - /** - * Attach a callback called when a transfer is finished - * - * @param fptr function pointer - */ - void attach(void (*fn)(void)) { - if(fn != NULL) { - rx.attach(fn); - } - } - - /* - * Call the handler associted to the end of a transfer - */ - void call() { - rx.call(); - }; - - - /* - * Setters - */ - void setState(USB_TYPE st) {state = st;} - void setDeviceAddress(uint8_t addr); - void setLengthTransferred(int len); - void setSpeed(uint8_t speed); - void setSize(uint32_t size); - void setDir(ENDPOINT_DIRECTION d) {dir = d;} - - /* - * Getters - */ - USB_TYPE getState() {return state;} - ENDPOINT_TYPE getType(); - uint8_t getDeviceAddress(); - int getLengthTransferred() {return transferred;} - uint32_t getBufStart(); - uint32_t getSize(); - volatile HCTD * getHeadTD(); - volatile HCTD** getTDList(); - volatile HCED * getHCED(); - ENDPOINT_DIRECTION getDir() {return dir;} - bool isSetup() {return setup;} - - -private: - ENDPOINT_TYPE type; - volatile USB_TYPE state; - ENDPOINT_DIRECTION dir; - bool setup; - - int transfer_len; - int transferred; - uint32_t buf_start; - - FunctionPointer rx; - - USBEndpoint* nextEp; - - // USBEndpoint descriptor - volatile HCED * hced; - - volatile HCTD * td_list[2]; - volatile HCTD * td_current; - volatile HCTD * td_next; - /*bool carry;*/ - - int count; - -}; - -#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.cpp b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.cpp deleted file mode 100644 index 4d7a202456..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.cpp +++ /dev/null @@ -1,404 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#define __DEBUG__ 0 //WARN: ENABLING DEBUGGING HERE WILL PRINTF IN IRQS!! UNEXPECTED BEHAVIOUR MAY RESULT... -#ifndef __MODULE__ -#define __MODULE__ "USBHALHost.cpp" -#endif - -#include "core/dbg.h" -#include - -#include "mbed.h" -#include "USBHALHost.h" - -// bits of the USB/OTG clock control register -#define HOST_CLK_EN (1<<0) -#define DEV_CLK_EN (1<<1) -#define PORTSEL_CLK_EN (1<<3) -#define AHB_CLK_EN (1<<4) - -// bits of the USB/OTG clock status register -#define HOST_CLK_ON (1<<0) -#define DEV_CLK_ON (1<<1) -#define PORTSEL_CLK_ON (1<<3) -#define AHB_CLK_ON (1<<4) - -// we need host clock, OTG/portsel clock and AHB clock -#define CLOCK_MASK (HOST_CLK_EN | PORTSEL_CLK_EN | AHB_CLK_EN) - - - -#define HCCA_SIZE 0x100 -#define ED_SIZE 0x10 -#define TD_SIZE 0x10 - -#define TOTAL_SIZE (HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE) + (MAX_TD*TD_SIZE)) - -static volatile uint8_t usb_buf[TOTAL_SIZE] __attribute((section("AHBSRAM1"),aligned(256))); //256 bytes aligned! - -USBHALHost * USBHALHost::instHost; - -USBHALHost::USBHALHost() : thread(USBHALHost::staticCb, (void*)this, osPriorityNormal, 4*128) { - instHost = this; - memInit(); - memset((void*)usb_hcca, 0, HCCA_SIZE); - for (int i = 0; i < MAX_ENDPOINT; i++) { - edBufAlloc[i] = false; - } - for (int i = 0; i < MAX_TD; i++) { - tdBufAlloc[i] = false; - } -} - - -void USBHALHost::init() { - thread.signal_set(USBHALHOST_SIG_INIT); -} - - -uint32_t USBHALHost::controlHeadED() { - return LPC_USB->HcControlHeadED; -} - -uint32_t USBHALHost::bulkHeadED() { - return LPC_USB->HcBulkHeadED; -} - -uint32_t USBHALHost::interruptHeadED() { - return usb_hcca->IntTable[0]; -} - -void USBHALHost::updateBulkHeadED(uint32_t addr) { - LPC_USB->HcBulkHeadED = addr; -} - - -void USBHALHost::updateControlHeadED(uint32_t addr) { - LPC_USB->HcControlHeadED = addr; -} - -void USBHALHost::updateInterruptHeadED(uint32_t addr) { - usb_hcca->IntTable[0] = addr; -} - - -void USBHALHost::enableControlList() { - LPC_USB->HcCommandStatus = OR_CMD_STATUS_CLF; - LPC_USB->HcControl |= OR_CONTROL_CLE; //Enable control list -} - -void USBHALHost::enableBulkList() { - LPC_USB->HcCommandStatus = OR_CMD_STATUS_BLF; - LPC_USB->HcControl |= OR_CONTROL_BLE; //Enable bulk list -} - -void USBHALHost::enableInterruptList() { - LPC_USB->HcControl |= OR_CONTROL_PLE; -} - -bool USBHALHost::disableControlList() { - if(LPC_USB->HcControl & OR_CONTROL_CLE) - { - LPC_USB->HcControl &= ~OR_CONTROL_CLE; //Disable control list - return true; - } - else - { - return false; - } -} - -bool USBHALHost::disableBulkList() { - if(LPC_USB->HcControl & OR_CONTROL_BLE) - { - LPC_USB->HcControl &= ~OR_CONTROL_BLE; //Disable bulk list - return true; - } - else - { - return false; - } -} - -bool USBHALHost::disableInterruptList() { - if(LPC_USB->HcControl & OR_CONTROL_PLE) - { - LPC_USB->HcControl &= ~OR_CONTROL_PLE; //Disable interrupt list - return true; - } - else - { - return false; - } -} - -//Lock processing -void USBHALHost::lock() -{ - mtx.lock(); -} - -void USBHALHost::unlock() -{ - mtx.unlock(); -} - -void USBHALHost::memInit() { - usb_hcca = (volatile HCCA *)usb_buf; - usb_edBuf = usb_buf + HCCA_SIZE; - usb_tdBuf = usb_buf + HCCA_SIZE + (MAX_ENDPOINT*ED_SIZE); -} - -volatile uint8_t * USBHALHost::getED() { - for (int i = 0; i < MAX_ENDPOINT; i++) { - if ( !edBufAlloc[i] ) { - edBufAlloc[i] = true; - return (volatile uint8_t *)(usb_edBuf + i*ED_SIZE); - } - } - perror("Could not allocate ED\r\n"); - return NULL; //Could not alloc ED -} - -volatile uint8_t * USBHALHost::getTD() { - int i; - for (i = 0; i < MAX_TD; i++) { - if ( !tdBufAlloc[i] ) { - tdBufAlloc[i] = true; - return (volatile uint8_t *)(usb_tdBuf + i*TD_SIZE); - } - } - perror("Could not allocate TD\r\n"); - return NULL; //Could not alloc TD -} - - -void USBHALHost::freeED(volatile uint8_t * ed) { - int i; - i = (ed - usb_edBuf) / ED_SIZE; - edBufAlloc[i] = false; -} - -void USBHALHost::freeTD(volatile uint8_t * td) { - int i; - i = (td - usb_tdBuf) / TD_SIZE; - tdBufAlloc[i] = false; -} - - -void USBHALHost::resetPort(int hub, int port) { - DBG("Resetting hub %d, port %d\n", hub, port); - if (hub == 0) { //Root hub - // USB 2.0 spec says at least 50ms delay before port reset - Thread::wait(200); - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset - while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS); - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal - // Wait for 100 MS after port reset - Thread::wait(200); - } else { - //TODO: Hubs - } -} - - -void USBHALHost::_usbisr(void) { - if (instHost) { - instHost->UsbIrqhandler(); - } -} - -void USBHALHost::UsbIrqhandler() { - if( LPC_USB->HcInterruptStatus & LPC_USB->HcInterruptEnable ) //Is there something to actually process? - { - NVIC_DisableIRQ(USB_IRQn); - NVIC_ClearPendingIRQ(USB_IRQn); - thread.signal_set(USBHALHOST_SIG_IRQ); //Signal processing thread - } - -} - -void USBHALHost::process() -{ - DBG("USB Process started"); - - lock(); - Thread::signal_wait(USBHALHOST_SIG_INIT); - - NVIC_DisableIRQ(USB_IRQn); // Disable the USB interrupt source - - LPC_SC->PCONP &= ~(1UL<<31); //Cut power - Thread::wait(200); - - // turn on power for USB - LPC_SC->PCONP |= (1UL<<31); - - // Enable USB host clock, port selection and AHB clock - LPC_USB->USBClkCtrl |= CLOCK_MASK; - - // Wait for clocks to become available - while ((LPC_USB->USBClkSt & CLOCK_MASK) != CLOCK_MASK); - - // it seems the bits[0:1] mean the following - // 0: U1=device, U2=host - // 1: U1=host, U2=host - // 2: reserved - // 3: U1=host, U2=device - // NB: this register is only available if OTG clock (aka "port select") is enabled!! - // since we don't care about port 2, set just bit 0 to 1 (U1=host) - LPC_USB->OTGStCtrl |= 1; - - // now that we've configured the ports, we can turn off the portsel clock - LPC_USB->USBClkCtrl &= ~PORTSEL_CLK_EN; - - // configure USB D+/D- pins - // P0[29] = USB_D+, 01 - // P0[30] = USB_D-, 01 - LPC_PINCON->PINSEL1 &= ~((3<<26) | (3<<28)); - LPC_PINCON->PINSEL1 |= ((1<<26)|(1<<28)); // 0x14000000 - - LPC_USB->HcControl = 0; // HARDWARE RESET - LPC_USB->HcControlHeadED = 0; // Initialize Control list head to Zero - LPC_USB->HcBulkHeadED = 0; // Initialize Bulk list head to Zero - - //wait_ms(100); // Wait 50 ms before apply reset - Thread::wait(100); - - // SOFTWARE RESET - LPC_USB->HcCommandStatus = OR_CMD_STATUS_HCR; - LPC_USB->HcFmInterval = DEFAULT_FMINTERVAL; // Write Fm Interval and Largest Data Packet Counter - LPC_USB->HcPeriodicStart = FI * 90 / 100; - - // Put HC in operational state - LPC_USB->HcControl = (LPC_USB->HcControl & (~OR_CONTROL_HCFS)) | OR_CONTROL_HC_OPER; - LPC_USB->HcRhStatus = OR_RH_STATUS_LPSC; // Set Global Power - - LPC_USB->HcHCCA = (uint32_t)(usb_hcca); - LPC_USB->HcInterruptStatus |= LPC_USB->HcInterruptStatus; // Clear Interrrupt Status - - LPC_USB->HcInterruptEnable = OR_INTR_ENABLE_MIE | OR_INTR_ENABLE_WDH | OR_INTR_ENABLE_RHSC; - - //DG: Do not set prio - //NVIC_SetPriority(USB_IRQn, 0); // highest priority - // Enable the USB Interrupt - NVIC_SetVector(USB_IRQn, (uint32_t)(_usbisr)); - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC; - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; - - NVIC_EnableIRQ(USB_IRQn); - - - // Check for any connected devices - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) { //Root device connected - //Device connected - Thread::wait(500); - DBG("Device connected (%08x)\n\r", LPC_USB->HcRhPortStatus1); - deviceConnected(0, 1, LPC_USB->HcRhPortStatus1 & OR_RH_PORT_LSDA); //Hub 0 (root hub), Port 1 (count starts at 1), Low or High speed - } - - unlock(); - - - for(;;) - { - Thread::signal_wait(USBHALHOST_SIG_IRQ); //Wait for IRQ to process - - lock(); - DBG("Locked"); - - WARN("isr %08x [EN %08x]", LPC_USB->HcInterruptStatus, LPC_USB->HcInterruptEnable); - - //Now process IRQ - uint32_t int_status = LPC_USB->HcInterruptStatus & LPC_USB->HcInterruptEnable; - - if (int_status & OR_INTR_STATUS_RHSC) - { // Root hub status change interrupt - WARN("Port status %08x", LPC_USB->HcRhPortStatus1); - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CSC) - { - if (LPC_USB->HcRhStatus & OR_RH_STATUS_DRWE) - { - - // When DRWE is on, Connect Status Change - // means a remote wakeup event. - - } - else - { - - // When DRWE is off, Connect Status Change - // is NOT a remote wakeup event - - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_CCS) - { //Root device connected - //Device connected - WARN("Device connected!!"); - // Thread::wait(500); - deviceConnected(0, 1, LPC_USB->HcRhPortStatus1 & OR_RH_PORT_LSDA); //Hub 0 (root hub), Port 1 (count starts at 1), Low or High speed - } - else - { //Root device disconnected - //Device disconnected - WARN("Device disconnected!!"); - Thread::wait(500); - if (!(int_status & OR_INTR_STATUS_WDH)) - { - usb_hcca->DoneHead = 0; - } - deviceDisconnected(0, 1, usb_hcca->DoneHead & 0xFFFFFFFE); - if (int_status & OR_INTR_STATUS_WDH) - { - usb_hcca->DoneHead = 0; - LPC_USB->HcInterruptStatus = OR_INTR_STATUS_WDH; - } - - } - //TODO: HUBS - } - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_CSC; - } - if (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRSC) - { - LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; - //int_status &= ~OR_RH_PORT_PRSC; - } - LPC_USB->HcInterruptStatus = OR_INTR_STATUS_RHSC; - } - - if (int_status & OR_INTR_STATUS_WDH) - { // Writeback Done Head interrupt - transferCompleted(usb_hcca->DoneHead & 0xFFFFFFFE); - LPC_USB->HcInterruptStatus = OR_INTR_STATUS_WDH; - } - - //IRQ Processed - - DBG("Unlocked"); - - NVIC_EnableIRQ(USB_IRQn); - - unlock(); - - } -} - -/*static*/ void USBHALHost::staticCb(void const* p) -{ - ((USBHALHost*)p)->process(); -} diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.h deleted file mode 100644 index c72a63a999..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHALHost.h +++ /dev/null @@ -1,206 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USBHALHOST_H -#define USBHALHOST_H - -#include "rtos.h" - -#include "USBHostTypes.h" - -#define MAX_ENDPOINT 5 -#define MAX_TD (MAX_ENDPOINT*2) - -#define USBHALHOST_SIG_INIT 0x01 -#define USBHALHOST_SIG_IRQ 0x02 - -class USBHALHost { -public: - - /* - * Constructor - * init variables and memory where will be stored HCCA, ED and TD - */ - USBHALHost(); - - /* - * Initialize host controller. Enable USB interrupts. This part is not in the constructor because, - * this function calls a virtual method if a device is already connected - */ - void init(); - - /* - * reset a port of a specific hub - * TODO: support hub - */ - void resetPort(int hub, int port); - - /* - * return the value contained in the control HEAD ED register - * - * @returns address of the control Head ED - */ - uint32_t controlHeadED(); - - /* - * return the value contained in the bulk HEAD ED register - * - * @returns address of the bulk head ED - */ - uint32_t bulkHeadED(); - - /* - * return the value of the head interrupt ED contained in the HCCA - * - * @returns address of the head interrupt ED contained in the HCCA - */ - uint32_t interruptHeadED(); - - - /* - * Update the head ED for control transfers - */ - void updateControlHeadED(uint32_t addr); - - /* - * Update the head ED for bulk transfers - */ - void updateBulkHeadED(uint32_t addr); - - /* - * Update the head ED for interrupt transfers - */ - void updateInterruptHeadED(uint32_t addr); - - /* - * Enable control list ED - */ - void enableControlList(); - - /* - * Enable bulk list ED - */ - void enableBulkList(); - - /* - * Enable Interrupt list ED - */ - void enableInterruptList(); - - /* - * Disable control list ED - */ - bool disableControlList(); - - /* - * Disable bulk list ED - */ - bool disableBulkList(); - - /* - * Disable Interrupt list ED - */ - bool disableInterruptList(); - - //Lock processing - void lock(); - - void unlock(); - - -protected: - /* - * Virtual method called when a device has been connected - * - * @param hub hub number of the device - * @param port port number of the device - * @param lowSpeed 1 if low speed, 0 otherwise - */ - virtual void deviceConnected(int hub, int port, bool lowSpeed) {}; - - /* - * Virtuel method called when a device has been disconnected - * - * @param hub hub number of the device - * @param port port number of the device - * @param addr list of the TDs which have been completed to dequeue freed TDs - */ - virtual void deviceDisconnected(int hub, int port, volatile uint32_t addr) {}; - - /* - * Virtual method called when a transfer has been completed - * - * @param addr list of the TDs which have been completed - */ - virtual void transferCompleted(volatile uint32_t addr){}; - - /* - * Find a memory section for a new ED - * - * @returns the address of this section - */ - volatile uint8_t * getED(); - - /* - * Find a memory section for a new TD - * - * @returns the address of this section - */ - volatile uint8_t * getTD(); - - /* - * Release a previous memory section reserved for an ED - * - * @param ed address of the ED - */ - void freeED(volatile uint8_t * ed); - - /* - * Release a previous memory section reserved for an TD - * - * @param ed address of the TD - */ - void freeTD(volatile uint8_t * td); - - -private: - static void _usbisr(void); - void UsbIrqhandler(); - - void memInit(); - - void process(); - - static void staticCb(void const* p); - - HCCA volatile * usb_hcca; //256 bytes aligned! - uint8_t volatile * usb_edBuf; //4 bytes aligned! - uint8_t volatile * usb_tdBuf; //4 bytes aligned! - - static USBHALHost * instHost; - - bool volatile edBufAlloc[MAX_ENDPOINT]; - bool volatile tdBufAlloc[MAX_TD]; - - //RTOS impl - Thread thread; - Mutex mtx; - -}; - -#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.cpp b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.cpp deleted file mode 100644 index f5bcbaecfe..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.cpp +++ /dev/null @@ -1,960 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#define __DEBUG__ 0 //WARN: ENABLING DEBUGGING HERE WILL PRINTF IN IRQS!! UNEXPECTED BEHAVIOUR MAY RESULT... -#ifndef __MODULE__ -#define __MODULE__ "USBHost.cpp" -#endif - -#include "core/dbg.h" -#include - -#include "USBHost.h" -#include "rtos.h" - - -#define NB_MAX_INTF 2 - -USBHost * USBHost::instHost = NULL; - -USBHost::USBHost() -#if 0 //try not to use this - : m_usbQueue(), m_usbThread(3, this, &USBHost::usbProcess) -#endif -{ - headControlEndpoint = NULL; - headBulkEndpoint = NULL; - headInterruptEndpoint = NULL; - tailControlEndpoint = NULL; - tailBulkEndpoint = NULL; - tailInterruptEndpoint = NULL; - - nb_devices = 0; - lenReportDescr = 0; - - controlEndpointAllocated = false; - - for (int i = 0; i < MAX_DEVICE_NB; i++) { - deviceInUse[i] = false; - devices[i].setAddress(i + 1); - deviceReset[i] = false; - } -} - - -void USBHost::transferCompleted(volatile uint32_t addr) { -#if 0 //try not to use this - Interrupt::enter(); - m_usbQueue.post(addr); - Interrupt::leave(); -#else - - if(addr == NULL) //Nothing to process? - { - return; - } - - volatile HCTD* tdList = NULL; - - //First we must reverse the list order and dequeue each TD - do - { - volatile HCTD* td = (volatile HCTD*)addr; - - if(td->control & 0xF0000000 != 0) - { - WARN("Condition code %02x", td->control >> 28); - } - - addr = td->nextTD; //Dequeue from physical list - td->nextTD = (uint32_t)tdList; //Enqueue into reversed list - tdList = td; - } while(addr); - - //Now we can process the list - USBEndpoint * volatile iter = NULL; - - while(tdList != NULL) - { - bool found = false; - volatile HCTD* td = tdList; - tdList = (volatile HCTD*)td->nextTD; //Dequeue element now as it could be modified below - for (int i = 0; i < 3; i++) { - if (found) { - break; - } - iter = (i == 0) ? headControlEndpoint : ( (i == 1) ? headBulkEndpoint : headInterruptEndpoint); - while (iter != NULL) { - if (iter->getProcessedTD() == td) { - DBG("td=%p FOUND ed: %08X", td, (void *)iter->getHCED()); - if (((HCTD *)td)->control >> 28) { - DBG("TD Error: %d", td->control >> 28); - iter->setState(USB_TYPE_TDFAIL); - } else if ((uint32_t)iter->getHCED() & 0x1) { - DBG("HALTED"); - iter->setState(USB_TYPE_HALTED); - } else if (!td->currBufPtr) { - DBG("!%p", iter); - iter->setState(USB_TYPE_IDLE); - found=true; - } else { - DBG("!%p", iter); - iter->setState(USB_TYPE_IDLE); - iter->setLengthTransferred(td->currBufPtr - iter->getBufStart()); - found=true; - } - break; - } - iter = iter->nextEndpoint(); - } - } - - - if (found) { - iter->unqueueTransfer(td); - - if (iter->getType() != CONTROL_ENDPOINT) { - iter->call(); - } - } - else - { - WARN("TD not found!!!"); - freeTD((uint8_t *)td); //Device must have been disconnected meanwhile - } - - } -#endif -} - -USBHost * USBHost::getHostInst() { - if (instHost == NULL) { - instHost = new USBHost(); - instHost->init(); - } - return instHost; -} - - -/* - * Call in ISR when a device has been connected - */ -void USBHost::deviceConnected(int hub, int port, bool lowSpeed) { - - for (int i = 0; i < MAX_DEVICE_NB; i++) { - if (!deviceInUse[i]) { - deviceInUse[i] = true; - WARN("will call init on device %p: speed: %d", (void *)&devices[i], lowSpeed); - devices[i].init(hub, port, lowSpeed); - deviceReset[i] = false; - break; - } - } - - if (!controlEndpointAllocated) { - control = newEndpoint(CONTROL_ENDPOINT, OUT, 0x08, 0x00); - addEndpoint(NULL, 0, (USBEndpoint*)control); - controlEndpointAllocated = true; - } -} - -/* - * Call in ISR when a device has been disconnected - */ -void USBHost::deviceDisconnected(int hub, int port, volatile uint32_t addr) { - - bool controlListState = disableControlList(); - bool bulkListState = disableBulkList(); - bool interruptListState = disableInterruptList(); - - transferCompleted(addr); //Finish processing any pending completed TD - - for (int i = 0; i < MAX_DEVICE_NB; i++) { - if ((devices[i].getHub() == hub) && (devices[i].getPort() == port)) { - WARN("device disconnected: %p", (void *)&devices[i]); - deviceInUse[i] = false; - deviceReset[i] = false; - freeDevice((USBDeviceConnected*)&devices[i]); - break; - } - } - nb_devices--; - - if (controlListState) enableControlList(); - if (bulkListState) enableBulkList(); - if (interruptListState) enableInterruptList(); -} - -void USBHost::freeDevice(USBDeviceConnected * dev) { - USBEndpoint * ep = NULL; -// HCTD * td = NULL; - HCED * ed = NULL; - - for (int j = 0; j < dev->getNbInterface(); j++) { - DBG("FREE INTF %d, %p, nb_endpot: %d", j, (void *)dev->getInterface(j), dev->getInterface(j)->nb_endpoint); - for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) { - if ((ep = dev->getEndpoint(j, i)) != NULL) { - DBG("Freeing USBEndpoint"); - ed = (HCED *)ep->getHCED(); - ed->control |= (1 << 13); //sKip bit - DBG("Dequeueing USBEndpoint"); - unqueueEndpoint(ep); - - DBG("Freeing first transfer descriptor"); - freeTD((volatile uint8_t*)ep->getTDList()[0]); - DBG("Freeing second transfer descriptor"); - freeTD((volatile uint8_t*)ep->getTDList()[1]); - - DBG("Freeing USBEndpoint descriptor"); - freeED((uint8_t *)ep->getHCED()); - } - //printBulk(); - //printInt(); - } - } - DBG("Disconnecting device"); - dev->disconnect(); - DBG("Device disconnected"); -} - - -void USBHost::unqueueEndpoint(USBEndpoint * ep) { - USBEndpoint * prec = NULL; - USBEndpoint * current = NULL; - bool found = false; - - DBG("want to unqueue ep: %p", (void *)ep->getHCED()); - - for (int i = 0; i < 2; i++) { - if (found) { - DBG("USBEndpoint unqueued: %p", (void *)ep->getHCED()); - break; - } - current = (i == 0) ? (USBEndpoint*)headBulkEndpoint : (USBEndpoint*)headInterruptEndpoint; - prec = current; - while (current != NULL) { - if (current == ep) { - if (current->nextEndpoint() != NULL) { - prec->queueEndpoint(current->nextEndpoint()); - if (current == headBulkEndpoint) { - updateBulkHeadED((uint32_t)current->nextEndpoint()->getHCED()); - headBulkEndpoint = current->nextEndpoint(); - } - if (current == headInterruptEndpoint) { - updateInterruptHeadED((uint32_t)current->nextEndpoint()->getHCED()); - headInterruptEndpoint = current->nextEndpoint(); - } - } else { - prec->queueEndpoint(NULL); - if (current == headBulkEndpoint) { - updateBulkHeadED(0); - headBulkEndpoint = current->nextEndpoint(); - } - if (current == headInterruptEndpoint) { - updateInterruptHeadED(0); - headInterruptEndpoint = current->nextEndpoint(); - } - } - found = true; - current->setState(USB_TYPE_FREE); - break; - } - prec = current; - current = current->nextEndpoint(); - } - } - //printBulk(); - //printInt(); -} - - -USBDeviceConnected * USBHost::getDevice(uint8_t index) { - if ((index >= MAX_DEVICE_NB) || (!deviceInUse[index])) { - return NULL; - } - return (USBDeviceConnected*)&devices[index]; -} - - - -// create an USBEndpoint descriptor. the USBEndpoint is not linked -USBEndpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) { - int i = 0; - HCED * ed = (HCED *)getED(); - HCTD* td_list[2] = { (HCTD*)getTD(), (HCTD*)getTD() }; - - memset((void *)td_list[0], 0x00, sizeof(HCTD)); - memset((void *)td_list[1], 0x00, sizeof(HCTD)); - - // search a free USBEndpoint - for (i = 0; i < MAX_ENDPOINT; i++) { - if (endpoints[i].getState() == USB_TYPE_FREE) { - DBG("Trying to create ep"); - endpoints[i].init(ed, type, dir, size, addr, td_list); - //endpoints[i].queueTransfer(nullTd); - DBG("USBEndpoint created (%p): type: %d, dir: %d, size: %d, addr: %d", &endpoints[i], type, dir, size, addr); - return &endpoints[i]; - } - } - DBG("could not allocate more endpoints!!!!"); - return NULL; -} - - -USB_TYPE USBHost::resetDevice(USBDeviceConnected * dev) { - int index = findDevice(dev); - if ((index != -1) && (!deviceReset[index])) { - resetPort(dev->getHub(), dev->getPort()); - deviceReset[index] = true; - return USB_TYPE_OK; - } - return USB_TYPE_NOTFOUND; -} - -// link the USBEndpoint to the linked list and attach an USBEndpoint to a device -bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) { - - if (ep == NULL) { - return false; - } - - DBG("New ep %p", ep); - - HCED * prevEd; - - // set device address in the USBEndpoint descriptor - if (dev == NULL) { - ep->setDeviceAddress(0); - } else { - ep->setDeviceAddress(dev->getAddress()); - } - - if (dev != NULL && dev->getSpeed()) { - DBG("add USBEndpoint: set speed"); - ep->setSpeed(dev->getSpeed()); - } - - // queue the new USBEndpoint on the ED list - switch (ep->getType()) { - - case CONTROL_ENDPOINT: - prevEd = ( HCED*) controlHeadED(); - if (!prevEd) { - updateControlHeadED((uint32_t) ep->getHCED()); - DBG("First control USBEndpoint: %08X", (uint32_t) ep->getHCED()); - headControlEndpoint = ep; - tailControlEndpoint = ep; - return true; - } - tailControlEndpoint->queueEndpoint(ep); - tailControlEndpoint = ep; - return true; - - case BULK_ENDPOINT: - prevEd = ( HCED*) bulkHeadED(); - if (!prevEd) { - updateBulkHeadED((uint32_t) ep->getHCED()); - //DBG("First bulk USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); - headBulkEndpoint = ep; - tailBulkEndpoint = ep; - break; - } - tailBulkEndpoint->queueEndpoint(ep); - tailBulkEndpoint = ep; - break; - - case INTERRUPT_ENDPOINT: - prevEd = ( HCED*) interruptHeadED(); - if (!prevEd) { - updateInterruptHeadED((uint32_t) ep->getHCED()); - //DBG("First interrupt USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); - headInterruptEndpoint = ep; - tailInterruptEndpoint = ep; - break; - } - tailInterruptEndpoint->queueEndpoint(ep); - tailInterruptEndpoint = ep; - break; - default: - return false; - } - - dev->addEndpoint(intf_nb, ep); - //printBulk(); - //printInt(); - - return true; -} - - -int USBHost::findDevice(USBDeviceConnected * dev) { - for (int i = 0; i < MAX_DEVICE_NB; i++) { - if (dev == &devices[i]) { - return i; - } - } - return -1; -} - -void USBHost::printBulk() { - HCED * hced = (HCED *)bulkHeadED(); - HCTD * hctd = NULL; - printf("---------State of Bulk:--------\r\n"); - while (hced != NULL) { - printf("hced: %p\r\n", hced); - hctd = (HCTD *)((uint32_t)(hced->headTD) & ~(0x0f)); - while (((uint32_t)hctd & ~(0x0f)) != ((hced->tailTD) & ~(0x0f))) { - printf("\thctd: %p\r\n", hctd); - hctd = (HCTD *)((uint32_t)(hctd->nextTD) & ~(0x0f)); - } - printf("\thctd: %p\r\n", hctd); - hced = (HCED *)((uint32_t)(hced->nextED) & ~(0x0f)); - } - printf("--------------------\r\n"); -} - -void USBHost::printInt() { - HCED * hced = (HCED *)interruptHeadED(); - HCTD * hctd = NULL; - printf("---------State of Int:--------\r\n"); - while (hced != NULL) { - printf("hced: %p\r\n", hced); - hctd = (HCTD *)((uint32_t)(hced->headTD) & ~(0x0f)); - while (((uint32_t)hctd & ~(0x0f)) != ((hced->tailTD) & ~(0x0f))) { - printf("\thctd: %p\r\n", hctd); - hctd = (HCTD *)((uint32_t)(hctd->nextTD) & ~(0x0f)); - } - printf("\thctd: %p\r\n", hctd); - hced = (HCED *)((uint32_t)(hced->nextED) & ~(0x0f)); - } - printf("--------------------\r\n"); -} - - -// add a transfer on the TD linked list -USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) { - - // allocate a TD which will be freed in TDcompletion - volatile HCTD * td = ed->getNextTD(); - if (td == NULL) { - return USB_TYPE_ERROR; - } - - DBG("Next td = %p",td); - - uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT )); - - uint32_t td_toggle; - - if (ed->getType() == CONTROL_ENDPOINT) { - if (ed->isSetup()) { - td_toggle = TD_TOGGLE_0; - } else { - td_toggle = TD_TOGGLE_1; - } - } else { - td_toggle = 0; - } - - DBG("Buf=%d, len=%d", buf, len); - td->control = (TD_ROUNDING | token | TD_DELAY_INT(0) | td_toggle | TD_CC); - td->currBufPtr = (uint32_t) buf; - td->bufEnd = (uint32_t)(buf + (len - 1)); - - DBG("Now do queue transfer on ep %p", ed); - - ed->queueTransfer(); - - DBG("Enable list if needed"); - - switch (ed->getType()) { - case CONTROL_ENDPOINT: - enableControlList(); - break; - case BULK_ENDPOINT: - enableBulkList(); - break; - case INTERRUPT_ENDPOINT: - //printInt(); - enableInterruptList(); - break; - } - - DBG("Wait for HC to process TD"); - - - return USB_TYPE_PROCESSING; -} - - - -USB_TYPE USBHost::getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf) { - return controlRead( dev, - USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, - GET_DESCRIPTOR, - (DEVICE_DESCRIPTOR << 8) | (0), - 0, - buf, - DEVICE_DESCRIPTOR_LENGTH); -} - -USB_TYPE USBHost::getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t * len_conf_descr) { - USB_TYPE res; - uint16_t total_conf_descr_length = 0; - - // fourth step: get the beginning of the configuration descriptor to have the total length of the conf descr - res = controlRead( dev, - USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, - GET_DESCRIPTOR, - (CONFIGURATION_DESCRIPTOR << 8) | (0), - 0, - buf, - CONFIGURATION_DESCRIPTOR_LENGTH); - - if (res != USB_TYPE_OK) { - ERR("GET CONF 1 DESCR FAILED"); - return res; - } - total_conf_descr_length = buf[2] | (buf[3] << 8); - if (len_conf_descr != NULL) { - *len_conf_descr = total_conf_descr_length; - } - DBG("TOTAL_LENGTH: %d \t NUM_INTERF: %d", total_conf_descr_length, buf[4]); - - return controlRead( dev, - USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, - GET_DESCRIPTOR, - (CONFIGURATION_DESCRIPTOR << 8) | (0), - 0, - buf, - total_conf_descr_length); - -} - -USB_TYPE USBHost::setConfiguration(USBDeviceConnected * dev, uint8_t conf) { - return controlWrite( dev, - USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, - SET_CONFIGURATION, - conf, - 0, - NULL, - 0); - -} - - -// enumerate a device with the control USBEndpoint -USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) { - uint8_t data[384]; - uint16_t total_conf_descr_length = 0; - USB_TYPE res; - - DBG("data = %p", data); - - if (dev->isEnumerated()) { - return USB_TYPE_OK; - } - - // first step: get the size of USBEndpoint 0 - DBG("Get size of EP 0"); - res = controlRead( dev, - USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, - GET_DESCRIPTOR, - (DEVICE_DESCRIPTOR << 8) | (0), - 0, - data, - 8); - - if (res != USB_TYPE_OK) { - ERR("Control read failed!!"); - return res; - } - dev->setSizeControlEndpoint(data[7]); - DBG("size control USBEndpoint: %d", dev->getSizeControlEndpoint()); - -DBG("Now set addr"); - // second step: set an address to the device - res = controlWrite( dev, - USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, - SET_ADDRESS, - dev->getAddress(), - 0, - NULL, - 0); - - if (res != USB_TYPE_OK) { - DBG("SET ADDR FAILED"); - freeDevice(dev); - return res; - } - dev->activeAddress(); - - - // third step: get the whole device descriptor to see vid, pid - res = getDeviceDescriptor(dev, data); - - if (res != USB_TYPE_OK) { - DBG("GET DEV DESCR FAILED"); - return res; - } - dev->setClass(data[4]); - dev->setSubClass(data[5]); - dev->setProtocol(data[6]); - dev->setVid(data[8] | (data[9] << 8)); - dev->setPid(data[10] | (data[11] << 8)); - DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8)); - - pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) ); - - res = getConfigurationDescriptor(dev, data, &total_conf_descr_length); - if (res != USB_TYPE_OK) { - return res; - } - - // Parse the configuration descriptor - parseConfDescr(dev, data, total_conf_descr_length, pEnumerator); - - - // sixth step: set configuration (only 1 supported) - res = setConfiguration(dev, 1); - - if (res != USB_TYPE_OK) { - DBG("SET CONF FAILED"); - freeDevice(dev); - return res; - } - - // Now the device is enumerated! - dev->setEnumerated(); - DBG("device enumerated!!!!"); - - // Some devices may require this delay - Thread::wait(100); - - return USB_TYPE_OK; -} - -// this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor. -void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) { - uint32_t index = 0; - uint32_t len_desc = 0; - uint8_t id = 0; - int nb_endpoints_used = 0; - USBEndpoint * ep = NULL; - uint8_t intf_nb = 0; - bool parsing_intf = false; - - while (index < len) { - len_desc = conf_descr[index]; - id = conf_descr[index+1]; - switch (id) { - case CONFIGURATION_DESCRIPTOR: - break; - case INTERFACE_DESCRIPTOR: - if(pEnumerator->parseInterface(intf_nb, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7])) - { - if (intf_nb++ <= NB_MAX_INTF) { - dev->addInterface(intf_nb - 1, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]); - nb_endpoints_used = 0; - DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", intf_nb - 1, (void *)dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]); - } else { - DBG("Drop intf..."); - } - parsing_intf = true; - } - else - { - parsing_intf = false; - } - break; - case ENDPOINT_DESCRIPTOR: - DBG("Ep DESC"); - if (parsing_intf && (intf_nb <= NB_MAX_INTF) ) { - if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { - if( pEnumerator->useEndpoint(intf_nb - 1, (ENDPOINT_TYPE)(conf_descr[index + 3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1)) ) - { - // if the USBEndpoint is isochronous -> skip it (TODO: fix this) - if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { - ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03), - (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1), - conf_descr[index + 4] | (conf_descr[index + 5] << 8), - conf_descr[index + 2] & 0x0f); - DBG("ADD USBEndpoint %p, on interf %d on device %p", (void *)ep, intf_nb - 1, (void *)dev); - if (ep != NULL && dev != NULL) { - addEndpoint(dev, intf_nb - 1, ep); - } else { - DBG("EP NULL"); - } - nb_endpoints_used++; - } else { - DBG("ISO USBEndpoint NOT SUPPORTED"); - } - } - } - } - //DBG("USBEndpoint DESCR"); - break; - case HID_DESCRIPTOR: - lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8); - break; - default: - break; - } - index += len_desc; - } -} - - -USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { - USB_TYPE res; - - if (dev == NULL || ep == NULL) { - return USB_TYPE_ERROR; - } - - if ((ep->getDir() != IN) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad USBEndpoint type"); - return USB_TYPE_ERROR; - } - if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("USBEndpoint addr and device addr don't match"); - return USB_TYPE_ERROR; - } - addTransfer(ep, buf, len); - if (blocking) { - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; - } - return USB_TYPE_PROCESSING; -} - -USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { - USB_TYPE res; - - if (dev == NULL || ep == NULL) { - return USB_TYPE_ERROR; - } - - if ((ep->getDir() != OUT) || (ep->getType() != BULK_ENDPOINT)) { - DBG("wrong dir or bad USBEndpoint type"); - return USB_TYPE_ERROR; - } - if (dev->getAddress() != ep->getDeviceAddress()) { - DBG("USBEndpoint addr and device addr don't match"); - return USB_TYPE_ERROR; - } - addTransfer(ep, buf, len); - if (blocking) { - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING) - { - DBG("!!!!!!!!!!!!!wait bulkwrite"); - Thread::wait(100); - } - lock(); - DBG("!!!!!!!!!!!!! bulkwrite finished"); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; - } - return USB_TYPE_PROCESSING; -} - -USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { - USB_TYPE res; - - if (dev == NULL || ep == NULL) { - return USB_TYPE_ERROR; - } - - if (ep->getState() != USB_TYPE_IDLE) { - return ep->getState(); - } - - if ((ep->getDir() != OUT) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad USBEndpoint type: %d, %d", ep->getDir(), ep->getType()); - return USB_TYPE_ERROR; - } - if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("USBEndpoint addr and device addr don't match"); - return USB_TYPE_ERROR; - } - addTransfer(ep, buf, len); - if (blocking) { - while ((res = ep->getState()) == USB_TYPE_PROCESSING); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; - } - return USB_TYPE_PROCESSING; -} - -USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) { - USB_TYPE res; - - if (dev == NULL || ep == NULL) { - return USB_TYPE_ERROR; - } - - if (ep->getState() != USB_TYPE_IDLE) { - return ep->getState(); - } - - if ((ep->getDir() != IN) || (ep->getType() != INTERRUPT_ENDPOINT)) { - ERR("wrong dir or bad USBEndpoint type"); - return USB_TYPE_ERROR; - } - - if (dev->getAddress() != ep->getDeviceAddress()) { - ERR("USBEndpoint addr and device addr don't match"); - return USB_TYPE_ERROR; - } - addTransfer(ep, buf, len); - if (blocking) { - while ((res = ep->getState()) == USB_TYPE_PROCESSING); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; - } - return USB_TYPE_PROCESSING; -} - - -USB_TYPE USBHost::controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) { - int length_transfer = len; - //DBG("want to transfer: %d bytes\r\n", length_transfer); - USB_TYPE res; - control->setSpeed(dev->getSpeed()); - control->setSize(dev->getSizeControlEndpoint()); - if (dev->isActiveAddress()) { - control->setDeviceAddress(dev->getAddress()); - } else { - control->setDeviceAddress(0); - } - fillControlBuf(requestType, request, value, index, len); - /* DBG("will call transfer: "); - for (int i = 0; i < 8; i++) { - DBG("%02X ", setupPacket[i]); - }*/ - control->setNextToken(TD_SETUP); - addTransfer(control, (uint8_t*)setupPacket, 8); - DBG("Now wait for TD to be processed"); - unlock(); - DBG("Unlocked"); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - DBG("TD processed with result %d", res); - if (res != USB_TYPE_IDLE) { - return res; - } - - if (length_transfer) { - DBG("In data to be transfered..."); - control->setNextToken(TD_IN); - addTransfer(control, (uint8_t *)buf, length_transfer); - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - } - - DBG("Transfer NULL packet (OUT)"); - control->setNextToken(TD_OUT); - addTransfer(control, NULL, 0); - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; -} - - -USB_TYPE USBHost::controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) { - control->setSpeed(dev->getSpeed()); - - int length_transfer = len; - USB_TYPE res; - - control->setSize(dev->getSizeControlEndpoint()); - if (dev->isActiveAddress()) { - control->setDeviceAddress(dev->getAddress()); - } else { - control->setDeviceAddress(0); - } - fillControlBuf(requestType, request, value, index, len); - /*DBG("will call transfer: "); - for (int i = 0; i < 8; i++) { - printf("%01X ", setupPacket[i]); - } - printf("\r\n");*/ - control->setNextToken(TD_SETUP); - addTransfer(control, (uint8_t*)setupPacket, 8); - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - - if (length_transfer) { - control->setNextToken(TD_OUT); - addTransfer(control, (uint8_t *)buf, length_transfer); - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - } - - control->setNextToken(TD_IN); - addTransfer(control, NULL, 0); - unlock(); - while ((res = control->getState()) == USB_TYPE_PROCESSING); - lock(); - if (res != USB_TYPE_IDLE) { - return res; - } - return USB_TYPE_OK; -} - - -void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, int len) { -#ifdef __BIG_ENDIAN -#error "Must implement BE to LE conv here" -#endif - setupPacket[0] = requestType; - setupPacket[1] = request; - //We are in LE so it's fine - *((uint32_t*)&setupPacket[2]) = value; - *((uint32_t*)&setupPacket[4]) = index; - *((uint32_t*)&setupPacket[6]) = (uint32_t) len; -} - diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.h deleted file mode 100644 index f42c438abb..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHost.h +++ /dev/null @@ -1,304 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USBHOST_H -#define USBHOST_H - -#include "USBHALHost.h" -#include "USBDeviceConnected.h" -#include "USBEndpoint.h" -#include "IUSBEnumerator.h" - -#define MAX_DEVICE_NB 1 - -// singleton class -class USBHost : public USBHALHost { -public: - /* - * Static method to create or retrieve the single USBHost instance - */ - static USBHost * getHostInst(); - - USB_TYPE getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf) ; - USB_TYPE getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t * len_conf_descr = NULL) ; - USB_TYPE setConfiguration(USBDeviceConnected * dev, uint8_t conf) ; - USB_TYPE getStringDescriptor(USBDeviceConnected * dev, uint8_t index, uint8_t * buf) ; - USB_TYPE getReportDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint8_t len) ; - - /* - * Control read: setup stage, data stage and status stage - * - * @param dev the control read will be done for this device - * @param requestType request type - * @param request request - * @param value value - * @param index index - * @param buf pointer on a buffer where will be store the data received - * @param len length of the transfer - * - * @returns status of the control read - */ - USB_TYPE controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) ; - - /* - * Control write: setup stage, data stage and status stage - * - * @param dev the control write will be done for this device - * @param requestType request type - * @param request request - * @param value value - * @param index index - * @param buf pointer on a buffer which will be written - * @param len length of the transfer - * - * @returns status of the control write - */ - USB_TYPE controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) ; - - - /* - * Bulk read - * - * @param dev the bulk transfer will be done for this device - * @param ep USBEndpoint which will be used to read a packet - * @param buf pointer on a buffer where will be store the data received - * @param len length of the transfer - * @param blocking if true, the read is blocking (wait for completion) - * - * @returns status of the bulk read - */ - USB_TYPE bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; - - /* - * Bulk write - * - * @param dev the bulk transfer will be done for this device - * @param ep USBEndpoint which will be used to write a packet - * @param buf pointer on a buffer which will be written - * @param len length of the transfer - * @param blocking if true, the write is blocking (wait for completion) - * - * @returns status of the bulk write - */ - USB_TYPE bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; - - /* - * Interrupt read - * - * @param dev the bulk transfer will be done for this device - * @param ep USBEndpoint which will be used to write a packet - * @param buf pointer on a buffer which will be written - * @param len length of the transfer - * @param blocking if true, the read is blocking (wait for completion) - * - * @returns status of the interrupt read - */ - USB_TYPE interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; - - /* - * Interrupt write - * - * @param dev the bulk transfer will be done for this device - * @param ep USBEndpoint which will be used to write a packet - * @param buf pointer on a buffer which will be written - * @param len length of the transfer - * @param blocking if true, the write is blocking (wait for completion) - * - * @returns status of the interrupt write - */ - USB_TYPE interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking = true) ; - - /* - * Enumerate a device. This method is responsible for: - * - set the address of the device - * - fill a USBDeviceConnected object: - * - add interfaces, endpoints, ... - * - set a configuration - * - * @param dev device which will be enumerated - * - * @returns status of the enumeration - */ - USB_TYPE enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) ; - - /* - * Get a device - * - * @param index index of the device which will be returned - * - * @returns pointer on the "index" device - */ - USBDeviceConnected * getDevice(uint8_t index) ; - - /* - * reset port and hub of a specific device - * - * @param pointer on the device hich will be reseted - */ - USB_TYPE resetDevice(USBDeviceConnected * dev) ; - - /* - * If there is a HID device connected, the host stores the length of the report descriptor. - * This avoid to the driver to re-ask the configuration descriptor to request the report descriptor - * - * @returns length of the report descriptor - */ - uint16_t getLengthReportDescr() { - return lenReportDescr; - }; - - /** - * register a driver into the host associated with a callback function called when the device is disconnected - * - * @param dev device - * @param tptr pointer to the object to call the member function on - * @param mptr pointer to the member function to be called - */ - template - void registerDriver(USBDeviceConnected * dev, uint8_t intf, T* tptr, void (T::*mptr)(void)) { - int index = findDevice(dev); - if ((index != -1) && (mptr != NULL) && (tptr != NULL)) { - dev->onDisconnect(intf, tptr, mptr); - } - } - - /** - * register a driver into the host associated with a callback function called when the device is disconnected - * - * @param dev device - * @param fn callback called when the specified device has been disconnected - */ - void registerDriver(USBDeviceConnected * dev, uint8_t intf, void (*fn)(void)) { - int index = findDevice(dev); - if ((index != -1) && (fn != NULL)) { - dev->onDisconnect(intf, fn); - } - } - - -protected: - - /* - * Virtual method called when a device has been connected - * - * @param hub hub number of the device - * @param port port number of the device - * @param lowSpeed 1 if low speed, 0 otherwise - */ - virtual void deviceConnected(int hub, int port, bool lowSpeed) ; - - /* - * Virtuel method called when a device has been disconnected - * - * @param hub hub number of the device - * @param port port number of the device - * @param addr list of the TDs which have been completed to dequeue freed TDs - */ - virtual void deviceDisconnected(int hub, int port, volatile uint32_t addr) ; - - /* - * Virtual method called when a transfer has been completed - * - * @param addr list of the TDs which have been completed - */ - virtual void transferCompleted(volatile uint32_t addr) ; - - -private: - // singleton class -> constructor is private - USBHost(); - - static USBHost * instHost; - - uint8_t nb_devices; - uint16_t lenReportDescr; - - void fillControlBuf(uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, int len) ; - void parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) ; - void freeDevice(USBDeviceConnected * dev) ; - int findDevice(USBDeviceConnected * dev) ; - - - // endpoints - void unqueueEndpoint(USBEndpoint * ep) ; - USBEndpoint endpoints[MAX_ENDPOINT]; - USBEndpoint* volatile control; - - USBEndpoint* volatile headControlEndpoint; - USBEndpoint* volatile headBulkEndpoint; - USBEndpoint* volatile headInterruptEndpoint; - - USBEndpoint* volatile tailControlEndpoint; - USBEndpoint* volatile tailBulkEndpoint; - USBEndpoint* volatile tailInterruptEndpoint; - - bool controlEndpointAllocated; - - - // devices connected - USBDeviceConnected devices[MAX_DEVICE_NB]; - volatile bool deviceInUse[MAX_DEVICE_NB]; - volatile bool deviceReset[MAX_DEVICE_NB]; - - /* - * Add a transfer on the TD linked list associated to an ED - * - * @param ed the transfer is associated to this ed - * @param buf pointer on a buffer where will be read/write data to send or receive - * @param len transfer length - * - * @return status of the transfer - */ - USB_TYPE addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) ; - - /* - * Link the USBEndpoint to the linked list and attach an USBEndpoint this USBEndpoint to a device - * - * @param dev pointer on a USBDeviceConnected object - * @param ep pointer on the USBEndpoint which will be added - * - * return true if successful - */ - bool addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) ; - - /* - * Create an USBEndpoint descriptor. Warning: the USBEndpoint is not linked. - * - * @param type USBEndpoint type (CONTROL_ENDPOINT, BULK_ENDPOINT, INTERRUPT_ENDPOINT) - * @param dir USBEndpoint direction (no meaning for CONTROL_ENDPOINT) - * @param size USBEndpoint max packet size - * @param addr USBEndpoint address - * - * @returns pointer on the USBEndpoint created - */ - USBEndpoint * newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) ; - - - // to store a setup packet - uint8_t setupPacket[8]; - - - ///////////////////////// - /// FOR DEBUG - ///////////////////////// - void printBulk(); - void printInt(); - -}; - -#endif diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHostTypes.h b/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHostTypes.h deleted file mode 100644 index cadfc69f3c..0000000000 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/USBHostTypes.h +++ /dev/null @@ -1,191 +0,0 @@ -/* Copyright (c) 2010-2012 mbed.org, MIT License -* -* Permission is hereby granted, free of charge, to any person obtaining a copy of this software -* and associated documentation files (the "Software"), to deal in the Software without -* restriction, including without limitation the rights to use, copy, modify, merge, publish, -* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the -* Software is furnished to do so, subject to the following conditions: -* -* The above copyright notice and this permission notice shall be included in all copies or -* substantial portions of the Software. -* -* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING -* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND -* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, -* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -*/ - -#ifndef USB_INC_H -#define USB_INC_H - -#include "mbed.h" - -enum USB_TYPE { - USB_TYPE_DISCONNECTED = -10, - USB_TYPE_NOTFOUND = -9, - USB_TYPE_BADCONFIG = -8, - USB_TYPE_FREE = -7, - USB_TYPE_IDLE = -6, - USB_TYPE_PROCESSING = -5, - USB_TYPE_HALTED = -4, //Transfer on an ep is stalled - USB_TYPE_BUSY = -3, - USB_TYPE_TDFAIL = -2, - USB_TYPE_ERROR = -1, - USB_TYPE_OK = 0 -}; - -#define AUDIO_CLASS 0x01 -#define CDC_CLASS 0x02 -#define MSD_CLASS 0x08 -#define HID_CLASS 0x03 - - -// From NXP's USBHostLite stack's usbhost_lpc17xx.h -// Only the types names have been changed to avoid unecessary typedefs - - -/* -************************************************************************************************************** -* NXP USB Host Stack -* -* (c) Copyright 2008, NXP SemiConductors -* (c) Copyright 2008, OnChip Technologies LLC -* All Rights Reserved -* -* www.nxp.com -* www.onchiptech.com -* -* File : usbhost_lpc17xx.h -* Programmer(s) : Ravikanth.P -* Version : -* -************************************************************************************************************** -*/ - - -// ------------------ HcControl Register --------------------- -#define OR_CONTROL_PLE 0x00000004 -#define OR_CONTROL_CLE 0x00000010 -#define OR_CONTROL_BLE 0x00000020 -#define OR_CONTROL_HCFS 0x000000C0 -#define OR_CONTROL_HC_OPER 0x00000080 -// ----------------- HcCommandStatus Register ----------------- -#define OR_CMD_STATUS_HCR 0x00000001 -#define OR_CMD_STATUS_CLF 0x00000002 -#define OR_CMD_STATUS_BLF 0x00000004 -// --------------- HcInterruptStatus Register ----------------- -#define OR_INTR_STATUS_WDH 0x00000002 -#define OR_INTR_STATUS_RHSC 0x00000040 -#define OR_INTR_STATUS_UE 0x00000010 -// --------------- HcInterruptEnable Register ----------------- -#define OR_INTR_ENABLE_WDH 0x00000002 -#define OR_INTR_ENABLE_RHSC 0x00000040 -#define OR_INTR_ENABLE_MIE 0x80000000 -// ---------------- HcRhDescriptorA Register ------------------ -#define OR_RH_STATUS_LPSC 0x00010000 -#define OR_RH_STATUS_DRWE 0x00008000 -// -------------- HcRhPortStatus[1:NDP] Register -------------- -#define OR_RH_PORT_CCS 0x00000001 -#define OR_RH_PORT_PRS 0x00000010 -#define OR_RH_PORT_CSC 0x00010000 -#define OR_RH_PORT_PRSC 0x00100000 -#define OR_RH_PORT_LSDA 0x00000200 - - -// -//************************************************************************************************************** -//* FRAME INTERVAL -//************************************************************************************************************** -// - -#define FI 0x2EDF // 12000 bits per frame (-1) -#define DEFAULT_FMINTERVAL ((((6 * (FI - 210)) / 7) << 16) | FI) - -// -//************************************************************************************************************** -//* ENDPOINT DESCRIPTOR CONTROL FIELDS -//************************************************************************************************************** -// - -#define ED_SKIP (uint32_t) (0x00001000) // Skip this ep in queue - -// -//************************************************************************************************************** -//* TRANSFER DESCRIPTOR CONTROL FIELDS -//************************************************************************************************************** -// - -#define TD_ROUNDING (uint32_t) (0x00040000) // Buffer Rounding -#define TD_SETUP (uint32_t)(0) // Direction of Setup Packet -#define TD_IN (uint32_t)(0x00100000) // Direction In -#define TD_OUT (uint32_t)(0x00080000) // Direction Out -#define TD_DELAY_INT(x) (uint32_t)((x) << 21) // Delay Interrupt -#define TD_TOGGLE_0 (uint32_t)(0x02000000) // Toggle 0 -#define TD_TOGGLE_1 (uint32_t)(0x03000000) // Toggle 1 -#define TD_CC (uint32_t)(0xF0000000) // Completion Code - -// -//************************************************************************************************************** -//* USB STANDARD REQUEST DEFINITIONS -//************************************************************************************************************** -// - -#define DEVICE_DESCRIPTOR (1) -#define CONFIGURATION_DESCRIPTOR (2) -#define INTERFACE_DESCRIPTOR (4) -#define ENDPOINT_DESCRIPTOR (5) -#define HID_DESCRIPTOR (33) - -// ----------- Control RequestType Fields ----------- -#define USB_DEVICE_TO_HOST 0x80 -#define USB_HOST_TO_DEVICE 0x00 -#define USB_REQUEST_TYPE_CLASS 0x20 -#define USB_RECIPIENT_DEVICE 0x00 -#define USB_RECIPIENT_INTERFACE 0x01 - -// -------------- USB Standard Requests -------------- -#define SET_ADDRESS 5 -#define GET_DESCRIPTOR 6 -#define SET_CONFIGURATION 9 -#define SET_INTERFACE 11 - -// -------------- USB Descriptor Length -------------- -#define DEVICE_DESCRIPTOR_LENGTH 0x12 -#define CONFIGURATION_DESCRIPTOR_LENGTH 0x09 - - -// -//************************************************************************************************************** -//* TYPE DEFINITIONS -//************************************************************************************************************** -// - -// ----------- HostController EndPoint Descriptor ------------- -typedef struct hcEd { - volatile uint32_t control; // Endpoint descriptor control - volatile uint32_t tailTD; // Physical address of tail in Transfer descriptor list - volatile uint32_t headTD; // Physcial address of head in Transfer descriptor list - volatile uint32_t nextED; // Physical address of next Endpoint descriptor -} HCED; - -// ------------ HostController Transfer Descriptor ------------ -typedef struct hcTd { - volatile uint32_t control; // Transfer descriptor control - volatile uint32_t currBufPtr; // Physical address of current buffer pointer - volatile uint32_t nextTD; // Physical pointer to next Transfer Descriptor - volatile uint32_t bufEnd; // Physical address of end of buffer -} HCTD; - -// ----------- Host Controller Communication Area ------------ -typedef struct hcca { - volatile uint32_t IntTable[32]; // Interrupt Table - volatile uint32_t FrameNumber; // Frame Number - volatile uint32_t DoneHead; // Done Head - volatile uint8_t Reserved[116]; // Reserved for future use - volatile uint8_t Unknown[4]; // Unused -} HCCA; - - - -#endif diff --git a/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.cpp b/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.cpp deleted file mode 100644 index a593587c6e..0000000000 --- a/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.cpp +++ /dev/null @@ -1,253 +0,0 @@ -/* IOSerialStream.cpp */ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#define __DEBUG__ 0 //Maximum verbosity -#ifndef __MODULE__ -#define __MODULE__ "IOSerialStream.cpp" -#endif - -#include "core/fwk.h" - -#include - -#include "IOSerialStream.h" - -IOSerialStream::IOSerialStream(mbed::Serial& serial) : m_serial(serial), m_serialTxFifoEmpty(true), -m_availableSphre(1), m_spaceSphre(1), m_inBuf(), m_outBuf() -{ - m_availableSphre.wait(); - m_spaceSphre.wait(); - //Attach interrupts - m_serial.attach(this, &IOSerialStream::readable, mbed::Serial::RxIrq); - m_serial.attach(this, &IOSerialStream::writeable, mbed::Serial::TxIrq); -} - -/*virtual*/ IOSerialStream::~IOSerialStream() -{ - m_serial.attach(NULL, mbed::Serial::RxIrq); - m_serial.attach(NULL, mbed::Serial::TxIrq); -} - -//0 for non-blocking (returns immediately), osWaitForever for infinite blocking -/*virtual*/ int IOSerialStream::read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout/*=osWaitForever*/) -{ - DBG("Trying to read at most %d chars", maxLength); - int ret = waitAvailable(timeout); - if(ret) - { - WARN("Error %d while waiting for incoming data", ret); - return ret; - } - int readLen = MIN( available(), maxLength ); - *pLength = readLen; - setupReadableISR(false); - while(readLen--) - { - m_inBuf.dequeue(buf); - buf++; - } - setupReadableISR(true); - DBG("Read %d chars successfully", *pLength); - return OK; -} - -/*virtual*/ size_t IOSerialStream::available() -{ - setupReadableISR(false); //m_inBuf.available() is not reentrant - size_t len = m_inBuf.available(); - setupReadableISR(true); - return len; -} - -/*virtual*/ int IOSerialStream::waitAvailable(uint32_t timeout/*=osWaitForever*/) //Wait for data to be available -{ - int ret; - if(available()) //Is data already available? - { - m_availableSphre.wait(0); //Clear the queue as data is available - return OK; - } - - DBG("Waiting for data availability %d ms (-1 is infinite)", timeout); - ret = m_availableSphre.wait(timeout); //Wait for data to arrive or for abort - if(ret <= 0) - { - DBG("Timeout"); - return NET_TIMEOUT; - } - if(!available()) //Even if abort has been called, return that data is available - { - DBG("Aborted"); - return NET_INTERRUPTED; - } - DBG("Finished waiting"); - m_availableSphre.wait(0); //Clear the queue as data is available - return OK; -} - -/*virtual*/ int IOSerialStream::abortRead() //Abort current reading (or waiting) operation -{ - if( !available() ) //If there is data pending, no need to abort - { - m_availableSphre.release(); //Force exiting the waiting state; kludge to pass a RC directly - } - else - { - DBG("Serial is readable"); ; - } - return OK; -} - -void IOSerialStream::setupReadableISR(bool en) -{ - if(en) - { - ((LPC_UART_TypeDef *)(UART_3))->IER |= 1 << 0; - } - else - { - ((LPC_UART_TypeDef *)(UART_3))->IER &= ~(1 << 0); - } -} - -void IOSerialStream::readable() //Callback from m_serial when new data is available -{ - do - { - m_inBuf.queue(((LPC_UART_TypeDef *)UART_3)->RBR); //FIXME mbed libraries this is an awful kludge - } while(m_serial.readable()); - m_availableSphre.release(); //Force exiting the waiting state -} - -//0 for non-blocking (returns immediately), osWaitForever for infinite blocking -/*virtual*/ int IOSerialStream::write(uint8_t* buf, size_t length, uint32_t timeout/*=osWaitForever*/) -{ - DBG("Trying to write %d chars", length); - int ret = waitSpace(timeout); - if(ret) - { - WARN("Error %d while waiting for space", ret); - return ret; - } - DBG("Writing %d chars", length); - setupWriteableISR(false); - while(length) - { - m_outBuf.queue(*buf); - buf++; - length--; - if(length && !space()) - { - DBG("Waiting to write remaining %d chars", length); - setupWriteableISR(true); - ret = waitSpace(timeout); - if(ret) - { - WARN("Error %d while waiting for space", ret); - return ret; - } - setupWriteableISR(false); - } - } - //If m_serial tx fifo is empty we need to manually tx a byte in order to trigger the interrupt - if( m_outBuf.available() && m_serialTxFifoEmpty ) - { - m_serialTxFifoEmpty = false; - uint8_t c; - m_outBuf.dequeue(&c); - //m_serial.putc((char)c); - ((LPC_UART_TypeDef *)UART_3)->THR = c; //FIXME awful kludge - } - setupWriteableISR(true); - DBG("Write successful"); - return OK; -} - -/*virtual*/ size_t IOSerialStream::space() -{ - setupWriteableISR(false); //m_outBuf.available() is not reentrant - size_t len = CIRCBUF_SIZE - m_outBuf.available(); - setupWriteableISR(true); - return len; -} - -/*virtual*/ int IOSerialStream::waitSpace(uint32_t timeout/*=osWaitForever*/) //Wait for space to be available -{ - int ret; - if(space()) //Is still space already left? - { - m_spaceSphre.wait(0); //Clear the queue as space is available - return OK; - } - - DBG("Waiting for data space %d ms (-1 is infinite)", timeout); - ret = m_spaceSphre.wait(timeout); //Wait for space to be made or for abort - if(ret <= 0) - { - DBG("Timeout"); - return NET_TIMEOUT; - } - if(!space()) //Even if abort has been called, return that space is available - { - DBG("Aborted"); - return NET_INTERRUPTED; - } - m_spaceSphre.wait(0); //Clear the queue as space is available - return OK; -} - -/*virtual*/ int IOSerialStream::abortWrite() //Abort current writing (or waiting) operation -{ - if( !space() ) //If there is space left, no need to abort - { - m_spaceSphre.release(); //Force exiting the waiting state - } - return OK; -} - -void IOSerialStream::setupWriteableISR(bool en) -{ - if(en) - { - ((LPC_UART_TypeDef *)(UART_3))->IER |= 1 << 1; - } - else - { - ((LPC_UART_TypeDef *)(UART_3))->IER &= ~(1 << 1); - } -} - -void IOSerialStream::writeable() //Callback from m_serial when new space is available -{ - if(m_outBuf.isEmpty()) - { - m_serialTxFifoEmpty = true; - } - else - { - while(m_serial.writeable() && !m_outBuf.isEmpty()) - { - uint8_t c; - m_outBuf.dequeue(&c); - //m_serial.putc((char)c); - ((LPC_UART_TypeDef *)UART_3)->THR = c; //FIXME awful kludge - } - } - m_spaceSphre.release(); //Force exiting the waiting state -} diff --git a/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.h b/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.h deleted file mode 100644 index 28d2fecca7..0000000000 --- a/libraries/net/VodafoneUSBModem/serial/io/IOSerialStream.h +++ /dev/null @@ -1,72 +0,0 @@ -/* IOSerialStream.h */ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ -#ifndef IOSERIALSTREAM_H_ -#define IOSERIALSTREAM_H_ - -#include "core/fwk.h" - -#include "Serial.h" - -#include "rtos.h" -#include "core/MtxCircBuffer.h" - -/** Input Serial Stream for physical serial interfaces (UART...) -This class is not thread-safe, except for the *Abort() methods that can be called by any thread/ISR -*/ -#define CIRCBUF_SIZE 255 -class IOSerialStream : public IOStream -{ -public: - IOSerialStream(mbed::Serial& serial); - /*virtual*/ ~IOSerialStream(); - - //0 for non-blocking (returns immediately), osWaitForever for infinite blocking - virtual int read(uint8_t* buf, size_t* pLength, size_t maxLength, uint32_t timeout=osWaitForever); - virtual size_t available(); - virtual int waitAvailable(uint32_t timeout=osWaitForever); //Wait for data to be available - virtual int abortRead(); //Abort current reading (or waiting) operation - - - //0 for non-blocking (returns immediately), osWaitForever for infinite blocking - virtual int write(uint8_t* buf, size_t length, uint32_t timeout=osWaitForever); - virtual size_t space(); - virtual int waitSpace(uint32_t timeout=osWaitForever); //Wait for space to be available - virtual int abortWrite(); //Abort current writing (or waiting) operation - -private: - - mbed::Serial& m_serial; - volatile bool m_serialTxFifoEmpty; - - void setupReadableISR(bool en); - void readable(); //Callback from m_serial when new data is available - - Semaphore m_availableSphre; //Used for signalling - - void setupWriteableISR(bool en); - void writeable(); //Callback from m_serial when new space is available - - Semaphore m_spaceSphre; //Used for signalling - - MtxCircBuffer m_inBuf; - MtxCircBuffer m_outBuf; - -}; - -#endif /* IOSERIALSTREAM_H_ */ diff --git a/libraries/net/VodafoneUSBModem/socket/bsd_socket.h b/libraries/net/VodafoneUSBModem/socket/bsd_socket.h deleted file mode 100644 index c442d9cf2a..0000000000 --- a/libraries/net/VodafoneUSBModem/socket/bsd_socket.h +++ /dev/null @@ -1,34 +0,0 @@ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef BSD_SOCKET_H_ -#define BSD_SOCKET_H_ - -#ifdef __cplusplus -extern "C" { -#endif - -#include "socket/sys/socket.h" //Must conform to -#include "socket/netinet/in.h" //Must conform to -#include "socket/netdb.h" //Must conform to - -#ifdef __cplusplus -} -#endif - -#endif /* BSD_SOCKET_H_ */ diff --git a/libraries/net/VodafoneUSBModem/socket/netdb.h b/libraries/net/VodafoneUSBModem/socket/netdb.h deleted file mode 100644 index 199891a503..0000000000 --- a/libraries/net/VodafoneUSBModem/socket/netdb.h +++ /dev/null @@ -1,47 +0,0 @@ -/* netdb.h */ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef NETDB_H_ -#define NETDB_H_ - -#include "lwip/netdb.h" - -//DNS - -inline struct hostent *gethostbyname(const char *name) -{ - return lwip_gethostbyname(name); -} - -inline int gethostbyname_r(const char *name, struct hostent *ret, char *buf, size_t buflen, struct hostent **result, int *h_errnop) -{ - return lwip_gethostbyname_r(name, ret, buf, buflen, result, h_errnop); -} - -inline void freeaddrinfo(struct addrinfo *ai) -{ - return lwip_freeaddrinfo(ai); -} - -inline int getaddrinfo(const char *nodename, const char *servname, const struct addrinfo *hints, struct addrinfo **res) -{ - return lwip_getaddrinfo(nodename, servname, hints, res); -} - -#endif /* NETDB_H_ */ diff --git a/libraries/net/VodafoneUSBModem/socket/netinet/in.h b/libraries/net/VodafoneUSBModem/socket/netinet/in.h deleted file mode 100644 index e67114245c..0000000000 --- a/libraries/net/VodafoneUSBModem/socket/netinet/in.h +++ /dev/null @@ -1,25 +0,0 @@ -/* in.h */ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - -#ifndef IN_H_ -#define IN_H_ - -#include "lwip/inet.h" - -#endif /* IN_H_ */ diff --git a/libraries/net/VodafoneUSBModem/socket/sys/socket.h b/libraries/net/VodafoneUSBModem/socket/sys/socket.h deleted file mode 100644 index 3db9028250..0000000000 --- a/libraries/net/VodafoneUSBModem/socket/sys/socket.h +++ /dev/null @@ -1,126 +0,0 @@ -/* socket.h */ -/* Copyright (C) 2012 mbed.org, MIT License - * - * Permission is hereby granted, free of charge, to any person obtaining a copy of this software - * and associated documentation files (the "Software"), to deal in the Software without restriction, - * including without limitation the rights to use, copy, modify, merge, publish, distribute, - * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is - * furnished to do so, subject to the following conditions: - * - * The above copyright notice and this permission notice shall be included in all copies or - * substantial portions of the Software. - * - * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING - * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND - * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, - * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. - */ - - -#ifndef SYS_SOCKET_H_ -#define SYS_SOCKET_H_ - -#include "lwip/sockets.h" - -//Sockets - -inline int accept(int s, struct sockaddr *addr, socklen_t *addrlen) -{ - return lwip_accept(s, addr, addrlen); -} - -inline int bind(int s, const struct sockaddr *name, socklen_t namelen) -{ - return lwip_bind(s, name, namelen); -} - -inline int shutdown(int s, int how) -{ - return lwip_shutdown(s, how); -} - -inline int getsockname (int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getsockname(s, name, namelen); -} - -inline int getpeername (int s, struct sockaddr *name, socklen_t *namelen) -{ - return lwip_getpeername(s, name, namelen); -} - -inline int getsockopt (int s, int level, int optname, void *optval, socklen_t *optlen) -{ - return lwip_getsockopt(s, level, optname, optval, optlen); -} - -inline int setsockopt (int s, int level, int optname, const void *optval, socklen_t optlen) -{ - return lwip_setsockopt(s, level, optname, optval, optlen); -} - -inline int connect(int s, const struct sockaddr *name, socklen_t namelen) -{ - return lwip_connect(s, name, namelen); -} - -inline int listen(int s, int backlog) -{ - return lwip_listen(s, backlog); -} - -inline int recv(int s, void *mem, size_t len, int flags) -{ - return lwip_recv(s, mem, len, flags); -} - -inline int recvfrom(int s, void *mem, size_t len, int flags, - struct sockaddr *from, socklen_t *fromlen) -{ - return lwip_recvfrom(s, mem, len, flags, from, fromlen); -} - -inline int send(int s, const void *dataptr, size_t size, int flags) -{ - return lwip_send(s, dataptr, size, flags); -} - -inline int sendto(int s, const void *dataptr, size_t size, int flags, - const struct sockaddr *to, socklen_t tolen) -{ - return lwip_sendto(s, dataptr, size, flags, to, tolen); -} - -inline int socket(int domain, int type, int protocol) -{ - return lwip_socket(domain, type, protocol); -} - -inline int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, - struct timeval *timeout) -{ - return lwip_select(maxfdp1, readset, writeset, exceptset, timeout); -} - -inline int ioctlsocket(int s, long cmd, void *argp) -{ - return lwip_ioctl(s, cmd, argp); -} - -inline int read(int s, void *mem, size_t len) -{ - return lwip_read(s, mem, len); -} - -inline int write(int s, const void *dataptr, size_t size) -{ - return lwip_write(s, dataptr, size); -} - -inline int close(int s) -{ - return lwip_close(s); -} - -#endif /* SYS_SOCKET_H_ */ diff --git a/libraries/net/cellular/CellularModem/CellularModem.h b/libraries/net/cellular/CellularModem/CellularModem.h new file mode 100644 index 0000000000..fd47622c86 --- /dev/null +++ b/libraries/net/cellular/CellularModem/CellularModem.h @@ -0,0 +1,78 @@ +/* CellularModem.h */ +/* Copyright (C) 2013 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef CELLULARMODEM_H_ +#define CELLULARMODEM_H_ + +#include "core/fwk.h" +#include "at/ATCommandsInterface.h" + +class CellularModem +{ +public: + //Internet-related functions + + /** Open a 3G internet connection + @return 0 on success, error code on failure + */ + virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL) = 0; + + /** Close the internet connection + @return 0 on success, error code on failure + */ + virtual int disconnect() = 0; + + + /** Send a SM + @param number The receiver's phone number + @param message The message to send + @return 0 on success, error code on failure + */ + virtual int sendSM(const char* number, const char* message) = 0; + + + /** Receive a SM + @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char) + @param message Pointer to a buffer to store the the incoming message + @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) + @return 0 on success, error code on failure + */ + virtual int getSM(char* number, char* message, size_t maxLength) = 0; + + /** Get the number of SMs in the incoming box + @param pCount pointer to store the number of unprocessed SMs on + @return 0 on success, error code on failure + */ + virtual int getSMCount(size_t* pCount) = 0; + + /** Get the ATCommandsInterface instance + @return Pointer to the ATCommandsInterface instance + */ + virtual ATCommandsInterface* getATCommandsInterface() = 0; + + /** Switch power on or off + In order to use this function, a pin name must have been entered in the constructor + @param enable true to switch the dongle on, false to switch it off + @return 0 on success, error code on failure + */ + virtual int power(bool enable) = 0; +}; + + +#endif /* CELLULARMODEM_H_ */ diff --git a/libraries/net/VodafoneUSBModem/at/ATCommandsInterface.cpp b/libraries/net/cellular/CellularModem/at/ATCommandsInterface.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/at/ATCommandsInterface.cpp rename to libraries/net/cellular/CellularModem/at/ATCommandsInterface.cpp diff --git a/libraries/net/VodafoneUSBModem/at/ATCommandsInterface.h b/libraries/net/cellular/CellularModem/at/ATCommandsInterface.h similarity index 100% rename from libraries/net/VodafoneUSBModem/at/ATCommandsInterface.h rename to libraries/net/cellular/CellularModem/at/ATCommandsInterface.h diff --git a/libraries/net/VodafoneUSBModem/core/IOStream.h b/libraries/net/cellular/CellularModem/core/IOStream.h similarity index 99% rename from libraries/net/VodafoneUSBModem/core/IOStream.h rename to libraries/net/cellular/CellularModem/core/IOStream.h index c9918b131d..6d411b8e4b 100644 --- a/libraries/net/VodafoneUSBModem/core/IOStream.h +++ b/libraries/net/cellular/CellularModem/core/IOStream.h @@ -20,8 +20,6 @@ #ifndef IOSTREAM_H_ #define IOSTREAM_H_ -#include "fwk.h" - #include "rtos.h" class IStream diff --git a/libraries/net/VodafoneUSBModem/core/MtxCircBuffer.h b/libraries/net/cellular/CellularModem/core/MtxCircBuffer.h similarity index 99% rename from libraries/net/VodafoneUSBModem/core/MtxCircBuffer.h rename to libraries/net/cellular/CellularModem/core/MtxCircBuffer.h index 8b86304719..b011693eb4 100644 --- a/libraries/net/VodafoneUSBModem/core/MtxCircBuffer.h +++ b/libraries/net/cellular/CellularModem/core/MtxCircBuffer.h @@ -20,8 +20,6 @@ #ifndef MTXCIRCBUFFER_H #define MTXCIRCBUFFER_H -#include "fwk.h" - #include "rtos.h" //Mutex protected circualr buffer diff --git a/libraries/net/VodafoneUSBModem/core/config.h b/libraries/net/cellular/CellularModem/core/config.h similarity index 100% rename from libraries/net/VodafoneUSBModem/core/config.h rename to libraries/net/cellular/CellularModem/core/config.h diff --git a/libraries/net/VodafoneUSBModem/core/dbg.cpp b/libraries/net/cellular/CellularModem/core/dbg.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/core/dbg.cpp rename to libraries/net/cellular/CellularModem/core/dbg.cpp diff --git a/libraries/net/VodafoneUSBModem/core/dbg.h b/libraries/net/cellular/CellularModem/core/dbg.h similarity index 100% rename from libraries/net/VodafoneUSBModem/core/dbg.h rename to libraries/net/cellular/CellularModem/core/dbg.h diff --git a/libraries/net/VodafoneUSBModem/core/errors.h b/libraries/net/cellular/CellularModem/core/errors.h similarity index 100% rename from libraries/net/VodafoneUSBModem/core/errors.h rename to libraries/net/cellular/CellularModem/core/errors.h diff --git a/libraries/net/VodafoneUSBModem/core/fwk.h b/libraries/net/cellular/CellularModem/core/fwk.h similarity index 100% rename from libraries/net/VodafoneUSBModem/core/fwk.h rename to libraries/net/cellular/CellularModem/core/fwk.h diff --git a/libraries/net/VodafoneUSBModem/ip/IPInterface.cpp b/libraries/net/cellular/CellularModem/ip/IPInterface.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/ip/IPInterface.cpp rename to libraries/net/cellular/CellularModem/ip/IPInterface.cpp diff --git a/libraries/net/VodafoneUSBModem/ip/IPInterface.h b/libraries/net/cellular/CellularModem/ip/IPInterface.h similarity index 100% rename from libraries/net/VodafoneUSBModem/ip/IPInterface.h rename to libraries/net/cellular/CellularModem/ip/IPInterface.h diff --git a/libraries/net/VodafoneUSBModem/ip/LwIPInterface.cpp b/libraries/net/cellular/CellularModem/ip/LwIPInterface.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/ip/LwIPInterface.cpp rename to libraries/net/cellular/CellularModem/ip/LwIPInterface.cpp diff --git a/libraries/net/VodafoneUSBModem/ip/LwIPInterface.h b/libraries/net/cellular/CellularModem/ip/LwIPInterface.h similarity index 100% rename from libraries/net/VodafoneUSBModem/ip/LwIPInterface.h rename to libraries/net/cellular/CellularModem/ip/LwIPInterface.h diff --git a/libraries/net/VodafoneUSBModem/ip/PPPIPInterface.cpp b/libraries/net/cellular/CellularModem/ip/PPPIPInterface.cpp similarity index 89% rename from libraries/net/VodafoneUSBModem/ip/PPPIPInterface.cpp rename to libraries/net/cellular/CellularModem/ip/PPPIPInterface.cpp index 2b398f0940..f71afea65b 100644 --- a/libraries/net/VodafoneUSBModem/ip/PPPIPInterface.cpp +++ b/libraries/net/cellular/CellularModem/ip/PPPIPInterface.cpp @@ -32,9 +32,10 @@ using std::sscanf; #define MSISDN "*99#" -#define CONNECT_CMD "ATD " MSISDN "\x0D" -#define EXPECTED_RESP CONNECT_CMD "\x0D" "\x0A" "CONNECT" "\x0D" "\x0A" -#define EXPECTED_RESP_DATARATE CONNECT_CMD "\x0D" "\x0A" "CONNECT %d" "\x0D" "\x0A" +#define CONNECT_CMD_PREFIX "ATD " +#define CONNECT_CMD_SUFFIX "\x0D" +#define EXPECTED_RESP_SUFFIX "\x0D" "\x0A" "CONNECT" "\x0D" "\x0A" +#define EXPECTED_RESP_DATARATE_SUFFIX "\x0D" "\x0A" "CONNECT %d" "\x0D" "\x0A" #define EXPECTED_RESP_MIN_LEN 20 #define OK_RESP "\x0D" "\x0A" "OK" "\x0D" "\x0A" #define ESCAPE_SEQ "+++" @@ -49,14 +50,22 @@ extern "C" { #include "netif/ppp/ppp.h" } -PPPIPInterface::PPPIPInterface(IOStream* pStream) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1) +PPPIPInterface::PPPIPInterface(IOStream* pStream, const char* msisdn) : LwIPInterface(), m_linkStatusSphre(1), m_pppErrCode(0), m_pStream(pStream), m_streamAvail(true), m_pppd(-1) { + m_connectCmd = new char[strlen(CONNECT_CMD_PREFIX) + strlen(msisdn) + strlen(CONNECT_CMD_SUFFIX) + 1]; + sprintf(m_connectCmd, "%s%s%s", CONNECT_CMD_PREFIX, msisdn, CONNECT_CMD_SUFFIX); + m_expectedResp = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_SUFFIX) + 1]; + sprintf(m_expectedResp, "%s%s", m_connectCmd, EXPECTED_RESP_SUFFIX); + m_expectedRespDatarate = new char[strlen(m_connectCmd) + strlen(EXPECTED_RESP_DATARATE_SUFFIX) + 1]; + sprintf(m_expectedRespDatarate, "%s%s", m_connectCmd, EXPECTED_RESP_DATARATE_SUFFIX); m_linkStatusSphre.wait(); } /*virtual*/ PPPIPInterface::~PPPIPInterface() { - + delete m_connectCmd; + delete m_expectedResp; + delete m_expectedRespDatarate; } /*virtual*/ int PPPIPInterface::init() //Init PPP-specific stuff, create the right bindings, etc @@ -86,15 +95,15 @@ int PPPIPInterface::setup(const char* user, const char* pw) cleanupLink(); - DBG("Sending %s", CONNECT_CMD); + DBG("Sending %s", m_connectCmd); - ret = m_pStream->write((uint8_t*)CONNECT_CMD, strlen(CONNECT_CMD), osWaitForever); + ret = m_pStream->write((uint8_t*)m_connectCmd, strlen(m_connectCmd), osWaitForever); if( ret != OK ) { return NET_UNKNOWN; } - DBG("Expect %s", EXPECTED_RESP); + DBG("Expect %s", m_expectedResp); len = 0; size_t readLen; @@ -119,7 +128,7 @@ int PPPIPInterface::setup(const char* user, const char* pw) DBG("Got %s[len %d]", buf, len); int datarate = 0; - if( (sscanf( buf, EXPECTED_RESP_DATARATE, &datarate ) != 1) && (strcmp(EXPECTED_RESP, buf) != 0) ) + if( (sscanf(buf, m_expectedRespDatarate, &datarate ) != 1) && (strcmp(m_expectedResp, buf) != 0) ) { //Discard buffer do //Clear buf diff --git a/libraries/net/VodafoneUSBModem/ip/PPPIPInterface.h b/libraries/net/cellular/CellularModem/ip/PPPIPInterface.h similarity index 90% rename from libraries/net/VodafoneUSBModem/ip/PPPIPInterface.h rename to libraries/net/cellular/CellularModem/ip/PPPIPInterface.h index ef1518a749..eba30e9461 100644 --- a/libraries/net/VodafoneUSBModem/ip/PPPIPInterface.h +++ b/libraries/net/cellular/CellularModem/ip/PPPIPInterface.h @@ -31,13 +31,16 @@ class Semaphore; } using namespace rtos; +#define DEFAULT_MSISDN_GSM "*99#" +#define DEFAULT_MSISDN_CDMA "#777" + /** Interface using PPP to connect to an IP-based network * */ class PPPIPInterface : public LwIPInterface { public: - PPPIPInterface(IOStream* pStream); + PPPIPInterface(IOStream* pStream, const char* msisdn); virtual ~PPPIPInterface(); int init(); //Init PPP-specific stuff, create the right bindings, etc @@ -60,6 +63,10 @@ private: friend u32_t sio_write(sio_fd_t fd, u8_t *data, u32_t len); friend u32_t sio_read(sio_fd_t fd, u8_t *data, u32_t len); friend void sio_read_abort(sio_fd_t fd); + + char* m_connectCmd; + char* m_expectedResp; + char* m_expectedRespDatarate; }; #endif /* PPPIPINTERFACE_H_ */ diff --git a/libraries/net/VodafoneUSBModem/link/LinkMonitor.cpp b/libraries/net/cellular/CellularModem/link/LinkMonitor.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/link/LinkMonitor.cpp rename to libraries/net/cellular/CellularModem/link/LinkMonitor.cpp diff --git a/libraries/net/VodafoneUSBModem/link/LinkMonitor.h b/libraries/net/cellular/CellularModem/link/LinkMonitor.h similarity index 100% rename from libraries/net/VodafoneUSBModem/link/LinkMonitor.h rename to libraries/net/cellular/CellularModem/link/LinkMonitor.h diff --git a/libraries/net/VodafoneUSBModem/lwipopts_conf.h b/libraries/net/cellular/CellularModem/lwipopts_conf.h similarity index 99% rename from libraries/net/VodafoneUSBModem/lwipopts_conf.h rename to libraries/net/cellular/CellularModem/lwipopts_conf.h index 065dd79190..5cd84be875 100644 --- a/libraries/net/VodafoneUSBModem/lwipopts_conf.h +++ b/libraries/net/cellular/CellularModem/lwipopts_conf.h @@ -23,3 +23,4 @@ #define LWIP_TRANSPORT_PPP 1 #endif /* LWIPOPTS_CONF_H_ */ + diff --git a/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.cpp b/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.cpp new file mode 100644 index 0000000000..c1a87550b0 --- /dev/null +++ b/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.cpp @@ -0,0 +1,348 @@ +/* CDMASMSInterface.cpp */ +/* Copyright (C) 2012 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#define __DEBUG__ 0 +#ifndef __MODULE__ +#define __MODULE__ "CDMASMSInterface.cpp" +#endif + +#include "core/fwk.h" + +#include "CDMASMSInterface.h" + +#include +#include + +#define DEFAULT_TIMEOUT 10000 + +CDMASMSInterface::CDMASMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL) +{ +} + +int CDMASMSInterface::init() +{ + m_state = SMS_IDLE; + + DBG("Get number of messages in the different inboxes"); + int ret = updateInbox(); + if(ret) + { + return NET_PROTOCOL; + } + + DBG("Initialization done"); + return OK; +} + +int CDMASMSInterface::send(const char* number, const char* message) +{ + if( strlen(number) > 16 ) + { + return NET_INVALID; //Number too long + } + + int ret; + + //Prepare infos + m_state = SMS_SEND_CMD_SENT; + + bool intlNumber=(number[0]=='+'); //If the number starts with the + sign, replace it with 011 instead (int'l dialing code in the US) + + DBG("Send SM"); + //Send command + char cmd[32+strlen(message)]; + std::sprintf(cmd, "AT!SSMS=0,%s%s,,\"%s\"",intlNumber?"011":"", intlNumber?(number+1):number, message); //Send with normal priority + ret = m_pIf->execute(cmd, this, NULL, DEFAULT_TIMEOUT); + + if(ret != OK) + { + WARN("ret %d", ret); + m_state = SMS_IDLE; + return NET_PROTOCOL; + } + + DBG("Check status"); + m_txState = SMS_PENDING; + + int tries = 10; + while(tries--) + { + m_state = SMS_GET_TX_STATUS_CMD_SENT; + ret = m_pIf->execute("AT!SSMS?", this, NULL, DEFAULT_TIMEOUT); + if(ret) + { + m_state = SMS_IDLE; + return ret; + } + m_state = SMS_IDLE; + if(m_txState == SMS_PENDING) //Wait more + { + Thread::wait(1000); + continue; + } + else if(m_txState == SMS_FAILED) + { + ERR("The modem could not send the SM"); + return NET_CONN; //Probably a conenction issue, the user can retry + } + else + { + break; + } + } + if(!tries) + { + ERR("The is still trying to send the SM"); + return NET_TIMEOUT; + } + return OK; +} + + +int CDMASMSInterface::get(char* number, char* message, size_t maxLength) +{ + if( maxLength < 1 ) + { + return NET_INVALID; //Buffer too short + } + + int ret; + + DBG("Get next message"); + if( (m_msgInListsCount[0] + m_msgInListsCount[1] + m_msgInListsCount[2]) == 0) + { + DBG("Message list count is 0 and needs updating. Running updateInbox."); + ret = updateInbox(); + if (ret) + { + return ret; + } + } + + if( (m_msgInListsCount[0] + m_msgInListsCount[1] + m_msgInListsCount[2]) == 0) + { + DBG("Message list count is 0"); + return NET_EMPTY; //No message to read + } + + //Determine which index to use : 3 (read), then 1 (urgent), then 2 (regular) + int index; + if(m_msgInListsCount[2]) + { + index = 3; + } + else if(m_msgInListsCount[0]) + { + index = 1; + } + else //if(m_msgInListsCount[1]) + { + index = 2; + } + + //Prepare infos + m_state = SMS_GET_CMD_SENT; + m_msisdn = (char*) number; + m_msg = (char*) message; + m_maxMsgLength = maxLength; + m_headersToRead = 3; + + m_msisdn[0] = '\0'; + + DBG("Get SMS"); + //Read command + char cmd[32]; + std::sprintf(cmd, "AT!GSMS?%d,1", index); //1 is the oldest message + ret = m_pIf->execute(cmd, this, NULL, DEFAULT_TIMEOUT); + if( ret != OK ) + { + WARN("AT!GSMS returned %d", ret); + m_state = SMS_IDLE; + return NET_PROTOCOL; + } + + //If message is not read, it will be put at the end of the read list + int item; + if( index != 3 ) + { + //Decrement count in relevant list + m_msgInListsCount[index-1]--; + //Increment count in read list + m_msgInListsCount[3-1]++; + item = m_msgInListsCount[3-1]; + //Normally item should be equal to 1 as we'd have read any older messages first + if( item != 1 ) + { + WARN("Still some older messages pending in the read inbox"); + } + } + else + { + //The item is still the oldest one + item = 1; + } + + DBG("Deleting message"); + //Delete message from inbox + std::sprintf(cmd, "AT!DSMS=3"/*,%d", item*/); //FIXME why doesn't that work when specifying the index?? + ret = m_pIf->executeSimple(cmd, NULL, DEFAULT_TIMEOUT); + if(ret != OK) + { + ERR("Could not delete message"); + } + else + { + //Now we can decrease the number of read messages + m_msgInListsCount[3-1]--; + } + + if (m_state != SMS_CMD_PROCESSED) + { + WARN("Message could not be retrieved properly"); + m_state = SMS_IDLE; + return NET_EMPTY; + } + + m_state = SMS_IDLE; + + return OK; +} + + +int CDMASMSInterface::getCount(size_t* pCount) +{ + int ret = updateInbox(); + if(ret) + { + return NET_PROTOCOL; + } + + *pCount = m_msgInListsCount[0] + m_msgInListsCount[1] + m_msgInListsCount[2]; //Urgent messages + regular messages + read messages + + return OK; +} + + +/*virtual*/ int CDMASMSInterface::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) +{ + if(m_state == SMS_SEND_CMD_SENT) + { + DBG("SMS Send: %s", line); + } + else if(m_state == SMS_GET_TX_STATUS_CMD_SENT) + { + if(!strcmp(line, "sent")) + { + m_txState = SMS_SENT; + m_state = SMS_CMD_PROCESSED; + } + else if(!strcmp(line, "failed")) + { + m_txState = SMS_FAILED; + m_state = SMS_CMD_PROCESSED; + } + else if(!strcmp(line, "none")) + { + m_txState = SMS_NONE; + m_state = SMS_CMD_PROCESSED; + } + else if(!strcmp(line, "pending")) + { + m_txState = SMS_PENDING; + m_state = SMS_CMD_PROCESSED; + } + } + else if(m_state == SMS_GET_CMD_SENT) + { + DBG("Header: %s", line); + + if(m_msisdn[0]=='\0') + { + sscanf(line, "From: %16s", m_msisdn); + } + + m_headersToRead--; + + if(m_headersToRead==0) //End of headers + { + if(m_msisdn[0]!='\0') //Checks that the incoming number has been retrieved + { + m_state = SMS_GET_HDR_RECEIVED; + } + else + { + m_state = SMS_IDLE; //Error, signal it + } + } + } + else if(m_state == SMS_GET_HDR_RECEIVED) + { + DBG("Message: %s", line); + size_t cpyLen = MIN( std::strlen(line), m_maxMsgLength - 1 ); + std::memcpy( m_msg, line, cpyLen ); + m_msg[cpyLen] = '\0'; + m_state = SMS_CMD_PROCESSED; + } + else if(m_state == SMS_GET_COUNT_CMD_SENT) + { + DBG("Inbox: %s", line); + int index; + size_t count; + if((strlen(line) > 16) && sscanf(line + 16, "{Index = %d}: %d", &index, &count) == 2) + { + if((index > 0) && (index <=4)) + { + m_msgInListsCount[index-1] = count; + } + if(index == 4) + { + m_state = SMS_CMD_PROCESSED; + } + } + } + return OK; +} + +/*virtual*/ int CDMASMSInterface::onNewEntryPrompt(ATCommandsInterface* pInst) +{ + return OK; +} + + +int CDMASMSInterface::updateInbox() +{ + //Get number of unread/read messages + + DBG("Updating inbox"); + m_msgInListsCount[0] = m_msgInListsCount[1] = m_msgInListsCount[2] = m_msgInListsCount[3] = 0; //Reset counts + + //Get counts + m_state = SMS_GET_COUNT_CMD_SENT; + int ret = m_pIf->execute("AT!CNTSMS", this, NULL, DEFAULT_TIMEOUT); + if( ret != OK ) + { + WARN("AT!CNTSMS returned %d", ret); + m_msgInListsCount[0] = m_msgInListsCount[1] = m_msgInListsCount[2] = m_msgInListsCount[3] = 0; //Invalidate counts + m_state = SMS_IDLE; + return NET_PROTOCOL; + } + + return OK; +} + diff --git a/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.h b/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.h new file mode 100644 index 0000000000..6aa4557c36 --- /dev/null +++ b/libraries/net/cellular/CellularModem/sms/CDMASMSInterface.h @@ -0,0 +1,90 @@ +/* SMSInterface.h */ +/* Copyright (C) 2012 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef CDMASMSINTERFACE_H_ +#define CDMASMSINTERFACE_H_ + +#include "SMSInterface.h" + +#define MAX_SM 8 + +/** Component to use the Short Messages Service (SMS) + * + */ +class CDMASMSInterface : public ISMSInterface, protected IATCommandsProcessor +{ +public: + /** Create SMSInterface instance + @param pIf Pointer to the ATCommandsInterface instance to use + */ + CDMASMSInterface(ATCommandsInterface* pIf); + + /** Initialize interface + Configure SMS commands & register for SMS-related unsolicited result codes + */ + virtual int init(); + + /** Send a SM + @param number The receiver's phone number + @param message The message to send + @return 0 on success, error code on failure + */ + virtual int send(const char* number, const char* message); + + + /** Receive a SM + @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the space for the null-terminating char) + @param message Pointer to a buffer to store the the incoming message + @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) + @return 0 on success, error code on failure + */ + virtual int get(char* number, char* message, size_t maxLength); + + + /** Get the number of SMs in the incoming box + @param pCount pointer to store the number of unprocessed SMs on + @return 0 on success, error code on failure + */ + virtual int getCount(size_t* pCount); + +protected: + //IATCommandsProcessor + virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line); + virtual int onNewEntryPrompt(ATCommandsInterface* pInst); + + int updateInbox(); //Update messages count in the different inboxes + +private: + ATCommandsInterface* m_pIf; + + //Current message + char* m_msg; + size_t m_maxMsgLength; + char* m_msisdn; + + //Messages list + size_t m_msgInListsCount[4]; //4 lists + + size_t m_headersToRead; + + enum { SMS_NONE, SMS_SENT, SMS_PENDING, SMS_FAILED } m_txState; + enum { SMS_IDLE, SMS_SEND_CMD_SENT, SMS_GET_TX_STATUS_CMD_SENT, SMS_GET_CMD_SENT, SMS_GET_HDR_RECEIVED, SMS_GET_COUNT_CMD_SENT, SMS_CMD_PROCESSED } m_state; +}; + +#endif /* CDMASMSINTERFACE_H_ */ diff --git a/libraries/net/VodafoneUSBModem/sms/SMSInterface.cpp b/libraries/net/cellular/CellularModem/sms/GSMSMSInterface.cpp similarity index 88% rename from libraries/net/VodafoneUSBModem/sms/SMSInterface.cpp rename to libraries/net/cellular/CellularModem/sms/GSMSMSInterface.cpp index 33a33a0bcc..2ed50ad126 100644 --- a/libraries/net/VodafoneUSBModem/sms/SMSInterface.cpp +++ b/libraries/net/cellular/CellularModem/sms/GSMSMSInterface.cpp @@ -1,4 +1,4 @@ -/* SMSInterface.cpp */ +/* GSMSMSInterface.cpp */ /* Copyright (C) 2012 mbed.org, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software @@ -19,24 +19,24 @@ #define __DEBUG__ 2 #ifndef __MODULE__ -#define __MODULE__ "SMSInterface.cpp" +#define __MODULE__ "GSMSMSInterface.cpp" #endif #include "core/fwk.h" -#include "SMSInterface.h" +#include "GSMSMSInterface.h" #include #include #define DEFAULT_TIMEOUT 10000 -SMSInterface::SMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL) +GSMSMSInterface::GSMSMSInterface(ATCommandsInterface* pIf) : m_pIf(pIf), m_msg(NULL), m_maxMsgLength(0), m_msisdn(NULL) { m_pIf->registerEventsHandler(this); //Add us to the unsolicited result codes handlers } -int SMSInterface::init() +int GSMSMSInterface::init() { m_msgRefListCount = 0; m_needsUpdate = true; @@ -75,7 +75,7 @@ int SMSInterface::init() return OK; } -int SMSInterface::send(const char* number, const char* message) +int GSMSMSInterface::send(const char* number, const char* message) { if( strlen(number) > 16 ) { @@ -107,7 +107,7 @@ int SMSInterface::send(const char* number, const char* message) } -int SMSInterface::get(char* number, char* message, size_t maxLength) +int GSMSMSInterface::get(char* number, char* message, size_t maxLength) { if( maxLength < 1 ) { @@ -197,7 +197,7 @@ int SMSInterface::get(char* number, char* message, size_t maxLength) } -int SMSInterface::getCount(size_t* pCount) +int GSMSMSInterface::getCount(size_t* pCount) { int ret; @@ -219,7 +219,7 @@ int SMSInterface::getCount(size_t* pCount) } -/*virtual*/ int SMSInterface::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) +/*virtual*/ int GSMSMSInterface::onNewATResponseLine(ATCommandsInterface* pInst, const char* line) { if(m_state == SMS_SEND_CMD_SENT) { @@ -269,7 +269,7 @@ int SMSInterface::getCount(size_t* pCount) return OK; } -/*virtual*/ int SMSInterface::onNewEntryPrompt(ATCommandsInterface* pInst) +/*virtual*/ int GSMSMSInterface::onNewEntryPrompt(ATCommandsInterface* pInst) { if(m_state == SMS_SEND_CMD_SENT) { @@ -316,7 +316,7 @@ int SMSInterface::getCount(size_t* pCount) return OK; } -/*virtual*/ bool SMSInterface::isATCodeHandled(const char* atCode) //Is this AT code handled +/*virtual*/ bool GSMSMSInterface::isATCodeHandled(const char* atCode) //Is this AT code handled { DBG("AT code is %s", atCode); if( strcmp("+CMTI", atCode) == 0 ) @@ -328,27 +328,27 @@ int SMSInterface::getCount(size_t* pCount) return false; } -/*virtual*/ void SMSInterface::onDispatchStart() +/*virtual*/ void GSMSMSInterface::onDispatchStart() { } -/*virtual*/ void SMSInterface::onDispatchStop() +/*virtual*/ void GSMSMSInterface::onDispatchStop() { } -/*virtual*/ char* SMSInterface::getEventsEnableCommand() +/*virtual*/ char* GSMSMSInterface::getEventsEnableCommand() { return "AT+CNMI=2,1,0,0,0"; } -/*virtual*/ char* SMSInterface::getEventsDisableCommand() +/*virtual*/ char* GSMSMSInterface::getEventsDisableCommand() { return "AT+CNMI=0,0,0,0,0"; //Indications will be buffered within the modem and flushed back when the former command is executed } -/*virtual*/ void SMSInterface::onEvent(const char* atCode, const char* evt) +/*virtual*/ void GSMSMSInterface::onEvent(const char* atCode, const char* evt) { if( strcmp("+CMTI", atCode) != 0 ) { @@ -359,7 +359,8 @@ int SMSInterface::getCount(size_t* pCount) //Get index int msgRef; - if( std::sscanf(evt, "\"SM\",%d", &msgRef) == 1 ) + if(( std::sscanf(evt, "\"SM\",%d", &msgRef) == 1 ) || + ( std::sscanf(evt, "\"ME\",%d", &msgRef) == 1 )) { DBG("Adding message to list (ref %d)", msgRef); if(m_inboxMtx.trylock()) @@ -380,7 +381,7 @@ int SMSInterface::getCount(size_t* pCount) } } -int SMSInterface::updateInbox() +int GSMSMSInterface::updateInbox() { //Get memory indexes of unread messages diff --git a/libraries/net/VodafoneUSBModem/sms/SMSInterface.h b/libraries/net/cellular/CellularModem/sms/GSMSMSInterface.h similarity index 87% rename from libraries/net/VodafoneUSBModem/sms/SMSInterface.h rename to libraries/net/cellular/CellularModem/sms/GSMSMSInterface.h index b2b5c5e6bc..446a73e518 100644 --- a/libraries/net/VodafoneUSBModem/sms/SMSInterface.h +++ b/libraries/net/cellular/CellularModem/sms/GSMSMSInterface.h @@ -17,39 +17,33 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef SMSINTERFACE_H_ -#define SMSINTERFACE_H_ +#ifndef GSMSMSINTERFACE_H_ +#define GSMSMSINTERFACE_H_ -#include "core/fwk.h" - -#include "rtos.h" - -#include "at/ATCommandsInterface.h" - -#define MAX_SM 8 +#include "SMSInterface.h" /** Component to use the Short Messages Service (SMS) * */ -class SMSInterface : protected IATCommandsProcessor, IATEventsHandler +class GSMSMSInterface : public ISMSInterface, protected IATCommandsProcessor, IATEventsHandler { public: /** Create SMSInterface instance @param pIf Pointer to the ATCommandsInterface instance to use */ - SMSInterface(ATCommandsInterface* pIf); + GSMSMSInterface(ATCommandsInterface* pIf); /** Initialize interface Configure SMS commands & register for SMS-related unsolicited result codes */ - int init(); + virtual int init(); /** Send a SM @param number The receiver's phone number @param message The message to send @return 0 on success, error code on failure */ - int send(const char* number, const char* message); + virtual int send(const char* number, const char* message); /** Receive a SM @@ -58,14 +52,14 @@ public: @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) @return 0 on success, error code on failure */ - int get(char* number, char* message, size_t maxLength); + virtual int get(char* number, char* message, size_t maxLength); /** Get the number of SMs in the incoming box @param pCount pointer to store the number of unprocessed SMs on @return 0 on success, error code on failure */ - int getCount(size_t* pCount); + virtual int getCount(size_t* pCount); protected: //IATCommandsProcessor @@ -100,4 +94,4 @@ private: enum { SMS_IDLE, SMS_SEND_CMD_SENT, SMS_GET_CMD_SENT, SMS_GET_HDR_RECEIVED, SMS_GET_COUNT_CMD_SENT, SMS_GET_COUNT_HDR_RECEIVED, SMS_CMD_PROCESSED } m_state; }; -#endif /* SMSINTERFACE_H_ */ +#endif /* GSMSMSINTERFACE_H_ */ diff --git a/libraries/net/cellular/CellularModem/sms/SMSInterface.h b/libraries/net/cellular/CellularModem/sms/SMSInterface.h new file mode 100644 index 0000000000..df226709d1 --- /dev/null +++ b/libraries/net/cellular/CellularModem/sms/SMSInterface.h @@ -0,0 +1,67 @@ +/* SMSInterface.h */ +/* Copyright (C) 2012 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef ISMSINTERFACE_H_ +#define ISMSINTERFACE_H_ + +#include "core/fwk.h" + +#include "rtos.h" + +#include "at/ATCommandsInterface.h" + +#define MAX_SM 8 + +/** Component to use the Short Messages Service (SMS) + * + */ +class ISMSInterface +{ +public: + /** Initialize interface + Configure SMS commands & register for SMS-related unsolicited result codes + */ + virtual int init() = 0; + + + /** Send a SM + @param number The receiver's phone number + @param message The message to send + @return 0 on success, error code on failure + */ + virtual int send(const char* number, const char* message) = 0; + + + /** Receive a SM + @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the space for the null-terminating char) + @param message Pointer to a buffer to store the the incoming message + @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) + @return 0 on success, error code on failure + */ + virtual int get(char* number, char* message, size_t maxLength) = 0; + + + /** Get the number of SMs in the incoming box + @param pCount pointer to store the number of unprocessed SMs on + @return 0 on success, error code on failure + */ + virtual int getCount(size_t* pCount) = 0; +}; + +#endif /* ISMSINTERFACE_H_ */ diff --git a/libraries/net/VodafoneUSBModem/ussd/USSDInterface.cpp b/libraries/net/cellular/CellularModem/ussd/USSDInterface.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/ussd/USSDInterface.cpp rename to libraries/net/cellular/CellularModem/ussd/USSDInterface.cpp diff --git a/libraries/net/VodafoneUSBModem/ussd/USSDInterface.h b/libraries/net/cellular/CellularModem/ussd/USSDInterface.h similarity index 100% rename from libraries/net/VodafoneUSBModem/ussd/USSDInterface.h rename to libraries/net/cellular/CellularModem/ussd/USSDInterface.h diff --git a/libraries/net/VodafoneUSBModem/serial/usb/USBSerialStream.cpp b/libraries/net/cellular/CellularUSBModem/serial/usb/USBSerialStream.cpp similarity index 100% rename from libraries/net/VodafoneUSBModem/serial/usb/USBSerialStream.cpp rename to libraries/net/cellular/CellularUSBModem/serial/usb/USBSerialStream.cpp diff --git a/libraries/net/VodafoneUSBModem/serial/usb/USBSerialStream.h b/libraries/net/cellular/CellularUSBModem/serial/usb/USBSerialStream.h similarity index 96% rename from libraries/net/VodafoneUSBModem/serial/usb/USBSerialStream.h rename to libraries/net/cellular/CellularUSBModem/serial/usb/USBSerialStream.h index 0b11dbdc9a..1af5f019db 100644 --- a/libraries/net/VodafoneUSBModem/serial/usb/USBSerialStream.h +++ b/libraries/net/cellular/CellularUSBModem/serial/usb/USBSerialStream.h @@ -23,8 +23,8 @@ #include "core/fwk.h" -#include "USB3GModule/IUSBHostSerial.h" -#include "USB3GModule/IUSBHostSerialListener.h" +#include "USBHost3GModule/IUSBHostSerial.h" +#include "USBHost3GModule/IUSBHostSerialListener.h" #include "rtos.h" #include "core/MtxCircBuffer.h" diff --git a/libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.cpp b/libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.cpp new file mode 100644 index 0000000000..d0a1e52c99 --- /dev/null +++ b/libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.cpp @@ -0,0 +1,114 @@ +/* Copyright (c) 2010-2012 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#define __DEBUG__ 4 +#ifndef __MODULE__ +#define __MODULE__ "UbloxCDMAModemInitializer.cpp" +#endif + +#include "core/dbg.h" + +#include + +#include "UbloxCDMAModemInitializer.h" + +UbloxCDMAModemInitializer::UbloxCDMAModemInitializer(USBHost* pHost) : WANDongleInitializer(pHost) +{ +} + +uint16_t UbloxCDMAModemInitializer::getMSDVid() +{ + return 0x05C6; +} +uint16_t UbloxCDMAModemInitializer::getMSDPid() +{ + return 0x0000; //No MSD mode (presumably) +} + +uint16_t UbloxCDMAModemInitializer::getSerialVid() +{ + return 0x05C6; +} +uint16_t UbloxCDMAModemInitializer::getSerialPid() +{ + return 0x9004; +} + +bool UbloxCDMAModemInitializer::switchMode(USBDeviceConnected* pDev) +{ + return true; +} + +int UbloxCDMAModemInitializer::getSerialPortCount() +{ + return 2; +} + +/*virtual*/ void UbloxCDMAModemInitializer::setVidPid(uint16_t vid, uint16_t pid) +{ + m_currentSerialIntf = 0; + m_currentEndpoint = 0; +} + +/*virtual*/ bool UbloxCDMAModemInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed +{ + DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); + + if( intf_class == 0xFF ) { + if( m_currentSerialIntf == 0 || m_currentSerialIntf == 1) { + m_serialIntfMap[m_currentSerialIntf++] = intf_nb; + return true; + } + m_currentSerialIntf++; + } + + return false; +} + +/*virtual*/ bool UbloxCDMAModemInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used +{ + DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d Current %d", intf_nb, type, dir, m_currentEndpoint); + if(type == BULK_ENDPOINT) { + if( intf_nb == 1 || intf_nb == 0) { + m_currentEndpoint++; + return true; + } else { + m_currentEndpoint++; + } + } + + /* + if(type == INTERRUPT_ENDPOINT) { + if( intf_nb == 1) { + m_currentEndpoint++; + return true; + } else { + m_currentEndpoint++; + } + } + */ + + return false; +} + + +/*virtual*/ int UbloxCDMAModemInitializer::getType() +{ + return WAN_DONGLE_TYPE_UBLOXC200; +} + diff --git a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/IUSBEnumerator.h b/libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.h similarity index 57% rename from libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/IUSBEnumerator.h rename to libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.h index 65c9e8be15..cccec7f8ec 100644 --- a/libraries/net/VodafoneUSBModem/USBHostWANDongle/USBHost/IUSBEnumerator.h +++ b/libraries/net/cellular/UbloxUSBModem/UbloxCDMAModemInitializer.h @@ -16,26 +16,48 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef IUSBENUMERATOR_H_ -#define IUSBENUMERATOR_H_ +#ifndef UBLOXCDMAMODEMINITIALIZER_H +#define UBLOXCDMAMODEMINITIALIZER_H -#include "stdint.h" +#include -#include "USBEndpoint.h" - -/* -Generic interface to implement for "smart" USB enumeration -*/ - -class IUSBEnumerator { -public: - - virtual void setVidPid(uint16_t vid, uint16_t pid) = 0; - - virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) = 0; //Must return true if the interface should be parsed - - virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) = 0; //Must return true if the endpoint will be used +#include "WANDongleInitializer.h" +#include "USBHost.h" +#include "IUSBEnumerator.h" +enum +{ + WAN_DONGLE_TYPE_UBLOXC200 }; -#endif /*IUSBENUMERATOR_H_*/ +class UbloxCDMAModemInitializer : public WANDongleInitializer +{ +public: + UbloxCDMAModemInitializer(USBHost* pHost); + + virtual uint16_t getMSDVid(); + virtual uint16_t getMSDPid(); + + virtual uint16_t getSerialVid(); + virtual uint16_t getSerialPid(); + + virtual bool switchMode(USBDeviceConnected* pDev); + + virtual int getSerialPortCount(); + + virtual void setVidPid(uint16_t vid, uint16_t pid); + + virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed + + virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used + + virtual int getType(); + +private: + + int m_currentSerialIntf; + int m_currentEndpoint; +}; + +#endif + diff --git a/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.cpp b/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.cpp new file mode 100644 index 0000000000..a3a89313db --- /dev/null +++ b/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.cpp @@ -0,0 +1,131 @@ +/* Copyright (c) 2010-2012 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#include "UbloxGSMModemInitializer.h" +#include "core/dbg.h" + +#define __DEBUG__ 0 +#ifndef __MODULE__ +#define __MODULE__ "UbloxGSMModemInitializer.cpp" +#endif + +//----------------------------------------------------------------------- +// mamm, u-blox Modem +//----------------------------------------------------------------------- + +UbloxGSMModemInitializer::UbloxGSMModemInitializer(USBHost* pHost) : WANDongleInitializer(pHost) +{ + +} + +uint16_t UbloxGSMModemInitializer::getMSDVid() { return 0x1546; } +uint16_t UbloxGSMModemInitializer::getMSDPid() { return 0x0000; } + +uint16_t UbloxGSMModemInitializer::getSerialVid() { return 0x1546; } +uint16_t UbloxGSMModemInitializer::getSerialPid() { return 0x1102; } + +bool UbloxGSMModemInitializer::switchMode(USBDeviceConnected* pDev) +{ + for (int i = 0; i < pDev->getNbIntf(); i++) + { + if (pDev->getInterface(i)->intf_class == MSD_CLASS) + { + USBEndpoint* pEp = pDev->getEndpoint(i, BULK_ENDPOINT, OUT); + if ( pEp != NULL ) + { + ERR("MSD descriptor found on device %p, intf %d", (void *)pDev, i); + } + } + } + return false; +} + +#define UBX_SERIALCOUNT 7 + +int UbloxGSMModemInitializer::getSerialPortCount() +{ + return UBX_SERIALCOUNT; +} + +/*virtual*/ void UbloxGSMModemInitializer::setVidPid(uint16_t vid, uint16_t pid) +{ + if( (vid == getSerialVid() ) && ( pid == getSerialPid() ) ) + { + m_hasSwitched = true; + m_currentSerialIntf = 0; + m_endpointsToFetch = UBX_SERIALCOUNT*2; + } + else + { + m_hasSwitched = false; + m_endpointsToFetch = 1; + } +} + +/*virtual*/ bool UbloxGSMModemInitializer::parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol) //Must return true if the interface should be parsed +{ + if( m_hasSwitched ) + { + DBG("Interface #%d; Class:%02x; SubClass:%02x; Protocol:%02x", intf_nb, intf_class, intf_subclass, intf_protocol); + if( intf_class == 0x0A ) + { + if( (m_currentSerialIntf == 0) || (m_currentSerialIntf == 1) ) + { + m_serialIntfMap[m_currentSerialIntf++] = intf_nb; + return true; + } + m_currentSerialIntf++; + } + } + else + { + if( (intf_nb == 0) && (intf_class == MSD_CLASS) ) + { + return true; + } + } + return false; +} + +/*virtual*/ bool UbloxGSMModemInitializer::useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir) //Must return true if the endpoint will be used +{ + if( m_hasSwitched ) + { + DBG("USBEndpoint on Interface #%d; Type:%d; Direction:%d", intf_nb, type, dir); + if( (type == BULK_ENDPOINT) && m_endpointsToFetch ) + { + m_endpointsToFetch--; + return true; + } + } + else + { + if( (type == BULK_ENDPOINT) && (dir == OUT) && m_endpointsToFetch ) + { + m_endpointsToFetch--; + return true; + } + } + return false; +} + +/*virtual*/ int UbloxGSMModemInitializer::getType() +{ + return WAN_DONGLE_TYPE_UBX; +} + diff --git a/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.h b/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.h new file mode 100644 index 0000000000..a1e9e038b4 --- /dev/null +++ b/libraries/net/cellular/UbloxUSBModem/UbloxGSMModemInitializer.h @@ -0,0 +1,63 @@ +/* Copyright (c) 2010-2012 mbed.org, MIT License +* +* Permission is hereby granted, free of charge, to any person obtaining a copy of this software +* and associated documentation files (the "Software"), to deal in the Software without +* restriction, including without limitation the rights to use, copy, modify, merge, publish, +* distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the +* Software is furnished to do so, subject to the following conditions: +* +* The above copyright notice and this permission notice shall be included in all copies or +* substantial portions of the Software. +* +* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING +* BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, +* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +*/ + +#ifndef UBLOXGSMMODEMINITIALIZER_H +#define UBLOXGSNMODEMINITIALIZER_H + +#include "WANDongleInitializer.h" + +enum +{ + WAN_DONGLE_TYPE_UBX +}; + +//----------------------------------------------------------------------- +// mamm, u-blox Modem +//----------------------------------------------------------------------- + +class UbloxGSMModemInitializer : public WANDongleInitializer +{ +public: + UbloxGSMModemInitializer(USBHost* pHost); + + virtual uint16_t getMSDVid(); + virtual uint16_t getMSDPid(); + + virtual uint16_t getSerialVid(); + virtual uint16_t getSerialPid(); + + virtual bool switchMode(USBDeviceConnected* pDev); + + virtual int getSerialPortCount(); + + virtual void setVidPid(uint16_t vid, uint16_t pid); + + virtual bool parseInterface(uint8_t intf_nb, uint8_t intf_class, uint8_t intf_subclass, uint8_t intf_protocol); //Must return true if the interface should be parsed + + virtual bool useEndpoint(uint8_t intf_nb, ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir); //Must return true if the endpoint will be used + + virtual int getType(); + +private: + + bool m_hasSwitched; + int m_currentSerialIntf; + int m_endpointsToFetch; +}; + +#endif diff --git a/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.cpp b/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.cpp new file mode 100644 index 0000000000..eb7be36fe6 --- /dev/null +++ b/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.cpp @@ -0,0 +1,398 @@ +/* UbloxUSBCDMAModem.cpp */ +/* Copyright (C) 2012 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#define __DEBUG__ 4 +#ifndef __MODULE__ +#define __MODULE__ "UbloxUSBCDMAModem.cpp" +#endif + +#include "core/fwk.h" + +#include "UbloxUSBCDMAModem.h" +#include "UbloxCDMAModemInitializer.h" +#include "USBHost.h" + +#define USE_ONE_PORT 1 + +UbloxUSBCDMAModem::UbloxUSBCDMAModem(PinName powerGatingPin /*= NC*/, bool powerGatingOnWhenPinHigh /* = true*/, int serial /* 0 */) : m_dongle(), +m_stream(m_dongle.getSerial(serial)), +m_at(&m_stream), +m_sms(&m_at), m_ppp(&m_stream, DEFAULT_MSISDN_CDMA), +m_dongleConnected(false), m_ipInit(false), m_smsInit(false), m_atOpen(false), +m_powerGatingPin(powerGatingPin), m_powerGatingOnWhenPinHigh(powerGatingOnWhenPinHigh) +{ + USBHost* host = USBHost::getHostInst(); + m_dongle.addInitializer(new UbloxCDMAModemInitializer(host)); + if( m_powerGatingPin != NC ) + { + power(false); //Dongle will have to be powered on manually + } +} + +class CSSProcessor : public IATCommandsProcessor +{ +public: + CSSProcessor() : status(STATUS_REGISTERING) + { + + } + enum REGISTERING_STATUS { STATUS_REGISTERING, STATUS_OK }; + REGISTERING_STATUS getStatus() + { + return status; + } +private: + virtual int onNewATResponseLine(ATCommandsInterface* pInst, const char* line) + { + char b; + char bc[3] = ""; + int sid = 99999; + + //if( sscanf(line, "%*d, %c", &r) == 1 ) + if(sscanf(line, "%*s %c,%2s,%d", &b,bc,&sid)==3) + { + if(strcmp("Z", bc) == 0) + status = STATUS_REGISTERING; + else + status = STATUS_OK; + } + return OK; + } + virtual int onNewEntryPrompt(ATCommandsInterface* pInst) + { + return OK; + } + volatile REGISTERING_STATUS status; +}; + +int UbloxUSBCDMAModem::connect(const char* apn, const char* user, const char* password) +{ + if( !m_ipInit ) + { + m_ipInit = true; + m_ppp.init(); + } + m_ppp.setup(user, password); + + int ret = init(); + if(ret) + { + return ret; + } + + #if USE_ONE_PORT + m_smsInit = false; //SMS status reset + //m_ussdInit = false; //USSD status reset + //m_linkMonitorInit = false; //Link monitor status reset + #endif + + ATCommandsInterface::ATResult result; + + if(apn != NULL) + { + char cmd[48]; + sprintf(cmd, "AT+CGDCONT=1,\"IP\",\"%s\"", apn); + ret = m_at.executeSimple(cmd, &result); + DBG("Result of command: Err code=%d", ret); + DBG("ATResult: AT return=%d (code %d)", result.result, result.code); + DBG("APN set to %s", apn); + } + + + //Connect + DBG("Connecting"); + #if USE_ONE_PORT + m_at.close(); // Closing AT parser + m_atOpen = false; //Will need to be reinitialized afterwards + #endif + + DBG("Connecting PPP"); + + ret = m_ppp.connect(); + DBG("Result of connect: Err code=%d", ret); + return ret; +} + + +int UbloxUSBCDMAModem::disconnect() +{ + DBG("Disconnecting from PPP"); + int ret = m_ppp.disconnect(); + if(ret) + { + ERR("Disconnect returned %d, still trying to disconnect", ret); + } + + //Ugly but leave dongle time to recover + Thread::wait(500); + + #if USE_ONE_PORT + ATCommandsInterface::ATResult result; + DBG("Starting AT thread"); + ret = m_at.open(); + if(ret) + { + return ret; + } + #endif + + DBG("Trying to hangup"); + + #if 0 //Does not appear to work + int tries = 10; + do + { + ret = m_at.executeSimple("+++", &result, 1000); + DBG("Result of command: Err code=%d\n", ret); + DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); + } while(tries-- && ret); + if(!ret) + { + ret = m_at.executeSimple("ATH", &result); + DBG("Result of command: Err code=%d\n", ret); + DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); + } + #endif + + #if USE_ONE_PORT + //Reinit AT parser + ret = m_at.init(); + DBG("Result of command: Err code=%d\n", ret); + if(ret) + { + m_at.close(); // Closing AT parser + DBG("AT Parser closed, could not complete disconnection"); + return NET_TIMEOUT; + } + + #if 0 + m_at.close(); // Closing AT parser + DBG("AT Parser closed"); + #endif + #endif + return OK; +} + +int UbloxUSBCDMAModem::sendSM(const char* number, const char* message) +{ + int ret = init(); + if(ret) + { + return ret; + } + + if(!m_smsInit) + { + ret = m_sms.init(); + if(ret) + { + return ret; + } + m_smsInit = true; + } + + ret = m_sms.send(number, message); + if(ret) + { + return ret; + } + + return OK; +} + +int UbloxUSBCDMAModem::getSM(char* number, char* message, size_t maxLength) +{ + int ret = init(); + if(ret) + { + return ret; + } + + if(!m_smsInit) + { + ret = m_sms.init(); + if(ret) + { + return ret; + } + m_smsInit = true; + } + + ret = m_sms.get(number, message, maxLength); + if(ret) + { + return ret; + } + + return OK; +} + +int UbloxUSBCDMAModem::getSMCount(size_t* pCount) +{ + int ret = init(); + if(ret) + { + return ret; + } + + if(!m_smsInit) + { + ret = m_sms.init(); + if(ret) + { + return ret; + } + m_smsInit = true; + } + + ret = m_sms.getCount(pCount); + if(ret) + { + return ret; + } + + return OK; +} + +ATCommandsInterface* UbloxUSBCDMAModem::getATCommandsInterface() +{ + return &m_at; +} + +int UbloxUSBCDMAModem::power(bool enable) +{ + if( m_powerGatingPin == NC ) + { + return NET_INVALID; //A pin name has not been provided in the constructor + } + + if(!enable) //Will force components to re-init + { + cleanup(); + } + + DigitalOut powerGatingOut(m_powerGatingPin); + powerGatingOut = m_powerGatingOnWhenPinHigh?enable:!enable; + + return OK; +} + +bool UbloxUSBCDMAModem::power() +{ + if( m_powerGatingPin == NC ) + { + return true; //Assume power is always on + } + + DigitalOut powerGatingOut(m_powerGatingPin); + return m_powerGatingOnWhenPinHigh?powerGatingOut:!powerGatingOut; +} + +int UbloxUSBCDMAModem::init() +{ + if( !m_dongleConnected ) + { + if(!power()) + { + //Obviously cannot initialize the dongle if it is disconnected... + ERR("Power is off"); + return NET_INVALID; + } + m_dongleConnected = true; + while( !m_dongle.connected() ) + { + m_dongle.tryConnect(); + Thread::wait(100); + } + } + + if(m_atOpen) + { + return OK; + } + + DBG("Starting AT thread if needed"); + int ret = m_at.open(); + if(ret) + { + return ret; + } + + DBG("Sending initialisation commands"); + ret = m_at.init(); + if(ret) + { + return ret; + } + + if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_UBLOXC200) + { + INFO("Using a UBLOX C200 Dongle"); + } + else + { + WARN("Using an Unknown Dongle"); + } + + ATCommandsInterface::ATResult result; + + //Wait for network registration + CSSProcessor cssProcessor; + do + { + DBG("Waiting for network registration"); + ret = m_at.execute("AT+CSS?", &cssProcessor, &result); + DBG("Result of command: Err code=%d\n", ret); + DBG("ATResult: AT return=%d (code %d)\n", result.result, result.code); + if(cssProcessor.getStatus() == CSSProcessor::STATUS_REGISTERING) + { + Thread::wait(3000); + } + } while(cssProcessor.getStatus() == CSSProcessor::STATUS_REGISTERING); + + m_atOpen = true; + + return OK; +} + +int UbloxUSBCDMAModem::cleanup() +{ + if(m_ppp.isConnected()) + { + WARN("Data connection is still open"); //Try to encourage good behaviour from the user + m_ppp.disconnect(); + } + + m_smsInit = false; +// m_linkMonitorInit = false; + //We don't reset m_ipInit as PPPIPInterface::init() only needs to be called once + + if(m_atOpen) + { + m_at.close(); + m_atOpen = false; + } + + m_dongle.disconnect(); + m_dongleConnected = false; + + return OK; +} + + diff --git a/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.h b/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.h new file mode 100644 index 0000000000..988afb29ad --- /dev/null +++ b/libraries/net/cellular/UbloxUSBModem/UbloxUSBCDMAModem.h @@ -0,0 +1,118 @@ +/* UbloxUSBCDMAModem.h */ +/* Copyright (C) 2012 mbed.org, MIT License + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software + * and associated documentation files (the "Software"), to deal in the Software without restriction, + * including without limitation the rights to use, copy, modify, merge, publish, distribute, + * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or + * substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING + * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND + * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, + * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + */ + +#ifndef UBLOXUSBCDMAMODEM_H_ +#define UBLOXUSBCDMAMODEM_H_ + +#include "core/fwk.h" + +#include "WANDongle.h" +#include "at/ATCommandsInterface.h" +#include "USBSerialStream.h" +#include "ip/PPPIPInterface.h" +#include "sms/CDMASMSInterface.h" +#include "CellularModem.h" + +/** u-blox LISA-C200 modem + */ +class UbloxUSBCDMAModem: public CellularModem +{ +public: + /** Create Sprint USB Modem (Sierra Wireless 598U) API instance + @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line + @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true + */ + UbloxUSBCDMAModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true, int serial = 0); + + //Internet-related functions + + /** Open a 3G internet connection + @return 0 on success, error code on failure + */ + virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL); + + /** Close the internet connection + @return 0 on success, error code on failure + */ + virtual int disconnect(); + + + /** Send a SM + @param number The receiver's phone number + @param message The message to send + @return 0 on success, error code on failure + */ + virtual int sendSM(const char* number, const char* message); + + + /** Receive a SM + @param number Pointer to a buffer to store the sender's phone number (must be at least 17 characters-long, including the sapce for the null-terminating char) + @param message Pointer to a buffer to store the the incoming message + @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) + @return 0 on success, error code on failure + */ + virtual int getSM(char* number, char* message, size_t maxLength); + + /** Get the number of SMs in the incoming box + @param pCount pointer to store the number of unprocessed SMs on + @return 0 on success, error code on failure + */ + virtual int getSMCount(size_t* pCount); + + /** Get the ATCommandsInterface instance + @return Pointer to the ATCommandsInterface instance + */ + virtual ATCommandsInterface* getATCommandsInterface(); + + /** Switch power on or off + In order to use this function, a pin name must have been entered in the constructor + @param enable true to switch the dongle on, false to switch it off + @return 0 on success, error code on failure + */ + virtual int power(bool enable); + +protected: + bool power(); + + int init(); + int cleanup(); + +private: + WANDongle m_dongle; + + USBSerialStream m_stream; + + ATCommandsInterface m_at; + + CDMASMSInterface m_sms; + + PPPIPInterface m_ppp; + + bool m_dongleConnected; + bool m_ipInit; + bool m_smsInit; + bool m_atOpen; + + PinName m_powerGatingPin; + bool m_powerGatingOnWhenPinHigh; +}; + + +#endif /* UBLOXUSBCDMAMODEM_H_ */ + diff --git a/libraries/net/VodafoneUSBModem/VodafoneUSBModem.cpp b/libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.cpp similarity index 77% rename from libraries/net/VodafoneUSBModem/VodafoneUSBModem.cpp rename to libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.cpp index 0b7b31c595..56ceacc63e 100644 --- a/libraries/net/VodafoneUSBModem/VodafoneUSBModem.cpp +++ b/libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.cpp @@ -1,4 +1,4 @@ -/* VodafoneUSBModem.cpp */ +/* UbloxUSBGSMModem.cpp */ /* Copyright (C) 2012 mbed.org, MIT License * * Permission is hereby granted, free of charge, to any person obtaining a copy of this software @@ -19,31 +19,35 @@ #define __DEBUG__ 3 #ifndef __MODULE__ -#define __MODULE__ "VodafoneUSBModem.cpp" +#define __MODULE__ "UbloxUSBGSMModem.cpp" #endif #include "core/fwk.h" -#include "VodafoneUSBModem.h" +#include "UbloxUSBGSMModem.h" +#include "UbloxGSMModemInitializer.h" +#include "USBHost.h" -VodafoneUSBModem::VodafoneUSBModem(PinName powerGatingPin /*= NC*/, bool powerGatingOnWhenPinHigh /* = true*/) : - m_dongle(), // Construct WANDongle: USB interface with two serial channels to the modem (USBSerialStream objects) - m_atStream(m_dongle.getSerial(1)), // AT commands are sent down one serial channel. - m_pppStream(m_dongle.getSerial(0)), // PPP connections are managed via another serial channel. - m_at(&m_atStream), // Construct ATCommandsInterface with the AT serial channel - m_sms(&m_at), // Construct SMSInterface with the ATCommandsInterface - m_ussd(&m_at), // Construct USSDInterface with the ATCommandsInterface - m_linkMonitor(&m_at), // Construct LinkMonitor with the ATCommandsInterface - m_ppp(&m_pppStream), // Construct PPPIPInterface with the PPP serial channel - m_dongleConnected(false), // Dongle is initially not ready for anything - m_ipInit(false), // PPIPInterface connection is initially down - m_smsInit(false), // SMSInterface starts un-initialised - m_ussdInit(false), // USSDInterface starts un-initialised - m_linkMonitorInit(false), // LinkMonitor subsystem starts un-initialised - m_atOpen(false), // ATCommandsInterface starts in a closed state - m_powerGatingPin(powerGatingPin), // set power gating pin +UbloxUSBGSMModem::UbloxUSBGSMModem(PinName powerGatingPin /*= NC*/, bool powerGatingOnWhenPinHigh /* = true*/) : + m_dongle(), // Construct WANDongle: USB interface with two serial channels to the modem (USBSerialStream objects) + m_atStream(m_dongle.getSerial(1)), // AT commands are sent down one serial channel. + m_pppStream(m_dongle.getSerial(0)), // PPP connections are managed via another serial channel. + m_at(&m_atStream), // Construct ATCommandsInterface with the AT serial channel + m_sms(&m_at), // Construct SMSInterface with the ATCommandsInterface + m_ussd(&m_at), // Construct USSDInterface with the ATCommandsInterface + m_linkMonitor(&m_at), // Construct LinkMonitor with the ATCommandsInterface + m_ppp(&m_pppStream, DEFAULT_MSISDN_GSM), // Construct PPPIPInterface with the PPP serial channel + m_dongleConnected(false), // Dongle is initially not ready for anything + m_ipInit(false), // PPIPInterface connection is initially down + m_smsInit(false), // SMSInterface starts un-initialised + m_ussdInit(false), // USSDInterface starts un-initialised + m_linkMonitorInit(false), // LinkMonitor subsystem starts un-initialised + m_atOpen(false), // ATCommandsInterface starts in a closed state + m_powerGatingPin(powerGatingPin), // set power gating pin m_powerGatingOnWhenPinHigh(powerGatingOnWhenPinHigh) // set state semantics for power gating pin { + USBHost* host = USBHost::getHostInst(); + m_dongle.addInitializer(new UbloxGSMModemInitializer(host)); if( m_powerGatingPin != NC ) { power(false); //Dongle will have to be powered on manually @@ -174,7 +178,7 @@ private: }; #endif -int VodafoneUSBModem::connect(const char* apn, const char* user, const char* password) +int UbloxUSBGSMModem::connect(const char* apn, const char* user, const char* password) { if( !m_ipInit ) { @@ -273,7 +277,7 @@ int VodafoneUSBModem::connect(const char* apn, const char* user, const char* pas } -int VodafoneUSBModem::disconnect() +int UbloxUSBGSMModem::disconnect() { DBG("Disconnecting from PPP"); int ret = m_ppp.disconnect(); @@ -332,7 +336,7 @@ int VodafoneUSBModem::disconnect() return OK; } -int VodafoneUSBModem::sendSM(const char* number, const char* message) +int UbloxUSBGSMModem::sendSM(const char* number, const char* message) { int ret = init(); if(ret) @@ -359,7 +363,7 @@ int VodafoneUSBModem::sendSM(const char* number, const char* message) return OK; } -int VodafoneUSBModem::getSM(char* number, char* message, size_t maxLength) +int UbloxUSBGSMModem::getSM(char* number, char* message, size_t maxLength) { int ret = init(); if(ret) @@ -386,7 +390,7 @@ int VodafoneUSBModem::getSM(char* number, char* message, size_t maxLength) return OK; } -int VodafoneUSBModem::getSMCount(size_t* pCount) +int UbloxUSBGSMModem::getSMCount(size_t* pCount) { int ret = init(); if(ret) @@ -413,7 +417,7 @@ int VodafoneUSBModem::getSMCount(size_t* pCount) return OK; } -int VodafoneUSBModem::sendUSSD(const char* command, char* result, size_t maxLength) +int UbloxUSBGSMModem::sendUSSD(const char* command, char* result, size_t maxLength) { int ret = init(); if(ret) @@ -440,7 +444,7 @@ int VodafoneUSBModem::sendUSSD(const char* command, char* result, size_t maxLeng return OK; } -int VodafoneUSBModem::getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer) +int UbloxUSBGSMModem::getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* pRegistrationState, LinkMonitor::BEARER* pBearer) { int ret = init(); if(ret) @@ -468,12 +472,12 @@ int VodafoneUSBModem::getLinkState(int* pRssi, LinkMonitor::REGISTRATION_STATE* } -ATCommandsInterface* VodafoneUSBModem::getATCommandsInterface() +ATCommandsInterface* UbloxUSBGSMModem::getATCommandsInterface() { return &m_at; } -int VodafoneUSBModem::power(bool enable) +int UbloxUSBGSMModem::power(bool enable) { if( m_powerGatingPin == NC ) { @@ -491,7 +495,7 @@ int VodafoneUSBModem::power(bool enable) return OK; } -bool VodafoneUSBModem::power() +bool UbloxUSBGSMModem::power() { if( m_powerGatingPin == NC ) { @@ -502,7 +506,7 @@ bool VodafoneUSBModem::power() return m_powerGatingOnWhenPinHigh?powerGatingOut:!powerGatingOut; } -int VodafoneUSBModem::init() +int UbloxUSBGSMModem::init() { if( !m_dongleConnected ) { @@ -539,38 +543,9 @@ int VodafoneUSBModem::init() return ret; } - if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VODAFONEK3770) + if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_UBX) { - INFO("Using a Vodafone K3770 Dongle"); - #if USE_ONE_PORT - DBG("Configuring unsolicited result codes support properly"); - //Configuring port to enable 3GPP-compliant unsollicited response codes but disable Huawei-specific unsollicited response codes - ret = m_at.executeSimple("AT^CURC=0;^PORTSEL=1", NULL); //Huawei-specific, not 3GPP-compliant - if(ret != OK) - { - return NET_PROTOCOL; - } - #else - //Configuring port to disable Huawei-specific unsollicited response codes - ret = m_at.executeSimple("AT^CURC=0", NULL); //Huawei-specific, not 3GPP-compliant - if(ret != OK) - { - return NET_PROTOCOL; - } - #endif - } - else if(m_dongle.getDongleType() == WAN_DONGLE_TYPE_VODAFONEK3772Z) - { - INFO("Using a Vodafone K3772-Z Dongle"); - //FIXME this returns %USBMODEM: [0] MODEM DRIVEROK which is not a compliant response - /* - //Configuring modem to directly boot into modem mode - ret = m_at.executeSimple("AT%USBMODEM=0", NULL); //Icera-specific, not 3GPP-compliant - if(ret != OK) - { - return NET_PROTOCOL; - } - */ + INFO("Using a u-blox LISA-U"); } else { @@ -603,7 +578,7 @@ int VodafoneUSBModem::init() return OK; } -int VodafoneUSBModem::cleanup() +int UbloxUSBGSMModem::cleanup() { if(m_ppp.isConnected()) { diff --git a/libraries/net/VodafoneUSBModem/VodafoneUSBModem.h b/libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.h similarity index 87% rename from libraries/net/VodafoneUSBModem/VodafoneUSBModem.h rename to libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.h index c93d027884..2cc432a2c2 100644 --- a/libraries/net/VodafoneUSBModem/VodafoneUSBModem.h +++ b/libraries/net/cellular/UbloxUSBModem/UbloxUSBGSMModem.h @@ -17,8 +17,8 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ -#ifndef VODAFONEUSBMODEM_H_ -#define VODAFONEUSBMODEM_H_ +#ifndef UBLOXUSBGSMMODEM_H_ +#define UBLOXUSBGSMMODEM_H_ #include "core/fwk.h" @@ -26,32 +26,33 @@ #include "at/ATCommandsInterface.h" #include "serial/usb/USBSerialStream.h" #include "ip/PPPIPInterface.h" -#include "sms/SMSInterface.h" +#include "sms/GSMSMSInterface.h" #include "ussd/USSDInterface.h" #include "link/LinkMonitor.h" +#include "CellularModem.h" -/** Vodafone USB Modem (K3770/K3772-Z) dongle +/** u-blox WCDMA modem (LISA-U200) */ -class VodafoneUSBModem +class UbloxUSBGSMModem: public CellularModem { public: - /** Create Vodafone USB Modem (K3770/K3772-Z) dongle API instance + /** Create u-blox API instance @param powerGatingPin Optional pin commanding a power gating transistor on the modem's power line @param powerGatingOnWhenPinHigh true if the pin needs to be high to power the dongle, defaults to true */ - VodafoneUSBModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true); + UbloxUSBGSMModem(PinName powerGatingPin = NC, bool powerGatingOnWhenPinHigh = true); //Internet-related functions /** Open a 3G internet connection @return 0 on success, error code on failure */ - int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL); + virtual int connect(const char* apn = NULL, const char* user = NULL, const char* password = NULL); /** Close the internet connection @return 0 on success, error code on failure */ - int disconnect(); + virtual int disconnect(); /** Send a SM @@ -59,7 +60,7 @@ public: @param message The message to send @return 0 on success, error code on failure */ - int sendSM(const char* number, const char* message); + virtual int sendSM(const char* number, const char* message); /** Receive a SM @@ -68,13 +69,13 @@ public: @param maxLength Maximum message length that can be stored in buffer (including null-terminating character) @return 0 on success, error code on failure */ - int getSM(char* number, char* message, size_t maxLength); + virtual int getSM(char* number, char* message, size_t maxLength); /** Get the number of SMs in the incoming box @param pCount pointer to store the number of unprocessed SMs on @return 0 on success, error code on failure */ - int getSMCount(size_t* pCount); + virtual int getSMCount(size_t* pCount); /** Send a USSD command & wait for its result @param command The command to send @@ -95,14 +96,14 @@ public: /** Get the ATCommandsInterface instance @return Pointer to the ATCommandsInterface instance */ - ATCommandsInterface* getATCommandsInterface(); + virtual ATCommandsInterface* getATCommandsInterface(); /** Switch power on or off In order to use this function, a pin name must have been entered in the constructor @param enable true to switch the dongle on, false to switch it off @return 0 on success, error code on failure */ - int power(bool enable); + virtual int power(bool enable); protected: bool power(); //< Turn power to USB dongle ON. @@ -133,7 +134,7 @@ private: ATCommandsInterface m_at; //< Interface to AT commands processing - SMSInterface m_sms; //< Interface to SMS manager (send/receive etc) + GSMSMSInterface m_sms; //< Interface to SMS manager (send/receive etc) USSDInterface m_ussd; //< Interface to USSD manager (send etc) LinkMonitor m_linkMonitor; //< Interface to link monitor (RSSI) @@ -151,4 +152,4 @@ private: }; -#endif /* VODAFONEUSBMODEM_H_ */ +#endif /* UBLOXMODEM_H_ */ diff --git a/libraries/tests/mbed/interrupt_chaining/interruptin/main.cpp b/libraries/tests/mbed/interrupt_chaining/interruptin/main.cpp deleted file mode 100644 index 65c3b6fdcf..0000000000 --- a/libraries/tests/mbed/interrupt_chaining/interruptin/main.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "test_env.h" - -DigitalOut myled(LED1); -DigitalOut led2(LED2); -DigitalOut led3(LED3); - -volatile int checks = 0; -volatile int total = 0; -void in_handler() { - checks++; - led2 = !led2; -} - -#if defined(TARGET_KL25Z) -#define PIN_OUT PTC6 -#define PIN_IN PTA5 - -#elif defined(TARGET_KL05Z) -#define PIN_OUT PTB11 -#define PIN_IN PTB1 - -#elif defined(TARGET_LPC812) -#define PIN_OUT D10 -#define PIN_IN D11 - -#elif defined(TARGET_LPC4088) -#define PIN_IN (p11) -#define PIN_OUT (p12) - -#elif defined(TARGET_LPC1114) -#define PIN_IN (dp1) -#define PIN_OUT (dp2) - -#else -#define PIN_IN (p5) -#define PIN_OUT (p25) - -#endif - -DigitalOut out(PIN_OUT); -InterruptIn in(PIN_IN); - -void flipper() { - for (int i = 0; i < 5; i++) { - out = 1; myled = 1; wait(0.2); - - out = 0; myled = 0; wait(0.2); - } -} - -void flipper2() { - led3 = !led3; -} - -void handler2() { - total++; -} - -int object_cnt = 0; - -class Incrementer { -public: - Incrementer() : _cnt(0) {} - void inc() { _cnt++; } - int get() const { return _cnt; } -private: - int _cnt; -}; - -int main() { - out = 0; myled = 0; - - //Test falling edges first - Incrementer i1; - in.rise(NULL); - in.fall(in_handler); - in.fall_add(handler2); - in.fall_add(flipper2); - in.fall_add_front(&i1, &Incrementer::inc); - flipper(); - - if(checks != 5 || i1.get() != 5) { - printf("falling edges test failed\n"); - notify_completion(false); - } - - //Now test rising edges - Incrementer i2; - in.rise(in_handler); - in.rise_add(handler2); - in.rise_add(&i2, &Incrementer::inc); - in.rise_add_front(flipper2); - in.fall(NULL); - flipper(); - - if (checks != 10 || i2.get() != 5) { - printf("raising edges test failed\n"); - notify_completion(false); - } - - //Finally test both - in.rise(in_handler); - in.rise_add(handler2); - pFunctionPointer_t rise_led = in.rise_add(flipper2); - in.fall(in_handler); - in.fall_add(handler2); - pFunctionPointer_t fall_led = in.fall_add(flipper2); - if (!in.rise_remove(rise_led) || !in.fall_remove(fall_led)) { - printf("remove handler failed\n"); - notify_completion(false); - } - flipper(); - - if (checks != 20) { - printf("Simultaneous rising and falling edges failed! check=%d\n", checks); - notify_completion(false); - } - printf("Total: %d\n", total); - notify_completion(true); - return 0; -} diff --git a/libraries/tests/mbed/interrupt_chaining/ticker/main.cpp b/libraries/tests/mbed/interrupt_chaining/main.cpp similarity index 96% rename from libraries/tests/mbed/interrupt_chaining/ticker/main.cpp rename to libraries/tests/mbed/interrupt_chaining/main.cpp index 3068aed584..65bc3ef699 100644 --- a/libraries/tests/mbed/interrupt_chaining/ticker/main.cpp +++ b/libraries/tests/mbed/interrupt_chaining/main.cpp @@ -84,9 +84,7 @@ int main() { // Test chaining inside Serial class flipper_1.attach(&flip_1, 1.0); // the address of the function to be attached (flip) and the interval (1 second) - flipper_1.add_function_front(&s1, &Sender::send); flipper_2.attach(&flip_2, 2.0); // the address of the function to be attached (flip) and the interval (2 seconds) - flipper_2.add_function(&s2, &Sender::send); // Test global chaining (InterruptManager) printf("Handler initially: %08X\n", initial_handler = NVIC_GetVector(TIMER_IRQ)); diff --git a/libraries/tests/mbed/interrupt_chaining/serial_interrupt/main.cpp b/libraries/tests/mbed/interrupt_chaining/serial_interrupt/main.cpp deleted file mode 100644 index 924f262229..0000000000 --- a/libraries/tests/mbed/interrupt_chaining/serial_interrupt/main.cpp +++ /dev/null @@ -1,41 +0,0 @@ -#include "mbed.h" - -DigitalOut led1(LED1); -DigitalOut led2(LED2); - -Serial computer(USBTX, USBRX); - -// This function is called when a character goes into the TX buffer. -void txCallback() { - led1 = !led1; -} - -// This function is called when a character goes into the RX buffer. -void rxCallback() { - led2 = !led2; - computer.putc(computer.getc()); -} - -class Counter { -public: - Counter(const char* name): _name(name), _cnt(0) {} - void inc() { _cnt++; } - void show() const { printf("%s: %d\n", _name, _cnt); } - int get() const { return _cnt; } - ~Counter() { show(); } -private: - const char *_name; - volatile int _cnt; -}; - -int main() { - printf("start test\n"); - Counter rx("RX bytes"), tx("TX bytes"); - - computer.attach(&txCallback, Serial::TxIrq); - computer.add_handler(&tx, &Counter::inc, Serial::TxIrq); - computer.attach(&rxCallback, Serial::RxIrq); - computer.add_handler_front(&rx, &Counter::inc, Serial::RxIrq); - - while (rx.get() < 40); -} diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/HTTPClient.cpp b/libraries/tests/net/cellular/http/common/HTTPClient/HTTPClient.cpp similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/HTTPClient.cpp rename to libraries/tests/net/cellular/http/common/HTTPClient/HTTPClient.cpp diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/HTTPClient.h b/libraries/tests/net/cellular/http/common/HTTPClient/HTTPClient.h similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/HTTPClient.h rename to libraries/tests/net/cellular/http/common/HTTPClient/HTTPClient.h diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/IHTTPData.h b/libraries/tests/net/cellular/http/common/HTTPClient/IHTTPData.h similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/IHTTPData.h rename to libraries/tests/net/cellular/http/common/HTTPClient/IHTTPData.h diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPMap.cpp b/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPMap.cpp rename to libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.cpp diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPMap.h b/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPMap.h rename to libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPMap.h diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.cpp b/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.cpp rename to libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.cpp diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.h b/libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h similarity index 100% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/HTTPClient/data/HTTPText.h rename to libraries/tests/net/cellular/http/common/HTTPClient/data/HTTPText.h diff --git a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/main.cpp b/libraries/tests/net/cellular/http/common/httptest.cpp similarity index 74% rename from libraries/tests/net/vodafone/HTTPClient_HelloWorld/main.cpp rename to libraries/tests/net/cellular/http/common/httptest.cpp index cc8aabdc99..3bbc4673ea 100644 --- a/libraries/tests/net/vodafone/HTTPClient_HelloWorld/main.cpp +++ b/libraries/tests/net/cellular/http/common/httptest.cpp @@ -1,21 +1,22 @@ #include "mbed.h" -#include "VodafoneUSBModem.h" +#include "CellularModem.h" #include "HTTPClient.h" -#include "test_env.h" +#include "httptest.h" -int main() +int httptest(CellularModem& modem, const char* apn, const char* username, const char* password) { printf("Connecting...\n"); - VodafoneUSBModem modem; HTTPClient http; char str[512]; - int ret = modem.connect("internet", "web", "web"); + modem.power(true); + Thread::wait(1000); + int ret = modem.connect(apn, username, password); if(ret) { printf("Could not connect\n"); - notify_completion(false); //Blocks indefinitely + return false; } //GET data @@ -30,7 +31,7 @@ int main() { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); modem.disconnect(); - notify_completion(false); //Blocks indefinitely + return false; } //POST data @@ -49,10 +50,9 @@ int main() { printf("Error - ret = %d - HTTP return code = %d\n", ret, http.getHTTPResponseCode()); modem.disconnect(); - notify_completion(false); //Blocks indefinitely + return false; } - modem.disconnect(); - - notify_completion(true); //Blocks indefinitely + modem.disconnect(); + return true; } diff --git a/libraries/tests/net/cellular/http/common/httptest.h b/libraries/tests/net/cellular/http/common/httptest.h new file mode 100644 index 0000000000..affd6d23be --- /dev/null +++ b/libraries/tests/net/cellular/http/common/httptest.h @@ -0,0 +1,9 @@ +#ifndef HTTPTEST_H_ +#define HTTPTEST_H_ + +#include "CellularModem.h" + +int httptest(CellularModem& modem, const char* apn = NULL, const char* username = NULL, const char* password= NULL); + +#endif + diff --git a/libraries/tests/net/cellular/http/ubloxusb/main.cpp b/libraries/tests/net/cellular/http/ubloxusb/main.cpp new file mode 100644 index 0000000000..3454114579 --- /dev/null +++ b/libraries/tests/net/cellular/http/ubloxusb/main.cpp @@ -0,0 +1,35 @@ +#include "UbloxUSBGSMModem.h" +#include "UbloxUSBCDMAModem.h" +#include "httptest.h" + +#if !defined(MODEM_UBLOX_GSM) && !defined(MODEM_UBLOX_CDMA) +#warning No modem defined, using GSM by default +#define MODEM_UBLOX_GSM +#endif + +#ifndef MODEM_APN +#warning APN not specified, using "internet" +#define MODEM_APN "internet" +#endif + +#ifndef MODEM_USERNAME +#warning username not specified +#define MODEM_USERNAME NULL +#endif + +#ifndef MODEM_PASSWORD +#warning password not specified +#define MODEM_PASSWORD NULL +#endif + +int main() +{ +#ifdef MODEM_UBLOX_GSM + UbloxUSBGSMModem modem; +#else + UbloxUSBCDMAModem modem(p18, true, 1); +#endif + httptest(modem, MODEM_APN, MODEM_USERNAME, MODEM_PASSWORD); + while (true); +} + diff --git a/libraries/tests/net/cellular/sms/common/smstest.cpp b/libraries/tests/net/cellular/sms/common/smstest.cpp new file mode 100644 index 0000000000..ca55e88543 --- /dev/null +++ b/libraries/tests/net/cellular/sms/common/smstest.cpp @@ -0,0 +1,41 @@ +#include "CellularModem.h" +#include "smstest.h" + +void smstest(CellularModem& modem) +{ + modem.power(true); + Thread::wait(1000); + +#ifdef DESTINATION_NUMBER + modem.sendSM(DESINATION_NUMBER, "Hello from mbed:)"); +#endif + + while(true) + { + char num[17]; + char msg[64]; + size_t count; + int ret = modem.getSMCount(&count); + if(ret) + { + printf("getSMCount returned %d\n", ret); + Thread::wait(3000); + continue; + } + if( count > 0) + { + printf("%d SMS to read\n", count); + ret = modem.getSM(num, msg, 64); + if(ret) + { + printf("getSM returned %d\n", ret); + Thread::wait(3000); + continue; + } + + printf("%s : %s\n", num, msg); + } + Thread::wait(3000); + } +} + diff --git a/libraries/tests/net/cellular/sms/common/smstest.h b/libraries/tests/net/cellular/sms/common/smstest.h new file mode 100644 index 0000000000..0d1ea80fc7 --- /dev/null +++ b/libraries/tests/net/cellular/sms/common/smstest.h @@ -0,0 +1,9 @@ +#ifndef SMSTEST_H_ +#define SMSTEST_H_ + +#include "CellularModem.h" + +void smstest(CellularModem&); + +#endif + diff --git a/libraries/tests/net/cellular/sms/ubloxusb/main.cpp b/libraries/tests/net/cellular/sms/ubloxusb/main.cpp new file mode 100644 index 0000000000..a493be7bfe --- /dev/null +++ b/libraries/tests/net/cellular/sms/ubloxusb/main.cpp @@ -0,0 +1,21 @@ +#include "UbloxUSBGSMModem.h" +#include "UbloxUSBCDMAModem.h" +#include "smstest.h" + +#if !defined(MODEM_UBLOX_GSM) && !defined(MODEM_UBLOX_CDMA) +#warning No modem defined, using GSM by default +#define MODEM_UBLOX_GSM +#endif + +int main() +{ +#ifdef MODEM_UBLOX_GSM + UbloxUSBGSMModem modem; +#else + UbloxUSBCDMAModem modem(p18, true, 1); +#endif + + smstest(modem); + while (true); +} + diff --git a/libraries/tests/net/vodafone/USSD_SMS_HelloWorld/main.cpp b/libraries/tests/net/vodafone/USSD_SMS_HelloWorld/main.cpp deleted file mode 100644 index 30aafb2df5..0000000000 --- a/libraries/tests/net/vodafone/USSD_SMS_HelloWorld/main.cpp +++ /dev/null @@ -1,138 +0,0 @@ -#include "mbed.h" -#include "VodafoneUSBModem.h" -#include "test_env.h" - -bool compare_msisdn(char* remote_msisdn, char* local_msisdn) -{ - if( !memcmp(remote_msisdn, "+44", 3) ) //Conver to local number - { - remote_msisdn += 2; - remote_msisdn[0] = '0'; - } - if( !memcmp(local_msisdn, "+44", 3) ) //Conver to local number - { - local_msisdn += 2; - local_msisdn[0] = '0'; - } - return !strcmp(remote_msisdn, local_msisdn); -} - -bool run(VodafoneUSBModem& modem) -{ - char local_msisdn[32]; - char remote_msisdn[32]; - char local_msg[192]; - char remote_msg[192]; - - int ret; - //Clear SMS inbox - size_t count; - do - { - ret = modem.getSMCount(&count); - if(ret) - { - return false; - } - if(count) - { - //Fetch SMS - ret = modem.getSM(remote_msisdn, remote_msg, 192); - if(ret) - { - return false; - } - } - } while(count); - - //Now get MSISDN using USSD - ret = modem.sendUSSD("*#100#", local_msisdn, 32); - if(ret) - { - return false; - } - - printf("Local MSISDN is %s\n", local_msisdn); - - //Makeup a random text message (32 uppper case letters) - for(int i = 0; i < 32; i++) - { - local_msg[i] = 'A' + (rand() % 26); //This is pseudo-random only, but we don't really care anyway - } - local_msg[32] = '\0'; //Terminate string - - printf("Sending '%s'\n", local_msg); - - //Send SM - ret = modem.sendSM(local_msisdn, local_msg); - if(ret) - { - return false; - } - - //Now wait for corresponding message for 15s max - Timer t; - t.start(); - do - { - ret = modem.getSMCount(&count); - if(ret) - { - return false; - } - if(count) - { - //Fetch SM - ret = modem.getSM(remote_msisdn, remote_msg, 192); - if(ret) - { - return false; - } - - printf("Received '%s' from %s\n", remote_msg, remote_msisdn); - - if( compare_msisdn(remote_msisdn, local_msisdn) && !strcmp(remote_msg, local_msg) ) - { - break; - } - } - if(t.read_ms() > 15000) - { - return false; - } - Thread::wait(500); - } while(true); - - //Success :) - return true; -} - -void test(void const*) -{ - VodafoneUSBModem modem; - bool test = run(modem); - if(test) - { - printf("Test successful\n"); - notify_completion(true); - } - else - { - printf("Test failed\n"); - notify_completion(false); - } - //notify_completion() blocks indefinitely -} - -int main() -{ - Thread testTask(test, NULL, osPriorityNormal, 1024 * 5); - DigitalOut led(LED1); - while(1) - { - led=!led; - Thread::wait(1000); - } - - return 0; -} diff --git a/setup.py b/setup.py new file mode 100644 index 0000000000..c63fadee2e --- /dev/null +++ b/setup.py @@ -0,0 +1,24 @@ +""" +This module defines the attributes of the +PyPI package for the Mbed SDK +""" + +from distutils.core import setup + +LICENSE = open('LICENSE').read() +DESCRIPTION = """A set of Python scripts that can be used to compile programs written on top of the `mbed framework`_. It can also be used to export mbed projects to other build systems and IDEs (uVision, IAR, makefiles). + +.. _mbed framework: http://mbed.org""" +OWNER_NAMES = 'emilmont, bogdanm' +OWNER_EMAILS = 'Emilio.Monti@arm.com, Bogdan.Marinescu@arm.com' + +setup(name='mbed-tools', + version='0.1.7', + description='Build and test system for mbed', + long_description=DESCRIPTION, + author=OWNER_NAMES, + author_email=OWNER_EMAILS, + maintainer=OWNER_NAMES, + maintainer_email=OWNER_EMAILS, + url='https://github.com/mbedmicro/mbed', + license=LICENSE) diff --git a/workspace_tools/build.py b/workspace_tools/build.py index d57b54c819..1cf2eb4acb 100644 --- a/workspace_tools/build.py +++ b/workspace_tools/build.py @@ -42,8 +42,6 @@ if __name__ == '__main__': default=False, help="Compile the rtos") parser.add_option("-e", "--eth", action="store_true", dest="eth", default=False, help="Compile the ethernet library") - parser.add_option("-V", "--vodafone", action="store_true", dest="vodafone", - default=False, help="Compile the Vodafone library") parser.add_option("-U", "--usb_host", action="store_true", dest="usb_host", default=False, help="Compile the USB Host library") parser.add_option("-u", "--usb", action="store_true", dest="usb", @@ -52,6 +50,10 @@ if __name__ == '__main__': default=False, help="Compile the DSP library") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose diagnostic output") + parser.add_option("-b", "--ublox", action="store_true", dest="ublox", + default=False, help="Compile the u-blox library") + parser.add_option("-D", "", action="append", dest="macros", + help="Add a macro definition") (options, args) = parser.parse_args() # Get target list @@ -74,14 +76,14 @@ if __name__ == '__main__': libraries.extend(["rtx", "rtos"]) if options.eth: libraries.append("eth") - if options.vodafone: - libraries.append("vodafone") if options.usb: libraries.append("usb") if options.usb_host: libraries.append("usb_host") if options.dsp: libraries.extend(["cmsis_dsp", "dsp"]) + if options.ublox: + libraries.extend(["rtx", "rtos", "usb_host", "ublox"]) # Build failures = [] @@ -92,10 +94,12 @@ if __name__ == '__main__': try: mcu = TARGET_MAP[target] build_mbed_libs(mcu, toolchain, options=options.options, - verbose=options.verbose, clean=options.clean) + verbose=options.verbose, clean=options.clean, + macros=options.macros) for lib_id in libraries: build_lib(lib_id, mcu, toolchain, options=options.options, - verbose=options.verbose, clean=options.clean) + verbose=options.verbose, clean=options.clean, + macros=options.macros) successes.append(id) except Exception, e: if options.verbose: diff --git a/workspace_tools/build_api.py b/workspace_tools/build_api.py index 5770718129..6a34ed47de 100644 --- a/workspace_tools/build_api.py +++ b/workspace_tools/build_api.py @@ -26,19 +26,21 @@ from workspace_tools.libraries import Library def build_project(src_path, build_path, target, toolchain_name, libraries_paths=None, options=None, linker_script=None, - clean=False, notify=None, verbose=False, name=None): + clean=False, notify=None, verbose=False, name=None, macros=None): # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros) toolchain.VERBOSE = verbose toolchain.build_all = clean - + + src_paths = [src_path] if type(src_path) != ListType else src_path if name is None: - name = basename(src_path) + name = basename(src_paths[0]) toolchain.info("\n>>> BUILD PROJECT: %s (%s, %s)" % (name.upper(), target.name, toolchain_name)) # Scan src_path and libraries_paths for resources - resources = toolchain.scan_resources(src_path) - src_paths = [src_path] + resources = toolchain.scan_resources(src_paths[0]) + for path in src_paths[1:]: + resources.add(toolchain.scan_resources(path)) if libraries_paths is not None: src_paths.extend(libraries_paths) for path in libraries_paths: @@ -75,7 +77,7 @@ verbose: Write the actual tools command lines if True """ def build_library(src_paths, build_path, target, toolchain_name, dependencies_paths=None, options=None, name=None, clean=False, - notify=None, verbose=False): + notify=None, verbose=False, macros=None): if type(src_paths) != ListType: src_paths = [src_paths] for src_path in src_paths: @@ -83,7 +85,7 @@ def build_library(src_paths, build_path, target, toolchain_name, raise Exception("The library source folder does not exist: %s", src_path) # Toolchain instance - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, notify, macros) toolchain.VERBOSE = verbose toolchain.build_all = clean @@ -112,6 +114,7 @@ def build_library(src_paths, build_path, target, toolchain_name, # Copy Headers for resource in resources: toolchain.copy_files(resource.headers, build_path, rel_path=resource.base_path) + dependencies_include_dir.extend(toolchain.scan_resources(build_path).inc_dirs) # Compile Sources objects = [] @@ -121,25 +124,25 @@ def build_library(src_paths, build_path, target, toolchain_name, toolchain.build_library(objects, bin_path, name) -def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False): +def build_lib(lib_id, target, toolchain, options=None, verbose=False, clean=False, macros=None): lib = Library(lib_id) if lib.is_supported(target, toolchain): build_library(lib.source_dir, lib.build_dir, target, toolchain, lib.dependencies, options, - verbose=verbose, clean=clean) + verbose=verbose, clean=clean, macros=macros) else: print '\n\nLibrary "%s" is not yet supported on target %s with toolchain %s' % (lib_id, target.name, toolchain) # We do have unique legacy conventions about how we build and package the mbed library -def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False): +def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=False, macros=None): # Check toolchain support if toolchain_name not in target.supported_toolchains: print '\n%s target is not yet supported by toolchain %s' % (target.name, toolchain_name) return # Toolchain - toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options) + toolchain = TOOLCHAIN_CLASSES[toolchain_name](target, options, macros=macros) toolchain.VERBOSE = verbose toolchain.build_all = clean @@ -188,3 +191,4 @@ def build_mbed_libs(target, toolchain_name, options=None, verbose=False, clean=F objects.remove(retargeting) toolchain.build_library(objects, BUILD_TOOLCHAIN, "mbed") toolchain.copy_files(retargeting, BUILD_TOOLCHAIN) + diff --git a/workspace_tools/debugger/README.md b/workspace_tools/debugger/README.md deleted file mode 100644 index 4155499d6d..0000000000 --- a/workspace_tools/debugger/README.md +++ /dev/null @@ -1,148 +0,0 @@ -pyOCD -===== -pyOCD is an Open Source python library in order to program and -debug ARM Cortex-M microcontrollers using CMSIS-DAP. You can either -use a python interpreter to control your target or start a GDB server. - - -What allows this library? -------------------------- -1. From a python interpretor: - * halt, step, resume execution - * read/write memory - * read/write block memory - * read-write core register - * set/remove hardware breakpoints - * flash new binary - * reset - -2. From a GDB client, you have all the features provided by gdb: - * load a .elf file - * read/write memory - * read/write core register - * set/remove hardware breakpoints - * high level stepping - * ... - - -DEPENDANCIES: -------------- -pyOCD relies on external libraries: -* pyOCD has been tested with python 2.7 -* distutils -* Windows: [pyWinUSB](https://github.com/rene-aguirre/pywinusb): - ``` - $ cd /path-to-pywinusb/ - $ python setup.py install - ``` -* Linux: [pyUSB](https://github.com/walac/pyusb): - ``` - $ sudo apt-get install python libusb-1.0-0-dev - $ cd /path-to-pyusb/ - $ sudo python setup.py install - ``` -* Mac: - - So far Mac OS X is not supported - - -Installation: -------------- - - $ cd /path-to-pyOCD/ - $ python setup.py install - - -Examples: ---------- -## Tests -A series of tests are on the test directory: -* basic_test.py: simple test that checks: - 1. read/write core registers - 2. read/write memory - 3. stop/resume/step the execution - 4. reset the target - 5. flash a binary -* gdb_test.py: launch a gdbserver - -## Hello World example: - - from pyOCD.board import MbedBoard - - import logging - logging.basicConfig(level=logging.INFO) - - board = MbedBoard.chooseBoard() - - target = board.target - flash = board.flash - target.resume() - target.halt() - print "pc: 0x%X" % target.readCoreRegister("pc") - pc: 0xA64 - target.step() - print "pc: 0x%X" % target.readCoreRegister("pc") - pc: 0xA30 - target.step() - print "pc: 0x%X" % target.readCoreRegister("pc") - pc: 0xA32 - flash.flashBinary("binaries/l1_lpc1768.bin") - print "pc: 0x%X" % target.readCoreRegister("pc") - pc: 0x10000000 - target.reset() - target.halt() - print "pc: 0x%X" % target.readCoreRegister("pc") - pc: 0xAAC - board.uninit() - -##GDB server example: -Python: - - from pyOCD.gdbserver import GDBServer - from pyOCD.board import MbedBoard - - import logging - logging.basicConfig(level=logging.INFO) - - board = MbedBoard.chooseBoard() - - # start gdbserver - gdb = GDBServer(board, 3333) - -gdb server: - - arm-none-eabi-gdb basic.elf - - target remote localhost:3333 - load - continue - - -Architecture: -------------- - -# interface: -An interface does the link between the target and the computer. -This package contains basic functions to write and read data to and from -an interface. You can inherit from Interface and overwrite read(), write(),... -Then declare your interface in INTERFACE (in pyOCD.interface.__init__.py) - -# target: -A target defines basic functionalities such as step, resume, halt, readMemory,... -You can inherit from Target to implement your own functions. -Then declare your target in TARGET (in pyOCD.target.__init__.py) - -# transport: -Defines the transport used to communicate. In particular, you can find CMSIS-DAP. -Defines functions such as memWriteAP, memReadAP, writeDP, readDP,... -You can inherit from Transport and implement your own functions. -Then declare your transport in TRANSPORT (in pyOCD.transport.__init__.py) - -# flash: -Contains flash algorithm in order to flash a new binary into the target. - -# gdbserver: -Start a GDB server. The server listens on a specific port. You can then -connect a GDB client to it and debug/program the target - -Then you can debug a board which is composed by an interface, a target, a transport and a flash \ No newline at end of file diff --git a/workspace_tools/debugger/__init__.py b/workspace_tools/debugger/__init__.py deleted file mode 100644 index 74a91f20af..0000000000 --- a/workspace_tools/debugger/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" \ No newline at end of file diff --git a/workspace_tools/debugger/binaries/l1_kl25z.bin b/workspace_tools/debugger/binaries/l1_kl25z.bin deleted file mode 100644 index eeae1524a7..0000000000 Binary files a/workspace_tools/debugger/binaries/l1_kl25z.bin and /dev/null differ diff --git a/workspace_tools/debugger/binaries/l1_lpc11u24.bin b/workspace_tools/debugger/binaries/l1_lpc11u24.bin deleted file mode 100644 index df9c391310..0000000000 Binary files a/workspace_tools/debugger/binaries/l1_lpc11u24.bin and /dev/null differ diff --git a/workspace_tools/debugger/binaries/l1_lpc1768.bin b/workspace_tools/debugger/binaries/l1_lpc1768.bin deleted file mode 100644 index f04a05c263..0000000000 Binary files a/workspace_tools/debugger/binaries/l1_lpc1768.bin and /dev/null differ diff --git a/workspace_tools/debugger/binaries/l1_lpc800.bin b/workspace_tools/debugger/binaries/l1_lpc800.bin deleted file mode 100644 index 5109f7bbf1..0000000000 Binary files a/workspace_tools/debugger/binaries/l1_lpc800.bin and /dev/null differ diff --git a/workspace_tools/debugger/elf_files/lpc11u24_l1_gcc_arm.elf b/workspace_tools/debugger/elf_files/lpc11u24_l1_gcc_arm.elf deleted file mode 100644 index 8d2b7c08ac..0000000000 Binary files a/workspace_tools/debugger/elf_files/lpc11u24_l1_gcc_arm.elf and /dev/null differ diff --git a/workspace_tools/debugger/elf_files/lpc1768_l1_gcc_arm.elf b/workspace_tools/debugger/elf_files/lpc1768_l1_gcc_arm.elf deleted file mode 100644 index 54957f67df..0000000000 Binary files a/workspace_tools/debugger/elf_files/lpc1768_l1_gcc_arm.elf and /dev/null differ diff --git a/workspace_tools/debugger/pyOCD/__init__.py b/workspace_tools/debugger/pyOCD/__init__.py deleted file mode 100644 index 74a91f20af..0000000000 --- a/workspace_tools/debugger/pyOCD/__init__.py +++ /dev/null @@ -1,16 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/board/__init__.py b/workspace_tools/debugger/pyOCD/board/__init__.py deleted file mode 100644 index a20583cf8e..0000000000 --- a/workspace_tools/debugger/pyOCD/board/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from mbed_board import MbedBoard \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/board/board.py b/workspace_tools/debugger/pyOCD/board/board.py deleted file mode 100644 index 93fab4bded..0000000000 --- a/workspace_tools/debugger/pyOCD/board/board.py +++ /dev/null @@ -1,60 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from pyOCD.target import TARGET -from pyOCD.transport import TRANSPORT -from pyOCD.interface import INTERFACE -from pyOCD.flash import FLASH - -import logging - -class Board(): - """ - This class associates a target, a flash, a transport and an interface - to create a board - """ - def __init__(self, target, flash, interface, transport = "cmsis_dap"): - if isinstance(interface, str) == False: - self.interface = interface - else: - self.interface = INTERFACE[interface].chooseInterface(INTERFACE[interface]) - self.transport = TRANSPORT[transport](self.interface) - self.target = TARGET[target](self.transport) - self.flash = FLASH[flash](self.target) - return - - def init(self): - """ - Initialize the board: interface, transport and target - """ - logging.debug("init board %s", self) - self.interface.init() - self.transport.init() - self.target.init() - - def uninit(self): - """ - Uninitialize the board: inetrface, transport and target. - This function resets the target - """ - logging.debug("uninit board %s", self) - self.target.resume() - self.transport.uninit() - self.interface.close() - - def getInfo(self): - return self.interface.getInfo() \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/board/mbed_board.py b/workspace_tools/debugger/pyOCD/board/mbed_board.py deleted file mode 100644 index 6f3fa52c31..0000000000 --- a/workspace_tools/debugger/pyOCD/board/mbed_board.py +++ /dev/null @@ -1,160 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import sys, os -import logging, array - -from time import sleep -from board import Board -from pyOCD.interface import INTERFACE - -TARGET_TYPE = {"1010": "lpc1768", - "0200": "kl25z", - "1040": "lpc11u24", - "0300": "lpc800", - } - -usb_backend = "" -if os.name == "nt": - usb_backend = "pywinusb" -elif os.name == "posix": - usb_backend = "pyusb" - -mbed_vid = 0x0d28 -mbed_pid = 0x0204 - -class MbedBoard(Board): - """ - This class inherits from Board and is specific to mbed boards. - Particularly, this class allows you to dynamically determine - the type of all boards connected based on the id board - """ - def __init__(self, target, flash, interface, transport = "cmsis_dap"): - """ - Init the board - """ - Board.__init__(self, target, flash, interface, transport) - self.unique_id = "" - self.target_type = "" - - def getUniqueID(self): - """ - Return the unique id of the board - """ - return self.unique_id - - def getTargetType(self): - """ - Return the type of the board - """ - return self.target_type - - def getInfo(self): - """ - Return info on the board - """ - return Board.getInfo(self) + " [" + self.target_type + "]" - - @staticmethod - def getAllConnectedBoards(transport = "cmsis_dap", close = False, blocking = True): - """ - Return an array of all mbed boards connected - """ - first = True - while True: - while True: - all_mbeds = INTERFACE[usb_backend].getAllConnectedInterface(mbed_vid, mbed_pid) - if all_mbeds != None or not blocking: - break - if (first == True): - logging.info("Waiting for a USB device connected") - first = False - sleep(0.2) - - mbed_boards = [] - for mbed in all_mbeds: - mbed.write([0x80]) - u_id_ = mbed.read() - try: - target_type = array.array('B', [i for i in u_id_[2:6]]).tostring() - target_type = TARGET_TYPE[target_type] - new_mbed = MbedBoard("target_" + target_type, "flash_" + target_type, mbed, transport) - new_mbed.target_type = target_type - new_mbed.unique_id = array.array('B', [i for i in u_id_[2:2+u_id_[1]]]).tostring() - logging.info("new board id detected: %s", new_mbed.unique_id) - mbed_boards.append(new_mbed) - if close: - mbed.close() - except Exception as e: - print "received exception: %s" % e - mbed.close() - - if len(mbed_boards) > 0 or not blocking: - return mbed_boards - - if (first == True): - logging.info("Waiting for a USB device connected") - first = False - - @staticmethod - def chooseBoard(transport = "cmsis_dap", blocking = True, return_first = False): - """ - Allow you to select a board among all boards connected - """ - all_mbeds = MbedBoard.getAllConnectedBoards(transport, False, blocking) - - if all_mbeds == None: - return None - - index = 0 - for mbed in all_mbeds: - print "%d => %s" % (index, mbed.getInfo()) - index += 1 - - if len(all_mbeds) == 1: - all_mbeds[0].init() - return all_mbeds[0] - - try: - ch = 0 - if not return_first: - while True: - ch = sys.stdin.readline() - sys.stdin.flush() - if (int(ch) < 0) or (int(ch) >= len(all_mbeds)): - logging.info("BAD CHOICE: %d", int(ch)) - index = 0 - for mbed in all_mbeds: - print "%d => %s" % ( index, mbed.getInfo()) - index += 1 - else: - break - # close all others mbed connected - for mbed in all_mbeds: - if mbed != all_mbeds[int(ch)]: - mbed.interface.close() - - all_mbeds[int(ch)].init() - return all_mbeds[int(ch)] - except Exception as e: - try: - print e - except: - pass - finally: - for mbed in all_mbeds: - mbed.interface.close() diff --git a/workspace_tools/debugger/pyOCD/flash/__init__.py b/workspace_tools/debugger/pyOCD/flash/__init__.py deleted file mode 100644 index bb29a295ba..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/__init__.py +++ /dev/null @@ -1,27 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from flash_lpc1768 import Flash_lpc1768 -from flash_kl25z import Flash_kl25z -from flash_lpc11u24 import Flash_lpc11u24 -from flash_lpc800 import Flash_lpc800 - -FLASH = {'flash_lpc1768': Flash_lpc1768, - 'flash_kl25z': Flash_kl25z, - 'flash_lpc11u24': Flash_lpc11u24, - 'flash_lpc800': Flash_lpc800 - } \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/flash/flash.py b/workspace_tools/debugger/pyOCD/flash/flash.py deleted file mode 100644 index 761e19e572..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/flash.py +++ /dev/null @@ -1,145 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from pyOCD.target.target import TARGET_RUNNING -import logging -from struct import unpack -from time import time -""" -import os,sys -parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0,parentdir) -""" - -class Flash(): - """ - This class is responsible to flash a new binary in a target - """ - - def __init__(self, target, flash_algo, memoryMapXML): - self.target = target - self.flash_algo = flash_algo - self.end_flash_algo = flash_algo['load_address'] + len(flash_algo)*4 - self.begin_stack = flash_algo['begin_stack'] - self.begin_data = flash_algo['begin_data'] - self.static_base = flash_algo['static_base'] - self.page_size = flash_algo['page_size'] - self.memoryMapXML = memoryMapXML - - def init(self): - """ - Download the flash algorithm in RAM - """ - self.target.halt() - self.target.setTargetState("PROGRAM") - - # download flash algo in RAM - self.target.writeBlockMemoryAligned32(self.flash_algo['load_address'], self.flash_algo['instructions']) - - # update core register to execute the init subroutine - self.updateCoreRegister(0, 0, 0, 0, self.flash_algo['pc_init']) - # resume and wait until the breakpoint is hit - self.target.resume() - while(self.target.getState() == TARGET_RUNNING): - pass - - return - - def eraseAll(self): - """ - Erase all the flash - """ - - # update core register to execute the eraseAll subroutine - self.updateCoreRegister(0, 0, 0, 0, self.flash_algo['pc_eraseAll']) - - # resume and wait until the breakpoint is hit - self.target.resume() - while(self.target.getState() == TARGET_RUNNING): - pass - - return - - def programPage(self, flashPtr, bytes): - """ - Flash one page - """ - # first transfer in RAM - self.target.writeBlockMemoryUnaligned8(self.begin_data, bytes) - - # update core register to execute the program_page subroutine - self.updateCoreRegister(flashPtr, self.page_size, self.begin_data, 0, self.flash_algo['pc_program_page']) - - # resume and wait until the breakpoint is hit - self.target.resume() - while(self.target.getState() == TARGET_RUNNING): - pass - return - - def flashBinary(self, path_file): - """ - Flash a binary - """ - f = open(path_file, "rb") - - start = time() - self.init() - logging.debug("flash init OK: pc: 0x%X", self.target.readCoreRegister('pc')) - self.eraseAll() - logging.debug("eraseAll OK: pc: 0x%X", self.target.readCoreRegister('pc')) - - """ - bin = open(os.path.join(parentdir, 'res', 'good_bin.txt'), "w+") - """ - - flashPtr = 0 - nb_bytes = 0 - try: - bytes_read = f.read(1024) - while bytes_read: - bytes_read = unpack(str(len(bytes_read)) + 'B', bytes_read) - nb_bytes += len(bytes_read) - # page download - self.programPage(flashPtr, bytes_read) - """ - i = 0 - while (i < len(bytes_read)): - bin.write(str(list(bytes_read[i:i+16])) + "\n") - i += 16 - """ - flashPtr += 1024 - - bytes_read = f.read(1024) - finally: - f.close() - """ - bin.close() - """ - end = time() - logging.info("%f kbytes flashed in %f seconds ===> %f kbytes/s" %(nb_bytes/1000, end-start, nb_bytes/(1000*(end - start)))) - - def updateCoreRegister(self, r0, r1, r2, r3, pc): - self.target.writeCoreRegister('pc', pc) - self.target.writeCoreRegister('r0', r0) - self.target.writeCoreRegister('r1', r1) - self.target.writeCoreRegister('r2', r2) - self.target.writeCoreRegister('r3', r3) - self.target.writeCoreRegister('r9', self.static_base) - self.target.writeCoreRegister('sp', self.begin_stack) - self.target.writeCoreRegister('lr', self.flash_algo['load_address'] + 1) - return - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/flash/flash_kl25z.py b/workspace_tools/debugger/pyOCD/flash/flash_kl25z.py deleted file mode 100644 index 805fa544b3..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/flash_kl25z.py +++ /dev/null @@ -1,92 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from flash import Flash - -flash_algo = { 'load_address' : 0x20000000, - 'instructions' : [ - 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, - 0xb510492f, 0x60084449, 0x2100482e, 0x482f6001, 0x44484a2d, 0x22016002, 0x04926041, 0x02926082, - 0x220560c2, 0x61420692, 0x03122201, 0x46026182, 0x70113220, 0x62411e49, 0xf929f000, 0xd0002800, - 0xbd102001, 0x47702000, 0xb5084a21, 0x0349447a, 0x0c0a9200, 0x481d4601, 0x44482300, 0xf9b7f000, - 0xd0002800, 0xbd082001, 0x4919b510, 0x48174479, 0x44483920, 0xf891f000, 0xd0002800, 0xbd102001, - 0x4b13b510, 0x4601447b, 0x22014810, 0x02923b38, 0xf0004448, 0x2800f8b4, 0x2001d000, 0xb538bd10, - 0x490b460c, 0x39584479, 0x46019100, 0x46134807, 0x44484622, 0xf948f000, 0xd0002800, 0xbd382001, - 0x00000004, 0x40048100, 0x40020000, 0x00000008, 0x00000085, 0x4604b570, 0x25006800, 0x061b7803, - 0x2370d5fc, 0x20007003, 0x0003e03a, 0xfa60f000, 0x0f0b070c, 0x1f1b1713, 0x2f2b2723, 0x68263633, - 0x71f37813, 0x6826e02a, 0x71b37853, 0x6826e026, 0x71737893, 0x6826e022, 0x713378d3, 0x6826e01e, - 0x72f37913, 0x6826e01a, 0x72b37953, 0x6826e016, 0x72737993, 0x6826e012, 0x723379d3, 0x6826e00e, - 0x73f37a13, 0x6826e00a, 0x73b37a53, 0x6826e006, 0x73737a93, 0x6826e002, 0x73337ad3, 0xb2c01c40, - 0xd9c24288, 0x20806821, 0xe0037008, 0x1c416a60, 0x4780d000, 0x78006820, 0xd5f70600, 0x78006820, - 0xd5010681, 0xe0062504, 0xd50106c1, 0xe0022508, 0xd00007c0, 0x46282510, 0xb508bd70, 0x2244460b, - 0x700a4669, 0x2100466a, 0xbd084798, 0x4614b538, 0xd002078a, 0x300120ff, 0x6843bd38, 0xd803428b, - 0x189a6882, 0xd80d428a, 0x428a68c2, 0x6903d803, 0x428b18d3, 0x2002d801, 0x1a89bd38, 0x05d22201, - 0xe0001889, 0x22081ac9, 0x701a466b, 0x705a0c0a, 0x709a0a0a, 0x466a70d9, 0x47a02103, 0xb5ffbd38, - 0x4615b081, 0x27019a01, 0x26006852, 0x02bf1948, 0xd804428a, 0x689b9b01, 0x428318d3, 0x9a01d20f, - 0x428a68d2, 0x9b01d804, 0x18d3691b, 0xd2014283, 0xe0292602, 0x21011a88, 0x184405c9, 0x1a8ce000, - 0x46204639, 0xf907f000, 0xd0022900, 0x360126ff, 0x4639e01a, 0xf0004628, 0x2900f8fe, 0x2601d012, - 0x2009e012, 0x70084669, 0x70480c20, 0x70880a20, 0x9b0470cc, 0x2103466a, 0x47989801, 0xd1030006, - 0x19e41bed, 0xd1ec2d00, 0xb0054630, 0xb5f0bdf0, 0x24006801, 0x0612780a, 0x2270d5fc, 0x6802700a, - 0x71d12103, 0x22806801, 0x6803718a, 0x71592100, 0x23fc6805, 0x6803712b, 0x680373d9, 0x6802701a, - 0x061b7813, 0x7a55d5fc, 0x07177a12, 0x0f3f2201, 0x105603d2, 0xf000003b, 0x0910f96b, 0x09100e0b, - 0x10090909, 0x09090e1f, 0x11090909, 0xe0056102, 0x03522203, 0x6106e7fa, 0x6101e000, 0x0f12072a, - 0xf0000013, 0x0c10f955, 0x120f0c0c, 0x1d1b1815, 0x0c0c0c1f, 0x0d0c0c0c, 0x03522201, 0x61c1e7e6, - 0xbdf04620, 0x02c92101, 0x2101e7f9, 0xe7f60289, 0x02492101, 0x21ffe7f3, 0xe7f03101, 0xe7ee2180, - 0xe7ec2140, 0xe7ea2120, 0x4607b5fe, 0x461d4616, 0x198a2000, 0xd002078b, 0x300120ff, 0x07b3bdfe, - 0x2001d001, 0x687bbdfe, 0xd803428b, 0x191c68bc, 0xd20d4294, 0x428b68fb, 0x693cd803, 0x4294191c, - 0x2002d201, 0x2201bdfe, 0x05d21ac9, 0xe01b188c, 0xe0191acc, 0x46692006, 0x0c207008, 0x0a207048, - 0x70cc7088, 0x710878e8, 0x714878a8, 0x71887868, 0x71c87828, 0x466a9b08, 0x46382107, 0x28004798, - 0x1d24d1e0, 0x1d2d1f36, 0xd1e32e00, 0xb5febdfe, 0x46044615, 0x00a86842, 0x461e1840, 0xd803428a, - 0x18d368a3, 0xd808428b, 0x428b68e3, 0x6927d803, 0x428b19db, 0x2002d801, 0x4282bdfe, 0x68a3d805, - 0x428318d3, 0x1a8fd301, 0x68e2e00a, 0xd9034282, 0x18d36923, 0xd3ee4283, 0x21011a88, 0x184705c9, - 0x46382104, 0xf817f000, 0xd0022900, 0x300120ff, 0x2001bdfe, 0x70084669, 0x70480c38, 0x70880a38, - 0x0a2870cf, 0x714d7108, 0x9b08718e, 0x2106466a, 0x47984620, 0x2200bdfe, 0x428b0903, 0x0a03d32c, - 0xd311428b, 0x469c2300, 0x4603e04e, 0xd43c430b, 0x08432200, 0xd331428b, 0x428b0903, 0x0a03d31c, - 0xd301428b, 0xe03f4694, 0x428b09c3, 0x01cbd301, 0x41521ac0, 0x428b0983, 0x018bd301, 0x41521ac0, - 0x428b0943, 0x014bd301, 0x41521ac0, 0x428b0903, 0x010bd301, 0x41521ac0, 0x428b08c3, 0x00cbd301, - 0x41521ac0, 0x428b0883, 0x008bd301, 0x41521ac0, 0x428b0843, 0x004bd301, 0x41521ac0, 0xd2001a41, - 0x41524601, 0x47704610, 0x0fcae05d, 0x4249d000, 0xd3001003, 0x40534240, 0x469c2200, 0x428b0903, - 0x0a03d32d, 0xd312428b, 0x018922fc, 0x0a03ba12, 0xd30c428b, 0x11920189, 0xd308428b, 0x11920189, - 0xd304428b, 0xd03a0189, 0xe0001192, 0x09c30989, 0xd301428b, 0x1ac001cb, 0x09834152, 0xd301428b, - 0x1ac0018b, 0x09434152, 0xd301428b, 0x1ac0014b, 0x09034152, 0xd301428b, 0x1ac0010b, 0x08c34152, - 0xd301428b, 0x1ac000cb, 0x08834152, 0xd301428b, 0x1ac0008b, 0xd2d94152, 0x428b0843, 0x004bd301, - 0x41521ac0, 0xd2001a41, 0x46634601, 0x105b4152, 0xd3014610, 0x2b004240, 0x4249d500, 0x46634770, - 0xd300105b, 0xb5014240, 0x46c02000, 0xbd0246c0, 0x4674b430, 0x78251e64, 0x42ab1c64, 0x461dd200, - 0x005b5d63, 0xbc3018e3, 0x00004718, 0xfffffffe - ], - 'pc_init' : 0x20000020, - 'pc_eraseAll' : 0x20000088, - 'pc_program_page' : 0x200000be, - 'begin_stack' : 0x20001000, - 'begin_data' : 0x20002000, - 'static_base' : 0x200005ec, - 'page_size' : 1024 - }; - -memoryMapXML = "" \ - "" \ - "" \ - " 0x400" \ - " " \ - "" - - -class Flash_kl25z(Flash): - - def __init__(self, target): - Flash.__init__(self, target, flash_algo, memoryMapXML) - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/flash/flash_lpc11u24.py b/workspace_tools/debugger/pyOCD/flash/flash_lpc11u24.py deleted file mode 100644 index 5d056c0892..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/flash_lpc11u24.py +++ /dev/null @@ -1,57 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from flash import Flash - -flash_algo = { 'load_address' : 0x10000000, - 'instructions' : [ - 0xe00abe00, 0x062d780d, 0x24084068, 0xd3000040, 0x1e644058, 0x1c49d1fa, 0x2a001e52, 0x4770d1f2, - 0x7803e005, 0x42931c40, 0x2001d001, 0x1e494770, 0x2000d2f7, 0x00004770, 0x47700b00, 0x484e494f, - 0x60084449, 0x2100484e, 0x22016301, 0x63416342, 0x6b416342, 0xd0fc07c9, 0x49496382, 0x39402002, - 0x20007008, 0x20004770, 0xb5f84770, 0x20324c45, 0x2500444c, 0x46222607, 0x4621c261, 0x4f423114, - 0x91004620, 0x696047b8, 0xd10c2800, 0x46212034, 0x483ac161, 0x68004448, 0x462060e0, 0x47b89900, - 0x28006960, 0x2001d000, 0xb5f8bdf8, 0x0b044d35, 0x2032444d, 0x4629606c, 0x311460ac, 0x4e326028, - 0x4628460f, 0x696847b0, 0xd10d2800, 0x2034606c, 0x602860ac, 0x46394829, 0x68004448, 0x462860e8, - 0x696847b0, 0xd0002800, 0xbdf82001, 0x0006b5f8, 0xd11e4614, 0x0180200b, 0x6bc11820, 0x42814823, - 0x4823d038, 0xd0354281, 0x42814822, 0x4822d032, 0xd02f4281, 0x68206861, 0x184068e2, 0x188968a1, - 0x69211840, 0x69611840, 0x69a11840, 0x42401840, 0x4d1461e0, 0x444d0b30, 0x60682132, 0x60a86029, - 0x31144629, 0x46284f10, 0x47b89100, 0x28006968, 0x606ed110, 0x60ac2033, 0x20016028, 0x60e80280, - 0x44484806, 0x61286800, 0x99004628, 0x696847b8, 0xd0002800, 0xbdf82001, 0x00002ee0, 0x00000004, - 0x40048040, 0x00000008, 0x1fff1ff1, 0x4e697370, 0x12345678, 0x87654321, 0x43218765, 0x00000000, - 0x00000000 - ], - 'pc_init' : 0x1000003d, - 'pc_eraseAll' : 0x1000006b, - 'pc_program_page' : 0x100000ed, - 'begin_data' : 0x100001c4, - 'begin_stack' : 0x10001000, - 'static_base' : 0x1000019c, - 'page_size' : 1024 - }; - -memoryMapXML = "" \ - "" \ - "" \ - " 0x400" \ - " " \ - "" - - -class Flash_lpc11u24(Flash): - - def __init__(self, target): - Flash.__init__(self, target, flash_algo, memoryMapXML) \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/flash/flash_lpc1768.py b/workspace_tools/debugger/pyOCD/flash/flash_lpc1768.py deleted file mode 100644 index e48738f3ac..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/flash_lpc1768.py +++ /dev/null @@ -1,61 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from flash import Flash - -flash_algo = { 'load_address' : 0x10000000, - 'instructions' : [ - 0xe00abe00, 0x062d780d, 0x24084068, 0xd3000040, 0x1e644058, 0x1c49d1fa, 0x2a001e52, 0x4770d1f2, - 0x7803e005, 0x42931c40, 0x2001d001, 0x1e494770, 0x2000d2f7, 0x00004770, 0x28100b00, 0x210ed302, - 0x00d0eb01, 0x486c4770, 0x7801b510, 0x0102f021, 0x22aa7001, 0x23557302, 0x78017303, 0x0101f021, - 0x73027001, 0xf8d07303, 0xf0411120, 0xf8c00120, 0xf1a01120, 0xf8d00080, 0x064911a0, 0xf100d5fb, - 0x24010080, 0x408cf880, 0x0113f04f, 0x73026041, 0x78017303, 0x0101f041, 0x73027001, 0xf1a07303, - 0xf8d00080, 0x01491088, 0xf100d5fb, 0x2107006d, 0x1097f880, 0x0109f04f, 0x109bf880, 0xf0417cc1, - 0x74c10102, 0x77c377c2, 0x4c2df800, 0xf64e494b, 0x44492060, 0xf04f6008, 0xbd100000, 0x47702000, - 0x41f0e92d, 0x20324c46, 0x2500444c, 0xe884271d, 0xf10400a1, 0x4e430114, 0x46204688, 0x696047b0, - 0x2034b960, 0x00a1e884, 0x4641483c, 0x68004448, 0x462060e0, 0x696047b0, 0xd0002800, 0xe8bd2001, - 0xe92d81f0, 0xf7ff41f0, 0x4d35ff87, 0x444d4604, 0xe9c52032, 0xf1050400, 0x4e320114, 0x4628460f, - 0x47b060ac, 0xb9686968, 0xe9c52034, 0x482b0400, 0x444860ac, 0x68004639, 0x462860e8, 0x696847b0, - 0xd0dc2800, 0xe7da2001, 0x41f0e92d, 0x46140006, 0x4925d11d, 0x02fcf8d4, 0xd03a4288, 0x42884923, - 0x4923d037, 0xd0344288, 0x4131ea4f, 0xd0304288, 0x0100e9d4, 0xe9d44408, 0x44111202, 0x69214408, - 0x69614408, 0x69a14408, 0x42404408, 0x463061e0, 0xff42f7ff, 0x21324d12, 0x4f12444d, 0x1000e9c5, - 0x0114f105, 0x468860a8, 0x47b84628, 0xb9806968, 0xe9c52033, 0xf44f0600, 0xe9c56080, 0x48074002, - 0x44484641, 0x61286800, 0x47b84628, 0x28006968, 0x2001d095, 0x0000e793, 0x400fc080, 0x00000004, - 0x00000008, 0x1fff1ff1, 0x4e697370, 0x12345678, 0x87654321, 0x00000000, 0x00000000 - ], - 'pc_init' : 0x10000047, - 'pc_eraseAll' : 0x100000e1, - 'pc_program_page' : 0x10000169, - 'begin_data' : 0x1000023c, - 'begin_stack' : 0x10001000, - 'static_base' : 0x10000214, - 'page_size' : 1024 - }; - -memoryMapXML = "" \ - "" \ - "" \ - " 0x400" \ - " " \ - " " \ - "" - - -class Flash_lpc1768(Flash): - - def __init__(self, target): - Flash.__init__(self, target, flash_algo, memoryMapXML) \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/flash/flash_lpc800.py b/workspace_tools/debugger/pyOCD/flash/flash_lpc800.py deleted file mode 100644 index 40da42a7c4..0000000000 --- a/workspace_tools/debugger/pyOCD/flash/flash_lpc800.py +++ /dev/null @@ -1,56 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from flash import Flash - -flash_algo = { 'load_address' : 0x10000000, - 'instructions' : [ - 0xE00ABE00, 0x062D780D, 0x24084068, 0xD3000040, 0x1E644058, 0x1C49D1FA, 0x2A001E52, 0x4770D1F2, - 0x47700a80, 0x484e494f, 0x60084449, 0x2100484e, 0x22016301, 0x63416342, 0x6b416342, 0xd0fc07c9, - 0x49496382, 0x39402002, 0x20007008, 0x20004770, 0xb5f84770, 0x20324c45, 0x2500444c, 0x4622260f, - 0x4621c261, 0x4f423114, 0x91004620, 0x696047b8, 0xd10c2800, 0x46212034, 0x483ac161, 0x68004448, - 0x462060e0, 0x47b89900, 0x28006960, 0x2001d000, 0xb5f8bdf8, 0x0a844d35, 0x2032444d, 0x4629606c, - 0x311460ac, 0x4e326028, 0x4628460f, 0x696847b0, 0xd10d2800, 0x2034606c, 0x602860ac, 0x46394829, - 0x68004448, 0x462860e8, 0x696847b0, 0xd0002800, 0xbdf82001, 0x4614b5f8, 0xd11e0006, 0x0180200b, - 0x6bc11820, 0x42814823, 0x4823d038, 0xd0354281, 0x42814822, 0x4822d032, 0xd02f4281, 0x68206861, - 0x184068e2, 0x188968a1, 0x69211840, 0x69611840, 0x69a11840, 0x42401840, 0x4d1461e0, 0x444d0ab0, - 0x60682132, 0x60a86029, 0x31144629, 0x46284f10, 0x47b89100, 0x28006968, 0x606ed110, 0x60ac2033, - 0x20016028, 0x60e80280, 0x44484806, 0x61286800, 0x99004628, 0x696847b8, 0xd0002800, 0xbdf82001, - 0x00002ee0, 0x00000004, 0x40048040, 0x00000008, 0x1fff1ff1, 0x4e697370, 0x12345678, 0x87654321, - 0x43218765 - ], - 'pc_init' : 0x10000024, - 'pc_eraseAll' : 0x10000052, - 'pc_program_page' : 0x100000d4, - 'begin_data' : 0x10000400, - 'begin_stack' : 0x10001000, - 'static_base' : 0x10000300, - 'page_size' : 1024 - }; - -memoryMapXML = "" \ - "" \ - "" \ - " 0x400" \ - " " \ - "" - - -class Flash_lpc800(Flash): - - def __init__(self, target): - Flash.__init__(self, target, flash_algo, memoryMapXML) \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/gdbserver/__init__.py b/workspace_tools/debugger/pyOCD/gdbserver/__init__.py deleted file mode 100644 index 9c54e524f0..0000000000 --- a/workspace_tools/debugger/pyOCD/gdbserver/__init__.py +++ /dev/null @@ -1,18 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from gdbserver import GDBServer \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/gdbserver/gdb_socket.py b/workspace_tools/debugger/pyOCD/gdbserver/gdb_socket.py deleted file mode 100644 index 1ed4a6d34e..0000000000 --- a/workspace_tools/debugger/pyOCD/gdbserver/gdb_socket.py +++ /dev/null @@ -1,55 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import socket, select - -class GDBSocket(): - def __init__(self, port, packet_size): - self.packet_size = packet_size - self.s = None - self.conn = None - self.port = port - return - - def init(self): - self.s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - self.s.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.s.bind(('', self.port)) - self.s.listen(5) - - def connect(self): - self.conn = None - self.init() - rr,_,_ = select.select([self.s],[],[], 0.5) - if rr: - self.conn, _ = self.s.accept() - - return self.conn - - def read(self): - return self.conn.recv(self.packet_size) - - def write(self, data): - return self.conn.send(data) - - def close(self): - if self.conn != None: - self.conn.close() - return self.s.close() - - def setBlocking(self, blocking): - return self.conn.setblocking(blocking) \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/gdbserver/gdb_websocket.py b/workspace_tools/debugger/pyOCD/gdbserver/gdb_websocket.py deleted file mode 100644 index f6ec479972..0000000000 --- a/workspace_tools/debugger/pyOCD/gdbserver/gdb_websocket.py +++ /dev/null @@ -1,51 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -try: - from websocket import create_connection -except: - pass - -class GDBWebSocket(): - def __init__(self, url): - self.url = url - self.wss = None - return - - def connect(self): - self.wss = None - try: - self.wss = create_connection(self.url) - except: - pass - return self.wss - - def read(self): - return self.wss.recv() - - def write(self, data): - return self.wss.send(data) - - def close(self): - return self.wss.close() - - def setBlocking(self, blocking): - if blocking != 0: - self.wss.settimeout(None) - else: - self.wss.settimeout(0) - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/gdbserver/gdbserver.py b/workspace_tools/debugger/pyOCD/gdbserver/gdbserver.py deleted file mode 100644 index e17947be9c..0000000000 --- a/workspace_tools/debugger/pyOCD/gdbserver/gdbserver.py +++ /dev/null @@ -1,594 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import logging, threading, socket -from pyOCD.target.cortex_m import CORE_REGISTER -from pyOCD.target.target import TARGET_HALTED -from struct import unpack -from time import sleep -import sys -from gdb_socket import GDBSocket -from gdb_websocket import GDBWebSocket - -""" -import os -parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) -sys.path.insert(0,parentdir) -""" - -SIGINT = (2) -SIGSEGV = (11) -SIGILL = (4) -SIGSTOP = (17) -SIGTRAP = (5) -SIGBUS = (10) - -FAULT = {0: "17", #SIGSTOP - 1: "17", - 2: "02", #SIGINT - 3: "11", #SIGSEGV - 4: "11", - 5: "10", #SIGBUS - 6: "04", #SIGILL - 7: "17", - 8: "17", - 9: "17", - 10: "17", - 11: "17", - 12: "17", - 13: "17", - 14: "17", - 15: "17", - } - -class GDBServer(threading.Thread): - """ - This class start a GDB server listening a gdb connection on a specific port. - It implements the RSP (Remote Serial Protocol). - """ - def __init__(self, board, port_urlWSS): - threading.Thread.__init__(self) - self.board = board - self.target = board.target - self.flash = board.flash - self.abstract_socket = None - self.wss_server = None - self.port = 0 - if isinstance(port_urlWSS, str) == True: - self.wss_server = port_urlWSS - else: - self.port = port_urlWSS - self.packet_size = 2048 - self.flashData = "" - self.conn = None - self.lock = threading.Lock() - self.shutdown_event = threading.Event() - self.detach_event = threading.Event() - self.quit = False - if self.wss_server == None: - self.abstract_socket = GDBSocket(self.port, self.packet_size) - else: - self.abstract_socket = GDBWebSocket(self.wss_server) - self.start() - - def restart(self): - if self.isAlive(): - self.detach_event.set() - - def stop(self): - if self.isAlive(): - self.shutdown_event.set() - while self.isAlive(): - pass - logging.info("GDB server thread killed") - self.board.uninit() - - def setBoard(self, board, stop = True): - self.lock.acquire() - if stop: - self.restart() - self.board = board - self.target = board.target - self.flash = board.flash - self.lock.release() - return - - def run(self): - while True: - new_command = False - data = [] - logging.info('GDB server started') - - self.shutdown_event.clear() - self.detach_event.clear() - - while not self.shutdown_event.isSet() and not self.detach_event.isSet(): - connected = self.abstract_socket.connect() - if connected != None: - break - - if self.shutdown_event.isSet(): - return - - if self.detach_event.isSet(): - continue - - logging.info("One client connected!") - - while True: - - if self.shutdown_event.isSet(): - return - - if self.detach_event.isSet(): - continue - - # read command - while True: - if (new_command == True): - new_command = False - break - try: - if self.shutdown_event.isSet() or self.detach_event.isSet(): - break - self.abstract_socket.setBlocking(0) - data = self.abstract_socket.read() - if data.index("$") >= 0 and data.index("#") >= 0: - break - except (ValueError, socket.error): - pass - - if self.shutdown_event.isSet(): - return - - if self.detach_event.isSet(): - continue - - self.abstract_socket.setBlocking(1) - - data = data[data.index("$"):] - - self.lock.acquire() - - if len(data) != 0: - # decode and prepare resp - [resp, ack, detach] = self.handleMsg(data) - - if resp is not None: - # ack - if ack: - resp = "+" + resp - # send resp - self.abstract_socket.write(resp) - # wait a '+' from the client - try: - data = self.abstract_socket.read() - if data[0] != '+': - logging.debug('gdb client has not ack!') - else: - logging.debug('gdb client has ack!') - if data.index("$") >= 0 and data.index("#") >= 0: - new_command = True - except: - pass - - if detach: - self.abstract_socket.close() - self.lock.release() - break - - self.lock.release() - - - def handleMsg(self, msg): - - if msg[0] != '$': - logging.debug('msg ignored: first char != $') - return None, 0, 0 - - #logging.debug('-->>>>>>>>>>>> GDB rsp packet: %s', msg) - - # query command - if msg[1] == 'q': - return self.handleQuery(msg[2:]), 1, 0 - - elif msg[1] == 'H': - return self.createRSPPacket(''), 1, 0 - - elif msg[1] == '?': - return self.lastSignal(), 1, 0 - - elif msg[1] == 'g': - return self.getRegister(), 1, 0 - - elif msg[1] == 'p': - return self.readRegister(msg[2:]), 1, 0 - - elif msg[1] == 'P': - return self.writeRegister(msg[2:]), 1, 0 - - elif msg[1] == 'm': - return self.getMemory(msg[2:]), 1, 0 - - elif msg[1] == 'X': - return self.writeMemory(msg[2:]), 1, 0 - - elif msg[1] == 'v': - return self.flashOp(msg[2:]), 1, 0 - - # we don't send immediately the response for C and S commands - elif msg[1] == 'C' or msg[1] == 'c': - return self.resume() - - elif msg[1] == 'S' or msg[1] == 's': - return self.step() - - elif msg[1] == 'Z' or msg[1] == 'z': - return self.breakpoint(msg[1:]), 1, 0 - - elif msg[1] == 'D': - return self.detach(msg[1:]), 1, 1 - - elif msg[1] == 'k': - return self.kill(), 1, 1 - - else: - logging.error("Unknown RSP packet: %s", msg) - return None - - def detach(self, data): - resp = "OK" - return self.createRSPPacket(resp) - - def kill(self): - return self.createRSPPacket("") - - def breakpoint(self, data): - # handle Z1/z1 commands - addr = int(data.split(',')[1], 16) - if data[1] == '1': - if data[0] == 'Z': - if self.target.setBreakpoint(addr) == False: - resp = "ENN" - return self.createRSPPacket(resp) - else: - self.target.removeBreakpoint(addr) - resp = "OK" - return self.createRSPPacket(resp) - - return None - - def resume(self): - self.ack() - self.target.resume() - self.abstract_socket.setBlocking(0) - - val = '' - - while True: - sleep(0.01) - - try: - data = self.abstract_socket.read() - if (data[0] == '\x03'): - self.target.halt() - val = 'S05' - logging.debug("receive CTRL-C") - break - except: - pass - - if self.target.getState() == TARGET_HALTED: - logging.debug("state halted") - val = 'S05' - break - - self.target.halt() - ipsr = self.target.readCoreRegister('xpsr') - logging.debug("GDB resume xpsr: 0x%X", ipsr) - if (ipsr & 0x1f) == 3: - val = "S" + FAULT[3] - break - self.target.resume() - - self.abstract_socket.setBlocking(1) - return self.createRSPPacket(val), 0, 0 - - def step(self): - self.ack() - self.target.step() - return self.createRSPPacket("S05"), 0, 0 - - def halt(self): - self.ack() - self.target.halt() - return self.createRSPPacket("S05"), 0, 0 - - def flashOp(self, data): - ops = data.split(':')[0] - #logging.debug("flash op: %s", ops) - - if ops == 'FlashErase': - self.flash.init() - self.flash.eraseAll() - return self.createRSPPacket("OK") - - elif ops == 'FlashWrite': - logging.debug("flash write addr: 0x%s", data.split(':')[1]) - # search for second ':' (beginning of data encoded in the message) - second_colon = 0 - idx_begin = 0 - while second_colon != 2: - if data[idx_begin] == ':': - second_colon += 1 - idx_begin += 1 - - self.flashData += data[idx_begin:len(data) - 3] - return self.createRSPPacket("OK") - - # we need to flash everything - elif 'FlashDone' in ops : - flashPtr = 0 - - unescaped_data = self.unescape(self.flashData) - - bytes_to_be_written = len(unescaped_data) - - """ - bin = open(os.path.join(parentdir, 'res', 'bad_bin.txt'), "w+") - - i = 0 - while (i < bytes_to_be_written): - bin.write(str(unescaped_data[i:i+16]) + "\n") - i += 16 - """ - - - logging.info("flashing %d bytes", bytes_to_be_written) - - while len(unescaped_data) > 0: - size_to_write = min(self.flash.page_size, len(unescaped_data)) - self.flash.programPage(flashPtr, unescaped_data[:size_to_write]) - flashPtr += size_to_write - - unescaped_data = unescaped_data[size_to_write:] - - # print progress bar - sys.stdout.write('\r') - i = int((float(flashPtr)/float(bytes_to_be_written))*20.0) - # the exact output you're looking for: - sys.stdout.write("[%-20s] %d%%" % ('='*i, 5*i)) - sys.stdout.flush() - - sys.stdout.write("\n\r") - - self.flashData = "" - - """ - bin.close() - """ - - # reset and stop on reset handler - self.target.resetStopOnReset() - - return self.createRSPPacket("OK") - - elif 'Cont' in ops: - if 'Cont?' in ops: - return self.createRSPPacket("vCont;c;s;t") - - return None - - def unescape(self, data): - data_idx = 0 - - # unpack the data into binary array - str_unpack = str(len(data)) + 'B' - data = unpack(str_unpack, data) - data = list(data) - - # check for escaped characters - while data_idx < len(data): - if data[data_idx] == 0x7d: - data.pop(data_idx) - data[data_idx] = data[data_idx] ^ 0x20 - data_idx += 1 - - return data - - - def getMemory(self, data): - split = data.split(',') - addr = int(split[0], 16) - length = split[1] - length = int(length[:len(length)-3],16) - - val = '' - - mem = self.target.readBlockMemoryUnaligned8(addr, length) - for x in mem: - if x >= 0x10: - val += hex(x)[2:4] - else: - val += '0' + hex(x)[2:3] - - return self.createRSPPacket(val) - - def writeMemory(self, data): - split = data.split(',') - addr = int(split[0], 16) - length = int(split[1].split(':')[0], 16) - - idx_begin = 0 - for i in range(len(data)): - if data[i] == ':': - idx_begin += 1 - break - idx_begin += 1 - - data = data[idx_begin:len(data) - 3] - data = self.unescape(data) - - if length > 0: - self.target.writeBlockMemoryUnaligned8(addr, data) - - return self.createRSPPacket("OK") - - def readRegister(self, data): - num = int(data.split('#')[0], 16) - reg = self.target.readCoreRegister(num) - logging.debug("GDB: read reg %d: 0x%X", num, reg) - val = self.intToHexGDB(reg) - return self.createRSPPacket(val) - - def writeRegister(self, data): - num = int(data.split('=')[0], 16) - val = data.split('=')[1].split('#')[0] - val = val[6:8] + val[4:6] + val[2:4] + val[0:2] - logging.debug("GDB: write reg %d: 0x%X", num, int(val, 16)) - self.target.writeCoreRegister(num, int(val, 16)) - return self.createRSPPacket("OK") - - def intToHexGDB(self, val): - val = hex(int(val))[2:] - size = len(val) - r = '' - for i in range(8-size): - r += '0' - r += str(val) - - resp = '' - for i in range(4): - resp += r[8 - 2*i - 2: 8 - 2*i] - - return resp - - def getRegister(self): - resp = '' - for i in range(len(CORE_REGISTER)): - reg = self.target.readCoreRegister(i) - resp += self.intToHexGDB(reg) - logging.debug("GDB reg: %s = 0x%X", i, reg) - return self.createRSPPacket(resp) - - def lastSignal(self): - fault = self.target.readCoreRegister('xpsr') & 0xff - fault = FAULT[fault] - logging.debug("GDB lastSignal: %s", fault) - return self.createRSPPacket('S' + fault) - - def handleQuery(self, msg): - query = msg.split(':') - logging.debug('GDB received query: %s', query) - - if query is None: - logging.error('GDB received query packet malformed') - return None - - if query[0] == 'Supported': - resp = "qXfer:memory-map:read+;qXfer:features:read+;PacketSize=" - resp += hex(self.packet_size)[2:] - return self.createRSPPacket(resp) - - elif query[0] == 'Xfer': - - if query[1] == 'features' and query[2] == 'read' and \ - query[3] == 'target.xml': - data = query[4].split(',') - resp = self.handleQueryXML('read_feature', int(data[0], 16), int(data[1].split('#')[0], 16)) - return self.createRSPPacket(resp) - - elif query[1] == 'memory-map' and query[2] == 'read': - data = query[4].split(',') - resp = self.handleQueryXML('momery_map', int(data[0], 16), int(data[1].split('#')[0], 16)) - return self.createRSPPacket(resp) - - else: - return None - - elif query[0] == 'C#b4': - return self.createRSPPacket("") - - elif query[0].find('Attached') != -1: - return self.createRSPPacket("1") - - elif query[0].find('TStatus') != -1: - return self.createRSPPacket("") - - elif query[0].find('Tf') != -1: - return self.createRSPPacket("") - - elif 'Offsets' in query[0]: - resp = "Text=0;Data=0;Bss=0" - return self.createRSPPacket(resp) - - elif 'Symbol' in query[0]: - resp = "OK" - return self.createRSPPacket(resp) - - else: - return None - - def handleQueryXML(self, query, offset, size): - logging.debug('GDB query %s: offset: %s, size: %s', query, offset, size) - xml = '' - if query == 'momery_map': - xml = self.flash.memoryMapXML - elif query == 'read_feature': - xml = self.target.targetXML - - size_xml = len(xml) - - prefix = 'm' - - if offset > size_xml: - logging.error('GDB: offset target.xml > size!') - return - - if size > (self.packet_size - 4): - size = self.packet_size - 4 - - nbBytesAvailable = size_xml - offset - - if size > nbBytesAvailable: - prefix = 'l' - size = nbBytesAvailable - - resp = prefix + xml[offset:offset + size] - - return resp - - - def createRSPPacket(self, data): - resp = '$' + data + '#' - - c = 0 - checksum = 0 - for c in data: - checksum += ord(c) - checksum = checksum % 256 - checksum = hex(checksum) - - if int(checksum[2:], 16) < 0x10: - resp += '0' - resp += checksum[2:] - - #logging.debug('--<<<<<<<<<<<< GDB rsp packet: %s', resp) - return resp - - def ack(self): - self.abstract_socket.write("+") \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/interface/__init__.py b/workspace_tools/debugger/pyOCD/interface/__init__.py deleted file mode 100644 index e093ce16a7..0000000000 --- a/workspace_tools/debugger/pyOCD/interface/__init__.py +++ /dev/null @@ -1,23 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from pyusb_backend import PyUSB -from pywinusb_backend import PyWinUSB - -INTERFACE = {'pyusb': PyUSB, - 'pywinusb': PyWinUSB - } \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/interface/interface.py b/workspace_tools/debugger/pyOCD/interface/interface.py deleted file mode 100644 index d051bd31d9..0000000000 --- a/workspace_tools/debugger/pyOCD/interface/interface.py +++ /dev/null @@ -1,45 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -class Interface: - - def __init__(self): - self.vid = 0 - self.pid = 0 - self.vendor_name = "" - self.product_name = "" - return - - def init(self): - return - - def write(self, data): - return - - def read(self, size = -1, timeout = -1): - return - - def getInfo(self): - return self.vendor_name + " " + \ - self.product_name + " (" + \ - str(hex(self.vid)) + ", " + \ - str(hex(self.pid)) + ")" - - def close(self): - return - - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/interface/pyusb_backend.py b/workspace_tools/debugger/pyOCD/interface/pyusb_backend.py deleted file mode 100644 index de7ca7bbf1..0000000000 --- a/workspace_tools/debugger/pyOCD/interface/pyusb_backend.py +++ /dev/null @@ -1,138 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from interface import Interface -import logging, os - -try: - import usb.core - import usb.util -except: - if os.name == "posix": - logging.error("PyUSB is required on a Linux Machine") - -class PyUSB(Interface): - """ - This class provides basic functions to access - a USB HID device using pyusb: - - write/read an endpoint - """ - - vid = 0 - pid = 0 - - def __init__(self): - self.ep_out = None - self.ep_in = None - self.dev = None - - @staticmethod - def getAllConnectedInterface(vid, pid): - """ - returns all the connected devices which matches PyUSB.vid/PyUSB.pid. - returns an array of PyUSB (Interface) objects - """ - # find all devices matching the vid/pid specified - all_devices = usb.core.find(find_all=True, idVendor=vid, idProduct=pid) - - if all_devices is None: - logging.debug("No device connected") - return None - - boards = [] - - # iterate on all devices found - for board in all_devices: - intf_number = 0 - found = False - - # get active config - config = board.get_active_configuration() - - # iterate on all interfaces: - # - if we found a HID interface -> CMSIS-DAP - for interface in config: - if interface.bInterfaceClass == 0x03: - intf_number = interface.bInterfaceNumber - found = True - break - - if found == False: - continue - - try: - if board.is_kernel_driver_active(intf_number) is True: - board.detach_kernel_driver(intf_number) - except Exception as e: - print e - pass - - intf = usb.util.find_descriptor(config, bInterfaceNumber = intf_number) - ep_out = usb.util.find_descriptor(intf, - # match the first OUT endpoint - custom_match = \ - lambda e: \ - usb.util.endpoint_direction(e.bEndpointAddress) == \ - usb.util.ENDPOINT_OUT - ) - ep_in = usb.util.find_descriptor(intf, - # match the first IN endpoint - custom_match = \ - lambda e: \ - usb.util.endpoint_direction(e.bEndpointAddress) == \ - usb.util.ENDPOINT_IN - ) - product_name = usb.util.get_string(board, 256, 2) - vendor_name = usb.util.get_string(board, 256, 1) - if ep_out is None or ep_in is None: - logging.error('Endpoints not found') - return None - - new_board = PyUSB() - new_board.ep_in = ep_in - new_board.ep_out = ep_out - new_board.dev = board - new_board.vid = vid - new_board.pid = pid - new_board.product_name = product_name - new_board.vendor_name = vendor_name - boards.append(new_board) - - return boards - - def write(self, data): - """ - write data on the OUT endpoint associated to the HID interface - """ - if self.ep_out is None: - raise ValueError('EP_OUT endpoint is NULL') - - self.ep_out.write(data) - #logging.debug('sent: %s', data) - return - - - def read(self, timeout = -1): - """ - read data on the IN endpoint associated to the HID interface - """ - if self.ep_in is None: - raise ValueError('EP_IN endpoint is NULL') - - data = self.ep_in.read(self.ep_in.wMaxPacketSize, timeout) - #logging.debug('received: %s', data) - return data diff --git a/workspace_tools/debugger/pyOCD/interface/pywinusb_backend.py b/workspace_tools/debugger/pyOCD/interface/pywinusb_backend.py deleted file mode 100644 index 90689039dd..0000000000 --- a/workspace_tools/debugger/pyOCD/interface/pywinusb_backend.py +++ /dev/null @@ -1,116 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from interface import Interface -import logging, os - -try: - import pywinusb.hid as hid -except: - if os.name == "nt": - logging.error("PyWinUSB is required on a Windows Machine") - -class PyWinUSB(Interface): - """ - This class provides basic functions to access - a USB HID device using pywinusb: - - write/read an endpoint - """ - vid = 0 - pid = 0 - - def __init__(self): - # Vendor page and usage_id = 2 - self.report = [] - self.rcv_data = [] - self.device = None - return - - # handler called when a report is received - def rx_handler(self, data): - #logging.debug("rcv: %s", data[1:]) - self.rcv_data.append(data[1:]) - - def open(self): - self.device.set_raw_data_handler(self.rx_handler) - self.device.open() - - @staticmethod - def getAllConnectedInterface(vid, pid): - """ - returns all the connected devices which matches PyWinUSB.vid/PyWinUSB.pid. - returns an array of PyWinUSB (Interface) objects - """ - all_devices = hid.find_all_hid_devices() - - # find devices with good vid/pid - all_mbed_devices = [] - for d in all_devices: - if (d.vendor_id == vid) and (d.product_id == pid): - all_mbed_devices.append(d) - - if not all_mbed_devices: - logging.debug("No Mbed device connected") - return - - boards = [] - for dev in all_mbed_devices: - try: - dev.open() - report = dev.find_output_reports() - if (len(report) == 1): - new_board = PyWinUSB() - new_board.report = report[0] - new_board.vendor_name = dev.vendor_name - new_board.product_name = dev.product_name - new_board.vid = dev.vendor_id - new_board.pid = dev.product_id - new_board.device = dev - new_board.device.set_raw_data_handler(new_board.rx_handler) - - boards.append(new_board) - except Exception as e: - logging.error("Receiving Exception: %s", e) - dev.close() - - return boards - - def write(self, data): - """ - write data on the OUT endpoint associated to the HID interface - """ - for _ in range(64 - len(data)): - data.append(0) - #logging.debug("send: %s", data) - self.report.send([0] + data) - return - - - def read(self, timeout = -1): - """ - read data on the IN endpoint associated to the HID interface - """ - while len(self.rcv_data) == 0: - pass - return self.rcv_data.pop(0) - - def close(self): - """ - close the interface - """ - logging.debug("closing interface") - self.device.close() diff --git a/workspace_tools/debugger/pyOCD/target/__init__.py b/workspace_tools/debugger/pyOCD/target/__init__.py deleted file mode 100644 index 9f7fd9ecca..0000000000 --- a/workspace_tools/debugger/pyOCD/target/__init__.py +++ /dev/null @@ -1,29 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import cortex_m -import target_lpc1768 -import target_kl25z -import target_lpc11u24 -import target_lpc800 - -TARGET = {'cortex_m': cortex_m.CortexM, - 'target_lpc1768': target_lpc1768.LPC1768, - 'target_kl25z': target_kl25z.KL25Z, - 'target_lpc11u24': target_lpc11u24.LPC11U24, - 'target_lpc800': target_lpc800.LPC800, - } \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/target/cortex_m.py b/workspace_tools/debugger/pyOCD/target/cortex_m.py deleted file mode 100644 index 24606654b4..0000000000 --- a/workspace_tools/debugger/pyOCD/target/cortex_m.py +++ /dev/null @@ -1,554 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from pyOCD.target.target import Target -from pyOCD.target.target import TARGET_RUNNING, TARGET_HALTED -from pyOCD.transport.cmsis_dap import DP_REG -import logging - -# Debug Halting Control and Status Register -DHCSR = 0xE000EDF0 -# Debug Core Register Selector Register -DCRSR = 0xE000EDF4 -REGWnR = (1 << 16) -# Debug Core Register Data Register -DCRDR = 0xE000EDF8 -# Debug Exception and Monitor Control Register -DEMCR = 0xE000EDFC -TRACE_ENA = (1 << 24) -VC_HARDERR = (1 << 9) -VC_BUSERR = (1 << 8) -VC_CORERESET = (1 << 0) - -NVIC_AIRCR = (0xE000ED0C) -NVIC_AIRCR_VECTKEY = (0x5FA << 16) -NVIC_AIRCR_VECTRESET = (1 << 0) -NVIC_AIRCR_SYSRESETREQ = (1 << 2) - -CSYSPWRUPACK = 0x80000000 -CDBGPWRUPACK = 0x20000000 -CSYSPWRUPREQ = 0x40000000 -CDBGPWRUPREQ = 0x10000000 - -TRNNORMAL = 0x00000000 -MASKLANE = 0x00000f00 - -C_DEBUGEN = (1 << 0) -C_HALT = (1 << 1) -C_STEP = (1 << 2) -C_MASKINTS = (1 << 3) -C_SNAPSTALL = (1 << 4) -DBGKEY = (0xA05F << 16) - -# FPB (breakpoint) -FP_CTRL = (0xE0002000) -FP_CTRL_KEY = (1 << 1) -FP_COMP0 = (0xE0002008) - -CORE_REGISTER = {'r0': 0, - 'r1': 1, - 'r2': 2, - 'r3': 3, - 'r4': 4, - 'r5': 5, - 'r6': 6, - 'r7': 7, - 'r8': 8, - 'r9': 9, - 'r10': 10, - 'r11': 11, - 'r12': 12, - 'sp': 13, - 'lr': 14, - 'pc': 15, - 'xpsr': 16, - } - -targetXML = "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" \ - "\n" - -""" -convert a byte array into a word array -""" -def byte2word(data): - res = [] - for i in range(len(data)/4): - res.append(data[i*4 + 0] << 0 | - data[i*4 + 1] << 8 | - data[i*4 + 2] << 16 | - data[i*4 + 3] << 24) - return res - -""" -convert a word array into a byte array -""" -def word2byte(data): - res = [] - for x in data: - res.append((x >> 0) & 0xff) - res.append((x >> 8) & 0xff) - res.append((x >> 16) & 0xff) - res.append((x >> 24) & 0xff) - return res - - -class Breakpoint(): - def __init__(self, comp_register_addr): - self.comp_register_addr = comp_register_addr - self.enabled = False - self.addr = 0 - - -class CortexM(Target): - - """ - This class has basic functions to access a Cortex M core: - - init - - read/write memory - - read/write core registers - - set/remove hardware breakpoints - """ - - def __init__(self, transport): - self.transport = transport - self.auto_increment_page_size = 0 - self.idcode = 0 - self.breakpoints = [] - self.nb_code = 0 - self.num_breakpoint_used = 0 - self.nb_lit = 0 - self.fpb_enabled = False - self.targetXML = targetXML - return - - def init(self, setup_fpb = True): - """ - Cortex M initialization - """ - self.idcode = self.readIDCode() - # select bank 0 (to access DRW and TAR) - self.transport.writeDP(DP_REG['SELECT'], 0) - self.transport.writeDP(DP_REG['CTRL_STAT'], CSYSPWRUPREQ | CDBGPWRUPREQ) - - while True: - r = self.transport.readDP(DP_REG['CTRL_STAT']) - if (r & (CDBGPWRUPACK | CSYSPWRUPACK)) == (CDBGPWRUPACK | CSYSPWRUPACK): - break - - self.transport.writeDP(DP_REG['CTRL_STAT'], CSYSPWRUPREQ | CDBGPWRUPREQ | TRNNORMAL | MASKLANE) - self.transport.writeDP(DP_REG['SELECT'], 0) - - if setup_fpb: - self.halt() - self.setupFPB() - - return - - def setupFPB(self): - """ - Reads the number of hardware breakpoints available on the core - and disable the FPB (Flash Patch and Breakpoint Unit) - which will be enabled when a first breakpoint will be set - """ - # setup FPB (breakpoint) - fpcr = self.readMemory(FP_CTRL) - self.nb_code = ((fpcr >> 8) & 0x70) | ((fpcr >> 4) & 0xF) - logging.info("%d hardware breakpoints", self.nb_code) - for i in range(self.nb_code): - self.breakpoints.append(Breakpoint(FP_COMP0 + 4*i)) - - # disable FPB (will be enabled on first bp set) - self.disableFPB() - for bp in self.breakpoints: - self.writeMemory(bp.comp_register_addr, 0) - - def info(self, request): - return self.transport.info(request) - - def readIDCode(self): - """ - return the IDCODE of the core - """ - if self.idcode == 0: - self.idcode = self.transport.readDP(DP_REG['IDCODE']) - return self.idcode - - def writeMemory(self, addr, value, transfer_size = 32): - """ - write a memory location. - By default the transfer size is a word - """ - self.transport.writeMem(addr, value, transfer_size) - return - - def readMemory(self, addr, transfer_size = 32): - """ - read a memory location. By default, a word will - be read - """ - return self.transport.readMem(addr, transfer_size) - - def readBlockMemoryUnaligned8(self, addr, size): - """ - read a block of unaligned bytes in memory. Returns - an array of byte values - """ - res = [] - - # try to read 8bits data - if (size > 0) and (addr & 0x01): - mem = self.readMemory(addr, 8) - logging.debug("get 1 byte at %s: 0x%X", hex(addr), mem) - res.append(mem) - size -= 1 - addr += 1 - - # try to read 16bits data - if (size > 1) and (addr & 0x02): - mem = self.readMemory(addr, 16) - logging.debug("get 2 bytes at %s: 0x%X", hex(addr), mem) - res.append(mem & 0xff) - res.append((mem >> 8) & 0xff) - size -= 2 - addr += 2 - - # try to read aligned block of 32bits - if (size >= 4): - logging.debug("read blocks aligned at 0x%X, size: 0x%X", addr, (size/4)*4) - mem = self.readBlockMemoryAligned32(addr, size/4) - res += word2byte(mem) - size -= 4*len(mem) - addr += 4*len(mem) - - if (size > 1): - mem = self.readMemory(addr, 16) - logging.debug("get 2 bytes at %s: 0x%X", hex(addr), mem) - res.append(mem & 0xff) - res.append((mem >> 8) & 0xff) - size -= 2 - addr += 2 - - if (size > 0): - mem = self.readMemory(addr, 8) - logging.debug("get 1 byte remaining at %s: 0x%X", hex(addr), mem) - res.append(mem) - size -= 1 - addr += 1 - - return res - - - def writeBlockMemoryUnaligned8(self, addr, data): - """ - write a block of unaligned bytes in memory. - """ - size = len(data) - idx = 0 - - #try to write 8 bits data - if (size > 0) and (addr & 0x01): - logging.debug("write 1 byte at 0x%X: 0x%X", addr, data[idx]) - self.writeMemory(addr, data[idx], 8) - size -= 1 - addr += 1 - idx += 1 - - # try to write 16 bits data - if (size > 1) and (addr & 0x02): - logging.debug("write 2 bytes at 0x%X: 0x%X", addr, data[idx] | (data[idx+1] << 8)) - self.writeMemory(addr, data[idx] | (data[idx+1] << 8), 16) - size -= 2 - addr += 2 - idx += 2 - - # write aligned block of 32 bits - if (size >= 4): - logging.debug("write blocks aligned at 0x%X, size: 0x%X", addr, (size/4)*4) - data32 = byte2word(data[idx:idx + (size & ~0x03)]) - self.writeBlockMemoryAligned32(addr, data32) - addr += size & ~0x03 - idx += size & ~0x03 - size -= size & ~0x03 - - # try to write 16 bits data - if (size > 1): - logging.debug("write 2 bytes at 0x%X: 0x%X", addr, data[idx] | (data[idx+1] << 8)) - self.writeMemory(addr, data[idx] | (data[idx+1] << 8), 16) - size -= 2 - addr += 2 - idx += 2 - - #try to write 8 bits data - if (size > 0): - logging.debug("write 1 byte at 0x%X: 0x%X", addr, data[idx]) - self.writeMemory(addr, data[idx], 8) - size -= 1 - addr += 1 - idx += 1 - - return - - def writeBlockMemoryAligned32(self, addr, data): - """ - write a block of aligned words in memory. - """ - size = len(data) - while size > 0: - n = self.auto_increment_page_size - (addr & (self.auto_increment_page_size - 1)) - if size*4 < n: - n = (size*4) & 0xfffffffc - self.transport.writeBlock32(addr, data[:n/4]) - data = data[n/4:] - size -= n/4 - addr += n - return - - def readBlockMemoryAligned32(self, addr, size): - """ - read a block of aligned words in memory. Returns - an array of word values - """ - resp = [] - while size > 0: - n = self.auto_increment_page_size - (addr & (self.auto_increment_page_size - 1)) - if size*4 < n: - n = (size*4) & 0xfffffffc - resp += self.transport.readBlock32(addr, n/4) - size -= n/4 - addr += n - return resp - - def halt(self): - """ - halt the core - """ - self.writeMemory(DHCSR, DBGKEY | C_DEBUGEN | C_HALT) - return - - def step(self): - """ - perform an instruction level step - """ - if self.getState() != TARGET_HALTED: - logging.debug('cannot step: target not halted') - return - if self.maybeSkipBreakpoint() is None: - self.writeMemory(DHCSR, DBGKEY | C_DEBUGEN | C_STEP) - return - - def reset(self): - """ - reset a core. After a call to this function, the core - is running - """ - self.transport.reset() - - def resetStopOnReset(self): - """ - perform a reset and stop the core on the reset handler - """ - logging.debug("reset stop on Reset") - # read address of reset handler - reset_handler = self.readMemory(4) - - # reset and halt the target - self.transport.reset() - self.halt() - - # set a breakpoint to the reset handler and reset the target - self.setBreakpoint(reset_handler) - self.transport.reset() - - # wait until the bp is reached - while (self.getState() == TARGET_RUNNING): - pass - - # remove the breakpoint - self.removeBreakpoint(reset_handler) - - logging.debug("stopped on reset handler: 0x%X", reset_handler) - - def setTargetState(self, state): - if state == "PROGRAM": - self.reset() - self.writeMemory(DHCSR, DBGKEY | C_DEBUGEN) - self.writeMemory(DEMCR, VC_CORERESET) - self.writeMemory(NVIC_AIRCR, NVIC_AIRCR_VECTKEY | NVIC_AIRCR_SYSRESETREQ) - while self.getState() == TARGET_RUNNING: - pass - self.writeMemory(DEMCR, 0) - - - def getState(self): - dhcsr = self.readMemory(DHCSR) - if dhcsr & (C_STEP | C_HALT): - return TARGET_HALTED - return TARGET_RUNNING - - def resume(self): - """ - resume the execution - """ - if self.getState() != TARGET_HALTED: - logging.debug('cannot resume: target not halted') - return - self.maybeSkipBreakpoint() - self.writeMemory(DHCSR, DBGKEY | C_DEBUGEN) - return - - def maybeSkipBreakpoint(self): - pc = self.readCoreRegister('pc') - bp = self.findBreakpoint(pc) - if bp is not None: - logging.debug('skip/resume breakpoint: pc 0x%X', pc) - self.removeBreakpoint(pc) - self.writeMemory(DHCSR, DBGKEY | C_DEBUGEN | C_STEP) - self.setBreakpoint(pc) - logging.debug('step over breakpoint: now pc0x%X', self.readCoreRegister('pc')) - return bp - return None - - def findBreakpoint(self, addr): - for bp in self.breakpoints: - if bp.enabled and bp.addr == addr: - return bp - return None - - def readCoreRegister(self, reg): - """ - read a core register (r0 .. r16). - If reg is a string, find the number associated to this register - in the lookup table CORE_REGISTER - """ - if isinstance(reg, str): - try: - reg = CORE_REGISTER[reg] - except KeyError: - logging.error('cannot find %s core register', id) - return - - if (reg < 0) or (reg > len(CORE_REGISTER)): - logging.error("unknown reg: %d", reg) - return - - # write id in DCRSR - self.writeMemory(DCRSR, reg) - # read DCRDR - return self.readMemory(DCRDR) - - - def writeCoreRegister(self, reg, data): - """ - write a core register (r0 .. r16) - If reg is a string, find the number associated to this register - in the lookup table CORE_REGISTER - """ - if isinstance(reg, str): - try: - reg = CORE_REGISTER[reg] - except KeyError: - logging.error('cannot find %s core register', id) - return - - if (reg < 0) or (reg > len(CORE_REGISTER)): - logging.error("unknown reg: %d", reg) - return - - # write id in DCRSR - self.writeMemory(DCRDR, data) - # read DCRDR - self.writeMemory(DCRSR, reg | REGWnR) - return - - - def setBreakpoint(self, addr): - """ - set a hardware breakpoint at a specific location in flash - """ - if self.fpb_enabled is False: - self.enableFPB() - - if self.availableBreakpoint() == 0: - logging.error('No more available breakpoint!!, dropped bp at 0x%X', addr) - return False - - for bp in self.breakpoints: - if not bp.enabled: - bp.enabled = True - bp_match = (1 << 30) - if addr & 0x2: - bp_match = (2 << 30) - self.writeMemory(bp.comp_register_addr, addr & 0x1ffffffc | bp_match | 1) - bp.addr = addr - self.num_breakpoint_used += 1 - return True - return False - - - def availableBreakpoint(self): - return len(self.breakpoints) - self.num_breakpoint_used - - def enableFPB(self): - self.writeMemory(FP_CTRL, FP_CTRL_KEY | 1) - self.fpb_enabled = True - logging.debug('fpb has been enabled') - return - - def disableFPB(self): - self.writeMemory(FP_CTRL, FP_CTRL_KEY | 0) - self.fpb_enabled = False - logging.debug('fpb has been disabled') - return - - def removeBreakpoint(self, addr): - """ - remove a hardware breakpoint at a specific location in flash - """ - for bp in self.breakpoints: - if bp.enabled and bp.addr == addr: - bp.enabled = False - self.writeMemory(bp.comp_register_addr, 0) - bp.addr = addr - self.num_breakpoint_used -= 1 - return - return - - # GDB functions - def getTargetXML(self): - return self.targetXML, len(self.targetXML) - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/target/target.py b/workspace_tools/debugger/pyOCD/target/target.py deleted file mode 100644 index 9c09892d32..0000000000 --- a/workspace_tools/debugger/pyOCD/target/target.py +++ /dev/null @@ -1,82 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -TARGET_RUNNING = (1 << 0) -TARGET_HALTED = (1 << 1) - -class Target(): - - def __init__(self, transport): - return - - def init(self): - return - - def info(self, request): - return - - def readIDCode(self): - return - - def halt(self): - return - - def step(self): - return - - def resume(self): - return - - def writeMemory(self, addr, value, transfer_size = 32): - return - - def readMemory(self, addr, transfer_size = 32): - return - - def writeBlockMemoryUnaligned8(self, addr, value): - return - - def writeBlockMemoryAligned32(self, addr, data): - return - - def readBlockMemoryUnaligned8(self, addr, size): - return - - def readBlockMemoryAligned32(self, addr, size): - return - - def readCoreRegister(self, id): - return - - def writeCoreRegister(self, id): - return - - def setBreakpoint(self, addr): - return - - def removeBreakpoint(self, addr): - return - - def reset(self): - return - - def getState(self): - return - - # GDB functions - def getTargetXML(self): - return \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/target/target_kl25z.py b/workspace_tools/debugger/pyOCD/target/target_kl25z.py deleted file mode 100644 index f2f98f69c9..0000000000 --- a/workspace_tools/debugger/pyOCD/target/target_kl25z.py +++ /dev/null @@ -1,57 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cortex_m import CortexM -import logging - - -MDM_STATUS = 0x01000000 -MDM_CTRL = 0x01000004 -MDM_IDR = 0x010000fc - -class KL25Z(CortexM): - - def __init__(self, transport): - CortexM.__init__(self, transport) - self.auto_increment_page_size = 0x400 - - def init(self): - CortexM.init(self, False) - - # check for flash security - val = self.transport.readAP(MDM_IDR) - if val != 0x001c0020: - logging.error("KL25Z: bad flash ID") - val = self.transport.readAP(MDM_STATUS) - if (val & (1 << 2)): - logging.warning("KL25Z secure state: will try to unlock") - self.transport.assertReset(True) - while True: - self.transport.writeAP(MDM_CTRL, 1) - val = self.transport.readAP(MDM_STATUS) - logging.info(val) - if (val & 1): - break - while True: - self.transport.writeAP(MDM_CTRL, 0) - val = self.transport.readAP(MDM_CTRL) - if (val == 0): - break - - logging.info("KL25Z not in secure state") - self.halt() - self.setupFPB() diff --git a/workspace_tools/debugger/pyOCD/target/target_lpc11u24.py b/workspace_tools/debugger/pyOCD/target/target_lpc11u24.py deleted file mode 100644 index 5bd3e06d15..0000000000 --- a/workspace_tools/debugger/pyOCD/target/target_lpc11u24.py +++ /dev/null @@ -1,24 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cortex_m import CortexM - -class LPC11U24(CortexM): - - def __init__(self, transport): - CortexM.__init__(self, transport) - self.auto_increment_page_size = 0x400 \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/target/target_lpc1768.py b/workspace_tools/debugger/pyOCD/target/target_lpc1768.py deleted file mode 100644 index 8d0d1deb21..0000000000 --- a/workspace_tools/debugger/pyOCD/target/target_lpc1768.py +++ /dev/null @@ -1,40 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cortex_m import CortexM - -class LPC1768(CortexM): - - def __init__(self, transport): - CortexM.__init__(self, transport) - self.auto_increment_page_size = 0x1000 - - - def reset(self): - # halt processor - self.halt() - # not remap 0x0000-0x0020 to anything but the flash - self.writeMemory(0x400FC040, 1) - CortexM.reset(self) - - def resetStopOnReset(self): - # halt processor - self.halt() - # not remap 0x0000-0x0020 to anything but the flash - self.writeMemory(0x400FC040, 1) - CortexM.resetStopOnReset(self) - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/target/target_lpc800.py b/workspace_tools/debugger/pyOCD/target/target_lpc800.py deleted file mode 100644 index 4ef73db9b9..0000000000 --- a/workspace_tools/debugger/pyOCD/target/target_lpc800.py +++ /dev/null @@ -1,24 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cortex_m import CortexM - -class LPC800(CortexM): - - def __init__(self, transport): - CortexM.__init__(self, transport) - self.auto_increment_page_size = 0x400 diff --git a/workspace_tools/debugger/pyOCD/transport/__init__.py b/workspace_tools/debugger/pyOCD/transport/__init__.py deleted file mode 100644 index c657d37349..0000000000 --- a/workspace_tools/debugger/pyOCD/transport/__init__.py +++ /dev/null @@ -1,21 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cmsis_dap import CMSIS_DAP - -TRANSPORT = {'cmsis_dap': CMSIS_DAP - } \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/transport/cmsis_dap.py b/workspace_tools/debugger/pyOCD/transport/cmsis_dap.py deleted file mode 100644 index 9c50d542da..0000000000 --- a/workspace_tools/debugger/pyOCD/transport/cmsis_dap.py +++ /dev/null @@ -1,229 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from cmsis_dap_core import dapTransferBlock, dapWriteAbort, dapSWJPins, dapConnect, dapDisconnect, dapTransfer, dapSWJSequence, dapSWDConfigure, dapSWJClock, dapTransferConfigure, dapInfo -from transport import Transport -import logging -from time import sleep - -# !! This value are A[2:3] and not A[3:2] -DP_REG = {'IDCODE' : 0x00, - 'ABORT' : 0x00, - 'CTRL_STAT': 0x04, - 'SELECT': 0x08 - } -AP_REG = {'CSW' : 0x00, - 'TAR' : 0x04, - 'DRW' : 0x0C - } - -IDCODE = 0 << 2 -AP_ACC = 1 << 0 -DP_ACC = 0 << 0 -READ = 1 << 1 -WRITE = 0 << 1 -VALUE_MATCH = 1 << 4 -MATCH_MASK = 1 << 5 - -APBANKSEL = 0x000000f0 - -# AP Control and Status Word definitions -CSW_SIZE = 0x00000007 -CSW_SIZE8 = 0x00000000 -CSW_SIZE16 = 0x00000001 -CSW_SIZE32 = 0x00000002 -CSW_ADDRINC = 0x00000030 -CSW_NADDRINC = 0x00000000 -CSW_SADDRINC = 0x00000010 -CSW_PADDRINC = 0x00000020 -CSW_DBGSTAT = 0x00000040 -CSW_TINPROG = 0x00000080 -CSW_HPROT = 0x02000000 -CSW_MSTRTYPE = 0x20000000 -CSW_MSTRCORE = 0x00000000 -CSW_MSTRDBG = 0x20000000 -CSW_RESERVED = 0x01000000 - -CSW_VALUE = (CSW_RESERVED | CSW_MSTRDBG | CSW_HPROT | CSW_DBGSTAT | CSW_SADDRINC) - -TRANSFER_SIZE = {8: CSW_SIZE8, - 16: CSW_SIZE16, - 32: CSW_SIZE32 - } - - -def JTAG2SWD(interface): - data = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] - dapSWJSequence(interface, data) - - data = [0x9e, 0xe7] - dapSWJSequence(interface, data) - - data = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff] - dapSWJSequence(interface, data) - - data = [0x00] - dapSWJSequence(interface, data) - -class CMSIS_DAP(Transport): - """ - This class implements the CMSIS-DAP protocol - """ - def __init__(self, interface): - self.interface = interface - self.packet_max_count = 0 - self.packet_max_size = 0 - self.csw = -1 - self.dp_select = -1 - return - - def init(self): - # init dap IO - dapConnect(self.interface) - # set clock freq at 1000000Hz - dapSWJClock(self.interface) - # configure transfer - dapTransferConfigure(self.interface) - # configure swd protocol - dapSWDConfigure(self.interface) - # switch from jtag to swd - JTAG2SWD(self.interface) - # read ID code - logging.info('IDCODE: 0x%X', self.readDP(DP_REG['IDCODE'])) - # clear abort err - dapWriteAbort(self.interface, 0x1e); - return - - def uninit(self): - dapDisconnect(self.interface) - return - - def info(self, request): - resp = None - try: - resp = dapInfo(self.interface, request) - except KeyError: - logging.error('request %s not supported', request) - return resp - - def writeMem(self, addr, data, transfer_size = 32): - self.writeAP(AP_REG['CSW'], CSW_VALUE | TRANSFER_SIZE[transfer_size]) - - if transfer_size == 8: - data = data << ((addr & 0x03) << 3) - elif transfer_size == 16: - data = data << ((addr & 0x02) << 3) - - dapTransfer(self.interface, 2, [WRITE | AP_ACC | AP_REG['TAR'], - WRITE | AP_ACC | AP_REG['DRW']], - [addr, data]) - - def readMem(self, addr, transfer_size = 32): - self.writeAP(AP_REG['CSW'], CSW_VALUE | TRANSFER_SIZE[transfer_size]) - - resp = dapTransfer(self.interface, 2, [WRITE | AP_ACC | AP_REG['TAR'], - READ | AP_ACC | AP_REG['DRW']], - [addr]) - - res = (resp[0] << 0) | \ - (resp[1] << 8) | \ - (resp[2] << 16) | \ - (resp[3] << 24) - - if transfer_size == 8: - res = (res >> ((addr & 0x03) << 3) & 0xff) - elif transfer_size == 16: - res = (res >> ((addr & 0x02) << 3) & 0xffff) - - return res - - # write aligned word ("data" are words) - def writeBlock32(self, addr, data): - # put address in TAR - self.writeAP(AP_REG['CSW'], CSW_VALUE | CSW_SIZE32) - self.writeAP(AP_REG['TAR'], addr) - dapTransferBlock(self.interface, len(data), WRITE | AP_ACC | AP_REG['DRW'], data) - return - - # read aligned word (the size is in words) - def readBlock32(self, addr, size): - # put address in TAR - self.writeAP(AP_REG['CSW'], CSW_VALUE | CSW_SIZE32) - self.writeAP(AP_REG['TAR'], addr) - data = [] - resp = dapTransferBlock(self.interface, size, READ | AP_ACC | AP_REG['DRW']) - for i in range(len(resp)/4): - data.append( (resp[i*4 + 0] << 0) | \ - (resp[i*4 + 1] << 8) | \ - (resp[i*4 + 2] << 16) | \ - (resp[i*4 + 3] << 24)) - return data - - - def readDP(self, addr): - resp = dapTransfer(self.interface, 1, [READ | DP_ACC | (addr & 0x0c)]) - return (resp[0] << 0) | \ - (resp[1] << 8) | \ - (resp[2] << 16) | \ - (resp[3] << 24) - - def writeDP(self, addr, data): - if addr == DP_REG['SELECT']: - if data == self.dp_select: - return - self.dp_select = data - - dapTransfer(self.interface, 1, [WRITE | DP_ACC | (addr & 0x0c)], [data]) - return True - - def writeAP(self, addr, data): - if addr == AP_REG['CSW']: - if data == self.csw: - return - self.csw = data - - ap_sel = addr & 0xff000000 - bank_sel = addr & APBANKSEL - - self.writeDP(DP_REG['SELECT'], ap_sel | bank_sel) - dapTransfer(self.interface, 1, [WRITE | AP_ACC | (addr & 0x0c)], [data]) - return True - - def readAP(self, addr): - ap_sel = addr & 0xff000000 - bank_sel = addr & APBANKSEL - - self.writeDP(DP_REG['SELECT'], ap_sel | bank_sel) - resp = dapTransfer(self.interface, 1, [READ | AP_ACC | (addr & 0x0c)]) - return (resp[0] << 0) | \ - (resp[1] << 8) | \ - (resp[2] << 16) | \ - (resp[3] << 24) - - def reset(self): - dapSWJPins(self.interface, 0, 'nRESET') - sleep(0.1) - dapSWJPins(self.interface, 0x80, 'nRESET') - sleep(0.1) - - def assertReset(self, asserted): - if asserted: - dapSWJPins(self.interface, 0, 'nRESET') - else: - dapSWJPins(self.interface, 0x80, 'nRESET') - - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/transport/cmsis_dap_core.py b/workspace_tools/debugger/pyOCD/transport/cmsis_dap_core.py deleted file mode 100644 index 49e281213d..0000000000 --- a/workspace_tools/debugger/pyOCD/transport/cmsis_dap_core.py +++ /dev/null @@ -1,315 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import logging -import array - -COMMAND_ID = {'DAP_INFO': 0x00, - 'DAP_LED': 0x01, - 'DAP_CONNECT': 0x02, - 'DAP_DISCONNECT': 0x03, - 'DAP_TRANSFER_CONFIGURE': 0x04, - 'DAP_TRANSFER': 0x05, - 'DAP_TRANSFER_BLOCK': 0x06, - 'DAP_TRANSFER_ABORT': 0x07, - 'DAP_WRITE_ABORT': 0x08, - 'DAP_DELAY': 0x09, - 'DAP_RESET_TARGET': 0x0a, - 'DAP_SWJ_PINS': 0x10, - 'DAP_SWJ_CLOCK': 0x11, - 'DAP_SWJ_SEQUENCE': 0x12, - 'DAP_SWD_CONFIGURE': 0x13, - } - -ID_INFO = {'VENDOR_ID': 0x01, - 'PRODUCT_ID': 0x02, - 'SERIAL_NUMBER': 0x03, - 'CMSIS_DAP_FW_VERSION': 0x04, - 'TARGET_DEVICE_VENDOR': 0x05, - 'TARGET_DEVICE_NAME': 0x06, - 'CAPABILITIES': 0xf0, - 'PACKET_COUNT': 0xfe, - 'PACKET_SIZE': 0xff - } - -PINS = {'None': 0x00, - 'SWCLK_TCK': (1 << 0), - 'SWDIO_TMS': (1 << 1), - 'TDI': (1 << 2), - 'TDO': (1 << 3), - 'nTRST': (1 << 5), - 'nRESET': (1 << 7), - } - -DAP_DEFAULT_PORT = 0 -DAP_SWD_PORT = 1 -DAP_JTAG_POR = 2 - -DAP_OK = 0 -DAP_ERROR = 0xff - -MAX_PACKET_SIZE = 0x0E - -def dapInfo(interface, id_): - cmd = [] - cmd.append(COMMAND_ID['DAP_INFO']) - cmd.append(ID_INFO[id_]) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_INFO']: - raise ValueError('DAP_INFO response error') - - if resp[1] == 0: - return - - if resp[1] == 1: - return resp[2] - - if resp[1] == 2: - return (resp[3] << 8) | resp[2] - - x = array.array('B', [i for i in resp[2:2+resp[1]]]) - - return x.tostring() - - -def dapLed(interface): - #not yet implemented - return - -def dapConnect(interface, mode = DAP_DEFAULT_PORT): - cmd = [] - cmd.append(COMMAND_ID['DAP_CONNECT']) - cmd.append(mode) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_CONNECT']: - raise ValueError('DAP_CONNECT response error') - - if resp[1] == 0: - raise ValueError('DAP Connect failed') - - if resp[1] == 1: - logging.info('DAP SWD MODE initialised') - - if resp[1] == 2: - logging.info('DAP JTAG MODE initialised') - - return resp[1] - -def dapDisconnect(interface): - cmd = [] - cmd.append(COMMAND_ID['DAP_DISCONNECT']) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_DISCONNECT']: - raise ValueError('DAP_DISCONNECT response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP Disconnect failed') - - return resp[1] - - -def dapWriteAbort(interface, data, dap_index = 0): - cmd = [] - cmd.append(COMMAND_ID['DAP_WRITE_ABORT']) - cmd.append(dap_index) - cmd.append((data >> 0) & 0xff) - cmd.append((data >> 8) & 0xff) - cmd.append((data >> 16) & 0xff) - cmd.append((data >> 24) & 0xff) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_WRITE_ABORT']: - raise ValueError('DAP_WRITE_ABORT response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP Write Abort failed') - - return True - -def dapResetTarget(interface): - cmd = [] - cmd.append(COMMAND_ID['DAP_RESET_TARGET']) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_RESET_TARGET']: - raise ValueError('DAP_RESET_TARGET response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP Reset target failed') - - return resp[1] - -def dapTransferConfigure(interface, idle_cycles = 0x00, wait_retry = 0x0050, match_retry = 0x0000): - cmd = [] - cmd.append(COMMAND_ID['DAP_TRANSFER_CONFIGURE']) - cmd.append(idle_cycles) - cmd.append(wait_retry & 0xff) - cmd.append(wait_retry >> 8) - cmd.append(match_retry & 0xff) - cmd.append(match_retry >> 8) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_TRANSFER_CONFIGURE']: - raise ValueError('DAP_TRANSFER_CONFIGURE response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP Transfer Configure failed') - - return resp[1] - -def dapTransfer(interface, count, request, data = [0], dap_index = 0): - cmd = [] - cmd.append(COMMAND_ID['DAP_TRANSFER']) - cmd.append(dap_index) - cmd.append(count) - count_write = count - for i in range(count): - cmd.append(request[i]) - if not ( request[i] & ((1 << 1) | (1 << 4))): - cmd.append(data[i] & 0xff) - cmd.append((data[i] >> 8) & 0xff) - cmd.append((data[i] >> 16) & 0xff) - cmd.append((data[i] >> 24) & 0xff) - count_write -= 1 - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_TRANSFER']: - raise ValueError('DAP_TRANSFER response error') - - if resp[1] != count: - raise ValueError('Transfer not completed') - - if resp[2] != 0x01: - raise ValueError('SWD Fault') - - return resp[3:3+count_write*4] - -def dapTransferBlock(interface, count, request, data = [0], dap_index = 0): - packet_count = count - nb = 0 - resp = [] - # we send successfully several packets if the size is bigger than MAX_PACKET_COUNT - while packet_count > 0: - cmd = [] - cmd.append(COMMAND_ID['DAP_TRANSFER_BLOCK']) - cmd.append(dap_index) - packet_written = min(packet_count, MAX_PACKET_SIZE) - cmd.append(packet_written & 0xff) - cmd.append((packet_written >> 8) & 0xff) - cmd.append(request) - if not (request & ((1 << 1))): - for i in range(packet_written): - cmd.append(data[i + nb*MAX_PACKET_SIZE] & 0xff) - cmd.append((data[i + nb*MAX_PACKET_SIZE] >> 8) & 0xff) - cmd.append((data[i + nb*MAX_PACKET_SIZE] >> 16) & 0xff) - cmd.append((data[i + nb*MAX_PACKET_SIZE] >> 24) & 0xff) - interface.write(cmd) - packet_count = packet_count - MAX_PACKET_SIZE - nb = nb + 1 - - # we then read - tmp = interface.read() - if tmp[0] != COMMAND_ID['DAP_TRANSFER_BLOCK'] or tmp[3] != 0x01: - raise ValueError('DAP_TRANSFER_BLOCK response error') - size_transfer = tmp[1] | (tmp[2] << 8) - resp.extend(tmp[4:4+size_transfer*4]) - - return resp - -def dapSWJClock(interface, clock = 1000000): - cmd = [] - cmd.append(COMMAND_ID['DAP_SWJ_CLOCK']) - cmd.append(clock & 0xff) - cmd.append((clock >> 8) & 0xff) - cmd.append((clock >> 16) & 0xff) - cmd.append((clock >> 24) & 0xff) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_SWJ_CLOCK']: - raise ValueError('DAP_SWJ_CLOCK response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP SWJ Clock failed') - - return resp[1] - -def dapSWJPins(interface, output, pin, wait = 0): - cmd = [] - cmd.append(COMMAND_ID['DAP_SWJ_PINS']) - try: - p = PINS[pin] - except KeyError: - logging.error('cannot find %s pin', pin) - return - cmd.append(output & 0xff) - cmd.append(p) - cmd.append(wait & 0xff) - cmd.append((wait >> 8) & 0xff) - cmd.append((wait >> 16) & 0xff) - cmd.append((wait >> 24) & 0xff) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_SWJ_PINS']: - raise ValueError('DAP_SWJ_PINS response error') - - return resp[1] - - -def dapSWDConfigure(interface, conf = 0): - cmd = [] - cmd.append(COMMAND_ID['DAP_SWD_CONFIGURE']) - cmd.append(conf) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_SWD_CONFIGURE']: - raise ValueError('DAP_SWD_CONFIGURE response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP SWD Configure failed') - - return resp[1] - -def dapSWJSequence(interface, data): - cmd = [] - cmd.append(COMMAND_ID['DAP_SWJ_SEQUENCE']) - cmd.append(len(data)*8) - for i in range(len(data)): - cmd.append(data[i]) - interface.write(cmd) - - resp = interface.read() - if resp[0] != COMMAND_ID['DAP_SWJ_SEQUENCE']: - raise ValueError('DAP_SWJ_SEQUENCE response error') - - if resp[1] != DAP_OK: - raise ValueError('DAP SWJ Sequence failed') - - return resp[1] - \ No newline at end of file diff --git a/workspace_tools/debugger/pyOCD/transport/transport.py b/workspace_tools/debugger/pyOCD/transport/transport.py deleted file mode 100644 index b0dae47f07..0000000000 --- a/workspace_tools/debugger/pyOCD/transport/transport.py +++ /dev/null @@ -1,64 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -class Transport(): - - def __init__(self, interface): - self.interface = interface - return - - def init(self): - return - - def uninit(self): - return - - def info(self, request): - return - - def readDP(self, addr): - return - - def writeDP(self, addr, data): - return - - def writeAP(self, addr, data): - return - - def readAP(self, addr): - return - - def writeMem(self, addr, data, transfer_size = 32): - return - - def readMem(self, addr, transfer_size = 32): - return - - def writeBlock32(self, addr, data): - return - - def readBlock32(self, addr, data): - return - - def assertReset(self, asserted): - return - - def getUniqueID(self): - return - - def reset(self): - return \ No newline at end of file diff --git a/workspace_tools/debugger/setup.py b/workspace_tools/debugger/setup.py deleted file mode 100644 index f61df3abaf..0000000000 --- a/workspace_tools/debugger/setup.py +++ /dev/null @@ -1,33 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -from distutils.core import setup - -setup( - name="pyOCD", - version="0.1", - description="CMSIS-DAP debugger for python", - author="samux", - author_email="samuel.mokrani@gmail.com", - license="Apache 2.0", - classifiers = [ - "Development Status :: 4 - Beta", - "License :: Apache 2.0", - "Programming Language :: Python", - ], - packages=["pyOCD", "pyOCD.flash", "pyOCD.gdbserver", "pyOCD.interface", "pyOCD.target", "pyOCD.transport", "pyOCD.board"] -) diff --git a/workspace_tools/debugger/test/basic_test.py b/workspace_tools/debugger/test/basic_test.py deleted file mode 100644 index 69ab407bf8..0000000000 --- a/workspace_tools/debugger/test/basic_test.py +++ /dev/null @@ -1,165 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import argparse, os -from time import sleep -from random import randrange - -parentdir = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) - -from pyOCD.board import MbedBoard - -addr = 0 -size = 0 -f = None -binary_file = "l1_" - -interface = None - -import logging - -logging.basicConfig(level=logging.INFO) - -parser = argparse.ArgumentParser(description='A CMSIS-DAP python debugger') -parser.add_argument('-f', help='binary file', dest = "file") -args = parser.parse_args() - -try: - - board = MbedBoard.chooseBoard() - target_type = board.getTargetType() - - if args.file is None: - binary_file += target_type + ".bin" - binary_file = os.path.join(parentdir, 'binaries', binary_file) - else: - binary_file = args.file - - print "binary file: %s" % binary_file - - if target_type == "lpc1768": - addr = 0x10000001 - size = 0x1102 - elif target_type == "lpc11u24": - addr = 0x10000001 - size = 0x502 - elif target_type == "kl25z": - addr = 0x20000001 - size = 0x502 - elif target_type == "lpc800": - addr = 0x10000001 - size = 0x502 - - target = board.target - transport = board.transport - flash = board.flash - interface = board.interface - - - print "\r\n\r\n------ GET Unique ID ------" - print "Unique ID: %s" % board.getUniqueID() - - print "\r\n\r\n------ TEST READ / WRITE CORE REGISTER ------" - pc = target.readCoreRegister('pc') - print "initial pc: 0x%X" % target.readCoreRegister('pc') - # write in pc dummy value - target.writeCoreRegister('pc', 0x3D82) - print "now pc: 0x%X" % target.readCoreRegister('pc') - # write initial pc value - target.writeCoreRegister('pc', pc) - print "initial pc value rewritten: 0x%X" % target.readCoreRegister('pc') - - - print "\r\n\r\n------ TEST HALT / RESUME ------" - - print "resume" - target.resume() - sleep(0.2) - - print "halt" - target.halt() - print "HALT: pc: 0x%X" % target.readCoreRegister('pc') - sleep(0.2) - - - - print "\r\n\r\n------ TEST READ / WRITE MEMORY ------" - target.halt() - print "READ32/WRITE32" - val = randrange(0, 0xffffffff) - print "write32 0x%X at 0x%X" % (val, addr) - target.writeMemory(addr, val) - res = target.readMemory(addr) - print "read32 at 0x%X: 0x%X" % (addr, res) - if res != val: - print "ERROR in READ/WRITE 32" - - print "\r\nREAD16/WRITE316" - val = randrange(0, 0xffff) - print "write16 0x%X at 0x%X" % (val, addr + 2) - target.writeMemory(addr + 2, val, 16) - res = target.readMemory(addr + 2, 16) - print "read16 at 0x%X: 0x%X" % (addr + 2, res) - if res != val: - print "ERROR in READ/WRITE 16" - - print "\r\nREAD8/WRITE8" - val = randrange(0, 0xff) - print "write8 0x%X at 0x%X" % (val, addr + 1) - target.writeMemory(addr + 1, val, 8) - res = target.readMemory(addr + 1, 8) - print "read8 at 0x%X: 0x%X" % (addr + 1, res) - if res != val: - print "ERROR in READ/WRITE 8" - - - print "\r\n\r\n------ TEST READ / WRITE MEMORY BLOCK ------" - data = [randrange(1, 50) for x in range(size)] - target.writeBlockMemoryUnaligned8(addr, data) - block = target.readBlockMemoryUnaligned8(addr, size) - error = False - for i in range(len(block)): - if (block[i] != data[i]): - error = True - print "ERROR: 0x%X, 0x%X, 0x%X!!!" % ((addr + i), block[i], data[i]) - if error: - print "TEST FAILED" - else: - print "TEST PASSED" - - - print "\r\n\r\n------ TEST RESET ------" - target.reset() - sleep(0.1) - target.halt() - - for i in range(5): - target.step() - print "pc: 0x%X" % target.readCoreRegister('pc') - - - print "\r\n\r\n----- FLASH NEW BINARY -----" - flash.flashBinary(binary_file) - - target.reset() - -except Exception as e: - print "Unknown exception: %s" % e - -finally: - if board != None: - board.uninit() \ No newline at end of file diff --git a/workspace_tools/debugger/test/gdb_test.py b/workspace_tools/debugger/test/gdb_test.py deleted file mode 100644 index dd04436fed..0000000000 --- a/workspace_tools/debugger/test/gdb_test.py +++ /dev/null @@ -1,36 +0,0 @@ -""" - mbed CMSIS-DAP debugger - Copyright (c) 2006-2013 ARM Limited - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. -""" - -import logging - -from pyOCD.gdbserver import GDBServer -from pyOCD.board import MbedBoard - -logging.basicConfig(level=logging.INFO) - -try: - board_selected = MbedBoard.chooseBoard() - if board_selected != None: - gdb = GDBServer(board_selected, 3333) - while gdb.isAlive(): - gdb.join(timeout = 0.5) - -except KeyboardInterrupt: - gdb.stop() -except Exception as e: - print "uncaught exception: %s" % e - gdb.stop() \ No newline at end of file diff --git a/workspace_tools/libraries.py b/workspace_tools/libraries.py index 915f80e531..1eca5e1413 100644 --- a/workspace_tools/libraries.py +++ b/workspace_tools/libraries.py @@ -70,16 +70,16 @@ LIBRARIES = [ "id": "eth", "source_dir": [ETH_SOURCES, LWIP_SOURCES], "build_dir": ETH_LIBRARY, - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_SOURCES, LWIP_SOURCES], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES] }, { - "id": "vodafone", - "source_dir": [VODAFONE_SOURCES, LWIP_SOURCES], - "build_dir": VODAFONE_LIBRARY, - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, VODAFONE_SOURCES, LWIP_SOURCES], - "supported": CORTEX_ARM_SUPPORT + "id": "ublox", + "source_dir": [UBLOX_SOURCES, CELLULAR_SOURCES, CELLULAR_USB_SOURCES, LWIP_SOURCES], + "build_dir": UBLOX_LIBRARY, + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES], }, + ] diff --git a/workspace_tools/make.py b/workspace_tools/make.py index 2abca9a22b..9366db922a 100644 --- a/workspace_tools/make.py +++ b/workspace_tools/make.py @@ -48,8 +48,26 @@ if __name__ == '__main__': help="The name of the desired test program") parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False, help="Verbose diagnostic output") - + parser.add_option("-D", "", action="append", dest="macros", + help="Add a macro definition") + # Local run + parser.add_option("--automated", action="store_true", dest="automated", + default=False, help="Automated test") + parser.add_option("--host", dest="host_test", + default=None, help="Host test") + parser.add_option("--extra", dest="extra", + default=None, help="Extra files") + parser.add_option("--peripherals", dest="peripherals", + default=None, help="Required peripherals") + parser.add_option("--dep", dest="dependencies", + default=None, help="Dependencies") + parser.add_option("--source", dest="source_dir", + default=None, help="The source (input) directory") + parser.add_option("--duration", type="int", dest="duration", + default=None, help="Duration of the test") + parser.add_option("--build", dest="build_dir", + default=None, help="The build (output) directory") parser.add_option("-d", "--disk", dest="disk", default=None, help="The mbed disk") parser.add_option("-s", "--serial", dest="serial", @@ -67,9 +85,15 @@ if __name__ == '__main__': default=None, help="use the specified linker script") (options, args) = parser.parse_args() - + + # force program to "0" if a source dir is specified + if options.source_dir is not None: + p = 0 + n = None + else: # Program Number or name - p, n = options.program, options.program_name + p, n = options.program, options.program_name + if n is not None and p is not None: args_error(parser, "[ERROR] specify either '-n' or '-p', not both") if n: @@ -99,6 +123,19 @@ if __name__ == '__main__': # Test test = Test(p) + if options.automated is not None: + test.automated = options.automated + if options.dependencies is not None: + test.dependencies = options.dependencies + if options.host_test is not None: + test.host_test = options.host_test; + if options.peripherals is not None: + test.peripherals = options.peripherals; + if options.duration is not None: + test.duration = options.duration; + if options.extra is not None: + test.extra_files = options.extra + if not test.is_supported(mcu, toolchain): print 'The selected test is not supported on target %s with toolchain %s' % (mcu, toolchain) sys.exit() @@ -108,13 +145,20 @@ if __name__ == '__main__': test.dependencies.append(RTOS_LIBRARIES) build_dir = join(BUILD_DIR, "test", mcu, toolchain, test.id) + if options.source_dir is not None: + test.source_dir = options.source_dir + build_dir = options.source_dir + + if options.build_dir is not None: + build_dir = options.build_dir target = TARGET_MAP[mcu] try: bin = build_project(test.source_dir, build_dir, target, toolchain, test.dependencies, options.options, linker_script=options.linker_script, - clean=options.clean, verbose=options.verbose) + clean=options.clean, verbose=options.verbose, + macros=options.macros) print 'Image: %s' % bin if options.disk: diff --git a/workspace_tools/options.py b/workspace_tools/options.py index 3ffabe8891..8ba8aff9d6 100644 --- a/workspace_tools/options.py +++ b/workspace_tools/options.py @@ -35,6 +35,6 @@ def get_default_options_parser(): help="clean the build directory") parser.add_option("-o", "--options", action="append", - help='Add a build option ("save-asm": save the asm generated by the compiler, "debug-info": generate debugging information)') + help='Add a build option ("save-asm": save the asm generated by the compiler, "debug-info": generate debugging information, "analyze": run static code analyzer")') return parser diff --git a/workspace_tools/paths.py b/workspace_tools/paths.py index 94341a9ba4..57e0e0c95d 100644 --- a/workspace_tools/paths.py +++ b/workspace_tools/paths.py @@ -55,10 +55,14 @@ NET = join(LIB_DIR, "net") ETH_SOURCES = join(NET, "eth") LWIP_SOURCES = join(NET, "lwip") VODAFONE_SOURCES = join(NET, "VodafoneUSBModem") +CELLULAR_SOURCES = join(NET, "cellular", "CellularModem") +CELLULAR_USB_SOURCES = join(NET, "cellular", "CellularUSBModem") +UBLOX_SOURCES = join(NET, "cellular", "UbloxUSBModem") NET_LIBRARIES = join(BUILD_DIR, "net") ETH_LIBRARY = join(NET_LIBRARIES, "eth") VODAFONE_LIBRARY = join(NET_LIBRARIES, "VodafoneUSBModem") +UBLOX_LIBRARY = join(NET_LIBRARIES, "UbloxUSBModem") # FS FS_PATH = join(LIB_DIR, "fs") diff --git a/workspace_tools/settings.py b/workspace_tools/settings.py index 9b6d3e9ce8..738c2a4394 100644 --- a/workspace_tools/settings.py +++ b/workspace_tools/settings.py @@ -68,6 +68,9 @@ IAR_PATH = "C:/Program Files (x86)/IAR Systems/Embedded Workbench 6.0/arm" CW_GCC_PATH = "C:/Freescale/CW MCU v10.3/Cross_Tools/arm-none-eabi-gcc-4_6_2/bin" CW_EWL_PATH = "C:/Freescale/CW MCU v10.3/MCU/ARM_GCC_Support/ewl/lib" +# Goanna static analyzer +GOANNA_PATH = "c:/Program Files (x86)/RedLizards/Goanna Central 3.1.4/bin" + BUILD_OPTIONS = [] ############################################################################## diff --git a/workspace_tools/synch.py b/workspace_tools/synch.py index afe6ae6a02..d3936a5048 100644 --- a/workspace_tools/synch.py +++ b/workspace_tools/synch.py @@ -58,6 +58,12 @@ OFFICIAL_CODE = ( ("USBDevice", "USBDevice"), ("USBHost" , "USBHost"), + + ("CellularModem", "net/cellular/CellularModem"), + ("CellularUSBModem", "net/cellular/CellularUSBModem"), + ("UbloxUSBModem", "net/cellular/UbloxUSBModem"), + ("UbloxModemHTTPClientTest", ["tests/net/cellular/http/common", "tests/net/cellular/http/ubloxusb"]), + ("UbloxModemSMSTest", ["tests/net/cellular/sms/common", "tests/net/cellular/sms/ubloxusb"]), ) @@ -235,7 +241,7 @@ def visit_files(path, visit): visit(join(root, file)) -def update_repo(repo_name, sdk_path): +def update_repo(repo_name, sdk_paths): repo = MbedOfficialRepository(repo_name) # copy files from mbed SDK to mbed_official repository def visit_mbed_sdk(sdk_file): @@ -246,12 +252,16 @@ def update_repo(repo_name, sdk_path): makedirs(repo_dir) copy_with_line_endings(sdk_file, repo_file) - visit_files(sdk_path, visit_mbed_sdk) + for sdk_path in sdk_paths: + visit_files(sdk_path, visit_mbed_sdk) # remove repository files that do not exist in the mbed SDK def visit_repo(repo_file): - sdk_file = join(sdk_path, relpath(repo_file, repo.path)) - if not exists(sdk_file): + for sdk_path in sdk_paths: + sdk_file = join(sdk_path, relpath(repo_file, repo.path)) + if exists(sdk_file): + break + else: remove(repo_file) print "remove: %s" % repo_file visit_files(repo.path, visit_repo) @@ -263,7 +273,8 @@ def update_repo(repo_name, sdk_path): def update_code(repositories): for repo_name, sdk_dir in repositories: print '\n=== Updating "%s" ===' % repo_name - sdk_path = join(LIB_DIR, sdk_dir) + sdk_dirs = [sdk_dir] if type(sdk_dir) != type([]) else sdk_dir + sdk_path = [join(LIB_DIR, d) for d in sdk_dirs] update_repo(repo_name, sdk_path) @@ -285,7 +296,7 @@ def update_dependencies(repositories): def update_mbed(): - update_repo("mbed", join(BUILD_DIR, "mbed")) + update_repo("mbed", [join(BUILD_DIR, "mbed")]) def do_sync(options): global push_remote, quiet, commit_msg, changed diff --git a/workspace_tools/tests.py b/workspace_tools/tests.py index cd4faec329..f649ce4375 100644 --- a/workspace_tools/tests.py +++ b/workspace_tools/tests.py @@ -198,13 +198,7 @@ TESTS = [ "peripherals": ["i2c_loop"] }, { - "id": "MBED_A21", "description": "Interrupt chaining (InterruptIn)", - "source_dir": join(TEST_DIR, "mbed", "interrupt_chaining", "interruptin"), - "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], - "peripherals": ["digital_loop"] - }, - { - "id": "MBED_A22", "description": "Call function before main (mbed_main)", + "id": "MBED_A21", "description": "Call function before main (mbed_main)", "source_dir": join(TEST_DIR, "mbed", "call_before_main"), "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], "automated": True, @@ -382,23 +376,18 @@ TESTS = [ "peripherals": ["ADXL345"] }, { - "id": "MBED_28", "description": "Interrupt chaining (serial)", - "source_dir": join(TEST_DIR, "mbed", "interrupt_chaining", "serial_interrupt"), + "id": "MBED_28", "description": "Interrupt chaining (InterruptManager)", + "source_dir": join(TEST_DIR, "mbed", "interrupt_chaining"), "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], }, { - "id": "MBED_29", "description": "Interrupt chaining (ticker + InterruptManager)", - "source_dir": join(TEST_DIR, "mbed", "interrupt_chaining", "ticker"), - "dependencies": [MBED_LIBRARIES, TEST_MBED_LIB], - }, - { - "id": "MBED_30", "description": "CAN network test", + "id": "MBED_29", "description": "CAN network test", "source_dir": join(TEST_DIR, "mbed", "can"), "dependencies": [MBED_LIBRARIES], "mcu": ["LPC1768", "LPC4088"] }, { - "id": "MBED_31", "description": "CAN network test using interrupts", + "id": "MBED_30", "description": "CAN network test using interrupts", "source_dir": join(TEST_DIR, "mbed", "can_interrupt"), "dependencies": [MBED_LIBRARIES], "mcu": ["LPC1768", "LPC4088"] @@ -565,20 +554,20 @@ TESTS = [ "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, ETH_LIBRARY], }, - # Vodafone tests + # u-blox tests { - "id": "VF_1", "description": "HTTP client", - "source_dir": join(TEST_DIR, "net", "vodafone", "HTTPClient_HelloWorld"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, VODAFONE_LIBRARY, TEST_MBED_LIB], + "id": "UB_1", "description": "u-blox USB modem: HTTP client", + "source_dir": [join(TEST_DIR, "net", "cellular", "http", "ubloxusb"), join(TEST_DIR, "net", "cellular", "http", "common")], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES, UBLOX_LIBRARY], "supported": CORTEX_ARM_SUPPORT, }, { - "id": "VF_2", "description": "USSD & SMS Test", - "source_dir": join(TEST_DIR, "net", "vodafone", "USSD_SMS_HelloWorld"), - "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, VODAFONE_LIBRARY, TEST_MBED_LIB], + "id": "UB_2", "description": "u-blox USB modem: SMS test", + "source_dir": [join(TEST_DIR, "net", "cellular", "sms", "ubloxusb"), join(TEST_DIR, "net", "cellular", "sms", "common")], + "dependencies": [MBED_LIBRARIES, RTOS_LIBRARIES, USB_HOST_LIBRARIES, UBLOX_LIBRARY], "supported": CORTEX_ARM_SUPPORT, }, - + # USB Tests { "id": "USB_1", "description": "Mouse", @@ -690,6 +679,7 @@ GROUPS = { } GROUPS["rtos"] = [test["id"] for test in TESTS if test["id"].startswith("RTOS_")] GROUPS["net"] = [test["id"] for test in TESTS if test["id"].startswith("NET_")] +GROUPS["automated"] = [test["id"] for test in TESTS if test.get("automated", False)] # Look for 'TEST_GROUPS' in private_settings.py and update the GROUPS dictionary # with the information in test_groups if found try: diff --git a/workspace_tools/toolchains/__init__.py b/workspace_tools/toolchains/__init__.py index 352aa1f048..a5ee60d497 100644 --- a/workspace_tools/toolchains/__init__.py +++ b/workspace_tools/toolchains/__init__.py @@ -26,6 +26,7 @@ from workspace_tools.patch import patch from workspace_tools.settings import BUILD_OPTIONS import workspace_tools.hooks as hooks +import re def print_notify(event): # Default command line notification @@ -141,8 +142,11 @@ class mbedToolchain: "Cortex-M0+": ["__CORTEX_M0PLUS", "ARM_MATH_CM0"], "Cortex-M4" : ["__CORTEX_M4", "ARM_MATH_CM4", "__FPU_PRESENT=1"], } - - def __init__(self, target, options=None, notify=None): + + GOANNA_FORMAT = "[Goanna] warning [%FILENAME%:%LINENO%] - [%CHECKNAME%(%SEVERITY%)] %MESSAGE%" + GOANNA_DIAGNOSTIC_PATTERN = re.compile(r'"\[Goanna\] (?Pwarning) \[(?P[^:]+):(?P\d+)\] \- (?P.*)"') + + def __init__(self, target, options=None, notify=None, macros=None): self.target = target self.name = self.__class__.__name__ self.hook = hooks.Hook(target, self) @@ -158,6 +162,7 @@ class mbedToolchain: self.options = [] else: self.options = options + self.macros = macros or [] self.options.extend(BUILD_OPTIONS) if self.options: self.info("Build Options: %s" % (', '.join(self.options))) @@ -168,6 +173,12 @@ class mbedToolchain: self.labels = None self.build_all = False + + def goanna_parse_line(self, line): + if "analyze" in self.options: + return self.GOANNA_DIAGNOSTIC_PATTERN.match(line) + else: + return None def get_symbols(self): if self.symbols is None: @@ -337,7 +348,7 @@ class mbedToolchain: self.progress("compile", source, build_update=True) # Compile - command = cc + ['-D%s' % s for s in self.get_symbols()] + ["-I%s" % i for i in includes] + ["-o", object, source] + command = cc + ['-D%s' % s for s in self.get_symbols() + self.macros] + ["-I%s" % i for i in includes] + ["-o", object, source] if hasattr(self, "get_dep_opt"): command.extend(self.get_dep_opt(dep_path)) diff --git a/workspace_tools/toolchains/arm.py b/workspace_tools/toolchains/arm.py index df265d0f76..5c96c9778b 100644 --- a/workspace_tools/toolchains/arm.py +++ b/workspace_tools/toolchains/arm.py @@ -20,6 +20,7 @@ from os.path import join from workspace_tools.toolchains import mbedToolchain from workspace_tools.settings import ARM_BIN, ARM_INC, ARM_LIB, MY_ARM_CLIB, ARM_CPPLIB from workspace_tools.hooks import hook_tool +from workspace_tools.settings import GOANNA_PATH class ARM(mbedToolchain): LINKER_EXT = '.sct' @@ -29,8 +30,8 @@ class ARM(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)", line (?P\d+): (?PWarning|Error): (?P.+)') DEP_PATTERN = re.compile('\S+:\s(?P.+)\n') - def __init__(self, target, options=None, notify=None): - mbedToolchain.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None): + mbedToolchain.__init__(self, target, options, notify, macros) if target.core == "Cortex-M0+": cpu = "Cortex-M0" @@ -39,7 +40,8 @@ class ARM(mbedToolchain): else: cpu = target.core - common = [join(ARM_BIN, "armcc"), "-c", + main_cc = join(ARM_BIN, "armcc") + common = ["-c", "--cpu=%s" % cpu, "--gnu", "-Ospace", "--split_sections", "--apcs=interwork", "--brief_diagnostics", "--restrict" @@ -56,9 +58,13 @@ class ARM(mbedToolchain): '-I%s' % ARM_INC ] - self.asm = common - self.cc = common + common_c + ["--c99"] - self.cppc = common + common_c + ["--cpp", "--no_rtti"] + self.asm = [main_cc] + common + if not "analyze" in self.options: + self.cc = [main_cc] + common + common_c + ["--c99"] + self.cppc = [main_cc] + common + common_c + ["--cpp", "--no_rtti"] + else: + self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--c99"] + self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cc.replace('\\', '/'), "--dialect=armcc", '--output-format="%s"' % self.GOANNA_FORMAT] + common + common_c + ["--cpp", "--no_rtti"] self.ld = [join(ARM_BIN, "armlink")] self.sys_libs = [] @@ -92,7 +98,15 @@ class ARM(mbedToolchain): match.group('line'), match.group('message') ) - + match = self.goanna_parse_line(line) + if match is not None: + self.cc_info( + match.group('severity').lower(), + match.group('file'), + match.group('line'), + match.group('message') + ) + def archive(self, objects, lib_path): self.default_cmd([self.ar, '-r', lib_path] + objects) @@ -109,16 +123,16 @@ class ARM(mbedToolchain): class ARM_STD(ARM): - def __init__(self, target, options=None, notify=None): - ARM.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None): + ARM.__init__(self, target, options, notify, macros) self.ld.append("--libpath=%s" % ARM_LIB) class ARM_MICRO(ARM): PATCHED_LIBRARY = False - def __init__(self, target, options=None, notify=None): - ARM.__init__(self, target, notify) + def __init__(self, target, options=None, notify=None, macros=None): + ARM.__init__(self, target, options, notify, macros) # Compiler self.asm += ["-D__MICROLIB"] diff --git a/workspace_tools/toolchains/gcc.py b/workspace_tools/toolchains/gcc.py index 014a8ff9e2..b74c1bd638 100644 --- a/workspace_tools/toolchains/gcc.py +++ b/workspace_tools/toolchains/gcc.py @@ -19,7 +19,7 @@ from os.path import join, basename, splitext from workspace_tools.toolchains import mbedToolchain from workspace_tools.settings import GCC_ARM_PATH, GCC_CR_PATH, GCC_CS_PATH, CW_EWL_PATH, CW_GCC_PATH - +from workspace_tools.settings import GOANNA_PATH class GCC(mbedToolchain): LINKER_EXT = '.ld' @@ -29,8 +29,8 @@ class GCC(mbedToolchain): CIRCULAR_DEPENDENCIES = True DIAGNOSTIC_PATTERN = re.compile('((?P\d+):)(\d+:)? (?Pwarning|error): (?P.+)') - def __init__(self, target, options=None, notify=None, tool_path=""): - mbedToolchain.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None, tool_path=""): + mbedToolchain.__init__(self, target, options, notify, macros) if target.core == "Cortex-M0+": cpu = "cortex-m0" @@ -59,11 +59,17 @@ class GCC(mbedToolchain): if "debug-info" in self.options: common_flags.append("-g") - + self.asm = [join(tool_path, "arm-none-eabi-as")] + self.cpu - - self.cc = [join(tool_path, "arm-none-eabi-gcc"), "-std=gnu99"] + common_flags - self.cppc =[join(tool_path, "arm-none-eabi-g++"), "-std=gnu++98"] + common_flags + + main_cc = join(tool_path, "arm-none-eabi-gcc") + main_cppc = join(tool_path, "arm-none-eabi-g++") + if not "analyze" in self.options: + self.cc = [main_cc, "-std=gnu99"] + common_flags + self.cppc =[main_cppc, "-std=gnu++98"] + common_flags + else: + self.cc = [join(GOANNA_PATH, "goannacc"), "--with-cc=" + main_cc.replace('\\', '/'), "-std=gnu99", "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT] + common_flags + self.cppc= [join(GOANNA_PATH, "goannac++"), "--with-cxx=" + main_cppc.replace('\\', '/'), "-std=gnu++98", "--dialect=gnu", '--output-format="%s"' % self.GOANNA_FORMAT] + common_flags self.ld = [join(tool_path, "arm-none-eabi-gcc"), "-Wl,--gc-sections", "-Wl,--wrap,main"] + self.cpu self.sys_libs = ["stdc++", "supc++", "m", "c", "gcc"] @@ -98,6 +104,16 @@ class GCC(mbedToolchain): WHERE, WHAT = 0, 1 state, file, message = WHERE, None, None for line in output.splitlines(): + match = self.goanna_parse_line(line) + if match is not None: + self.cc_info( + match.group('severity').lower(), + match.group('file'), + match.group('line'), + match.group('message') + ) + continue + # Each line should start with the file information: "filepath: ..." # i should point past the file path ^ # avoid the first column in Windows (C:\) @@ -146,8 +162,8 @@ class GCC(mbedToolchain): class GCC_ARM(GCC): - def __init__(self, target, options=None, notify=None): - GCC.__init__(self, target, options, notify, GCC_ARM_PATH) + def __init__(self, target, options=None, notify=None, macros=None): + GCC.__init__(self, target, options, notify, macros, GCC_ARM_PATH) # Use latest gcc nanolib self.ld.append("--specs=nano.specs") @@ -158,8 +174,8 @@ class GCC_ARM(GCC): class GCC_CR(GCC): - def __init__(self, target, options=None, notify=None): - GCC.__init__(self, target, options, notify, GCC_CR_PATH) + def __init__(self, target, options=None, notify=None, macros=None): + GCC.__init__(self, target, options, notify, macros, GCC_CR_PATH) additional_compiler_flags = [ "-D__NEWLIB__", "-D__CODE_RED", "-D__USE_CMSIS", "-DCPP_USE_HEAP", @@ -171,8 +187,8 @@ class GCC_CR(GCC): class GCC_CS(GCC): - def __init__(self, target, options=None, notify=None): - GCC.__init__(self, target, options, notify, GCC_CS_PATH) + def __init__(self, target, options=None, notify=None, macros=None): + GCC.__init__(self, target, options, notify, macros, GCC_CS_PATH) class GCC_CW(GCC): @@ -180,13 +196,13 @@ class GCC_CW(GCC): "Cortex-M0+": "armv6-m", } - def __init__(self, target, options=None, notify=None): - GCC.__init__(self, target, options, notify, CW_GCC_PATH) + def __init__(self, target, options=None, notify=None, macros=None): + GCC.__init__(self, target, options, notify, macros, CW_GCC_PATH) class GCC_CW_EWL(GCC_CW): - def __init__(self, target, options=None, notify=None): - GCC_CW.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None): + GCC_CW.__init__(self, target, options, notify, macros) # Compiler common = [ @@ -214,5 +230,5 @@ class GCC_CW_EWL(GCC_CW): class GCC_CW_NEWLIB(GCC_CW): - def __init__(self, target, options=None, notify=None): - GCC_CW.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None): + GCC_CW.__init__(self, target, options, notify, macros) diff --git a/workspace_tools/toolchains/iar.py b/workspace_tools/toolchains/iar.py index e4816d2f72..f6a6741d84 100644 --- a/workspace_tools/toolchains/iar.py +++ b/workspace_tools/toolchains/iar.py @@ -20,7 +20,7 @@ from os.path import join, exists from workspace_tools.toolchains import mbedToolchain from workspace_tools.settings import IAR_PATH - +from workspace_tools.settings import GOANNA_PATH class IAR(mbedToolchain): LIBRARY_EXT = '.a' @@ -29,8 +29,8 @@ class IAR(mbedToolchain): DIAGNOSTIC_PATTERN = re.compile('"(?P[^"]+)",(?P[\d]+)\s+(?PWarning|Error)(?P.+)') - def __init__(self, target, options=None, notify=None): - mbedToolchain.__init__(self, target, options, notify) + def __init__(self, target, options=None, notify=None, macros=None): + mbedToolchain.__init__(self, target, options, notify, macros) c_flags = [ "-Oh", @@ -49,10 +49,14 @@ class IAR(mbedToolchain): c_flags.append("-r") IAR_BIN = join(IAR_PATH, "bin") + main_cc = join(IAR_BIN, "iccarm") self.asm = [join(IAR_BIN, "iasmarm")] + ["--cpu", target.core] - self.cc = [join(IAR_BIN, "iccarm")] + c_flags - self.cppc = [join(IAR_BIN, "iccarm"), "--c++", "--no_rtti", "--no_exceptions"] + c_flags - + if not "analyze" in self.options: + self.cc = [main_cc] + c_flags + self.cppc = [main_cc, "--c++", "--no_rtti", "--no_exceptions"] + c_flags + else: + self.cc = [join(GOANNA_PATH, "goannacc"), '--with-cc="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + c_flags + self.cppc = [join(GOANNA_PATH, "goannac++"), '--with-cxx="%s"' % main_cc.replace('\\', '/'), "--dialect=iar-arm", '--output-format="%s"' % self.GOANNA_FORMAT] + ["--c++", "--no_rtti", "--no_exceptions"] + c_flags self.ld = join(IAR_BIN, "ilinkarm") self.ar = join(IAR_BIN, "iarchive") self.elf2bin = join(IAR_BIN, "ielftool") @@ -67,6 +71,14 @@ class IAR(mbedToolchain): match.group('line'), match.group('message'), ) + match = self.goanna_parse_line(line) + if match is not None: + self.cc_info( + match.group('severity').lower(), + match.group('file'), + match.group('line'), + match.group('message') + ) def get_dep_opt(self, dep_path): return ["--dependencies", dep_path]