teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

uart.cpp

Committer:
takeru0x1103
Date:
2018-12-01
Revision:
18:5aa48aec9cae
Parent:
17:f9610f3cfa1b
Child:
19:4b0fe9a5ec38

File content as of revision 18:5aa48aec9cae:

#include "typedef.h"
#include "uart.h"
#include "hbCommand.h"

//ログ吐出し様シリアルポートインスタンス
//----------------------------------
#define WIREED_SERIAL
#ifdef  WIREED_SERIAL
    Serial sp(USBTX, USBRX); //有線のポート
    #define BAUD_RATE   115200
#else
    Serial  sp(p9, p10);//TWILITEをモジュールを接続したポート
    #define BAUD_RATE   115200
#endif

//Serial sp46Axis(p28,p27);

//Asciiコード
#define CR 0x0D
#define LF 0x0A
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// UART 受信割り込みハンドラ
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void uartRxIntHndler(){
    //1Byte抜き出す
    UCHAR buf = sp.getc();
    //エコーバック
    sp.putc(buf);    
    //コマンドバッファに突っ込む
    commandPush(buf);
}

//=============================================================
//初期設定
//=============================================================
void uartInit(){
    //ボーレート設定
    sp.baud(BAUD_RATE);
    
    //受信割り込みハンドラ登録(登録するハンドラ,割り込み要因)
    sp.attach(uartRxIntHndler,Serial::RxIrq);
        
    sp.printf("***********\r\n");
    sp.printf("UART open!!\r\n");    
    sp.printf("-----------\r\n");
    sp.printf("INT16        = %d\r\n" ,sizeof(INT16) );
    sp.printf("unsigned int = %d\r\n" ,sizeof(unsigned int) );
    sp.printf("long         = %d\r\n" ,sizeof(unsigned long) );
    sp.printf("unsigned int = %d\r\n" ,sizeof(unsigned int) );
    sp.printf("***********\r\n");
}