Skip to content

Commit d0f0391

Browse files
committed
zpu: add ZPUino 2.0 support
1 parent ccc2d9c commit d0f0391

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+6607
-0
lines changed

hardware/zpuino/zpu20/boards.txt

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
##############################################################
2+
zpuino15_papilio_one500.name=ZPUino 1.5 on Papilio One (500) board
3+
zpuino15_papilio_one500.upload.protocol=zpuino-serial
4+
zpuino15_papilio_one500.upload.maximum_size=27648
5+
zpuino15_papilio_one500.upload.size_sections=all
6+
zpuino15_papilio_one500.upload.speed=1000000
7+
zpuino15_papilio_one500.upload.tool=zpuinoprogrammer
8+
zpuino15_papilio_one500.build.f_cpu=96000000L
9+
zpuino15_papilio_one500.build.core=zpuino
10+
zpuino15_papilio_one500.build.mcu=zpu
11+
zpuino15_papilio_one500.build.ldscript=zpuelf.lds
12+
zpuino15_papilio_one500.build.pins=standard
13+
zpuino15_papilio_one500.build.toolchain=zpu
14+
zpuino15_papilio_one500.build.extra_flags=-D__ZPUINO_PAPILIO_ONE__ -DZPU15 -DBOARD_ID=0xA5010F00 -DBOARD_MEMORYSIZE=0x8000 -D__S3E_500__ -nostartfiles
15+
zpuino15_papilio_one500.build.extraSflags=-DBOARD_ID=0xA5010F00 -DZPU15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#ifndef __ARDUINO_H__
2+
#define __ARDUINO_H__
3+
4+
#include <zpuino.h>
5+
#include <delay.h>
6+
#include <HardwareSerial.h>
7+
#include <binary.h>
8+
9+
#ifndef boolean
10+
#define boolean bool
11+
#endif
12+
13+
#ifndef _BV
14+
#define _BV(x) (1<<(x))
15+
#endif
16+
17+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include "BaseDevice.h"
2+
3+
namespace ZPUino {
4+
int BaseDevice::deviceBegin(uint8_t vendor, uint8_t product) {
5+
uint8_t slot;
6+
slot = DeviceRegistry::scanDevice(vendor,product,m_instance);
7+
if (slot==NO_DEVICE) {
8+
/* Uuups */
9+
m_slot=0xff;
10+
return -1;
11+
}
12+
m_slot=slot;
13+
m_baseaddress = (register_t)IO_SLOT(m_slot);
14+
return 0;
15+
}
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifndef __BASEDEVICE_H__
2+
#define __BASEDEVICE_H__
3+
4+
#include "register.h"
5+
#include "DeviceRegistry.h"
6+
7+
namespace ZPUino {
8+
9+
class REGW {
10+
public:
11+
REGW(register_t reg): _r(reg) {};
12+
inline operator uint32_t const ()
13+
{
14+
return*_r;
15+
}
16+
void operator=(uint32_t value) { *_r=value; }
17+
private:
18+
register_t _r;
19+
};
20+
21+
class BaseDevice {
22+
public:
23+
BaseDevice(uint8_t instance=0xff): m_slot(0xff), m_instance(instance) {}
24+
inline REGW REG(uint32_t offset=0) {
25+
return REGW(m_baseaddress+offset);
26+
}
27+
int deviceBegin(uint8_t vendor, uint8_t product);
28+
int isError() { return m_slot==0xff; }
29+
protected:
30+
private:
31+
uint8_t m_slot;
32+
uint8_t m_instance;
33+
register_t m_baseaddress;
34+
};
35+
};
36+
37+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include "DeviceRegistry.h"
2+
#include "register.h"
3+
4+
namespace ZPUino {
5+
6+
int DeviceRegistry::registerDevice(uint8_t slot) {
7+
if (slot>=MAX_SLOTS)
8+
return -2;
9+
if (m_sDeviceRegistry & (1<<slot))
10+
return -1;
11+
m_sDeviceRegistry |= (1<<slot);
12+
return 0;
13+
}
14+
15+
uint8_t DeviceRegistry::scanDevice(uint8_t vendor, uint8_t product, int instance) {
16+
uint8_t i;
17+
for (i=0;i<16;i++) {
18+
unsigned val = REGISTER(SYSCTLBASE,16+i);
19+
if (val!=0) {
20+
if (vendor!=VENDOR_ANY) {
21+
if (vendor != ((val>>8)&0xff))
22+
continue; /* No match */
23+
}
24+
if (vendor!=PRODUCT_ANY) {
25+
if (product != (val&0xff))
26+
continue; /* No match */
27+
}
28+
if (isRegistered(i))
29+
continue;
30+
31+
if (--instance==0)
32+
return i;
33+
}
34+
}
35+
return NO_DEVICE;
36+
}
37+
38+
39+
uint32_t DeviceRegistry::m_sDeviceRegistry = 0;
40+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
#ifndef __DEVICEREGISTRY_H__
2+
#define __DEVICEREGISTRY_H__
3+
4+
#include "register.h"
5+
#include <zpuino-types.h>
6+
7+
#define VENDOR_ANY 0xff
8+
#define PRODUCT_ANY 0xff
9+
#define FIRST_INSTANCE -1
10+
#define NO_DEVICE 0xff
11+
#define MAX_SLOTS 16
12+
13+
namespace ZPUino {
14+
class BaseDevice;
15+
16+
class DeviceRegistry {
17+
friend class BaseDevice;
18+
19+
protected:
20+
/**
21+
*
22+
* @brief Register device on a specified Wishbone Slot
23+
* @param slot The slot to register
24+
* @return 0 on success, -1 on failure (already registered)
25+
*/
26+
static int registerDevice(uint8_t slot);
27+
/**
28+
* @brief Scan for a specified device on the Wishbone slots
29+
* @param vendor Vendor id for the device, or VENDOR_ANY for all vendors
30+
* @param product Product id for the device, or PRODUCT_ANY for all devices
31+
* @param instance Instance number of this device or FIRST_INSTANCE for 1st available instance. The first instance
32+
* number is always 1, not 0.
33+
* @return The slot for the device, or NO_DEVICE if not found.
34+
*/
35+
static uint8_t scanDevice(uint8_t vendor, uint8_t product, int instance);
36+
/**
37+
* @brief Check if any device is registered for a specific slot
38+
* @param slot The slot to check
39+
* @return true if a device is already registered there, false otherwise
40+
*/
41+
static bool isRegistered(uint8_t slot) { return m_sDeviceRegistry&(1<<slot); }
42+
/**
43+
* @brief Release a device. This should be called from within end() if you have sucessufully
44+
* acquired the device.
45+
* @param slot The slot where the device is
46+
* @return true if successfuly unregistered, false otherwise
47+
*/
48+
static int releaseDevice(uint8_t slot);
49+
private:
50+
static uint32_t m_sDeviceRegistry;
51+
};
52+
};
53+
54+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
#include "HardwareSerial.h"
2+
3+
HardwareSerial Serial(1); /* 1st instance/slot */
4+
5+
#ifdef ZPU15
6+
7+
void HardwareSerial::begin_slow(const unsigned int baudrate) {
8+
REG(1) = BAUDRATEGEN(baudrate)|BIT(UARTEN);
9+
}
10+
11+
void HardwareSerial::flush() {
12+
while (REG(1) & 4);
13+
}
14+
15+
size_t HardwareSerial::write(unsigned char c) {
16+
while ((REG(1) & 2)==2);
17+
REG(0) = c;
18+
return 1;
19+
}
20+
21+
#else
22+
23+
void HardwareSerial::begin_slow(const unsigned int baudrate) {
24+
REGISTER(ioslot,1) = BAUDRATEGEN(baudrate)|BIT(UARTEN);
25+
}
26+
27+
size_t HardwareSerial::write(unsigned char c) {
28+
while ((REGISTER(ioslot,1) & 2)==2);
29+
REGISTER(ioslot,0) = c;
30+
}
31+
32+
33+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
#ifndef __HardwareSerial_h__
2+
#define __HardwareSerial_h__
3+
4+
#include <zpuino.h>
5+
#include <zpuino-types.h>
6+
#include "Stream.h"
7+
#include "Print.h"
8+
9+
#ifdef ZPU15
10+
#include "BaseDevice.h"
11+
12+
#define VENDOR_ZPUINO 0x08
13+
#define PRODUCT_ZPUINO_UART 0x11
14+
15+
namespace ZPUino {
16+
};
17+
18+
class HardwareSerial: public ZPUino::BaseDevice, public Stream
19+
{
20+
private:
21+
public:
22+
HardwareSerial(uint8_t instance=0xff): BaseDevice(instance) {}
23+
24+
__attribute__((always_inline)) inline void begin(const unsigned int baudrate) {
25+
if (deviceBegin(VENDOR_ZPUINO, PRODUCT_ZPUINO_UART)==0) {
26+
if (__builtin_constant_p(baudrate)) {
27+
REG(1) = BAUDRATEGEN(baudrate) | BIT(UARTEN);
28+
} else {
29+
begin_slow(baudrate);
30+
}
31+
}
32+
}
33+
void begin_slow(const unsigned int baudrate);
34+
35+
int available(void) {
36+
return (REG(1) & 1);
37+
}
38+
39+
virtual int read(void) {
40+
return REG(0);
41+
}
42+
43+
virtual void flush(void);
44+
45+
size_t write(uint8_t c);
46+
47+
virtual int peek() { return -1; }
48+
49+
using Print::write; // pull in write(str) and write(buf, size) from Print
50+
private:
51+
unsigned int ioslot;
52+
};
53+
54+
extern void serialEventRun(void) __attribute__((weak));
55+
56+
extern HardwareSerial Serial; /* 1st slot */
57+
extern HardwareSerial Serial1; /* 1st slot */
58+
59+
#else
60+
class HardwareSerial: public Stream
61+
{
62+
private:
63+
public:
64+
HardwareSerial(unsigned int b): ioslot(IO_SLOT(b)) {}
65+
66+
__attribute__((always_inline)) inline void begin(const unsigned int baudrate) {
67+
if (__builtin_constant_p(baudrate)) {
68+
REGISTER(ioslot,1) = BAUDRATEGEN(baudrate) | BIT(UARTEN);
69+
} else {
70+
begin_slow(baudrate);
71+
}
72+
}
73+
void begin_slow(const unsigned int baudrate);
74+
75+
int available(void) {
76+
return (REGISTER(ioslot,1) & 1);
77+
}
78+
79+
virtual int read(void) {
80+
return REGISTER(ioslot,0);
81+
}
82+
83+
virtual void flush(void) {};
84+
85+
size_t write(uint8_t c);
86+
87+
virtual int peek() { return -1; }
88+
89+
using Print::write; // pull in write(str) and write(buf, size) from Print
90+
private:
91+
unsigned int ioslot;
92+
};
93+
94+
extern void serialEventRun(void) __attribute__((weak));
95+
96+
extern HardwareSerial Serial; /* 1st slot */
97+
#endif
98+
99+
#endif
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
2+
#include <Arduino.h>
3+
#include <IPAddress.h>
4+
5+
IPAddress::IPAddress()
6+
{
7+
memset(_address, 0, sizeof(_address));
8+
}
9+
10+
IPAddress::IPAddress(uint8_t first_octet, uint8_t second_octet, uint8_t third_octet, uint8_t fourth_octet)
11+
{
12+
_address[0] = first_octet;
13+
_address[1] = second_octet;
14+
_address[2] = third_octet;
15+
_address[3] = fourth_octet;
16+
}
17+
18+
IPAddress::IPAddress(uint32_t address)
19+
{
20+
memcpy(_address, &address, sizeof(_address));
21+
}
22+
23+
IPAddress::IPAddress(const uint8_t *address)
24+
{
25+
memcpy(_address, address, sizeof(_address));
26+
}
27+
28+
IPAddress& IPAddress::operator=(const uint8_t *address)
29+
{
30+
memcpy(_address, address, sizeof(_address));
31+
return *this;
32+
}
33+
34+
IPAddress& IPAddress::operator=(uint32_t address)
35+
{
36+
memcpy(_address, (const uint8_t *)&address, sizeof(_address));
37+
return *this;
38+
}
39+
40+
bool IPAddress::operator==(const uint8_t* addr)
41+
{
42+
return memcmp(addr, _address, sizeof(_address)) == 0;
43+
}
44+
45+
size_t IPAddress::printTo(Print& p) const
46+
{
47+
size_t n = 0;
48+
for (int i =0; i < 3; i++)
49+
{
50+
n += p.print(_address[i], DEC);
51+
n += p.print('.');
52+
}
53+
n += p.print(_address[3], DEC);
54+
return n;
55+
}
56+

0 commit comments

Comments
 (0)