10 1007 978-1-4842-3354-2 by Unknown

10 1007 978-1-4842-3354-2 by Unknown

Author:Unknown
Language: eng
Format: epub
Published: 2018-03-07T03:51:37+00:00


Chapter 8 ImplementIng the CompressIon Code In pasm

We’ll set up these files:

8.2 Setting Up steim_pasm0

Create two new files: steim_pasm0_Demo.spin (Listing 8-1) and steim_

pasm0.spin (Listing 8-2). Most of what is shown here is similar to what is in the pure-Spin version, but the compression will be done in PASM instead.

First, we set up the ..._Demo.spin file, which is the entry point.

Listing 8-1. steim_pasm0_Demo: Spin Side of the First Iteration of the PASM Compression

1 {* -*- Spin -*- *}

2 {* steim_pasm0_Demo .spin *}

3

4 CON ' Clock mode settings

5 _CLKMODE = XTAL1 + PLL16X

6 _XINFREQ = 6 _250_000

7

8 ' system freq as a constant

9 FULL_SPEED = (( _clkmode - xtal1) >> 6) * _xinfreq

10 ONE_MS = FULL_SPEED / 1_000 ' ticks in 1ms

11 ONE_US = FULL_SPEED / 1 _000_000 ' ticks in 1us

12

13 CON ' Pin map

14

15 DEBUG_TX_TO = 30

16 DEBUG_RX_FROM = 31

17

140

Chapter 8 ImplementIng the CompressIon Code In pasm

18 CON ' UART ports

19 DEBUG = 0

20 DEBUG_BAUD = 115200

21

22 UART_SIZE = 100

23 CR = 13

24 LF = 10

25 SPACE = 32

26 TAB = 9

27 COLON = 58

28 COMMA = 44

29

30 OBJ

31 '1 COG for 3 serial ports

32 UARTS : "FullDuplexSerial4portPlus_0v3"

33 NUM : "Numbers" 'Object for writing numbers to debug

34 COMPR : "steim_pasm0"

35

36 CON

37 NSAMPS_MAX = 128

38

39 VAR

40 long nsamps, ncompr

41 long sampsBuf[NSAMPS_MAX]

42 long comprCodeBuf[NSAMPS_MAX >> 4]

43

44 byte mainCogId, serialCogId, comprCogId

45 byte packBuf[NSAMPS_MAX << 2]

46

47 PUB MAIN

48

141

Chapter 8 ImplementIng the CompressIon Code In pasm

49 ' main cog

50 mainCogId := cogid

51

52 ' uart cog

53 LAUNCH_SERIAL_COG

54 PAUSE_MS(500)

55

56 UARTS.STR(DEBUG, string(CR, " Compression ", CR, LF))

57 UARTS.STR(DEBUG, string(" mainCogId : "))

58 UARTS.DEC(DEBUG, mainCogId)

59 UARTS.PUTC(DEBUG, CR)

60 UARTS.PUTC(DEBUG, LF)

61

62 ' compression cog

63 COMPR.INIT(NSAMPS_MAX)

64 comprCogId := COMPR.START

65

66 UARTS.STR(DEBUG, string(" comprCogId : "))

67 UARTS.DEC(DEBUG, comprCogId)

68 UARTS.PUTC(DEBUG, CR)

69 UARTS.PUTC(DEBUG, LF)

70

71 nsamps := 1

72 ncompr := COMPR.COMPRESS (@sampsBuf, nsamps, 

@packBuf, @comprCodeBuf)

73

74 UARTS.STR(DEBUG, string(" ncompr : "))

75 UARTS.DEC(DEBUG, ncompr)

76 UARTS.PUTC(DEBUG, CR)

77 UARTS.PUTC(DEBUG, LF)

142

Chapter 8 ImplementIng the CompressIon Code In pasm

78 repeat

79 PAUSE_MS(1000)

80

81 PRI LAUNCH_SERIAL_COG

82 " method that sets up the serial ports

83 NUM.INIT

84 UARTS.INIT

85 UARTS.ADDPORT (DEBUG, DEBUG_RX_FROM, DEBUG_TX_TO, -1, 

-1, 0, %000000, DEBUG_BAUD) 'Add DEBUG port

86 UARTS.START

87 serialCogId := UARTS.GETCOGID 'Start the, ports

88 PAUSE_MS(300)

89

90 PRI PAUSE_MS(mS)

91 waitcnt(clkfreq /1000 * mS + cnt)

92

93 ' Program ends here

• Line 34: Import the file steim_pasm0.spin as object

COMPR.

• Lines 63–64: Initialize and start the compression cog.

As you will see, the COMPR.START function (a Spin

function) launches a new PASM cog.

• Lines 71–72: Call the Spin method COMPR.COMPRESS

(a Spin function), which signals the PASM cog to

compress the samples in sampsBuf.

We will start by implementing the simplest possible compression code

in Spin and PASM code in steim_pasm0. It includes passing nsamps to the

PASM cog and reading ncompr back. As I said earlier, the PASM code has

to monitor the hub memory and react to a change. Here we use nsamps as

143

Chapter 8 ImplementIng the CompressIon Code In pasm

the trigger. If the value is greater than zero, then perform a compression,

and at the end of the compression, set ncompr to a nonzero value. That, in

turn, will be the signal to the Spin code that the PASM cog has completed

its work. In this first example,



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.