Link here

USB C Demo

C language demonstration program with examples of how to use the USB Wildcard library of driver functions


The USB Wildcard™ implements a standard USB (Universal Serial Bus) interface that enables a PC host to communicate with Mosaic's microcontroller-based embedded computers to implement remote data loggers, data acquisition systems, and instrumentation. This tiny 2" by 2.5" board is a member of the Wildcard series of mezzanine boards that connect to Mosaic embedded instrument controllers.


USB C Demo

// ****************************************************************************************
// FILE NAME: USBDemo.c
// copyright 2008 Mosaic Industries, Inc. All rights reserved.
// ---------------------------------------------------------------------
// DATE: 4/3/2009
// VERSION: 1.2, for QED/Q-Line (HC-11) and PDQ line (HCS-12) controllers
// ---------------------------------------------------------------------
// This is the demonstration code for the USB Wildcard.
// Please see its User Guide for more details.
// QED/Q-Line:
// The USB Wildcard kernel extension file Install.txt
// MUST be loaded into memory before this file can be loaded.
// This is an illustrative demonstration ("demo") program that
// shows how to run a task using the USB Wildcard serial port. The task simply
// echoes incoming characters back to the terminal.
// When the top level function main() is running, the controller
// is simultaneously using 2 serial ports:
// the standard primary serial port is running the QED interactive monitor,
// and the USB serial channel on the USB Wildcard is echoing characters.
//
// The QED operating system supports revectorable I/O, meaning that
// in any given task the standard C serial I/O routines such as
// putchar, puts, getchar, gets, printf, and scanf can be made to use
// any specified serial channel. All that is required is to customize
// three functions named Key, AskKey, and Emit to the specified serial channel
// for the specified task. This file shows how to do this
// using the functions defined in the USB Wildcard kernel extension.
//
// MAKE SURE THAT THE USB_MODULE_NUM CONSTANT MATCHES YOUR HARDWARE JUMPER SETTINGS!!
// ---------------------------------------------------------------------
// Demonstration functions defined in this file:
// USB_MODULE_NUM // this constant MUST match hardware jumper settings!
// void USB_Monitor(void) // infinite task loop, echoes all incoming chars on usb
// void USB_Demo(void)
// builds and activates an echoing monitor task on the usb port,
// leaving the standard monitor running on the rs232 port.
// void main(void) // runs the demo program
// ---------------------------------------------------------------------
// Disclaimer: THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT
// ANY WARRANTIES OR REPRESENTATIONS EXPRESS OR IMPLIED,
// INCLUDING, BUT NOT LIMITED TO, ANY IMPLIED WARRANTIES
// OF MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE.
//
// *********************************************************************
 
#include <mosaic\allqed.h>
#ifdef __GNUC__
// For PDQ line platforms, the driver is enabled by simply including
// the header file below.
#include <wusb.h>
#else
// For the QED/Q line platform, we include the kernel extension manager
// generated library.c. We assume that it is present in this directory.
#include "library.h"
#include "library.c"
#endif // __GNU__
// ******************* DEMONSTRATION PROGRAM ***************************
// The default task runs an interactive monitor as usual, using the 68HC11/12 UART.
// We create a second task that echoes all incoming chars via the USB Wildcard serial port.
// To run this demonstration, simply execute:
// main
// You'll be running the standard monitor on the RS232 port,
// plus an independent serial-echo task on the USB port.
// You can open two instances of the Mosaic terminal, one for each task,
// and interact with both tasks. Use the terminal's
// Settings -> Comm -> Port menu item to specify the USB's comm port.
 
// NOTE: YOU MUST MAKE SURE THAT USB_MODULE_NUM CONSTANT MATCHES YOUR HARDWARE JUMPERS!!
#define USB_MODULE_NUM 0 // double check your hardware jumper settings!!!
 
// Define and allocate RAM for the task areas:
TASK usb_task; // 1 Kbyte per task area
 
 
void USB_Monitor(void)
// infinite task loop for usb_task, simply echoes all incoming chars on usb
{   uchar this_char;
    USB_Revector();
    printf("Ready to echo incoming characters on USB...\r\n");
    while(1) // infinite task loop
    {   this_char = USB_Key();
        USB_Emit( this_char );
    }
}
 
void USB_Demo(void)
// builds and activates an echoing monitor task on the usb port,
// leaving the standard monitor running on the rs232 port.
{   usb_module = USB_MODULE_NUM;
    printf("\nStarting USB Wildcard Demo...\r\n");
    SERIAL_ACCESS = RELEASE_ALWAYS; // ensure lots of PAUSEs in Forth task
    NEXT_TASK = TASKBASE; // required! empty the round-robin task loop
    BUILD_C_TASK(0,0,&usb_task); // no heap needed
    ACTIVATE(USB_Monitor,&usb_task);
    StartTimeslicer(); // enable task switching
}
 
int main(void)
{   USB_Demo();
    printf("USB Demo task has been set up; use the Mosaic Terminal to exercise it.\r\n");
    return (0);
}



See also → USB Wildcard Users Guide
USB Forth Demo

 
This page is about: C Language Demonstration Program, USB Wildcard Driver Library – C language demonstration program with examples of how to use the USB Wildcard library of driver functions
 
 
Navigation