Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement LittleFS for LN882H - only first basic testing from WebApp … #1191

Merged
merged 16 commits into from
May 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/cmnds/cmd_eventHandlers.c
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ void EventHandlers_ProcessVariableChange_Integer(byte eventCode, int oldValue, i
ev = ev->next;
}

#if defined(PLATFORM_BEKEN) || defined(WINDOWS)
#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_LN882H)
CMD_Script_ProcessWaitersForEvent(eventCode, newValue);
#endif
}
Expand Down Expand Up @@ -383,7 +383,7 @@ void EventHandlers_FireEvent(byte eventCode, int argument) {
ev = ev->next;
}

#if defined(PLATFORM_BEKEN) || defined(WINDOWS)
#if defined(PLATFORM_BEKEN) || defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_LN882H)
CMD_Script_ProcessWaitersForEvent(eventCode, argument);
#endif
}
Expand Down
4 changes: 2 additions & 2 deletions src/cmnds/cmd_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,7 +269,7 @@ static commandResult_t CMD_ClearAll(const void* context, const char* cmd, const
CHANNEL_ClearAllChannels();
CMD_ClearAllHandlers(0, 0, 0, 0);
RepeatingEvents_Cmd_ClearRepeatingEvents(0, 0, 0, 0);
#if defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_BEKEN)
#if defined(WINDOWS) || defined(PLATFORM_BL602) || defined(PLATFORM_BEKEN) || defined(PLATFORM_LN882H)
CMD_resetSVM(0, 0, 0, 0);
#endif

Expand Down Expand Up @@ -824,7 +824,7 @@ void CMD_Init_Early() {
//cmddetail:"examples":""}
CMD_RegisterCommand("PWMFrequency", CMD_PWMFrequency, NULL);

#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602)
#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) || (defined PLATFORM_LN882H)
CMD_InitScripting();
#endif
if (!bSafeMode) {
Expand Down
2 changes: 1 addition & 1 deletion src/littlefs/lfs_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

#if PLATFORM_BEKEN
#include "mem_pub.h"
#elif PLATFORM_BL602
#elif PLATFORM_BL602 || PLATFORM_LN882H
#define os_free free
#define os_malloc malloc
#endif
Expand Down
51 changes: 51 additions & 0 deletions src/littlefs/our_lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,13 @@
#include <bl_flash.h>
#include <bl_mtd.h>

#elif PLATFORM_LN882H

#include "../hal/hal_flashConfig.h"
#include "hal/hal_flash.h"
#include "flash_partition_table.h"


#endif


Expand Down Expand Up @@ -562,6 +569,50 @@ static int lfs_erase(const struct lfs_config *c, lfs_block_t block){
}



#elif PLATFORM_LN882H

static int lfs_read(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, void *buffer, lfs_size_t size){
int res;
unsigned int startAddr = LFS_Start;
startAddr += block*LFS_BLOCK_SIZE;
startAddr += off;
res = hal_flash_read(startAddr, size, (uint8_t *)buffer);
return res;
}

// Program a region in a block. The block must have previously
// been erased. Negative error codes are propogated to the user.
// May return LFS_ERR_CORRUPT if the block should be considered bad.
static int lfs_write(const struct lfs_config *c, lfs_block_t block,
lfs_off_t off, const void *buffer, lfs_size_t size){
int res;
unsigned int startAddr = LFS_Start;


startAddr += block*LFS_BLOCK_SIZE;
startAddr += off;

res = hal_flash_program(startAddr, size, (uint8_t *)buffer);


return res;
}

// Erase a block. A block must be erased before being programmed.
// The state of an erased block is undefined. Negative error codes
// are propogated to the user.
// May return LFS_ERR_CORRUPT if the block should be considered bad.
static int lfs_erase(const struct lfs_config *c, lfs_block_t block){
int res = LFS_ERR_OK;
unsigned int startAddr = LFS_Start;
startAddr += block*LFS_BLOCK_SIZE;
hal_flash_erase(startAddr, LFS_BLOCK_SIZE); // it's a void function for LN882H, so no return value
return res;
}


#endif

// Sync the state of the underlying block device. Negative error codes
Expand Down
12 changes: 11 additions & 1 deletion src/littlefs/our_lfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,16 @@
// end media partition
#define LFS_BLOCKS_END 0x1E9000

#elif PLATFORM_LN882H
// start0x1000 after OTA addr (OTA, start_addr: 0x00133000, size_KB: 0x000AA000)
// (OTA, start_addr: 0x00133000, size_KB: 0x000AA000)
// --> OTA-start + 0x1000 = 0x00133000 + 0x1000 = 0x00134000
// --> OTA-end = 0x00133000 + 0x000AA000 = 0x001DD000
#define LFS_BLOCKS_START 0x00134000
#define LFS_BLOCKS_START_MIN 0x00134000
// end media partition
#define LFS_BLOCKS_END 0x001DD000

#else
// TODO
// start 0x1000 after OTA addr
Expand Down Expand Up @@ -67,4 +77,4 @@ void init_lfs(int create);
void release_lfs();
int lfs_present();
#endif
#endif
#endif
4 changes: 1 addition & 3 deletions src/new_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -322,9 +322,7 @@ OSStatus rtos_create_thread( beken_thread_t* thread,
#elif PLATFORM_LN882H

// TODO:LN882H Platform setup here.
typedef int bool;
#define true 1
#define false 0
#include <stdbool.h>

#define ASSERT
#define os_strcpy strcpy
Expand Down
9 changes: 6 additions & 3 deletions src/obk_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,15 @@

//#define OBK_DISABLE_ALL_DRIVERS 1
//#define ENABLE_TASMOTADEVICEGROUPS 1
#define ENABLE_NTP 1
#define ENABLE_DRIVER_BL0937 1
#define ENABLE_DRIVER_LED 1
#define ENABLE_NTP 1
#define ENABLE_DRIVER_BL0937 1
#define ENABLE_DRIVER_LED 1
#define ENABLE_DRIVER_WEMO 1
#define ENABLE_DRIVER_HUE 1
#define ENABLE_DRIVER_DHT 1
#define ENABLE_LITTLEFS 1
#define ENABLE_TEST_COMMANDS 0
#define ENABLE_EXPAND_CONSTANT 1
//#define ENABLE_DRIVER_TMGN 1

#else
Expand Down
2 changes: 1 addition & 1 deletion src/user_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ void QuickTick(void* param)
g_last_time = g_time;


#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602)
#if (defined WINDOWS) || (defined PLATFORM_BEKEN) || (defined PLATFORM_BL602) || (defined PLATFORM_LN882H)
SVM_RunThreads(g_deltaTimeMS);
#endif
RepeatingEvents_RunUpdate(g_deltaTimeMS * 0.001f);
Expand Down
Loading