Exemplo n.º 1
0
// Called in ISR context when a data has been transferred
bool USBMSD::EP2_IN_callback() {
    switch (stage) {

            // the device has to send data to the host
        case PROCESS_CBW:
            switch (cbw.CB[0]) {
                case READ10:
                case READ12:
                    memoryRead();
                    break;
            }
            break;

            //the device has to send a CSW
        case SEND_CSW:
            sendCSW();
            break;

            // an error has occured
        case ERROR:
            stallEndpoint(EPBULK_IN);
            sendCSW();
            break;

            // the host has received the CSW -> we wait a CBW
        case WAIT_CSW:
            stage = READ_CBW;
            break;
        case READ_CBW:
            break;
    }
    return true;
}
void test_memoryReadByte_should_read_memory_and_return_data_in_byte(void)
{
  int size = BYTE_SIZE;
  uint32_t address = 0x20000000, dataRead = 0;
  uint8_t data[] = {0xAA, 0xBB, 0xCC, 0xDD};
  
  readMemory_ExpectAndReturn(_session, address, size, data);
  
	int result = memoryRead(address, &dataRead, BYTE_SIZE);
  
  TEST_ASSERT_EQUAL(1, result);
  TEST_ASSERT_EQUAL_HEX32(0xAA, dataRead);
}
void test_memoryReadWord_should_read_memory_and_return_data_in_word(void)
{
  int size = WORD_SIZE;
  uint32_t dataRead = 0, address = 0x20000000;
  uint8_t data[] = {0xEF, 0xBE, 0xAD, 0xDE};
  
  readMemory_ExpectAndReturn(_session, address, size, data);
  
	int result = memoryRead(address, &dataRead, WORD_SIZE);
  
  TEST_ASSERT_EQUAL(1, result);
  TEST_ASSERT_EQUAL_HEX32(0xDEADBEEF, dataRead);
}
void test_memoryReadWord_should_continute_wait_until_data_is_return(void)
{
  int size = WORD_SIZE;
  uint32_t dataRead = 0, address = 0x20000000;
  uint8_t data[] = {0xEF, 0xBE, 0xAD, 0xDE};
  
  readMemory_ExpectAndReturn(_session, address, size, 0);
  tlvService_Expect(_session);
  readMemory_ExpectAndReturn(_session, address, size, data);
  
	int result = memoryRead(address, &dataRead, WORD_SIZE);
  
  TEST_ASSERT_EQUAL(1, result);
  TEST_ASSERT_EQUAL_HEX32(0xDEADBEEF, dataRead);
}
Exemplo n.º 5
0
void USBCDCMSC::CBWDecode(uint8_t * buf, uint16_t size) {
    if (size == sizeof(cbw)) {
        memcpy((uint8_t *)&cbw, buf, size);
        if (cbw.Signature == CBW_Signature) {
            csw.Tag = cbw.Tag;
            csw.DataResidue = cbw.DataLength;
            if ((cbw.CBLength <  1) || (cbw.CBLength > 16) ) {
                fail();
            } else {
                switch (cbw.CB[0]) {
                    case TEST_UNIT_READY:
                        testUnitReady();
                        break;
                    case REQUEST_SENSE:
                        requestSense();
                        break;
                    case INQUIRY:
                        inquiryRequest();
                        break;
                    case MODE_SENSE6:
                        modeSense6();
                        break;
                    case READ_FORMAT_CAPACITIES:
                        readFormatCapacity();
                        break;
	                case MEDIA_REMOVAL:
	                    mediaRemoval();
						break;
                    case READ_CAPACITY:
                        readCapacity();
                        break;
                    case READ10:
                    case READ12:
                        if (infoTransfer()) {
                            if ((cbw.Flags & 0x80)) {
                                stage = PROCESS_CBW;
                                memoryRead();
                            } else {
                                stallEndpoint(MSDBULK_OUT);
                                csw.Status = CSW_ERROR;
                                sendCSW();
                            }
                        }
                        break;
                    case WRITE10:
                    case WRITE12:
                        if (infoTransfer()) {
                            if (!(cbw.Flags & 0x80)) {
                                stage = PROCESS_CBW;
                            } else {
                                stallEndpoint(MSDBULK_IN);
                                csw.Status = CSW_ERROR;
                                sendCSW();
                            }
                        }
                        break;
                    case VERIFY10:
                        if (!(cbw.CB[1] & 0x02)) {
                            csw.Status = CSW_PASSED;
                            sendCSW();
                            break;
                        }
                        if (infoTransfer()) {
                            if (!(cbw.Flags & 0x80)) {
                                stage = PROCESS_CBW;
                                memOK = true;
                            } else {
                                stallEndpoint(MSDBULK_IN);
                                csw.Status = CSW_ERROR;
                                sendCSW();
                            }
                        }
                        break;
                    default:
                        fail();
                        break;
                }
            }
        }
    }
}
Exemplo n.º 6
0
Calculator::Calculator(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Calculator), memory(0), result(0), currOperand(0), currOper("")
{
    ui->setupUi(this);

    QSignalMapper *numberPressed = new QSignalMapper(this);

    {
    QObject::connect(ui->n0Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n1Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n2Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n3Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n4Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n5Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n6Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n7Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n8Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->n9Button, SIGNAL(clicked()), numberPressed, SLOT(map()));
    QObject::connect(ui->nDotButton, SIGNAL(clicked()), numberPressed, SLOT(map()));
    }

    {
    numberPressed->setMapping(ui->n0Button, "0");
    numberPressed->setMapping(ui->n1Button, "1");
    numberPressed->setMapping(ui->n2Button, "2");
    numberPressed->setMapping(ui->n3Button, "3");
    numberPressed->setMapping(ui->n4Button, "4");
    numberPressed->setMapping(ui->n5Button, "5");
    numberPressed->setMapping(ui->n6Button, "6");
    numberPressed->setMapping(ui->n7Button, "7");
    numberPressed->setMapping(ui->n8Button, "8");
    numberPressed->setMapping(ui->n9Button, "9");
    numberPressed->setMapping(ui->nDotButton, ".");
    }
    QObject::connect(numberPressed, SIGNAL(mapped(QString)), this, SLOT(appendToDisplayString(QString)));
    QObject::connect(this, SIGNAL(displayStringChanged(QString)), ui->lineEdit, SLOT(setText(QString)));

    QObject::connect(ui->cClearButton, SIGNAL(clicked()), this, SLOT(clearDisplayString()));
    QObject::connect(ui->cCEButton, SIGNAL(clicked()), this, SLOT(clearExpression()));
    QObject::connect(ui->cACButton, SIGNAL(clicked()), this, SLOT(clearAll()));
    QObject::connect(ui->cBackSpaceButton, SIGNAL(clicked()), this, SLOT(backSpace()));

    QSignalMapper *operatorPressed = new QSignalMapper;

    QObject::connect(ui->oDivButton, SIGNAL(clicked()), operatorPressed, SLOT(map()));
    QObject::connect(ui->oMultButton, SIGNAL(clicked()), operatorPressed, SLOT(map()));
    QObject::connect(ui->oPlusButton, SIGNAL(clicked()), operatorPressed, SLOT(map()));
    QObject::connect(ui->oMinusButton, SIGNAL(clicked()), operatorPressed, SLOT(map()));
    QObject::connect(ui->oEqButton, SIGNAL(clicked()), operatorPressed, SLOT(map()));

    operatorPressed->setMapping(ui->oDivButton, "/");
    operatorPressed->setMapping(ui->oMultButton, "*");
    operatorPressed->setMapping(ui->oPlusButton, "+");
    operatorPressed->setMapping(ui->oMinusButton, "-");
    operatorPressed->setMapping(ui->oEqButton, "=");

    QObject::connect(operatorPressed, SIGNAL(mapped(QString)), this, SLOT(operButtonPressed(QString)));

    QObject::connect(ui->nDotButton, SIGNAL(clicked(bool)), ui->nDotButton, SLOT(setEnabled(bool)));

    QObject::connect(ui->mClearButton, SIGNAL(clicked()), this, SLOT(clearMemory()));
    QObject::connect(ui->mReadButton, SIGNAL(clicked()), this, SLOT(memoryRead()));
    QObject::connect(ui->mPlusButton, SIGNAL(clicked()), this, SLOT(memoryAdd()));
    QObject::connect(ui->mMinusButton, SIGNAL(clicked()), this, SLOT(memoryDec()));

}
int memoryReadWord(uint32_t address, uint32_t *dataRead) {
  return memoryRead(address, dataRead, WORD_SIZE);
}
int memoryReadHalfword(uint32_t address, uint32_t *dataRead) {
  return memoryRead(address, dataRead, HALFWORD_SIZE);
}
/* ########################## Mock ############################ */
int memoryReadByte(uint32_t address, uint32_t *dataRead) {
  return memoryRead(address, dataRead, BYTE_SIZE);
}