Added support for custom datatype for Python code generated by SDF
parent
7de5cc0caf
commit
e7010120fd
@ -0,0 +1,87 @@
|
||||
###########################################
|
||||
# Project: CMSIS DSP Library
|
||||
# Title: appnodes.py
|
||||
# Description: Application nodes for Example 4
|
||||
#
|
||||
# $Date: 29 July 2021
|
||||
# $Revision: V1.10.0
|
||||
#
|
||||
# Target Processor: Cortex-M and Cortex-A cores
|
||||
# -------------------------------------------------------------------- */
|
||||
#
|
||||
# Copyright (C) 2010-2021 ARM Limited or its affiliates. All rights reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
# not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
############################################
|
||||
from cmsisdsp.sdf.nodes.simu import *
|
||||
from custom import *
|
||||
from cmsisdsp.sdf.nodes.Duplicate import *
|
||||
|
||||
class Sink(GenericSink):
|
||||
def __init__(self,inputSize,fifoin):
|
||||
GenericSink.__init__(self,inputSize,fifoin)
|
||||
|
||||
|
||||
def run(self):
|
||||
# The null sink must at least get a buffer from the FIFO
|
||||
# or the FIFO will never be emptied
|
||||
# and the scheduling will fail
|
||||
print("Sink")
|
||||
i=self.getReadBuffer()
|
||||
for c in i:
|
||||
print("%f + I %f" % (c.re,c.im))
|
||||
return(0)
|
||||
|
||||
class ProcessingNode(GenericNode):
|
||||
def __init__(self,inputSize,outputSize,fifoin,fifoout,i,s,v):
|
||||
GenericNode.__init__(self,inputSize,outputSize,fifoin,fifoout)
|
||||
|
||||
def run(self):
|
||||
print("ProcessingNode");
|
||||
a=self.getReadBuffer()
|
||||
b=self.getWriteBuffer()
|
||||
# Python objects have reference semantic and not
|
||||
# value semantic.
|
||||
# So in a write buffer, we can change the
|
||||
# fields of an object but we should not
|
||||
# replace the object and risk creating sharing
|
||||
# Duplicating the a object may be ok
|
||||
b[0]=a[3]
|
||||
return(0)
|
||||
|
||||
class Source(GenericSource):
|
||||
def __init__(self,outputSize,fifoout):
|
||||
GenericSource.__init__(self,outputSize,fifoout)
|
||||
self._counter=0
|
||||
|
||||
def run(self):
|
||||
print("Source");
|
||||
a=self.getWriteBuffer()
|
||||
|
||||
# Python objects have reference semantic and not
|
||||
# value semantic.
|
||||
# So in a write buffer, we can change the
|
||||
# fields of an object but we should not
|
||||
# replace the object and risk creating sharing
|
||||
# Creating a new object may be ok
|
||||
for i in range(self._outputSize):
|
||||
#a[i].re = 1.0*self._counter
|
||||
#a[i].im = 0.0
|
||||
a[i] = MyComplex(1.0*self._counter, 0.0)
|
||||
self._counter = self._counter + 1
|
||||
|
||||
return(0)
|
||||
|
||||
|
||||
@ -0,0 +1,13 @@
|
||||
import numpy as np
|
||||
|
||||
class MyComplex:
|
||||
def __init__(self,re=0,im=0):
|
||||
self.re = re
|
||||
self.im = im
|
||||
|
||||
def __str__(self):
|
||||
return("%f + I %f" % (self.re, self.im))
|
||||
|
||||
def __repr__(self):
|
||||
return("MyComplex(%f,%f)" % (self.re, self.im))
|
||||
|
||||
@ -0,0 +1,12 @@
|
||||
import sched as s
|
||||
from custom import *
|
||||
|
||||
# Only ONE FileSink can be used since the data will be dumped
|
||||
# into this global buffer for display with Matplotlib
|
||||
# It will have to be cleaned and reworked in future to use better
|
||||
# mechanism of communication with the main code
|
||||
|
||||
print("Start")
|
||||
nb,error = s.scheduler("test")
|
||||
print("Nb sched = %d" % nb)
|
||||
|
||||
@ -0,0 +1,180 @@
|
||||
#
|
||||
# Generated with CMSIS-DSP SDF Scripts.
|
||||
# The generated code is not covered by CMSIS-DSP license.
|
||||
#
|
||||
# The support classes and code is covered by CMSIS-DSP license.
|
||||
#
|
||||
|
||||
import sys
|
||||
|
||||
|
||||
import numpy as np
|
||||
import cmsisdsp as dsp
|
||||
from cmsisdsp.sdf.nodes.simu import *
|
||||
from appnodes import *
|
||||
from custom import *
|
||||
|
||||
DEBUGSCHED=False
|
||||
|
||||
#
|
||||
# FIFO buffers
|
||||
#
|
||||
|
||||
|
||||
FIFOSIZE0=11
|
||||
|
||||
buf0=np.empty(FIFOSIZE0,dtype=object)
|
||||
for i in range(FIFOSIZE0):
|
||||
buf0[i] = MyComplex()
|
||||
|
||||
FIFOSIZE1=5
|
||||
|
||||
buf1=np.empty(FIFOSIZE1,dtype=object)
|
||||
for i in range(FIFOSIZE1):
|
||||
buf1[i] = MyComplex()
|
||||
|
||||
FIFOSIZE2=5
|
||||
|
||||
buf2=np.empty(FIFOSIZE2,dtype=object)
|
||||
for i in range(FIFOSIZE2):
|
||||
buf2[i] = MyComplex()
|
||||
|
||||
FIFOSIZE3=5
|
||||
|
||||
buf3=np.empty(FIFOSIZE3,dtype=object)
|
||||
for i in range(FIFOSIZE3):
|
||||
buf3[i] = MyComplex()
|
||||
|
||||
FIFOSIZE4=5
|
||||
|
||||
buf4=np.empty(FIFOSIZE4,dtype=object)
|
||||
for i in range(FIFOSIZE4):
|
||||
buf4[i] = MyComplex()
|
||||
|
||||
|
||||
def scheduler(someVariable):
|
||||
sdfError=0
|
||||
nbSchedule=0
|
||||
debugCounter=1
|
||||
|
||||
#
|
||||
# Create FIFOs objects
|
||||
#
|
||||
fifo0=FIFO(FIFOSIZE0,buf0)
|
||||
fifo1=FIFO(FIFOSIZE1,buf1)
|
||||
fifo2=FIFO(FIFOSIZE2,buf2)
|
||||
fifo3=FIFO(FIFOSIZE3,buf3)
|
||||
fifo4=FIFO(FIFOSIZE4,buf4)
|
||||
|
||||
#
|
||||
# Create node objects
|
||||
#
|
||||
dup = Duplicate3(5,5,5,5,fifo1,fifo2,fifo3,fifo4)
|
||||
filter = ProcessingNode(7,5,fifo0,fifo1,4,"Test",someVariable)
|
||||
sa = Sink(5,fifo2)
|
||||
sb = Sink(5,fifo3)
|
||||
sc = Sink(5,fifo4)
|
||||
source = Source(5,fifo0)
|
||||
|
||||
while((sdfError==0) and (debugCounter > 0)):
|
||||
nbSchedule = nbSchedule + 1
|
||||
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = filter.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = dup.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sc.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sb.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sa.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = filter.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = dup.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sc.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sb.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sa.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = filter.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = dup.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sc.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sb.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sa.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = filter.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = source.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = dup.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sc.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sb.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sa.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = filter.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = dup.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sc.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sb.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
sdfError = sa.run()
|
||||
if sdfError < 0:
|
||||
break
|
||||
|
||||
debugCounter = debugCounter - 1
|
||||
return(nbSchedule,sdfError)
|
||||
@ -0,0 +1,56 @@
|
||||
###########################################
|
||||
# Project: CMSIS DSP Library
|
||||
# Title: Duplicate.py
|
||||
# Description: Duplicate nodes
|
||||
#
|
||||
# $Date: 08 September 2022
|
||||
#
|
||||
# Target Processor: Cortex-M and Cortex-A cores
|
||||
# -------------------------------------------------------------------- */
|
||||
#
|
||||
# Copyright (C) 2010-2022 ARM Limited or its affiliates. All rights reserved.
|
||||
#
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the License); you may
|
||||
# not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an AS IS BASIS, WITHOUT
|
||||
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
############################################
|
||||
from .simu import *
|
||||
import cmsisdsp as dsp
|
||||
|
||||
class Duplicate2(GenericNode12):
|
||||
def __init__(self,inputSize,outputSize1,outputSize2,fifoin,fifoout1,fifoout2):
|
||||
GenericNode12.__init__(self,inputSize,outputSize1,outputSize2,fifoin,fifoout1,fifoout2)
|
||||
|
||||
def run(self):
|
||||
a=self.getReadBuffer()
|
||||
b=self.getWriteBuffer1()
|
||||
c=self.getWriteBuffer2()
|
||||
b[:] = a[:]
|
||||
c[:] = a[:]
|
||||
|
||||
return(0)
|
||||
|
||||
class Duplicate3(GenericNode13):
|
||||
def __init__(self,inputSize,outputSize1,outputSize2,outputSize3,fifoin,fifoout1,fifoout2,fifoout3):
|
||||
GenericNode13.__init__(self,inputSize,outputSize1,outputSize2,outputSize3,fifoin,fifoout1,fifoout2,fifoout3)
|
||||
|
||||
def run(self):
|
||||
a=self.getReadBuffer()
|
||||
b=self.getWriteBuffer1()
|
||||
c=self.getWriteBuffer2()
|
||||
d=self.getWriteBuffer3()
|
||||
b[:] = copy.deepcopy(a[:])
|
||||
c[:] = copy.deepcopy(a[:])
|
||||
d[:] = copy.deepcopy(a[:])
|
||||
|
||||
return(0)
|
||||
Loading…
Reference in New Issue