Subversion Repositories Code-Repo

Compare Revisions

Ignore whitespace Rev 230 → Rev 231

/PIC Stuff/Cerebot_32MX7_LED_Cube/SPI4.c
1,5 → 1,3
#include <xc.h>
#include <plib.h>
#include "defines.h"
#include "SPI4.h"
 
20,7 → 18,7
// FSCK = FPB / (2 * (SPIxBRG + 1))
IEC1CLR = 0x00000700; // Disable all SPI interrupts
SPI4CON = 0; // Stops and resets the SPI4.
int tmp = SPI4BUF; // Clears the receive buffer
uint32_t tmp = SPI4BUF; // Clears the receive buffer
IFS1CLR = 0x00000700; // Clear any existing event
IPC8CLR = 0x0000001F; // Clear the priority
IPC8SET = 0x0000001A; // Set IPL=6, Subpriority 2
35,7 → 33,7
INTEnableInterrupts();
}
 
int SPI4_Read(int length, void (*rx_callback)(char, char *)) {
uint8_t SPI4_Read(uint32_t length, void (*rx_callback)(uint8_t, uint8_t *)) {
spi_data_ptr->rx_callback = rx_callback;
 
// Ensure that the receiving buffer is large enough
54,7 → 52,7
return 1;
}
 
int SPI4_Write(char *array, int length, void (*tx_callback)(void)) {
uint8_t SPI4_Write(uint8_t *array, uint32_t length, void (*tx_callback)(void)) {
spi_data_ptr->tx_callback = tx_callback;
 
// We only care about the transmit length if we are sending data
71,7 → 69,7
 
// Copy only if we are actually going to transmit data
if (!spi_data_ptr->write_blank) {
int i;
int32_t i;
for (i = 0; i < length; i++) {
spi_data_ptr->buffer_out[i] = array[i];
}
92,11 → 90,11
 
// Process SPI4 receive flag
if (IFS1bits.SPI4RXIF) {
int i;
uint32_t i;
// Read the data received from the last transfer
int rxBufferCount = SPI4STATbits.RXBUFELM;
uint32_t rxBufferCount = SPI4STATbits.RXBUFELM;
for (i = 0; i < rxBufferCount; i++) {
char c = SPI4BUF;
int8_t c = SPI4BUF;
// Put the received data into the buffer
if (spi_data_ptr->buffer_in_len != 0) {
spi_data_ptr->buffer_in[spi_data_ptr->buffer_in_ind] = c;
115,7 → 113,7
 
// Process SPI4 transmit flag
if (IFS1bits.SPI4TXIF && IEC1bits.SPI4TXIE) {
int i;
int32_t i;
// Disable the transmit interrupt if all data has been sent
if (spi_data_ptr->buffer_out_len == 0) {
IEC1CLR=0x00000400;
125,7 → 123,7
(*spi_data_ptr->tx_callback)();
} else {
// Start transmitting the data in the buffer
int txBufferFree = 16 - SPI4STATbits.TXBUFELM;
int32_t txBufferFree = 16 - SPI4STATbits.TXBUFELM;
if (spi_data_ptr->buffer_out_len > txBufferFree) {
for (i = 0; i < txBufferFree; i++) {
if (spi_data_ptr->write_blank) {