Shop OBEX P1 Docs P2 Docs Learn Events
XMMC and cog threads — Parallax Forums

XMMC and cog threads

pinedustpinedust Posts: 19
edited 2012-04-13 07:13 in Propeller 1
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

Comments

  • denominatordenominator Posts: 242
    edited 2012-04-12 16:58
    pinedust wrote: »
    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?
  • pinedustpinedust Posts: 19
    edited 2012-04-12 17:49
    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.
  • denominatordenominator Posts: 242
    edited 2012-04-12 18:23
    pinedust wrote: »
    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.
  • denominatordenominator Posts: 242
    edited 2012-04-13 07:13
    A simpler place to start might be the toggle demos in demos/toggle/cog_c_toggle.
Sign In or Register to comment.