Skip to content

Commit

Permalink
- final changes for 5.0.4
Browse files Browse the repository at this point in the history
  • Loading branch information
RudolphRiedel committed Apr 23, 2022
1 parent dfc9087 commit 70d0722
Show file tree
Hide file tree
Showing 23 changed files with 773 additions and 172 deletions.
25 changes: 19 additions & 6 deletions EVE_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
@file EVE_commands.c
@brief contains FT8xx / BT8xx functions
@version 5.0
@date 2021-12-27
@date 2022-04-23
@author Rudolph Riedel
@section info
Expand All @@ -15,7 +15,7 @@ The c-standard is C99.
MIT License
Copyright (c) 2016-2021 Rudolph Riedel
Copyright (c) 2016-2022 Rudolph Riedel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
Expand Down Expand Up @@ -159,6 +159,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
- finally removed EVE_cmd_start() after setting it to deprecatd with the first 5.0 release
- renamed EVE_cmd_execute() to EVE_execute_cmd() to be more consistent, this is is not an EVE command
- changed EVE_init_flash() to return E_OK in case of success and more meaningfull values in case of failure
- added the return-value of EVE_FIFO_HALF_EMPTY to EVE_busy() to indicate there is more than 2048 bytes available
*/

Expand Down Expand Up @@ -305,8 +306,9 @@ void EVE_memWrite_sram_buffer(uint32_t ftAddress, const uint8_t *data, uint32_t
/**
* @brief Check if the co-processor completed executing the current command list.
*
* @return returns E_OK in case EVE is not busy (REG_CMDB_SPACE has the value 0xffc),
* returns EVE_IS_BUSY if a DMA transfer is active or REG_CMDB_SPACE has a value smaller than 0xffc
* @return returns E_OK in case EVE is not busy (no DMA transfer active and REG_CMDB_SPACE has the value 0xffc, meaning the CMD-FIFO is empty),
* returns EVE_FIFO_HALF_EMPTY if no DMA transfer is active and REG_CMDB_SPACE shows more than 2048 bytes available,
* returns EVE_IS_BUSY if a DMA transfer is active or REG_CMDB_SPACE has a value smaller than 0xffc,
*/
uint8_t EVE_busy(void)
{
Expand Down Expand Up @@ -357,8 +359,19 @@ uint8_t EVE_busy(void)

#endif
}

return (space != 0xffc) ? EVE_IS_BUSY : E_OK;

if(space == 0xffc)
{
return E_OK;
}
else if(space > 0x800)
{
return EVE_FIFO_HALF_EMPTY;
}
else
{
return EVE_IS_BUSY;
}
}


Expand Down
8 changes: 5 additions & 3 deletions EVE_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
@file EVE_commands.h
@brief contains FT8xx / BT8xx function prototypes
@version 5.0
@date 2021-12-27
@date 2022-04-23
@author Rudolph Riedel
@section LICENSE
MIT License
Copyright (c) 2016-2021 Rudolph Riedel
Copyright (c) 2016-2022 Rudolph Riedel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
Expand Down Expand Up @@ -81,6 +81,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
- added an enum with return codes to have the functions return something more meaningfull
- finally removed EVE_cmd_start() after setting it to deprecatd with the first 5.0 release
- renamed EVE_cmd_execute() to EVE_execute_cmd() to be more consistent, this is is not an EVE command
- added the return-value of EVE_FIFO_HALF_EMPTY to EVE_busy() to indicate there is more than 2048 bytes available
*/

Expand All @@ -106,7 +107,8 @@ enum
EVE_FAIL_FLASHFAST_SECTOR0_FAILED,
EVE_FAIL_FLASHFAST_BLOB_MISMATCH,
EVE_FAIL_FLASHFAST_SPEED_TEST,
EVE_IS_BUSY
EVE_IS_BUSY,
EVE_FIFO_HALF_EMPTY
};


Expand Down
9 changes: 5 additions & 4 deletions EVE_target.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
@file EVE_target.c
@brief target specific functions for plain C targets
@version 5.0
@date 2021-12-04
@date 2022-04-23
@author Rudolph Riedel
@section LICENSE
MIT License
Copyright (c) 2016-2021 Rudolph Riedel
Copyright (c) 2016-2022 Rudolph Riedel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
Expand Down Expand Up @@ -49,6 +49,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
- split up this file in EVE_target.c for the plain C targets and EVE_target.cpp for the Arduino C++ targets
- converted all TABs to SPACEs
- split the ATSAMC21 and ATSAMx51 targets into separate sections
- added more defines for ATSAMC21 and ATSAMx51 - chip crises...
*/

Expand All @@ -62,7 +63,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

#if defined (__SAMC21E18A__) || (__SAMC21J18A__)
#if defined (__SAMC21E18A__) || (__SAMC21J18A__) || (__SAMC21J17A__) || (__SAMC21J16A__)
/* note: target as set by AtmelStudio, valid are all from the same family */

