diff --git a/boards.txt b/boards.txt index 7d0f0d6..3c16f4b 100644 --- a/boards.txt +++ b/boards.txt @@ -15,8 +15,6 @@ m1.build.variant=standard m1.menu.clksrc=400MHz FPGA Clock m1.menu.clksrc.fpga.build.f_cpu=400000000L -#m1.build.mcu=rv64gc -#m1.build.mabi=ilp64 m1.build.mcmodel=medany #"The 'core' file directory for this board, in ./cores diff --git a/cores/arduino/Arduino.h b/cores/arduino/Arduino.h index 455bcfe..25253d3 100644 --- a/cores/arduino/Arduino.h +++ b/cores/arduino/Arduino.h @@ -33,14 +33,18 @@ //#include #include "binary.h" -//#include "pins_arduino.h" +#include "pins_arduino.h" + +#include "fpioa.h" +#include "gpiohs.h" +#include "gpio.h" +#include "gpio_common.h" #ifdef __cplusplus extern "C"{ #endif // __cplusplus - -//#include "wiring.h" -//#include "wiring_constants.h" +#include "wiring.h" +#include "wiring_constants.h" #define SystemCoreClock F_CPU @@ -77,7 +81,7 @@ void noTone(uint8_t _pin); // Include board variant //#include "variant.h" -//#include "wiring_digital.h" +#include "wiring_digital.h" //#include "wiring_analog.h" //#include "wiring_shift.h" //#include "WInterrupts.h" diff --git a/cores/arduino/main.cpp b/cores/arduino/main.cpp index b345b3b..bbf10e4 100644 --- a/cores/arduino/main.cpp +++ b/cores/arduino/main.cpp @@ -1,7 +1,7 @@ #define ARDUINO_MAIN #include "Arduino.h" -//#include "encoding.h" +#include "encoding.h" #define cmb() __asm__ __volatile__ ("" ::: "memory") @@ -12,8 +12,8 @@ */ int main( void ) { - //init(); - + pll_init(); + fpioa_init(); setup(); do { diff --git a/cores/arduino/wiring.c b/cores/arduino/wiring.c new file mode 100644 index 0000000..4264bb9 --- /dev/null +++ b/cores/arduino/wiring.c @@ -0,0 +1,20 @@ +#include "Arduino.h" +#include "sysctl.h" +#include "sleep.h" + +uint64_t millis(){ + return sysctl_get_time_us()/1000; +} +uint64_t micros(){ + return sysctl_get_time_us(); +} +void delay(uint64_t dwMs){ + msleep(dwMs); + return; +} +void pll_init(){ + sysctl_pll_set_freq(SYSCTL_PLL0, 800000000UL); + sysctl_pll_set_freq(SYSCTL_PLL1, 300000000UL); + sysctl_pll_set_freq(SYSCTL_PLL2, 45158400UL); + return; +} \ No newline at end of file diff --git a/cores/arduino/wiring.h b/cores/arduino/wiring.h new file mode 100644 index 0000000..33cc8a7 --- /dev/null +++ b/cores/arduino/wiring.h @@ -0,0 +1,32 @@ +#ifndef _WIRING_ +#define _WIRING_ + +#include "sysctl.h" +#include "sleep.h" +/** + * \brief Returns the number of milliseconds since the board began running the current program. + * + * \return Number of milliseconds since the program started (uint64_t) + */ +extern uint64_t millis(void); + +/** + * \brief Returns the number of microseconds since the board began running the current program. + * + * \note There are 1,000 microseconds in a millisecond and 1,000,000 microseconds in a second. + */ +extern uint64_t micros(void); + +/** + * \brief Pauses the program for the amount of time (in miliseconds) specified as parameter. + * (There are 1000 milliseconds in a second.) + * + * \param dwMs the number of milliseconds to pause (uint64_t) + */ +extern void delay(uint64_t dwMs); + +void pll_init(void); + + + +#endif \ No newline at end of file diff --git a/cores/arduino/wiring_constants.h b/cores/arduino/wiring_constants.h new file mode 100644 index 0000000..bb31dca --- /dev/null +++ b/cores/arduino/wiring_constants.h @@ -0,0 +1,105 @@ +/* + Copyright (c) 2011 Arduino. All right reserved. + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + See the GNU Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef _WIRING_CONSTANTS_ +#define _WIRING_CONSTANTS_ + +#include "encoding.h" + +#include + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +#define HIGH 0x1 +#define LOW 0x0 + +#define INPUT 0x0 +#define OUTPUT 0x3 +#define INPUT_PULLUP 0x2 +#define INPUT_PULLDOWN 0X1 + +#define PI 3.1415926535897932384626433832795 +#define HALF_PI 1.5707963267948966192313216916398 +#define TWO_PI 6.283185307179586476925286766559 +#define DEG_TO_RAD 0.017453292519943295769236907684886 +#define RAD_TO_DEG 57.295779513082320876798154814105 +#define EULER 2.718281828459045235360287471352 + +#define SERIAL 0x0 +#define DISPLAY 0x1 + +enum BitOrder { + LSBFIRST = 0, + MSBFIRST = 1 +}; + +// LOW 0 +// HIGH 1 +#define CHANGE 2 +#define FALLING 3 +#define RISING 4 + +#define DEFAULT 1 +#define EXTERNAL 0 + +// undefine stdlib's abs if encountered +#ifdef abs +#undef abs +#endif // abs + +#ifndef min +#define min(a,b) ((a)<(b)?(a):(b)) +#endif // min + +#ifndef max +#define max(a,b) ((a)>(b)?(a):(b)) +#endif // max + +#define abs(x) ((x)>0?(x):-(x)) +#define constrain(amt,low,high) ((amt)<(low)?(low):((amt)>(high)?(high):(amt))) +#define round(x) ((x)>=0?(long)((x)+0.5):(long)((x)-0.5)) +#define radians(deg) ((deg)*DEG_TO_RAD) +#define degrees(rad) ((rad)*RAD_TO_DEG) +#define sq(x) ((x)*(x)) + +#define interrupts() set_csr(mstatus, MSTATUS_MIE) +#define noInterrupts() clear_csr(mstatus, MSTATUS_MIE) + +#define lowByte(w) ((uint8_t) ((w) & 0xff)) +#define highByte(w) ((uint8_t) ((w) >> 8)) + +#define bitRead(value, bit) (((value) >> (bit)) & 0x01) +#define bitSet(value, bit) ((value) |= (1UL << (bit))) +#define bitClear(value, bit) ((value) &= ~(1UL << (bit))) +#define bitWrite(value, bit, bitvalue) (bitvalue ? bitSet(value, bit) : bitClear(value, bit)) + +typedef unsigned int word; + +#define bit(b) (1UL << (b)) + +typedef bool boolean ; +typedef uint8_t byte ; + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus + + +#endif /* _WIRING_CONSTANTS_ */ \ No newline at end of file diff --git a/cores/arduino/wiring_digital.c b/cores/arduino/wiring_digital.c new file mode 100644 index 0000000..bb270e5 --- /dev/null +++ b/cores/arduino/wiring_digital.c @@ -0,0 +1,33 @@ + +#include "Arduino.h" + +#include + +#include "fpioa.h" +#include "gpiohs.h" +#include "gpio.h" +#include "wiring_constants.h" +#include "wiring_digital.h" + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +void pinMode(uint8_t dwPin, uint8_t dwMode){ //48个fpio 对应32个gpiohs? + fpioa_set_function(dwPin, FUNC_GPIOHS0 + dwPin); + gpiohs_set_drive_mode(dwPin, (gpio_drive_mode_t)dwMode); + return ; +} + +void digitalWrite(uint8_t dwPin, uint8_t dwVal){ + gpiohs_set_pin(dwPin, (gpio_pin_value_t)dwVal); + return ; +} + +int digitalRead(uint8_t ulPin){ + return (int)gpiohs_get_pin(ulPin); +} + +#ifdef __cplusplus +} // extern "C" +#endif // __cplusplus \ No newline at end of file diff --git a/cores/arduino/wiring_digital.h b/cores/arduino/wiring_digital.h new file mode 100644 index 0000000..ca1f354 --- /dev/null +++ b/cores/arduino/wiring_digital.h @@ -0,0 +1,59 @@ +#ifndef _WIRING_DIGITAL_ +#define _WIRING_DIGITAL_ + +#include "Arduino.h" +#include + +#ifdef __cplusplus +extern "C"{ +#endif // __cplusplus + +#define PortValue_t uint32_t +#define PortAddr_t uint32_t +#define PortRegister_t volatile uint32_t * + +#define digitalPinToPort(pin) ((PortAddr_t) GPIO_CTRL_ADDR) +#define digitalPinToPortIn(pin) ((PortAddr_t) GPIO_CTRL_ADDR) +#define digitalPinToBitMask(pin) ((PortValue_t) (1< + +#define RISCV +#include "platform.h" + +#include "Arduino.h" + + +/* BOARD PIN DEFINE */ +/* LEDs */ +#define PIN_LED_GREEN 13 +#define PIN_LED_BLUE 12 +#define PIN_LED_RED 14 +#define PIN_LED 13 +#define LED_BUILTIN 13 +/* KEY */ +#define KEY0 16 +/* UART */ +#define RX0 4 +#define TX0 5 +/* MIC ARRAY */ +#define MIC_BCK 18 +#define MIC_WS 19 +#define MIC_DAT3 20 +#define MIC_DAT2 21 +#define MIC_DAT1 22 +#define MIC_DAT0 23 +#define MIC_LED_DAT 24 +/* SPI0 */ +#define SPI0_CS1 25 +#define SPI0_MISO 26 +#define SPI0_SCLK 27 +#define SPI0_MOSI 28 +#define SPI0_CS0 29 +/* I2S */ +#define MIC0_WS 30 +#define MIC0_DATA 31 +#define MIC0_BCK 32 +#define I2S_WS 33 +#define I2S_DA 34 +#define I2S_BCK 35 +/* LCD */ +#define LCD_CS 36 +#define LCD_RST 37 +#define LCD_DC 38 +#define LCD_WR 39 + +static const uint8_t RX = RX0; +static const uint8_t TX = TX0; + +static const uint8_t SDA = 10; +static const uint8_t SCL = 9; + +static const uint8_t SS = SPI0_CS0 ; +static const uint8_t MOSI = SPI0_MOSI; +static const uint8_t MISO = SPI0_MISO; +static const uint8_t SCK = SPI0_SCLK; + +#define VARIANT_NUM_GPIOHS (32) +#define VARIANT_NUM_GPIO ( 8) +#define VARIANT_NUM_PWM ( 3) +#define VARIANT_NUM_I2C ( 3) +#define VARIANT_NUM_SPI ( 3) +#define VARIANT_NUM_UART ( 3) + +#endif