teamALI / Mbed 2 deprecated HB2018

Dependencies:   mbed FreeRTOS

uart.cpp

Committer:
MasashiNomura
Date:
2018-11-23
Revision:
4:7aa8cf0dd56f
Parent:
2:f0fbb23b4605

File content as of revision 4:7aa8cf0dd56f:

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

//#define WIREED_SERIAL

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

Serial sp46Axis(p28,p27);
#define BAUD_RATE4_6AXIS   115200

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

//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
// UART 受信割り込みハンドラ for Arduino UNO(Six Axis Sensor)
//+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
void uartRxIntHndler46Axis(){
    //1Byte抜き出す
    UCHAR buf = sp46Axis.getc();
    //エコーバック
    sp46Axis.putc(buf);
    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("short = %d\r\n" ,sizeof(unsigned short) );
    sp.printf("int   = %d\r\n" ,sizeof(unsigned int) );
    sp.printf("long  = %d\r\n" ,sizeof(unsigned long) );
    sp.printf("***********\r\n");

    // for 6Axis Sensor
    //ボーレート設定
    sp46Axis.baud(BAUD_RATE4_6AXIS);
    
    //受信割り込みハンドラ登録
    sp46Axis.attach
        (uartRxIntHndler46Axis    //登録するハンドラ
        ,Serial::RxIrq           //割り込み要因
        );
        
    sp46Axis.printf("***********\r\n");
    sp46Axis.printf("UART open!!\r\n");    
    sp46Axis.printf("-----------\r\n");
    sp46Axis.printf("short = %d\r\n" ,sizeof(unsigned short) );
    sp46Axis.printf("int   = %d\r\n" ,sizeof(unsigned int) );
    sp46Axis.printf("long  = %d\r\n" ,sizeof(unsigned long) );
    sp46Axis.printf("***********\r\n");
}