60 lines
1017 B
C
60 lines
1017 B
C
|
/*
|
||
|
* 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);
|
||
|
|
||
|
void uart_receive_data(uint8_t* chara);
|
||
|
|
||
|
|
||
|
#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_ */
|