2014-04-17 2 views
0

DMA 인터럽트 처리기에 문제가 있습니다. MicroChip PIC32 임베디드 칩의 LCD 디스플레이에 맞게 조정했습니다.for 루프의 바이트에서 니블 추출하기

저는 내부 메모리가 제한되어 있으며 내 컬러 LCD 용 프레임 버퍼가 필요합니다. 16 색을 사용하고 픽셀 당 니블을 사용하기로 결정했습니다. 내가 병렬 포트 및 DMA 전송을 통해 LCD에 보낼 16 비트 값으로 4 비트 니블 변환하고 내 인터럽트 핸들러에서

unsigned char GraphicsFrame[FRAME_HEIGHT][LINE_LENGTH/2]; 

:이처럼 보이는 배열을 만들었습니다. 내가 이것을 달성하기 위해 인터럽트 처리기에서 테이블을 사용하지만,이 때 나는 General_Exception_Handler로 갈거야 디버깅하고 내가 4 비트 니블을 추출하고 16 비트 값으로 변환하는 방식으로 문제를 지적하고있어 :

for(i=0,j=0; i<30; i++, lineX++) 
{ 
    // not particularly elegant, perhaps look at a better way 
    if  ((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x0) lineBuffer[j++] = (unsigned short int)RGBBlack; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x1) lineBuffer[j++] = (unsigned short int)RGBBlue; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x2) lineBuffer[j++] = (unsigned short int)RGBRed; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x3) lineBuffer[j++] = (unsigned short int)RGBGreen; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x4) lineBuffer[j++] = (unsigned short int)RGBCyan; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x6) lineBuffer[j++] = (unsigned short int)RGBYellow; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0x7) lineBuffer[j++] = (unsigned short int)RGBKaneGreen; 
    else if((((GraphicsFrame[line][i]) >> 4) & 0x0F) == 0xF) lineBuffer[j++] = (unsigned short int)RGBWhite; 

    if  ((GraphicsFrame[line][i] & 0x0F) == 0x0) lineBuffer[j++] = (unsigned short int)RGBBlack; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x1) lineBuffer[j++] = (unsigned short int)RGBBlue; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x2) lineBuffer[j++] = (unsigned short int)RGBRed; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x3) lineBuffer[j++] = (unsigned short int)RGBGreen; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x4) lineBuffer[j++] = (unsigned short int)RGBCyan; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x5) lineBuffer[j++] = (unsigned short int)RGBMagenta; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x6) lineBuffer[j++] = (unsigned short int)RGBYellow; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0x7) lineBuffer[j++] = (unsigned short int)RGBKaneGreen; 
    else if((GraphicsFrame[line][i] & 0x0F) == 0xF) lineBuffer[j++] = (unsigned short int)RGBWhite; 
} 

나는 60 개 픽셀이 들어있는 다른 배열을 사용하여 한 번 (60 × 16 비트)에서 60 개 픽셀을 전송하는 DMA를 설정하기 위해 노력하고있어 :

unsigned short int lineBuffer[60]; 

사람은 자리 수를 니블을 추출하고 변환하는 방식에 문제가 있습니까? 아무런 경고 나 오류도 없으므로 아무 것도 나에게 뛰어 오지 않습니다! 그것은 지금까지 내가 당신이 무엇을 게시에서 말할 수 괜찮아 보이는

답변

1

감사 어떤 도움이, 감사합니다. 물고기가 유일한 것은 linelineX 변수입니다. 그들은 사용하지 않는 것 같습니다. 또한 2D 배열의 첫 번째 차원을 반복하려는 경우 중첩 된 for 루프를 사용해야 할 것입니다.

게시물의 나머지 부분은 오히려 대답보다, 코드 리뷰입니다 : 게시

코드는 조회 테이블이 아닙니다. 이 대신에 같은 그 일을 고려 : 위의

const uint16_t COLOR_TABLE [COLORS_N] = 
{ 
    RGBBlack,  // 0x0 
    RGBBlue,  // 0x1 
    RGBRed,  // 0x2 
    RGBGreen,  // 0x3 
    RGBCyan,  // 0x4 
    undefined,  // 0x5 
    RGBYellow,  // 0x6 
    RGBKaneGreen, // 0x7 
    undefined,  // 0x8 
    undefined,  // 0x9 
    undefined,  // 0xA 
    undefined,  // 0xB 
    undefined,  // 0xC 
    undefined,  // 0xD 
    undefined,  // 0xE 
    RGBWhite,  // 0xF 
}; 

... 

uint8_t line_iterator=0; 

for(uint8_t i=0; i<LINE_LENGTH/2; i++) 
{ 
    uint8_t nibble; 

    nibble = (uint8_t) ((GraphicsFrame[line][i]) >> 4) & 0x0F); 
    lineBuffer[line_iterator] = COLOR_TABLE[nibble]; 

    nibble = (uint8_t) (GraphicsFrame[line][i] & 0x0F); 
    lineBuffer[line_iterator + 1] = COLOR_TABLE[nibble]; 

    line_iterator += 2; 
} 

댓글 :

  • 이 조회 테이블은 크게 두 가독성과 프로그램 속도를 향상시킬 수 있습니다. 이것이 ISR을위한 것이라면 반드시 이와 같은 표를 사용해야합니다.
  • 임베디드 시스템이므로 stdint.h의 정수 유형을 사용해야합니다.
  • 암시 적 정수 프로모션에주의하십시오.
  • for 루프를 간단하게 유지하고 난독 화를 피하십시오. 둘 이상이 필요하면 반복자에 대해 자체 설명 변수 이름을 사용하십시오.
  • 30과 같은 "마법 번호"는 사용하지 마십시오.
+0

감사의 말을 많이 전합니다. 네, 실제로 look up table을 구현하지 않았습니다! 약간 '진행중인 작업'이었지만 여러분의 솔루션이 마음에 들었고 대부분 구현했습니다. 나는 여전히 문제를 겪고 있으므로 ISR의 어딘가에서 벗어날 것이라고 생각합니다. –