Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "supervisor.h"
- #include "obc_sci_io.h"
- #include "obc_i2c_io.h"
- #include <FreeRTOS.h>
- #include <os_task.h>
- #include <sys_common.h>
- #include "system.h"
- #include <stdio.h>
- #include <gio.h>
- #include <sci.h>
- #include <i2c.h>
- #include "spi.h"
- #define SPI_REG spiREG3
- #define TEST_REG 0x00
- #define VERSION_REG 0x40 // RM46: 96, Arduino: 128
- spiDAT1_t spi_config = {
- .CS_HOLD = FALSE,
- .WDEL = TRUE,
- .DFSEL = SPI_FMT_1,
- .CSNR = SPI_CS_1
- };
- void write_reg(uint16_t addr, uint16_t data) {
- spiPORT3->DCLR = (1 << 1);
- addr = addr | 0x80;
- spiTransmitData(SPI_REG, &spi_config, 1, &addr);
- spiTransmitData(SPI_REG, &spi_config, 1, &data);
- spiPORT3->DSET = (1 << 1);
- }
- void read_reg(uint16_t addr, uint8_t *rx_data) {
- spiPORT3->DCLR = (1 << 1);
- addr = addr & 0x7F;
- spiTransmitData(SPI_REG, &spi_config, 1, &addr);
- spiReceiveData(SPI_REG, &spi_config, 1, (uint16_t *)rx_data);
- spiPORT3->DSET = (1 << 1);
- }
- int main(void) {
- // Run hardware initialization code (TODO: refactor all this into one function call)
- gioInit();
- sciInit();
- i2cInit();
- // Initialize bus mutexes
- initSciMutex();
- initI2CMutex();
- spiInit();
- uint16_t tx_data = 0;
- uint8_t rx_data = 7;
- //Reset the CPLD
- write_reg(0x07, 0x80);
- // Simple delay.
- for (int i = 0; i < 10000000; i++) {
- // Do nothing.
- }
- write_reg(0x07, 0x00);
- // Simple delay.
- for (int i = 0; i < 10000000; i++) {
- // Do nothing.
- }
- while(1) {
- // Toggle the LED.
- gioToggleBit(gioPORTB, 1);
- write_reg(TEST_REG, tx_data);
- read_reg(0x41, &rx_data);
- char buffer[50];
- uint8_t len = sprintf(buffer, "\r\nrx_data: %d", rx_data);
- printTextSci(scilinREG, (unsigned char *)buffer, len);
- if(++tx_data >= 6) {
- tx_data = 0;
- }
- // Simple delay.
- for (int i = 0; i < 10000000; i++) {
- // Do nothing.
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement