Skip to content

Commit

Permalink
norflash: Style fixes
Browse files Browse the repository at this point in the history
As pointed out by Axel, thanks!
  • Loading branch information
Ithamar committed Nov 21, 2012
1 parent 066688d commit 64e4a82
Showing 1 changed file with 30 additions and 53 deletions.
83 changes: 30 additions & 53 deletions src/add-ons/kernel/drivers/disk/norflash/norflash.cpp
Expand Up @@ -7,15 +7,16 @@
*/


#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

#include <drivers/device_manager.h>
#include <drivers/KernelExport.h>
#include <drivers/Drivers.h>
#include <kernel/OS.h>

#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>

//#define TRACE_NORFLASH
#ifdef TRACE_NORFLASH
Expand All @@ -24,11 +25,14 @@
#define TRACE(x...)
#endif


#define NORFLASH_DEVICE_MODULE_NAME "drivers/disk/norflash/device_v1"
#define NORFLASH_DRIVER_MODULE_NAME "drivers/disk/norflash/driver_v1"


#define NORFLASH_ADDR 0x00000000


struct nor_driver_info {
device_node *node;
size_t blocksize;
Expand All @@ -38,42 +42,15 @@ struct nor_driver_info {
void *mapped;
};

static device_manager_info* sDeviceManager;

static const char *sTabTab = "\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t";
#define DS "%.*s"
#define DA depth - 1, sTabTab

static void
dump_hex(const char *data, int32 len, int depth = 1)
{
char str[128];
char astr[32];
char *p;
int l;
int i;

for (i = 0; i < len; ) {
p = str;
l = sizeof(str);
for (; i < len && (p == str || (i % 16 != 0)); i++) {
snprintf(p, l - 1, "%02x ", data[i]);
l -= strlen(p);
p += strlen(p);
astr[i % 16] = isprint(data[i]) ? data[i] : '.';
astr[i % 16] = isprint(data[i]) ? data[i] : '.';
astr[(i % 16) + 1] = '\0';
}
dprintf(DS" %-48.48s %s\n", DA, str, astr);
}
}
static device_manager_info *sDeviceManager;


static status_t
nor_init_device(void* _info, void** _cookie)
nor_init_device(void *_info, void **_cookie)
{
TRACE("init_device\n");
nor_driver_info* info = (nor_driver_info*)_info;
nor_driver_info *info = (nor_driver_info*)_info;

info->mapped = NULL;
info->blocksize = 128 * 1024;
Expand All @@ -89,18 +66,18 @@ nor_init_device(void* _info, void** _cookie)


static void
nor_uninit_device(void* _cookie)
nor_uninit_device(void *_cookie)
{
TRACE("uninit_device\n");
nor_driver_info* info = (nor_driver_info*)_cookie;
nor_driver_info *info = (nor_driver_info*)_cookie;
if (info)
delete_area(info->id);
}


static status_t
nor_open(void *deviceCookie, const char *path, int openMode,
void **_cookie)
void **_cookie)
{
TRACE("open(%s)\n", path);
*_cookie = deviceCookie;
Expand All @@ -127,11 +104,11 @@ nor_free(void *_cookie)
static status_t
nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
{
nor_driver_info* info = (nor_driver_info*)cookie;
nor_driver_info *info = (nor_driver_info*)cookie;
TRACE("ioctl(%ld,%lu)\n", op, length);

switch(op) {
case B_GET_GEOMETRY:
switch (op) {
case B_GET_GEOMETRY:
{
device_geometry *deviceGeometry = (device_geometry*)buffer;
deviceGeometry->removable = false;
Expand All @@ -146,9 +123,10 @@ nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
return B_OK;
}
break;
case B_GET_DEVICE_NAME:
strlcpy((char*)buffer, "NORFlash", length);
break;

case B_GET_DEVICE_NAME:
strlcpy((char*)buffer, "NORFlash", length);
break;
}

return B_ERROR;
Expand All @@ -158,18 +136,14 @@ nor_ioctl(void *cookie, uint32 op, void *buffer, size_t length)
static status_t
nor_read(void *_cookie, off_t position, void *data, size_t *numbytes)
{
nor_driver_info* info = (nor_driver_info*)_cookie;
nor_driver_info *info = (nor_driver_info*)_cookie;
TRACE("read(%Ld,%lu)\n", position, *numbytes);

if (position + *numbytes > info->totalsize)
*numbytes = info->totalsize - (position + *numbytes);

memcpy(data, info->mapped + position, *numbytes);

#ifdef TRACE_NORFLASH
dump_hex((const char*)(info->mapped + position), *numbytes, 1);
#endif

return B_OK;
}

Expand Down Expand Up @@ -210,7 +184,7 @@ nor_init_driver(device_node *node, void **cookie)
{
TRACE("init_driver\n");

nor_driver_info* info = (nor_driver_info*)malloc(sizeof(nor_driver_info));
nor_driver_info *info = (nor_driver_info*)malloc(sizeof(nor_driver_info));
if (info == NULL)
return B_NO_MEMORY;

Expand All @@ -227,16 +201,16 @@ static void
nor_uninit_driver(void *_cookie)
{
TRACE("uninit_driver\n");
nor_driver_info* info = (nor_driver_info*)_cookie;
nor_driver_info *info = (nor_driver_info*)_cookie;
free(info);
}


static status_t
nor_register_child_devices(void* _cookie)
nor_register_child_devices(void *_cookie)
{
TRACE("register_child_devices\n");
nor_driver_info* info = (nor_driver_info*)_cookie;
nor_driver_info *info = (nor_driver_info*)_cookie;
status_t status;

status = sDeviceManager->publish_device(info->node, "disk/nor/0/raw",
Expand All @@ -245,6 +219,7 @@ nor_register_child_devices(void* _cookie)
return status;
}


struct device_module_info sNORFlashDiskDevice = {
{
NORFLASH_DEVICE_MODULE_NAME,
Expand Down Expand Up @@ -286,12 +261,14 @@ struct driver_module_info sNORFlashDiskDriver = {
NULL, // removed
};


module_dependency module_dependencies[] = {
{ B_DEVICE_MANAGER_MODULE_NAME, (module_info**)&sDeviceManager },
{ }
};

module_info* modules[] = {

module_info *modules[] = {
(module_info*)&sNORFlashDiskDriver,
(module_info*)&sNORFlashDiskDevice,
NULL
Expand Down

0 comments on commit 64e4a82

Please sign in to comment.