How to call one cog from another
mynet43
Posts: 644
I have an assembly language routine that needs to call another assembly language routine in another cog.
Can you tell me how this can be done?
In the main program I have:
OBJ
adc : "MCP3208_fast" ' Read ADC Ports
xmotor: "Motor Controller-001" ' Stepper Motor Control Routine
ymotor: "Motor Controller-001" ' Stepper Motor Control Routine
The assembly code in the motor routine needs to call the adc input routine in the adc module.
If it were called from the main program, the call would be:
limit_1 := adc.in(4) ' detect limit switch setting
I'm trying to make an equivalent assembly language call from the motor code.
Thank you for your help.
Jim
Can you tell me how this can be done?
In the main program I have:
OBJ
adc : "MCP3208_fast" ' Read ADC Ports
xmotor: "Motor Controller-001" ' Stepper Motor Control Routine
ymotor: "Motor Controller-001" ' Stepper Motor Control Routine
The assembly code in the motor routine needs to call the adc input routine in the adc module.
If it were called from the main program, the call would be:
limit_1 := adc.in(4) ' detect limit switch setting
I'm trying to make an equivalent assembly language call from the motor code.
Thank you for your help.
Jim
Comments
The ADC object works by having its assembly routine communicate with the Spin code through a shared long in main memory. Look at the do_cmd and in methods in the ADC object for details. Your motor control routine can be passed the address of the shared long and it can do the same things as the do_cmd and the in methods in the ADC object. If you're using the ADC object for other things, you will also have to use semaphores (LOCKxxx) to make sure that the cogs using the ADC object's assembly cog share the shared long nicely.
That's what I was afraid of. I was hoping...
For what I'm doing, I think the easiest way is to copy the adc routine to the motor module. The adc code I'm using isn't Chip's continuous loop, it's just a call with a port input and a value output, so I think it should work.
The motor routine is the only thing running when it's told to move the motor, so I don't think I'll need the semaphore.
Thanks again for the great help.
Jim
Humanoido
See attachment. Question: is there a way to insert code in the new forum?
Thanks for the feedback.
Jim
Humanoido
I tried to do it from memory and got the format wrong...
Humanoido
http://forums.parallax.com/forumdisplay.php?f=45
Humanoido
I was used to using the buttons in the old forum...
Thanks