From 12b524a5f326cd6052e40627f6c82d7fc87e2ffc Mon Sep 17 00:00:00 2001 From: Seungsu Lim Date: Thu, 9 May 2019 18:44:59 +0900 Subject: [PATCH] BT & CC2530 INTEG, DISPLAY ADD --- .../BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h | 38 +- .../BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c | 360 +++++++++++++++++- Drivers/CC2530/CC2530_MAC/Src/mac_interface.c | 25 +- Drivers/INTEG_MAC/Inc/integ_mac.h | 27 +- Drivers/INTEG_MAC/Src/frame_queue.c | 9 +- Drivers/INTEG_MAC/Src/integ_mac.c | 164 ++++++-- Drivers/LIFI/LIFI_MAC/Src/lifi.c | 2 + Inc/display.h | 22 ++ Inc/gpio.h | 3 +- Inc/stm32f4xx_it.h | 3 + Inc/uart.h | 7 +- Src/display.c | 114 ++++++ Src/gpio.c | 41 +- Src/main.c | 35 +- Src/queue.c | 4 +- Src/stm32f4xx_hal_msp.c | 267 ++++++------- Src/stm32f4xx_it.c | 42 ++ Src/task.c | 27 +- Src/uart.c | 168 +++++++- 19 files changed, 1125 insertions(+), 233 deletions(-) create mode 100644 Inc/display.h create mode 100644 Src/display.c diff --git a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h index d4dae81..48676ee 100644 --- a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h +++ b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Inc/bluetooth.h @@ -1,6 +1,40 @@ /* bluetooth.h */ - +extern unsigned char bt_state; +extern unsigned char bt_index; +extern unsigned char bt_count; +extern unsigned char bt_dis_count; +extern unsigned char btBuf[100]; unsigned char bluetooth_init(unsigned char deviceType); -unsigned char bluetooth_send(unsigned char* dest_addr, unsigned char* data, int data_length); \ No newline at end of file +unsigned char bluetooth_send(unsigned char* dest_addr, unsigned char* data, int data_length); + +// BlueTooth Init +void BT_M_Init(); +void BT_S_Init(); +void task_bt_update(void *arg); +void task_connect(void *arg); + +// AT Ŀ�Ǵ� ���� +void BT_AT(); +//�ӵ� ���� - 115200 +void BT_SetBaud(); +// Mac �ּ� ����� +void BT_MacAddress(); +// ��� ���� +void BT_ControlMode(); +// ������ / �����̺� ���� +void BT_SetChangeRole(); +// Master ���� +void BT_SetMaster(); +// SLAVE ���� +void BT_SetSlave(); +// �ʱ�ȭ +void BT_Reset(); +//IMME 1 +void BT_IMME(); +//START +void BT_START(); +//CONNECT +void BT_CONNET(); +void bluetooth_print_buf(); // �ӽ� diff --git a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c index 75ef049..b930104 100644 --- a/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c +++ b/Drivers/BLUETOOTH/BLUETOOTH_MAC/Src/bluetooth.c @@ -1,14 +1,368 @@ /* - bluetooth.c +bluetooth.c */ +#include +#include //for strncmp +#include "stm32f4xx_hal.h" #include "integ_mac.h" - +#include "uart.h" +#include "bluetooth.h" +unsigned char bt_state; +unsigned char bt_index; +unsigned char bt_count; +unsigned char bt_dis_count; +unsigned char btBuf[100]; unsigned char bluetooth_init(unsigned char deviceType) { - return R_FAIL; + bt_state = 0; + bt_index = 0; + bt_count = 0; + bt_dis_count = 0; + + if(deviceType == MASTER) { + //printf("MASTER �� �ʱ�ȭ\r\n"); + BT_M_Init(); + } + // SLAVE + else { + //printf("SLAVE �� �ʱ�ȭ\r\n"); + BT_S_Init(); + } + return R_SUCCESS; } unsigned char bluetooth_send(unsigned char* dest_addr, unsigned char* data, int data_length) { + //printf("[BLUETOOTH] ���� �õ�\r\n"); + HAL_UART_Transmit(&huart2, data, data_length, 1000); return 0; +} + +void bluetooth_print_buf() { + int i; + + for (i = 0; i < 10; i++) { + printf("%c", btBuf[i]); + } + printf("\r\n"); + +} + +//AT_COMMAND +uint8_t AT[] = "AT"; +uint8_t OK[3]; + +//SET BAUD 115200 +uint8_t SET_BAUD[] = "AT+BAUD4"; +uint8_t BAUD[8]; + +//MAC QURRY +uint8_t QR_MAC_ADDRESS[] = "AT+ADDR?"; +uint8_t SAVE_ADDRESS[20]; +uint8_t MAC1[] = "OK+ADDR:A810871D1386"; +uint8_t MAC2[] = "OK+ADDR:A810871B48F5"; + +//SET MODE +uint8_t SET_MODE[] = "AT+MODE0"; +uint8_t MODE[8]; + +//FACTORY SETUP +uint8_t SET_RENEW[] = "AT+RENEW"; +uint8_t RENEW[8]; + +//RESET MODULE +uint8_t SET_RESET[] = "AT+RESET"; +uint8_t BT_RESET[8]; + +// START DISC +uint8_t SET_SCAN[] = "AT+DISC?"; + +//MASTER & SLAVE +uint8_t SET_MASTER[] = "AT+ROLE1"; +uint8_t SET_SLAVE[] = "AT+ROLE0"; +uint8_t RESULT_ROLE[8]; +uint8_t QR_ROLE[] = "AT+ROLE?"; +uint8_t ROLE[8]; + +//SET IMME(CENTRAL) +//IMME0 = AUTO SCAN - CONNECT +//IMME1 = COMMAND - SCAN - CONNECT +uint8_t SET_IMME0[] = "AT+IMME0"; +uint8_t SET_IMME1[] = "AT+IMME1"; +uint8_t IMME[8]; +//START +uint8_t BT_START1[] = "AT+START"; +uint8_t START1[8]; + +//CONN RESULT +uint8_t NOTI[] = "AT+NOTP1"; +uint8_t NOTI1[8]; +uint8_t CONN_RESULT[8]; +uint8_t CON_MAC1[] = "AT+CONA810871D1386"; +uint8_t CON_MAC2[] = "AT+CONA810871B48F5"; + +uint8_t CONNL[] = "AT+CONNL"; + + +void task_bt_update(void *arg) +{ + // AT + if(strncmp((char*)arg, "1", 1)) { + insert_display_message("* [BLUETOOTH] ���� ��\r\n"); + } + else { + insert_display_message("* [BLUETOOTH] ���� ����\r\n"); + } +} + +void task_connect(void *arg) +{ + HAL_UART_Transmit(&huart2, CON_MAC2, 18, 1000); + HAL_Delay(100); +} + +/* �������� ��� ��� ���� */ +// BlueTooth Init +// Master +void BT_M_Init() +{ + // BAUD + HAL_UART_Transmit(&huart2, SET_BAUD, 8, 1000); + HAL_Delay(100); + + // AT + //HAL_UART_Transmit(&huart2, AT, 2, 1000); + HAL_Delay(100); + + // MODE 2 + HAL_UART_Transmit(&huart2, SET_MODE, 8, 1000); + HAL_Delay(100); + + // notp + HAL_UART_Transmit(&huart2, NOTI, 8, 1000); + HAL_Delay(300); + + // SET IMME1 + HAL_UART_Transmit(&huart2, SET_IMME1, 8, 1000); + HAL_Delay(10); + + // SET ROLE1 + HAL_UART_Transmit(&huart2, SET_MASTER, 8, 1000); + HAL_Delay(10); + + // SET_RESET + HAL_UART_Transmit(&huart2, SET_RESET, 8, 1000); + HAL_Delay(100); + + // SET START + HAL_UART_Transmit(&huart2, BT_START1, 8, 1000); + HAL_Delay(100); + + // DISC + HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); + HAL_Delay(100); + + memcpy(SAVE_ADDRESS, MAC1, 20); + + // QR_MAC + //HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); + HAL_Delay(10); + + // BT_CONNET() + HAL_UART_Transmit(&huart2, CON_MAC2, 18, 1000); + HAL_Delay(100); + + //HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); + HAL_Delay(100); + +} +//Slave +void BT_S_Init() +{ + // RENEW + //HAL_UART_Transmit(&huart2, SET_RENEW, 8, 1000); + HAL_Delay(1000); + + // BAUD + HAL_UART_Transmit(&huart2, SET_BAUD, 8, 1000); + HAL_Delay(100); + + // AT + //HAL_UART_Transmit(&huart2, AT, 2, 1000); + HAL_Delay(100); + + // MODE 2 + HAL_UART_Transmit(&huart2, SET_MODE, 8, 1000); + HAL_Delay(300); + + // notp + HAL_UART_Transmit(&huart2, NOTI, 8, 1000); + HAL_Delay(100); + + // SET IMME1 + HAL_UART_Transmit(&huart2, SET_IMME0, 8, 1000); + HAL_Delay(10); + + // ROLE0 : SLAVE + HAL_UART_Transmit(&huart2, SET_SLAVE, 8, 1000); + HAL_Delay(10); + + // SET_RESET + HAL_UART_Transmit(&huart2, SET_RESET, 8, 1000); + HAL_Delay(10); + + // DISC + //HAL_UART_Transmit(&huart2, SET_SCAN, 8, 1000); + HAL_Delay(100); + + // QR_MAC + HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); + HAL_Delay(10); + + memcpy(SAVE_ADDRESS, MAC2, 20); +} + +// AT Ŀ�Ǵ� ���� +void BT_AT() +{ + if(HAL_UART_Transmit(&huart2, AT, 2, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, OK, 2, 1000); + HAL_UART_Transmit(&huart3, OK, 2, 1000); + } + HAL_Delay(200); +} +//�ӵ� ���� - 115200 +void BT_SetBaud() +{ + if(HAL_UART_Transmit(&huart2, SET_BAUD, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, BAUD, 8, 1000); + HAL_UART_Transmit(&huart3, BAUD, 8, 1000); + } +} +// Mac �ּ� ����� +void BT_MacAddress() +{ + if(HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, SAVE_ADDRESS, 20, 1000); + HAL_UART_Transmit(&huart3, SAVE_ADDRESS, 20, 1000); + } +} +// ��� ���� +void BT_ControlMode() +{ + if(HAL_UART_Transmit(&huart2, SET_MODE, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, MODE, 8, 1000); + HAL_UART_Transmit(&huart3, MODE, 8, 1000); + } + HAL_Delay(200); + /* + 0: Transmission Mode + 1: PIO collection Mode + Mode 0 + 2: Remote Control Mode + Mode 0 + */ +} +// Master ���� +void BT_SetMaster() +{ + if(HAL_UART_Transmit(&huart2, SET_MASTER, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, RESULT_ROLE, 8, 1000); + HAL_UART_Transmit(&huart3, RESULT_ROLE, 8, 1000); + } +} +// SLAVE ���� +void BT_SetSlave() +{ + if(HAL_UART_Transmit(&huart2, SET_SLAVE, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, RESULT_ROLE, 8, 1000); + HAL_UART_Transmit(&huart3, RESULT_ROLE, 8, 1000); + } +} +// ������ / �����̺� ���� +void BT_SetChangeRole() +{ + if(HAL_UART_Transmit(&huart2, QR_ROLE, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, ROLE, 8, 1000); + HAL_UART_Transmit(&huart3, ROLE, 8, 1000); + + if(strncmp((char *)ROLE, "OK+Get:0", 8) == 0) + BT_SetMaster(); + else if (strncmp((char *)ROLE, "OK+Get:1", 8) == 0) + BT_SetSlave(); + } +} +// �ʱ�ȭ +void BT_Reset() +{ + if(HAL_UART_Transmit(&huart2, SET_RENEW, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, RENEW, 8, 1000); + + if(!strncmp((char *)RENEW, "OK+RENEW", 8)) + { + if(HAL_UART_Transmit(&huart2, AT+RESET, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, RESET, 8, 1000); + HAL_UART_Transmit(&huart3, RESET, 8, 1000); + } + } + } +} + +//IMMIE 1 +void BT_IMME() +{ + if(HAL_UART_Transmit(&huart2, SET_IMME1, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, IMME, 8, 1000); + HAL_UART_Transmit(&huart3, IMME, 8, 1000); + } + BT_START(); +} + +//START +void BT_START() +{ + if(HAL_UART_Transmit(&huart2, BT_START1, 8, 1000)==HAL_OK) + { + HAL_UART_Receive(&huart2, START1, 8, 1000); + HAL_UART_Transmit(&huart3, START1, 8, 1000); + } +} + +//CONNECT +void BT_CONNET() +{ + //uint8_t* i="a"; + + //HAL_UART_Transmit(&huart2, CONNL, 8, 1000); + + + if(!strncmp((char *)SAVE_ADDRESS, (char *)MAC1, 20)) + { + if(HAL_UART_Transmit(&huart2, CON_MAC2, 18, 1000)==HAL_OK) + { + //HAL_UART_Receive(&huart2, CONN_RESULT, 8, 10000); + //HAL_UART_Transmit(&huart3, CONN_RESULT, 8, 1000); + } + } + else if (!strncmp((char *)SAVE_ADDRESS, (char *)MAC2, 20)) + { + if(HAL_UART_Transmit(&huart2, CON_MAC1, 18, 1000)==HAL_OK) + { + //HAL_UART_Receive(&huart2, CONN_RESULT, 8, 10000); + //HAL_UART_Transmit(&huart3, CONN_RESULT, 8, 1000); + } + } + HAL_Delay(200); + + //HAL_UART_Transmit(&huart2, QR_MAC_ADDRESS, 8, 1000); + //HAL_Delay(100); + } \ No newline at end of file diff --git a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c index 13e5ff0..09d0c54 100644 --- a/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c +++ b/Drivers/CC2530/CC2530_MAC/Src/mac_interface.c @@ -21,12 +21,25 @@ unsigned char macAddr[8]; unsigned char startMac(unsigned char deviceType) { + deviceType = PAN_COORDINATOR; unsigned char attrValue[16] = {0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x11, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; unsigned char attrValue2[16] = {0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; +#define ZMAC_SHORT_ADDRESS 0x53 +#define ZMAC_EXTENDED_ADDRESS 0xE2 +#define ZMAC_ASSOCIATION_PERMIT 0x41 +#define ZMAC_RX_ON_IDLE 0x52 +#define ZMAC_AUTO_REQUEST 0x42 +#define ZMAC_BEACON_ORDER 0x47 + +#define ENERGY_DETECT 0x00 +#define ACTIVE_SCAN 0x01 +#define PASSIVE 0x02 +#define ORPHAN 0x03 + // SYS_RESET_REQ macReset(); @@ -38,13 +51,6 @@ unsigned char startMac(unsigned char deviceType) utilCallbackSubCmd(); HAL_Delay(100); -#define ZMAC_SHORT_ADDRESS 0x53 -#define ZMAC_EXTENDED_ADDRESS 0xE2 -#define ZMAC_ASSOCIATION_PERMIT 0x41 -#define ZMAC_RX_ON_IDLE 0x52 -#define ZMAC_AUTO_REQUEST 0x42 -#define ZMAC_BEACON_ORDER 0x47 - if(deviceType == PAN_COORDINATOR) { // MAC_SET_REQ [SHORT ADDRESS, EXT ADDRESS] // set the parameter @@ -59,10 +65,6 @@ unsigned char startMac(unsigned char deviceType) HAL_Delay(100); // MAC_SCAN_REQ -#define ENERGY_DETECT 0x00 -#define ACTIVE_SCAN 0x01 -#define PASSIVE 0x02 -#define ORPHAN 0x03 macScanReq(ACTIVE_SCAN); HAL_Delay(100); @@ -383,6 +385,7 @@ void macAssociateReq() #define MAC_DATA_REQ_PAYLOAD_LEN 0x1C unsigned char macDataReq(unsigned char* dest_addr, unsigned char* data, int data_length) { + //printf("[CC2530] ���� �õ�\r\n"); macBuf[0] = MAC_DATA_REQ_PAYLOAD_LEN + data_length; macBuf[1] = MSB(MAC_DATA_REQ); macBuf[2] = LSB(MAC_DATA_REQ); diff --git a/Drivers/INTEG_MAC/Inc/integ_mac.h b/Drivers/INTEG_MAC/Inc/integ_mac.h index e4686e3..190e0ec 100644 --- a/Drivers/INTEG_MAC/Inc/integ_mac.h +++ b/Drivers/INTEG_MAC/Inc/integ_mac.h @@ -8,13 +8,25 @@ #define LIFI 0 // Media Type #define BLUETOOTH 1 #define CC2530 2 -#define OPT_MEDIA 0xFF // ���� ������ ��ü�� ��� +#define OPT_MEDIA 0xF0 // ���� ������ ��ü�� ��� static char *media_name[MEDIA_NUM] = {"LI-FI", "BLUETOOTH", "CC2530"}; extern unsigned char cur_media; // ���� ����� ��ũ extern unsigned char opt_media; // ���� ������ ��ũ +extern unsigned char integ_init_state; // ���� MAC �ʱ�ȭ ���� -#define RETRANSMIT_TIME 3 // ������ �ֱ� 300ms +// ���� ���� ���� ���̺� +#define STATUS_NUM 2 +#define INIT_STATUS 0 +#define CONNECT_STATUS 1 +#define CON 1 +#define DISCON 0 +static char *STATUS_NAME[STATUS_NUM] = {"Init", "Connect"}; +extern unsigned char STATUS_TABLE[STATUS_NUM][MEDIA_NUM]; + + +#define FIND_OPT_PERIOD 5 // ���� ��� �˻� �ֱ� 500ms +#define RETRANSMIT_TIME 3 // ������ �ֱ� 300ms #define R_SUCCESS 1 #define R_FAIL 0 static char *result_string[2] = {"FAIL", "SUCCESS"}; @@ -27,6 +39,7 @@ static unsigned char media_addr_len[MEDIA_NUM] = {LIFI_ADDR_LEN, BLUETOOTH_ADDR_ #define INTEG_FRAME_HEADER_LEN 17 // ���� �� ������ ��� ���� #define INTEG_FRAME_DATA_LEN 40 +#define INTEG_FRAME_TOTAL_LEN 57 #define INTEG_FRAME_LEN_FIELD 0 @@ -35,6 +48,10 @@ static unsigned char media_addr_len[MEDIA_NUM] = {LIFI_ADDR_LEN, BLUETOOTH_ADDR_ #define ACK_MSG 0x02 #define PASS_MSG 0xFF +// deviceType +#define MASTER 0x00 +#define SLAVE 0x01 + extern unsigned char my_integ_address[INTEG_ADDR_LEN]; #define HOOD_HASH_ID 0x10 @@ -47,12 +64,16 @@ extern unsigned char hood_integ_address[INTEG_ADDR_LEN]; #define STATIC_ADDR 0 #define DYNAMIC_ADDR 1 static char *addr_type_name[2] = {"STATIC", "DYNAMIC"}; + +// ���� MAC ���̺� ����ü typedef struct integ_table { unsigned char integ_addr[INTEG_ADDR_LEN]; unsigned char addr_type; // static : 0, dynamic : 1 unsigned char *media_addr[MEDIA_NUM]; } INTEG_TABLE; + +// ���� MAC ������ ����ü typedef struct integ_frame { unsigned char frame_length; unsigned char message_type; @@ -64,10 +85,10 @@ typedef struct integ_frame { unsigned char data[INTEG_FRAME_DATA_LEN]; } INTEG_FRAME; - unsigned char get_seq_number(void); void integ_mac_handler(void * arg); void integ_retransmit_handler(void * arg); +void integ_find_opt_link(void *); void integ_mac_init(void); void integ_print_frame(INTEG_FRAME *frame); diff --git a/Drivers/INTEG_MAC/Src/frame_queue.c b/Drivers/INTEG_MAC/Src/frame_queue.c index 45afad7..f86f225 100644 --- a/Drivers/INTEG_MAC/Src/frame_queue.c +++ b/Drivers/INTEG_MAC/Src/frame_queue.c @@ -44,7 +44,14 @@ void re_frame_queue_init(void) void re_frame_queue_remove(unsigned char index) { - re_frame_queue[index].message_type = PASS_MSG; + int i; + + // �ӽ� + for(i = 1; i < RE_FRAME_QUEUE_SIZE; i++) { + if(re_frame_queue[i].seqNumber == index) { + re_frame_queue[i].message_type = PASS_MSG; + } + } } unsigned int re_frame_queue_insert(unsigned char *ch) diff --git a/Drivers/INTEG_MAC/Src/integ_mac.c b/Drivers/INTEG_MAC/Src/integ_mac.c index 8679337..0035c6d 100644 --- a/Drivers/INTEG_MAC/Src/integ_mac.c +++ b/Drivers/INTEG_MAC/Src/integ_mac.c @@ -1,4 +1,5 @@ #include +#include #include #include "integ_mac.h" #include "frame_queue.h" @@ -8,9 +9,14 @@ #include "bluetooth.h" // blluetooth #include "lifi.h" // lifi #include "mac_interface.h" // CC2530 +#include "uart.h" +#include "display.h" #define STM32_UUID ((uint32_t *)0x1FFF7A10) +// dispaly �� ���� +unsigned char message_buffer[COL_NUMS]; + // �� ��ü �� �Լ� ������ unsigned char (*fun_init[MEDIA_NUM])(unsigned char) = {lifi_init, bluetooth_init, startMac}; // �ʱ�ȭ unsigned char (*fun_send[MEDIA_NUM])(unsigned char* , unsigned char* , int ) = {lifi_send, bluetooth_send, macDataReq}; // ������ ���� @@ -29,8 +35,12 @@ unsigned char my_cc2530_address[CC2530_ADDR_LEN] = {0x11, 0x11, 0x11, 0x11, 0x11 unsigned char seqNumber; // ���� ��ȣ unsigned char cur_media; // ���� ����ϴ� ��ü +unsigned char prev_media; // ������ ����� ��ü unsigned char opt_media; // ������ ��ü +unsigned char deviceType; // ��ġ ���� +unsigned char STATUS_TABLE[STATUS_NUM][MEDIA_NUM] = {{R_FAIL, R_FAIL, R_FAIL}, {DISCON, DISCON, DISCON}}; +unsigned char integ_init_state = 0; #define TRANSMIT_FRAME 1 #define RECEIVE_FRAME 0 @@ -44,7 +54,7 @@ void integ_mac_handler(void * arg) unsigned char frame_state; // �۽ſ� ���ſ� while((frame = frame_queue_delete()) != NULL) { - integ_print_frame(frame); + //integ_print_frame(frame); message_type = frame->message_type; // �ٿ��� �ּ� �ʵ�� �ڽ��� �ּ� �� @@ -60,51 +70,85 @@ void integ_mac_handler(void * arg) case DATA_MSG: // ������ �۽� ���� if(frame_state == TRANSMIT_FRAME) { - printf("** Data �۽�\r\n"); + //sprintf(message_buffer, "* [INTEG] ������ �۽� ������ (������ : %02x)\r\n", frame->dest_address[0]); + //insert_display_message(message_buffer); + //printf("** Data �۽� seqNum %d\r\n", frame->seqNumber); cur_media = frame->media_type; - // ������ ��⿭�� ������ �߰� - frame->media_type = OPT_MEDIA; // ������ �� ��� ������ ��ü�� ����ؼ� ���� - re_frame_queue_insert((unsigned char *)frame); - frame->media_type = cur_media; + // ������ �������� ��� ������ ��ü�� ���� + if((cur_media & OPT_MEDIA) == OPT_MEDIA) { + prev_media = cur_media & 0x0F; + + // ���� ���� ��ü ���� ���� ���� + STATUS_TABLE[CONNECT_STATUS][prev_media] = DISCON; + + integ_find_opt_link(NULL); + cur_media = opt_media; + frame->media_type = OPT_MEDIA | cur_media; + + // ������ ��⿭�� ������ �߰� + re_frame_queue_insert((unsigned char *)frame); + sprintf(message_buffer, "* [%s] ������ ���� ���� \r\n", media_name[prev_media]); + insert_display_message(message_buffer); + + if(prev_media != cur_media) { + sprintf(message_buffer, "* [%s] ���� [%s] ���� ��ü ���� \r\n", media_name[prev_media], media_name[cur_media]); + insert_display_message(message_buffer); + } + + sprintf(message_buffer, "* [%s][SEQ : %d] ������ ������ (�� ������ : %02x) : %s\r\n", media_name[cur_media], frame->seqNumber, frame->dest_address[0], frame->data); + insert_display_message(message_buffer); + } + // ó�� ������ ��� + else { + frame->media_type ^= OPT_MEDIA; + re_frame_queue_insert((unsigned char *)frame); + frame->media_type = cur_media; + + sprintf(message_buffer, "* [%s][SEQ : %d] ������ ���� ( �� ������ : %02x) : %s\r\n", media_name[cur_media], frame->seqNumber, frame->dest_address[0], frame->data); + insert_display_message(message_buffer); + } // ������ Task �߰� retrans_task.fun = integ_retransmit_handler; strcpy(retrans_task.arg, ""); insert_timer(&retrans_task, RETRANSMIT_TIME); - // ������ �������� ��� ������ ��ü�� �����ض� - if(cur_media == OPT_MEDIA) { - cur_media = opt_media; - frame->media_type = cur_media; - } - // INTEG ADDR -> MAC ADDR ��ȯ struct node *table = FindHashData(HOOD_HASH_ID); if(table != NULL) { // �۽� + //printf("cur_media = %d\r\n", cur_media); fun_send[cur_media](table->data.media_addr[cur_media], (unsigned char *)frame, frame->frame_length); } } - // ������ ���� �� ACK �۽� + // ������ ���� �� ACK ���� else if(frame_state == RECEIVE_FRAME) { - printf("** Data ����\r\n"); + //printf("** Data ����\r\n"); + // ACK ��Ŷ ���� t_frame.frame_length = frame->frame_length; t_frame.message_type = ACK_MSG; - t_frame.media_type = frame->media_type; + t_frame.media_type = frame->media_type & 0x0F; t_frame.ackNumber = frame->seqNumber + 1; memcpy(t_frame.dest_address, frame->src_address, INTEG_ADDR_LEN); memcpy(t_frame.src_address, my_integ_address, INTEG_ADDR_LEN); + + sprintf(message_buffer, "* [%s][SEQ : %d] ������ ���� ( �� �ٿ��� : %02x) : %s\r\n", media_name[t_frame.media_type], frame->seqNumber, frame->src_address[0], frame->data); + insert_display_message(message_buffer); + + // ���� ��ü ���� ���� ���� + STATUS_TABLE[CONNECT_STATUS][t_frame.media_type] = CON; + frame_queue_insert((unsigned char *)&t_frame); - printf("** ACK ����\r\n"); + //printf("** ACK ����\r\n"); } break; case ACK_MSG: // ACK �۽� ���� if(frame_state == TRANSMIT_FRAME) { - printf("** ACK �۽�\r\n"); + //printf("** ACK �۽�\r\n"); // ACK �۽��� ���� ��ü�� cur_media = frame->media_type; @@ -113,18 +157,31 @@ void integ_mac_handler(void * arg) struct node *table = FindHashData(HOOD_HASH_ID); if(table != NULL) { // �۽� + //printf("cur_media = %d\r\n", cur_media); fun_send[cur_media](table->data.media_addr[cur_media], (unsigned char *)frame, frame->frame_length); } + + sprintf(message_buffer, "* [%s][ACK : %d] ACK �۽� ( �� ������ : %02x) \r\n", media_name[cur_media], frame->ackNumber, frame->dest_address[0]); + insert_display_message(message_buffer); } // ACK ���� �� else if(frame_state == RECEIVE_FRAME) { - printf("** ACK ����\r\n"); + int ackNumber; + + // ���� ��ü ���� ���� ���� + STATUS_TABLE[CONNECT_STATUS][frame->media_type] = CON; + + ackNumber = frame->ackNumber - 1; + //printf("** ACK ���� ackNum : %d\r\n", ackNumber + 1); // ������ ��⿭�� ������ ���� - re_frame_queue_remove((frame->ackNumber - 1) % MAX_SEQ_NUMBER); + re_frame_queue_remove(ackNumber % MAX_SEQ_NUMBER); + + sprintf(message_buffer, "* [%s][ACK : %d] ACK ���� ( ��ٿ��� : %02x) \r\n", media_name[frame->media_type], frame->ackNumber, frame->src_address[0]); + insert_display_message(message_buffer); } break; case PASS_MSG: - printf("������ ���\r\n"); + //printf("������ ���\r\n"); break; } } @@ -153,21 +210,12 @@ void integ_mac_init(void) int i, result; struct node *table; // MAC Table ���� + insert_display_message("* [INTEG] ���� MAC �ʱ�ȭ ����\r\n"); + seqNumber = DEFAULT_SEQ_NUMBER; frame_queue_init(); re_frame_queue_init(); - - // MCU <---> ��ü ��� �ʱ�ȭ - - // ��ü �ʱ�ȭ - for(i = 0; i < MEDIA_NUM; i++) { - result = fun_init[i](0x00); - printf("* [%s] �ʱ�ȭ %s \r\n", media_name[i], result_string[result]); - } - // ���� ��ü ���� - opt_media = cur_media = CC2530; - my_integ_address[0] = LSB(STM32_UUID[0]); my_cc2530_address[0] = LSB(STM32_UUID[0]); my_lifi_address[0] = LSB(STM32_UUID[0]); @@ -177,12 +225,14 @@ void integ_mac_init(void) hood_cc2530_address[0] = 0x2E; hood_lifi_address[0] = 0x2E; hood_bluetooth_address[0] = 0x2E; + deviceType = MASTER; } else { hood_integ_address[0] = 0x2c; hood_cc2530_address[0] = 0x2c; hood_lifi_address[0] = 0x2c; hood_bluetooth_address[0] = 0x2c; + deviceType = SLAVE; } table = get_hashNode(); @@ -203,7 +253,57 @@ void integ_mac_init(void) table->data.media_addr[CC2530] = hood_cc2530_address; AddHashData(table->id, table); + // MCU <---> ��ü ��� �ʱ�ȭ + + // ��ü �ʱ�ȭ + for(i = 0; i < MEDIA_NUM; i++) { + result = fun_init[i](deviceType); + STATUS_TABLE[INIT_STATUS][i] = result; + STATUS_TABLE[CONNECT_STATUS][i] = result; + sprintf(message_buffer, "* [%s] �ʱ�ȭ %s \r\n", media_name[i], result_string[result]); + insert_display_message(message_buffer); + } + + // ���� ��ü ���� + integ_find_opt_link(NULL); + + // ù ��� ������ ���� ��ü ���� + cur_media = opt_media; + + // ���� MAC Handler TASK ���� integ_mac_handler(""); + integ_init_state = 1; + insert_display_message("* [INTEG] ���� MAC �ʱ�ȭ �Ϸ�\r\n"); + + + struct task task; + task.fun = integ_find_opt_link; + strcpy(task.arg, ""); + insert_timer(&task, FIND_OPT_PERIOD); + +} + +void integ_find_opt_link(void * arg) +{ + struct task task; + int i; + + // �ֱ����� TASK ���� + task.fun = integ_find_opt_link; + strcpy(task.arg, ""); + insert_timer(&task, FIND_OPT_PERIOD); + + for(i = 0; i < MEDIA_NUM; i++) { + if(STATUS_TABLE[INIT_STATUS][i] && STATUS_TABLE[CONNECT_STATUS][i]) { + //opt_media = BLUETOOTH; + opt_media = i; + //printf("������ü : %s\r\n", media_name[opt_media]); + return; + } + } + //opt_media = (rand() % 2) + 1; + opt_media = (opt_media + 1) % 2 + 1; + } @@ -211,6 +311,7 @@ void integ_mac_init(void) void integ_print_frame(INTEG_FRAME *frame) { int i; + printf("----------\r\n"); printf("Source Address : "); for(i = 0; i < INTEG_ADDR_LEN; i++) { @@ -222,6 +323,7 @@ void integ_print_frame(INTEG_FRAME *frame) } printf("\r\nLength : %d | msgType : %d | mediaType : %d | seqNumber : %d | ackNumber : %d\r\n", frame->frame_length, frame->message_type, frame->media_type, frame->seqNumber, frame->ackNumber); printf("----------\r\n"); + } unsigned char get_seq_number(void) diff --git a/Drivers/LIFI/LIFI_MAC/Src/lifi.c b/Drivers/LIFI/LIFI_MAC/Src/lifi.c index 33718ab..2bbb562 100644 --- a/Drivers/LIFI/LIFI_MAC/Src/lifi.c +++ b/Drivers/LIFI/LIFI_MAC/Src/lifi.c @@ -1,6 +1,7 @@ /* lifi.c */ +#include #include "integ_mac.h" unsigned char lifi_init(unsigned char deviceType) @@ -10,5 +11,6 @@ unsigned char lifi_init(unsigned char deviceType) unsigned char lifi_send(unsigned char* dest_addr, unsigned char* data, int data_length) { + printf("LIFI_SEND_����_�õ�\r\n"); return 0; } \ No newline at end of file diff --git a/Inc/display.h b/Inc/display.h new file mode 100644 index 0000000..5e9d433 --- /dev/null +++ b/Inc/display.h @@ -0,0 +1,22 @@ +/* +display.h +*/ +#define ROW_LINES 12 +#define FIRST_ROW 0 +#define LAST_ROW ROW_LINES - 1 + +#define COL_NUMS 79 +#define FIRST_COL 0 +#define LAST_COL COL_NUMS - 1 + +#define RECT_CHAR_START 22 +#define RECT_CHAR_END 54 +#define RECT_CHAR_LEN 10 +#define RECT_FIRST_CON_START RECT_CHAR_START - 6 +#define RECT_SECOND_CON_START (RECT_CHAR_START + RECT_CHAR_LEN + 4) +void init_display_buffer(); + +void insert_display_message(unsigned char *message); +void print_info(void *arg); +void print_message(void *arg); +void display(); \ No newline at end of file diff --git a/Inc/gpio.h b/Inc/gpio.h index 0f0bc6a..cb8532c 100644 --- a/Inc/gpio.h +++ b/Inc/gpio.h @@ -4,4 +4,5 @@ */ -void GPIO_Init(void); \ No newline at end of file +void GPIO_Init(void); +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin); \ No newline at end of file diff --git a/Inc/stm32f4xx_it.h b/Inc/stm32f4xx_it.h index 6debe0c..d0766bc 100644 --- a/Inc/stm32f4xx_it.h +++ b/Inc/stm32f4xx_it.h @@ -71,9 +71,12 @@ void SVC_Handler(void); void DebugMon_Handler(void); void PendSV_Handler(void); void SysTick_Handler(void); +void USART2_IRQHandler(void); void USART3_IRQHandler(void); void UART4_IRQHandler(void); +void UART5_IRQHandler(void); void TIM6_DAC_IRQHandler(void); +void EXTI9_5_IRQHandler(void); /* USER CODE BEGIN EFP */ /* USER CODE END EFP */ diff --git a/Inc/uart.h b/Inc/uart.h index 8c61f86..0826e80 100644 --- a/Inc/uart.h +++ b/Inc/uart.h @@ -3,17 +3,20 @@ uart.h */ +extern UART_HandleTypeDef huart2; // <---> BT extern UART_HandleTypeDef huart3; // <---> PC extern UART_HandleTypeDef huart4; // <---> CC2530 -extern UART_HandleTypeDef huart1; -extern UART_HandleTypeDef huart2; +extern UART_HandleTypeDef huart5; // <---> LIFI + int fputc(int ch, FILE *f); int fgetc(FILE *f); char *fgets(char *s, int n, FILE *f); +void UART2_Init(void); void UART3_Init(void); void UART4_Init(void); +void UART5_Init(void); void uart_echo(uint8_t ch); void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart); void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart); \ No newline at end of file diff --git a/Src/display.c b/Src/display.c new file mode 100644 index 0000000..ab406a1 --- /dev/null +++ b/Src/display.c @@ -0,0 +1,114 @@ +/* +display.c +*/ +#include +#include +#include "display.h" +#include "integ_mac.h" +#include "task.h" + +unsigned char display_buffer_index = 0; +unsigned char new_line[2] = {'\r', '\n'}; +unsigned char display_buffer[ROW_LINES][COL_NUMS]; +unsigned char *media_name_for_display[MEDIA_NUM] = {" LI-FI ", "BLUETOOTH ", " CC2530 "}; +unsigned char rectange1[COL_NUMS] = {"�������������� �������������� ��������������\r\n"}; +unsigned char rectange1_1[COL_NUMS] = {"�� �� �������������� ��������������\r\n"}; +unsigned char rectange2[COL_NUMS] = {"�� MCU ����X ���� ABCDEFG ����X ���� NEIGHBOR ��\r\n"}; +unsigned char rectange3_1[COL_NUMS] = {"�������������� �������������� ��������������\r\n"}; +unsigned char rectange3[COL_NUMS] = {"�� �� �������������� ��������������\r\n"}; + +void init_display_buffer() +{ + int row; + + for(row = 0; row < ROW_LINES; row++) { + memcpy(display_buffer[row], new_line, 2); + } +} + + +void display() { + print_info(NULL); + print_message(NULL); + printf("$ "); +} + +void print_info(void *arg) +{ + int i; + printf("\033[2J"); + //printf("\033[%d;%dH\r\n", 0, 0); + printf(" ** ��ü ���� ���� ** ** ���� ���� ��ü **\r\n"); + for(i = 0; i < MEDIA_NUM; i++) { + if(i == 0) { + printf("%s", rectange1); + } + else { + printf("%s", rectange1_1); + } + if (i == 1) { + memcpy(rectange2 + 5, "MCU", 3); + } + else { + memcpy(rectange2 + 5, " ", 4); + } + memcpy(rectange2 + RECT_CHAR_START, media_name_for_display[i], RECT_CHAR_LEN); + if(STATUS_TABLE[INIT_STATUS][i]) { + rectange2[RECT_FIRST_CON_START] = 0xA6; + rectange2[RECT_FIRST_CON_START+1] = 0xAC; + } + else { + rectange2[RECT_FIRST_CON_START] = 'X'; + rectange2[RECT_FIRST_CON_START+1] = ' '; + } + + if(STATUS_TABLE[CONNECT_STATUS][i]) { + rectange2[RECT_SECOND_CON_START] = 0xA6; + rectange2[RECT_SECOND_CON_START+1] = 0xAC; + } + else { + rectange2[RECT_SECOND_CON_START] = 'X'; + rectange2[RECT_SECOND_CON_START+1] = ' '; + } + + printf("%s", rectange2); + + if(i == 2) { + printf("%s", rectange3_1); + } + else { + printf("%s", rectange3); + } + } +} + +void insert_display_message(unsigned char *message) +{ + strcpy(display_buffer[display_buffer_index], message); + display_buffer_index = (display_buffer_index + 1) % ROW_LINES; + display(); +} + +void print_message(void *arg) +{ + int row, col; + printf(" ** �޽��� ���� **\r\n"); + + /* + for(row = ROW_LINES - 1; row > display_buffer_index; row--) { + printf("%s", display_buffer[row]); + } + for(row = 0; row < display_buffer_index; row++) { + printf("%s", display_buffer[row]); + } + */ + + for(row = display_buffer_index; row < ROW_LINES; row++) { + printf("%s", display_buffer[row]); + } + + for(row = 0; row < display_buffer_index; row++) { + printf("%s", display_buffer[row]); + } + +} diff --git a/Src/gpio.c b/Src/gpio.c index e5543d1..858d862 100644 --- a/Src/gpio.c +++ b/Src/gpio.c @@ -8,7 +8,8 @@ gpio.c #include "gpio.h" #include "utilities.h" #include "task.h" -#include "cc2530.h" +#include "integ_mac.h" +#include "bluetooth.h" void GPIO_Init(void) { @@ -19,6 +20,7 @@ void GPIO_Init(void) __HAL_RCC_GPIOB_CLK_ENABLE(); __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); + __HAL_RCC_GPIOH_CLK_ENABLE(); // CC2530 RESET_PIN /*Configure GPIO pin : PC9 */ @@ -28,4 +30,41 @@ void GPIO_Init(void) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); //HAL_GPIO_WritePin(GPIOC, GPIO_PIN_9, GPIO_PIN_SET); + + /*Configure GPIO pin : PC8 */ + GPIO_InitStruct.Pin = GPIO_PIN_8; + GPIO_InitStruct.Mode = GPIO_MODE_IT_FALLING; + GPIO_InitStruct.Pull = GPIO_PULLDOWN; + HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); + + /* EXTI interrupt init */ + HAL_NVIC_SetPriority(EXTI9_5_IRQn, 3, 1); + HAL_NVIC_EnableIRQ(EXTI9_5_IRQn); +} + +// BT STATE : PC8 Falling interrupt Callback +void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) +{ + switch(GPIO_Pin) + { + case GPIO_PIN_8: + // falling BT ���� ���� + if (HAL_GPIO_ReadPin(GPIOC, GPIO_PIN_8) == GPIO_PIN_RESET) { + if(integ_init_state) { + bt_dis_count++; + //printf("BT disconnected\r\n"); + // BT �翬�� + if(bt_dis_count > 4) { + struct task task; + task.fun = task_connect; + strcpy(task.arg, ""); + task_insert(&task); + bt_dis_count = 0; + } + } + } + else { + } + break; + } } \ No newline at end of file diff --git a/Src/main.c b/Src/main.c index ace28e5..74e2798 100644 --- a/Src/main.c +++ b/Src/main.c @@ -45,13 +45,10 @@ #include "task.h" #include "timer.h" #include "integ_mac.h" +#include "display.h" void SystemClock_Config(void); -//LI-FI data -uint8_t rx3_data; -uint8_t tx_data[5]="hello"; - int main(void) { int tag; @@ -61,25 +58,17 @@ int main(void) SystemClock_Config(); GPIO_Init(); MX_TIM6_Init(); + UART2_Init(); // BT UART3_Init(); // PC - UART4_Init(); + UART4_Init(); // CC2530 + UART5_Init(); // LIFI HAL_Delay(500); + + init_display_buffer(); integ_mac_init(); - - printf("$ "); while(1) { - - -/////////////LI-FI////////////////////////// -//send "HELLO from huart5 to huart3" -/* - HAL_UART_Transmit(&huart5,tx_data,5,1000); - HAL_Delay(1000); -*/ -//////////////Li-FI///////////////////////// - __disable_interrupt(); tag = task_delete(&task); __enable_interrupt(); @@ -93,18 +82,6 @@ int main(void) * @brief System Clock Configuration * @retval None */ - - //LI-FI callback function - /* - void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) -{ - if(huart->Instance ==USART3) - { - HAL_UART_Receive_IT(&huart3,&rx3_data,5); - HAL_UART_Transmit(&huart3,&rx3_data,5,10); - } -} -*/ void SystemClock_Config(void) { RCC_OscInitTypeDef RCC_OscInitStruct = {0}; diff --git a/Src/queue.c b/Src/queue.c index 9ab585a..d100969 100644 --- a/Src/queue.c +++ b/Src/queue.c @@ -7,8 +7,8 @@ #include "queue.h" -#define QO_SIZE 512 -#define QI_SIZE 512 +#define QO_SIZE 1024 +#define QI_SIZE 1024 unsigned char qo[QO_SIZE], qi[QI_SIZE]; unsigned int fi, ri, fo, ro; diff --git a/Src/stm32f4xx_hal_msp.c b/Src/stm32f4xx_hal_msp.c index 83508cb..18c4c3d 100644 --- a/Src/stm32f4xx_hal_msp.c +++ b/Src/stm32f4xx_hal_msp.c @@ -1,42 +1,42 @@ /* USER CODE BEGIN Header */ /** - ****************************************************************************** - * File Name : stm32f4xx_hal_msp.c - * Description : This file provides code for the MSP Initialization - * and de-Initialization codes. - ****************************************************************************** - ** This notice applies to any and all portions of this file - * that are not between comment pairs USER CODE BEGIN and - * USER CODE END. Other portions of this file, whether - * inserted by the user or by software development tools - * are owned by their respective copyright owners. - * - * COPYRIGHT(c) 2019 STMicroelectronics - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright notice, - * this list of conditions and the following disclaimer in the documentation - * and/or other materials provided with the distribution. - * 3. Neither the name of STMicroelectronics nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR - * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * - ****************************************************************************** - */ +****************************************************************************** +* File Name : stm32f4xx_hal_msp.c +* Description : This file provides code for the MSP Initialization +* and de-Initialization codes. +****************************************************************************** +** This notice applies to any and all portions of this file +* that are not between comment pairs USER CODE BEGIN and +* USER CODE END. Other portions of this file, whether +* inserted by the user or by software development tools +* are owned by their respective copyright owners. +* +* COPYRIGHT(c) 2019 STMicroelectronics +* +* Redistribution and use in source and binary forms, with or without modification, +* are permitted provided that the following conditions are met: +* 1. Redistributions of source code must retain the above copyright notice, +* this list of conditions and the following disclaimer. +* 2. Redistributions in binary form must reproduce the above copyright notice, +* this list of conditions and the following disclaimer in the documentation +* and/or other materials provided with the distribution. +* 3. Neither the name of STMicroelectronics nor the names of its contributors +* may be used to endorse or promote products derived from this software +* without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" +* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE +* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER +* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, +* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE +* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +* +****************************************************************************** +*/ /* USER CODE END Header */ /* Includes ------------------------------------------------------------------*/ @@ -52,7 +52,7 @@ /* Private define ------------------------------------------------------------*/ /* USER CODE BEGIN Define */ - + /* USER CODE END Define */ /* Private macro -------------------------------------------------------------*/ @@ -79,21 +79,21 @@ /* USER CODE END 0 */ /** - * Initializes the Global MSP. - */ +* Initializes the Global MSP. +*/ void HAL_MspInit(void) { /* USER CODE BEGIN MspInit 0 */ - + /* USER CODE END MspInit 0 */ - + __HAL_RCC_SYSCFG_CLK_ENABLE(); __HAL_RCC_PWR_CLK_ENABLE(); - + /* System interrupt init*/ - + /* USER CODE BEGIN MspInit 1 */ - + /* USER CODE END MspInit 1 */ } @@ -105,18 +105,18 @@ void HAL_MspInit(void) */ void HAL_UART_MspInit(UART_HandleTypeDef* huart) { - + GPIO_InitTypeDef GPIO_InitStruct = {0}; if(huart->Instance==USART2) { - /* USER CODE BEGIN USART2_MspInit 0 */ - - /* USER CODE END USART2_MspInit 0 */ + /* USER CODE BEGIN USART2_MspInit 0 */ + + /* USER CODE END USART2_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_USART2_CLK_ENABLE(); - - __HAL_RCC_GPIOA_CLK_ENABLE(); + + __HAL_RCC_GPIOD_CLK_ENABLE(); /**USART2 GPIO Configuration PD5 ------> USART2_TX PD6 ------> USART2_RX @@ -127,19 +127,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART2; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /* USER CODE BEGIN USART2_MspInit 1 */ - - /* USER CODE END USART2_MspInit 1 */ + + /* USART2 interrupt Init */ + HAL_NVIC_SetPriority(USART2_IRQn, 0, 2); + HAL_NVIC_EnableIRQ(USART2_IRQn); + /* USER CODE BEGIN USART2_MspInit 1 */ + + /* USER CODE END USART2_MspInit 1 */ } else if(huart->Instance==USART3) { - /* USER CODE BEGIN USART3_MspInit 0 */ - - /* USER CODE END USART3_MspInit 0 */ + /* USER CODE BEGIN USART3_MspInit 0 */ + + /* USER CODE END USART3_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_USART3_CLK_ENABLE(); - + __HAL_RCC_GPIOB_CLK_ENABLE(); /**USART3 GPIO Configuration PD8 ------> USART3_TX @@ -151,22 +154,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF7_USART3; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - + /* USART3 interrupt Init */ - HAL_NVIC_SetPriority(USART3_IRQn, 5, 1); + HAL_NVIC_SetPriority(USART3_IRQn, 0, 0); HAL_NVIC_EnableIRQ(USART3_IRQn); - /* USER CODE BEGIN USART3_MspInit 1 */ - - /* USER CODE END USART3_MspInit 1 */ + /* USER CODE BEGIN USART3_MspInit 1 */ + + /* USER CODE END USART3_MspInit 1 */ } else if(huart->Instance==UART4) { - /* USER CODE BEGIN UART4_MspInit 0 */ - - /* USER CODE END UART4_MspInit 0 */ + /* USER CODE BEGIN UART4_MspInit 0 */ + + /* USER CODE END UART4_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_UART4_CLK_ENABLE(); - + __HAL_RCC_GPIOA_CLK_ENABLE(); /**UART4 GPIO Configuration PC10 ------> UART4_TX @@ -179,22 +182,22 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF8_UART4; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - + /* UART4 interrupt Init */ - HAL_NVIC_SetPriority(UART4_IRQn, 4, 1); + HAL_NVIC_SetPriority(UART4_IRQn, 0, 3); HAL_NVIC_EnableIRQ(UART4_IRQn); - /* USER CODE BEGIN UART4_MspInit 1 */ - - /* USER CODE END UART4_MspInit 1 */ + /* USER CODE BEGIN UART4_MspInit 1 */ + + /* USER CODE END UART4_MspInit 1 */ } else if(huart->Instance==UART5) { - /* USER CODE BEGIN UART5_MspInit 0 */ - - /* USER CODE END UART5_MspInit 0 */ + /* USER CODE BEGIN UART5_MspInit 0 */ + + /* USER CODE END UART5_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_UART5_CLK_ENABLE(); - + __HAL_RCC_GPIOC_CLK_ENABLE(); __HAL_RCC_GPIOD_CLK_ENABLE(); /**UART5 GPIO Configuration @@ -207,17 +210,17 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF8_UART5; HAL_GPIO_Init(GPIOC, &GPIO_InitStruct); - + GPIO_InitStruct.Pin = GPIO_PIN_2; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_PULLUP; GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH; GPIO_InitStruct.Alternate = GPIO_AF8_UART5; HAL_GPIO_Init(GPIOD, &GPIO_InitStruct); - - /* USER CODE BEGIN UART5_MspInit 1 */ - - /* USER CODE END UART5_MspInit 1 */ + + /* USER CODE BEGIN UART5_MspInit 1 */ + + /* USER CODE END UART5_MspInit 1 */ } } @@ -229,20 +232,20 @@ void HAL_UART_MspInit(UART_HandleTypeDef* huart) */ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) { - + if(htim_base->Instance==TIM6) { - /* USER CODE BEGIN TIM6_MspInit 0 */ - - /* USER CODE END TIM6_MspInit 0 */ + /* USER CODE BEGIN TIM6_MspInit 0 */ + + /* USER CODE END TIM6_MspInit 0 */ /* Peripheral clock enable */ __HAL_RCC_TIM6_CLK_ENABLE(); /* TIM6 interrupt Init */ HAL_NVIC_SetPriority(TIM6_DAC_IRQn, 0, 0); HAL_NVIC_EnableIRQ(TIM6_DAC_IRQn); - /* USER CODE BEGIN TIM6_MspInit 1 */ - - /* USER CODE END TIM6_MspInit 1 */ + /* USER CODE BEGIN TIM6_MspInit 1 */ + + /* USER CODE END TIM6_MspInit 1 */ } } @@ -255,22 +258,22 @@ void HAL_TIM_Base_MspInit(TIM_HandleTypeDef* htim_base) void HAL_TIM_Base_MspDeInit(TIM_HandleTypeDef* htim_base) { - + if(htim_base->Instance==TIM6) { - /* USER CODE BEGIN TIM6_MspDeInit 0 */ - - /* USER CODE END TIM6_MspDeInit 0 */ + /* USER CODE BEGIN TIM6_MspDeInit 0 */ + + /* USER CODE END TIM6_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_TIM6_CLK_DISABLE(); - + /* TIM6 interrupt DeInit */ HAL_NVIC_DisableIRQ(TIM6_DAC_IRQn); - /* USER CODE BEGIN TIM6_MspDeInit 1 */ - - /* USER CODE END TIM6_MspDeInit 1 */ + /* USER CODE BEGIN TIM6_MspDeInit 1 */ + + /* USER CODE END TIM6_MspDeInit 1 */ } - + } @@ -285,81 +288,83 @@ void HAL_UART_MspDeInit(UART_HandleTypeDef* huart) { if(huart->Instance==USART2) { - /* USER CODE BEGIN USART2_MspDeInit 0 */ - - /* USER CODE END USART2_MspDeInit 0 */ + /* USER CODE BEGIN USART2_MspDeInit 0 */ + + /* USER CODE END USART2_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART2_CLK_DISABLE(); - + /**USART2 GPIO Configuration PD5 ------> USART2_TX PD6 ------> USART2_RX */ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_5|GPIO_PIN_6); - - /* USER CODE BEGIN USART2_MspDeInit 1 */ - - /* USER CODE END USART2_MspDeInit 1 */ + + /* USART2 interrupt DeInit */ + HAL_NVIC_DisableIRQ(USART2_IRQn); + /* USER CODE BEGIN USART2_MspDeInit 1 */ + + /* USER CODE END USART2_MspDeInit 1 */ } else if(huart->Instance==USART3) { - /* USER CODE BEGIN USART3_MspDeInit 0 */ - - /* USER CODE END USART3_MspDeInit 0 */ + /* USER CODE BEGIN USART3_MspDeInit 0 */ + + /* USER CODE END USART3_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_USART3_CLK_DISABLE(); - + /**USART3 GPIO Configuration PD8 ------> USART3_TX PD9 ------> USART3_RX */ HAL_GPIO_DeInit(GPIOD, GPIO_PIN_8|GPIO_PIN_9); - + /* USART3 interrupt DeInit */ HAL_NVIC_DisableIRQ(USART3_IRQn); - /* USER CODE BEGIN USART3_MspDeInit 1 */ - - /* USER CODE END USART3_MspDeInit 1 */ + /* USER CODE BEGIN USART3_MspDeInit 1 */ + + /* USER CODE END USART3_MspDeInit 1 */ } else if(huart->Instance==UART4) { - /* USER CODE BEGIN UART4_MspDeInit 0 */ - - /* USER CODE END UART4_MspDeInit 0 */ + /* USER CODE BEGIN UART4_MspDeInit 0 */ + + /* USER CODE END UART4_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_UART4_CLK_DISABLE(); - + /**UART4 GPIO Configuration PC10 ------> UART4_TX PC11 ------> UART4_RX */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11); - + /* UART4 interrupt DeInit */ HAL_NVIC_DisableIRQ(UART4_IRQn); - /* USER CODE BEGIN UART4_MspDeInit 1 */ - - /* USER CODE END UART4_MspDeInit 1 */ + /* USER CODE BEGIN UART4_MspDeInit 1 */ + + /* USER CODE END UART4_MspDeInit 1 */ } else if(huart->Instance==UART5) { - /* USER CODE BEGIN UART5_MspDeInit 0 */ - - /* USER CODE END UART5_MspDeInit 0 */ + /* USER CODE BEGIN UART5_MspDeInit 0 */ + + /* USER CODE END UART5_MspDeInit 0 */ /* Peripheral clock disable */ __HAL_RCC_UART5_CLK_DISABLE(); - + /**UART5 GPIO Configuration PC12 ------> UART5_TX PD2 ------> UART5_RX */ HAL_GPIO_DeInit(GPIOC, GPIO_PIN_12); - + HAL_GPIO_DeInit(GPIOD, GPIO_PIN_2); - - /* USER CODE BEGIN UART5_MspDeInit 1 */ - - /* USER CODE END UART5_MspDeInit 1 */ + + /* USER CODE BEGIN UART5_MspDeInit 1 */ + + /* USER CODE END UART5_MspDeInit 1 */ } } diff --git a/Src/stm32f4xx_it.c b/Src/stm32f4xx_it.c index ff3c4d1..49e9d9d 100644 --- a/Src/stm32f4xx_it.c +++ b/Src/stm32f4xx_it.c @@ -169,6 +169,28 @@ void SysTick_Handler(void) /* please refer to the startup file (startup_stm32f4xx.s). */ /******************************************************************************/ +/** + * @brief This function handles USART2 global interrupt. + */ +void USART2_IRQHandler(void) +{ + + /* USER CODE BEGIN USART2_IRQn 0 + uint8_t Rx_message[1]; + + if(HAL_UART_Receive(&huart2, Rx_message, 1, 1000)==HAL_OK) + { + HAL_UART_Transmit(&huart3, Rx_message, 1, 1000); + } + */ + /* USER CODE END USART2_IRQn 0 */ + HAL_UART_IRQHandler(&huart2); + /* USER CODE BEGIN USART2_IRQn 1 */ + + /* USER CODE END USART2_IRQn 1 */ +} + + /** * @brief This function handles USART3 global interrupt. */ @@ -197,6 +219,20 @@ void UART4_IRQHandler(void) /* USER CODE END UART4_IRQn 1 */ } +/** + * @brief This function handles UART5 global interrupt. + */ +void UART5_IRQHandler(void) +{ + /* USER CODE BEGIN UART5_IRQn 0 */ + + /* USER CODE END UART5_IRQn 0 */ + HAL_UART_IRQHandler(&huart5); + /* USER CODE BEGIN UART5_IRQn 1 */ + + /* USER CODE END UART5_IRQn 1 */ +} + /** * @brief This function handles TIM6 global interrupt, DAC1 and DAC2 underrun error interrupts. */ @@ -209,5 +245,11 @@ void TIM6_DAC_IRQHandler(void) /* USER CODE END TIM6_DAC_IRQn 1 */ } + +/* USER CODE BEGIN 1 */ +void EXTI9_5_IRQHandler(void) +{ + HAL_GPIO_EXTI_IRQHandler(GPIO_PIN_8); +} /* USER CODE END 1 */ /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ diff --git a/Src/task.c b/Src/task.c index b1e3877..3ae2482 100644 --- a/Src/task.c +++ b/Src/task.c @@ -7,10 +7,13 @@ task.c #include #include #include "stm32f4xx_hal.h" +#include "uart.h" #include "task.h" #include "integ_mac.h" #include "frame_queue.h" #include "hash.h" +#include "bluetooth.h" +#include "display.h" struct task Task_q[MAX_TASK]; volatile int Task_f, Task_r; @@ -43,7 +46,7 @@ void task_cmd(void *arg) char buf[64], *cp0, *cp1, *cp2; int deviceType = 0; if (fgets(buf, 64, stdin) == NULL) { - printf("$ "); + display(); return; } cp0 = strtok(buf, " \t\n\r"); @@ -51,21 +54,30 @@ void task_cmd(void *arg) // �ƹ��͵� �Է¾��� ��� if (cp0 == NULL) { - printf("$ "); + //printf("$ "); + insert_display_message("* [SYSTEM] \r\n"); + display(); return; } else if(!strcmp(cp0, "info")) { - PrintAllHashData(); + //PrintAllHashData(); + //print_uart_state(); + BT_CONNET(); } else if(!strcmp(cp0, "s")) { INTEG_FRAME frame; - frame.frame_length = INTEG_FRAME_HEADER_LEN + 0x05; + frame.frame_length = INTEG_FRAME_HEADER_LEN + 0x06; memcpy(frame.src_address, my_integ_address, INTEG_ADDR_LEN); memcpy(frame.dest_address, hood_integ_address, INTEG_ADDR_LEN); frame.media_type = cur_media; frame.message_type = DATA_MSG; - frame.data[0] = 0x65; + frame.data[0] = 0x48; + frame.data[1] = 0x65; + frame.data[2] = 0x6c; + frame.data[3] = 0x6c; + frame.data[4] = 0x6f; frame.seqNumber = get_seq_number(); + frame.data[5] = frame.seqNumber + 0x30; frame_queue_insert((unsigned char *)&frame); //macDataReq(broadcast_addr, &frame, frame.frame_length); } @@ -85,7 +97,8 @@ void task_cmd(void *arg) } // �߸��� ���ɾ� �Է��� ��� else { - printf("!!!-Wrong command\n"); + insert_display_message("* [SYSTEM] !!!-Wrong command\r\n"); + //printf("* [SYSTEM] !!!-Wrong command\r\n"); } - printf("$ "); + display(); } \ No newline at end of file diff --git a/Src/uart.c b/Src/uart.c index fa57d64..5652bb7 100644 --- a/Src/uart.c +++ b/Src/uart.c @@ -11,8 +11,11 @@ uart.c #include "task.h" #include "mac_interface_uart.h" #include "mac_interface.h" // ASSO RSP +#include "bluetooth.h" #include "integ_mac.h" #include "frame_queue.h" +#include "display.h" +#include "timer.h" #define ETX 0x04 @@ -25,15 +28,17 @@ FILE __stdout; FILE __stdin; -UART_HandleTypeDef huart1; -UART_HandleTypeDef huart2; +UART_HandleTypeDef huart2; // <---> BT UART_HandleTypeDef huart3; // <---> PC UART_HandleTypeDef huart4; // <---> CC2530 +UART_HandleTypeDef huart5; // <---> LIFI uint8_t rxData; +uint8_t rxData_b; uint8_t txData; unsigned char uart_busy; unsigned char uart_back; +unsigned char is_at = 0; int fputc(int ch, FILE *f) { @@ -117,7 +122,24 @@ void uart_echo(uint8_t ch) else qo_insert(ch); } - +// UART2 <---> BT +void UART2_Init(void) +{ + huart2.Instance = USART2; + huart2.Init.BaudRate = 115200; + huart2.Init.WordLength = UART_WORDLENGTH_8B; + huart2.Init.StopBits = UART_STOPBITS_1; + huart2.Init.Parity = UART_PARITY_NONE; + huart2.Init.Mode = UART_MODE_TX_RX; + huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart2.Init.OverSampling = UART_OVERSAMPLING_16; + + if (HAL_UART_Init(&huart2) != HAL_OK) + { + //Error_Handler(); + } + HAL_UART_Receive_IT(&huart2, btBuf, 1); +} // UART3 <---> PC void UART3_Init(void) @@ -127,7 +149,7 @@ void UART3_Init(void) q_init(); /* USART3 Init */ huart3.Instance = USART3; - huart3.Init.BaudRate = 115200; + huart3.Init.BaudRate = 921600; huart3.Init.WordLength = UART_WORDLENGTH_8B; huart3.Init.StopBits = UART_STOPBITS_1; huart3.Init.Parity = UART_PARITY_NONE; @@ -160,11 +182,136 @@ void UART4_Init(void) HAL_UART_Receive_IT(&huart4, macBuf, 4); } +// UART5 <---> LIFI +void UART5_Init(void) +{ + huart5.Instance = UART5; + huart5.Init.BaudRate = 38400; + huart5.Init.WordLength = UART_WORDLENGTH_8B; + huart5.Init.StopBits = UART_STOPBITS_1; + huart5.Init.Parity = UART_PARITY_NONE; + huart5.Init.Mode = UART_MODE_TX_RX; + huart5.Init.HwFlowCtl = UART_HWCONTROL_NONE; + huart5.Init.OverSampling = UART_OVERSAMPLING_16; + if (HAL_UART_Init(&huart5) != HAL_OK) + { + // Error_Handler(); + } +} + void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) { struct task task; + unsigned char t_char; + + // BT + if(huart->Instance == huart2.Instance) { + + /* + t_char = btBuf[bt_index]; + printf("%c", t_char); + HAL_UART_Receive_IT(&huart2, btBuf + bt_index, 1); + return; + */ + + t_char = btBuf[bt_index]; + switch(bt_state) { + case 0: + if(t_char == 'O') { bt_state = 1; bt_index++; } + else if(t_char == 'A') {bt_state = 1; bt_index++; } + else{ bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, t_char - 1, 1000); bt_index = 0; + frame_queue_insert(btBuf); + } + break; + case 1: + if(t_char == 'K') { bt_state = 2; bt_index++;} + else if(t_char == 'T') { bt_state = 2; bt_index++; is_at = 1;} + break; + case 2: + if(t_char == '+') { bt_state = 3; bt_index++;} + break; + case 3: + // AT + if(is_at) { + // AT+CON + if(t_char == 'C') { + bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 14, 1000); bt_index = 0; + } + else { + bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 4, 1000); bt_index = 0; + } + is_at = 0; + } + // OK + else { + // SET, START + if(t_char == 'S') { + bt_state = 4; + bt_index++; + } + // OK+ADDR: + else if(t_char == 'A') { bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 16, 1000); bt_index = 0; } + + // OK+LOST + else if(t_char == 'L') { bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 3, 1000); bt_index = 0; + + STATUS_TABLE[CONNECT_STATUS][BLUETOOTH] = DISCON; + task.fun = task_bt_update; + strcpy(task.arg, "1"); + task_insert(&task); + } + // OK+CONN + else if(t_char == 'C') { + HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 4, 1000); + t_char = btBuf[7]; + // OK+CONN: ADDR + if(t_char == ':') { + bt_index += 4; + HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 12, 1000); + STATUS_TABLE[CONNECT_STATUS][BLUETOOTH] = CON; + task.fun = task_bt_update; + strcpy(task.arg, "0"); + task_insert(&task); + + } + bt_state = 0; + bt_index = 0; + } + // OK+DISKS + else if(t_char == 'D') { bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 4, 1000); bt_index = 0; } + // OK+RESET + else if(t_char == 'R') { bt_state = 0; HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 4, 1000); bt_index = 0; } + else { } + } + break; + case 4: + // OK+Set:X + if(t_char == 'e') { + HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 3, 1000); + bt_state = 0; + bt_index = 0; + } + // OK+START + else if(t_char == 'T') { + HAL_UART_Receive(&huart2, btBuf + bt_index + 1, 3, 1000); + bt_state = 0; + bt_index = 0; + } + else {} + break; + } + HAL_UART_Receive_IT(&huart2, btBuf + bt_index, 1); + + /* + dataLength = btBuf[0]; + HAL_UART_Receive(&huart2, btBuf + 1, dataLength - 1, 1000); + frame_queue_insert(btBuf); + HAL_UART_Receive_IT(&huart2, btBuf, 1); + */ + } - if (huart->Instance == huart3.Instance) + // CC2530 + else if (huart->Instance == huart3.Instance) { if (rxData != ETX) { if (rxData == '\r') @@ -238,7 +385,7 @@ void HAL_UART_RxCpltCallback(UART_HandleTypeDef *huart) } /* for (int i=0; iInstance == huart3.Instance) + + if (huart->Instance == huart2.Instance) { + printf("a"); + } + else if (huart->Instance == huart3.Instance) { if ((ch = qo_delete()) == 0) { uart_busy = 0; @@ -261,7 +411,7 @@ void HAL_UART_TxCpltCallback(UART_HandleTypeDef *huart) } } else if (huart->Instance == huart4.Instance) { - + printf("a"); } }