这是官方例程pinstandby,它只是在线程里调用sleep()
int main(void)
{
pthread_t thread;
pthread_attr_t pAttrs;
struct sched_param priParam;
int retc;
int detachState;
/* Call driver init functions */
Board_initGeneral();
/* Set priority and stack size attributes */
pthread_attr_init(&pAttrs);
priParam.sched_priority = 1;
detachState = PTHREAD_CREATE_DETACHED;
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}
pthread_attr_setschedparam(&pAttrs, &priParam);
retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}
retc = pthread_create(&thread, &pAttrs, mainThread, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
BIOS_start();
return (0);
}
void *threadFxn0(void *arg0)
{
PIN_State pinState;
PIN_Handle hPin;
uint_t currentOutputVal;
uint32_t standbyDuration = 5;
/* Allocate LED pins */
hPin = PIN_open(&pinState, LedPinTable);
/* Loop forever */
while(1) {
/* Sleep, to let the power policy transition the device to standby */
sleep(standbyDuration);
/* Read current output value for all pins */
currentOutputVal = PIN_getPortOutputValue(hPin);
/* Toggle the LEDs, configuring all LEDs at once */
PIN_setPortOutputValue(hPin, ~currentOutputVal);
}
}
/*
* ======== mainThread ========
*/
void *mainThread(void *arg0)
{
pthread_t thread0;
pthread_attr_t pAttrs;
struct sched_param priParam;
int retc;
int detachState;
/* Shut down external flash on LaunchPads. It is powered on by default
* but can be shut down through SPI
*/
#if defined(CC2650_LAUNCHXL) || defined(CC2640R2_LAUNCHXL) || defined(CC1310_LAUNCHXL) || defined(CC1350_LAUNCHXL)
SPI_init();
bool extFlashOpened = ExtFlash_open();
if (extFlashOpened) {
ExtFlash_close();
}
#endif
/* Create application thread */
pthread_attr_init(&pAttrs);
detachState = PTHREAD_CREATE_DETACHED;
/* Set priority and stack size attributes */
retc = pthread_attr_setdetachstate(&pAttrs, detachState);
if (retc != 0) {
/* pthread_attr_setdetachstate() failed */
while (1);
}
retc |= pthread_attr_setstacksize(&pAttrs, THREADSTACKSIZE);
if (retc != 0) {
/* pthread_attr_setstacksize() failed */
while (1);
}
/* Create threadFxn0 thread */
priParam.sched_priority = 1;
pthread_attr_setschedparam(&pAttrs, &priParam);
retc = pthread_create(&thread0, &pAttrs, threadFxn0, NULL);
if (retc != 0) {
/* pthread_create() failed */
while (1);
}
return (NULL);
}
|