diff options
author | (no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-07-23 16:47:18 +0000 |
---|---|---|
committer | (no author) <(no author)@6dc7ffe9-61d6-0310-9af1-9938baff3ed1> | 2006-07-23 16:47:18 +0000 |
commit | fe4d6ec2522a13a301c417f8e34b722e3e4c50c1 (patch) | |
tree | a25b30672182794bf552756333373accb41f1638 | |
parent | eca19c6f633e4f547ba14258ada05fed2a9787c6 (diff) |
add clear bits and set bits functions
git-svn-id: https://svn.openpcd.org:2342/trunk@30 6dc7ffe9-61d6-0310-9af1-9938baff3ed1
-rw-r--r-- | openpcd/firmware/src/rc632.c | 47 | ||||
-rw-r--r-- | openpcd/firmware/src/rc632.h | 2 |
2 files changed, 35 insertions, 14 deletions
diff --git a/openpcd/firmware/src/rc632.c b/openpcd/firmware/src/rc632.c index 4d62b49..64ab91e 100644 --- a/openpcd/firmware/src/rc632.c +++ b/openpcd/firmware/src/rc632.c @@ -39,6 +39,9 @@ int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len, u_int16_t rx_len_max = 0; u_int16_t rx_cnt = 0; + /* disable RC632 interrupt because it wants to do SPI transactions */ + AT91F_AIC_DisableIt(AT91C_BASE_AIC, OPENPCD_RC632_IRQ); + DEBUGPCRF("enter(tx_len=%u)", tx_len); if (rx_len) { @@ -50,26 +53,28 @@ int spi_transceive(const u_int8_t *tx_data, u_int16_t tx_len, while (1) { u_int32_t sr = pSPI->SPI_SR; u_int8_t tmp; - //DEBUGP("loop:SPI_SR 0x%08x\r\n", sr); if (sr & AT91C_SPI_RDRF) { tmp = pSPI->SPI_RDR; rx_cnt++; - //DEBUGP("<= RDRF, reading byte 0x%02x\r\n", tmp); if (rx_len && *rx_len < rx_len_max) rx_data[(*rx_len)++] = tmp; } if (sr & AT91C_SPI_TDRE) { - if (tx_len > tx_cur) { - tmp = tx_data[tx_cur++]; - //DEBUGP("=> TDRE, sending byte 0x%02x\r\n", tmp); - pSPI->SPI_TDR = tmp; - } + if (tx_len > tx_cur) + pSPI->SPI_TDR = tx_data[tx_cur++]; } if (tx_cur >= tx_len && rx_cnt >= tx_len) break; } AT91F_SPI_Disable(pSPI); - DEBUGPCRF("leave(%02x %02x)", rx_data[0], rx_data[1]); + if (rx_data) + DEBUGPCRF("leave(%02x %02x)", rx_data[0], rx_data[1]); + else + DEBUGPCRF("leave()"); + + /* Re-enable RC632 interrupts */ + AT91F_AIC_EnableIt(AT91C_BASE_AIC, OPENPCD_RC632_IRQ); + return 0; } @@ -96,7 +101,6 @@ void rc632_reg_write(u_int8_t addr, u_int8_t data) spi_outbuf[0] = addr; spi_outbuf[1] = data; - /* transceive */ //spi_transceive(spi_outbuf, 2, NULL, NULL); spi_transceive(spi_outbuf, 2, spi_inbuf, &rx_len); } @@ -109,7 +113,6 @@ int rc632_fifo_write(u_int8_t len, u_int8_t *data) spi_outbuf[0] = FIFO_ADDR; memcpy(&spi_outbuf[1], data, len); - /* transceive (len+1) */ spi_transceive(spi_outbuf, len+1, NULL, NULL); return len; @@ -124,7 +127,6 @@ u_int8_t rc632_reg_read(u_int8_t addr) spi_outbuf[0] = addr | 0x80; spi_outbuf[1] = 0x00; - /* transceive */ spi_transceive(spi_outbuf, 2, spi_inbuf, &rx_len); return spi_inbuf[1]; @@ -145,13 +147,30 @@ u_int8_t rc632_fifo_read(u_int8_t max_len, u_int8_t *data) spi_outbuf[0] |= 0x80; spi_outbuf[fifo_length] = 0x00; - /* transceive */ spi_transceive(spi_outbuf, fifo_length+1, spi_inbuf, &rx_len); memcpy(data, spi_inbuf+1, rx_len-1); return rx_len-1; } +u_int8_t rc632_set_bits(u_int8_t reg, u_int8_t bits) +{ + u_int8_t val = rc632_reg_read(reg); + val |= bits; + rc632_reg_write(reg, val); + + return val; +} + +u_int8_t rc632_clear_bits(u_int8_t reg, u_int8_t bits) +{ + u_int8_t val = rc632_reg_read(reg); + val &= bits; + rc632_reg_write(reg, val); + + return val; +} + /* RC632 interrupt handling */ static struct openpcd_hdr irq_opcdh; @@ -317,7 +336,7 @@ int rc632_test(void) return 0; } -#else +#else /* DEBUG */ int rc632_test(void) {} int rc632_dump(void) {} -#endif +#endif /* DEBUG */ diff --git a/openpcd/firmware/src/rc632.h b/openpcd/firmware/src/rc632.h index 824cca9..77f7c20 100644 --- a/openpcd/firmware/src/rc632.h +++ b/openpcd/firmware/src/rc632.h @@ -8,6 +8,8 @@ extern void rc632_write_reg(u_int8_t addr, u_int8_t data); extern void rc632_write_fifo(u_int8_t len, u_int8_t *data); extern u_int8_t rc632_read_reg(u_int8_t addr); extern u_int8_t rc632_read_fifo(u_int8_t max_len, u_int8_t *data); +extern u_int8_t rc632_clear_bits(u_int8_t reg, u_int8_t bits); +extern u_int8_t rc632_set_bits(u_int8_t reg, u_int8_t bits); extern void rc632_init(void); extern void rc632_exit(void); |