Welcome to Hackster!
Hackster is a community dedicated to learning hardware, from beginner to pro. Join us, it's free!
Guilherme Fernandes
Published © GPL3+

Real Time Scheduler on Windows Embedded Compact

Learn how to make use of the Windows CE real-time scheduler in this simple GPIO toggling article.

BeginnerProtip2 hours782
Real Time Scheduler on Windows Embedded Compact

Things used in this project

Hardware components

Colibri Vybrid
Toradex Colibri Vybrid
Colibri VF61
×1
Iris Carrier Board
Toradex Iris Carrier Board
×1

Story

Read more

Code

GPIO demo

C/C++
Simply compile for Windows CE and run
/// @file         Gpio_Demo.c
/// @copyright    Copyright (c) 2014 Toradex AG
/// $Author: guilherme.fernandes $
/// $Revision: 2908 $
/// $Date: 2015-08-10 08:29:50 +0200 (Mo, 10 Aug 2015) $
/// @brief        Program to show how to use the Gpio Library 
///               
/// @target       Colibri VFxx,Txx,iMx Modules
/// @test         Tested on:  VFxx
/// @caveats      None
 
#include  
#include "gpio.h"
 
// === define constant pins / gpios ===
uIo io1 = COLIBRI_PIN(101);  
HANDLE hGpio;
HANDLE hThreadON, hThreadOFF;
 
DWORD WINAPI ThreadON (void){
	//Set Thread Priority
	CeSetThreadPriority(GetCurrentThread(), 100);
	Sleep(5); //Allow the other Thread to configure its PRIO
	//INFINITE LOCKING LOOP
	while ( 1 ){
		//Set GPIO logic high
		Gpio_SetLevel(hGpio, io1, ioHigh);
   }
   return 0;
}
 
 
DWORD WINAPI ThreadOFF (void){
	//Set Thread Priority
	CeSetThreadPriority(GetCurrentThread(), 100);
	//INFINITE LOCKING LOOP
	while ( 1 ){
		//Set GPIO logic low
		Gpio_SetLevel(hGpio, io1, ioLow);
   }
   return 0;
}
 
 
//=============================================================================
// Application Entry Point
// 
// The simple error handling using ASSERT statements is only effective when 
// the application is run as a debug version.
//=============================================================================
int wmain(int argc, _TCHAR* argv[])   
{ 
   //HANDLE hGpio = NULL;            ///< handle to the GPIO library
   BOOL success;
 
   // === Initialize GPIO library. ===
   // We don't use registry-based  configuration, thus we can 
   // pass NULL go Gpio_Init()
   hGpio = Gpio_Init(NULL);   
   ASSERT(hGpio != 0);
   success = Gpio_Open(hGpio);
   ASSERT (success);
 
   // === Io Manipulation ===
   // Configure the pin to act as GPIO (as opposed to an Alternate function)
   // Set it to Output,  High
   Gpio_ConfigureAsGpio(hGpio, io1);
   Gpio_SetDir         (hGpio, io1, ioOutput);
   Gpio_SetLevel       (hGpio, io1, ioHigh);
 
	CeSetThreadPriority(GetCurrentThread(), 99);
 
	//Create two concorrent Threads, one set GPIO to High and other to Low
	hThreadON = CreateThread (0, 0, ThreadON, 0, 0, 0);
	hThreadOFF = CreateThread (0, 0, ThreadOFF, 0, 0, 0);
 
	//Time to finish the Program
	Sleep(3000);
 
   return(TRUE);
}

Credits

Guilherme Fernandes
1 project • 1 follower
Contact

Comments

Please log in or sign up to comment.