Skip to content

Commit e935797

Browse files
committed
Update devices and sigmadelta
1 parent 09f2c4e commit e935797

File tree

6 files changed

+179
-49
lines changed

6 files changed

+179
-49
lines changed

hardware/zpuino/zpu20/boards.txt

+14
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,17 @@ zpuino15_papilio_one500.build.pins=standard
1414
zpuino15_papilio_one500.build.toolchain=zpu
1515
zpuino15_papilio_one500.build.extra_flags=-D__ZPUINO_PAPILIO_ONE__ -DZPU20 -DBOARD_ID=0xA5010F00 -DBOARD_MEMORYSIZE=0x8000 -D__S3E_500__ -nostartfiles
1616
zpuino15_papilio_one500.build.extraSflags=-DBOARD_ID=0xA5010F00 -DZPU20
17+
##############################################################
18+
zpuino20_papilio_prolx9v.name=ZPUino on Papilio Pro (LX9)
19+
zpuino20_papilio_prolx9v.boardid=0xA5041700
20+
zpuino20_papilio_prolx9v.upload.protocol=zpuino-serial
21+
zpuino20_papilio_prolx9v.upload.maximum_size=8388608
22+
zpuino20_papilio_prolx9v.upload.size_sections=all
23+
zpuino20_papilio_prolx9v.upload.speed=115200
24+
zpuino20_papilio_prolx9v.upload.tool=zpuinoprogrammer
25+
zpuino20_papilio_prolx9v.build.f_cpu=96000000L
26+
zpuino20_papilio_prolx9v.build.core=zpuino
27+
zpuino20_papilio_prolx9v.build.mcu=zpu
28+
zpuino20_papilio_prolx9v.build.toolchain=zpu
29+
zpuino20_papilio_prolx9v.build.extra_flags=-D__ZPUINO_PAPILIO_PRO__ -DBOARD_ID=0xA5041700 -DBOARD_MEMORYSIZE=0x800000 -nostartfiles
30+
zpuino20_papilio_prolx9v.build.extraSflags=-DBOARD_ID=0xA5041700
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
#include "BaseDevice.h"
22

33
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-
}
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+
}
1616
};

hardware/zpuino/zpu20/cores/zpuino/BaseDevice.h

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ namespace ZPUino {
1313
{
1414
return*_r;
1515
}
16-
void operator=(uint32_t value) { *_r=value; }
16+
void operator=(uint32_t value) { *_r=value; }
17+
inline void setBit(int bit) { *_r = *_r | BIT(bit); }
18+
inline void clearBit(int bit) { *_r = *_r & ~(BIT(bit)); }
1719
private:
1820
register_t _r;
1921
};
@@ -25,7 +27,8 @@ namespace ZPUino {
2527
return REGW(m_baseaddress+offset);
2628
}
2729
int deviceBegin(uint8_t vendor, uint8_t product);
28-
int isError() { return m_slot==0xff; }
30+
int isError() { return m_slot==0xff; }
31+
inline uint8_t getSlot() const { return m_slot; }
2932
protected:
3033
private:
3134
uint8_t m_slot;

hardware/zpuino/zpu20/cores/zpuino/DeviceRegistry.cpp

+61-30
Original file line numberDiff line numberDiff line change
@@ -3,38 +3,69 @@
33

44
namespace ZPUino {
55

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))
6+
int DeviceRegistry::registerDevice(int 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(unsigned vendor, unsigned product, int instance) {
16+
int 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))
2222
continue; /* No match */
23-
}
23+
}
2424
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-
}
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+
}
3535
return NO_DEVICE;
36-
}
37-
36+
}
37+
38+
int DeviceRegistry::getPPSInputPin(int masterslot, int offset)
39+
{
40+
return getPPSPin(masterslot,offset,16);
41+
}
42+
43+
int DeviceRegistry::getPPSOutputPin(int masterslot, int offset)
44+
{
45+
return getPPSPin(masterslot,offset,0);
46+
}
47+
48+
int DeviceRegistry::getPPSPin(int masterslot, int offset, int shift)
49+
{
50+
unsigned count = REGISTER(SYSCTLBASE, 32+shift);
51+
//unsigned i;
52+
register_t startreg = &REGISTER(SYSCTLBASE, 64);
53+
54+
//for (i=0;i<count;i++) {
55+
while(count--) {
56+
unsigned val = *startreg++;//REGISTER(SYSCTLBASE, 64+i);
57+
unsigned char dev = (val>>shift)&0xff;
58+
if (dev!=masterslot) {
59+
continue;
60+
} else {
61+
int pin = (val>>(8+shift))&0xff;
62+
if (offset==0)
63+
return pin;
64+
offset--;
65+
}
66+
}
67+
return -1;
68+
}
3869

