├── MuraxArduino.zip ├── README.md ├── firmware └── QSPIanalog │ └── QSPIanalog.ino ├── fpga └── Blackice │ ├── bin │ └── toplevel.bin │ └── toplevel.pcf ├── hardware └── fpga │ └── f32c │ ├── cores │ └── f32c │ │ ├── Arduino.h │ │ ├── Client.h │ │ ├── HardwareSerial.h │ │ ├── IPAddress.cpp │ │ ├── IPAddress.h │ │ ├── Print.cpp │ │ ├── Print.h │ │ ├── Printable.h │ │ ├── Server.h │ │ ├── Stream.cpp │ │ ├── Stream.h │ │ ├── Tone.cpp │ │ ├── UARTClass.cpp │ │ ├── UARTClass.h │ │ ├── Udp.h │ │ ├── WCharacter.h │ │ ├── WInterrupts.c │ │ ├── WInterrupts.h │ │ ├── WMath.cpp │ │ ├── WMath.h │ │ ├── WString.cpp │ │ ├── WString.h │ │ ├── abi.cpp │ │ ├── avr │ │ ├── dtostrf.h │ │ └── pgmspace.h │ │ ├── binary.h │ │ ├── dtostrf.c │ │ ├── hooks.c │ │ ├── itoa.c │ │ ├── itoa.h │ │ ├── main.cpp │ │ ├── new.cpp │ │ ├── wiring.c │ │ ├── wiring.h │ │ ├── wiring_analog.c │ │ ├── wiring_analog.h │ │ ├── wiring_constants.h │ │ ├── wiring_digital.c │ │ ├── wiring_digital.h │ │ ├── wiring_private.h │ │ ├── wiring_pulse.cpp │ │ ├── wiring_pulse.h │ │ ├── wiring_shift.c │ │ └── wiring_shift.h │ ├── programmers.txt │ ├── system │ ├── include │ │ ├── assert.h │ │ ├── complex.h │ │ ├── ctype.h │ │ ├── dev │ │ │ └── sio.h │ │ ├── errno.h │ │ ├── fatfs │ │ │ ├── diskio.h │ │ │ ├── ff.h │ │ │ ├── ffconf.h │ │ │ └── integer.h │ │ ├── fcntl.h │ │ ├── float.h │ │ ├── inttypes.h │ │ ├── limits.h │ │ ├── math.h │ │ ├── mips │ │ │ ├── _fpmath.h │ │ │ ├── _limits.h │ │ │ ├── _types.h │ │ │ ├── endian.h │ │ │ └── setjmp.h │ │ ├── riscv │ │ │ └── io.h │ │ ├── setjmp.h │ │ ├── stdarg.h │ │ ├── stdbool.h │ │ ├── stddef.h │ │ ├── stdint.h │ │ ├── stdio.h │ │ ├── stdlib.h │ │ ├── string.h │ │ ├── strings.h │ │ ├── sys │ │ │ ├── _null.h │ │ │ ├── _sigset.h │ │ │ ├── _timespec.h │ │ │ ├── _timeval.h │ │ │ ├── _types.h │ │ │ ├── cdefs.h │ │ │ ├── elf32.h │ │ │ ├── elf_common.h │ │ │ ├── endian.h │ │ │ ├── errno.h │ │ │ ├── fcntl.h │ │ │ ├── isr.h │ │ │ ├── limits.h │ │ │ ├── null.h │ │ │ ├── param.h │ │ │ ├── queue.h │ │ │ ├── select.h │ │ │ ├── signal.h │ │ │ ├── stat.h │ │ │ ├── stdint.h │ │ │ ├── time.h │ │ │ ├── timespec.h │ │ │ └── types.h │ │ ├── time.h │ │ └── unistd.h │ ├── riscv │ │ └── lib │ │ │ ├── libc.a │ │ │ ├── libcrt0.a │ │ │ └── libm.a │ └── src │ │ ├── Makefile │ │ ├── assert.c │ │ ├── atoi.c │ │ ├── div.c │ │ ├── div64.c │ │ ├── float │ │ ├── CREDITS.TXT │ │ ├── LICENSE.TXT │ │ ├── adddf3.c │ │ ├── addsf3.c │ │ ├── ashldi3.c │ │ ├── clzdi2.c │ │ ├── clzsi2.c │ │ ├── comparedf2.c │ │ ├── comparesf2.c │ │ ├── divdf3.c │ │ ├── divsf3.c │ │ ├── extendsfdf2.c │ │ ├── fixdfsi.c │ │ ├── fixsfsi.c │ │ ├── fixunsdfdi.c │ │ ├── fixunsdfsi.c │ │ ├── fixunssfsi.c │ │ ├── floatdisf.c │ │ ├── floatsidf.c │ │ ├── floatsisf.c │ │ ├── floatundidf.c │ │ ├── floatundisf.c │ │ ├── floatunsidf.c │ │ ├── floatunsisf.c │ │ ├── fp_lib.h │ │ ├── int_endianness.h │ │ ├── int_lib.h │ │ ├── int_types.h │ │ ├── int_util.h │ │ ├── lshrdi3.c │ │ ├── muldf3.c │ │ ├── mulsf3.c │ │ ├── negdf2.c │ │ ├── negsf2.c │ │ ├── subdf3.c │ │ ├── subsf3.c │ │ └── truncdfsf2.c │ │ ├── gets.c │ │ ├── malloc.c │ │ ├── math │ │ ├── acos.c │ │ ├── acosf.c │ │ ├── acosh.c │ │ ├── acoshf.c │ │ ├── asin.c │ │ ├── asinf.c │ │ ├── asinh.c │ │ ├── asinhf.c │ │ ├── atan.c │ │ ├── atan2.c │ │ ├── atan2f.c │ │ ├── atanf.c │ │ ├── atanh.c │ │ ├── atanhf.c │ │ ├── ceil.c │ │ ├── ceilf.c │ │ ├── copysignf.c │ │ ├── cos.c │ │ ├── cosf.c │ │ ├── cosh.c │ │ ├── coshf.c │ │ ├── erf.c │ │ ├── erff.c │ │ ├── exp.c │ │ ├── expf.c │ │ ├── expm1.c │ │ ├── expm1f.c │ │ ├── fabs.c │ │ ├── fabsf.c │ │ ├── floor.c │ │ ├── floorf.c │ │ ├── fmod.c │ │ ├── fmodf.c │ │ ├── fpmath.h │ │ ├── frexp.c │ │ ├── frexpf.c │ │ ├── isfinite.c │ │ ├── isinf.c │ │ ├── isnan.c │ │ ├── k_log.h │ │ ├── k_logf.h │ │ ├── log.c │ │ ├── log10.c │ │ ├── log10f.c │ │ ├── log1p.c │ │ ├── log1pf.c │ │ ├── log2.c │ │ ├── log2f.c │ │ ├── logf.c │ │ ├── math_private.h │ │ ├── modf.c │ │ ├── modff.c │ │ ├── pow.c │ │ ├── powf.c │ │ ├── scalbn.c │ │ ├── scalbnf.c │ │ ├── sin.c │ │ ├── sinf.c │ │ ├── sinh.c │ │ ├── sinhf.c │ │ ├── sqrt.c │ │ ├── sqrtf.c │ │ ├── tan.c │ │ ├── tanf.c │ │ ├── tanh.c │ │ └── tanhf.c │ │ ├── memcmp.c │ │ ├── memcpy.c │ │ ├── memmove.c │ │ ├── memset.c │ │ ├── mul.c │ │ ├── post.mk │ │ ├── printf.c │ │ ├── qsort.c │ │ ├── random.c │ │ ├── riscv │ │ └── start.S │ │ ├── sprintf.c │ │ ├── strcasecmp.c │ │ ├── strcpy.c │ │ ├── strncpy.c │ │ ├── strrchr.c │ │ ├── strstr.c │ │ └── strtol.c │ ├── tools │ └── boards-manager │ │ ├── boards.txt │ │ ├── mkjson.sh │ │ ├── packbm.sh │ │ └── platform.txt │ └── variants │ ├── blackice │ ├── config.txt │ ├── dev │ │ └── io.h │ ├── pins_arduino.h │ └── variant.h │ ├── generic │ ├── config.txt │ ├── dev │ │ └── io.h │ ├── pins_arduino.h │ └── variant.h │ └── test │ ├── config.txt │ ├── dev │ └── io.h │ ├── pins_arduino.h │ ├── toplevel.bin │ └── variant.h ├── libraries ├── EEPROM │ ├── EEPROM.cpp │ └── EEPROM.h ├── Firmata │ ├── .gitignore │ ├── Boards.h │ ├── Firmata.cpp │ ├── Firmata.h │ ├── FirmataConstants.h │ ├── FirmataDefines.h │ ├── FirmataMarshaller.cpp │ ├── FirmataMarshaller.h │ ├── FirmataParser.cpp │ ├── FirmataParser.h │ ├── LICENSE.txt │ ├── examples │ │ ├── AllInputsFirmata │ │ │ └── AllInputsFirmata.ino │ │ ├── AnalogFirmata │ │ │ └── AnalogFirmata.ino │ │ ├── EchoString │ │ │ └── EchoString.ino │ │ ├── OldStandardFirmata │ │ │ ├── LICENSE.txt │ │ │ └── OldStandardFirmata.ino │ │ ├── ServoFirmata │ │ │ └── ServoFirmata.ino │ │ ├── SimpleAnalogFirmata │ │ │ └── SimpleAnalogFirmata.ino │ │ ├── SimpleDigitalFirmata │ │ │ └── SimpleDigitalFirmata.ino │ │ ├── StandardFirmata │ │ │ ├── LICENSE.txt │ │ │ └── StandardFirmata.ino │ │ ├── StandardFirmataBLE │ │ │ ├── LICENSE.txt │ │ │ ├── StandardFirmataBLE.ino │ │ │ └── bleConfig.h │ │ ├── StandardFirmataChipKIT │ │ │ ├── LICENSE.txt │ │ │ └── StandardFirmataChipKIT.ino │ │ ├── StandardFirmataEthernet │ │ │ ├── LICENSE.txt │ │ │ ├── StandardFirmataEthernet.ino │ │ │ └── ethernetConfig.h │ │ ├── StandardFirmataPlus │ │ │ ├── LICENSE.txt │ │ │ └── StandardFirmataPlus.ino │ │ └── StandardFirmataWiFi │ │ │ ├── LICENSE.txt │ │ │ ├── StandardFirmataWiFi.ino │ │ │ └── wifiConfig.h │ ├── extras │ │ └── revisions.txt │ ├── keywords.txt │ ├── library.properties │ ├── readme.md │ ├── release.sh │ ├── test │ │ ├── firmata_test │ │ │ └── firmata_test.ino │ │ └── readme.md │ └── utility │ │ ├── BLEStream.cpp │ │ ├── BLEStream.h │ │ ├── EthernetClientStream.cpp │ │ ├── EthernetClientStream.h │ │ ├── FirmataFeature.h │ │ ├── SerialFirmata.cpp │ │ ├── SerialFirmata.h │ │ ├── WiFiClientStream.h │ │ ├── WiFiServerStream.h │ │ ├── WiFiStream.cpp │ │ ├── WiFiStream.h │ │ └── firmataDebug.h ├── LedStrip │ ├── LedStrip.cpp │ ├── LedStrip.h │ └── examples │ │ └── LedStripTest │ │ └── LedStripTest.ino ├── MsTimer2 │ ├── MsTimer2.cpp │ ├── MsTimer2.h │ └── examples │ │ └── FlashLed │ │ └── FlashLed.ino ├── Mux │ ├── Mux.cpp │ └── Mux.h ├── Quadrature │ ├── Quadrature.cpp │ ├── Quadrature.h │ └── examples │ │ └── Quadtest │ │ └── Quadtest.ino ├── SD │ ├── README.adoc │ ├── examples │ │ ├── CardInfo │ │ │ └── CardInfo.ino │ │ ├── Datalogger │ │ │ └── Datalogger.ino │ │ ├── DumpFile │ │ │ └── DumpFile.ino │ │ ├── Files │ │ │ └── Files.ino │ │ ├── ReadWrite │ │ │ └── ReadWrite.ino │ │ └── listfiles │ │ │ └── listfiles.ino │ ├── keywords.txt │ ├── library.properties │ └── src │ │ ├── File.cpp │ │ ├── README.txt │ │ ├── SD.cpp │ │ ├── SD.h │ │ └── utility │ │ ├── FatStructs.h │ │ ├── Sd2Card.cpp │ │ ├── Sd2Card.h │ │ ├── Sd2PinMap.h │ │ ├── SdFat.h │ │ ├── SdFatUtil.h │ │ ├── SdFatmainpage.h │ │ ├── SdFile.cpp │ │ ├── SdInfo.h │ │ ├── SdVolume.cpp │ │ └── dirty_workaround.h ├── SPI │ ├── SPI.cpp │ ├── SPI.h │ ├── examples │ │ ├── BarometricPressureSensor │ │ │ ├── BarometricPressureSensor.ino │ │ │ └── BarometricPressureSensor │ │ │ │ └── BarometricPressureSensor.ino │ │ └── DigitalPotControl │ │ │ └── DigitalPotControl.ino │ └── keywords.txt ├── Servo │ ├── Servo.cpp │ ├── Servo.h │ └── examples │ │ ├── Knob │ │ └── Knob.ino │ │ └── Sweep │ │ └── Sweep.ino ├── SevenSegment │ ├── SevenSegment.cpp │ └── SevenSegment.h └── Wire │ ├── Wire.cpp │ ├── Wire.h │ ├── examples │ ├── SFRRanger_reader │ │ └── SFRRanger_reader.ino │ ├── digital_potentiometer │ │ └── digital_potentiometer.ino │ ├── master_reader │ │ └── master_reader.ino │ ├── master_writer │ │ └── master_writer.ino │ ├── slave_receiver │ │ └── slave_receiver.ino │ └── slave_sender │ │ └── slave_sender.ino │ └── keywords.txt └── package_murax_core_index.json /MuraxArduino.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/MuraxArduino.zip -------------------------------------------------------------------------------- /firmware/QSPIanalog/QSPIanalog.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Iceboot plus send analog values over QSPI 3 | */ 4 | 5 | #include 6 | #include 7 | 8 | static bool debug = false; 9 | 10 | void setup() { 11 | pinMode(LED_BUILTIN, OUTPUT); 12 | QSPI.begin(5000000, QSPI.Mode3); 13 | Serial.begin(9600); 14 | // configure the FPGA 15 | digitalWrite(LED_BUILTIN, 1); 16 | myStorm.FPGAConfigure((const byte*)0x0801F000, 135100); 17 | digitalWrite(LED_BUILTIN, 0); 18 | QSPI.beginTransaction(); 19 | } 20 | 21 | void loop() { 22 | short analog; 23 | short response; 24 | 25 | // Send 6 analog values to ice40 using QSPI 26 | for(int i=0;i<8;i++) { 27 | analog = (i == 0 ? 0xAAAA : i == 7 ? 0x0000 : analogRead(A0 + i - 1)); 28 | if (debug) { 29 | Serial.print("Sending A"); 30 | Serial.print(i); 31 | Serial.print(": "); 32 | Serial.println(analog, HEX); 33 | } 34 | response = 0; 35 | for(int j=0;j<2;j++) { 36 | if (!QSPI.write(((byte *) &analog) + j, 1)) 37 | Serial.println("QSPI.transmit failed"); 38 | if (!QSPI.read(((byte *) &response) + j, 1)) 39 | Serial.println("QSPI.receive failed"); 40 | } 41 | if (debug) { 42 | Serial.print("Received: "); 43 | Serial.println(response, HEX); 44 | if (response != analog) { 45 | Serial.print("*** ERROR: sent: "); 46 | Serial.print(analog, HEX); 47 | Serial.print(" received: "); 48 | Serial.println(response, HEX); 49 | } 50 | } 51 | //delay(1); 52 | } 53 | 54 | // Check for bitstream 55 | if (!Serial.available()) return; 56 | 57 | digitalWrite(LED_BUILTIN, 1); 58 | if (myStorm.FPGAConfigure(Serial)) { 59 | while (Serial.available()) 60 | Serial.read(); 61 | } 62 | digitalWrite(LED_BUILTIN, 0); 63 | 64 | } 65 | -------------------------------------------------------------------------------- /fpga/Blackice/bin/toplevel.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/fpga/Blackice/bin/toplevel.bin -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/Client.h: -------------------------------------------------------------------------------- 1 | /* 2 | Client.h - Base class that provides Client 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef client_h 21 | #define client_h 22 | #include "Print.h" 23 | #include "Stream.h" 24 | #include "IPAddress.h" 25 | 26 | class Client : public Stream { 27 | 28 | public: 29 | virtual int connect(IPAddress ip, uint16_t port) =0; 30 | virtual int connect(const char *host, uint16_t port) =0; 31 | virtual size_t write(uint8_t) =0; 32 | virtual size_t write(const uint8_t *buf, size_t size) =0; 33 | virtual int available() = 0; 34 | virtual int read() = 0; 35 | virtual int read(uint8_t *buf, size_t size) = 0; 36 | virtual int peek() = 0; 37 | virtual void flush() = 0; 38 | virtual void stop() = 0; 39 | virtual uint8_t connected() = 0; 40 | virtual operator bool() = 0; 41 | protected: 42 | uint8_t* rawIPAddress(IPAddress& addr) { return addr.raw_address(); }; 43 | }; 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/HardwareSerial.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef HardwareSerial_h 20 | #define HardwareSerial_h 21 | 22 | #include 23 | 24 | #include "Stream.h" 25 | 26 | class HardwareSerial : public Stream 27 | { 28 | public: 29 | virtual void begin(unsigned long); 30 | virtual void end(); 31 | virtual int available(void) = 0; 32 | virtual int peek(void) = 0; 33 | virtual int read(void) = 0; 34 | virtual void flush(void) = 0; 35 | virtual size_t write(uint8_t) = 0; 36 | using Print::write; // pull in write(str) and write(buf, size) from Print 37 | virtual operator bool() = 0; 38 | }; 39 | 40 | extern void serialEventRun(void) __attribute__((weak)); 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/Printable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Printable.h - Interface class that allows printing of complex types 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef Printable_h 21 | #define Printable_h 22 | 23 | #include 24 | 25 | class Print; 26 | 27 | /** The Printable class provides a way for new classes to allow themselves to be printed. 28 | By deriving from Printable and implementing the printTo method, it will then be possible 29 | for users to print out instances of this class by passing them into the usual 30 | Print::print and Print::println methods. 31 | */ 32 | 33 | class Printable 34 | { 35 | public: 36 | virtual size_t printTo(Print& p) const = 0; 37 | }; 38 | 39 | #endif 40 | 41 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/Server.h: -------------------------------------------------------------------------------- 1 | /* 2 | Server.h - Base class that provides Server 3 | Copyright (c) 2011 Adrian McEwen. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #ifndef server_h 21 | #define server_h 22 | 23 | #include "Print.h" 24 | 25 | class Server : public Print { 26 | public: 27 | virtual void begin() =0; 28 | }; 29 | 30 | #endif 31 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/Tone.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | void tone(uint8_t _pin, unsigned int frequency, unsigned long duration) 4 | { 5 | pinMode(TONE_PIN, OUTPUT); // Make Tone pin output 6 | (*(volatile uint32_t *) IO_MUX) |= (1 << TONE_MUX); // Switch on Tone mux 7 | (*(volatile uint32_t *) IO_TONE_PERIOD) = 1000000 / frequency; 8 | (*(volatile uint32_t *) IO_TONE_DURATION) = duration; 9 | } 10 | 11 | void noTone(uint8_t _pin) 12 | { 13 | (*(volatile uint32_t *) IO_TONE_DURATION) = 0; 14 | (*(volatile uint32_t *) IO_MUX) &= ~(1 << TONE_MUX); // Switch off tone mux 15 | } 16 | 17 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/WInterrupts.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include "wiring_private.h" 4 | 5 | __BEGIN_DECLS 6 | 7 | void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode) { 8 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_MASKS) = 0xFFFFFFFF; 9 | (*(volatile uint32_t*)(IO_PIN_INTERRUPT_ADDR + (pin << 2))) = (uint32_t) callback; 10 | 11 | if (mode == RISING || mode == CHANGE) { 12 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_RISING) |= (1 << pin); 13 | } 14 | 15 | if (mode == FALLING || mode == CHANGE) { 16 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_FALLING) |= (1 << pin); 17 | } 18 | } 19 | 20 | void detachInterrupt(uint32_t pin) { 21 | (*(volatile uint32_t*)(IO_PIN_INTERRUPT_ADDR + (pin << 2))) = 0; 22 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_RISING) &= ~(1 << pin); 23 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_FALLING) &= ~(1 << pin); 24 | } 25 | 26 | static uint32_t old_timer_masks; 27 | 28 | void interrupts(void) { 29 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_MASKS) = 0xFFFFFFFF; 30 | (*(volatile uint32_t*)IO_TIMER_INTERRUPT_MASKS) = old_timer_masks; 31 | } 32 | 33 | void noInterrupts(void) { 34 | old_timer_masks = (*(volatile uint32_t*)IO_TIMER_INTERRUPT_MASKS); 35 | (*(volatile uint32_t*)IO_PIN_INTERRUPT_MASKS) = 0; 36 | (*(volatile uint32_t*)IO_TIMER_INTERRUPT_MASKS) = 0; 37 | } 38 | 39 | 40 | __END_DECLS 41 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/WInterrupts.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011-2012 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_INTERRUPTS_ 20 | #define _WIRING_INTERRUPTS_ 21 | 22 | #include "Arduino.h" 23 | 24 | __BEGIN_DECLS 25 | 26 | struct variant_icp_control_s 27 | { 28 | uint32_t control_and; // first and'ed to preserve bits 29 | uint32_t control_or; // last or'ed to set bits that enable this timer 30 | uint32_t control_and_or;// 1-use and logic, 0-use or logic 31 | uint32_t apply; 32 | uint8_t icp_start; 33 | uint8_t icp_stop; 34 | uint32_t icp_ie; 35 | uint32_t icp_if; 36 | uint8_t icp_register; 37 | }; 38 | 39 | extern const struct variant_icp_control_s variant_icp_control[]; 40 | 41 | extern int timerInterval; 42 | void attachInterrupt(uint32_t pin, void (*callback)(void), uint32_t mode); 43 | void detachInterrupt(uint32_t pin); 44 | void icpFilter(uint32_t pin, uint32_t icp_start, uint32_t icp_stop); 45 | 46 | void interrupts(void); 47 | void noInterrupts(void); 48 | 49 | #ifdef __riscv 50 | #define __enable_irq() 51 | #define __disable_irq() 52 | #endif // __riscv 53 | 54 | __END_DECLS 55 | 56 | #endif /* _WIRING_INTERRUPTS_ */ 57 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/WMath.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | extern "C" { 20 | #include "stdlib.h" 21 | #include "stdint.h" 22 | } 23 | #include "WMath.h" 24 | 25 | extern void randomSeed( uint32_t dwSeed ) 26 | { 27 | if ( dwSeed != 0 ) 28 | { 29 | srand( dwSeed ) ; 30 | } 31 | } 32 | 33 | extern long random( long howbig ) 34 | { 35 | if ( howbig == 0 ) 36 | { 37 | return 0 ; 38 | } 39 | 40 | return rand() % howbig; 41 | } 42 | 43 | extern long random( long howsmall, long howbig ) 44 | { 45 | if (howsmall >= howbig) 46 | { 47 | return howsmall; 48 | } 49 | 50 | long diff = howbig - howsmall; 51 | 52 | return random(diff) + howsmall; 53 | } 54 | 55 | extern long map(long x, long in_min, long in_max, long out_min, long out_max) 56 | { 57 | return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; 58 | } 59 | 60 | extern uint16_t makeWord( uint16_t w ) 61 | { 62 | return w ; 63 | } 64 | 65 | extern uint16_t makeWord( uint8_t h, uint8_t l ) 66 | { 67 | return (h << 8) | l ; 68 | } 69 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/WMath.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_MATH_ 20 | #define _WIRING_MATH_ 21 | 22 | extern long random( long ) ; 23 | extern long random( long, long ) ; 24 | extern void randomSeed( uint32_t dwSeed ) ; 25 | extern long map( long, long, long, long, long ) ; 26 | 27 | extern uint16_t makeWord( uint16_t w ) ; 28 | extern uint16_t makeWord( uint8_t h, uint8_t l ) ; 29 | 30 | #define word(...) makeWord(__VA_ARGS__) 31 | 32 | 33 | #endif /* _WIRING_MATH_ */ 34 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/abi.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | extern "C" void __cxa_pure_virtual(void) __attribute__ ((__noreturn__)); 22 | extern "C" void __cxa_deleted_virtual(void) __attribute__ ((__noreturn__)); 23 | 24 | void __cxa_pure_virtual(void) { 25 | // We might want to write some diagnostics to uart in this case 26 | //std::terminate(); 27 | while (1) 28 | ; 29 | } 30 | 31 | void __cxa_deleted_virtual(void) { 32 | // We might want to write some diagnostics to uart in this case 33 | //std::terminate(); 34 | while (1) 35 | ; 36 | } 37 | 38 | // EMARD: I'm not sure is "abi.cpp" right place, 39 | // but for compilation of some libraries like MIDI Library from Forty Seven Effects 40 | // it will fix errors like: 41 | // Callbacks.ino.cpp:(.text.startup._GLOBAL__sub_I_MIDI+0xb4): undefined reference to `__dso_handle' 42 | // Callbacks.ino.cpp:(.text.startup._GLOBAL__sub_I_MIDI+0xbc): undefined reference to `__cxa_atexit' 43 | __BEGIN_DECLS 44 | void *__dso_handle = (void*) &__dso_handle; 45 | int __cxa_atexit(void (_destructor) (void *), void *arg, void *dso) { return (0);} 46 | __END_DECLS; 47 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/avr/dtostrf.h: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | Lesser General Public License for more details. 12 | You should have received a copy of the GNU Lesser General Public 13 | License along with this library; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | */ 16 | 17 | #pragma once 18 | 19 | #ifdef __cplusplus 20 | extern "C" { 21 | #endif 22 | 23 | char *dtostrf(double val, signed char width, unsigned char prec, char *sout); 24 | 25 | #ifdef __cplusplus 26 | } 27 | #endif 28 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/avr/pgmspace.h: -------------------------------------------------------------------------------- 1 | #ifndef __PGMSPACE_H_ 2 | #define __PGMSPACE_H_ 1 3 | 4 | #include 5 | 6 | #define PROGMEM 7 | #define PGM_P const char * 8 | #define PSTR(str) (str) 9 | 10 | #define _SFR_BYTE(n) (n) 11 | 12 | typedef void prog_void; 13 | typedef char prog_char; 14 | typedef unsigned char prog_uchar; 15 | typedef int8_t prog_int8_t; 16 | typedef uint8_t prog_uint8_t; 17 | typedef int16_t prog_int16_t; 18 | typedef uint16_t prog_uint16_t; 19 | typedef int32_t prog_int32_t; 20 | typedef uint32_t prog_uint32_t; 21 | 22 | #define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) 23 | #define strcpy_P(dest, src) strcpy((dest), (src)) 24 | #define strcat_P(dest, src) strcat((dest), (src)) 25 | #define strcmp_P(a, b) strcmp((a), (b)) 26 | #define strstr_P(a, b) strstr((a), (b)) 27 | #define strlen_P(a) strlen((a)) 28 | #define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) 29 | 30 | #define pgm_read_byte(addr) (*(const unsigned char *)(addr)) 31 | #define pgm_read_word(addr) (*(const unsigned short *)(addr)) 32 | #define pgm_read_dword(addr) (*(const unsigned long *)(addr)) 33 | #define pgm_read_float(addr) (*(const float *)(addr)) 34 | 35 | #define pgm_read_byte_near(addr) pgm_read_byte(addr) 36 | #define pgm_read_word_near(addr) pgm_read_word(addr) 37 | #define pgm_read_dword_near(addr) pgm_read_dword(addr) 38 | #define pgm_read_float_near(addr) pgm_read_float(addr) 39 | #define pgm_read_byte_far(addr) pgm_read_byte(addr) 40 | #define pgm_read_word_far(addr) pgm_read_word(addr) 41 | #define pgm_read_dword_far(addr) pgm_read_dword(addr) 42 | #define pgm_read_float_far(addr) pgm_read_float(addr) 43 | 44 | #endif 45 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/dtostrf.c: -------------------------------------------------------------------------------- 1 | /* 2 | dtostrf - Emulation for dtostrf function from avr-libc 3 | Copyright (c) 2015 Arduino LLC. All rights reserved. 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | This library is distributed in the hope that it will be useful, 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 | Lesser General Public License for more details. 12 | You should have received a copy of the GNU Lesser General Public 13 | License along with this library; if not, write to the Free Software 14 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 15 | */ 16 | 17 | #include 18 | 19 | char *dtostrf (double val, signed char width, unsigned char prec, char *sout) { 20 | asm(".global _printf_float"); 21 | 22 | char fmt[20]; 23 | sprintf(fmt, "%%%d.%df", width, prec); 24 | sprintf(sout, fmt, val); 25 | return sout; 26 | } 27 | 28 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/hooks.c: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2012 Arduino. All right reserved. 3 | This library is free software; you can redistribute it and/or 4 | modify it under the terms of the GNU Lesser General Public 5 | License as published by the Free Software Foundation; either 6 | version 2.1 of the License, or (at your option) any later version. 7 | This library is distributed in the hope that it will be useful, 8 | but WITHOUT ANY WARRANTY; without even the implied warranty of 9 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 10 | See the GNU Lesser General Public License for more details. 11 | You should have received a copy of the GNU Lesser General Public 12 | License along with this library; if not, write to the Free Software 13 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 14 | */ 15 | 16 | /** 17 | * Empty yield() hook. 18 | * 19 | * This function is intended to be used by library writers to build 20 | * libraries or sketches that supports cooperative threads. 21 | * 22 | * Its defined as a weak symbol and it can be redefined to implement a 23 | * real cooperative scheduler. 24 | */ 25 | static void __empty() { 26 | // Empty 27 | } 28 | void yield(void) __attribute__ ((weak, alias("__empty"))); 29 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/itoa.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _ITOA_ 20 | #define _ITOA_ 21 | 22 | __BEGIN_DECLS 23 | 24 | #if 0 25 | 26 | extern void itoa( int n, char s[] ) ; 27 | 28 | #else 29 | 30 | extern char* itoa( int value, char *string, int radix ) ; 31 | extern char* ltoa( long value, char *string, int radix ) ; 32 | extern char* utoa( unsigned long value, char *string, int radix ) ; 33 | extern char* ultoa( unsigned long value, char *string, int radix ) ; 34 | #endif /* 0 */ 35 | 36 | __END_DECLS 37 | 38 | #endif // _ITOA_ 39 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/main.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | main.cpp - Main loop for Arduino sketches 3 | Copyright (c) 2005-2013 Arduino Team. All right reserved. 4 | 5 | This library is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU Lesser General Public 7 | License as published by the Free Software Foundation; either 8 | version 2.1 of the License, or (at your option) any later version. 9 | 10 | This library is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 13 | Lesser General Public License for more details. 14 | 15 | You should have received a copy of the GNU Lesser General Public 16 | License along with this library; if not, write to the Free Software 17 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 18 | */ 19 | 20 | #define ARDUINO_MAIN 21 | #include "Arduino.h" 22 | 23 | /* 24 | * \brief Main entry point of Arduino application 25 | */ 26 | int main( void ) 27 | { 28 | setup(); 29 | 30 | do { 31 | loop(); 32 | if (serialEventRun) 33 | serialEventRun(); 34 | } while (1); 35 | 36 | return 0; 37 | } 38 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/new.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2014 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include 20 | 21 | void *operator new(size_t size) { 22 | return malloc(size); 23 | } 24 | 25 | void *operator new[](size_t size) { 26 | return malloc(size); 27 | } 28 | 29 | void operator delete(void * ptr) { 30 | free(ptr); 31 | } 32 | 33 | void operator delete[](void * ptr) { 34 | free(ptr); 35 | } 36 | 37 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_analog.c: -------------------------------------------------------------------------------- 1 | /* EMARD */ 2 | 3 | #include "Arduino.h" 4 | #include "wiring_analog.h" 5 | #include 6 | 7 | __BEGIN_DECLS 8 | 9 | static uint8_t analog_write_resolution_bits = 8; 10 | /* old arduino uses 490 Hz */ 11 | /* new arduino uses 980 Hz */ 12 | static uint32_t analog_write_frequency = 980; 13 | 14 | /* todo: support analogWriteResolution(bits) 15 | ** default is 8 for old arduino, 16 | ** new arduino can use up to 12 17 | */ 18 | void analogWriteResolution(int res) 19 | { 20 | analog_write_resolution_bits = res; 21 | } 22 | 23 | void analogWriteFrequency(int freq) 24 | { 25 | analog_write_frequency = freq; 26 | } 27 | 28 | void analogWritePhase(uint32_t pin, uint32_t phase) 29 | { 30 | } 31 | 32 | /* setup the common parameters (why isn't it called at startup?) 33 | */ 34 | void analogOutputInit( void ) 35 | { 36 | } 37 | 38 | void analogWrite(uint32_t ulPin, uint32_t ulValue) 39 | { 40 | if (PWM_PINS[ulPin] >= 0) pinMode(PWM_PINS[ulPin], OUTPUT); 41 | (*(volatile uint32_t *)IO_MUX) |= (1 << (ulPin + PWM_MUX)); 42 | (*(volatile uint32_t *) (IO_PWM_DUTY + (ulPin << 2))) = ulValue; 43 | } 44 | 45 | void analogReference( eAnalogReference ulMode ) 46 | { 47 | } 48 | 49 | uint32_t analogRead(uint32_t ulPin) 50 | { 51 | return (*(volatile uint32_t *) (IO_ANALOG + ((ulPin - A0) << 2))); 52 | } 53 | 54 | /* input capture setting */ 55 | uint32_t setInputCapture(uint32_t ulPin) 56 | { 57 | return 0; 58 | } 59 | 60 | __END_DECLS 61 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_digital.c: -------------------------------------------------------------------------------- 1 | /* 2 | * ULX2S board GPIO & hardwired pins 3 | */ 4 | 5 | #include "Arduino.h" 6 | #include "wiring_analog.h" // this is needed to turn off pwm 7 | #include 8 | 9 | __BEGIN_DECLS 10 | 11 | void 12 | pinMode(uint32_t pin, uint32_t mode) 13 | { 14 | volatile uint32_t *port = (volatile uint32_t *) (pin < 32 ? IO_GPIO_A_CTL : IO_GPIO_B_CTL); 15 | 16 | if (pin >= variant_pin_map_size || 17 | (digitalPinToPort(pin) != IO_GPIO_A_DATA && digitalPinToPort(pin) != IO_GPIO_B_DATA)) 18 | return; 19 | 20 | switch (mode) { 21 | case INPUT_PULLUP: 22 | *port &= ~(1<= variant_pin_map_size) 40 | return; 41 | 42 | port = (PortRegister_t)digitalPinToPort(pin); 43 | 44 | if (val) 45 | *port |= (1<= variant_pin_map_size) 57 | return 0; 58 | 59 | port = (PortRegister_t)digitalPinToPortIn(pin); 60 | return ((*port & (1< 33 | #include 34 | 35 | typedef void (*voidFuncPtr)(void); 36 | 37 | __END_DECLS 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_pulse.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #include "Arduino.h" 20 | //#include "wiring_private.h" 21 | 22 | 23 | /* Measures the length (in microseconds) of a pulse on the pin; state is HIGH 24 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 25 | * to 3 minutes in length, but must be called at least a few dozen microseconds 26 | * before the start of the pulse. */ 27 | extern uint32_t 28 | pulseIn(uint32_t pin, bool state, uint32_t timeout) 29 | { 30 | uint32_t index = pin * 4; // 4 words per channel 31 | 32 | pinMode(PULSE_IN_PINS[pin], INPUT); 33 | 34 | ((volatile uint32_t *)IO_PULSE_IN_TIMEOUT)[index] = timeout; 35 | ((volatile uint32_t *)IO_PULSE_IN_VALUE)[index] = state; 36 | 37 | uint32_t pulse; 38 | 39 | for(int i=0;i<100000;i++) { 40 | pulse = ((volatile uint32_t *)IO_PULSE_IN_LENGTH)[index]; 41 | if (pulse != 0) return pulse; 42 | } 43 | 44 | return 0; 45 | } 46 | 47 | extern uint32_t 48 | pulseInLong(uint32_t pin, bool state, uint32_t timeout) 49 | { 50 | return pulseIn(pin, state, timeout); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_pulse.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_PULSE_ 20 | #define _WIRING_PULSE_ 21 | 22 | __BEGIN_DECLS 23 | 24 | /* 25 | * \brief Measures the length (in microseconds) of a pulse on the pin; state is HIGH 26 | * or LOW, the type of pulse to measure. Works on pulses from 2-3 microseconds 27 | * to 3 minutes in length, but must be called at least a few dozen microseconds 28 | * before the start of the pulse. 29 | */ 30 | extern uint32_t pulseIn(uint32_t ulPin, bool ulState, uint32_t ulTimeout = 1000000L); 31 | extern uint32_t pulseInLong(uint32_t ulPin, bool ulState, uint32_t ulTimeout = 1000000L); 32 | 33 | __END_DECLS 34 | 35 | #endif /* _WIRING_PULSE_ */ 36 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_shift.c: -------------------------------------------------------------------------------- 1 | /* 2 | wiring_shift.c - shiftOut() function 3 | Part of Arduino - http://www.arduino.cc/ 4 | 5 | Copyright (c) 2005-2006 David A. Mellis 6 | 7 | This library is free software; you can redistribute it and/or 8 | modify it under the terms of the GNU Lesser General Public 9 | License as published by the Free Software Foundation; either 10 | version 2.1 of the License, or (at your option) any later version. 11 | 12 | This library is distributed in the hope that it will be useful, 13 | but WITHOUT ANY WARRANTY; without even the implied warranty of 14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 15 | Lesser General Public License for more details. 16 | 17 | You should have received a copy of the GNU Lesser General 18 | Public License along with this library; if not, write to the 19 | Free Software Foundation, Inc., 59 Temple Place, Suite 330, 20 | Boston, MA 02111-1307 USA 21 | 22 | $Id: wiring.c 248 2007-02-03 15:36:30Z mellis $ 23 | */ 24 | 25 | #include "Arduino.h" 26 | uint8_t shiftIn(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder) { 27 | (*(volatile uint32_t*) IO_MUX) |= (1 << SHIFT_IN_MUX); // Switch clock pin to shiftIn peripheral 28 | pinMode(SHIFT_IN_CLOCK_PIN, OUTPUT); 29 | pinMode(SHIFT_IN_DATA_PIN, INPUT); 30 | (*(volatile uint32_t*) IO_SHIFT_IN_PRE_SCALE) = 50; 31 | (*(volatile uint32_t*) IO_SHIFT_IN_BIT_ORDER) = bitOrder; 32 | delayMicroseconds(100); 33 | return (*(volatile uint32_t*) IO_SHIFT_IN_BYTE_VALUE); 34 | } 35 | 36 | void shiftOut(uint8_t dataPin, uint8_t clockPin, uint8_t bitOrder, uint8_t val) 37 | { 38 | (*(volatile uint32_t*) IO_MUX) |= (1 << SHIFT_OUT_MUX); // Switch clock and data pins to shiftOut peripheral 39 | pinMode(SHIFT_OUT_CLOCK_PIN, OUTPUT); 40 | pinMode(SHIFT_OUT_DATA_PIN, OUTPUT); 41 | (*(volatile uint32_t*) IO_SHIFT_OUT_PRE_SCALE) = 1000; 42 | (*(volatile uint32_t*) IO_SHIFT_OUT_BIT_ORDER) = bitOrder; 43 | (*(volatile uint32_t*) IO_SHIFT_OUT_BYTE_VALUE) = val; 44 | } 45 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/cores/f32c/wiring_shift.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (c) 2011 Arduino. All right reserved. 3 | 4 | This library is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU Lesser General Public 6 | License as published by the Free Software Foundation; either 7 | version 2.1 of the License, or (at your option) any later version. 8 | 9 | This library is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | See the GNU Lesser General Public License for more details. 13 | 14 | You should have received a copy of the GNU Lesser General Public 15 | License along with this library; if not, write to the Free Software 16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 17 | */ 18 | 19 | #ifndef _WIRING_SHIFT_ 20 | #define _WIRING_SHIFT_ 21 | 22 | __BEGIN_DECLS 23 | /* 24 | * \brief 25 | */ 26 | extern uint8_t shiftIn( uint8_t ulDataPin, uint8_t ulClockPin, uint8_t ulBitOrder ) ; 27 | 28 | 29 | /* 30 | * \brief 31 | */ 32 | extern void shiftOut( uint8_t ulDataPin, uint8_t ulClockPin, uint8_t ulBitOrder, uint8_t ulVal ) ; 33 | 34 | __END_DECLS 35 | 36 | #endif /* _WIRING_SHIFT_ */ 37 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/programmers.txt: -------------------------------------------------------------------------------- 1 | ujprog.name=ujprog (FPGArduino) 2 | ujprog.communication=usb 3 | ujprog.protocol=ujprog 4 | ujprog.program.protocol=ujprog 5 | ujprog.program.tool=ujprog 6 | ujprog.program.extra_params= 7 | ujprog.bootloader.tool=ujprog 8 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/dev/sio.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | #ifndef _SIO_H_ 29 | #define _SIO_H_ 30 | 31 | extern void (*sio_idle_fn)(void); 32 | 33 | int sio_getchar(int); 34 | int sio_putchar(int, int); 35 | void sio_setbaud(int); 36 | 37 | #endif /* !_IO_H_ */ 38 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/fatfs/integer.h: -------------------------------------------------------------------------------- 1 | /*-------------------------------------------*/ 2 | /* Integer type definitions for FatFs module */ 3 | /*-------------------------------------------*/ 4 | 5 | #ifndef _INTEGER 6 | #define _INTEGER 7 | 8 | #ifdef _WIN32 /* FatFs development platform */ 9 | 10 | #include 11 | #include 12 | 13 | #else /* Embedded platform */ 14 | 15 | /* These types must be 16-bit, 32-bit or larger integer */ 16 | typedef int INT; 17 | typedef unsigned int UINT; 18 | 19 | /* These types must be 8-bit integer */ 20 | typedef char CHAR; 21 | typedef unsigned char UCHAR; 22 | typedef unsigned char BYTE; 23 | 24 | /* These types must be 16-bit integer */ 25 | typedef short SHORT; 26 | typedef unsigned short USHORT; 27 | typedef unsigned short WORD; 28 | typedef unsigned short WCHAR; 29 | 30 | /* These types must be 32-bit integer */ 31 | typedef long LONG; 32 | typedef unsigned long ULONG; 33 | typedef unsigned long DWORD; 34 | 35 | #endif 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/mips/_fpmath.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2002, 2003 David Schultz 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: stable/9/lib/libc/mips/_fpmath.h 178580 2008-04-26 12:08:02Z imp $ 27 | */ 28 | 29 | union IEEEl2bits { 30 | long double e; 31 | struct { 32 | #ifndef __MIPSEB__ 33 | unsigned int manl :32; 34 | unsigned int manh :20; 35 | unsigned int exp :11; 36 | unsigned int sign :1; 37 | #else 38 | unsigned int sign :1; 39 | unsigned int exp :11; 40 | unsigned int manh :20; 41 | unsigned int manl :32; 42 | #endif 43 | } bits; 44 | }; 45 | 46 | #define LDBL_NBIT 0 47 | #define mask_nbit_l(u) ((void)0) 48 | #define LDBL_IMPLICIT_NBIT 49 | 50 | #define LDBL_MANH_SIZE 20 51 | #define LDBL_MANL_SIZE 32 52 | 53 | #define LDBL_TO_ARRAY32(u, a) do { \ 54 | (a)[0] = (uint32_t)(u).bits.manl; \ 55 | (a)[1] = (uint32_t)(u).bits.manh; \ 56 | } while(0) 57 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/stdarg.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | #ifndef _STDARG_H_ 29 | #define _STDARG_H_ 30 | 31 | /* va_arg stuff */ 32 | typedef __builtin_va_list __va_list; 33 | typedef __va_list va_list; 34 | #define va_start(ap, last) __builtin_va_start((ap), (last)) 35 | #define va_arg(ap, type) __builtin_va_arg((ap), type) 36 | #define va_copy(dest, src) __builtin_va_copy((dest), (src)) 37 | #define va_end(ap) __builtin_va_end(ap) 38 | 39 | #endif /* !_STDARG_H_ */ 40 | 41 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/stdbool.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2000 Jeroen Ruigrok van der Werven 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: stable/9/include/stdbool.h 229285 2012-01-02 16:14:52Z mdf $ 27 | */ 28 | 29 | #ifndef _STDBOOL_H_ 30 | #define _STDBOOL_H_ 31 | 32 | #ifndef __bool_true_false_are_defined 33 | #define __bool_true_false_are_defined 1 34 | 35 | #ifndef __cplusplus 36 | 37 | #define false 0 38 | #define true 1 39 | 40 | #define bool _Bool 41 | #if __STDC_VERSION__ < 199901L && __GNUC__ < 3 && !defined(__INTEL_COMPILER) 42 | typedef int _Bool; 43 | #endif 44 | 45 | #endif /* !__cplusplus */ 46 | #endif /* __bool_true_false_are_defined */ 47 | 48 | #endif /* !_STDBOOL_H_ */ 49 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/strings.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | #ifndef _STRINGS_H_ 29 | #define _STRINGS_H_ 30 | 31 | int strcasecmp(const char *, const char *) __pure; 32 | int strncasecmp(const char *, const char *, size_t) __pure; 33 | 34 | #endif /* _STRINGS_H_ */ 35 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/_null.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003 Marcel Moolenaar 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * $FreeBSD: f32c/src/include/sys/_null.h 907 2012-02-14 21:18:19Z marko $ 27 | */ 28 | 29 | #ifndef NULL 30 | 31 | #if !defined(__cplusplus) 32 | #define NULL ((void *)0) 33 | #else 34 | #if defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 35 | #define NULL __null 36 | #else 37 | #if defined(__LP64__) 38 | #define NULL (0L) 39 | #else 40 | #define NULL 0 41 | #endif /* __LP64__ */ 42 | #endif /* __GNUG__ */ 43 | #endif /* !__cplusplus */ 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/_timespec.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1982, 1986, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 4. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | * 29 | * @(#)time.h 8.5 (Berkeley) 5/4/95 30 | * from: FreeBSD: src/sys/sys/time.h,v 1.43 2000/03/20 14:09:05 phk Exp 31 | * $FreeBSD: stable/9/sys/sys/_timespec.h 205792 2010-03-28 13:13:22Z ed $ 32 | */ 33 | 34 | #ifndef _SYS__TIMESPEC_H_ 35 | #define _SYS__TIMESPEC_H_ 36 | 37 | #include 38 | 39 | #ifndef _TIME_T_DECLARED 40 | typedef __time_t time_t; 41 | #define _TIME_T_DECLARED 42 | #endif 43 | 44 | struct timespec { 45 | time_t tv_sec; /* seconds */ 46 | long tv_nsec; /* and nanoseconds */ 47 | }; 48 | 49 | #endif /* !_SYS__TIMESPEC_H_ */ 50 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/_timeval.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2002 Mike Barcroft 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: stable/9/sys/sys/_timeval.h 158471 2006-05-12 05:04:46Z jhb $ 27 | */ 28 | 29 | #ifndef _SYS__TIMEVAL_H_ 30 | #define _SYS__TIMEVAL_H_ 31 | 32 | #include 33 | 34 | #ifndef _SUSECONDS_T_DECLARED 35 | typedef __suseconds_t suseconds_t; 36 | #define _SUSECONDS_T_DECLARED 37 | #endif 38 | 39 | #ifndef _TIME_T_DECLARED 40 | typedef __time_t time_t; 41 | #define _TIME_T_DECLARED 42 | #endif 43 | 44 | /* 45 | * Structure returned by gettimeofday(2) system call, and used in other calls. 46 | */ 47 | struct timeval { 48 | time_t tv_sec; /* seconds */ 49 | suseconds_t tv_usec; /* and microseconds */ 50 | }; 51 | 52 | #endif /* !_SYS__TIMEVAL_H_ */ 53 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/endian.h: -------------------------------------------------------------------------------- 1 | 2 | #include 3 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/isr.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2014 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | #ifndef _SYS_ISR_H_ 29 | #define _SYS_ISR_H_ 30 | 31 | #include 32 | 33 | typedef int isr_handler_fn(void); 34 | 35 | struct isr_link { 36 | SLIST_ENTRY(isr_link) isr_le; 37 | isr_handler_fn *handler_fn; 38 | }; 39 | 40 | 41 | void isr_register_handler(int, struct isr_link *); 42 | void isr_remove_handler(int, struct isr_link *); 43 | void enable_irq(int); 44 | void disable_irq(int); 45 | 46 | #endif /* !_SYS_ISR_H_ */ 47 | 48 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/include/sys/null.h: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2003 Marcel Moolenaar 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 16 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 17 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 18 | * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 19 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 20 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 21 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 22 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 23 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 24 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 25 | * 26 | * $FreeBSD: f32c/src/include/sys/null.h 907 2012-02-14 21:18:19Z marko $ 27 | */ 28 | 29 | #ifndef NULL 30 | 31 | #if !defined(__cplusplus) 32 | #define NULL ((void *)0) 33 | #else 34 | #if defined(__GNUG__) && defined(__GNUC__) && __GNUC__ >= 4 35 | #define NULL __null 36 | #else 37 | #if defined(__LP64__) 38 | #define NULL (0L) 39 | #else 40 | #define NULL 0 41 | #endif /* __LP64__ */ 42 | #endif /* __GNUG__ */ 43 | #endif /* !__cplusplus */ 44 | 45 | #endif 46 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/riscv/lib/libc.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/hardware/fpga/f32c/system/riscv/lib/libc.a -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/riscv/lib/libcrt0.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/hardware/fpga/f32c/system/riscv/lib/libcrt0.a -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/riscv/lib/libm.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/hardware/fpga/f32c/system/riscv/lib/libm.a -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/assert.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1992, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 4. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | #include 32 | #include 33 | 34 | void 35 | __assert(const char *func, const char *file, int line, const char *failedexpr) 36 | { 37 | if (func == NULL) 38 | printf("Assertion failed: (%s), file %s, line %d.\n", 39 | failedexpr, file, line); 40 | else 41 | printf( 42 | "Assertion failed: (%s), function %s, file %s, line %d.\n", 43 | failedexpr, func, file, line); 44 | exit(0); 45 | /* NOTREACHED */ 46 | } 47 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/atoi.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | __attribute__((optimize("-Os"))) int 29 | atoi(const char *c) 30 | { 31 | int i = 0; 32 | int sign = 1; 33 | 34 | if (*c == '-') { 35 | sign = -1; 36 | c++; 37 | } 38 | for (; *c != '\0'; c++) { 39 | if (*c >= '0' && *c <= '9') 40 | i = i * 10 + (*c - '0'); 41 | else 42 | break; 43 | } 44 | 45 | return (sign * i); 46 | } 47 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/CREDITS.TXT: -------------------------------------------------------------------------------- 1 | This file is a partial list of people who have contributed to the LLVM/CompilerRT 2 | project. If you have contributed a patch or made some other contribution to 3 | LLVM/CompilerRT, please submit a patch to this file to add yourself, and it will be 4 | done! 5 | 6 | The list is sorted by surname and formatted to allow easy grepping and 7 | beautification by scripts. The fields are: name (N), email (E), web-address 8 | (W), PGP key ID and fingerprint (P), description (D), and snail-mail address 9 | (S). 10 | 11 | N: Craig van Vliet 12 | E: cvanvliet@auroraux.org 13 | W: http://www.auroraux.org 14 | D: Code style and Readability fixes. 15 | 16 | N: Edward O'Callaghan 17 | E: eocallaghan@auroraux.org 18 | W: http://www.auroraux.org 19 | D: CMake'ify Compiler-RT build system 20 | D: Maintain Solaris & AuroraUX ports of Compiler-RT 21 | 22 | N: Howard Hinnant 23 | E: hhinnant@apple.com 24 | D: Architect and primary author of compiler-rt 25 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/LICENSE.TXT: -------------------------------------------------------------------------------- 1 | 2 | Copyright (c) 2009-2012 by the contributors listed in CREDITS.TXT 3 | 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in 12 | all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20 | THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/ashldi3.c: -------------------------------------------------------------------------------- 1 | /* ====-- ashldi3.c - Implement __ashldi3 -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __ashldi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: a << b */ 18 | 19 | /* Precondition: 0 <= b < bits_in_dword */ 20 | 21 | ARM_EABI_FNALIAS(llsl, ashldi3); 22 | 23 | COMPILER_RT_ABI di_int 24 | __ashldi3(di_int a, si_int b) 25 | { 26 | const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); 27 | dwords input; 28 | dwords result; 29 | input.all = a; 30 | if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ 31 | { 32 | result.s.low = 0; 33 | result.s.high = input.s.low << (b - bits_in_word); 34 | } 35 | else /* 0 <= b < bits_in_word */ 36 | { 37 | if (b == 0) 38 | return a; 39 | result.s.low = input.s.low << b; 40 | result.s.high = (input.s.high << b) | (input.s.low >> (bits_in_word - b)); 41 | } 42 | return result.all; 43 | } 44 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/clzdi2.c: -------------------------------------------------------------------------------- 1 | /* ===-- clzdi2.c - Implement __clzdi2 -------------------------------------=== 2 | * 3 | * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4 | * See https://llvm.org/LICENSE.txt for license information. 5 | * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6 | * 7 | * ===----------------------------------------------------------------------=== 8 | * 9 | * This file implements __clzdi2 for the compiler_rt library. 10 | * 11 | * ===----------------------------------------------------------------------=== 12 | */ 13 | 14 | #include "int_lib.h" 15 | 16 | /* Returns: the number of leading 0-bits */ 17 | 18 | #if !defined(__clang__) && \ 19 | ((defined(__sparc__) && defined(__arch64__)) || \ 20 | defined(__mips64) || \ 21 | (defined(__riscv) && __SIZEOF_POINTER__ >= 8)) 22 | /* On 64-bit architectures with neither a native clz instruction nor a native 23 | * ctz instruction, gcc resolves __builtin_clz to __clzdi2 rather than 24 | * __clzsi2, leading to infinite recursion. */ 25 | #define __builtin_clz(a) __clzsi2(a) 26 | extern si_int __clzsi2(si_int); 27 | #endif 28 | 29 | /* Precondition: a != 0 */ 30 | 31 | COMPILER_RT_ABI si_int 32 | __clzdi2(di_int a) 33 | { 34 | dwords x; 35 | x.all = a; 36 | const si_int f = -(x.s.high == 0); 37 | return __builtin_clz((x.s.high & ~f) | (x.s.low & f)) + 38 | (f & ((si_int)(sizeof(si_int) * CHAR_BIT))); 39 | } 40 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/clzsi2.c: -------------------------------------------------------------------------------- 1 | /* ===-- clzsi2.c - Implement __clzsi2 -------------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __clzsi2 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: the number of leading 0-bits */ 18 | 19 | /* Precondition: a != 0 */ 20 | 21 | COMPILER_RT_ABI si_int 22 | __clzsi2(si_int a) 23 | { 24 | su_int x = (su_int)a; 25 | si_int t = ((x & 0xFFFF0000) == 0) << 4; /* if (x is small) t = 16 else 0 */ 26 | x >>= 16 - t; /* x = [0 - 0xFFFF] */ 27 | su_int r = t; /* r = [0, 16] */ 28 | /* return r + clz(x) */ 29 | t = ((x & 0xFF00) == 0) << 3; 30 | x >>= 8 - t; /* x = [0 - 0xFF] */ 31 | r += t; /* r = [0, 8, 16, 24] */ 32 | /* return r + clz(x) */ 33 | t = ((x & 0xF0) == 0) << 2; 34 | x >>= 4 - t; /* x = [0 - 0xF] */ 35 | r += t; /* r = [0, 4, 8, 12, 16, 20, 24, 28] */ 36 | /* return r + clz(x) */ 37 | t = ((x & 0xC) == 0) << 1; 38 | x >>= 2 - t; /* x = [0 - 3] */ 39 | r += t; /* r = [0 - 30] and is even */ 40 | /* return r + clz(x) */ 41 | /* switch (x) 42 | * { 43 | * case 0: 44 | * return r + 2; 45 | * case 1: 46 | * return r + 1; 47 | * case 2: 48 | * case 3: 49 | * return r; 50 | * } 51 | */ 52 | return r + ((2 - x) & -((x & 2) == 0)); 53 | } 54 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/fixdfsi.c: -------------------------------------------------------------------------------- 1 | //===-- lib/fixdfsi.c - Double-precision -> integer conversion ----*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements double-precision to integer conversion for the 11 | // compiler-rt library. No range checking is performed; the behavior of this 12 | // conversion is undefined for out of range values in the C standard. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define DOUBLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | #include "int_lib.h" 20 | 21 | ARM_EABI_FNALIAS(d2iz, fixdfsi); 22 | 23 | int __fixdfsi(fp_t a) { 24 | 25 | // Break a into sign, exponent, significand 26 | const rep_t aRep = toRep(a); 27 | const rep_t aAbs = aRep & absMask; 28 | const int sign = aRep & signBit ? -1 : 1; 29 | const int exponent = (aAbs >> significandBits) - exponentBias; 30 | const rep_t significand = (aAbs & significandMask) | implicitBit; 31 | 32 | // If 0 < exponent < significandBits, right shift to get the result. 33 | if ((unsigned int)exponent < significandBits) { 34 | return sign * (significand >> (significandBits - exponent)); 35 | } 36 | 37 | // If exponent is negative, the result is zero. 38 | else if (exponent < 0) { 39 | return 0; 40 | } 41 | 42 | // If significandBits < exponent, left shift to get the result. This shift 43 | // may end up being larger than the type width, which incurs undefined 44 | // behavior, but the conversion itself is undefined in that case, so 45 | // whatever the compiler decides to do is fine. 46 | else { 47 | return sign * (significand << (exponent - significandBits)); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/fixsfsi.c: -------------------------------------------------------------------------------- 1 | //===-- lib/fixsfsi.c - Single-precision -> integer conversion ----*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements single-precision to integer conversion for the 11 | // compiler-rt library. No range checking is performed; the behavior of this 12 | // conversion is undefined for out of range values in the C standard. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define SINGLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | ARM_EABI_FNALIAS(f2iz, fixsfsi); 20 | 21 | COMPILER_RT_ABI int 22 | __fixsfsi(fp_t a) { 23 | // Break a into sign, exponent, significand 24 | const rep_t aRep = toRep(a); 25 | const rep_t aAbs = aRep & absMask; 26 | const int sign = aRep & signBit ? -1 : 1; 27 | const int exponent = (aAbs >> significandBits) - exponentBias; 28 | const rep_t significand = (aAbs & significandMask) | implicitBit; 29 | 30 | // If 0 < exponent < significandBits, right shift to get the result. 31 | if ((unsigned int)exponent < significandBits) { 32 | return sign * (significand >> (significandBits - exponent)); 33 | } 34 | 35 | // If exponent is negative, the result is zero. 36 | else if (exponent < 0) { 37 | return 0; 38 | } 39 | 40 | // If significandBits < exponent, left shift to get the result. This shift 41 | // may end up being larger than the type width, which incurs undefined 42 | // behavior, but the conversion itself is undefined in that case, so 43 | // whatever the compiler decides to do is fine. 44 | else { 45 | return sign * (significand << (exponent - significandBits)); 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/fixunsdfdi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunsdfdi.c - Implement __fixunsdfdi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __fixunsdfdi for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: convert a to a unsigned long long, rounding toward zero. 18 | * Negative values all become zero. 19 | */ 20 | 21 | /* Assumption: double is a IEEE 64 bit floating point type 22 | * du_int is a 64 bit integral type 23 | * value in double is representable in du_int or is negative 24 | * (no range checking performed) 25 | */ 26 | 27 | /* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */ 28 | 29 | ARM_EABI_FNALIAS(d2ulz, fixunsdfdi); 30 | 31 | COMPILER_RT_ABI du_int 32 | __fixunsdfdi(double a) 33 | { 34 | double_bits fb; 35 | fb.f = a; 36 | int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023; 37 | if (e < 0 || (fb.u.s.high & 0x80000000)) 38 | return 0; 39 | udwords r; 40 | r.s.high = (fb.u.s.high & 0x000FFFFF) | 0x00100000; 41 | r.s.low = fb.u.s.low; 42 | if (e > 52) 43 | r.all <<= (e - 52); 44 | else 45 | r.all >>= (52 - e); 46 | return r.all; 47 | } 48 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/fixunsdfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunsdfsi.c - Implement __fixunsdfsi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __fixunsdfsi for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: convert a to a unsigned int, rounding toward zero. 18 | * Negative values all become zero. 19 | */ 20 | 21 | /* Assumption: double is a IEEE 64 bit floating point type 22 | * su_int is a 32 bit integral type 23 | * value in double is representable in su_int or is negative 24 | * (no range checking performed) 25 | */ 26 | 27 | /* seee eeee eeee mmmm mmmm mmmm mmmm mmmm | mmmm mmmm mmmm mmmm mmmm mmmm mmmm mmmm */ 28 | 29 | ARM_EABI_FNALIAS(d2uiz, fixunsdfsi); 30 | 31 | COMPILER_RT_ABI su_int 32 | __fixunsdfsi(double a) 33 | { 34 | double_bits fb; 35 | fb.f = a; 36 | int e = ((fb.u.s.high & 0x7FF00000) >> 20) - 1023; 37 | if (e < 0 || (fb.u.s.high & 0x80000000)) 38 | return 0; 39 | return ( 40 | 0x80000000u | 41 | ((fb.u.s.high & 0x000FFFFF) << 11) | 42 | (fb.u.s.low >> 21) 43 | ) >> (31 - e); 44 | } 45 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/fixunssfsi.c: -------------------------------------------------------------------------------- 1 | /* ===-- fixunssfsi.c - Implement __fixunssfsi -----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __fixunssfsi for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: convert a to a unsigned int, rounding toward zero. 18 | * Negative values all become zero. 19 | */ 20 | 21 | /* Assumption: float is a IEEE 32 bit floating point type 22 | * su_int is a 32 bit integral type 23 | * value in float is representable in su_int or is negative 24 | * (no range checking performed) 25 | */ 26 | 27 | /* seee eeee emmm mmmm mmmm mmmm mmmm mmmm */ 28 | 29 | ARM_EABI_FNALIAS(f2uiz, fixunssfsi); 30 | 31 | COMPILER_RT_ABI su_int 32 | __fixunssfsi(float a) 33 | { 34 | float_bits fb; 35 | fb.f = a; 36 | int e = ((fb.u & 0x7F800000) >> 23) - 127; 37 | if (e < 0 || (fb.u & 0x80000000)) 38 | return 0; 39 | su_int r = (fb.u & 0x007FFFFF) | 0x00800000; 40 | if (e > 23) 41 | r <<= (e - 23); 42 | else 43 | r >>= (23 - e); 44 | return r; 45 | } 46 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/floatsidf.c: -------------------------------------------------------------------------------- 1 | //===-- lib/floatsidf.c - integer -> double-precision conversion --*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements integer to double-precision conversion for the 11 | // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12 | // mode. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define DOUBLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | #include "int_lib.h" 20 | 21 | ARM_EABI_FNALIAS(i2d, floatsidf); 22 | 23 | fp_t __floatsidf(int a) { 24 | 25 | const int aWidth = sizeof a * CHAR_BIT; 26 | 27 | // Handle zero as a special case to protect clz 28 | if (a == 0) 29 | return fromRep(0); 30 | 31 | // All other cases begin by extracting the sign and absolute value of a 32 | rep_t sign = 0; 33 | if (a < 0) { 34 | sign = signBit; 35 | a = -a; 36 | } 37 | 38 | // Exponent of (fp_t)a is the width of abs(a). 39 | const int exponent = (aWidth - 1) - __builtin_clz(a); 40 | rep_t result; 41 | 42 | // Shift a into the significand field and clear the implicit bit. Extra 43 | // cast to unsigned int is necessary to get the correct behavior for 44 | // the input INT_MIN. 45 | const int shift = significandBits - exponent; 46 | result = (rep_t)(unsigned int)a << shift ^ implicitBit; 47 | 48 | // Insert the exponent 49 | result += (rep_t)(exponent + exponentBias) << significandBits; 50 | // Insert the sign bit and return 51 | return fromRep(result | sign); 52 | } 53 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/floatsisf.c: -------------------------------------------------------------------------------- 1 | //===-- lib/floatsisf.c - integer -> single-precision conversion --*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements integer to single-precision conversion for the 11 | // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12 | // mode. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define SINGLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | #include "int_lib.h" 20 | 21 | ARM_EABI_FNALIAS(i2f, floatsisf); 22 | 23 | fp_t __floatsisf(int a) { 24 | 25 | const int aWidth = sizeof a * CHAR_BIT; 26 | 27 | // Handle zero as a special case to protect clz 28 | if (a == 0) 29 | return fromRep(0); 30 | 31 | // All other cases begin by extracting the sign and absolute value of a 32 | rep_t sign = 0; 33 | if (a < 0) { 34 | sign = signBit; 35 | a = -a; 36 | } 37 | 38 | // Exponent of (fp_t)a is the width of abs(a). 39 | const int exponent = (aWidth - 1) - __builtin_clz(a); 40 | rep_t result; 41 | 42 | // Shift a into the significand field, rounding if it is a right-shift 43 | if (exponent <= significandBits) { 44 | const int shift = significandBits - exponent; 45 | result = (rep_t)a << shift ^ implicitBit; 46 | } else { 47 | const int shift = exponent - significandBits; 48 | result = (rep_t)a >> shift ^ implicitBit; 49 | rep_t round = (rep_t)a << (typeWidth - shift); 50 | if (round > signBit) result++; 51 | if (round == signBit) result += result & 1; 52 | } 53 | 54 | // Insert the exponent 55 | result += (rep_t)(exponent + exponentBias) << significandBits; 56 | // Insert the sign bit and return 57 | return fromRep(result | sign); 58 | } 59 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/floatunsidf.c: -------------------------------------------------------------------------------- 1 | //===-- lib/floatunsidf.c - uint -> double-precision conversion ---*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements unsigned integer to double-precision conversion for the 11 | // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12 | // mode. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define DOUBLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | #include "int_lib.h" 20 | 21 | ARM_EABI_FNALIAS(ui2d, floatunsidf); 22 | 23 | fp_t __floatunsidf(unsigned int a) { 24 | 25 | const int aWidth = sizeof a * CHAR_BIT; 26 | 27 | // Handle zero as a special case to protect clz 28 | if (a == 0) return fromRep(0); 29 | 30 | // Exponent of (fp_t)a is the width of abs(a). 31 | const int exponent = (aWidth - 1) - __builtin_clz(a); 32 | rep_t result; 33 | 34 | // Shift a into the significand field and clear the implicit bit. 35 | const int shift = significandBits - exponent; 36 | result = (rep_t)a << shift ^ implicitBit; 37 | 38 | // Insert the exponent 39 | result += (rep_t)(exponent + exponentBias) << significandBits; 40 | return fromRep(result); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/floatunsisf.c: -------------------------------------------------------------------------------- 1 | //===-- lib/floatunsisf.c - uint -> single-precision conversion ---*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements unsigned integer to single-precision conversion for the 11 | // compiler-rt library in the IEEE-754 default round-to-nearest, ties-to-even 12 | // mode. 13 | // 14 | //===----------------------------------------------------------------------===// 15 | 16 | #define SINGLE_PRECISION 17 | #include "fp_lib.h" 18 | 19 | #include "int_lib.h" 20 | 21 | ARM_EABI_FNALIAS(ui2f, floatunsisf); 22 | 23 | fp_t __floatunsisf(unsigned int a) { 24 | 25 | const int aWidth = sizeof a * CHAR_BIT; 26 | 27 | // Handle zero as a special case to protect clz 28 | if (a == 0) return fromRep(0); 29 | 30 | // Exponent of (fp_t)a is the width of abs(a). 31 | const int exponent = (aWidth - 1) - __builtin_clz(a); 32 | rep_t result; 33 | 34 | // Shift a into the significand field, rounding if it is a right-shift 35 | if (exponent <= significandBits) { 36 | const int shift = significandBits - exponent; 37 | result = (rep_t)a << shift ^ implicitBit; 38 | } else { 39 | const int shift = exponent - significandBits; 40 | result = (rep_t)a >> shift ^ implicitBit; 41 | rep_t round = (rep_t)a << (typeWidth - shift); 42 | if (round > signBit) result++; 43 | if (round == signBit) result += result & 1; 44 | } 45 | 46 | // Insert the exponent 47 | result += (rep_t)(exponent + exponentBias) << significandBits; 48 | return fromRep(result); 49 | } 50 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/int_util.h: -------------------------------------------------------------------------------- 1 | /* ===-- int_util.h - internal utility functions ----------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===-----------------------------------------------------------------------=== 9 | * 10 | * This file is not part of the interface of this library. 11 | * 12 | * This file defines non-inline utilities which are available for use in the 13 | * library. The function definitions themselves are all contained in int_util.c 14 | * which will always be compiled into any compiler-rt library. 15 | * 16 | * ===-----------------------------------------------------------------------=== 17 | */ 18 | 19 | #ifndef INT_UTIL_H 20 | #define INT_UTIL_H 21 | 22 | /** \brief Trigger a program abort (or panic for kernel code). */ 23 | #define compilerrt_abort() compilerrt_abort_impl(__FILE__, __LINE__, \ 24 | __FUNCTION__) 25 | void compilerrt_abort_impl(const char *file, int line, 26 | const char *function) 27 | #ifndef KERNEL_USE 28 | __attribute__((weak)) 29 | #endif 30 | __attribute__((noreturn)) __attribute__((visibility("hidden"))); 31 | 32 | #endif /* INT_UTIL_H */ 33 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/lshrdi3.c: -------------------------------------------------------------------------------- 1 | /* ===-- lshrdi3.c - Implement __lshrdi3 -----------------------------------=== 2 | * 3 | * The LLVM Compiler Infrastructure 4 | * 5 | * This file is dual licensed under the MIT and the University of Illinois Open 6 | * Source Licenses. See LICENSE.TXT for details. 7 | * 8 | * ===----------------------------------------------------------------------=== 9 | * 10 | * This file implements __lshrdi3 for the compiler_rt library. 11 | * 12 | * ===----------------------------------------------------------------------=== 13 | */ 14 | 15 | #include "int_lib.h" 16 | 17 | /* Returns: logical a >> b */ 18 | 19 | /* Precondition: 0 <= b < bits_in_dword */ 20 | 21 | ARM_EABI_FNALIAS(llsr, lshrdi3); 22 | 23 | COMPILER_RT_ABI di_int 24 | __lshrdi3(di_int a, si_int b) 25 | { 26 | const int bits_in_word = (int)(sizeof(si_int) * CHAR_BIT); 27 | udwords input; 28 | udwords result; 29 | input.all = a; 30 | if (b & bits_in_word) /* bits_in_word <= b < bits_in_dword */ 31 | { 32 | result.s.high = 0; 33 | result.s.low = input.s.high >> (b - bits_in_word); 34 | } 35 | else /* 0 <= b < bits_in_word */ 36 | { 37 | if (b == 0) 38 | return a; 39 | result.s.high = input.s.high >> b; 40 | result.s.low = (input.s.high << (bits_in_word - b)) | (input.s.low >> b); 41 | } 42 | return result.all; 43 | } 44 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/negdf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/negdf2.c - double-precision negation ------------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements double-precision soft-float negation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define DOUBLE_PRECISION 15 | #include "fp_lib.h" 16 | 17 | ARM_EABI_FNALIAS(dneg, negdf2); 18 | 19 | fp_t __negdf2(fp_t a) { 20 | return fromRep(toRep(a) ^ signBit); 21 | } 22 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/negsf2.c: -------------------------------------------------------------------------------- 1 | //===-- lib/negsf2.c - single-precision negation ------------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements single-precision soft-float negation. 11 | // 12 | //===----------------------------------------------------------------------===// 13 | 14 | #define SINGLE_PRECISION 15 | #include "fp_lib.h" 16 | 17 | ARM_EABI_FNALIAS(fneg, negsf2); 18 | 19 | COMPILER_RT_ABI fp_t 20 | __negsf2(fp_t a) { 21 | return fromRep(toRep(a) ^ signBit); 22 | } 23 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/subdf3.c: -------------------------------------------------------------------------------- 1 | //===-- lib/adddf3.c - Double-precision subtraction ---------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements double-precision soft-float subtraction with the 11 | // IEEE-754 default rounding (to nearest, ties to even). 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #define DOUBLE_PRECISION 16 | #include "fp_lib.h" 17 | 18 | fp_t COMPILER_RT_ABI __adddf3(fp_t a, fp_t b); 19 | 20 | 21 | ARM_EABI_FNALIAS(dsub, subdf3); 22 | 23 | // Subtraction; flip the sign bit of b and add. 24 | COMPILER_RT_ABI fp_t 25 | __subdf3(fp_t a, fp_t b) { 26 | return __adddf3(a, fromRep(toRep(b) ^ signBit)); 27 | } 28 | 29 | /* FIXME: rsub for ARM EABI */ 30 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/float/subsf3.c: -------------------------------------------------------------------------------- 1 | //===-- lib/subsf3.c - Single-precision subtraction ---------------*- C -*-===// 2 | // 3 | // The LLVM Compiler Infrastructure 4 | // 5 | // This file is dual licensed under the MIT and the University of Illinois Open 6 | // Source Licenses. See LICENSE.TXT for details. 7 | // 8 | //===----------------------------------------------------------------------===// 9 | // 10 | // This file implements single-precision soft-float subtraction with the 11 | // IEEE-754 default rounding (to nearest, ties to even). 12 | // 13 | //===----------------------------------------------------------------------===// 14 | 15 | #define SINGLE_PRECISION 16 | #include "fp_lib.h" 17 | 18 | fp_t COMPILER_RT_ABI __addsf3(fp_t a, fp_t b); 19 | 20 | ARM_EABI_FNALIAS(fsub, subsf3); 21 | 22 | // Subtraction; flip the sign bit of b and add. 23 | COMPILER_RT_ABI fp_t 24 | __subsf3(fp_t a, fp_t b) { 25 | return __addsf3(a, fromRep(toRep(b) ^ signBit)); 26 | } 27 | 28 | /* FIXME: rsub for ARM EABI */ 29 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/gets.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1999 Michael Smith 3 | * Copyright (c) 2005 Pawel Jakub Dawidek 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | 28 | #include 29 | #include 30 | 31 | __attribute__((optimize("-Os"))) int 32 | gets(char *cp, int size) 33 | { 34 | char *lp, *end; 35 | int c; 36 | int error = 0; 37 | 38 | lp = cp; 39 | end = cp + size - 1; 40 | for (;;) { 41 | c = getchar() & 0177; 42 | switch (c) { 43 | case 3: /* CTRL + C */ 44 | error = -1; 45 | case '\n': 46 | case '\r': 47 | printf("\n"); 48 | *lp = '\0'; 49 | return (error); 50 | case '\b': 51 | case '\177': 52 | if (lp > cp) { 53 | printf("%c \b", c); 54 | lp--; 55 | } 56 | continue; 57 | case '\0': 58 | continue; 59 | default: 60 | if (lp < end) { 61 | printf("%c", c); 62 | *lp++ = c; 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/acosh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_acosh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | #include 16 | __FBSDID("$FreeBSD: head/lib/msun/src/e_acosh.c 251599 2013-06-10 06:04:58Z das $"); 17 | 18 | /* __ieee754_acosh(x) 19 | * Method : 20 | * Based on 21 | * acosh(x) = log [ x + sqrt(x*x-1) ] 22 | * we have 23 | * acosh(x) := log(x)+ln2, if x is large; else 24 | * acosh(x) := log(2x-1/(sqrt(x*x-1)+x)) if x>2; else 25 | * acosh(x) := log1p(t+sqrt(2.0*t+t*t)); where t=x-1. 26 | * 27 | * Special cases: 28 | * acosh(x) is NaN with signal if x<1. 29 | * acosh(NaN) is NaN without signal. 30 | */ 31 | 32 | #include 33 | 34 | #include "math.h" 35 | #include "math_private.h" 36 | 37 | static const double 38 | one = 1.0, 39 | ln2 = 6.93147180559945286227e-01; /* 0x3FE62E42, 0xFEFA39EF */ 40 | 41 | double 42 | acosh(double x) 43 | { 44 | double t; 45 | int32_t hx; 46 | u_int32_t lx; 47 | EXTRACT_WORDS(hx,lx,x); 48 | if(hx<0x3ff00000) { /* x < 1 */ 49 | return (x-x)/(x-x); 50 | } else if(hx >=0x41b00000) { /* x > 2**28 */ 51 | if(hx >=0x7ff00000) { /* x is inf of NaN */ 52 | return x+x; 53 | } else 54 | return log(x)+ln2; /* acosh(huge)=log(2x) */ 55 | } else if(((hx-0x3ff00000)|lx)==0) { 56 | return 0.0; /* acosh(1) = 0 */ 57 | } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ 58 | t=x*x; 59 | return log(2.0*x-one/(x+sqrt(t-one))); 60 | } else { /* 1 17 | __FBSDID("$FreeBSD: head/lib/msun/src/e_acoshf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float 23 | one = 1.0, 24 | ln2 = 6.9314718246e-01; /* 0x3f317218 */ 25 | 26 | float 27 | acoshf(float x) 28 | { 29 | float t; 30 | int32_t hx; 31 | GET_FLOAT_WORD(hx,x); 32 | if(hx<0x3f800000) { /* x < 1 */ 33 | return (x-x)/(x-x); 34 | } else if(hx >=0x4d800000) { /* x > 2**28 */ 35 | if(hx >=0x7f800000) { /* x is inf of NaN */ 36 | return x+x; 37 | } else 38 | return logf(x)+ln2; /* acosh(huge)=log(2x) */ 39 | } else if (hx==0x3f800000) { 40 | return 0.0; /* acosh(1) = 0 */ 41 | } else if (hx > 0x40000000) { /* 2**28 > x > 2 */ 42 | t=x*x; 43 | return logf((float)2.0*x-one/(x+sqrtf(t-one))); 44 | } else { /* 1 17 | __FBSDID("$FreeBSD: head/lib/msun/src/e_asinf.c 181405 2008-08-08 00:21:27Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float 23 | one = 1.0000000000e+00, /* 0x3F800000 */ 24 | huge = 1.000e+30, 25 | /* coefficient for R(x^2) */ 26 | pS0 = 1.6666586697e-01, 27 | pS1 = -4.2743422091e-02, 28 | pS2 = -8.6563630030e-03, 29 | qS1 = -7.0662963390e-01; 30 | 31 | static const double 32 | pio2 = 1.570796326794896558e+00; 33 | 34 | float 35 | asinf(float x) 36 | { 37 | double s; 38 | float t,w,p,q; 39 | int32_t hx,ix; 40 | GET_FLOAT_WORD(hx,x); 41 | ix = hx&0x7fffffff; 42 | if(ix>=0x3f800000) { /* |x| >= 1 */ 43 | if(ix==0x3f800000) /* |x| == 1 */ 44 | return x*pio2; /* asin(+-1) = +-pi/2 with inexact */ 45 | return (x-x)/(x-x); /* asin(|x|>1) is NaN */ 46 | } else if (ix<0x3f000000) { /* |x|<0.5 */ 47 | if(ix<0x39800000) { /* |x| < 2**-12 */ 48 | if(huge+x>one) return x;/* return x with inexact if x!=0*/ 49 | } 50 | t = x*x; 51 | p = t*(pS0+t*(pS1+t*pS2)); 52 | q = one+t*qS1; 53 | w = p/q; 54 | return x+x*w; 55 | } 56 | /* 1> |x|>= 0.5 */ 57 | w = one-fabsf(x); 58 | t = w*(float)0.5; 59 | p = t*(pS0+t*(pS1+t*pS2)); 60 | q = one+t*qS1; 61 | s = sqrt(t); 62 | w = p/q; 63 | t = pio2-2.0*(s+s*w); 64 | if(hx>0) return t; else return -t; 65 | } 66 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/asinh.c: -------------------------------------------------------------------------------- 1 | /* @(#)s_asinh.c 5.1 93/09/24 */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | #include 14 | __FBSDID("$FreeBSD: head/lib/msun/src/s_asinh.c 251599 2013-06-10 06:04:58Z das $"); 15 | 16 | /* asinh(x) 17 | * Method : 18 | * Based on 19 | * asinh(x) = sign(x) * log [ |x| + sqrt(x*x+1) ] 20 | * we have 21 | * asinh(x) := x if 1+x*x=1, 22 | * := sign(x)*(log(x)+ln2)) for large |x|, else 23 | * := sign(x)*log(2|x|+1/(|x|+sqrt(x*x+1))) if|x|>2, else 24 | * := sign(x)*log1p(|x| + x^2/(1 + sqrt(1+x^2))) 25 | */ 26 | 27 | #include 28 | 29 | #include "math.h" 30 | #include "math_private.h" 31 | 32 | static const double 33 | one = 1.00000000000000000000e+00, /* 0x3FF00000, 0x00000000 */ 34 | ln2 = 6.93147180559945286227e-01, /* 0x3FE62E42, 0xFEFA39EF */ 35 | huge= 1.00000000000000000000e+300; 36 | 37 | double 38 | asinh(double x) 39 | { 40 | double t,w; 41 | int32_t hx,ix; 42 | GET_HIGH_WORD(hx,x); 43 | ix = hx&0x7fffffff; 44 | if(ix>=0x7ff00000) return x+x; /* x is inf or NaN */ 45 | if(ix< 0x3e300000) { /* |x|<2**-28 */ 46 | if(huge+x>one) return x; /* return x inexact except 0 */ 47 | } 48 | if(ix>0x41b00000) { /* |x| > 2**28 */ 49 | w = log(fabs(x))+ln2; 50 | } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ 51 | t = fabs(x); 52 | w = log(2.0*t+one/(sqrt(x*x+one)+t)); 53 | } else { /* 2.0 > |x| > 2**-28 */ 54 | t = x*x; 55 | w =log1p(fabs(x)+t/(one+sqrt(one+t))); 56 | } 57 | if(hx>0) return w; else return -w; 58 | } 59 | 60 | #if LDBL_MANT_DIG == 53 61 | __weak_reference(asinh, asinhl); 62 | #endif 63 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/asinhf.c: -------------------------------------------------------------------------------- 1 | /* s_asinhf.c -- float version of s_asinh.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_asinhf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float 23 | one = 1.0000000000e+00, /* 0x3F800000 */ 24 | ln2 = 6.9314718246e-01, /* 0x3f317218 */ 25 | huge= 1.0000000000e+30; 26 | 27 | float 28 | asinhf(float x) 29 | { 30 | float t,w; 31 | int32_t hx,ix; 32 | GET_FLOAT_WORD(hx,x); 33 | ix = hx&0x7fffffff; 34 | if(ix>=0x7f800000) return x+x; /* x is inf or NaN */ 35 | if(ix< 0x31800000) { /* |x|<2**-28 */ 36 | if(huge+x>one) return x; /* return x inexact except 0 */ 37 | } 38 | if(ix>0x4d800000) { /* |x| > 2**28 */ 39 | w = logf(fabsf(x))+ln2; 40 | } else if (ix>0x40000000) { /* 2**28 > |x| > 2.0 */ 41 | t = fabsf(x); 42 | w = logf((float)2.0*t+one/(sqrtf(x*x+one)+t)); 43 | } else { /* 2.0 > |x| > 2**-28 */ 44 | t = x*x; 45 | w =log1pf(fabsf(x)+t/(one+sqrtf(one+t))); 46 | } 47 | if(hx>0) return w; else return -w; 48 | } 49 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/atanh.c: -------------------------------------------------------------------------------- 1 | 2 | /* @(#)e_atanh.c 1.3 95/01/18 */ 3 | /* 4 | * ==================================================== 5 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 6 | * 7 | * Developed at SunSoft, a Sun Microsystems, Inc. business. 8 | * Permission to use, copy, modify, and distribute this 9 | * software is freely granted, provided that this notice 10 | * is preserved. 11 | * ==================================================== 12 | * 13 | */ 14 | 15 | #include 16 | __FBSDID("$FreeBSD: head/lib/msun/src/e_atanh.c 251599 2013-06-10 06:04:58Z das $"); 17 | 18 | /* __ieee754_atanh(x) 19 | * Method : 20 | * 1.Reduced x to positive by atanh(-x) = -atanh(x) 21 | * 2.For x>=0.5 22 | * 1 2x x 23 | * atanh(x) = --- * log(1 + -------) = 0.5 * log1p(2 * --------) 24 | * 2 1 - x 1 - x 25 | * 26 | * For x<0.5 27 | * atanh(x) = 0.5*log1p(2x+2x*x/(1-x)) 28 | * 29 | * Special cases: 30 | * atanh(x) is NaN if |x| > 1 with signal; 31 | * atanh(NaN) is that NaN with no signal; 32 | * atanh(+-1) is +-INF with signal. 33 | * 34 | */ 35 | 36 | #include 37 | 38 | #include "math.h" 39 | #include "math_private.h" 40 | 41 | static const double one = 1.0, huge = 1e300; 42 | static const double zero = 0.0; 43 | 44 | double 45 | atanh(double x) 46 | { 47 | double t; 48 | int32_t hx,ix; 49 | u_int32_t lx; 50 | EXTRACT_WORDS(hx,lx,x); 51 | ix = hx&0x7fffffff; 52 | if ((ix|((lx|(-lx))>>31))>0x3ff00000) /* |x|>1 */ 53 | return (x-x)/(x-x); 54 | if(ix==0x3ff00000) 55 | return x/zero; 56 | if(ix<0x3e300000&&(huge+x)>zero) return x; /* x<2**-28 */ 57 | SET_HIGH_WORD(x,ix); 58 | if(ix<0x3fe00000) { /* x < 0.5 */ 59 | t = x+x; 60 | t = 0.5*log1p(t+t*x/(one-x)); 61 | } else 62 | t = 0.5*log1p((x+x)/(one-x)); 63 | if(hx>=0) return t; else return -t; 64 | } 65 | 66 | #if LDBL_MANT_DIG == 53 67 | __weak_reference(atanh, atanhl); 68 | #endif 69 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/atanhf.c: -------------------------------------------------------------------------------- 1 | /* e_atanhf.c -- float version of e_atanh.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/e_atanhf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float one = 1.0, huge = 1e30; 23 | 24 | static const float zero = 0.0; 25 | 26 | float 27 | atanhf(float x) 28 | { 29 | float t; 30 | int32_t hx,ix; 31 | GET_FLOAT_WORD(hx,x); 32 | ix = hx&0x7fffffff; 33 | if (ix>0x3f800000) /* |x|>1 */ 34 | return (x-x)/(x-x); 35 | if(ix==0x3f800000) 36 | return x/zero; 37 | if(ix<0x31800000&&(huge+x)>zero) return x; /* x<2**-28 */ 38 | SET_FLOAT_WORD(x,ix); 39 | if(ix<0x3f000000) { /* x < 0.5 */ 40 | t = x+x; 41 | t = (float)0.5*log1pf(t+t*x/(one-x)); 42 | } else 43 | t = (float)0.5*log1pf((x+x)/(one-x)); 44 | if(hx>=0) return t; else return -t; 45 | } 46 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/ceil.c: -------------------------------------------------------------------------------- 1 | /* @(#)s_ceil.c 5.1 93/09/24 */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | #include 14 | __FBSDID("$FreeBSD: head/lib/msun/src/s_ceil.c 176305 2008-02-15 07:01:40Z bde $"); 15 | 16 | /* 17 | * ceil(x) 18 | * Return x rounded toward -inf to integral value 19 | * Method: 20 | * Bit twiddling. 21 | * Exception: 22 | * Inexact flag raised if x not equal to ceil(x). 23 | */ 24 | 25 | #include 26 | 27 | #include "math.h" 28 | #include "math_private.h" 29 | 30 | static const double huge = 1.0e300; 31 | 32 | double 33 | ceil(double x) 34 | { 35 | int32_t i0,i1,j0; 36 | u_int32_t i,j; 37 | EXTRACT_WORDS(i0,i1,x); 38 | j0 = ((i0>>20)&0x7ff)-0x3ff; 39 | if(j0<20) { 40 | if(j0<0) { /* raise inexact if x != 0 */ 41 | if(huge+x>0.0) {/* return 0*sign(x) if |x|<1 */ 42 | if(i0<0) {i0=0x80000000;i1=0;} 43 | else if((i0|i1)!=0) { i0=0x3ff00000;i1=0;} 44 | } 45 | } else { 46 | i = (0x000fffff)>>j0; 47 | if(((i0&i)|i1)==0) return x; /* x is integral */ 48 | if(huge+x>0.0) { /* raise inexact flag */ 49 | if(i0>0) i0 += (0x00100000)>>j0; 50 | i0 &= (~i); i1=0; 51 | } 52 | } 53 | } else if (j0>51) { 54 | if(j0==0x400) return x+x; /* inf or NaN */ 55 | else return x; /* x is integral */ 56 | } else { 57 | i = ((u_int32_t)(0xffffffff))>>(j0-20); 58 | if((i1&i)==0) return x; /* x is integral */ 59 | if(huge+x>0.0) { /* raise inexact flag */ 60 | if(i0>0) { 61 | if(j0==20) i0+=1; 62 | else { 63 | j = i1 + (1<<(52-j0)); 64 | if(j 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_ceilf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float huge = 1.0e30; 23 | 24 | float 25 | ceilf(float x) 26 | { 27 | int32_t i0,j0; 28 | u_int32_t i; 29 | 30 | GET_FLOAT_WORD(i0,x); 31 | j0 = ((i0>>23)&0xff)-0x7f; 32 | if(j0<23) { 33 | if(j0<0) { /* raise inexact if x != 0 */ 34 | if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ 35 | if(i0<0) {i0=0x80000000;} 36 | else if(i0!=0) { i0=0x3f800000;} 37 | } 38 | } else { 39 | i = (0x007fffff)>>j0; 40 | if((i0&i)==0) return x; /* x is integral */ 41 | if(huge+x>(float)0.0) { /* raise inexact flag */ 42 | if(i0>0) i0 += (0x00800000)>>j0; 43 | i0 &= (~i); 44 | } 45 | } 46 | } else { 47 | if(j0==0x80) return x+x; /* inf or NaN */ 48 | else return x; /* x is integral */ 49 | } 50 | SET_FLOAT_WORD(x,i0); 51 | return x; 52 | } 53 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/copysignf.c: -------------------------------------------------------------------------------- 1 | /* s_copysignf.c -- float version of s_copysign.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: stable/10/lib/msun/src/s_copysignf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | /* 20 | * copysignf(float x, float y) 21 | * copysignf(x,y) returns a value with the magnitude of x and 22 | * with the sign bit of y. 23 | */ 24 | 25 | #include "math.h" 26 | #include "math_private.h" 27 | 28 | float 29 | copysignf(float x, float y) 30 | { 31 | u_int32_t ix,iy; 32 | GET_FLOAT_WORD(ix,x); 33 | GET_FLOAT_WORD(iy,y); 34 | SET_FLOAT_WORD(x,(ix&0x7fffffff)|(iy&0x80000000)); 35 | return x; 36 | } 37 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/cos.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_cos.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009-2011 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | double cos(double x) 39 | { 40 | return sin(x + M_PI_2); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/cosf.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_cosf.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009-2011 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | float cosf(float x) 39 | { 40 | return sinf(x + M_PI_2); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/cosh.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_cosh.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009-2011 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | double cosh(double x) 39 | { 40 | x = exp(x); 41 | return ((x + (1.0 / x)) / 2.0); 42 | } 43 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/coshf.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_coshf.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009-2011 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | float coshf(float x) 39 | { 40 | x = expf(x); 41 | return ((x + (1.0 / x)) / 2.0); 42 | } 43 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/fabs.c: -------------------------------------------------------------------------------- 1 | /* @(#)s_fabs.c 5.1 93/09/24 */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | 14 | /* 15 | * fabs(x) returns the absolute value of x. 16 | */ 17 | 18 | #include "math.h" 19 | #include "math_private.h" 20 | 21 | double 22 | fabs(double x) 23 | { 24 | u_int32_t high; 25 | GET_HIGH_WORD(high,x); 26 | SET_HIGH_WORD(x,high&0x7fffffff); 27 | return x; 28 | } 29 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/fabsf.c: -------------------------------------------------------------------------------- 1 | /* s_fabsf.c -- float version of s_fabs.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_fabsf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | /* 20 | * fabsf(x) returns the absolute value of x. 21 | */ 22 | 23 | #include "math.h" 24 | #include "math_private.h" 25 | 26 | float 27 | fabsf(float x) 28 | { 29 | u_int32_t ix; 30 | GET_FLOAT_WORD(ix,x); 31 | SET_FLOAT_WORD(x,ix&0x7fffffff); 32 | return x; 33 | } 34 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/floor.c: -------------------------------------------------------------------------------- 1 | /* origin: FreeBSD /usr/src/lib/msun/src/s_floor.c */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | /* 13 | * floor(x) 14 | * Return x rounded toward -inf to integral value 15 | * Method: 16 | * Bit twiddling. 17 | * Exception: 18 | * Inexact flag raised if x not equal to floor(x). 19 | */ 20 | 21 | #include "math_private.h" 22 | 23 | static const double huge = 1.0e300; 24 | 25 | double floor(double x) 26 | { 27 | int32_t i0,i1,j0; 28 | uint32_t i,j; 29 | 30 | EXTRACT_WORDS(i0, i1, x); 31 | // FIXME: signed shift 32 | j0 = ((i0>>20)&0x7ff) - 0x3ff; 33 | if (j0 < 20) { 34 | if (j0 < 0) { /* |x| < 1 */ 35 | /* raise inexact if x != 0 */ 36 | if (huge+x > 0.0) { 37 | if (i0 >= 0) { /* x >= 0 */ 38 | i0 = i1 = 0; 39 | } else if (((i0&0x7fffffff)|i1) != 0) { 40 | i0 = 0xbff00000; 41 | i1 = 0; 42 | } 43 | } 44 | } else { 45 | i = 0x000fffff>>j0; 46 | if (((i0&i)|i1) == 0) 47 | return x; /* x is integral */ 48 | /* raise inexact flag */ 49 | if (huge+x > 0.0) { 50 | if (i0 < 0) 51 | i0 += 0x00100000>>j0; 52 | i0 &= ~i; 53 | i1 = 0; 54 | } 55 | } 56 | } else if (j0 > 51) { 57 | if (j0 == 0x400) 58 | return x+x; /* inf or NaN */ 59 | else 60 | return x; /* x is integral */ 61 | } else { 62 | i = (uint32_t)0xffffffff>>(j0-20); 63 | if ((i1&i) == 0) 64 | return x; /* x is integral */ 65 | /* raise inexact flag */ 66 | if (huge+x > 0.0) { 67 | if (i0 < 0) { 68 | if (j0 == 20) 69 | i0++; 70 | else { 71 | j = i1+(1<<(52-j0)); 72 | if ((int) j < i1) 73 | i0++; /* got a carry */ 74 | i1 = j; 75 | } 76 | } 77 | i1 &= ~i; 78 | } 79 | } 80 | INSERT_WORDS(x, i0, i1); 81 | return x; 82 | } 83 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/floorf.c: -------------------------------------------------------------------------------- 1 | /* s_floorf.c -- float version of s_floor.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_floorf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | /* 20 | * floorf(x) 21 | * Return x rounded toward -inf to integral value 22 | * Method: 23 | * Bit twiddling. 24 | * Exception: 25 | * Inexact flag raised if x not equal to floorf(x). 26 | */ 27 | 28 | #include "math.h" 29 | #include "math_private.h" 30 | 31 | static const float huge = 1.0e30; 32 | 33 | float 34 | floorf(float x) 35 | { 36 | int32_t i0,j0; 37 | u_int32_t i; 38 | GET_FLOAT_WORD(i0,x); 39 | j0 = ((i0>>23)&0xff)-0x7f; 40 | if(j0<23) { 41 | if(j0<0) { /* raise inexact if x != 0 */ 42 | if(huge+x>(float)0.0) {/* return 0*sign(x) if |x|<1 */ 43 | if(i0>=0) {i0=0;} 44 | else if((i0&0x7fffffff)!=0) 45 | { i0=0xbf800000;} 46 | } 47 | } else { 48 | i = (0x007fffff)>>j0; 49 | if((i0&i)==0) return x; /* x is integral */ 50 | if(huge+x>(float)0.0) { /* raise inexact flag */ 51 | if(i0<0) i0 += (0x00800000)>>j0; 52 | i0 &= (~i); 53 | } 54 | } 55 | } else { 56 | if(j0==0x80) return x+x; /* inf or NaN */ 57 | else return x; /* x is integral */ 58 | } 59 | SET_FLOAT_WORD(x,i0); 60 | return x; 61 | } 62 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/frexp.c: -------------------------------------------------------------------------------- 1 | /* @(#)s_frexp.c 5.1 93/09/24 */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | #include 14 | __FBSDID("$FreeBSD: head/lib/msun/src/s_frexp.c 176451 2008-02-22 02:30:36Z das $"); 15 | 16 | /* 17 | * for non-zero x 18 | * x = frexp(arg,&exp); 19 | * return a double fp quantity x such that 0.5 <= |x| <1.0 20 | * and the corresponding binary exponent "exp". That is 21 | * arg = x*2^exp. 22 | * If arg is inf, 0.0, or NaN, then frexp(arg,&exp) returns arg 23 | * with *exp=0. 24 | */ 25 | 26 | #include 27 | 28 | #include "math.h" 29 | #include "math_private.h" 30 | 31 | static const double 32 | two54 = 1.80143985094819840000e+16; /* 0x43500000, 0x00000000 */ 33 | 34 | double 35 | frexp(double x, int *eptr) 36 | { 37 | int32_t hx, ix, lx; 38 | EXTRACT_WORDS(hx,lx,x); 39 | ix = 0x7fffffff&hx; 40 | *eptr = 0; 41 | if(ix>=0x7ff00000||((ix|lx)==0)) return x; /* 0,inf,nan */ 42 | if (ix<0x00100000) { /* subnormal */ 43 | x *= two54; 44 | GET_HIGH_WORD(hx,x); 45 | ix = hx&0x7fffffff; 46 | *eptr = -54; 47 | } 48 | *eptr += (ix>>20)-1022; 49 | hx = (hx&0x800fffff)|0x3fe00000; 50 | SET_HIGH_WORD(x,hx); 51 | return x; 52 | } 53 | 54 | #if (LDBL_MANT_DIG == 53) 55 | __weak_reference(frexp, frexpl); 56 | #endif 57 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/frexpf.c: -------------------------------------------------------------------------------- 1 | /* s_frexpf.c -- float version of s_frexp.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_frexpf.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float 23 | two25 = 3.3554432000e+07; /* 0x4c000000 */ 24 | 25 | float 26 | frexpf(float x, int *eptr) 27 | { 28 | int32_t hx,ix; 29 | GET_FLOAT_WORD(hx,x); 30 | ix = 0x7fffffff&hx; 31 | *eptr = 0; 32 | if(ix>=0x7f800000||(ix==0)) return x; /* 0,inf,nan */ 33 | if (ix<0x00800000) { /* subnormal */ 34 | x *= two25; 35 | GET_FLOAT_WORD(hx,x); 36 | ix = hx&0x7fffffff; 37 | *eptr = -25; 38 | } 39 | *eptr += (ix>>23)-126; 40 | hx = (hx&0x807fffff)|0x3f000000; 41 | SET_FLOAT_WORD(x,hx); 42 | return x; 43 | } 44 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/isfinite.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2004 David Schultz 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: head/lib/msun/src/s_isfinite.c 131852 2004-07-09 03:32:40Z das $ 27 | */ 28 | 29 | #include 30 | 31 | #include "fpmath.h" 32 | 33 | int 34 | __isfinite(double d) 35 | { 36 | union IEEEd2bits u; 37 | 38 | u.d = d; 39 | return (u.bits.exp != 2047); 40 | } 41 | 42 | int 43 | __isfinitef(float f) 44 | { 45 | union IEEEf2bits u; 46 | 47 | u.f = f; 48 | return (u.bits.exp != 255); 49 | } 50 | 51 | int 52 | __isfinitel(long double e) 53 | { 54 | union IEEEl2bits u; 55 | 56 | u.e = e; 57 | return (u.bits.exp != 32767); 58 | } 59 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/isnan.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2004 David Schultz 3 | * All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 | * SUCH DAMAGE. 25 | * 26 | * $FreeBSD: stable/9/lib/msun/src/s_isnan.c 243193 2012-11-17 23:05:18Z dim $ 27 | */ 28 | 29 | #include 30 | 31 | #include "fpmath.h" 32 | 33 | /* Provided by libc.so */ 34 | #ifndef PIC 35 | #undef isnan 36 | int 37 | isnan(double d) 38 | { 39 | union IEEEd2bits u; 40 | 41 | u.d = d; 42 | return (u.bits.exp == 2047 && (u.bits.manl != 0 || u.bits.manh != 0)); 43 | } 44 | #endif /* !PIC */ 45 | 46 | int 47 | __isnanf(float f) 48 | { 49 | union IEEEf2bits u; 50 | 51 | u.f = f; 52 | return (u.bits.exp == 255 && u.bits.man != 0); 53 | } 54 | 55 | int 56 | __isnanl(long double e) 57 | { 58 | union IEEEl2bits u; 59 | 60 | u.e = e; 61 | mask_nbit_l(u); 62 | return (u.bits.exp == 32767 && (u.bits.manl != 0 || u.bits.manh != 0)); 63 | } 64 | 65 | __weak_reference(__isnanf, isnanf); 66 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/k_logf.h: -------------------------------------------------------------------------------- 1 | /* 2 | * ==================================================== 3 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 4 | * 5 | * Developed at SunPro, a Sun Microsystems, Inc. business. 6 | * Permission to use, copy, modify, and distribute this 7 | * software is freely granted, provided that this notice 8 | * is preserved. 9 | * ==================================================== 10 | */ 11 | 12 | #include 13 | __FBSDID("$FreeBSD: head/lib/msun/src/k_logf.h 226376 2011-10-15 05:23:28Z das $"); 14 | 15 | /* 16 | * Float version of k_log.h. See the latter for most comments. 17 | */ 18 | 19 | static const float 20 | /* |(log(1+s)-log(1-s))/s - Lg(s)| < 2**-34.24 (~[-4.95e-11, 4.97e-11]). */ 21 | Lg1 = 0xaaaaaa.0p-24, /* 0.66666662693 */ 22 | Lg2 = 0xccce13.0p-25, /* 0.40000972152 */ 23 | Lg3 = 0x91e9ee.0p-25, /* 0.28498786688 */ 24 | Lg4 = 0xf89e26.0p-26; /* 0.24279078841 */ 25 | 26 | static inline float 27 | k_log1pf(float f) 28 | { 29 | float hfsq,s,z,R,w,t1,t2; 30 | 31 | s = f/((float)2.0+f); 32 | z = s*s; 33 | w = z*z; 34 | t1= w*(Lg2+w*Lg4); 35 | t2= z*(Lg1+w*Lg3); 36 | R = t2+t1; 37 | hfsq=(float)0.5*f*f; 38 | return s*(hfsq+R); 39 | } 40 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/modf.c: -------------------------------------------------------------------------------- 1 | /* @(#)s_modf.c 5.1 93/09/24 */ 2 | /* 3 | * ==================================================== 4 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 5 | * 6 | * Developed at SunPro, a Sun Microsystems, Inc. business. 7 | * Permission to use, copy, modify, and distribute this 8 | * software is freely granted, provided that this notice 9 | * is preserved. 10 | * ==================================================== 11 | */ 12 | 13 | 14 | /* 15 | * modf(double x, double *iptr) 16 | * return fraction part of x, and return x's integral part in *iptr. 17 | * Method: 18 | * Bit twiddling. 19 | * 20 | * Exception: 21 | * No exception. 22 | */ 23 | 24 | #include "math.h" 25 | #include "math_private.h" 26 | 27 | static const double one = 1.0; 28 | 29 | double 30 | modf(double x, double *iptr) 31 | { 32 | int32_t i0,i1,j0; 33 | u_int32_t i; 34 | EXTRACT_WORDS(i0,i1,x); 35 | j0 = ((i0>>20)&0x7ff)-0x3ff; /* exponent of x */ 36 | if(j0<20) { /* integer part in high x */ 37 | if(j0<0) { /* |x|<1 */ 38 | INSERT_WORDS(*iptr,i0&0x80000000,0); /* *iptr = +-0 */ 39 | return x; 40 | } else { 41 | i = (0x000fffff)>>j0; 42 | if(((i0&i)|i1)==0) { /* x is integral */ 43 | u_int32_t high; 44 | *iptr = x; 45 | GET_HIGH_WORD(high,x); 46 | INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 47 | return x; 48 | } else { 49 | INSERT_WORDS(*iptr,i0&(~i),0); 50 | return x - *iptr; 51 | } 52 | } 53 | } else if (j0>51) { /* no fraction part */ 54 | u_int32_t high; 55 | if (j0 == 0x400) { /* inf/NaN */ 56 | *iptr = x; 57 | return 0.0 / x; 58 | } 59 | *iptr = x*one; 60 | GET_HIGH_WORD(high,x); 61 | INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 62 | return x; 63 | } else { /* fraction part in low x */ 64 | i = ((u_int32_t)(0xffffffff))>>(j0-20); 65 | if((i1&i)==0) { /* x is integral */ 66 | u_int32_t high; 67 | *iptr = x; 68 | GET_HIGH_WORD(high,x); 69 | INSERT_WORDS(x,high&0x80000000,0); /* return +-0 */ 70 | return x; 71 | } else { 72 | INSERT_WORDS(*iptr,i0,i1&(~i)); 73 | return x - *iptr; 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/modff.c: -------------------------------------------------------------------------------- 1 | /* s_modff.c -- float version of s_modf.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | #include 17 | __FBSDID("$FreeBSD: head/lib/msun/src/s_modff.c 176451 2008-02-22 02:30:36Z das $"); 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float one = 1.0; 23 | 24 | float 25 | modff(float x, float *iptr) 26 | { 27 | int32_t i0,j0; 28 | u_int32_t i; 29 | GET_FLOAT_WORD(i0,x); 30 | j0 = ((i0>>23)&0xff)-0x7f; /* exponent of x */ 31 | if(j0<23) { /* integer part in x */ 32 | if(j0<0) { /* |x|<1 */ 33 | SET_FLOAT_WORD(*iptr,i0&0x80000000); /* *iptr = +-0 */ 34 | return x; 35 | } else { 36 | i = (0x007fffff)>>j0; 37 | if((i0&i)==0) { /* x is integral */ 38 | u_int32_t ix; 39 | *iptr = x; 40 | GET_FLOAT_WORD(ix,x); 41 | SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ 42 | return x; 43 | } else { 44 | SET_FLOAT_WORD(*iptr,i0&(~i)); 45 | return x - *iptr; 46 | } 47 | } 48 | } else { /* no fraction part */ 49 | u_int32_t ix; 50 | *iptr = x*one; 51 | if (x != x) /* NaN */ 52 | return x; 53 | GET_FLOAT_WORD(ix,x); 54 | SET_FLOAT_WORD(x,ix&0x80000000); /* return +-0 */ 55 | return x; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/scalbn.c: -------------------------------------------------------------------------------- 1 | #include "math_private.h" 2 | 3 | double scalbn(double x, int n) 4 | { 5 | double scale; 6 | 7 | if (n > 1023) { 8 | x *= 0x1p1023; 9 | n -= 1023; 10 | if (n > 1023) { 11 | x *= 0x1p1023; 12 | n -= 1023; 13 | if (n > 1023) { 14 | STRICT_ASSIGN(double, x, x * 0x1p1023); 15 | return x; 16 | } 17 | } 18 | } else if (n < -1022) { 19 | x *= 0x1p-1022; 20 | n += 1022; 21 | if (n < -1022) { 22 | x *= 0x1p-1022; 23 | n += 1022; 24 | if (n < -1022) { 25 | STRICT_ASSIGN(double, x, x * 0x1p-1022); 26 | return x; 27 | } 28 | } 29 | } 30 | INSERT_WORDS(scale, (uint32_t)(0x3ff+n)<<20, 0); 31 | STRICT_ASSIGN(double, x, x * scale); 32 | return x; 33 | } 34 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/scalbnf.c: -------------------------------------------------------------------------------- 1 | /* s_scalbnf.c -- float version of s_scalbn.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | 17 | #include 18 | 19 | #include "math.h" 20 | #include "math_private.h" 21 | 22 | static const float 23 | two25 = 3.355443200e+07, /* 0x4c000000 */ 24 | twom25 = 2.9802322388e-08, /* 0x33000000 */ 25 | huge = 1.0e+30, 26 | tiny = 1.0e-30; 27 | 28 | float 29 | scalbnf (float x, int n) 30 | { 31 | int32_t k,ix; 32 | GET_FLOAT_WORD(ix,x); 33 | k = (ix&0x7f800000)>>23; /* extract exponent */ 34 | if (k==0) { /* 0 or subnormal x */ 35 | if ((ix&0x7fffffff)==0) return x; /* +-0 */ 36 | x *= two25; 37 | GET_FLOAT_WORD(ix,x); 38 | k = ((ix&0x7f800000)>>23) - 25; 39 | if (n< -50000) return tiny*x; /*underflow*/ 40 | } 41 | if (k==0xff) return x+x; /* NaN or Inf */ 42 | k = k+n; 43 | if (k > 0xfe) return huge*copysignf(huge,x); /* overflow */ 44 | if (k > 0) /* normal result */ 45 | {SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); return x;} 46 | if (k <= -25) { 47 | if (n > 50000) /* in case integer overflow in n+k */ 48 | return huge*copysignf(huge,x); /*overflow*/ 49 | else 50 | return tiny*copysignf(tiny,x); /*underflow*/ 51 | } 52 | k += 25; /* subnormal result */ 53 | SET_FLOAT_WORD(x,(ix&0x807fffff)|(k<<23)); 54 | return x*twom25; 55 | } 56 | 57 | __strong_reference(scalbnf, ldexpf); 58 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/sinh.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_sinh.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | double sinh(double x) 39 | { 40 | x = exp(x); 41 | return ((x - (1.0 / x)) / 2.0); 42 | } 43 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/sinhf.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_sinhf.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | float sinhf(float x) 39 | { 40 | x = expf(x); 41 | return ((x - (1.0 / x)) / 2.0); 42 | } 43 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/sqrtf.c: -------------------------------------------------------------------------------- 1 | /* e_sqrtf.c -- float version of e_sqrt.c. 2 | * Conversion to float by Ian Lance Taylor, Cygnus Support, ian@cygnus.com. 3 | */ 4 | 5 | /* 6 | * ==================================================== 7 | * Copyright (C) 1993 by Sun Microsystems, Inc. All rights reserved. 8 | * 9 | * Developed at SunPro, a Sun Microsystems, Inc. business. 10 | * Permission to use, copy, modify, and distribute this 11 | * software is freely granted, provided that this notice 12 | * is preserved. 13 | * ==================================================== 14 | */ 15 | 16 | 17 | #include "math.h" 18 | #include "math_private.h" 19 | 20 | static const float one = 1.0, tiny=1.0e-30; 21 | 22 | float 23 | sqrtf(float x) 24 | { 25 | float z; 26 | int32_t sign = (int)0x80000000; 27 | int32_t ix,s,q,m,t,i; 28 | u_int32_t r; 29 | 30 | GET_FLOAT_WORD(ix,x); 31 | 32 | /* take care of Inf and NaN */ 33 | if((ix&0x7f800000)==0x7f800000) { 34 | return x*x+x; /* sqrt(NaN)=NaN, sqrt(+inf)=+inf 35 | sqrt(-inf)=sNaN */ 36 | } 37 | /* take care of zero */ 38 | if(ix<=0) { 39 | if((ix&(~sign))==0) return x;/* sqrt(+-0) = +-0 */ 40 | else if(ix<0) 41 | return (x-x)/(x-x); /* sqrt(-ve) = sNaN */ 42 | } 43 | /* normalize x */ 44 | m = (ix>>23); 45 | if(m==0) { /* subnormal x */ 46 | for(i=0;(ix&0x00800000)==0;i++) ix<<=1; 47 | m -= i-1; 48 | } 49 | m -= 127; /* unbias exponent */ 50 | ix = (ix&0x007fffff)|0x00800000; 51 | if(m&1) /* odd m, double x to make it even */ 52 | ix += ix; 53 | m >>= 1; /* m = [m/2] */ 54 | 55 | /* generate sqrt(x) bit by bit */ 56 | ix += ix; 57 | q = s = 0; /* q = sqrt(x) */ 58 | r = 0x01000000; /* r = moving bit from right to left */ 59 | 60 | while(r!=0) { 61 | t = s+r; 62 | if(t<=ix) { 63 | s = t+r; 64 | ix -= t; 65 | q += r; 66 | } 67 | ix += ix; 68 | r>>=1; 69 | } 70 | 71 | /* use floating add to find out rounding direction */ 72 | if(ix!=0) { 73 | z = one-tiny; /* trigger inexact flag */ 74 | if (z>=one) { 75 | z = one+tiny; 76 | if (z>one) 77 | q += 2; 78 | else 79 | q += (q&1); 80 | } 81 | } 82 | ix = (q>>1)+0x3f000000; 83 | ix += (m <<23); 84 | SET_FLOAT_WORD(z,ix); 85 | return z; 86 | } 87 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/tan.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_tan.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | double tan(double x) 39 | { 40 | return (sin(x) / cos(x)); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/tanf.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_tanf.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | float tanf(float x) 39 | { 40 | return (sinf(x) / cosf(x)); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/tanh.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_tanh.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | double tanh(double x) 39 | { 40 | double x0 = exp(x); 41 | double x1 = 1.0 / x0; 42 | 43 | return ((x0 - x1) / (x0 + x1)); 44 | } 45 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/math/tanhf.c: -------------------------------------------------------------------------------- 1 | /************************************************************************ 2 | * libc/math/lib_tanhf.c 3 | * 4 | * This file is a part of NuttX: 5 | * 6 | * Copyright (C) 2012 Gregory Nutt. All rights reserved. 7 | * Ported by: Darcy Gong 8 | * 9 | * It derives from the Rhombs OS math library by Nick Johnson which has 10 | * a compatibile, MIT-style license: 11 | * 12 | * Copyright (C) 2009, 2010 Nick Johnson 13 | * 14 | * Permission to use, copy, modify, and distribute this software for any 15 | * purpose with or without fee is hereby granted, provided that the above 16 | * copyright notice and this permission notice appear in all copies. 17 | * 18 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 19 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 20 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 21 | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 22 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 23 | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 24 | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 | * 26 | ************************************************************************/ 27 | 28 | /************************************************************************ 29 | * Included Files 30 | ************************************************************************/ 31 | 32 | #include 33 | 34 | /************************************************************************ 35 | * Public Functions 36 | ************************************************************************/ 37 | 38 | float tanhf(float x) 39 | { 40 | float x0 = expf(x); 41 | float x1 = 1.0 / x0; 42 | 43 | return ((x0 + x1) / (x0 - x1)); 44 | } 45 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/memcmp.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1990, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * This code is derived from software contributed to Berkeley by 6 | * Chris Torek. 7 | * 8 | * Redistribution and use in source and binary forms, with or without 9 | * modification, are permitted provided that the following conditions 10 | * are met: 11 | * 1. Redistributions of source code must retain the above copyright 12 | * notice, this list of conditions and the following disclaimer. 13 | * 2. Redistributions in binary form must reproduce the above copyright 14 | * notice, this list of conditions and the following disclaimer in the 15 | * documentation and/or other materials provided with the distribution. 16 | * 4. Neither the name of the University nor the names of its contributors 17 | * may be used to endorse or promote products derived from this software 18 | * without specific prior written permission. 19 | * 20 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 | * SUCH DAMAGE. 31 | */ 32 | 33 | #include 34 | __FBSDID("$FreeBSD: stable/9/sys/libkern/memcmp.c 183299 2008-09-23 14:45:10Z obrien $"); 35 | 36 | 37 | /* 38 | * Compare memory regions. 39 | */ 40 | int 41 | memcmp(const void *s1, const void *s2, size_t n) 42 | { 43 | if (n != 0) { 44 | const unsigned char *p1 = s1, *p2 = s2; 45 | 46 | do { 47 | if (*p1++ != *p2++) 48 | return (*--p1 - *--p2); 49 | } while (--n != 0); 50 | } 51 | return (0); 52 | } 53 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/memcpy.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | __attribute__((optimize("-Os"))) void * 29 | memcpy(int *dst, const int *src, unsigned int len) 30 | { 31 | char *from = (char *) src; 32 | char *to = (char *) dst; 33 | 34 | for (; len != 0; len--) 35 | *to++ = *from++; 36 | 37 | return (dst); 38 | } 39 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/memset.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | __attribute__((optimize("-Os"))) void * 29 | memset(char *b, int c, unsigned int len) 30 | { 31 | 32 | for (; len != 0; len--) 33 | *b++ = c; 34 | 35 | return (b); 36 | } 37 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/mul.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 2013 Marko Zec, University of Zagreb 3 | * 4 | * Redistribution and use in source and binary forms, with or without 5 | * modification, are permitted provided that the following conditions 6 | * are met: 7 | * 1. Redistributions of source code must retain the above copyright 8 | * notice, this list of conditions and the following disclaimer. 9 | * 2. Redistributions in binary form must reproduce the above copyright 10 | * notice, this list of conditions and the following disclaimer in the 11 | * documentation and/or other materials provided with the distribution. 12 | * 13 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 14 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 15 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 16 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 17 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 19 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 20 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 21 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 22 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 23 | * SUCH DAMAGE. 24 | * 25 | * $Id$ 26 | */ 27 | 28 | 29 | uint32_t 30 | __mulsi3(uint32_t a, uint32_t b) 31 | { 32 | uint32_t res; 33 | 34 | for (res = 0; b != 0; b >>= 1, a <<= 1) 35 | if (b & 1) 36 | res += a; 37 | return (res); 38 | } 39 | 40 | 41 | uint64_t 42 | __muldi3(uint64_t a, uint64_t b) 43 | { 44 | uint64_t res; 45 | 46 | for (res = 0; b != 0; b >>= 1, a <<= 1) 47 | if (b & 1) 48 | res += a; 49 | return (res); 50 | } 51 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/random.c: -------------------------------------------------------------------------------- 1 | 2 | static int randseed; 3 | 4 | 5 | uint32_t 6 | random(void) 7 | { 8 | int x, t; 9 | uint32_t hi, lo; 10 | 11 | /* 12 | * Compute x[n + 1] = (7^5 * x[n]) mod (2^31 - 1). 13 | * From "Random number generators: good ones are hard to find", 14 | * Park and Miller, Communications of the ACM, vol. 31, no. 10, 15 | * October 1988, p. 1195. 16 | */ 17 | /* Can't be initialized with 0, so use another value. */ 18 | if ((x = randseed) == 0) 19 | x = 123459876; 20 | hi = x / 127773; 21 | lo = x % 127773; 22 | t = 16807 * lo - 2836 * hi; 23 | if (t < 0) 24 | t += 0x7fffffff; 25 | randseed = t; 26 | return (t); 27 | } 28 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/strcpy.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * Copyright (c) 1988, 1993 3 | * The Regents of the University of California. All rights reserved. 4 | * 5 | * Redistribution and use in source and binary forms, with or without 6 | * modification, are permitted provided that the following conditions 7 | * are met: 8 | * 1. Redistributions of source code must retain the above copyright 9 | * notice, this list of conditions and the following disclaimer. 10 | * 2. Redistributions in binary form must reproduce the above copyright 11 | * notice, this list of conditions and the following disclaimer in the 12 | * documentation and/or other materials provided with the distribution. 13 | * 4. Neither the name of the University nor the names of its contributors 14 | * may be used to endorse or promote products derived from this software 15 | * without specific prior written permission. 16 | * 17 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 | * SUCH DAMAGE. 28 | */ 29 | 30 | #include 31 | __FBSDID("$FreeBSD: stable/10/sys/libkern/strcpy.c 139815 2005-01-07 00:24:33Z imp $"); 32 | 33 | 34 | char * 35 | strcpy(char * __restrict to, const char * __restrict from) 36 | { 37 | char *save = to; 38 | 39 | for (; (*to = *from) != 0; ++from, ++to); 40 | return(save); 41 | } 42 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/system/src/strrchr.c: -------------------------------------------------------------------------------- 1 | /*- 2 | * SPDX-License-Identifier: BSD-3-Clause 3 | * 4 | * Copyright (c) 1988, 1993 5 | * The Regents of the University of California. All rights reserved. 6 | * 7 | * Redistribution and use in source and binary forms, with or without 8 | * modification, are permitted provided that the following conditions 9 | * are met: 10 | * 1. Redistributions of source code must retain the above copyright 11 | * notice, this list of conditions and the following disclaimer. 12 | * 2. Redistributions in binary form must reproduce the above copyright 13 | * notice, this list of conditions and the following disclaimer in the 14 | * documentation and/or other materials provided with the distribution. 15 | * 3. Neither the name of the University nor the names of its contributors 16 | * may be used to endorse or promote products derived from this software 17 | * without specific prior written permission. 18 | * 19 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 20 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 21 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 22 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 23 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 24 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 25 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 26 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 27 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 28 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29 | * SUCH DAMAGE. 30 | */ 31 | 32 | #include 33 | __FBSDID("$FreeBSD$"); 34 | 35 | #include 36 | 37 | char * 38 | strrchr(const char *cp, int ch) 39 | { 40 | char *p, *save; 41 | 42 | p = __DECONST(char *, cp); 43 | for (save = NULL;; ++p) { 44 | if (*p == ch) 45 | save = p; 46 | if (*p == '\0') 47 | return (save); 48 | } 49 | /* NOTREACHED */ 50 | } 51 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/tools/boards-manager/packbm.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | ARCHIVE=/tmp/MuraxArduino.zip 3 | ARDUINODIR=~/MuraxArduino 4 | TOOLDIR=$(pwd) 5 | 6 | cd /tmp 7 | rm -rf arduino 8 | ln -sf "${ARDUINODIR}" arduino 9 | 10 | rm -f $ARCHIVE 11 | zip -r $ARCHIVE arduino/libraries 12 | rm -rf pack 13 | mkdir -p pack 14 | cd pack 15 | ln -s ../arduino/hardware/fpga/f32c arduino 16 | zip -r $ARCHIVE arduino/cores arduino/programmers.txt arduino/system arduino/variants arduino/tools 17 | cd .. 18 | rm -rf pack2 19 | mkdir -p pack2 20 | cd pack2 21 | ln -s ../arduino/hardware/fpga/f32c/tools/boards-manager arduino 22 | zip -r $ARCHIVE arduino/platform.txt arduino/boards.txt 23 | cd /tmp 24 | rm -rf arduino 25 | unzip $ARCHIVE 26 | rm -f $ARCHIVE 27 | zip -r $ARCHIVE arduino 28 | sha256sum $ARCHIVE 29 | ls -al $ARCHIVE 30 | 31 | -------------------------------------------------------------------------------- /hardware/fpga/f32c/variants/test/toplevel.bin: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/lawrie/MuraxArduino/02c2752e79e78b5661af4c1cc5c1caf22c24504a/hardware/fpga/f32c/variants/test/toplevel.bin -------------------------------------------------------------------------------- /libraries/EEPROM/EEPROM.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | bool eeprom_check() { 5 | Wire.beginTransmission(EEPROM_ADDRESS); 6 | return (Wire.endTransmission() == 0); 7 | } 8 | 9 | uint8_t eeprom_read_byte(int idx) { 10 | Wire.beginTransmission(EEPROM_ADDRESS); 11 | Wire.write((byte) (idx >> 8)); // Set address 12 | Wire.write((byte) idx); 13 | Wire.endTransmission(); 14 | 15 | Wire.requestFrom(EEPROM_ADDRESS, 1); 16 | 17 | return Wire.read(); 18 | } 19 | 20 | void eeprom_write_byte(int idx, int in) { 21 | Wire.beginTransmission(EEPROM_ADDRESS); 22 | Wire.write((byte) (idx >> 8)); 23 | Wire.write((byte) idx); 24 | Wire.write(in); 25 | Wire.endTransmission(); 26 | delay(10); 27 | } 28 | 29 | EEPROMClass EEPROM; 30 | -------------------------------------------------------------------------------- /libraries/Firmata/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | -------------------------------------------------------------------------------- /libraries/Firmata/examples/EchoString/EchoString.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Firmata is a generic protocol for communicating with microcontrollers 3 | * from software on a host computer. It is intended to work with 4 | * any host computer software package. 5 | * 6 | * To download a host software package, please click on the following link 7 | * to open the download page in your default browser. 8 | * 9 | * http://firmata.org/wiki/Download 10 | */ 11 | 12 | /* This sketch accepts strings and raw sysex messages and echos them back. 13 | * 14 | * This example code is in the public domain. 15 | */ 16 | #include 17 | 18 | void stringCallback(char *myString) 19 | { 20 | Firmata.sendString(myString); 21 | } 22 | 23 | 24 | void sysexCallback(byte command, byte argc, byte *argv) 25 | { 26 | Firmata.sendSysex(command, argc, argv); 27 | } 28 | 29 | void setup() 30 | { 31 | Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); 32 | Firmata.attach(STRING_DATA, stringCallback); 33 | Firmata.attach(START_SYSEX, sysexCallback); 34 | Firmata.begin(57600); 35 | } 36 | 37 | void loop() 38 | { 39 | while (Firmata.available()) { 40 | Firmata.processInput(); 41 | } 42 | } 43 | 44 | 45 | -------------------------------------------------------------------------------- /libraries/Firmata/examples/ServoFirmata/ServoFirmata.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Firmata is a generic protocol for communicating with microcontrollers 3 | * from software on a host computer. It is intended to work with 4 | * any host computer software package. 5 | * 6 | * To download a host software package, please click on the following link 7 | * to open the download page in your default browser. 8 | * 9 | * http://firmata.org/wiki/Download 10 | */ 11 | 12 | /* This firmware supports as many servos as possible using the Servo library 13 | * included in Arduino 0017 14 | * 15 | * This example code is in the public domain. 16 | */ 17 | 18 | #include 19 | #include 20 | 21 | Servo servos[MAX_SERVOS]; 22 | byte servoPinMap[TOTAL_PINS]; 23 | byte servoCount = 0; 24 | 25 | void analogWriteCallback(byte pin, int value) 26 | { 27 | if (IS_PIN_DIGITAL(pin)) { 28 | servos[servoPinMap[pin]].write(value); 29 | } 30 | } 31 | 32 | void systemResetCallback() 33 | { 34 | servoCount = 0; 35 | } 36 | 37 | void setup() 38 | { 39 | byte pin; 40 | 41 | Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); 42 | Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); 43 | Firmata.attach(SYSTEM_RESET, systemResetCallback); 44 | 45 | Firmata.begin(57600); 46 | systemResetCallback(); 47 | 48 | // attach servos from first digital pin up to max number of 49 | // servos supported for the board 50 | for (pin = 0; pin < TOTAL_PINS; pin++) { 51 | if (IS_PIN_DIGITAL(pin)) { 52 | if (servoCount < MAX_SERVOS) { 53 | servoPinMap[pin] = servoCount; 54 | servos[servoPinMap[pin]].attach(PIN_TO_DIGITAL(pin)); 55 | servoCount++; 56 | } 57 | } 58 | } 59 | } 60 | 61 | void loop() 62 | { 63 | while (Firmata.available()) 64 | Firmata.processInput(); 65 | } 66 | -------------------------------------------------------------------------------- /libraries/Firmata/examples/SimpleAnalogFirmata/SimpleAnalogFirmata.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Firmata is a generic protocol for communicating with microcontrollers 3 | * from software on a host computer. It is intended to work with 4 | * any host computer software package. 5 | * 6 | * To download a host software package, please click on the following link 7 | * to open the download page in your default browser. 8 | * 9 | * http://firmata.org/wiki/Download 10 | */ 11 | 12 | /* Supports as many analog inputs and analog PWM outputs as possible. 13 | * 14 | * This example code is in the public domain. 15 | */ 16 | #include 17 | 18 | byte analogPin = 0; 19 | 20 | void analogWriteCallback(byte pin, int value) 21 | { 22 | if (IS_PIN_PWM(pin)) { 23 | pinMode(PIN_TO_DIGITAL(pin), OUTPUT); 24 | analogWrite(PIN_TO_PWM(pin), value); 25 | } 26 | } 27 | 28 | void setup() 29 | { 30 | Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); 31 | Firmata.attach(ANALOG_MESSAGE, analogWriteCallback); 32 | Firmata.begin(57600); 33 | } 34 | 35 | void loop() 36 | { 37 | while (Firmata.available()) { 38 | Firmata.processInput(); 39 | } 40 | // do one analogRead per loop, so if PC is sending a lot of 41 | // analog write messages, we will only delay 1 analogRead 42 | Firmata.sendAnalog(analogPin, analogRead(analogPin)); 43 | analogPin = analogPin + 1; 44 | if (analogPin >= TOTAL_ANALOG_PINS) analogPin = 0; 45 | } 46 | 47 | -------------------------------------------------------------------------------- /libraries/Firmata/examples/SimpleDigitalFirmata/SimpleDigitalFirmata.ino: -------------------------------------------------------------------------------- 1 | /* 2 | * Firmata is a generic protocol for communicating with microcontrollers 3 | * from software on a host computer. It is intended to work with 4 | * any host computer software package. 5 | * 6 | * To download a host software package, please click on the following link 7 | * to open the download page in your default browser. 8 | * 9 | * http://firmata.org/wiki/Download 10 | */ 11 | 12 | /* Supports as many digital inputs and outputs as possible. 13 | * 14 | * This example code is in the public domain. 15 | */ 16 | #include 17 | 18 | byte previousPIN[TOTAL_PORTS]; // PIN means PORT for input 19 | byte previousPORT[TOTAL_PORTS]; 20 | 21 | void outputPort(byte portNumber, byte portValue) 22 | { 23 | // only send the data when it changes, otherwise you get too many messages! 24 | if (previousPIN[portNumber] != portValue) { 25 | Firmata.sendDigitalPort(portNumber, portValue); 26 | previousPIN[portNumber] = portValue; 27 | } 28 | } 29 | 30 | void setPinModeCallback(byte pin, int mode) { 31 | if (IS_PIN_DIGITAL(pin)) { 32 | pinMode(PIN_TO_DIGITAL(pin), mode); 33 | } 34 | } 35 | 36 | void digitalWriteCallback(byte port, int value) 37 | { 38 | byte i; 39 | byte currentPinValue, previousPinValue; 40 | 41 | if (port < TOTAL_PORTS && value != previousPORT[port]) { 42 | for (i = 0; i < 8; i++) { 43 | currentPinValue = (byte) value & (1 << i); 44 | previousPinValue = previousPORT[port] & (1 << i); 45 | if (currentPinValue != previousPinValue) { 46 | digitalWrite(i + (port * 8), currentPinValue); 47 | } 48 | } 49 | previousPORT[port] = value; 50 | } 51 | } 52 | 53 | void setup() 54 | { 55 | Firmata.setFirmwareVersion(FIRMATA_FIRMWARE_MAJOR_VERSION, FIRMATA_FIRMWARE_MINOR_VERSION); 56 | Firmata.attach(DIGITAL_MESSAGE, digitalWriteCallback); 57 | Firmata.attach(SET_PIN_MODE, setPinModeCallback); 58 | Firmata.begin(57600); 59 | } 60 | 61 | void loop() 62 | { 63 | byte i; 64 | 65 | for (i = 0; i < TOTAL_PORTS; i++) { 66 | outputPort(i, readPort(i, 0xff)); 67 | } 68 | 69 | while (Firmata.available()) { 70 | Firmata.processInput(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /libraries/Firmata/library.properties: -------------------------------------------------------------------------------- 1 | name=Firmata 2 | version=2.5.6 3 | author=Firmata Developers 4 | maintainer=https://github.com/firmata/arduino 5 | sentence=Enables the communication with computer apps using a standard serial protocol. For all Arduino/Genuino boards. 6 | paragraph=The Firmata library implements the Firmata protocol for communicating with software on the host computer. This allows you to write custom firmware without having to create your own protocol and objects for the programming environment that you are using. 7 | category=Device Control 8 | url=https://github.com/firmata/arduino 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/Firmata/release.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # use this script to package Firmata for distribution 4 | 5 | # package for Arduino 1.0.x 6 | mkdir -p temp/Firmata 7 | cp -r examples temp/Firmata 8 | cp -r extras temp/Firmata 9 | cp -r utility temp/Firmata 10 | cp *.cpp temp/Firmata 11 | cp *.h temp/Firmata 12 | cp keywords.txt temp/Firmata 13 | cp readme.md temp/Firmata 14 | cd temp 15 | find . -name "*.DS_Store" -type f -delete 16 | zip -r Firmata.zip ./Firmata/ 17 | cd .. 18 | mv ./temp/Firmata.zip Firmata-2.5.6.zip 19 | 20 | #package for Arduino 1.6.x 21 | cp library.properties temp/Firmata 22 | cd temp/Firmata 23 | mv readme.md ./extras/ 24 | mkdir src 25 | mv *.cpp ./src/ 26 | mv *.h ./src/ 27 | mv utility ./src/ 28 | cd .. 29 | find . -name "*.DS_Store" -type f -delete 30 | zip -r Firmata.zip ./Firmata/ 31 | cd .. 32 | mv ./temp/Firmata.zip Arduino-1.6.x-Firmata-2.5.6.zip 33 | rm -r ./temp 34 | -------------------------------------------------------------------------------- /libraries/Firmata/test/readme.md: -------------------------------------------------------------------------------- 1 | #Testing Firmata 2 | 3 | Tests tests are written using the [ArduinoUnit](https://github.com/mmurdoch/arduinounit) library (version 2.0). 4 | 5 | Follow the instructions in the [ArduinoUnit readme](https://github.com/mmurdoch/arduinounit/blob/master/readme.md) to install the library. 6 | 7 | Compile and upload the test sketch as you would any other sketch. Then open the 8 | Serial Monitor to view the test results. 9 | 10 | If you make changes to Firmata.cpp, run the tests in /test/ to ensure 11 | that your changes have not produced any unexpected errors. 12 | 13 | You should also perform manual tests against actual hardware. 14 | -------------------------------------------------------------------------------- /libraries/Firmata/utility/BLEStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation is in BLEStream.h to avoid linker issues. 3 | */ 4 | -------------------------------------------------------------------------------- /libraries/Firmata/utility/EthernetClientStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation is in EthernetClientStream.h to avoid linker issues. 3 | */ 4 | -------------------------------------------------------------------------------- /libraries/Firmata/utility/FirmataFeature.h: -------------------------------------------------------------------------------- 1 | /* 2 | FirmataFeature.h 3 | Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved. 4 | Copyright (C) 2010-2011 Paul Stoffregen. All rights reserved. 5 | Copyright (C) 2009 Shigeru Kobayashi. All rights reserved. 6 | Copyright (C) 2013 Norbert Truchsess. All rights reserved. 7 | Copyright (C) 2009-2016 Jeff Hoefs. All rights reserved. 8 | 9 | This library is free software; you can redistribute it and/or 10 | modify it under the terms of the GNU Lesser General Public 11 | License as published by the Free Software Foundation; either 12 | version 2.1 of the License, or (at your option) any later version. 13 | 14 | Interface for Firmata feature classes. 15 | 16 | This version of FirmataFeature.h differs from the ConfigurableFirmata 17 | version in the following ways: 18 | 19 | - Imports Firmata.h rather than ConfigurableFirmata.h 20 | 21 | See file LICENSE.txt for further informations on licensing terms. 22 | */ 23 | 24 | #ifndef FirmataFeature_h 25 | #define FirmataFeature_h 26 | 27 | #include 28 | 29 | class FirmataFeature 30 | { 31 | public: 32 | virtual void handleCapability(byte pin) = 0; 33 | virtual boolean handlePinMode(byte pin, int mode) = 0; 34 | virtual boolean handleSysex(byte command, byte argc, byte* argv) = 0; 35 | virtual void reset() = 0; 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /libraries/Firmata/utility/WiFiStream.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Implementation is in WiFiStream.h to avoid linker issues. Legacy WiFi and modern WiFi101 both define WiFiClass which 3 | * will cause linker errors whenever Firmata.h is included. 4 | */ 5 | -------------------------------------------------------------------------------- /libraries/Firmata/utility/firmataDebug.h: -------------------------------------------------------------------------------- 1 | #ifndef FIRMATA_DEBUG_H 2 | #define FIRMATA_DEBUG_H 3 | 4 | #ifdef SERIAL_DEBUG 5 | #define DEBUG_BEGIN(baud) Serial.begin(baud); while(!Serial) {;} 6 | #define DEBUG_PRINTLN(x) Serial.println (x); Serial.flush() 7 | #define DEBUG_PRINT(x) Serial.print (x) 8 | #else 9 | #define DEBUG_BEGIN(baud) 10 | #define DEBUG_PRINTLN(x) 11 | #define DEBUG_PRINT(x) 12 | #endif 13 | 14 | #endif /* FIRMATA_DEBUG_H */ 15 | -------------------------------------------------------------------------------- /libraries/LedStrip/LedStrip.cpp: -------------------------------------------------------------------------------- 1 | #include "LedStrip.h" 2 | #include 3 | 4 | LedStrip::LedStrip(uint16_t n, uint8_t p) : 5 | brightness(0) { 6 | updateLength(n); 7 | setPin(p); 8 | } 9 | 10 | void LedStrip::begin(void) { 11 | pinMode(pin, OUTPUT); 12 | Mux.set(12); 13 | } 14 | 15 | void LedStrip::updateLength(uint16_t n) { 16 | numLEDs = n; 17 | } 18 | 19 | void LedStrip::show(void) {} 20 | 21 | void LedStrip::setPixelColor( uint16_t n, uint8_t r, uint8_t g, uint8_t b) { 22 | setPixelColor(n, Color(r, g, b)); 23 | } 24 | 25 | void LedStrip::setPixelColor(uint16_t n, uint32_t c) { 26 | LEDS_PIXEL = c; 27 | LEDS_ADDR = n; 28 | } 29 | 30 | void LedStrip::fill(uint32_t c, uint16_t first, uint16_t count) { 31 | uint16_t i, end; 32 | 33 | if(first >= numLEDs) { 34 | return; 35 | } 36 | 37 | if(count == 0) { 38 | end = numLEDs; 39 | } else { 40 | end = first + count; 41 | if(end > numLEDs) end = numLEDs; 42 | } 43 | 44 | for(i = first; i < end; i++) { 45 | this->setPixelColor(i, c); 46 | } 47 | } 48 | 49 | void LedStrip::setPin(uint8_t p) { 50 | pin = p; 51 | } 52 | 53 | void LedStrip::setBrightness(uint8_t b) { 54 | brightness = b; 55 | } 56 | 57 | void LedStrip::clear(void) { 58 | LEDS_PIXEL = 0; 59 | for (int i=0;i 2 | 3 | unsigned long MsTimer2::msecs; 4 | void (*MsTimer2::func)(); 5 | 6 | void MsTimer2::set(unsigned long ms, void (*f)()) { 7 | 8 | msecs = (ms == 0 ? 1 : ms); 9 | func = f; 10 | 11 | TIMER_INTERRUPT->MASKS = 0; 12 | TIMER_PRESCALER->LIMIT = 50000-1; //1 ms rate 13 | TIMER_INTERRUPT->PENDINGS = 0xF; 14 | 15 | TIMER_A->VALUE = 0; 16 | TIMER_A->LIMIT = msecs -1; 17 | TIMER_A->CLEARS_TICKS = 0x00010002; 18 | 19 | IO_TIMER_INTERRUPT = (uint32_t) f; 20 | } 21 | 22 | void MsTimer2::start() { 23 | TIMER_INTERRUPT->MASKS = 0x1; 24 | } 25 | 26 | 27 | void MsTimer2::stop() { 28 | TIMER_INTERRUPT->MASKS = 0x0; 29 | } 30 | 31 | -------------------------------------------------------------------------------- /libraries/MsTimer2/MsTimer2.h: -------------------------------------------------------------------------------- 1 | #ifndef MsTimer2_h 2 | #define MsTimer2_h 3 | 4 | #include 5 | 6 | #define TIMER_PRESCALER ((Prescaler_Reg*) (IO_TIMER + 0x00)) 7 | #define TIMER_INTERRUPT ((InterruptCtrl_Reg*) (IO_TIMER + 0x10)) 8 | #define TIMER_A ((Timer_Reg*) (IO_TIMER + 0x40)) 9 | #define TIMER_B ((Timer_Reg*) (IO_TIMER + 0x50)) 10 | 11 | #define IO_TIMER_INTERRUPT (*(volatile uint32_t*)0x80002000) 12 | 13 | typedef struct 14 | { 15 | volatile uint32_t LIMIT; 16 | } Prescaler_Reg; 17 | 18 | 19 | typedef struct 20 | { 21 | volatile uint32_t CLEARS_TICKS; 22 | volatile uint32_t LIMIT; 23 | volatile uint32_t VALUE; 24 | } Timer_Reg; 25 | 26 | typedef struct 27 | { 28 | volatile uint32_t PENDINGS; 29 | volatile uint32_t MASKS; 30 | } InterruptCtrl_Reg; 31 | 32 | 33 | namespace MsTimer2 { 34 | extern unsigned long msecs; 35 | extern void (*func)(); 36 | 37 | void set(unsigned long ms, void (*f)()); 38 | void start(); 39 | void stop(); 40 | } 41 | 42 | #endif 43 | -------------------------------------------------------------------------------- /libraries/MsTimer2/examples/FlashLed/FlashLed.ino: -------------------------------------------------------------------------------- 1 | /* 2 | MsTimer2 is a small and very easy to use library to interface Timer2 with 3 | humans. It's called MsTimer2 because it "hardcodes" a resolution of 1 4 | millisecond on timer2 5 | For Details see: http://www.arduino.cc/playground/Main/MsTimer2 6 | */ 7 | #include 8 | 9 | // Switch on LED on and off each half second 10 | 11 | const int led_pin = LED_BUILTIN; // 1.0 built in LED pin var 12 | 13 | void flash() 14 | { 15 | static boolean output = HIGH; 16 | 17 | digitalWrite(led_pin, output); 18 | output = !output; 19 | } 20 | 21 | void setup() 22 | { 23 | pinMode(led_pin, OUTPUT); 24 | 25 | MsTimer2::set(500, flash); // 500ms period 26 | MsTimer2::start(); 27 | } 28 | 29 | void loop() 30 | { 31 | } 32 | -------------------------------------------------------------------------------- /libraries/Mux/Mux.cpp: -------------------------------------------------------------------------------- 1 | #include "Mux.h" 2 | #include 3 | 4 | void 5 | MuxClass::set(int pin) { 6 | (*(volatile uint32_t*)IO_MUX) |= (1 << pin); 7 | } 8 | 9 | void 10 | MuxClass::unset(int pin) { 11 | (*(volatile uint32_t*)IO_MUX) &= ~(1 << pin); 12 | } 13 | 14 | MuxClass Mux; 15 | -------------------------------------------------------------------------------- /libraries/Mux/Mux.h: -------------------------------------------------------------------------------- 1 | #ifndef _MUX_CLASS_ 2 | #define _MUX_CLASS_ 3 | 4 | class MuxClass { 5 | public: 6 | void set(int pin); 7 | void unset(int pin); 8 | }; 9 | 10 | extern MuxClass Mux; 11 | 12 | #endif 13 | 14 | -------------------------------------------------------------------------------- /libraries/Quadrature/Quadrature.cpp: -------------------------------------------------------------------------------- 1 | #include "Quadrature.h" 2 | 3 | int 4 | QuadratureClass::read(void) { 5 | return IO_QUADRATURE_VALUE; 6 | } 7 | 8 | QuadratureClass Quadrature; 9 | -------------------------------------------------------------------------------- /libraries/Quadrature/Quadrature.h: -------------------------------------------------------------------------------- 1 | #ifndef _QUADRATURE_CLASS_ 2 | #define _QUADRATURE_CLASS_ 3 | 4 | #define IO_QUADRATURE_VALUE (*(volatile uint32_t*) IO_QUADRATURE) 5 | 6 | #include 7 | 8 | class QuadratureClass { 9 | public: 10 | int read(void); 11 | }; 12 | 13 | extern QuadratureClass Quadrature; 14 | 15 | #endif 16 | 17 | -------------------------------------------------------------------------------- /libraries/Quadrature/examples/Quadtest/Quadtest.ino: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | void setup() { 5 | pinMode(QUADRATURE_QUAD_A, INPUT); 6 | pinMode(QUADRATURE_QUAD_B, INPUT); 7 | } 8 | 9 | void loop() { 10 | SevenSegment.write(Quadrature.read()); 11 | } 12 | -------------------------------------------------------------------------------- /libraries/SD/README.adoc: -------------------------------------------------------------------------------- 1 | = SD Library for Arduino = 2 | 3 | The SD library allows for reading from and writing to SD cards. 4 | 5 | For more information about this library please visit us at 6 | http://www.arduino.cc/en/Reference/SD 7 | 8 | == License == 9 | 10 | Copyright (C) 2009 by William Greiman 11 | Copyright (c) 2010 SparkFun Electronics 12 | 13 | This program is free software: you can redistribute it and/or modify 14 | it under the terms of the GNU General Public License as published by 15 | the Free Software Foundation, either version 3 of the License, or 16 | (at your option) any later version. 17 | 18 | This program is distributed in the hope that it will be useful, 19 | but WITHOUT ANY WARRANTY; without even the implied warranty of 20 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 21 | GNU General Public License for more details. 22 | 23 | You should have received a copy of the GNU General Public License 24 | along with this program. If not, see . 25 | -------------------------------------------------------------------------------- /libraries/SD/examples/Datalogger/Datalogger.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card datalogger 3 | 4 | This example shows how to log data from three analog sensors 5 | to an SD card using the SD library. 6 | 7 | The circuit: 8 | * analog sensors on analog ins 0, 1, and 2 9 | * SD card attached to SPI bus as follows: 10 | ** MOSI - pin 11 11 | ** MISO - pin 12 12 | ** CLK - pin 13 13 | ** CS - pin 4 14 | 15 | created 24 Nov 2010 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | const int chipSelect = 4; 27 | 28 | void setup() 29 | { 30 | // Open serial communications and wait for port to open: 31 | Serial.begin(9600); 32 | while (!Serial) { 33 | ; // wait for serial port to connect. Needed for Leonardo only 34 | } 35 | 36 | 37 | Serial.print("Initializing SD card..."); 38 | 39 | // see if the card is present and can be initialized: 40 | if (!SD.begin(chipSelect)) { 41 | Serial.println("Card failed, or not present"); 42 | // don't do anything more: 43 | return; 44 | } 45 | Serial.println("card initialized."); 46 | } 47 | 48 | void loop() 49 | { 50 | // make a string for assembling the data to log: 51 | String dataString = ""; 52 | 53 | // read three sensors and append to the string: 54 | for (int analogPin = 0; analogPin < 3; analogPin++) { 55 | int sensor = analogRead(analogPin); 56 | dataString += String(sensor); 57 | if (analogPin < 2) { 58 | dataString += ","; 59 | } 60 | } 61 | 62 | // open the file. note that only one file can be open at a time, 63 | // so you have to close this one before opening another. 64 | File dataFile = SD.open("datalog.txt", FILE_WRITE); 65 | 66 | // if the file is available, write to it: 67 | if (dataFile) { 68 | dataFile.println(dataString); 69 | dataFile.close(); 70 | // print to the serial port too: 71 | Serial.println(dataString); 72 | } 73 | // if the file isn't open, pop up an error: 74 | else { 75 | Serial.println("error opening datalog.txt"); 76 | } 77 | } 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /libraries/SD/examples/DumpFile/DumpFile.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card file dump 3 | 4 | This example shows how to read a file from the SD card using the 5 | SD library and send it over the serial port. 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 11 10 | ** MISO - pin 12 11 | ** CLK - pin 13 12 | ** CS - pin 4 13 | 14 | created 22 December 2010 15 | by Limor Fried 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | 19 | This example code is in the public domain. 20 | 21 | */ 22 | 23 | #include 24 | #include 25 | 26 | const int chipSelect = 4; 27 | 28 | void setup() 29 | { 30 | // Open serial communications and wait for port to open: 31 | Serial.begin(9600); 32 | while (!Serial) { 33 | ; // wait for serial port to connect. Needed for Leonardo only 34 | } 35 | 36 | 37 | Serial.print("Initializing SD card..."); 38 | 39 | // see if the card is present and can be initialized: 40 | if (!SD.begin(chipSelect)) { 41 | Serial.println("Card failed, or not present"); 42 | // don't do anything more: 43 | return; 44 | } 45 | Serial.println("card initialized."); 46 | 47 | // open the file. note that only one file can be open at a time, 48 | // so you have to close this one before opening another. 49 | File dataFile = SD.open("datalog.txt"); 50 | 51 | // if the file is available, write to it: 52 | if (dataFile) { 53 | while (dataFile.available()) { 54 | Serial.write(dataFile.read()); 55 | } 56 | dataFile.close(); 57 | } 58 | // if the file isn't open, pop up an error: 59 | else { 60 | Serial.println("error opening datalog.txt"); 61 | } 62 | } 63 | 64 | void loop() 65 | { 66 | } 67 | 68 | -------------------------------------------------------------------------------- /libraries/SD/examples/Files/Files.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card basic file example 3 | 4 | This example shows how to create and destroy an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 11 8 | ** MISO - pin 12 9 | ** CLK - pin 13 10 | ** CS - pin 4 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | 17 | This example code is in the public domain. 18 | 19 | */ 20 | #include 21 | #include 22 | 23 | File myFile; 24 | 25 | void setup() 26 | { 27 | // Open serial communications and wait for port to open: 28 | Serial.begin(9600); 29 | while (!Serial) { 30 | ; // wait for serial port to connect. Needed for Leonardo only 31 | } 32 | 33 | 34 | Serial.print("Initializing SD card..."); 35 | 36 | if (!SD.begin(4)) { 37 | Serial.println("initialization failed!"); 38 | return; 39 | } 40 | Serial.println("initialization done."); 41 | 42 | if (SD.exists("example.txt")) { 43 | Serial.println("example.txt exists."); 44 | } 45 | else { 46 | Serial.println("example.txt doesn't exist."); 47 | } 48 | 49 | // open a new file and immediately close it: 50 | Serial.println("Creating example.txt..."); 51 | myFile = SD.open("example.txt", FILE_WRITE); 52 | myFile.close(); 53 | 54 | // Check to see if the file exists: 55 | if (SD.exists("example.txt")) { 56 | Serial.println("example.txt exists."); 57 | } 58 | else { 59 | Serial.println("example.txt doesn't exist."); 60 | } 61 | 62 | // delete the file: 63 | Serial.println("Removing example.txt..."); 64 | SD.remove("example.txt"); 65 | 66 | if (SD.exists("example.txt")) { 67 | Serial.println("example.txt exists."); 68 | } 69 | else { 70 | Serial.println("example.txt doesn't exist."); 71 | } 72 | } 73 | 74 | void loop() 75 | { 76 | // nothing happens after setup finishes. 77 | } 78 | 79 | 80 | 81 | -------------------------------------------------------------------------------- /libraries/SD/examples/ReadWrite/ReadWrite.ino: -------------------------------------------------------------------------------- 1 | /* 2 | SD card read/write 3 | 4 | This example shows how to read and write data to and from an SD card file 5 | The circuit: 6 | * SD card attached to SPI bus as follows: 7 | ** MOSI - pin 11 8 | ** MISO - pin 12 9 | ** CLK - pin 13 10 | ** CS - pin 4 11 | 12 | created Nov 2010 13 | by David A. Mellis 14 | modified 9 Apr 2012 15 | by Tom Igoe 16 | 17 | This example code is in the public domain. 18 | 19 | */ 20 | 21 | #include 22 | #include 23 | 24 | File myFile; 25 | 26 | void setup() 27 | { 28 | // Open serial communications and wait for port to open: 29 | Serial.begin(9600); 30 | while (!Serial) { 31 | ; // wait for serial port to connect. Needed for Leonardo only 32 | } 33 | 34 | 35 | Serial.print("Initializing SD card..."); 36 | 37 | if (!SD.begin(4)) { 38 | Serial.println("initialization failed!"); 39 | return; 40 | } 41 | Serial.println("initialization done."); 42 | 43 | // open the file. note that only one file can be open at a time, 44 | // so you have to close this one before opening another. 45 | myFile = SD.open("test.txt", FILE_WRITE); 46 | 47 | // if the file opened okay, write to it: 48 | if (myFile) { 49 | Serial.print("Writing to test.txt..."); 50 | myFile.println("testing 1, 2, 3."); 51 | // close the file: 52 | myFile.close(); 53 | Serial.println("done."); 54 | } else { 55 | // if the file didn't open, print an error: 56 | Serial.println("error opening test.txt"); 57 | } 58 | 59 | // re-open the file for reading: 60 | myFile = SD.open("test.txt"); 61 | if (myFile) { 62 | Serial.println("test.txt:"); 63 | 64 | // read from the file until there's nothing else in it: 65 | while (myFile.available()) { 66 | Serial.write(myFile.read()); 67 | } 68 | // close the file: 69 | myFile.close(); 70 | } else { 71 | // if the file didn't open, print an error: 72 | Serial.println("error opening test.txt"); 73 | } 74 | } 75 | 76 | void loop() 77 | { 78 | // nothing happens after setup 79 | } 80 | 81 | 82 | -------------------------------------------------------------------------------- /libraries/SD/examples/listfiles/listfiles.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Listfiles 3 | 4 | This example shows how print out the files in a 5 | directory on a SD card 6 | 7 | The circuit: 8 | * SD card attached to SPI bus as follows: 9 | ** MOSI - pin 11 10 | ** MISO - pin 12 11 | ** CLK - pin 13 12 | ** CS - pin 4 13 | 14 | created Nov 2010 15 | by David A. Mellis 16 | modified 9 Apr 2012 17 | by Tom Igoe 18 | modified 2 Feb 2014 19 | by Scott Fitzgerald 20 | 21 | This example code is in the public domain. 22 | 23 | */ 24 | #include 25 | #include 26 | 27 | File root; 28 | 29 | void setup() 30 | { 31 | // Open serial communications and wait for port to open: 32 | Serial.begin(9600); 33 | while (!Serial) { 34 | ; // wait for serial port to connect. Needed for Leonardo only 35 | } 36 | 37 | Serial.print("Initializing SD card..."); 38 | 39 | if (!SD.begin(4)) { 40 | Serial.println("initialization failed!"); 41 | return; 42 | } 43 | Serial.println("initialization done."); 44 | 45 | root = SD.open("/"); 46 | 47 | printDirectory(root, 0); 48 | 49 | Serial.println("done!"); 50 | } 51 | 52 | void loop() 53 | { 54 | // nothing happens after setup finishes. 55 | } 56 | 57 | void printDirectory(File dir, int numTabs) { 58 | while(true) { 59 | 60 | File entry = dir.openNextFile(); 61 | if (! entry) { 62 | // no more files 63 | break; 64 | } 65 | for (uint8_t i=0; i 5 | sentence=Enables reading and writing on SD cards. For all Arduino boards. 6 | paragraph=Once an SD memory card is connected to the SPI interfare of the Arduino board you are enabled to create files and read/write on them. You can also move through directories on the SD card. 7 | category=Data Storage 8 | url=http://www.arduino.cc/en/Reference/SD 9 | architectures=* 10 | -------------------------------------------------------------------------------- /libraries/SD/src/README.txt: -------------------------------------------------------------------------------- 1 | 2 | ** SD - a slightly more friendly wrapper for sdfatlib ** 3 | 4 | This library aims to expose a subset of SD card functionality in the 5 | form of a higher level "wrapper" object. 6 | 7 | License: GNU General Public License V3 8 | (Because sdfatlib is licensed with this.) 9 | 10 | (C) Copyright 2010 SparkFun Electronics 11 | 12 | Now better than ever with optimization, multiple file support, directory handling, etc - ladyada! 13 | 14 | -------------------------------------------------------------------------------- /libraries/SD/src/utility/dirty_workaround.h: -------------------------------------------------------------------------------- 1 | #ifndef _DIRTY_WORKAROUND_H_ 2 | #define _DIRTY_WORKAROUND_H_ 3 | #define __arm__ 4 | 5 | #if 1 6 | #define SCK 10 7 | #define SS 11 8 | #define MOSI 13 9 | #define MISO 8 10 | #define softdelay() 11 | #endif 12 | 13 | #define SOFTWARE_SPI 14 | 15 | #define cli() noInterrupts() 16 | #define sei() interrupts() 17 | #define fastDigitalWrite(a,b) digitalWrite(a,b) 18 | #define fastDigitalRead(a) digitalRead(a) 19 | #endif 20 | -------------------------------------------------------------------------------- /libraries/SPI/SPI.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | SPIClass SPI; 5 | 6 | #if defined(IO_SPI_MASTER_A) 7 | SPIClass SPI1(1); 8 | #endif 9 | 10 | SPIClass::SPIClass(uint8_t spi_bus) 11 | :_spi_num(spi_bus) 12 | ,_spi(NULL) 13 | ,_ss(-1) 14 | ,_divider(5) 15 | {} 16 | 17 | void SPIClass::begin(int8_t ss) 18 | { 19 | int start_pin = SPI_MASTER_SCLK; 20 | int spi_mux = SPI_MASTER_MUX; 21 | 22 | #if defined(IO_SPI_MASTER_A) 23 | if (_spi_num == 1) { 24 | start_pin = SPI_MASTER_A_SCLK; 25 | spi_mux = SPI_MASTER_A_MUX; 26 | } 27 | #endif 28 | 29 | // Set SPI pins 30 | for(int i=0;i<4;i++) pinMode(start_pin + i, (i == 2 ? INPUT : OUTPUT)); 31 | 32 | // Set Mux 5 33 | (*(volatile uint32_t*)IO_MUX) |= (1 << spi_mux); 34 | 35 | // Initialise SPI peripheral 36 | _ss = ss; 37 | _spi = (volatile uint32_t *)(IO_SPI_MASTER + (_spi_num * 0x1000)); 38 | _spi[3] = _divider; 39 | _spi[4] = 500; // setup 40 | _spi[5] = 500; // hold 41 | _spi[6] = 500; //disable 42 | } 43 | 44 | void SPIClass::end() { 45 | } 46 | 47 | void SPIClass::setClockDivider(uint32_t divider) 48 | { 49 | _divider = divider; 50 | _spi[3] = _divider; 51 | } 52 | 53 | void SPIClass::setBitOrder(uint8_t bitOrder) { 54 | } 55 | 56 | void SPIClass::setDataMode(uint8_t dataMode) { 57 | _spi[2] = dataMode; 58 | } 59 | 60 | uint8_t SPIClass::transfer(uint8_t data) 61 | { 62 | _spi[0] = (data | 0x01000000); // Send and push reply 63 | 64 | while(1) { 65 | uint32_t r = ((volatile uint32_t *)_spi)[0]; 66 | if (!(r & SPI_RX_VALID)) return r & 0xff; 67 | } 68 | } 69 | 70 | void SPIClass::beginTransaction(SPISettings settings) { 71 | setClockDivider((F_CPU / settings._clock) / 2); 72 | setDataMode(settings._dataMode); 73 | beginTransaction(); 74 | } 75 | 76 | void SPIClass::beginTransaction() { 77 | _spi[0] = 0x11000000; 78 | } 79 | 80 | void SPIClass::endTransaction() { 81 | _spi[0] = 0x10000000; 82 | } 83 | 84 | -------------------------------------------------------------------------------- /libraries/SPI/SPI.h: -------------------------------------------------------------------------------- 1 | #ifndef _SPI_H 2 | #define _SPI_H 3 | 4 | #include 5 | 6 | // #define SPI_NOP __asm__ __volatile__ ("nop\n\t") 7 | #define SPI_NOP 8 | 9 | #if (_BYTE_ORDER == _LITTLE_ENDIAN) 10 | #define SPI_READY_MASK (1 << 8) 11 | #else 12 | #define SPI_READY_MASK (1 << 16) 13 | #endif 14 | 15 | #define SPI_LSBFIRST 0 16 | #define SPI_MSBFIRST 1 17 | 18 | #define SPI_MODE0 0x00 19 | #define SPI_MODE1 0x02 20 | #define SPI_MODE2 0x01 21 | #define SPI_MODE3 0x03 22 | 23 | #define SPI_DEFAULT 0 24 | 25 | #define SPI_RX_VALID (1 << 31) 26 | 27 | class SPISettings 28 | { 29 | public: 30 | SPISettings() :_clock(400000), _bitOrder(SPI_MSBFIRST), _dataMode(SPI_MODE0) {} 31 | SPISettings(uint32_t clock, uint8_t bitOrder, uint8_t dataMode) :_clock(clock), _bitOrder(bitOrder), _dataMode(dataMode) {} 32 | uint32_t _clock; 33 | uint8_t _bitOrder; 34 | uint8_t _dataMode; 35 | }; 36 | 37 | class SPIClass 38 | { 39 | private: 40 | int8_t _spi_num; 41 | volatile uint32_t * _spi; 42 | int8_t _ss; 43 | uint8_t _divider; 44 | 45 | public: 46 | SPIClass(uint8_t spi_bus=SPI_DEFAULT); 47 | void begin(int8_t ss=-1); 48 | void end(); 49 | 50 | void setClockDivider(uint32_t divider); 51 | void setBitOrder(uint8_t bitOrder); 52 | void setDataMode(uint8_t dataMode); 53 | 54 | uint8_t transfer(uint8_t _data); 55 | void beginTransaction(); 56 | void beginTransaction(SPISettings settings); 57 | void endTransaction(); 58 | }; 59 | 60 | extern SPIClass SPI; 61 | 62 | #if defined(IO_SPI_MASTER_A) 63 | extern SPIClass SPI1; 64 | #endif 65 | 66 | #endif // _SPI_H 67 | -------------------------------------------------------------------------------- /libraries/SPI/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map SPI 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | SPI KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | begin KEYWORD2 15 | end KEYWORD2 16 | transfer KEYWORD2 17 | setBitOrder KEYWORD2 18 | setDataMode KEYWORD2 19 | setClockDivider KEYWORD2 20 | setMOSI KEYWORD2 21 | setMISO KEYWORD2 22 | setSCK KEYWORD2 23 | usingInterrupt KEYWORD2 24 | beginTransaction KEYWORD2 25 | endTransaction KEYWORD2 26 | SPISettings KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | SPI_CLOCK_DIV4 LITERAL1 32 | SPI_CLOCK_DIV16 LITERAL1 33 | SPI_CLOCK_DIV64 LITERAL1 34 | SPI_CLOCK_DIV128 LITERAL1 35 | SPI_CLOCK_DIV2 LITERAL1 36 | SPI_CLOCK_DIV8 LITERAL1 37 | SPI_CLOCK_DIV32 LITERAL1 38 | SPI_MODE0 LITERAL1 39 | SPI_MODE1 LITERAL1 40 | SPI_MODE2 LITERAL1 41 | SPI_MODE3 LITERAL1 42 | -------------------------------------------------------------------------------- /libraries/Servo/Servo.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include "Servo.h" 3 | 4 | Servo::Servo() { 5 | _pin = -1; 6 | } 7 | 8 | uint8_t Servo::attach(int pin) { 9 | _pin = pin; 10 | 11 | (*(volatile uint32_t*)IO_MUX) |= (1 << SERVO_MUX); 12 | 13 | pinMode(SERVO_PINS[pin], OUTPUT); 14 | 15 | return pin; 16 | } 17 | 18 | uint8_t Servo::attach(int pin, int min, int max) { 19 | _pin = pin; 20 | return pin; 21 | } 22 | 23 | void Servo::detach() { 24 | if (_pin >= 0) IO_SERVO_PULSE_LENGTH[_pin] = 0; 25 | } 26 | 27 | void Servo::write(int value) { 28 | if (_pin >= 0) IO_SERVO_PULSE_LENGTH[_pin] = map(value, 0, 180, MIN_PULSE_WIDTH, MAX_PULSE_WIDTH); 29 | } 30 | 31 | void Servo::writeMicroseconds(int value) { 32 | if (_pin >= 0) IO_SERVO_PULSE_LENGTH[_pin] = value; 33 | } 34 | 35 | int Servo::read() { // return the value as degrees 36 | if (_pin < 0) return 0; 37 | return map(IO_SERVO_PULSE_LENGTH[_pin], MIN_PULSE_WIDTH, MAX_PULSE_WIDTH, 0, 180); 38 | } 39 | 40 | int Servo::readMicroseconds() { 41 | if (_pin < 0) return 0; 42 | return IO_SERVO_PULSE_LENGTH[_pin]; 43 | } 44 | 45 | bool Servo::attached() { 46 | return (_pin >= 0); 47 | } 48 | 49 | -------------------------------------------------------------------------------- /libraries/Servo/Servo.h: -------------------------------------------------------------------------------- 1 | #ifndef Servo_h 2 | #define Servo_h 3 | 4 | #include 5 | 6 | #define MIN_PULSE_WIDTH 544 // the shortest pulse sent to a servo 7 | #define MAX_PULSE_WIDTH 2400 // the longest pulse sent to a servo 8 | #define DEFAULT_PULSE_WIDTH 1500 // default pulse width when servo is attached 9 | #define REFRESH_INTERVAL 20000 // minimum time to refresh servos in microseconds 10 | 11 | #define IO_SERVO_PULSE_LENGTH ((volatile uint32_t*) IO_SERVO) 12 | 13 | class Servo { 14 | public: 15 | Servo(); 16 | uint8_t attach(int pin); // attach the given pin to the next free channel, sets pinMode, returns channel number or 0 if failure 17 | uint8_t attach(int pin, int min, int max); // as above but also sets min and max values for writes. 18 | void detach(); 19 | void write(int value); // if value is < 200 its treated as an angle, otherwise as pulse width in microseconds 20 | void writeMicroseconds(int value); // Write pulse width in microseconds 21 | int read(); // returns current pulse width as an angle between 0 and 180 degrees 22 | int readMicroseconds(); // returns current pulse width in microseconds for this servo (was read_us() in first release) 23 | bool attached(); // return true if this servo is attached, otherwise false 24 | private: 25 | uint8_t _pin; 26 | }; 27 | #endif 28 | -------------------------------------------------------------------------------- /libraries/Servo/examples/Knob/Knob.ino: -------------------------------------------------------------------------------- 1 | /* 2 | Controlling a servo position using a potentiometer (variable resistor) 3 | by Michal Rinott 4 | 5 | modified on 8 Nov 2013 6 | by Scott Fitzgerald 7 | http://www.arduino.cc/en/Tutorial/Knob 8 | */ 9 | 10 | #include 11 | 12 | Servo myservo; // create servo object to control a servo 13 | 14 | int potpin = 0; // analog pin used to connect the potentiometer 15 | int val; // variable to read the value from the analog pin 16 | 17 | void setup() { 18 | myservo.attach(9); // attaches the servo on pin 9 to the servo object 19 | } 20 | 21 | void loop() { 22 | val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023) 23 | val = map(val, 0, 1023, 0, 180); // scale it to use it with the servo (value between 0 and 180) 24 | myservo.write(val); // sets the servo position according to the scaled value 25 | delay(15); // waits for the servo to get there 26 | } 27 | 28 | -------------------------------------------------------------------------------- /libraries/Servo/examples/Sweep/Sweep.ino: -------------------------------------------------------------------------------- 1 | /* Sweep 2 | by BARRAGAN 3 | This example code is in the public domain. 4 | 5 | modified 8 Nov 2013 6 | by Scott Fitzgerald 7 | http://www.arduino.cc/en/Tutorial/Sweep 8 | */ 9 | 10 | #include 11 | 12 | Servo myservo; // create servo object to control a servo 13 | // twelve servo objects can be created on most boards 14 | 15 | int pos = 0; // variable to store the servo position 16 | 17 | void setup() { 18 | myservo.attach(9); // attaches the servo on pin 9 to the servo object 19 | } 20 | 21 | void loop() { 22 | for (pos = 0; pos <= 180; pos += 1) { // goes from 0 degrees to 180 degrees 23 | // in steps of 1 degree 24 | myservo.write(pos); // tell servo to go to position in variable 'pos' 25 | delay(15); // waits 15ms for the servo to reach the position 26 | } 27 | for (pos = 180; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees 28 | myservo.write(pos); // tell servo to go to position in variable 'pos' 29 | delay(15); // waits 15ms for the servo to reach the position 30 | } 31 | } 32 | 33 | -------------------------------------------------------------------------------- /libraries/SevenSegment/SevenSegment.cpp: -------------------------------------------------------------------------------- 1 | #include "SevenSegment.h" 2 | 3 | void 4 | SevenSegmentClass::write(int data) { 5 | if (_channel == 0) { 6 | pinMode(SEVEN_SEGMENT_A_DIGIT_PIN, OUTPUT); 7 | for(int i=0;i<7;i++) pinMode(SEVEN_SEGMENT_A_SEG_PINS[i], OUTPUT); 8 | Mux.set(SEVEN_SEGMENT_A_MUX); 9 | } else if (_channel == 1) { 10 | pinMode(SEVEN_SEGMENT_B_DIGIT_PIN, OUTPUT); 11 | for(int i=0;i<7;i++) pinMode(SEVEN_SEGMENT_B_SEG_PINS[i], OUTPUT); 12 | Mux.set(SEVEN_SEGMENT_B_MUX); 13 | } 14 | 15 | IO_SEVEN_SEGMENT[_channel * 0x2000] = data; 16 | } 17 | 18 | SevenSegmentClass SevenSegment(0); 19 | -------------------------------------------------------------------------------- /libraries/SevenSegment/SevenSegment.h: -------------------------------------------------------------------------------- 1 | #ifndef _SEVEN_SEGMENT_CLASS_ 2 | #define _SEVEN_SEGMENT_CLASS_ 3 | 4 | #include 5 | #include 6 | 7 | #define IO_SEVEN_SEGMENT ((volatile uint32_t*) IO_SEVEN_SEGMENT_A) 8 | 9 | class SevenSegmentClass { 10 | public: 11 | SevenSegmentClass(uint8_t channel) : _channel(channel) {} 12 | void write(int data); 13 | private: 14 | uint8_t _channel; 15 | }; 16 | 17 | extern SevenSegmentClass SevenSegment; 18 | 19 | #endif 20 | 21 | -------------------------------------------------------------------------------- /libraries/Wire/examples/digital_potentiometer/digital_potentiometer.ino: -------------------------------------------------------------------------------- 1 | // I2C Digital Potentiometer 2 | // by Nicholas Zambetti 3 | // and Shawn Bonkowski 4 | 5 | // Demonstrates use of the Wire library 6 | // Controls AD5171 digital potentiometer via I2C/TWI 7 | 8 | // Created 31 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | // This example code is in the public domain. 13 | 14 | 15 | #include 16 | 17 | void setup() 18 | { 19 | Wire.begin(); // join i2c bus (address optional for master) 20 | } 21 | 22 | byte val = 0; 23 | 24 | void loop() 25 | { 26 | Wire.beginTransmission(44); // transmit to device #44 (0x2c) 27 | // device address is specified in datasheet 28 | Wire.write(byte(0x00)); // sends instruction byte 29 | Wire.write(val); // sends potentiometer value byte 30 | Wire.endTransmission(); // stop transmitting 31 | 32 | val++; // increment value 33 | if(val == 64) // if reached 64th position (max) 34 | { 35 | val = 0; // start over from lowest value 36 | } 37 | delay(500); 38 | } 39 | 40 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_reader/master_reader.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Reader 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Reads data from an I2C/TWI slave device 6 | // Refer to the "Wire Slave Sender" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | Serial.begin(9600); // start serial for output 19 | } 20 | 21 | void loop() 22 | { 23 | Wire.requestFrom(2, 6); // request 6 bytes from slave device #2 24 | 25 | while(Wire.available()) // slave may send less than requested 26 | { 27 | char c = Wire.read(); // receive a byte as character 28 | Serial.print(c); // print the character 29 | } 30 | 31 | delay(500); 32 | } 33 | -------------------------------------------------------------------------------- /libraries/Wire/examples/master_writer/master_writer.ino: -------------------------------------------------------------------------------- 1 | // Wire Master Writer 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Writes data to an I2C/TWI slave device 6 | // Refer to the "Wire Slave Receiver" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(); // join i2c bus (address optional for master) 18 | } 19 | 20 | byte x = 0; 21 | 22 | void loop() 23 | { 24 | Wire.beginTransmission(4); // transmit to device #4 25 | Wire.write("x is "); // sends five bytes 26 | Wire.write(x); // sends one byte 27 | Wire.endTransmission(); // stop transmitting 28 | 29 | x++; 30 | delay(500); 31 | } 32 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_receiver/slave_receiver.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Receiver 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Receives data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Writer" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(4); // join i2c bus with address #4 18 | Wire.onReceive(receiveEvent); // register event 19 | Serial.begin(9600); // start serial for output 20 | } 21 | 22 | void loop() 23 | { 24 | delay(100); 25 | } 26 | 27 | // function that executes whenever data is received from master 28 | // this function is registered as an event, see setup() 29 | void receiveEvent(int howMany) 30 | { 31 | while(1 < Wire.available()) // loop through all but the last 32 | { 33 | char c = Wire.read(); // receive byte as a character 34 | Serial.print(c); // print the character 35 | } 36 | int x = Wire.read(); // receive byte as an integer 37 | Serial.println(x); // print the integer 38 | } 39 | -------------------------------------------------------------------------------- /libraries/Wire/examples/slave_sender/slave_sender.ino: -------------------------------------------------------------------------------- 1 | // Wire Slave Sender 2 | // by Nicholas Zambetti 3 | 4 | // Demonstrates use of the Wire library 5 | // Sends data as an I2C/TWI slave device 6 | // Refer to the "Wire Master Reader" example for use with this 7 | 8 | // Created 29 March 2006 9 | 10 | // This example code is in the public domain. 11 | 12 | 13 | #include 14 | 15 | void setup() 16 | { 17 | Wire.begin(2); // join i2c bus with address #2 18 | Wire.onRequest(requestEvent); // register event 19 | } 20 | 21 | void loop() 22 | { 23 | delay(100); 24 | } 25 | 26 | // function that executes whenever data is requested by master 27 | // this function is registered as an event, see setup() 28 | void requestEvent() 29 | { 30 | Wire.write("hello "); // respond with message of 6 bytes 31 | // as expected by master 32 | } 33 | -------------------------------------------------------------------------------- /libraries/Wire/keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring Map For Wire 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | ####################################### 10 | # Methods and Functions (KEYWORD2) 11 | ####################################### 12 | 13 | begin KEYWORD2 14 | beginTransmission KEYWORD2 15 | endTransmission KEYWORD2 16 | requestFrom KEYWORD2 17 | send KEYWORD2 18 | receive KEYWORD2 19 | onReceive KEYWORD2 20 | onRequest KEYWORD2 21 | 22 | ####################################### 23 | # Instances (KEYWORD2) 24 | ####################################### 25 | 26 | Wire KEYWORD2 27 | 28 | ####################################### 29 | # Constants (LITERAL1) 30 | ####################################### 31 | 32 | --------------------------------------------------------------------------------