Buffered Serial Port Driver for RTOS tested with a K64F

Dependents:   JRO_CR2 frdm_test JRO_DDSv2 JRO_DDSv2_rev2019

Fork of SerialDriver by BlazeX .

Committer:
miguelcordero191
Date:
Tue Feb 10 14:29:32 2015 +0000
Revision:
5:ee58295c58e1
Parent:
1:1464146bd7fb
This library just was modified when a K64F is used

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BlazeX 0:cd0d79be0c1a 1 /// @file Example_printf.cpp
BlazeX 0:cd0d79be0c1a 2 /// @brief Formatted output
BlazeX 0:cd0d79be0c1a 3 ///
BlazeX 0:cd0d79be0c1a 4 /// - Uses SerialDriver with USBTX and USBRX.
BlazeX 0:cd0d79be0c1a 5 /// - Has much too small buffers, but printf is blocking, so it does not matter
BlazeX 0:cd0d79be0c1a 6 ///
BlazeX 0:cd0d79be0c1a 7 /// - The terminal will be flooded with text
BlazeX 0:cd0d79be0c1a 8 /// - LED4 indicates parallel thread working
BlazeX 0:cd0d79be0c1a 9 ///
BlazeX 0:cd0d79be0c1a 10
BlazeX 0:cd0d79be0c1a 11 #if 0
BlazeX 0:cd0d79be0c1a 12
BlazeX 0:cd0d79be0c1a 13 #include "SerialDriver.h"
BlazeX 0:cd0d79be0c1a 14
BlazeX 0:cd0d79be0c1a 15 // only 4 byte of software ring buffer?
BlazeX 0:cd0d79be0c1a 16 // No problem! SerialDriver uses idle blocking calls :D
BlazeX 0:cd0d79be0c1a 17 SerialDriver pc(USBTX, USBRX, 4, 4);
BlazeX 0:cd0d79be0c1a 18
BlazeX 0:cd0d79be0c1a 19 // This thread is running in parallel
BlazeX 0:cd0d79be0c1a 20 DigitalOut led4(LED4);
BlazeX 0:cd0d79be0c1a 21 void parallel(void const * argument)
BlazeX 0:cd0d79be0c1a 22 {
BlazeX 0:cd0d79be0c1a 23 while(1)
BlazeX 0:cd0d79be0c1a 24 {
BlazeX 0:cd0d79be0c1a 25 Thread::wait(20);
BlazeX 0:cd0d79be0c1a 26 led4= !led4;
BlazeX 0:cd0d79be0c1a 27 }
BlazeX 0:cd0d79be0c1a 28 }
BlazeX 0:cd0d79be0c1a 29
BlazeX 0:cd0d79be0c1a 30 int main()
BlazeX 0:cd0d79be0c1a 31 {
BlazeX 0:cd0d79be0c1a 32 // Start the other thread
BlazeX 0:cd0d79be0c1a 33 Thread parallelTask(&parallel);
BlazeX 0:cd0d79be0c1a 34
BlazeX 0:cd0d79be0c1a 35 float f= 0.0f;
BlazeX 0:cd0d79be0c1a 36 while(1)
BlazeX 0:cd0d79be0c1a 37 {
BlazeX 0:cd0d79be0c1a 38 // unformatted text
BlazeX 0:cd0d79be0c1a 39 pc.puts("Hi! this uses puts.\r\n");
BlazeX 0:cd0d79be0c1a 40
BlazeX 0:cd0d79be0c1a 41 // formatted text
BlazeX 0:cd0d79be0c1a 42 pc.printf("And this is formatted. Here is the sin(%f)=%f.\r\n", f, sinf(f));
BlazeX 0:cd0d79be0c1a 43 f+= 0.25f;
BlazeX 0:cd0d79be0c1a 44 }
BlazeX 0:cd0d79be0c1a 45 }
BlazeX 0:cd0d79be0c1a 46
BlazeX 0:cd0d79be0c1a 47 #endif