Shop OBEX P1 Docs P2 Docs Learn Events
what gets loaded to a cog — Parallax Forums

what gets loaded to a cog

Bobb FwedBobb Fwed Posts: 1,119
edited 2009-01-29 17:41 in Propeller 1
I'm not sure how I haven't run across this before, but I'm trying to figure out the logic.
I have a program:
CON

  RFID_SERIAL_p = 14                                 ' RFID serial data
  RFID_ENABLE_p = 4                                  ' RFID /ENABLE pin

VAR
                  
  BYTE cogon, cog         
  LONG rfidstack[noparse][[/noparse]50], RFIDdata[noparse][[/noparse]12]

PUB start_rfid (door_outputAddr)

  stop
  cogon := (cog := cognew(rfid(door_outputAddr), @rfidstack)) > 0  

PUB stop

  if cogon~      
    cogstop(cog)

PUB rfid (door_outputAddr) | i
  REPEAT                                                                      ' repeat forever
    ReadRFID                                                                  ' get RFID value
     
    IF (CheckRFID)
      byte[noparse][[/noparse]door_outputAddr] &= %011                                           ' force bit 2 to 0
      pause(1000)
    ELSE
      byte[noparse][[/noparse]door_outputAddr] |= %100

PRI ReadRFID | bit, time, deltaT, i
  DIRA[noparse][[/noparse]RFID_SERIAL_p]~                                                        ' Set direction of RFID to be an input          
  DIRA[noparse][[/noparse]RFID_ENABLE_p]~~                                                       ' Set direction of RFID_EN to be an output                             
  deltaT := clkfreq / 2400                                                    ' Set deltaT to 1/2400th of a second for 2400bps "Baud" rate

  OUTA[noparse][[/noparse]RFID_ENABLE_p]~                                                        ' Enable the RFID reader
  REPEAT i FROM 0 TO 11                                                       ' Fill in the 12 byte arrays with data sent from RFID reader                 
    waitpeq(1 << RFID_SERIAL_p, |< RFID_SERIAL_p, 0)                          ' Wait for a high-to-low signal on RFID's SOUT pin, which
    waitpeq(0 << RFID_SERIAL_p, |< RFID_SERIAL_p, 0)                          ' signals the start of the transfer of each packet of 10 data bits
    time := cnt                                                               ' Record the counter value at start of each transmission packet
    waitcnt(time += deltaT + deltaT / 2)                                      ' Skip the start bit (always zero) and center on the 2nd bit

    REPEAT 8                                                                  ' Gather 8 bits for each byte of RFID's data       
      RFIDdata[noparse][[/noparse] i ] := RFIDdata[noparse][[/noparse] i ] << 1 + INA[noparse][[/noparse]RFID_SERIAL_p]                ' Shift RFIDdata bits left and add current bit (state of RFID pin)
      waitcnt(time += deltaT)                                                 ' Pause for 1/2400th of a second (2400 bits per second)
    RFIDdata[noparse][[/noparse] i ] ><= 8                                                       ' Reverse the order of the bits (RFID scanner sends LSB first)  
  OUTA[noparse][[/noparse]RFID_ENABLE_p]~~                                                       ' Disable the RFID reader

PRI CheckRFID | i
  REPEAT i FROM 0 TO 9                                                        ' Compare tag's 10 unique ID #s against ID #s stored in data table
    IF RFIDdata[noparse][[/noparse]i + 1] <> tag1[noparse][[/noparse] i ] AND RFIDdata[noparse][[/noparse]i + 1] <> tag2[noparse][[/noparse] i ]          ' ...etc.       
      RETURN 0                                                                ' If one of the IDs does not match, return a zero
  RETURN 1                                                                    ' If one of the ID sequences matched, return a one

PUB pause (wait) | ClkCycles 

  ClkCycles := ((clkfreq / 1000 * wait) - 4296) #> 381
  waitcnt(ClkCycles + cnt)

DAT
        tag1            byte            "XXXXXXXXXX"
        tag2            byte            "XXXXXXXXXX"



The question is, what is being loaded to the cog. I assume the rfid method is there, but what about the methods that rfid calls: ReadRFID, CheckRFID, and pause? Seems like a bit of a waste if the called methods aren't put onto the cog. But then how that work with calling methods of a another object (is the whole object stored or just the method).
Anyway, I'm sure someone just has a simple answer for this.

Comments

Sign In or Register to comment.