void DELAY_MS(uint16_t val)
Expand Down Expand Up @@ -136,7 +137,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

#if defined (__SAME51J19A__) || (__SAMD51P20A__) || (__SAMD51J19A__) || (__SAMD51G18A__)
#if defined (__SAME51J19A__) || (__SAME51J18A__) || (__SAMD51P20A__) || (__SAMD51J19A__) || (__SAMD51G18A__)
/* note: target as set by AtmelStudio, valid are all from the same family */

void DELAY_MS(uint16_t val)
Expand Down
136 changes: 113 additions & 23 deletions EVE_target.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
@file EVE_target.h
@brief target specific includes, definitions and functions
@version 5.0
@date 2021-12-27
@date 2022-04-23
@author Rudolph Riedel
@section LICENSE
MIT License
Copyright (c) 2016-2021 Rudolph Riedel
Copyright (c) 2016-2022 Rudolph Riedel
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"),
to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute,
Expand Down Expand Up @@ -85,6 +85,8 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
- made the pin defines for all targets that have one optional
- split the ATSAMC21 and ATSAMx51 targets into separate sections
- updated the explanation of how DMA works
- added a TMS320F28335 target
- added more defines for ATSAMC21 and ATSAMx51 - chip crises...
*/

Expand Down Expand Up @@ -132,7 +134,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

while(val > 0)
{
for(counter=0; counter < 2000;counter++) // maybe ~1ms at 16MHz clock
for(counter=0; counter < 2000;counter++) /* maybe ~1ms at 16MHz clock */
{
__asm__ volatile ("nop");
}
Expand Down Expand Up @@ -250,7 +252,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
static inline void spi_transmit(uint8_t data)
{
EVE_SPI.DATA = data;
while(!(EVE_SPI.STATUS & 0x80)) {}; // wait for transmit complete
while(!(EVE_SPI.STATUS & 0x80)) {}; /* wait for transmit complete */
}

static inline void spi_transmit_32(uint32_t data)
Expand All @@ -270,7 +272,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
static inline uint8_t spi_receive(uint8_t data)
{
EVE_SPI.DATA = data;
while(!(EVE_SPI.STATUS & 0x80)) {}; // wait for transmit complete
while(!(EVE_SPI.STATUS & 0x80)) {}; /* wait for transmit complete */
return EVE_SPI.DATA;
}

Expand Down Expand Up @@ -330,13 +332,13 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
SPDR = data; /* start transmission */
while(!(SPSR & (1<<SPIF))) {}; /* wait for transmission to complete - 1us @ 8MHz SPI-Clock */
#else
/* software-spi example */
/* software-spi example */
uint8_t spiIndex = 0x80;
uint8_t k;

for(k = 0; k <8; k++) // Output each bit of spiOutByte
for(k = 0; k <8; k++) /* Output each bit of spiOutByte */
{
if(data & spiIndex) // Output MOSI Bit
if(data & spiIndex) /* Output MOSI Bit */
{
PORTC |= (1<<PORTC1);
}
Expand All @@ -345,7 +347,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
PORTC &= ~(1<<PORTC1);
}

PORTA |= (1<<PORTA1); // toggle SCK
PORTA |= (1<<PORTA1); /* toggle SCK */
PORTA &= ~(1<<PORTA1);

spiIndex >>= 1;
Expand Down Expand Up @@ -378,9 +380,9 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
uint8_t spiInByte = 0;
uint8_t k;

for(k = 0; k <8; k++) // Output each bit of spiOutByte
for(k = 0; k <8; k++) /* Output each bit of spiOutByte */
{
if(data & spiIndex) // Output MOSI Bit
if(data & spiIndex) /* Output MOSI Bit */
{
PORTC |= (1<<PORTC1);
}
Expand All @@ -389,7 +391,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
PORTC &= ~(1<<PORTC1);
}

PORTA |= (1<<PORTA1); // toggle SCK
PORTA |= (1<<PORTA1); /* toggle SCK */
PORTA &= ~(1<<PORTA1);

if(PINC & (1<<PORTC0))
Expand Down Expand Up @@ -547,7 +549,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

#if defined (__SAMC21E18A__) || (__SAMC21J18A__)
#if defined (__SAMC21E18A__) || (__SAMC21J18A__) || (__SAMC21J17A__) || (__SAMC21J16A__)
/* note: target as set by AtmelStudio, valid are all from the same family */

#include "sam.h"
Expand Down Expand Up @@ -638,11 +640,10 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

#if defined (__SAME51J19A__) || (__SAMD51P20A__) || (__SAMD51J19A__) || (__SAMD51G18A__)
#if defined (__SAME51J19A__) || (__SAME51J18A__) || (__SAMD51P20A__) || (__SAMD51J19A__) || (__SAMD51G18A__)
/* note: target as set by AtmelStudio, valid are all from the same family */

#include "sam.h"
#include <stdbool.h>

#if !defined (EVE_CS)
#define EVE_CS_PORT 0
Expand Down Expand Up @@ -1088,12 +1089,12 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

static inline void EVE_cs_set(void)
{
gpio_put(EVE_CS, 0); // active low
gpio_put(EVE_CS, 0);
}

static inline void EVE_cs_clear(void)
{
gpio_put(EVE_CS, 1); // active high
gpio_put(EVE_CS, 1);
}

static inline void EVE_pdn_set(void)
Expand Down Expand Up @@ -1405,13 +1406,13 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

#if !defined (EVE_CS)
#define RIVERDI_PORT GPIO_PORT_P1
#define RIVERDI_SIMO BIT6 // P1.6
#define RIVERDI_SOMI BIT7 // P1.7
#define RIVERDI_CLK BIT5 // P1.5
#define RIVERDI_SIMO BIT6 /* P1.6 */
#define RIVERDI_SOMI BIT7 /* P1.7 */
#define RIVERDI_CLK BIT5 /* P1.5 */
#define EVE_CS_PORT GPIO_PORT_P5
#define EVE_CS GPIO_PIN0 //P5.0
#define EVE_CS GPIO_PIN0 /* P5.0 */
#define EVE_PDN_PORT GPIO_PORT_P5
#define EVE_PDN GPIO_PIN1 //P5.1
#define EVE_PDN GPIO_PIN1 /* P5.1 */
#endif

void EVE_SPI_Init(void);
Expand All @@ -1422,7 +1423,7 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH

while(val > 0)
{
for(counter=0; counter < 8000;counter++) // ~1ms at 48MHz Core-Clock
for(counter=0; counter < 8000;counter++) /* ~1ms at 48MHz Core-Clock */
{
__nop();
}
Expand Down Expand Up @@ -1502,6 +1503,95 @@ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR TH
#endif /* __TI_ARM */
#endif

/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

/* this is for TIs C2000 compiled with their ti-cgt-c2000 compiler which does not define this many symbols */
#if defined (__TMS320C28XX__)

/* the designated target actually is a TMS320F28335 */
/* credit for this goes to David Sakal-Sega */
/* note: the SPI unit of the TMS320F28335 does not support DMA, using one of the UARTs in SPI mode would allow DMA */

#include <stdint.h>
#include <DSP2833x_Device.h>

typedef uint_least8_t uint8_t; /* this architecture does not actually know what a byte is, uint_least8_t is 16 bits wide */

/* 150MHz -> 6.67ns per cycle, 5 cycles for the loop itself and 8 NOPs -> 1ms / (6.67ns * 13) = 11532 */
#define EVE_DELAY_1MS 12000

static inline void DELAY_MS(uint16_t val)
{
uint16_t counter;

while(val > 0)
{
for(counter=0; counter < EVE_DELAY_1MS;counter++)
{
asm(" RPT #7 || NOP");
}
val--;
}
}

static inline void EVE_pdn_set(void)
{
GpioDataRegs.GPACLEAR.bit.GPIO14 = 1; /* Power-Down low */
}

static inline void EVE_pdn_clear(void)
{
GpioDataRegs.GPASET.bit.GPIO14 = 1; /* Power-Down high */
}

static inline void EVE_cs_set(void)
{
GpioDataRegs.GPACLEAR.bit.GPIO19 = 1; /* CS low */
}

static inline void EVE_cs_clear(void)
{
asm(" RPT #60 || NOP"); /* wait 60 cycles to make sure CS is not going high too early */
GpioDataRegs.GPASET.bit.GPIO19 = 1; /* CS high */
}

static inline void spi_transmit(uint8_t data)
{
SpiaRegs.SPITXBUF = (data & 0xFF) << 8; /* start transfer, looks odd with data = uint8_t but uint8_t actually is 16 bits wide on this controller */
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0); /* wait for transmission to complete */
(void) SpiaRegs.SPIRXBUF; /* dummy read to clear the flags */
}

static inline void spi_transmit_32(uint32_t data)
{
spi_transmit((uint8_t)(data & 0x000000ff));
spi_transmit((uint8_t)(data >> 8));
spi_transmit((uint8_t)(data >> 16));
spi_transmit((uint8_t)(data >> 24));
}

/* spi_transmit_burst() is only used for cmd-FIFO commands so it *always* has to transfer 4 bytes */
static inline void spi_transmit_burst(uint32_t data)
{
spi_transmit_32(data);
}

static inline uint8_t spi_receive(uint8_t data)
{
SpiaRegs.SPITXBUF = (data & 0xFF) << 8; /* start transfer */
while(SpiaRegs.SPISTS.bit.INT_FLAG == 0); /* wait for transmission to complete */
return (SpiaRegs.SPIRXBUF & 0x00FF); /* data is right justified in SPIRXBUF */
}

static inline uint8_t fetch_flash_byte(const uint8_t *data)
{
return *data;
}

#endif


/*----------------------------------------------------------------------------------------------------------------*/
/*----------------------------------------------------------------------------------------------------------------*/

Expand Down
Loading

0 comments on commit 70d0722

Please sign in to comment.