afLib 1.3 which is supporting both SPI and UART

Dependencies:   vt100 mbed afLib_1_3

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers af_mgr.cpp Source File

af_mgr.cpp

00001 #include "mbed.h"
00002 #include "string.h"
00003 #include "edge_mgr.h"
00004 #include "edge_time.h"
00005 #include "edge_pin.h"
00006 #include "afLib.h"
00007 #include "af_attributes.h"
00008 #include "afTransport.h"
00009 #include "msg_types.h"
00010 #include "mbedSPI.h"
00011 #include "mbedUART.h"
00012 #include "af_mgr.h"
00013 
00014 #define ASR_USE_SPI 0
00015 #define ASR_USE_UART 1
00016 
00017 afLib           *afero = 0 ;
00018 InterruptIn     *afero_int = 0 ;
00019 afTransport     *afero_spi = 0 ;
00020 afTransport     *afero_uart = 0 ;
00021 DigitalOut      *afero_reset ;
00022 bool            gLinked = false ;
00023 bool            gConnected = false ;
00024 
00025 void afero_isr(void)
00026 {
00027     afero->mcuISR() ;
00028 }
00029 
00030 void init_aflib(void)
00031 {
00032     afero_reset = new DigitalOut(PIN_ASR_RESET, 1) ; /* create as deasserted */
00033     Serial *theLog = new Serial(USBTX, USBRX, 115200) ;
00034 
00035 #if (ASR_USE_SPI)
00036 tty->printf("afero is using SPI\n") ;
00037     afero_spi = (afTransport*) new mbedSPI(PIN_MOSI, PIN_MISO, PIN_SCK, PIN_CS) ;
00038     afero = new afLib(
00039         PIN_INTR,
00040         afero_isr,
00041         attributeChangeRequest,
00042         attributeUpdatedReport,
00043         theLog, /* Stream for log */
00044         (afTransport *)afero_spi ) ;
00045 #elif (ASR_USE_UART)
00046 tty->printf("afero is using UART2\n") ;
00047     afero_uart = (afTransport*) new mbedUART(PIN_UART2_RX, PIN_UART2_TX, theLog) ;
00048     afero = new afLib(
00049         PIN_INTR,
00050         0,
00051         attributeChangeRequest,
00052         attributeUpdatedReport,
00053         theLog, /* Stream for log */
00054         (afTransport *)afero_uart ) ;
00055 #endif
00056 
00057     wait(0.1) ;
00058     *afero_reset = 0 ;
00059     wait(0.5) ; /* required 250ms ~ time for reset */
00060     *afero_reset = 1 ;       
00061     wait(0.5) ;
00062 }