Created
July 6, 2015 15:44
-
-
Save kcmannem/03a3c0c0322b07fc2113 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdbool.h> | |
#include <stdint.h> | |
#include "inc/hw_i2c.h" | |
#include "inc/hw_ints.h" | |
#include "inc/hw_memmap.h" | |
#include "inc/hw_types.h" | |
#include "inc/hw_gpio.h" | |
#include "driverlib/sysctl.h" | |
#include "driverlib/gpio.h" | |
#include "driverlib/pin_map.h" | |
#include "driverlib/rom.h" | |
#include "driverlib/uart.h" | |
#include "driverlib/fpu.h" | |
typedef struct { | |
uint8_t lenght; | |
char cmd[]; | |
} AT_CMD; | |
const AT_CMD _AT = {4, "AT\r\n"}; | |
const AT_CMD _ATE0 = {6, "ATE0\r\n"}; | |
const AT_CMD _ATRST = {8, "AT+RST\r\n"}; | |
const AT_CMD _ATRSTCWJAP = {34, "AT+CWJAP_DEF=\"man24\",\"smannem24\"\r\n"}; | |
const AT_CMD _ATCWLAP = {10, "AT+CWLAP\r\n"}; | |
const AT_CMD _ATCWMODE_CUR = {16,"AT+CWMODE_CUR?\r\n"}; | |
const AT_CMD _ATCWMODE = {11,"AT+CWMODE=3\r\n"}; | |
typedef void (*ResponseOperator)(char dataFromHW); | |
void uartInit_DEBUG(void); | |
void uartInit_Wifi(void); | |
void UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count); | |
void sendWifiCommandBlocking(const AT_CMD *cmd); | |
void operateOnResponseData(ResponseOperator operation); | |
void printToDebugConsole(char characterToWrite); | |
void delay_mS(uint32_t ms); | |
//void checkForSuccess(char *dataFromHW); | |
int main(void){ | |
ROM_FPUEnable(); | |
ROM_FPULazyStackingEnable(); | |
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ); | |
ROM_IntMasterEnable(); | |
uartInit_DEBUG(); | |
uartInit_Wifi(); | |
sendWifiCommandBlocking(&_ATRST); | |
delay_mS(2000); | |
operateOnResponseData(&printToDebugConsole); | |
//sendWifiCommandBlocking(&_ATE0); | |
//operateOnResponseData(&printToDebugConsole); | |
while(1); | |
} | |
void UARTSendDEBUG(const uint8_t *pui8Buffer, uint32_t ui32Count) | |
{ | |
while(ui32Count--) | |
{ | |
ROM_UARTCharPutNonBlocking(UART0_BASE, *pui8Buffer++); | |
while (ROM_UARTBusy(UART0_BASE)); | |
} | |
} | |
void sendWifiCommandBlocking(const AT_CMD *wificmd) | |
{ | |
for(uint8_t n =0; n < wificmd->lenght; n++) { | |
ROM_UARTCharPutNonBlocking(UART1_BASE, wificmd->cmd[n]); | |
while (ROM_UARTBusy(UART1_BASE)); | |
} | |
while(!ROM_UARTCharsAvail(UART1_BASE)); | |
} | |
void operateOnResponseData(ResponseOperator operation) | |
{ | |
//char buffer[100]; | |
while(ROM_UARTCharsAvail(UART1_BASE)) { | |
operation(ROM_UARTCharGetNonBlocking(UART1_BASE)); | |
} | |
} | |
/* | |
void checkForSuccess(char *dataFromHW) | |
{ | |
//int lenght = (sizeof dataFromHW)/8; | |
}*/ | |
void printToDebugConsole(char characterToWrite) { | |
if (characterToWrite != '\r') { | |
ROM_UARTCharPutNonBlocking(UART0_BASE ,characterToWrite); | |
} | |
} | |
void uartInit_DEBUG() | |
{ | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0); | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA); | |
ROM_GPIOPinConfigure(GPIO_PA0_U0RX); | |
ROM_GPIOPinConfigure(GPIO_PA1_U0TX); | |
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1); | |
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); | |
} | |
void uartInit_Wifi(void) | |
{ | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1); | |
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOB); | |
ROM_GPIOPinConfigure(GPIO_PB0_U1RX); | |
ROM_GPIOPinConfigure(GPIO_PB1_U1TX); | |
ROM_GPIOPinTypeUART(GPIO_PORTB_BASE, GPIO_PIN_0 | GPIO_PIN_1); | |
ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 9600, | |
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE)); | |
ROM_IntEnable(INT_UART1); | |
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT); | |
delay_mS(1); | |
} | |
void delay_mS(uint32_t ms) { | |
uint16_t cnt =1001; | |
while(cnt-- > 1){ | |
ROM_SysCtlDelay((ROM_SysCtlClockGet()/(3*1000000)*ms )); // more accurate | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment