mirror of
https://github.com/Ralim/IronOS.git
synced 2025-02-26 07:53:55 +00:00
Further work on Pinecil compile
This commit is contained in:
@@ -18,6 +18,6 @@ RUN wget -qO- https://github.com/riscv-mcu/riscv-gnu-toolchain/releases/download
|
|||||||
|
|
||||||
# Add compiler to the path
|
# Add compiler to the path
|
||||||
ENV PATH "/build/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH"
|
ENV PATH "/build/gcc-arm-none-eabi-9-2020-q2-update/bin:$PATH"
|
||||||
ENV PATH "/build/rv_linux_bare_1908291308/bin:$PATH"
|
ENV PATH "/build/rv_linux_bare_1908312208/bin/:$PATH"
|
||||||
COPY . /build/source
|
COPY . /build/source
|
||||||
COPY ./ci /build/ci
|
COPY ./ci /build/ci
|
||||||
|
|||||||
@@ -12,7 +12,8 @@ SemaphoreHandle_t FRToSI2C::I2CSemaphore;
|
|||||||
StaticSemaphore_t FRToSI2C::xSemaphoreBuffer;
|
StaticSemaphore_t FRToSI2C::xSemaphoreBuffer;
|
||||||
#define FLAG_TIMEOUT 1000
|
#define FLAG_TIMEOUT 1000
|
||||||
|
|
||||||
void FRToSI2C::CpltCallback() {
|
void FRToSI2C::CpltCallback()
|
||||||
|
{
|
||||||
//TODO
|
//TODO
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,27 +21,30 @@ void FRToSI2C::CpltCallback() {
|
|||||||
*
|
*
|
||||||
* @param obj The I2C object
|
* @param obj The I2C object
|
||||||
*/
|
*/
|
||||||
int i2c_start() {
|
int i2c_start()
|
||||||
|
{
|
||||||
int timeout;
|
int timeout;
|
||||||
|
|
||||||
/* clear I2C_FLAG_AERR Flag */
|
/* clear I2C_FLAG_AERR Flag */
|
||||||
i2c_flag_clear(I2C0, I2C_FLAG_AERR);
|
i2c_flag_clear(I2C0, I2C_FLAG_AERR);
|
||||||
|
|
||||||
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
|
|
||||||
return (int)-1;
|
return (int)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ensure the i2c has been stopped */
|
/* ensure the i2c has been stopped */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP) == I2C_CTL0_STOP)
|
||||||
while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP) == I2C_CTL0_STOP) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
return (int)-1;
|
return (int)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,10 +53,11 @@ int i2c_start() {
|
|||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
|
|
||||||
/* ensure the i2c has been started successfully */
|
/* ensure the i2c has been started successfully */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
return (int)-1;
|
return (int)-1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -64,15 +69,18 @@ int i2c_start() {
|
|||||||
*
|
*
|
||||||
* @param obj The I2C object
|
* @param obj The I2C object
|
||||||
*/
|
*/
|
||||||
int i2c_stop() {
|
int i2c_stop()
|
||||||
|
{
|
||||||
|
|
||||||
/* generate a STOP condition */
|
/* generate a STOP condition */
|
||||||
i2c_stop_on_bus(I2C0);
|
i2c_stop_on_bus(I2C0);
|
||||||
|
|
||||||
/* wait for STOP bit reset */
|
/* wait for STOP bit reset */
|
||||||
int timeout = FLAG_TIMEOUT;
|
int timeout = FLAG_TIMEOUT;
|
||||||
while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP)) {
|
while ((I2C_CTL0(I2C0) & I2C_CTL0_STOP))
|
||||||
if ((timeout--) == 0) {
|
{
|
||||||
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,21 +94,27 @@ int i2c_stop() {
|
|||||||
* @param last Acknoledge
|
* @param last Acknoledge
|
||||||
* @return The read byte
|
* @return The read byte
|
||||||
*/
|
*/
|
||||||
int i2c_byte_read(int last) {
|
int i2c_byte_read(int last)
|
||||||
|
{
|
||||||
int timeout;
|
int timeout;
|
||||||
|
|
||||||
if (last) {
|
if (last)
|
||||||
|
{
|
||||||
/* disable acknowledge */
|
/* disable acknowledge */
|
||||||
i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
i2c_ack_config(I2C0, I2C_ACK_DISABLE);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
/* enable acknowledge */
|
/* enable acknowledge */
|
||||||
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
i2c_ack_config(I2C0, I2C_ACK_ENABLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* wait until the byte is received */
|
/* wait until the byte is received */
|
||||||
timeout = FLAG_TIMEOUT;
|
timeout = FLAG_TIMEOUT;
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_RBNE)) == RESET) {
|
while ((i2c_flag_get(I2C0, I2C_FLAG_RBNE)) == RESET)
|
||||||
if ((timeout--) == 0) {
|
{
|
||||||
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,15 +128,17 @@ int i2c_byte_read(int last) {
|
|||||||
* @param data Byte to be written
|
* @param data Byte to be written
|
||||||
* @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
|
* @return 0 if NAK was received, 1 if ACK was received, 2 for timeout.
|
||||||
*/
|
*/
|
||||||
int i2c_byte_write(int data) {
|
int i2c_byte_write(int data)
|
||||||
|
{
|
||||||
int timeout;
|
int timeout;
|
||||||
i2c_data_transmit(I2C0, data);
|
i2c_data_transmit(I2C0, data);
|
||||||
|
|
||||||
/* wait until the byte is transmitted */
|
/* wait until the byte is transmitted */
|
||||||
timeout = FLAG_TIMEOUT;
|
timeout = FLAG_TIMEOUT;
|
||||||
while (((i2c_flag_get(I2C0, I2C_FLAG_TBE)) == RESET)
|
while (((i2c_flag_get(I2C0, I2C_FLAG_TBE)) == RESET) || ((i2c_flag_get(I2C0, I2C_FLAG_BTC)) == RESET))
|
||||||
|| ((i2c_flag_get(I2C0, I2C_FLAG_BTC)) == RESET)) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +147,8 @@ int i2c_byte_write(int data) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
||||||
uint8_t *pData, uint16_t Size) {
|
uint8_t *pData, uint16_t Size)
|
||||||
|
{
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
@@ -140,13 +157,18 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
|
|
||||||
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
||||||
timeout = FLAG_TIMEOUT;
|
timeout = FLAG_TIMEOUT;
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) {
|
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET)
|
||||||
if ((timeout--) == 0) {
|
{
|
||||||
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
} else {
|
}
|
||||||
if (timeout % 5 == 0) {
|
else
|
||||||
|
{
|
||||||
|
if (timeout % 5 == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -155,10 +177,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
|
|
||||||
/* ensure the i2c has been started successfully */
|
/* ensure the i2c has been started successfully */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -170,9 +193,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
/* wait until I2C_FLAG_ADDSEND flag is set */
|
/* wait until I2C_FLAG_ADDSEND flag is set */
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND))
|
||||||
|
{
|
||||||
timeout++;
|
timeout++;
|
||||||
if (timeout > 100000) {
|
if (timeout > 100000)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -180,7 +205,8 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
}
|
}
|
||||||
bool no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR);
|
bool no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR);
|
||||||
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR);
|
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR);
|
||||||
if (no_ack) {
|
if (no_ack)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -190,7 +216,8 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
int status = i2c_byte_write(MemAddress);
|
int status = i2c_byte_write(MemAddress);
|
||||||
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR);
|
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_BERR);
|
||||||
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_LOSTARB);
|
no_ack |= i2c_flag_get(I2C0, I2C_FLAG_LOSTARB);
|
||||||
if (status == 2 || no_ack) {
|
if (status == 2 || no_ack)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -201,10 +228,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
|
|
||||||
/* ensure the i2c has been started successfully */
|
/* ensure the i2c has been started successfully */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -216,9 +244,11 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
/* wait until I2C_FLAG_ADDSEND flag is set */
|
/* wait until I2C_FLAG_ADDSEND flag is set */
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND))
|
||||||
|
{
|
||||||
timeout++;
|
timeout++;
|
||||||
if (timeout > 100000) {
|
if (timeout > 100000)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -228,13 +258,15 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
/* clear ADDSEND */
|
/* clear ADDSEND */
|
||||||
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
||||||
no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR);
|
no_ack = i2c_flag_get(I2C0, I2C_FLAG_AERR);
|
||||||
if (no_ack) {
|
if (no_ack)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for (count = 0; count < Size; count++) {
|
for (count = 0; count < Size; count++)
|
||||||
pData[count] = i2c_byte_read(count == (Size - 1));
|
{
|
||||||
|
pData[count] = i2c_byte_read(count == (uint32_t)(Size - 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if not sequential write, then send stop */
|
/* if not sequential write, then send stop */
|
||||||
@@ -243,17 +275,20 @@ bool FRToSI2C::Mem_Read(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
unlock();
|
unlock();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data) {
|
void FRToSI2C::I2C_RegisterWrite(uint8_t address, uint8_t reg, uint8_t data)
|
||||||
|
{
|
||||||
Mem_Write(address, reg, &data, 1);
|
Mem_Write(address, reg, &data, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg) {
|
uint8_t FRToSI2C::I2C_RegisterRead(uint8_t add, uint8_t reg)
|
||||||
|
{
|
||||||
uint8_t temp = 0;
|
uint8_t temp = 0;
|
||||||
Mem_Read(add, reg, &temp, 1);
|
Mem_Read(add, reg, &temp, 1);
|
||||||
return temp;
|
return temp;
|
||||||
}
|
}
|
||||||
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
||||||
uint8_t *pData, uint16_t Size) {
|
uint8_t *pData, uint16_t Size)
|
||||||
|
{
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -261,15 +296,19 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
int timeout = 0;
|
int timeout = 0;
|
||||||
|
|
||||||
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
if (timeout % 5 == 0) {
|
else
|
||||||
|
{
|
||||||
|
if (timeout % 5 == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -278,10 +317,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
|
|
||||||
/* ensure the i2c has been started successfully */
|
/* ensure the i2c has been started successfully */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -293,9 +333,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
/* wait until I2C_FLAG_ADDSEND flag is set */
|
/* wait until I2C_FLAG_ADDSEND flag is set */
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND))
|
||||||
|
{
|
||||||
timeout++;
|
timeout++;
|
||||||
if (timeout > 100000) {
|
if (timeout > 100000)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -305,9 +347,11 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
/* clear ADDSEND */
|
/* clear ADDSEND */
|
||||||
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
||||||
int status = i2c_byte_write(MemAddress);
|
int status = i2c_byte_write(MemAddress);
|
||||||
for (count = 0; count < Size; count++) {
|
for (count = 0; count < Size; count++)
|
||||||
|
{
|
||||||
status = i2c_byte_write(pData[count]);
|
status = i2c_byte_write(pData[count]);
|
||||||
if (status != 1) {
|
if (status != 1)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -320,7 +364,8 @@ void FRToSI2C::Mem_Write(uint16_t DevAddress, uint16_t MemAddress,
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size)
|
||||||
|
{
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return;
|
return;
|
||||||
uint32_t count = 0;
|
uint32_t count = 0;
|
||||||
@@ -328,13 +373,18 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
|
|
||||||
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
/* wait until I2C_FLAG_I2CBSY flag is reset */
|
||||||
timeout = FLAG_TIMEOUT;
|
timeout = FLAG_TIMEOUT;
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET) {
|
while ((i2c_flag_get(I2C0, I2C_FLAG_I2CBSY)) == SET)
|
||||||
if ((timeout--) == 0) {
|
{
|
||||||
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
} else {
|
}
|
||||||
if (timeout % 5 == 0) {
|
else
|
||||||
|
{
|
||||||
|
if (timeout % 5 == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,10 +393,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
i2c_start_on_bus(I2C0);
|
i2c_start_on_bus(I2C0);
|
||||||
|
|
||||||
/* ensure the i2c has been started successfully */
|
/* ensure the i2c has been started successfully */
|
||||||
timeout = FLAG_TIMEOUT
|
timeout = FLAG_TIMEOUT;
|
||||||
;
|
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET)
|
||||||
while ((i2c_flag_get(I2C0, I2C_FLAG_SBSEND)) == RESET) {
|
{
|
||||||
if ((timeout--) == 0) {
|
if ((timeout--) == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -358,9 +409,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
|
|
||||||
timeout = 0;
|
timeout = 0;
|
||||||
/* wait until I2C_FLAG_ADDSEND flag is set */
|
/* wait until I2C_FLAG_ADDSEND flag is set */
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND))
|
||||||
|
{
|
||||||
timeout++;
|
timeout++;
|
||||||
if (timeout > 100000) {
|
if (timeout > 100000)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -370,9 +423,11 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
/* clear ADDSEND */
|
/* clear ADDSEND */
|
||||||
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
i2c_flag_clear(I2C0, I2C_FLAG_ADDSEND);
|
||||||
|
|
||||||
for (count = 0; count < Size; count++) {
|
for (count = 0; count < Size; count++)
|
||||||
|
{
|
||||||
int status = i2c_byte_write(pData[count]);
|
int status = i2c_byte_write(pData[count]);
|
||||||
if (status != 1) {
|
if (status != 1)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return;
|
return;
|
||||||
@@ -385,7 +440,8 @@ void FRToSI2C::Transmit(uint16_t DevAddress, uint8_t *pData, uint16_t Size) {
|
|||||||
unlock();
|
unlock();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::probe(uint16_t DevAddress) {
|
bool FRToSI2C::probe(uint16_t DevAddress)
|
||||||
|
{
|
||||||
if (!lock())
|
if (!lock())
|
||||||
return false;
|
return false;
|
||||||
i2c_start();
|
i2c_start();
|
||||||
@@ -393,14 +449,16 @@ bool FRToSI2C::probe(uint16_t DevAddress) {
|
|||||||
i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER);
|
i2c_master_addressing(I2C0, DevAddress, I2C_TRANSMITTER);
|
||||||
/* wait until ADDSEND bit is set */
|
/* wait until ADDSEND bit is set */
|
||||||
int timeout = FLAG_TIMEOUT;
|
int timeout = FLAG_TIMEOUT;
|
||||||
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND)) {
|
while (!i2c_flag_get(I2C0, I2C_FLAG_ADDSEND))
|
||||||
if (i2c_flag_get(I2C0, I2C_FLAG_AERR)
|
{
|
||||||
|| i2c_flag_get(I2C0, I2C_FLAG_BERR)) {
|
if (i2c_flag_get(I2C0, I2C_FLAG_AERR) || i2c_flag_get(I2C0, I2C_FLAG_BERR))
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (timeout-- == 0) {
|
if (timeout-- == 0)
|
||||||
|
{
|
||||||
i2c_stop();
|
i2c_stop();
|
||||||
unlock();
|
unlock();
|
||||||
return false;
|
return false;
|
||||||
@@ -422,17 +480,20 @@ bool FRToSI2C::probe(uint16_t DevAddress) {
|
|||||||
return !no_ack;
|
return !no_ack;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRToSI2C::I2C_Unstick() {
|
void FRToSI2C::I2C_Unstick()
|
||||||
|
{
|
||||||
unstick_I2C();
|
unstick_I2C();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FRToSI2C::lock() {
|
bool FRToSI2C::lock()
|
||||||
|
{
|
||||||
if (I2CSemaphore == nullptr)
|
if (I2CSemaphore == nullptr)
|
||||||
return true;
|
return true;
|
||||||
return xSemaphoreTake(I2CSemaphore, 1000) == pdTRUE;
|
return xSemaphoreTake(I2CSemaphore, 1000) == pdTRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FRToSI2C::unlock() {
|
void FRToSI2C::unlock()
|
||||||
|
{
|
||||||
if (I2CSemaphore == nullptr)
|
if (I2CSemaphore == nullptr)
|
||||||
return;
|
return;
|
||||||
xSemaphoreGive(I2CSemaphore);
|
xSemaphoreGive(I2CSemaphore);
|
||||||
|
|||||||
27
workspace/TS100/Core/BSP/Pine64/Model_Config.h
Normal file
27
workspace/TS100/Core/BSP/Pine64/Model_Config.h
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* Model_Config.h
|
||||||
|
*
|
||||||
|
* Created on: 25 Jul 2020
|
||||||
|
* Author: Ralim
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef BSP_MINIWARE_MODEL_CONFIG_H_
|
||||||
|
#define BSP_MINIWARE_MODEL_CONFIG_H_
|
||||||
|
/*
|
||||||
|
* Lookup for mapping features <-> Models
|
||||||
|
*/
|
||||||
|
|
||||||
|
#if defined(MODEL_Pinecil) > 1
|
||||||
|
#error "Multiple models defined!"
|
||||||
|
#elif defined(MODEL_Pinecil) == 0
|
||||||
|
#error "No model defined!"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODEL_Pinecil
|
||||||
|
#define ACCEL_LIS
|
||||||
|
#define TEMP_TMP36
|
||||||
|
#define POW_QC
|
||||||
|
#define POW_PD
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* BSP_MINIWARE_MODEL_CONFIG_H_ */
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
#include "FreeRTOSConfig.h"
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "task.h"
|
#include "task.h"
|
||||||
#include "portmacro.h"
|
#include "portmacro.h"
|
||||||
@@ -6,13 +7,11 @@
|
|||||||
#include "riscv_encoding.h"
|
#include "riscv_encoding.h"
|
||||||
#include "n200_timer.h"
|
#include "n200_timer.h"
|
||||||
#include "n200_eclic.h"
|
#include "n200_eclic.h"
|
||||||
|
|
||||||
/* Standard Includes */
|
/* Standard Includes */
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
|
|
||||||
/* Each task maintains its own interrupt status in the critical nesting variable. */
|
/* Each task maintains its own interrupt status in the critical nesting variable. */
|
||||||
UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
||||||
|
|
||||||
@@ -30,13 +29,11 @@ UBaseType_t uxCriticalNesting = 0xaaaaaaaa;
|
|||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Used to catch tasks that attempt to return from their implementing function.
|
* Used to catch tasks that attempt to return from their implementing function.
|
||||||
*/
|
*/
|
||||||
static void prvTaskExitError(void);
|
static void prvTaskExitError(void);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief System Call Trap
|
* @brief System Call Trap
|
||||||
*
|
*
|
||||||
@@ -92,7 +89,6 @@ unsigned long ulSynchTrap(unsigned long mcause, unsigned long sp, unsigned long
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 设置触发软中断
|
* @brief 设置触发软中断
|
||||||
* @note 目的是在软中断内进行任务上下文切换
|
* @note 目的是在软中断内进行任务上下文切换
|
||||||
@@ -106,7 +102,6 @@ void vPortSetMSIPInt(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 清除软中断
|
* @brief 清除软中断
|
||||||
*
|
*
|
||||||
@@ -117,7 +112,6 @@ void vPortClearMSIPInt(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 执行任务上下文切换,在portasm.S中被调用
|
* @brief 执行任务上下文切换,在portasm.S中被调用
|
||||||
*
|
*
|
||||||
@@ -136,7 +130,6 @@ unsigned long taskswitch( unsigned long sp, unsigned long arg1)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 调研freertos内建函数vTaskSwitchContext,在portasm.S中被调用
|
* @brief 调研freertos内建函数vTaskSwitchContext,在portasm.S中被调用
|
||||||
*
|
*
|
||||||
@@ -149,7 +142,6 @@ void vDoTaskSwitchContext( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 进入临界段
|
* @brief 进入临界段
|
||||||
*
|
*
|
||||||
@@ -166,7 +158,6 @@ void vPortEnterCritical( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 退出临界段
|
* @brief 退出临界段
|
||||||
*
|
*
|
||||||
@@ -187,7 +178,6 @@ void vPortExitCritical( void )
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Clear current interrupt mask and set given mask
|
* @brief Clear current interrupt mask and set given mask
|
||||||
*
|
*
|
||||||
@@ -199,7 +189,6 @@ void vPortClearInterruptMask(int int_mask)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set interrupt mask and return current interrupt enable register
|
* @brief Set interrupt mask and return current interrupt enable register
|
||||||
*
|
*
|
||||||
@@ -215,7 +204,6 @@ int xPortSetInterruptMask(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化任务栈帧
|
* @brief 初始化任务栈帧
|
||||||
*
|
*
|
||||||
@@ -255,7 +243,6 @@ StackType_t *pxPortInitialiseStack( StackType_t *pxTopOfStack, TaskFunction_t px
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 任务退出函数
|
* @brief 任务退出函数
|
||||||
*
|
*
|
||||||
@@ -269,11 +256,11 @@ void prvTaskExitError( void )
|
|||||||
defined, then stop here so application writers can catch the error. */
|
defined, then stop here so application writers can catch the error. */
|
||||||
configASSERT(uxCriticalNesting == ~0UL);
|
configASSERT(uxCriticalNesting == ~0UL);
|
||||||
portDISABLE_INTERRUPTS();
|
portDISABLE_INTERRUPTS();
|
||||||
for( ;; );
|
for (;;)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief tick中断
|
* @brief tick中断
|
||||||
* @note 由于该中断配置为向量模式,则中断到来会调用portasm.S的MTIME_HANDLER,进行栈帧保存之后该函数会调用vPortSysTickHandler
|
* @note 由于该中断配置为向量模式,则中断到来会调用portasm.S的MTIME_HANDLER,进行栈帧保存之后该函数会调用vPortSysTickHandler
|
||||||
@@ -313,7 +300,6 @@ void vPortSysTickHandler(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化tick
|
* @brief 初始化tick
|
||||||
*
|
*
|
||||||
@@ -335,7 +321,6 @@ void vPortSetupTimer(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 初始化软中断
|
* @brief 初始化软中断
|
||||||
*
|
*
|
||||||
@@ -347,7 +332,6 @@ void vPortSetupMSIP(void)
|
|||||||
}
|
}
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 调度启动前的初始化准备
|
* @brief 调度启动前的初始化准备
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
#ifndef PORTMACRO_H
|
#ifndef PINE_PORTMACRO_H
|
||||||
#define PORTMACRO_H
|
#define PINE_PORTMACRO_H
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#include "riscv_encoding.h"
|
#include "riscv_encoding.h"
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------
|
/*-----------------------------------------------------------
|
||||||
* Port specific definitions.
|
* Port specific definitions.
|
||||||
*
|
*
|
||||||
@@ -54,7 +53,6 @@ extern void vPortYield_from_ulSynchTrap(unsigned long,unsigned long);
|
|||||||
extern int xPortSetInterruptMask(void);
|
extern int xPortSetInterruptMask(void);
|
||||||
extern void vPortClearInterruptMask(int uxSavedStatusValue);
|
extern void vPortClearInterruptMask(int uxSavedStatusValue);
|
||||||
|
|
||||||
|
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
/*System Calls */
|
/*System Calls */
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
@@ -68,7 +66,6 @@ extern void vPortClearInterruptMask( int uxSavedStatusValue );
|
|||||||
a2; \
|
a2; \
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
extern void vPortSetMSIPInt(void);
|
extern void vPortSetMSIPInt(void);
|
||||||
#define port_MSIPSET_BIT vPortSetMSIPInt()
|
#define port_MSIPSET_BIT vPortSetMSIPInt()
|
||||||
|
|
||||||
@@ -78,17 +75,29 @@ extern void vPortSetMSIPInt(void);
|
|||||||
#define PORT_YIELD_TO_RA 50
|
#define PORT_YIELD_TO_RA 50
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
/* Scheduler utilities. */
|
/* Scheduler utilities. */
|
||||||
/* the return after the ECALL is VERY important */
|
/* the return after the ECALL is VERY important */
|
||||||
|
|
||||||
//#define portYIELD() ECALL(PORT_YIELD);
|
//#define portYIELD() ECALL(PORT_YIELD);
|
||||||
#define portYIELD() port_MSIPSET_BIT;
|
#define portYIELD() port_MSIPSET_BIT;
|
||||||
|
|
||||||
#if CONFIG_SYSTEMVIEW_EN
|
#ifdef CONFIG_SYSTEMVIEW_EN
|
||||||
#define portEND_SWITCHING_ISR(xSwitchRequired) { if( xSwitchRequired != pdFALSE) { traceISR_EXIT_TO_SCHEDULER(); portYIELD(); } else {traceISR_EXIT(); } }
|
#define portEND_SWITCHING_ISR(xSwitchRequired) \
|
||||||
|
{ \
|
||||||
|
if (xSwitchRequired != pdFALSE) \
|
||||||
|
{ \
|
||||||
|
traceISR_EXIT_TO_SCHEDULER(); \
|
||||||
|
portYIELD(); \
|
||||||
|
} \
|
||||||
|
else \
|
||||||
|
{ \
|
||||||
|
traceISR_EXIT(); \
|
||||||
|
} \
|
||||||
|
}
|
||||||
#else
|
#else
|
||||||
#define portEND_SWITCHING_ISR(xSwitchRequired) if( xSwitchRequired != pdFALSE) portYIELD()
|
#define portEND_SWITCHING_ISR(xSwitchRequired) \
|
||||||
|
if (xSwitchRequired != pdFALSE) \
|
||||||
|
portYIELD()
|
||||||
#endif
|
#endif
|
||||||
#define portYIELD_FROM_ISR(x) portEND_SWITCHING_ISR(x)
|
#define portYIELD_FROM_ISR(x) portEND_SWITCHING_ISR(x)
|
||||||
|
|
||||||
@@ -124,19 +133,14 @@ not necessary for to use this port. They are defined so the common demo files
|
|||||||
#endif
|
#endif
|
||||||
/*-----------------------------------------------------------*/
|
/*-----------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#define portINLINE __inline
|
#define portINLINE __inline
|
||||||
|
|
||||||
#ifndef portFORCE_INLINE
|
#ifndef portFORCE_INLINE
|
||||||
#define portFORCE_INLINE inline __attribute__((always_inline))
|
#define portFORCE_INLINE inline __attribute__((always_inline))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* PORTMACRO_H */
|
#endif /* PORTMACRO_H */
|
||||||
|
|
||||||
|
|||||||
@@ -18,14 +18,16 @@
|
|||||||
*
|
*
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
class FRToSI2C {
|
class FRToSI2C
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
static void init()
|
||||||
static void init() {
|
{
|
||||||
I2CSemaphore = nullptr;
|
I2CSemaphore = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void FRToSInit() {
|
static void FRToSInit()
|
||||||
|
{
|
||||||
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
|
I2CSemaphore = xSemaphoreCreateBinaryStatic(&xSemaphoreBuffer);
|
||||||
xSemaphoreGive(I2CSemaphore);
|
xSemaphoreGive(I2CSemaphore);
|
||||||
}
|
}
|
||||||
@@ -47,6 +49,8 @@ public:
|
|||||||
static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg);
|
static uint8_t I2C_RegisterRead(uint8_t address, uint8_t reg);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static bool lock();
|
||||||
|
static void unlock();
|
||||||
static void I2C_Unstick();
|
static void I2C_Unstick();
|
||||||
static SemaphoreHandle_t I2CSemaphore;
|
static SemaphoreHandle_t I2CSemaphore;
|
||||||
static StaticSemaphore_t xSemaphoreBuffer;
|
static StaticSemaphore_t xSemaphoreBuffer;
|
||||||
|
|||||||
@@ -10,7 +10,8 @@
|
|||||||
#include "LIS2DH12.hpp"
|
#include "LIS2DH12.hpp"
|
||||||
#include "cmsis_os.h"
|
#include "cmsis_os.h"
|
||||||
|
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
const uint8_t reg;
|
const uint8_t reg;
|
||||||
const uint8_t value;
|
const uint8_t value;
|
||||||
} LIS_REG;
|
} LIS_REG;
|
||||||
@@ -19,23 +20,32 @@ static const LIS_REG i2c_registers[] = { { LIS_CTRL_REG1, 0x17 }, // 25Hz
|
|||||||
{LIS_CTRL_REG2, 0b00001000}, // Highpass filter off
|
{LIS_CTRL_REG2, 0b00001000}, // Highpass filter off
|
||||||
{LIS_CTRL_REG3, 0b01100000}, // Setup interrupt pins
|
{LIS_CTRL_REG3, 0b01100000}, // Setup interrupt pins
|
||||||
{LIS_CTRL_REG4, 0b00001000}, // Block update mode off, HR on
|
{LIS_CTRL_REG4, 0b00001000}, // Block update mode off, HR on
|
||||||
{ LIS_CTRL_REG5, 0b00000010 }, { LIS_CTRL_REG6, 0b01100010 },
|
{LIS_CTRL_REG5, 0b00000010},
|
||||||
|
{LIS_CTRL_REG6, 0b01100010},
|
||||||
//Basically setup the unit to run, and enable 4D orientation detection
|
//Basically setup the unit to run, and enable 4D orientation detection
|
||||||
{LIS_INT2_CFG, 0b01111110}, //setup for movement detection
|
{LIS_INT2_CFG, 0b01111110}, //setup for movement detection
|
||||||
{ LIS_INT2_THS, 0x28 }, { LIS_INT2_DURATION, 64 }, {
|
{LIS_INT2_THS, 0x28},
|
||||||
LIS_INT1_CFG, 0b01111110 }, { LIS_INT1_THS, 0x28 }, {
|
{LIS_INT2_DURATION, 64},
|
||||||
LIS_INT1_DURATION, 64 } };
|
{LIS_INT1_CFG, 0b01111110},
|
||||||
|
{LIS_INT1_THS, 0x28},
|
||||||
|
{LIS_INT1_DURATION, 64}};
|
||||||
|
|
||||||
void LIS2DH12::initalize() {
|
void LIS2DH12::initalize()
|
||||||
|
{
|
||||||
|
#ifdef ACCEL_LIS
|
||||||
for (size_t index = 0;
|
for (size_t index = 0;
|
||||||
index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
index < (sizeof(i2c_registers) / sizeof(i2c_registers[0]));
|
||||||
index++) {
|
index++)
|
||||||
|
{
|
||||||
FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS,
|
FRToSI2C::I2C_RegisterWrite(LIS2DH_I2C_ADDRESS,
|
||||||
i2c_registers[index].reg, i2c_registers[index].value);
|
i2c_registers[index].reg, i2c_registers[index].value);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z)
|
||||||
|
{
|
||||||
|
#ifdef ACCEL_LIS
|
||||||
std::array<int16_t, 3> sensorData;
|
std::array<int16_t, 3> sensorData;
|
||||||
|
|
||||||
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8,
|
FRToSI2C::Mem_Read(LIS2DH_I2C_ADDRESS, 0xA8,
|
||||||
@@ -45,8 +55,10 @@ void LIS2DH12::getAxisReadings(int16_t &x, int16_t &y, int16_t &z) {
|
|||||||
x = sensorData[0];
|
x = sensorData[0];
|
||||||
y = sensorData[1];
|
y = sensorData[1];
|
||||||
z = sensorData[2];
|
z = sensorData[2];
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
bool LIS2DH12::detect() {
|
bool LIS2DH12::detect()
|
||||||
|
{
|
||||||
return FRToSI2C::probe(LIS2DH_I2C_ADDRESS);
|
return FRToSI2C::probe(LIS2DH_I2C_ADDRESS);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,15 +11,18 @@
|
|||||||
#include "LIS2DH12_defines.hpp"
|
#include "LIS2DH12_defines.hpp"
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
|
|
||||||
class LIS2DH12 {
|
class LIS2DH12
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
static bool detect();
|
static bool detect();
|
||||||
static void initalize();
|
static void initalize();
|
||||||
//1 = rh, 2,=lh, 8=flat
|
//1 = rh, 2,=lh, 8=flat
|
||||||
static Orientation getOrientation() {
|
static Orientation getOrientation()
|
||||||
|
{
|
||||||
#ifdef LIS_ORI_FLIP
|
#ifdef LIS_ORI_FLIP
|
||||||
uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,
|
uint8_t val = (FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS,
|
||||||
LIS_INT2_SRC) >> 2);
|
LIS_INT2_SRC) >>
|
||||||
|
2);
|
||||||
if (val == 8)
|
if (val == 8)
|
||||||
val = 3;
|
val = 3;
|
||||||
else if (val == 1)
|
else if (val == 1)
|
||||||
@@ -30,8 +33,10 @@ public:
|
|||||||
val = 3;
|
val = 3;
|
||||||
return static_cast<Orientation>(val);
|
return static_cast<Orientation>(val);
|
||||||
#endif
|
#endif
|
||||||
#ifdef MODEL_TS100
|
#ifdef ACCEL_LIS
|
||||||
return static_cast<Orientation>((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, LIS_INT2_SRC) >> 2) - 1);
|
return static_cast<Orientation>((FRToSI2C::I2C_RegisterRead(LIS2DH_I2C_ADDRESS, LIS_INT2_SRC) >> 2) - 1);
|
||||||
|
#else
|
||||||
|
return Orientation::ORIENTATION_FLAT;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
static void getAxisReadings(int16_t &x, int16_t &y, int16_t &z);
|
||||||
|
|||||||
@@ -9,11 +9,11 @@
|
|||||||
#define INC_FREERTOSHOOKS_H_
|
#define INC_FREERTOSHOOKS_H_
|
||||||
|
|
||||||
#include "FreeRTOS.h"
|
#include "FreeRTOS.h"
|
||||||
#include "cmsis_os.h"
|
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// RToS
|
// RToS
|
||||||
@@ -24,5 +24,4 @@ void vApplicationIdleHook(void);
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#endif /* INC_FREERTOSHOOKS_H_ */
|
#endif /* INC_FREERTOSHOOKS_H_ */
|
||||||
|
|||||||
@@ -10,7 +10,6 @@
|
|||||||
#ifndef SETTINGS_H_
|
#ifndef SETTINGS_H_
|
||||||
#define SETTINGS_H_
|
#define SETTINGS_H_
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include "stm32f1xx_hal.h"
|
|
||||||
#include "unit.h"
|
#include "unit.h"
|
||||||
#define SETTINGSVERSION (0x20)
|
#define SETTINGSVERSION (0x20)
|
||||||
/*Change this if you change the struct below to prevent people getting \
|
/*Change this if you change the struct below to prevent people getting \
|
||||||
@@ -20,7 +19,8 @@
|
|||||||
* This struct must be a multiple of 2 bytes as it is saved / restored from
|
* This struct must be a multiple of 2 bytes as it is saved / restored from
|
||||||
* flash in uint16_t chunks
|
* flash in uint16_t chunks
|
||||||
*/
|
*/
|
||||||
typedef struct {
|
typedef struct
|
||||||
|
{
|
||||||
uint8_t version; // Used to track if a reset is needed on firmware upgrade
|
uint8_t version; // Used to track if a reset is needed on firmware upgrade
|
||||||
|
|
||||||
uint16_t SolderingTemp; // current set point for the iron
|
uint16_t SolderingTemp; // current set point for the iron
|
||||||
|
|||||||
@@ -8,10 +8,11 @@ extern uint32_t currentTempTargetDegC;
|
|||||||
extern bool settingsWereReset;
|
extern bool settingsWereReset;
|
||||||
extern bool usb_pd_available;
|
extern bool usb_pd_available;
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void vApplicationStackOverflowHook(xTaskHandle *pxTask,
|
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
|
||||||
signed portCHAR *pcTaskName);
|
signed portCHAR *pcTaskName);
|
||||||
|
|
||||||
//Threads
|
//Threads
|
||||||
|
|||||||
@@ -7,7 +7,9 @@
|
|||||||
|
|
||||||
#include "FreeRTOSHooks.h"
|
#include "FreeRTOSHooks.h"
|
||||||
#include "BSP.h"
|
#include "BSP.h"
|
||||||
void vApplicationIdleHook(void) {
|
#include "cmsis_os.h"
|
||||||
|
void vApplicationIdleHook(void)
|
||||||
|
{
|
||||||
resetWatchdog();
|
resetWatchdog();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -16,19 +18,19 @@ static StaticTask_t xIdleTaskTCBBuffer;
|
|||||||
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
static StackType_t xIdleStack[configMINIMAL_STACK_SIZE];
|
||||||
|
|
||||||
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
void vApplicationGetIdleTaskMemory(StaticTask_t **ppxIdleTaskTCBBuffer,
|
||||||
StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize) {
|
StackType_t **ppxIdleTaskStackBuffer, uint32_t *pulIdleTaskStackSize)
|
||||||
|
{
|
||||||
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
*ppxIdleTaskTCBBuffer = &xIdleTaskTCBBuffer;
|
||||||
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
*ppxIdleTaskStackBuffer = &xIdleStack[0];
|
||||||
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
*pulIdleTaskStackSize = configMINIMAL_STACK_SIZE;
|
||||||
/* place for user code */
|
/* place for user code */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void vApplicationStackOverflowHook(TaskHandle_t *pxTask,
|
||||||
void vApplicationStackOverflowHook(xTaskHandle *pxTask,
|
signed portCHAR *pcTaskName)
|
||||||
signed portCHAR *pcTaskName) {
|
{
|
||||||
(void)pxTask;
|
(void)pxTask;
|
||||||
(void)pcTaskName;
|
(void)pcTaskName;
|
||||||
asm("bkpt");
|
|
||||||
// We dont have a good way to handle a stack overflow at this point in time
|
// We dont have a good way to handle a stack overflow at this point in time
|
||||||
reboot();
|
reboot();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ TaskHandle_t pidTaskNotification = NULL;
|
|||||||
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
uint32_t currentTempTargetDegC = 0; // Current temperature target in C
|
||||||
|
|
||||||
/* StartPIDTask function */
|
/* StartPIDTask function */
|
||||||
void startPIDTask(void const *argument __unused) {
|
void startPIDTask(void const *argument __unused)
|
||||||
|
{
|
||||||
/*
|
/*
|
||||||
* We take the current tip temperature & evaluate the next step for the tip
|
* We take the current tip temperature & evaluate the next step for the tip
|
||||||
* control PWM.
|
* control PWM.
|
||||||
@@ -34,22 +35,27 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// be over-ridden rapidly
|
// be over-ridden rapidly
|
||||||
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
pidTaskNotification = xTaskGetCurrentTaskHandle();
|
||||||
uint32_t PIDTempTarget = 0;
|
uint32_t PIDTempTarget = 0;
|
||||||
for (;;) {
|
for (;;)
|
||||||
|
{
|
||||||
|
|
||||||
if (ulTaskNotifyTake(pdTRUE, 2000)) {
|
if (ulTaskNotifyTake(pdTRUE, 2000))
|
||||||
|
{
|
||||||
// This is a call to block this thread until the ADC does its samples
|
// This is a call to block this thread until the ADC does its samples
|
||||||
int32_t x10WattsOut = 0;
|
int32_t x10WattsOut = 0;
|
||||||
// Do the reading here to keep the temp calculations churning along
|
// Do the reading here to keep the temp calculations churning along
|
||||||
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
|
uint32_t currentTipTempInC = TipThermoModel::getTipInC(true);
|
||||||
PIDTempTarget = currentTempTargetDegC;
|
PIDTempTarget = currentTempTargetDegC;
|
||||||
if (PIDTempTarget) {
|
if (PIDTempTarget)
|
||||||
|
{
|
||||||
// Cap the max set point to 450C
|
// Cap the max set point to 450C
|
||||||
if (PIDTempTarget > (450)) {
|
if (PIDTempTarget > (450))
|
||||||
|
{
|
||||||
//Maximum allowed output
|
//Maximum allowed output
|
||||||
PIDTempTarget = (450);
|
PIDTempTarget = (450);
|
||||||
}
|
}
|
||||||
//Safety check that not aiming higher than current tip can measure
|
//Safety check that not aiming higher than current tip can measure
|
||||||
if (PIDTempTarget > TipThermoModel::getTipMaxInC()) {
|
if (PIDTempTarget > TipThermoModel::getTipMaxInC())
|
||||||
|
{
|
||||||
PIDTempTarget = TipThermoModel::getTipMaxInC();
|
PIDTempTarget = TipThermoModel::getTipMaxInC();
|
||||||
}
|
}
|
||||||
// Convert the current tip to degree's C
|
// Convert the current tip to degree's C
|
||||||
@@ -89,38 +95,41 @@ void startPIDTask(void const *argument __unused) {
|
|||||||
// and counters extra power if the iron is no longer losing temp.
|
// and counters extra power if the iron is no longer losing temp.
|
||||||
// basically: temp - lastTemp
|
// basically: temp - lastTemp
|
||||||
// Unfortunately, our temp signal is too noisy to really help.
|
// Unfortunately, our temp signal is too noisy to really help.
|
||||||
|
|
||||||
}
|
}
|
||||||
//If the user turns on the option of using an occasional pulse to keep the power bank on
|
//If the user turns on the option of using an occasional pulse to keep the power bank on
|
||||||
if (systemSettings.KeepAwakePulse) {
|
if (systemSettings.KeepAwakePulse)
|
||||||
|
{
|
||||||
|
|
||||||
if (xTaskGetTickCount() - lastPowerPulseStart
|
if (xTaskGetTickCount() - lastPowerPulseStart > powerPulseRate)
|
||||||
> powerPulseRate) {
|
{
|
||||||
lastPowerPulseStart = xTaskGetTickCount();
|
lastPowerPulseStart = xTaskGetTickCount();
|
||||||
lastPowerPulseEnd = lastPowerPulseStart
|
lastPowerPulseEnd = lastPowerPulseStart + powerPulseDuration;
|
||||||
+ powerPulseDuration;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
|
//If current PID is less than the pulse level, check if we want to constrain to the pulse as the floor
|
||||||
if (x10WattsOut < systemSettings.KeepAwakePulse
|
if (x10WattsOut < systemSettings.KeepAwakePulse && xTaskGetTickCount() < lastPowerPulseEnd)
|
||||||
&& xTaskGetTickCount() < lastPowerPulseEnd) {
|
{
|
||||||
x10WattsOut = systemSettings.KeepAwakePulse;
|
x10WattsOut = systemSettings.KeepAwakePulse;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
//Secondary safety check to forcefully disable header when within ADC noise of top of ADC
|
||||||
if (getTipRawTemp(0) > (0x7FFF - 150)) {
|
if (getTipRawTemp(0) > (0x7FFF - 150))
|
||||||
|
{
|
||||||
x10WattsOut = 0;
|
x10WattsOut = 0;
|
||||||
}
|
}
|
||||||
if (systemSettings.powerLimitEnable
|
if (systemSettings.powerLimitEnable && x10WattsOut > (systemSettings.powerLimit * 10))
|
||||||
&& x10WattsOut > (systemSettings.powerLimit * 10)) {
|
{
|
||||||
setTipX10Watts(systemSettings.powerLimit * 10);
|
setTipX10Watts(systemSettings.powerLimit * 10);
|
||||||
} else {
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
setTipX10Watts(x10WattsOut);
|
setTipX10Watts(x10WattsOut);
|
||||||
}
|
}
|
||||||
|
resetWatchdog();
|
||||||
HAL_IWDG_Refresh(&hiwdg);
|
}
|
||||||
} else {
|
else
|
||||||
|
{
|
||||||
//ADC interrupt timeout
|
//ADC interrupt timeout
|
||||||
setTipPWM(0);
|
setTipPWM(0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ MINIWARE_INC_DIR = ./Core/BSP/Miniware
|
|||||||
PINE_INC_DIR = ./Core/BSP/Pine64
|
PINE_INC_DIR = ./Core/BSP/Pine64
|
||||||
PINE_VENDOR_INC_DIR = ./Core/BSP/Pine64/Vendor/Lib
|
PINE_VENDOR_INC_DIR = ./Core/BSP/Pine64/Vendor/Lib
|
||||||
PINE_RISCV_INC_DIR = ./Core/BSP/Pine64/Vendor/RISCV
|
PINE_RISCV_INC_DIR = ./Core/BSP/Pine64/Vendor/RISCV
|
||||||
|
PINE_N200_INC_DIR = ./Core/BSP/Pine64/N200
|
||||||
SOURCE_THREADS_DIR = ./Core/Threads
|
SOURCE_THREADS_DIR = ./Core/Threads
|
||||||
SOURCE_CORE_DIR = ./Core/Src
|
SOURCE_CORE_DIR = ./Core/Src
|
||||||
SOURCE_DRIVERS_DIR = ./Core/Drivers
|
SOURCE_DRIVERS_DIR = ./Core/Drivers
|
||||||
@@ -45,6 +46,9 @@ DEVICE_INCLUDES = -I$(MINIWARE_INC_DIR) \
|
|||||||
DEVICE_BSP_DIR = ./Core/BSP/Miniware
|
DEVICE_BSP_DIR = ./Core/BSP/Miniware
|
||||||
S_SRCS := ./Startup/startup_stm32f103t8ux.S
|
S_SRCS := ./Startup/startup_stm32f103t8ux.S
|
||||||
LDSCRIPT=stm32f103.ld
|
LDSCRIPT=stm32f103.ld
|
||||||
|
DEV_GLOBAL_DEFS= -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D GCC_ARMCM3 \
|
||||||
|
-D ARM_MATH_CM3 \
|
||||||
|
-D STM32F10X_MD
|
||||||
DEV_LDFLAGS=
|
DEV_LDFLAGS=
|
||||||
DEV_AFLAGS=
|
DEV_AFLAGS=
|
||||||
DEV_CFLAGS=
|
DEV_CFLAGS=
|
||||||
@@ -55,12 +59,14 @@ ifeq ($(model),Pinecil)
|
|||||||
DEVICE_INCLUDES = -I$(PINE_INC_DIR) \
|
DEVICE_INCLUDES = -I$(PINE_INC_DIR) \
|
||||||
-I$(PINE_INC_DIR)/N200 \
|
-I$(PINE_INC_DIR)/N200 \
|
||||||
-I$(PINE_VENDOR_INC_DIR) \
|
-I$(PINE_VENDOR_INC_DIR) \
|
||||||
-I$(PINE_RISCV_INC_DIR)
|
-I$(PINE_RISCV_INC_DIR) \
|
||||||
|
-I$(PINE_N200_INC_DIR)\
|
||||||
|
-I$(INC_PD_DRIVERS_DIR)
|
||||||
|
|
||||||
DEVICE_BSP_DIR = ./Core/BSP/Pine64
|
DEVICE_BSP_DIR = ./Core/BSP/Pine64
|
||||||
S_SRCS := $(shell find $(PINE_INC_DIR) -type f -name '*.s')
|
S_SRCS := $(shell find $(PINE_INC_DIR) -type f -name '*.S')
|
||||||
ASM_INC = -I$(PINE_RISCV_INC_DIR)
|
ASM_INC = -I$(PINE_RISCV_INC_DIR)
|
||||||
LDSCRIPT=GD32VF103x8.ld
|
LDSCRIPT=GD32VF103xB.ld
|
||||||
DEV_LDFLAGS=-nostartfiles
|
DEV_LDFLAGS=-nostartfiles
|
||||||
DEV_AFLAGS = -msmall-data-limit=8 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections
|
DEV_AFLAGS = -msmall-data-limit=8 -fmessage-length=0 -fsigned-char -ffunction-sections -fdata-sections
|
||||||
DEV_CFLAGS= -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"
|
DEV_CFLAGS= -MMD -MP -MF"$(@:%.o=%.d)" -MT"$(@:%.o=%.d)"
|
||||||
@@ -97,9 +103,7 @@ OPTIM=-Os -flto -ffat-lto-objects -finline-small-functions -findirect-inlining -
|
|||||||
|
|
||||||
|
|
||||||
# global defines ---------------------------------------------------------------
|
# global defines ---------------------------------------------------------------
|
||||||
GLOBAL_DEFINES += -D STM32F103T8Ux -D STM32F1 -D STM32 -D USE_HAL_DRIVER -D STM32F103xB -D USE_RTOS_SYSTICK -D LANG_$(lang) -D LANG -D MODEL_$(model) -D GCC_ARMCM3 \
|
GLOBAL_DEFINES += -D LANG_$(lang) -D LANG -D MODEL_$(model) $(DEV_GLOBAL_DEFS)
|
||||||
-D ARM_MATH_CM3 \
|
|
||||||
-D STM32F10X_MD \
|
|
||||||
|
|
||||||
# Enable debug code generation
|
# Enable debug code generation
|
||||||
DEBUG=-g3
|
DEBUG=-g3
|
||||||
@@ -277,6 +281,7 @@ $(OUT_HEXFILE).elf : $(OUT_OBJS_S) $(OUT_OBJS) $(OUT_OBJS_CPP) Makefile $(LDSCR
|
|||||||
$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile
|
$(OUT_OBJS): $(OUTPUT_DIR)/%.o : %.c Makefile
|
||||||
@test -d $(@D) || mkdir -p $(@D)
|
@test -d $(@D) || mkdir -p $(@D)
|
||||||
@echo Compiling ${<}
|
@echo Compiling ${<}
|
||||||
|
@echo @$(CC) -c $(CFLAGS) $< -o $@
|
||||||
@$(CC) -c $(CFLAGS) $< -o $@
|
@$(CC) -c $(CFLAGS) $< -o $@
|
||||||
@$(OBJDUMP) -d -S $@ > $@.lst
|
@$(OBJDUMP) -d -S $@ > $@.lst
|
||||||
|
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
*
|
*
|
||||||
*----------------------------------------------------------------------------
|
*----------------------------------------------------------------------------
|
||||||
*
|
*
|
||||||
* Portions Copyright <20> 2016 STMicroelectronics International N.V. All rights reserved.
|
* Portions Copyright <20> 2016 STMicroelectronics International N.V. All rights reserved.
|
||||||
* Portions Copyright (c) 2013 ARM LIMITED
|
* Portions Copyright (c) 2013 ARM LIMITED
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
@@ -118,9 +118,7 @@
|
|||||||
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
#define __INLINE inline /*!< inline keyword for GNU Compiler */
|
||||||
#define __STATIC_INLINE static inline
|
#define __STATIC_INLINE static inline
|
||||||
|
|
||||||
|
// #include "cmsis_gcc.h"
|
||||||
#include "cmsis_gcc.h"
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* IAR Compiler
|
* IAR Compiler
|
||||||
@@ -147,7 +145,8 @@ static unsigned portBASE_TYPE makeFreeRtosPriority (osPriority priority)
|
|||||||
{
|
{
|
||||||
unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY;
|
unsigned portBASE_TYPE fpriority = tskIDLE_PRIORITY;
|
||||||
|
|
||||||
if (priority != osPriorityError) {
|
if (priority != osPriorityError)
|
||||||
|
{
|
||||||
fpriority += (priority - osPriorityIdle);
|
fpriority += (priority - osPriorityIdle);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +159,8 @@ static osPriority makeCmsisPriority (unsigned portBASE_TYPE fpriority)
|
|||||||
{
|
{
|
||||||
osPriority priority = osPriorityError;
|
osPriority priority = osPriorityError;
|
||||||
|
|
||||||
if ((fpriority - tskIDLE_PRIORITY) <= (osPriorityRealtime - osPriorityIdle)) {
|
if ((fpriority - tskIDLE_PRIORITY) <= (osPriorityRealtime - osPriorityIdle))
|
||||||
|
{
|
||||||
priority = (osPriority)((int)osPriorityIdle + (int)(fpriority - tskIDLE_PRIORITY));
|
priority = (osPriority)((int)osPriorityIdle + (int)(fpriority - tskIDLE_PRIORITY));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -168,7 +168,6 @@ static osPriority makeCmsisPriority (unsigned portBASE_TYPE fpriority)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
/* Determine whether we are in thread mode or handler mode. */
|
/* Determine whether we are in thread mode or handler mode. */
|
||||||
static int inHandlerMode(void)
|
static int inHandlerMode(void)
|
||||||
{
|
{
|
||||||
@@ -226,10 +225,12 @@ int32_t osKernelRunning(void)
|
|||||||
*/
|
*/
|
||||||
uint32_t osKernelSysTick(void)
|
uint32_t osKernelSysTick(void)
|
||||||
{
|
{
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return xTaskGetTickCountFromISR();
|
return xTaskGetTickCountFromISR();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return xTaskGetTickCount();
|
return xTaskGetTickCount();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -247,15 +248,18 @@ osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
|
|||||||
TaskHandle_t handle;
|
TaskHandle_t handle;
|
||||||
|
|
||||||
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
if((thread_def->buffer != NULL) && (thread_def->controlblock != NULL)) {
|
if ((thread_def->buffer != NULL) && (thread_def->controlblock != NULL))
|
||||||
|
{
|
||||||
handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
handle = xTaskCreateStatic((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
||||||
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
||||||
thread_def->buffer, thread_def->controlblock);
|
thread_def->buffer, thread_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
||||||
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
||||||
&handle) != pdPASS) {
|
&handle) != pdPASS)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +271,8 @@ osThreadId osThreadCreate (const osThreadDef_t *thread_def, void *argument)
|
|||||||
#else
|
#else
|
||||||
if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
if (xTaskCreate((TaskFunction_t)thread_def->pthread, (const portCHAR *)thread_def->name,
|
||||||
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
thread_def->stacksize, argument, makeFreeRtosPriority(thread_def->tpriority),
|
||||||
&handle) != pdPASS) {
|
&handle) != pdPASS)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
@@ -402,7 +407,8 @@ osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void
|
|||||||
#if (configUSE_TIMERS == 1)
|
#if (configUSE_TIMERS == 1)
|
||||||
|
|
||||||
#if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1))
|
#if ((configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1))
|
||||||
if(timer_def->controlblock != NULL) {
|
if (timer_def->controlblock != NULL)
|
||||||
|
{
|
||||||
return xTimerCreateStatic((const char *)"",
|
return xTimerCreateStatic((const char *)"",
|
||||||
1, // period should be filled when starting the Timer using osTimerStart
|
1, // period should be filled when starting the Timer using osTimerStart
|
||||||
(type == osTimerPeriodic) ? pdTRUE : pdFALSE,
|
(type == osTimerPeriodic) ? pdTRUE : pdFALSE,
|
||||||
@@ -410,7 +416,8 @@ osTimerId osTimerCreate (const osTimerDef_t *timer_def, os_timer_type type, void
|
|||||||
(TaskFunction_t)timer_def->ptimer,
|
(TaskFunction_t)timer_def->ptimer,
|
||||||
(StaticTimer_t *)timer_def->controlblock);
|
(StaticTimer_t *)timer_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return xTimerCreate((const char *)"",
|
return xTimerCreate((const char *)"",
|
||||||
1, // period should be filled when starting the Timer using osTimerStart
|
1, // period should be filled when starting the Timer using osTimerStart
|
||||||
(type == osTimerPeriodic) ? pdTRUE : pdFALSE,
|
(type == osTimerPeriodic) ? pdTRUE : pdFALSE,
|
||||||
@@ -489,14 +496,18 @@ osStatus osTimerStop (osTimerId timer_id)
|
|||||||
#if (configUSE_TIMERS == 1)
|
#if (configUSE_TIMERS == 1)
|
||||||
portBASE_TYPE taskWoken = pdFALSE;
|
portBASE_TYPE taskWoken = pdFALSE;
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xTimerStopFromISR(timer_id, &taskWoken) != pdPASS) {
|
{
|
||||||
|
if (xTimerStopFromISR(timer_id, &taskWoken) != pdPASS)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xTimerStop(timer_id, 0) != pdPASS) {
|
{
|
||||||
|
if (xTimerStop(timer_id, 0) != pdPASS)
|
||||||
|
{
|
||||||
result = osErrorOS;
|
result = osErrorOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -518,11 +529,14 @@ osStatus result = osOK;
|
|||||||
|
|
||||||
#if (configUSE_TIMERS == 1)
|
#if (configUSE_TIMERS == 1)
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return osErrorISR;
|
return osErrorISR;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if ((xTimerDelete(timer_id, osWaitForever )) != pdPASS) {
|
{
|
||||||
|
if ((xTimerDelete(timer_id, osWaitForever)) != pdPASS)
|
||||||
|
{
|
||||||
result = osErrorOS;
|
result = osErrorOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -593,12 +607,15 @@ osEvent osSignalWait (int32_t signals, uint32_t millisec)
|
|||||||
|
|
||||||
ret.value.signals = 0;
|
ret.value.signals = 0;
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -611,14 +628,17 @@ osEvent osSignalWait (int32_t signals, uint32_t millisec)
|
|||||||
{
|
{
|
||||||
if (xTaskNotifyWait(0, (uint32_t)signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE)
|
if (xTaskNotifyWait(0, (uint32_t)signals, (uint32_t *)&ret.value.signals, ticks) != pdTRUE)
|
||||||
{
|
{
|
||||||
if(ticks == 0) ret.status = osOK;
|
if (ticks == 0)
|
||||||
else ret.status = osEventTimeout;
|
ret.status = osOK;
|
||||||
|
else
|
||||||
|
ret.status = osEventTimeout;
|
||||||
}
|
}
|
||||||
else if (ret.value.signals < 0)
|
else if (ret.value.signals < 0)
|
||||||
{
|
{
|
||||||
ret.status = osErrorValue;
|
ret.status = osErrorValue;
|
||||||
}
|
}
|
||||||
else ret.status = osEventSignal;
|
else
|
||||||
|
ret.status = osEventSignal;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
(void)signals;
|
(void)signals;
|
||||||
@@ -643,10 +663,12 @@ osMutexId osMutexCreate (const osMutexDef_t *mutex_def)
|
|||||||
|
|
||||||
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
|
|
||||||
if (mutex_def->controlblock != NULL) {
|
if (mutex_def->controlblock != NULL)
|
||||||
|
{
|
||||||
return xSemaphoreCreateMutexStatic(mutex_def->controlblock);
|
return xSemaphoreCreateMutexStatic(mutex_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return xSemaphoreCreateMutex();
|
return xSemaphoreCreateMutex();
|
||||||
}
|
}
|
||||||
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||||
@@ -671,29 +693,35 @@ osStatus osMutexWait (osMutexId mutex_id, uint32_t millisec)
|
|||||||
TickType_t ticks;
|
TickType_t ticks;
|
||||||
portBASE_TYPE taskWoken = pdFALSE;
|
portBASE_TYPE taskWoken = pdFALSE;
|
||||||
|
|
||||||
|
if (mutex_id == NULL)
|
||||||
if (mutex_id == NULL) {
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xSemaphoreTakeFromISR(mutex_id, &taskWoken) != pdTRUE) {
|
{
|
||||||
|
if (xSemaphoreTakeFromISR(mutex_id, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else if (xSemaphoreTake(mutex_id, ticks) != pdTRUE) {
|
else if (xSemaphoreTake(mutex_id, ticks) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -711,8 +739,10 @@ osStatus osMutexRelease (osMutexId mutex_id)
|
|||||||
osStatus result = osOK;
|
osStatus result = osOK;
|
||||||
portBASE_TYPE taskWoken = pdFALSE;
|
portBASE_TYPE taskWoken = pdFALSE;
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE) {
|
{
|
||||||
|
if (xSemaphoreGiveFromISR(mutex_id, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
@@ -732,7 +762,8 @@ osStatus osMutexRelease (osMutexId mutex_id)
|
|||||||
*/
|
*/
|
||||||
osStatus osMutexDelete(osMutexId mutex_id)
|
osStatus osMutexDelete(osMutexId mutex_id)
|
||||||
{
|
{
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return osErrorISR;
|
return osErrorISR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -758,11 +789,14 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t
|
|||||||
|
|
||||||
osSemaphoreId sema;
|
osSemaphoreId sema;
|
||||||
|
|
||||||
if (semaphore_def->controlblock != NULL){
|
if (semaphore_def->controlblock != NULL)
|
||||||
if (count == 1) {
|
{
|
||||||
|
if (count == 1)
|
||||||
|
{
|
||||||
return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock);
|
return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
||||||
return xSemaphoreCreateCountingStatic(count, count, semaphore_def->controlblock);
|
return xSemaphoreCreateCountingStatic(count, count, semaphore_def->controlblock);
|
||||||
#else
|
#else
|
||||||
@@ -770,12 +804,15 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (count == 1) {
|
{
|
||||||
|
if (count == 1)
|
||||||
|
{
|
||||||
vSemaphoreCreateBinary(sema);
|
vSemaphoreCreateBinary(sema);
|
||||||
return sema;
|
return sema;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
||||||
return xSemaphoreCreateCounting(count, count);
|
return xSemaphoreCreateCounting(count, count);
|
||||||
#else
|
#else
|
||||||
@@ -784,7 +821,8 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
#elif (configSUPPORT_STATIC_ALLOCATION == 1) // configSUPPORT_DYNAMIC_ALLOCATION == 0
|
#elif (configSUPPORT_STATIC_ALLOCATION == 1) // configSUPPORT_DYNAMIC_ALLOCATION == 0
|
||||||
if(count == 1) {
|
if (count == 1)
|
||||||
|
{
|
||||||
return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock);
|
return xSemaphoreCreateBinaryStatic(semaphore_def->controlblock);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -798,11 +836,13 @@ osSemaphoreId osSemaphoreCreate (const osSemaphoreDef_t *semaphore_def, int32_t
|
|||||||
#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1
|
#else // configSUPPORT_STATIC_ALLOCATION == 0 && configSUPPORT_DYNAMIC_ALLOCATION == 1
|
||||||
osSemaphoreId sema;
|
osSemaphoreId sema;
|
||||||
|
|
||||||
if (count == 1) {
|
if (count == 1)
|
||||||
|
{
|
||||||
vSemaphoreCreateBinary(sema);
|
vSemaphoreCreateBinary(sema);
|
||||||
return sema;
|
return sema;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
#if (configUSE_COUNTING_SEMAPHORES == 1)
|
||||||
return xSemaphoreCreateCounting(count, count);
|
return xSemaphoreCreateCounting(count, count);
|
||||||
#else
|
#else
|
||||||
@@ -824,29 +864,35 @@ int32_t osSemaphoreWait (osSemaphoreId semaphore_id, uint32_t millisec)
|
|||||||
TickType_t ticks;
|
TickType_t ticks;
|
||||||
portBASE_TYPE taskWoken = pdFALSE;
|
portBASE_TYPE taskWoken = pdFALSE;
|
||||||
|
|
||||||
|
if (semaphore_id == NULL)
|
||||||
if (semaphore_id == NULL) {
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE) {
|
{
|
||||||
|
if (xSemaphoreTakeFromISR(semaphore_id, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE) {
|
else if (xSemaphoreTake(semaphore_id, ticks) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,15 +910,18 @@ osStatus osSemaphoreRelease (osSemaphoreId semaphore_id)
|
|||||||
osStatus result = osOK;
|
osStatus result = osOK;
|
||||||
portBASE_TYPE taskWoken = pdFALSE;
|
portBASE_TYPE taskWoken = pdFALSE;
|
||||||
|
|
||||||
|
if (inHandlerMode())
|
||||||
if (inHandlerMode()) {
|
{
|
||||||
if (xSemaphoreGiveFromISR(semaphore_id, &taskWoken) != pdTRUE) {
|
if (xSemaphoreGiveFromISR(semaphore_id, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xSemaphoreGive(semaphore_id) != pdTRUE) {
|
{
|
||||||
|
if (xSemaphoreGive(semaphore_id) != pdTRUE)
|
||||||
|
{
|
||||||
result = osErrorOS;
|
result = osErrorOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -888,7 +937,8 @@ osStatus osSemaphoreRelease (osSemaphoreId semaphore_id)
|
|||||||
*/
|
*/
|
||||||
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
|
osStatus osSemaphoreDelete(osSemaphoreId semaphore_id)
|
||||||
{
|
{
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return osErrorISR;
|
return osErrorISR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -907,8 +957,8 @@ osStatus osSemaphoreDelete (osSemaphoreId semaphore_id)
|
|||||||
//This is a primitive and inefficient wrapper around the existing FreeRTOS memory management.
|
//This is a primitive and inefficient wrapper around the existing FreeRTOS memory management.
|
||||||
//A better implementation will have to modify heap_x.c!
|
//A better implementation will have to modify heap_x.c!
|
||||||
|
|
||||||
|
typedef struct os_pool_cb
|
||||||
typedef struct os_pool_cb {
|
{
|
||||||
void *pool;
|
void *pool;
|
||||||
uint8_t *markers;
|
uint8_t *markers;
|
||||||
uint32_t pool_sz;
|
uint32_t pool_sz;
|
||||||
@@ -916,7 +966,6 @@ typedef struct os_pool_cb {
|
|||||||
uint32_t currentIndex;
|
uint32_t currentIndex;
|
||||||
} os_pool_cb_t;
|
} os_pool_cb_t;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Create and Initialize a memory pool
|
* @brief Create and Initialize a memory pool
|
||||||
* @param pool_def memory pool definition referenced with \ref osPool.
|
* @param pool_def memory pool definition referenced with \ref osPool.
|
||||||
@@ -933,8 +982,8 @@ osPoolId osPoolCreate (const osPoolDef_t *pool_def)
|
|||||||
/* First have to allocate memory for the pool control block. */
|
/* First have to allocate memory for the pool control block. */
|
||||||
thePool = pvPortMalloc(sizeof(os_pool_cb_t));
|
thePool = pvPortMalloc(sizeof(os_pool_cb_t));
|
||||||
|
|
||||||
|
if (thePool)
|
||||||
if (thePool) {
|
{
|
||||||
thePool->pool_sz = pool_def->pool_sz;
|
thePool->pool_sz = pool_def->pool_sz;
|
||||||
thePool->item_sz = itemSize;
|
thePool->item_sz = itemSize;
|
||||||
thePool->currentIndex = 0;
|
thePool->currentIndex = 0;
|
||||||
@@ -942,22 +991,27 @@ osPoolId osPoolCreate (const osPoolDef_t *pool_def)
|
|||||||
/* Memory for markers */
|
/* Memory for markers */
|
||||||
thePool->markers = pvPortMalloc(pool_def->pool_sz);
|
thePool->markers = pvPortMalloc(pool_def->pool_sz);
|
||||||
|
|
||||||
if (thePool->markers) {
|
if (thePool->markers)
|
||||||
|
{
|
||||||
/* Now allocate the pool itself. */
|
/* Now allocate the pool itself. */
|
||||||
thePool->pool = pvPortMalloc(pool_def->pool_sz * itemSize);
|
thePool->pool = pvPortMalloc(pool_def->pool_sz * itemSize);
|
||||||
|
|
||||||
if (thePool->pool) {
|
if (thePool->pool)
|
||||||
for (i = 0; i < pool_def->pool_sz; i++) {
|
{
|
||||||
|
for (i = 0; i < pool_def->pool_sz; i++)
|
||||||
|
{
|
||||||
thePool->markers[i] = 0;
|
thePool->markers[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
vPortFree(thePool->markers);
|
vPortFree(thePool->markers);
|
||||||
vPortFree(thePool);
|
vPortFree(thePool);
|
||||||
thePool = NULL;
|
thePool = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
vPortFree(thePool);
|
vPortFree(thePool);
|
||||||
thePool = NULL;
|
thePool = NULL;
|
||||||
}
|
}
|
||||||
@@ -983,20 +1037,25 @@ void *osPoolAlloc (osPoolId pool_id)
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
dummy = portSET_INTERRUPT_MASK_FROM_ISR();
|
dummy = portSET_INTERRUPT_MASK_FROM_ISR();
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
vPortEnterCritical();
|
vPortEnterCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < pool_id->pool_sz; i++) {
|
for (i = 0; i < pool_id->pool_sz; i++)
|
||||||
|
{
|
||||||
index = pool_id->currentIndex + i;
|
index = pool_id->currentIndex + i;
|
||||||
if (index >= pool_id->pool_sz) {
|
if (index >= pool_id->pool_sz)
|
||||||
|
{
|
||||||
index = 0;
|
index = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pool_id->markers[index] == 0) {
|
if (pool_id->markers[index] == 0)
|
||||||
|
{
|
||||||
pool_id->markers[index] = 1;
|
pool_id->markers[index] = 1;
|
||||||
p = (void *)((uint32_t)(pool_id->pool) + (index * pool_id->item_sz));
|
p = (void *)((uint32_t)(pool_id->pool) + (index * pool_id->item_sz));
|
||||||
pool_id->currentIndex = index;
|
pool_id->currentIndex = index;
|
||||||
@@ -1004,10 +1063,12 @@ void *osPoolAlloc (osPoolId pool_id)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
|
portCLEAR_INTERRUPT_MASK_FROM_ISR(dummy);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
vPortExitCritical();
|
vPortExitCritical();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1043,24 +1104,29 @@ osStatus osPoolFree (osPoolId pool_id, void *block)
|
|||||||
{
|
{
|
||||||
uint32_t index;
|
uint32_t index;
|
||||||
|
|
||||||
if (pool_id == NULL) {
|
if (pool_id == NULL)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block == NULL) {
|
if (block == NULL)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (block < pool_id->pool) {
|
if (block < pool_id->pool)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
index = (uint32_t)block - (uint32_t)(pool_id->pool);
|
index = (uint32_t)block - (uint32_t)(pool_id->pool);
|
||||||
if (index % pool_id->item_sz) {
|
if (index % pool_id->item_sz)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
index = index / pool_id->item_sz;
|
index = index / pool_id->item_sz;
|
||||||
if (index >= pool_id->pool_sz) {
|
if (index >= pool_id->pool_sz)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1069,7 +1135,6 @@ osStatus osPoolFree (osPoolId pool_id, void *block)
|
|||||||
return osOK;
|
return osOK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#endif /* Use Memory Pool Management */
|
#endif /* Use Memory Pool Management */
|
||||||
|
|
||||||
/******************* Message Queue Management Functions *********************/
|
/******************* Message Queue Management Functions *********************/
|
||||||
@@ -1089,10 +1154,12 @@ osMessageQId osMessageCreate (const osMessageQDef_t *queue_def, osThreadId threa
|
|||||||
|
|
||||||
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
|
|
||||||
if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL)) {
|
if ((queue_def->buffer != NULL) && (queue_def->controlblock != NULL))
|
||||||
|
{
|
||||||
return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock);
|
return xQueueCreateStatic(queue_def->queue_sz, queue_def->item_sz, queue_def->buffer, queue_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return xQueueCreate(queue_def->queue_sz, queue_def->item_sz);
|
return xQueueCreate(queue_def->queue_sz, queue_def->item_sz);
|
||||||
}
|
}
|
||||||
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||||
@@ -1116,18 +1183,23 @@ osStatus osMessagePut (osMessageQId queue_id, uint32_t info, uint32_t millisec)
|
|||||||
TickType_t ticks;
|
TickType_t ticks;
|
||||||
|
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE) {
|
{
|
||||||
|
if (xQueueSendFromISR(queue_id, &info, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xQueueSend(queue_id, &info, ticks) != pdTRUE) {
|
{
|
||||||
|
if (xQueueSend(queue_id, &info, ticks) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1151,7 +1223,8 @@ osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
|
|||||||
event.def.message_id = queue_id;
|
event.def.message_id = queue_id;
|
||||||
event.value.v = 0;
|
event.value.v = 0;
|
||||||
|
|
||||||
if (queue_id == NULL) {
|
if (queue_id == NULL)
|
||||||
|
{
|
||||||
event.status = osErrorParameter;
|
event.status = osErrorParameter;
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
@@ -1159,32 +1232,41 @@ osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
|
|||||||
taskWoken = pdFALSE;
|
taskWoken = pdFALSE;
|
||||||
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE) {
|
{
|
||||||
|
if (xQueueReceiveFromISR(queue_id, &event.value.v, &taskWoken) == pdTRUE)
|
||||||
|
{
|
||||||
/* We have mail */
|
/* We have mail */
|
||||||
event.status = osEventMessage;
|
event.status = osEventMessage;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
event.status = osOK;
|
event.status = osOK;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE) {
|
{
|
||||||
|
if (xQueueReceive(queue_id, &event.value.v, ticks) == pdTRUE)
|
||||||
|
{
|
||||||
/* We have mail */
|
/* We have mail */
|
||||||
event.status = osEventMessage;
|
event.status = osEventMessage;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
event.status = (ticks == 0) ? osOK : osEventTimeout;
|
event.status = (ticks == 0) ? osOK : osEventTimeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1197,8 +1279,8 @@ osEvent osMessageGet (osMessageQId queue_id, uint32_t millisec)
|
|||||||
/******************** Mail Queue Management Functions ***********************/
|
/******************** Mail Queue Management Functions ***********************/
|
||||||
#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */
|
#if (defined(osFeature_MailQ) && (osFeature_MailQ != 0)) /* Use Mail Queues */
|
||||||
|
|
||||||
|
typedef struct os_mailQ_cb
|
||||||
typedef struct os_mailQ_cb {
|
{
|
||||||
const osMailQDef_t *queue_def;
|
const osMailQDef_t *queue_def;
|
||||||
QueueHandle_t handle;
|
QueueHandle_t handle;
|
||||||
osPoolId pool;
|
osPoolId pool;
|
||||||
@@ -1222,7 +1304,8 @@ osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id)
|
|||||||
|
|
||||||
*(queue_def->cb) = pvPortMalloc(sizeof(struct os_mailQ_cb));
|
*(queue_def->cb) = pvPortMalloc(sizeof(struct os_mailQ_cb));
|
||||||
|
|
||||||
if (*(queue_def->cb) == NULL) {
|
if (*(queue_def->cb) == NULL)
|
||||||
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
(*(queue_def->cb))->queue_def = queue_def;
|
(*(queue_def->cb))->queue_def = queue_def;
|
||||||
@@ -1230,15 +1313,16 @@ osMailQId osMailCreate (const osMailQDef_t *queue_def, osThreadId thread_id)
|
|||||||
/* Create a queue in FreeRTOS */
|
/* Create a queue in FreeRTOS */
|
||||||
(*(queue_def->cb))->handle = xQueueCreate(queue_def->queue_sz, sizeof(void *));
|
(*(queue_def->cb))->handle = xQueueCreate(queue_def->queue_sz, sizeof(void *));
|
||||||
|
|
||||||
|
if ((*(queue_def->cb))->handle == NULL)
|
||||||
if ((*(queue_def->cb))->handle == NULL) {
|
{
|
||||||
vPortFree(*(queue_def->cb));
|
vPortFree(*(queue_def->cb));
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a mail pool */
|
/* Create a mail pool */
|
||||||
(*(queue_def->cb))->pool = osPoolCreate(&pool_def);
|
(*(queue_def->cb))->pool = osPoolCreate(&pool_def);
|
||||||
if ((*(queue_def->cb))->pool == NULL) {
|
if ((*(queue_def->cb))->pool == NULL)
|
||||||
|
{
|
||||||
//TODO: Delete queue. How to do it in FreeRTOS?
|
//TODO: Delete queue. How to do it in FreeRTOS?
|
||||||
vPortFree(*(queue_def->cb));
|
vPortFree(*(queue_def->cb));
|
||||||
return NULL;
|
return NULL;
|
||||||
@@ -1262,8 +1346,8 @@ void *osMailAlloc (osMailQId queue_id, uint32_t millisec)
|
|||||||
(void)millisec;
|
(void)millisec;
|
||||||
void *p;
|
void *p;
|
||||||
|
|
||||||
|
if (queue_id == NULL)
|
||||||
if (queue_id == NULL) {
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1284,8 +1368,10 @@ void *osMailCAlloc (osMailQId queue_id, uint32_t millisec)
|
|||||||
uint32_t i;
|
uint32_t i;
|
||||||
void *p = osMailAlloc(queue_id, millisec);
|
void *p = osMailAlloc(queue_id, millisec);
|
||||||
|
|
||||||
if (p) {
|
if (p)
|
||||||
for (i = 0; i < queue_id->queue_def->item_sz; i++) {
|
{
|
||||||
|
for (i = 0; i < queue_id->queue_def->item_sz; i++)
|
||||||
|
{
|
||||||
((uint8_t *)p)[i] = 0;
|
((uint8_t *)p)[i] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1304,21 +1390,25 @@ osStatus osMailPut (osMailQId queue_id, void *mail)
|
|||||||
{
|
{
|
||||||
portBASE_TYPE taskWoken;
|
portBASE_TYPE taskWoken;
|
||||||
|
|
||||||
|
if (queue_id == NULL)
|
||||||
if (queue_id == NULL) {
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
taskWoken = pdFALSE;
|
taskWoken = pdFALSE;
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE) {
|
{
|
||||||
|
if (xQueueSendFromISR(queue_id->handle, &mail, &taskWoken) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE) {
|
{
|
||||||
|
if (xQueueSend(queue_id->handle, &mail, 0) != pdTRUE)
|
||||||
|
{
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1341,7 +1431,8 @@ osEvent osMailGet (osMailQId queue_id, uint32_t millisec)
|
|||||||
|
|
||||||
event.def.mail_id = queue_id;
|
event.def.mail_id = queue_id;
|
||||||
|
|
||||||
if (queue_id == NULL) {
|
if (queue_id == NULL)
|
||||||
|
{
|
||||||
event.status = osErrorParameter;
|
event.status = osErrorParameter;
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
@@ -1349,32 +1440,41 @@ osEvent osMailGet (osMailQId queue_id, uint32_t millisec)
|
|||||||
taskWoken = pdFALSE;
|
taskWoken = pdFALSE;
|
||||||
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE) {
|
{
|
||||||
|
if (xQueueReceiveFromISR(queue_id->handle, &event.value.p, &taskWoken) == pdTRUE)
|
||||||
|
{
|
||||||
/* We have mail */
|
/* We have mail */
|
||||||
event.status = osEventMail;
|
event.status = osEventMail;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
event.status = osOK;
|
event.status = osOK;
|
||||||
}
|
}
|
||||||
portEND_SWITCHING_ISR(taskWoken);
|
portEND_SWITCHING_ISR(taskWoken);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE) {
|
{
|
||||||
|
if (xQueueReceive(queue_id->handle, &event.value.p, ticks) == pdTRUE)
|
||||||
|
{
|
||||||
/* We have mail */
|
/* We have mail */
|
||||||
event.status = osEventMail;
|
event.status = osEventMail;
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
event.status = (ticks == 0) ? osOK : osEventTimeout;
|
event.status = (ticks == 0) ? osOK : osEventTimeout;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1391,7 +1491,8 @@ osEvent osMailGet (osMailQId queue_id, uint32_t millisec)
|
|||||||
*/
|
*/
|
||||||
osStatus osMailFree(osMailQId queue_id, void *mail)
|
osStatus osMailFree(osMailQId queue_id, void *mail)
|
||||||
{
|
{
|
||||||
if (queue_id == NULL) {
|
if (queue_id == NULL)
|
||||||
|
{
|
||||||
return osErrorParameter;
|
return osErrorParameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1532,7 +1633,6 @@ osStatus osThreadResumeAll (void)
|
|||||||
return osOK;
|
return osOK;
|
||||||
else
|
else
|
||||||
return osErrorOS;
|
return osErrorOS;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1605,18 +1705,22 @@ osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec)
|
|||||||
|
|
||||||
event.def.message_id = queue_id;
|
event.def.message_id = queue_id;
|
||||||
|
|
||||||
if (queue_id == NULL) {
|
if (queue_id == NULL)
|
||||||
|
{
|
||||||
event.status = osErrorParameter;
|
event.status = osErrorParameter;
|
||||||
return event;
|
return event;
|
||||||
}
|
}
|
||||||
|
|
||||||
ticks = 0;
|
ticks = 0;
|
||||||
if (millisec == osWaitForever) {
|
if (millisec == osWaitForever)
|
||||||
|
{
|
||||||
ticks = portMAX_DELAY;
|
ticks = portMAX_DELAY;
|
||||||
}
|
}
|
||||||
else if (millisec != 0) {
|
else if (millisec != 0)
|
||||||
|
{
|
||||||
ticks = millisec / portTICK_PERIOD_MS;
|
ticks = millisec / portTICK_PERIOD_MS;
|
||||||
if (ticks == 0) {
|
if (ticks == 0)
|
||||||
|
{
|
||||||
ticks = 1;
|
ticks = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1641,7 +1745,8 @@ osEvent osMessagePeek (osMessageQId queue_id, uint32_t millisec)
|
|||||||
*/
|
*/
|
||||||
uint32_t osMessageWaiting(osMessageQId queue_id)
|
uint32_t osMessageWaiting(osMessageQId queue_id)
|
||||||
{
|
{
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return uxQueueMessagesWaitingFromISR(queue_id);
|
return uxQueueMessagesWaitingFromISR(queue_id);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -1667,7 +1772,8 @@ uint32_t osMessageAvailableSpace(osMessageQId queue_id)
|
|||||||
*/
|
*/
|
||||||
osStatus osMessageDelete(osMessageQId queue_id)
|
osStatus osMessageDelete(osMessageQId queue_id)
|
||||||
{
|
{
|
||||||
if (inHandlerMode()) {
|
if (inHandlerMode())
|
||||||
|
{
|
||||||
return osErrorISR;
|
return osErrorISR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1686,10 +1792,12 @@ osMutexId osRecursiveMutexCreate (const osMutexDef_t *mutex_def)
|
|||||||
#if (configUSE_RECURSIVE_MUTEXES == 1)
|
#if (configUSE_RECURSIVE_MUTEXES == 1)
|
||||||
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
#if (configSUPPORT_STATIC_ALLOCATION == 1) && (configSUPPORT_DYNAMIC_ALLOCATION == 1)
|
||||||
|
|
||||||
if (mutex_def->controlblock != NULL){
|
if (mutex_def->controlblock != NULL)
|
||||||
|
{
|
||||||
return xSemaphoreCreateRecursiveMutexStatic(mutex_def->controlblock);
|
return xSemaphoreCreateRecursiveMutexStatic(mutex_def->controlblock);
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
|
{
|
||||||
return xSemaphoreCreateRecursiveMutex();
|
return xSemaphoreCreateRecursiveMutex();
|
||||||
}
|
}
|
||||||
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
#elif (configSUPPORT_STATIC_ALLOCATION == 1)
|
||||||
|
|||||||
@@ -1,279 +0,0 @@
|
|||||||
/*
|
|
||||||
* FreeRTOS Kernel V10.3.1
|
|
||||||
* Copyright (C) 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
|
|
||||||
*
|
|
||||||
* 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, sublicense, and/or sell copies of
|
|
||||||
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
||||||
* subject to the following conditions:
|
|
||||||
*
|
|
||||||
* The above copyright notice and this permission notice shall be included in all
|
|
||||||
* copies or substantial portions of the Software.
|
|
||||||
*
|
|
||||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
||||||
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
||||||
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
||||||
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
||||||
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
||||||
*
|
|
||||||
* http://www.FreeRTOS.org
|
|
||||||
* http://aws.amazon.com/freertos
|
|
||||||
*
|
|
||||||
* 1 tab == 4 spaces!
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DEPRECATED_DEFINITIONS_H
|
|
||||||
#define DEPRECATED_DEFINITIONS_H
|
|
||||||
|
|
||||||
|
|
||||||
/* Each FreeRTOS port has a unique portmacro.h header file. Originally a
|
|
||||||
pre-processor definition was used to ensure the pre-processor found the correct
|
|
||||||
portmacro.h file for the port being used. That scheme was deprecated in favour
|
|
||||||
of setting the compiler's include path such that it found the correct
|
|
||||||
portmacro.h file - removing the need for the constant and allowing the
|
|
||||||
portmacro.h file to be located anywhere in relation to the port being used. The
|
|
||||||
definitions below remain in the code for backward compatibility only. New
|
|
||||||
projects should not use them. */
|
|
||||||
|
|
||||||
#ifdef OPEN_WATCOM_INDUSTRIAL_PC_PORT
|
|
||||||
#include "..\..\Source\portable\owatcom\16bitdos\pc\portmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef OPEN_WATCOM_FLASH_LITE_186_PORT
|
|
||||||
#include "..\..\Source\portable\owatcom\16bitdos\flsh186\portmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MEGA_AVR
|
|
||||||
#include "../portable/GCC/ATMega323/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_MEGA_AVR
|
|
||||||
#include "../portable/IAR/ATMega323/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC24_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_DSPIC_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC24_dsPIC/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC18F_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC18F/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MPLAB_PIC32MX_PORT
|
|
||||||
#include "../../Source/portable/MPLAB/PIC32MX/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _FEDPICC
|
|
||||||
#include "libFreeRTOS/Include/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SDCC_CYGNAL
|
|
||||||
#include "../../Source/portable/SDCC/Cygnal/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARM7
|
|
||||||
#include "../../Source/portable/GCC/ARM7_LPC2000/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARM7_ECLIPSE
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ROWLEY_LPC23xx
|
|
||||||
#include "../../Source/portable/GCC/ARM7_LPC23xx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_MSP430
|
|
||||||
#include "..\..\Source\portable\IAR\MSP430\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MSP430
|
|
||||||
#include "../../Source/portable/GCC/MSP430F449/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ROWLEY_MSP430
|
|
||||||
#include "../../Source/portable/Rowley/MSP430F449/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ARM7_LPC21xx_KEIL_RVDS
|
|
||||||
#include "..\..\Source\portable\RVDS\ARM7_LPC21xx\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM7_GCC
|
|
||||||
#include "../../Source/portable/GCC/ARM7_AT91SAM7S/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM7_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\AtmelSAM7S64\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef SAM9XE_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\AtmelSAM9XE\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef LPC2000_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\LPC2000\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR71X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR71x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR75X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR75x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR75X_GCC
|
|
||||||
#include "..\..\Source\portable\GCC\STR75x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef STR91X_IAR
|
|
||||||
#include "..\..\Source\portable\IAR\STR91x\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_H8S
|
|
||||||
#include "../../Source/portable/GCC/H8S2329/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_AT91FR40008
|
|
||||||
#include "../../Source/portable/GCC/ARM7_AT91FR40008/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef RVDS_ARMCM3_LM3S102
|
|
||||||
#include "../../Source/portable/RVDS/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARMCM3_LM3S102
|
|
||||||
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_ARMCM3
|
|
||||||
#include "../../Source/portable/GCC/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_ARM_CM3
|
|
||||||
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef IAR_ARMCM3_LM
|
|
||||||
#include "../../Source/portable/IAR/ARM_CM3/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef HCS12_CODE_WARRIOR
|
|
||||||
#include "../../Source/portable/CodeWarrior/HCS12/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef MICROBLAZE_GCC
|
|
||||||
#include "../../Source/portable/GCC/MicroBlaze/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef TERN_EE
|
|
||||||
#include "..\..\Source\portable\Paradigm\Tern_EE\small\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_HCS12
|
|
||||||
#include "../../Source/portable/GCC/HCS12/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_MCF5235
|
|
||||||
#include "../../Source/portable/GCC/MCF5235/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef COLDFIRE_V2_GCC
|
|
||||||
#include "../../../Source/portable/GCC/ColdFire_V2/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef COLDFIRE_V2_CODEWARRIOR
|
|
||||||
#include "../../Source/portable/CodeWarrior/ColdFire_V2/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_PPC405
|
|
||||||
#include "../../Source/portable/GCC/PPC405_Xilinx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef GCC_PPC440
|
|
||||||
#include "../../Source/portable/GCC/PPC440_Xilinx/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef _16FX_SOFTUNE
|
|
||||||
#include "..\..\Source\portable\Softune\MB96340\portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BCC_INDUSTRIAL_PC_PORT
|
|
||||||
/* A short file name has to be used in place of the normal
|
|
||||||
FreeRTOSConfig.h when using the Borland compiler. */
|
|
||||||
#include "frconfig.h"
|
|
||||||
#include "..\portable\BCC\16BitDOS\PC\prtmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef BCC_FLASH_LITE_186_PORT
|
|
||||||
/* A short file name has to be used in place of the normal
|
|
||||||
FreeRTOSConfig.h when using the Borland compiler. */
|
|
||||||
#include "frconfig.h"
|
|
||||||
#include "..\portable\BCC\16BitDOS\flsh186\prtmacro.h"
|
|
||||||
typedef void ( __interrupt __far *pxISR )();
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __GNUC__
|
|
||||||
#ifdef __AVR32_AVR32A__
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __ICCAVR32__
|
|
||||||
#ifdef __CORE__
|
|
||||||
#if __CORE__ == __AVR32A__
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __91467D
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __96340
|
|
||||||
#include "portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Fx3__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx3__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx3_L__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Jx2__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_V850ES_Hx2__
|
|
||||||
#include "../../Source/portable/IAR/V850ES/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_78K0R_Kx3__
|
|
||||||
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef __IAR_78K0R_Kx3L__
|
|
||||||
#include "../../Source/portable/IAR/78K0R/portmacro.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#endif /* DEPRECATED_DEFINITIONS_H */
|
|
||||||
|
|
||||||
@@ -42,7 +42,6 @@ Purely for reasons of backward compatibility the old method is still valid, but
|
|||||||
to make it clear that new projects should not use it, support for the port
|
to make it clear that new projects should not use it, support for the port
|
||||||
specific constants has been moved into the deprecated_definitions.h header
|
specific constants has been moved into the deprecated_definitions.h header
|
||||||
file. */
|
file. */
|
||||||
#include "deprecated_definitions.h"
|
|
||||||
|
|
||||||
/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h
|
/* If portENTER_CRITICAL is not defined then including deprecated_definitions.h
|
||||||
did not result in a portmacro.h header file being included - and it should be
|
did not result in a portmacro.h header file being included - and it should be
|
||||||
@@ -93,7 +92,8 @@ must be set in the compiler's include path. */
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C"
|
||||||
|
{
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "mpu_wrappers.h"
|
#include "mpu_wrappers.h"
|
||||||
@@ -196,4 +196,3 @@ void vPortEndScheduler( void ) PRIVILEGED_FUNCTION;
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif /* PORTABLE_H */
|
#endif /* PORTABLE_H */
|
||||||
|
|
||||||
|
|||||||
@@ -108,6 +108,16 @@
|
|||||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODEL_Pinecil
|
||||||
|
#define VOLTAGE_DIV 467 // 467 - Default divider from schematic
|
||||||
|
#define CALIBRATION_OFFSET 900 // 900 - Default adc offset in uV
|
||||||
|
#define PID_POWER_LIMIT 70 // Sets the max pwm power limit
|
||||||
|
#define POWER_LIMIT 30 // 30 watts default limit
|
||||||
|
#define MAX_POWER_LIMIT 65 //
|
||||||
|
#define POWER_LIMIT_STEPS 5 //
|
||||||
|
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS100
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_TS80
|
#ifdef MODEL_TS80
|
||||||
#define VOLTAGE_DIV 780 // Default divider from schematic
|
#define VOLTAGE_DIV 780 // Default divider from schematic
|
||||||
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit
|
#define PID_POWER_LIMIT 24 // Sets the max pwm power limit
|
||||||
@@ -128,13 +138,16 @@
|
|||||||
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
|
#define OP_AMP_GAIN_STAGE OP_AMP_GAIN_STAGE_TS80
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#ifdef MODEL_TS100
|
#ifdef MODEL_TS100
|
||||||
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
|
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
|
||||||
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
|
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#ifdef MODEL_Pinecil
|
||||||
|
const int32_t tipMass = 45; // X10 watts to raise 1 deg C in 1 second
|
||||||
|
const uint8_t tipResistance = 85; //x10 ohms, 8.5 typical for ts100, 4.5 typical for ts80
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef MODEL_TS80
|
#ifdef MODEL_TS80
|
||||||
const uint32_t tipMass = 40;
|
const uint32_t tipMass = 40;
|
||||||
const uint8_t tipResistance = 45; //x10 ohms, 4.5 typical for ts80 tips
|
const uint8_t tipResistance = 45; //x10 ohms, 4.5 typical for ts80 tips
|
||||||
|
|||||||
Reference in New Issue
Block a user