8장 - FreeRTOS Monitor

조재훈·2023년 6월 19일

Monitor

  • Monitor Task 생성
  • USART Serial Rx 인터럽트에서 받아온 글자를 Queue를 이용해 Monitor Task로 보냄
  • Monitor Task에서 Queue에 글자가 입력되었는지 조사하여 글자 입력시 글자 처리 Processor로 넘어감
  • 명령어 테이블에서 검색하여 명령어가 테이블에 있으면 명령어 Shell Command 함수 호출
  • Shell Command 함수에서 입력되어온 글자를 스페이스 단위로 몇 개가 들어왔는지 입력된 글자의 String은 포인터로 넘겨주어 Shell Command에서 처리

명령어 테이블

  • 명령어 테이블은 Struct로 정의
typedef struct
{
	char *str;  // 명령어
    int (*func)(int, char **); // 명령어 서버루틴
    char *usage;  // 사용법
} Cmd_tbl;

const Cmd_tbl cmd_ctbl[] = {
	{"help",   monitor_chelp,    "monitor help"},
    {"ls",     monitor_lshelp,   "Command List"},
    {0,0,0}
};
  • "help" : 입력시 받아들일 명령어

  • monitor_chelp : 명령어가 일치할 경우 처리할 서버루틴

  • "monitor help" : 사용법에 대한 정의

  • 새로운 명령어 추가시

int NameRoutine(int argc, char* argv[])
{
	argc // 명령어 개수
    argv[1] // 입력 String 주소
    코딩
    return YES;
}
  • argc
    : Space로 구분된 입력이 몇 개 인지 가르쳐줌
    : ex) name honggildong
    => argc는 2
    => argv[1]에는 honggildong String이 저장된 주소 전달

Queue

  • FIFO (First In First Out)
  • 입구는 Front, 출구는 Rear 인덱스로 관리
    => Queue에 자료가 있는지, 꽉 차있는지, 비어있는지 처리

1) Queue가 비어있는지 확인

  • Front의 "rx_point_head"와 Rear의 "rx_point_tail" 값이 같으면 비어있다고 판단

2) Insert Queue (큐에 입력)

  • 현재의 Rx_Point를 가르치고 있는 Index에 데이터를 넣고 Rx Head Point를 증가
void Uart3_EnQueue(uint16_t data)
{
	u3_rx_buffer[u3_rx_point_head] = data;
    y3_increase_point_value(&u3_rx_point_head);
}

3) Delete Queue (큐에서 빼내기)

  • 현재의 rx_point_tail index에 있는 내용 읽어내고 난 후 rx_point_tail 인덱스 증가
uint16_t Uart3_DeQueue(void)
{
	uint16_t retVal = u3_rx_buffer[u3_rx_point_tail];
    u3_increase_point_value(&u3_rx_point_tail);
    return retVal;
}
profile
맨땅에 헤딩. 인생은 실전.

0개의 댓글