Preliminary addition of static memory allocations for packet buffers.
Fixed(?) DDS frequency calculation on-chip.
This commit is contained in:
parent
d2dc9adbc0
commit
80a1741575
25
AFSK.cpp
25
AFSK.cpp
|
@ -24,6 +24,10 @@ volatile unsigned long lastRx = 0;
|
||||||
|
|
||||||
#define T_BIT ((unsigned int)(9600/1200))
|
#define T_BIT ((unsigned int)(9600/1200))
|
||||||
|
|
||||||
|
#ifdef PACKET_PREALLOCATE
|
||||||
|
SimpleFIFO<AFSK::Packet *,PPOOL_SIZE> preallocPool;
|
||||||
|
#endif
|
||||||
|
|
||||||
void AFSK::Encoder::process() {
|
void AFSK::Encoder::process() {
|
||||||
// Check what clock pulse we're on
|
// Check what clock pulse we're on
|
||||||
if(bitClock == 0) { // We are onto our next bit timing
|
if(bitClock == 0) { // We are onto our next bit timing
|
||||||
|
@ -396,11 +400,16 @@ AFSK::Packet *AFSK::PacketBuffer::getPacket() volatile {
|
||||||
void AFSK::Packet::init(unsigned short dlen) {
|
void AFSK::Packet::init(unsigned short dlen) {
|
||||||
//data = (unsigned char *)buf;
|
//data = (unsigned char *)buf;
|
||||||
ready = 0;
|
ready = 0;
|
||||||
freeData = 1; //freeData;
|
#ifdef PACKET_PREALLOCATE
|
||||||
|
freeData = 0;
|
||||||
|
maxLen = 128; // Put it here instead
|
||||||
|
#else
|
||||||
|
freeData = 1;
|
||||||
|
dataPtr = (uint8_t *)malloc(dlen+16);
|
||||||
|
maxLen = dlen; // Put it here instead
|
||||||
|
#endif
|
||||||
type = PACKET_STATIC;
|
type = PACKET_STATIC;
|
||||||
len = 0; // We had a length, but don't put it here.
|
len = 0; // We had a length, but don't put it here.
|
||||||
maxLen = dlen; // Put it here instead
|
|
||||||
dataPtr = (uint8_t *)malloc(dlen+16);
|
|
||||||
dataPos = dataPtr;
|
dataPos = dataPtr;
|
||||||
readPos = dataPtr;
|
readPos = dataPtr;
|
||||||
fcs = 0xffff;
|
fcs = 0xffff;
|
||||||
|
@ -411,7 +420,11 @@ AFSK::Packet *AFSK::PacketBuffer::makePacket(unsigned short dlen) {
|
||||||
AFSK::Packet *p;
|
AFSK::Packet *p;
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||||
//Packet *p = findPooledPacket();
|
//Packet *p = findPooledPacket();
|
||||||
|
#ifdef PACKET_PREALLOCATE
|
||||||
|
p = preallocPool.dequeue();
|
||||||
|
#else
|
||||||
p = new Packet(); //(Packet *)malloc(sizeof(Packet));
|
p = new Packet(); //(Packet *)malloc(sizeof(Packet));
|
||||||
|
#endif
|
||||||
if(p) // If allocated
|
if(p) // If allocated
|
||||||
p->init(dlen);
|
p->init(dlen);
|
||||||
}
|
}
|
||||||
|
@ -421,8 +434,11 @@ AFSK::Packet *AFSK::PacketBuffer::makePacket(unsigned short dlen) {
|
||||||
// Free a packet struct, mainly convenience
|
// Free a packet struct, mainly convenience
|
||||||
void AFSK::PacketBuffer::freePacket(Packet *p) {
|
void AFSK::PacketBuffer::freePacket(Packet *p) {
|
||||||
if(!p)
|
if(!p)
|
||||||
return;
|
return;
|
||||||
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
ATOMIC_BLOCK(ATOMIC_RESTORESTATE) {
|
||||||
|
#ifdef PACKET_PREALLOCATE
|
||||||
|
preallocPool.enqueue(p);
|
||||||
|
#else
|
||||||
p->free();
|
p->free();
|
||||||
/*unsigned char i;
|
/*unsigned char i;
|
||||||
for(i = 0; i < PPOOL_SIZE; ++i)
|
for(i = 0; i < PPOOL_SIZE; ++i)
|
||||||
|
@ -431,6 +447,7 @@ void AFSK::PacketBuffer::freePacket(Packet *p) {
|
||||||
if(i < PPOOL_SIZE)
|
if(i < PPOOL_SIZE)
|
||||||
pStatus &= ~(1<<i);*/
|
pStatus &= ~(1<<i);*/
|
||||||
delete p;
|
delete p;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
8
AFSK.h
8
AFSK.h
|
@ -14,6 +14,7 @@
|
||||||
|
|
||||||
#define PACKET_BUFFER_SIZE 2
|
#define PACKET_BUFFER_SIZE 2
|
||||||
#define PACKET_STATIC 0
|
#define PACKET_STATIC 0
|
||||||
|
//#define PACKET_PREALLOCATE
|
||||||
|
|
||||||
// This is with all the digis, two addresses, framing and full payload
|
// This is with all the digis, two addresses, framing and full payload
|
||||||
// Two more bytes are added for HDLC_ESCAPEs
|
// Two more bytes are added for HDLC_ESCAPEs
|
||||||
|
@ -105,7 +106,12 @@ public:
|
||||||
return (fcs == 0xF0B8);
|
return (fcs == 0xF0B8);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
uint8_t *dataPtr, *dataPos, *readPos;
|
#ifdef PACKET_PREALLOCATE
|
||||||
|
uint8_t dataPtr[128];
|
||||||
|
#else
|
||||||
|
uint8_t *dataPtr;
|
||||||
|
#endif
|
||||||
|
uint8_t *dataPos, *readPos;
|
||||||
unsigned short fcs;
|
unsigned short fcs;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
2
DDS.cpp
2
DDS.cpp
|
@ -73,7 +73,7 @@ void DDS::setFrequency(unsigned short freq) {
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// BUG: Step rate isn't properly calculated here, it gets the wrong frequency
|
// BUG: Step rate isn't properly calculated here, it gets the wrong frequency
|
||||||
stepRate = (freq/(refclk+DDS_REFCLK_OFFSET)) * pow(2,ACCUMULATOR_BITS);
|
stepRate = pow(2,ACCUMULATOR_BITS)*freq / (refclk+DDS_REFCLK_OFFSET);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue