/*------------------------------------------------------------------------------ * Outputs a character. *-----------------------------------------------------------------------------*/ int fputc(int ch, FILE *f) { if ((f == stdout) || (f == stderr)) { DBG_PutChar(ch); return ch; } else return EOF; }
/** * Get Dec Input * \param numChar Number of character to wait. * \param pInt Pointer to uint32_t for input result. * \return 0 if valid data input. */ static uint8_t GetDecInput(uint8_t numChar, uint32_t *pInt) { uint8_t key; uint32_t i; uint32_t result = 0; for (i = 0; i < numChar;) { key = DBG_GetChar(); if (key == 27) { printf(" Canceled\n\r"); return key; } if (key > '9' || key < '0') continue; DBG_PutChar(key); result = result * 10 + (key - '0'); i ++; } if (pInt) *pInt = result; return 0; }
void _ttywrch( int ch ) { DBG_PutChar( (uint8_t)ch ) ; }
/** * Monitor keyboard buttons & Update key status in HID driver */ static void HIDDKeyboardProcessKeys(void) { uint32_t i; uint8_t pressedKeys[NUM_KEYS]; uint8_t pressedKeysSize = 0; uint8_t releasedKeys[NUM_KEYS]; uint8_t releasedKeysSize = 0; /* Monitor buttons */ #ifdef NO_PUSHBUTTON if (DBG_IsRxReady()) { uint8_t key = DBG_GetChar(); switch (key) { case '1': case '2': i = key - '1'; if (keyStatus[i]) { /* Key press simulation */ TRACE_INFO("Key %u pressed\n\r", (unsigned int)i); keyStatus[i] = 0; pressedKeys[pressedKeysSize] = keyCodes[i]; pressedKeysSize ++; HIDDKeyboard_RemoteWakeUp(); } else { /* Key release simulation */ TRACE_INFO("Key %u released\n\r", (unsigned int)i); keyStatus[i] = 1; releasedKeys[releasedKeysSize] = keyCodes[i]; releasedKeysSize++; } break; default: DBG_PutChar(key); } } #else for (i = 0; i < PIO_LISTSIZE(pinsPushButtons); i++) { /* Check if button state has changed */ uint8_t isButtonPressed = PIO_Get(&(pinsPushButtons[i])); if (isButtonPressed != keyStatus[i]) { /* Update button state */ if (!isButtonPressed) { /* Key has been pressed */ TRACE_INFO("Key %u has been pressed\n\r", i); keyStatus[i] = 0; pressedKeys[pressedKeysSize] = keyCodes[i]; pressedKeysSize++; HIDDKeyboard_RemoteWakeUp(); } else { /* Key has been released */ TRACE_INFO("Key %u has been released\n\r", i); keyStatus[i] = 1; releasedKeys[releasedKeysSize] = keyCodes[i]; releasedKeysSize++; } } } #endif /* Update key status in the HID driver if necessary */ if ((pressedKeysSize != 0) || (releasedKeysSize != 0)) { uint8_t status; do { status = HIDDKeyboard_ChangeKeys(pressedKeys, pressedKeysSize, releasedKeys, releasedKeysSize); } while (status != USBD_STATUS_SUCCESS); } }
/** * \brief Application entry point for MPU example. * * \return Unused (ANSI-C compatibility). */ extern int main( void ) { uint8_t ucChoice = 0; /* Disable watchdog */ WDT_Disable(WDT); uint32_t *pdw = (uint32_t *)MPU_SRAM_PRIVILEGE_START_ADDRESS; /* Output example information */ printf("\n\r\n\r\n\r"); printf("-- MPU Example %s --\n\r", SOFTPACK_VERSION); printf("-- %s\n\r", BOARD_NAME); printf("-- Compiled: %s %s With %s--\n\r", __DATE__, __TIME__, COMPILER_NAME); LED_Configure(LED_YELLOW0); /* Set up the default memory regions */ _SetupMPU(); /* Set the environment to thread mode */ __set_CONTROL(USER_MODE); while (ucChoice != '9') { printf("----------------------------------------\n\r"); printf(" Choose an option below:\n\r"); printf(" 1. Protect the Yellow LED region\n\r"); printf(" 2. UN-protect the Yellow LED region\n\r"); printf(" 3. Toggle the green LED\n\r"); printf(" 4. Set the RAM region to read only \n\r"); printf(" 5. Set the RAM region to read/write\n\r"); printf(" 6. Read the RAM content at offset 0\n\r"); printf(" 7. Write the RAM context at offset 0\n\r"); printf(" 8. Quit the external program\n\r"); printf("\n\r"); printf(" Choice: "); ucChoice = DBG_GetChar(); DBG_PutChar(ucChoice); printf("\n\r"); switch (ucChoice) { case '1': _UpdateMPU(MPU_PIOC_REGION_REGION, MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS | MPU_REGION_VALID | MPU_PIOC_REGION_REGION, MPU_AP_UNPRIVILEGED_READONLY | MPU_REGION_EXECUTE_NEVER | MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS - MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) | MPU_REGION_ENABLE); break; case '2': _UpdateMPU(MPU_PIOC_REGION_REGION, MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS | MPU_REGION_VALID | MPU_PIOC_REGION_REGION, MPU_AP_FULL_ACCESS | MPU_REGION_EXECUTE_NEVER | MPU_CalMPURegionSize(MPU_PIOC_PERIPHERALS_REGION_END_ADDRESS - MPU_PIOC_PERIPHERALS_REGION_START_ADDRESS) | MPU_REGION_ENABLE); break; case '3': /* Set back to unprivileged mode*/ LED_Toggle(LED_YELLOW0); __set_CONTROL(USER_MODE); break; case '4': _UpdateMPU(MPU_PRIVILEGE_RAM_REGION, MPU_SRAM_PRIVILEGE_START_ADDRESS | MPU_REGION_VALID | MPU_PRIVILEGE_RAM_REGION, MPU_AP_UNPRIVILEGED_READONLY | MPU_REGION_CACHEABLE | MPU_REGION_BUFFERABLE | MPU_TEX_B001| MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS - MPU_SRAM_PRIVILEGE_START_ADDRESS) | MPU_REGION_ENABLE); break; case '5': _UpdateMPU(MPU_PRIVILEGE_RAM_REGION, MPU_SRAM_PRIVILEGE_START_ADDRESS | MPU_REGION_VALID | MPU_PRIVILEGE_RAM_REGION, MPU_AP_FULL_ACCESS | MPU_REGION_CACHEABLE | MPU_REGION_BUFFERABLE | MPU_TEX_B001| MPU_CalMPURegionSize(MPU_SRAM_PRIVILEGE_END_ADDRESS - MPU_SRAM_PRIVILEGE_START_ADDRESS) | MPU_REGION_ENABLE); break; case '6': printf("-I- RAM address has content %x \n\r",(unsigned)(pdw[0])); break; case '7': printf("-I- Write offset 0 of RAM region with content 0x55AA55AA\n\r"); pdw[0] = 0x55AA55AA; break; case '8': printf("-I- MPU TEST FINISH ...\n\r"); break; default: printf("-I- This option is not valid\n\r"); break; } } /* Setback to privilege mode, before entering the main routine, it is supervisor mode*/ __ASM volatile(" svc 0x00 "); while (!dwRaisePriDone); dwRaisePriDone = 0; __set_CONTROL(PRIVILEGE_MODE); return 0; }