// Called in ISR context called when a data is received bool USBMSD::EP2_OUT_callback() { uint32_t size = 0; uint8_t buf[MAX_PACKET_SIZE_EPBULK]; readEP(EPBULK_OUT, buf, &size, MAX_PACKET_SIZE_EPBULK); switch (stage) { // the device has to decode the CBW received case READ_CBW: CBWDecode(buf, size); break; // the device has to receive data from the host case PROCESS_CBW: switch (cbw.CB[0]) { case WRITE10: case WRITE12: memoryWrite(buf, size); break; case VERIFY10: memoryVerify(buf, size); break; } break; // an error has occured: stall endpoint and send CSW default: stallEndpoint(EPBULK_OUT); csw.Status = CSW_ERROR; sendCSW(); break; } //reactivate readings on the OUT bulk endpoint readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); return true; }
void test_memoryWriteHalfWord_should_write_memory_in_word_and_return_1_if_success(void) { int size = HALFWORD_SIZE; uint32_t writeData = 0xCAFE, address = 0x20000000; writeMemory_ExpectAndReturn(_session, (uint8_t *)&writeData, address, HALFWORD_SIZE, TLV_WRITE_RAM, PROCESS_DONE); int result = memoryWrite(address, writeData, HALFWORD_SIZE); TEST_ASSERT_EQUAL(PROCESS_DONE, result); }
void test_memoryWriteByte_should_write_memory_in_word_and_return_1_if_success(void) { int size = BYTE_SIZE; uint32_t writeData = 0xBE, address = 0x20000000; writeMemory_ExpectAndReturn(_session, (uint8_t *)&writeData, address, BYTE_SIZE, TLV_WRITE_RAM, 0); tlvService_Expect(_session); writeMemory_ExpectAndReturn(_session, (uint8_t *)&writeData, address, BYTE_SIZE, TLV_WRITE_RAM, PROCESS_DONE); int result = memoryWrite(address, writeData, BYTE_SIZE); TEST_ASSERT_EQUAL(PROCESS_DONE, result); }
int memoryWriteWord(uint32_t address, uint32_t dataWrite) { return memoryWrite(address, dataWrite, WORD_SIZE); }
int memoryWriteHalfword(uint32_t address, uint32_t dataWrite) { return memoryWrite(address, dataWrite, HALFWORD_SIZE); }
int memoryWriteByte(uint32_t address, uint32_t dataWrite) { return memoryWrite(address, dataWrite, BYTE_SIZE); }