git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@1271 35acf78f-673a-0410-8e92-d51de3d6d3f4
This commit is contained in:
parent
0521c90a44
commit
0bd69a2cb1
|
@ -41,13 +41,6 @@ static msg_t Thread1(void *arg) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static SPIConfig spicfg = {
|
|
||||||
16, IOPORT1, 4, 0
|
|
||||||
};
|
|
||||||
|
|
||||||
static uint8_t txbuf[8] = {0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF};
|
|
||||||
static uint8_t rxbuf[8];
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Entry point, note, the main() function is already a thread in the system
|
* Entry point, note, the main() function is already a thread in the system
|
||||||
* on entry.
|
* on entry.
|
||||||
|
@ -67,14 +60,6 @@ int main(int argc, char **argv) {
|
||||||
*/
|
*/
|
||||||
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
|
||||||
|
|
||||||
palSetPadMode(IOPORT1, 4, PAL_MODE_OUTPUT_PUSHPULL);
|
|
||||||
palSetPad(IOPORT1, 4);
|
|
||||||
spiStart(&SPID1, &spicfg);
|
|
||||||
spiSelect(&SPID1);
|
|
||||||
spiExchange(&SPID1, 8, txbuf, rxbuf);
|
|
||||||
spiUnselect(&SPID1);
|
|
||||||
spiStop(&SPID1);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Normal main() thread activity, in this demo it does nothing except
|
* Normal main() thread activity, in this demo it does nothing except
|
||||||
* sleeping in a loop and check the button state.
|
* sleeping in a loop and check the button state.
|
||||||
|
|
14
os/io/spi.c
14
os/io/spi.c
|
@ -60,13 +60,15 @@ void spiObjectInit(SPIDriver *spip) {
|
||||||
void spiStart(SPIDriver *spip, const SPIConfig *config) {
|
void spiStart(SPIDriver *spip, const SPIConfig *config) {
|
||||||
|
|
||||||
chDbgCheck((spip != NULL) && (config != NULL), "spiStart");
|
chDbgCheck((spip != NULL) && (config != NULL), "spiStart");
|
||||||
|
|
||||||
|
chSysLock();
|
||||||
chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY),
|
chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY),
|
||||||
"spiStart(), #1",
|
"spiStart(), #1",
|
||||||
"invalid state");
|
"invalid state");
|
||||||
|
|
||||||
spip->spd_config = config;
|
spip->spd_config = config;
|
||||||
spi_lld_start(spip);
|
spi_lld_start(spip);
|
||||||
spip->spd_state = SPI_READY;
|
spip->spd_state = SPI_READY;
|
||||||
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -77,12 +79,14 @@ void spiStart(SPIDriver *spip, const SPIConfig *config) {
|
||||||
void spiStop(SPIDriver *spip) {
|
void spiStop(SPIDriver *spip) {
|
||||||
|
|
||||||
chDbgCheck(spip != NULL, "spiStop");
|
chDbgCheck(spip != NULL, "spiStop");
|
||||||
|
|
||||||
|
chSysLock();
|
||||||
chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY),
|
chDbgAssert((spip->spd_state == SPI_STOP) || (spip->spd_state == SPI_READY),
|
||||||
"spiStop(), #1",
|
"spiStop(), #1",
|
||||||
"invalid state");
|
"invalid state");
|
||||||
|
|
||||||
spi_lld_stop(spip);
|
spi_lld_stop(spip);
|
||||||
spip->spd_state = SPI_STOP;
|
spip->spd_state = SPI_STOP;
|
||||||
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -94,12 +98,13 @@ void spiSelect(SPIDriver *spip) {
|
||||||
|
|
||||||
chDbgCheck(spip != NULL, "spiSelect");
|
chDbgCheck(spip != NULL, "spiSelect");
|
||||||
|
|
||||||
|
chSysLock();
|
||||||
chDbgAssert(spip->spd_state == SPI_READY,
|
chDbgAssert(spip->spd_state == SPI_READY,
|
||||||
"spiSelect(), #1",
|
"spiSelect(), #1",
|
||||||
"not idle");
|
"not idle");
|
||||||
|
|
||||||
spi_lld_select(spip);
|
spi_lld_select(spip);
|
||||||
spip->spd_state = SPI_ACTIVE;
|
spip->spd_state = SPI_ACTIVE;
|
||||||
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -112,12 +117,13 @@ void spiUnselect(SPIDriver *spip) {
|
||||||
|
|
||||||
chDbgCheck(spip != NULL, "spiUnselect");
|
chDbgCheck(spip != NULL, "spiUnselect");
|
||||||
|
|
||||||
|
chSysLock();
|
||||||
chDbgAssert(spip->spd_state == SPI_ACTIVE,
|
chDbgAssert(spip->spd_state == SPI_ACTIVE,
|
||||||
"spiUnselect(), #1",
|
"spiUnselect(), #1",
|
||||||
"not locked");
|
"not locked");
|
||||||
|
|
||||||
spi_lld_unselect(spip);
|
spi_lld_unselect(spip);
|
||||||
spip->spd_state = SPI_READY;
|
spip->spd_state = SPI_READY;
|
||||||
|
chSysUnlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue