2022-05-19 08:57:38 -04:00
|
|
|
/*
|
|
|
|
* uart.h
|
|
|
|
*
|
|
|
|
* Created on: 15 Mar 2022
|
|
|
|
* Author: pika
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef UART_H_
|
|
|
|
#define UART_H_
|
|
|
|
|
|
|
|
#ifndef __SYSTEM_LPC17xx_H
|
|
|
|
#define __SYSTEM_LPC17xx_H
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef __USE_CMSIS
|
|
|
|
#include "LPC17xx.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <cr_section_macros.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
#endif /* __SYSTEM_LPC17xx_H */
|
|
|
|
|
|
|
|
#define DLAB_SET LPC_UART1->LCR |= (1<<7) //DLAB == 1
|
|
|
|
#define DLAB_CLR LPC_UART1->LCR &= ~(1<<7) //DLAB == 0 //not needed
|
|
|
|
|
|
|
|
#define SIZE_OF_BUFFER 8
|
|
|
|
#define UART_PCLK (100000000)
|
|
|
|
|
|
|
|
typedef struct circbuff_t{
|
|
|
|
uint8_t data[SIZE_OF_BUFFER];
|
|
|
|
uint16_t ptr_write;
|
|
|
|
uint16_t ptr_read;
|
|
|
|
} circbuff;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void uart_init(uint32_t baudrate);
|
|
|
|
|
|
|
|
void uart_send(char* buff, uint32_t length);
|
|
|
|
|
|
|
|
void uart_receive_command(char* chara);
|
|
|
|
|
2022-05-22 13:52:44 -04:00
|
|
|
void uart_receive_data(uint8_t* chara, int size);
|
2022-05-19 08:57:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
#define THRE (1<<5)
|
|
|
|
#define MULVAL 15
|
|
|
|
#define DIVADDVAL 2
|
|
|
|
#define Ux_FIFO_EN (1<<0)
|
|
|
|
#define RX_FIFO_RST (1<<1)
|
|
|
|
#define TX_FIFO_RST (1<<2)
|
|
|
|
#define DLAB_BIT (1<<7)
|
|
|
|
#define CARRIAGE_RETURN 0x0D
|
|
|
|
|
|
|
|
#endif /* UART_H_ */
|