39-
uint32_t DeviceRegistry::m_sDeviceRegistry = 0;
70+
uint32_t DeviceRegistry::m_sDeviceRegistry = 0;
4071
};

hardware/zpuino/zpu20/cores/zpuino/DeviceRegistry.h

+11-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ namespace ZPUino {
2323
* @param slot The slot to register
2424
* @return 0 on success, -1 on failure (already registered)
2525
*/
26-
static int registerDevice(uint8_t slot);
26+
static int registerDevice(int slot);
2727
/**
2828
* @brief Scan for a specified device on the Wishbone slots
2929
* @param vendor Vendor id for the device, or VENDOR_ANY for all vendors
@@ -32,21 +32,27 @@ namespace ZPUino {
3232
* number is always 1, not 0.
3333
* @return The slot for the device, or NO_DEVICE if not found.
3434
*/
35-
static uint8_t scanDevice(uint8_t vendor, uint8_t product, int instance);
35+
static uint8_t scanDevice(unsigned vendor, unsigned product, int instance);
3636
/**
3737
* @brief Check if any device is registered for a specific slot
3838
* @param slot The slot to check
3939
* @return true if a device is already registered there, false otherwise
4040
*/
41-
static bool isRegistered(uint8_t slot) { return m_sDeviceRegistry&(1<<slot); }
41+
static bool isRegistered(int slot) { return m_sDeviceRegistry&(1<<(slot&31)); }
4242
/**
4343
* @brief Release a device. This should be called from within end() if you have sucessufully
4444
* acquired the device.
4545
* @param slot The slot where the device is
4646
* @return true if successfuly unregistered, false otherwise
4747
*/
48-
static int releaseDevice(uint8_t slot);
49-
private:
48+
static int releaseDevice(int slot);
49+
public:
50+
static int getPPSInputPin(int masterslot, int offset);
51+
static int getPPSOutputPin(int masterslot, int offset);
52+
protected:
53+
static int getPPSPin(int masterslot, int offset, int shift);
54+
55+
private:
5056
static uint32_t m_sDeviceRegistry;
5157
};
5258
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#ifndef __SIGMADELTA_H__
2+
#define __SIGMADELTA_H__
3+
4+
#include <zpuino.h>
5+
#include <zpuino-types.h>
6+
#include "BaseDevice.h"
7+
8+
#define VENDOR_ZPUINO 0x08
9+
#define PRODUCT_ZPUINO_SIGMADELTA 0x14
10+
11+
namespace ZPUino {
12+
};
13+
14+
typedef enum { CHANNEL_LEFT, CHANNEL_RIGHT } channel_t;
15+
typedef enum { BIG_ENDIAN, LITTLE_ENDIAN } endian_t;
16+
17+
/**
18+
* SigmaDelta class.
19+
*/
20+
21+
class SigmaDelta_class: public ZPUino::BaseDevice
22+
{
23+
private:
24+
public:
25+
/**
26+
* @brief Construct a new SigmaDelta_class instance.
27+
* @param instance Then Nth Hardware SigmaDelta instance to attach to.
28+
*/
29+
SigmaDelta_class(uint8_t instance=0xff): BaseDevice(instance), m_leftPin(-1), m_rightPin(-1) {}
30+
/**
31+
* @brief Start and initialize the SigmaDelta.
32+
*
33+
*
34+
*/
35+
void begin();
36+
37+
/**
38+
* @brief Start and initialize the SigmaDelta, using the defined pins as outputs.
39+
*/
40+
void begin(int pin_left, int pin_right);
41+
/**
42+
* @brief Set SigmaDelta sample endianness.
43+
*/
44+
void setEndianness(endian_t endianess);
45+
/**
46+
* @brief Set the output pin for a specified channel
47+
*/
48+
int setChannelPin(channel_t channel, int pin);
49+
/**
50+
* @brief Set output pins for both channels
51+
*/
52+
int setPins(int left_pin, int right_pin);
53+
/**
54+
* @brief Set the output value for a single channel
55+
*/
56+
void setChannelValue(channel_t channel, uint16_t value);
57+
/**
58+
* @brief Set the output value for both channels, with individual values
59+
*/
60+
void setValues(uint16_t value_left, uint16_t value_right);
61+
/**
62+
* @brief Set the output value for both channels using a composite value.
63+
*/
64+
void setValues(uint32_t values);
65+
/**
66+
* @brief De-initialize the SigmaDelta and release device.
67+
*/
68+
void end();
69+
private:
70+
int m_leftPin, m_rightPin;
71+
};
72+
73+
extern SigmaDelta_class SigmaDelta;
74+
extern SigmaDelta_class SigmaDelta1;
75+
76+
#endif

0 commit comments

Comments
 (0)