Skip to content
This repository has been archived by the owner on Mar 10, 2024. It is now read-only.

Commit

Permalink
Fixed incorrect cycle units.
Browse files Browse the repository at this point in the history
  • Loading branch information
Dual Tachyon authored and Dual Tachyon committed Oct 26, 2023
1 parent b8fff25 commit 7f4e33b
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
26 changes: 13 additions & 13 deletions driver/bk1080.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,33 +109,33 @@ static uint8_t RecvByte(void)
SDA_SetOutput();

gpio_bits_reset(GPIOB, BOARD_GPIOB_BK1080_SDA);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_set(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_reset(GPIOC, BOARD_GPIOC_BK1080_SCL);
gpio_bits_set(GPIOB, BOARD_GPIOB_BK1080_SDA);
DELAY_WaitNS(1);
DELAY_WaitUS(1);

SDA_SetInput();

Value = 0;
for (i = 0; i < 8; i++) {
Value <<= 1;
gpio_bits_reset(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
if (gpio_input_data_bit_read(GPIOB, BOARD_GPIOB_BK1080_SDA)) {
Value |= 1;
}
gpio_bits_set(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
}

SDA_SetOutput();

gpio_bits_set(GPIOB, BOARD_GPIOB_BK1080_SDA);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_reset(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);

return Value;
}
Expand All @@ -147,9 +147,9 @@ static void SendByte(uint8_t Value)
SDA_SetOutput();

gpio_bits_reset(GPIOB, BOARD_GPIOB_BK1080_SDA);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_set(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_reset(GPIOC, BOARD_GPIOC_BK1080_SCL);

for (i = 0; i < 8; i++) {
Expand Down Expand Up @@ -181,19 +181,19 @@ static uint16_t AdjustFrequency(uint32_t Frequency)
static void StopI2C(void)
{
gpio_bits_set(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_set(GPIOB, BOARD_GPIOB_BK1080_SDA);
}

static void RenameLater(void)
{
SDA_SetOutput();
gpio_bits_reset(GPIOB, BOARD_GPIOB_BK1080_SDA);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_set(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);
gpio_bits_reset(GPIOC, BOARD_GPIOC_BK1080_SCL);
DELAY_WaitNS(1);
DELAY_WaitUS(1);

StopI2C();
}
Expand Down
24 changes: 12 additions & 12 deletions driver/delay.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,21 @@
#include "driver/crm.h"
#include "driver/delay.h"

static uint32_t gCyclesPerNanoSec;
static uint32_t gCyclesPerMicroSec;
static uint32_t gCyclesPerMilliSec;

void DELAY_Init(void)
{
systick_clock_source_config(SYSTICK_CLOCK_SOURCE_AHBCLK_NODIV);
gCyclesPerNanoSec = gSystemCoreClock / 1000000;
gCyclesPerMicroSec = (gSystemCoreClock / 1000000) * 1000;
gCyclesPerMicroSec = gSystemCoreClock / 1000000;
gCyclesPerMilliSec = (gSystemCoreClock / 1000000) * 1000;
}

void DELAY_WaitNS(uint32_t Delay)
void DELAY_WaitUS(uint32_t Delay)
{
uint32_t Control;

SysTick->LOAD = gCyclesPerNanoSec * Delay;
SysTick->LOAD = gCyclesPerMicroSec * Delay;
SysTick->VAL = 0;
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;

Expand All @@ -44,7 +44,7 @@ void DELAY_WaitNS(uint32_t Delay)
SysTick->VAL = 0;
}

void DELAY_WaitUS(uint16_t Delay)
static void WaitMS(uint16_t Delay)
{
uint32_t Control;

Expand All @@ -53,10 +53,10 @@ void DELAY_WaitUS(uint16_t Delay)
return;
}
if (Delay > 50) {
SysTick->LOAD = gCyclesPerMicroSec * 50;
Delay = Delay - 50;
SysTick->LOAD = gCyclesPerMilliSec * 50;
Delay -= 50;
} else {
SysTick->LOAD = gCyclesPerMicroSec * Delay;
SysTick->LOAD = gCyclesPerMilliSec * Delay;
Delay = 0;
}
SysTick->CTRL |= SysTick_CTRL_ENABLE_Msk;
Expand All @@ -75,9 +75,9 @@ void DELAY_WaitMS(uint16_t Delay)
uint16_t i;

for (i = 0; i < (Delay / 500); i++) {
DELAY_WaitUS(500);
DELAY_WaitNS(13000);
WaitMS(500);
DELAY_WaitUS(13000);
}
DELAY_WaitUS(Delay - (500 * (Delay / 500)));
WaitMS(Delay % 500);
}

3 changes: 1 addition & 2 deletions driver/delay.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
#include <stdint.h>

void DELAY_Init(void);
void DELAY_WaitNS(uint32_t Delay);
void DELAY_WaitUS(uint16_t Delay);
void DELAY_WaitUS(uint32_t Delay);
void DELAY_WaitMS(uint16_t Delay);

#endif
Expand Down
4 changes: 2 additions & 2 deletions driver/serial-flash.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void SFLASH_Write(const void *pBuffer, uint32_t Address, uint16_t Size)
Address += Remaining;
Size -= Remaining;
Remaining = 0x100;
if (Size < 0x101) {
if (Size <= 0x100) {
Remaining = Size;
}
}
Expand Down Expand Up @@ -220,7 +220,7 @@ void SFLASH_Update(const void *pBuffer, uint32_t Address, uint16_t Size)
Address += Remaining;
Size -= Remaining;
Remaining = 0x1000;
if (Size < 0x1001) {
if (Size <= 0x1000) {
Remaining = Size;
}
}
Expand Down

0 comments on commit 7f4e33b

Please sign in to comment.