int main (int argc, char* argv[]) { int n; int cog; int pin[] = { 16, 17, 18, 19, 20, 21, 22, 23 }; unsigned int nextcnt; wait_time = CLKFREQ/20; syncstart = 0; for(n = 1; n < COGS; n++) { cog = _start_cog_thread(cog_stack[n] + STACK_SIZE, do_toggle, (void*)pin[n], &thread_data); printf("Toggle COG %d Started\n", cog); } startcnt = CNT; syncstart = 1; nextcnt = wait_time + startcnt; while(1) { high(pin[0]); nextcnt = waitcnt2(nextcnt, wait_time); low(pin[0]); nextcnt = waitcnt2(nextcnt, wait_time); } return 0; }
_NATIVE void main (volatile struct toggle_mailbox *m) { /* add the base pin number and make a mask */ pinmask = (1 << m->basepin + pinmask); /* get a half second delay from parameters */ _DIRA = pinmask; /* make the token delay 1 second */ tokendelay = *CLKFREQ_P; /* figure out how long to wait the first time */ nextcnt = _CNT + m->wait_time; /* loop forever, updating the wait time from the mailbox */ for (;;) { if (m->token) { m->wait_time >>= 1; if (m->wait_time < MIN_GAP) m->wait_time = *CLKFREQ_P; nextcnt = waitcnt2(_CNT + tokendelay, m->wait_time); m->next->token = 1; m->token = 0; } else {
/* * toggle thread function gets started in an LMM COG. * param arg = pin number to toggle */ void do_toggle(void *arg) { int pin = (int) arg; unsigned int nextcnt; while(syncstart == 0) ; // wait for start signal from main cog nextcnt = wait_time + startcnt; while(1) { high(pin); nextcnt = waitcnt2(nextcnt, wait_time); low(pin); nextcnt = waitcnt2(nextcnt, wait_time); } }
_NAKED void main (volatile struct toggle_mailbox *m) { /* get which pins to toggle from parameters */ pins = m->pins; _OUTA = 0; _DIRA = pins; /* figure out how long to wait the first time */ nextcnt = _CNT + m->wait_time; /* loop forever, updating the wait time from the mailbox */ for(;;) { waitdelay = m->wait_time; _OUTA ^= pins; togglecount++; nextcnt = waitcnt2(nextcnt, waitdelay); //waitcnt(CNT+waitdelay); } }
/* figure out how long to wait the first time */ nextcnt = _CNT + m->wait_time; /* loop forever, updating the wait time from the mailbox */ for (;;) { if (m->token) { m->wait_time >>= 1; if (m->wait_time < MIN_GAP) m->wait_time = *CLKFREQ_P; nextcnt = waitcnt2(_CNT + tokendelay, m->wait_time); m->next->token = 1; m->token = 0; } else { _OUTA ^= pinmask; nextcnt = waitcnt2(nextcnt, m->wait_time); } } } /* +-------------------------------------------------------------------- * ¦ TERMS OF USE: MIT License * +-------------------------------------------------------------------- * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files * (the "Software"), to deal in the Software without restriction, * including without limitation the rights to use, copy, modify, merge, * publish, distribute, sublicense, and/or sell copies of the Software, * and to permit persons to whom the Software is furnished to do so, * subject to the following conditions: *