Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
nimaltd authored Apr 14, 2021
1 parent d2f0f41 commit 8600c9f
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 37 deletions.
26 changes: 2 additions & 24 deletions atc.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,15 @@ void atc_free(void *ptr)
#endif
}
//####################################################################################################
#ifdef HAL_MODULE_ENABLED
void atc_init(atc_t *atc, const char *name, UART_HandleTypeDef *USARTx, void *found)
#elif
void atc_init(atc_t *atc, const char *name, USART_TypeDef *USARTx, void *found)
#endif
{
if (atc->inited == true)
return;
memset(atc, 0, sizeof(atc_t));
strncpy(atc->name, name, sizeof(atc->name) - 1);
atc->usart = USARTx;
atc->found = found;
#ifdef HAL_MODULE_ENABLED
#elif
LL_USART_EnableIT_RXNE(atc->usart);
#endif
atc->inited = true;
atc_printf("\r\n[%s] inited.\r\n", atc->name);
}
Expand Down Expand Up @@ -75,10 +68,6 @@ void atc_unlock(atc_t *atc)
//####################################################################################################
void atc_transmit(atc_t *atc, uint8_t *data, uint16_t len)
{
#ifdef HAL_MODULE_ENABLED
HAL_UART_Transmit_IT(atc->usart,data,len);
atc_delay(1);
#elif
for (uint16_t i = 0; i < len; i++)
{
while (!LL_USART_IsActiveFlag_TXE(atc->usart))
Expand All @@ -87,26 +76,16 @@ void atc_transmit(atc_t *atc, uint8_t *data, uint16_t len)
}
while (!LL_USART_IsActiveFlag_TC(atc->usart))
atc_delay(1);
#endif
}
//####################################################################################################
void atc_rxCallback(atc_t *atc)
{
#ifdef HAL_MODULE_ENABLED
if (atc->rxIndex < _ATC_RXSIZE - 1)
{
atc->rxBuffer[atc->rxIndex] = atc->tmp;
atc->rxIndex++;
}
atc->rxTime = HAL_GetTick();
HAL_UART_Receive_IT(atc->usart, &atc->tmp, 1);
#elif
if (LL_USART_IsActiveFlag_RXNE(atc->usart))
{
atc->tmp = LL_USART_ReceiveData8(atc->usart);
uint8_t tmp = LL_USART_ReceiveData8(atc->usart);
if (atc->rxIndex < _ATC_RXSIZE - 1)
{
atc->rxBuffer[atc->rxIndex] = atc->tmp;
atc->rxBuffer[atc->rxIndex] = tmp;
atc->rxIndex++;
}
atc->rxTime = HAL_GetTick();
Expand All @@ -120,7 +99,6 @@ void atc_rxCallback(atc_t *atc)
// LL_USART_ClearFlag_ORE(atc->usart);
// if (LL_USART_IsActiveFlag_NE(atc->usart))
// LL_USART_ClearFlag_NE(atc->usart);
#endif
}
//####################################################################################################
void atc_search(atc_t *atc)
Expand Down
12 changes: 1 addition & 11 deletions atc.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
*/

/*
* Version: 3.0.3
* Version: 3.0.2
*
* History:
*
* (3.0.3): Added check for HAL && LL.
* (3.0.2): Clear answer buffer before use.
* (3.0.1): Change some defines.
* (3.0.0): Rewrite again. Support NONE-RTOS, RTOS V1 and RTOS V2.
Expand Down Expand Up @@ -46,15 +45,10 @@ typedef struct
char *search[_ATC_SEARCH_MAX];
char *searchCmd[_ATC_SEARCH_CMD_MAX];
uint8_t searchIndex;
uint8_t tmp;
char name[8];

bool lock;
#ifdef HAL_MODULE_ENABLED
UART_HandleTypeDef *usart;
#elif
USART_TypeDef *usart;
#endif
void (*found)(char *foundStr);

} atc_t;
Expand All @@ -66,11 +60,7 @@ typedef struct
* USARTx: selected USART
* found: atc found function. auto called after found strings you added before. do not use atc_command function into this
*/
#ifdef HAL_MODULE_ENABLED
void atc_init(atc_t *atc, const char *name, UART_HandleTypeDef *USARTx, void *found);
#elif
void atc_init(atc_t *atc, const char *name, USART_TypeDef *USARTx, void *found);
#endif
//###############################################################################################################
/*
* put in usart rx interrupt
Expand Down
4 changes: 2 additions & 2 deletions atcConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#define _ATCCONFIG_H_

#define _ATC_DEBUG 0 // use printf debug
#define _ATC_RTOS 0 // 0: no rtos 1: cmsis_os v1 2: cmsis_os v2
#define _ATC_RXSIZE 1024 // at-command rx buffer size
#define _ATC_RTOS 1 // 0: no rtos 1: cmsis_os v1 2: cmsis_os v2
#define _ATC_RXSIZE 1500 // at-command rx buffer size
#define _ATC_SEARCH_CMD_MAX 5 // maximum of answer in at-command
#define _ATC_SEARCH_MAX 10 // maximum of always search in buffer
#define _ATC_RXTIMEOUT_MS 50 // rx timeout to get new packet
Expand Down

0 comments on commit 8600c9f

Please sign in to comment.