PDA

View Full Version : XMMC and cog threads



pinedust
04-12-2012, 11:27 PM
Hi all, I have some time today and am having fun playing.

I am wondering if I can use cog threads with the XMMC from my SD card on my GG PPUSB board.

This is a simple example of what I am trying to do.


/**
* @file cog_thread.c
* This is the main cog_thread program start point.
*/
#include <stdio.h>
#include <sys/thread.h>
#include <propeller.h>

#define STACK_SIZE 16

static int cogStack[STACK_SIZE];

static _thread_state_t threadData;

void cogFunc(void *arg);

/**
* Main program function.
*/
int main(void)
{
int cogID;

waitcnt(CNT + CLKFREQ);

cogID = _start_cog_thread(cogStack+STACK_SIZE, cogFunc, (void*)0, &threadData);
printf("CogID: %d\n", cogID);

return 0;
}

void cogFunc(void *arg)
{
for(;;) {
waitpeq(0x00, 0x01 << 16);
}
}

LMM and PPUSB works:
CogID: 1
XMMC and PPUSB-SDXMMC does not:
CogID: -1

denominator
04-13-2012, 12:58 AM
I am wondering if I can use cog threads with the XMMC from my SD card on my GG PPUSB board.


According to http://propgcc.googlecode.com/hg/doc/Library.html, _start_cog_thread is LMM-only and will always return an error in the XMM* modes. It is a limitation of the XMMC and XMM kernels that you can have only one running XMM C cog, so you must use pthreads (http://forums.parallax.com/showthread.php?137776-What-is-a-pthread) to get multithreading. You can also load additional cogs with PASM and cog-mode C programs.

The rest of the PropGCC users might be more sure to see and respond if you posted follow-up questions in the Propeller GCC Alpha Test Forum?

pinedust
04-13-2012, 01:49 AM
According to http://propgcc.googlecode.com/hg/doc/Library.html, _start_cog_thread is LMM-only and will always return an error in the XMM* modes. It is a limitation of the XMMC and XMM kernels that you can have only one running XMM C cog, so you must use pthreads (http://forums.parallax.com/showthread.php?137776-What-is-a-pthread) to get multithreading. You can also load additional cogs with PASM and cog-mode C programs.Thanks, I will look into those options. I have worked with pthreads before, but have never tried loading cog mode C programs.



The rest of the PropGCC users might be more sure to see and respond if you posted follow-up questions in the Propeller GCC Alpha Test Forum?Yes, I meant to put the original post in that sub thread.

denominator
04-13-2012, 02:23 AM
Thanks, I will look into those options. I have worked with pthreads before, but have never tried loading cog mode C programs.


A good place to start might be the demos. Check out the propboe demo, especially the propboe/libsrc subdirectory - the I2C driver is written in cog mode C.

denominator
04-13-2012, 03:13 PM
A simpler place to start might be the toggle demos in demos/toggle/cog_c_toggle.